From 44f63c69baba2d8de508e1e32c492729f36f01c7 Mon Sep 17 00:00:00 2001 From: spencer-lunarg Date: Thu, 12 Dec 2024 00:10:24 +0900 Subject: [PATCH] tests: More Sampled Images tests for GPU-AV --- tests/unit/gpu_av_descriptor_indexing.cpp | 68 +++++++++++++++++++ .../gpu_av_descriptor_indexing_positive.cpp | 67 ++++++++++++++++++ 2 files changed, 135 insertions(+) diff --git a/tests/unit/gpu_av_descriptor_indexing.cpp b/tests/unit/gpu_av_descriptor_indexing.cpp index f661943f919..d96c180f0f0 100644 --- a/tests/unit/gpu_av_descriptor_indexing.cpp +++ b/tests/unit/gpu_av_descriptor_indexing.cpp @@ -3319,6 +3319,74 @@ TEST_F(NegativeGpuAVDescriptorIndexing, ConstantArrayOOBBuffer) { m_errorMonitor->VerifyFound(); } +// https://github.com/KhronosGroup/Vulkan-ValidationLayers/issues/8922 +TEST_F(NegativeGpuAVDescriptorIndexing, DISABLED_NonUniformSamplers) { + AddRequiredExtensions(VK_EXT_DESCRIPTOR_INDEXING_EXTENSION_NAME); + AddRequiredFeature(vkt::Feature::runtimeDescriptorArray); + RETURN_IF_SKIP(InitGpuAvFramework()); + RETURN_IF_SKIP(InitState()); + InitRenderTarget(); + + const char fs_source[] = R"glsl( + #version 460 + #extension GL_EXT_nonuniform_qualifier : require + + layout(push_constant, std430) uniform PushConstants { + uint tId; + uint sId; + } pc; + + layout(set = 0, binding = 0) uniform texture2D kTextures2D[]; + layout(set = 0, binding = 1) uniform sampler kSamplers[]; + layout(location = 0) out vec4 out_color; + + void main() { + out_color = texture(nonuniformEXT(sampler2D(kTextures2D[pc.tId], kSamplers[pc.sId])), vec2(0)); + } + )glsl"; + VkShaderObj vs(this, kVertexDrawPassthroughGlsl, VK_SHADER_STAGE_VERTEX_BIT); + VkShaderObj fs(this, fs_source, VK_SHADER_STAGE_FRAGMENT_BIT); + + VkPushConstantRange pc_range = {VK_SHADER_STAGE_FRAGMENT_BIT, 0, 16}; + OneOffDescriptorSet descriptor_set(m_device, {{0, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr}, + {1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr}}); + const vkt::PipelineLayout pipeline_layout(*m_device, {&descriptor_set.layout_}, {pc_range}); + + CreatePipelineHelper pipe(*this); + pipe.shader_stages_ = {vs.GetStageCreateInfo(), fs.GetStageCreateInfo()}; + pipe.gp_ci_.layout = pipeline_layout.handle(); + pipe.CreateGraphicsPipeline(); + + vkt::Sampler sampler(*m_device, SafeSaneSamplerCreateInfo()); + vkt::Image image(*m_device, 16, 16, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT); + image.SetLayout(VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); + vkt::ImageView image_view = image.CreateView(); + + descriptor_set.WriteDescriptorImageInfo(0, image_view, VK_NULL_HANDLE, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE); + descriptor_set.WriteDescriptorImageInfo(1, VK_NULL_HANDLE, sampler, VK_DESCRIPTOR_TYPE_SAMPLER); + descriptor_set.UpdateDescriptorSets(); + + m_command_buffer.Begin(); + m_command_buffer.BeginRenderPass(m_renderPassBeginInfo); + + uint32_t texture_id = 0; + uint32_t sampler_id = 1; + vk::CmdPushConstants(m_command_buffer.handle(), pipeline_layout.handle(), VK_SHADER_STAGE_FRAGMENT_BIT, 0, 4, &texture_id); + vk::CmdPushConstants(m_command_buffer.handle(), pipeline_layout.handle(), VK_SHADER_STAGE_FRAGMENT_BIT, 4, 4, &sampler_id); + + vk::CmdBindPipeline(m_command_buffer.handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.Handle()); + vk::CmdBindDescriptorSets(m_command_buffer.handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, + &descriptor_set.set_, 0, nullptr); + vk::CmdDraw(m_command_buffer.handle(), 3, 1, 0, 0); + m_command_buffer.EndRenderPass(); + m_command_buffer.End(); + + m_errorMonitor->SetDesiredError("VUID-vkCmdDraw-None-10068", gpuav::glsl::kMaxErrorsPerCmd); + m_default_queue->Submit(m_command_buffer); + m_default_queue->Wait(); + m_errorMonitor->VerifyFound(); +} + TEST_F(NegativeGpuAVDescriptorIndexing, TexelFetchNested) { RETURN_IF_SKIP(InitGpuVUDescriptorIndexing()); InitRenderTarget(); diff --git a/tests/unit/gpu_av_descriptor_indexing_positive.cpp b/tests/unit/gpu_av_descriptor_indexing_positive.cpp index a7b6ac52b7b..5445a809396 100644 --- a/tests/unit/gpu_av_descriptor_indexing_positive.cpp +++ b/tests/unit/gpu_av_descriptor_indexing_positive.cpp @@ -345,6 +345,73 @@ TEST_F(PositiveGpuAVDescriptorIndexing, BasicHLSLRuntimeArray) { m_default_queue->Wait(); } +TEST_F(PositiveGpuAVDescriptorIndexing, NonUniformSamplers) { + AddRequiredExtensions(VK_EXT_DESCRIPTOR_INDEXING_EXTENSION_NAME); + AddRequiredFeature(vkt::Feature::runtimeDescriptorArray); + RETURN_IF_SKIP(InitGpuAvFramework()); + RETURN_IF_SKIP(InitState()); + InitRenderTarget(); + + const char fs_source[] = R"glsl( + #version 460 + #extension GL_EXT_nonuniform_qualifier : require + + layout(push_constant, std430) uniform PushConstants { + uint tId; + uint sId; + } pc; + + layout(set = 0, binding = 0) uniform texture2D kTextures2D[]; + layout(set = 0, binding = 1) uniform sampler kSamplers[]; + layout(location = 0) out vec4 out_color; + + void main() { + vec4 a = texture(sampler2D(kTextures2D[pc.tId], kSamplers[pc.sId]), vec2(0)); + vec4 b = texture(nonuniformEXT(sampler2D(kTextures2D[pc.tId], kSamplers[pc.sId])), vec2(0)); + out_color = a + b; + } + )glsl"; + VkShaderObj vs(this, kVertexDrawPassthroughGlsl, VK_SHADER_STAGE_VERTEX_BIT); + VkShaderObj fs(this, fs_source, VK_SHADER_STAGE_FRAGMENT_BIT); + + VkPushConstantRange pc_range = {VK_SHADER_STAGE_FRAGMENT_BIT, 0, 16}; + OneOffDescriptorSet descriptor_set(m_device, {{0, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr}, + {1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr}}); + const vkt::PipelineLayout pipeline_layout(*m_device, {&descriptor_set.layout_}, {pc_range}); + + CreatePipelineHelper pipe(*this); + pipe.shader_stages_ = {vs.GetStageCreateInfo(), fs.GetStageCreateInfo()}; + pipe.gp_ci_.layout = pipeline_layout.handle(); + pipe.CreateGraphicsPipeline(); + + vkt::Sampler sampler(*m_device, SafeSaneSamplerCreateInfo()); + vkt::Image image(*m_device, 16, 16, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT); + image.SetLayout(VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); + vkt::ImageView image_view = image.CreateView(); + + descriptor_set.WriteDescriptorImageInfo(0, image_view, VK_NULL_HANDLE, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE); + descriptor_set.WriteDescriptorImageInfo(1, VK_NULL_HANDLE, sampler, VK_DESCRIPTOR_TYPE_SAMPLER); + descriptor_set.UpdateDescriptorSets(); + + m_command_buffer.Begin(); + m_command_buffer.BeginRenderPass(m_renderPassBeginInfo); + + uint32_t texture_id = 0; + uint32_t sampler_id = 0; + vk::CmdPushConstants(m_command_buffer.handle(), pipeline_layout.handle(), VK_SHADER_STAGE_FRAGMENT_BIT, 0, 4, &texture_id); + vk::CmdPushConstants(m_command_buffer.handle(), pipeline_layout.handle(), VK_SHADER_STAGE_FRAGMENT_BIT, 4, 4, &sampler_id); + + vk::CmdBindPipeline(m_command_buffer.handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.Handle()); + vk::CmdBindDescriptorSets(m_command_buffer.handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, + &descriptor_set.set_, 0, nullptr); + vk::CmdDraw(m_command_buffer.handle(), 3, 1, 0, 0); + m_command_buffer.EndRenderPass(); + m_command_buffer.End(); + + m_default_queue->Submit(m_command_buffer); + m_default_queue->Wait(); +} + TEST_F(PositiveGpuAVDescriptorIndexing, UnInitImage) { TEST_DESCRIPTION( "Make sure there's not a crash if the sampler of a combined image sampler is initialized but the image isn't.");