Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes for sokol-gfx bindings cleanup. #152

Merged
merged 37 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
7a86b5d
start fixing cube-metal.c for bindings rework
floooh Sep 8, 2024
948c4f6
fix metal/cube-metal.c
floooh Sep 10, 2024
596d5af
fix metal/texcube-metal.c
floooh Sep 14, 2024
1b93b86
fix all metal samples except imgui-metal
floooh Sep 14, 2024
cb6681c
sg_shader_bind_stage => sg_shader_stage
floooh Sep 14, 2024
a7aa05f
fix cube-d3d11 for bindings cleanup
floooh Sep 15, 2024
2a2fe55
update texcube-d3d11.c for bindings cleanup
floooh Sep 16, 2024
1ec7e41
update all d3d11 sampler for bindings cleanup
floooh Sep 16, 2024
6b02958
fix d3d11 samples (vertex_attrs => attrs)
floooh Sep 18, 2024
6311b3d
fix most glfw samples for new binding model
floooh Sep 21, 2024
0c65351
fix vertexpulling-glfw for new binding model
floooh Sep 21, 2024
e4ddca6
start porting webgl2 samples to new binding model
floooh Sep 21, 2024
7282bec
webgl2 sample update wip
floooh Sep 22, 2024
53ffb78
emscripten samples bindings cleanup wip
floooh Sep 22, 2024
ab2ff2b
fix bufferoffsets-emsc and offscreen-emsc
floooh Sep 22, 2024
1149271
wgpu samples: Dawn native fixes
floooh Sep 29, 2024
05c09fc
fix webgpu deprecations in 'raw' wgpu samples
floooh Sep 30, 2024
8a57457
fix triangle-wgpu.c for bindings cleanup
floooh Sep 30, 2024
d05406b
fix cube-wgpu for bindings cleanup
floooh Oct 1, 2024
a3bb2d0
fix texcube-wgpu for bindings cleanup
floooh Oct 1, 2024
2137f17
fix more wgpu samples for bindings cleanup
floooh Oct 1, 2024
5007ea3
update standalone wgpu samples for bindings cleanup (all except drawc…
floooh Oct 2, 2024
c043eed
fix sapp samples for bindings cleanup wip
floooh Oct 6, 2024
cb88e12
fix some sapp samples for layout(binding) and bindings cleanup
floooh Oct 7, 2024
9cd7e20
fix more samples for bindings cleanup
floooh Oct 9, 2024
0a0a659
fix drawcallperf-sapp, but needs further fixes because of sokol_imgui.h
floooh Oct 9, 2024
26a986d
more samples fixed/tested for bindings cleanup
floooh Oct 10, 2024
bb71bdc
fix more samples for bindings cleanup
floooh Oct 12, 2024
722ae74
fix uniformarrays-glfw for bindings cleanup
floooh Oct 14, 2024
c17b13b
fix more sapp samples for bindings cleanup
floooh Oct 14, 2024
d35ddac
fix more sapp samples for bindings cleanup
floooh Oct 14, 2024
54c1428
all sapp samples updated for bindings cleanup
floooh Oct 16, 2024
a4731a0
Merge branch 'master' into issue1037_bindings_cleanup
floooh Oct 25, 2024
2053f5e
add new shared-bindings-sapp sample
floooh Oct 26, 2024
060e48c
update metal samples
floooh Oct 28, 2024
b756f03
fix cubemap-jpeg-sapp-ui asset copying
floooh Oct 28, 2024
fbfa2d3
fix d3d11 samples
floooh Oct 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 62 additions & 53 deletions d3d11/arraytex-d3d11.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,65 +115,74 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _
sg_bindings bind = {
.vertex_buffers[0] = vbuf,
.index_buffer = ibuf,
.fs = {
.images[0] = img,
.samplers[0] = smp,
}
.images[0] = img,
.samplers[0] = smp,
};

// shader to sample from array texture
sg_shader shd = sg_make_shader(&(sg_shader_desc){
.vertex_func.source =
"cbuffer params: register(b0) {\n"
" float4x4 mvp;\n"
" float2 offset0;\n"
" float2 offset1;\n"
" float2 offset2;\n"
"};\n"
"struct vs_in {\n"
" float4 pos: POSITION;\n"
" float2 uv: TEXCOORD0;\n"
"};\n"
"struct vs_out {\n"
" float3 uv0: TEXCOORD0;\n"
" float3 uv1: TEXCOORD1;\n"
" float3 uv2: TEXCOORD2;\n"
" float4 pos: SV_Position;\n"
"};\n"
"vs_out main(vs_in inp) {\n"
" vs_out outp;\n"
" outp.pos = mul(mvp, inp.pos);\n"
" outp.uv0 = float3(inp.uv + offset0, 0.0);\n"
" outp.uv1 = float3(inp.uv + offset1, 1.0);\n"
" outp.uv2 = float3(inp.uv + offset2, 2.0);\n"
" return outp;\n"
"}\n",
.fragment_func.source =
"Texture2DArray<float4> tex: register(t0);\n"
"sampler smp: register(s0);\n"
"struct fs_in {\n"
" float3 uv0: TEXCOORD0;\n"
" float3 uv1: TEXCOORD1;\n"
" float3 uv2: TEXCOORD2;\n"
"};\n"
"float4 main(fs_in inp): SV_Target0 {\n"
" float3 c0 = tex.Sample(smp, inp.uv0).xyz;\n"
" float3 c1 = tex.Sample(smp, inp.uv1).xyz;\n"
" float3 c2 = tex.Sample(smp, inp.uv2).xyz;\n"
" return float4(c0+c1+c2, 1.0);\n"
"}\n",
.attrs = {
[0].sem_name = "POSITION",
[1].sem_name = "TEXCOORD"
[0].hlsl_sem_name = "POSITION",
[1].hlsl_sem_name = "TEXCOORD"
},
.vs = {
.uniform_blocks[0].size = sizeof(params_t),
.source =
"cbuffer params {\n"
" float4x4 mvp;\n"
" float2 offset0;\n"
" float2 offset1;\n"
" float2 offset2;\n"
"};\n"
"struct vs_in {\n"
" float4 pos: POSITION;\n"
" float2 uv: TEXCOORD0;\n"
"};\n"
"struct vs_out {\n"
" float3 uv0: TEXCOORD0;\n"
" float3 uv1: TEXCOORD1;\n"
" float3 uv2: TEXCOORD2;\n"
" float4 pos: SV_Position;\n"
"};\n"
"vs_out main(vs_in inp) {\n"
" vs_out outp;\n"
" outp.pos = mul(mvp, inp.pos);\n"
" outp.uv0 = float3(inp.uv + offset0, 0.0);\n"
" outp.uv1 = float3(inp.uv + offset1, 1.0);\n"
" outp.uv2 = float3(inp.uv + offset2, 2.0);\n"
" return outp;\n"
"}\n",
.uniform_blocks[0] = {
.stage = SG_SHADERSTAGE_VERTEX,
.size = sizeof(params_t),
.hlsl_register_b_n = 0,
},
.images[0] = {
.stage = SG_SHADERSTAGE_FRAGMENT,
.image_type = SG_IMAGETYPE_ARRAY,
.hlsl_register_t_n = 0,
},
.samplers[0] = {
.stage = SG_SHADERSTAGE_FRAGMENT,
.hlsl_register_s_n = 0,
},
.image_sampler_pairs[0] = {
.stage = SG_SHADERSTAGE_FRAGMENT,
.image_slot = 0,
.sampler_slot = 0,
},
.fs = {
.images[0] = { .used = true, .image_type = SG_IMAGETYPE_ARRAY },
.samplers[0] = { .used = true },
.image_sampler_pairs[0] = { .used = true, .image_slot = 0, .sampler_slot = 0 },
.source =
"Texture2DArray<float4> tex: register(t0);\n"
"sampler smp: register(s0);\n"
"struct fs_in {\n"
" float3 uv0: TEXCOORD0;\n"
" float3 uv1: TEXCOORD1;\n"
" float3 uv2: TEXCOORD2;\n"
"};\n"
"float4 main(fs_in inp): SV_Target0 {\n"
" float3 c0 = tex.Sample(smp, inp.uv0).xyz;\n"
" float3 c1 = tex.Sample(smp, inp.uv1).xyz;\n"
" float3 c2 = tex.Sample(smp, inp.uv2).xyz;\n"
" return float4(c0+c1+c2, 1.0);\n"
"}\n"
}
});

// create pipeline object
Expand Down Expand Up @@ -225,7 +234,7 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _
sg_begin_pass(&(sg_pass){ .action = pass_action, .swapchain = d3d11_swapchain() });
sg_apply_pipeline(pip);
sg_apply_bindings(&bind);
sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(vs_params));
sg_apply_uniforms(0, &SG_RANGE(vs_params));
sg_draw(0, 36, 1);
sg_end_pass();
sg_commit();
Expand Down
18 changes: 9 additions & 9 deletions d3d11/binshader-d3d11.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,17 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _

// create shader
sg_shader shd = sg_make_shader(&(sg_shader_desc){
.vertex_func.bytecode = SG_RANGE(vs_bin),
.fragment_func.bytecode = SG_RANGE(fs_bin),
.attrs = {
[0].sem_name = "POSITION",
[1].sem_name = "COLOR"
[0].hlsl_sem_name = "POSITION",
[1].hlsl_sem_name = "COLOR"
},
.vs = {
.uniform_blocks[0].size = sizeof(vs_params_t),
.bytecode = SG_RANGE(vs_bin)
.uniform_blocks[0] = {
.stage = SG_SHADERSTAGE_VERTEX,
.size = sizeof(vs_params_t),
.hlsl_register_b_n = 0,
},
.fs = {
.bytecode = SG_RANGE(fs_bin)
}
});

// a pipeline object
Expand Down Expand Up @@ -139,7 +139,7 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _
sg_begin_pass(&(sg_pass){ .action = pass_action, .swapchain = d3d11_swapchain() });
sg_apply_pipeline(pip);
sg_apply_bindings(&bind);
sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(vs_params));
sg_apply_uniforms(0, &SG_RANGE(vs_params));
sg_draw(0, 36, 1);
sg_end_pass();
sg_commit();
Expand Down
54 changes: 30 additions & 24 deletions d3d11/blend-d3d11.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _

// a shader for the fullscreen background quad
sg_shader bg_shd = sg_make_shader(&(sg_shader_desc){
.attrs[0].sem_name = "POS",
.vs.source =
.vertex_func.source =
"struct vs_in {\n"
" float2 pos: POS;\n"
"};\n"
Expand All @@ -61,18 +60,21 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _
" outp.pos = float4(inp.pos, 0.5, 1.0);\n"
" return outp;\n"
"};\n",
.fs = {
.uniform_blocks[0].size = sizeof(fs_params_t),
.source =
"cbuffer params: register(b0) {\n"
" float tick;\n"
"};\n"
"float4 main(float4 frag_coord: SV_Position): SV_Target0 {\n"
" float2 xy = frac((frag_coord.xy-float2(tick,tick)) / 50.0);\n"
" float c = xy.x * xy.y;\n"
" return float4(c, c, c, 1.0);\n"
"};\n"
}
.fragment_func.source =
"cbuffer params: register(b0) {\n"
" float tick;\n"
"};\n"
"float4 main(float4 frag_coord: SV_Position): SV_Target0 {\n"
" float2 xy = frac((frag_coord.xy-float2(tick,tick)) / 50.0);\n"
" float c = xy.x * xy.y;\n"
" return float4(c, c, c, 1.0);\n"
"};\n",
.attrs[0].hlsl_sem_name = "POS",
.uniform_blocks[0] = {
.stage = SG_SHADERSTAGE_FRAGMENT,
.size = sizeof(fs_params_t),
.hlsl_register_b_n = 0,
},
});

// a pipeline state object for rendering the background quad
Expand All @@ -87,12 +89,7 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _

// a shader for the blended quads
sg_shader quad_shd = sg_make_shader(&(sg_shader_desc){
.attrs = {
[0].sem_name = "POS",
[1].sem_name = "COLOR"
},
.vs.uniform_blocks[0].size = sizeof(vs_params_t),
.vs.source =
.vertex_func.source =
"cbuffer params: register(b0) {\n"
" float4x4 mvp;\n"
"};\n"
Expand All @@ -110,10 +107,19 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _
" outp.color = inp.color;\n"
" return outp;\n"
"}\n",
.fs.source =
.fragment_func.source =
"float4 main(float4 color: COLOR): SV_Target0 {\n"
" return color;\n"
"}\n"
"}\n",
.attrs = {
[0].hlsl_sem_name = "POS",
[1].hlsl_sem_name = "COLOR"
},
.uniform_blocks[0] = {
.stage = SG_SHADERSTAGE_VERTEX,
.size = sizeof(vs_params_t),
.hlsl_register_b_n = 0,
},
});

// one pipeline object per blend-factor combination
Expand Down Expand Up @@ -169,7 +175,7 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _
// draw a background quad
sg_apply_pipeline(bg_pip);
sg_apply_bindings(&bind);
sg_apply_uniforms(SG_SHADERSTAGE_FS, 0, &SG_RANGE(fs_params));
sg_apply_uniforms(0, &SG_RANGE(fs_params));
sg_draw(0, 4, 1);

// draw the blended quads
Expand All @@ -185,7 +191,7 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _

sg_apply_pipeline(pips[src][dst]);
sg_apply_bindings(&bind);
sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(vs_params));
sg_apply_uniforms(0, &SG_RANGE(vs_params));
sg_draw(0, 4, 1);
}
}
Expand Down
14 changes: 7 additions & 7 deletions d3d11/bufferoffsets-d3d11.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,7 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _

// a shader to render the 2D shapes
sg_shader shd = sg_make_shader(&(sg_shader_desc){
.attrs = {
[0].sem_name = "POSITION",
[1].sem_name = "COLOR"
},
.vs.source =
.vertex_func.source =
"struct vs_in {\n"
" float2 pos: POSITION;\n"
" float3 color: COLOR0;\n"
Expand All @@ -70,10 +66,14 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _
" outp.color = float4(inp.color, 1.0);\n"
" return outp;\n"
"}\n",
.fs.source =
.fragment_func.source =
"float4 main(float4 color: COLOR0): SV_Target0 {\n"
" return color;\n"
"}\n"
"}\n",
.attrs = {
[0].hlsl_sem_name = "POSITION",
[1].hlsl_sem_name = "COLOR"
},
});

// a pipeline state object, default states are fine
Expand Down
56 changes: 29 additions & 27 deletions d3d11/cube-d3d11.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,35 +86,37 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _

// create shader
sg_shader shd = sg_make_shader(&(sg_shader_desc){
.vertex_func.source =
"cbuffer params: register(b0) {\n"
" float4x4 mvp;\n"
"};\n"
"struct vs_in {\n"
" float4 pos: POSITION;\n"
" float4 color: COLOR1;\n"
"};\n"
"struct vs_out {\n"
" float4 color: COLOR0;\n"
" float4 pos: SV_Position;\n"
"};\n"
"vs_out main(vs_in inp) {\n"
" vs_out outp;\n"
" outp.pos = mul(mvp, inp.pos);\n"
" outp.color = inp.color;\n"
" return outp;\n"
"};\n",
.fragment_func.source =
"float4 main(float4 color: COLOR0): SV_Target0 {\n"
" return color;\n"
"}\n",
.attrs = {
[0] = { .sem_name = "POSITION" },
[1] = { .sem_name = "COLOR", .sem_index=1 }
[0] = { .hlsl_sem_name = "POSITION" },
[1] = { .hlsl_sem_name = "COLOR", .hlsl_sem_index = 1 },
},
.vs = {
.uniform_blocks[0].size = sizeof(vs_params_t),
.source =
"cbuffer params: register(b0) {\n"
" float4x4 mvp;\n"
"};\n"
"struct vs_in {\n"
" float4 pos: POSITION;\n"
" float4 color: COLOR1;\n"
"};\n"
"struct vs_out {\n"
" float4 color: COLOR0;\n"
" float4 pos: SV_Position;\n"
"};\n"
"vs_out main(vs_in inp) {\n"
" vs_out outp;\n"
" outp.pos = mul(mvp, inp.pos);\n"
" outp.color = inp.color;\n"
" return outp;\n"
"};\n",
.uniform_blocks[0] = {
.stage = SG_SHADERSTAGE_VERTEX,
.size = sizeof(vs_params_t),
.hlsl_register_b_n = 0,
},
.fs.source =
"float4 main(float4 color: COLOR0): SV_Target0 {\n"
" return color;\n"
"}\n"
});

// a pipeline object
Expand Down Expand Up @@ -157,7 +159,7 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _
sg_begin_pass(&(sg_pass){ .action = pass_action, .swapchain = d3d11_swapchain() });
sg_apply_pipeline(pip);
sg_apply_bindings(&bind);
sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &SG_RANGE(vs_params));
sg_apply_uniforms(0, &SG_RANGE(vs_params));
sg_draw(0, 36, 1);
sg_end_pass();
sg_commit();
Expand Down
Loading