Helper Shader fixes for non float formats

This commit is contained in:
Isaac Marovitz
2024-08-01 00:37:37 +01:00
committed by Evan Husted
parent 80bb95dfb9
commit 68146fa285
5 changed files with 166 additions and 31 deletions

View File

@@ -17,7 +17,7 @@ struct ConstantBuffers {
struct Textures
{
texture2d<float, access::sample> texture;
texture2d<FORMAT, access::sample> texture;
sampler sampler;
};
@@ -37,7 +37,7 @@ vertex CopyVertexOut vertexMain(uint vid [[vertex_id]],
return out;
}
fragment float4 fragmentMain(CopyVertexOut in [[stage_in]],
fragment FORMAT4 fragmentMain(CopyVertexOut in [[stage_in]],
constant Textures &textures [[buffer(TEXTURES_INDEX)]]) {
return textures.texture.sample(textures.sampler, in.uv);
}

View File

@@ -7,12 +7,36 @@ struct CopyVertexOut {
float2 uv;
};
struct Textures
{
texture2d_ms<float, access::read> texture;
struct TexCoords {
float data[4];
};
fragment float4 fragmentMain(CopyVertexOut in [[stage_in]],
struct ConstantBuffers {
constant TexCoords* tex_coord;
};
struct Textures
{
texture2d_ms<FORMAT, access::read> texture;
};
vertex CopyVertexOut vertexMain(uint vid [[vertex_id]],
constant ConstantBuffers &constant_buffers [[buffer(CONSTANT_BUFFERS_INDEX)]]) {
CopyVertexOut out;
int low = vid & 1;
int high = vid >> 1;
out.uv.x = constant_buffers.tex_coord->data[low];
out.uv.y = constant_buffers.tex_coord->data[2 + high];
out.position.x = (float(low) - 0.5f) * 2.0f;
out.position.y = (float(high) - 0.5f) * 2.0f;
out.position.z = 0.0f;
out.position.w = 1.0f;
return out;
}
fragment FORMAT4 fragmentMain(CopyVertexOut in [[stage_in]],
constant Textures &textures [[buffer(TEXTURES_INDEX)]],
uint sample_id [[sample_id]]) {
uint2 tex_size = uint2(textures.texture.get_width(), textures.texture.get_height());

View File

@@ -7,7 +7,7 @@ struct VertexOut {
};
struct ClearColor {
float4 data;
FORMAT4 data;
};
struct ConstantBuffers {
@@ -29,7 +29,7 @@ vertex VertexOut vertexMain(ushort vid [[vertex_id]]) {
}
struct FragmentOut {
float4 color [[color(COLOR_ATTACHMENT_INDEX)]];
FORMAT4 color [[color(COLOR_ATTACHMENT_INDEX)]];
};
fragment FragmentOut fragmentMain(VertexOut in [[stage_in]],