Add support for VK_EXT_custom_border_color

This commit is contained in:
baldurk
2020-05-27 22:38:04 +01:00
parent 3b28df0543
commit 82e9228ace
13 changed files with 367 additions and 9 deletions
+7 -1
View File
@@ -786,11 +786,13 @@ DECLARE_REFLECTION_STRUCT(VkPerformanceQuerySubmitInfoKHR);
DECLARE_REFLECTION_STRUCT(VkPhysicalDevice16BitStorageFeatures);
DECLARE_REFLECTION_STRUCT(VkPhysicalDevice8BitStorageFeatures);
DECLARE_REFLECTION_STRUCT(VkPhysicalDeviceASTCDecodeFeaturesEXT);
DECLARE_REFLECTION_STRUCT(VkPhysicalDeviceBufferDeviceAddressFeaturesEXT);
DECLARE_REFLECTION_STRUCT(VkPhysicalDeviceBufferDeviceAddressFeatures);
DECLARE_REFLECTION_STRUCT(VkPhysicalDeviceBufferDeviceAddressFeaturesEXT);
DECLARE_REFLECTION_STRUCT(VkPhysicalDeviceCoherentMemoryFeaturesAMD);
DECLARE_REFLECTION_STRUCT(VkPhysicalDeviceConditionalRenderingFeaturesEXT);
DECLARE_REFLECTION_STRUCT(VkPhysicalDeviceConservativeRasterizationPropertiesEXT);
DECLARE_REFLECTION_STRUCT(VkPhysicalDeviceCustomBorderColorFeaturesEXT);
DECLARE_REFLECTION_STRUCT(VkPhysicalDeviceCustomBorderColorPropertiesEXT);
DECLARE_REFLECTION_STRUCT(VkPhysicalDeviceDepthClipEnableFeaturesEXT);
DECLARE_REFLECTION_STRUCT(VkPhysicalDeviceDepthStencilResolveProperties);
DECLARE_REFLECTION_STRUCT(VkPhysicalDeviceDescriptorIndexingFeatures)
@@ -914,6 +916,7 @@ DECLARE_REFLECTION_STRUCT(VkRenderPassMultiviewCreateInfo);
DECLARE_REFLECTION_STRUCT(VkRenderPassSampleLocationsBeginInfoEXT);
DECLARE_REFLECTION_STRUCT(VkSampleLocationsInfoEXT);
DECLARE_REFLECTION_STRUCT(VkSamplerCreateInfo);
DECLARE_REFLECTION_STRUCT(VkSamplerCustomBorderColorCreateInfoEXT);
DECLARE_REFLECTION_STRUCT(VkSamplerReductionModeCreateInfo);
DECLARE_REFLECTION_STRUCT(VkSamplerYcbcrConversionCreateInfo);
DECLARE_REFLECTION_STRUCT(VkSamplerYcbcrConversionImageFormatProperties);
@@ -1082,6 +1085,8 @@ DECLARE_DESERIALISE_TYPE(VkPhysicalDeviceASTCDecodeFeaturesEXT);
DECLARE_DESERIALISE_TYPE(VkPhysicalDeviceCoherentMemoryFeaturesAMD);
DECLARE_DESERIALISE_TYPE(VkPhysicalDeviceConditionalRenderingFeaturesEXT);
DECLARE_DESERIALISE_TYPE(VkPhysicalDeviceConservativeRasterizationPropertiesEXT);
DECLARE_DESERIALISE_TYPE(VkPhysicalDeviceCustomBorderColorFeaturesEXT);
DECLARE_DESERIALISE_TYPE(VkPhysicalDeviceCustomBorderColorPropertiesEXT);
DECLARE_DESERIALISE_TYPE(VkPhysicalDeviceDepthClipEnableFeaturesEXT);
DECLARE_DESERIALISE_TYPE(VkPhysicalDeviceDepthStencilResolveProperties);
DECLARE_DESERIALISE_TYPE(VkPhysicalDeviceDescriptorIndexingFeatures)
@@ -1202,6 +1207,7 @@ DECLARE_DESERIALISE_TYPE(VkRenderPassMultiviewCreateInfo);
DECLARE_DESERIALISE_TYPE(VkRenderPassSampleLocationsBeginInfoEXT);
DECLARE_DESERIALISE_TYPE(VkSampleLocationsInfoEXT);
DECLARE_DESERIALISE_TYPE(VkSamplerCreateInfo);
DECLARE_DESERIALISE_TYPE(VkSamplerCustomBorderColorCreateInfoEXT);
DECLARE_DESERIALISE_TYPE(VkSamplerReductionModeCreateInfo);
DECLARE_DESERIALISE_TYPE(VkSamplerYcbcrConversionCreateInfo);
DECLARE_DESERIALISE_TYPE(VkSamplerYcbcrConversionImageFormatProperties);
+3
View File
@@ -764,6 +764,9 @@ static const VkExtensionProperties supportedExtensions[] = {
VK_EXT_CONSERVATIVE_RASTERIZATION_EXTENSION_NAME,
VK_EXT_CONSERVATIVE_RASTERIZATION_SPEC_VERSION,
},
{
VK_EXT_CUSTOM_BORDER_COLOR_EXTENSION_NAME, VK_EXT_CUSTOM_BORDER_COLOR_SPEC_VERSION,
},
{
VK_EXT_DEBUG_MARKER_EXTENSION_NAME, VK_EXT_DEBUG_MARKER_SPEC_VERSION,
},
+14
View File
@@ -1012,6 +1012,20 @@ void VulkanCreationInfo::Sampler::Init(VulkanResourceManager *resourceMan, Vulka
{
ycbcr = GetResID(ycbcrInfo->conversion);
}
customBorder = false;
RDCEraseEl(customBorderColor);
customBorderFormat = VK_FORMAT_UNDEFINED;
const VkSamplerCustomBorderColorCreateInfoEXT *border =
(const VkSamplerCustomBorderColorCreateInfoEXT *)FindNextStruct(
pCreateInfo, VK_STRUCTURE_TYPE_SAMPLER_CUSTOM_BORDER_COLOR_CREATE_INFO_EXT);
if(border)
{
customBorder = true;
customBorderColor = border->customBorderColor;
customBorderFormat = border->format;
}
}
void VulkanCreationInfo::YCbCrSampler::Init(VulkanResourceManager *resourceMan,
+8
View File
@@ -493,9 +493,17 @@ struct VulkanCreationInfo
float maxLod;
VkBorderColor borderColor;
bool unnormalizedCoordinates;
// VkSamplerReductionModeCreateInfo
VkSamplerReductionMode reductionMode;
// VkSamplerYcbcrConversionInfo
ResourceId ycbcr;
// VkSamplerCustomBorderColorCreateInfoEXT
bool customBorder;
VkClearColorValue customBorderColor;
VkFormat customBorderFormat;
};
std::map<ResourceId, Sampler> m_Sampler;
+6 -3
View File
@@ -184,6 +184,10 @@ static void AppendModifiedChainedStruct(byte *&tempMem, VkStruct *outputStruct,
VkPhysicalDeviceConditionalRenderingFeaturesEXT); \
COPY_STRUCT(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CONSERVATIVE_RASTERIZATION_PROPERTIES_EXT, \
VkPhysicalDeviceConservativeRasterizationPropertiesEXT); \
COPY_STRUCT(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CUSTOM_BORDER_COLOR_FEATURES_EXT, \
VkPhysicalDeviceCustomBorderColorFeaturesEXT); \
COPY_STRUCT(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CUSTOM_BORDER_COLOR_PROPERTIES_EXT, \
VkPhysicalDeviceCustomBorderColorPropertiesEXT); \
COPY_STRUCT(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEDICATED_ALLOCATION_IMAGE_ALIASING_FEATURES_NV, \
VkPhysicalDeviceDedicatedAllocationImageAliasingFeaturesNV); \
COPY_STRUCT(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_CLIP_ENABLE_FEATURES_EXT, \
@@ -391,6 +395,8 @@ static void AppendModifiedChainedStruct(byte *&tempMem, VkStruct *outputStruct,
VkRenderPassSampleLocationsBeginInfoEXT); \
COPY_STRUCT(VK_STRUCTURE_TYPE_SAMPLE_LOCATIONS_INFO_EXT, VkSampleLocationsInfoEXT); \
COPY_STRUCT(VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO, VkSamplerCreateInfo); \
COPY_STRUCT(VK_STRUCTURE_TYPE_SAMPLER_CUSTOM_BORDER_COLOR_CREATE_INFO_EXT, \
VkSamplerCustomBorderColorCreateInfoEXT); \
COPY_STRUCT(VK_STRUCTURE_TYPE_SAMPLER_REDUCTION_MODE_CREATE_INFO, \
VkSamplerReductionModeCreateInfo); \
COPY_STRUCT(VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_CREATE_INFO, \
@@ -614,8 +620,6 @@ static void AppendModifiedChainedStruct(byte *&tempMem, VkStruct *outputStruct,
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COOPERATIVE_MATRIX_PROPERTIES_NV: \
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CORNER_SAMPLED_IMAGE_FEATURES_NV: \
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COVERAGE_REDUCTION_MODE_FEATURES_NV: \
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CUSTOM_BORDER_COLOR_FEATURES_EXT: \
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CUSTOM_BORDER_COLOR_PROPERTIES_EXT: \
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEVICE_GENERATED_COMMANDS_FEATURES_NV: \
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEVICE_GENERATED_COMMANDS_PROPERTIES_NV: \
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DIAGNOSTICS_CONFIG_FEATURES_NV: \
@@ -664,7 +668,6 @@ static void AppendModifiedChainedStruct(byte *&tempMem, VkStruct *outputStruct,
case VK_STRUCTURE_TYPE_RAY_TRACING_SHADER_GROUP_CREATE_INFO_KHR: \
case VK_STRUCTURE_TYPE_RAY_TRACING_SHADER_GROUP_CREATE_INFO_NV: \
case VK_STRUCTURE_TYPE_RENDER_PASS_TRANSFORM_BEGIN_INFO_QCOM: \
case VK_STRUCTURE_TYPE_SAMPLER_CUSTOM_BORDER_COLOR_CREATE_INFO_EXT: \
case VK_STRUCTURE_TYPE_SURFACE_CAPABILITIES_FULL_SCREEN_EXCLUSIVE_EXT: \
case VK_STRUCTURE_TYPE_SURFACE_FULL_SCREEN_EXCLUSIVE_INFO_EXT: \
case VK_STRUCTURE_TYPE_SURFACE_FULL_SCREEN_EXCLUSIVE_WIN32_INFO_EXT: \
+13
View File
@@ -1771,6 +1771,19 @@ void VulkanReplay::SavePipelineState(uint32_t eventId)
el.chromaFilter = ycbcr.chromaFilter;
el.forceExplicitReconstruction = ycbcr.forceExplicitReconstruction;
}
if(sampl.customBorder)
{
if(sampl.borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT)
{
for(int bord = 0; bord < 4; bord++)
el.borderColor[bord] = float(sampl.customBorderColor.int32[bord]);
}
else
{
memcpy(el.borderColor, sampl.customBorderColor.float32, sizeof(Vec4f));
}
}
}
}
else if(layoutBind.descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE ||
+61 -5
View File
@@ -488,6 +488,14 @@ SERIALISE_VK_HANDLES();
PNEXT_STRUCT(VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_CONSERVATIVE_STATE_CREATE_INFO_EXT, \
VkPipelineRasterizationConservativeStateCreateInfoEXT) \
\
/* VK_EXT_custom_border_color */ \
PNEXT_STRUCT(VK_STRUCTURE_TYPE_SAMPLER_CUSTOM_BORDER_COLOR_CREATE_INFO_EXT, \
VkSamplerCustomBorderColorCreateInfoEXT) \
PNEXT_STRUCT(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CUSTOM_BORDER_COLOR_PROPERTIES_EXT, \
VkPhysicalDeviceCustomBorderColorPropertiesEXT) \
PNEXT_STRUCT(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CUSTOM_BORDER_COLOR_FEATURES_EXT, \
VkPhysicalDeviceCustomBorderColorFeaturesEXT) \
\
/* VK_EXT_debug_marker */ \
PNEXT_STRUCT(VK_STRUCTURE_TYPE_DEBUG_MARKER_OBJECT_NAME_INFO_EXT, VkDebugMarkerObjectNameInfoEXT) \
PNEXT_STRUCT(VK_STRUCTURE_TYPE_DEBUG_MARKER_OBJECT_TAG_INFO_EXT, VkDebugMarkerObjectTagInfoEXT) \
@@ -1037,11 +1045,6 @@ SERIALISE_VK_HANDLES();
PNEXT_UNSUPPORTED(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BLEND_OPERATION_ADVANCED_PROPERTIES_EXT) \
PNEXT_UNSUPPORTED(VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_ADVANCED_STATE_CREATE_INFO_EXT) \
\
/* VK_EXT_custom_border_color */ \
PNEXT_UNSUPPORTED(VK_STRUCTURE_TYPE_SAMPLER_CUSTOM_BORDER_COLOR_CREATE_INFO_EXT) \
PNEXT_UNSUPPORTED(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CUSTOM_BORDER_COLOR_PROPERTIES_EXT) \
PNEXT_UNSUPPORTED(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CUSTOM_BORDER_COLOR_FEATURES_EXT) \
\
/* VK_EXT_external_memory_host */ \
PNEXT_UNSUPPORTED(VK_STRUCTURE_TYPE_IMPORT_MEMORY_HOST_POINTER_INFO_EXT) \
PNEXT_UNSUPPORTED(VK_STRUCTURE_TYPE_MEMORY_HOST_POINTER_PROPERTIES_EXT) \
@@ -4324,6 +4327,56 @@ void Deserialise(const VkPipelineRasterizationConservativeStateCreateInfoEXT &el
DeserialiseNext(el.pNext);
}
template <typename SerialiserType>
void DoSerialise(SerialiserType &ser, VkSamplerCustomBorderColorCreateInfoEXT &el)
{
RDCASSERT(ser.IsReading() ||
el.sType == VK_STRUCTURE_TYPE_SAMPLER_CUSTOM_BORDER_COLOR_CREATE_INFO_EXT);
SerialiseNext(ser, el.sType, el.pNext);
SERIALISE_MEMBER(customBorderColor);
SERIALISE_MEMBER(format);
}
template <>
void Deserialise(const VkSamplerCustomBorderColorCreateInfoEXT &el)
{
DeserialiseNext(el.pNext);
}
template <typename SerialiserType>
void DoSerialise(SerialiserType &ser, VkPhysicalDeviceCustomBorderColorPropertiesEXT &el)
{
RDCASSERT(ser.IsReading() ||
el.sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CUSTOM_BORDER_COLOR_PROPERTIES_EXT);
SerialiseNext(ser, el.sType, el.pNext);
SERIALISE_MEMBER(maxCustomBorderColorSamplers);
}
template <>
void Deserialise(const VkPhysicalDeviceCustomBorderColorPropertiesEXT &el)
{
DeserialiseNext(el.pNext);
}
template <typename SerialiserType>
void DoSerialise(SerialiserType &ser, VkPhysicalDeviceCustomBorderColorFeaturesEXT &el)
{
RDCASSERT(ser.IsReading() ||
el.sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CUSTOM_BORDER_COLOR_FEATURES_EXT);
SerialiseNext(ser, el.sType, el.pNext);
SERIALISE_MEMBER(customBorderColors);
SERIALISE_MEMBER(customBorderColorWithoutFormat);
}
template <>
void Deserialise(const VkPhysicalDeviceCustomBorderColorFeaturesEXT &el)
{
DeserialiseNext(el.pNext);
}
template <typename SerialiserType>
void DoSerialise(SerialiserType &ser, VkPipelineTessellationDomainOriginStateCreateInfo &el)
{
@@ -8363,6 +8416,8 @@ INSTANTIATE_SERIALISE_TYPE(VkPhysicalDeviceBufferDeviceAddressFeaturesEXT);
INSTANTIATE_SERIALISE_TYPE(VkPhysicalDeviceCoherentMemoryFeaturesAMD);
INSTANTIATE_SERIALISE_TYPE(VkPhysicalDeviceConditionalRenderingFeaturesEXT);
INSTANTIATE_SERIALISE_TYPE(VkPhysicalDeviceConservativeRasterizationPropertiesEXT);
INSTANTIATE_SERIALISE_TYPE(VkPhysicalDeviceCustomBorderColorFeaturesEXT);
INSTANTIATE_SERIALISE_TYPE(VkPhysicalDeviceCustomBorderColorPropertiesEXT);
INSTANTIATE_SERIALISE_TYPE(VkPhysicalDeviceDepthClipEnableFeaturesEXT);
INSTANTIATE_SERIALISE_TYPE(VkPhysicalDeviceDepthStencilResolveProperties);
INSTANTIATE_SERIALISE_TYPE(VkPhysicalDeviceDescriptorIndexingFeatures)
@@ -8484,6 +8539,7 @@ INSTANTIATE_SERIALISE_TYPE(VkRenderPassMultiviewCreateInfo);
INSTANTIATE_SERIALISE_TYPE(VkRenderPassSampleLocationsBeginInfoEXT);
INSTANTIATE_SERIALISE_TYPE(VkSampleLocationsInfoEXT);
INSTANTIATE_SERIALISE_TYPE(VkSamplerCreateInfo);
INSTANTIATE_SERIALISE_TYPE(VkSamplerCustomBorderColorCreateInfoEXT);
INSTANTIATE_SERIALISE_TYPE(VkSamplerReductionModeCreateInfo);
INSTANTIATE_SERIALISE_TYPE(VkSamplerYcbcrConversionCreateInfo);
INSTANTIATE_SERIALISE_TYPE(VkSamplerYcbcrConversionImageFormatProperties);
@@ -738,6 +738,7 @@ public:
if(samplerProps.reductionMode != VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE)
{
reductionInfo.reductionMode = samplerProps.reductionMode;
reductionInfo.pNext = sampInfo.pNext;
sampInfo.pNext = &reductionInfo;
}
@@ -748,10 +749,22 @@ public:
ycbcrInfo.conversion =
m_pDriver->GetResourceManager()->GetCurrentHandle<VkSamplerYcbcrConversion>(
viewProps.image);
ycbcrInfo.pNext = sampInfo.pNext;
sampInfo.pNext = &ycbcrInfo;
}
VkSamplerCustomBorderColorCreateInfoEXT borderInfo = {
VK_STRUCTURE_TYPE_SAMPLER_CUSTOM_BORDER_COLOR_CREATE_INFO_EXT};
if(samplerProps.customBorder)
{
borderInfo.customBorderColor = samplerProps.customBorderColor;
borderInfo.format = samplerProps.customBorderFormat;
borderInfo.pNext = sampInfo.pNext;
sampInfo.pNext = &borderInfo;
}
// now add the shader's bias on
sampInfo.mipLodBias += bias;
@@ -2531,6 +2531,14 @@ bool WrappedVulkan::Serialise_vkCreateDevice(SerialiserType &ser, VkPhysicalDevi
CHECK_PHYS_EXT_FEATURE(descriptorBindingInlineUniformBlockUpdateAfterBind);
}
END_PHYS_EXT_CHECK();
BEGIN_PHYS_EXT_CHECK(VkPhysicalDeviceCustomBorderColorFeaturesEXT,
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CUSTOM_BORDER_COLOR_FEATURES_EXT);
{
CHECK_PHYS_EXT_FEATURE(customBorderColors);
CHECK_PHYS_EXT_FEATURE(customBorderColorWithoutFormat);
}
END_PHYS_EXT_CHECK();
}
if(availFeatures.depthClamp)
+1
View File
@@ -9,6 +9,7 @@ set(VULKAN_SRC
vk/vk_test.cpp
vk/vk_adv_cbuffer_zoo.cpp
vk/vk_cbuffer_zoo.cpp
vk/vk_custom_border_color.cpp
vk/vk_descriptor_index.cpp
vk/vk_discard_rects.cpp
vk/vk_draw_zoo.cpp
+1
View File
@@ -253,6 +253,7 @@
<ClCompile Include="main.cpp" />
<ClCompile Include="test_common.cpp" />
<ClCompile Include="texture_zoo.cpp" />
<ClCompile Include="vk\vk_custom_border_color.cpp" />
<ClCompile Include="vk\vk_empty_capture.cpp" />
<ClCompile Include="vk\vk_khr_buffer_address.cpp" />
<ClCompile Include="vk\vk_large_buffer.cpp" />
+3
View File
@@ -496,6 +496,9 @@
<ClCompile Include="gl\gl_draw_zoo.cpp">
<Filter>OpenGL\demos</Filter>
</ClCompile>
<ClCompile Include="vk\vk_custom_border_color.cpp">
<Filter>Vulkan\demos</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Filter Include="D3D11">
@@ -0,0 +1,229 @@
/******************************************************************************
* The MIT License (MIT)
*
* Copyright (c) 2019-2020 Baldur Karlsson
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
******************************************************************************/
#include "vk_test.h"
RD_TEST(VK_Custom_Border_Color, VulkanGraphicsTest)
{
static constexpr const char *Description = "Tests the VK_EXT_custom_border_color extension.";
const std::string vertex = R"EOSHADER(
#version 450 core
layout(location = 0) in vec3 Position;
layout(location = 2) in vec2 UV;
layout(location = 0) out vec2 uv;
void main()
{
gl_Position = vec4(Position.xyz*vec3(1,-1,1), 1);
uv = UV;
}
)EOSHADER";
const std::string pixel = R"EOSHADER(
#version 450 core
layout(location = 0) in vec2 uv;
layout(location = 0, index = 0) out vec4 Color;
layout(set = 0, binding = 0) uniform sampler2D tex;
void main()
{
Color = texture(tex, uv.xy);
}
)EOSHADER";
void Prepare(int argc, char **argv)
{
devExts.push_back(VK_EXT_CUSTOM_BORDER_COLOR_EXTENSION_NAME);
VulkanGraphicsTest::Prepare(argc, argv);
static VkPhysicalDeviceCustomBorderColorFeaturesEXT feat = {};
feat.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CUSTOM_BORDER_COLOR_FEATURES_EXT;
feat.customBorderColors = VK_TRUE;
devInfoNext = &feat;
}
int main()
{
// initialise, create window, create context, etc
if(!Init())
return 3;
VkDescriptorSetLayout setlayout = createDescriptorSetLayout(vkh::DescriptorSetLayoutCreateInfo({
{
0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_FRAGMENT_BIT,
},
}));
VkPipelineLayout layout = createPipelineLayout(vkh::PipelineLayoutCreateInfo({setlayout}));
vkh::GraphicsPipelineCreateInfo pipeCreateInfo;
pipeCreateInfo.layout = layout;
pipeCreateInfo.renderPass = mainWindow->rp;
pipeCreateInfo.inputAssemblyState.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
pipeCreateInfo.vertexInputState.vertexBindingDescriptions = {vkh::vertexBind(0, DefaultA2V)};
pipeCreateInfo.vertexInputState.vertexAttributeDescriptions = {
vkh::vertexAttr(0, 0, DefaultA2V, pos), vkh::vertexAttr(1, 0, DefaultA2V, col),
vkh::vertexAttr(2, 0, DefaultA2V, uv),
};
pipeCreateInfo.stages = {
CompileShaderModule(vertex, ShaderLang::glsl, ShaderStage::vert, "main"),
CompileShaderModule(pixel, ShaderLang::glsl, ShaderStage::frag, "main"),
};
VkPipeline pipe = createGraphicsPipeline(pipeCreateInfo);
const DefaultA2V quad[4] = {
{Vec3f(-0.5f, -0.5f, 0.0f), Vec4f(0.0f, 0.0f, 0.0f, 1.0f), Vec2f(-0.5f, -0.5f)},
{Vec3f(0.5f, -0.5f, 0.0f), Vec4f(0.0f, 0.0f, 0.0f, 1.0f), Vec2f(1.5f, -0.5f)},
{Vec3f(-0.5f, 0.5f, 0.0f), Vec4f(0.0f, 0.0f, 0.0f, 1.0f), Vec2f(-0.5f, 1.5f)},
{Vec3f(0.5f, 0.5f, 0.0f), Vec4f(0.0f, 0.0f, 0.0f, 1.0f), Vec2f(1.5f, 1.5f)},
};
AllocatedBuffer vb(this,
vkh::BufferCreateInfo(sizeof(quad), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT |
VK_BUFFER_USAGE_TRANSFER_DST_BIT),
VmaAllocationCreateInfo({0, VMA_MEMORY_USAGE_CPU_TO_GPU}));
vb.upload(quad);
AllocatedImage img(
this, vkh::ImageCreateInfo(4, 4, 0, VK_FORMAT_R32G32B32A32_SFLOAT,
VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT),
VmaAllocationCreateInfo({0, VMA_MEMORY_USAGE_GPU_ONLY}));
AllocatedBuffer uploadBuf(
this, vkh::BufferCreateInfo(4 * 4 * sizeof(Vec4f), VK_BUFFER_USAGE_TRANSFER_SRC_BIT),
VmaAllocationCreateInfo({0, VMA_MEMORY_USAGE_CPU_TO_GPU}));
Vec4f *f = (Vec4f *)uploadBuf.map();
for(int i = 0; i < 4 * 4; i++)
f[i] = Vec4f(float(i % 4) / 4.0f, float(i / 4) / 4.0f, 0.0f, 1.0f);
uploadBuf.unmap();
uploadBufferToImage(img.image, {4, 4, 1}, uploadBuf.buffer,
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
VkImageView view = createImageView(
vkh::ImageViewCreateInfo(img.image, VK_IMAGE_VIEW_TYPE_2D, VK_FORMAT_R32G32B32A32_SFLOAT));
VkSampler blackbordersampler = createSampler(
vkh::SamplerCreateInfo(VK_FILTER_NEAREST, VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER, 0.0f,
VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK));
VkSamplerCustomBorderColorCreateInfoEXT custom = {};
custom.sType = VK_STRUCTURE_TYPE_SAMPLER_CUSTOM_BORDER_COLOR_CREATE_INFO_EXT;
custom.format = VK_FORMAT_R32G32B32A32_SFLOAT;
custom.customBorderColor.float32[0] = 1.0f;
custom.customBorderColor.float32[1] = 0.0f;
custom.customBorderColor.float32[2] = 1.0f;
custom.customBorderColor.float32[3] = 1.0f;
VkSampler custombordersampler = createSampler(
vkh::SamplerCreateInfo(VK_FILTER_NEAREST, VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER, 0.0f,
VK_BORDER_COLOR_FLOAT_CUSTOM_EXT)
.next(&custom));
VkDescriptorSet descset0 = allocateDescriptorSet(setlayout);
VkDescriptorSet descset1 = allocateDescriptorSet(setlayout);
vkh::updateDescriptorSets(
device, {
vkh::WriteDescriptorSet(
descset0, 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
{
vkh::DescriptorImageInfo(view, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
blackbordersampler),
}),
vkh::WriteDescriptorSet(
descset1, 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
{
vkh::DescriptorImageInfo(view, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
custombordersampler),
}),
});
while(Running())
{
VkCommandBuffer cmd = GetCommandBuffer();
vkBeginCommandBuffer(cmd, vkh::CommandBufferBeginInfo());
VkImage swapimg =
StartUsingBackbuffer(cmd, VK_ACCESS_TRANSFER_WRITE_BIT, VK_IMAGE_LAYOUT_GENERAL);
vkCmdClearColorImage(cmd, swapimg, VK_IMAGE_LAYOUT_GENERAL,
vkh::ClearColorValue(0.2f, 0.2f, 0.2f, 1.0f), 1,
vkh::ImageSubresourceRange());
vkCmdBeginRenderPass(
cmd, vkh::RenderPassBeginInfo(mainWindow->rp, mainWindow->GetFB(), mainWindow->scissor),
VK_SUBPASS_CONTENTS_INLINE);
VkViewport v = mainWindow->viewport;
v.width /= 2.0f;
vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, pipe);
vkCmdSetViewport(cmd, 0, 1, &v);
vkCmdSetScissor(cmd, 0, 1, &mainWindow->scissor);
vkh::cmdBindVertexBuffers(cmd, 0, {vb.buffer}, {0});
vkh::cmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, layout, 0, {descset0}, {});
vkCmdDraw(cmd, 4, 1, 0, 0);
v.x += v.width;
vkCmdSetViewport(cmd, 0, 1, &v);
vkh::cmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, layout, 0, {descset1}, {});
vkCmdDraw(cmd, 4, 1, 0, 0);
vkCmdEndRenderPass(cmd);
FinishUsingBackbuffer(cmd, VK_ACCESS_TRANSFER_WRITE_BIT, VK_IMAGE_LAYOUT_GENERAL);
vkEndCommandBuffer(cmd);
Submit(0, 1, {cmd});
Present();
}
return 0;
}
};
REGISTER_TEST();