SurvivalMachine
SurvivalMachine

Reputation: 8356

What is the correct descriptor type for Buffer<float4> when using an HLSL shader in Vulkan?

I'm trying to use an HLSL fragment shader in my Vulkan renderer. The shader reads a buffer:

layout(set=0, binding=3) Buffer<float4> pointLightBufferCenterAndRadius : register(t1);

I don't know what kind of descriptor I should use for that descriptor slot. I tried to use VK_DESCRIPTOR_TYPE_STORAGE_BUFFER but the validation layer gives me the following error:

Type mismatch on descriptor slot 0.3 (used as type ptr to const uniform image(dim=5, sampled=1)) but descriptor of type VK_DESCRIPTOR_TYPE_STORAGE_BUFFER

What is the correct descriptor type for Buffer<float4>?

Upvotes: 1

Views: 1069

Answers (1)

Nicol Bolas
Nicol Bolas

Reputation: 474226

After some quick Googling, the Buffer type in HLSL appears to represent what OpenGL would call a "buffer texture" and what Vulkan would call a "texel buffer". That is, a buffer which is interpreted as a 1D array of "pixels" of a particular format (hence the <float4> part).

The compiler is generating SPIR-V that matches this description: a uniform variable with a type created by OpTypeImage, with a dimension of Buffer(hence, the "dim=5" part of the error). Such a variable expects to be used against a descriptor of type VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER. You will need to bind a VkBufferView to this descriptor, and the VkBuffer source of that view must allow for the VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT usage.

And of course the memory backing that VkBuffer must allow such usage.

Upvotes: 1

Related Questions