I want to write an hlsl shader that renders a 2D textured quad onto a render target.
I wrote the following vertex shader:
struct VertexData
{
float2 position;
float2 uv;
};
// 2 2D triangles that cover the whole render target
static VertexData vertices[6] =
{
{float2(-1.0, 1.0), float2(0.0, 0.0)},
{float2(-1.0, -1.0), float2(0.0, 1.0)},
{float2(1.0, 1.0), float2(0.0, 1.0)},
{float2(1.0, 1.0), float2(0.0, 1.0)},
{float2(-1.0, -1.0), float2(0.0, 1.0)},
{float2(1.0, -1.0), float2(1.0, 1.0)}
};
struct VSOutput
{
float4 position : SV_POSITION; // position in normalized device coordinates
[[vk::location(0)]] float2 uv : TEXCOORD0;
};
VSOutput main(uint vertexIndex : SV_VertexID)
{
VSOutput output = (VSOutput)0;
output.position = float4(vertices[vertexIndex].position, 0.0, 1.0);
output.uv = vertices[vertexIndex].uv;
return output;
}
I am trying to understand whether this is the 'best' or 'simplest' approach.
Specifically:
- Where does the memory for the
vertices
array reside? constant memory? global memory? is it cached? is it read only? - Is this the optimal approach? Should I use a constant buffer? AFAIK constant buffers are optimized for uniform access across the shader. Which is not the case here.