This commit is contained in:
Peter Li 2025-04-16 23:25:52 -07:00
parent ed3eb8ac83
commit d797083adf
6 changed files with 170 additions and 0 deletions

View File

@ -32,6 +32,7 @@ pub fn build(b: *std.Build) void {
}
sdl3.shaderDefintion(b, mod, "../../lib/sdl3", optimize, "sample.vert", b.path("shaders/sample.vert.json"));
sdl3.shaderDefintion(b, mod, "../../lib/sdl3", optimize, "meshes.vert", b.path("shaders/meshes.vert.json"));
// ========== tests ==========
const tests = b.addTest(.{

View File

@ -0,0 +1,34 @@
struct Input
{
float3 Position : TEXCOORD0;
float2 TexCoord : TEXCOORD1;
uint InstanceIndex : SV_InstanceID;
};
struct Output
{
float2 TexCoord : TEXCOORD0;
float4 Position : SV_Position;
};
struct Scene
{
float4x4 Model;
};
StructuredBuffer<Scene> scene: register(t0, space0);
cbuffer Uniforms : register(b0, space1)
{
float4x4 ViewProjection;
float time;
};
Output main(Input input)
{
Output output;
output.TexCoord = input.TexCoord;
output.Position = mul(ViewProjection, mul(float4(input.Position, 1.0), scene[input.InstanceIndex].Model));
return output;
}

View File

@ -0,0 +1,94 @@
{
"entryPoints" : [
{
"name" : "main",
"mode" : "vert"
}
],
"types" : {
"_8" : {
"name" : "Scene",
"members" : [
{
"name" : "Model",
"type" : "mat4",
"offset" : 0,
"matrix_stride" : 16,
"row_major" : true
}
]
},
"_7" : {
"name" : "type.StructuredBuffer.Scene",
"members" : [
{
"name" : "_m0",
"type" : "_8",
"array" : [
0
],
"array_size_is_literal" : [
true
],
"offset" : 0,
"array_stride" : 64
}
]
},
"_10" : {
"name" : "type.Uniforms",
"members" : [
{
"name" : "ViewProjection",
"type" : "mat4",
"offset" : 0,
"matrix_stride" : 16,
"row_major" : true
},
{
"name" : "time",
"type" : "float",
"offset" : 64
}
]
}
},
"inputs" : [
{
"type" : "vec3",
"name" : "in.var.TEXCOORD0",
"location" : 0
},
{
"type" : "vec2",
"name" : "in.var.TEXCOORD1",
"location" : 1
}
],
"outputs" : [
{
"type" : "vec2",
"name" : "out.var.TEXCOORD0",
"location" : 0
}
],
"ssbos" : [
{
"type" : "_7",
"name" : "scene",
"readonly" : true,
"block_size" : 0,
"set" : 0,
"binding" : 0
}
],
"ubos" : [
{
"type" : "_10",
"name" : "type.Uniforms",
"block_size" : 68,
"set" : 1,
"binding" : 0
}
]
}

Binary file not shown.

View File

@ -0,0 +1,41 @@
#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
struct Scene
{
float4x4 Model;
};
struct type_StructuredBuffer_Scene
{
Scene _m0[1];
};
struct type_Uniforms
{
float4x4 ViewProjection;
float time;
};
struct main0_out
{
float2 out_var_TEXCOORD0 [[user(locn0)]];
float4 gl_Position [[position]];
};
struct main0_in
{
float3 in_var_TEXCOORD0 [[attribute(0)]];
float2 in_var_TEXCOORD1 [[attribute(1)]];
};
vertex main0_out main0(main0_in in [[stage_in]], constant type_Uniforms& Uniforms [[buffer(0)]], const device type_StructuredBuffer_Scene& scene [[buffer(1)]], uint gl_InstanceIndex [[instance_id]])
{
main0_out out = {};
out.out_var_TEXCOORD0 = in.in_var_TEXCOORD1;
out.gl_Position = Uniforms.ViewProjection * (float4(in.in_var_TEXCOORD0, 1.0) * scene._m0[gl_InstanceIndex].Model);
return out;
}

Binary file not shown.