struct Fragment {
    float4 color : SV_Target;
}

struct VertexIn {
	[[vk::layout(0)]] float2 pos;
	[[vk::layout(1)]] float2 uv;
	[[vk::layout(2)]] float4 color;
}
struct VertexOut {
	[[vk::layout(0)]] float4 color;
	[[vk::layout(1)]] float2 uv;
	[[vk::layout(2), flat]] uint draw_id;
	float4 position : SV_Position;
}

struct PushConstant {
	float2 screen_size;
}

[[vk::push_constant]]
ConstantBuffer<PushConstant> push_constant;

[shader("vertex")]
VertexOut vertex(VertexIn vertex, uint draw_id: SV_DrawIndex) {
    VertexOut output;

	output.position = float4(
	    2.0 * vertex.pos.x / push_constant.screen_size.x - 1.0,
		       2.0 * vertex.pos.y / push_constant.screen_size.y - 1.0,
		       0.0,
1.0,
    );
	output.color = vertex.color;
	output.uv = vertex.uv;
	output.draw_id = draw_id;

	return output;
}

[[vk::binding(0)]]
Sampler2D texture[];


[[vk::binding(1)]]
StructuredBuffer<uint> texture_ids;

[shader("fragment")]
Fragment fragment(VertexOut input) {
    Fragment output;

    uint texture_id = texture_ids[input.draw_id];
    output.color = input.color * texture[texture_id].Sample(input.uv);
	return output;
}
