graphicsvulkanhlslshaderc

Spirv cross and HLSL for vulkan, merge bindings?


I am extracting reflection data from an HLSL shader targetting vulkan using spirv-cross. This is the shader in question:

struct VSInput
{
[[vk::location(0)]] float2 Pos : POSITION0;
[[vk::location(1)]] float3 Color : COLOR0;
};

struct UBO
{
   float2x2 transform;
};

cbuffer ubo : register(b0) { UBO ubo; }

struct VSOutput
{
   float4 Pos : SV_POSITION;
   [[vk::location(0)]] float3 Color : COLOR0;
};

VSOutput main(VSInput input)
{
   VSOutput output = (VSOutput)0;
   output.Color = input.Color;
   output.Pos = float4(ubo.transform * input.Pos.xy, 0, 1);
   return output;
}
Resource { id: 53, type_id: 52, base_type_id: 7, name: "input.Pos" }
Float { vecsize: 2, columns: 1, array: [] }
Location: Ok(0)
Binding: Ok(0)
Offset: Ok(0)
Resource { id: 57, type_id: 56, base_type_id: 8, name: "input.Color" }
Float { vecsize: 3, columns: 1, array: [] }
Location: Ok(1)
Binding: Ok(0)
Offset: Ok(0)

In particular the vertex input data, i.e. the position and the color, are in the same binding. Is there a way to tell hlsl (or shaderc, which is what I am compiling with) to separate both inputs into the different bindings?


Solution

  • The buffer binding used to feed a particular attribute aren't set in the shader. They're set with VkVertexInputAttributeDescription in code. As such, whatever tool is telling you that they have a "Binding" or "Offset" is incorrect. I imagine that's some generic tool that treats vertex attributes in exactly the same way as other resources (even though other resources don't have "locations"). Regardless, the "binding" it is referring to is something it made up and won't matter to Vulkan.