From 82e9228ace1b111bd033748ce75101dd9275ef29 Mon Sep 17 00:00:00 2001 From: baldurk Date: Wed, 27 May 2020 13:21:52 +0100 Subject: [PATCH] Add support for VK_EXT_custom_border_color --- renderdoc/driver/vulkan/vk_common.h | 8 +- renderdoc/driver/vulkan/vk_core.cpp | 3 + renderdoc/driver/vulkan/vk_info.cpp | 14 ++ renderdoc/driver/vulkan/vk_info.h | 8 + renderdoc/driver/vulkan/vk_next_chains.cpp | 9 +- renderdoc/driver/vulkan/vk_replay.cpp | 13 + renderdoc/driver/vulkan/vk_serialise.cpp | 66 ++++- renderdoc/driver/vulkan/vk_shaderdebug.cpp | 13 + .../vulkan/wrappers/vk_device_funcs.cpp | 8 + util/test/demos/CMakeLists.txt | 1 + util/test/demos/demos.vcxproj | 1 + util/test/demos/demos.vcxproj.filters | 3 + util/test/demos/vk/vk_custom_border_color.cpp | 229 ++++++++++++++++++ 13 files changed, 367 insertions(+), 9 deletions(-) create mode 100644 util/test/demos/vk/vk_custom_border_color.cpp diff --git a/renderdoc/driver/vulkan/vk_common.h b/renderdoc/driver/vulkan/vk_common.h index fc728339f..f01bbbd62 100644 --- a/renderdoc/driver/vulkan/vk_common.h +++ b/renderdoc/driver/vulkan/vk_common.h @@ -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); diff --git a/renderdoc/driver/vulkan/vk_core.cpp b/renderdoc/driver/vulkan/vk_core.cpp index 1a53d68ff..b819854da 100644 --- a/renderdoc/driver/vulkan/vk_core.cpp +++ b/renderdoc/driver/vulkan/vk_core.cpp @@ -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, }, diff --git a/renderdoc/driver/vulkan/vk_info.cpp b/renderdoc/driver/vulkan/vk_info.cpp index 31439dd3c..927dda48b 100644 --- a/renderdoc/driver/vulkan/vk_info.cpp +++ b/renderdoc/driver/vulkan/vk_info.cpp @@ -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, diff --git a/renderdoc/driver/vulkan/vk_info.h b/renderdoc/driver/vulkan/vk_info.h index a4ba19706..c5cddced8 100644 --- a/renderdoc/driver/vulkan/vk_info.h +++ b/renderdoc/driver/vulkan/vk_info.h @@ -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 m_Sampler; diff --git a/renderdoc/driver/vulkan/vk_next_chains.cpp b/renderdoc/driver/vulkan/vk_next_chains.cpp index 457aeb675..7cced11f7 100644 --- a/renderdoc/driver/vulkan/vk_next_chains.cpp +++ b/renderdoc/driver/vulkan/vk_next_chains.cpp @@ -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: \ diff --git a/renderdoc/driver/vulkan/vk_replay.cpp b/renderdoc/driver/vulkan/vk_replay.cpp index b991c4e58..924e95c22 100644 --- a/renderdoc/driver/vulkan/vk_replay.cpp +++ b/renderdoc/driver/vulkan/vk_replay.cpp @@ -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 || diff --git a/renderdoc/driver/vulkan/vk_serialise.cpp b/renderdoc/driver/vulkan/vk_serialise.cpp index 11ac8ceac..29b1aa6ee 100644 --- a/renderdoc/driver/vulkan/vk_serialise.cpp +++ b/renderdoc/driver/vulkan/vk_serialise.cpp @@ -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 +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 +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 +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 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); diff --git a/renderdoc/driver/vulkan/vk_shaderdebug.cpp b/renderdoc/driver/vulkan/vk_shaderdebug.cpp index bb570f68b..ed7e04e46 100644 --- a/renderdoc/driver/vulkan/vk_shaderdebug.cpp +++ b/renderdoc/driver/vulkan/vk_shaderdebug.cpp @@ -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( 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; diff --git a/renderdoc/driver/vulkan/wrappers/vk_device_funcs.cpp b/renderdoc/driver/vulkan/wrappers/vk_device_funcs.cpp index 63b3684d7..a4212ceb0 100644 --- a/renderdoc/driver/vulkan/wrappers/vk_device_funcs.cpp +++ b/renderdoc/driver/vulkan/wrappers/vk_device_funcs.cpp @@ -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) diff --git a/util/test/demos/CMakeLists.txt b/util/test/demos/CMakeLists.txt index ad5f03413..e5ca1b5e2 100644 --- a/util/test/demos/CMakeLists.txt +++ b/util/test/demos/CMakeLists.txt @@ -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 diff --git a/util/test/demos/demos.vcxproj b/util/test/demos/demos.vcxproj index d587476a6..3532c29fc 100644 --- a/util/test/demos/demos.vcxproj +++ b/util/test/demos/demos.vcxproj @@ -253,6 +253,7 @@ + diff --git a/util/test/demos/demos.vcxproj.filters b/util/test/demos/demos.vcxproj.filters index d811c2bb1..d059cac33 100644 --- a/util/test/demos/demos.vcxproj.filters +++ b/util/test/demos/demos.vcxproj.filters @@ -496,6 +496,9 @@ OpenGL\demos + + Vulkan\demos + diff --git a/util/test/demos/vk/vk_custom_border_color.cpp b/util/test/demos/vk/vk_custom_border_color.cpp new file mode 100644 index 000000000..acdd5860e --- /dev/null +++ b/util/test/demos/vk/vk_custom_border_color.cpp @@ -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();