Proper usage of combined ImageSamplers with Vulkan #5654
-
Hello, I have recently rewrote all my shaders from To accommodate for this i have created the following struct in my Slang shader struct TextureSampler
{
Texture2D texture;
SamplerState sampler;
float4 Sample(float2 uv) {
return texture.Sample(sampler, uv);
}
}
[[vk::binding(2,0)]]
ConstantBuffer<TextureSampler> albedo; This works as expected. However Vulkan validation layers are complaining with the following message. Error: { Validation }:
messageIDName = <VUID-VkGraphicsPipelineCreateInfo-layout-07988>
messageIdNumber = 559874765
message = <Validation Error: [ VUID-VkGraphicsPipelineCreateInfo-layout-07988 ] Object 0: handle = 0x340000000034, type = VK_OBJECT_TYPE_SHADER_MODULE; Object 1: handle = 0x350000000035, type = VK_OBJECT_TYPE_PIPELINE_LAYOUT; | MessageID = 0x215f02cd | vkCreateGraphicsPipelines(): pCreateInfos[1].pStages[1] SPIR-V (VK_SHADER_STAGE_FRAGMENT_BIT) uses descriptor [Set 0, Binding 3, variable "albedo.sampler"] (type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER or VK_DESCRIPTOR_TYPE_SAMPLER) but was not declared in the pipeline layout.
The Vulkan spec states: If a resource variables is declared in a shader, a descriptor slot in layout must match the shader stage (https://www.khronos.org/registry/vulkan/specs/1.3-extensions/html/vkspec.html#VUID-VkGraphicsPipelineCreateInfo-layout-07988)>
Objects:
Object 0
objectType = ShaderModule
objectHandle = 57174604644404
Object 1
objectType = PipelineLayout
objectHandle = 58274116272181
My question is if there is proper way of using What I was thinking is that I will pass the sampler and Texture image separately and than use the same sampler for all of the images but I would prefer to use the combined image sampler if possible. Thank you :) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
The provided shader code looks fine to me. I think the validation error is coming from the other part of the shader where the sampler is used in an unexpected stage. The struct might be meant for vertex shader only but it might be used in a fragment shader incorrectly. If you think it is a bug on Slang, we can work on it, but we need a repro case that reproduces the validation error mentioned. The texture-combined samplers such as *EDIT: I forgot to mention that you have to use |
Beta Was this translation helpful? Give feedback.
-
Hello, thank you for taking time and replying to my question. I have used Just to clarify, the |
Beta Was this translation helpful? Give feedback.
The provided shader code looks fine to me. I think the validation error is coming from the other part of the shader where the sampler is used in an unexpected stage. The struct might be meant for vertex shader only but it might be used in a fragment shader incorrectly.
If you think it is a bug on Slang, we can work on it, but we need a repro case that reproduces the validation error mentioned.
The texture-combined samplers such as
sampler2D
in GLSL are legalized by Slang in a way described above. If you usesampler2D
, Slang will create a Texture2D and SamplerState automatically. Please give a try and let us know if it doesn't work.*EDIT: I forgot to mention that you have to use
-allow-glsl
…