diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e047be3..b4394cf 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -17,7 +17,7 @@ jobs: - uses: dlang-community/setup-dlang@v1 with: compiler: ldc-master - + - name: prepare-linux if: runner.os == 'Linux' run: | @@ -30,11 +30,11 @@ jobs: dub build :clear dub build :sgl_context dub build :sgl_points - dub build :debugtext_print - # dub build :cube - # dub build :blend + dub build :debugtext + dub build :cube + dub build :blend dub build :triangle - # dub build :mrt + dub build :mrt dub build :user_data - name: (Zig) Running Test diff --git a/README.md b/README.md index 0886feb..3c64ba9 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ zig build -Doptimize=ReleaseFast -Dshared zig build run-blend -Doptimize=ReleaseFast zig build run-clear -Doptimize=ReleaseFast zig build run-cube -Doptimize=ReleaseFast -zig build run-debugtext_print -Doptimize=ReleaseFast +zig build run-debugtext -Doptimize=ReleaseFast zig build run-mrt -Doptimize=ReleaseFast zig build run-saudio -Doptimize=ReleaseFast zig build run-sgl_context -Doptimize=ReleaseFast diff --git a/build.zig b/build.zig index 45e4a61..3fbeee1 100644 --- a/build.zig +++ b/build.zig @@ -86,7 +86,7 @@ pub fn buildLibSokol(b: *Build, options: LibSokolOptions) !*CompileStep { const backend_cflags = switch (backend) { .d3d11 => "-DSOKOL_D3D11", .metal => "-DSOKOL_METAL", - .gl => "-DSOKOL_GLCORE33", + .gl => "-DSOKOL_GLCORE", .gles3 => "-DSOKOL_GLES3", .wgpu => "-DSOKOL_WGPU", else => @panic("unknown sokol backend"), @@ -218,7 +218,7 @@ pub fn build(b: *Build) !void { "saudio", "sgl_context", "sgl_points", - "debugtext_print", + "debugtext", "user_data", // Need GC for user data [associative array] }; @@ -360,10 +360,6 @@ pub fn ldcBuildStep(b: *Build, options: DCompileStep) !*RunStep { // name object files uniquely (so the files don't collide) try cmds.append("-oq"); - // remove object files after success build, and put them in a unique temp directory - if (options.kind != .obj) - try cmds.append("-cleanup-obj"); - // disable LLVM-IR verifier // https://llvm.org/docs/Passes.html#verify-module-verifier try cmds.append("-disable-verify"); @@ -630,6 +626,7 @@ fn buildShaders(b: *Build) void { const sokol_tools_bin_dir = "../sokol-tools-bin/bin/"; const shaders_dir = "src/shaders/"; const shaders = .{ + "triangle.glsl", "bufferoffsets.glsl", "cube.glsl", "instancing.glsl", @@ -661,7 +658,7 @@ fn buildShaders(b: *Build) void { "-o", shaders_dir ++ shader[0 .. shader.len - 5] ++ ".d", "-l", - "glsl330:metal_macos:hlsl4:glsl300es:wgsl", + "glsl430:metal_macos:hlsl4:glsl300es:wgsl", "-f", "sokol_d", }); diff --git a/dub.sdl b/dub.sdl index edcc0bf..66cb6a2 100644 --- a/dub.sdl +++ b/dub.sdl @@ -34,9 +34,10 @@ subPackage { targetPath "build" sourceFiles "src/examples/clear.d" libs "sokol" + dflags "-preview=all" "-i" lflags "-Lzig-out/lib" platform="posix" lflags "/LIBPATH:zig-out/lib" platform="windows" - excludedSourceFiles "src/examples/sgl_context.d" "src/examples/triangle.d" "src/examples/sgl_points.d" "src/examples/saudio.d" "src/examples/debugtext_print.d" "src/examples/mrt.d" "src/examples/user_data.d" "src/examples/cube.d" "src/examples/blend.d" "src/shaders/*.d" + excludedSourceFiles "src/examples/sgl_context.d" "src/examples/triangle.d" "src/examples/sgl_points.d" "src/examples/saudio.d" "src/examples/debugtext.d" "src/examples/mrt.d" "src/examples/user_data.d" "src/examples/cube.d" "src/examples/blend.d" "src/shaders/*.d" preBuildCommands "zig build -Dshared -Doptimize=ReleaseFast" } subPackage { @@ -45,9 +46,10 @@ subPackage { targetPath "build" sourceFiles "src/examples/sgl_context.d" libs "sokol" + dflags "-preview=all" "-i" lflags "-Lzig-out/lib" platform="posix" lflags "/LIBPATH:zig-out/lib" platform="windows" - excludedSourceFiles "src/examples/clear.d" "src/examples/triangle.d" "src/examples/sgl_points.d" "src/examples/saudio.d" "src/examples/debugtext_print.d" "src/examples/mrt.d" "src/examples/user_data.d" "src/examples/cube.d" "src/examples/blend.d" "src/shaders/*.d" + excludedSourceFiles "src/examples/clear.d" "src/examples/triangle.d" "src/examples/sgl_points.d" "src/examples/saudio.d" "src/examples/debugtext.d" "src/examples/mrt.d" "src/examples/user_data.d" "src/examples/cube.d" "src/examples/blend.d" "src/shaders/*.d" preBuildCommands "zig build -Dshared -Doptimize=ReleaseFast" } subPackage { @@ -56,17 +58,19 @@ subPackage { targetPath "build" sourceFiles "src/examples/sgl_points.d" libs "sokol" + dflags "-preview=all" "-i" lflags "-Lzig-out/lib" platform="posix" lflags "/LIBPATH:zig-out/lib" platform="windows" - excludedSourceFiles "src/examples/clear.d" "src/examples/triangle.d" "src/examples/sgl_context.d" "src/examples/saudio.d" "src/examples/debugtext_print.d" "src/examples/mrt.d" "src/examples/user_data.d" "src/examples/cube.d" "src/examples/blend.d" "src/shaders/*.d" + excludedSourceFiles "src/examples/clear.d" "src/examples/triangle.d" "src/examples/sgl_context.d" "src/examples/saudio.d" "src/examples/debugtext.d" "src/examples/mrt.d" "src/examples/user_data.d" "src/examples/cube.d" "src/examples/blend.d" "src/shaders/*.d" preBuildCommands "zig build -Dshared -Doptimize=ReleaseFast" } subPackage { - name "debugtext_print" + name "debugtext" targetType "executable" targetPath "build" - sourceFiles "src/examples/debugtext_print.d" + sourceFiles "src/examples/debugtext.d" libs "sokol" + dflags "-preview=all" "-i" lflags "-Lzig-out/lib" platform="posix" lflags "/LIBPATH:zig-out/lib" platform="windows" excludedSourceFiles "src/examples/sgl_context.d" "src/examples/triangle.d" "src/examples/sgl_points.d" "src/examples/saudio.d" "src/examples/clear.d" "src/examples/mrt.d" "src/examples/user_data.d" "src/examples/cube.d" "src/examples/blend.d" "src/shaders/*.d" @@ -78,9 +82,10 @@ subPackage { targetPath "build" sourceFiles "src/examples/triangle.d" libs "sokol" + dflags "-preview=all" "-i" lflags "-Lzig-out/lib" platform="posix" lflags "/LIBPATH:zig-out/lib" platform="windows" - excludedSourceFiles "src/examples/sgl_context.d" "src/examples/clear.d" "src/examples/sgl_points.d" "src/examples/saudio.d" "src/examples/debugtext_print.d" "src/examples/mrt.d" "src/examples/user_data.d" "src/examples/cube.d" "src/examples/blend.d" "src/shaders/*.d" + excludedSourceFiles "src/examples/sgl_context.d" "src/examples/clear.d" "src/examples/sgl_points.d" "src/examples/saudio.d" "src/examples/debugtext.d" "src/examples/mrt.d" "src/examples/user_data.d" "src/examples/cube.d" "src/examples/blend.d" "src/shaders/*.d" preBuildCommands "zig build -Dshared -Doptimize=ReleaseFast" } subPackage { @@ -89,9 +94,10 @@ subPackage { targetPath "build" sourceFiles "src/examples/blend.d" libs "sokol" + dflags "-preview=all" "-i" lflags "-Lzig-out/lib" platform="posix" lflags "/LIBPATH:zig-out/lib" platform="windows" - excludedSourceFiles "src/examples/sgl_context.d" "src/examples/clear.d" "src/examples/saudio.d" "src/examples/debugtext_print.d" "src/examples/mrt.d" "src/examples/user_data.d" "src/examples/cube.d" "src/examples/triangle.d" "src/examples/sgl_points.d" "src/shaders/*.d" + excludedSourceFiles "src/examples/sgl_context.d" "src/examples/clear.d" "src/examples/saudio.d" "src/examples/debugtext.d" "src/examples/mrt.d" "src/examples/user_data.d" "src/examples/cube.d" "src/examples/triangle.d" "src/examples/sgl_points.d" "src/shaders/*.d" preBuildCommands "zig build -Dshared -Doptimize=ReleaseFast" } subPackage { @@ -100,9 +106,10 @@ subPackage { targetPath "build" sourceFiles "src/examples/saudio.d" libs "sokol" + dflags "-preview=all" "-i" lflags "-Lzig-out/lib" platform="posix" lflags "/LIBPATH:zig-out/lib" platform="windows" - excludedSourceFiles "src/examples/sgl_context.d" "src/examples/clear.d" "src/examples/triangle.d" "src/examples/sgl_points.d" "src/examples/debugtext_print.d" "src/examples/mrt.d" "src/examples/user_data.d" "src/examples/cube.d" "src/examples/blend.d" "src/shaders/*.d" + excludedSourceFiles "src/examples/sgl_context.d" "src/examples/clear.d" "src/examples/triangle.d" "src/examples/sgl_points.d" "src/examples/debugtext.d" "src/examples/mrt.d" "src/examples/user_data.d" "src/examples/cube.d" "src/examples/blend.d" "src/shaders/*.d" preBuildCommands "zig build -Dshared -Doptimize=ReleaseFast" } subPackage { @@ -111,9 +118,10 @@ subPackage { targetPath "build" sourceFiles "src/examples/mrt.d" libs "sokol" + dflags "-preview=all" "-i" lflags "-Lzig-out/lib" platform="posix" lflags "/LIBPATH:zig-out/lib" platform="windows" - excludedSourceFiles "src/examples/sgl_context.d" "src/examples/clear.d" "src/examples/saudio.d" "src/examples/debugtext_print.d" "src/examples/triangle.d" "src/examples/sgl_points.d" "src/examples/user_data.d" "src/examples/cube.d" "src/examples/blend.d" "src/shaders/*.d" + excludedSourceFiles "src/examples/sgl_context.d" "src/examples/clear.d" "src/examples/saudio.d" "src/examples/debugtext.d" "src/examples/triangle.d" "src/examples/sgl_points.d" "src/examples/user_data.d" "src/examples/cube.d" "src/examples/blend.d" "src/shaders/*.d" preBuildCommands "zig build -Dshared -Doptimize=ReleaseFast" } subPackage { @@ -122,9 +130,10 @@ subPackage { targetPath "build" sourceFiles "src/examples/cube.d" libs "sokol" + dflags "-preview=all" "-i" lflags "-Lzig-out/lib" platform="posix" lflags "/LIBPATH:zig-out/lib" platform="windows" - excludedSourceFiles "src/examples/sgl_context.d" "src/examples/clear.d" "src/examples/saudio.d" "src/examples/debugtext_print.d" "src/examples/triangle.d" "src/examples/sgl_points.d" "src/examples/user_data.d" "src/examples/mrt.d" "src/examples/blend.d" "src/shaders/*.d" + excludedSourceFiles "src/examples/sgl_context.d" "src/examples/clear.d" "src/examples/saudio.d" "src/examples/debugtext.d" "src/examples/triangle.d" "src/examples/sgl_points.d" "src/examples/user_data.d" "src/examples/mrt.d" "src/examples/blend.d" "src/shaders/*.d" preBuildCommands "zig build -Dshared -Doptimize=ReleaseFast" } subPackage { @@ -133,8 +142,9 @@ subPackage { targetPath "build" sourceFiles "src/examples/user_data.d" libs "sokol" + dflags "-preview=all" "-i" lflags "-Lzig-out/lib" platform="posix" lflags "/LIBPATH:zig-out/lib" platform="windows" - excludedSourceFiles "src/examples/sgl_context.d" "src/examples/clear.d" "src/examples/saudio.d" "src/examples/debugtext_print.d" "src/examples/triangle.d" "src/examples/sgl_points.d" "src/examples/cube.d" "src/examples/mrt.d" "src/examples/blend.d" "src/shaders/*.d" + excludedSourceFiles "src/examples/sgl_context.d" "src/examples/clear.d" "src/examples/saudio.d" "src/examples/debugtext.d" "src/examples/triangle.d" "src/examples/sgl_points.d" "src/examples/cube.d" "src/examples/mrt.d" "src/examples/blend.d" "src/shaders/*.d" preBuildCommands "zig build -Dshared -Doptimize=ReleaseFast" } diff --git a/src/examples/blend.d b/src/examples/blend.d index ebb0f99..99bda5f 100644 --- a/src/examples/blend.d +++ b/src/examples/blend.d @@ -10,7 +10,6 @@ import app = sokol.app; import log = sokol.log; import handmade.math : Mat4, Vec3; import sglue = sokol.glue; -import sgutil = sokol.utils : asRange; import shd = shaders.blend; extern (C): @@ -18,60 +17,68 @@ extern (C): immutable NUM_BLEND_FACTORS = 15; -struct State -{ +struct State { float r = 0.0f; sg.Pipeline bg_pip; sg.Pipeline[NUM_BLEND_FACTORS][NUM_BLEND_FACTORS] pips; sg.Bindings bind; sg.PassAction passAction = { - colors: [ - {load_action: sg.LoadAction.Dontcare} - ], - depth: {load_action: sg.LoadAction.Dontcare}, - stencil: {load_action: sg.LoadAction.Dontcare} + colors: [ { load_action: sg.LoadAction.Dontcare } ], + depth: { load_action: sg.LoadAction.Dontcare }, + stencil: { load_action: sg.LoadAction.Dontcare } }; shd.QuadVsParams quad_vs_params; shd.BgFsParams bg_fs_params; } - static State state; -void init() @trusted -{ +void init() { sg.Desc gfx = { pipeline_pool_size: NUM_BLEND_FACTORS * NUM_BLEND_FACTORS + 1, environment: sglue.environment, - logger: {func: &log.func} + logger: { func: &log.func } }; sg.setup(gfx); float[28] vertices = [ // pos color - -1.0, -1.0, 0.0, 1.0, 0.0, 0.0, 0.5, - 1.0, -1.0, 0.0, 0.0, 1.0, 0.0, 0.5, - -1.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.5, - 1.0, 1.0, 0.0, 1.0, 1.0, 0.0, 0.5, + -1.0, -1.0, 0.0, 1.0, 0.0, 0.0, 0.5, + 1.0, -1.0, 0.0, 0.0, 1.0, 0.0, 0.5, + -1.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.5, + 1.0, 1.0, 0.0, 1.0, 1.0, 0.0, 0.5, ]; - // Create vertex buffer - sg.BufferDesc vbuffer = {data: sgutil.asRange(&vertices[0])}; - state.bind.vertex_buffers[0] = sg.makeBuffer(vbuffer); + // create vertex buffer + sg.BufferDesc vbufd = { + data: { + ptr: vertices.ptr, + size: vertices.sizeof, + } + }; + state.bind.vertex_buffers[0] = sg.makeBuffer(vbufd); - sg.ShaderDesc bgShader = shd.bg_shader_desc(sg.queryBackend()); sg.PipelineDesc pld = { - layout: {buffers: [{stride: 28}]}, + shader: sg.makeShader(shd.bgShaderDesc(sg.queryBackend())), + layout: { + buffers: [ { stride: 28 } ], + attrs: [ + shd.ATTR_VS_BG_POSITION: { format: sg.VertexFormat.Float2 }, + ], + }, primitive_type: sg.PrimitiveType.Triangle_strip }; - pld.shader = sg.makeShader(bgShader); - pld.layout.attrs[shd.ATTR_VS_BG_POSITION].format = sg.VertexFormat.Float2; state.bg_pip = sg.makePipeline(pld); - sg.ShaderDesc quadShader = shd.quad_shader_desc(sg.queryBackend()); sg.PipelineDesc pip_desc = { - layout: {buffers: [{stride: 28}]}, + shader: sg.makeShader(shd.quadShaderDesc(sg.queryBackend())), + layout: { + attrs: [ + shd.ATTR_VS_QUAD_POSITION: { format: sg.VertexFormat.Float3 }, + shd.ATTR_VS_QUAD_COLOR0: { format: sg.VertexFormat.Float4 }, + ], + }, primitive_type: sg.PrimitiveType.Triangle_strip, - blend_color: {r: 1.0, g: 0.0, b: 0.0, a: 1.0}, + blend_color: { r: 1.0, g: 0.0, b: 0.0, a: 1.0 }, colors: [ { blend: { @@ -82,13 +89,8 @@ void init() @trusted } ] }; - pip_desc.shader = sg.makeShader(quadShader); - pip_desc.layout.attrs[shd.ATTR_VS_QUAD_POSITION].format = sg.VertexFormat.Float3; - pip_desc.layout.attrs[shd.ATTR_VS_QUAD_COLOR0].format = sg.VertexFormat.Float4; - foreach (src; 0 .. NUM_BLEND_FACTORS) - { - foreach (dst; 0 .. NUM_BLEND_FACTORS) - { + foreach (src; 0 .. NUM_BLEND_FACTORS) { + foreach (dst; 0 .. NUM_BLEND_FACTORS) { pip_desc.colors[0].blend.src_factor_rgb = cast(sg.BlendFactor)(src + 1); pip_desc.colors[0].blend.dst_factor_rgb = cast(sg.BlendFactor)(dst + 1); state.pips[src][dst] = sg.makePipeline(pip_desc); @@ -96,8 +98,7 @@ void init() @trusted } } -void frame() -{ +void frame() { immutable float t = cast(float)(app.frameDuration() * 60.0); state.r += 0.6 * t; @@ -108,10 +109,12 @@ void frame() immutable view = Mat4.lookAt(Vec3(0.0, 0.0, 25.0), Vec3.zero(), Vec3.up()); immutable view_proj = Mat4.mul(proj, view); - sg.Pass pass = {action: state.passAction, swapchain: sglue.swapchain}; + sg.Pass pass = { action: state.passAction, swapchain: sglue.swapchain() }; sg.beginPass(pass); - - sg.Range r = sgutil.asRange(state.bg_fs_params); + sg.Range r = { + ptr: &state.bg_fs_params, + size: state.bg_fs_params.sizeof, + }; sg.applyPipeline(state.bg_pip); sg.applyBindings(state.bind); sg.applyUniforms(sg.ShaderStage.Fs, shd.SLOT_BG_FS_PARAMS, r); @@ -119,25 +122,21 @@ void frame() // draw the blended quads float r0 = state.r; - foreach (src; 0 .. NUM_BLEND_FACTORS) - { - foreach (dst; 0 .. NUM_BLEND_FACTORS) - { + foreach (src; 0 .. NUM_BLEND_FACTORS) { + foreach (dst; 0 .. NUM_BLEND_FACTORS) { // compute model-view-proj matrix auto rm = Mat4.rotate(state.r, Vec3(0.0, 1.0, 0.0)); immutable x = (dst - (NUM_BLEND_FACTORS / 2)) * 3.0; immutable y = (src - (NUM_BLEND_FACTORS / 2)) * 2.2; immutable model = Mat4.mul(Mat4.translate(Vec3(x, y, 0.0)), rm); state.quad_vs_params.mvp = Mat4.mul(view_proj, model); - sg.Range rg = sgutil.asRange(state.quad_vs_params); - + sg.Range rg = { + ptr: &state.quad_vs_params, + size: state.quad_vs_params.sizeof, + }; sg.applyPipeline(state.pips[src][dst]); sg.applyBindings(state.bind); - sg.applyUniforms( - sg.ShaderStage.Vs, - shd.SLOT_QUAD_VS_PARAMS, - rg, - ); + sg.applyUniforms(sg.ShaderStage.Vs, shd.SLOT_QUAD_VS_PARAMS, rg); sg.draw(0, 4, 1); r0 += 0.6; } @@ -146,13 +145,11 @@ void frame() sg.commit(); } -void cleanup() -{ +void cleanup() { sg.shutdown(); } -void main() -{ +void main() { app.Desc runner = { window_title: "blend.d", init_cb: &init, diff --git a/src/examples/clear.d b/src/examples/clear.d index b32907a..0a9daf0 100644 --- a/src/examples/clear.d +++ b/src/examples/clear.d @@ -11,39 +11,29 @@ import sapp = sokol.app; import log = sokol.log; extern (C): +@safe: -__gshared sg.PassAction pass_action; +sg.PassAction pass_action = { + colors: [ + { load_action: sg.LoadAction.Clear, clear_value: { r: 1, g: 1, b: 0, a: 1 } } + ] +}; -void init() -{ +static void init() { sg.Desc gfx = { - environment: sglue.environment, - logger: {func: &log.slog_func} + environment: sglue.environment(), + logger: { func: &log.slog_func }, }; sg.setup(gfx); - - pass_action.colors[0].load_action = sg.LoadAction.Clear; - pass_action.colors[0].clear_value.r = 1; - pass_action.colors[0].clear_value.g = 1; - pass_action.colors[0].clear_value.b = 0; - pass_action.colors[0].clear_value.a = 1; - - debug - { + debug { import std.stdio : writeln; - - try - { + try { writeln("Backend: ", sg.queryBackend()); - } - catch (Exception) - { - } + } catch (Exception) {} } } -void frame() -{ +static void frame() { const g = pass_action.colors[0].clear_value.g + 0.01; pass_action.colors[0].clear_value.g = g > 1.0 ? 0.0 : g; sg.Pass pass = {action: pass_action, swapchain: sglue.swapchain}; @@ -52,13 +42,11 @@ void frame() sg.commit(); } -void cleanup() -{ +static void cleanup() { sg.shutdown(); } -void main() -{ +void main() { sapp.Desc runner = { window_title: "clear.d", init_cb: &init, @@ -67,7 +55,7 @@ void main() width: 640, height: 480, win32_console_attach: true, - icon: {sokol_default: true}, + icon: { sokol_default: true }, logger: {func: &log.func} }; sapp.run(runner); diff --git a/src/examples/cube.d b/src/examples/cube.d index 680778e..5af68fd 100644 --- a/src/examples/cube.d +++ b/src/examples/cube.d @@ -11,41 +11,38 @@ import log = sokol.log; import handmade.math : Mat4, Vec3; import sglue = sokol.glue; import shd = shaders.cube; -import sgutil = sokol.utils : asRange; extern (C): @safe: -struct State -{ - float rx; - float ry; +struct State { + float rx = 0; + float ry = 0; sg.Pipeline pip; sg.Bindings bind; sg.PassAction passAction = { colors: [ { - load_action: sg.LoadAction.Clear, clear_value: { - r: 0.25, g: 0.5, b: 0.75, a: 1.0 - } + load_action: sg.LoadAction.Clear, + clear_value: { r: 0.25, g: 0.5, b: 0.75, a: 1.0 } } ] }; - Mat4 view() - { + Mat4 view() { return Mat4.lookAt(Vec3(0.0, 1.5, 6.0), Vec3.zero(), Vec3.up()); } } static State state; -void init() @trusted -{ - sg.Desc gfx = {environment: sglue.environment, - logger: {func: &log.func}}; - sg.setup(gfx); +void init() { + sg.Desc gfxd = { + environment: sglue.environment, + logger: { func: &log.func } + }; + sg.setup(gfxd); float[168] vertices = [ -1.0, -1.0, -1.0, 1.0, 0.0, 0.0, 1.0, @@ -78,12 +75,12 @@ void init() @trusted 1.0, 1.0, 1.0, 1.0, 0.0, 0.5, 1.0, 1.0, 1.0, -1.0, 1.0, 0.0, 0.5, 1.0 ]; + sg.BufferDesc vbufd = { + data: { ptr: vertices.ptr, size: vertices.sizeof }, + }; + state.bind.vertex_buffers[0] = sg.makeBuffer(vbufd); - // Create vertex buffer - sg.BufferDesc vbuffer = {data: sgutil.asRange(&vertices[0])}; - state.bind.vertex_buffers[0] = sg.makeBuffer(vbuffer); - - double[36] indices = [ + ushort[36] indices = [ 0, 1, 2, 0, 2, 3, 6, 5, 4, 7, 6, 4, 8, 9, 10, 8, 10, 11, @@ -91,65 +88,63 @@ void init() @trusted 16, 17, 18, 16, 18, 19, 22, 21, 20, 23, 22, 20, ]; - - sg.BufferDesc ibuffer = { + sg.BufferDesc ibufd = { type: sg.BufferType.Indexbuffer, - data: sgutil.asRange(&indices[0]) + data: { ptr: indices.ptr, size: indices.sizeof }, }; - state.bind.index_buffer = sg.makeBuffer(ibuffer); + state.bind.index_buffer = sg.makeBuffer(ibufd); - sg.ShaderDesc cubeShader = shd.cube_shader_desc(sg.queryBackend()); sg.PipelineDesc pld = { + layout: { + attrs: [ + shd.ATTR_VS_POSITION: { format: sg.VertexFormat.Float3 }, + shd.ATTR_VS_COLOR0: { format: sg.VertexFormat.Float4 }, + ], + }, + shader: sg.makeShader(shd.cubeShaderDesc(sg.queryBackend())), index_type: sg.IndexType.Uint16, cull_mode: sg.CullMode.Back, - depth: {write_enabled: true, compare: sg.CompareFunc.Less_equal}, - layout: {buffers: [{stride: 28}]} + depth: { + write_enabled: true, + compare: sg.CompareFunc.Less_equal + }, }; - pld.shader = sg.makeShader(cubeShader); - pld.layout.attrs[shd.ATTR_VS_POSITION].format = sg.VertexFormat.Float3; - pld.layout.attrs[shd.ATTR_VS_COLOR0].format = sg.VertexFormat.Float4; state.pip = sg.makePipeline(pld); } -void frame() -{ +void frame() { immutable float t = cast(float)(app.frameDuration() * 60.0); state.rx += 1.0 * t; state.ry += 2.0 * t; - shd.VsParams vsParams = {mvp: computeVsParams(state.rx, state.ry)}; + shd.VsParams vsParams = { mvp: computeMvp(state.rx, state.ry) }; - sg.Pass pass = {action: state.passAction, swapchain: sglue.swapchain}; + sg.Pass pass = { action: state.passAction, swapchain: sglue.swapchain() }; sg.beginPass(pass); - - sg.Range r = sgutil.asRange(vsParams); sg.applyPipeline(state.pip); sg.applyBindings(state.bind); + sg.Range r = { ptr: &vsParams, size: vsParams.sizeof }; sg.applyUniforms(sg.ShaderStage.Vs, shd.SLOT_VS_PARAMS, r); sg.draw(0, 36, 1); sg.endPass(); sg.commit(); } -void cleanup() -{ +void cleanup() { sg.shutdown(); } -Mat4 computeVsParams(float rx, float ry) -{ +Mat4 computeMvp(float rx, float ry) { immutable proj = Mat4.perspective(60.0, app.widthf() / app.heightf(), 0.01, 10.0); immutable rxm = Mat4.rotate(rx, Vec3(1.0, 0.0, 0.0)); immutable rym = Mat4.rotate(ry, Vec3(0.0, 1.0, 0.0)); immutable model = Mat4.mul(rxm, rym); immutable view_proj = Mat4.mul(proj, state.view()); - return Mat4.mul(view_proj, model); } -void main() -{ +void main() { app.Desc runner = { window_title: "cube.d", init_cb: &init, @@ -158,8 +153,8 @@ void main() width: 800, height: 600, sample_count: 4, - icon: {sokol_default: true}, - logger: {func: &log.func} + icon: { sokol_default: true }, + logger: { func: &log.func } }; app.run(runner); } diff --git a/src/examples/debugtext_print.d b/src/examples/debugtext.d similarity index 74% rename from src/examples/debugtext_print.d rename to src/examples/debugtext.d index e939c27..63e46a6 100644 --- a/src/examples/debugtext_print.d +++ b/src/examples/debugtext.d @@ -1,9 +1,9 @@ //------------------------------------------------------------------------------ -// debugtext_print.d +// debugtext.d // -// Demonstrates formatted printing with sokol.debugtext +// Test sokol_debugtext.h //------------------------------------------------------------------------------ -module examples.debugtext_print; +module examples.debugtext; import sg = sokol.gfx; import sglue = sokol.glue; @@ -23,28 +23,27 @@ immutable FONT_CPC = 3; immutable FONT_C64 = 4; immutable FONT_ORIC = 5; -struct State -{ +struct State { // background color sg.PassAction passAction = { colors: [ { - load_action: sg.LoadAction.Clear, clear_value: { - r: 0.0, g: 0.125, b: 0.25, a: 1.0 - } + load_action: sg.LoadAction.Clear, + clear_value: { r: 0.0, g: 0.125, b: 0.25, a: 1.0 } } ] }; } +static State state; -void init() -{ - sg.Desc gfx = {environment: sglue.environment, - logger: {func: &log.func}}; +void init() { + sg.Desc gfx = { + environment: sglue.environment(), + logger: { func: &log.func } + }; sg.setup(gfx); sdtx.Desc desc = { - logger: {func: &log.func}, fonts: [ sdtx.fontKc853(), sdtx.fontKc854(), @@ -52,31 +51,26 @@ void init() sdtx.fontCpc(), sdtx.fontC64(), sdtx.fontOric() - ] + ], + logger: { func: &log.func }, }; sdtx.setup(desc); } -void print_font(uint font_index, string title, ubyte r, ubyte g, ubyte b) -{ +void print_font(uint font_index, string title, ubyte r, ubyte g, ubyte b) { sdtx.font(font_index); sdtx.color3b(r, g, b); sdtx.puts(&title[0]); - - foreach (c; 32 .. 255) - { + foreach (c; 32 .. 255) { sdtx.putc(cast(char) c); - if (((c + 1) & 63) == 0) - { + if (((c + 1) & 63) == 0) { sdtx.crlf(); } } sdtx.crlf(); } -void frame() -{ - State state; +void frame() { sdtx.canvas(sapp.widthf() * 0.5, sapp.heightf() * 0.5); sdtx.origin(0.0, 2.0); sdtx.home(); @@ -88,23 +82,21 @@ void frame() print_font(FONT_C64, "C64:\n", 0x79, 0x86, 0xcb); print_font(FONT_ORIC, "Oric Atmos:\n", 0xff, 0x98, 0x00); - sg.Pass pass = {action: state.passAction, swapchain: sglue.swapchain}; + sg.Pass pass = { action: state.passAction, swapchain: sglue.swapchain() }; sg.beginPass(pass); sdtx.draw(); sg.endPass(); sg.commit(); } -void cleanup() -{ +void cleanup() { sdtx.shutdown(); sg.shutdown(); } -void main() -{ +void main() { sapp.Desc runner = { - window_title: "debugtext-print.d", + window_title: "debugtext.d", init_cb: &init, frame_cb: &frame, cleanup_cb: &cleanup, diff --git a/src/examples/mrt.d b/src/examples/mrt.d index a5a4039..96077ea 100644 --- a/src/examples/mrt.d +++ b/src/examples/mrt.d @@ -17,87 +17,68 @@ import log = sokol.log; import handmade.math : Mat4, Vec3, Vec2, sin, cos; import sglue = sokol.glue; import shd = shaders.mrt; -import sgutil = sokol.utils : asRange; extern (C): @safe: enum OFFSCREEN_SAMPLE_COUNT = 1; -struct Offscreen -{ - sg.PassAction pass_action; +struct Offscreen { sg.AttachmentsDesc atts_desc; sg.Attachments atts; sg.Pipeline pip; sg.Bindings bind; + sg.PassAction pass_action = { + colors: [ + { load_action: sg.LoadAction.Clear, clear_value: { r: 0.25, g: 0, b: 0, a: 1} }, + { load_action: sg.LoadAction.Clear, clear_value: { r: 0, g: 0.25, b: 0, a: 1} }, + { load_action: sg.LoadAction.Clear, clear_value: { r: 0, g: 0, b: 0.25, a: 1} }, + ] + }; } -struct Fsq -{ +struct Fsq { sg.Pipeline pip; sg.Bindings bind; } -struct Dbg -{ +struct Dbg { sg.Pipeline pip; sg.Bindings bind; } -struct Dflt -{ - sg.PassAction pass_action; +struct Dflt { + sg.PassAction pass_action = { + colors: [ { load_action: sg.LoadAction.Dontcare } ], + depth: { load_action: sg.LoadAction.Dontcare }, + stencil: { load_action: sg.LoadAction.Dontcare }, + }; } -struct State -{ +struct State { Offscreen offscreen; Fsq fsq; Dbg dbg; Dflt dflt; - float rx; - float ry; + float rx = 0; + float ry = 0; Mat4 view; } static State state; -void init() @trusted -{ - sg.Desc gfx = {environment: sglue.environment, - logger: {func: &log.slog_func}}; - sg.setup(gfx); - - // setup pass action for default render pass - state.dflt.pass_action.colors[0].load_action = sg.LoadAction.Dontcare; - state.dflt.pass_action.depth.load_action = sg.LoadAction.Dontcare; - state.dflt.pass_action.stencil.load_action = sg.LoadAction.Dontcare; - - // set pass action for offscreen render pass - state.offscreen.pass_action.colors[0].load_action = sg.LoadAction.Clear, - state.offscreen.pass_action.colors[0].clear_value.r = 0.25; - state.offscreen.pass_action.colors[0].clear_value.g = 0.0; - state.offscreen.pass_action.colors[0].clear_value.b = 0.0; - state.offscreen.pass_action.colors[0].clear_value.a = 1.0; - - state.offscreen.pass_action.colors[1].load_action = sg.LoadAction.Clear; - state.offscreen.pass_action.colors[1].clear_value.r = 0.0; - state.offscreen.pass_action.colors[1].clear_value.g = 0.25; - state.offscreen.pass_action.colors[1].clear_value.b = 0.0; - state.offscreen.pass_action.colors[1].clear_value.a = 1.0; - - state.offscreen.pass_action.colors[2].load_action = sg.LoadAction.Clear; - state.offscreen.pass_action.colors[2].clear_value.r = 0.0; - state.offscreen.pass_action.colors[2].clear_value.g = 0.0; - state.offscreen.pass_action.colors[2].clear_value.b = 0.25; - state.offscreen.pass_action.colors[2].clear_value.a = 1.0; +void init() { + sg.Desc gfxd = { + environment: sglue.environment, + logger: { func: &log.slog_func } }; + sg.setup(gfxd); // setup the offscreen render pass and render target images, // this will also be called when the window resizes createOffscreenAttachments(app.width(), app.height()); - float[96] VERTICES = [ + // create vertex buffer for a cube + float[96] vertices = [ // positions brightness -1.0, -1.0, -1.0, 1.0, 1.0, -1.0, -1.0, 1.0, @@ -129,12 +110,16 @@ void init() @trusted 1.0, 1.0, 1.0, 0.7, 1.0, 1.0, -1.0, 0.7, ]; + sg.BufferDesc cube_vbuf_desc = { + data: { + ptr: vertices.ptr, + size: vertices.sizeof, + }, + }; + const cube_vbuf = sg.makeBuffer(cube_vbuf_desc); - // create vertex buffer for a cube - sg.BufferDesc buf = {data: sgutil.asRange(&VERTICES[0])}; - auto cube_vbuf = sg.makeBuffer(buf); - - double[36] INDICES = [ + // index buffer for a cube + ushort[36] indices = [ 0, 1, 2, 0, 2, 3, 6, 5, 4, 7, 6, 4, 8, 9, 10, 8, 10, 11, @@ -142,22 +127,25 @@ void init() @trusted 16, 17, 18, 16, 18, 19, 22, 21, 20, 23, 22, 20, ]; - - // index buffer for a cube - sg.BufferDesc ibuf = { + sg.BufferDesc cube_ibuf_desc = { type: sg.BufferType.Indexbuffer, - data: sgutil.asRange(&INDICES[0]), + data: { ptr: indices.ptr, size: indices.sizeof }, }; - auto cube_ibuf = sg.makeBuffer(ibuf); + const cube_ibuf = sg.makeBuffer(cube_ibuf_desc); // resource bindings for offscreen rendering state.offscreen.bind.vertex_buffers[0] = cube_vbuf; state.offscreen.bind.index_buffer = cube_ibuf; // shader and pipeline state object for rendering cube into MRT render targets - auto sh = shd.offscreen_shader_desc(sg.queryBackend()); sg.PipelineDesc offscreen_pip_desc = { - shader: sg.makeShader(sh), + layout: { + attrs: [ + shd.ATTR_VS_OFFSCREEN_POS: { format: sg.VertexFormat.Float3 }, + shd.ATTR_VS_OFFSCREEN_BRIGHT0: { format: sg.VertexFormat.Float }, + ] + }, + shader: sg.makeShader(shd.offscreenShaderDesc(sg.queryBackend())), index_type: sg.IndexType.Uint16, cull_mode: sg.CullMode.Back, sample_count: OFFSCREEN_SAMPLE_COUNT, @@ -168,50 +156,55 @@ void init() @trusted }, color_count: 3, }; - offscreen_pip_desc.layout.attrs[shd.ATTR_VS_OFFSCREEN_POS].format = sg.VertexFormat.Float3; - offscreen_pip_desc.layout.attrs[shd.ATTR_VS_OFFSCREEN_BRIGHT0].format = sg.VertexFormat.Float; state.offscreen.pip = sg.makePipeline(offscreen_pip_desc); - float[8] QUAD_VERTICES = [0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0]; // a vertex buffer to render a fullscreen quad - sg.BufferDesc quad_buf = {data: sgutil.asRange(&QUAD_VERTICES[0])}; - const quad_vbuf = sg.makeBuffer(quad_buf); + float[8] quad_vertices = [0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0]; + sg.BufferDesc quad_vbuf_desc = { + data: { ptr: quad_vertices.ptr, size: quad_vertices.sizeof }, + }; + const quad_vbuf = sg.makeBuffer(quad_vbuf_desc); // shader and pipeline object to render a fullscreen quad which composes // the 3 offscreen render targets into the default framebuffer - auto shader2 = shd.fsq_shader_desc(sg.queryBackend()); sg.PipelineDesc fsq_pip_desc = { - shader: sg.makeShader(shader2), + layout: { + attrs: [ + shd.ATTR_VS_FSQ_POS: { format: sg.VertexFormat.Float2 }, + ] + }, + shader: sg.makeShader(shd.fsqShaderDesc(sg.queryBackend())), primitive_type: sg.PrimitiveType.Triangle_strip, }; - fsq_pip_desc.layout.attrs[shd.ATTR_VS_FSQ_POS].format = sg.VertexFormat.Float2; state.fsq.pip = sg.makePipeline(fsq_pip_desc); // a sampler to sample the offscreen render targets as texture - sg.SamplerDesc sampler = { + sg.SamplerDesc smp_desc = { min_filter: sg.Filter.Linear, mag_filter: sg.Filter.Linear, wrap_u: sg.Wrap.Clamp_to_edge, wrap_v: sg.Wrap.Clamp_to_edge, }; - sg.Sampler smp = sg.makeSampler(sampler); + const smp = sg.makeSampler(smp_desc); // resource bindings to render the fullscreen quad (composed from the // offscreen render target textures state.fsq.bind.vertex_buffers[0] = quad_vbuf; - foreach (i; [0, 1, 2]) - { + foreach (i; [0, 1, 2]) { state.fsq.bind.fs.images[i] = state.offscreen.atts_desc.colors[i].image; } state.fsq.bind.fs.samplers[0] = smp; // shader, pipeline and resource bindings to render debug visualization quads - auto dbg_shader = shd.dbg_shader_desc(sg.queryBackend()); sg.PipelineDesc dbg_pip_desc = { - shader: sg.makeShader(dbg_shader), + layout: { + attrs: [ + shd.ATTR_VS_DBG_POS: { format: sg.VertexFormat.Float2 }, + ] + }, + shader: sg.makeShader(shd.dbgShaderDesc(sg.queryBackend())), primitive_type: sg.PrimitiveType.Triangle_strip, }; - dbg_pip_desc.layout.attrs[shd.ATTR_VS_DBG_POS].format = sg.VertexFormat.Float2; state.dbg.pip = sg.makePipeline(dbg_pip_desc); // resource bindings to render the debug visualization @@ -220,44 +213,40 @@ void init() @trusted state.dbg.bind.fs.samplers[0] = smp; } -void frame() -{ +void frame() { immutable(float) dt = (app.frameDuration() * 60.0); state.rx += 1.0 * dt; state.ry += 2.0 * dt; // compute shader uniform data - shd.OffscreenParams offscreen_params = {mvp: compute_mvp(state.rx, state.ry)}; + shd.OffscreenParams offscreen_params = { + mvp: computeMvp(state.rx, state.ry), + }; shd.FsqParams fsq_params = { offset: Vec2(sin(state.rx * 0.01) * 0.1, cos(state.ry * 0.01) * 0.1), }; // render cube into MRT offscreen render targets - sg.Pass pass_atts = {action: state.offscreen.pass_action, attachments: state.offscreen.atts}; + sg.Pass pass_atts = { action: state.offscreen.pass_action, attachments: state.offscreen.atts }; sg.beginPass(pass_atts); sg.applyPipeline(state.offscreen.pip); sg.applyBindings(state.offscreen.bind); - auto offs_rg = sgutil.asRange(offscreen_params); - sg.applyUniforms( - sg.ShaderStage.Vs, - shd.SLOT_OFFSCREEN_PARAMS, - offs_rg, - ); + sg.Range offs_rg = { ptr: &offscreen_params, offscreen_params.sizeof }; + sg.applyUniforms(sg.ShaderStage.Vs, shd.SLOT_OFFSCREEN_PARAMS, offs_rg); sg.draw(0, 36, 1); sg.endPass(); // render fullscreen quad with the composed offscreen-render images, // 3 a small debug view quads at the bottom of the screen - sg.Pass pass_swap = {action: state.dflt.pass_action, swapchain: sglue.swapchain}; + sg.Pass pass_swap = { action: state.dflt.pass_action, swapchain: sglue.swapchain }; sg.beginPass(pass_swap); sg.applyPipeline(state.fsq.pip); sg.applyBindings(state.fsq.bind); - auto fsq_rg = sgutil.asRange(fsq_params); + sg.Range fsq_rg = { ptr: &fsq_params, size: fsq_params.sizeof }; sg.applyUniforms(sg.ShaderStage.Vs, shd.SLOT_FSQ_PARAMS, fsq_rg); sg.draw(0, 4, 1); sg.applyPipeline(state.dbg.pip); - foreach (i; [0, 1, 2]) - { + foreach (i; [0, 1, 2]) { sg.applyViewport(i * 100, 0, 100, 100, false); state.dbg.bind.fs.images[0] = state.offscreen.atts_desc.colors[i].image; sg.applyBindings(state.dbg.bind); @@ -267,21 +256,17 @@ void frame() sg.commit(); } -void event(const app.Event* ev) -{ - if (ev.type == app.EventType.Resized) - { +void event(const app.Event* ev) { + if (ev.type == app.EventType.Resized) { createOffscreenAttachments(ev.framebuffer_width, ev.framebuffer_height); } } -void cleanup() -{ +void cleanup() { sg.shutdown(); } -void main() -{ +void main() { app.Desc runner = { window_title: "mrt.d", init_cb: &init, @@ -297,12 +282,10 @@ void main() app.run(runner); } -void createOffscreenAttachments(int width, int height) -{ +void createOffscreenAttachments(int width, int height) { // destroy previous resources (can be called with invalid ids) sg.destroyAttachments(state.offscreen.atts); - foreach (att; state.offscreen.atts_desc.colors) - { + foreach (att; state.offscreen.atts_desc.colors) { sg.destroyImage(att.image); } sg.destroyImage(state.offscreen.atts_desc.depth_stencil.image); @@ -317,23 +300,19 @@ void createOffscreenAttachments(int width, int height) sg.ImageDesc depth_img_desc = color_img_desc; depth_img_desc.pixel_format = sg.PixelFormat.Depth; - foreach (i; [0, 1, 2]) - { + foreach (i; [0, 1, 2]) { state.offscreen.atts_desc.colors[i].image = sg.makeImage(color_img_desc); } state.offscreen.atts_desc.depth_stencil.image = sg.makeImage(depth_img_desc); state.offscreen.atts = sg.makeAttachments(state.offscreen.atts_desc); // update the fullscreen-quad texture bindings - foreach (i; [0, 1, 2]) - { + foreach (i; [0, 1, 2]) { state.fsq.bind.fs.images[i] = state.offscreen.atts_desc.colors[i].image; } - } -Mat4 compute_mvp(float rx, float ry) -{ +Mat4 computeMvp(float rx, float ry) { immutable proj = Mat4.perspective(60.0, app.widthf() / app.heightf(), 0.01, 10.0); immutable view = Mat4.lookAt(Vec3(0.0, 1.5, 6.0), Vec3.zero, Vec3.up); immutable rxm = Mat4.rotate(rx, Vec3(1.0, 0.0, 0.0)); diff --git a/src/examples/saudio.d b/src/examples/saudio.d index 08cf9e4..425206b 100644 --- a/src/examples/saudio.d +++ b/src/examples/saudio.d @@ -15,66 +15,53 @@ extern (C): enum NUM_SAMPLES = 32; -struct State -{ +struct State { sg.PassAction pass_action = { colors: [ - { - load_action: sg.LoadAction.Clear, - clear_value: {r: 1.0, g: 0.5, b: 0.0, a: 1.0}, - } + { load_action: sg.LoadAction.Clear, clear_value: {r: 1.0, g: 0.5, b: 0.0, a: 1.0} }, ] }; int even_odd; size_t sample_pos; float[NUM_SAMPLES] samples; } - static State state; -void init() -{ +void init() { sg.Desc gfx = { environment: sglue.environment, - logger: {func: &log.slog_func} + logger: { func: &log.slog_func } }; sg.setup(gfx); - saudio.Desc audio = {logger: {func: &log.slog_func}}; + saudio.Desc audio = { + logger: { func: &log.slog_func } + }; saudio.setup(audio); } -void frame() -{ +void frame() { immutable num_frames = saudio.expect(); - - foreach (_; 0 .. num_frames) - { + foreach (_; 0 .. num_frames) { state.even_odd += 1; state.sample_pos += 1; - - if (state.sample_pos == NUM_SAMPLES) - { + if (state.sample_pos == NUM_SAMPLES) { state.sample_pos = 0; saudio.push(&state.samples[0], NUM_SAMPLES); } - state.samples[state.sample_pos] = (0 != (state.even_odd & 0x20)) ? 0.1 : -0.1; } - - sg.Pass pass = {action: state.pass_action, swapchain: sglue.swapchain}; + sg.Pass pass = { action: state.pass_action, swapchain: sglue.swapchain() }; sg.beginPass(pass); sg.endPass(); sg.commit(); } -void cleanup() -{ +void cleanup() { saudio.shutdown(); sg.shutdown(); } -void main() -{ +void main() { app.Desc runner = { window_title: "saudio.d", init_cb: &init, diff --git a/src/examples/sgl_context.d b/src/examples/sgl_context.d index e2e397d..cb91892 100644 --- a/src/examples/sgl_context.d +++ b/src/examples/sgl_context.d @@ -16,36 +16,43 @@ import handmade.math : sin, cos; extern (C): @safe: -struct Offscreen -{ - sg.PassAction pass_action; +struct Offscreen { sg.Attachments attachments; sg.Image img; sgl.Context sgl_ctx; + sg.PassAction pass_action = { + colors: [ + { load_action: sg.LoadAction.Clear, clear_value: { r: 0, g: 0, b: 0, a: 1} }, + ] + }; } -struct Display -{ - sg.PassAction pass_action; +struct Display { sg.Sampler smp; sgl.Pipeline sgl_pip; + sg.PassAction pass_action = { + colors: [ + { load_action: sg.LoadAction.Clear, clear_value: { r: 0.5, g: 0.7, b: 1.0, a: 1.0 } }, + ], + }; } -struct State -{ - static Display display; - static Offscreen offscreen; +struct State { + Display display; + Offscreen offscreen; } +static State state; enum offscreen_pixel_format = sg.PixelFormat.Rgba8; enum offscreen_sample_count = 1; enum offscreen_width = 32; enum offscreen_height = 32; -void init() -{ - sg.Desc gfxd = {environment: sglue.environment, - logger: {func: &slog.func}}; +void init() { + sg.Desc gfxd = { + environment: sglue.environment(), + logger: { func: &slog.func } + }; sg.setup(gfxd); // setup sokol-gl with the default context compatible with the default @@ -55,22 +62,17 @@ void init() sgl.Desc gld = { max_vertices: 64, max_commands: 16, - logger: {func: &slog.func} + logger: { func: &slog.func }, }; sgl.setup(gld); - State state; - // initialize a pass action struct for the default pass to clear to a light-blue color - state.display.pass_action.colors[0].load_action = sg.LoadAction.Clear; - state.display.pass_action.colors[0].clear_value.r = 0.5; - state.display.pass_action.colors[0].clear_value.g = 0.7; - state.display.pass_action.colors[0].clear_value.b = 1.0; - state.display.pass_action.colors[0].clear_value.a = 1.0; - // create a sokol-gl pipeline object for 3D rendering into the default pass sg.PipelineDesc pld = { cull_mode: sg.CullMode.Back, - depth: {write_enabled: true, compare: sg.CompareFunc.Less_equal} + depth: { + write_enabled: true, + compare: sg.CompareFunc.Less_equal + }, }; state.display.sgl_pip = sgl.contextMakePipeline(sgl.defaultContext, pld); @@ -95,15 +97,12 @@ void init() }; state.offscreen.img = sg.makeImage(imgd); - sg.AttachmentsDesc attachmentDesc; - attachmentDesc.colors[0].image = state.offscreen.img; - state.offscreen.attachments = sg.makeAttachments(attachmentDesc); - - state.offscreen.pass_action.colors[0].load_action = sg.LoadAction.Clear; - state.offscreen.pass_action.colors[0].clear_value.r = 0.0; - state.offscreen.pass_action.colors[0].clear_value.g = 0.0; - state.offscreen.pass_action.colors[0].clear_value.b = 0.0; - state.offscreen.pass_action.colors[0].clear_value.a = 1.0; + sg.AttachmentsDesc attd = { + colors: [ + { image: state.offscreen.img } + ] + }; + state.offscreen.attachments = sg.makeAttachments(attd); // sampler for sampling the offscreen render target sg.SamplerDesc smd = { @@ -115,10 +114,8 @@ void init() state.display.smp = sg.makeSampler(smd); } -void frame() -{ +void frame() { immutable float a = sgl.asRadians(sapp.frameCount()); - State state; // draw a rotating quad into the offscreen render target texture sgl.setContext(state.offscreen.sgl_ctx); @@ -141,29 +138,29 @@ void frame() draw_cube(); // do the actual offscreen and display rendering in sokol-gfx passes - sg.Pass pass1 = { - action: state.offscreen.pass_action, attachments: state.offscreen.attachments + sg.Pass offscreen_pass = { + action: state.offscreen.pass_action, + attachments: state.offscreen.attachments }; - sg.beginPass(pass1); + sg.beginPass(offscreen_pass); sgl.contextDraw(state.offscreen.sgl_ctx); sg.endPass(); - sg.Pass pass2 = { - action: state.display.pass_action, swapchain: sglue.swapchain + sg.Pass display_pass = { + action: state.display.pass_action, + swapchain: sglue.swapchain }; - sg.beginPass(pass2); + sg.beginPass(display_pass); sgl.contextDraw(sgl.defaultContext()); sg.endPass(); sg.commit(); } -void cleanup() -{ +void cleanup() { sgl.shutdown(); sg.shutdown(); } -void main() -{ +void main() { sapp.Desc runner = { window_title: "sgl-context.d", init_cb: &init, @@ -172,14 +169,13 @@ void main() width: 800, height: 600, sample_count: 4, - logger: {func: &slog.func}, - icon: {sokol_default: true} + logger: { func: &slog.func }, + icon: { sokol_default: true } }; sapp.run(runner); } -void draw_quad() -{ +void draw_quad() { sgl.beginQuads(); sgl.v2fC3b(0.0, -1.0, 255, 0, 0); sgl.v2fC3b(1.0, 0.0, 0, 0, 255); @@ -188,8 +184,7 @@ void draw_quad() sgl.end(); } -void draw_cube() -{ +void draw_cube() { sgl.beginQuads(); sgl.v3fT2f(-1.0, 1.0, -1.0, 0.0, 1.0); sgl.v3fT2f(1.0, 1.0, -1.0, 1.0, 1.0); diff --git a/src/examples/sgl_points.d b/src/examples/sgl_points.d index 72b70be..ab9f850 100644 --- a/src/examples/sgl_points.d +++ b/src/examples/sgl_points.d @@ -18,14 +18,12 @@ import handmade.math : sin, cos, floor; extern (C): @safe: -struct RGB -{ +struct RGB { float r = 0.0, g = 0.0, b = 0.0; } -struct State -{ - static sg.PassAction pass_action = { +struct State { + sg.PassAction pass_action = { colors: [ { load_action: sg.LoadAction.Clear, @@ -34,8 +32,9 @@ struct State ] }; } +static State state; -immutable float[3][16] pallete = [ +immutable float[3][16] palette = [ [0.957, 0.263, 0.212], [0.914, 0.118, 0.388], [0.612, 0.153, 0.690], @@ -54,26 +53,24 @@ immutable float[3][16] pallete = [ [1.000, 0.341, 0.133], ]; -void init() -{ - sg.Desc gfxd = {environment: sglue.environment, - logger: {func: &slog.func}}; - sg.setup(gfxd); - - sgl.Desc gld = {logger: {func: &slog.func}}; - sgl.setup(gld); +void init() { + sg.Desc gfx = { + environment: sglue.environment(), + logger: { func: &slog.func } + }; + sg.setup(gfx); + sgl.Desc gl = { + logger: { func: &slog.func } + }; + sgl.setup(gl); } -void frame() -{ +void frame() { immutable float angle = sapp.frameCount() % 360.0; - State state; - sgl.defaults(); sgl.beginPoints(); float psize = 5.0; - foreach (i; 0 .. 360) - { + foreach (i; 0 .. 360) { auto a = sgl.asRadians(angle + i); auto color = computeColor(((sapp.frameCount() + i) % 300) / 300.0); auto r = sin(a * 4.0); @@ -88,21 +85,19 @@ void frame() } sgl.end(); - sg.Pass pass = {action: state.pass_action, swapchain: sglue.swapchain}; + sg.Pass pass = { action: state.pass_action, swapchain: sglue.swapchain() }; sg.beginPass(pass); sgl.draw(); sg.endPass(); sg.commit(); } -void cleanup() -{ +void cleanup() { sgl.shutdown(); sg.shutdown(); } -void main() -{ +void main() { sapp.Desc runner = { window_title: "sgl-points.d", init_cb: &init, @@ -116,13 +111,12 @@ void main() sapp.run(runner); } -RGB computeColor(float t) -{ +RGB computeColor(float t) { const(size_t) idx0 = cast(size_t)(t * 16) % 16; const(size_t) idx1 = cast(size_t)(idx0 + 1) % 16; const l = (t * 16) - floor(t * 16); - const c0 = pallete[idx0]; - const c1 = pallete[idx1]; + const c0 = palette[idx0]; + const c1 = palette[idx1]; RGB rgb = { r: (c0[0] * (1 - l)) + (c1[0] * l), g: (c0[1] * (1 - l)) + (c1[1] * l), diff --git a/src/examples/triangle.d b/src/examples/triangle.d index 908e008..aeba277 100644 --- a/src/examples/triangle.d +++ b/src/examples/triangle.d @@ -9,156 +9,77 @@ import sg = sokol.gfx; import sapp = sokol.app; import log = sokol.log; import sglue = sokol.glue; -import sgutil = sokol.utils; +import shd = shaders.triangle; extern (C): @safe: -struct State -{ - static sg.Bindings bind; - static sg.Pipeline pip; +struct State { + sg.Bindings bind; + sg.Pipeline pip; } +static State state; -void init() @trusted -{ - sg.Desc gfx = {environment: sglue.environment, - logger: {func: &log.slog_func}}; - sg.setup(gfx); - State state; +static void init() { + sg.Desc sg_desc = { + environment: sglue.environment(), + logger: { func: &log.slog_func }, + }; + sg.setup(sg_desc); - // create vertex buffer with triangle vertices - float[21] vertices = [ - // positions colors - 0.0, 0.5, 0.5, 1.0, 0.0, 0.0, 1.0, - 0.5, -0.5, 0.5, 0.0, 1.0, 0.0, 1.0, - -0.5, -0.5, 0.5, 0.0, 0.0, 1.0, 1.0, - ]; - sg.BufferDesc buff = {data: sgutil.asRange(&vertices[0])}; - state.bind.vertex_buffers[0] = sg.makeBuffer(buff); + // create vertex buffer with triangle vertices + float[21] vertices = [ + // positions colors + 0.0, 0.5, 0.5, 1.0, 0.0, 0.0, 1.0, + 0.5, -0.5, 0.5, 0.0, 1.0, 0.0, 1.0, + -0.5, -0.5, 0.5, 0.0, 0.0, 1.0, 1.0, + ]; + sg.BufferDesc buf_desc = { + data: { + ptr: vertices.ptr, + size: vertices.sizeof, + } + }; + state.bind.vertex_buffers[0] = sg.makeBuffer(buf_desc); - // create a shader and pipeline object - sg.ShaderDesc shader = shaderDesc(); - const shd = sg.makeShader(shader); - sg.PipelineDesc pip_desc = {shader: shd}; - pip_desc.layout.attrs[0].format = sg.VertexFormat.Float3; - pip_desc.layout.attrs[1].format = sg.VertexFormat.Float4; - state.pip = sg.makePipeline(pip_desc); + // create a shader and pipeline object + sg.PipelineDesc pip_desc = { + shader: sg.makeShader(shd.triangleShaderDesc(sg.queryBackend())), + layout: { + attrs: [ + shd.ATTR_VS_POSITION: { format: sg.VertexFormat.Float3 }, + shd.ATTR_VS_COLOR0: { format: sg.VertexFormat.Float4 }, + ], + } + }; + state.pip = sg.makePipeline(pip_desc); } -void frame() -{ - State state; - // default pass-action clears to grey - sg.PassAction pass_action; - sg.Pass pass = {action: pass_action, swapchain: sglue.swapchain}; - sg.beginPass(pass); - sg.applyPipeline(state.pip); - sg.applyBindings(state.bind); - sg.draw(0, 3, 1); - sg.endPass(); - sg.commit(); +static void frame() { + // default pass-action clears to grey + sg.Pass pass = { swapchain: sglue.swapchain() }; + sg.beginPass(pass); + sg.applyPipeline(state.pip); + sg.applyBindings(state.bind); + sg.draw(0, 3, 1); + sg.endPass(); + sg.commit(); } -void cleanup() -{ - sg.shutdown(); +static void cleanup() { + sg.shutdown(); } -void main() -{ - sapp.Desc runner = { - window_title: "triangle.d", - init_cb: &init, - frame_cb: &frame, - cleanup_cb: &cleanup, - width: 800, - height: 600, - icon: {sokol_default: true}, - logger: {func: &log.func} - }; - sapp.run(runner); -} - -sg.ShaderDesc shaderDesc() @trusted nothrow @nogc -{ - sg.ShaderDesc desc; - switch (sg.queryBackend) - { - case sg.Backend.Glcore33: - desc.attrs[0].name = "position"; - desc.attrs[1].name = "color0"; - desc.vs.source = " - #version 330 - in vec4 position; - in vec4 color0; - out vec4 color; - void main() { - gl_Position = position; - color = color0; - }"; - desc.fs.source = " - #version 330 - in vec4 color; - out vec4 frag_color; - void main() { - frag_color = color; - }"; - break; - case sg.Backend.D3d11: - desc.attrs[0].sem_name = "POS"; - desc.attrs[1].sem_name = "COLOR"; - desc.vs.source = " - struct vs_in { - float4 pos: POS; - float4 color: COLOR; - }; - struct vs_out { - float4 color: COLOR0; - float4 pos: SV_Position; - }; - vs_out main(vs_in inp) { - vs_out outp; - outp.pos = inp.pos; - outp.color = inp.color; - return outp; - } - "; - desc.fs.source = " - float4 main(float4 color: COLOR0): SV_Target0 { - return color; - } - "; - break; - case sg.Backend.Metal_macos: - desc.vs.source = " - #include - using namespace metal; - struct vs_in { - float4 position [[attribute(0)]]; - float4 color [[attribute(1)]]; - }; - struct vs_out { - float4 position [[position]]; - float4 color; - }; - vertex vs_out _main(vs_in inp [[stage_in]]) { - vs_out outp; - outp.position = inp.position; - outp.color = inp.color; - return outp; - } - "; - desc.fs.source = " - #include - using namespace metal; - fragment float4 _main(float4 color [[stage_in]]) { - return color; - }; - "; - break; - default: - break; - } - return desc; +void main() { + sapp.Desc runner = { + window_title: "triangle.d", + init_cb: &init, + frame_cb: &frame, + cleanup_cb: &cleanup, + width: 800, + height: 600, + icon: {sokol_default: true}, + logger: {func: &log.func} + }; + sapp.run(runner); } diff --git a/src/examples/user_data.d b/src/examples/user_data.d index d545fd2..f5fcf9d 100644 --- a/src/examples/user_data.d +++ b/src/examples/user_data.d @@ -7,71 +7,53 @@ import sglue = sokol.glue; extern (C): -struct ExampleUserData -{ +struct ExampleUserData { ubyte data; int[ubyte] map; // need druntime } -void init() @safe -{ +void init() @safe { sg.Desc gfx = { environment: sglue.environment, - logger: {func: &log.slog_func} + logger: { func: &log.slog_func } }; sg.setup(gfx); } -void frame_userdata(scope void* userdata) @trusted -{ +void frame_userdata(scope void* userdata) @trusted { auto state = cast(ExampleUserData*) userdata; state.data++; - - version (WebAssembly) - { + version (WebAssembly) { // TODO support } - else - { - if (state.data % 13 == 0) - { + else { + if (state.data % 13 == 0) { state.map[state.data] = state.data * 13 / 3; } - if (state.data % 12 == 0 && state.data % 15 == 0) - { + if (state.data % 12 == 0 && state.data % 15 == 0) { state.map.clear(); } } - debug - { + debug { import std.stdio : writeln; - - try - { + try { writeln(*state); - } - catch (Exception) - { - } + } catch (Exception) { } } - sg.PassAction pass_action; - sg.Pass pass = {action: pass_action, swapchain: sglue.swapchain}; + sg.Pass pass = { swapchain: sglue.swapchain }; sg.beginPass(pass); sg.endPass(); sg.commit(); } -void cleanup() @safe -{ +void cleanup() @safe { sg.shutdown(); } -void main() -{ +void main() { auto userData = ExampleUserData(0, null); - sapp.Desc runner = { window_title: "user-data.d", init_cb: &init, diff --git a/src/handmade/math.d b/src/handmade/math.d index 552e67b..8fd3547 100644 --- a/src/handmade/math.d +++ b/src/handmade/math.d @@ -12,8 +12,7 @@ module handmade.math; extern (C): @safe: -version (WebAssembly) -{ +version (WebAssembly) { // zig stdlib no-libc math functions enum PI = 3.14159265358979323846264338327950288419716939937510; double zig_cos(double value) @nogc nothrow @trusted; @@ -27,139 +26,112 @@ version (WebAssembly) alias sin = zig_sin; alias tan = zig_tan; - auto sqrt(T)(T value) - { - static if (is(T == double) || is(T == float)) - { + auto sqrt(T)(T value) { + static if (is(T == double) || is(T == float)) { return zig_sqrtf(value); - } - else - { + } else { return zig_sqrt(value); } } -} -else -{ +} else { public import core.stdc.math : sqrt, cos, sin, tan, floor; public import std.math : PI; } -struct Vec2 -{ +struct Vec2 { float x = 0.0, y = 0.0; - static Vec2 zero() - { + static Vec2 zero() { return Vec2(0, 0); } - this(float x, float y) - { + this(float x, float y) { this.x = x; this.y = y; } } -struct Vec3 -{ +struct Vec3 { float x = 0.0, y = 0.0, z = 0.0; - static Vec3 zero() - { + static Vec3 zero() { return Vec3(0, 0, 0); } - this(float x, float y, float z) - { + this(float x, float y, float z) { this.x = x; this.y = y; this.z = z; } - static Vec3 up() - { + static Vec3 up() { return Vec3(0, 1, 0); } - float len() const - { + float len() const { return sqrt(dot(this, this)); } - static Vec3 add(Vec3 left, Vec3 right) - { + static Vec3 add(Vec3 left, Vec3 right) { return Vec3(left.x + right.x, left.y + right.y, left.z + right.z); } - static Vec3 sub(Vec3 left, Vec3 right) - { + static Vec3 sub(Vec3 left, Vec3 right) { return Vec3(left.x - right.x, left.y - right.y, left.z - right.z); } - static Vec3 mul(Vec3 v, float s) - { + static Vec3 mul(Vec3 v, float s) { return Vec3(v.x * s, v.y * s, v.z * s); } - static Vec3 norm(Vec3 v) - { - auto l = v.len; - if (l != 0) - { + static Vec3 norm(Vec3 v) { + auto l = v.len(); + if (l != 0) { return Vec3(v.x / l, v.y / l, v.z / l); - } - else - { + } else { return Vec3.zero; } } - static Vec3 cross(Vec3 v0, Vec3 v1) - { - return Vec3((v0.y * v1.z) - (v0.z * v1.y), (v0.z * v1.x) - (v0.x * v1.z), - (v0.x * v1.y) - (v0.y * v1.x)); + static Vec3 cross(Vec3 v0, Vec3 v1) { + return Vec3( + (v0.y * v1.z) - (v0.z * v1.y), + (v0.z * v1.x) - (v0.x * v1.z), + (v0.x * v1.y) - (v0.y * v1.x) + ); } - static float dot(Vec3 v0, Vec3 v1) - { + static float dot(Vec3 v0, Vec3 v1) { return v0.x * v1.x + v0.y * v1.y + v0.z * v1.z; } } -struct Mat4 -{ +struct Mat4 { float[4][4] m; - static Mat4 identity() - { + static Mat4 identity() { return Mat4([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]); } - static Mat4 zero() - { + static Mat4 zero() { return Mat4([[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]); } - static Mat4 mul(Mat4 left, Mat4 right) - { + static Mat4 mul(Mat4 left, Mat4 right) { Mat4 result = Mat4.zero; - - foreach (row; 0 .. 4) - { - foreach (col; 0 .. 4) - { - result.m[row][col] = left.m[row][0] * right.m[0][col] - + left.m[row][1] * right.m[1][col] + left.m[row][2] - * right.m[2][col] + left.m[row][3] * right.m[3][col]; + foreach (col; 0 .. 4) { + foreach (row; 0 .. 4) { + result.m[col][row] = + left.m[0][row] * right.m[col][0] + + left.m[1][row] * right.m[col][1] + + left.m[2][row] * right.m[col][2] + + left.m[3][row] * right.m[col][3]; } } - return result; } - static Mat4 perspective(float fov, float aspect, float near, float far) - { + static Mat4 perspective(float fov, float aspect, float near, float far) { Mat4 result = Mat4.identity; float t = tan(fov * (PI / 360.0)); @@ -173,8 +145,7 @@ struct Mat4 return result; } - static Mat4 lookAt(Vec3 eye, Vec3 center, Vec3 up) - { + static Mat4 lookAt(Vec3 eye, Vec3 center, Vec3 up) { Mat4 result = Mat4.zero(); Vec3 f = Vec3.norm(Vec3.sub(center, eye)); @@ -201,8 +172,7 @@ struct Mat4 return result; } - static Mat4 rotate(float angle, Vec3 axis) - { + static Mat4 rotate(float angle, Vec3 axis) { Mat4 result = Mat4.identity; axis = Vec3.norm(axis); @@ -225,8 +195,7 @@ struct Mat4 return result; } - static Mat4 translate(Vec3 translation) - { + static Mat4 translate(Vec3 translation) { Mat4 result = Mat4.identity; result.m[3][0] = translation.x; @@ -237,13 +206,11 @@ struct Mat4 } } -float radians(float deg) -{ +float radians(float deg) { return deg * (PI / 180.0); } -unittest -{ +unittest { import std.math : isClose; // Vec3.zero test @@ -256,8 +223,7 @@ unittest } -unittest -{ +unittest { import std.math : isClose; // Vec3.new test @@ -270,29 +236,20 @@ unittest } -unittest -{ +unittest { import std.math : isClose; // Mat4.identity test { auto m = Mat4.identity(); - - foreach (i; 0 .. 4) - { - foreach (j; 0 .. 4) - { - if (i == j) - { + foreach (i; 0 .. 4) { + foreach (j; 0 .. 4) { + if (i == j) { assert(m.m[i][j].isClose(1.0)); - } - else - { + } else { assert(m.m[i][j].isClose(0.0)); } } } - } - } diff --git a/src/shaders/blend.d b/src/shaders/blend.d index ed58224..a1c0add 100644 --- a/src/shaders/blend.d +++ b/src/shaders/blend.d @@ -1,64 +1,63 @@ module shaders.blend; import sg = sokol.gfx; +import m = handmade.math; extern(C): /* #version:1# (machine generated, don't edit!) - + Generated by sokol-shdc (https://github.com/floooh/sokol-tools) - - Cmdline: sokol-shdc -i src/shaders/blend.glsl -o src/shaders/blend.d -l glsl330:metal_macos:hlsl4:glsl300es:wgsl -f sokol_d - + + Cmdline: + sokol-shdc -i src/shaders/blend.glsl -o src/shaders/blend.d -l glsl430:metal_macos:hlsl4:glsl300es:wgsl -f sokol_d + Overview: - - Shader program 'bg': - Get shader desc: bg_shader_desc(sg.query_backend()); - Vertex shader: vs_bg - Attribute slots: - ATTR_VS_BG_POSITION = 0 - Fragment shader: fs_bg - Uniform block 'bg_fs_params': - C struct: bg_fs_params_t - Bind slot: SLOT_BG_FS_PARAMS = 0 - - Shader program 'quad': - Get shader desc: quad_shader_desc(sg.query_backend()); - Vertex shader: vs_quad - Attribute slots: - ATTR_VS_QUAD_POSITION = 0 - ATTR_VS_QUAD_COLOR0 = 1 - Uniform block 'quad_vs_params': - C struct: quad_vs_params_t - Bind slot: SLOT_QUAD_VS_PARAMS = 0 - Fragment shader: fs_quad - + ========= + Shader program: 'bg': + Get shader desc: bgShaderDesc(sg.queryBackend()); + Vertex shader: vs_bg + Attributes: + ATTR_VS_BG_POSITION => 0 + Fragment shader: fs_bg + Uniform block 'bg_fs_params': + D struct: BgFsParams + Bind slot: SLOT_BG_FS_PARAMS => 0 + Shader program: 'quad': + Get shader desc: quadShaderDesc(sg.queryBackend()); + Vertex shader: vs_quad + Attributes: + ATTR_VS_QUAD_POSITION => 0 + ATTR_VS_QUAD_COLOR0 => 1 + Uniform block 'quad_vs_params': + D struct: QuadVsParams + Bind slot: SLOT_QUAD_VS_PARAMS => 0 + Fragment shader: fs_quad */ -import m = handmade.math; enum ATTR_VS_BG_POSITION = 0; enum ATTR_VS_QUAD_POSITION = 0; enum ATTR_VS_QUAD_COLOR0 = 1; enum SLOT_BG_FS_PARAMS = 0; +enum SLOT_QUAD_VS_PARAMS = 0; struct BgFsParams { - float tick; - ubyte[12] _pad_4; + align(16) float tick = 0; + align(1) ubyte[12] _pad_4 = 0; } -enum SLOT_QUAD_VS_PARAMS = 0; struct QuadVsParams { - m.Mat4 mvp; + align(16) m.Mat4 mvp; } /* - #version 330 - - layout(location = 0) in vec2 position; - - void main() - { - gl_Position = vec4(position, 0.5, 1.0); - } - + #version 430 + + layout(location = 0) in vec2 position; + + void main() + { + gl_Position = vec4(position, 0.5, 1.0); + } + */ -__gshared char[116] VS_BG_SOURCE_GLSL330 = [ - 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x33,0x30,0x0a,0x0a,0x6c,0x61, +__gshared char[116] VS_BG_SOURCE_GLSL430 = [ + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x6c,0x61, 0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, 0x30,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x32,0x20,0x70,0x6f,0x73,0x69,0x74, 0x69,0x6f,0x6e,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28, @@ -68,21 +67,21 @@ __gshared char[116] VS_BG_SOURCE_GLSL330 = [ 0x7d,0x0a,0x0a,0x00, ]; /* - #version 330 - - uniform vec4 bg_fs_params[1]; - layout(location = 0) out vec4 frag_color; - - void main() - { - vec2 _28 = fract((gl_FragCoord.xy - vec2(bg_fs_params[0].x)) * vec2(0.0199999995529651641845703125)); - float _39 = _28.x * _28.y; - frag_color = vec4(_39, _39, _39, 1.0); - } - + #version 430 + + uniform vec4 bg_fs_params[1]; + layout(location = 0) out vec4 frag_color; + + void main() + { + vec2 _28 = fract((gl_FragCoord.xy - vec2(bg_fs_params[0].x)) * vec2(0.0199999995529651641845703125)); + float _39 = _28.x * _28.y; + frag_color = vec4(_39, _39, _39, 1.0); + } + */ -__gshared char[285] FS_BG_SOURCE_GLSL330 = [ - 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x33,0x30,0x0a,0x0a,0x75,0x6e, +__gshared char[285] FS_BG_SOURCE_GLSL430 = [ + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x75,0x6e, 0x69,0x66,0x6f,0x72,0x6d,0x20,0x76,0x65,0x63,0x34,0x20,0x62,0x67,0x5f,0x66,0x73, 0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x31,0x5d,0x3b,0x0a,0x6c,0x61,0x79,0x6f, 0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29, @@ -102,73 +101,75 @@ __gshared char[285] FS_BG_SOURCE_GLSL330 = [ 0x39,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - #version 330 - - uniform vec4 quad_vs_params[4]; - layout(location = 0) in vec4 position; - out vec4 color; - layout(location = 1) in vec4 color0; - - void main() - { - gl_Position = mat4(quad_vs_params[0], quad_vs_params[1], quad_vs_params[2], quad_vs_params[3]) * position; - color = color0; - } - + #version 430 + + uniform vec4 quad_vs_params[4]; + layout(location = 0) in vec4 position; + layout(location = 0) out vec4 color; + layout(location = 1) in vec4 color0; + + void main() + { + gl_Position = mat4(quad_vs_params[0], quad_vs_params[1], quad_vs_params[2], quad_vs_params[3]) * position; + color = color0; + } + */ -__gshared char[288] VS_QUAD_SOURCE_GLSL330 = [ - 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x33,0x30,0x0a,0x0a,0x75,0x6e, +__gshared char[309] VS_QUAD_SOURCE_GLSL430 = [ + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x75,0x6e, 0x69,0x66,0x6f,0x72,0x6d,0x20,0x76,0x65,0x63,0x34,0x20,0x71,0x75,0x61,0x64,0x5f, 0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x34,0x5d,0x3b,0x0a,0x6c,0x61, 0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, 0x30,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20,0x70,0x6f,0x73,0x69,0x74, - 0x69,0x6f,0x6e,0x3b,0x0a,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x6f, - 0x6c,0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61, - 0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63, - 0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20, - 0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f, - 0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x6d,0x61,0x74,0x34,0x28, - 0x71,0x75,0x61,0x64,0x5f,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x30, - 0x5d,0x2c,0x20,0x71,0x75,0x61,0x64,0x5f,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d, - 0x73,0x5b,0x31,0x5d,0x2c,0x20,0x71,0x75,0x61,0x64,0x5f,0x76,0x73,0x5f,0x70,0x61, - 0x72,0x61,0x6d,0x73,0x5b,0x32,0x5d,0x2c,0x20,0x71,0x75,0x61,0x64,0x5f,0x76,0x73, - 0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x33,0x5d,0x29,0x20,0x2a,0x20,0x70,0x6f, - 0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x63,0x6f,0x6c,0x6f, - 0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, - + 0x69,0x6f,0x6e,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61, + 0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65, + 0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74, + 0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x69, + 0x6e,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x0a, + 0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, + 0x6d,0x61,0x74,0x34,0x28,0x71,0x75,0x61,0x64,0x5f,0x76,0x73,0x5f,0x70,0x61,0x72, + 0x61,0x6d,0x73,0x5b,0x30,0x5d,0x2c,0x20,0x71,0x75,0x61,0x64,0x5f,0x76,0x73,0x5f, + 0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x31,0x5d,0x2c,0x20,0x71,0x75,0x61,0x64,0x5f, + 0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x32,0x5d,0x2c,0x20,0x71,0x75, + 0x61,0x64,0x5f,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x33,0x5d,0x29, + 0x20,0x2a,0x20,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b, + 0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - #version 330 - - layout(location = 0) out vec4 frag_color; - in vec4 color; - - void main() - { - frag_color = color; - } - + #version 430 + + layout(location = 0) out vec4 frag_color; + layout(location = 0) in vec4 color; + + void main() + { + frag_color = color; + } + */ -__gshared char[114] FS_QUAD_SOURCE_GLSL330 = [ - 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x33,0x30,0x0a,0x0a,0x6c,0x61, +__gshared char[135] FS_QUAD_SOURCE_GLSL430 = [ + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x6c,0x61, 0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, 0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x66,0x72,0x61,0x67, - 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20, - 0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69, - 0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x63, - 0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x7d,0x0a, - 0x0a,0x00, + 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c, + 0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e,0x20, + 0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x0a,0x76,0x6f,0x69, + 0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f, + 0x72,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - #version 300 es - - layout(location = 0) in vec2 position; - - void main() - { - gl_Position = vec4(position, 0.5, 1.0); - } - + #version 300 es + + layout(location = 0) in vec2 position; + + void main() + { + gl_Position = vec4(position, 0.5, 1.0); + } + */ __gshared char[119] VS_BG_SOURCE_GLSL300ES = [ 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x30,0x30,0x20,0x65,0x73,0x0a, @@ -181,20 +182,20 @@ __gshared char[119] VS_BG_SOURCE_GLSL300ES = [ 0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - #version 300 es - precision mediump float; - precision highp int; - - uniform highp vec4 bg_fs_params[1]; - layout(location = 0) out highp vec4 frag_color; - - void main() - { - highp vec2 _28 = fract((gl_FragCoord.xy - vec2(bg_fs_params[0].x)) * vec2(0.0199999995529651641845703125)); - highp float _39 = _28.x * _28.y; - frag_color = vec4(_39, _39, _39, 1.0); - } - + #version 300 es + precision mediump float; + precision highp int; + + uniform highp vec4 bg_fs_params[1]; + layout(location = 0) out highp vec4 frag_color; + + void main() + { + highp vec2 _28 = fract((gl_FragCoord.xy - vec2(bg_fs_params[0].x)) * vec2(0.0199999995529651641845703125)); + highp float _39 = _28.x * _28.y; + frag_color = vec4(_39, _39, _39, 1.0); + } + */ __gshared char[358] FS_BG_SOURCE_GLSL300ES = [ 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x30,0x30,0x20,0x65,0x73,0x0a, @@ -222,19 +223,19 @@ __gshared char[358] FS_BG_SOURCE_GLSL300ES = [ 0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - #version 300 es - - uniform vec4 quad_vs_params[4]; - layout(location = 0) in vec4 position; - out vec4 color; - layout(location = 1) in vec4 color0; - - void main() - { - gl_Position = mat4(quad_vs_params[0], quad_vs_params[1], quad_vs_params[2], quad_vs_params[3]) * position; - color = color0; - } - + #version 300 es + + uniform vec4 quad_vs_params[4]; + layout(location = 0) in vec4 position; + out vec4 color; + layout(location = 1) in vec4 color0; + + void main() + { + gl_Position = mat4(quad_vs_params[0], quad_vs_params[1], quad_vs_params[2], quad_vs_params[3]) * position; + color = color0; + } + */ __gshared char[291] VS_QUAD_SOURCE_GLSL300ES = [ 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x30,0x30,0x20,0x65,0x73,0x0a, @@ -258,18 +259,18 @@ __gshared char[291] VS_QUAD_SOURCE_GLSL300ES = [ 0x0a,0x0a,0x00, ]; /* - #version 300 es - precision mediump float; - precision highp int; - - layout(location = 0) out highp vec4 frag_color; - in highp vec4 color; - - void main() - { - frag_color = color; - } - + #version 300 es + precision mediump float; + precision highp int; + + layout(location = 0) out highp vec4 frag_color; + in highp vec4 color; + + void main() + { + frag_color = color; + } + */ __gshared char[175] FS_QUAD_SOURCE_GLSL300ES = [ 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x30,0x30,0x20,0x65,0x73,0x0a, @@ -285,32 +286,32 @@ __gshared char[175] FS_QUAD_SOURCE_GLSL300ES = [ 0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - static float4 gl_Position; - static float2 position; - - struct SPIRV_Cross_Input - { - float2 position : TEXCOORD0; - }; - - struct SPIRV_Cross_Output - { - float4 gl_Position : SV_Position; - }; - - void vert_main() - { - gl_Position = float4(position, 0.5f, 1.0f); - } - - SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) - { - position = stage_input.position; - vert_main(); - SPIRV_Cross_Output stage_output; - stage_output.gl_Position = gl_Position; - return stage_output; - } + static float4 gl_Position; + static float2 position; + + struct SPIRV_Cross_Input + { + float2 position : TEXCOORD0; + }; + + struct SPIRV_Cross_Output + { + float4 gl_Position : SV_Position; + }; + + void vert_main() + { + gl_Position = float4(position, 0.5f, 1.0f); + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + position = stage_input.position; + vert_main(); + SPIRV_Cross_Output stage_output; + stage_output.gl_Position = gl_Position; + return stage_output; + } */ __gshared char[476] VS_BG_SOURCE_HLSL4 = [ 0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c, @@ -345,41 +346,41 @@ __gshared char[476] VS_BG_SOURCE_HLSL4 = [ 0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x00, ]; /* - cbuffer bg_fs_params : register(b0) - { - float _17_tick : packoffset(c0); - }; - - - static float4 gl_FragCoord; - static float4 frag_color; - - struct SPIRV_Cross_Input - { - float4 gl_FragCoord : SV_Position; - }; - - struct SPIRV_Cross_Output - { - float4 frag_color : SV_Target0; - }; - - void frag_main() - { - float2 _28 = frac((gl_FragCoord.xy - _17_tick.xx) * 0.0199999995529651641845703125f.xx); - float _39 = _28.x * _28.y; - frag_color = float4(_39, _39, _39, 1.0f); - } - - SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) - { - gl_FragCoord = stage_input.gl_FragCoord; - gl_FragCoord.w = 1.0 / gl_FragCoord.w; - frag_main(); - SPIRV_Cross_Output stage_output; - stage_output.frag_color = frag_color; - return stage_output; - } + cbuffer bg_fs_params : register(b0) + { + float _17_tick : packoffset(c0); + }; + + + static float4 gl_FragCoord; + static float4 frag_color; + + struct SPIRV_Cross_Input + { + float4 gl_FragCoord : SV_Position; + }; + + struct SPIRV_Cross_Output + { + float4 frag_color : SV_Target0; + }; + + void frag_main() + { + float2 _28 = frac((gl_FragCoord.xy - _17_tick.xx) * 0.0199999995529651641845703125f.xx); + float _39 = _28.x * _28.y; + frag_color = float4(_39, _39, _39, 1.0f); + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + gl_FragCoord = stage_input.gl_FragCoord; + gl_FragCoord.w = 1.0 / gl_FragCoord.w; + frag_main(); + SPIRV_Cross_Output stage_output; + stage_output.frag_color = frag_color; + return stage_output; + } */ __gshared char[734] FS_BG_SOURCE_HLSL4 = [ 0x63,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x62,0x67,0x5f,0x66,0x73,0x5f,0x70,0x61, @@ -430,45 +431,45 @@ __gshared char[734] FS_BG_SOURCE_HLSL4 = [ 0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x00, ]; /* - cbuffer quad_vs_params : register(b0) - { - row_major float4x4 _19_mvp : packoffset(c0); - }; - - - static float4 gl_Position; - static float4 position; - static float4 color; - static float4 color0; - - struct SPIRV_Cross_Input - { - float4 position : TEXCOORD0; - float4 color0 : TEXCOORD1; - }; - - struct SPIRV_Cross_Output - { - float4 color : TEXCOORD0; - float4 gl_Position : SV_Position; - }; - - void vert_main() - { - gl_Position = mul(position, _19_mvp); - color = color0; - } - - SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) - { - position = stage_input.position; - color0 = stage_input.color0; - vert_main(); - SPIRV_Cross_Output stage_output; - stage_output.gl_Position = gl_Position; - stage_output.color = color; - return stage_output; - } + cbuffer quad_vs_params : register(b0) + { + row_major float4x4 _19_mvp : packoffset(c0); + }; + + + static float4 gl_Position; + static float4 position; + static float4 color; + static float4 color0; + + struct SPIRV_Cross_Input + { + float4 position : TEXCOORD0; + float4 color0 : TEXCOORD1; + }; + + struct SPIRV_Cross_Output + { + float4 color : TEXCOORD0; + float4 gl_Position : SV_Position; + }; + + void vert_main() + { + gl_Position = mul(position, _19_mvp); + color = color0; + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + position = stage_input.position; + color0 = stage_input.color0; + vert_main(); + SPIRV_Cross_Output stage_output; + stage_output.gl_Position = gl_Position; + stage_output.color = color; + return stage_output; + } */ __gshared char[753] VS_QUAD_SOURCE_HLSL4 = [ 0x63,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x71,0x75,0x61,0x64,0x5f,0x76,0x73,0x5f, @@ -521,32 +522,32 @@ __gshared char[753] VS_QUAD_SOURCE_HLSL4 = [ 0x00, ]; /* - static float4 frag_color; - static float4 color; - - struct SPIRV_Cross_Input - { - float4 color : TEXCOORD0; - }; - - struct SPIRV_Cross_Output - { - float4 frag_color : SV_Target0; - }; - - void frag_main() - { - frag_color = color; - } - - SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) - { - color = stage_input.color; - frag_main(); - SPIRV_Cross_Output stage_output; - stage_output.frag_color = frag_color; - return stage_output; - } + static float4 frag_color; + static float4 color; + + struct SPIRV_Cross_Input + { + float4 color : TEXCOORD0; + }; + + struct SPIRV_Cross_Output + { + float4 frag_color : SV_Target0; + }; + + void frag_main() + { + frag_color = color; + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + color = stage_input.color; + frag_main(); + SPIRV_Cross_Output stage_output; + stage_output.frag_color = frag_color; + return stage_output; + } */ __gshared char[435] FS_QUAD_SOURCE_HLSL4 = [ 0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x66,0x72, @@ -579,28 +580,28 @@ __gshared char[435] FS_QUAD_SOURCE_HLSL4 = [ 0x7d,0x0a,0x00, ]; /* - #include - #include - - using namespace metal; - - struct main0_out - { - float4 gl_Position [[position]]; - }; - - struct main0_in - { - float2 position [[attribute(0)]]; - }; - - vertex main0_out main0(main0_in in [[stage_in]]) - { - main0_out out = {}; - out.gl_Position = float4(in.position, 0.5, 1.0); - return out; - } - + #include + #include + + using namespace metal; + + struct main0_out + { + float4 gl_Position [[position]]; + }; + + struct main0_in + { + float2 position [[attribute(0)]]; + }; + + vertex main0_out main0(main0_in in [[stage_in]]) + { + main0_out out = {}; + out.gl_Position = float4(in.position, 0.5, 1.0); + return out; + } + */ __gshared char[340] VS_BG_SOURCE_METAL_MACOS = [ 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, @@ -627,30 +628,30 @@ __gshared char[340] VS_BG_SOURCE_METAL_MACOS = [ 0x7d,0x0a,0x0a,0x00, ]; /* - #include - #include - - using namespace metal; - - struct bg_fs_params - { - float tick; - }; - - struct main0_out - { - float4 frag_color [[color(0)]]; - }; - - fragment main0_out main0(constant bg_fs_params& _17 [[buffer(0)]], float4 gl_FragCoord [[position]]) - { - main0_out out = {}; - float2 _28 = fract((gl_FragCoord.xy - float2(_17.tick)) * float2(0.0199999995529651641845703125)); - float _39 = _28.x * _28.y; - out.frag_color = float4(_39, _39, _39, 1.0); - return out; - } - + #include + #include + + using namespace metal; + + struct bg_fs_params + { + float tick; + }; + + struct main0_out + { + float4 frag_color [[color(0)]]; + }; + + fragment main0_out main0(constant bg_fs_params& _17 [[buffer(0)]], float4 gl_FragCoord [[position]]) + { + main0_out out = {}; + float2 _28 = fract((gl_FragCoord.xy - float2(_17.tick)) * float2(0.0199999995529651641845703125)); + float _39 = _28.x * _28.y; + out.frag_color = float4(_39, _39, _39, 1.0); + return out; + } + */ __gshared char[503] FS_BG_SOURCE_METAL_MACOS = [ 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, @@ -687,36 +688,36 @@ __gshared char[503] FS_BG_SOURCE_METAL_MACOS = [ 0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - #include - #include - - using namespace metal; - - struct quad_vs_params - { - float4x4 mvp; - }; - - struct main0_out - { - float4 color [[user(locn0)]]; - float4 gl_Position [[position]]; - }; - - struct main0_in - { - float4 position [[attribute(0)]]; - float4 color0 [[attribute(1)]]; - }; - - vertex main0_out main0(main0_in in [[stage_in]], constant quad_vs_params& _19 [[buffer(0)]]) - { - main0_out out = {}; - out.gl_Position = _19.mvp * in.position; - out.color = in.color0; - return out; - } - + #include + #include + + using namespace metal; + + struct quad_vs_params + { + float4x4 mvp; + }; + + struct main0_out + { + float4 color [[user(locn0)]]; + float4 gl_Position [[position]]; + }; + + struct main0_in + { + float4 position [[attribute(0)]]; + float4 color0 [[attribute(1)]]; + }; + + vertex main0_out main0(main0_in in [[stage_in]], constant quad_vs_params& _19 [[buffer(0)]]) + { + main0_out out = {}; + out.gl_Position = _19.mvp * in.position; + out.color = in.color0; + return out; + } + */ __gshared char[519] VS_QUAD_SOURCE_METAL_MACOS = [ 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, @@ -754,28 +755,28 @@ __gshared char[519] VS_QUAD_SOURCE_METAL_MACOS = [ 0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - #include - #include - - using namespace metal; - - struct main0_out - { - float4 frag_color [[color(0)]]; - }; - - struct main0_in - { - float4 color [[user(locn0)]]; - }; - - fragment main0_out main0(main0_in in [[stage_in]]) - { - main0_out out = {}; - out.frag_color = in.color; - return out; - } - + #include + #include + + using namespace metal; + + struct main0_out + { + float4 frag_color [[color(0)]]; + }; + + struct main0_in + { + float4 color [[user(locn0)]]; + }; + + fragment main0_out main0(main0_in in [[stage_in]]) + { + main0_out out = {}; + out.frag_color = in.color; + return out; + } + */ __gshared char[315] FS_QUAD_SOURCE_METAL_MACOS = [ 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, @@ -800,30 +801,30 @@ __gshared char[315] FS_QUAD_SOURCE_METAL_MACOS = [ 0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - diagnostic(off, derivative_uniformity); - - var position_1 : vec2f; - - var gl_Position : vec4f; - - fn main_1() { - let x_19 : vec2f = position_1; - gl_Position = vec4f(x_19.x, x_19.y, 0.5f, 1.0f); - return; - } - - struct main_out { - @builtin(position) - gl_Position : vec4f, - } - - @vertex - fn main(@location(0) position_1_param : vec2f) -> main_out { - position_1 = position_1_param; - main_1(); - return main_out(gl_Position); - } - + diagnostic(off, derivative_uniformity); + + var position_1 : vec2f; + + var gl_Position : vec4f; + + fn main_1() { + let x_19 : vec2f = position_1; + gl_Position = vec4f(x_19.x, x_19.y, 0.5f, 1.0f); + return; + } + + struct main_out { + @builtin(position) + gl_Position : vec4f, + } + + @vertex + fn main(@location(0) position_1_param : vec2f) -> main_out { + position_1 = position_1_param; + main_1(); + return main_out(gl_Position); + } + */ __gshared char[436] VS_BG_SOURCE_WGSL = [ 0x64,0x69,0x61,0x67,0x6e,0x6f,0x73,0x74,0x69,0x63,0x28,0x6f,0x66,0x66,0x2c,0x20, @@ -856,44 +857,44 @@ __gshared char[436] VS_BG_SOURCE_WGSL = [ 0x7d,0x0a,0x0a,0x00, ]; /* - diagnostic(off, derivative_uniformity); - - struct bg_fs_params { - /_ @offset(0) _/ - tick : f32, - } - - var gl_FragCoord : vec4f; - - @group(0) @binding(4) var x_17 : bg_fs_params; - - var frag_color : vec4f; - - fn main_1() { - var xy : vec2f; - let x_13 : vec4f = gl_FragCoord; - let x_22 : f32 = x_17.tick; - xy = fract(((vec2f(x_13.x, x_13.y) - vec2f(x_22, x_22)) / vec2f(50.0f, 50.0f))); - let x_35 : f32 = xy.x; - let x_38 : f32 = xy.y; - let x_39 : f32 = (x_35 * x_38); - let x_41 : vec3f = vec3f(x_39, x_39, x_39); - frag_color = vec4f(x_41.x, x_41.y, x_41.z, 1.0f); - return; - } - - struct main_out { - @location(0) - frag_color_1 : vec4f, - } - - @fragment - fn main(@builtin(position) gl_FragCoord_param : vec4f) -> main_out { - gl_FragCoord = gl_FragCoord_param; - main_1(); - return main_out(frag_color); - } - + diagnostic(off, derivative_uniformity); + + struct bg_fs_params { + /_ @offset(0) _/ + tick : f32, + } + + var gl_FragCoord : vec4f; + + @group(0) @binding(4) var x_17 : bg_fs_params; + + var frag_color : vec4f; + + fn main_1() { + var xy : vec2f; + let x_13 : vec4f = gl_FragCoord; + let x_22 : f32 = x_17.tick; + xy = fract(((vec2f(x_13.x, x_13.y) - vec2f(x_22, x_22)) / vec2f(50.0f, 50.0f))); + let x_35 : f32 = xy.x; + let x_38 : f32 = xy.y; + let x_39 : f32 = (x_35 * x_38); + let x_41 : vec3f = vec3f(x_39, x_39, x_39); + frag_color = vec4f(x_41.x, x_41.y, x_41.z, 1.0f); + return; + } + + struct main_out { + @location(0) + frag_color_1 : vec4f, + } + + @fragment + fn main(@builtin(position) gl_FragCoord_param : vec4f) -> main_out { + gl_FragCoord = gl_FragCoord_param; + main_1(); + return main_out(frag_color); + } + */ __gshared char[824] FS_BG_SOURCE_WGSL = [ 0x64,0x69,0x61,0x67,0x6e,0x6f,0x73,0x74,0x69,0x63,0x28,0x6f,0x66,0x66,0x2c,0x20, @@ -950,47 +951,47 @@ __gshared char[824] FS_BG_SOURCE_WGSL = [ 0x72,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - diagnostic(off, derivative_uniformity); - - struct quad_vs_params { - /_ @offset(0) _/ - mvp : mat4x4f, - } - - @group(0) @binding(0) var x_19 : quad_vs_params; - - var position_1 : vec4f; - - var color : vec4f; - - var color0 : vec4f; - - var gl_Position : vec4f; - - fn main_1() { - let x_22 : mat4x4f = x_19.mvp; - let x_25 : vec4f = position_1; - gl_Position = (x_22 * x_25); - let x_31 : vec4f = color0; - color = x_31; - return; - } - - struct main_out { - @builtin(position) - gl_Position : vec4f, - @location(0) - color_1 : vec4f, - } - - @vertex - fn main(@location(0) position_1_param : vec4f, @location(1) color0_param : vec4f) -> main_out { - position_1 = position_1_param; - color0 = color0_param; - main_1(); - return main_out(gl_Position, color); - } - + diagnostic(off, derivative_uniformity); + + struct quad_vs_params { + /_ @offset(0) _/ + mvp : mat4x4f, + } + + @group(0) @binding(0) var x_19 : quad_vs_params; + + var position_1 : vec4f; + + var color : vec4f; + + var color0 : vec4f; + + var gl_Position : vec4f; + + fn main_1() { + let x_22 : mat4x4f = x_19.mvp; + let x_25 : vec4f = position_1; + gl_Position = (x_22 * x_25); + let x_31 : vec4f = color0; + color = x_31; + return; + } + + struct main_out { + @builtin(position) + gl_Position : vec4f, + @location(0) + color_1 : vec4f, + } + + @vertex + fn main(@location(0) position_1_param : vec4f, @location(1) color0_param : vec4f) -> main_out { + position_1 = position_1_param; + color0 = color0_param; + main_1(); + return main_out(gl_Position, color); + } + */ __gshared char[776] VS_QUAD_SOURCE_WGSL = [ 0x64,0x69,0x61,0x67,0x6e,0x6f,0x73,0x74,0x69,0x63,0x28,0x6f,0x66,0x66,0x2c,0x20, @@ -1044,30 +1045,30 @@ __gshared char[776] VS_QUAD_SOURCE_WGSL = [ 0x72,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - diagnostic(off, derivative_uniformity); - - var frag_color : vec4f; - - var color : vec4f; - - fn main_1() { - let x_12 : vec4f = color; - frag_color = x_12; - return; - } - - struct main_out { - @location(0) - frag_color_1 : vec4f, - } - - @fragment - fn main(@location(0) color_param : vec4f) -> main_out { - color = color_param; - main_1(); - return main_out(frag_color); - } - + diagnostic(off, derivative_uniformity); + + var frag_color : vec4f; + + var color : vec4f; + + fn main_1() { + let x_12 : vec4f = color; + frag_color = x_12; + return; + } + + struct main_out { + @location(0) + frag_color_1 : vec4f, + } + + @fragment + fn main(@location(0) color_param : vec4f) -> main_out { + color = color_param; + main_1(); + return main_out(frag_color); + } + */ __gshared char[376] FS_QUAD_SOURCE_WGSL = [ 0x64,0x69,0x61,0x67,0x6e,0x6f,0x73,0x74,0x69,0x63,0x28,0x6f,0x66,0x66,0x2c,0x20, @@ -1095,138 +1096,127 @@ __gshared char[376] FS_QUAD_SOURCE_WGSL = [ 0x69,0x6e,0x5f,0x6f,0x75,0x74,0x28,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f, 0x72,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; - -sg.ShaderDesc bg_shader_desc(sg.Backend backend) @trusted @nogc nothrow { - sg.ShaderDesc desc; - switch (backend) { - case sg.Backend.Glcore33: - desc.attrs[0].name = "position"; - desc.vs.source = &VS_BG_SOURCE_GLSL330[0]; - desc.vs.entry = "main"; - desc.fs.source = &FS_BG_SOURCE_GLSL330[0]; - desc.fs.entry = "main"; - desc.fs.uniform_blocks[0].size = 16; - desc.fs.uniform_blocks[0].layout = sg.UniformLayout.Std140; - desc.fs.uniform_blocks[0].uniforms[0].name = "bg_fs_params"; - desc.fs.uniform_blocks[0].uniforms[0].type = sg.UniformType.Float4; - desc.fs.uniform_blocks[0].uniforms[0].array_count = 1; - desc.label = "bg_shader"; - break; - case sg.Backend.Gles3: - desc.attrs[0].name = "position"; - desc.vs.source = &VS_BG_SOURCE_GLSL300ES[0]; - desc.vs.entry = "main"; - desc.fs.source = &FS_BG_SOURCE_GLSL300ES[0]; - desc.fs.entry = "main"; - desc.fs.uniform_blocks[0].size = 16; - desc.fs.uniform_blocks[0].layout = sg.UniformLayout.Std140; - desc.fs.uniform_blocks[0].uniforms[0].name = "bg_fs_params"; - desc.fs.uniform_blocks[0].uniforms[0].type = sg.UniformType.Float4; - desc.fs.uniform_blocks[0].uniforms[0].array_count = 1; - desc.label = "bg_shader"; - break; - case sg.Backend.D3d11: - desc.attrs[0].sem_name = "TEXCOORD"; - desc.attrs[0].sem_index = 0; - desc.vs.source = &VS_BG_SOURCE_HLSL4[0]; - desc.vs.d3d11_target = "vs_4_0"; - desc.vs.entry = "main"; - desc.fs.source = &FS_BG_SOURCE_HLSL4[0]; - desc.fs.d3d11_target = "ps_4_0"; - desc.fs.entry = "main"; - desc.fs.uniform_blocks[0].size = 16; - desc.fs.uniform_blocks[0].layout = sg.UniformLayout.Std140; - desc.label = "bg_shader"; - break; - case sg.Backend.Metal_macos: - desc.vs.source = &VS_BG_SOURCE_METAL_MACOS[0]; - desc.vs.entry = "main0"; - desc.fs.source = &FS_BG_SOURCE_METAL_MACOS[0]; - desc.fs.entry = "main0"; - desc.fs.uniform_blocks[0].size = 16; - desc.fs.uniform_blocks[0].layout = sg.UniformLayout.Std140; - desc.label = "bg_shader"; - break; - case sg.Backend.Wgpu: - desc.vs.source = &VS_BG_SOURCE_WGSL[0]; - desc.vs.entry = "main"; - desc.fs.source = &FS_BG_SOURCE_WGSL[0]; - desc.fs.entry = "main"; - desc.fs.uniform_blocks[0].size = 16; - desc.fs.uniform_blocks[0].layout = sg.UniformLayout.Std140; - desc.label = "bg_shader"; - break; - default: - break; - } - return desc; +sg.ShaderDesc bgShaderDesc(sg.Backend backend) @trusted @nogc nothrow { + sg.ShaderDesc desc; + desc.label = "bg_shader"; + switch (backend) { + case sg.Backend.Glcore: + desc.attrs[0].name = "position"; + desc.vs.source = &VS_BG_SOURCE_GLSL430[0]; + desc.vs.entry = "main"; + desc.fs.source = &FS_BG_SOURCE_GLSL430[0]; + desc.fs.entry = "main"; + desc.fs.uniform_blocks[0].size = 16; + desc.fs.uniform_blocks[0].layout = sg.UniformLayout.Std140; + desc.fs.uniform_blocks[0].uniforms[0].name = "bg_fs_params"; + desc.fs.uniform_blocks[0].uniforms[0].type = sg.UniformType.Float4; + desc.fs.uniform_blocks[0].uniforms[0].array_count = 1; + break; + case sg.Backend.Gles3: + desc.attrs[0].name = "position"; + desc.vs.source = &VS_BG_SOURCE_GLSL300ES[0]; + desc.vs.entry = "main"; + desc.fs.source = &FS_BG_SOURCE_GLSL300ES[0]; + desc.fs.entry = "main"; + desc.fs.uniform_blocks[0].size = 16; + desc.fs.uniform_blocks[0].layout = sg.UniformLayout.Std140; + desc.fs.uniform_blocks[0].uniforms[0].name = "bg_fs_params"; + desc.fs.uniform_blocks[0].uniforms[0].type = sg.UniformType.Float4; + desc.fs.uniform_blocks[0].uniforms[0].array_count = 1; + break; + case sg.Backend.D3d11: + desc.attrs[0].sem_name = "TEXCOORD"; + desc.attrs[0].sem_index = 0; + desc.vs.source = &VS_BG_SOURCE_HLSL4[0]; + desc.vs.d3d11_target = "vs_4_0"; + desc.vs.entry = "main"; + desc.fs.source = &FS_BG_SOURCE_HLSL4[0]; + desc.fs.d3d11_target = "ps_4_0"; + desc.fs.entry = "main"; + desc.fs.uniform_blocks[0].size = 16; + desc.fs.uniform_blocks[0].layout = sg.UniformLayout.Std140; + break; + case sg.Backend.Metal_macos: + desc.vs.source = &VS_BG_SOURCE_METAL_MACOS[0]; + desc.vs.entry = "main0"; + desc.fs.source = &FS_BG_SOURCE_METAL_MACOS[0]; + desc.fs.entry = "main0"; + desc.fs.uniform_blocks[0].size = 16; + desc.fs.uniform_blocks[0].layout = sg.UniformLayout.Std140; + break; + case sg.Backend.Wgpu: + desc.vs.source = &VS_BG_SOURCE_WGSL[0]; + desc.vs.entry = "main"; + desc.fs.source = &FS_BG_SOURCE_WGSL[0]; + desc.fs.entry = "main"; + desc.fs.uniform_blocks[0].size = 16; + desc.fs.uniform_blocks[0].layout = sg.UniformLayout.Std140; + break; + default: break; + } + return desc; } -sg.ShaderDesc quad_shader_desc(sg.Backend backend) @trusted @nogc nothrow { - sg.ShaderDesc desc; - switch (backend) { - case sg.Backend.Glcore33: - desc.attrs[0].name = "position"; - desc.attrs[1].name = "color0"; - desc.vs.source = &VS_QUAD_SOURCE_GLSL330[0]; - desc.vs.entry = "main"; - desc.vs.uniform_blocks[0].size = 64; - desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; - desc.vs.uniform_blocks[0].uniforms[0].name = "quad_vs_params"; - desc.vs.uniform_blocks[0].uniforms[0].type = sg.UniformType.Float4; - desc.vs.uniform_blocks[0].uniforms[0].array_count = 4; - desc.fs.source = &FS_QUAD_SOURCE_GLSL330[0]; - desc.fs.entry = "main"; - desc.label = "quad_shader"; - break; - case sg.Backend.Gles3: - desc.attrs[0].name = "position"; - desc.attrs[1].name = "color0"; - desc.vs.source = &VS_QUAD_SOURCE_GLSL300ES[0]; - desc.vs.entry = "main"; - desc.vs.uniform_blocks[0].size = 64; - desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; - desc.vs.uniform_blocks[0].uniforms[0].name = "quad_vs_params"; - desc.vs.uniform_blocks[0].uniforms[0].type = sg.UniformType.Float4; - desc.vs.uniform_blocks[0].uniforms[0].array_count = 4; - desc.fs.source = &FS_QUAD_SOURCE_GLSL300ES[0]; - desc.fs.entry = "main"; - desc.label = "quad_shader"; - break; - case sg.Backend.D3d11: - desc.attrs[0].sem_name = "TEXCOORD"; - desc.attrs[0].sem_index = 0; - desc.attrs[1].sem_name = "TEXCOORD"; - desc.attrs[1].sem_index = 1; - desc.vs.source = &VS_QUAD_SOURCE_HLSL4[0]; - desc.vs.d3d11_target = "vs_4_0"; - desc.vs.entry = "main"; - desc.vs.uniform_blocks[0].size = 64; - desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; - desc.fs.source = &FS_QUAD_SOURCE_HLSL4[0]; - desc.fs.d3d11_target = "ps_4_0"; - desc.fs.entry = "main"; - desc.label = "quad_shader"; - break; - case sg.Backend.Metal_macos: - desc.vs.source = &VS_QUAD_SOURCE_METAL_MACOS[0]; - desc.vs.entry = "main0"; - desc.vs.uniform_blocks[0].size = 64; - desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; - desc.fs.source = &FS_QUAD_SOURCE_METAL_MACOS[0]; - desc.fs.entry = "main0"; - desc.label = "quad_shader"; - break; - case sg.Backend.Wgpu: - desc.vs.source = &VS_QUAD_SOURCE_WGSL[0]; - desc.vs.entry = "main"; - desc.vs.uniform_blocks[0].size = 64; - desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; - desc.fs.source = &FS_QUAD_SOURCE_WGSL[0]; - desc.fs.entry = "main"; - desc.label = "quad_shader"; - break; - default: - break; - } - return desc; +sg.ShaderDesc quadShaderDesc(sg.Backend backend) @trusted @nogc nothrow { + sg.ShaderDesc desc; + desc.label = "quad_shader"; + switch (backend) { + case sg.Backend.Glcore: + desc.attrs[0].name = "position"; + desc.attrs[1].name = "color0"; + desc.vs.source = &VS_QUAD_SOURCE_GLSL430[0]; + desc.vs.entry = "main"; + desc.vs.uniform_blocks[0].size = 64; + desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; + desc.vs.uniform_blocks[0].uniforms[0].name = "quad_vs_params"; + desc.vs.uniform_blocks[0].uniforms[0].type = sg.UniformType.Float4; + desc.vs.uniform_blocks[0].uniforms[0].array_count = 4; + desc.fs.source = &FS_QUAD_SOURCE_GLSL430[0]; + desc.fs.entry = "main"; + break; + case sg.Backend.Gles3: + desc.attrs[0].name = "position"; + desc.attrs[1].name = "color0"; + desc.vs.source = &VS_QUAD_SOURCE_GLSL300ES[0]; + desc.vs.entry = "main"; + desc.vs.uniform_blocks[0].size = 64; + desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; + desc.vs.uniform_blocks[0].uniforms[0].name = "quad_vs_params"; + desc.vs.uniform_blocks[0].uniforms[0].type = sg.UniformType.Float4; + desc.vs.uniform_blocks[0].uniforms[0].array_count = 4; + desc.fs.source = &FS_QUAD_SOURCE_GLSL300ES[0]; + desc.fs.entry = "main"; + break; + case sg.Backend.D3d11: + desc.attrs[0].sem_name = "TEXCOORD"; + desc.attrs[0].sem_index = 0; + desc.attrs[1].sem_name = "TEXCOORD"; + desc.attrs[1].sem_index = 1; + desc.vs.source = &VS_QUAD_SOURCE_HLSL4[0]; + desc.vs.d3d11_target = "vs_4_0"; + desc.vs.entry = "main"; + desc.vs.uniform_blocks[0].size = 64; + desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; + desc.fs.source = &FS_QUAD_SOURCE_HLSL4[0]; + desc.fs.d3d11_target = "ps_4_0"; + desc.fs.entry = "main"; + break; + case sg.Backend.Metal_macos: + desc.vs.source = &VS_QUAD_SOURCE_METAL_MACOS[0]; + desc.vs.entry = "main0"; + desc.vs.uniform_blocks[0].size = 64; + desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; + desc.fs.source = &FS_QUAD_SOURCE_METAL_MACOS[0]; + desc.fs.entry = "main0"; + break; + case sg.Backend.Wgpu: + desc.vs.source = &VS_QUAD_SOURCE_WGSL[0]; + desc.vs.entry = "main"; + desc.vs.uniform_blocks[0].size = 64; + desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; + desc.fs.source = &FS_QUAD_SOURCE_WGSL[0]; + desc.fs.entry = "main"; + break; + default: break; + } + return desc; } diff --git a/src/shaders/bufferoffsets.d b/src/shaders/bufferoffsets.d index 8068be9..c3d99b3 100644 --- a/src/shaders/bufferoffsets.d +++ b/src/shaders/bufferoffsets.d @@ -4,86 +4,89 @@ extern(C): /* #version:1# (machine generated, don't edit!) - + Generated by sokol-shdc (https://github.com/floooh/sokol-tools) - - Cmdline: sokol-shdc -i src/shaders/bufferoffsets.glsl -o src/shaders/bufferoffsets.d -l glsl330:metal_macos:hlsl4:glsl300es:wgsl -f sokol_d - + + Cmdline: + sokol-shdc -i src/shaders/bufferoffsets.glsl -o src/shaders/bufferoffsets.d -l glsl430:metal_macos:hlsl4:glsl300es:wgsl -f sokol_d + Overview: - - Shader program 'bufferoffsets': - Get shader desc: bufferoffsets_shader_desc(sg.query_backend()); - Vertex shader: vs - Attribute slots: - ATTR_VS_POSITION = 0 - ATTR_VS_COLOR0 = 1 - Fragment shader: fs - + ========= + Shader program: 'bufferoffsets': + Get shader desc: bufferoffsetsShaderDesc(sg.queryBackend()); + Vertex shader: vs + Attributes: + ATTR_VS_POSITION => 0 + ATTR_VS_COLOR0 => 1 + Fragment shader: fs */ enum ATTR_VS_POSITION = 0; enum ATTR_VS_COLOR0 = 1; /* - #version 330 - - layout(location = 0) in vec4 position; - out vec4 color; - layout(location = 1) in vec4 color0; - - void main() - { - gl_Position = position; - color = color0; - } - + #version 430 + + layout(location = 0) in vec4 position; + layout(location = 0) out vec4 color; + layout(location = 1) in vec4 color0; + + void main() + { + gl_Position = position; + color = color0; + } + */ -__gshared char[173] VS_SOURCE_GLSL330 = [ - 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x33,0x30,0x0a,0x0a,0x6c,0x61, +__gshared char[194] VS_SOURCE_GLSL430 = [ + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x6c,0x61, 0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, 0x30,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20,0x70,0x6f,0x73,0x69,0x74, - 0x69,0x6f,0x6e,0x3b,0x0a,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x6f, - 0x6c,0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61, - 0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63, - 0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20, - 0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f, - 0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x70,0x6f,0x73,0x69,0x74, - 0x69,0x6f,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d, - 0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, + 0x69,0x6f,0x6e,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61, + 0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65, + 0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74, + 0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x69, + 0x6e,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x0a, + 0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, + 0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x63,0x6f, + 0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x7d,0x0a, + 0x0a,0x00, ]; /* - #version 330 - - layout(location = 0) out vec4 frag_color; - in vec4 color; - - void main() - { - frag_color = color; - } - + #version 430 + + layout(location = 0) out vec4 frag_color; + layout(location = 0) in vec4 color; + + void main() + { + frag_color = color; + } + */ -__gshared char[114] FS_SOURCE_GLSL330 = [ - 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x33,0x30,0x0a,0x0a,0x6c,0x61, +__gshared char[135] FS_SOURCE_GLSL430 = [ + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x6c,0x61, 0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, 0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x66,0x72,0x61,0x67, - 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20, - 0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69, - 0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x63, - 0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x7d,0x0a, - 0x0a,0x00, + 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c, + 0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e,0x20, + 0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x0a,0x76,0x6f,0x69, + 0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f, + 0x72,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - #version 300 es - - layout(location = 0) in vec4 position; - out vec4 color; - layout(location = 1) in vec4 color0; - - void main() - { - gl_Position = position; - color = color0; - } - + #version 300 es + + layout(location = 0) in vec4 position; + out vec4 color; + layout(location = 1) in vec4 color0; + + void main() + { + gl_Position = position; + color = color0; + } + */ __gshared char[176] VS_SOURCE_GLSL300ES = [ 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x30,0x30,0x20,0x65,0x73,0x0a, @@ -100,18 +103,18 @@ __gshared char[176] VS_SOURCE_GLSL300ES = [ ]; /* - #version 300 es - precision mediump float; - precision highp int; - - layout(location = 0) out highp vec4 frag_color; - in highp vec4 color; - - void main() - { - frag_color = color; - } - + #version 300 es + precision mediump float; + precision highp int; + + layout(location = 0) out highp vec4 frag_color; + in highp vec4 color; + + void main() + { + frag_color = color; + } + */ __gshared char[175] FS_SOURCE_GLSL300ES = [ 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x30,0x30,0x20,0x65,0x73,0x0a, @@ -127,39 +130,39 @@ __gshared char[175] FS_SOURCE_GLSL300ES = [ 0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - static float4 gl_Position; - static float4 position; - static float4 color; - static float4 color0; - - struct SPIRV_Cross_Input - { - float4 position : TEXCOORD0; - float4 color0 : TEXCOORD1; - }; - - struct SPIRV_Cross_Output - { - float4 color : TEXCOORD0; - float4 gl_Position : SV_Position; - }; - - void vert_main() - { - gl_Position = position; - color = color0; - } - - SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) - { - position = stage_input.position; - color0 = stage_input.color0; - vert_main(); - SPIRV_Cross_Output stage_output; - stage_output.gl_Position = gl_Position; - stage_output.color = color; - return stage_output; - } + static float4 gl_Position; + static float4 position; + static float4 color; + static float4 color0; + + struct SPIRV_Cross_Input + { + float4 position : TEXCOORD0; + float4 color0 : TEXCOORD1; + }; + + struct SPIRV_Cross_Output + { + float4 color : TEXCOORD0; + float4 gl_Position : SV_Position; + }; + + void vert_main() + { + gl_Position = position; + color = color0; + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + position = stage_input.position; + color0 = stage_input.color0; + vert_main(); + SPIRV_Cross_Output stage_output; + stage_output.gl_Position = gl_Position; + stage_output.color = color; + return stage_output; + } */ __gshared char[645] VS_SOURCE_HLSL4 = [ 0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c, @@ -205,32 +208,32 @@ __gshared char[645] VS_SOURCE_HLSL4 = [ 0x3b,0x0a,0x7d,0x0a,0x00, ]; /* - static float4 frag_color; - static float4 color; - - struct SPIRV_Cross_Input - { - float4 color : TEXCOORD0; - }; - - struct SPIRV_Cross_Output - { - float4 frag_color : SV_Target0; - }; - - void frag_main() - { - frag_color = color; - } - - SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) - { - color = stage_input.color; - frag_main(); - SPIRV_Cross_Output stage_output; - stage_output.frag_color = frag_color; - return stage_output; - } + static float4 frag_color; + static float4 color; + + struct SPIRV_Cross_Input + { + float4 color : TEXCOORD0; + }; + + struct SPIRV_Cross_Output + { + float4 frag_color : SV_Target0; + }; + + void frag_main() + { + frag_color = color; + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + color = stage_input.color; + frag_main(); + SPIRV_Cross_Output stage_output; + stage_output.frag_color = frag_color; + return stage_output; + } */ __gshared char[435] FS_SOURCE_HLSL4 = [ 0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x66,0x72, @@ -263,31 +266,31 @@ __gshared char[435] FS_SOURCE_HLSL4 = [ 0x7d,0x0a,0x00, ]; /* - #include - #include - - using namespace metal; - - struct main0_out - { - float4 color [[user(locn0)]]; - float4 gl_Position [[position]]; - }; - - struct main0_in - { - float4 position [[attribute(0)]]; - float4 color0 [[attribute(1)]]; - }; - - vertex main0_out main0(main0_in in [[stage_in]]) - { - main0_out out = {}; - out.gl_Position = in.position; - out.color = in.color0; - return out; - } - + #include + #include + + using namespace metal; + + struct main0_out + { + float4 color [[user(locn0)]]; + float4 gl_Position [[position]]; + }; + + struct main0_in + { + float4 position [[attribute(0)]]; + float4 color0 [[attribute(1)]]; + }; + + vertex main0_out main0(main0_in in [[stage_in]]) + { + main0_out out = {}; + out.gl_Position = in.position; + out.color = in.color0; + return out; + } + */ __gshared char[419] VS_SOURCE_METAL_MACOS = [ 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, @@ -319,28 +322,28 @@ __gshared char[419] VS_SOURCE_METAL_MACOS = [ 0x0a,0x0a,0x00, ]; /* - #include - #include - - using namespace metal; - - struct main0_out - { - float4 frag_color [[color(0)]]; - }; - - struct main0_in - { - float4 color [[user(locn0)]]; - }; - - fragment main0_out main0(main0_in in [[stage_in]]) - { - main0_out out = {}; - out.frag_color = in.color; - return out; - } - + #include + #include + + using namespace metal; + + struct main0_out + { + float4 frag_color [[color(0)]]; + }; + + struct main0_in + { + float4 color [[user(locn0)]]; + }; + + fragment main0_out main0(main0_in in [[stage_in]]) + { + main0_out out = {}; + out.frag_color = in.color; + return out; + } + */ __gshared char[315] FS_SOURCE_METAL_MACOS = [ 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, @@ -365,39 +368,39 @@ __gshared char[315] FS_SOURCE_METAL_MACOS = [ 0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - diagnostic(off, derivative_uniformity); - - var position_1 : vec4f; - - var color : vec4f; - - var color0 : vec4f; - - var gl_Position : vec4f; - - fn main_1() { - let x_18 : vec4f = position_1; - gl_Position = x_18; - let x_23 : vec4f = color0; - color = x_23; - return; - } - - struct main_out { - @builtin(position) - gl_Position : vec4f, - @location(0) - color_1 : vec4f, - } - - @vertex - fn main(@location(0) position_1_param : vec4f, @location(1) color0_param : vec4f) -> main_out { - position_1 = position_1_param; - color0 = color0_param; - main_1(); - return main_out(gl_Position, color); - } - + diagnostic(off, derivative_uniformity); + + var position_1 : vec4f; + + var color : vec4f; + + var color0 : vec4f; + + var gl_Position : vec4f; + + fn main_1() { + let x_18 : vec4f = position_1; + gl_Position = x_18; + let x_23 : vec4f = color0; + color = x_23; + return; + } + + struct main_out { + @builtin(position) + gl_Position : vec4f, + @location(0) + color_1 : vec4f, + } + + @vertex + fn main(@location(0) position_1_param : vec4f, @location(1) color0_param : vec4f) -> main_out { + position_1 = position_1_param; + color0 = color0_param; + main_1(); + return main_out(gl_Position, color); + } + */ __gshared char[612] VS_SOURCE_WGSL = [ 0x64,0x69,0x61,0x67,0x6e,0x6f,0x73,0x74,0x69,0x63,0x28,0x6f,0x66,0x66,0x2c,0x20, @@ -441,30 +444,30 @@ __gshared char[612] VS_SOURCE_WGSL = [ 0x7d,0x0a,0x0a,0x00, ]; /* - diagnostic(off, derivative_uniformity); - - var frag_color : vec4f; - - var color : vec4f; - - fn main_1() { - let x_12 : vec4f = color; - frag_color = x_12; - return; - } - - struct main_out { - @location(0) - frag_color_1 : vec4f, - } - - @fragment - fn main(@location(0) color_param : vec4f) -> main_out { - color = color_param; - main_1(); - return main_out(frag_color); - } - + diagnostic(off, derivative_uniformity); + + var frag_color : vec4f; + + var color : vec4f; + + fn main_1() { + let x_12 : vec4f = color; + frag_color = x_12; + return; + } + + struct main_out { + @location(0) + frag_color_1 : vec4f, + } + + @fragment + fn main(@location(0) color_param : vec4f) -> main_out { + color = color_param; + main_1(); + return main_out(frag_color); + } + */ __gshared char[376] FS_SOURCE_WGSL = [ 0x64,0x69,0x61,0x67,0x6e,0x6f,0x73,0x74,0x69,0x63,0x28,0x6f,0x66,0x66,0x2c,0x20, @@ -492,57 +495,51 @@ __gshared char[376] FS_SOURCE_WGSL = [ 0x69,0x6e,0x5f,0x6f,0x75,0x74,0x28,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f, 0x72,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; - -sg.ShaderDesc bufferoffsets_shader_desc(sg.Backend backend) @trusted @nogc nothrow { - sg.ShaderDesc desc; - switch (backend) { - case sg.Backend.Glcore33: - desc.attrs[0].name = "position"; - desc.attrs[1].name = "color0"; - desc.vs.source = &VS_SOURCE_GLSL330[0]; - desc.vs.entry = "main"; - desc.fs.source = &FS_SOURCE_GLSL330[0]; - desc.fs.entry = "main"; - desc.label = "bufferoffsets_shader"; - break; - case sg.Backend.Gles3: - desc.attrs[0].name = "position"; - desc.attrs[1].name = "color0"; - desc.vs.source = &VS_SOURCE_GLSL300ES[0]; - desc.vs.entry = "main"; - desc.fs.source = &FS_SOURCE_GLSL300ES[0]; - desc.fs.entry = "main"; - desc.label = "bufferoffsets_shader"; - break; - case sg.Backend.D3d11: - desc.attrs[0].sem_name = "TEXCOORD"; - desc.attrs[0].sem_index = 0; - desc.attrs[1].sem_name = "TEXCOORD"; - desc.attrs[1].sem_index = 1; - desc.vs.source = &VS_SOURCE_HLSL4[0]; - desc.vs.d3d11_target = "vs_4_0"; - desc.vs.entry = "main"; - desc.fs.source = &FS_SOURCE_HLSL4[0]; - desc.fs.d3d11_target = "ps_4_0"; - desc.fs.entry = "main"; - desc.label = "bufferoffsets_shader"; - break; - case sg.Backend.Metal_macos: - desc.vs.source = &VS_SOURCE_METAL_MACOS[0]; - desc.vs.entry = "main0"; - desc.fs.source = &FS_SOURCE_METAL_MACOS[0]; - desc.fs.entry = "main0"; - desc.label = "bufferoffsets_shader"; - break; - case sg.Backend.Wgpu: - desc.vs.source = &VS_SOURCE_WGSL[0]; - desc.vs.entry = "main"; - desc.fs.source = &FS_SOURCE_WGSL[0]; - desc.fs.entry = "main"; - desc.label = "bufferoffsets_shader"; - break; - default: - break; - } - return desc; +sg.ShaderDesc bufferoffsetsShaderDesc(sg.Backend backend) @trusted @nogc nothrow { + sg.ShaderDesc desc; + desc.label = "bufferoffsets_shader"; + switch (backend) { + case sg.Backend.Glcore: + desc.attrs[0].name = "position"; + desc.attrs[1].name = "color0"; + desc.vs.source = &VS_SOURCE_GLSL430[0]; + desc.vs.entry = "main"; + desc.fs.source = &FS_SOURCE_GLSL430[0]; + desc.fs.entry = "main"; + break; + case sg.Backend.Gles3: + desc.attrs[0].name = "position"; + desc.attrs[1].name = "color0"; + desc.vs.source = &VS_SOURCE_GLSL300ES[0]; + desc.vs.entry = "main"; + desc.fs.source = &FS_SOURCE_GLSL300ES[0]; + desc.fs.entry = "main"; + break; + case sg.Backend.D3d11: + desc.attrs[0].sem_name = "TEXCOORD"; + desc.attrs[0].sem_index = 0; + desc.attrs[1].sem_name = "TEXCOORD"; + desc.attrs[1].sem_index = 1; + desc.vs.source = &VS_SOURCE_HLSL4[0]; + desc.vs.d3d11_target = "vs_4_0"; + desc.vs.entry = "main"; + desc.fs.source = &FS_SOURCE_HLSL4[0]; + desc.fs.d3d11_target = "ps_4_0"; + desc.fs.entry = "main"; + break; + case sg.Backend.Metal_macos: + desc.vs.source = &VS_SOURCE_METAL_MACOS[0]; + desc.vs.entry = "main0"; + desc.fs.source = &FS_SOURCE_METAL_MACOS[0]; + desc.fs.entry = "main0"; + break; + case sg.Backend.Wgpu: + desc.vs.source = &VS_SOURCE_WGSL[0]; + desc.vs.entry = "main"; + desc.fs.source = &FS_SOURCE_WGSL[0]; + desc.fs.entry = "main"; + break; + default: break; + } + return desc; } diff --git a/src/shaders/cube.d b/src/shaders/cube.d index 61ea232..a7b52a0 100644 --- a/src/shaders/cube.d +++ b/src/shaders/cube.d @@ -1,105 +1,107 @@ module shaders.cube; import sg = sokol.gfx; +import m = handmade.math; extern(C): /* #version:1# (machine generated, don't edit!) - + Generated by sokol-shdc (https://github.com/floooh/sokol-tools) - - Cmdline: sokol-shdc -i src/shaders/cube.glsl -o src/shaders/cube.d -l glsl330:metal_macos:hlsl4:glsl300es:wgsl -f sokol_d - + + Cmdline: + sokol-shdc -i src/shaders/cube.glsl -o src/shaders/cube.d -l glsl430:metal_macos:hlsl4:glsl300es:wgsl -f sokol_d + Overview: - - Shader program 'cube': - Get shader desc: cube_shader_desc(sg.query_backend()); - Vertex shader: vs - Attribute slots: - ATTR_VS_POSITION = 0 - ATTR_VS_COLOR0 = 1 - Uniform block 'vs_params': - C struct: vs_params_t - Bind slot: SLOT_VS_PARAMS = 0 - Fragment shader: fs - + ========= + Shader program: 'cube': + Get shader desc: cubeShaderDesc(sg.queryBackend()); + Vertex shader: vs + Attributes: + ATTR_VS_POSITION => 0 + ATTR_VS_COLOR0 => 1 + Uniform block 'vs_params': + D struct: VsParams + Bind slot: SLOT_VS_PARAMS => 0 + Fragment shader: fs */ -import m = handmade.math; enum ATTR_VS_POSITION = 0; enum ATTR_VS_COLOR0 = 1; enum SLOT_VS_PARAMS = 0; struct VsParams { - m.Mat4 mvp; + align(16) m.Mat4 mvp; } /* - #version 330 - - uniform vec4 vs_params[4]; - layout(location = 0) in vec4 position; - out vec4 color; - layout(location = 1) in vec4 color0; - - void main() - { - gl_Position = mat4(vs_params[0], vs_params[1], vs_params[2], vs_params[3]) * position; - color = color0; - } - + #version 430 + + uniform vec4 vs_params[4]; + layout(location = 0) in vec4 position; + layout(location = 0) out vec4 color; + layout(location = 1) in vec4 color0; + + void main() + { + gl_Position = mat4(vs_params[0], vs_params[1], vs_params[2], vs_params[3]) * position; + color = color0; + } + */ -__gshared char[263] VS_SOURCE_GLSL330 = [ - 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x33,0x30,0x0a,0x0a,0x75,0x6e, +__gshared char[284] VS_SOURCE_GLSL430 = [ + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x75,0x6e, 0x69,0x66,0x6f,0x72,0x6d,0x20,0x76,0x65,0x63,0x34,0x20,0x76,0x73,0x5f,0x70,0x61, 0x72,0x61,0x6d,0x73,0x5b,0x34,0x5d,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28, 0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e, 0x20,0x76,0x65,0x63,0x34,0x20,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a, - 0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a, 0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20, - 0x3d,0x20,0x31,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c, - 0x6f,0x72,0x30,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28, - 0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74, - 0x69,0x6f,0x6e,0x20,0x3d,0x20,0x6d,0x61,0x74,0x34,0x28,0x76,0x73,0x5f,0x70,0x61, - 0x72,0x61,0x6d,0x73,0x5b,0x30,0x5d,0x2c,0x20,0x76,0x73,0x5f,0x70,0x61,0x72,0x61, - 0x6d,0x73,0x5b,0x31,0x5d,0x2c,0x20,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73, - 0x5b,0x32,0x5d,0x2c,0x20,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x33, - 0x5d,0x29,0x20,0x2a,0x20,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72, - 0x30,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, + 0x3d,0x20,0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x6f, + 0x6c,0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61, + 0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63, + 0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20, + 0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f, + 0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x6d,0x61,0x74,0x34,0x28, + 0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x30,0x5d,0x2c,0x20,0x76,0x73, + 0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x31,0x5d,0x2c,0x20,0x76,0x73,0x5f,0x70, + 0x61,0x72,0x61,0x6d,0x73,0x5b,0x32,0x5d,0x2c,0x20,0x76,0x73,0x5f,0x70,0x61,0x72, + 0x61,0x6d,0x73,0x5b,0x33,0x5d,0x29,0x20,0x2a,0x20,0x70,0x6f,0x73,0x69,0x74,0x69, + 0x6f,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20, + 0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - #version 330 - - layout(location = 0) out vec4 frag_color; - in vec4 color; - - void main() - { - frag_color = color; - } - + #version 430 + + layout(location = 0) out vec4 frag_color; + layout(location = 0) in vec4 color; + + void main() + { + frag_color = color; + } + */ -__gshared char[114] FS_SOURCE_GLSL330 = [ - 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x33,0x30,0x0a,0x0a,0x6c,0x61, +__gshared char[135] FS_SOURCE_GLSL430 = [ + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x6c,0x61, 0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, 0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x66,0x72,0x61,0x67, - 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20, - 0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69, - 0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x63, - 0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x7d,0x0a, - 0x0a,0x00, + 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c, + 0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e,0x20, + 0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x0a,0x76,0x6f,0x69, + 0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f, + 0x72,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - #version 300 es - - uniform vec4 vs_params[4]; - layout(location = 0) in vec4 position; - out vec4 color; - layout(location = 1) in vec4 color0; - - void main() - { - gl_Position = mat4(vs_params[0], vs_params[1], vs_params[2], vs_params[3]) * position; - color = color0; - } - + #version 300 es + + uniform vec4 vs_params[4]; + layout(location = 0) in vec4 position; + out vec4 color; + layout(location = 1) in vec4 color0; + + void main() + { + gl_Position = mat4(vs_params[0], vs_params[1], vs_params[2], vs_params[3]) * position; + color = color0; + } + */ __gshared char[266] VS_SOURCE_GLSL300ES = [ 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x30,0x30,0x20,0x65,0x73,0x0a, @@ -121,18 +123,18 @@ __gshared char[266] VS_SOURCE_GLSL300ES = [ 0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - #version 300 es - precision mediump float; - precision highp int; - - layout(location = 0) out highp vec4 frag_color; - in highp vec4 color; - - void main() - { - frag_color = color; - } - + #version 300 es + precision mediump float; + precision highp int; + + layout(location = 0) out highp vec4 frag_color; + in highp vec4 color; + + void main() + { + frag_color = color; + } + */ __gshared char[175] FS_SOURCE_GLSL300ES = [ 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x30,0x30,0x20,0x65,0x73,0x0a, @@ -148,45 +150,45 @@ __gshared char[175] FS_SOURCE_GLSL300ES = [ 0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - cbuffer vs_params : register(b0) - { - row_major float4x4 _19_mvp : packoffset(c0); - }; - - - static float4 gl_Position; - static float4 position; - static float4 color; - static float4 color0; - - struct SPIRV_Cross_Input - { - float4 position : TEXCOORD0; - float4 color0 : TEXCOORD1; - }; - - struct SPIRV_Cross_Output - { - float4 color : TEXCOORD0; - float4 gl_Position : SV_Position; - }; - - void vert_main() - { - gl_Position = mul(position, _19_mvp); - color = color0; - } - - SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) - { - position = stage_input.position; - color0 = stage_input.color0; - vert_main(); - SPIRV_Cross_Output stage_output; - stage_output.gl_Position = gl_Position; - stage_output.color = color; - return stage_output; - } + cbuffer vs_params : register(b0) + { + row_major float4x4 _19_mvp : packoffset(c0); + }; + + + static float4 gl_Position; + static float4 position; + static float4 color; + static float4 color0; + + struct SPIRV_Cross_Input + { + float4 position : TEXCOORD0; + float4 color0 : TEXCOORD1; + }; + + struct SPIRV_Cross_Output + { + float4 color : TEXCOORD0; + float4 gl_Position : SV_Position; + }; + + void vert_main() + { + gl_Position = mul(position, _19_mvp); + color = color0; + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + position = stage_input.position; + color0 = stage_input.color0; + vert_main(); + SPIRV_Cross_Output stage_output; + stage_output.gl_Position = gl_Position; + stage_output.color = color; + return stage_output; + } */ __gshared char[748] VS_SOURCE_HLSL4 = [ 0x63,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d, @@ -238,32 +240,32 @@ __gshared char[748] VS_SOURCE_HLSL4 = [ 0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x00, ]; /* - static float4 frag_color; - static float4 color; - - struct SPIRV_Cross_Input - { - float4 color : TEXCOORD0; - }; - - struct SPIRV_Cross_Output - { - float4 frag_color : SV_Target0; - }; - - void frag_main() - { - frag_color = color; - } - - SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) - { - color = stage_input.color; - frag_main(); - SPIRV_Cross_Output stage_output; - stage_output.frag_color = frag_color; - return stage_output; - } + static float4 frag_color; + static float4 color; + + struct SPIRV_Cross_Input + { + float4 color : TEXCOORD0; + }; + + struct SPIRV_Cross_Output + { + float4 frag_color : SV_Target0; + }; + + void frag_main() + { + frag_color = color; + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + color = stage_input.color; + frag_main(); + SPIRV_Cross_Output stage_output; + stage_output.frag_color = frag_color; + return stage_output; + } */ __gshared char[435] FS_SOURCE_HLSL4 = [ 0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x66,0x72, @@ -296,36 +298,36 @@ __gshared char[435] FS_SOURCE_HLSL4 = [ 0x7d,0x0a,0x00, ]; /* - #include - #include - - using namespace metal; - - struct vs_params - { - float4x4 mvp; - }; - - struct main0_out - { - float4 color [[user(locn0)]]; - float4 gl_Position [[position]]; - }; - - struct main0_in - { - float4 position [[attribute(0)]]; - float4 color0 [[attribute(1)]]; - }; - - vertex main0_out main0(main0_in in [[stage_in]], constant vs_params& _19 [[buffer(0)]]) - { - main0_out out = {}; - out.gl_Position = _19.mvp * in.position; - out.color = in.color0; - return out; - } - + #include + #include + + using namespace metal; + + struct vs_params + { + float4x4 mvp; + }; + + struct main0_out + { + float4 color [[user(locn0)]]; + float4 gl_Position [[position]]; + }; + + struct main0_in + { + float4 position [[attribute(0)]]; + float4 color0 [[attribute(1)]]; + }; + + vertex main0_out main0(main0_in in [[stage_in]], constant vs_params& _19 [[buffer(0)]]) + { + main0_out out = {}; + out.gl_Position = _19.mvp * in.position; + out.color = in.color0; + return out; + } + */ __gshared char[509] VS_SOURCE_METAL_MACOS = [ 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, @@ -362,28 +364,28 @@ __gshared char[509] VS_SOURCE_METAL_MACOS = [ 0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - #include - #include - - using namespace metal; - - struct main0_out - { - float4 frag_color [[color(0)]]; - }; - - struct main0_in - { - float4 color [[user(locn0)]]; - }; - - fragment main0_out main0(main0_in in [[stage_in]]) - { - main0_out out = {}; - out.frag_color = in.color; - return out; - } - + #include + #include + + using namespace metal; + + struct main0_out + { + float4 frag_color [[color(0)]]; + }; + + struct main0_in + { + float4 color [[user(locn0)]]; + }; + + fragment main0_out main0(main0_in in [[stage_in]]) + { + main0_out out = {}; + out.frag_color = in.color; + return out; + } + */ __gshared char[315] FS_SOURCE_METAL_MACOS = [ 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, @@ -408,47 +410,47 @@ __gshared char[315] FS_SOURCE_METAL_MACOS = [ 0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - diagnostic(off, derivative_uniformity); - - struct vs_params { - /_ @offset(0) _/ - mvp : mat4x4f, - } - - @group(0) @binding(0) var x_19 : vs_params; - - var position_1 : vec4f; - - var color : vec4f; - - var color0 : vec4f; - - var gl_Position : vec4f; - - fn main_1() { - let x_22 : mat4x4f = x_19.mvp; - let x_25 : vec4f = position_1; - gl_Position = (x_22 * x_25); - let x_31 : vec4f = color0; - color = x_31; - return; - } - - struct main_out { - @builtin(position) - gl_Position : vec4f, - @location(0) - color_1 : vec4f, - } - - @vertex - fn main(@location(0) position_1_param : vec4f, @location(1) color0_param : vec4f) -> main_out { - position_1 = position_1_param; - color0 = color0_param; - main_1(); - return main_out(gl_Position, color); - } - + diagnostic(off, derivative_uniformity); + + struct vs_params { + /_ @offset(0) _/ + mvp : mat4x4f, + } + + @group(0) @binding(0) var x_19 : vs_params; + + var position_1 : vec4f; + + var color : vec4f; + + var color0 : vec4f; + + var gl_Position : vec4f; + + fn main_1() { + let x_22 : mat4x4f = x_19.mvp; + let x_25 : vec4f = position_1; + gl_Position = (x_22 * x_25); + let x_31 : vec4f = color0; + color = x_31; + return; + } + + struct main_out { + @builtin(position) + gl_Position : vec4f, + @location(0) + color_1 : vec4f, + } + + @vertex + fn main(@location(0) position_1_param : vec4f, @location(1) color0_param : vec4f) -> main_out { + position_1 = position_1_param; + color0 = color0_param; + main_1(); + return main_out(gl_Position, color); + } + */ __gshared char[766] VS_SOURCE_WGSL = [ 0x64,0x69,0x61,0x67,0x6e,0x6f,0x73,0x74,0x69,0x63,0x28,0x6f,0x66,0x66,0x2c,0x20, @@ -501,30 +503,30 @@ __gshared char[766] VS_SOURCE_WGSL = [ 0x2c,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - diagnostic(off, derivative_uniformity); - - var frag_color : vec4f; - - var color : vec4f; - - fn main_1() { - let x_12 : vec4f = color; - frag_color = x_12; - return; - } - - struct main_out { - @location(0) - frag_color_1 : vec4f, - } - - @fragment - fn main(@location(0) color_param : vec4f) -> main_out { - color = color_param; - main_1(); - return main_out(frag_color); - } - + diagnostic(off, derivative_uniformity); + + var frag_color : vec4f; + + var color : vec4f; + + fn main_1() { + let x_12 : vec4f = color; + frag_color = x_12; + return; + } + + struct main_out { + @location(0) + frag_color_1 : vec4f, + } + + @fragment + fn main(@location(0) color_param : vec4f) -> main_out { + color = color_param; + main_1(); + return main_out(frag_color); + } + */ __gshared char[376] FS_SOURCE_WGSL = [ 0x64,0x69,0x61,0x67,0x6e,0x6f,0x73,0x74,0x69,0x63,0x28,0x6f,0x66,0x66,0x2c,0x20, @@ -552,73 +554,67 @@ __gshared char[376] FS_SOURCE_WGSL = [ 0x69,0x6e,0x5f,0x6f,0x75,0x74,0x28,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f, 0x72,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; - -sg.ShaderDesc cube_shader_desc(sg.Backend backend) @trusted @nogc nothrow { - sg.ShaderDesc desc; - switch (backend) { - case sg.Backend.Glcore33: - desc.attrs[0].name = "position"; - desc.attrs[1].name = "color0"; - desc.vs.source = &VS_SOURCE_GLSL330[0]; - desc.vs.entry = "main"; - desc.vs.uniform_blocks[0].size = 64; - desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; - desc.vs.uniform_blocks[0].uniforms[0].name = "vs_params"; - desc.vs.uniform_blocks[0].uniforms[0].type = sg.UniformType.Float4; - desc.vs.uniform_blocks[0].uniforms[0].array_count = 4; - desc.fs.source = &FS_SOURCE_GLSL330[0]; - desc.fs.entry = "main"; - desc.label = "cube_shader"; - break; - case sg.Backend.Gles3: - desc.attrs[0].name = "position"; - desc.attrs[1].name = "color0"; - desc.vs.source = &VS_SOURCE_GLSL300ES[0]; - desc.vs.entry = "main"; - desc.vs.uniform_blocks[0].size = 64; - desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; - desc.vs.uniform_blocks[0].uniforms[0].name = "vs_params"; - desc.vs.uniform_blocks[0].uniforms[0].type = sg.UniformType.Float4; - desc.vs.uniform_blocks[0].uniforms[0].array_count = 4; - desc.fs.source = &FS_SOURCE_GLSL300ES[0]; - desc.fs.entry = "main"; - desc.label = "cube_shader"; - break; - case sg.Backend.D3d11: - desc.attrs[0].sem_name = "TEXCOORD"; - desc.attrs[0].sem_index = 0; - desc.attrs[1].sem_name = "TEXCOORD"; - desc.attrs[1].sem_index = 1; - desc.vs.source = &VS_SOURCE_HLSL4[0]; - desc.vs.d3d11_target = "vs_4_0"; - desc.vs.entry = "main"; - desc.vs.uniform_blocks[0].size = 64; - desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; - desc.fs.source = &FS_SOURCE_HLSL4[0]; - desc.fs.d3d11_target = "ps_4_0"; - desc.fs.entry = "main"; - desc.label = "cube_shader"; - break; - case sg.Backend.Metal_macos: - desc.vs.source = &VS_SOURCE_METAL_MACOS[0]; - desc.vs.entry = "main0"; - desc.vs.uniform_blocks[0].size = 64; - desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; - desc.fs.source = &FS_SOURCE_METAL_MACOS[0]; - desc.fs.entry = "main0"; - desc.label = "cube_shader"; - break; - case sg.Backend.Wgpu: - desc.vs.source = &VS_SOURCE_WGSL[0]; - desc.vs.entry = "main"; - desc.vs.uniform_blocks[0].size = 64; - desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; - desc.fs.source = &FS_SOURCE_WGSL[0]; - desc.fs.entry = "main"; - desc.label = "cube_shader"; - break; - default: - break; - } - return desc; +sg.ShaderDesc cubeShaderDesc(sg.Backend backend) @trusted @nogc nothrow { + sg.ShaderDesc desc; + desc.label = "cube_shader"; + switch (backend) { + case sg.Backend.Glcore: + desc.attrs[0].name = "position"; + desc.attrs[1].name = "color0"; + desc.vs.source = &VS_SOURCE_GLSL430[0]; + desc.vs.entry = "main"; + desc.vs.uniform_blocks[0].size = 64; + desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; + desc.vs.uniform_blocks[0].uniforms[0].name = "vs_params"; + desc.vs.uniform_blocks[0].uniforms[0].type = sg.UniformType.Float4; + desc.vs.uniform_blocks[0].uniforms[0].array_count = 4; + desc.fs.source = &FS_SOURCE_GLSL430[0]; + desc.fs.entry = "main"; + break; + case sg.Backend.Gles3: + desc.attrs[0].name = "position"; + desc.attrs[1].name = "color0"; + desc.vs.source = &VS_SOURCE_GLSL300ES[0]; + desc.vs.entry = "main"; + desc.vs.uniform_blocks[0].size = 64; + desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; + desc.vs.uniform_blocks[0].uniforms[0].name = "vs_params"; + desc.vs.uniform_blocks[0].uniforms[0].type = sg.UniformType.Float4; + desc.vs.uniform_blocks[0].uniforms[0].array_count = 4; + desc.fs.source = &FS_SOURCE_GLSL300ES[0]; + desc.fs.entry = "main"; + break; + case sg.Backend.D3d11: + desc.attrs[0].sem_name = "TEXCOORD"; + desc.attrs[0].sem_index = 0; + desc.attrs[1].sem_name = "TEXCOORD"; + desc.attrs[1].sem_index = 1; + desc.vs.source = &VS_SOURCE_HLSL4[0]; + desc.vs.d3d11_target = "vs_4_0"; + desc.vs.entry = "main"; + desc.vs.uniform_blocks[0].size = 64; + desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; + desc.fs.source = &FS_SOURCE_HLSL4[0]; + desc.fs.d3d11_target = "ps_4_0"; + desc.fs.entry = "main"; + break; + case sg.Backend.Metal_macos: + desc.vs.source = &VS_SOURCE_METAL_MACOS[0]; + desc.vs.entry = "main0"; + desc.vs.uniform_blocks[0].size = 64; + desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; + desc.fs.source = &FS_SOURCE_METAL_MACOS[0]; + desc.fs.entry = "main0"; + break; + case sg.Backend.Wgpu: + desc.vs.source = &VS_SOURCE_WGSL[0]; + desc.vs.entry = "main"; + desc.vs.uniform_blocks[0].size = 64; + desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; + desc.fs.source = &FS_SOURCE_WGSL[0]; + desc.fs.entry = "main"; + break; + default: break; + } + return desc; } diff --git a/src/shaders/instancing.d b/src/shaders/instancing.d index 3566fdb..ad61440 100644 --- a/src/shaders/instancing.d +++ b/src/shaders/instancing.d @@ -1,112 +1,114 @@ module shaders.instancing; import sg = sokol.gfx; +import m = handmade.math; extern(C): /* #version:1# (machine generated, don't edit!) - + Generated by sokol-shdc (https://github.com/floooh/sokol-tools) - - Cmdline: sokol-shdc -i src/shaders/instancing.glsl -o src/shaders/instancing.d -l glsl330:metal_macos:hlsl4:glsl300es:wgsl -f sokol_d - + + Cmdline: + sokol-shdc -i src/shaders/instancing.glsl -o src/shaders/instancing.d -l glsl430:metal_macos:hlsl4:glsl300es:wgsl -f sokol_d + Overview: - - Shader program 'instancing': - Get shader desc: instancing_shader_desc(sg.query_backend()); - Vertex shader: vs - Attribute slots: - ATTR_VS_POS = 0 - ATTR_VS_COLOR0 = 1 - ATTR_VS_INST_POS = 2 - Uniform block 'vs_params': - C struct: vs_params_t - Bind slot: SLOT_VS_PARAMS = 0 - Fragment shader: fs - + ========= + Shader program: 'instancing': + Get shader desc: instancingShaderDesc(sg.queryBackend()); + Vertex shader: vs + Attributes: + ATTR_VS_POS => 0 + ATTR_VS_COLOR0 => 1 + ATTR_VS_INST_POS => 2 + Uniform block 'vs_params': + D struct: VsParams + Bind slot: SLOT_VS_PARAMS => 0 + Fragment shader: fs */ -import m = handmade.math; enum ATTR_VS_POS = 0; enum ATTR_VS_COLOR0 = 1; enum ATTR_VS_INST_POS = 2; enum SLOT_VS_PARAMS = 0; struct VsParams { - m.Mat4 mvp; + align(16) m.Mat4 mvp; } /* - #version 330 - - uniform vec4 vs_params[4]; - layout(location = 0) in vec3 pos; - layout(location = 2) in vec3 inst_pos; - out vec4 color; - layout(location = 1) in vec4 color0; - - void main() - { - gl_Position = mat4(vs_params[0], vs_params[1], vs_params[2], vs_params[3]) * vec4(pos + inst_pos, 1.0); - color = color0; - } - + #version 430 + + uniform vec4 vs_params[4]; + layout(location = 0) in vec3 pos; + layout(location = 2) in vec3 inst_pos; + layout(location = 0) out vec4 color; + layout(location = 1) in vec4 color0; + + void main() + { + gl_Position = mat4(vs_params[0], vs_params[1], vs_params[2], vs_params[3]) * vec4(pos + inst_pos, 1.0); + color = color0; + } + */ -__gshared char[314] VS_SOURCE_GLSL330 = [ - 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x33,0x30,0x0a,0x0a,0x75,0x6e, +__gshared char[335] VS_SOURCE_GLSL430 = [ + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x75,0x6e, 0x69,0x66,0x6f,0x72,0x6d,0x20,0x76,0x65,0x63,0x34,0x20,0x76,0x73,0x5f,0x70,0x61, 0x72,0x61,0x6d,0x73,0x5b,0x34,0x5d,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28, 0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e, 0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x6f,0x73,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75, 0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x32,0x29,0x20, 0x69,0x6e,0x20,0x76,0x65,0x63,0x33,0x20,0x69,0x6e,0x73,0x74,0x5f,0x70,0x6f,0x73, - 0x3b,0x0a,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72, 0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f, - 0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20,0x63, - 0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69, - 0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73, - 0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x6d,0x61,0x74,0x34,0x28,0x76,0x73,0x5f, - 0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x30,0x5d,0x2c,0x20,0x76,0x73,0x5f,0x70,0x61, - 0x72,0x61,0x6d,0x73,0x5b,0x31,0x5d,0x2c,0x20,0x76,0x73,0x5f,0x70,0x61,0x72,0x61, - 0x6d,0x73,0x5b,0x32,0x5d,0x2c,0x20,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73, - 0x5b,0x33,0x5d,0x29,0x20,0x2a,0x20,0x76,0x65,0x63,0x34,0x28,0x70,0x6f,0x73,0x20, - 0x2b,0x20,0x69,0x6e,0x73,0x74,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x31,0x2e,0x30,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f, - 0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, + 0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20, + 0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f, + 0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x69,0x6e,0x20,0x76, + 0x65,0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x0a,0x76,0x6f,0x69, + 0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67, + 0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x6d,0x61,0x74, + 0x34,0x28,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x30,0x5d,0x2c,0x20, + 0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x31,0x5d,0x2c,0x20,0x76,0x73, + 0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x32,0x5d,0x2c,0x20,0x76,0x73,0x5f,0x70, + 0x61,0x72,0x61,0x6d,0x73,0x5b,0x33,0x5d,0x29,0x20,0x2a,0x20,0x76,0x65,0x63,0x34, + 0x28,0x70,0x6f,0x73,0x20,0x2b,0x20,0x69,0x6e,0x73,0x74,0x5f,0x70,0x6f,0x73,0x2c, + 0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x63,0x6f,0x6c,0x6f,0x72, + 0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - #version 330 - - layout(location = 0) out vec4 frag_color; - in vec4 color; - - void main() - { - frag_color = color; - } - + #version 430 + + layout(location = 0) out vec4 frag_color; + layout(location = 0) in vec4 color; + + void main() + { + frag_color = color; + } + */ -__gshared char[114] FS_SOURCE_GLSL330 = [ - 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x33,0x30,0x0a,0x0a,0x6c,0x61, +__gshared char[135] FS_SOURCE_GLSL430 = [ + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x6c,0x61, 0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, 0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x66,0x72,0x61,0x67, - 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20, - 0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69, - 0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x63, - 0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x7d,0x0a, - 0x0a,0x00, + 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c, + 0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e,0x20, + 0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x0a,0x76,0x6f,0x69, + 0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f, + 0x72,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - #version 300 es - - uniform vec4 vs_params[4]; - layout(location = 0) in vec3 pos; - layout(location = 2) in vec3 inst_pos; - out vec4 color; - layout(location = 1) in vec4 color0; - - void main() - { - gl_Position = mat4(vs_params[0], vs_params[1], vs_params[2], vs_params[3]) * vec4(pos + inst_pos, 1.0); - color = color0; - } - + #version 300 es + + uniform vec4 vs_params[4]; + layout(location = 0) in vec3 pos; + layout(location = 2) in vec3 inst_pos; + out vec4 color; + layout(location = 1) in vec4 color0; + + void main() + { + gl_Position = mat4(vs_params[0], vs_params[1], vs_params[2], vs_params[3]) * vec4(pos + inst_pos, 1.0); + color = color0; + } + */ __gshared char[317] VS_SOURCE_GLSL300ES = [ 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x30,0x30,0x20,0x65,0x73,0x0a, @@ -131,18 +133,18 @@ __gshared char[317] VS_SOURCE_GLSL300ES = [ 0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - #version 300 es - precision mediump float; - precision highp int; - - layout(location = 0) out highp vec4 frag_color; - in highp vec4 color; - - void main() - { - frag_color = color; - } - + #version 300 es + precision mediump float; + precision highp int; + + layout(location = 0) out highp vec4 frag_color; + in highp vec4 color; + + void main() + { + frag_color = color; + } + */ __gshared char[175] FS_SOURCE_GLSL300ES = [ 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x30,0x30,0x20,0x65,0x73,0x0a, @@ -158,48 +160,48 @@ __gshared char[175] FS_SOURCE_GLSL300ES = [ 0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - cbuffer vs_params : register(b0) - { - row_major float4x4 _33_mvp : packoffset(c0); - }; - - - static float4 gl_Position; - static float3 pos; - static float3 inst_pos; - static float4 color; - static float4 color0; - - struct SPIRV_Cross_Input - { - float3 pos : TEXCOORD0; - float4 color0 : TEXCOORD1; - float3 inst_pos : TEXCOORD2; - }; - - struct SPIRV_Cross_Output - { - float4 color : TEXCOORD0; - float4 gl_Position : SV_Position; - }; - - void vert_main() - { - gl_Position = mul(float4(pos + inst_pos, 1.0f), _33_mvp); - color = color0; - } - - SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) - { - pos = stage_input.pos; - inst_pos = stage_input.inst_pos; - color0 = stage_input.color0; - vert_main(); - SPIRV_Cross_Output stage_output; - stage_output.gl_Position = gl_Position; - stage_output.color = color; - return stage_output; - } + cbuffer vs_params : register(b0) + { + row_major float4x4 _33_mvp : packoffset(c0); + }; + + + static float4 gl_Position; + static float3 pos; + static float3 inst_pos; + static float4 color; + static float4 color0; + + struct SPIRV_Cross_Input + { + float3 pos : TEXCOORD0; + float4 color0 : TEXCOORD1; + float3 inst_pos : TEXCOORD2; + }; + + struct SPIRV_Cross_Output + { + float4 color : TEXCOORD0; + float4 gl_Position : SV_Position; + }; + + void vert_main() + { + gl_Position = mul(float4(pos + inst_pos, 1.0f), _33_mvp); + color = color0; + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + pos = stage_input.pos; + inst_pos = stage_input.inst_pos; + color0 = stage_input.color0; + vert_main(); + SPIRV_Cross_Output stage_output; + stage_output.gl_Position = gl_Position; + stage_output.color = color; + return stage_output; + } */ __gshared char[842] VS_SOURCE_HLSL4 = [ 0x63,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d, @@ -257,32 +259,32 @@ __gshared char[842] VS_SOURCE_HLSL4 = [ 0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x00, ]; /* - static float4 frag_color; - static float4 color; - - struct SPIRV_Cross_Input - { - float4 color : TEXCOORD0; - }; - - struct SPIRV_Cross_Output - { - float4 frag_color : SV_Target0; - }; - - void frag_main() - { - frag_color = color; - } - - SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) - { - color = stage_input.color; - frag_main(); - SPIRV_Cross_Output stage_output; - stage_output.frag_color = frag_color; - return stage_output; - } + static float4 frag_color; + static float4 color; + + struct SPIRV_Cross_Input + { + float4 color : TEXCOORD0; + }; + + struct SPIRV_Cross_Output + { + float4 frag_color : SV_Target0; + }; + + void frag_main() + { + frag_color = color; + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + color = stage_input.color; + frag_main(); + SPIRV_Cross_Output stage_output; + stage_output.frag_color = frag_color; + return stage_output; + } */ __gshared char[435] FS_SOURCE_HLSL4 = [ 0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x66,0x72, @@ -315,37 +317,37 @@ __gshared char[435] FS_SOURCE_HLSL4 = [ 0x7d,0x0a,0x00, ]; /* - #include - #include - - using namespace metal; - - struct vs_params - { - float4x4 mvp; - }; - - struct main0_out - { - float4 color [[user(locn0)]]; - float4 gl_Position [[position]]; - }; - - struct main0_in - { - float3 pos [[attribute(0)]]; - float4 color0 [[attribute(1)]]; - float3 inst_pos [[attribute(2)]]; - }; - - vertex main0_out main0(main0_in in [[stage_in]], constant vs_params& _33 [[buffer(0)]]) - { - main0_out out = {}; - out.gl_Position = _33.mvp * float4(in.pos + in.inst_pos, 1.0); - out.color = in.color0; - return out; - } - + #include + #include + + using namespace metal; + + struct vs_params + { + float4x4 mvp; + }; + + struct main0_out + { + float4 color [[user(locn0)]]; + float4 gl_Position [[position]]; + }; + + struct main0_in + { + float3 pos [[attribute(0)]]; + float4 color0 [[attribute(1)]]; + float3 inst_pos [[attribute(2)]]; + }; + + vertex main0_out main0(main0_in in [[stage_in]], constant vs_params& _33 [[buffer(0)]]) + { + main0_out out = {}; + out.gl_Position = _33.mvp * float4(in.pos + in.inst_pos, 1.0); + out.color = in.color0; + return out; + } + */ __gshared char[564] VS_SOURCE_METAL_MACOS = [ 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, @@ -386,28 +388,28 @@ __gshared char[564] VS_SOURCE_METAL_MACOS = [ 0x7d,0x0a,0x0a,0x00, ]; /* - #include - #include - - using namespace metal; - - struct main0_out - { - float4 frag_color [[color(0)]]; - }; - - struct main0_in - { - float4 color [[user(locn0)]]; - }; - - fragment main0_out main0(main0_in in [[stage_in]]) - { - main0_out out = {}; - out.frag_color = in.color; - return out; - } - + #include + #include + + using namespace metal; + + struct main0_out + { + float4 frag_color [[color(0)]]; + }; + + struct main0_in + { + float4 color [[user(locn0)]]; + }; + + fragment main0_out main0(main0_in in [[stage_in]]) + { + main0_out out = {}; + out.frag_color = in.color; + return out; + } + */ __gshared char[315] FS_SOURCE_METAL_MACOS = [ 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, @@ -432,55 +434,55 @@ __gshared char[315] FS_SOURCE_METAL_MACOS = [ 0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - diagnostic(off, derivative_uniformity); - - struct vs_params { - /_ @offset(0) _/ - mvp : mat4x4f, - } - - var pos_1 : vec3f; - - var inst_pos : vec3f; - - @group(0) @binding(0) var x_33 : vs_params; - - var color : vec4f; - - var color0 : vec4f; - - var gl_Position : vec4f; - - fn main_1() { - var pos : vec4f; - let x_13 : vec3f = pos_1; - let x_15 : vec3f = inst_pos; - let x_16 : vec3f = (x_13 + x_15); - pos = vec4f(x_16.x, x_16.y, x_16.z, 1.0f); - let x_36 : mat4x4f = x_33.mvp; - let x_37 : vec4f = pos; - gl_Position = (x_36 * x_37); - let x_44 : vec4f = color0; - color = x_44; - return; - } - - struct main_out { - @builtin(position) - gl_Position : vec4f, - @location(0) - color_1 : vec4f, - } - - @vertex - fn main(@location(0) pos_1_param : vec3f, @location(2) inst_pos_param : vec3f, @location(1) color0_param : vec4f) -> main_out { - pos_1 = pos_1_param; - inst_pos = inst_pos_param; - color0 = color0_param; - main_1(); - return main_out(gl_Position, color); - } - + diagnostic(off, derivative_uniformity); + + struct vs_params { + /_ @offset(0) _/ + mvp : mat4x4f, + } + + var pos_1 : vec3f; + + var inst_pos : vec3f; + + @group(0) @binding(0) var x_33 : vs_params; + + var color : vec4f; + + var color0 : vec4f; + + var gl_Position : vec4f; + + fn main_1() { + var pos : vec4f; + let x_13 : vec3f = pos_1; + let x_15 : vec3f = inst_pos; + let x_16 : vec3f = (x_13 + x_15); + pos = vec4f(x_16.x, x_16.y, x_16.z, 1.0f); + let x_36 : mat4x4f = x_33.mvp; + let x_37 : vec4f = pos; + gl_Position = (x_36 * x_37); + let x_44 : vec4f = color0; + color = x_44; + return; + } + + struct main_out { + @builtin(position) + gl_Position : vec4f, + @location(0) + color_1 : vec4f, + } + + @vertex + fn main(@location(0) pos_1_param : vec3f, @location(2) inst_pos_param : vec3f, @location(1) color0_param : vec4f) -> main_out { + pos_1 = pos_1_param; + inst_pos = inst_pos_param; + color0 = color0_param; + main_1(); + return main_out(gl_Position, color); + } + */ __gshared char[996] VS_SOURCE_WGSL = [ 0x64,0x69,0x61,0x67,0x6e,0x6f,0x73,0x74,0x69,0x63,0x28,0x6f,0x66,0x66,0x2c,0x20, @@ -548,30 +550,30 @@ __gshared char[996] VS_SOURCE_WGSL = [ 0x7d,0x0a,0x0a,0x00, ]; /* - diagnostic(off, derivative_uniformity); - - var frag_color : vec4f; - - var color : vec4f; - - fn main_1() { - let x_12 : vec4f = color; - frag_color = x_12; - return; - } - - struct main_out { - @location(0) - frag_color_1 : vec4f, - } - - @fragment - fn main(@location(0) color_param : vec4f) -> main_out { - color = color_param; - main_1(); - return main_out(frag_color); - } - + diagnostic(off, derivative_uniformity); + + var frag_color : vec4f; + + var color : vec4f; + + fn main_1() { + let x_12 : vec4f = color; + frag_color = x_12; + return; + } + + struct main_out { + @location(0) + frag_color_1 : vec4f, + } + + @fragment + fn main(@location(0) color_param : vec4f) -> main_out { + color = color_param; + main_1(); + return main_out(frag_color); + } + */ __gshared char[376] FS_SOURCE_WGSL = [ 0x64,0x69,0x61,0x67,0x6e,0x6f,0x73,0x74,0x69,0x63,0x28,0x6f,0x66,0x66,0x2c,0x20, @@ -599,77 +601,71 @@ __gshared char[376] FS_SOURCE_WGSL = [ 0x69,0x6e,0x5f,0x6f,0x75,0x74,0x28,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f, 0x72,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; - -sg.ShaderDesc instancing_shader_desc(sg.Backend backend) @trusted @nogc nothrow { - sg.ShaderDesc desc; - switch (backend) { - case sg.Backend.Glcore33: - desc.attrs[0].name = "pos"; - desc.attrs[1].name = "color0"; - desc.attrs[2].name = "inst_pos"; - desc.vs.source = &VS_SOURCE_GLSL330[0]; - desc.vs.entry = "main"; - desc.vs.uniform_blocks[0].size = 64; - desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; - desc.vs.uniform_blocks[0].uniforms[0].name = "vs_params"; - desc.vs.uniform_blocks[0].uniforms[0].type = sg.UniformType.Float4; - desc.vs.uniform_blocks[0].uniforms[0].array_count = 4; - desc.fs.source = &FS_SOURCE_GLSL330[0]; - desc.fs.entry = "main"; - desc.label = "instancing_shader"; - break; - case sg.Backend.Gles3: - desc.attrs[0].name = "pos"; - desc.attrs[1].name = "color0"; - desc.attrs[2].name = "inst_pos"; - desc.vs.source = &VS_SOURCE_GLSL300ES[0]; - desc.vs.entry = "main"; - desc.vs.uniform_blocks[0].size = 64; - desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; - desc.vs.uniform_blocks[0].uniforms[0].name = "vs_params"; - desc.vs.uniform_blocks[0].uniforms[0].type = sg.UniformType.Float4; - desc.vs.uniform_blocks[0].uniforms[0].array_count = 4; - desc.fs.source = &FS_SOURCE_GLSL300ES[0]; - desc.fs.entry = "main"; - desc.label = "instancing_shader"; - break; - case sg.Backend.D3d11: - desc.attrs[0].sem_name = "TEXCOORD"; - desc.attrs[0].sem_index = 0; - desc.attrs[1].sem_name = "TEXCOORD"; - desc.attrs[1].sem_index = 1; - desc.attrs[2].sem_name = "TEXCOORD"; - desc.attrs[2].sem_index = 2; - desc.vs.source = &VS_SOURCE_HLSL4[0]; - desc.vs.d3d11_target = "vs_4_0"; - desc.vs.entry = "main"; - desc.vs.uniform_blocks[0].size = 64; - desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; - desc.fs.source = &FS_SOURCE_HLSL4[0]; - desc.fs.d3d11_target = "ps_4_0"; - desc.fs.entry = "main"; - desc.label = "instancing_shader"; - break; - case sg.Backend.Metal_macos: - desc.vs.source = &VS_SOURCE_METAL_MACOS[0]; - desc.vs.entry = "main0"; - desc.vs.uniform_blocks[0].size = 64; - desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; - desc.fs.source = &FS_SOURCE_METAL_MACOS[0]; - desc.fs.entry = "main0"; - desc.label = "instancing_shader"; - break; - case sg.Backend.Wgpu: - desc.vs.source = &VS_SOURCE_WGSL[0]; - desc.vs.entry = "main"; - desc.vs.uniform_blocks[0].size = 64; - desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; - desc.fs.source = &FS_SOURCE_WGSL[0]; - desc.fs.entry = "main"; - desc.label = "instancing_shader"; - break; - default: - break; - } - return desc; +sg.ShaderDesc instancingShaderDesc(sg.Backend backend) @trusted @nogc nothrow { + sg.ShaderDesc desc; + desc.label = "instancing_shader"; + switch (backend) { + case sg.Backend.Glcore: + desc.attrs[0].name = "pos"; + desc.attrs[1].name = "color0"; + desc.attrs[2].name = "inst_pos"; + desc.vs.source = &VS_SOURCE_GLSL430[0]; + desc.vs.entry = "main"; + desc.vs.uniform_blocks[0].size = 64; + desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; + desc.vs.uniform_blocks[0].uniforms[0].name = "vs_params"; + desc.vs.uniform_blocks[0].uniforms[0].type = sg.UniformType.Float4; + desc.vs.uniform_blocks[0].uniforms[0].array_count = 4; + desc.fs.source = &FS_SOURCE_GLSL430[0]; + desc.fs.entry = "main"; + break; + case sg.Backend.Gles3: + desc.attrs[0].name = "pos"; + desc.attrs[1].name = "color0"; + desc.attrs[2].name = "inst_pos"; + desc.vs.source = &VS_SOURCE_GLSL300ES[0]; + desc.vs.entry = "main"; + desc.vs.uniform_blocks[0].size = 64; + desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; + desc.vs.uniform_blocks[0].uniforms[0].name = "vs_params"; + desc.vs.uniform_blocks[0].uniforms[0].type = sg.UniformType.Float4; + desc.vs.uniform_blocks[0].uniforms[0].array_count = 4; + desc.fs.source = &FS_SOURCE_GLSL300ES[0]; + desc.fs.entry = "main"; + break; + case sg.Backend.D3d11: + desc.attrs[0].sem_name = "TEXCOORD"; + desc.attrs[0].sem_index = 0; + desc.attrs[1].sem_name = "TEXCOORD"; + desc.attrs[1].sem_index = 1; + desc.attrs[2].sem_name = "TEXCOORD"; + desc.attrs[2].sem_index = 2; + desc.vs.source = &VS_SOURCE_HLSL4[0]; + desc.vs.d3d11_target = "vs_4_0"; + desc.vs.entry = "main"; + desc.vs.uniform_blocks[0].size = 64; + desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; + desc.fs.source = &FS_SOURCE_HLSL4[0]; + desc.fs.d3d11_target = "ps_4_0"; + desc.fs.entry = "main"; + break; + case sg.Backend.Metal_macos: + desc.vs.source = &VS_SOURCE_METAL_MACOS[0]; + desc.vs.entry = "main0"; + desc.vs.uniform_blocks[0].size = 64; + desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; + desc.fs.source = &FS_SOURCE_METAL_MACOS[0]; + desc.fs.entry = "main0"; + break; + case sg.Backend.Wgpu: + desc.vs.source = &VS_SOURCE_WGSL[0]; + desc.vs.entry = "main"; + desc.vs.uniform_blocks[0].size = 64; + desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; + desc.fs.source = &FS_SOURCE_WGSL[0]; + desc.fs.entry = "main"; + break; + default: break; + } + return desc; } diff --git a/src/shaders/mrt.d b/src/shaders/mrt.d index efd6d9f..88029ab 100644 --- a/src/shaders/mrt.d +++ b/src/shaders/mrt.d @@ -1,344 +1,345 @@ module shaders.mrt; import sg = sokol.gfx; +import m = handmade.math; extern(C): /* #version:1# (machine generated, don't edit!) - + Generated by sokol-shdc (https://github.com/floooh/sokol-tools) - - Cmdline: sokol-shdc -i src/shaders/mrt.glsl -o src/shaders/mrt.d -l glsl330:metal_macos:hlsl4:glsl300es:wgsl -f sokol_d - + + Cmdline: + sokol-shdc -i src/shaders/mrt.glsl -o src/shaders/mrt.d -l glsl430:metal_macos:hlsl4:glsl300es:wgsl -f sokol_d + Overview: - - Shader program 'dbg': - Get shader desc: dbg_shader_desc(sg.query_backend()); - Vertex shader: vs_dbg - Attribute slots: - ATTR_VS_DBG_POS = 0 - Fragment shader: fs_dbg - Image 'tex': - Type: sg.ImageType._2d - Sample Type: sg.ImageSampleType.Float - Bind slot: SLOT_TEX = 0 - Image 'tex': - Image Type: sg.ImageType._2d - Sample Type: sg.ImageSampleType.Float - Multisampled: false - Bind slot: SLOT_tex = 0 - Sampler 'smp': - Type: sg.SamplerType.Filtering - Bind slot: SLOT_smp = 0 - Image Sampler Pair 'tex_smp': - Image: tex - Sampler: smp - - Shader program 'fsq': - Get shader desc: fsq_shader_desc(sg.query_backend()); - Vertex shader: vs_fsq - Attribute slots: - ATTR_VS_FSQ_POS = 0 - Uniform block 'fsq_params': - C struct: fsq_params_t - Bind slot: SLOT_FSQ_PARAMS = 0 - Fragment shader: fs_fsq - Image 'tex0': - Type: sg.ImageType._2d - Sample Type: sg.ImageSampleType.Float - Bind slot: SLOT_TEX0 = 0 - Image 'tex1': - Type: sg.ImageType._2d - Sample Type: sg.ImageSampleType.Float - Bind slot: SLOT_TEX1 = 1 - Image 'tex2': - Type: sg.ImageType._2d - Sample Type: sg.ImageSampleType.Float - Bind slot: SLOT_TEX2 = 2 - Image 'tex0': - Image Type: sg.ImageType._2d - Sample Type: sg.ImageSampleType.Float - Multisampled: false - Bind slot: SLOT_tex0 = 0 - Image 'tex1': - Image Type: sg.ImageType._2d - Sample Type: sg.ImageSampleType.Float - Multisampled: false - Bind slot: SLOT_tex1 = 1 - Image 'tex2': - Image Type: sg.ImageType._2d - Sample Type: sg.ImageSampleType.Float - Multisampled: false - Bind slot: SLOT_tex2 = 2 - Sampler 'smp': - Type: sg.SamplerType.Filtering - Bind slot: SLOT_smp = 0 - Image Sampler Pair 'tex0_smp': - Image: tex0 - Sampler: smp - Image Sampler Pair 'tex1_smp': - Image: tex1 - Sampler: smp - Image Sampler Pair 'tex2_smp': - Image: tex2 - Sampler: smp - - Shader program 'offscreen': - Get shader desc: offscreen_shader_desc(sg.query_backend()); - Vertex shader: vs_offscreen - Attribute slots: - ATTR_VS_OFFSCREEN_POS = 0 - ATTR_VS_OFFSCREEN_BRIGHT0 = 1 - Uniform block 'offscreen_params': - C struct: offscreen_params_t - Bind slot: SLOT_OFFSCREEN_PARAMS = 0 - Fragment shader: fs_offscreen - + ========= + Shader program: 'dbg': + Get shader desc: dbgShaderDesc(sg.queryBackend()); + Vertex shader: vs_dbg + Attributes: + ATTR_VS_DBG_POS => 0 + Fragment shader: fs_dbg + Image 'tex': + Image type: sg.ImageType._2d + Sample type: sg.ImageSampleType.Float + Multisampled: false + Bind slot: SLOT_TEX => 0 + Sampler 'smp': + Type: sg.SamplerType.Filtering + Bind slot: SLOT_SMP => 0 + Image Sampler Pair 'tex_smp': + Image: tex + Sampler: smp + Shader program: 'fsq': + Get shader desc: fsqShaderDesc(sg.queryBackend()); + Vertex shader: vs_fsq + Attributes: + ATTR_VS_FSQ_POS => 0 + Uniform block 'fsq_params': + D struct: FsqParams + Bind slot: SLOT_FSQ_PARAMS => 0 + Fragment shader: fs_fsq + Image 'tex0': + Image type: sg.ImageType._2d + Sample type: sg.ImageSampleType.Float + Multisampled: false + Bind slot: SLOT_TEX0 => 0 + Image 'tex1': + Image type: sg.ImageType._2d + Sample type: sg.ImageSampleType.Float + Multisampled: false + Bind slot: SLOT_TEX1 => 1 + Image 'tex2': + Image type: sg.ImageType._2d + Sample type: sg.ImageSampleType.Float + Multisampled: false + Bind slot: SLOT_TEX2 => 2 + Sampler 'smp': + Type: sg.SamplerType.Filtering + Bind slot: SLOT_SMP => 0 + Image Sampler Pair 'tex0_smp': + Image: tex0 + Sampler: smp + Image Sampler Pair 'tex1_smp': + Image: tex1 + Sampler: smp + Image Sampler Pair 'tex2_smp': + Image: tex2 + Sampler: smp + Shader program: 'offscreen': + Get shader desc: offscreenShaderDesc(sg.queryBackend()); + Vertex shader: vs_offscreen + Attributes: + ATTR_VS_OFFSCREEN_POS => 0 + ATTR_VS_OFFSCREEN_BRIGHT0 => 1 + Uniform block 'offscreen_params': + D struct: OffscreenParams + Bind slot: SLOT_OFFSCREEN_PARAMS => 0 + Fragment shader: fs_offscreen */ -import m = handmade.math; +enum ATTR_VS_DBG_POS = 0; +enum ATTR_VS_FSQ_POS = 0; enum ATTR_VS_OFFSCREEN_POS = 0; enum ATTR_VS_OFFSCREEN_BRIGHT0 = 1; -enum ATTR_VS_FSQ_POS = 0; -enum ATTR_VS_DBG_POS = 0; +enum SLOT_OFFSCREEN_PARAMS = 0; +enum SLOT_FSQ_PARAMS = 0; enum SLOT_TEX0 = 0; enum SLOT_TEX1 = 1; enum SLOT_TEX2 = 2; enum SLOT_TEX = 0; enum SLOT_SMP = 0; -enum SLOT_OFFSCREEN_PARAMS = 0; struct OffscreenParams { - m.Mat4 mvp; + align(16) m.Mat4 mvp; } -enum SLOT_FSQ_PARAMS = 0; struct FsqParams { - m.Vec2 offset; - ubyte[8] _pad_8; + align(16) m.Vec2 offset; + align(1) ubyte[8] _pad_8 = 0; } /* - #version 330 - - uniform vec4 offscreen_params[4]; - layout(location = 0) in vec4 pos; - out float bright; - layout(location = 1) in float bright0; - - void main() - { - gl_Position = mat4(offscreen_params[0], offscreen_params[1], offscreen_params[2], offscreen_params[3]) * pos; - bright = bright0; - } - + #version 430 + + uniform vec4 offscreen_params[4]; + layout(location = 0) in vec4 pos; + layout(location = 0) out float bright; + layout(location = 1) in float bright0; + + void main() + { + gl_Position = mat4(offscreen_params[0], offscreen_params[1], offscreen_params[2], offscreen_params[3]) * pos; + bright = bright0; + } + */ -__gshared char[294] VS_OFFSCREEN_SOURCE_GLSL330 = [ - 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x33,0x30,0x0a,0x0a,0x75,0x6e, +__gshared char[315] VS_OFFSCREEN_SOURCE_GLSL430 = [ + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x75,0x6e, 0x69,0x66,0x6f,0x72,0x6d,0x20,0x76,0x65,0x63,0x34,0x20,0x6f,0x66,0x66,0x73,0x63, 0x72,0x65,0x65,0x6e,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x34,0x5d,0x3b,0x0a, 0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20, 0x3d,0x20,0x30,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20,0x70,0x6f,0x73, - 0x3b,0x0a,0x6f,0x75,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x62,0x72,0x69,0x67, - 0x68,0x74,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74, - 0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x69,0x6e,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x62,0x72,0x69,0x67,0x68,0x74,0x30,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64, - 0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c, - 0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x6d,0x61,0x74,0x34, - 0x28,0x6f,0x66,0x66,0x73,0x63,0x72,0x65,0x65,0x6e,0x5f,0x70,0x61,0x72,0x61,0x6d, - 0x73,0x5b,0x30,0x5d,0x2c,0x20,0x6f,0x66,0x66,0x73,0x63,0x72,0x65,0x65,0x6e,0x5f, - 0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x31,0x5d,0x2c,0x20,0x6f,0x66,0x66,0x73,0x63, - 0x72,0x65,0x65,0x6e,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x32,0x5d,0x2c,0x20, + 0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f, + 0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x62,0x72,0x69,0x67,0x68,0x74,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28, + 0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x69,0x6e, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x62,0x72,0x69,0x67,0x68,0x74,0x30,0x3b,0x0a, + 0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d, + 0x20,0x6d,0x61,0x74,0x34,0x28,0x6f,0x66,0x66,0x73,0x63,0x72,0x65,0x65,0x6e,0x5f, + 0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x30,0x5d,0x2c,0x20,0x6f,0x66,0x66,0x73,0x63, + 0x72,0x65,0x65,0x6e,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x31,0x5d,0x2c,0x20, 0x6f,0x66,0x66,0x73,0x63,0x72,0x65,0x65,0x6e,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73, - 0x5b,0x33,0x5d,0x29,0x20,0x2a,0x20,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x62,0x72,0x69,0x67,0x68,0x74,0x20,0x3d,0x20,0x62,0x72,0x69,0x67,0x68,0x74,0x30, - 0x3b,0x0a,0x7d,0x0a,0x0a,0x00, + 0x5b,0x32,0x5d,0x2c,0x20,0x6f,0x66,0x66,0x73,0x63,0x72,0x65,0x65,0x6e,0x5f,0x70, + 0x61,0x72,0x61,0x6d,0x73,0x5b,0x33,0x5d,0x29,0x20,0x2a,0x20,0x70,0x6f,0x73,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x62,0x72,0x69,0x67,0x68,0x74,0x20,0x3d,0x20,0x62,0x72, + 0x69,0x67,0x68,0x74,0x30,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - #version 330 - - layout(location = 0) out vec4 frag_color_0; - in float bright; - layout(location = 1) out vec4 frag_color_1; - layout(location = 2) out vec4 frag_color_2; - - void main() - { - frag_color_0 = vec4(bright, 0.0, 0.0, 1.0); - frag_color_1 = vec4(0.0, bright, 0.0, 1.0); - frag_color_2 = vec4(0.0, 0.0, bright, 1.0); - } - + #version 430 + + layout(location = 0) out vec4 frag_color_0; + layout(location = 0) in float bright; + layout(location = 1) out vec4 frag_color_1; + layout(location = 2) out vec4 frag_color_2; + + void main() + { + frag_color_0 = vec4(bright, 0.0, 0.0, 1.0); + frag_color_1 = vec4(0.0, bright, 0.0, 1.0); + frag_color_2 = vec4(0.0, 0.0, bright, 1.0); + } + */ -__gshared char[326] FS_OFFSCREEN_SOURCE_GLSL330 = [ - 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x33,0x30,0x0a,0x0a,0x6c,0x61, +__gshared char[347] FS_OFFSCREEN_SOURCE_GLSL430 = [ + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x6c,0x61, 0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, 0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x66,0x72,0x61,0x67, - 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x5f,0x30,0x3b,0x0a,0x69,0x6e,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x62,0x72,0x69,0x67,0x68,0x74,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75, - 0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20, - 0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f, - 0x6c,0x6f,0x72,0x5f,0x31,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f, - 0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x32,0x29,0x20,0x6f,0x75,0x74,0x20, - 0x76,0x65,0x63,0x34,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x5f, - 0x32,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a, - 0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72, - 0x5f,0x30,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x62,0x72,0x69,0x67,0x68,0x74, - 0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72, - 0x5f,0x31,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x30,0x2e,0x30,0x2c,0x20,0x62, - 0x72,0x69,0x67,0x68,0x74,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72, - 0x5f,0x32,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x30,0x2e,0x30,0x2c,0x20,0x30, - 0x2e,0x30,0x2c,0x20,0x62,0x72,0x69,0x67,0x68,0x74,0x2c,0x20,0x31,0x2e,0x30,0x29, - 0x3b,0x0a,0x7d,0x0a,0x0a,0x00, + 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x5f,0x30,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74, + 0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69, + 0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x62,0x72,0x69,0x67,0x68,0x74,0x3b,0x0a, + 0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20, + 0x3d,0x20,0x31,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x66,0x72, + 0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x5f,0x31,0x3b,0x0a,0x6c,0x61,0x79,0x6f, + 0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x32,0x29, + 0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x66,0x72,0x61,0x67,0x5f,0x63, + 0x6f,0x6c,0x6f,0x72,0x5f,0x32,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61, + 0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f, + 0x63,0x6f,0x6c,0x6f,0x72,0x5f,0x30,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x62, + 0x72,0x69,0x67,0x68,0x74,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x2c, + 0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f, + 0x63,0x6f,0x6c,0x6f,0x72,0x5f,0x31,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x30, + 0x2e,0x30,0x2c,0x20,0x62,0x72,0x69,0x67,0x68,0x74,0x2c,0x20,0x30,0x2e,0x30,0x2c, + 0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f, + 0x63,0x6f,0x6c,0x6f,0x72,0x5f,0x32,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x30, + 0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x62,0x72,0x69,0x67,0x68,0x74,0x2c, + 0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - #version 330 - - uniform vec4 fsq_params[1]; - layout(location = 0) in vec2 pos; - out vec2 uv0; - out vec2 uv1; - out vec2 uv2; - - void main() - { - gl_Position = vec4((pos * 2.0) - vec2(1.0), 0.5, 1.0); - uv0 = pos + vec2(fsq_params[0].x, 0.0); - uv1 = pos + vec2(0.0, fsq_params[0].y); - uv2 = pos; - gl_Position.y = -gl_Position.y; - } - + #version 430 + + uniform vec4 fsq_params[1]; + layout(location = 0) in vec2 pos; + layout(location = 0) out vec2 uv0; + layout(location = 1) out vec2 uv1; + layout(location = 2) out vec2 uv2; + + void main() + { + gl_Position = vec4((pos * 2.0) - vec2(1.0), 0.5, 1.0); + uv0 = pos + vec2(fsq_params[0].x, 0.0); + uv1 = pos + vec2(0.0, fsq_params[0].y); + uv2 = pos; + gl_Position.y = -gl_Position.y; + } + */ -__gshared char[335] VS_FSQ_SOURCE_GLSL330 = [ - 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x33,0x30,0x0a,0x0a,0x75,0x6e, +__gshared char[398] VS_FSQ_SOURCE_GLSL430 = [ + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x75,0x6e, 0x69,0x66,0x6f,0x72,0x6d,0x20,0x76,0x65,0x63,0x34,0x20,0x66,0x73,0x71,0x5f,0x70, 0x61,0x72,0x61,0x6d,0x73,0x5b,0x31,0x5d,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74, 0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69, - 0x6e,0x20,0x76,0x65,0x63,0x32,0x20,0x70,0x6f,0x73,0x3b,0x0a,0x6f,0x75,0x74,0x20, - 0x76,0x65,0x63,0x32,0x20,0x75,0x76,0x30,0x3b,0x0a,0x6f,0x75,0x74,0x20,0x76,0x65, - 0x63,0x32,0x20,0x75,0x76,0x31,0x3b,0x0a,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x32, - 0x20,0x75,0x76,0x32,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e, - 0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69, - 0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x28,0x70,0x6f,0x73, - 0x20,0x2a,0x20,0x32,0x2e,0x30,0x29,0x20,0x2d,0x20,0x76,0x65,0x63,0x32,0x28,0x31, - 0x2e,0x30,0x29,0x2c,0x20,0x30,0x2e,0x35,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x75,0x76,0x30,0x20,0x3d,0x20,0x70,0x6f,0x73,0x20,0x2b,0x20, - 0x76,0x65,0x63,0x32,0x28,0x66,0x73,0x71,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b, - 0x30,0x5d,0x2e,0x78,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x75,0x76,0x31,0x20,0x3d,0x20,0x70,0x6f,0x73,0x20,0x2b,0x20,0x76,0x65,0x63,0x32, - 0x28,0x30,0x2e,0x30,0x2c,0x20,0x66,0x73,0x71,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73, - 0x5b,0x30,0x5d,0x2e,0x79,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x75,0x76,0x32,0x20, - 0x3d,0x20,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f, - 0x73,0x69,0x74,0x69,0x6f,0x6e,0x2e,0x79,0x20,0x3d,0x20,0x2d,0x67,0x6c,0x5f,0x50, - 0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x2e,0x79,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, + 0x6e,0x20,0x76,0x65,0x63,0x32,0x20,0x70,0x6f,0x73,0x3b,0x0a,0x6c,0x61,0x79,0x6f, + 0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29, + 0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x32,0x20,0x75,0x76,0x30,0x3b,0x0a,0x6c, + 0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d, + 0x20,0x31,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x32,0x20,0x75,0x76,0x31, + 0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f, + 0x6e,0x20,0x3d,0x20,0x32,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x32,0x20, + 0x75,0x76,0x32,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28, + 0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74, + 0x69,0x6f,0x6e,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x28,0x70,0x6f,0x73,0x20, + 0x2a,0x20,0x32,0x2e,0x30,0x29,0x20,0x2d,0x20,0x76,0x65,0x63,0x32,0x28,0x31,0x2e, + 0x30,0x29,0x2c,0x20,0x30,0x2e,0x35,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x75,0x76,0x30,0x20,0x3d,0x20,0x70,0x6f,0x73,0x20,0x2b,0x20,0x76, + 0x65,0x63,0x32,0x28,0x66,0x73,0x71,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x30, + 0x5d,0x2e,0x78,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x75, + 0x76,0x31,0x20,0x3d,0x20,0x70,0x6f,0x73,0x20,0x2b,0x20,0x76,0x65,0x63,0x32,0x28, + 0x30,0x2e,0x30,0x2c,0x20,0x66,0x73,0x71,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b, + 0x30,0x5d,0x2e,0x79,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x75,0x76,0x32,0x20,0x3d, + 0x20,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73, + 0x69,0x74,0x69,0x6f,0x6e,0x2e,0x79,0x20,0x3d,0x20,0x2d,0x67,0x6c,0x5f,0x50,0x6f, + 0x73,0x69,0x74,0x69,0x6f,0x6e,0x2e,0x79,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - #version 330 - - uniform sampler2D tex0_smp; - uniform sampler2D tex1_smp; - uniform sampler2D tex2_smp; - - in vec2 uv0; - in vec2 uv1; - in vec2 uv2; - layout(location = 0) out vec4 frag_color; - - void main() - { - frag_color = vec4((texture(tex0_smp, uv0).xyz + texture(tex1_smp, uv1).xyz) + texture(tex2_smp, uv2).xyz, 1.0); - } - + #version 430 + + layout(binding = 0) uniform sampler2D tex0_smp; + layout(binding = 1) uniform sampler2D tex1_smp; + layout(binding = 2) uniform sampler2D tex2_smp; + + layout(location = 0) in vec2 uv0; + layout(location = 1) in vec2 uv1; + layout(location = 2) in vec2 uv2; + layout(location = 0) out vec4 frag_color; + + void main() + { + frag_color = vec4((texture(tex0_smp, uv0).xyz + texture(tex1_smp, uv1).xyz) + texture(tex2_smp, uv2).xyz, 1.0); + } + */ -__gshared char[315] FS_FSQ_SOURCE_GLSL330 = [ - 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x33,0x30,0x0a,0x0a,0x75,0x6e, - 0x69,0x66,0x6f,0x72,0x6d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x32,0x44,0x20, - 0x74,0x65,0x78,0x30,0x5f,0x73,0x6d,0x70,0x3b,0x0a,0x75,0x6e,0x69,0x66,0x6f,0x72, - 0x6d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x32,0x44,0x20,0x74,0x65,0x78,0x31, - 0x5f,0x73,0x6d,0x70,0x3b,0x0a,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x73,0x61, - 0x6d,0x70,0x6c,0x65,0x72,0x32,0x44,0x20,0x74,0x65,0x78,0x32,0x5f,0x73,0x6d,0x70, - 0x3b,0x0a,0x0a,0x69,0x6e,0x20,0x76,0x65,0x63,0x32,0x20,0x75,0x76,0x30,0x3b,0x0a, - 0x69,0x6e,0x20,0x76,0x65,0x63,0x32,0x20,0x75,0x76,0x31,0x3b,0x0a,0x69,0x6e,0x20, - 0x76,0x65,0x63,0x32,0x20,0x75,0x76,0x32,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74, - 0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x6f, - 0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c, - 0x6f,0x72,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29, - 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f, - 0x72,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x28,0x74,0x65,0x78,0x74,0x75,0x72, - 0x65,0x28,0x74,0x65,0x78,0x30,0x5f,0x73,0x6d,0x70,0x2c,0x20,0x75,0x76,0x30,0x29, - 0x2e,0x78,0x79,0x7a,0x20,0x2b,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x74, - 0x65,0x78,0x31,0x5f,0x73,0x6d,0x70,0x2c,0x20,0x75,0x76,0x31,0x29,0x2e,0x78,0x79, - 0x7a,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x74,0x65,0x78, - 0x32,0x5f,0x73,0x6d,0x70,0x2c,0x20,0x75,0x76,0x32,0x29,0x2e,0x78,0x79,0x7a,0x2c, - 0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +__gshared char[438] FS_FSQ_SOURCE_GLSL430 = [ + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x6c,0x61, + 0x79,0x6f,0x75,0x74,0x28,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d,0x20,0x30, + 0x29,0x20,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65, + 0x72,0x32,0x44,0x20,0x74,0x65,0x78,0x30,0x5f,0x73,0x6d,0x70,0x3b,0x0a,0x6c,0x61, + 0x79,0x6f,0x75,0x74,0x28,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d,0x20,0x31, + 0x29,0x20,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65, + 0x72,0x32,0x44,0x20,0x74,0x65,0x78,0x31,0x5f,0x73,0x6d,0x70,0x3b,0x0a,0x6c,0x61, + 0x79,0x6f,0x75,0x74,0x28,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d,0x20,0x32, + 0x29,0x20,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65, + 0x72,0x32,0x44,0x20,0x74,0x65,0x78,0x32,0x5f,0x73,0x6d,0x70,0x3b,0x0a,0x0a,0x6c, + 0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d, + 0x20,0x30,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x32,0x20,0x75,0x76,0x30,0x3b, + 0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e, + 0x20,0x3d,0x20,0x31,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x32,0x20,0x75,0x76, + 0x31,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69, + 0x6f,0x6e,0x20,0x3d,0x20,0x32,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x32,0x20, + 0x75,0x76,0x32,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61, + 0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65, + 0x63,0x34,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x0a, + 0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x76, + 0x65,0x63,0x34,0x28,0x28,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x74,0x65,0x78, + 0x30,0x5f,0x73,0x6d,0x70,0x2c,0x20,0x75,0x76,0x30,0x29,0x2e,0x78,0x79,0x7a,0x20, + 0x2b,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x74,0x65,0x78,0x31,0x5f,0x73, + 0x6d,0x70,0x2c,0x20,0x75,0x76,0x31,0x29,0x2e,0x78,0x79,0x7a,0x29,0x20,0x2b,0x20, + 0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x74,0x65,0x78,0x32,0x5f,0x73,0x6d,0x70, + 0x2c,0x20,0x75,0x76,0x32,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x31,0x2e,0x30,0x29, + 0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - #version 330 - - layout(location = 0) in vec2 pos; - out vec2 uv; - - void main() - { - gl_Position = vec4((pos * 2.0) - vec2(1.0), 0.5, 1.0); - uv = pos; - gl_Position.y = -gl_Position.y; - } - + #version 430 + + layout(location = 0) in vec2 pos; + layout(location = 0) out vec2 uv; + + void main() + { + gl_Position = vec4((pos * 2.0) - vec2(1.0), 0.5, 1.0); + uv = pos; + gl_Position.y = -gl_Position.y; + } + */ -__gshared char[189] VS_DBG_SOURCE_GLSL330 = [ - 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x33,0x30,0x0a,0x0a,0x6c,0x61, +__gshared char[210] VS_DBG_SOURCE_GLSL430 = [ + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x6c,0x61, 0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, 0x30,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x32,0x20,0x70,0x6f,0x73,0x3b,0x0a, - 0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x32,0x20,0x75,0x76,0x3b,0x0a,0x0a,0x76,0x6f, - 0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, - 0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x76,0x65, - 0x63,0x34,0x28,0x28,0x70,0x6f,0x73,0x20,0x2a,0x20,0x32,0x2e,0x30,0x29,0x20,0x2d, - 0x20,0x76,0x65,0x63,0x32,0x28,0x31,0x2e,0x30,0x29,0x2c,0x20,0x30,0x2e,0x35,0x2c, - 0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x75,0x76,0x20,0x3d,0x20, - 0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69, - 0x74,0x69,0x6f,0x6e,0x2e,0x79,0x20,0x3d,0x20,0x2d,0x67,0x6c,0x5f,0x50,0x6f,0x73, - 0x69,0x74,0x69,0x6f,0x6e,0x2e,0x79,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, + 0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20, + 0x3d,0x20,0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x32,0x20,0x75,0x76, + 0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e, + 0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x28,0x70,0x6f,0x73,0x20,0x2a,0x20,0x32, + 0x2e,0x30,0x29,0x20,0x2d,0x20,0x76,0x65,0x63,0x32,0x28,0x31,0x2e,0x30,0x29,0x2c, + 0x20,0x30,0x2e,0x35,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x75,0x76,0x20,0x3d,0x20,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c, + 0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x2e,0x79,0x20,0x3d,0x20,0x2d,0x67, + 0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x2e,0x79,0x3b,0x0a,0x7d,0x0a, + 0x0a,0x00, ]; /* - #version 330 - - uniform sampler2D tex_smp; - - layout(location = 0) out vec4 frag_color; - in vec2 uv; - - void main() - { - frag_color = vec4(texture(tex_smp, uv).xyz, 1.0); - } - + #version 430 + + layout(binding = 0) uniform sampler2D tex_smp; + + layout(location = 0) out vec4 frag_color; + layout(location = 0) in vec2 uv; + + void main() + { + frag_color = vec4(texture(tex_smp, uv).xyz, 1.0); + } + */ -__gshared char[169] FS_DBG_SOURCE_GLSL330 = [ - 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x33,0x30,0x0a,0x0a,0x75,0x6e, - 0x69,0x66,0x6f,0x72,0x6d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x32,0x44,0x20, - 0x74,0x65,0x78,0x5f,0x73,0x6d,0x70,0x3b,0x0a,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74, - 0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x6f, - 0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c, - 0x6f,0x72,0x3b,0x0a,0x69,0x6e,0x20,0x76,0x65,0x63,0x32,0x20,0x75,0x76,0x3b,0x0a, - 0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20, - 0x76,0x65,0x63,0x34,0x28,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x74,0x65,0x78, - 0x5f,0x73,0x6d,0x70,0x2c,0x20,0x75,0x76,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x31, - 0x2e,0x30,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +__gshared char[210] FS_DBG_SOURCE_GLSL430 = [ + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x6c,0x61, + 0x79,0x6f,0x75,0x74,0x28,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d,0x20,0x30, + 0x29,0x20,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65, + 0x72,0x32,0x44,0x20,0x74,0x65,0x78,0x5f,0x73,0x6d,0x70,0x3b,0x0a,0x0a,0x6c,0x61, + 0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, + 0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x66,0x72,0x61,0x67, + 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c, + 0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e,0x20, + 0x76,0x65,0x63,0x32,0x20,0x75,0x76,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d, + 0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67, + 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x74,0x65, + 0x78,0x74,0x75,0x72,0x65,0x28,0x74,0x65,0x78,0x5f,0x73,0x6d,0x70,0x2c,0x20,0x75, + 0x76,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x7d,0x0a, + 0x0a,0x00, ]; /* - #version 300 es - - uniform vec4 offscreen_params[4]; - layout(location = 0) in vec4 pos; - out float bright; - layout(location = 1) in float bright0; - - void main() - { - gl_Position = mat4(offscreen_params[0], offscreen_params[1], offscreen_params[2], offscreen_params[3]) * pos; - bright = bright0; - } - + #version 300 es + + uniform vec4 offscreen_params[4]; + layout(location = 0) in vec4 pos; + out float bright; + layout(location = 1) in float bright0; + + void main() + { + gl_Position = mat4(offscreen_params[0], offscreen_params[1], offscreen_params[2], offscreen_params[3]) * pos; + bright = bright0; + } + */ __gshared char[297] VS_OFFSCREEN_SOURCE_GLSL300ES = [ 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x30,0x30,0x20,0x65,0x73,0x0a, @@ -362,22 +363,22 @@ __gshared char[297] VS_OFFSCREEN_SOURCE_GLSL300ES = [ 0x68,0x74,0x30,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - #version 300 es - precision mediump float; - precision highp int; - - layout(location = 0) out highp vec4 frag_color_0; - in highp float bright; - layout(location = 1) out highp vec4 frag_color_1; - layout(location = 2) out highp vec4 frag_color_2; - - void main() - { - frag_color_0 = vec4(bright, 0.0, 0.0, 1.0); - frag_color_1 = vec4(0.0, bright, 0.0, 1.0); - frag_color_2 = vec4(0.0, 0.0, bright, 1.0); - } - + #version 300 es + precision mediump float; + precision highp int; + + layout(location = 0) out highp vec4 frag_color_0; + in highp float bright; + layout(location = 1) out highp vec4 frag_color_1; + layout(location = 2) out highp vec4 frag_color_2; + + void main() + { + frag_color_0 = vec4(bright, 0.0, 0.0, 1.0); + frag_color_1 = vec4(0.0, bright, 0.0, 1.0); + frag_color_2 = vec4(0.0, 0.0, bright, 1.0); + } + */ __gshared char[399] FS_OFFSCREEN_SOURCE_GLSL300ES = [ 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x30,0x30,0x20,0x65,0x73,0x0a, @@ -407,23 +408,23 @@ __gshared char[399] FS_OFFSCREEN_SOURCE_GLSL300ES = [ 0x67,0x68,0x74,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - #version 300 es - - uniform vec4 fsq_params[1]; - layout(location = 0) in vec2 pos; - out vec2 uv0; - out vec2 uv1; - out vec2 uv2; - - void main() - { - gl_Position = vec4((pos * 2.0) - vec2(1.0), 0.5, 1.0); - uv0 = pos + vec2(fsq_params[0].x, 0.0); - uv1 = pos + vec2(0.0, fsq_params[0].y); - uv2 = pos; - gl_Position.y = -gl_Position.y; - } - + #version 300 es + + uniform vec4 fsq_params[1]; + layout(location = 0) in vec2 pos; + out vec2 uv0; + out vec2 uv1; + out vec2 uv2; + + void main() + { + gl_Position = vec4((pos * 2.0) - vec2(1.0), 0.5, 1.0); + uv0 = pos + vec2(fsq_params[0].x, 0.0); + uv1 = pos + vec2(0.0, fsq_params[0].y); + uv2 = pos; + gl_Position.y = -gl_Position.y; + } + */ __gshared char[338] VS_FSQ_SOURCE_GLSL300ES = [ 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x30,0x30,0x20,0x65,0x73,0x0a, @@ -450,24 +451,24 @@ __gshared char[338] VS_FSQ_SOURCE_GLSL300ES = [ 0x0a,0x00, ]; /* - #version 300 es - precision mediump float; - precision highp int; - - uniform highp sampler2D tex0_smp; - uniform highp sampler2D tex1_smp; - uniform highp sampler2D tex2_smp; - - in highp vec2 uv0; - in highp vec2 uv1; - in highp vec2 uv2; - layout(location = 0) out highp vec4 frag_color; - - void main() - { - frag_color = vec4((texture(tex0_smp, uv0).xyz + texture(tex1_smp, uv1).xyz) + texture(tex2_smp, uv2).xyz, 1.0); - } - + #version 300 es + precision mediump float; + precision highp int; + + uniform highp sampler2D tex0_smp; + uniform highp sampler2D tex1_smp; + uniform highp sampler2D tex2_smp; + + in highp vec2 uv0; + in highp vec2 uv1; + in highp vec2 uv2; + layout(location = 0) out highp vec4 frag_color; + + void main() + { + frag_color = vec4((texture(tex0_smp, uv0).xyz + texture(tex1_smp, uv1).xyz) + texture(tex2_smp, uv2).xyz, 1.0); + } + */ __gshared char[406] FS_FSQ_SOURCE_GLSL300ES = [ 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x30,0x30,0x20,0x65,0x73,0x0a, @@ -498,18 +499,18 @@ __gshared char[406] FS_FSQ_SOURCE_GLSL300ES = [ 0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - #version 300 es - - layout(location = 0) in vec2 pos; - out vec2 uv; - - void main() - { - gl_Position = vec4((pos * 2.0) - vec2(1.0), 0.5, 1.0); - uv = pos; - gl_Position.y = -gl_Position.y; - } - + #version 300 es + + layout(location = 0) in vec2 pos; + out vec2 uv; + + void main() + { + gl_Position = vec4((pos * 2.0) - vec2(1.0), 0.5, 1.0); + uv = pos; + gl_Position.y = -gl_Position.y; + } + */ __gshared char[192] VS_DBG_SOURCE_GLSL300ES = [ 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x30,0x30,0x20,0x65,0x73,0x0a, @@ -527,20 +528,20 @@ __gshared char[192] VS_DBG_SOURCE_GLSL300ES = [ ]; /* - #version 300 es - precision mediump float; - precision highp int; - - uniform highp sampler2D tex_smp; - - layout(location = 0) out highp vec4 frag_color; - in highp vec2 uv; - - void main() - { - frag_color = vec4(texture(tex_smp, uv).xyz, 1.0); - } - + #version 300 es + precision mediump float; + precision highp int; + + uniform highp sampler2D tex_smp; + + layout(location = 0) out highp vec4 frag_color; + in highp vec2 uv; + + void main() + { + frag_color = vec4(texture(tex_smp, uv).xyz, 1.0); + } + */ __gshared char[236] FS_DBG_SOURCE_GLSL300ES = [ 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x30,0x30,0x20,0x65,0x73,0x0a, @@ -560,45 +561,45 @@ __gshared char[236] FS_DBG_SOURCE_GLSL300ES = [ 0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - cbuffer offscreen_params : register(b0) - { - row_major float4x4 _19_mvp : packoffset(c0); - }; - - - static float4 gl_Position; - static float4 pos; - static float bright; - static float bright0; - - struct SPIRV_Cross_Input - { - float4 pos : TEXCOORD0; - float bright0 : TEXCOORD1; - }; - - struct SPIRV_Cross_Output - { - float bright : TEXCOORD0; - float4 gl_Position : SV_Position; - }; - - void vert_main() - { - gl_Position = mul(pos, _19_mvp); - bright = bright0; - } - - SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) - { - pos = stage_input.pos; - bright0 = stage_input.bright0; - vert_main(); - SPIRV_Cross_Output stage_output; - stage_output.gl_Position = gl_Position; - stage_output.bright = bright; - return stage_output; - } + cbuffer offscreen_params : register(b0) + { + row_major float4x4 _19_mvp : packoffset(c0); + }; + + + static float4 gl_Position; + static float4 pos; + static float bright; + static float bright0; + + struct SPIRV_Cross_Input + { + float4 pos : TEXCOORD0; + float bright0 : TEXCOORD1; + }; + + struct SPIRV_Cross_Output + { + float bright : TEXCOORD0; + float4 gl_Position : SV_Position; + }; + + void vert_main() + { + gl_Position = mul(pos, _19_mvp); + bright = bright0; + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + pos = stage_input.pos; + bright0 = stage_input.bright0; + vert_main(); + SPIRV_Cross_Output stage_output; + stage_output.gl_Position = gl_Position; + stage_output.bright = bright; + return stage_output; + } */ __gshared char[736] VS_OFFSCREEN_SOURCE_HLSL4 = [ 0x63,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x6f,0x66,0x66,0x73,0x63,0x72,0x65,0x65, @@ -650,40 +651,40 @@ __gshared char[736] VS_OFFSCREEN_SOURCE_HLSL4 = [ ]; /* - static float4 frag_color_0; - static float bright; - static float4 frag_color_1; - static float4 frag_color_2; - - struct SPIRV_Cross_Input - { - float bright : TEXCOORD0; - }; - - struct SPIRV_Cross_Output - { - float4 frag_color_0 : SV_Target0; - float4 frag_color_1 : SV_Target1; - float4 frag_color_2 : SV_Target2; - }; - - void frag_main() - { - frag_color_0 = float4(bright, 0.0f, 0.0f, 1.0f); - frag_color_1 = float4(0.0f, bright, 0.0f, 1.0f); - frag_color_2 = float4(0.0f, 0.0f, bright, 1.0f); - } - - SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) - { - bright = stage_input.bright; - frag_main(); - SPIRV_Cross_Output stage_output; - stage_output.frag_color_0 = frag_color_0; - stage_output.frag_color_1 = frag_color_1; - stage_output.frag_color_2 = frag_color_2; - return stage_output; - } + static float4 frag_color_0; + static float bright; + static float4 frag_color_1; + static float4 frag_color_2; + + struct SPIRV_Cross_Input + { + float bright : TEXCOORD0; + }; + + struct SPIRV_Cross_Output + { + float4 frag_color_0 : SV_Target0; + float4 frag_color_1 : SV_Target1; + float4 frag_color_2 : SV_Target2; + }; + + void frag_main() + { + frag_color_0 = float4(bright, 0.0f, 0.0f, 1.0f); + frag_color_1 = float4(0.0f, bright, 0.0f, 1.0f); + frag_color_2 = float4(0.0f, 0.0f, bright, 1.0f); + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + bright = stage_input.bright; + frag_main(); + SPIRV_Cross_Output stage_output; + stage_output.frag_color_0 = frag_color_0; + stage_output.frag_color_1 = frag_color_1; + stage_output.frag_color_2 = frag_color_2; + return stage_output; + } */ __gshared char[804] FS_OFFSCREEN_SOURCE_HLSL4 = [ 0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x66,0x72, @@ -739,50 +740,50 @@ __gshared char[804] FS_OFFSCREEN_SOURCE_HLSL4 = [ 0x0a,0x7d,0x0a,0x00, ]; /* - cbuffer fsq_params : register(b0) - { - float2 _36_offset : packoffset(c0); - }; - - - static float4 gl_Position; - static float2 pos; - static float2 uv0; - static float2 uv1; - static float2 uv2; - - struct SPIRV_Cross_Input - { - float2 pos : TEXCOORD0; - }; - - struct SPIRV_Cross_Output - { - float2 uv0 : TEXCOORD0; - float2 uv1 : TEXCOORD1; - float2 uv2 : TEXCOORD2; - float4 gl_Position : SV_Position; - }; - - void vert_main() - { - gl_Position = float4((pos * 2.0f) - 1.0f.xx, 0.5f, 1.0f); - uv0 = pos + float2(_36_offset.x, 0.0f); - uv1 = pos + float2(0.0f, _36_offset.y); - uv2 = pos; - } - - SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) - { - pos = stage_input.pos; - vert_main(); - SPIRV_Cross_Output stage_output; - stage_output.gl_Position = gl_Position; - stage_output.uv0 = uv0; - stage_output.uv1 = uv1; - stage_output.uv2 = uv2; - return stage_output; - } + cbuffer fsq_params : register(b0) + { + float2 _36_offset : packoffset(c0); + }; + + + static float4 gl_Position; + static float2 pos; + static float2 uv0; + static float2 uv1; + static float2 uv2; + + struct SPIRV_Cross_Input + { + float2 pos : TEXCOORD0; + }; + + struct SPIRV_Cross_Output + { + float2 uv0 : TEXCOORD0; + float2 uv1 : TEXCOORD1; + float2 uv2 : TEXCOORD2; + float4 gl_Position : SV_Position; + }; + + void vert_main() + { + gl_Position = float4((pos * 2.0f) - 1.0f.xx, 0.5f, 1.0f); + uv0 = pos + float2(_36_offset.x, 0.0f); + uv1 = pos + float2(0.0f, _36_offset.y); + uv2 = pos; + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + pos = stage_input.pos; + vert_main(); + SPIRV_Cross_Output stage_output; + stage_output.gl_Position = gl_Position; + stage_output.uv0 = uv0; + stage_output.uv1 = uv1; + stage_output.uv2 = uv2; + return stage_output; + } */ __gshared char[879] VS_FSQ_SOURCE_HLSL4 = [ 0x63,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x66,0x73,0x71,0x5f,0x70,0x61,0x72,0x61, @@ -842,43 +843,43 @@ __gshared char[879] VS_FSQ_SOURCE_HLSL4 = [ 0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x00, ]; /* - Texture2D tex0 : register(t0); - SamplerState smp : register(s0); - Texture2D tex1 : register(t1); - Texture2D tex2 : register(t2); - - static float2 uv0; - static float2 uv1; - static float2 uv2; - static float4 frag_color; - - struct SPIRV_Cross_Input - { - float2 uv0 : TEXCOORD0; - float2 uv1 : TEXCOORD1; - float2 uv2 : TEXCOORD2; - }; - - struct SPIRV_Cross_Output - { - float4 frag_color : SV_Target0; - }; - - void frag_main() - { - frag_color = float4((tex0.Sample(smp, uv0).xyz + tex1.Sample(smp, uv1).xyz) + tex2.Sample(smp, uv2).xyz, 1.0f); - } - - SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) - { - uv0 = stage_input.uv0; - uv1 = stage_input.uv1; - uv2 = stage_input.uv2; - frag_main(); - SPIRV_Cross_Output stage_output; - stage_output.frag_color = frag_color; - return stage_output; - } + Texture2D tex0 : register(t0); + SamplerState smp : register(s0); + Texture2D tex1 : register(t1); + Texture2D tex2 : register(t2); + + static float2 uv0; + static float2 uv1; + static float2 uv2; + static float4 frag_color; + + struct SPIRV_Cross_Input + { + float2 uv0 : TEXCOORD0; + float2 uv1 : TEXCOORD1; + float2 uv2 : TEXCOORD2; + }; + + struct SPIRV_Cross_Output + { + float4 frag_color : SV_Target0; + }; + + void frag_main() + { + frag_color = float4((tex0.Sample(smp, uv0).xyz + tex1.Sample(smp, uv1).xyz) + tex2.Sample(smp, uv2).xyz, 1.0f); + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + uv0 = stage_input.uv0; + uv1 = stage_input.uv1; + uv2 = stage_input.uv2; + frag_main(); + SPIRV_Cross_Output stage_output; + stage_output.frag_color = frag_color; + return stage_output; + } */ __gshared char[818] FS_FSQ_SOURCE_HLSL4 = [ 0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x44,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34, @@ -935,36 +936,36 @@ __gshared char[818] FS_FSQ_SOURCE_HLSL4 = [ 0x0a,0x00, ]; /* - static float4 gl_Position; - static float2 pos; - static float2 uv; - - struct SPIRV_Cross_Input - { - float2 pos : TEXCOORD0; - }; - - struct SPIRV_Cross_Output - { - float2 uv : TEXCOORD0; - float4 gl_Position : SV_Position; - }; - - void vert_main() - { - gl_Position = float4((pos * 2.0f) - 1.0f.xx, 0.5f, 1.0f); - uv = pos; - } - - SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) - { - pos = stage_input.pos; - vert_main(); - SPIRV_Cross_Output stage_output; - stage_output.gl_Position = gl_Position; - stage_output.uv = uv; - return stage_output; - } + static float4 gl_Position; + static float2 pos; + static float2 uv; + + struct SPIRV_Cross_Input + { + float2 pos : TEXCOORD0; + }; + + struct SPIRV_Cross_Output + { + float2 uv : TEXCOORD0; + float4 gl_Position : SV_Position; + }; + + void vert_main() + { + gl_Position = float4((pos * 2.0f) - 1.0f.xx, 0.5f, 1.0f); + uv = pos; + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + pos = stage_input.pos; + vert_main(); + SPIRV_Cross_Output stage_output; + stage_output.gl_Position = gl_Position; + stage_output.uv = uv; + return stage_output; + } */ __gshared char[555] VS_DBG_SOURCE_HLSL4 = [ 0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c, @@ -1004,35 +1005,35 @@ __gshared char[555] VS_DBG_SOURCE_HLSL4 = [ 0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x00, ]; /* - Texture2D tex : register(t0); - SamplerState smp : register(s0); - - static float4 frag_color; - static float2 uv; - - struct SPIRV_Cross_Input - { - float2 uv : TEXCOORD0; - }; - - struct SPIRV_Cross_Output - { - float4 frag_color : SV_Target0; - }; - - void frag_main() - { - frag_color = float4(tex.Sample(smp, uv).xyz, 1.0f); - } - - SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) - { - uv = stage_input.uv; - frag_main(); - SPIRV_Cross_Output stage_output; - stage_output.frag_color = frag_color; - return stage_output; - } + Texture2D tex : register(t0); + SamplerState smp : register(s0); + + static float4 frag_color; + static float2 uv; + + struct SPIRV_Cross_Input + { + float2 uv : TEXCOORD0; + }; + + struct SPIRV_Cross_Output + { + float4 frag_color : SV_Target0; + }; + + void frag_main() + { + frag_color = float4(tex.Sample(smp, uv).xyz, 1.0f); + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + uv = stage_input.uv; + frag_main(); + SPIRV_Cross_Output stage_output; + stage_output.frag_color = frag_color; + return stage_output; + } */ __gshared char[527] FS_DBG_SOURCE_HLSL4 = [ 0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x44,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34, @@ -1070,36 +1071,36 @@ __gshared char[527] FS_DBG_SOURCE_HLSL4 = [ 0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x00, ]; /* - #include - #include - - using namespace metal; - - struct offscreen_params - { - float4x4 mvp; - }; - - struct main0_out - { - float bright [[user(locn0)]]; - float4 gl_Position [[position]]; - }; - - struct main0_in - { - float4 pos [[attribute(0)]]; - float bright0 [[attribute(1)]]; - }; - - vertex main0_out main0(main0_in in [[stage_in]], constant offscreen_params& _19 [[buffer(0)]]) - { - main0_out out = {}; - out.gl_Position = _19.mvp * in.pos; - out.bright = in.bright0; - return out; - } - + #include + #include + + using namespace metal; + + struct offscreen_params + { + float4x4 mvp; + }; + + struct main0_out + { + float bright [[user(locn0)]]; + float4 gl_Position [[position]]; + }; + + struct main0_in + { + float4 pos [[attribute(0)]]; + float bright0 [[attribute(1)]]; + }; + + vertex main0_out main0(main0_in in [[stage_in]], constant offscreen_params& _19 [[buffer(0)]]) + { + main0_out out = {}; + out.gl_Position = _19.mvp * in.pos; + out.bright = in.bright0; + return out; + } + */ __gshared char[515] VS_OFFSCREEN_SOURCE_METAL_MACOS = [ 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, @@ -1137,32 +1138,32 @@ __gshared char[515] VS_OFFSCREEN_SOURCE_METAL_MACOS = [ 0x0a,0x0a,0x00, ]; /* - #include - #include - - using namespace metal; - - struct main0_out - { - float4 frag_color_0 [[color(0)]]; - float4 frag_color_1 [[color(1)]]; - float4 frag_color_2 [[color(2)]]; - }; - - struct main0_in - { - float bright [[user(locn0)]]; - }; - - fragment main0_out main0(main0_in in [[stage_in]]) - { - main0_out out = {}; - out.frag_color_0 = float4(in.bright, 0.0, 0.0, 1.0); - out.frag_color_1 = float4(0.0, in.bright, 0.0, 1.0); - out.frag_color_2 = float4(0.0, 0.0, in.bright, 1.0); - return out; - } - + #include + #include + + using namespace metal; + + struct main0_out + { + float4 frag_color_0 [[color(0)]]; + float4 frag_color_1 [[color(1)]]; + float4 frag_color_2 [[color(2)]]; + }; + + struct main0_in + { + float bright [[user(locn0)]]; + }; + + fragment main0_out main0(main0_in in [[stage_in]]) + { + main0_out out = {}; + out.frag_color_0 = float4(in.bright, 0.0, 0.0, 1.0); + out.frag_color_1 = float4(0.0, in.bright, 0.0, 1.0); + out.frag_color_2 = float4(0.0, 0.0, in.bright, 1.0); + return out; + } + */ __gshared char[533] FS_OFFSCREEN_SOURCE_METAL_MACOS = [ 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, @@ -1201,39 +1202,39 @@ __gshared char[533] FS_OFFSCREEN_SOURCE_METAL_MACOS = [ 0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - #include - #include - - using namespace metal; - - struct fsq_params - { - float2 offset; - }; - - struct main0_out - { - float2 uv0 [[user(locn0)]]; - float2 uv1 [[user(locn1)]]; - float2 uv2 [[user(locn2)]]; - float4 gl_Position [[position]]; - }; - - struct main0_in - { - float2 pos [[attribute(0)]]; - }; - - vertex main0_out main0(main0_in in [[stage_in]], constant fsq_params& _36 [[buffer(0)]]) - { - main0_out out = {}; - out.gl_Position = float4((in.pos * 2.0) - float2(1.0), 0.5, 1.0); - out.uv0 = in.pos + float2(_36.offset.x, 0.0); - out.uv1 = in.pos + float2(0.0, _36.offset.y); - out.uv2 = in.pos; - return out; - } - + #include + #include + + using namespace metal; + + struct fsq_params + { + float2 offset; + }; + + struct main0_out + { + float2 uv0 [[user(locn0)]]; + float2 uv1 [[user(locn1)]]; + float2 uv2 [[user(locn2)]]; + float4 gl_Position [[position]]; + }; + + struct main0_in + { + float2 pos [[attribute(0)]]; + }; + + vertex main0_out main0(main0_in in [[stage_in]], constant fsq_params& _36 [[buffer(0)]]) + { + main0_out out = {}; + out.gl_Position = float4((in.pos * 2.0) - float2(1.0), 0.5, 1.0); + out.uv0 = in.pos + float2(_36.offset.x, 0.0); + out.uv1 = in.pos + float2(0.0, _36.offset.y); + out.uv2 = in.pos; + return out; + } + */ __gshared char[653] VS_FSQ_SOURCE_METAL_MACOS = [ 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, @@ -1279,30 +1280,30 @@ __gshared char[653] VS_FSQ_SOURCE_METAL_MACOS = [ 0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - #include - #include - - using namespace metal; - - struct main0_out - { - float4 frag_color [[color(0)]]; - }; - - struct main0_in - { - float2 uv0 [[user(locn0)]]; - float2 uv1 [[user(locn1)]]; - float2 uv2 [[user(locn2)]]; - }; - - fragment main0_out main0(main0_in in [[stage_in]], texture2d tex0 [[texture(0)]], texture2d tex1 [[texture(1)]], texture2d tex2 [[texture(2)]], sampler smp [[sampler(0)]]) - { - main0_out out = {}; - out.frag_color = float4((tex0.sample(smp, in.uv0).xyz + tex1.sample(smp, in.uv1).xyz) + tex2.sample(smp, in.uv2).xyz, 1.0); - return out; - } - + #include + #include + + using namespace metal; + + struct main0_out + { + float4 frag_color [[color(0)]]; + }; + + struct main0_in + { + float2 uv0 [[user(locn0)]]; + float2 uv1 [[user(locn1)]]; + float2 uv2 [[user(locn2)]]; + }; + + fragment main0_out main0(main0_in in [[stage_in]], texture2d tex0 [[texture(0)]], texture2d tex1 [[texture(1)]], texture2d tex2 [[texture(2)]], sampler smp [[sampler(0)]]) + { + main0_out out = {}; + out.frag_color = float4((tex0.sample(smp, in.uv0).xyz + tex1.sample(smp, in.uv1).xyz) + tex2.sample(smp, in.uv2).xyz, 1.0); + return out; + } + */ __gshared char[616] FS_FSQ_SOURCE_METAL_MACOS = [ 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, @@ -1346,30 +1347,30 @@ __gshared char[616] FS_FSQ_SOURCE_METAL_MACOS = [ 0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - #include - #include - - using namespace metal; - - struct main0_out - { - float2 uv [[user(locn0)]]; - float4 gl_Position [[position]]; - }; - - struct main0_in - { - float2 pos [[attribute(0)]]; - }; - - vertex main0_out main0(main0_in in [[stage_in]]) - { - main0_out out = {}; - out.gl_Position = float4((in.pos * 2.0) - float2(1.0), 0.5, 1.0); - out.uv = in.pos; - return out; - } - + #include + #include + + using namespace metal; + + struct main0_out + { + float2 uv [[user(locn0)]]; + float4 gl_Position [[position]]; + }; + + struct main0_in + { + float2 pos [[attribute(0)]]; + }; + + vertex main0_out main0(main0_in in [[stage_in]]) + { + main0_out out = {}; + out.gl_Position = float4((in.pos * 2.0) - float2(1.0), 0.5, 1.0); + out.uv = in.pos; + return out; + } + */ __gshared char[404] VS_DBG_SOURCE_METAL_MACOS = [ 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, @@ -1400,28 +1401,28 @@ __gshared char[404] VS_DBG_SOURCE_METAL_MACOS = [ 0x7d,0x0a,0x0a,0x00, ]; /* - #include - #include - - using namespace metal; - - struct main0_out - { - float4 frag_color [[color(0)]]; - }; - - struct main0_in - { - float2 uv [[user(locn0)]]; - }; - - fragment main0_out main0(main0_in in [[stage_in]], texture2d tex [[texture(0)]], sampler smp [[sampler(0)]]) - { - main0_out out = {}; - out.frag_color = float4(tex.sample(smp, in.uv).xyz, 1.0); - return out; - } - + #include + #include + + using namespace metal; + + struct main0_out + { + float4 frag_color [[color(0)]]; + }; + + struct main0_in + { + float2 uv [[user(locn0)]]; + }; + + fragment main0_out main0(main0_in in [[stage_in]], texture2d tex [[texture(0)]], sampler smp [[sampler(0)]]) + { + main0_out out = {}; + out.frag_color = float4(tex.sample(smp, in.uv).xyz, 1.0); + return out; + } + */ __gshared char[408] FS_DBG_SOURCE_METAL_MACOS = [ 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, @@ -1452,47 +1453,47 @@ __gshared char[408] FS_DBG_SOURCE_METAL_MACOS = [ 0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - diagnostic(off, derivative_uniformity); - - struct offscreen_params { - /_ @offset(0) _/ - mvp : mat4x4f, - } - - @group(0) @binding(0) var x_19 : offscreen_params; - - var pos : vec4f; - - var bright : f32; - - var bright0 : f32; - - var gl_Position : vec4f; - - fn main_1() { - let x_22 : mat4x4f = x_19.mvp; - let x_25 : vec4f = pos; - gl_Position = (x_22 * x_25); - let x_33 : f32 = bright0; - bright = x_33; - return; - } - - struct main_out { - @builtin(position) - gl_Position : vec4f, - @location(0) - bright_1 : f32, - } - - @vertex - fn main(@location(0) pos_param : vec4f, @location(1) bright0_param : f32) -> main_out { - pos = pos_param; - bright0 = bright0_param; - main_1(); - return main_out(gl_Position, bright); - } - + diagnostic(off, derivative_uniformity); + + struct offscreen_params { + /_ @offset(0) _/ + mvp : mat4x4f, + } + + @group(0) @binding(0) var x_19 : offscreen_params; + + var pos : vec4f; + + var bright : f32; + + var bright0 : f32; + + var gl_Position : vec4f; + + fn main_1() { + let x_22 : mat4x4f = x_19.mvp; + let x_25 : vec4f = pos; + gl_Position = (x_22 * x_25); + let x_33 : f32 = bright0; + bright = x_33; + return; + } + + struct main_out { + @builtin(position) + gl_Position : vec4f, + @location(0) + bright_1 : f32, + } + + @vertex + fn main(@location(0) pos_param : vec4f, @location(1) bright0_param : f32) -> main_out { + pos = pos_param; + bright0 = bright0_param; + main_1(); + return main_out(gl_Position, bright); + } + */ __gshared char[744] VS_OFFSCREEN_SOURCE_WGSL = [ 0x64,0x69,0x61,0x67,0x6e,0x6f,0x73,0x74,0x69,0x63,0x28,0x6f,0x66,0x66,0x2c,0x20, @@ -1544,42 +1545,42 @@ __gshared char[744] VS_OFFSCREEN_SOURCE_WGSL = [ 0x74,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - diagnostic(off, derivative_uniformity); - - var frag_color_0 : vec4f; - - var bright : f32; - - var frag_color_1 : vec4f; - - var frag_color_2 : vec4f; - - fn main_1() { - let x_12 : f32 = bright; - frag_color_0 = vec4f(x_12, 0.0f, 0.0f, 1.0f); - let x_17 : f32 = bright; - frag_color_1 = vec4f(0.0f, x_17, 0.0f, 1.0f); - let x_20 : f32 = bright; - frag_color_2 = vec4f(0.0f, 0.0f, x_20, 1.0f); - return; - } - - struct main_out { - @location(0) - frag_color_0_1 : vec4f, - @location(1) - frag_color_1_1 : vec4f, - @location(2) - frag_color_2_1 : vec4f, - } - - @fragment - fn main(@location(0) bright_param : f32) -> main_out { - bright = bright_param; - main_1(); - return main_out(frag_color_0, frag_color_1, frag_color_2); - } - + diagnostic(off, derivative_uniformity); + + var frag_color_0 : vec4f; + + var bright : f32; + + var frag_color_1 : vec4f; + + var frag_color_2 : vec4f; + + fn main_1() { + let x_12 : f32 = bright; + frag_color_0 = vec4f(x_12, 0.0f, 0.0f, 1.0f); + let x_17 : f32 = bright; + frag_color_1 = vec4f(0.0f, x_17, 0.0f, 1.0f); + let x_20 : f32 = bright; + frag_color_2 = vec4f(0.0f, 0.0f, x_20, 1.0f); + return; + } + + struct main_out { + @location(0) + frag_color_0_1 : vec4f, + @location(1) + frag_color_1_1 : vec4f, + @location(2) + frag_color_2_1 : vec4f, + } + + @fragment + fn main(@location(0) bright_param : f32) -> main_out { + bright = bright_param; + main_1(); + return main_out(frag_color_0, frag_color_1, frag_color_2); + } + */ __gshared char[740] FS_OFFSCREEN_SOURCE_WGSL = [ 0x64,0x69,0x61,0x67,0x6e,0x6f,0x73,0x74,0x69,0x63,0x28,0x6f,0x66,0x66,0x2c,0x20, @@ -1631,58 +1632,58 @@ __gshared char[740] FS_OFFSCREEN_SOURCE_WGSL = [ 0x7d,0x0a,0x0a,0x00, ]; /* - diagnostic(off, derivative_uniformity); - - struct fsq_params { - /_ @offset(0) _/ - offset : vec2f, - } - - var pos : vec2f; - - var uv0 : vec2f; - - @group(0) @binding(0) var x_36 : fsq_params; - - var uv1 : vec2f; - - var uv2 : vec2f; - - var gl_Position : vec4f; - - fn main_1() { - let x_19 : vec2f = pos; - let x_24 : vec2f = ((x_19 * 2.0f) - vec2f(1.0f, 1.0f)); - gl_Position = vec4f(x_24.x, x_24.y, 0.5f, 1.0f); - let x_33 : vec2f = pos; - let x_40 : f32 = x_36.offset.x; - uv0 = (x_33 + vec2f(x_40, 0.0f)); - let x_45 : vec2f = pos; - let x_47 : f32 = x_36.offset.y; - uv1 = (x_45 + vec2f(0.0f, x_47)); - let x_51 : vec2f = pos; - uv2 = x_51; - return; - } - - struct main_out { - @builtin(position) - gl_Position : vec4f, - @location(0) - uv0_1 : vec2f, - @location(1) - uv1_1 : vec2f, - @location(2) - uv2_1 : vec2f, - } - - @vertex - fn main(@location(0) pos_param : vec2f) -> main_out { - pos = pos_param; - main_1(); - return main_out(gl_Position, uv0, uv1, uv2); - } - + diagnostic(off, derivative_uniformity); + + struct fsq_params { + /_ @offset(0) _/ + offset : vec2f, + } + + var pos : vec2f; + + var uv0 : vec2f; + + @group(0) @binding(0) var x_36 : fsq_params; + + var uv1 : vec2f; + + var uv2 : vec2f; + + var gl_Position : vec4f; + + fn main_1() { + let x_19 : vec2f = pos; + let x_24 : vec2f = ((x_19 * 2.0f) - vec2f(1.0f, 1.0f)); + gl_Position = vec4f(x_24.x, x_24.y, 0.5f, 1.0f); + let x_33 : vec2f = pos; + let x_40 : f32 = x_36.offset.x; + uv0 = (x_33 + vec2f(x_40, 0.0f)); + let x_45 : vec2f = pos; + let x_47 : f32 = x_36.offset.y; + uv1 = (x_45 + vec2f(0.0f, x_47)); + let x_51 : vec2f = pos; + uv2 = x_51; + return; + } + + struct main_out { + @builtin(position) + gl_Position : vec4f, + @location(0) + uv0_1 : vec2f, + @location(1) + uv1_1 : vec2f, + @location(2) + uv2_1 : vec2f, + } + + @vertex + fn main(@location(0) pos_param : vec2f) -> main_out { + pos = pos_param; + main_1(); + return main_out(gl_Position, uv0, uv1, uv2); + } + */ __gshared char[998] VS_FSQ_SOURCE_WGSL = [ 0x64,0x69,0x61,0x67,0x6e,0x6f,0x73,0x74,0x69,0x63,0x28,0x6f,0x66,0x66,0x2c,0x20, @@ -1750,78 +1751,78 @@ __gshared char[998] VS_FSQ_SOURCE_WGSL = [ 0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - diagnostic(off, derivative_uniformity); - - @group(1) @binding(32) var tex0 : texture_2d; - - @group(1) @binding(48) var smp : sampler; - - var uv0 : vec2f; - - @group(1) @binding(33) var tex1 : texture_2d; - - var uv1 : vec2f; - - @group(1) @binding(34) var tex2 : texture_2d; - - var uv2 : vec2f; - - var frag_color : vec4f; - - fn main_1() { - var c0 : vec3f; - var c1 : vec3f; - var c2 : vec3f; - let x_23 : vec2f = uv0; - let x_25 : vec4f = textureSample(tex0, smp, x_23); - c0 = vec3f(x_25.x, x_25.y, x_25.z); - let x_33 : vec2f = uv1; - let x_34 : vec4f = textureSample(tex1, smp, x_33); - c1 = vec3f(x_34.x, x_34.y, x_34.z); - let x_42 : vec2f = uv2; - let x_43 : vec4f = textureSample(tex2, smp, x_42); - c2 = vec3f(x_43.x, x_43.y, x_43.z); - let x_47 : vec3f = c0; - let x_48 : vec3f = c1; - let x_50 : vec3f = c2; - let x_51 : vec3f = ((x_47 + x_48) + x_50); - frag_color = vec4f(x_51.x, x_51.y, x_51.z, 1.0f); - return; - } - - struct main_out { - @location(0) - frag_color_1 : vec4f, - } - - @fragment - fn main(@location(0) uv0_param : vec2f, @location(1) uv1_param : vec2f, @location(2) uv2_param : vec2f) -> main_out { - uv0 = uv0_param; - uv1 = uv1_param; - uv2 = uv2_param; - main_1(); - return main_out(frag_color); - } - + diagnostic(off, derivative_uniformity); + + @group(1) @binding(48) var tex0 : texture_2d; + + @group(1) @binding(64) var smp : sampler; + + var uv0 : vec2f; + + @group(1) @binding(49) var tex1 : texture_2d; + + var uv1 : vec2f; + + @group(1) @binding(50) var tex2 : texture_2d; + + var uv2 : vec2f; + + var frag_color : vec4f; + + fn main_1() { + var c0 : vec3f; + var c1 : vec3f; + var c2 : vec3f; + let x_23 : vec2f = uv0; + let x_25 : vec4f = textureSample(tex0, smp, x_23); + c0 = vec3f(x_25.x, x_25.y, x_25.z); + let x_33 : vec2f = uv1; + let x_34 : vec4f = textureSample(tex1, smp, x_33); + c1 = vec3f(x_34.x, x_34.y, x_34.z); + let x_42 : vec2f = uv2; + let x_43 : vec4f = textureSample(tex2, smp, x_42); + c2 = vec3f(x_43.x, x_43.y, x_43.z); + let x_47 : vec3f = c0; + let x_48 : vec3f = c1; + let x_50 : vec3f = c2; + let x_51 : vec3f = ((x_47 + x_48) + x_50); + frag_color = vec4f(x_51.x, x_51.y, x_51.z, 1.0f); + return; + } + + struct main_out { + @location(0) + frag_color_1 : vec4f, + } + + @fragment + fn main(@location(0) uv0_param : vec2f, @location(1) uv1_param : vec2f, @location(2) uv2_param : vec2f) -> main_out { + uv0 = uv0_param; + uv1 = uv1_param; + uv2 = uv2_param; + main_1(); + return main_out(frag_color); + } + */ __gshared char[1251] FS_FSQ_SOURCE_WGSL = [ 0x64,0x69,0x61,0x67,0x6e,0x6f,0x73,0x74,0x69,0x63,0x28,0x6f,0x66,0x66,0x2c,0x20, 0x64,0x65,0x72,0x69,0x76,0x61,0x74,0x69,0x76,0x65,0x5f,0x75,0x6e,0x69,0x66,0x6f, 0x72,0x6d,0x69,0x74,0x79,0x29,0x3b,0x0a,0x0a,0x40,0x67,0x72,0x6f,0x75,0x70,0x28, - 0x31,0x29,0x20,0x40,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x28,0x33,0x32,0x29,0x20, + 0x31,0x29,0x20,0x40,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x28,0x34,0x38,0x29,0x20, 0x76,0x61,0x72,0x20,0x74,0x65,0x78,0x30,0x20,0x3a,0x20,0x74,0x65,0x78,0x74,0x75, 0x72,0x65,0x5f,0x32,0x64,0x3c,0x66,0x33,0x32,0x3e,0x3b,0x0a,0x0a,0x40,0x67,0x72, 0x6f,0x75,0x70,0x28,0x31,0x29,0x20,0x40,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x28, - 0x34,0x38,0x29,0x20,0x76,0x61,0x72,0x20,0x73,0x6d,0x70,0x20,0x3a,0x20,0x73,0x61, + 0x36,0x34,0x29,0x20,0x76,0x61,0x72,0x20,0x73,0x6d,0x70,0x20,0x3a,0x20,0x73,0x61, 0x6d,0x70,0x6c,0x65,0x72,0x3b,0x0a,0x0a,0x76,0x61,0x72,0x3c,0x70,0x72,0x69,0x76, 0x61,0x74,0x65,0x3e,0x20,0x75,0x76,0x30,0x20,0x3a,0x20,0x76,0x65,0x63,0x32,0x66, 0x3b,0x0a,0x0a,0x40,0x67,0x72,0x6f,0x75,0x70,0x28,0x31,0x29,0x20,0x40,0x62,0x69, - 0x6e,0x64,0x69,0x6e,0x67,0x28,0x33,0x33,0x29,0x20,0x76,0x61,0x72,0x20,0x74,0x65, + 0x6e,0x64,0x69,0x6e,0x67,0x28,0x34,0x39,0x29,0x20,0x76,0x61,0x72,0x20,0x74,0x65, 0x78,0x31,0x20,0x3a,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x5f,0x32,0x64,0x3c, 0x66,0x33,0x32,0x3e,0x3b,0x0a,0x0a,0x76,0x61,0x72,0x3c,0x70,0x72,0x69,0x76,0x61, 0x74,0x65,0x3e,0x20,0x75,0x76,0x31,0x20,0x3a,0x20,0x76,0x65,0x63,0x32,0x66,0x3b, 0x0a,0x0a,0x40,0x67,0x72,0x6f,0x75,0x70,0x28,0x31,0x29,0x20,0x40,0x62,0x69,0x6e, - 0x64,0x69,0x6e,0x67,0x28,0x33,0x34,0x29,0x20,0x76,0x61,0x72,0x20,0x74,0x65,0x78, + 0x64,0x69,0x6e,0x67,0x28,0x35,0x30,0x29,0x20,0x76,0x61,0x72,0x20,0x74,0x65,0x78, 0x32,0x20,0x3a,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x5f,0x32,0x64,0x3c,0x66, 0x33,0x32,0x3e,0x3b,0x0a,0x0a,0x76,0x61,0x72,0x3c,0x70,0x72,0x69,0x76,0x61,0x74, 0x65,0x3e,0x20,0x75,0x76,0x32,0x20,0x3a,0x20,0x76,0x65,0x63,0x32,0x66,0x3b,0x0a, @@ -1886,37 +1887,37 @@ __gshared char[1251] FS_FSQ_SOURCE_WGSL = [ 0x0a,0x0a,0x00, ]; /* - diagnostic(off, derivative_uniformity); - - var pos : vec2f; - - var uv : vec2f; - - var gl_Position : vec4f; - - fn main_1() { - let x_19 : vec2f = pos; - let x_24 : vec2f = ((x_19 * 2.0f) - vec2f(1.0f, 1.0f)); - gl_Position = vec4f(x_24.x, x_24.y, 0.5f, 1.0f); - let x_33 : vec2f = pos; - uv = x_33; - return; - } - - struct main_out { - @builtin(position) - gl_Position : vec4f, - @location(0) - uv_1 : vec2f, - } - - @vertex - fn main(@location(0) pos_param : vec2f) -> main_out { - pos = pos_param; - main_1(); - return main_out(gl_Position, uv); - } - + diagnostic(off, derivative_uniformity); + + var pos : vec2f; + + var uv : vec2f; + + var gl_Position : vec4f; + + fn main_1() { + let x_19 : vec2f = pos; + let x_24 : vec2f = ((x_19 * 2.0f) - vec2f(1.0f, 1.0f)); + gl_Position = vec4f(x_24.x, x_24.y, 0.5f, 1.0f); + let x_33 : vec2f = pos; + uv = x_33; + return; + } + + struct main_out { + @builtin(position) + gl_Position : vec4f, + @location(0) + uv_1 : vec2f, + } + + @vertex + fn main(@location(0) pos_param : vec2f) -> main_out { + pos = pos_param; + main_1(); + return main_out(gl_Position, uv); + } + */ __gshared char[559] VS_DBG_SOURCE_WGSL = [ 0x64,0x69,0x61,0x67,0x6e,0x6f,0x73,0x74,0x69,0x63,0x28,0x6f,0x66,0x66,0x2c,0x20, @@ -1956,36 +1957,36 @@ __gshared char[559] VS_DBG_SOURCE_WGSL = [ 0x74,0x69,0x6f,0x6e,0x2c,0x20,0x75,0x76,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - diagnostic(off, derivative_uniformity); - - var frag_color : vec4f; - - @group(1) @binding(32) var tex : texture_2d; - - @group(1) @binding(48) var smp : sampler; - - var uv : vec2f; - - fn main_1() { - let x_23 : vec2f = uv; - let x_24 : vec4f = textureSample(tex, smp, x_23); - let x_26 : vec3f = vec3f(x_24.x, x_24.y, x_24.z); - frag_color = vec4f(x_26.x, x_26.y, x_26.z, 1.0f); - return; - } - - struct main_out { - @location(0) - frag_color_1 : vec4f, - } - - @fragment - fn main(@location(0) uv_param : vec2f) -> main_out { - uv = uv_param; - main_1(); - return main_out(frag_color); - } - + diagnostic(off, derivative_uniformity); + + var frag_color : vec4f; + + @group(1) @binding(48) var tex : texture_2d; + + @group(1) @binding(64) var smp : sampler; + + var uv : vec2f; + + fn main_1() { + let x_23 : vec2f = uv; + let x_24 : vec4f = textureSample(tex, smp, x_23); + let x_26 : vec3f = vec3f(x_24.x, x_24.y, x_24.z); + frag_color = vec4f(x_26.x, x_26.y, x_26.z, 1.0f); + return; + } + + struct main_out { + @location(0) + frag_color_1 : vec4f, + } + + @fragment + fn main(@location(0) uv_param : vec2f) -> main_out { + uv = uv_param; + main_1(); + return main_out(frag_color); + } + */ __gshared char[590] FS_DBG_SOURCE_WGSL = [ 0x64,0x69,0x61,0x67,0x6e,0x6f,0x73,0x74,0x69,0x63,0x28,0x6f,0x66,0x66,0x2c,0x20, @@ -1993,11 +1994,11 @@ __gshared char[590] FS_DBG_SOURCE_WGSL = [ 0x72,0x6d,0x69,0x74,0x79,0x29,0x3b,0x0a,0x0a,0x76,0x61,0x72,0x3c,0x70,0x72,0x69, 0x76,0x61,0x74,0x65,0x3e,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72, 0x20,0x3a,0x20,0x76,0x65,0x63,0x34,0x66,0x3b,0x0a,0x0a,0x40,0x67,0x72,0x6f,0x75, - 0x70,0x28,0x31,0x29,0x20,0x40,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x28,0x33,0x32, + 0x70,0x28,0x31,0x29,0x20,0x40,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x28,0x34,0x38, 0x29,0x20,0x76,0x61,0x72,0x20,0x74,0x65,0x78,0x20,0x3a,0x20,0x74,0x65,0x78,0x74, 0x75,0x72,0x65,0x5f,0x32,0x64,0x3c,0x66,0x33,0x32,0x3e,0x3b,0x0a,0x0a,0x40,0x67, 0x72,0x6f,0x75,0x70,0x28,0x31,0x29,0x20,0x40,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67, - 0x28,0x34,0x38,0x29,0x20,0x76,0x61,0x72,0x20,0x73,0x6d,0x70,0x20,0x3a,0x20,0x73, + 0x28,0x36,0x34,0x29,0x20,0x76,0x61,0x72,0x20,0x73,0x6d,0x70,0x20,0x3a,0x20,0x73, 0x61,0x6d,0x70,0x6c,0x65,0x72,0x3b,0x0a,0x0a,0x76,0x61,0x72,0x3c,0x70,0x72,0x69, 0x76,0x61,0x74,0x65,0x3e,0x20,0x75,0x76,0x20,0x3a,0x20,0x76,0x65,0x63,0x32,0x66, 0x3b,0x0a,0x0a,0x66,0x6e,0x20,0x6d,0x61,0x69,0x6e,0x5f,0x31,0x28,0x29,0x20,0x7b, @@ -2026,355 +2027,339 @@ __gshared char[590] FS_DBG_SOURCE_WGSL = [ 0x75,0x72,0x6e,0x20,0x6d,0x61,0x69,0x6e,0x5f,0x6f,0x75,0x74,0x28,0x66,0x72,0x61, 0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; - -sg.ShaderDesc dbg_shader_desc(sg.Backend backend) @trusted @nogc nothrow { - sg.ShaderDesc desc; - switch (backend) { - case sg.Backend.Glcore33: - desc.attrs[0].name = "pos"; - desc.vs.source = &VS_DBG_SOURCE_GLSL330[0]; - desc.vs.entry = "main"; - desc.fs.source = &FS_DBG_SOURCE_GLSL330[0]; - desc.fs.entry = "main"; - desc.fs.images[0].used = true; - desc.fs.images[0].multisampled = false; - desc.fs.images[0].image_type = sg.ImageType._2d; - desc.fs.images[0].sample_type = sg.ImageSampleType.Float; - desc.fs.samplers[0].used = true; - desc.fs.samplers[0].sampler_type = sg.SamplerType.Filtering; - desc.fs.image_sampler_pairs[0].used = true; - desc.fs.image_sampler_pairs[0].image_slot = 0; - desc.fs.image_sampler_pairs[0].sampler_slot = 0; - desc.fs.image_sampler_pairs[0].glsl_name = "tex_smp"; - desc.label = "dbg_shader"; - break; - case sg.Backend.Gles3: - desc.attrs[0].name = "pos"; - desc.vs.source = &VS_DBG_SOURCE_GLSL300ES[0]; - desc.vs.entry = "main"; - desc.fs.source = &FS_DBG_SOURCE_GLSL300ES[0]; - desc.fs.entry = "main"; - desc.fs.images[0].used = true; - desc.fs.images[0].multisampled = false; - desc.fs.images[0].image_type = sg.ImageType._2d; - desc.fs.images[0].sample_type = sg.ImageSampleType.Float; - desc.fs.samplers[0].used = true; - desc.fs.samplers[0].sampler_type = sg.SamplerType.Filtering; - desc.fs.image_sampler_pairs[0].used = true; - desc.fs.image_sampler_pairs[0].image_slot = 0; - desc.fs.image_sampler_pairs[0].sampler_slot = 0; - desc.fs.image_sampler_pairs[0].glsl_name = "tex_smp"; - desc.label = "dbg_shader"; - break; - case sg.Backend.D3d11: - desc.attrs[0].sem_name = "TEXCOORD"; - desc.attrs[0].sem_index = 0; - desc.vs.source = &VS_DBG_SOURCE_HLSL4[0]; - desc.vs.d3d11_target = "vs_4_0"; - desc.vs.entry = "main"; - desc.fs.source = &FS_DBG_SOURCE_HLSL4[0]; - desc.fs.d3d11_target = "ps_4_0"; - desc.fs.entry = "main"; - desc.fs.images[0].used = true; - desc.fs.images[0].multisampled = false; - desc.fs.images[0].image_type = sg.ImageType._2d; - desc.fs.images[0].sample_type = sg.ImageSampleType.Float; - desc.fs.samplers[0].used = true; - desc.fs.samplers[0].sampler_type = sg.SamplerType.Filtering; - desc.fs.image_sampler_pairs[0].used = true; - desc.fs.image_sampler_pairs[0].image_slot = 0; - desc.fs.image_sampler_pairs[0].sampler_slot = 0; - desc.label = "dbg_shader"; - break; - case sg.Backend.Metal_macos: - desc.vs.source = &VS_DBG_SOURCE_METAL_MACOS[0]; - desc.vs.entry = "main0"; - desc.fs.source = &FS_DBG_SOURCE_METAL_MACOS[0]; - desc.fs.entry = "main0"; - desc.fs.images[0].used = true; - desc.fs.images[0].multisampled = false; - desc.fs.images[0].image_type = sg.ImageType._2d; - desc.fs.images[0].sample_type = sg.ImageSampleType.Float; - desc.fs.samplers[0].used = true; - desc.fs.samplers[0].sampler_type = sg.SamplerType.Filtering; - desc.fs.image_sampler_pairs[0].used = true; - desc.fs.image_sampler_pairs[0].image_slot = 0; - desc.fs.image_sampler_pairs[0].sampler_slot = 0; - desc.label = "dbg_shader"; - break; - case sg.Backend.Wgpu: - desc.vs.source = &VS_DBG_SOURCE_WGSL[0]; - desc.vs.entry = "main"; - desc.fs.source = &FS_DBG_SOURCE_WGSL[0]; - desc.fs.entry = "main"; - desc.fs.images[0].used = true; - desc.fs.images[0].multisampled = false; - desc.fs.images[0].image_type = sg.ImageType._2d; - desc.fs.images[0].sample_type = sg.ImageSampleType.Float; - desc.fs.samplers[0].used = true; - desc.fs.samplers[0].sampler_type = sg.SamplerType.Filtering; - desc.fs.image_sampler_pairs[0].used = true; - desc.fs.image_sampler_pairs[0].image_slot = 0; - desc.fs.image_sampler_pairs[0].sampler_slot = 0; - desc.label = "dbg_shader"; - break; - default: - break; - } - return desc; +sg.ShaderDesc dbgShaderDesc(sg.Backend backend) @trusted @nogc nothrow { + sg.ShaderDesc desc; + desc.label = "dbg_shader"; + switch (backend) { + case sg.Backend.Glcore: + desc.attrs[0].name = "pos"; + desc.vs.source = &VS_DBG_SOURCE_GLSL430[0]; + desc.vs.entry = "main"; + desc.fs.source = &FS_DBG_SOURCE_GLSL430[0]; + desc.fs.entry = "main"; + desc.fs.images[0].used = true; + desc.fs.images[0].multisampled = false; + desc.fs.images[0].image_type = sg.ImageType._2d; + desc.fs.images[0].sample_type = sg.ImageSampleType.Float; + desc.fs.samplers[0].used = true; + desc.fs.samplers[0].sampler_type = sg.SamplerType.Filtering; + desc.fs.image_sampler_pairs[0].used = true; + desc.fs.image_sampler_pairs[0].image_slot = 0; + desc.fs.image_sampler_pairs[0].sampler_slot = 0; + desc.fs.image_sampler_pairs[0].glsl_name = "tex_smp"; + break; + case sg.Backend.Gles3: + desc.attrs[0].name = "pos"; + desc.vs.source = &VS_DBG_SOURCE_GLSL300ES[0]; + desc.vs.entry = "main"; + desc.fs.source = &FS_DBG_SOURCE_GLSL300ES[0]; + desc.fs.entry = "main"; + desc.fs.images[0].used = true; + desc.fs.images[0].multisampled = false; + desc.fs.images[0].image_type = sg.ImageType._2d; + desc.fs.images[0].sample_type = sg.ImageSampleType.Float; + desc.fs.samplers[0].used = true; + desc.fs.samplers[0].sampler_type = sg.SamplerType.Filtering; + desc.fs.image_sampler_pairs[0].used = true; + desc.fs.image_sampler_pairs[0].image_slot = 0; + desc.fs.image_sampler_pairs[0].sampler_slot = 0; + desc.fs.image_sampler_pairs[0].glsl_name = "tex_smp"; + break; + case sg.Backend.D3d11: + desc.attrs[0].sem_name = "TEXCOORD"; + desc.attrs[0].sem_index = 0; + desc.vs.source = &VS_DBG_SOURCE_HLSL4[0]; + desc.vs.d3d11_target = "vs_4_0"; + desc.vs.entry = "main"; + desc.fs.source = &FS_DBG_SOURCE_HLSL4[0]; + desc.fs.d3d11_target = "ps_4_0"; + desc.fs.entry = "main"; + desc.fs.images[0].used = true; + desc.fs.images[0].multisampled = false; + desc.fs.images[0].image_type = sg.ImageType._2d; + desc.fs.images[0].sample_type = sg.ImageSampleType.Float; + desc.fs.samplers[0].used = true; + desc.fs.samplers[0].sampler_type = sg.SamplerType.Filtering; + desc.fs.image_sampler_pairs[0].used = true; + desc.fs.image_sampler_pairs[0].image_slot = 0; + desc.fs.image_sampler_pairs[0].sampler_slot = 0; + break; + case sg.Backend.Metal_macos: + desc.vs.source = &VS_DBG_SOURCE_METAL_MACOS[0]; + desc.vs.entry = "main0"; + desc.fs.source = &FS_DBG_SOURCE_METAL_MACOS[0]; + desc.fs.entry = "main0"; + desc.fs.images[0].used = true; + desc.fs.images[0].multisampled = false; + desc.fs.images[0].image_type = sg.ImageType._2d; + desc.fs.images[0].sample_type = sg.ImageSampleType.Float; + desc.fs.samplers[0].used = true; + desc.fs.samplers[0].sampler_type = sg.SamplerType.Filtering; + desc.fs.image_sampler_pairs[0].used = true; + desc.fs.image_sampler_pairs[0].image_slot = 0; + desc.fs.image_sampler_pairs[0].sampler_slot = 0; + break; + case sg.Backend.Wgpu: + desc.vs.source = &VS_DBG_SOURCE_WGSL[0]; + desc.vs.entry = "main"; + desc.fs.source = &FS_DBG_SOURCE_WGSL[0]; + desc.fs.entry = "main"; + desc.fs.images[0].used = true; + desc.fs.images[0].multisampled = false; + desc.fs.images[0].image_type = sg.ImageType._2d; + desc.fs.images[0].sample_type = sg.ImageSampleType.Float; + desc.fs.samplers[0].used = true; + desc.fs.samplers[0].sampler_type = sg.SamplerType.Filtering; + desc.fs.image_sampler_pairs[0].used = true; + desc.fs.image_sampler_pairs[0].image_slot = 0; + desc.fs.image_sampler_pairs[0].sampler_slot = 0; + break; + default: break; + } + return desc; } -sg.ShaderDesc fsq_shader_desc(sg.Backend backend) @trusted @nogc nothrow { - sg.ShaderDesc desc; - switch (backend) { - case sg.Backend.Glcore33: - desc.attrs[0].name = "pos"; - desc.vs.source = &VS_FSQ_SOURCE_GLSL330[0]; - desc.vs.entry = "main"; - desc.vs.uniform_blocks[0].size = 16; - desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; - desc.vs.uniform_blocks[0].uniforms[0].name = "fsq_params"; - desc.vs.uniform_blocks[0].uniforms[0].type = sg.UniformType.Float4; - desc.vs.uniform_blocks[0].uniforms[0].array_count = 1; - desc.fs.source = &FS_FSQ_SOURCE_GLSL330[0]; - desc.fs.entry = "main"; - desc.fs.images[0].used = true; - desc.fs.images[0].multisampled = false; - desc.fs.images[0].image_type = sg.ImageType._2d; - desc.fs.images[0].sample_type = sg.ImageSampleType.Float; - desc.fs.images[1].used = true; - desc.fs.images[1].multisampled = false; - desc.fs.images[1].image_type = sg.ImageType._2d; - desc.fs.images[1].sample_type = sg.ImageSampleType.Float; - desc.fs.images[2].used = true; - desc.fs.images[2].multisampled = false; - desc.fs.images[2].image_type = sg.ImageType._2d; - desc.fs.images[2].sample_type = sg.ImageSampleType.Float; - desc.fs.samplers[0].used = true; - desc.fs.samplers[0].sampler_type = sg.SamplerType.Filtering; - desc.fs.image_sampler_pairs[0].used = true; - desc.fs.image_sampler_pairs[0].image_slot = 0; - desc.fs.image_sampler_pairs[0].sampler_slot = 0; - desc.fs.image_sampler_pairs[0].glsl_name = "tex0_smp"; - desc.fs.image_sampler_pairs[1].used = true; - desc.fs.image_sampler_pairs[1].image_slot = 1; - desc.fs.image_sampler_pairs[1].sampler_slot = 0; - desc.fs.image_sampler_pairs[1].glsl_name = "tex1_smp"; - desc.fs.image_sampler_pairs[2].used = true; - desc.fs.image_sampler_pairs[2].image_slot = 2; - desc.fs.image_sampler_pairs[2].sampler_slot = 0; - desc.fs.image_sampler_pairs[2].glsl_name = "tex2_smp"; - desc.label = "fsq_shader"; - break; - case sg.Backend.Gles3: - desc.attrs[0].name = "pos"; - desc.vs.source = &VS_FSQ_SOURCE_GLSL300ES[0]; - desc.vs.entry = "main"; - desc.vs.uniform_blocks[0].size = 16; - desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; - desc.vs.uniform_blocks[0].uniforms[0].name = "fsq_params"; - desc.vs.uniform_blocks[0].uniforms[0].type = sg.UniformType.Float4; - desc.vs.uniform_blocks[0].uniforms[0].array_count = 1; - desc.fs.source = &FS_FSQ_SOURCE_GLSL300ES[0]; - desc.fs.entry = "main"; - desc.fs.images[0].used = true; - desc.fs.images[0].multisampled = false; - desc.fs.images[0].image_type = sg.ImageType._2d; - desc.fs.images[0].sample_type = sg.ImageSampleType.Float; - desc.fs.images[1].used = true; - desc.fs.images[1].multisampled = false; - desc.fs.images[1].image_type = sg.ImageType._2d; - desc.fs.images[1].sample_type = sg.ImageSampleType.Float; - desc.fs.images[2].used = true; - desc.fs.images[2].multisampled = false; - desc.fs.images[2].image_type = sg.ImageType._2d; - desc.fs.images[2].sample_type = sg.ImageSampleType.Float; - desc.fs.samplers[0].used = true; - desc.fs.samplers[0].sampler_type = sg.SamplerType.Filtering; - desc.fs.image_sampler_pairs[0].used = true; - desc.fs.image_sampler_pairs[0].image_slot = 0; - desc.fs.image_sampler_pairs[0].sampler_slot = 0; - desc.fs.image_sampler_pairs[0].glsl_name = "tex0_smp"; - desc.fs.image_sampler_pairs[1].used = true; - desc.fs.image_sampler_pairs[1].image_slot = 1; - desc.fs.image_sampler_pairs[1].sampler_slot = 0; - desc.fs.image_sampler_pairs[1].glsl_name = "tex1_smp"; - desc.fs.image_sampler_pairs[2].used = true; - desc.fs.image_sampler_pairs[2].image_slot = 2; - desc.fs.image_sampler_pairs[2].sampler_slot = 0; - desc.fs.image_sampler_pairs[2].glsl_name = "tex2_smp"; - desc.label = "fsq_shader"; - break; - case sg.Backend.D3d11: - desc.attrs[0].sem_name = "TEXCOORD"; - desc.attrs[0].sem_index = 0; - desc.vs.source = &VS_FSQ_SOURCE_HLSL4[0]; - desc.vs.d3d11_target = "vs_4_0"; - desc.vs.entry = "main"; - desc.vs.uniform_blocks[0].size = 16; - desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; - desc.fs.source = &FS_FSQ_SOURCE_HLSL4[0]; - desc.fs.d3d11_target = "ps_4_0"; - desc.fs.entry = "main"; - desc.fs.images[0].used = true; - desc.fs.images[0].multisampled = false; - desc.fs.images[0].image_type = sg.ImageType._2d; - desc.fs.images[0].sample_type = sg.ImageSampleType.Float; - desc.fs.images[1].used = true; - desc.fs.images[1].multisampled = false; - desc.fs.images[1].image_type = sg.ImageType._2d; - desc.fs.images[1].sample_type = sg.ImageSampleType.Float; - desc.fs.images[2].used = true; - desc.fs.images[2].multisampled = false; - desc.fs.images[2].image_type = sg.ImageType._2d; - desc.fs.images[2].sample_type = sg.ImageSampleType.Float; - desc.fs.samplers[0].used = true; - desc.fs.samplers[0].sampler_type = sg.SamplerType.Filtering; - desc.fs.image_sampler_pairs[0].used = true; - desc.fs.image_sampler_pairs[0].image_slot = 0; - desc.fs.image_sampler_pairs[0].sampler_slot = 0; - desc.fs.image_sampler_pairs[1].used = true; - desc.fs.image_sampler_pairs[1].image_slot = 1; - desc.fs.image_sampler_pairs[1].sampler_slot = 0; - desc.fs.image_sampler_pairs[2].used = true; - desc.fs.image_sampler_pairs[2].image_slot = 2; - desc.fs.image_sampler_pairs[2].sampler_slot = 0; - desc.label = "fsq_shader"; - break; - case sg.Backend.Metal_macos: - desc.vs.source = &VS_FSQ_SOURCE_METAL_MACOS[0]; - desc.vs.entry = "main0"; - desc.vs.uniform_blocks[0].size = 16; - desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; - desc.fs.source = &FS_FSQ_SOURCE_METAL_MACOS[0]; - desc.fs.entry = "main0"; - desc.fs.images[0].used = true; - desc.fs.images[0].multisampled = false; - desc.fs.images[0].image_type = sg.ImageType._2d; - desc.fs.images[0].sample_type = sg.ImageSampleType.Float; - desc.fs.images[1].used = true; - desc.fs.images[1].multisampled = false; - desc.fs.images[1].image_type = sg.ImageType._2d; - desc.fs.images[1].sample_type = sg.ImageSampleType.Float; - desc.fs.images[2].used = true; - desc.fs.images[2].multisampled = false; - desc.fs.images[2].image_type = sg.ImageType._2d; - desc.fs.images[2].sample_type = sg.ImageSampleType.Float; - desc.fs.samplers[0].used = true; - desc.fs.samplers[0].sampler_type = sg.SamplerType.Filtering; - desc.fs.image_sampler_pairs[0].used = true; - desc.fs.image_sampler_pairs[0].image_slot = 0; - desc.fs.image_sampler_pairs[0].sampler_slot = 0; - desc.fs.image_sampler_pairs[1].used = true; - desc.fs.image_sampler_pairs[1].image_slot = 1; - desc.fs.image_sampler_pairs[1].sampler_slot = 0; - desc.fs.image_sampler_pairs[2].used = true; - desc.fs.image_sampler_pairs[2].image_slot = 2; - desc.fs.image_sampler_pairs[2].sampler_slot = 0; - desc.label = "fsq_shader"; - break; - case sg.Backend.Wgpu: - desc.vs.source = &VS_FSQ_SOURCE_WGSL[0]; - desc.vs.entry = "main"; - desc.vs.uniform_blocks[0].size = 16; - desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; - desc.fs.source = &FS_FSQ_SOURCE_WGSL[0]; - desc.fs.entry = "main"; - desc.fs.images[0].used = true; - desc.fs.images[0].multisampled = false; - desc.fs.images[0].image_type = sg.ImageType._2d; - desc.fs.images[0].sample_type = sg.ImageSampleType.Float; - desc.fs.images[1].used = true; - desc.fs.images[1].multisampled = false; - desc.fs.images[1].image_type = sg.ImageType._2d; - desc.fs.images[1].sample_type = sg.ImageSampleType.Float; - desc.fs.images[2].used = true; - desc.fs.images[2].multisampled = false; - desc.fs.images[2].image_type = sg.ImageType._2d; - desc.fs.images[2].sample_type = sg.ImageSampleType.Float; - desc.fs.samplers[0].used = true; - desc.fs.samplers[0].sampler_type = sg.SamplerType.Filtering; - desc.fs.image_sampler_pairs[0].used = true; - desc.fs.image_sampler_pairs[0].image_slot = 0; - desc.fs.image_sampler_pairs[0].sampler_slot = 0; - desc.fs.image_sampler_pairs[1].used = true; - desc.fs.image_sampler_pairs[1].image_slot = 1; - desc.fs.image_sampler_pairs[1].sampler_slot = 0; - desc.fs.image_sampler_pairs[2].used = true; - desc.fs.image_sampler_pairs[2].image_slot = 2; - desc.fs.image_sampler_pairs[2].sampler_slot = 0; - desc.label = "fsq_shader"; - break; - default: - break; - } - return desc; +sg.ShaderDesc fsqShaderDesc(sg.Backend backend) @trusted @nogc nothrow { + sg.ShaderDesc desc; + desc.label = "fsq_shader"; + switch (backend) { + case sg.Backend.Glcore: + desc.attrs[0].name = "pos"; + desc.vs.source = &VS_FSQ_SOURCE_GLSL430[0]; + desc.vs.entry = "main"; + desc.vs.uniform_blocks[0].size = 16; + desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; + desc.vs.uniform_blocks[0].uniforms[0].name = "fsq_params"; + desc.vs.uniform_blocks[0].uniforms[0].type = sg.UniformType.Float4; + desc.vs.uniform_blocks[0].uniforms[0].array_count = 1; + desc.fs.source = &FS_FSQ_SOURCE_GLSL430[0]; + desc.fs.entry = "main"; + desc.fs.images[0].used = true; + desc.fs.images[0].multisampled = false; + desc.fs.images[0].image_type = sg.ImageType._2d; + desc.fs.images[0].sample_type = sg.ImageSampleType.Float; + desc.fs.images[1].used = true; + desc.fs.images[1].multisampled = false; + desc.fs.images[1].image_type = sg.ImageType._2d; + desc.fs.images[1].sample_type = sg.ImageSampleType.Float; + desc.fs.images[2].used = true; + desc.fs.images[2].multisampled = false; + desc.fs.images[2].image_type = sg.ImageType._2d; + desc.fs.images[2].sample_type = sg.ImageSampleType.Float; + desc.fs.samplers[0].used = true; + desc.fs.samplers[0].sampler_type = sg.SamplerType.Filtering; + desc.fs.image_sampler_pairs[0].used = true; + desc.fs.image_sampler_pairs[0].image_slot = 0; + desc.fs.image_sampler_pairs[0].sampler_slot = 0; + desc.fs.image_sampler_pairs[0].glsl_name = "tex0_smp"; + desc.fs.image_sampler_pairs[1].used = true; + desc.fs.image_sampler_pairs[1].image_slot = 1; + desc.fs.image_sampler_pairs[1].sampler_slot = 0; + desc.fs.image_sampler_pairs[1].glsl_name = "tex1_smp"; + desc.fs.image_sampler_pairs[2].used = true; + desc.fs.image_sampler_pairs[2].image_slot = 2; + desc.fs.image_sampler_pairs[2].sampler_slot = 0; + desc.fs.image_sampler_pairs[2].glsl_name = "tex2_smp"; + break; + case sg.Backend.Gles3: + desc.attrs[0].name = "pos"; + desc.vs.source = &VS_FSQ_SOURCE_GLSL300ES[0]; + desc.vs.entry = "main"; + desc.vs.uniform_blocks[0].size = 16; + desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; + desc.vs.uniform_blocks[0].uniforms[0].name = "fsq_params"; + desc.vs.uniform_blocks[0].uniforms[0].type = sg.UniformType.Float4; + desc.vs.uniform_blocks[0].uniforms[0].array_count = 1; + desc.fs.source = &FS_FSQ_SOURCE_GLSL300ES[0]; + desc.fs.entry = "main"; + desc.fs.images[0].used = true; + desc.fs.images[0].multisampled = false; + desc.fs.images[0].image_type = sg.ImageType._2d; + desc.fs.images[0].sample_type = sg.ImageSampleType.Float; + desc.fs.images[1].used = true; + desc.fs.images[1].multisampled = false; + desc.fs.images[1].image_type = sg.ImageType._2d; + desc.fs.images[1].sample_type = sg.ImageSampleType.Float; + desc.fs.images[2].used = true; + desc.fs.images[2].multisampled = false; + desc.fs.images[2].image_type = sg.ImageType._2d; + desc.fs.images[2].sample_type = sg.ImageSampleType.Float; + desc.fs.samplers[0].used = true; + desc.fs.samplers[0].sampler_type = sg.SamplerType.Filtering; + desc.fs.image_sampler_pairs[0].used = true; + desc.fs.image_sampler_pairs[0].image_slot = 0; + desc.fs.image_sampler_pairs[0].sampler_slot = 0; + desc.fs.image_sampler_pairs[0].glsl_name = "tex0_smp"; + desc.fs.image_sampler_pairs[1].used = true; + desc.fs.image_sampler_pairs[1].image_slot = 1; + desc.fs.image_sampler_pairs[1].sampler_slot = 0; + desc.fs.image_sampler_pairs[1].glsl_name = "tex1_smp"; + desc.fs.image_sampler_pairs[2].used = true; + desc.fs.image_sampler_pairs[2].image_slot = 2; + desc.fs.image_sampler_pairs[2].sampler_slot = 0; + desc.fs.image_sampler_pairs[2].glsl_name = "tex2_smp"; + break; + case sg.Backend.D3d11: + desc.attrs[0].sem_name = "TEXCOORD"; + desc.attrs[0].sem_index = 0; + desc.vs.source = &VS_FSQ_SOURCE_HLSL4[0]; + desc.vs.d3d11_target = "vs_4_0"; + desc.vs.entry = "main"; + desc.vs.uniform_blocks[0].size = 16; + desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; + desc.fs.source = &FS_FSQ_SOURCE_HLSL4[0]; + desc.fs.d3d11_target = "ps_4_0"; + desc.fs.entry = "main"; + desc.fs.images[0].used = true; + desc.fs.images[0].multisampled = false; + desc.fs.images[0].image_type = sg.ImageType._2d; + desc.fs.images[0].sample_type = sg.ImageSampleType.Float; + desc.fs.images[1].used = true; + desc.fs.images[1].multisampled = false; + desc.fs.images[1].image_type = sg.ImageType._2d; + desc.fs.images[1].sample_type = sg.ImageSampleType.Float; + desc.fs.images[2].used = true; + desc.fs.images[2].multisampled = false; + desc.fs.images[2].image_type = sg.ImageType._2d; + desc.fs.images[2].sample_type = sg.ImageSampleType.Float; + desc.fs.samplers[0].used = true; + desc.fs.samplers[0].sampler_type = sg.SamplerType.Filtering; + desc.fs.image_sampler_pairs[0].used = true; + desc.fs.image_sampler_pairs[0].image_slot = 0; + desc.fs.image_sampler_pairs[0].sampler_slot = 0; + desc.fs.image_sampler_pairs[1].used = true; + desc.fs.image_sampler_pairs[1].image_slot = 1; + desc.fs.image_sampler_pairs[1].sampler_slot = 0; + desc.fs.image_sampler_pairs[2].used = true; + desc.fs.image_sampler_pairs[2].image_slot = 2; + desc.fs.image_sampler_pairs[2].sampler_slot = 0; + break; + case sg.Backend.Metal_macos: + desc.vs.source = &VS_FSQ_SOURCE_METAL_MACOS[0]; + desc.vs.entry = "main0"; + desc.vs.uniform_blocks[0].size = 16; + desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; + desc.fs.source = &FS_FSQ_SOURCE_METAL_MACOS[0]; + desc.fs.entry = "main0"; + desc.fs.images[0].used = true; + desc.fs.images[0].multisampled = false; + desc.fs.images[0].image_type = sg.ImageType._2d; + desc.fs.images[0].sample_type = sg.ImageSampleType.Float; + desc.fs.images[1].used = true; + desc.fs.images[1].multisampled = false; + desc.fs.images[1].image_type = sg.ImageType._2d; + desc.fs.images[1].sample_type = sg.ImageSampleType.Float; + desc.fs.images[2].used = true; + desc.fs.images[2].multisampled = false; + desc.fs.images[2].image_type = sg.ImageType._2d; + desc.fs.images[2].sample_type = sg.ImageSampleType.Float; + desc.fs.samplers[0].used = true; + desc.fs.samplers[0].sampler_type = sg.SamplerType.Filtering; + desc.fs.image_sampler_pairs[0].used = true; + desc.fs.image_sampler_pairs[0].image_slot = 0; + desc.fs.image_sampler_pairs[0].sampler_slot = 0; + desc.fs.image_sampler_pairs[1].used = true; + desc.fs.image_sampler_pairs[1].image_slot = 1; + desc.fs.image_sampler_pairs[1].sampler_slot = 0; + desc.fs.image_sampler_pairs[2].used = true; + desc.fs.image_sampler_pairs[2].image_slot = 2; + desc.fs.image_sampler_pairs[2].sampler_slot = 0; + break; + case sg.Backend.Wgpu: + desc.vs.source = &VS_FSQ_SOURCE_WGSL[0]; + desc.vs.entry = "main"; + desc.vs.uniform_blocks[0].size = 16; + desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; + desc.fs.source = &FS_FSQ_SOURCE_WGSL[0]; + desc.fs.entry = "main"; + desc.fs.images[0].used = true; + desc.fs.images[0].multisampled = false; + desc.fs.images[0].image_type = sg.ImageType._2d; + desc.fs.images[0].sample_type = sg.ImageSampleType.Float; + desc.fs.images[1].used = true; + desc.fs.images[1].multisampled = false; + desc.fs.images[1].image_type = sg.ImageType._2d; + desc.fs.images[1].sample_type = sg.ImageSampleType.Float; + desc.fs.images[2].used = true; + desc.fs.images[2].multisampled = false; + desc.fs.images[2].image_type = sg.ImageType._2d; + desc.fs.images[2].sample_type = sg.ImageSampleType.Float; + desc.fs.samplers[0].used = true; + desc.fs.samplers[0].sampler_type = sg.SamplerType.Filtering; + desc.fs.image_sampler_pairs[0].used = true; + desc.fs.image_sampler_pairs[0].image_slot = 0; + desc.fs.image_sampler_pairs[0].sampler_slot = 0; + desc.fs.image_sampler_pairs[1].used = true; + desc.fs.image_sampler_pairs[1].image_slot = 1; + desc.fs.image_sampler_pairs[1].sampler_slot = 0; + desc.fs.image_sampler_pairs[2].used = true; + desc.fs.image_sampler_pairs[2].image_slot = 2; + desc.fs.image_sampler_pairs[2].sampler_slot = 0; + break; + default: break; + } + return desc; } -sg.ShaderDesc offscreen_shader_desc(sg.Backend backend) @trusted @nogc nothrow { - sg.ShaderDesc desc; - switch (backend) { - case sg.Backend.Glcore33: - desc.attrs[0].name = "pos"; - desc.attrs[1].name = "bright0"; - desc.vs.source = &VS_OFFSCREEN_SOURCE_GLSL330[0]; - desc.vs.entry = "main"; - desc.vs.uniform_blocks[0].size = 64; - desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; - desc.vs.uniform_blocks[0].uniforms[0].name = "offscreen_params"; - desc.vs.uniform_blocks[0].uniforms[0].type = sg.UniformType.Float4; - desc.vs.uniform_blocks[0].uniforms[0].array_count = 4; - desc.fs.source = &FS_OFFSCREEN_SOURCE_GLSL330[0]; - desc.fs.entry = "main"; - desc.label = "offscreen_shader"; - break; - case sg.Backend.Gles3: - desc.attrs[0].name = "pos"; - desc.attrs[1].name = "bright0"; - desc.vs.source = &VS_OFFSCREEN_SOURCE_GLSL300ES[0]; - desc.vs.entry = "main"; - desc.vs.uniform_blocks[0].size = 64; - desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; - desc.vs.uniform_blocks[0].uniforms[0].name = "offscreen_params"; - desc.vs.uniform_blocks[0].uniforms[0].type = sg.UniformType.Float4; - desc.vs.uniform_blocks[0].uniforms[0].array_count = 4; - desc.fs.source = &FS_OFFSCREEN_SOURCE_GLSL300ES[0]; - desc.fs.entry = "main"; - desc.label = "offscreen_shader"; - break; - case sg.Backend.D3d11: - desc.attrs[0].sem_name = "TEXCOORD"; - desc.attrs[0].sem_index = 0; - desc.attrs[1].sem_name = "TEXCOORD"; - desc.attrs[1].sem_index = 1; - desc.vs.source = &VS_OFFSCREEN_SOURCE_HLSL4[0]; - desc.vs.d3d11_target = "vs_4_0"; - desc.vs.entry = "main"; - desc.vs.uniform_blocks[0].size = 64; - desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; - desc.fs.source = &FS_OFFSCREEN_SOURCE_HLSL4[0]; - desc.fs.d3d11_target = "ps_4_0"; - desc.fs.entry = "main"; - desc.label = "offscreen_shader"; - break; - case sg.Backend.Metal_macos: - desc.vs.source = &VS_OFFSCREEN_SOURCE_METAL_MACOS[0]; - desc.vs.entry = "main0"; - desc.vs.uniform_blocks[0].size = 64; - desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; - desc.fs.source = &FS_OFFSCREEN_SOURCE_METAL_MACOS[0]; - desc.fs.entry = "main0"; - desc.label = "offscreen_shader"; - break; - case sg.Backend.Wgpu: - desc.vs.source = &VS_OFFSCREEN_SOURCE_WGSL[0]; - desc.vs.entry = "main"; - desc.vs.uniform_blocks[0].size = 64; - desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; - desc.fs.source = &FS_OFFSCREEN_SOURCE_WGSL[0]; - desc.fs.entry = "main"; - desc.label = "offscreen_shader"; - break; - default: - break; - } - return desc; +sg.ShaderDesc offscreenShaderDesc(sg.Backend backend) @trusted @nogc nothrow { + sg.ShaderDesc desc; + desc.label = "offscreen_shader"; + switch (backend) { + case sg.Backend.Glcore: + desc.attrs[0].name = "pos"; + desc.attrs[1].name = "bright0"; + desc.vs.source = &VS_OFFSCREEN_SOURCE_GLSL430[0]; + desc.vs.entry = "main"; + desc.vs.uniform_blocks[0].size = 64; + desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; + desc.vs.uniform_blocks[0].uniforms[0].name = "offscreen_params"; + desc.vs.uniform_blocks[0].uniforms[0].type = sg.UniformType.Float4; + desc.vs.uniform_blocks[0].uniforms[0].array_count = 4; + desc.fs.source = &FS_OFFSCREEN_SOURCE_GLSL430[0]; + desc.fs.entry = "main"; + break; + case sg.Backend.Gles3: + desc.attrs[0].name = "pos"; + desc.attrs[1].name = "bright0"; + desc.vs.source = &VS_OFFSCREEN_SOURCE_GLSL300ES[0]; + desc.vs.entry = "main"; + desc.vs.uniform_blocks[0].size = 64; + desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; + desc.vs.uniform_blocks[0].uniforms[0].name = "offscreen_params"; + desc.vs.uniform_blocks[0].uniforms[0].type = sg.UniformType.Float4; + desc.vs.uniform_blocks[0].uniforms[0].array_count = 4; + desc.fs.source = &FS_OFFSCREEN_SOURCE_GLSL300ES[0]; + desc.fs.entry = "main"; + break; + case sg.Backend.D3d11: + desc.attrs[0].sem_name = "TEXCOORD"; + desc.attrs[0].sem_index = 0; + desc.attrs[1].sem_name = "TEXCOORD"; + desc.attrs[1].sem_index = 1; + desc.vs.source = &VS_OFFSCREEN_SOURCE_HLSL4[0]; + desc.vs.d3d11_target = "vs_4_0"; + desc.vs.entry = "main"; + desc.vs.uniform_blocks[0].size = 64; + desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; + desc.fs.source = &FS_OFFSCREEN_SOURCE_HLSL4[0]; + desc.fs.d3d11_target = "ps_4_0"; + desc.fs.entry = "main"; + break; + case sg.Backend.Metal_macos: + desc.vs.source = &VS_OFFSCREEN_SOURCE_METAL_MACOS[0]; + desc.vs.entry = "main0"; + desc.vs.uniform_blocks[0].size = 64; + desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; + desc.fs.source = &FS_OFFSCREEN_SOURCE_METAL_MACOS[0]; + desc.fs.entry = "main0"; + break; + case sg.Backend.Wgpu: + desc.vs.source = &VS_OFFSCREEN_SOURCE_WGSL[0]; + desc.vs.entry = "main"; + desc.vs.uniform_blocks[0].size = 64; + desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; + desc.fs.source = &FS_OFFSCREEN_SOURCE_WGSL[0]; + desc.fs.entry = "main"; + break; + default: break; + } + return desc; } diff --git a/src/shaders/noninterleaved.d b/src/shaders/noninterleaved.d index 417c064..9c70e35 100644 --- a/src/shaders/noninterleaved.d +++ b/src/shaders/noninterleaved.d @@ -1,105 +1,107 @@ module shaders.noninterleaved; import sg = sokol.gfx; +import m = handmade.math; extern(C): /* #version:1# (machine generated, don't edit!) - + Generated by sokol-shdc (https://github.com/floooh/sokol-tools) - - Cmdline: sokol-shdc -i src/shaders/noninterleaved.glsl -o src/shaders/noninterleaved.d -l glsl330:metal_macos:hlsl4:glsl300es:wgsl -f sokol_d - + + Cmdline: + sokol-shdc -i src/shaders/noninterleaved.glsl -o src/shaders/noninterleaved.d -l glsl430:metal_macos:hlsl4:glsl300es:wgsl -f sokol_d + Overview: - - Shader program 'noninterleaved': - Get shader desc: noninterleaved_shader_desc(sg.query_backend()); - Vertex shader: vs - Attribute slots: - ATTR_VS_POSITION = 0 - ATTR_VS_COLOR0 = 1 - Uniform block 'vs_params': - C struct: vs_params_t - Bind slot: SLOT_VS_PARAMS = 0 - Fragment shader: fs - + ========= + Shader program: 'noninterleaved': + Get shader desc: noninterleavedShaderDesc(sg.queryBackend()); + Vertex shader: vs + Attributes: + ATTR_VS_POSITION => 0 + ATTR_VS_COLOR0 => 1 + Uniform block 'vs_params': + D struct: VsParams + Bind slot: SLOT_VS_PARAMS => 0 + Fragment shader: fs */ -import m = handmade.math; enum ATTR_VS_POSITION = 0; enum ATTR_VS_COLOR0 = 1; enum SLOT_VS_PARAMS = 0; struct VsParams { - m.Mat4 mvp; + align(16) m.Mat4 mvp; } /* - #version 330 - - uniform vec4 vs_params[4]; - layout(location = 0) in vec4 position; - out vec4 color; - layout(location = 1) in vec4 color0; - - void main() - { - gl_Position = mat4(vs_params[0], vs_params[1], vs_params[2], vs_params[3]) * position; - color = color0; - } - + #version 430 + + uniform vec4 vs_params[4]; + layout(location = 0) in vec4 position; + layout(location = 0) out vec4 color; + layout(location = 1) in vec4 color0; + + void main() + { + gl_Position = mat4(vs_params[0], vs_params[1], vs_params[2], vs_params[3]) * position; + color = color0; + } + */ -__gshared char[263] VS_SOURCE_GLSL330 = [ - 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x33,0x30,0x0a,0x0a,0x75,0x6e, +__gshared char[284] VS_SOURCE_GLSL430 = [ + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x75,0x6e, 0x69,0x66,0x6f,0x72,0x6d,0x20,0x76,0x65,0x63,0x34,0x20,0x76,0x73,0x5f,0x70,0x61, 0x72,0x61,0x6d,0x73,0x5b,0x34,0x5d,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28, 0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e, 0x20,0x76,0x65,0x63,0x34,0x20,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a, - 0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a, 0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20, - 0x3d,0x20,0x31,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c, - 0x6f,0x72,0x30,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28, - 0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74, - 0x69,0x6f,0x6e,0x20,0x3d,0x20,0x6d,0x61,0x74,0x34,0x28,0x76,0x73,0x5f,0x70,0x61, - 0x72,0x61,0x6d,0x73,0x5b,0x30,0x5d,0x2c,0x20,0x76,0x73,0x5f,0x70,0x61,0x72,0x61, - 0x6d,0x73,0x5b,0x31,0x5d,0x2c,0x20,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73, - 0x5b,0x32,0x5d,0x2c,0x20,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x33, - 0x5d,0x29,0x20,0x2a,0x20,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72, - 0x30,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, + 0x3d,0x20,0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x6f, + 0x6c,0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61, + 0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63, + 0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20, + 0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f, + 0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x6d,0x61,0x74,0x34,0x28, + 0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x30,0x5d,0x2c,0x20,0x76,0x73, + 0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x31,0x5d,0x2c,0x20,0x76,0x73,0x5f,0x70, + 0x61,0x72,0x61,0x6d,0x73,0x5b,0x32,0x5d,0x2c,0x20,0x76,0x73,0x5f,0x70,0x61,0x72, + 0x61,0x6d,0x73,0x5b,0x33,0x5d,0x29,0x20,0x2a,0x20,0x70,0x6f,0x73,0x69,0x74,0x69, + 0x6f,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20, + 0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - #version 330 - - layout(location = 0) out vec4 frag_color; - in vec4 color; - - void main() - { - frag_color = color; - } - + #version 430 + + layout(location = 0) out vec4 frag_color; + layout(location = 0) in vec4 color; + + void main() + { + frag_color = color; + } + */ -__gshared char[114] FS_SOURCE_GLSL330 = [ - 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x33,0x30,0x0a,0x0a,0x6c,0x61, +__gshared char[135] FS_SOURCE_GLSL430 = [ + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x6c,0x61, 0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, 0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x66,0x72,0x61,0x67, - 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20, - 0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69, - 0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x63, - 0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x7d,0x0a, - 0x0a,0x00, + 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c, + 0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e,0x20, + 0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x0a,0x76,0x6f,0x69, + 0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f, + 0x72,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - #version 300 es - - uniform vec4 vs_params[4]; - layout(location = 0) in vec4 position; - out vec4 color; - layout(location = 1) in vec4 color0; - - void main() - { - gl_Position = mat4(vs_params[0], vs_params[1], vs_params[2], vs_params[3]) * position; - color = color0; - } - + #version 300 es + + uniform vec4 vs_params[4]; + layout(location = 0) in vec4 position; + out vec4 color; + layout(location = 1) in vec4 color0; + + void main() + { + gl_Position = mat4(vs_params[0], vs_params[1], vs_params[2], vs_params[3]) * position; + color = color0; + } + */ __gshared char[266] VS_SOURCE_GLSL300ES = [ 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x30,0x30,0x20,0x65,0x73,0x0a, @@ -121,18 +123,18 @@ __gshared char[266] VS_SOURCE_GLSL300ES = [ 0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - #version 300 es - precision mediump float; - precision highp int; - - layout(location = 0) out highp vec4 frag_color; - in highp vec4 color; - - void main() - { - frag_color = color; - } - + #version 300 es + precision mediump float; + precision highp int; + + layout(location = 0) out highp vec4 frag_color; + in highp vec4 color; + + void main() + { + frag_color = color; + } + */ __gshared char[175] FS_SOURCE_GLSL300ES = [ 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x30,0x30,0x20,0x65,0x73,0x0a, @@ -148,45 +150,45 @@ __gshared char[175] FS_SOURCE_GLSL300ES = [ 0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - cbuffer vs_params : register(b0) - { - row_major float4x4 _19_mvp : packoffset(c0); - }; - - - static float4 gl_Position; - static float4 position; - static float4 color; - static float4 color0; - - struct SPIRV_Cross_Input - { - float4 position : TEXCOORD0; - float4 color0 : TEXCOORD1; - }; - - struct SPIRV_Cross_Output - { - float4 color : TEXCOORD0; - float4 gl_Position : SV_Position; - }; - - void vert_main() - { - gl_Position = mul(position, _19_mvp); - color = color0; - } - - SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) - { - position = stage_input.position; - color0 = stage_input.color0; - vert_main(); - SPIRV_Cross_Output stage_output; - stage_output.gl_Position = gl_Position; - stage_output.color = color; - return stage_output; - } + cbuffer vs_params : register(b0) + { + row_major float4x4 _19_mvp : packoffset(c0); + }; + + + static float4 gl_Position; + static float4 position; + static float4 color; + static float4 color0; + + struct SPIRV_Cross_Input + { + float4 position : TEXCOORD0; + float4 color0 : TEXCOORD1; + }; + + struct SPIRV_Cross_Output + { + float4 color : TEXCOORD0; + float4 gl_Position : SV_Position; + }; + + void vert_main() + { + gl_Position = mul(position, _19_mvp); + color = color0; + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + position = stage_input.position; + color0 = stage_input.color0; + vert_main(); + SPIRV_Cross_Output stage_output; + stage_output.gl_Position = gl_Position; + stage_output.color = color; + return stage_output; + } */ __gshared char[748] VS_SOURCE_HLSL4 = [ 0x63,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d, @@ -238,32 +240,32 @@ __gshared char[748] VS_SOURCE_HLSL4 = [ 0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x00, ]; /* - static float4 frag_color; - static float4 color; - - struct SPIRV_Cross_Input - { - float4 color : TEXCOORD0; - }; - - struct SPIRV_Cross_Output - { - float4 frag_color : SV_Target0; - }; - - void frag_main() - { - frag_color = color; - } - - SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) - { - color = stage_input.color; - frag_main(); - SPIRV_Cross_Output stage_output; - stage_output.frag_color = frag_color; - return stage_output; - } + static float4 frag_color; + static float4 color; + + struct SPIRV_Cross_Input + { + float4 color : TEXCOORD0; + }; + + struct SPIRV_Cross_Output + { + float4 frag_color : SV_Target0; + }; + + void frag_main() + { + frag_color = color; + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + color = stage_input.color; + frag_main(); + SPIRV_Cross_Output stage_output; + stage_output.frag_color = frag_color; + return stage_output; + } */ __gshared char[435] FS_SOURCE_HLSL4 = [ 0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x66,0x72, @@ -296,36 +298,36 @@ __gshared char[435] FS_SOURCE_HLSL4 = [ 0x7d,0x0a,0x00, ]; /* - #include - #include - - using namespace metal; - - struct vs_params - { - float4x4 mvp; - }; - - struct main0_out - { - float4 color [[user(locn0)]]; - float4 gl_Position [[position]]; - }; - - struct main0_in - { - float4 position [[attribute(0)]]; - float4 color0 [[attribute(1)]]; - }; - - vertex main0_out main0(main0_in in [[stage_in]], constant vs_params& _19 [[buffer(0)]]) - { - main0_out out = {}; - out.gl_Position = _19.mvp * in.position; - out.color = in.color0; - return out; - } - + #include + #include + + using namespace metal; + + struct vs_params + { + float4x4 mvp; + }; + + struct main0_out + { + float4 color [[user(locn0)]]; + float4 gl_Position [[position]]; + }; + + struct main0_in + { + float4 position [[attribute(0)]]; + float4 color0 [[attribute(1)]]; + }; + + vertex main0_out main0(main0_in in [[stage_in]], constant vs_params& _19 [[buffer(0)]]) + { + main0_out out = {}; + out.gl_Position = _19.mvp * in.position; + out.color = in.color0; + return out; + } + */ __gshared char[509] VS_SOURCE_METAL_MACOS = [ 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, @@ -362,28 +364,28 @@ __gshared char[509] VS_SOURCE_METAL_MACOS = [ 0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - #include - #include - - using namespace metal; - - struct main0_out - { - float4 frag_color [[color(0)]]; - }; - - struct main0_in - { - float4 color [[user(locn0)]]; - }; - - fragment main0_out main0(main0_in in [[stage_in]]) - { - main0_out out = {}; - out.frag_color = in.color; - return out; - } - + #include + #include + + using namespace metal; + + struct main0_out + { + float4 frag_color [[color(0)]]; + }; + + struct main0_in + { + float4 color [[user(locn0)]]; + }; + + fragment main0_out main0(main0_in in [[stage_in]]) + { + main0_out out = {}; + out.frag_color = in.color; + return out; + } + */ __gshared char[315] FS_SOURCE_METAL_MACOS = [ 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, @@ -408,47 +410,47 @@ __gshared char[315] FS_SOURCE_METAL_MACOS = [ 0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - diagnostic(off, derivative_uniformity); - - struct vs_params { - /_ @offset(0) _/ - mvp : mat4x4f, - } - - @group(0) @binding(0) var x_19 : vs_params; - - var position_1 : vec4f; - - var color : vec4f; - - var color0 : vec4f; - - var gl_Position : vec4f; - - fn main_1() { - let x_22 : mat4x4f = x_19.mvp; - let x_25 : vec4f = position_1; - gl_Position = (x_22 * x_25); - let x_31 : vec4f = color0; - color = x_31; - return; - } - - struct main_out { - @builtin(position) - gl_Position : vec4f, - @location(0) - color_1 : vec4f, - } - - @vertex - fn main(@location(0) position_1_param : vec4f, @location(1) color0_param : vec4f) -> main_out { - position_1 = position_1_param; - color0 = color0_param; - main_1(); - return main_out(gl_Position, color); - } - + diagnostic(off, derivative_uniformity); + + struct vs_params { + /_ @offset(0) _/ + mvp : mat4x4f, + } + + @group(0) @binding(0) var x_19 : vs_params; + + var position_1 : vec4f; + + var color : vec4f; + + var color0 : vec4f; + + var gl_Position : vec4f; + + fn main_1() { + let x_22 : mat4x4f = x_19.mvp; + let x_25 : vec4f = position_1; + gl_Position = (x_22 * x_25); + let x_31 : vec4f = color0; + color = x_31; + return; + } + + struct main_out { + @builtin(position) + gl_Position : vec4f, + @location(0) + color_1 : vec4f, + } + + @vertex + fn main(@location(0) position_1_param : vec4f, @location(1) color0_param : vec4f) -> main_out { + position_1 = position_1_param; + color0 = color0_param; + main_1(); + return main_out(gl_Position, color); + } + */ __gshared char[766] VS_SOURCE_WGSL = [ 0x64,0x69,0x61,0x67,0x6e,0x6f,0x73,0x74,0x69,0x63,0x28,0x6f,0x66,0x66,0x2c,0x20, @@ -501,30 +503,30 @@ __gshared char[766] VS_SOURCE_WGSL = [ 0x2c,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - diagnostic(off, derivative_uniformity); - - var frag_color : vec4f; - - var color : vec4f; - - fn main_1() { - let x_12 : vec4f = color; - frag_color = x_12; - return; - } - - struct main_out { - @location(0) - frag_color_1 : vec4f, - } - - @fragment - fn main(@location(0) color_param : vec4f) -> main_out { - color = color_param; - main_1(); - return main_out(frag_color); - } - + diagnostic(off, derivative_uniformity); + + var frag_color : vec4f; + + var color : vec4f; + + fn main_1() { + let x_12 : vec4f = color; + frag_color = x_12; + return; + } + + struct main_out { + @location(0) + frag_color_1 : vec4f, + } + + @fragment + fn main(@location(0) color_param : vec4f) -> main_out { + color = color_param; + main_1(); + return main_out(frag_color); + } + */ __gshared char[376] FS_SOURCE_WGSL = [ 0x64,0x69,0x61,0x67,0x6e,0x6f,0x73,0x74,0x69,0x63,0x28,0x6f,0x66,0x66,0x2c,0x20, @@ -552,73 +554,67 @@ __gshared char[376] FS_SOURCE_WGSL = [ 0x69,0x6e,0x5f,0x6f,0x75,0x74,0x28,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f, 0x72,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; - -sg.ShaderDesc noninterleaved_shader_desc(sg.Backend backend) @trusted @nogc nothrow { - sg.ShaderDesc desc; - switch (backend) { - case sg.Backend.Glcore33: - desc.attrs[0].name = "position"; - desc.attrs[1].name = "color0"; - desc.vs.source = &VS_SOURCE_GLSL330[0]; - desc.vs.entry = "main"; - desc.vs.uniform_blocks[0].size = 64; - desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; - desc.vs.uniform_blocks[0].uniforms[0].name = "vs_params"; - desc.vs.uniform_blocks[0].uniforms[0].type = sg.UniformType.Float4; - desc.vs.uniform_blocks[0].uniforms[0].array_count = 4; - desc.fs.source = &FS_SOURCE_GLSL330[0]; - desc.fs.entry = "main"; - desc.label = "noninterleaved_shader"; - break; - case sg.Backend.Gles3: - desc.attrs[0].name = "position"; - desc.attrs[1].name = "color0"; - desc.vs.source = &VS_SOURCE_GLSL300ES[0]; - desc.vs.entry = "main"; - desc.vs.uniform_blocks[0].size = 64; - desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; - desc.vs.uniform_blocks[0].uniforms[0].name = "vs_params"; - desc.vs.uniform_blocks[0].uniforms[0].type = sg.UniformType.Float4; - desc.vs.uniform_blocks[0].uniforms[0].array_count = 4; - desc.fs.source = &FS_SOURCE_GLSL300ES[0]; - desc.fs.entry = "main"; - desc.label = "noninterleaved_shader"; - break; - case sg.Backend.D3d11: - desc.attrs[0].sem_name = "TEXCOORD"; - desc.attrs[0].sem_index = 0; - desc.attrs[1].sem_name = "TEXCOORD"; - desc.attrs[1].sem_index = 1; - desc.vs.source = &VS_SOURCE_HLSL4[0]; - desc.vs.d3d11_target = "vs_4_0"; - desc.vs.entry = "main"; - desc.vs.uniform_blocks[0].size = 64; - desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; - desc.fs.source = &FS_SOURCE_HLSL4[0]; - desc.fs.d3d11_target = "ps_4_0"; - desc.fs.entry = "main"; - desc.label = "noninterleaved_shader"; - break; - case sg.Backend.Metal_macos: - desc.vs.source = &VS_SOURCE_METAL_MACOS[0]; - desc.vs.entry = "main0"; - desc.vs.uniform_blocks[0].size = 64; - desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; - desc.fs.source = &FS_SOURCE_METAL_MACOS[0]; - desc.fs.entry = "main0"; - desc.label = "noninterleaved_shader"; - break; - case sg.Backend.Wgpu: - desc.vs.source = &VS_SOURCE_WGSL[0]; - desc.vs.entry = "main"; - desc.vs.uniform_blocks[0].size = 64; - desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; - desc.fs.source = &FS_SOURCE_WGSL[0]; - desc.fs.entry = "main"; - desc.label = "noninterleaved_shader"; - break; - default: - break; - } - return desc; +sg.ShaderDesc noninterleavedShaderDesc(sg.Backend backend) @trusted @nogc nothrow { + sg.ShaderDesc desc; + desc.label = "noninterleaved_shader"; + switch (backend) { + case sg.Backend.Glcore: + desc.attrs[0].name = "position"; + desc.attrs[1].name = "color0"; + desc.vs.source = &VS_SOURCE_GLSL430[0]; + desc.vs.entry = "main"; + desc.vs.uniform_blocks[0].size = 64; + desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; + desc.vs.uniform_blocks[0].uniforms[0].name = "vs_params"; + desc.vs.uniform_blocks[0].uniforms[0].type = sg.UniformType.Float4; + desc.vs.uniform_blocks[0].uniforms[0].array_count = 4; + desc.fs.source = &FS_SOURCE_GLSL430[0]; + desc.fs.entry = "main"; + break; + case sg.Backend.Gles3: + desc.attrs[0].name = "position"; + desc.attrs[1].name = "color0"; + desc.vs.source = &VS_SOURCE_GLSL300ES[0]; + desc.vs.entry = "main"; + desc.vs.uniform_blocks[0].size = 64; + desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; + desc.vs.uniform_blocks[0].uniforms[0].name = "vs_params"; + desc.vs.uniform_blocks[0].uniforms[0].type = sg.UniformType.Float4; + desc.vs.uniform_blocks[0].uniforms[0].array_count = 4; + desc.fs.source = &FS_SOURCE_GLSL300ES[0]; + desc.fs.entry = "main"; + break; + case sg.Backend.D3d11: + desc.attrs[0].sem_name = "TEXCOORD"; + desc.attrs[0].sem_index = 0; + desc.attrs[1].sem_name = "TEXCOORD"; + desc.attrs[1].sem_index = 1; + desc.vs.source = &VS_SOURCE_HLSL4[0]; + desc.vs.d3d11_target = "vs_4_0"; + desc.vs.entry = "main"; + desc.vs.uniform_blocks[0].size = 64; + desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; + desc.fs.source = &FS_SOURCE_HLSL4[0]; + desc.fs.d3d11_target = "ps_4_0"; + desc.fs.entry = "main"; + break; + case sg.Backend.Metal_macos: + desc.vs.source = &VS_SOURCE_METAL_MACOS[0]; + desc.vs.entry = "main0"; + desc.vs.uniform_blocks[0].size = 64; + desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; + desc.fs.source = &FS_SOURCE_METAL_MACOS[0]; + desc.fs.entry = "main0"; + break; + case sg.Backend.Wgpu: + desc.vs.source = &VS_SOURCE_WGSL[0]; + desc.vs.entry = "main"; + desc.vs.uniform_blocks[0].size = 64; + desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; + desc.fs.source = &FS_SOURCE_WGSL[0]; + desc.fs.entry = "main"; + break; + default: break; + } + return desc; } diff --git a/src/shaders/offscreen.d b/src/shaders/offscreen.d index fb209f9..f268f49 100644 --- a/src/shaders/offscreen.d +++ b/src/shaders/offscreen.d @@ -1,222 +1,225 @@ module shaders.offscreen; import sg = sokol.gfx; +import m = handmade.math; extern(C): /* #version:1# (machine generated, don't edit!) - + Generated by sokol-shdc (https://github.com/floooh/sokol-tools) - - Cmdline: sokol-shdc -i src/shaders/offscreen.glsl -o src/shaders/offscreen.d -l glsl330:metal_macos:hlsl4:glsl300es:wgsl -f sokol_d - + + Cmdline: + sokol-shdc -i src/shaders/offscreen.glsl -o src/shaders/offscreen.d -l glsl430:metal_macos:hlsl4:glsl300es:wgsl -f sokol_d + Overview: - - Shader program 'default': - Get shader desc: default_shader_desc(sg.query_backend()); - Vertex shader: vs_default - Attribute slots: - ATTR_VS_DEFAULT_POSITION = 0 - ATTR_VS_DEFAULT_NORMAL = 1 - ATTR_VS_DEFAULT_TEXCOORD0 = 2 - Uniform block 'vs_params': - C struct: vs_params_t - Bind slot: SLOT_VS_PARAMS = 0 - Fragment shader: fs_default - Image 'tex': - Type: sg.ImageType._2d - Sample Type: sg.ImageSampleType.Float - Bind slot: SLOT_TEX = 0 - Image 'tex': - Image Type: sg.ImageType._2d - Sample Type: sg.ImageSampleType.Float - Multisampled: false - Bind slot: SLOT_tex = 0 - Sampler 'smp': - Type: sg.SamplerType.Filtering - Bind slot: SLOT_smp = 0 - Image Sampler Pair 'tex_smp': - Image: tex - Sampler: smp - - Shader program 'offscreen': - Get shader desc: offscreen_shader_desc(sg.query_backend()); - Vertex shader: vs_offscreen - Attribute slots: - ATTR_VS_OFFSCREEN_POSITION = 0 - ATTR_VS_OFFSCREEN_NORMAL = 1 - Uniform block 'vs_params': - C struct: vs_params_t - Bind slot: SLOT_VS_PARAMS = 0 - Fragment shader: fs_offscreen - + ========= + Shader program: 'default': + Get shader desc: defaultShaderDesc(sg.queryBackend()); + Vertex shader: vs_default + Attributes: + ATTR_VS_DEFAULT_POSITION => 0 + ATTR_VS_DEFAULT_NORMAL => 1 + ATTR_VS_DEFAULT_TEXCOORD0 => 2 + Uniform block 'vs_params': + D struct: VsParams + Bind slot: SLOT_VS_PARAMS => 0 + Fragment shader: fs_default + Image 'tex': + Image type: sg.ImageType._2d + Sample type: sg.ImageSampleType.Float + Multisampled: false + Bind slot: SLOT_TEX => 0 + Sampler 'smp': + Type: sg.SamplerType.Filtering + Bind slot: SLOT_SMP => 0 + Image Sampler Pair 'tex_smp': + Image: tex + Sampler: smp + Shader program: 'offscreen': + Get shader desc: offscreenShaderDesc(sg.queryBackend()); + Vertex shader: vs_offscreen + Attributes: + ATTR_VS_OFFSCREEN_POSITION => 0 + ATTR_VS_OFFSCREEN_NORMAL => 1 + Uniform block 'vs_params': + D struct: VsParams + Bind slot: SLOT_VS_PARAMS => 0 + Fragment shader: fs_offscreen */ -import m = handmade.math; -enum ATTR_VS_OFFSCREEN_POSITION = 0; -enum ATTR_VS_OFFSCREEN_NORMAL = 1; enum ATTR_VS_DEFAULT_POSITION = 0; enum ATTR_VS_DEFAULT_NORMAL = 1; enum ATTR_VS_DEFAULT_TEXCOORD0 = 2; +enum ATTR_VS_OFFSCREEN_POSITION = 0; +enum ATTR_VS_OFFSCREEN_NORMAL = 1; +enum SLOT_VS_PARAMS = 0; enum SLOT_TEX = 0; enum SLOT_SMP = 0; -enum SLOT_VS_PARAMS = 0; struct VsParams { - m.Mat4 mvp; + align(16) m.Mat4 mvp; } /* - #version 330 - - uniform vec4 vs_params[4]; - layout(location = 0) in vec4 position; - out vec4 nrm; - layout(location = 1) in vec4 normal; - - void main() - { - gl_Position = mat4(vs_params[0], vs_params[1], vs_params[2], vs_params[3]) * position; - nrm = normal; - } - + #version 430 + + uniform vec4 vs_params[4]; + layout(location = 0) in vec4 position; + layout(location = 0) out vec4 nrm; + layout(location = 1) in vec4 normal; + + void main() + { + gl_Position = mat4(vs_params[0], vs_params[1], vs_params[2], vs_params[3]) * position; + nrm = normal; + } + */ -__gshared char[259] VS_OFFSCREEN_SOURCE_GLSL330 = [ - 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x33,0x30,0x0a,0x0a,0x75,0x6e, +__gshared char[280] VS_OFFSCREEN_SOURCE_GLSL430 = [ + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x75,0x6e, 0x69,0x66,0x6f,0x72,0x6d,0x20,0x76,0x65,0x63,0x34,0x20,0x76,0x73,0x5f,0x70,0x61, 0x72,0x61,0x6d,0x73,0x5b,0x34,0x5d,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28, 0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e, 0x20,0x76,0x65,0x63,0x34,0x20,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a, - 0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x6e,0x72,0x6d,0x3b,0x0a,0x6c,0x61, - 0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, - 0x31,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20,0x6e,0x6f,0x72,0x6d,0x61, - 0x6c,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a, - 0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f, - 0x6e,0x20,0x3d,0x20,0x6d,0x61,0x74,0x34,0x28,0x76,0x73,0x5f,0x70,0x61,0x72,0x61, - 0x6d,0x73,0x5b,0x30,0x5d,0x2c,0x20,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73, - 0x5b,0x31,0x5d,0x2c,0x20,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x32, - 0x5d,0x2c,0x20,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x33,0x5d,0x29, - 0x20,0x2a,0x20,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x6e,0x72,0x6d,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x3b,0x0a,0x7d, - 0x0a,0x0a,0x00, + 0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20, + 0x3d,0x20,0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x6e,0x72, + 0x6d,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69, + 0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20, + 0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61, + 0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f, + 0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x6d,0x61,0x74,0x34,0x28,0x76,0x73, + 0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x30,0x5d,0x2c,0x20,0x76,0x73,0x5f,0x70, + 0x61,0x72,0x61,0x6d,0x73,0x5b,0x31,0x5d,0x2c,0x20,0x76,0x73,0x5f,0x70,0x61,0x72, + 0x61,0x6d,0x73,0x5b,0x32,0x5d,0x2c,0x20,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d, + 0x73,0x5b,0x33,0x5d,0x29,0x20,0x2a,0x20,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x72,0x6d,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d, + 0x61,0x6c,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - #version 330 - - layout(location = 0) out vec4 frag_color; - in vec4 nrm; - - void main() - { - frag_color = vec4((nrm.xyz * 0.5) + vec3(0.5), 1.0); - } - + #version 430 + + layout(location = 0) out vec4 frag_color; + layout(location = 0) in vec4 nrm; + + void main() + { + frag_color = vec4((nrm.xyz * 0.5) + vec3(0.5), 1.0); + } + */ -__gshared char[145] FS_OFFSCREEN_SOURCE_GLSL330 = [ - 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x33,0x30,0x0a,0x0a,0x6c,0x61, +__gshared char[166] FS_OFFSCREEN_SOURCE_GLSL430 = [ + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x6c,0x61, 0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, 0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x66,0x72,0x61,0x67, - 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20, - 0x6e,0x72,0x6d,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28, - 0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c, - 0x6f,0x72,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x28,0x6e,0x72,0x6d,0x2e,0x78, - 0x79,0x7a,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x76,0x65,0x63,0x33, - 0x28,0x30,0x2e,0x35,0x29,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x7d,0x0a,0x0a, - 0x00, + 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c, + 0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e,0x20, + 0x76,0x65,0x63,0x34,0x20,0x6e,0x72,0x6d,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20, + 0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61, + 0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x28, + 0x6e,0x72,0x6d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b, + 0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x35,0x29,0x2c,0x20,0x31,0x2e,0x30,0x29, + 0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - #version 330 - - uniform vec4 vs_params[4]; - layout(location = 0) in vec4 position; - out vec2 uv; - layout(location = 2) in vec2 texcoord0; - out vec4 nrm; - layout(location = 1) in vec4 normal; - - void main() - { - mat4 _22 = mat4(vs_params[0], vs_params[1], vs_params[2], vs_params[3]); - gl_Position = _22 * position; - uv = texcoord0; - nrm = _22 * normal; - } - + #version 430 + + uniform vec4 vs_params[4]; + layout(location = 0) in vec4 position; + layout(location = 1) out vec2 uv; + layout(location = 2) in vec2 texcoord0; + layout(location = 0) out vec4 nrm; + layout(location = 1) in vec4 normal; + + void main() + { + mat4 _22 = mat4(vs_params[0], vs_params[1], vs_params[2], vs_params[3]); + gl_Position = _22 * position; + uv = texcoord0; + nrm = _22 * normal; + } + */ -__gshared char[358] VS_DEFAULT_SOURCE_GLSL330 = [ - 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x33,0x30,0x0a,0x0a,0x75,0x6e, +__gshared char[400] VS_DEFAULT_SOURCE_GLSL430 = [ + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x75,0x6e, 0x69,0x66,0x6f,0x72,0x6d,0x20,0x76,0x65,0x63,0x34,0x20,0x76,0x73,0x5f,0x70,0x61, 0x72,0x61,0x6d,0x73,0x5b,0x34,0x5d,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28, 0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e, 0x20,0x76,0x65,0x63,0x34,0x20,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a, - 0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x32,0x20,0x75,0x76,0x3b,0x0a,0x6c,0x61,0x79, - 0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x32, - 0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x32,0x20,0x74,0x65,0x78,0x63,0x6f,0x6f, - 0x72,0x64,0x30,0x3b,0x0a,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x6e,0x72, - 0x6d,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69, - 0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20, - 0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61, - 0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x74,0x34,0x20, - 0x5f,0x32,0x32,0x20,0x3d,0x20,0x6d,0x61,0x74,0x34,0x28,0x76,0x73,0x5f,0x70,0x61, - 0x72,0x61,0x6d,0x73,0x5b,0x30,0x5d,0x2c,0x20,0x76,0x73,0x5f,0x70,0x61,0x72,0x61, - 0x6d,0x73,0x5b,0x31,0x5d,0x2c,0x20,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73, - 0x5b,0x32,0x5d,0x2c,0x20,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x33, - 0x5d,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74, - 0x69,0x6f,0x6e,0x20,0x3d,0x20,0x5f,0x32,0x32,0x20,0x2a,0x20,0x70,0x6f,0x73,0x69, - 0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x75,0x76,0x20,0x3d,0x20,0x74, - 0x65,0x78,0x63,0x6f,0x6f,0x72,0x64,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x72, - 0x6d,0x20,0x3d,0x20,0x5f,0x32,0x32,0x20,0x2a,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c, - 0x3b,0x0a,0x7d,0x0a,0x0a,0x00, + 0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20, + 0x3d,0x20,0x31,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x32,0x20,0x75,0x76, + 0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f, + 0x6e,0x20,0x3d,0x20,0x32,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x32,0x20,0x74, + 0x65,0x78,0x63,0x6f,0x6f,0x72,0x64,0x30,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74, + 0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x6f, + 0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x6e,0x72,0x6d,0x3b,0x0a,0x6c,0x61,0x79, + 0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31, + 0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c, + 0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x74,0x34,0x20,0x5f,0x32,0x32,0x20,0x3d,0x20, + 0x6d,0x61,0x74,0x34,0x28,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x30, + 0x5d,0x2c,0x20,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x31,0x5d,0x2c, + 0x20,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x32,0x5d,0x2c,0x20,0x76, + 0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x33,0x5d,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, + 0x5f,0x32,0x32,0x20,0x2a,0x20,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x75,0x76,0x20,0x3d,0x20,0x74,0x65,0x78,0x63,0x6f,0x6f,0x72, + 0x64,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x72,0x6d,0x20,0x3d,0x20,0x5f,0x32, + 0x32,0x20,0x2a,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, + ]; /* - #version 330 - - uniform sampler2D tex_smp; - - in vec2 uv; - in vec4 nrm; - layout(location = 0) out vec4 frag_color; - - void main() - { - frag_color = vec4(texture(tex_smp, uv * vec2(20.0, 10.0)).xyz * (clamp(dot(nrm.xyz, vec3(0.57735025882720947265625, 0.57735025882720947265625, -0.57735025882720947265625)), 0.0, 1.0) * 2.0 + 0.25), 1.0); - } - -*/ -__gshared char[336] FS_DEFAULT_SOURCE_GLSL330 = [ - 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x33,0x30,0x0a,0x0a,0x75,0x6e, - 0x69,0x66,0x6f,0x72,0x6d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x32,0x44,0x20, - 0x74,0x65,0x78,0x5f,0x73,0x6d,0x70,0x3b,0x0a,0x0a,0x69,0x6e,0x20,0x76,0x65,0x63, - 0x32,0x20,0x75,0x76,0x3b,0x0a,0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20,0x6e,0x72, - 0x6d,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69, - 0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34, - 0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x0a,0x76,0x6f, - 0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x76,0x65,0x63, - 0x34,0x28,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x74,0x65,0x78,0x5f,0x73,0x6d, - 0x70,0x2c,0x20,0x75,0x76,0x20,0x2a,0x20,0x76,0x65,0x63,0x32,0x28,0x32,0x30,0x2e, - 0x30,0x2c,0x20,0x31,0x30,0x2e,0x30,0x29,0x29,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20, - 0x28,0x63,0x6c,0x61,0x6d,0x70,0x28,0x64,0x6f,0x74,0x28,0x6e,0x72,0x6d,0x2e,0x78, - 0x79,0x7a,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x35,0x37,0x37,0x33,0x35, - 0x30,0x32,0x35,0x38,0x38,0x32,0x37,0x32,0x30,0x39,0x34,0x37,0x32,0x36,0x35,0x36, - 0x32,0x35,0x2c,0x20,0x30,0x2e,0x35,0x37,0x37,0x33,0x35,0x30,0x32,0x35,0x38,0x38, - 0x32,0x37,0x32,0x30,0x39,0x34,0x37,0x32,0x36,0x35,0x36,0x32,0x35,0x2c,0x20,0x2d, - 0x30,0x2e,0x35,0x37,0x37,0x33,0x35,0x30,0x32,0x35,0x38,0x38,0x32,0x37,0x32,0x30, - 0x39,0x34,0x37,0x32,0x36,0x35,0x36,0x32,0x35,0x29,0x29,0x2c,0x20,0x30,0x2e,0x30, - 0x2c,0x20,0x31,0x2e,0x30,0x29,0x20,0x2a,0x20,0x32,0x2e,0x30,0x20,0x2b,0x20,0x30, - 0x2e,0x32,0x35,0x29,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, + #version 430 + + layout(binding = 0) uniform sampler2D tex_smp; + + layout(location = 1) in vec2 uv; + layout(location = 0) in vec4 nrm; + layout(location = 0) out vec4 frag_color; + + void main() + { + frag_color = vec4(texture(tex_smp, uv * vec2(20.0, 10.0)).xyz * fma(clamp(dot(nrm.xyz, vec3(0.57735025882720947265625, 0.57735025882720947265625, -0.57735025882720947265625)), 0.0, 1.0), 2.0, 0.25), 1.0); + } +*/ +__gshared char[399] FS_DEFAULT_SOURCE_GLSL430 = [ + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x6c,0x61, + 0x79,0x6f,0x75,0x74,0x28,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d,0x20,0x30, + 0x29,0x20,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65, + 0x72,0x32,0x44,0x20,0x74,0x65,0x78,0x5f,0x73,0x6d,0x70,0x3b,0x0a,0x0a,0x6c,0x61, + 0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, + 0x31,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x32,0x20,0x75,0x76,0x3b,0x0a,0x6c, + 0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d, + 0x20,0x30,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20,0x6e,0x72,0x6d,0x3b, + 0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e, + 0x20,0x3d,0x20,0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x66, + 0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64, + 0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72, + 0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28, + 0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x74,0x65,0x78,0x5f,0x73,0x6d,0x70,0x2c, + 0x20,0x75,0x76,0x20,0x2a,0x20,0x76,0x65,0x63,0x32,0x28,0x32,0x30,0x2e,0x30,0x2c, + 0x20,0x31,0x30,0x2e,0x30,0x29,0x29,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x66,0x6d, + 0x61,0x28,0x63,0x6c,0x61,0x6d,0x70,0x28,0x64,0x6f,0x74,0x28,0x6e,0x72,0x6d,0x2e, + 0x78,0x79,0x7a,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x35,0x37,0x37,0x33, + 0x35,0x30,0x32,0x35,0x38,0x38,0x32,0x37,0x32,0x30,0x39,0x34,0x37,0x32,0x36,0x35, + 0x36,0x32,0x35,0x2c,0x20,0x30,0x2e,0x35,0x37,0x37,0x33,0x35,0x30,0x32,0x35,0x38, + 0x38,0x32,0x37,0x32,0x30,0x39,0x34,0x37,0x32,0x36,0x35,0x36,0x32,0x35,0x2c,0x20, + 0x2d,0x30,0x2e,0x35,0x37,0x37,0x33,0x35,0x30,0x32,0x35,0x38,0x38,0x32,0x37,0x32, + 0x30,0x39,0x34,0x37,0x32,0x36,0x35,0x36,0x32,0x35,0x29,0x29,0x2c,0x20,0x30,0x2e, + 0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x2c,0x20,0x32,0x2e,0x30,0x2c,0x20,0x30,0x2e, + 0x32,0x35,0x29,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - #version 300 es - - uniform vec4 vs_params[4]; - layout(location = 0) in vec4 position; - out vec4 nrm; - layout(location = 1) in vec4 normal; - - void main() - { - gl_Position = mat4(vs_params[0], vs_params[1], vs_params[2], vs_params[3]) * position; - nrm = normal; - } - + #version 300 es + + uniform vec4 vs_params[4]; + layout(location = 0) in vec4 position; + out vec4 nrm; + layout(location = 1) in vec4 normal; + + void main() + { + gl_Position = mat4(vs_params[0], vs_params[1], vs_params[2], vs_params[3]) * position; + nrm = normal; + } + */ __gshared char[262] VS_OFFSCREEN_SOURCE_GLSL300ES = [ 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x30,0x30,0x20,0x65,0x73,0x0a, @@ -238,18 +241,18 @@ __gshared char[262] VS_OFFSCREEN_SOURCE_GLSL300ES = [ 0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - #version 300 es - precision mediump float; - precision highp int; - - layout(location = 0) out highp vec4 frag_color; - in highp vec4 nrm; - - void main() - { - frag_color = vec4((nrm.xyz * 0.5) + vec3(0.5), 1.0); - } - + #version 300 es + precision mediump float; + precision highp int; + + layout(location = 0) out highp vec4 frag_color; + in highp vec4 nrm; + + void main() + { + frag_color = vec4((nrm.xyz * 0.5) + vec3(0.5), 1.0); + } + */ __gshared char[206] FS_OFFSCREEN_SOURCE_GLSL300ES = [ 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x30,0x30,0x20,0x65,0x73,0x0a, @@ -267,23 +270,23 @@ __gshared char[206] FS_OFFSCREEN_SOURCE_GLSL300ES = [ 0x35,0x29,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - #version 300 es - - uniform vec4 vs_params[4]; - layout(location = 0) in vec4 position; - out vec2 uv; - layout(location = 2) in vec2 texcoord0; - out vec4 nrm; - layout(location = 1) in vec4 normal; - - void main() - { - mat4 _22 = mat4(vs_params[0], vs_params[1], vs_params[2], vs_params[3]); - gl_Position = _22 * position; - uv = texcoord0; - nrm = _22 * normal; - } - + #version 300 es + + uniform vec4 vs_params[4]; + layout(location = 0) in vec4 position; + out vec2 uv; + layout(location = 2) in vec2 texcoord0; + out vec4 nrm; + layout(location = 1) in vec4 normal; + + void main() + { + mat4 _22 = mat4(vs_params[0], vs_params[1], vs_params[2], vs_params[3]); + gl_Position = _22 * position; + uv = texcoord0; + nrm = _22 * normal; + } + */ __gshared char[361] VS_DEFAULT_SOURCE_GLSL300ES = [ 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x30,0x30,0x20,0x65,0x73,0x0a, @@ -311,21 +314,21 @@ __gshared char[361] VS_DEFAULT_SOURCE_GLSL300ES = [ 0x6d,0x61,0x6c,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - #version 300 es - precision mediump float; - precision highp int; - - uniform highp sampler2D tex_smp; - - in highp vec2 uv; - in highp vec4 nrm; - layout(location = 0) out highp vec4 frag_color; - - void main() - { - frag_color = vec4(texture(tex_smp, uv * vec2(20.0, 10.0)).xyz * (clamp(dot(nrm.xyz, vec3(0.57735025882720947265625, 0.57735025882720947265625, -0.57735025882720947265625)), 0.0, 1.0) * 2.0 + 0.25), 1.0); - } - + #version 300 es + precision mediump float; + precision highp int; + + uniform highp sampler2D tex_smp; + + in highp vec2 uv; + in highp vec4 nrm; + layout(location = 0) out highp vec4 frag_color; + + void main() + { + frag_color = vec4(texture(tex_smp, uv * vec2(20.0, 10.0)).xyz * (clamp(dot(nrm.xyz, vec3(0.57735025882720947265625, 0.57735025882720947265625, -0.57735025882720947265625)), 0.0, 1.0) * 2.0 + 0.25), 1.0); + } + */ __gshared char[409] FS_DEFAULT_SOURCE_GLSL300ES = [ 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x30,0x30,0x20,0x65,0x73,0x0a, @@ -356,45 +359,45 @@ __gshared char[409] FS_DEFAULT_SOURCE_GLSL300ES = [ 0x2e,0x30,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - cbuffer vs_params : register(b0) - { - row_major float4x4 _19_mvp : packoffset(c0); - }; - - - static float4 gl_Position; - static float4 position; - static float4 nrm; - static float4 normal; - - struct SPIRV_Cross_Input - { - float4 position : TEXCOORD0; - float4 normal : TEXCOORD1; - }; - - struct SPIRV_Cross_Output - { - float4 nrm : TEXCOORD0; - float4 gl_Position : SV_Position; - }; - - void vert_main() - { - gl_Position = mul(position, _19_mvp); - nrm = normal; - } - - SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) - { - position = stage_input.position; - normal = stage_input.normal; - vert_main(); - SPIRV_Cross_Output stage_output; - stage_output.gl_Position = gl_Position; - stage_output.nrm = nrm; - return stage_output; - } + cbuffer vs_params : register(b0) + { + row_major float4x4 _19_mvp : packoffset(c0); + }; + + + static float4 gl_Position; + static float4 position; + static float4 nrm; + static float4 normal; + + struct SPIRV_Cross_Input + { + float4 position : TEXCOORD0; + float4 normal : TEXCOORD1; + }; + + struct SPIRV_Cross_Output + { + float4 nrm : TEXCOORD0; + float4 gl_Position : SV_Position; + }; + + void vert_main() + { + gl_Position = mul(position, _19_mvp); + nrm = normal; + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + position = stage_input.position; + normal = stage_input.normal; + vert_main(); + SPIRV_Cross_Output stage_output; + stage_output.gl_Position = gl_Position; + stage_output.nrm = nrm; + return stage_output; + } */ __gshared char[738] VS_OFFSCREEN_SOURCE_HLSL4 = [ 0x63,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d, @@ -446,32 +449,32 @@ __gshared char[738] VS_OFFSCREEN_SOURCE_HLSL4 = [ 0x0a,0x00, ]; /* - static float4 frag_color; - static float4 nrm; - - struct SPIRV_Cross_Input - { - float4 nrm : TEXCOORD0; - }; - - struct SPIRV_Cross_Output - { - float4 frag_color : SV_Target0; - }; - - void frag_main() - { - frag_color = float4((nrm.xyz * 0.5f) + 0.5f.xxx, 1.0f); - } - - SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) - { - nrm = stage_input.nrm; - frag_main(); - SPIRV_Cross_Output stage_output; - stage_output.frag_color = frag_color; - return stage_output; - } + static float4 frag_color; + static float4 nrm; + + struct SPIRV_Cross_Input + { + float4 nrm : TEXCOORD0; + }; + + struct SPIRV_Cross_Output + { + float4 frag_color : SV_Target0; + }; + + void frag_main() + { + frag_color = float4((nrm.xyz * 0.5f) + 0.5f.xxx, 1.0f); + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + nrm = stage_input.nrm; + frag_main(); + SPIRV_Cross_Output stage_output; + stage_output.frag_color = frag_color; + return stage_output; + } */ __gshared char[463] FS_OFFSCREEN_SOURCE_HLSL4 = [ 0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x66,0x72, @@ -505,52 +508,52 @@ __gshared char[463] FS_OFFSCREEN_SOURCE_HLSL4 = [ 0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x00, ]; /* - cbuffer vs_params : register(b0) - { - row_major float4x4 _19_mvp : packoffset(c0); - }; - - - static float4 gl_Position; - static float4 position; - static float2 uv; - static float2 texcoord0; - static float4 nrm; - static float4 normal; - - struct SPIRV_Cross_Input - { - float4 position : TEXCOORD0; - float4 normal : TEXCOORD1; - float2 texcoord0 : TEXCOORD2; - }; - - struct SPIRV_Cross_Output - { - float4 nrm : TEXCOORD0; - float2 uv : TEXCOORD1; - float4 gl_Position : SV_Position; - }; - - void vert_main() - { - gl_Position = mul(position, _19_mvp); - uv = texcoord0; - nrm = mul(normal, _19_mvp); - } - - SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) - { - position = stage_input.position; - texcoord0 = stage_input.texcoord0; - normal = stage_input.normal; - vert_main(); - SPIRV_Cross_Output stage_output; - stage_output.gl_Position = gl_Position; - stage_output.uv = uv; - stage_output.nrm = nrm; - return stage_output; - } + cbuffer vs_params : register(b0) + { + row_major float4x4 _19_mvp : packoffset(c0); + }; + + + static float4 gl_Position; + static float4 position; + static float2 uv; + static float2 texcoord0; + static float4 nrm; + static float4 normal; + + struct SPIRV_Cross_Input + { + float4 position : TEXCOORD0; + float4 normal : TEXCOORD1; + float2 texcoord0 : TEXCOORD2; + }; + + struct SPIRV_Cross_Output + { + float4 nrm : TEXCOORD0; + float2 uv : TEXCOORD1; + float4 gl_Position : SV_Position; + }; + + void vert_main() + { + gl_Position = mul(position, _19_mvp); + uv = texcoord0; + nrm = mul(normal, _19_mvp); + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + position = stage_input.position; + texcoord0 = stage_input.texcoord0; + normal = stage_input.normal; + vert_main(); + SPIRV_Cross_Output stage_output; + stage_output.gl_Position = gl_Position; + stage_output.uv = uv; + stage_output.nrm = nrm; + return stage_output; + } */ __gshared char[941] VS_DEFAULT_SOURCE_HLSL4 = [ 0x63,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d, @@ -614,38 +617,38 @@ __gshared char[941] VS_DEFAULT_SOURCE_HLSL4 = [ 0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x00, ]; /* - Texture2D tex : register(t0); - SamplerState smp : register(s0); - - static float2 uv; - static float4 nrm; - static float4 frag_color; - - struct SPIRV_Cross_Input - { - float4 nrm : TEXCOORD0; - float2 uv : TEXCOORD1; - }; - - struct SPIRV_Cross_Output - { - float4 frag_color : SV_Target0; - }; - - void frag_main() - { - frag_color = float4(tex.Sample(smp, uv * float2(20.0f, 10.0f)).xyz * mad(clamp(dot(nrm.xyz, float3(0.57735025882720947265625f, 0.57735025882720947265625f, -0.57735025882720947265625f)), 0.0f, 1.0f), 2.0f, 0.25f), 1.0f); - } - - SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) - { - uv = stage_input.uv; - nrm = stage_input.nrm; - frag_main(); - SPIRV_Cross_Output stage_output; - stage_output.frag_color = frag_color; - return stage_output; - } + Texture2D tex : register(t0); + SamplerState smp : register(s0); + + static float2 uv; + static float4 nrm; + static float4 frag_color; + + struct SPIRV_Cross_Input + { + float4 nrm : TEXCOORD0; + float2 uv : TEXCOORD1; + }; + + struct SPIRV_Cross_Output + { + float4 frag_color : SV_Target0; + }; + + void frag_main() + { + frag_color = float4(tex.Sample(smp, uv * float2(20.0f, 10.0f)).xyz * mad(clamp(dot(nrm.xyz, float3(0.57735025882720947265625f, 0.57735025882720947265625f, -0.57735025882720947265625f)), 0.0f, 1.0f), 2.0f, 0.25f), 1.0f); + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + uv = stage_input.uv; + nrm = stage_input.nrm; + frag_main(); + SPIRV_Cross_Output stage_output; + stage_output.frag_color = frag_color; + return stage_output; + } */ __gshared char[769] FS_DEFAULT_SOURCE_HLSL4 = [ 0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x44,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34, @@ -699,36 +702,36 @@ __gshared char[769] FS_DEFAULT_SOURCE_HLSL4 = [ 0x00, ]; /* - #include - #include - - using namespace metal; - - struct vs_params - { - float4x4 mvp; - }; - - struct main0_out - { - float4 nrm [[user(locn0)]]; - float4 gl_Position [[position]]; - }; - - struct main0_in - { - float4 position [[attribute(0)]]; - float4 normal [[attribute(1)]]; - }; - - vertex main0_out main0(main0_in in [[stage_in]], constant vs_params& _19 [[buffer(0)]]) - { - main0_out out = {}; - out.gl_Position = _19.mvp * in.position; - out.nrm = in.normal; - return out; - } - + #include + #include + + using namespace metal; + + struct vs_params + { + float4x4 mvp; + }; + + struct main0_out + { + float4 nrm [[user(locn0)]]; + float4 gl_Position [[position]]; + }; + + struct main0_in + { + float4 position [[attribute(0)]]; + float4 normal [[attribute(1)]]; + }; + + vertex main0_out main0(main0_in in [[stage_in]], constant vs_params& _19 [[buffer(0)]]) + { + main0_out out = {}; + out.gl_Position = _19.mvp * in.position; + out.nrm = in.normal; + return out; + } + */ __gshared char[505] VS_OFFSCREEN_SOURCE_METAL_MACOS = [ 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, @@ -765,28 +768,28 @@ __gshared char[505] VS_OFFSCREEN_SOURCE_METAL_MACOS = [ 0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - #include - #include - - using namespace metal; - - struct main0_out - { - float4 frag_color [[color(0)]]; - }; - - struct main0_in - { - float4 nrm [[user(locn0)]]; - }; - - fragment main0_out main0(main0_in in [[stage_in]]) - { - main0_out out = {}; - out.frag_color = float4((in.nrm.xyz * 0.5) + float3(0.5), 1.0); - return out; - } - + #include + #include + + using namespace metal; + + struct main0_out + { + float4 frag_color [[color(0)]]; + }; + + struct main0_in + { + float4 nrm [[user(locn0)]]; + }; + + fragment main0_out main0(main0_in in [[stage_in]]) + { + main0_out out = {}; + out.frag_color = float4((in.nrm.xyz * 0.5) + float3(0.5), 1.0); + return out; + } + */ __gshared char[350] FS_OFFSCREEN_SOURCE_METAL_MACOS = [ 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, @@ -813,39 +816,39 @@ __gshared char[350] FS_OFFSCREEN_SOURCE_METAL_MACOS = [ 0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - #include - #include - - using namespace metal; - - struct vs_params - { - float4x4 mvp; - }; - - struct main0_out - { - float4 nrm [[user(locn0)]]; - float2 uv [[user(locn1)]]; - float4 gl_Position [[position]]; - }; - - struct main0_in - { - float4 position [[attribute(0)]]; - float4 normal [[attribute(1)]]; - float2 texcoord0 [[attribute(2)]]; - }; - - vertex main0_out main0(main0_in in [[stage_in]], constant vs_params& _19 [[buffer(0)]]) - { - main0_out out = {}; - out.gl_Position = _19.mvp * in.position; - out.uv = in.texcoord0; - out.nrm = _19.mvp * in.normal; - return out; - } - + #include + #include + + using namespace metal; + + struct vs_params + { + float4x4 mvp; + }; + + struct main0_out + { + float4 nrm [[user(locn0)]]; + float2 uv [[user(locn1)]]; + float4 gl_Position [[position]]; + }; + + struct main0_in + { + float4 position [[attribute(0)]]; + float4 normal [[attribute(1)]]; + float2 texcoord0 [[attribute(2)]]; + }; + + vertex main0_out main0(main0_in in [[stage_in]], constant vs_params& _19 [[buffer(0)]]) + { + main0_out out = {}; + out.gl_Position = _19.mvp * in.position; + out.uv = in.texcoord0; + out.nrm = _19.mvp * in.normal; + return out; + } + */ __gshared char[612] VS_DEFAULT_SOURCE_METAL_MACOS = [ 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, @@ -889,29 +892,29 @@ __gshared char[612] VS_DEFAULT_SOURCE_METAL_MACOS = [ 0x7d,0x0a,0x0a,0x00, ]; /* - #include - #include - - using namespace metal; - - struct main0_out - { - float4 frag_color [[color(0)]]; - }; - - struct main0_in - { - float4 nrm [[user(locn0)]]; - float2 uv [[user(locn1)]]; - }; - - fragment main0_out main0(main0_in in [[stage_in]], texture2d tex [[texture(0)]], sampler smp [[sampler(0)]]) - { - main0_out out = {}; - out.frag_color = float4(tex.sample(smp, (in.uv * float2(20.0, 10.0))).xyz * fma(fast::clamp(dot(in.nrm.xyz, float3(0.57735025882720947265625, 0.57735025882720947265625, -0.57735025882720947265625)), 0.0, 1.0), 2.0, 0.25), 1.0); - return out; - } - + #include + #include + + using namespace metal; + + struct main0_out + { + float4 frag_color [[color(0)]]; + }; + + struct main0_in + { + float4 nrm [[user(locn0)]]; + float2 uv [[user(locn1)]]; + }; + + fragment main0_out main0(main0_in in [[stage_in]], texture2d tex [[texture(0)]], sampler smp [[sampler(0)]]) + { + main0_out out = {}; + out.frag_color = float4(tex.sample(smp, (in.uv * float2(20.0, 10.0))).xyz * fma(fast::clamp(dot(in.nrm.xyz, float3(0.57735025882720947265625, 0.57735025882720947265625, -0.57735025882720947265625)), 0.0, 1.0), 2.0, 0.25), 1.0); + return out; + } + */ __gshared char[610] FS_DEFAULT_SOURCE_METAL_MACOS = [ 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, @@ -955,47 +958,47 @@ __gshared char[610] FS_DEFAULT_SOURCE_METAL_MACOS = [ 0x0a,0x00, ]; /* - diagnostic(off, derivative_uniformity); - - struct vs_params { - /_ @offset(0) _/ - mvp : mat4x4f, - } - - @group(0) @binding(0) var x_19 : vs_params; - - var position_1 : vec4f; - - var nrm : vec4f; - - var normal : vec4f; - - var gl_Position : vec4f; - - fn main_1() { - let x_22 : mat4x4f = x_19.mvp; - let x_25 : vec4f = position_1; - gl_Position = (x_22 * x_25); - let x_31 : vec4f = normal; - nrm = x_31; - return; - } - - struct main_out { - @builtin(position) - gl_Position : vec4f, - @location(0) - nrm_1 : vec4f, - } - - @vertex - fn main(@location(0) position_1_param : vec4f, @location(1) normal_param : vec4f) -> main_out { - position_1 = position_1_param; - normal = normal_param; - main_1(); - return main_out(gl_Position, nrm); - } - + diagnostic(off, derivative_uniformity); + + struct vs_params { + /_ @offset(0) _/ + mvp : mat4x4f, + } + + @group(0) @binding(0) var x_19 : vs_params; + + var position_1 : vec4f; + + var nrm : vec4f; + + var normal : vec4f; + + var gl_Position : vec4f; + + fn main_1() { + let x_22 : mat4x4f = x_19.mvp; + let x_25 : vec4f = position_1; + gl_Position = (x_22 * x_25); + let x_31 : vec4f = normal; + nrm = x_31; + return; + } + + struct main_out { + @builtin(position) + gl_Position : vec4f, + @location(0) + nrm_1 : vec4f, + } + + @vertex + fn main(@location(0) position_1_param : vec4f, @location(1) normal_param : vec4f) -> main_out { + position_1 = position_1_param; + normal = normal_param; + main_1(); + return main_out(gl_Position, nrm); + } + */ __gshared char[758] VS_OFFSCREEN_SOURCE_WGSL = [ 0x64,0x69,0x61,0x67,0x6e,0x6f,0x73,0x74,0x69,0x63,0x28,0x6f,0x66,0x66,0x2c,0x20, @@ -1048,31 +1051,31 @@ __gshared char[758] VS_OFFSCREEN_SOURCE_WGSL = [ 0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - diagnostic(off, derivative_uniformity); - - var frag_color : vec4f; - - var nrm : vec4f; - - fn main_1() { - let x_13 : vec4f = nrm; - let x_18 : vec3f = ((vec3f(x_13.x, x_13.y, x_13.z) * 0.5f) + vec3f(0.5f, 0.5f, 0.5f)); - frag_color = vec4f(x_18.x, x_18.y, x_18.z, 1.0f); - return; - } - - struct main_out { - @location(0) - frag_color_1 : vec4f, - } - - @fragment - fn main(@location(0) nrm_param : vec4f) -> main_out { - nrm = nrm_param; - main_1(); - return main_out(frag_color); - } - + diagnostic(off, derivative_uniformity); + + var frag_color : vec4f; + + var nrm : vec4f; + + fn main_1() { + let x_13 : vec4f = nrm; + let x_18 : vec3f = ((vec3f(x_13.x, x_13.y, x_13.z) * 0.5f) + vec3f(0.5f, 0.5f, 0.5f)); + frag_color = vec4f(x_18.x, x_18.y, x_18.z, 1.0f); + return; + } + + struct main_out { + @location(0) + frag_color_1 : vec4f, + } + + @fragment + fn main(@location(0) nrm_param : vec4f) -> main_out { + nrm = nrm_param; + main_1(); + return main_out(frag_color); + } + */ __gshared char[486] FS_OFFSCREEN_SOURCE_WGSL = [ 0x64,0x69,0x61,0x67,0x6e,0x6f,0x73,0x74,0x69,0x63,0x28,0x6f,0x66,0x66,0x2c,0x20, @@ -1108,57 +1111,57 @@ __gshared char[486] FS_OFFSCREEN_SOURCE_WGSL = [ 0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - diagnostic(off, derivative_uniformity); - - struct vs_params { - /_ @offset(0) _/ - mvp : mat4x4f, - } - - @group(0) @binding(0) var x_19 : vs_params; - - var position_1 : vec4f; - - var uv : vec2f; - - var texcoord0 : vec2f; - - var nrm : vec4f; - - var normal : vec4f; - - var gl_Position : vec4f; - - fn main_1() { - let x_22 : mat4x4f = x_19.mvp; - let x_25 : vec4f = position_1; - gl_Position = (x_22 * x_25); - let x_34 : vec2f = texcoord0; - uv = x_34; - let x_37 : mat4x4f = x_19.mvp; - let x_39 : vec4f = normal; - nrm = (x_37 * x_39); - return; - } - - struct main_out { - @builtin(position) - gl_Position : vec4f, - @location(1) - uv_1 : vec2f, - @location(0) - nrm_1 : vec4f, - } - - @vertex - fn main(@location(0) position_1_param : vec4f, @location(2) texcoord0_param : vec2f, @location(1) normal_param : vec4f) -> main_out { - position_1 = position_1_param; - texcoord0 = texcoord0_param; - normal = normal_param; - main_1(); - return main_out(gl_Position, uv, nrm); - } - + diagnostic(off, derivative_uniformity); + + struct vs_params { + /_ @offset(0) _/ + mvp : mat4x4f, + } + + @group(0) @binding(0) var x_19 : vs_params; + + var position_1 : vec4f; + + var uv : vec2f; + + var texcoord0 : vec2f; + + var nrm : vec4f; + + var normal : vec4f; + + var gl_Position : vec4f; + + fn main_1() { + let x_22 : mat4x4f = x_19.mvp; + let x_25 : vec4f = position_1; + gl_Position = (x_22 * x_25); + let x_34 : vec2f = texcoord0; + uv = x_34; + let x_37 : mat4x4f = x_19.mvp; + let x_39 : vec4f = normal; + nrm = (x_37 * x_39); + return; + } + + struct main_out { + @builtin(position) + gl_Position : vec4f, + @location(1) + uv_1 : vec2f, + @location(0) + nrm_1 : vec4f, + } + + @vertex + fn main(@location(0) position_1_param : vec4f, @location(2) texcoord0_param : vec2f, @location(1) normal_param : vec4f) -> main_out { + position_1 = position_1_param; + texcoord0 = texcoord0_param; + normal = normal_param; + main_1(); + return main_out(gl_Position, uv, nrm); + } + */ __gshared char[1008] VS_DEFAULT_SOURCE_WGSL = [ 0x64,0x69,0x61,0x67,0x6e,0x6f,0x73,0x74,0x69,0x63,0x28,0x6f,0x66,0x66,0x2c,0x20, @@ -1227,56 +1230,56 @@ __gshared char[1008] VS_DEFAULT_SOURCE_WGSL = [ ]; /* - diagnostic(off, derivative_uniformity); - - @group(1) @binding(32) var tex : texture_2d; - - @group(1) @binding(48) var smp : sampler; - - var uv : vec2f; - - var nrm : vec4f; - - var frag_color : vec4f; - - fn main_1() { - var c : vec4f; - var l : f32; - let x_23 : vec2f = uv; - let x_28 : vec4f = textureSample(tex, smp, (x_23 * vec2f(20.0f, 10.0f))); - c = x_28; - let x_34 : vec4f = nrm; - l = (clamp(dot(vec3f(x_34.x, x_34.y, x_34.z), vec3f(0.57735025882720947266f, 0.57735025882720947266f, -0.57735025882720947266f)), 0.0f, 1.0f) * 2.0f); - let x_47 : vec4f = c; - let x_49 : f32 = l; - let x_52 : vec3f = (vec3f(x_47.x, x_47.y, x_47.z) * (x_49 + 0.25f)); - frag_color = vec4f(x_52.x, x_52.y, x_52.z, 1.0f); - return; - } - - struct main_out { - @location(0) - frag_color_1 : vec4f, - } - - @fragment - fn main(@location(1) uv_param : vec2f, @location(0) nrm_param : vec4f) -> main_out { - uv = uv_param; - nrm = nrm_param; - main_1(); - return main_out(frag_color); - } - + diagnostic(off, derivative_uniformity); + + @group(1) @binding(48) var tex : texture_2d; + + @group(1) @binding(64) var smp : sampler; + + var uv : vec2f; + + var nrm : vec4f; + + var frag_color : vec4f; + + fn main_1() { + var c : vec4f; + var l : f32; + let x_23 : vec2f = uv; + let x_28 : vec4f = textureSample(tex, smp, (x_23 * vec2f(20.0f, 10.0f))); + c = x_28; + let x_34 : vec4f = nrm; + l = (clamp(dot(vec3f(x_34.x, x_34.y, x_34.z), vec3f(0.57735025882720947266f, 0.57735025882720947266f, -0.57735025882720947266f)), 0.0f, 1.0f) * 2.0f); + let x_47 : vec4f = c; + let x_49 : f32 = l; + let x_52 : vec3f = (vec3f(x_47.x, x_47.y, x_47.z) * (x_49 + 0.25f)); + frag_color = vec4f(x_52.x, x_52.y, x_52.z, 1.0f); + return; + } + + struct main_out { + @location(0) + frag_color_1 : vec4f, + } + + @fragment + fn main(@location(1) uv_param : vec2f, @location(0) nrm_param : vec4f) -> main_out { + uv = uv_param; + nrm = nrm_param; + main_1(); + return main_out(frag_color); + } + */ __gshared char[980] FS_DEFAULT_SOURCE_WGSL = [ 0x64,0x69,0x61,0x67,0x6e,0x6f,0x73,0x74,0x69,0x63,0x28,0x6f,0x66,0x66,0x2c,0x20, 0x64,0x65,0x72,0x69,0x76,0x61,0x74,0x69,0x76,0x65,0x5f,0x75,0x6e,0x69,0x66,0x6f, 0x72,0x6d,0x69,0x74,0x79,0x29,0x3b,0x0a,0x0a,0x40,0x67,0x72,0x6f,0x75,0x70,0x28, - 0x31,0x29,0x20,0x40,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x28,0x33,0x32,0x29,0x20, + 0x31,0x29,0x20,0x40,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x28,0x34,0x38,0x29,0x20, 0x76,0x61,0x72,0x20,0x74,0x65,0x78,0x20,0x3a,0x20,0x74,0x65,0x78,0x74,0x75,0x72, 0x65,0x5f,0x32,0x64,0x3c,0x66,0x33,0x32,0x3e,0x3b,0x0a,0x0a,0x40,0x67,0x72,0x6f, - 0x75,0x70,0x28,0x31,0x29,0x20,0x40,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x28,0x34, - 0x38,0x29,0x20,0x76,0x61,0x72,0x20,0x73,0x6d,0x70,0x20,0x3a,0x20,0x73,0x61,0x6d, + 0x75,0x70,0x28,0x31,0x29,0x20,0x40,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x28,0x36, + 0x34,0x29,0x20,0x76,0x61,0x72,0x20,0x73,0x6d,0x70,0x20,0x3a,0x20,0x73,0x61,0x6d, 0x70,0x6c,0x65,0x72,0x3b,0x0a,0x0a,0x76,0x61,0x72,0x3c,0x70,0x72,0x69,0x76,0x61, 0x74,0x65,0x3e,0x20,0x75,0x76,0x20,0x3a,0x20,0x76,0x65,0x63,0x32,0x66,0x3b,0x0a, 0x0a,0x76,0x61,0x72,0x3c,0x70,0x72,0x69,0x76,0x61,0x74,0x65,0x3e,0x20,0x6e,0x72, @@ -1332,193 +1335,182 @@ __gshared char[980] FS_DEFAULT_SOURCE_WGSL = [ 0x75,0x74,0x28,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x29,0x3b,0x0a, 0x7d,0x0a,0x0a,0x00, ]; - -sg.ShaderDesc default_shader_desc(sg.Backend backend) @trusted @nogc nothrow { - sg.ShaderDesc desc; - switch (backend) { - case sg.Backend.Glcore33: - desc.attrs[0].name = "position"; - desc.attrs[1].name = "normal"; - desc.attrs[2].name = "texcoord0"; - desc.vs.source = &VS_DEFAULT_SOURCE_GLSL330[0]; - desc.vs.entry = "main"; - desc.vs.uniform_blocks[0].size = 64; - desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; - desc.vs.uniform_blocks[0].uniforms[0].name = "vs_params"; - desc.vs.uniform_blocks[0].uniforms[0].type = sg.UniformType.Float4; - desc.vs.uniform_blocks[0].uniforms[0].array_count = 4; - desc.fs.source = &FS_DEFAULT_SOURCE_GLSL330[0]; - desc.fs.entry = "main"; - desc.fs.images[0].used = true; - desc.fs.images[0].multisampled = false; - desc.fs.images[0].image_type = sg.ImageType._2d; - desc.fs.images[0].sample_type = sg.ImageSampleType.Float; - desc.fs.samplers[0].used = true; - desc.fs.samplers[0].sampler_type = sg.SamplerType.Filtering; - desc.fs.image_sampler_pairs[0].used = true; - desc.fs.image_sampler_pairs[0].image_slot = 0; - desc.fs.image_sampler_pairs[0].sampler_slot = 0; - desc.fs.image_sampler_pairs[0].glsl_name = "tex_smp"; - desc.label = "default_shader"; - break; - case sg.Backend.Gles3: - desc.attrs[0].name = "position"; - desc.attrs[1].name = "normal"; - desc.attrs[2].name = "texcoord0"; - desc.vs.source = &VS_DEFAULT_SOURCE_GLSL300ES[0]; - desc.vs.entry = "main"; - desc.vs.uniform_blocks[0].size = 64; - desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; - desc.vs.uniform_blocks[0].uniforms[0].name = "vs_params"; - desc.vs.uniform_blocks[0].uniforms[0].type = sg.UniformType.Float4; - desc.vs.uniform_blocks[0].uniforms[0].array_count = 4; - desc.fs.source = &FS_DEFAULT_SOURCE_GLSL300ES[0]; - desc.fs.entry = "main"; - desc.fs.images[0].used = true; - desc.fs.images[0].multisampled = false; - desc.fs.images[0].image_type = sg.ImageType._2d; - desc.fs.images[0].sample_type = sg.ImageSampleType.Float; - desc.fs.samplers[0].used = true; - desc.fs.samplers[0].sampler_type = sg.SamplerType.Filtering; - desc.fs.image_sampler_pairs[0].used = true; - desc.fs.image_sampler_pairs[0].image_slot = 0; - desc.fs.image_sampler_pairs[0].sampler_slot = 0; - desc.fs.image_sampler_pairs[0].glsl_name = "tex_smp"; - desc.label = "default_shader"; - break; - case sg.Backend.D3d11: - desc.attrs[0].sem_name = "TEXCOORD"; - desc.attrs[0].sem_index = 0; - desc.attrs[1].sem_name = "TEXCOORD"; - desc.attrs[1].sem_index = 1; - desc.attrs[2].sem_name = "TEXCOORD"; - desc.attrs[2].sem_index = 2; - desc.vs.source = &VS_DEFAULT_SOURCE_HLSL4[0]; - desc.vs.d3d11_target = "vs_4_0"; - desc.vs.entry = "main"; - desc.vs.uniform_blocks[0].size = 64; - desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; - desc.fs.source = &FS_DEFAULT_SOURCE_HLSL4[0]; - desc.fs.d3d11_target = "ps_4_0"; - desc.fs.entry = "main"; - desc.fs.images[0].used = true; - desc.fs.images[0].multisampled = false; - desc.fs.images[0].image_type = sg.ImageType._2d; - desc.fs.images[0].sample_type = sg.ImageSampleType.Float; - desc.fs.samplers[0].used = true; - desc.fs.samplers[0].sampler_type = sg.SamplerType.Filtering; - desc.fs.image_sampler_pairs[0].used = true; - desc.fs.image_sampler_pairs[0].image_slot = 0; - desc.fs.image_sampler_pairs[0].sampler_slot = 0; - desc.label = "default_shader"; - break; - case sg.Backend.Metal_macos: - desc.vs.source = &VS_DEFAULT_SOURCE_METAL_MACOS[0]; - desc.vs.entry = "main0"; - desc.vs.uniform_blocks[0].size = 64; - desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; - desc.fs.source = &FS_DEFAULT_SOURCE_METAL_MACOS[0]; - desc.fs.entry = "main0"; - desc.fs.images[0].used = true; - desc.fs.images[0].multisampled = false; - desc.fs.images[0].image_type = sg.ImageType._2d; - desc.fs.images[0].sample_type = sg.ImageSampleType.Float; - desc.fs.samplers[0].used = true; - desc.fs.samplers[0].sampler_type = sg.SamplerType.Filtering; - desc.fs.image_sampler_pairs[0].used = true; - desc.fs.image_sampler_pairs[0].image_slot = 0; - desc.fs.image_sampler_pairs[0].sampler_slot = 0; - desc.label = "default_shader"; - break; - case sg.Backend.Wgpu: - desc.vs.source = &VS_DEFAULT_SOURCE_WGSL[0]; - desc.vs.entry = "main"; - desc.vs.uniform_blocks[0].size = 64; - desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; - desc.fs.source = &FS_DEFAULT_SOURCE_WGSL[0]; - desc.fs.entry = "main"; - desc.fs.images[0].used = true; - desc.fs.images[0].multisampled = false; - desc.fs.images[0].image_type = sg.ImageType._2d; - desc.fs.images[0].sample_type = sg.ImageSampleType.Float; - desc.fs.samplers[0].used = true; - desc.fs.samplers[0].sampler_type = sg.SamplerType.Filtering; - desc.fs.image_sampler_pairs[0].used = true; - desc.fs.image_sampler_pairs[0].image_slot = 0; - desc.fs.image_sampler_pairs[0].sampler_slot = 0; - desc.label = "default_shader"; - break; - default: - break; - } - return desc; +sg.ShaderDesc defaultShaderDesc(sg.Backend backend) @trusted @nogc nothrow { + sg.ShaderDesc desc; + desc.label = "default_shader"; + switch (backend) { + case sg.Backend.Glcore: + desc.attrs[0].name = "position"; + desc.attrs[1].name = "normal"; + desc.attrs[2].name = "texcoord0"; + desc.vs.source = &VS_DEFAULT_SOURCE_GLSL430[0]; + desc.vs.entry = "main"; + desc.vs.uniform_blocks[0].size = 64; + desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; + desc.vs.uniform_blocks[0].uniforms[0].name = "vs_params"; + desc.vs.uniform_blocks[0].uniforms[0].type = sg.UniformType.Float4; + desc.vs.uniform_blocks[0].uniforms[0].array_count = 4; + desc.fs.source = &FS_DEFAULT_SOURCE_GLSL430[0]; + desc.fs.entry = "main"; + desc.fs.images[0].used = true; + desc.fs.images[0].multisampled = false; + desc.fs.images[0].image_type = sg.ImageType._2d; + desc.fs.images[0].sample_type = sg.ImageSampleType.Float; + desc.fs.samplers[0].used = true; + desc.fs.samplers[0].sampler_type = sg.SamplerType.Filtering; + desc.fs.image_sampler_pairs[0].used = true; + desc.fs.image_sampler_pairs[0].image_slot = 0; + desc.fs.image_sampler_pairs[0].sampler_slot = 0; + desc.fs.image_sampler_pairs[0].glsl_name = "tex_smp"; + break; + case sg.Backend.Gles3: + desc.attrs[0].name = "position"; + desc.attrs[1].name = "normal"; + desc.attrs[2].name = "texcoord0"; + desc.vs.source = &VS_DEFAULT_SOURCE_GLSL300ES[0]; + desc.vs.entry = "main"; + desc.vs.uniform_blocks[0].size = 64; + desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; + desc.vs.uniform_blocks[0].uniforms[0].name = "vs_params"; + desc.vs.uniform_blocks[0].uniforms[0].type = sg.UniformType.Float4; + desc.vs.uniform_blocks[0].uniforms[0].array_count = 4; + desc.fs.source = &FS_DEFAULT_SOURCE_GLSL300ES[0]; + desc.fs.entry = "main"; + desc.fs.images[0].used = true; + desc.fs.images[0].multisampled = false; + desc.fs.images[0].image_type = sg.ImageType._2d; + desc.fs.images[0].sample_type = sg.ImageSampleType.Float; + desc.fs.samplers[0].used = true; + desc.fs.samplers[0].sampler_type = sg.SamplerType.Filtering; + desc.fs.image_sampler_pairs[0].used = true; + desc.fs.image_sampler_pairs[0].image_slot = 0; + desc.fs.image_sampler_pairs[0].sampler_slot = 0; + desc.fs.image_sampler_pairs[0].glsl_name = "tex_smp"; + break; + case sg.Backend.D3d11: + desc.attrs[0].sem_name = "TEXCOORD"; + desc.attrs[0].sem_index = 0; + desc.attrs[1].sem_name = "TEXCOORD"; + desc.attrs[1].sem_index = 1; + desc.attrs[2].sem_name = "TEXCOORD"; + desc.attrs[2].sem_index = 2; + desc.vs.source = &VS_DEFAULT_SOURCE_HLSL4[0]; + desc.vs.d3d11_target = "vs_4_0"; + desc.vs.entry = "main"; + desc.vs.uniform_blocks[0].size = 64; + desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; + desc.fs.source = &FS_DEFAULT_SOURCE_HLSL4[0]; + desc.fs.d3d11_target = "ps_4_0"; + desc.fs.entry = "main"; + desc.fs.images[0].used = true; + desc.fs.images[0].multisampled = false; + desc.fs.images[0].image_type = sg.ImageType._2d; + desc.fs.images[0].sample_type = sg.ImageSampleType.Float; + desc.fs.samplers[0].used = true; + desc.fs.samplers[0].sampler_type = sg.SamplerType.Filtering; + desc.fs.image_sampler_pairs[0].used = true; + desc.fs.image_sampler_pairs[0].image_slot = 0; + desc.fs.image_sampler_pairs[0].sampler_slot = 0; + break; + case sg.Backend.Metal_macos: + desc.vs.source = &VS_DEFAULT_SOURCE_METAL_MACOS[0]; + desc.vs.entry = "main0"; + desc.vs.uniform_blocks[0].size = 64; + desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; + desc.fs.source = &FS_DEFAULT_SOURCE_METAL_MACOS[0]; + desc.fs.entry = "main0"; + desc.fs.images[0].used = true; + desc.fs.images[0].multisampled = false; + desc.fs.images[0].image_type = sg.ImageType._2d; + desc.fs.images[0].sample_type = sg.ImageSampleType.Float; + desc.fs.samplers[0].used = true; + desc.fs.samplers[0].sampler_type = sg.SamplerType.Filtering; + desc.fs.image_sampler_pairs[0].used = true; + desc.fs.image_sampler_pairs[0].image_slot = 0; + desc.fs.image_sampler_pairs[0].sampler_slot = 0; + break; + case sg.Backend.Wgpu: + desc.vs.source = &VS_DEFAULT_SOURCE_WGSL[0]; + desc.vs.entry = "main"; + desc.vs.uniform_blocks[0].size = 64; + desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; + desc.fs.source = &FS_DEFAULT_SOURCE_WGSL[0]; + desc.fs.entry = "main"; + desc.fs.images[0].used = true; + desc.fs.images[0].multisampled = false; + desc.fs.images[0].image_type = sg.ImageType._2d; + desc.fs.images[0].sample_type = sg.ImageSampleType.Float; + desc.fs.samplers[0].used = true; + desc.fs.samplers[0].sampler_type = sg.SamplerType.Filtering; + desc.fs.image_sampler_pairs[0].used = true; + desc.fs.image_sampler_pairs[0].image_slot = 0; + desc.fs.image_sampler_pairs[0].sampler_slot = 0; + break; + default: break; + } + return desc; } -sg.ShaderDesc offscreen_shader_desc(sg.Backend backend) @trusted @nogc nothrow { - sg.ShaderDesc desc; - switch (backend) { - case sg.Backend.Glcore33: - desc.attrs[0].name = "position"; - desc.attrs[1].name = "normal"; - desc.vs.source = &VS_OFFSCREEN_SOURCE_GLSL330[0]; - desc.vs.entry = "main"; - desc.vs.uniform_blocks[0].size = 64; - desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; - desc.vs.uniform_blocks[0].uniforms[0].name = "vs_params"; - desc.vs.uniform_blocks[0].uniforms[0].type = sg.UniformType.Float4; - desc.vs.uniform_blocks[0].uniforms[0].array_count = 4; - desc.fs.source = &FS_OFFSCREEN_SOURCE_GLSL330[0]; - desc.fs.entry = "main"; - desc.label = "offscreen_shader"; - break; - case sg.Backend.Gles3: - desc.attrs[0].name = "position"; - desc.attrs[1].name = "normal"; - desc.vs.source = &VS_OFFSCREEN_SOURCE_GLSL300ES[0]; - desc.vs.entry = "main"; - desc.vs.uniform_blocks[0].size = 64; - desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; - desc.vs.uniform_blocks[0].uniforms[0].name = "vs_params"; - desc.vs.uniform_blocks[0].uniforms[0].type = sg.UniformType.Float4; - desc.vs.uniform_blocks[0].uniforms[0].array_count = 4; - desc.fs.source = &FS_OFFSCREEN_SOURCE_GLSL300ES[0]; - desc.fs.entry = "main"; - desc.label = "offscreen_shader"; - break; - case sg.Backend.D3d11: - desc.attrs[0].sem_name = "TEXCOORD"; - desc.attrs[0].sem_index = 0; - desc.attrs[1].sem_name = "TEXCOORD"; - desc.attrs[1].sem_index = 1; - desc.vs.source = &VS_OFFSCREEN_SOURCE_HLSL4[0]; - desc.vs.d3d11_target = "vs_4_0"; - desc.vs.entry = "main"; - desc.vs.uniform_blocks[0].size = 64; - desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; - desc.fs.source = &FS_OFFSCREEN_SOURCE_HLSL4[0]; - desc.fs.d3d11_target = "ps_4_0"; - desc.fs.entry = "main"; - desc.label = "offscreen_shader"; - break; - case sg.Backend.Metal_macos: - desc.vs.source = &VS_OFFSCREEN_SOURCE_METAL_MACOS[0]; - desc.vs.entry = "main0"; - desc.vs.uniform_blocks[0].size = 64; - desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; - desc.fs.source = &FS_OFFSCREEN_SOURCE_METAL_MACOS[0]; - desc.fs.entry = "main0"; - desc.label = "offscreen_shader"; - break; - case sg.Backend.Wgpu: - desc.vs.source = &VS_OFFSCREEN_SOURCE_WGSL[0]; - desc.vs.entry = "main"; - desc.vs.uniform_blocks[0].size = 64; - desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; - desc.fs.source = &FS_OFFSCREEN_SOURCE_WGSL[0]; - desc.fs.entry = "main"; - desc.label = "offscreen_shader"; - break; - default: - break; - } - return desc; +sg.ShaderDesc offscreenShaderDesc(sg.Backend backend) @trusted @nogc nothrow { + sg.ShaderDesc desc; + desc.label = "offscreen_shader"; + switch (backend) { + case sg.Backend.Glcore: + desc.attrs[0].name = "position"; + desc.attrs[1].name = "normal"; + desc.vs.source = &VS_OFFSCREEN_SOURCE_GLSL430[0]; + desc.vs.entry = "main"; + desc.vs.uniform_blocks[0].size = 64; + desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; + desc.vs.uniform_blocks[0].uniforms[0].name = "vs_params"; + desc.vs.uniform_blocks[0].uniforms[0].type = sg.UniformType.Float4; + desc.vs.uniform_blocks[0].uniforms[0].array_count = 4; + desc.fs.source = &FS_OFFSCREEN_SOURCE_GLSL430[0]; + desc.fs.entry = "main"; + break; + case sg.Backend.Gles3: + desc.attrs[0].name = "position"; + desc.attrs[1].name = "normal"; + desc.vs.source = &VS_OFFSCREEN_SOURCE_GLSL300ES[0]; + desc.vs.entry = "main"; + desc.vs.uniform_blocks[0].size = 64; + desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; + desc.vs.uniform_blocks[0].uniforms[0].name = "vs_params"; + desc.vs.uniform_blocks[0].uniforms[0].type = sg.UniformType.Float4; + desc.vs.uniform_blocks[0].uniforms[0].array_count = 4; + desc.fs.source = &FS_OFFSCREEN_SOURCE_GLSL300ES[0]; + desc.fs.entry = "main"; + break; + case sg.Backend.D3d11: + desc.attrs[0].sem_name = "TEXCOORD"; + desc.attrs[0].sem_index = 0; + desc.attrs[1].sem_name = "TEXCOORD"; + desc.attrs[1].sem_index = 1; + desc.vs.source = &VS_OFFSCREEN_SOURCE_HLSL4[0]; + desc.vs.d3d11_target = "vs_4_0"; + desc.vs.entry = "main"; + desc.vs.uniform_blocks[0].size = 64; + desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; + desc.fs.source = &FS_OFFSCREEN_SOURCE_HLSL4[0]; + desc.fs.d3d11_target = "ps_4_0"; + desc.fs.entry = "main"; + break; + case sg.Backend.Metal_macos: + desc.vs.source = &VS_OFFSCREEN_SOURCE_METAL_MACOS[0]; + desc.vs.entry = "main0"; + desc.vs.uniform_blocks[0].size = 64; + desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; + desc.fs.source = &FS_OFFSCREEN_SOURCE_METAL_MACOS[0]; + desc.fs.entry = "main0"; + break; + case sg.Backend.Wgpu: + desc.vs.source = &VS_OFFSCREEN_SOURCE_WGSL[0]; + desc.vs.entry = "main"; + desc.vs.uniform_blocks[0].size = 64; + desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; + desc.fs.source = &FS_OFFSCREEN_SOURCE_WGSL[0]; + desc.fs.entry = "main"; + break; + default: break; + } + return desc; } diff --git a/src/shaders/quad.d b/src/shaders/quad.d index 1606980..e034ebd 100644 --- a/src/shaders/quad.d +++ b/src/shaders/quad.d @@ -4,86 +4,89 @@ extern(C): /* #version:1# (machine generated, don't edit!) - + Generated by sokol-shdc (https://github.com/floooh/sokol-tools) - - Cmdline: sokol-shdc -i src/shaders/quad.glsl -o src/shaders/quad.d -l glsl330:metal_macos:hlsl4:glsl300es:wgsl -f sokol_d - + + Cmdline: + sokol-shdc -i src/shaders/quad.glsl -o src/shaders/quad.d -l glsl430:metal_macos:hlsl4:glsl300es:wgsl -f sokol_d + Overview: - - Shader program 'quad': - Get shader desc: quad_shader_desc(sg.query_backend()); - Vertex shader: vs - Attribute slots: - ATTR_VS_POSITION = 0 - ATTR_VS_COLOR0 = 1 - Fragment shader: fs - + ========= + Shader program: 'quad': + Get shader desc: quadShaderDesc(sg.queryBackend()); + Vertex shader: vs + Attributes: + ATTR_VS_POSITION => 0 + ATTR_VS_COLOR0 => 1 + Fragment shader: fs */ enum ATTR_VS_POSITION = 0; enum ATTR_VS_COLOR0 = 1; /* - #version 330 - - layout(location = 0) in vec4 position; - out vec4 color; - layout(location = 1) in vec4 color0; - - void main() - { - gl_Position = position; - color = color0; - } - + #version 430 + + layout(location = 0) in vec4 position; + layout(location = 0) out vec4 color; + layout(location = 1) in vec4 color0; + + void main() + { + gl_Position = position; + color = color0; + } + */ -__gshared char[173] VS_SOURCE_GLSL330 = [ - 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x33,0x30,0x0a,0x0a,0x6c,0x61, +__gshared char[194] VS_SOURCE_GLSL430 = [ + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x6c,0x61, 0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, 0x30,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20,0x70,0x6f,0x73,0x69,0x74, - 0x69,0x6f,0x6e,0x3b,0x0a,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x6f, - 0x6c,0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61, - 0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63, - 0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20, - 0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f, - 0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x70,0x6f,0x73,0x69,0x74, - 0x69,0x6f,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d, - 0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, + 0x69,0x6f,0x6e,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61, + 0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65, + 0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74, + 0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x69, + 0x6e,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x0a, + 0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, + 0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x63,0x6f, + 0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x7d,0x0a, + 0x0a,0x00, ]; /* - #version 330 - - layout(location = 0) out vec4 frag_color; - in vec4 color; - - void main() - { - frag_color = color; - } - + #version 430 + + layout(location = 0) out vec4 frag_color; + layout(location = 0) in vec4 color; + + void main() + { + frag_color = color; + } + */ -__gshared char[114] FS_SOURCE_GLSL330 = [ - 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x33,0x30,0x0a,0x0a,0x6c,0x61, +__gshared char[135] FS_SOURCE_GLSL430 = [ + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x6c,0x61, 0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, 0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x66,0x72,0x61,0x67, - 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20, - 0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69, - 0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x63, - 0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x7d,0x0a, - 0x0a,0x00, + 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c, + 0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e,0x20, + 0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x0a,0x76,0x6f,0x69, + 0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f, + 0x72,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - #version 300 es - - layout(location = 0) in vec4 position; - out vec4 color; - layout(location = 1) in vec4 color0; - - void main() - { - gl_Position = position; - color = color0; - } - + #version 300 es + + layout(location = 0) in vec4 position; + out vec4 color; + layout(location = 1) in vec4 color0; + + void main() + { + gl_Position = position; + color = color0; + } + */ __gshared char[176] VS_SOURCE_GLSL300ES = [ 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x30,0x30,0x20,0x65,0x73,0x0a, @@ -100,18 +103,18 @@ __gshared char[176] VS_SOURCE_GLSL300ES = [ ]; /* - #version 300 es - precision mediump float; - precision highp int; - - layout(location = 0) out highp vec4 frag_color; - in highp vec4 color; - - void main() - { - frag_color = color; - } - + #version 300 es + precision mediump float; + precision highp int; + + layout(location = 0) out highp vec4 frag_color; + in highp vec4 color; + + void main() + { + frag_color = color; + } + */ __gshared char[175] FS_SOURCE_GLSL300ES = [ 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x30,0x30,0x20,0x65,0x73,0x0a, @@ -127,39 +130,39 @@ __gshared char[175] FS_SOURCE_GLSL300ES = [ 0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - static float4 gl_Position; - static float4 position; - static float4 color; - static float4 color0; - - struct SPIRV_Cross_Input - { - float4 position : TEXCOORD0; - float4 color0 : TEXCOORD1; - }; - - struct SPIRV_Cross_Output - { - float4 color : TEXCOORD0; - float4 gl_Position : SV_Position; - }; - - void vert_main() - { - gl_Position = position; - color = color0; - } - - SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) - { - position = stage_input.position; - color0 = stage_input.color0; - vert_main(); - SPIRV_Cross_Output stage_output; - stage_output.gl_Position = gl_Position; - stage_output.color = color; - return stage_output; - } + static float4 gl_Position; + static float4 position; + static float4 color; + static float4 color0; + + struct SPIRV_Cross_Input + { + float4 position : TEXCOORD0; + float4 color0 : TEXCOORD1; + }; + + struct SPIRV_Cross_Output + { + float4 color : TEXCOORD0; + float4 gl_Position : SV_Position; + }; + + void vert_main() + { + gl_Position = position; + color = color0; + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + position = stage_input.position; + color0 = stage_input.color0; + vert_main(); + SPIRV_Cross_Output stage_output; + stage_output.gl_Position = gl_Position; + stage_output.color = color; + return stage_output; + } */ __gshared char[645] VS_SOURCE_HLSL4 = [ 0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c, @@ -205,32 +208,32 @@ __gshared char[645] VS_SOURCE_HLSL4 = [ 0x3b,0x0a,0x7d,0x0a,0x00, ]; /* - static float4 frag_color; - static float4 color; - - struct SPIRV_Cross_Input - { - float4 color : TEXCOORD0; - }; - - struct SPIRV_Cross_Output - { - float4 frag_color : SV_Target0; - }; - - void frag_main() - { - frag_color = color; - } - - SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) - { - color = stage_input.color; - frag_main(); - SPIRV_Cross_Output stage_output; - stage_output.frag_color = frag_color; - return stage_output; - } + static float4 frag_color; + static float4 color; + + struct SPIRV_Cross_Input + { + float4 color : TEXCOORD0; + }; + + struct SPIRV_Cross_Output + { + float4 frag_color : SV_Target0; + }; + + void frag_main() + { + frag_color = color; + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + color = stage_input.color; + frag_main(); + SPIRV_Cross_Output stage_output; + stage_output.frag_color = frag_color; + return stage_output; + } */ __gshared char[435] FS_SOURCE_HLSL4 = [ 0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x66,0x72, @@ -263,31 +266,31 @@ __gshared char[435] FS_SOURCE_HLSL4 = [ 0x7d,0x0a,0x00, ]; /* - #include - #include - - using namespace metal; - - struct main0_out - { - float4 color [[user(locn0)]]; - float4 gl_Position [[position]]; - }; - - struct main0_in - { - float4 position [[attribute(0)]]; - float4 color0 [[attribute(1)]]; - }; - - vertex main0_out main0(main0_in in [[stage_in]]) - { - main0_out out = {}; - out.gl_Position = in.position; - out.color = in.color0; - return out; - } - + #include + #include + + using namespace metal; + + struct main0_out + { + float4 color [[user(locn0)]]; + float4 gl_Position [[position]]; + }; + + struct main0_in + { + float4 position [[attribute(0)]]; + float4 color0 [[attribute(1)]]; + }; + + vertex main0_out main0(main0_in in [[stage_in]]) + { + main0_out out = {}; + out.gl_Position = in.position; + out.color = in.color0; + return out; + } + */ __gshared char[419] VS_SOURCE_METAL_MACOS = [ 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, @@ -319,28 +322,28 @@ __gshared char[419] VS_SOURCE_METAL_MACOS = [ 0x0a,0x0a,0x00, ]; /* - #include - #include - - using namespace metal; - - struct main0_out - { - float4 frag_color [[color(0)]]; - }; - - struct main0_in - { - float4 color [[user(locn0)]]; - }; - - fragment main0_out main0(main0_in in [[stage_in]]) - { - main0_out out = {}; - out.frag_color = in.color; - return out; - } - + #include + #include + + using namespace metal; + + struct main0_out + { + float4 frag_color [[color(0)]]; + }; + + struct main0_in + { + float4 color [[user(locn0)]]; + }; + + fragment main0_out main0(main0_in in [[stage_in]]) + { + main0_out out = {}; + out.frag_color = in.color; + return out; + } + */ __gshared char[315] FS_SOURCE_METAL_MACOS = [ 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, @@ -365,39 +368,39 @@ __gshared char[315] FS_SOURCE_METAL_MACOS = [ 0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - diagnostic(off, derivative_uniformity); - - var position_1 : vec4f; - - var color : vec4f; - - var color0 : vec4f; - - var gl_Position : vec4f; - - fn main_1() { - let x_18 : vec4f = position_1; - gl_Position = x_18; - let x_23 : vec4f = color0; - color = x_23; - return; - } - - struct main_out { - @builtin(position) - gl_Position : vec4f, - @location(0) - color_1 : vec4f, - } - - @vertex - fn main(@location(0) position_1_param : vec4f, @location(1) color0_param : vec4f) -> main_out { - position_1 = position_1_param; - color0 = color0_param; - main_1(); - return main_out(gl_Position, color); - } - + diagnostic(off, derivative_uniformity); + + var position_1 : vec4f; + + var color : vec4f; + + var color0 : vec4f; + + var gl_Position : vec4f; + + fn main_1() { + let x_18 : vec4f = position_1; + gl_Position = x_18; + let x_23 : vec4f = color0; + color = x_23; + return; + } + + struct main_out { + @builtin(position) + gl_Position : vec4f, + @location(0) + color_1 : vec4f, + } + + @vertex + fn main(@location(0) position_1_param : vec4f, @location(1) color0_param : vec4f) -> main_out { + position_1 = position_1_param; + color0 = color0_param; + main_1(); + return main_out(gl_Position, color); + } + */ __gshared char[612] VS_SOURCE_WGSL = [ 0x64,0x69,0x61,0x67,0x6e,0x6f,0x73,0x74,0x69,0x63,0x28,0x6f,0x66,0x66,0x2c,0x20, @@ -441,30 +444,30 @@ __gshared char[612] VS_SOURCE_WGSL = [ 0x7d,0x0a,0x0a,0x00, ]; /* - diagnostic(off, derivative_uniformity); - - var frag_color : vec4f; - - var color : vec4f; - - fn main_1() { - let x_12 : vec4f = color; - frag_color = x_12; - return; - } - - struct main_out { - @location(0) - frag_color_1 : vec4f, - } - - @fragment - fn main(@location(0) color_param : vec4f) -> main_out { - color = color_param; - main_1(); - return main_out(frag_color); - } - + diagnostic(off, derivative_uniformity); + + var frag_color : vec4f; + + var color : vec4f; + + fn main_1() { + let x_12 : vec4f = color; + frag_color = x_12; + return; + } + + struct main_out { + @location(0) + frag_color_1 : vec4f, + } + + @fragment + fn main(@location(0) color_param : vec4f) -> main_out { + color = color_param; + main_1(); + return main_out(frag_color); + } + */ __gshared char[376] FS_SOURCE_WGSL = [ 0x64,0x69,0x61,0x67,0x6e,0x6f,0x73,0x74,0x69,0x63,0x28,0x6f,0x66,0x66,0x2c,0x20, @@ -492,57 +495,51 @@ __gshared char[376] FS_SOURCE_WGSL = [ 0x69,0x6e,0x5f,0x6f,0x75,0x74,0x28,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f, 0x72,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; - -sg.ShaderDesc quad_shader_desc(sg.Backend backend) @trusted @nogc nothrow { - sg.ShaderDesc desc; - switch (backend) { - case sg.Backend.Glcore33: - desc.attrs[0].name = "position"; - desc.attrs[1].name = "color0"; - desc.vs.source = &VS_SOURCE_GLSL330[0]; - desc.vs.entry = "main"; - desc.fs.source = &FS_SOURCE_GLSL330[0]; - desc.fs.entry = "main"; - desc.label = "quad_shader"; - break; - case sg.Backend.Gles3: - desc.attrs[0].name = "position"; - desc.attrs[1].name = "color0"; - desc.vs.source = &VS_SOURCE_GLSL300ES[0]; - desc.vs.entry = "main"; - desc.fs.source = &FS_SOURCE_GLSL300ES[0]; - desc.fs.entry = "main"; - desc.label = "quad_shader"; - break; - case sg.Backend.D3d11: - desc.attrs[0].sem_name = "TEXCOORD"; - desc.attrs[0].sem_index = 0; - desc.attrs[1].sem_name = "TEXCOORD"; - desc.attrs[1].sem_index = 1; - desc.vs.source = &VS_SOURCE_HLSL4[0]; - desc.vs.d3d11_target = "vs_4_0"; - desc.vs.entry = "main"; - desc.fs.source = &FS_SOURCE_HLSL4[0]; - desc.fs.d3d11_target = "ps_4_0"; - desc.fs.entry = "main"; - desc.label = "quad_shader"; - break; - case sg.Backend.Metal_macos: - desc.vs.source = &VS_SOURCE_METAL_MACOS[0]; - desc.vs.entry = "main0"; - desc.fs.source = &FS_SOURCE_METAL_MACOS[0]; - desc.fs.entry = "main0"; - desc.label = "quad_shader"; - break; - case sg.Backend.Wgpu: - desc.vs.source = &VS_SOURCE_WGSL[0]; - desc.vs.entry = "main"; - desc.fs.source = &FS_SOURCE_WGSL[0]; - desc.fs.entry = "main"; - desc.label = "quad_shader"; - break; - default: - break; - } - return desc; +sg.ShaderDesc quadShaderDesc(sg.Backend backend) @trusted @nogc nothrow { + sg.ShaderDesc desc; + desc.label = "quad_shader"; + switch (backend) { + case sg.Backend.Glcore: + desc.attrs[0].name = "position"; + desc.attrs[1].name = "color0"; + desc.vs.source = &VS_SOURCE_GLSL430[0]; + desc.vs.entry = "main"; + desc.fs.source = &FS_SOURCE_GLSL430[0]; + desc.fs.entry = "main"; + break; + case sg.Backend.Gles3: + desc.attrs[0].name = "position"; + desc.attrs[1].name = "color0"; + desc.vs.source = &VS_SOURCE_GLSL300ES[0]; + desc.vs.entry = "main"; + desc.fs.source = &FS_SOURCE_GLSL300ES[0]; + desc.fs.entry = "main"; + break; + case sg.Backend.D3d11: + desc.attrs[0].sem_name = "TEXCOORD"; + desc.attrs[0].sem_index = 0; + desc.attrs[1].sem_name = "TEXCOORD"; + desc.attrs[1].sem_index = 1; + desc.vs.source = &VS_SOURCE_HLSL4[0]; + desc.vs.d3d11_target = "vs_4_0"; + desc.vs.entry = "main"; + desc.fs.source = &FS_SOURCE_HLSL4[0]; + desc.fs.d3d11_target = "ps_4_0"; + desc.fs.entry = "main"; + break; + case sg.Backend.Metal_macos: + desc.vs.source = &VS_SOURCE_METAL_MACOS[0]; + desc.vs.entry = "main0"; + desc.fs.source = &FS_SOURCE_METAL_MACOS[0]; + desc.fs.entry = "main0"; + break; + case sg.Backend.Wgpu: + desc.vs.source = &VS_SOURCE_WGSL[0]; + desc.vs.entry = "main"; + desc.fs.source = &FS_SOURCE_WGSL[0]; + desc.fs.entry = "main"; + break; + default: break; + } + return desc; } diff --git a/src/shaders/shapes.d b/src/shaders/shapes.d index 37bebfc..089d6e2 100644 --- a/src/shaders/shapes.d +++ b/src/shaders/shapes.d @@ -1,164 +1,166 @@ module shaders.shapes; import sg = sokol.gfx; +import m = handmade.math; extern(C): /* #version:1# (machine generated, don't edit!) - + Generated by sokol-shdc (https://github.com/floooh/sokol-tools) - - Cmdline: sokol-shdc -i src/shaders/shapes.glsl -o src/shaders/shapes.d -l glsl330:metal_macos:hlsl4:glsl300es:wgsl -f sokol_d - + + Cmdline: + sokol-shdc -i src/shaders/shapes.glsl -o src/shaders/shapes.d -l glsl430:metal_macos:hlsl4:glsl300es:wgsl -f sokol_d + Overview: - - Shader program 'shapes': - Get shader desc: shapes_shader_desc(sg.query_backend()); - Vertex shader: vs - Attribute slots: - ATTR_VS_POSITION = 0 - ATTR_VS_NORMAL = 1 - ATTR_VS_TEXCOORD = 2 - ATTR_VS_COLOR0 = 3 - Uniform block 'vs_params': - C struct: vs_params_t - Bind slot: SLOT_VS_PARAMS = 0 - Fragment shader: fs - + ========= + Shader program: 'shapes': + Get shader desc: shapesShaderDesc(sg.queryBackend()); + Vertex shader: vs + Attributes: + ATTR_VS_POSITION => 0 + ATTR_VS_NORMAL => 1 + ATTR_VS_TEXCOORD => 2 + ATTR_VS_COLOR0 => 3 + Uniform block 'vs_params': + D struct: VsParams + Bind slot: SLOT_VS_PARAMS => 0 + Fragment shader: fs */ -import m = handmade.math; enum ATTR_VS_POSITION = 0; enum ATTR_VS_NORMAL = 1; enum ATTR_VS_TEXCOORD = 2; enum ATTR_VS_COLOR0 = 3; enum SLOT_VS_PARAMS = 0; struct VsParams { - float draw_mode; - ubyte[12] _pad_4; - m.Mat4 mvp; + align(16) float draw_mode = 0; + align(1) ubyte[12] _pad_4 = 0; + align(1) m.Mat4 mvp; } /* - #version 330 - - uniform vec4 vs_params[5]; - layout(location = 0) in vec4 position; - out vec4 color; - layout(location = 1) in vec3 normal; - layout(location = 2) in vec2 texcoord; - layout(location = 3) in vec4 color0; - - void main() - { - gl_Position = mat4(vs_params[1], vs_params[2], vs_params[3], vs_params[4]) * position; - if (vs_params[0].x == 0.0) - { - color = vec4((normal + vec3(1.0)) * 0.5, 1.0); - } - else - { - if (vs_params[0].x == 1.0) - { - color = vec4(texcoord, 0.0, 1.0); - } - else - { - color = color0; - } - } - } - + #version 430 + + uniform vec4 vs_params[5]; + layout(location = 0) in vec4 position; + layout(location = 0) out vec4 color; + layout(location = 1) in vec3 normal; + layout(location = 2) in vec2 texcoord; + layout(location = 3) in vec4 color0; + + void main() + { + gl_Position = mat4(vs_params[1], vs_params[2], vs_params[3], vs_params[4]) * position; + if (vs_params[0].x == 0.0) + { + color = vec4((normal + vec3(1.0)) * 0.5, 1.0); + } + else + { + if (vs_params[0].x == 1.0) + { + color = vec4(texcoord, 0.0, 1.0); + } + else + { + color = color0; + } + } + } + */ -__gshared char[600] VS_SOURCE_GLSL330 = [ - 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x33,0x30,0x0a,0x0a,0x75,0x6e, +__gshared char[621] VS_SOURCE_GLSL430 = [ + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x75,0x6e, 0x69,0x66,0x6f,0x72,0x6d,0x20,0x76,0x65,0x63,0x34,0x20,0x76,0x73,0x5f,0x70,0x61, 0x72,0x61,0x6d,0x73,0x5b,0x35,0x5d,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28, 0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e, 0x20,0x76,0x65,0x63,0x34,0x20,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a, - 0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a, 0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20, - 0x3d,0x20,0x31,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x33,0x20,0x6e,0x6f,0x72, - 0x6d,0x61,0x6c,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61, - 0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x32,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63, - 0x32,0x20,0x74,0x65,0x78,0x63,0x6f,0x6f,0x72,0x64,0x3b,0x0a,0x6c,0x61,0x79,0x6f, - 0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x33,0x29, - 0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b, - 0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a, - 0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20, - 0x3d,0x20,0x6d,0x61,0x74,0x34,0x28,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73, - 0x5b,0x31,0x5d,0x2c,0x20,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x32, - 0x5d,0x2c,0x20,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x33,0x5d,0x2c, - 0x20,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x34,0x5d,0x29,0x20,0x2a, - 0x20,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69, - 0x66,0x20,0x28,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x30,0x5d,0x2e, - 0x78,0x20,0x3d,0x3d,0x20,0x30,0x2e,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20, - 0x76,0x65,0x63,0x34,0x28,0x28,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x20,0x2b,0x20,0x76, - 0x65,0x63,0x33,0x28,0x31,0x2e,0x30,0x29,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35,0x2c, - 0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, - 0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x3d,0x20,0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x6f, + 0x6c,0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61, + 0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63, + 0x33,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74, + 0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x32,0x29,0x20,0x69, + 0x6e,0x20,0x76,0x65,0x63,0x32,0x20,0x74,0x65,0x78,0x63,0x6f,0x6f,0x72,0x64,0x3b, + 0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e, + 0x20,0x3d,0x20,0x33,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x6f, + 0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e, + 0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69, + 0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x6d,0x61,0x74,0x34,0x28,0x76,0x73,0x5f,0x70, + 0x61,0x72,0x61,0x6d,0x73,0x5b,0x31,0x5d,0x2c,0x20,0x76,0x73,0x5f,0x70,0x61,0x72, + 0x61,0x6d,0x73,0x5b,0x32,0x5d,0x2c,0x20,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d, + 0x73,0x5b,0x33,0x5d,0x2c,0x20,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b, + 0x34,0x5d,0x29,0x20,0x2a,0x20,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a, 0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d, - 0x73,0x5b,0x30,0x5d,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x31,0x2e,0x30,0x29,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x76,0x65,0x63, - 0x34,0x28,0x74,0x65,0x78,0x63,0x6f,0x6f,0x72,0x64,0x2c,0x20,0x30,0x2e,0x30,0x2c, - 0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d, - 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f, - 0x72,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, - 0x20,0x20,0x7d,0x0a,0x7d,0x0a,0x0a,0x00, + 0x73,0x5b,0x30,0x5d,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x30,0x2e,0x30,0x29,0x0a,0x20, + 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x6f,0x6c, + 0x6f,0x72,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x28,0x6e,0x6f,0x72,0x6d,0x61, + 0x6c,0x20,0x2b,0x20,0x76,0x65,0x63,0x33,0x28,0x31,0x2e,0x30,0x29,0x29,0x20,0x2a, + 0x20,0x30,0x2e,0x35,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x76,0x73,0x5f, + 0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x30,0x5d,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x31, + 0x2e,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20, + 0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x74,0x65,0x78,0x63,0x6f,0x6f,0x72,0x64,0x2c, + 0x20,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c, + 0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d, + 0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - #version 330 - - layout(location = 0) out vec4 frag_color; - in vec4 color; - - void main() - { - frag_color = color; - } - + #version 430 + + layout(location = 0) out vec4 frag_color; + layout(location = 0) in vec4 color; + + void main() + { + frag_color = color; + } + */ -__gshared char[114] FS_SOURCE_GLSL330 = [ - 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x33,0x30,0x0a,0x0a,0x6c,0x61, +__gshared char[135] FS_SOURCE_GLSL430 = [ + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x6c,0x61, 0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, 0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x66,0x72,0x61,0x67, - 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20, - 0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69, - 0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x63, - 0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x7d,0x0a, - 0x0a,0x00, + 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c, + 0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e,0x20, + 0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x0a,0x76,0x6f,0x69, + 0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f, + 0x72,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - #version 300 es - - uniform vec4 vs_params[5]; - layout(location = 0) in vec4 position; - out vec4 color; - layout(location = 1) in vec3 normal; - layout(location = 2) in vec2 texcoord; - layout(location = 3) in vec4 color0; - - void main() - { - gl_Position = mat4(vs_params[1], vs_params[2], vs_params[3], vs_params[4]) * position; - if (vs_params[0].x == 0.0) - { - color = vec4((normal + vec3(1.0)) * 0.5, 1.0); - } - else - { - if (vs_params[0].x == 1.0) - { - color = vec4(texcoord, 0.0, 1.0); - } - else - { - color = color0; - } - } - } - + #version 300 es + + uniform vec4 vs_params[5]; + layout(location = 0) in vec4 position; + out vec4 color; + layout(location = 1) in vec3 normal; + layout(location = 2) in vec2 texcoord; + layout(location = 3) in vec4 color0; + + void main() + { + gl_Position = mat4(vs_params[1], vs_params[2], vs_params[3], vs_params[4]) * position; + if (vs_params[0].x == 0.0) + { + color = vec4((normal + vec3(1.0)) * 0.5, 1.0); + } + else + { + if (vs_params[0].x == 1.0) + { + color = vec4(texcoord, 0.0, 1.0); + } + else + { + color = color0; + } + } + } + */ __gshared char[603] VS_SOURCE_GLSL300ES = [ 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x30,0x30,0x20,0x65,0x73,0x0a, @@ -201,18 +203,18 @@ __gshared char[603] VS_SOURCE_GLSL300ES = [ 0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - #version 300 es - precision mediump float; - precision highp int; - - layout(location = 0) out highp vec4 frag_color; - in highp vec4 color; - - void main() - { - frag_color = color; - } - + #version 300 es + precision mediump float; + precision highp int; + + layout(location = 0) out highp vec4 frag_color; + in highp vec4 color; + + void main() + { + frag_color = color; + } + */ __gshared char[175] FS_SOURCE_GLSL300ES = [ 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x30,0x30,0x20,0x65,0x73,0x0a, @@ -228,66 +230,66 @@ __gshared char[175] FS_SOURCE_GLSL300ES = [ 0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - cbuffer vs_params : register(b0) - { - float _19_draw_mode : packoffset(c0); - row_major float4x4 _19_mvp : packoffset(c1); - }; - - - static float4 gl_Position; - static float4 position; - static float4 color; - static float3 normal; - static float2 texcoord; - static float4 color0; - - struct SPIRV_Cross_Input - { - float4 position : TEXCOORD0; - float3 normal : TEXCOORD1; - float2 texcoord : TEXCOORD2; - float4 color0 : TEXCOORD3; - }; - - struct SPIRV_Cross_Output - { - float4 color : TEXCOORD0; - float4 gl_Position : SV_Position; - }; - - void vert_main() - { - gl_Position = mul(position, _19_mvp); - if (_19_draw_mode == 0.0f) - { - color = float4((normal + 1.0f.xxx) * 0.5f, 1.0f); - } - else - { - if (_19_draw_mode == 1.0f) - { - color = float4(texcoord, 0.0f, 1.0f); - } - else - { - color = color0; - } - } - } - - SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) - { - position = stage_input.position; - normal = stage_input.normal; - texcoord = stage_input.texcoord; - color0 = stage_input.color0; - vert_main(); - SPIRV_Cross_Output stage_output; - stage_output.gl_Position = gl_Position; - stage_output.color = color; - return stage_output; - } + cbuffer vs_params : register(b0) + { + float _19_draw_mode : packoffset(c0); + row_major float4x4 _19_mvp : packoffset(c1); + }; + + + static float4 gl_Position; + static float4 position; + static float4 color; + static float3 normal; + static float2 texcoord; + static float4 color0; + + struct SPIRV_Cross_Input + { + float4 position : TEXCOORD0; + float3 normal : TEXCOORD1; + float2 texcoord : TEXCOORD2; + float4 color0 : TEXCOORD3; + }; + + struct SPIRV_Cross_Output + { + float4 color : TEXCOORD0; + float4 gl_Position : SV_Position; + }; + + void vert_main() + { + gl_Position = mul(position, _19_mvp); + if (_19_draw_mode == 0.0f) + { + color = float4((normal + 1.0f.xxx) * 0.5f, 1.0f); + } + else + { + if (_19_draw_mode == 1.0f) + { + color = float4(texcoord, 0.0f, 1.0f); + } + else + { + color = color0; + } + } + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + position = stage_input.position; + normal = stage_input.normal; + texcoord = stage_input.texcoord; + color0 = stage_input.color0; + vert_main(); + SPIRV_Cross_Output stage_output; + stage_output.gl_Position = gl_Position; + stage_output.color = color; + return stage_output; + } */ __gshared char[1238] VS_SOURCE_HLSL4 = [ 0x63,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d, @@ -370,32 +372,32 @@ __gshared char[1238] VS_SOURCE_HLSL4 = [ 0x74,0x3b,0x0a,0x7d,0x0a,0x00, ]; /* - static float4 frag_color; - static float4 color; - - struct SPIRV_Cross_Input - { - float4 color : TEXCOORD0; - }; - - struct SPIRV_Cross_Output - { - float4 frag_color : SV_Target0; - }; - - void frag_main() - { - frag_color = color; - } - - SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) - { - color = stage_input.color; - frag_main(); - SPIRV_Cross_Output stage_output; - stage_output.frag_color = frag_color; - return stage_output; - } + static float4 frag_color; + static float4 color; + + struct SPIRV_Cross_Input + { + float4 color : TEXCOORD0; + }; + + struct SPIRV_Cross_Output + { + float4 frag_color : SV_Target0; + }; + + void frag_main() + { + frag_color = color; + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + color = stage_input.color; + frag_main(); + SPIRV_Cross_Output stage_output; + stage_output.frag_color = frag_color; + return stage_output; + } */ __gshared char[435] FS_SOURCE_HLSL4 = [ 0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x66,0x72, @@ -428,53 +430,53 @@ __gshared char[435] FS_SOURCE_HLSL4 = [ 0x7d,0x0a,0x00, ]; /* - #include - #include - - using namespace metal; - - struct vs_params - { - float draw_mode; - float4x4 mvp; - }; - - struct main0_out - { - float4 color [[user(locn0)]]; - float4 gl_Position [[position]]; - }; - - struct main0_in - { - float4 position [[attribute(0)]]; - float3 normal [[attribute(1)]]; - float2 texcoord [[attribute(2)]]; - float4 color0 [[attribute(3)]]; - }; - - vertex main0_out main0(main0_in in [[stage_in]], constant vs_params& _19 [[buffer(0)]]) - { - main0_out out = {}; - out.gl_Position = _19.mvp * in.position; - if (_19.draw_mode == 0.0) - { - out.color = float4((in.normal + float3(1.0)) * 0.5, 1.0); - } - else - { - if (_19.draw_mode == 1.0) - { - out.color = float4(in.texcoord, 0.0, 1.0); - } - else - { - out.color = in.color0; - } - } - return out; - } - + #include + #include + + using namespace metal; + + struct vs_params + { + float draw_mode; + float4x4 mvp; + }; + + struct main0_out + { + float4 color [[user(locn0)]]; + float4 gl_Position [[position]]; + }; + + struct main0_in + { + float4 position [[attribute(0)]]; + float3 normal [[attribute(1)]]; + float2 texcoord [[attribute(2)]]; + float4 color0 [[attribute(3)]]; + }; + + vertex main0_out main0(main0_in in [[stage_in]], constant vs_params& _19 [[buffer(0)]]) + { + main0_out out = {}; + out.gl_Position = _19.mvp * in.position; + if (_19.draw_mode == 0.0) + { + out.color = float4((in.normal + float3(1.0)) * 0.5, 1.0); + } + else + { + if (_19.draw_mode == 1.0) + { + out.color = float4(in.texcoord, 0.0, 1.0); + } + else + { + out.color = in.color0; + } + } + return out; + } + */ __gshared char[883] VS_SOURCE_METAL_MACOS = [ 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, @@ -535,28 +537,28 @@ __gshared char[883] VS_SOURCE_METAL_MACOS = [ 0x0a,0x0a,0x00, ]; /* - #include - #include - - using namespace metal; - - struct main0_out - { - float4 frag_color [[color(0)]]; - }; - - struct main0_in - { - float4 color [[user(locn0)]]; - }; - - fragment main0_out main0(main0_in in [[stage_in]]) - { - main0_out out = {}; - out.frag_color = in.color; - return out; - } - + #include + #include + + using namespace metal; + + struct main0_out + { + float4 frag_color [[color(0)]]; + }; + + struct main0_in + { + float4 color [[user(locn0)]]; + }; + + fragment main0_out main0(main0_in in [[stage_in]]) + { + main0_out out = {}; + out.frag_color = in.color; + return out; + } + */ __gshared char[315] FS_SOURCE_METAL_MACOS = [ 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, @@ -581,68 +583,68 @@ __gshared char[315] FS_SOURCE_METAL_MACOS = [ 0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - diagnostic(off, derivative_uniformity); - - struct vs_params { - /_ @offset(0) _/ - draw_mode : f32, - /_ @offset(16) _/ - mvp : mat4x4f, - } - - @group(0) @binding(0) var x_19 : vs_params; - - var position_1 : vec4f; - - var color : vec4f; - - var normal : vec3f; - - var texcoord : vec2f; - - var color0 : vec4f; - - var gl_Position : vec4f; - - fn main_1() { - let x_23 : mat4x4f = x_19.mvp; - let x_26 : vec4f = position_1; - gl_Position = (x_23 * x_26); - let x_32 : f32 = x_19.draw_mode; - if ((x_32 == 0.0f)) { - let x_42 : vec3f = normal; - let x_47 : vec3f = ((x_42 + vec3f(1.0f, 1.0f, 1.0f)) * 0.5f); - color = vec4f(x_47.x, x_47.y, x_47.z, 1.0f); - } else { - let x_54 : f32 = x_19.draw_mode; - if ((x_54 == 1.0f)) { - let x_61 : vec2f = texcoord; - color = vec4f(x_61.x, x_61.y, 0.0f, 1.0f); - } else { - let x_67 : vec4f = color0; - color = x_67; - } - } - return; - } - - struct main_out { - @builtin(position) - gl_Position : vec4f, - @location(0) - color_1 : vec4f, - } - - @vertex - fn main(@location(0) position_1_param : vec4f, @location(1) normal_param : vec3f, @location(2) texcoord_param : vec2f, @location(3) color0_param : vec4f) -> main_out { - position_1 = position_1_param; - normal = normal_param; - texcoord = texcoord_param; - color0 = color0_param; - main_1(); - return main_out(gl_Position, color); - } - + diagnostic(off, derivative_uniformity); + + struct vs_params { + /_ @offset(0) _/ + draw_mode : f32, + /_ @offset(16) _/ + mvp : mat4x4f, + } + + @group(0) @binding(0) var x_19 : vs_params; + + var position_1 : vec4f; + + var color : vec4f; + + var normal : vec3f; + + var texcoord : vec2f; + + var color0 : vec4f; + + var gl_Position : vec4f; + + fn main_1() { + let x_23 : mat4x4f = x_19.mvp; + let x_26 : vec4f = position_1; + gl_Position = (x_23 * x_26); + let x_32 : f32 = x_19.draw_mode; + if ((x_32 == 0.0f)) { + let x_42 : vec3f = normal; + let x_47 : vec3f = ((x_42 + vec3f(1.0f, 1.0f, 1.0f)) * 0.5f); + color = vec4f(x_47.x, x_47.y, x_47.z, 1.0f); + } else { + let x_54 : f32 = x_19.draw_mode; + if ((x_54 == 1.0f)) { + let x_61 : vec2f = texcoord; + color = vec4f(x_61.x, x_61.y, 0.0f, 1.0f); + } else { + let x_67 : vec4f = color0; + color = x_67; + } + } + return; + } + + struct main_out { + @builtin(position) + gl_Position : vec4f, + @location(0) + color_1 : vec4f, + } + + @vertex + fn main(@location(0) position_1_param : vec4f, @location(1) normal_param : vec3f, @location(2) texcoord_param : vec2f, @location(3) color0_param : vec4f) -> main_out { + position_1 = position_1_param; + normal = normal_param; + texcoord = texcoord_param; + color0 = color0_param; + main_1(); + return main_out(gl_Position, color); + } + */ __gshared char[1387] VS_SOURCE_WGSL = [ 0x64,0x69,0x61,0x67,0x6e,0x6f,0x73,0x74,0x69,0x63,0x28,0x6f,0x66,0x66,0x2c,0x20, @@ -734,30 +736,30 @@ __gshared char[1387] VS_SOURCE_WGSL = [ 0x6f,0x6c,0x6f,0x72,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - diagnostic(off, derivative_uniformity); - - var frag_color : vec4f; - - var color : vec4f; - - fn main_1() { - let x_12 : vec4f = color; - frag_color = x_12; - return; - } - - struct main_out { - @location(0) - frag_color_1 : vec4f, - } - - @fragment - fn main(@location(0) color_param : vec4f) -> main_out { - color = color_param; - main_1(); - return main_out(frag_color); - } - + diagnostic(off, derivative_uniformity); + + var frag_color : vec4f; + + var color : vec4f; + + fn main_1() { + let x_12 : vec4f = color; + frag_color = x_12; + return; + } + + struct main_out { + @location(0) + frag_color_1 : vec4f, + } + + @fragment + fn main(@location(0) color_param : vec4f) -> main_out { + color = color_param; + main_1(); + return main_out(frag_color); + } + */ __gshared char[376] FS_SOURCE_WGSL = [ 0x64,0x69,0x61,0x67,0x6e,0x6f,0x73,0x74,0x69,0x63,0x28,0x6f,0x66,0x66,0x2c,0x20, @@ -785,81 +787,75 @@ __gshared char[376] FS_SOURCE_WGSL = [ 0x69,0x6e,0x5f,0x6f,0x75,0x74,0x28,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f, 0x72,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; - -sg.ShaderDesc shapes_shader_desc(sg.Backend backend) @trusted @nogc nothrow { - sg.ShaderDesc desc; - switch (backend) { - case sg.Backend.Glcore33: - desc.attrs[0].name = "position"; - desc.attrs[1].name = "normal"; - desc.attrs[2].name = "texcoord"; - desc.attrs[3].name = "color0"; - desc.vs.source = &VS_SOURCE_GLSL330[0]; - desc.vs.entry = "main"; - desc.vs.uniform_blocks[0].size = 80; - desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; - desc.vs.uniform_blocks[0].uniforms[0].name = "vs_params"; - desc.vs.uniform_blocks[0].uniforms[0].type = sg.UniformType.Float4; - desc.vs.uniform_blocks[0].uniforms[0].array_count = 5; - desc.fs.source = &FS_SOURCE_GLSL330[0]; - desc.fs.entry = "main"; - desc.label = "shapes_shader"; - break; - case sg.Backend.Gles3: - desc.attrs[0].name = "position"; - desc.attrs[1].name = "normal"; - desc.attrs[2].name = "texcoord"; - desc.attrs[3].name = "color0"; - desc.vs.source = &VS_SOURCE_GLSL300ES[0]; - desc.vs.entry = "main"; - desc.vs.uniform_blocks[0].size = 80; - desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; - desc.vs.uniform_blocks[0].uniforms[0].name = "vs_params"; - desc.vs.uniform_blocks[0].uniforms[0].type = sg.UniformType.Float4; - desc.vs.uniform_blocks[0].uniforms[0].array_count = 5; - desc.fs.source = &FS_SOURCE_GLSL300ES[0]; - desc.fs.entry = "main"; - desc.label = "shapes_shader"; - break; - case sg.Backend.D3d11: - desc.attrs[0].sem_name = "TEXCOORD"; - desc.attrs[0].sem_index = 0; - desc.attrs[1].sem_name = "TEXCOORD"; - desc.attrs[1].sem_index = 1; - desc.attrs[2].sem_name = "TEXCOORD"; - desc.attrs[2].sem_index = 2; - desc.attrs[3].sem_name = "TEXCOORD"; - desc.attrs[3].sem_index = 3; - desc.vs.source = &VS_SOURCE_HLSL4[0]; - desc.vs.d3d11_target = "vs_4_0"; - desc.vs.entry = "main"; - desc.vs.uniform_blocks[0].size = 80; - desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; - desc.fs.source = &FS_SOURCE_HLSL4[0]; - desc.fs.d3d11_target = "ps_4_0"; - desc.fs.entry = "main"; - desc.label = "shapes_shader"; - break; - case sg.Backend.Metal_macos: - desc.vs.source = &VS_SOURCE_METAL_MACOS[0]; - desc.vs.entry = "main0"; - desc.vs.uniform_blocks[0].size = 80; - desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; - desc.fs.source = &FS_SOURCE_METAL_MACOS[0]; - desc.fs.entry = "main0"; - desc.label = "shapes_shader"; - break; - case sg.Backend.Wgpu: - desc.vs.source = &VS_SOURCE_WGSL[0]; - desc.vs.entry = "main"; - desc.vs.uniform_blocks[0].size = 80; - desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; - desc.fs.source = &FS_SOURCE_WGSL[0]; - desc.fs.entry = "main"; - desc.label = "shapes_shader"; - break; - default: - break; - } - return desc; +sg.ShaderDesc shapesShaderDesc(sg.Backend backend) @trusted @nogc nothrow { + sg.ShaderDesc desc; + desc.label = "shapes_shader"; + switch (backend) { + case sg.Backend.Glcore: + desc.attrs[0].name = "position"; + desc.attrs[1].name = "normal"; + desc.attrs[2].name = "texcoord"; + desc.attrs[3].name = "color0"; + desc.vs.source = &VS_SOURCE_GLSL430[0]; + desc.vs.entry = "main"; + desc.vs.uniform_blocks[0].size = 80; + desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; + desc.vs.uniform_blocks[0].uniforms[0].name = "vs_params"; + desc.vs.uniform_blocks[0].uniforms[0].type = sg.UniformType.Float4; + desc.vs.uniform_blocks[0].uniforms[0].array_count = 5; + desc.fs.source = &FS_SOURCE_GLSL430[0]; + desc.fs.entry = "main"; + break; + case sg.Backend.Gles3: + desc.attrs[0].name = "position"; + desc.attrs[1].name = "normal"; + desc.attrs[2].name = "texcoord"; + desc.attrs[3].name = "color0"; + desc.vs.source = &VS_SOURCE_GLSL300ES[0]; + desc.vs.entry = "main"; + desc.vs.uniform_blocks[0].size = 80; + desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; + desc.vs.uniform_blocks[0].uniforms[0].name = "vs_params"; + desc.vs.uniform_blocks[0].uniforms[0].type = sg.UniformType.Float4; + desc.vs.uniform_blocks[0].uniforms[0].array_count = 5; + desc.fs.source = &FS_SOURCE_GLSL300ES[0]; + desc.fs.entry = "main"; + break; + case sg.Backend.D3d11: + desc.attrs[0].sem_name = "TEXCOORD"; + desc.attrs[0].sem_index = 0; + desc.attrs[1].sem_name = "TEXCOORD"; + desc.attrs[1].sem_index = 1; + desc.attrs[2].sem_name = "TEXCOORD"; + desc.attrs[2].sem_index = 2; + desc.attrs[3].sem_name = "TEXCOORD"; + desc.attrs[3].sem_index = 3; + desc.vs.source = &VS_SOURCE_HLSL4[0]; + desc.vs.d3d11_target = "vs_4_0"; + desc.vs.entry = "main"; + desc.vs.uniform_blocks[0].size = 80; + desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; + desc.fs.source = &FS_SOURCE_HLSL4[0]; + desc.fs.d3d11_target = "ps_4_0"; + desc.fs.entry = "main"; + break; + case sg.Backend.Metal_macos: + desc.vs.source = &VS_SOURCE_METAL_MACOS[0]; + desc.vs.entry = "main0"; + desc.vs.uniform_blocks[0].size = 80; + desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; + desc.fs.source = &FS_SOURCE_METAL_MACOS[0]; + desc.fs.entry = "main0"; + break; + case sg.Backend.Wgpu: + desc.vs.source = &VS_SOURCE_WGSL[0]; + desc.vs.entry = "main"; + desc.vs.uniform_blocks[0].size = 80; + desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; + desc.fs.source = &FS_SOURCE_WGSL[0]; + desc.fs.entry = "main"; + break; + default: break; + } + return desc; } diff --git a/src/shaders/texcube.d b/src/shaders/texcube.d index c0d6822..c510fc8 100644 --- a/src/shaders/texcube.d +++ b/src/shaders/texcube.d @@ -1,141 +1,143 @@ module shaders.texcube; import sg = sokol.gfx; +import m = handmade.math; extern(C): /* #version:1# (machine generated, don't edit!) - + Generated by sokol-shdc (https://github.com/floooh/sokol-tools) - - Cmdline: sokol-shdc -i src/shaders/texcube.glsl -o src/shaders/texcube.d -l glsl330:metal_macos:hlsl4:glsl300es:wgsl -f sokol_d - + + Cmdline: + sokol-shdc -i src/shaders/texcube.glsl -o src/shaders/texcube.d -l glsl430:metal_macos:hlsl4:glsl300es:wgsl -f sokol_d + Overview: - - Shader program 'texcube': - Get shader desc: texcube_shader_desc(sg.query_backend()); - Vertex shader: vs - Attribute slots: - ATTR_VS_POS = 0 - ATTR_VS_COLOR0 = 1 - ATTR_VS_TEXCOORD0 = 2 - Uniform block 'vs_params': - C struct: vs_params_t - Bind slot: SLOT_VS_PARAMS = 0 - Fragment shader: fs - Image 'tex': - Type: sg.ImageType._2d - Sample Type: sg.ImageSampleType.Float - Bind slot: SLOT_TEX = 0 - Image 'tex': - Image Type: sg.ImageType._2d - Sample Type: sg.ImageSampleType.Float - Multisampled: false - Bind slot: SLOT_tex = 0 - Sampler 'smp': - Type: sg.SamplerType.Filtering - Bind slot: SLOT_smp = 0 - Image Sampler Pair 'tex_smp': - Image: tex - Sampler: smp - + ========= + Shader program: 'texcube': + Get shader desc: texcubeShaderDesc(sg.queryBackend()); + Vertex shader: vs + Attributes: + ATTR_VS_POS => 0 + ATTR_VS_COLOR0 => 1 + ATTR_VS_TEXCOORD0 => 2 + Uniform block 'vs_params': + D struct: VsParams + Bind slot: SLOT_VS_PARAMS => 0 + Fragment shader: fs + Image 'tex': + Image type: sg.ImageType._2d + Sample type: sg.ImageSampleType.Float + Multisampled: false + Bind slot: SLOT_TEX => 0 + Sampler 'smp': + Type: sg.SamplerType.Filtering + Bind slot: SLOT_SMP => 0 + Image Sampler Pair 'tex_smp': + Image: tex + Sampler: smp */ -import m = handmade.math; enum ATTR_VS_POS = 0; enum ATTR_VS_COLOR0 = 1; enum ATTR_VS_TEXCOORD0 = 2; +enum SLOT_VS_PARAMS = 0; enum SLOT_TEX = 0; enum SLOT_SMP = 0; -enum SLOT_VS_PARAMS = 0; struct VsParams { - m.Mat4 mvp; + align(16) m.Mat4 mvp; } /* - #version 330 - - uniform vec4 vs_params[4]; - layout(location = 0) in vec4 pos; - out vec4 color; - layout(location = 1) in vec4 color0; - out vec2 uv; - layout(location = 2) in vec2 texcoord0; - - void main() - { - gl_Position = mat4(vs_params[0], vs_params[1], vs_params[2], vs_params[3]) * pos; - color = color0; - uv = texcoord0 * 5.0; - } - + #version 430 + + uniform vec4 vs_params[4]; + layout(location = 0) in vec4 pos; + layout(location = 0) out vec4 color; + layout(location = 1) in vec4 color0; + layout(location = 1) out vec2 uv; + layout(location = 2) in vec2 texcoord0; + + void main() + { + gl_Position = mat4(vs_params[0], vs_params[1], vs_params[2], vs_params[3]) * pos; + color = color0; + uv = texcoord0 * 5.0; + } + */ -__gshared char[332] VS_SOURCE_GLSL330 = [ - 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x33,0x30,0x0a,0x0a,0x75,0x6e, +__gshared char[374] VS_SOURCE_GLSL430 = [ + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x75,0x6e, 0x69,0x66,0x6f,0x72,0x6d,0x20,0x76,0x65,0x63,0x34,0x20,0x76,0x73,0x5f,0x70,0x61, 0x72,0x61,0x6d,0x73,0x5b,0x34,0x5d,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28, 0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e, - 0x20,0x76,0x65,0x63,0x34,0x20,0x70,0x6f,0x73,0x3b,0x0a,0x6f,0x75,0x74,0x20,0x76, - 0x65,0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75, - 0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20, - 0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a, - 0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x32,0x20,0x75,0x76,0x3b,0x0a,0x6c,0x61,0x79, - 0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x32, - 0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x32,0x20,0x74,0x65,0x78,0x63,0x6f,0x6f, - 0x72,0x64,0x30,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28, - 0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74, - 0x69,0x6f,0x6e,0x20,0x3d,0x20,0x6d,0x61,0x74,0x34,0x28,0x76,0x73,0x5f,0x70,0x61, - 0x72,0x61,0x6d,0x73,0x5b,0x30,0x5d,0x2c,0x20,0x76,0x73,0x5f,0x70,0x61,0x72,0x61, - 0x6d,0x73,0x5b,0x31,0x5d,0x2c,0x20,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73, - 0x5b,0x32,0x5d,0x2c,0x20,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x33, - 0x5d,0x29,0x20,0x2a,0x20,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x63,0x6f, - 0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x75,0x76,0x20,0x3d,0x20,0x74,0x65,0x78,0x63,0x6f,0x6f,0x72,0x64,0x30, - 0x20,0x2a,0x20,0x35,0x2e,0x30,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, + 0x20,0x76,0x65,0x63,0x34,0x20,0x70,0x6f,0x73,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75, + 0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20, + 0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a, + 0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20, + 0x3d,0x20,0x31,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c, + 0x6f,0x72,0x30,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61, + 0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65, + 0x63,0x32,0x20,0x75,0x76,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f, + 0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x32,0x29,0x20,0x69,0x6e,0x20,0x76, + 0x65,0x63,0x32,0x20,0x74,0x65,0x78,0x63,0x6f,0x6f,0x72,0x64,0x30,0x3b,0x0a,0x0a, + 0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, + 0x6d,0x61,0x74,0x34,0x28,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x30, + 0x5d,0x2c,0x20,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x31,0x5d,0x2c, + 0x20,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x32,0x5d,0x2c,0x20,0x76, + 0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x33,0x5d,0x29,0x20,0x2a,0x20,0x70, + 0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20, + 0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x75,0x76,0x20,0x3d, + 0x20,0x74,0x65,0x78,0x63,0x6f,0x6f,0x72,0x64,0x30,0x20,0x2a,0x20,0x35,0x2e,0x30, + 0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - #version 330 - - uniform sampler2D tex_smp; - - layout(location = 0) out vec4 frag_color; - in vec2 uv; - in vec4 color; - - void main() - { - frag_color = texture(tex_smp, uv) * color; - } - + #version 430 + + layout(binding = 0) uniform sampler2D tex_smp; + + layout(location = 0) out vec4 frag_color; + layout(location = 1) in vec2 uv; + layout(location = 0) in vec4 color; + + void main() + { + frag_color = texture(tex_smp, uv) * color; + } + */ -__gshared char[177] FS_SOURCE_GLSL330 = [ - 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x33,0x30,0x0a,0x0a,0x75,0x6e, - 0x69,0x66,0x6f,0x72,0x6d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x32,0x44,0x20, - 0x74,0x65,0x78,0x5f,0x73,0x6d,0x70,0x3b,0x0a,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74, - 0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x6f, - 0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c, - 0x6f,0x72,0x3b,0x0a,0x69,0x6e,0x20,0x76,0x65,0x63,0x32,0x20,0x75,0x76,0x3b,0x0a, - 0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x0a, - 0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x74, - 0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x74,0x65,0x78,0x5f,0x73,0x6d,0x70,0x2c,0x20, - 0x75,0x76,0x29,0x20,0x2a,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x7d,0x0a,0x0a, - 0x00, +__gshared char[239] FS_SOURCE_GLSL430 = [ + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x6c,0x61, + 0x79,0x6f,0x75,0x74,0x28,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d,0x20,0x30, + 0x29,0x20,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65, + 0x72,0x32,0x44,0x20,0x74,0x65,0x78,0x5f,0x73,0x6d,0x70,0x3b,0x0a,0x0a,0x6c,0x61, + 0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, + 0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x66,0x72,0x61,0x67, + 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c, + 0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x69,0x6e,0x20, + 0x76,0x65,0x63,0x32,0x20,0x75,0x76,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28, + 0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e, + 0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x0a,0x76,0x6f, + 0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x74,0x65,0x78, + 0x74,0x75,0x72,0x65,0x28,0x74,0x65,0x78,0x5f,0x73,0x6d,0x70,0x2c,0x20,0x75,0x76, + 0x29,0x20,0x2a,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - #version 300 es - - uniform vec4 vs_params[4]; - layout(location = 0) in vec4 pos; - out vec4 color; - layout(location = 1) in vec4 color0; - out vec2 uv; - layout(location = 2) in vec2 texcoord0; - - void main() - { - gl_Position = mat4(vs_params[0], vs_params[1], vs_params[2], vs_params[3]) * pos; - color = color0; - uv = texcoord0 * 5.0; - } - + #version 300 es + + uniform vec4 vs_params[4]; + layout(location = 0) in vec4 pos; + out vec4 color; + layout(location = 1) in vec4 color0; + out vec2 uv; + layout(location = 2) in vec2 texcoord0; + + void main() + { + gl_Position = mat4(vs_params[0], vs_params[1], vs_params[2], vs_params[3]) * pos; + color = color0; + uv = texcoord0 * 5.0; + } + */ __gshared char[335] VS_SOURCE_GLSL300ES = [ 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x30,0x30,0x20,0x65,0x73,0x0a, @@ -161,21 +163,21 @@ __gshared char[335] VS_SOURCE_GLSL300ES = [ 0x72,0x64,0x30,0x20,0x2a,0x20,0x35,0x2e,0x30,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - #version 300 es - precision mediump float; - precision highp int; - - uniform highp sampler2D tex_smp; - - layout(location = 0) out highp vec4 frag_color; - in highp vec2 uv; - in highp vec4 color; - - void main() - { - frag_color = texture(tex_smp, uv) * color; - } - + #version 300 es + precision mediump float; + precision highp int; + + uniform highp sampler2D tex_smp; + + layout(location = 0) out highp vec4 frag_color; + in highp vec2 uv; + in highp vec4 color; + + void main() + { + frag_color = texture(tex_smp, uv) * color; + } + */ __gshared char[250] FS_SOURCE_GLSL300ES = [ 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x30,0x30,0x20,0x65,0x73,0x0a, @@ -196,52 +198,52 @@ __gshared char[250] FS_SOURCE_GLSL300ES = [ 0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - cbuffer vs_params : register(b0) - { - row_major float4x4 _19_mvp : packoffset(c0); - }; - - - static float4 gl_Position; - static float4 pos; - static float4 color; - static float4 color0; - static float2 uv; - static float2 texcoord0; - - struct SPIRV_Cross_Input - { - float4 pos : TEXCOORD0; - float4 color0 : TEXCOORD1; - float2 texcoord0 : TEXCOORD2; - }; - - struct SPIRV_Cross_Output - { - float4 color : TEXCOORD0; - float2 uv : TEXCOORD1; - float4 gl_Position : SV_Position; - }; - - void vert_main() - { - gl_Position = mul(pos, _19_mvp); - color = color0; - uv = texcoord0 * 5.0f; - } - - SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) - { - pos = stage_input.pos; - color0 = stage_input.color0; - texcoord0 = stage_input.texcoord0; - vert_main(); - SPIRV_Cross_Output stage_output; - stage_output.gl_Position = gl_Position; - stage_output.color = color; - stage_output.uv = uv; - return stage_output; - } + cbuffer vs_params : register(b0) + { + row_major float4x4 _19_mvp : packoffset(c0); + }; + + + static float4 gl_Position; + static float4 pos; + static float4 color; + static float4 color0; + static float2 uv; + static float2 texcoord0; + + struct SPIRV_Cross_Input + { + float4 pos : TEXCOORD0; + float4 color0 : TEXCOORD1; + float2 texcoord0 : TEXCOORD2; + }; + + struct SPIRV_Cross_Output + { + float4 color : TEXCOORD0; + float2 uv : TEXCOORD1; + float4 gl_Position : SV_Position; + }; + + void vert_main() + { + gl_Position = mul(pos, _19_mvp); + color = color0; + uv = texcoord0 * 5.0f; + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + pos = stage_input.pos; + color0 = stage_input.color0; + texcoord0 = stage_input.texcoord0; + vert_main(); + SPIRV_Cross_Output stage_output; + stage_output.gl_Position = gl_Position; + stage_output.color = color; + stage_output.uv = uv; + return stage_output; + } */ __gshared char[919] VS_SOURCE_HLSL4 = [ 0x63,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d, @@ -304,38 +306,38 @@ __gshared char[919] VS_SOURCE_HLSL4 = [ 0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x00, ]; /* - Texture2D tex : register(t0); - SamplerState smp : register(s0); - - static float4 frag_color; - static float2 uv; - static float4 color; - - struct SPIRV_Cross_Input - { - float4 color : TEXCOORD0; - float2 uv : TEXCOORD1; - }; - - struct SPIRV_Cross_Output - { - float4 frag_color : SV_Target0; - }; - - void frag_main() - { - frag_color = tex.Sample(smp, uv) * color; - } - - SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) - { - uv = stage_input.uv; - color = stage_input.color; - frag_main(); - SPIRV_Cross_Output stage_output; - stage_output.frag_color = frag_color; - return stage_output; - } + Texture2D tex : register(t0); + SamplerState smp : register(s0); + + static float4 frag_color; + static float2 uv; + static float4 color; + + struct SPIRV_Cross_Input + { + float4 color : TEXCOORD0; + float2 uv : TEXCOORD1; + }; + + struct SPIRV_Cross_Output + { + float4 frag_color : SV_Target0; + }; + + void frag_main() + { + frag_color = tex.Sample(smp, uv) * color; + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + uv = stage_input.uv; + color = stage_input.color; + frag_main(); + SPIRV_Cross_Output stage_output; + stage_output.frag_color = frag_color; + return stage_output; + } */ __gshared char[599] FS_SOURCE_HLSL4 = [ 0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x44,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34, @@ -378,39 +380,39 @@ __gshared char[599] FS_SOURCE_HLSL4 = [ 0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x00, ]; /* - #include - #include - - using namespace metal; - - struct vs_params - { - float4x4 mvp; - }; - - struct main0_out - { - float4 color [[user(locn0)]]; - float2 uv [[user(locn1)]]; - float4 gl_Position [[position]]; - }; - - struct main0_in - { - float4 pos [[attribute(0)]]; - float4 color0 [[attribute(1)]]; - float2 texcoord0 [[attribute(2)]]; - }; - - vertex main0_out main0(main0_in in [[stage_in]], constant vs_params& _19 [[buffer(0)]]) - { - main0_out out = {}; - out.gl_Position = _19.mvp * in.pos; - out.color = in.color0; - out.uv = in.texcoord0 * 5.0; - return out; - } - + #include + #include + + using namespace metal; + + struct vs_params + { + float4x4 mvp; + }; + + struct main0_out + { + float4 color [[user(locn0)]]; + float2 uv [[user(locn1)]]; + float4 gl_Position [[position]]; + }; + + struct main0_in + { + float4 pos [[attribute(0)]]; + float4 color0 [[attribute(1)]]; + float2 texcoord0 [[attribute(2)]]; + }; + + vertex main0_out main0(main0_in in [[stage_in]], constant vs_params& _19 [[buffer(0)]]) + { + main0_out out = {}; + out.gl_Position = _19.mvp * in.pos; + out.color = in.color0; + out.uv = in.texcoord0 * 5.0; + return out; + } + */ __gshared char[602] VS_SOURCE_METAL_MACOS = [ 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, @@ -453,29 +455,29 @@ __gshared char[602] VS_SOURCE_METAL_MACOS = [ 0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* - #include - #include - - using namespace metal; - - struct main0_out - { - float4 frag_color [[color(0)]]; - }; - - struct main0_in - { - float4 color [[user(locn0)]]; - float2 uv [[user(locn1)]]; - }; - - fragment main0_out main0(main0_in in [[stage_in]], texture2d tex [[texture(0)]], sampler smp [[sampler(0)]]) - { - main0_out out = {}; - out.frag_color = tex.sample(smp, in.uv) * in.color; - return out; - } - + #include + #include + + using namespace metal; + + struct main0_out + { + float4 frag_color [[color(0)]]; + }; + + struct main0_in + { + float4 color [[user(locn0)]]; + float2 uv [[user(locn1)]]; + }; + + fragment main0_out main0(main0_in in [[stage_in]], texture2d tex [[texture(0)]], sampler smp [[sampler(0)]]) + { + main0_out out = {}; + out.frag_color = tex.sample(smp, in.uv) * in.color; + return out; + } + */ __gshared char[436] FS_SOURCE_METAL_MACOS = [ 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, @@ -508,56 +510,56 @@ __gshared char[436] FS_SOURCE_METAL_MACOS = [ 0x7d,0x0a,0x0a,0x00, ]; /* - diagnostic(off, derivative_uniformity); - - struct vs_params { - /_ @offset(0) _/ - mvp : mat4x4f, - } - - @group(0) @binding(0) var x_19 : vs_params; - - var pos : vec4f; - - var color : vec4f; - - var color0 : vec4f; - - var uv : vec2f; - - var texcoord0 : vec2f; - - var gl_Position : vec4f; - - fn main_1() { - let x_22 : mat4x4f = x_19.mvp; - let x_25 : vec4f = pos; - gl_Position = (x_22 * x_25); - let x_31 : vec4f = color0; - color = x_31; - let x_37 : vec2f = texcoord0; - uv = (x_37 * 5.0f); - return; - } - - struct main_out { - @builtin(position) - gl_Position : vec4f, - @location(0) - color_1 : vec4f, - @location(1) - uv_1 : vec2f, - } - - @vertex - fn main(@location(0) pos_param : vec4f, @location(1) color0_param : vec4f, @location(2) texcoord0_param : vec2f) -> main_out { - pos = pos_param; - color0 = color0_param; - texcoord0 = texcoord0_param; - main_1(); - return main_out(gl_Position, color, uv); - } - + diagnostic(off, derivative_uniformity); + + struct vs_params { + /_ @offset(0) _/ + mvp : mat4x4f, + } + + @group(0) @binding(0) var x_19 : vs_params; + + var pos : vec4f; + + var color : vec4f; + + var color0 : vec4f; + + var uv : vec2f; + + var texcoord0 : vec2f; + + var gl_Position : vec4f; + + fn main_1() { + let x_22 : mat4x4f = x_19.mvp; + let x_25 : vec4f = pos; + gl_Position = (x_22 * x_25); + let x_31 : vec4f = color0; + color = x_31; + let x_37 : vec2f = texcoord0; + uv = (x_37 * 5.0f); + return; + } + + struct main_out { + @builtin(position) + gl_Position : vec4f, + @location(0) + color_1 : vec4f, + @location(1) + uv_1 : vec2f, + } + + @vertex + fn main(@location(0) pos_param : vec4f, @location(1) color0_param : vec4f, @location(2) texcoord0_param : vec2f) -> main_out { + pos = pos_param; + color0 = color0_param; + texcoord0 = texcoord0_param; + main_1(); + return main_out(gl_Position, color, uv); + } + */ __gshared char[948] VS_SOURCE_WGSL = [ 0x64,0x69,0x61,0x67,0x6e,0x6f,0x73,0x74,0x69,0x63,0x28,0x6f,0x66,0x66,0x2c,0x20, @@ -622,39 +624,39 @@ __gshared char[948] VS_SOURCE_WGSL = [ 0x7d,0x0a,0x0a,0x00, ]; /* - diagnostic(off, derivative_uniformity); - - var frag_color : vec4f; - - @group(1) @binding(32) var tex : texture_2d; - - @group(1) @binding(48) var smp : sampler; - - var uv : vec2f; - - var color : vec4f; - - fn main_1() { - let x_23 : vec2f = uv; - let x_24 : vec4f = textureSample(tex, smp, x_23); - let x_27 : vec4f = color; - frag_color = (x_24 * x_27); - return; - } - - struct main_out { - @location(0) - frag_color_1 : vec4f, - } - - @fragment - fn main(@location(1) uv_param : vec2f, @location(0) color_param : vec4f) -> main_out { - uv = uv_param; - color = color_param; - main_1(); - return main_out(frag_color); - } - + diagnostic(off, derivative_uniformity); + + var frag_color : vec4f; + + @group(1) @binding(48) var tex : texture_2d; + + @group(1) @binding(64) var smp : sampler; + + var uv : vec2f; + + var color : vec4f; + + fn main_1() { + let x_23 : vec2f = uv; + let x_24 : vec4f = textureSample(tex, smp, x_23); + let x_27 : vec4f = color; + frag_color = (x_24 * x_27); + return; + } + + struct main_out { + @location(0) + frag_color_1 : vec4f, + } + + @fragment + fn main(@location(1) uv_param : vec2f, @location(0) color_param : vec4f) -> main_out { + uv = uv_param; + color = color_param; + main_1(); + return main_out(frag_color); + } + */ __gshared char[630] FS_SOURCE_WGSL = [ 0x64,0x69,0x61,0x67,0x6e,0x6f,0x73,0x74,0x69,0x63,0x28,0x6f,0x66,0x66,0x2c,0x20, @@ -662,11 +664,11 @@ __gshared char[630] FS_SOURCE_WGSL = [ 0x72,0x6d,0x69,0x74,0x79,0x29,0x3b,0x0a,0x0a,0x76,0x61,0x72,0x3c,0x70,0x72,0x69, 0x76,0x61,0x74,0x65,0x3e,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72, 0x20,0x3a,0x20,0x76,0x65,0x63,0x34,0x66,0x3b,0x0a,0x0a,0x40,0x67,0x72,0x6f,0x75, - 0x70,0x28,0x31,0x29,0x20,0x40,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x28,0x33,0x32, + 0x70,0x28,0x31,0x29,0x20,0x40,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x28,0x34,0x38, 0x29,0x20,0x76,0x61,0x72,0x20,0x74,0x65,0x78,0x20,0x3a,0x20,0x74,0x65,0x78,0x74, 0x75,0x72,0x65,0x5f,0x32,0x64,0x3c,0x66,0x33,0x32,0x3e,0x3b,0x0a,0x0a,0x40,0x67, 0x72,0x6f,0x75,0x70,0x28,0x31,0x29,0x20,0x40,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67, - 0x28,0x34,0x38,0x29,0x20,0x76,0x61,0x72,0x20,0x73,0x6d,0x70,0x20,0x3a,0x20,0x73, + 0x28,0x36,0x34,0x29,0x20,0x76,0x61,0x72,0x20,0x73,0x6d,0x70,0x20,0x3a,0x20,0x73, 0x61,0x6d,0x70,0x6c,0x65,0x72,0x3b,0x0a,0x0a,0x76,0x61,0x72,0x3c,0x70,0x72,0x69, 0x76,0x61,0x74,0x65,0x3e,0x20,0x75,0x76,0x20,0x3a,0x20,0x76,0x65,0x63,0x32,0x66, 0x3b,0x0a,0x0a,0x76,0x61,0x72,0x3c,0x70,0x72,0x69,0x76,0x61,0x74,0x65,0x3e,0x20, @@ -698,124 +700,118 @@ __gshared char[630] FS_SOURCE_WGSL = [ 0x5f,0x6f,0x75,0x74,0x28,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x29, 0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; - -sg.ShaderDesc texcube_shader_desc(sg.Backend backend) @trusted @nogc nothrow { - sg.ShaderDesc desc; - switch (backend) { - case sg.Backend.Glcore33: - desc.attrs[0].name = "pos"; - desc.attrs[1].name = "color0"; - desc.attrs[2].name = "texcoord0"; - desc.vs.source = &VS_SOURCE_GLSL330[0]; - desc.vs.entry = "main"; - desc.vs.uniform_blocks[0].size = 64; - desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; - desc.vs.uniform_blocks[0].uniforms[0].name = "vs_params"; - desc.vs.uniform_blocks[0].uniforms[0].type = sg.UniformType.Float4; - desc.vs.uniform_blocks[0].uniforms[0].array_count = 4; - desc.fs.source = &FS_SOURCE_GLSL330[0]; - desc.fs.entry = "main"; - desc.fs.images[0].used = true; - desc.fs.images[0].multisampled = false; - desc.fs.images[0].image_type = sg.ImageType._2d; - desc.fs.images[0].sample_type = sg.ImageSampleType.Float; - desc.fs.samplers[0].used = true; - desc.fs.samplers[0].sampler_type = sg.SamplerType.Filtering; - desc.fs.image_sampler_pairs[0].used = true; - desc.fs.image_sampler_pairs[0].image_slot = 0; - desc.fs.image_sampler_pairs[0].sampler_slot = 0; - desc.fs.image_sampler_pairs[0].glsl_name = "tex_smp"; - desc.label = "texcube_shader"; - break; - case sg.Backend.Gles3: - desc.attrs[0].name = "pos"; - desc.attrs[1].name = "color0"; - desc.attrs[2].name = "texcoord0"; - desc.vs.source = &VS_SOURCE_GLSL300ES[0]; - desc.vs.entry = "main"; - desc.vs.uniform_blocks[0].size = 64; - desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; - desc.vs.uniform_blocks[0].uniforms[0].name = "vs_params"; - desc.vs.uniform_blocks[0].uniforms[0].type = sg.UniformType.Float4; - desc.vs.uniform_blocks[0].uniforms[0].array_count = 4; - desc.fs.source = &FS_SOURCE_GLSL300ES[0]; - desc.fs.entry = "main"; - desc.fs.images[0].used = true; - desc.fs.images[0].multisampled = false; - desc.fs.images[0].image_type = sg.ImageType._2d; - desc.fs.images[0].sample_type = sg.ImageSampleType.Float; - desc.fs.samplers[0].used = true; - desc.fs.samplers[0].sampler_type = sg.SamplerType.Filtering; - desc.fs.image_sampler_pairs[0].used = true; - desc.fs.image_sampler_pairs[0].image_slot = 0; - desc.fs.image_sampler_pairs[0].sampler_slot = 0; - desc.fs.image_sampler_pairs[0].glsl_name = "tex_smp"; - desc.label = "texcube_shader"; - break; - case sg.Backend.D3d11: - desc.attrs[0].sem_name = "TEXCOORD"; - desc.attrs[0].sem_index = 0; - desc.attrs[1].sem_name = "TEXCOORD"; - desc.attrs[1].sem_index = 1; - desc.attrs[2].sem_name = "TEXCOORD"; - desc.attrs[2].sem_index = 2; - desc.vs.source = &VS_SOURCE_HLSL4[0]; - desc.vs.d3d11_target = "vs_4_0"; - desc.vs.entry = "main"; - desc.vs.uniform_blocks[0].size = 64; - desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; - desc.fs.source = &FS_SOURCE_HLSL4[0]; - desc.fs.d3d11_target = "ps_4_0"; - desc.fs.entry = "main"; - desc.fs.images[0].used = true; - desc.fs.images[0].multisampled = false; - desc.fs.images[0].image_type = sg.ImageType._2d; - desc.fs.images[0].sample_type = sg.ImageSampleType.Float; - desc.fs.samplers[0].used = true; - desc.fs.samplers[0].sampler_type = sg.SamplerType.Filtering; - desc.fs.image_sampler_pairs[0].used = true; - desc.fs.image_sampler_pairs[0].image_slot = 0; - desc.fs.image_sampler_pairs[0].sampler_slot = 0; - desc.label = "texcube_shader"; - break; - case sg.Backend.Metal_macos: - desc.vs.source = &VS_SOURCE_METAL_MACOS[0]; - desc.vs.entry = "main0"; - desc.vs.uniform_blocks[0].size = 64; - desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; - desc.fs.source = &FS_SOURCE_METAL_MACOS[0]; - desc.fs.entry = "main0"; - desc.fs.images[0].used = true; - desc.fs.images[0].multisampled = false; - desc.fs.images[0].image_type = sg.ImageType._2d; - desc.fs.images[0].sample_type = sg.ImageSampleType.Float; - desc.fs.samplers[0].used = true; - desc.fs.samplers[0].sampler_type = sg.SamplerType.Filtering; - desc.fs.image_sampler_pairs[0].used = true; - desc.fs.image_sampler_pairs[0].image_slot = 0; - desc.fs.image_sampler_pairs[0].sampler_slot = 0; - desc.label = "texcube_shader"; - break; - case sg.Backend.Wgpu: - desc.vs.source = &VS_SOURCE_WGSL[0]; - desc.vs.entry = "main"; - desc.vs.uniform_blocks[0].size = 64; - desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; - desc.fs.source = &FS_SOURCE_WGSL[0]; - desc.fs.entry = "main"; - desc.fs.images[0].used = true; - desc.fs.images[0].multisampled = false; - desc.fs.images[0].image_type = sg.ImageType._2d; - desc.fs.images[0].sample_type = sg.ImageSampleType.Float; - desc.fs.samplers[0].used = true; - desc.fs.samplers[0].sampler_type = sg.SamplerType.Filtering; - desc.fs.image_sampler_pairs[0].used = true; - desc.fs.image_sampler_pairs[0].image_slot = 0; - desc.fs.image_sampler_pairs[0].sampler_slot = 0; - desc.label = "texcube_shader"; - break; - default: - break; - } - return desc; +sg.ShaderDesc texcubeShaderDesc(sg.Backend backend) @trusted @nogc nothrow { + sg.ShaderDesc desc; + desc.label = "texcube_shader"; + switch (backend) { + case sg.Backend.Glcore: + desc.attrs[0].name = "pos"; + desc.attrs[1].name = "color0"; + desc.attrs[2].name = "texcoord0"; + desc.vs.source = &VS_SOURCE_GLSL430[0]; + desc.vs.entry = "main"; + desc.vs.uniform_blocks[0].size = 64; + desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; + desc.vs.uniform_blocks[0].uniforms[0].name = "vs_params"; + desc.vs.uniform_blocks[0].uniforms[0].type = sg.UniformType.Float4; + desc.vs.uniform_blocks[0].uniforms[0].array_count = 4; + desc.fs.source = &FS_SOURCE_GLSL430[0]; + desc.fs.entry = "main"; + desc.fs.images[0].used = true; + desc.fs.images[0].multisampled = false; + desc.fs.images[0].image_type = sg.ImageType._2d; + desc.fs.images[0].sample_type = sg.ImageSampleType.Float; + desc.fs.samplers[0].used = true; + desc.fs.samplers[0].sampler_type = sg.SamplerType.Filtering; + desc.fs.image_sampler_pairs[0].used = true; + desc.fs.image_sampler_pairs[0].image_slot = 0; + desc.fs.image_sampler_pairs[0].sampler_slot = 0; + desc.fs.image_sampler_pairs[0].glsl_name = "tex_smp"; + break; + case sg.Backend.Gles3: + desc.attrs[0].name = "pos"; + desc.attrs[1].name = "color0"; + desc.attrs[2].name = "texcoord0"; + desc.vs.source = &VS_SOURCE_GLSL300ES[0]; + desc.vs.entry = "main"; + desc.vs.uniform_blocks[0].size = 64; + desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; + desc.vs.uniform_blocks[0].uniforms[0].name = "vs_params"; + desc.vs.uniform_blocks[0].uniforms[0].type = sg.UniformType.Float4; + desc.vs.uniform_blocks[0].uniforms[0].array_count = 4; + desc.fs.source = &FS_SOURCE_GLSL300ES[0]; + desc.fs.entry = "main"; + desc.fs.images[0].used = true; + desc.fs.images[0].multisampled = false; + desc.fs.images[0].image_type = sg.ImageType._2d; + desc.fs.images[0].sample_type = sg.ImageSampleType.Float; + desc.fs.samplers[0].used = true; + desc.fs.samplers[0].sampler_type = sg.SamplerType.Filtering; + desc.fs.image_sampler_pairs[0].used = true; + desc.fs.image_sampler_pairs[0].image_slot = 0; + desc.fs.image_sampler_pairs[0].sampler_slot = 0; + desc.fs.image_sampler_pairs[0].glsl_name = "tex_smp"; + break; + case sg.Backend.D3d11: + desc.attrs[0].sem_name = "TEXCOORD"; + desc.attrs[0].sem_index = 0; + desc.attrs[1].sem_name = "TEXCOORD"; + desc.attrs[1].sem_index = 1; + desc.attrs[2].sem_name = "TEXCOORD"; + desc.attrs[2].sem_index = 2; + desc.vs.source = &VS_SOURCE_HLSL4[0]; + desc.vs.d3d11_target = "vs_4_0"; + desc.vs.entry = "main"; + desc.vs.uniform_blocks[0].size = 64; + desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; + desc.fs.source = &FS_SOURCE_HLSL4[0]; + desc.fs.d3d11_target = "ps_4_0"; + desc.fs.entry = "main"; + desc.fs.images[0].used = true; + desc.fs.images[0].multisampled = false; + desc.fs.images[0].image_type = sg.ImageType._2d; + desc.fs.images[0].sample_type = sg.ImageSampleType.Float; + desc.fs.samplers[0].used = true; + desc.fs.samplers[0].sampler_type = sg.SamplerType.Filtering; + desc.fs.image_sampler_pairs[0].used = true; + desc.fs.image_sampler_pairs[0].image_slot = 0; + desc.fs.image_sampler_pairs[0].sampler_slot = 0; + break; + case sg.Backend.Metal_macos: + desc.vs.source = &VS_SOURCE_METAL_MACOS[0]; + desc.vs.entry = "main0"; + desc.vs.uniform_blocks[0].size = 64; + desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; + desc.fs.source = &FS_SOURCE_METAL_MACOS[0]; + desc.fs.entry = "main0"; + desc.fs.images[0].used = true; + desc.fs.images[0].multisampled = false; + desc.fs.images[0].image_type = sg.ImageType._2d; + desc.fs.images[0].sample_type = sg.ImageSampleType.Float; + desc.fs.samplers[0].used = true; + desc.fs.samplers[0].sampler_type = sg.SamplerType.Filtering; + desc.fs.image_sampler_pairs[0].used = true; + desc.fs.image_sampler_pairs[0].image_slot = 0; + desc.fs.image_sampler_pairs[0].sampler_slot = 0; + break; + case sg.Backend.Wgpu: + desc.vs.source = &VS_SOURCE_WGSL[0]; + desc.vs.entry = "main"; + desc.vs.uniform_blocks[0].size = 64; + desc.vs.uniform_blocks[0].layout = sg.UniformLayout.Std140; + desc.fs.source = &FS_SOURCE_WGSL[0]; + desc.fs.entry = "main"; + desc.fs.images[0].used = true; + desc.fs.images[0].multisampled = false; + desc.fs.images[0].image_type = sg.ImageType._2d; + desc.fs.images[0].sample_type = sg.ImageSampleType.Float; + desc.fs.samplers[0].used = true; + desc.fs.samplers[0].sampler_type = sg.SamplerType.Filtering; + desc.fs.image_sampler_pairs[0].used = true; + desc.fs.image_sampler_pairs[0].image_slot = 0; + desc.fs.image_sampler_pairs[0].sampler_slot = 0; + break; + default: break; + } + return desc; } diff --git a/src/shaders/triangle.d b/src/shaders/triangle.d new file mode 100644 index 0000000..56a8d10 --- /dev/null +++ b/src/shaders/triangle.d @@ -0,0 +1,545 @@ +module shaders.triangle; +import sg = sokol.gfx; +extern(C): + +/* + #version:1# (machine generated, don't edit!) + + Generated by sokol-shdc (https://github.com/floooh/sokol-tools) + + Cmdline: + sokol-shdc -i src/shaders/triangle.glsl -o src/shaders/triangle.d -l glsl430:metal_macos:hlsl4:glsl300es:wgsl -f sokol_d + + Overview: + ========= + Shader program: 'triangle': + Get shader desc: triangleShaderDesc(sg.queryBackend()); + Vertex shader: vs + Attributes: + ATTR_VS_POSITION => 0 + ATTR_VS_COLOR0 => 1 + Fragment shader: fs +*/ +enum ATTR_VS_POSITION = 0; +enum ATTR_VS_COLOR0 = 1; +/* + #version 430 + + layout(location = 0) in vec4 position; + layout(location = 0) out vec4 color; + layout(location = 1) in vec4 color0; + + void main() + { + gl_Position = position; + color = color0; + } + +*/ +__gshared char[194] VS_SOURCE_GLSL430 = [ + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x6c,0x61, + 0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, + 0x30,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20,0x70,0x6f,0x73,0x69,0x74, + 0x69,0x6f,0x6e,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61, + 0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65, + 0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74, + 0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x69, + 0x6e,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x0a, + 0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, + 0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x63,0x6f, + 0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x7d,0x0a, + 0x0a,0x00, +]; +/* + #version 430 + + layout(location = 0) out vec4 frag_color; + layout(location = 0) in vec4 color; + + void main() + { + frag_color = color; + } + +*/ +__gshared char[135] FS_SOURCE_GLSL430 = [ + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x6c,0x61, + 0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, + 0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x66,0x72,0x61,0x67, + 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c, + 0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e,0x20, + 0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x0a,0x76,0x6f,0x69, + 0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f, + 0x72,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +]; +/* + #version 300 es + + layout(location = 0) in vec4 position; + out vec4 color; + layout(location = 1) in vec4 color0; + + void main() + { + gl_Position = position; + color = color0; + } + +*/ +__gshared char[176] VS_SOURCE_GLSL300ES = [ + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x30,0x30,0x20,0x65,0x73,0x0a, + 0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e, + 0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20,0x70,0x6f, + 0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34, + 0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c, + 0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x69,0x6e,0x20, + 0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x0a,0x76,0x6f, + 0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x70,0x6f, + 0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x63,0x6f,0x6c,0x6f, + 0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, + +]; +/* + #version 300 es + precision mediump float; + precision highp int; + + layout(location = 0) out highp vec4 frag_color; + in highp vec4 color; + + void main() + { + frag_color = color; + } + +*/ +__gshared char[175] FS_SOURCE_GLSL300ES = [ + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x30,0x30,0x20,0x65,0x73,0x0a, + 0x70,0x72,0x65,0x63,0x69,0x73,0x69,0x6f,0x6e,0x20,0x6d,0x65,0x64,0x69,0x75,0x6d, + 0x70,0x20,0x66,0x6c,0x6f,0x61,0x74,0x3b,0x0a,0x70,0x72,0x65,0x63,0x69,0x73,0x69, + 0x6f,0x6e,0x20,0x68,0x69,0x67,0x68,0x70,0x20,0x69,0x6e,0x74,0x3b,0x0a,0x0a,0x6c, + 0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d, + 0x20,0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x68,0x69,0x67,0x68,0x70,0x20,0x76,0x65, + 0x63,0x34,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x69, + 0x6e,0x20,0x68,0x69,0x67,0x68,0x70,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c, + 0x6f,0x72,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29, + 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f, + 0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +]; +/* + static float4 gl_Position; + static float4 position; + static float4 color; + static float4 color0; + + struct SPIRV_Cross_Input + { + float4 position : TEXCOORD0; + float4 color0 : TEXCOORD1; + }; + + struct SPIRV_Cross_Output + { + float4 color : TEXCOORD0; + float4 gl_Position : SV_Position; + }; + + void vert_main() + { + gl_Position = position; + color = color0; + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + position = stage_input.position; + color0 = stage_input.color0; + vert_main(); + SPIRV_Cross_Output stage_output; + stage_output.gl_Position = gl_Position; + stage_output.color = color; + return stage_output; + } +*/ +__gshared char[645] VS_SOURCE_HLSL4 = [ + 0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c, + 0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69, + 0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f, + 0x6e,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x0a,0x73, + 0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73, + 0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x20,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3a,0x20, + 0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x20,0x3a,0x20,0x54, + 0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x31,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74, + 0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73, + 0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20,0x54,0x45,0x58, + 0x43,0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3a, + 0x20,0x53,0x56,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x7d,0x3b, + 0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x76,0x65,0x72,0x74,0x5f,0x6d,0x61,0x69,0x6e, + 0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69, + 0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c, + 0x6f,0x72,0x30,0x3b,0x0a,0x7d,0x0a,0x0a,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72, + 0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x28, + 0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75, + 0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, + 0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x70,0x6f,0x73,0x69, + 0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30, + 0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x63, + 0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x72,0x74,0x5f, + 0x6d,0x61,0x69,0x6e,0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x53,0x50,0x49,0x52, + 0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x73, + 0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x67,0x6c, + 0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x67,0x6c,0x5f,0x50, + 0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61, + 0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x63,0x6f,0x6c,0x6f,0x72,0x20, + 0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74, + 0x75,0x72,0x6e,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74, + 0x3b,0x0a,0x7d,0x0a,0x00, +]; +/* + static float4 frag_color; + static float4 color; + + struct SPIRV_Cross_Input + { + float4 color : TEXCOORD0; + }; + + struct SPIRV_Cross_Output + { + float4 frag_color : SV_Target0; + }; + + void frag_main() + { + frag_color = color; + } + + SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) + { + color = stage_input.color; + frag_main(); + SPIRV_Cross_Output stage_output; + stage_output.frag_color = frag_color; + return stage_output; + } +*/ +__gshared char[435] FS_SOURCE_HLSL4 = [ + 0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x66,0x72, + 0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x0a, + 0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f, + 0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20,0x54,0x45, + 0x58,0x43,0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72, + 0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f, + 0x4f,0x75,0x74,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a, + 0x20,0x53,0x56,0x5f,0x54,0x61,0x72,0x67,0x65,0x74,0x30,0x3b,0x0a,0x7d,0x3b,0x0a, + 0x0a,0x76,0x6f,0x69,0x64,0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61,0x69,0x6e,0x28, + 0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c, + 0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x7d,0x0a,0x0a,0x53, + 0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75, + 0x74,0x20,0x6d,0x61,0x69,0x6e,0x28,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f, + 0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69, + 0x6e,0x70,0x75,0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x63,0x6f,0x6c,0x6f, + 0x72,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e, + 0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f, + 0x6d,0x61,0x69,0x6e,0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x53,0x50,0x49,0x52, + 0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x73, + 0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x66,0x72, + 0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x72,0x61,0x67,0x5f, + 0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, + 0x6e,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a, + 0x7d,0x0a,0x00, +]; +/* + #include + #include + + using namespace metal; + + struct main0_out + { + float4 color [[user(locn0)]]; + float4 gl_Position [[position]]; + }; + + struct main0_in + { + float4 position [[attribute(0)]]; + float4 color0 [[attribute(1)]]; + }; + + vertex main0_out main0(main0_in in [[stage_in]]) + { + main0_out out = {}; + out.gl_Position = in.position; + out.color = in.color0; + return out; + } + +*/ +__gshared char[419] VS_SOURCE_METAL_MACOS = [ + 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, + 0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65, + 0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a, + 0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20, + 0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d, + 0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x5b,0x5b,0x75,0x73, + 0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74, + 0x69,0x6f,0x6e,0x20,0x5b,0x5b,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x5d,0x5d, + 0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69, + 0x6e,0x30,0x5f,0x69,0x6e,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x20,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x5b,0x5b,0x61,0x74, + 0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x28,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x20, + 0x5b,0x5b,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x28,0x31,0x29,0x5d,0x5d, + 0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x76,0x65,0x72,0x74,0x65,0x78,0x20,0x6d,0x61,0x69, + 0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x28,0x6d,0x61,0x69, + 0x6e,0x30,0x5f,0x69,0x6e,0x20,0x69,0x6e,0x20,0x5b,0x5b,0x73,0x74,0x61,0x67,0x65, + 0x5f,0x69,0x6e,0x5d,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x69, + 0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75,0x74,0x20,0x3d,0x20,0x7b,0x7d,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69, + 0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x70,0x6f,0x73,0x69,0x74,0x69, + 0x6f,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x63,0x6f,0x6c,0x6f, + 0x72,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d, + 0x0a,0x0a,0x00, +]; +/* + #include + #include + + using namespace metal; + + struct main0_out + { + float4 frag_color [[color(0)]]; + }; + + struct main0_in + { + float4 color [[user(locn0)]]; + }; + + fragment main0_out main0(main0_in in [[stage_in]]) + { + main0_out out = {}; + out.frag_color = in.color; + return out; + } + +*/ +__gshared char[315] FS_SOURCE_METAL_MACOS = [ + 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, + 0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65, + 0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a, + 0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20, + 0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d, + 0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72, + 0x20,0x5b,0x5b,0x63,0x6f,0x6c,0x6f,0x72,0x28,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x7d, + 0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f, + 0x69,0x6e,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20, + 0x63,0x6f,0x6c,0x6f,0x72,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63, + 0x6e,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x66,0x72,0x61,0x67,0x6d, + 0x65,0x6e,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6d,0x61, + 0x69,0x6e,0x30,0x28,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x20,0x69,0x6e,0x20, + 0x5b,0x5b,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x5d,0x5d,0x29,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75, + 0x74,0x20,0x3d,0x20,0x7b,0x7d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e, + 0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x69,0x6e,0x2e, + 0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, + 0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +]; +/* + diagnostic(off, derivative_uniformity); + + var position_1 : vec4f; + + var color : vec4f; + + var color0 : vec4f; + + var gl_Position : vec4f; + + fn main_1() { + let x_18 : vec4f = position_1; + gl_Position = x_18; + let x_23 : vec4f = color0; + color = x_23; + return; + } + + struct main_out { + @builtin(position) + gl_Position : vec4f, + @location(0) + color_1 : vec4f, + } + + @vertex + fn main(@location(0) position_1_param : vec4f, @location(1) color0_param : vec4f) -> main_out { + position_1 = position_1_param; + color0 = color0_param; + main_1(); + return main_out(gl_Position, color); + } + +*/ +__gshared char[612] VS_SOURCE_WGSL = [ + 0x64,0x69,0x61,0x67,0x6e,0x6f,0x73,0x74,0x69,0x63,0x28,0x6f,0x66,0x66,0x2c,0x20, + 0x64,0x65,0x72,0x69,0x76,0x61,0x74,0x69,0x76,0x65,0x5f,0x75,0x6e,0x69,0x66,0x6f, + 0x72,0x6d,0x69,0x74,0x79,0x29,0x3b,0x0a,0x0a,0x76,0x61,0x72,0x3c,0x70,0x72,0x69, + 0x76,0x61,0x74,0x65,0x3e,0x20,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x5f,0x31, + 0x20,0x3a,0x20,0x76,0x65,0x63,0x34,0x66,0x3b,0x0a,0x0a,0x76,0x61,0x72,0x3c,0x70, + 0x72,0x69,0x76,0x61,0x74,0x65,0x3e,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20, + 0x76,0x65,0x63,0x34,0x66,0x3b,0x0a,0x0a,0x76,0x61,0x72,0x3c,0x70,0x72,0x69,0x76, + 0x61,0x74,0x65,0x3e,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x20,0x3a,0x20,0x76,0x65, + 0x63,0x34,0x66,0x3b,0x0a,0x0a,0x76,0x61,0x72,0x3c,0x70,0x72,0x69,0x76,0x61,0x74, + 0x65,0x3e,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3a, + 0x20,0x76,0x65,0x63,0x34,0x66,0x3b,0x0a,0x0a,0x66,0x6e,0x20,0x6d,0x61,0x69,0x6e, + 0x5f,0x31,0x28,0x29,0x20,0x7b,0x0a,0x20,0x20,0x6c,0x65,0x74,0x20,0x78,0x5f,0x31, + 0x38,0x20,0x3a,0x20,0x76,0x65,0x63,0x34,0x66,0x20,0x3d,0x20,0x70,0x6f,0x73,0x69, + 0x74,0x69,0x6f,0x6e,0x5f,0x31,0x3b,0x0a,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73, + 0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x78,0x5f,0x31,0x38,0x3b,0x0a,0x20,0x20, + 0x6c,0x65,0x74,0x20,0x78,0x5f,0x32,0x33,0x20,0x3a,0x20,0x76,0x65,0x63,0x34,0x66, + 0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x20,0x20,0x63,0x6f,0x6c, + 0x6f,0x72,0x20,0x3d,0x20,0x78,0x5f,0x32,0x33,0x3b,0x0a,0x20,0x20,0x72,0x65,0x74, + 0x75,0x72,0x6e,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d, + 0x61,0x69,0x6e,0x5f,0x6f,0x75,0x74,0x20,0x7b,0x0a,0x20,0x20,0x40,0x62,0x75,0x69, + 0x6c,0x74,0x69,0x6e,0x28,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x29,0x0a,0x20, + 0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3a,0x20,0x76, + 0x65,0x63,0x34,0x66,0x2c,0x0a,0x20,0x20,0x40,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f, + 0x6e,0x28,0x30,0x29,0x0a,0x20,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x5f,0x31,0x20,0x3a, + 0x20,0x76,0x65,0x63,0x34,0x66,0x2c,0x0a,0x7d,0x0a,0x0a,0x40,0x76,0x65,0x72,0x74, + 0x65,0x78,0x0a,0x66,0x6e,0x20,0x6d,0x61,0x69,0x6e,0x28,0x40,0x6c,0x6f,0x63,0x61, + 0x74,0x69,0x6f,0x6e,0x28,0x30,0x29,0x20,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e, + 0x5f,0x31,0x5f,0x70,0x61,0x72,0x61,0x6d,0x20,0x3a,0x20,0x76,0x65,0x63,0x34,0x66, + 0x2c,0x20,0x40,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x28,0x31,0x29,0x20,0x63, + 0x6f,0x6c,0x6f,0x72,0x30,0x5f,0x70,0x61,0x72,0x61,0x6d,0x20,0x3a,0x20,0x76,0x65, + 0x63,0x34,0x66,0x29,0x20,0x2d,0x3e,0x20,0x6d,0x61,0x69,0x6e,0x5f,0x6f,0x75,0x74, + 0x20,0x7b,0x0a,0x20,0x20,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x5f,0x31,0x20, + 0x3d,0x20,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x5f,0x31,0x5f,0x70,0x61,0x72, + 0x61,0x6d,0x3b,0x0a,0x20,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x20,0x3d,0x20,0x63, + 0x6f,0x6c,0x6f,0x72,0x30,0x5f,0x70,0x61,0x72,0x61,0x6d,0x3b,0x0a,0x20,0x20,0x6d, + 0x61,0x69,0x6e,0x5f,0x31,0x28,0x29,0x3b,0x0a,0x20,0x20,0x72,0x65,0x74,0x75,0x72, + 0x6e,0x20,0x6d,0x61,0x69,0x6e,0x5f,0x6f,0x75,0x74,0x28,0x67,0x6c,0x5f,0x50,0x6f, + 0x73,0x69,0x74,0x69,0x6f,0x6e,0x2c,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x29,0x3b,0x0a, + 0x7d,0x0a,0x0a,0x00, +]; +/* + diagnostic(off, derivative_uniformity); + + var frag_color : vec4f; + + var color : vec4f; + + fn main_1() { + let x_12 : vec4f = color; + frag_color = x_12; + return; + } + + struct main_out { + @location(0) + frag_color_1 : vec4f, + } + + @fragment + fn main(@location(0) color_param : vec4f) -> main_out { + color = color_param; + main_1(); + return main_out(frag_color); + } + +*/ +__gshared char[376] FS_SOURCE_WGSL = [ + 0x64,0x69,0x61,0x67,0x6e,0x6f,0x73,0x74,0x69,0x63,0x28,0x6f,0x66,0x66,0x2c,0x20, + 0x64,0x65,0x72,0x69,0x76,0x61,0x74,0x69,0x76,0x65,0x5f,0x75,0x6e,0x69,0x66,0x6f, + 0x72,0x6d,0x69,0x74,0x79,0x29,0x3b,0x0a,0x0a,0x76,0x61,0x72,0x3c,0x70,0x72,0x69, + 0x76,0x61,0x74,0x65,0x3e,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72, + 0x20,0x3a,0x20,0x76,0x65,0x63,0x34,0x66,0x3b,0x0a,0x0a,0x76,0x61,0x72,0x3c,0x70, + 0x72,0x69,0x76,0x61,0x74,0x65,0x3e,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20, + 0x76,0x65,0x63,0x34,0x66,0x3b,0x0a,0x0a,0x66,0x6e,0x20,0x6d,0x61,0x69,0x6e,0x5f, + 0x31,0x28,0x29,0x20,0x7b,0x0a,0x20,0x20,0x6c,0x65,0x74,0x20,0x78,0x5f,0x31,0x32, + 0x20,0x3a,0x20,0x76,0x65,0x63,0x34,0x66,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72, + 0x3b,0x0a,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d, + 0x20,0x78,0x5f,0x31,0x32,0x3b,0x0a,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b, + 0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x5f, + 0x6f,0x75,0x74,0x20,0x7b,0x0a,0x20,0x20,0x40,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f, + 0x6e,0x28,0x30,0x29,0x0a,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f, + 0x72,0x5f,0x31,0x20,0x3a,0x20,0x76,0x65,0x63,0x34,0x66,0x2c,0x0a,0x7d,0x0a,0x0a, + 0x40,0x66,0x72,0x61,0x67,0x6d,0x65,0x6e,0x74,0x0a,0x66,0x6e,0x20,0x6d,0x61,0x69, + 0x6e,0x28,0x40,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x28,0x30,0x29,0x20,0x63, + 0x6f,0x6c,0x6f,0x72,0x5f,0x70,0x61,0x72,0x61,0x6d,0x20,0x3a,0x20,0x76,0x65,0x63, + 0x34,0x66,0x29,0x20,0x2d,0x3e,0x20,0x6d,0x61,0x69,0x6e,0x5f,0x6f,0x75,0x74,0x20, + 0x7b,0x0a,0x20,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f, + 0x72,0x5f,0x70,0x61,0x72,0x61,0x6d,0x3b,0x0a,0x20,0x20,0x6d,0x61,0x69,0x6e,0x5f, + 0x31,0x28,0x29,0x3b,0x0a,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6d,0x61, + 0x69,0x6e,0x5f,0x6f,0x75,0x74,0x28,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f, + 0x72,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +]; +sg.ShaderDesc triangleShaderDesc(sg.Backend backend) @trusted @nogc nothrow { + sg.ShaderDesc desc; + desc.label = "triangle_shader"; + switch (backend) { + case sg.Backend.Glcore: + desc.attrs[0].name = "position"; + desc.attrs[1].name = "color0"; + desc.vs.source = &VS_SOURCE_GLSL430[0]; + desc.vs.entry = "main"; + desc.fs.source = &FS_SOURCE_GLSL430[0]; + desc.fs.entry = "main"; + break; + case sg.Backend.Gles3: + desc.attrs[0].name = "position"; + desc.attrs[1].name = "color0"; + desc.vs.source = &VS_SOURCE_GLSL300ES[0]; + desc.vs.entry = "main"; + desc.fs.source = &FS_SOURCE_GLSL300ES[0]; + desc.fs.entry = "main"; + break; + case sg.Backend.D3d11: + desc.attrs[0].sem_name = "TEXCOORD"; + desc.attrs[0].sem_index = 0; + desc.attrs[1].sem_name = "TEXCOORD"; + desc.attrs[1].sem_index = 1; + desc.vs.source = &VS_SOURCE_HLSL4[0]; + desc.vs.d3d11_target = "vs_4_0"; + desc.vs.entry = "main"; + desc.fs.source = &FS_SOURCE_HLSL4[0]; + desc.fs.d3d11_target = "ps_4_0"; + desc.fs.entry = "main"; + break; + case sg.Backend.Metal_macos: + desc.vs.source = &VS_SOURCE_METAL_MACOS[0]; + desc.vs.entry = "main0"; + desc.fs.source = &FS_SOURCE_METAL_MACOS[0]; + desc.fs.entry = "main0"; + break; + case sg.Backend.Wgpu: + desc.vs.source = &VS_SOURCE_WGSL[0]; + desc.vs.entry = "main"; + desc.fs.source = &FS_SOURCE_WGSL[0]; + desc.fs.entry = "main"; + break; + default: break; + } + return desc; +} diff --git a/src/shaders/triangle.glsl b/src/shaders/triangle.glsl new file mode 100644 index 0000000..0c31a1e --- /dev/null +++ b/src/shaders/triangle.glsl @@ -0,0 +1,22 @@ +@vs vs +in vec4 position; +in vec4 color0; + +out vec4 color; + +void main() { + gl_Position = position; + color = color0; +} +@end + +@fs fs +in vec4 color; +out vec4 frag_color; + +void main() { + frag_color = color; +} +@end + +@program triangle vs fs diff --git a/src/sokol/app.d b/src/sokol/app.d index dc5d61c..a8dbc34 100644 --- a/src/sokol/app.d +++ b/src/sokol/app.d @@ -329,7 +329,7 @@ enum LogItem { } extern(C) struct Logger { - extern(C) void function(scope const(char)*, uint, uint, scope const(char)*, uint, scope const(char)*, void*) func = null; + extern(C) void function(const(char)*, uint, uint, const(char)*, uint, const(char)*, void*) func = null; void* user_data = null; } extern(C) @@ -525,39 +525,39 @@ extern(C) double sapp_frame_duration() @system @nogc nothrow; double frameDuration() @trusted @nogc nothrow { return sapp_frame_duration(); } -extern(C) void sapp_set_clipboard_string(scope const(char)*) @system @nogc nothrow; +extern(C) void sapp_set_clipboard_string(const(char)*) @system @nogc nothrow; void setClipboardString(scope const(char)* str) @trusted @nogc nothrow { sapp_set_clipboard_string(str); } -extern(C) scope const(char)* sapp_get_clipboard_string() @system @nogc nothrow; +extern(C) const(char)* sapp_get_clipboard_string() @system @nogc nothrow; scope const(char)* getClipboardString() @trusted @nogc nothrow { return sapp_get_clipboard_string(); } -extern(C) void sapp_set_window_title(scope const(char)*) @system @nogc nothrow; +extern(C) void sapp_set_window_title(const(char)*) @system @nogc nothrow; void setWindowTitle(scope const(char)* str) @trusted @nogc nothrow { sapp_set_window_title(str); } extern(C) void sapp_set_icon(const IconDesc *) @system @nogc nothrow; -void setIcon(ref IconDesc icon_desc) @trusted @nogc nothrow { +void setIcon(scope ref IconDesc icon_desc) @trusted @nogc nothrow { sapp_set_icon(&icon_desc); } extern(C) int sapp_get_num_dropped_files() @system @nogc nothrow; int getNumDroppedFiles() @trusted @nogc nothrow { return sapp_get_num_dropped_files(); } -extern(C) scope const(char)* sapp_get_dropped_file_path(int) @system @nogc nothrow; +extern(C) const(char)* sapp_get_dropped_file_path(int) @system @nogc nothrow; scope const(char)* getDroppedFilePath(int index) @trusted @nogc nothrow { return sapp_get_dropped_file_path(index); } extern(C) void sapp_run(const Desc *) @system @nogc nothrow; -void run(ref Desc desc) @trusted @nogc nothrow { +void run(scope ref Desc desc) @trusted @nogc nothrow { sapp_run(&desc); } -extern(C) scope const(void)* sapp_egl_get_display() @system @nogc nothrow; +extern(C) const(void)* sapp_egl_get_display() @system @nogc nothrow; scope const(void)* eglGetDisplay() @trusted @nogc nothrow { return sapp_egl_get_display(); } -extern(C) scope const(void)* sapp_egl_get_context() @system @nogc nothrow; +extern(C) const(void)* sapp_egl_get_context() @system @nogc nothrow; scope const(void)* eglGetContext() @trusted @nogc nothrow { return sapp_egl_get_context(); } @@ -570,74 +570,74 @@ uint html5GetDroppedFileSize(int index) @trusted @nogc nothrow { return sapp_html5_get_dropped_file_size(index); } extern(C) void sapp_html5_fetch_dropped_file(const Html5FetchRequest *) @system @nogc nothrow; -void html5FetchDroppedFile(ref Html5FetchRequest request) @trusted @nogc nothrow { +void html5FetchDroppedFile(scope ref Html5FetchRequest request) @trusted @nogc nothrow { sapp_html5_fetch_dropped_file(&request); } -extern(C) scope const(void)* sapp_metal_get_device() @system @nogc nothrow; +extern(C) const(void)* sapp_metal_get_device() @system @nogc nothrow; scope const(void)* metalGetDevice() @trusted @nogc nothrow { return sapp_metal_get_device(); } -extern(C) scope const(void)* sapp_metal_get_current_drawable() @system @nogc nothrow; +extern(C) const(void)* sapp_metal_get_current_drawable() @system @nogc nothrow; scope const(void)* metalGetCurrentDrawable() @trusted @nogc nothrow { return sapp_metal_get_current_drawable(); } -extern(C) scope const(void)* sapp_metal_get_depth_stencil_texture() @system @nogc nothrow; +extern(C) const(void)* sapp_metal_get_depth_stencil_texture() @system @nogc nothrow; scope const(void)* metalGetDepthStencilTexture() @trusted @nogc nothrow { return sapp_metal_get_depth_stencil_texture(); } -extern(C) scope const(void)* sapp_metal_get_msaa_color_texture() @system @nogc nothrow; +extern(C) const(void)* sapp_metal_get_msaa_color_texture() @system @nogc nothrow; scope const(void)* metalGetMsaaColorTexture() @trusted @nogc nothrow { return sapp_metal_get_msaa_color_texture(); } -extern(C) scope const(void)* sapp_macos_get_window() @system @nogc nothrow; +extern(C) const(void)* sapp_macos_get_window() @system @nogc nothrow; scope const(void)* macosGetWindow() @trusted @nogc nothrow { return sapp_macos_get_window(); } -extern(C) scope const(void)* sapp_ios_get_window() @system @nogc nothrow; +extern(C) const(void)* sapp_ios_get_window() @system @nogc nothrow; scope const(void)* iosGetWindow() @trusted @nogc nothrow { return sapp_ios_get_window(); } -extern(C) scope const(void)* sapp_d3d11_get_device() @system @nogc nothrow; +extern(C) const(void)* sapp_d3d11_get_device() @system @nogc nothrow; scope const(void)* d3d11GetDevice() @trusted @nogc nothrow { return sapp_d3d11_get_device(); } -extern(C) scope const(void)* sapp_d3d11_get_device_context() @system @nogc nothrow; +extern(C) const(void)* sapp_d3d11_get_device_context() @system @nogc nothrow; scope const(void)* d3d11GetDeviceContext() @trusted @nogc nothrow { return sapp_d3d11_get_device_context(); } -extern(C) scope const(void)* sapp_d3d11_get_swap_chain() @system @nogc nothrow; +extern(C) const(void)* sapp_d3d11_get_swap_chain() @system @nogc nothrow; scope const(void)* d3d11GetSwapChain() @trusted @nogc nothrow { return sapp_d3d11_get_swap_chain(); } -extern(C) scope const(void)* sapp_d3d11_get_render_view() @system @nogc nothrow; +extern(C) const(void)* sapp_d3d11_get_render_view() @system @nogc nothrow; scope const(void)* d3d11GetRenderView() @trusted @nogc nothrow { return sapp_d3d11_get_render_view(); } -extern(C) scope const(void)* sapp_d3d11_get_resolve_view() @system @nogc nothrow; +extern(C) const(void)* sapp_d3d11_get_resolve_view() @system @nogc nothrow; scope const(void)* d3d11GetResolveView() @trusted @nogc nothrow { return sapp_d3d11_get_resolve_view(); } -extern(C) scope const(void)* sapp_d3d11_get_depth_stencil_view() @system @nogc nothrow; +extern(C) const(void)* sapp_d3d11_get_depth_stencil_view() @system @nogc nothrow; scope const(void)* d3d11GetDepthStencilView() @trusted @nogc nothrow { return sapp_d3d11_get_depth_stencil_view(); } -extern(C) scope const(void)* sapp_win32_get_hwnd() @system @nogc nothrow; +extern(C) const(void)* sapp_win32_get_hwnd() @system @nogc nothrow; scope const(void)* win32GetHwnd() @trusted @nogc nothrow { return sapp_win32_get_hwnd(); } -extern(C) scope const(void)* sapp_wgpu_get_device() @system @nogc nothrow; +extern(C) const(void)* sapp_wgpu_get_device() @system @nogc nothrow; scope const(void)* wgpuGetDevice() @trusted @nogc nothrow { return sapp_wgpu_get_device(); } -extern(C) scope const(void)* sapp_wgpu_get_render_view() @system @nogc nothrow; +extern(C) const(void)* sapp_wgpu_get_render_view() @system @nogc nothrow; scope const(void)* wgpuGetRenderView() @trusted @nogc nothrow { return sapp_wgpu_get_render_view(); } -extern(C) scope const(void)* sapp_wgpu_get_resolve_view() @system @nogc nothrow; +extern(C) const(void)* sapp_wgpu_get_resolve_view() @system @nogc nothrow; scope const(void)* wgpuGetResolveView() @trusted @nogc nothrow { return sapp_wgpu_get_resolve_view(); } -extern(C) scope const(void)* sapp_wgpu_get_depth_stencil_view() @system @nogc nothrow; +extern(C) const(void)* sapp_wgpu_get_depth_stencil_view() @system @nogc nothrow; scope const(void)* wgpuGetDepthStencilView() @trusted @nogc nothrow { return sapp_wgpu_get_depth_stencil_view(); } @@ -645,7 +645,15 @@ extern(C) uint sapp_gl_get_framebuffer() @system @nogc nothrow; uint glGetFramebuffer() @trusted @nogc nothrow { return sapp_gl_get_framebuffer(); } -extern(C) scope const(void)* sapp_android_get_native_activity() @system @nogc nothrow; +extern(C) int sapp_gl_get_major_version() @system @nogc nothrow; +int glGetMajorVersion() @trusted @nogc nothrow { + return sapp_gl_get_major_version(); +} +extern(C) int sapp_gl_get_minor_version() @system @nogc nothrow; +int glGetMinorVersion() @trusted @nogc nothrow { + return sapp_gl_get_minor_version(); +} +extern(C) const(void)* sapp_android_get_native_activity() @system @nogc nothrow; scope const(void)* androidGetNativeActivity() @trusted @nogc nothrow { return sapp_android_get_native_activity(); } diff --git a/src/sokol/audio.d b/src/sokol/audio.d index caf03da..9a62ab5 100644 --- a/src/sokol/audio.d +++ b/src/sokol/audio.d @@ -42,7 +42,7 @@ enum LogItem { } extern(C) struct Logger { - extern(C) void function(scope const(char)*, uint, uint, scope const(char)*, uint, scope const(char)*, void*) func = null; + extern(C) void function(const(char)*, uint, uint, const(char)*, uint, const(char)*, void*) func = null; void* user_data = null; } extern(C) @@ -65,7 +65,7 @@ struct Desc { Logger logger; } extern(C) void saudio_setup(const Desc *) @system @nogc nothrow; -void setup(ref Desc desc) @trusted @nogc nothrow { +void setup(scope ref Desc desc) @trusted @nogc nothrow { saudio_setup(&desc); } extern(C) void saudio_shutdown() @system @nogc nothrow; @@ -105,6 +105,6 @@ int expect() @trusted @nogc nothrow { return saudio_expect(); } extern(C) int saudio_push(const float *, int) @system @nogc nothrow; -int push(const float * frames, int num_frames) @trusted @nogc nothrow { +int push(scope const float * frames, int num_frames) @trusted @nogc nothrow { return saudio_push(frames, num_frames); } diff --git a/src/sokol/c/sokol_app.h b/src/sokol/c/sokol_app.h index f5db5b7..515796a 100644 --- a/src/sokol/c/sokol_app.h +++ b/src/sokol/c/sokol_app.h @@ -18,11 +18,12 @@ the backend selected for sokol_gfx.h if both are used in the same project): - #define SOKOL_GLCORE33 + #define SOKOL_GLCORE #define SOKOL_GLES3 #define SOKOL_D3D11 #define SOKOL_METAL #define SOKOL_WGPU + #define SOKOL_NOAPI Optionally provide the following defines with your own implementations: @@ -47,7 +48,7 @@ On Windows, SOKOL_DLL will define SOKOL_APP_API_DECL as __declspec(dllexport) or __declspec(dllimport) as needed. - On Linux, SOKOL_GLCORE33 can use either GLX or EGL. + On Linux, SOKOL_GLCORE can use either GLX or EGL. GLX is default, set SOKOL_FORCE_EGL to override. For example code, see https://github.com/floooh/sokol-samples/tree/master/sapp @@ -87,7 +88,7 @@ - makes the rendered frame visible - provides keyboard-, mouse- and low-level touch-events - platforms: MacOS, iOS, HTML5, Win32, Linux/RaspberryPi, Android - - 3D-APIs: Metal, D3D11, GL3.2, GLES3, WebGL, WebGL2 + - 3D-APIs: Metal, D3D11, GL3.2, GLES3, WebGL, WebGL2, NOAPI FEATURE/PLATFORM MATRIX ======================= @@ -97,6 +98,7 @@ gles3/webgl2 | --- | --- | YES(2)| YES | YES | YES metal | --- | YES | --- | YES | --- | --- d3d11 | YES | --- | --- | --- | --- | --- + noapi | YES | TODO | TODO | --- | TODO | --- KEY_DOWN | YES | YES | YES | SOME | TODO | YES KEY_UP | YES | YES | YES | SOME | TODO | YES CHAR | YES | YES | YES | YES | TODO | YES @@ -313,10 +315,15 @@ objects and values required for rendering. If sokol_app.h is not compiled with SOKOL_WGPU, these functions return null. - const uint32_t sapp_gl_get_framebuffer(void) + uint32_t sapp_gl_get_framebuffer(void) This returns the 'default framebuffer' of the GL context. Typically this will be zero. + int sapp_gl_get_major_version(void) + int sapp_gl_get_minor_version(void) + Returns the major and minor version of the GL context + (only for SOKOL_GLCORE, all other backends return zero here, including SOKOL_GLES3) + const void* sapp_android_get_native_activity(void); On Android, get the native activity ANativeActivity pointer, otherwise a null pointer. @@ -1892,6 +1899,10 @@ SOKOL_APP_API_DECL const void* sapp_wgpu_get_depth_stencil_view(void); /* GL: get framebuffer object */ SOKOL_APP_API_DECL uint32_t sapp_gl_get_framebuffer(void); +/* GL: get major version (only valid for desktop GL) */ +SOKOL_APP_API_DECL int sapp_gl_get_major_version(void); +/* GL: get minor version (only valid for desktop GL) */ +SOKOL_APP_API_DECL int sapp_gl_get_minor_version(void); /* Android: get native activity handle */ SOKOL_APP_API_DECL const void* sapp_android_get_native_activity(void); @@ -1959,8 +1970,8 @@ inline void sapp_run(const sapp_desc& desc) { return sapp_run(&desc); } #if defined(TARGET_OS_IPHONE) && !TARGET_OS_IPHONE /* MacOS */ #define _SAPP_MACOS (1) - #if !defined(SOKOL_METAL) && !defined(SOKOL_GLCORE33) - #error("sokol_app.h: unknown 3D API selected for MacOS, must be SOKOL_METAL or SOKOL_GLCORE33") + #if !defined(SOKOL_METAL) && !defined(SOKOL_GLCORE) + #error("sokol_app.h: unknown 3D API selected for MacOS, must be SOKOL_METAL or SOKOL_GLCORE") #endif #else /* iOS or iOS Simulator */ @@ -1978,8 +1989,8 @@ inline void sapp_run(const sapp_desc& desc) { return sapp_run(&desc); } #elif defined(_WIN32) /* Windows (D3D11 or GL) */ #define _SAPP_WIN32 (1) - #if !defined(SOKOL_D3D11) && !defined(SOKOL_GLCORE33) - #error("sokol_app.h: unknown 3D API selected for Win32, must be SOKOL_D3D11 or SOKOL_GLCORE33") + #if !defined(SOKOL_D3D11) && !defined(SOKOL_GLCORE) && !defined(SOKOL_NOAPI) + #error("sokol_app.h: unknown 3D API selected for Win32, must be SOKOL_D3D11, SOKOL_GLCORE or SOKOL_NOAPI") #endif #elif defined(__ANDROID__) /* Android */ @@ -1993,7 +2004,7 @@ inline void sapp_run(const sapp_desc& desc) { return sapp_run(&desc); } #elif defined(__linux__) || defined(__unix__) /* Linux */ #define _SAPP_LINUX (1) - #if defined(SOKOL_GLCORE33) + #if defined(SOKOL_GLCORE) #if !defined(SOKOL_FORCE_EGL) #define _SAPP_GLX (1) #endif @@ -2003,13 +2014,13 @@ inline void sapp_run(const sapp_desc& desc) { return sapp_run(&desc); } #include #include #else - #error("sokol_app.h: unknown 3D API selected for Linux, must be SOKOL_GLCORE33, SOKOL_GLES3") + #error("sokol_app.h: unknown 3D API selected for Linux, must be SOKOL_GLCORE, SOKOL_GLES3") #endif #else #error "sokol_app.h: Unknown platform" #endif -#if defined(SOKOL_GLCORE33) || defined(SOKOL_GLES3) +#if defined(SOKOL_GLCORE) || defined(SOKOL_GLES3) #define _SAPP_ANY_GL (1) #endif @@ -2399,11 +2410,11 @@ _SOKOL_PRIVATE double _sapp_timing_get_avg(_sapp_timing_t* t) { #if defined(SOKOL_METAL) @interface _sapp_macos_view : MTKView @end -#elif defined(SOKOL_GLCORE33) +#elif defined(SOKOL_GLCORE) @interface _sapp_macos_view : NSOpenGLView - (void)timerFired:(id)sender; @end -#endif // SOKOL_GLCORE33 +#endif // SOKOL_GLCORE typedef struct { uint32_t flags_changed_store; @@ -2545,7 +2556,7 @@ typedef struct { uint8_t raw_input_data[256]; } _sapp_win32_t; -#if defined(SOKOL_GLCORE33) +#if defined(SOKOL_GLCORE) #define WGL_NUMBER_PIXEL_FORMATS_ARB 0x2000 #define WGL_SUPPORT_OPENGL_ARB 0x2010 #define WGL_DRAW_TO_WINDOW_ARB 0x2001 @@ -2605,7 +2616,7 @@ typedef struct { HWND msg_hwnd; HDC msg_dc; } _sapp_wgl_t; -#endif // SOKOL_GLCORE33 +#endif // SOKOL_GLCORE #endif // _SAPP_WIN32 @@ -2876,7 +2887,7 @@ typedef struct { _sapp_win32_t win32; #if defined(SOKOL_D3D11) _sapp_d3d11_t d3d11; - #elif defined(SOKOL_GLCORE33) + #elif defined(SOKOL_GLCORE) _sapp_wgl_t wgl; #endif #elif defined(_SAPP_ANDROID) @@ -3085,8 +3096,13 @@ _SOKOL_PRIVATE sapp_desc _sapp_desc_defaults(const sapp_desc* desc) { // (or expressed differently: zero is a valid value for gl_minor_version // and can't be used to indicate 'default') if (0 == res.gl_major_version) { - res.gl_major_version = 3; - res.gl_minor_version = 2; + #if defined(_SAPP_APPLE) + res.gl_major_version = 4; + res.gl_minor_version = 1; + #else + res.gl_major_version = 4; + res.gl_minor_version = 3; + #endif } res.html5_canvas_name = _sapp_def(res.html5_canvas_name, "canvas"); res.clipboard_size = _sapp_def(res.clipboard_size, 8192); @@ -3650,7 +3666,7 @@ _SOKOL_PRIVATE void _sapp_macos_update_dimensions(void) { const int cur_fb_height = (int)roundf(fb_size.height); const bool dim_changed = (_sapp.framebuffer_width != cur_fb_width) || (_sapp.framebuffer_height != cur_fb_height); - #elif defined(SOKOL_GLCORE33) + #elif defined(SOKOL_GLCORE) const int cur_fb_width = (int)roundf(bounds.size.width * _sapp.dpi_scale); const int cur_fb_height = (int)roundf(bounds.size.height * _sapp.dpi_scale); const bool dim_changed = (_sapp.framebuffer_width != cur_fb_width) || @@ -3892,7 +3908,7 @@ _SOKOL_PRIVATE void _sapp_macos_frame(void) { _sapp.macos.window.contentView = _sapp.macos.view; [_sapp.macos.window makeFirstResponder:_sapp.macos.view]; _sapp.macos.view.layer.magnificationFilter = kCAFilterNearest; - #elif defined(SOKOL_GLCORE33) + #elif defined(SOKOL_GLCORE) NSOpenGLPixelFormatAttribute attrs[32]; int i = 0; attrs[i++] = NSOpenGLPFAAccelerated; @@ -4124,7 +4140,7 @@ _SOKOL_PRIVATE void _sapp_macos_frame(void) { @end @implementation _sapp_macos_view -#if defined(SOKOL_GLCORE33) +#if defined(SOKOL_GLCORE) - (void)timerFired:(id)sender { _SOKOL_UNUSED(sender); [self setNeedsDisplay:YES]; @@ -4224,7 +4240,7 @@ _SOKOL_PRIVATE void _sapp_macos_poll_input_events(void) { // helper function to make GL context active static void _sapp_gl_make_current(void) { - #if defined(SOKOL_GLCORE33) + #if defined(SOKOL_GLCORE) [[_sapp.macos.view openGLContext] makeCurrentContext]; #endif } @@ -5945,7 +5961,7 @@ int main(int argc, char* argv[]) { // ██████ ███████ ██ ██ ███████ ███████ ██ ███████ ██ ██ ███████ // // >>gl helpers -#if defined(SOKOL_GLCORE33) +#if defined(SOKOL_GLCORE) typedef struct { int red_bits; int green_bits; @@ -6596,7 +6612,7 @@ _SOKOL_PRIVATE void _sapp_d3d11_present(bool do_not_wait) { #endif /* SOKOL_D3D11 */ -#if defined(SOKOL_GLCORE33) +#if defined(SOKOL_GLCORE) _SOKOL_PRIVATE void _sapp_wgl_init(void) { _sapp.wgl.opengl32 = LoadLibraryA("opengl32.dll"); if (!_sapp.wgl.opengl32) { @@ -6894,7 +6910,7 @@ _SOKOL_PRIVATE void _sapp_wgl_swap_buffers(void) { /* FIXME: DwmIsCompositionEnabled? (see GLFW) */ SwapBuffers(_sapp.win32.dc); } -#endif /* SOKOL_GLCORE33 */ +#endif /* SOKOL_GLCORE */ _SOKOL_PRIVATE bool _sapp_win32_wide_to_utf8(const wchar_t* src, char* dst, int dst_num_bytes) { SOKOL_ASSERT(src && dst && (dst_num_bytes > 1)); @@ -7311,7 +7327,10 @@ _SOKOL_PRIVATE void _sapp_win32_timing_measure(void) { // fallback if swap model isn't "flip-discard" or GetFrameStatistics failed for another reason _sapp_timing_measure(&_sapp.timing); #endif - #if defined(SOKOL_GLCORE33) + #if defined(SOKOL_GLCORE) + _sapp_timing_measure(&_sapp.timing); + #endif + #if defined(SOKOL_NOAPI) _sapp_timing_measure(&_sapp.timing); #endif } @@ -7513,7 +7532,7 @@ _SOKOL_PRIVATE LRESULT CALLBACK _sapp_win32_wndproc(HWND hWnd, UINT uMsg, WPARAM // present with DXGI_PRESENT_DO_NOT_WAIT _sapp_d3d11_present(true); #endif - #if defined(SOKOL_GLCORE33) + #if defined(SOKOL_GLCORE) _sapp_wgl_swap_buffers(); #endif /* NOTE: resizing the swap-chain during resize leads to a substantial @@ -7926,7 +7945,7 @@ _SOKOL_PRIVATE void _sapp_win32_run(const sapp_desc* desc) { _sapp_d3d11_create_device_and_swapchain(); _sapp_d3d11_create_default_render_target(); #endif - #if defined(SOKOL_GLCORE33) + #if defined(SOKOL_GLCORE) _sapp_wgl_init(); _sapp_wgl_load_extensions(); _sapp_wgl_create_context(); @@ -7954,7 +7973,7 @@ _SOKOL_PRIVATE void _sapp_win32_run(const sapp_desc* desc) { Sleep((DWORD)(16 * _sapp.swap_interval)); } #endif - #if defined(SOKOL_GLCORE33) + #if defined(SOKOL_GLCORE) _sapp_wgl_swap_buffers(); #endif /* check for window resized, this cannot happen in WM_SIZE as it explodes memory usage */ @@ -10947,7 +10966,7 @@ _SOKOL_PRIVATE void _sapp_x11_process_event(XEvent* event) { #if !defined(_SAPP_GLX) _SOKOL_PRIVATE void _sapp_egl_init(void) { -#if defined(SOKOL_GLCORE33) +#if defined(SOKOL_GLCORE) if (!eglBindAPI(EGL_OPENGL_API)) { _SAPP_PANIC(LINUX_EGL_BIND_OPENGL_API_FAILED); } @@ -10971,7 +10990,7 @@ _SOKOL_PRIVATE void _sapp_egl_init(void) { EGLint alpha_size = _sapp.desc.alpha ? 8 : 0; const EGLint config_attrs[] = { EGL_SURFACE_TYPE, EGL_WINDOW_BIT, - #if defined(SOKOL_GLCORE33) + #if defined(SOKOL_GLCORE) EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT, #elif defined(SOKOL_GLES3) EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT, @@ -11034,7 +11053,7 @@ _SOKOL_PRIVATE void _sapp_egl_init(void) { } EGLint ctx_attrs[] = { - #if defined(SOKOL_GLCORE33) + #if defined(SOKOL_GLCORE) EGL_CONTEXT_MAJOR_VERSION, _sapp.desc.gl_major_version, EGL_CONTEXT_MINOR_VERSION, _sapp.desc.gl_minor_version, EGL_CONTEXT_OPENGL_PROFILE_MASK, EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT, @@ -11753,6 +11772,24 @@ SOKOL_API_IMPL uint32_t sapp_gl_get_framebuffer(void) { #endif } +SOKOL_API_IMPL int sapp_gl_get_major_version(void) { + SOKOL_ASSERT(_sapp.valid); + #if defined(SOKOL_GLCORE) + return _sapp.desc.gl_major_version; + #else + return 0; + #endif +} + +SOKOL_API_IMPL int sapp_gl_get_minor_version(void) { + SOKOL_ASSERT(_sapp.valid); + #if defined(SOKOL_GLCORE) + return _sapp.desc.gl_minor_version; + #else + return 0; + #endif +} + SOKOL_API_IMPL const void* sapp_android_get_native_activity(void) { // NOTE: _sapp.valid is not asserted here because sapp_android_get_native_activity() // needs to be callable from within sokol_main() (see: https://github.com/floooh/sokol/issues/708) diff --git a/src/sokol/c/sokol_debugtext.h b/src/sokol/c/sokol_debugtext.h index 9e5062d..12ca7a6 100644 --- a/src/sokol/c/sokol_debugtext.h +++ b/src/sokol/c/sokol_debugtext.h @@ -17,7 +17,7 @@ platform-specific embedded shader code (these are the same defines as used by sokol_gfx.h and sokol_app.h): - SOKOL_GLCORE33 + SOKOL_GLCORE SOKOL_GLES3 SOKOL_D3D11 SOKOL_METAL @@ -2374,7 +2374,7 @@ static const uint8_t _sdtx_font_oric[2048] = { /* Embedded source code compiled with: - sokol-shdc -i debugtext.glsl -o debugtext.h -l glsl330:glsl300es:hlsl4:metal_macos:metal_ios:metal_sim:wgsl -b + sokol-shdc -i debugtext.glsl -o debugtext.h -l glsl410:glsl300es:hlsl4:metal_macos:metal_ios:metal_sim:wgsl -b (not that for Metal and D3D11 byte code, sokol-shdc must be run on macOS and Windows) @@ -2405,44 +2405,50 @@ static const uint8_t _sdtx_font_oric[2048] = { @program debugtext vs fs */ -#if defined(SOKOL_GLCORE33) -static const char _sdtx_vs_source_glsl330[298] = { - 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x33,0x30,0x0a,0x0a,0x6c,0x61, +#if defined(SOKOL_GLCORE) +static const uint8_t _sdtx_vs_source_glsl410[343] = { + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x31,0x30,0x0a,0x0a,0x6c,0x61, 0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, 0x30,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x32,0x20,0x70,0x6f,0x73,0x69,0x74, - 0x69,0x6f,0x6e,0x3b,0x0a,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x32,0x20,0x75,0x76, - 0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f, - 0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x32,0x20,0x74, - 0x65,0x78,0x63,0x6f,0x6f,0x72,0x64,0x30,0x3b,0x0a,0x6f,0x75,0x74,0x20,0x76,0x65, - 0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74, - 0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x32,0x29,0x20,0x69, - 0x6e,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x0a, - 0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20, - 0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, - 0x76,0x65,0x63,0x34,0x28,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x2a,0x20, - 0x76,0x65,0x63,0x32,0x28,0x32,0x2e,0x30,0x2c,0x20,0x2d,0x32,0x2e,0x30,0x29,0x20, - 0x2b,0x20,0x76,0x65,0x63,0x32,0x28,0x2d,0x31,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30, - 0x29,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x75,0x76,0x20,0x3d,0x20,0x74,0x65,0x78,0x63,0x6f,0x6f,0x72,0x64,0x30, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f, - 0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, + 0x69,0x6f,0x6e,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61, + 0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65, + 0x63,0x32,0x20,0x75,0x76,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f, + 0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x69,0x6e,0x20,0x76, + 0x65,0x63,0x32,0x20,0x74,0x65,0x78,0x63,0x6f,0x6f,0x72,0x64,0x30,0x3b,0x0a,0x6c, + 0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d, + 0x20,0x31,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c, + 0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74, + 0x69,0x6f,0x6e,0x20,0x3d,0x20,0x32,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x34, + 0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d, + 0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50, + 0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x66, + 0x6d,0x61,0x28,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x2c,0x20,0x76,0x65,0x63, + 0x32,0x28,0x32,0x2e,0x30,0x2c,0x20,0x2d,0x32,0x2e,0x30,0x29,0x2c,0x20,0x76,0x65, + 0x63,0x32,0x28,0x2d,0x31,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x29,0x2c,0x20, + 0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x75, + 0x76,0x20,0x3d,0x20,0x74,0x65,0x78,0x63,0x6f,0x6f,0x72,0x64,0x30,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72, + 0x30,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, }; -static const char _sdtx_fs_source_glsl330[182] = { - 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x33,0x30,0x0a,0x0a,0x75,0x6e, +static const uint8_t _sdtx_fs_source_glsl410[224] = { + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x31,0x30,0x0a,0x0a,0x75,0x6e, 0x69,0x66,0x6f,0x72,0x6d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x32,0x44,0x20, 0x74,0x65,0x78,0x5f,0x73,0x6d,0x70,0x3b,0x0a,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74, 0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x6f, 0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c, - 0x6f,0x72,0x3b,0x0a,0x69,0x6e,0x20,0x76,0x65,0x63,0x32,0x20,0x75,0x76,0x3b,0x0a, - 0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x0a, - 0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x74, - 0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x74,0x65,0x78,0x5f,0x73,0x6d,0x70,0x2c,0x20, - 0x75,0x76,0x29,0x2e,0x78,0x78,0x78,0x78,0x20,0x2a,0x20,0x63,0x6f,0x6c,0x6f,0x72, - 0x3b,0x0a,0x7d,0x0a,0x0a,0x00, + 0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74, + 0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x32, + 0x20,0x75,0x76,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61, + 0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63, + 0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d, + 0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67, + 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65, + 0x28,0x74,0x65,0x78,0x5f,0x73,0x6d,0x70,0x2c,0x20,0x75,0x76,0x29,0x2e,0x78,0x78, + 0x78,0x78,0x20,0x2a,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, + }; #elif defined(SOKOL_GLES3) -static const char _sdtx_vs_source_glsl300es[301] = { +static const uint8_t _sdtx_vs_source_glsl300es[301] = { 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x30,0x30,0x20,0x65,0x73,0x0a, 0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e, 0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x32,0x20,0x70,0x6f, @@ -2463,7 +2469,7 @@ static const char _sdtx_vs_source_glsl300es[301] = { 0x72,0x64,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d, 0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, }; -static const char _sdtx_fs_source_glsl300es[255] = { +static const uint8_t _sdtx_fs_source_glsl300es[255] = { 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x30,0x30,0x20,0x65,0x73,0x0a, 0x70,0x72,0x65,0x63,0x69,0x73,0x69,0x6f,0x6e,0x20,0x6d,0x65,0x64,0x69,0x75,0x6d, 0x70,0x20,0x66,0x6c,0x6f,0x61,0x74,0x3b,0x0a,0x70,0x72,0x65,0x63,0x69,0x73,0x69, @@ -3194,7 +3200,7 @@ static const uint8_t _sdtx_fs_bytecode_metal_ios[2825] = { 0x32,0x04,0x03,0x62,0x01,0x23,0x9f,0xd9,0x06,0x23,0x00,0x32,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, }; -static const char _sdtx_vs_source_metal_sim[577] = { +static const uint8_t _sdtx_vs_source_metal_sim[577] = { 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, 0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65, 0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a, @@ -3233,7 +3239,7 @@ static const char _sdtx_vs_source_metal_sim[577] = { 0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a, 0x00, }; -static const char _sdtx_fs_source_metal_sim[441] = { +static const uint8_t _sdtx_fs_source_metal_sim[441] = { 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, 0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65, 0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a, @@ -3351,7 +3357,7 @@ static const uint8_t _sdtx_fs_bytecode_hlsl4[608] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, }; #elif defined(SOKOL_WGPU) -static const char _sdtx_vs_source_wgsl[922] = { +static const uint8_t _sdtx_vs_source_wgsl[922] = { 0x64,0x69,0x61,0x67,0x6e,0x6f,0x73,0x74,0x69,0x63,0x28,0x6f,0x66,0x66,0x2c,0x20, 0x64,0x65,0x72,0x69,0x76,0x61,0x74,0x69,0x76,0x65,0x5f,0x75,0x6e,0x69,0x66,0x6f, 0x72,0x6d,0x69,0x74,0x79,0x29,0x3b,0x0a,0x0a,0x76,0x61,0x72,0x3c,0x70,0x72,0x69, @@ -3411,17 +3417,17 @@ static const char _sdtx_vs_source_wgsl[922] = { 0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x2c,0x20,0x75,0x76,0x2c,0x20,0x63,0x6f, 0x6c,0x6f,0x72,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, }; -static const char _sdtx_fs_source_wgsl[663] = { +static const uint8_t _sdtx_fs_source_wgsl[663] = { 0x64,0x69,0x61,0x67,0x6e,0x6f,0x73,0x74,0x69,0x63,0x28,0x6f,0x66,0x66,0x2c,0x20, 0x64,0x65,0x72,0x69,0x76,0x61,0x74,0x69,0x76,0x65,0x5f,0x75,0x6e,0x69,0x66,0x6f, 0x72,0x6d,0x69,0x74,0x79,0x29,0x3b,0x0a,0x0a,0x76,0x61,0x72,0x3c,0x70,0x72,0x69, 0x76,0x61,0x74,0x65,0x3e,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72, 0x20,0x3a,0x20,0x76,0x65,0x63,0x34,0x66,0x3b,0x0a,0x0a,0x40,0x67,0x72,0x6f,0x75, - 0x70,0x28,0x31,0x29,0x20,0x40,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x28,0x33,0x32, + 0x70,0x28,0x31,0x29,0x20,0x40,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x28,0x34,0x38, 0x29,0x20,0x76,0x61,0x72,0x20,0x74,0x65,0x78,0x20,0x3a,0x20,0x74,0x65,0x78,0x74, 0x75,0x72,0x65,0x5f,0x32,0x64,0x3c,0x66,0x33,0x32,0x3e,0x3b,0x0a,0x0a,0x40,0x67, 0x72,0x6f,0x75,0x70,0x28,0x31,0x29,0x20,0x40,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67, - 0x28,0x34,0x38,0x29,0x20,0x76,0x61,0x72,0x20,0x73,0x6d,0x70,0x20,0x3a,0x20,0x73, + 0x28,0x36,0x34,0x29,0x20,0x76,0x61,0x72,0x20,0x73,0x6d,0x70,0x20,0x3a,0x20,0x73, 0x61,0x6d,0x70,0x6c,0x65,0x72,0x3b,0x0a,0x0a,0x76,0x61,0x72,0x3c,0x70,0x72,0x69, 0x76,0x61,0x74,0x65,0x3e,0x20,0x75,0x76,0x20,0x3a,0x20,0x76,0x65,0x63,0x32,0x66, 0x3b,0x0a,0x0a,0x76,0x61,0x72,0x3c,0x70,0x72,0x69,0x76,0x61,0x74,0x65,0x3e,0x20, @@ -3459,7 +3465,7 @@ static const char _sdtx_fs_source_wgsl[663] = { static const char* _sdtx_vs_src_dummy = ""; static const char* _sdtx_fs_src_dummy = ""; #else -#error "Please define one of SOKOL_GLCORE33, SOKOL_GLES3, SOKOL_D3D11, SOKOL_METAL, SOKOL_WGPU or SOKOL_DUMMY_BACKEND!" +#error "Please define one of SOKOL_GLCORE, SOKOL_GLES3, SOKOL_D3D11, SOKOL_METAL, SOKOL_WGPU or SOKOL_DUMMY_BACKEND!" #endif // ███████ ████████ ██████ ██ ██ ██████ ████████ ███████ @@ -3952,12 +3958,12 @@ static void _sdtx_setup_common(void) { shd_desc.fs.image_sampler_pairs[0].image_slot = 0; shd_desc.fs.image_sampler_pairs[0].sampler_slot = 0; shd_desc.fs.image_sampler_pairs[0].glsl_name = "tex_smp"; - #if defined(SOKOL_GLCORE33) - shd_desc.vs.source = _sdtx_vs_source_glsl330; - shd_desc.fs.source = _sdtx_fs_source_glsl330; + #if defined(SOKOL_GLCORE) + shd_desc.vs.source = (const char*)_sdtx_vs_source_glsl410; + shd_desc.fs.source = (const char*)_sdtx_fs_source_glsl410; #elif defined(SOKOL_GLES3) - shd_desc.vs.source = _sdtx_vs_source_glsl300es; - shd_desc.fs.source = _sdtx_fs_source_glsl300es; + shd_desc.vs.source = (const char*)_sdtx_vs_source_glsl300es; + shd_desc.fs.source = (const char*)_sdtx_fs_source_glsl300es; #elif defined(SOKOL_METAL) shd_desc.vs.entry = "main0"; shd_desc.fs.entry = "main0"; @@ -3971,16 +3977,16 @@ static void _sdtx_setup_common(void) { shd_desc.fs.bytecode = SG_RANGE(_sdtx_fs_bytecode_metal_ios); break; default: - shd_desc.vs.source = _sdtx_vs_source_metal_sim; - shd_desc.fs.source = _sdtx_fs_source_metal_sim; + shd_desc.vs.source = (const char*)_sdtx_vs_source_metal_sim; + shd_desc.fs.source = (const char*)_sdtx_fs_source_metal_sim; break; } #elif defined(SOKOL_D3D11) shd_desc.vs.bytecode = SG_RANGE(_sdtx_vs_bytecode_hlsl4); shd_desc.fs.bytecode = SG_RANGE(_sdtx_fs_bytecode_hlsl4); #elif defined(SOKOL_WGPU) - shd_desc.vs.source = _sdtx_vs_source_wgsl; - shd_desc.fs.source = _sdtx_fs_source_wgsl; + shd_desc.vs.source = (const char*)_sdtx_vs_source_wgsl; + shd_desc.fs.source = (const char*)_sdtx_fs_source_wgsl; #else shd_desc.vs.source = _sdtx_vs_src_dummy; shd_desc.fs.source = _sdtx_fs_src_dummy; diff --git a/src/sokol/c/sokol_gfx.h b/src/sokol/c/sokol_gfx.h index 7bf0454..e7478d2 100644 --- a/src/sokol/c/sokol_gfx.h +++ b/src/sokol/c/sokol_gfx.h @@ -17,19 +17,19 @@ In the same place define one of the following to select the rendering backend: - #define SOKOL_GLCORE33 + #define SOKOL_GLCORE #define SOKOL_GLES3 #define SOKOL_D3D11 #define SOKOL_METAL #define SOKOL_WGPU #define SOKOL_DUMMY_BACKEND - I.e. for the GL 3.3 Core Profile it should look like this: + I.e. for the desktop GL it should look like this: #include ... #include ... #define SOKOL_IMPL - #define SOKOL_GLCORE33 + #define SOKOL_GLCORE #include "sokol_gfx.h" The dummy backend replaces the platform-specific backend code with empty @@ -148,9 +148,8 @@ sg_apply_pipeline(sg_pipeline pip) --- fill an sg_bindings struct with the resource bindings for the next - draw call (1..N vertex buffers, 0 or 1 index buffer, 0..N image objects and - 0..N sampler objects on the vertex-shader- and fragment-shader-stage - and then call + draw call (0..N vertex buffers, 0 or 1 index buffer, 0..N image-objects, + samplers and storage-buffers), and call: sg_apply_bindings(const sg_bindings* bindings) @@ -718,7 +717,9 @@ the sg_make_shader() function requires the following information: - Shader code or shader binary blobs for the vertex- and fragment- shader-stage: - - for the desktop GL backend, source code must be provided in '#version 330' syntax + - for the desktop GL backend, source code can be provided in '#version 410' or + '#version 430', version 430 is required for storage buffer support, but note + that this is not available on macOS - for the GLES3 backend, source code must be provided in '#version 300 es' syntax - for the D3D11 backend, shaders can be provided as source or binary blobs, the source code should be in HLSL4.0 (for best compatibility) or alternatively @@ -757,6 +758,12 @@ - please also NOTE the documentation sections about UNIFORM DATA LAYOUT and CROSS-BACKEND COMMON UNIFORM DATA LAYOUT below! + - A description of each storage buffer used in the shader: + - a boolean 'readonly' flag, note that currently only + readonly storage buffers are supported + - note that storage buffers are not supported on all backends + and platforms + - A description of each texture/image used in the shader: - the expected image type: - SG_IMAGETYPE_2D @@ -773,7 +780,7 @@ (currently it's not supported to fetch data from multisampled textures in shaders, but this is planned for a later time) - - A description of each sampler used in the shader: + - A description of each texture sampler used in the shader: - SG_SAMPLERTYPE_FILTERING, - SG_SAMPLERTYPE_NONFILTERING, - SG_SAMPLERTYPE_COMPARISON, @@ -953,6 +960,126 @@ The by far easiest way to tackle the common uniform block layout problem is to use the sokol-shdc shader cross-compiler tool! + ON STORAGE BUFFERS + ================== + Storage buffers can be used to pass large amounts of random access structured + data fromt the CPU side to the shaders. They are similar to data textures, but are + more convenient to use both on the CPU and shader side since they can be accessed + in shaders as as a 1-dimensional array of struct items. + + Storage buffers are *NOT* supported on the following platform/backend combos: + + - macOS+GL (because storage buffers require GL 4.3, while macOS only goes up to GL 4.1) + - all GLES3 platforms (WebGL2, iOS, Android - with the option that support on + Android may be added at a later point) + + Currently only 'readonly' storage buffers are supported (meaning it's not possible + to write to storage buffers from shaders). + + To use storage buffers, the following steps are required: + + - write a shader which uses storage buffers (also see the example links below) + - create one or more storage buffers via sg_make_buffer() with the + buffer type SG_BUFFERTYPE_STORAGEBUFFER + - when creating a shader via sg_make_shader(), populate the sg_shader_desc + struct with binding info (when using sokol-shdc, this step will be taken care + of automatically) + - which storage buffer bind slots on the vertex- and fragment-stage + are occupied + - whether the storage buffer on that bind slot is readonly (this is currently required + to be true) + - when calling sg_apply_bindings(), apply the matching bind slots with the previously + created storage buffers + - ...and that's it. + + For more details, see the following backend-agnostic sokol samples: + + - simple vertex pulling from a storage buffer: + - C code: https://github.com/floooh/sokol-samples/blob/master/sapp/vertexpull-sapp.c + - shader: https://github.com/floooh/sokol-samples/blob/master/sapp/vertexpull-sapp.glsl + - instanced rendering via storage buffers (vertex- and instance-pulling): + - C code: https://github.com/floooh/sokol-samples/blob/master/sapp/instancing-pull-sapp.c + - shader: https://github.com/floooh/sokol-samples/blob/master/sapp/instancing-pull-sapp.glsl + - storage buffers both on the vertex- and fragment-stage: + - C code: https://github.com/floooh/sokol-samples/blob/master/sapp/sbuftex-sapp.c + - shader: https://github.com/floooh/sokol-samples/blob/master/sapp/sbuftex-sapp.glsl + - the Ozz animation sample rewritten to pull all rendering data from storage buffers: + - C code: https://github.com/floooh/sokol-samples/blob/master/sapp/ozz-storagebuffer-sapp.cc + - shader: https://github.com/floooh/sokol-samples/blob/master/sapp/ozz-storagebuffer-sapp.glsl + + ...also see the following backend-specific vertex pulling samples (those also don't use sokol-shdc): + + - D3D11: https://github.com/floooh/sokol-samples/blob/master/d3d11/vertexpulling-d3d11.c + - desktop GL: https://github.com/floooh/sokol-samples/blob/master/glfw/vertexpulling-glfw.c + - Metal: https://github.com/floooh/sokol-samples/blob/master/metal/vertexpulling-metal.c + - WebGPU: https://github.com/floooh/sokol-samples/blob/master/wgpu/vertexpulling-wgpu.c + + Storage buffer shader authoring caveats when using sokol-shdc: + + - declare a storage buffer interface block with `readonly buffer [name] { ... }` + - do NOT annotate storage buffers with `layout(...)`, sokol-shdc will take care of that + - declare a struct which describes a single array item in the storage buffer interface block + - only put a single flexible array member into the storage buffer interface block + + E.g. a complete example in 'sokol-shdc GLSL': + + ```glsl + // declare a struct: + struct sb_vertex { + vec3 pos; + vec4 color; + } + // declare a buffer interface block with a single flexible struct array: + readonly buffer vertices { + sb_vertex vtx[]; + } + // in the shader function, access the storage buffer like this: + void main() { + vec3 pos = vtx[gl_VertexIndex].pos; + ... + } + ``` + + Backend-specific storage-buffer caveats (not relevant when using sokol-shdc): + + D3D11: + - storage buffers are created as 'raw' Byte Address Buffers + (https://learn.microsoft.com/en-us/windows/win32/direct3d11/overviews-direct3d-11-resources-intro#raw-views-of-buffers) + - in HLSL, use a ByteAddressBuffer to access the buffer content + (https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/sm5-object-byteaddressbuffer) + - in D3D11, storage buffers and textures share the same bind slots, sokol-gfx reserves + shader resource slots 0..15 for textures and 16..23 for storage buffers. + - e.g. in HLSL, storage buffer bindings start at register(t16) no matter the shader stage + + Metal: + - in Metal there is no internal difference between vertex-, uniform- and + storage-buffers, all are bound to the same 'buffer bind slots' with the + following reserved ranges: + - vertex shader stage: + - uniform buffers (internal): slots 0..3 + - vertex buffers: slots 4..11 + - storage buffers: slots 12..19 + - fragment shader stage: + - uniform buffers (internal): slots 0..3 + - storage buffers: slots 4..11 + - this means in MSL, storage buffer bindings start at [[buffer(12)]] in the vertex + shaders, and at [[buffer(4)]] in fragment shaders + + GL: + - the GL backend doesn't use name-lookup to find storage buffer bindings, this + means you must annotate buffers with `layout(std430, binding=N)` in GLSL + - ...where N is 0..7 in the vertex shader, and 8..15 in the fragment shader + + WebGPU: + - in WGSL, use the following bind locations for the various shader resource types: + - vertex shader stage: + - textures `@group(1) @binding(0..15)` + - samplers `@group(1) @binding(16..31)` + - storage buffers `@group(1) @binding(32..47)` + - fragment shader stage: + - textures `@group(1) @binding(48..63)` + - samplers `@group(1) @binding(64..79)` + - storage buffers `@group(1) @binding(80..95)` TRACE HOOKS: ============ @@ -1334,12 +1461,14 @@ offsets depending on resource type and shader stage. - Vertex shader textures must start at `@group(1) @binding(0)` - Vertex shader samplers must start at `@group(1) @binding(16)` - - Fragment shader textures must start at `@group(1) @binding(32)` - - Fragment shader samplers must start at `@group(1) @binding(48)` + - Vertex shader storage buffers must start at `@group(1) @binding(32)` + - Fragment shader textures must start at `@group(1) @binding(48)` + - Fragment shader samplers must start at `@group(1) @binding(64)` + - Fragment shader storage buffers must start at `@group(1) @binding(80)` Note that the actual number of allowed per-stage texture- and sampler-bindings in sokol-gfx is currently lower than the above ranges (currently only up to - 12 textures and 8 samplers per shader stage are allowed). + 12 textures, 8 samplers and 8 storage buffers are allowed per shader stage). If you use sokol-shdc to generate WGSL shader code, you don't need to worry about the above binding convention since sokol-shdc assigns bind slots @@ -1516,6 +1645,7 @@ enum { SG_MAX_SHADERSTAGE_IMAGES = 12, SG_MAX_SHADERSTAGE_SAMPLERS = 8, SG_MAX_SHADERSTAGE_IMAGESAMPLERPAIRS = 12, + SG_MAX_SHADERSTAGE_STORAGEBUFFERS = 8, SG_MAX_SHADERSTAGE_UBS = 4, SG_MAX_UB_MEMBERS = 16, SG_MAX_VERTEX_ATTRIBUTES = 16, @@ -1537,7 +1667,7 @@ typedef struct sg_color { float r, g, b, a; } sg_color; to get the currently active backend. */ typedef enum sg_backend { - SG_BACKEND_GLCORE33, + SG_BACKEND_GLCORE, SG_BACKEND_GLES3, SG_BACKEND_D3D11, SG_BACKEND_METAL_IOS, @@ -1666,8 +1796,10 @@ typedef enum sg_pixel_format { SG_PIXELFORMAT_ETC2_RGB8A1, SG_PIXELFORMAT_ETC2_RGBA8, SG_PIXELFORMAT_ETC2_SRGB8A8, - SG_PIXELFORMAT_ETC2_RG11, - SG_PIXELFORMAT_ETC2_RG11SN, + SG_PIXELFORMAT_EAC_R11, + SG_PIXELFORMAT_EAC_R11SN, + SG_PIXELFORMAT_EAC_RG11, + SG_PIXELFORMAT_EAC_RG11SN, SG_PIXELFORMAT_ASTC_4x4_RGBA, SG_PIXELFORMAT_ASTC_4x4_SRGBA, @@ -1700,6 +1832,7 @@ typedef struct sg_features { bool image_clamp_to_border; // border color and clamp-to-border UV-wrap mode is supported bool mrt_independent_blend_state; // multiple-render-target rendering can use per-render-target blend state bool mrt_independent_write_mask; // multiple-render-target rendering can use per-render-target color write masks + bool storage_buffer; // storage buffers are supported } sg_features; /* @@ -1789,8 +1922,10 @@ typedef enum sg_usage { /* sg_buffer_type - This indicates whether a buffer contains vertex- or index-data, - used in the sg_buffer_desc.type member when creating a buffer. + Indicates whether a buffer will be bound as vertex-, + index- or storage-buffer. + + Used in the sg_buffer_desc.type member when creating a buffer. The default value is SG_BUFFERTYPE_VERTEXBUFFER. */ @@ -1798,6 +1933,7 @@ typedef enum sg_buffer_type { _SG_BUFFERTYPE_DEFAULT, // value 0 reserved for default-init SG_BUFFERTYPE_VERTEXBUFFER, SG_BUFFERTYPE_INDEXBUFFER, + SG_BUFFERTYPE_STORAGEBUFFER, _SG_BUFFERTYPE_NUM, _SG_BUFFERTYPE_FORCE_U32 = 0x7FFFFFFF } sg_buffer_type; @@ -1921,12 +2057,12 @@ typedef enum sg_cube_face { sg_shader_stage There are 2 shader stages: vertex- and fragment-shader-stage. - Each shader stage consists of: + Each shader stage - - one slot for a shader function (provided as source- or byte-code) - - SG_MAX_SHADERSTAGE_UBS slots for uniform blocks - - SG_MAX_SHADERSTAGE_IMAGES slots for images used as textures by - the shader function + - SG_MAX_SHADERSTAGE_UBS slots for applying uniform data + - SG_MAX_SHADERSTAGE_IMAGES slots for images used as textures + - SG_MAX_SHADERSTAGE_SAMPLERS slots for texture samplers + - SG_MAX_SHADERSTAGE_STORAGEBUFFERS slots for storage buffer bindings */ typedef enum sg_shader_stage { SG_SHADERSTAGE_VS, @@ -2562,12 +2698,17 @@ typedef struct sg_pass { - 0..1 index buffer offsets - 0..N vertex shader stage images - 0..N vertex shader stage samplers + - 0..N vertex shader storage buffers - 0..N fragment shader stage images - 0..N fragment shader stage samplers + - 0..N fragment shader storage buffers - The max number of vertex buffer and shader stage images - are defined by the SG_MAX_VERTEX_BUFFERS and - SG_MAX_SHADERSTAGE_IMAGES configuration constants. + For the max number of bindings, see the constant definitions: + + - SG_MAX_VERTEX_BUFFERS + - SG_MAX_SHADERSTAGE_IMAGES + - SG_MAX_SHADERSTAGE_SAMPLERS + - SG_MAX_SHADERSTAGE_STORAGEBUFFERS The optional buffer offsets can be used to put different unrelated chunks of vertex- and/or index-data into the same buffer objects. @@ -2575,6 +2716,7 @@ typedef struct sg_pass { typedef struct sg_stage_bindings { sg_image images[SG_MAX_SHADERSTAGE_IMAGES]; sg_sampler samplers[SG_MAX_SHADERSTAGE_SAMPLERS]; + sg_buffer storage_buffers[SG_MAX_SHADERSTAGE_STORAGEBUFFERS]; } sg_stage_bindings; typedef struct sg_bindings { @@ -2601,11 +2743,7 @@ typedef struct sg_bindings { .usage: SG_USAGE_IMMUTABLE .data.ptr 0 (*must* be valid for immutable buffers) .data.size 0 (*must* be > 0 for immutable buffers) - .label 0 (optional string label for trace hooks) - - The label will be ignored by sokol_gfx.h, it is only useful - when hooking into sg_make_buffer() or sg_init_buffer() via - the sg_install_trace_hooks() function. + .label 0 (optional string label) For immutable buffers which are initialized with initial data, keep the .size item zero-initialized, and set the size together with the @@ -2818,6 +2956,9 @@ typedef struct sg_sampler_desc { - the texture slot of the involved texture - the sampler slot of the involved sampler - for GLSL only: the name of the combined image-sampler object + - reflection info for each storage-buffer used by the shader: + - whether the storage buffer is readonly (currently this + must be true) For all GL backends, shader source-code must be provided. For D3D11 and Metal, either shader source-code or byte-code can be provided. @@ -2846,6 +2987,11 @@ typedef struct sg_shader_uniform_block_desc { sg_shader_uniform_desc uniforms[SG_MAX_UB_MEMBERS]; } sg_shader_uniform_block_desc; +typedef struct sg_shader_storage_buffer_desc { + bool used; + bool readonly; +} sg_shader_storage_buffer_desc; + typedef struct sg_shader_image_desc { bool used; bool multisampled; @@ -2871,6 +3017,7 @@ typedef struct sg_shader_stage_desc { const char* entry; const char* d3d11_target; sg_shader_uniform_block_desc uniform_blocks[SG_MAX_SHADERSTAGE_UBS]; + sg_shader_storage_buffer_desc storage_buffers[SG_MAX_SHADERSTAGE_STORAGEBUFFERS]; sg_shader_image_desc images[SG_MAX_SHADERSTAGE_IMAGES]; sg_shader_sampler_desc samplers[SG_MAX_SHADERSTAGE_SAMPLERS]; sg_shader_image_sampler_pair_desc image_sampler_pairs[SG_MAX_SHADERSTAGE_IMAGESAMPLERPAIRS]; @@ -3214,9 +3361,9 @@ typedef struct sg_attachments_info { /* sg_frame_stats - Allows to track generic and backend-specific tracking stats about a + Allows to track generic and backend-specific stats about a render frame. Obtained by calling sg_query_frame_stats(). The returned - struct will contains information about the *previous* frame. + struct contains information about the *previous* frame. */ typedef struct sg_frame_stats_gl { uint32_t num_bind_buffer; @@ -3301,6 +3448,7 @@ typedef struct sg_frame_stats_metal_bindings { uint32_t num_set_vertex_buffer; uint32_t num_set_vertex_texture; uint32_t num_set_vertex_sampler_state; + uint32_t num_set_fragment_buffer; uint32_t num_set_fragment_texture; uint32_t num_set_fragment_sampler_state; } sg_frame_stats_metal_bindings; @@ -3390,6 +3538,7 @@ typedef struct sg_frame_stats { _SG_LOGITEM_XMACRO(GL_FRAMEBUFFER_STATUS_INCOMPLETE_MULTISAMPLE, "framebuffer completeness check failed with GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE (gl)") \ _SG_LOGITEM_XMACRO(GL_FRAMEBUFFER_STATUS_UNKNOWN, "framebuffer completeness check failed (unknown reason) (gl)") \ _SG_LOGITEM_XMACRO(D3D11_CREATE_BUFFER_FAILED, "CreateBuffer() failed (d3d11)") \ + _SG_LOGITEM_XMACRO(D3D11_CREATE_BUFFER_SRV_FAILED, "CreateShaderResourceView() failed for storage buffer (d3d11)") \ _SG_LOGITEM_XMACRO(D3D11_CREATE_DEPTH_TEXTURE_UNSUPPORTED_PIXEL_FORMAT, "pixel format not supported for depth-stencil texture (d3d11)") \ _SG_LOGITEM_XMACRO(D3D11_CREATE_DEPTH_TEXTURE_FAILED, "CreateTexture2D() failed for depth-stencil texture (d3d11)") \ _SG_LOGITEM_XMACRO(D3D11_CREATE_2D_TEXTURE_UNSUPPORTED_PIXEL_FORMAT, "pixel format not supported for 2d-, cube- or array-texture (d3d11)") \ @@ -3436,6 +3585,7 @@ typedef struct sg_frame_stats { _SG_LOGITEM_XMACRO(WGPU_CREATE_SHADER_MODULE_FAILED, "wgpuDeviceCreateShaderModule() failed") \ _SG_LOGITEM_XMACRO(WGPU_SHADER_TOO_MANY_IMAGES, "shader uses too many sampled images on shader stage (wgpu)") \ _SG_LOGITEM_XMACRO(WGPU_SHADER_TOO_MANY_SAMPLERS, "shader uses too many samplers on shader stage (wgpu)") \ + _SG_LOGITEM_XMACRO(WGPU_SHADER_TOO_MANY_STORAGEBUFFERS, "shader uses too many storage buffer bindings on shader stage (wgpu)") \ _SG_LOGITEM_XMACRO(WGPU_SHADER_CREATE_BINDGROUP_LAYOUT_FAILED, "wgpuDeviceCreateBindGroupLayout() for shader stage failed") \ _SG_LOGITEM_XMACRO(WGPU_CREATE_PIPELINE_LAYOUT_FAILED, "wgpuDeviceCreatePipelineLayout() failed") \ _SG_LOGITEM_XMACRO(WGPU_CREATE_RENDER_PIPELINE_FAILED, "wgpuDeviceCreateRenderPipeline() failed") \ @@ -3480,6 +3630,8 @@ typedef struct sg_frame_stats { _SG_LOGITEM_XMACRO(VALIDATE_BUFFERDESC_DATA, "immutable buffers must be initialized with data (sg_buffer_desc.data.ptr and sg_buffer_desc.data.size)") \ _SG_LOGITEM_XMACRO(VALIDATE_BUFFERDESC_DATA_SIZE, "immutable buffer data size differs from buffer size") \ _SG_LOGITEM_XMACRO(VALIDATE_BUFFERDESC_NO_DATA, "dynamic/stream usage buffers cannot be initialized with data") \ + _SG_LOGITEM_XMACRO(VALIDATE_BUFFERDESC_STORAGEBUFFER_SUPPORTED, "storage buffers not supported by the backend 3D API (requires OpenGL >= 4.3)") \ + _SG_LOGITEM_XMACRO(VALIDATE_BUFFERDESC_STORAGEBUFFER_SIZE_MULTIPLE_4, "size of storage buffers must be a multiple of 4") \ _SG_LOGITEM_XMACRO(VALIDATE_IMAGEDATA_NODATA, "sg_image_data: no data (.ptr and/or .size is zero)") \ _SG_LOGITEM_XMACRO(VALIDATE_IMAGEDATA_DATA_SIZE, "sg_image_data: data size doesn't match expected surface size") \ _SG_LOGITEM_XMACRO(VALIDATE_IMAGEDESC_CANARY, "sg_image_desc not initialized") \ @@ -3513,6 +3665,8 @@ typedef struct sg_frame_stats { _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_UB_SIZE_MISMATCH, "size of uniform block members doesn't match uniform block size") \ _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_UB_ARRAY_COUNT, "uniform array count must be >= 1") \ _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_UB_STD140_ARRAY_TYPE, "uniform arrays only allowed for FLOAT4, INT4, MAT4 in std140 layout") \ + _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_NO_CONT_STORAGEBUFFERS, "shader stage storage buffers must occupy continuous slots (sg_shader_desc.vs|fs.storage_buffers[])") \ + _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_STORAGEBUFFER_READONLY, "shader stage storage buffers must be readonly (sg_shader_desc.vs|fs.storage_buffers[].readonly)") \ _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_NO_CONT_IMAGES, "shader stage images must occupy continuous slots (sg_shader_desc.vs|fs.images[])") \ _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_NO_CONT_SAMPLERS, "shader stage samplers must occupy continuous slots (sg_shader_desc.vs|fs.samplers[])") \ _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_IMAGE_SAMPLER_PAIR_IMAGE_SLOT_OUT_OF_RANGE, "shader stage: image-sampler-pair image slot index is out of range (sg_shader_desc.vs|fs.image_sampler_pairs[].image_slot)") \ @@ -3526,11 +3680,10 @@ typedef struct sg_frame_stats { _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_IMAGE_NOT_REFERENCED_BY_IMAGE_SAMPLER_PAIRS, "shader stage: one or more images are note referenced by (sg_shader_desc.vs|fs.image_sampler_pairs[].image_slot)") \ _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_SAMPLER_NOT_REFERENCED_BY_IMAGE_SAMPLER_PAIRS, "shader stage: one or more samplers are not referenced by image-sampler-pairs (sg_shader_desc.vs|fs.image_sampler_pairs[].sampler_slot)") \ _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_NO_CONT_IMAGE_SAMPLER_PAIRS, "shader stage image-sampler-pairs must occupy continuous slots (sg_shader_desc.vs|fs.image_samplers[])") \ - _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_ATTR_SEMANTICS, "D3D11 backend requires vertex attribute semantics") \ _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_ATTR_STRING_TOO_LONG, "vertex attribute name/semantic string too long (max len 16)") \ _SG_LOGITEM_XMACRO(VALIDATE_PIPELINEDESC_CANARY, "sg_pipeline_desc not initialized") \ _SG_LOGITEM_XMACRO(VALIDATE_PIPELINEDESC_SHADER, "sg_pipeline_desc.shader missing or invalid") \ - _SG_LOGITEM_XMACRO(VALIDATE_PIPELINEDESC_NO_ATTRS, "sg_pipeline_desc.layout.attrs is empty or not continuous") \ + _SG_LOGITEM_XMACRO(VALIDATE_PIPELINEDESC_NO_CONT_ATTRS, "sg_pipeline_desc.layout.attrs is not continuous") \ _SG_LOGITEM_XMACRO(VALIDATE_PIPELINEDESC_LAYOUT_STRIDE4, "sg_pipeline_desc.layout.buffers[].stride must be multiple of 4") \ _SG_LOGITEM_XMACRO(VALIDATE_PIPELINEDESC_ATTR_SEMANTICS, "D3D11 missing vertex attribute semantics in shader") \ _SG_LOGITEM_XMACRO(VALIDATE_ATTACHMENTSDESC_CANARY, "sg_attachments_desc not initialized") \ @@ -3634,6 +3787,10 @@ typedef struct sg_frame_stats { _SG_LOGITEM_XMACRO(VALIDATE_ABND_VS_EXPECTED_NONFILTERING_SAMPLER, "sg_apply_bindings: shader expected SG_SAMPLERTYPE_NONFILTERING on vertex stage, but sampler has SG_FILTER_LINEAR filters") \ _SG_LOGITEM_XMACRO(VALIDATE_ABND_VS_UNEXPECTED_SAMPLER_BINDING, "sg_apply_bindings: unexpected sampler binding on vertex stage") \ _SG_LOGITEM_XMACRO(VALIDATE_ABND_VS_SMP_EXISTS, "sg_apply_bindings: sampler bound to vertex stage no longer alive") \ + _SG_LOGITEM_XMACRO(VALIDATE_ABND_VS_EXPECTED_STORAGEBUFFER_BINDING, "sg_apply_bindings: storage buffer binding on vertex stage is missing or the buffer handle is invalid") \ + _SG_LOGITEM_XMACRO(VALIDATE_ABND_VS_STORAGEBUFFER_EXISTS, "sg_apply_bindings: storage buffer bound to vertex stage no longer alive") \ + _SG_LOGITEM_XMACRO(VALIDATE_ABND_VS_STORAGEBUFFER_BINDING_BUFFERTYPE, "sg_apply_bindings: buffer bound to vertex stage storage buffer slot is not of type storage buffer") \ + _SG_LOGITEM_XMACRO(VALIDATE_ABND_VS_UNEXPECTED_STORAGEBUFFER_BINDING, "sg_apply_bindings: unexpected storage buffer binding on vertex stage") \ _SG_LOGITEM_XMACRO(VALIDATE_ABND_FS_EXPECTED_IMAGE_BINDING, "sg_apply_bindings: image binding on fragment stage is missing or the image handle is invalid") \ _SG_LOGITEM_XMACRO(VALIDATE_ABND_FS_IMG_EXISTS, "sg_apply_bindings: image bound to fragment stage no longer alive") \ _SG_LOGITEM_XMACRO(VALIDATE_ABND_FS_IMAGE_TYPE_MISMATCH, "sg_apply_bindings: type of image bound to fragment stage doesn't match shader desc") \ @@ -3647,6 +3804,10 @@ typedef struct sg_frame_stats { _SG_LOGITEM_XMACRO(VALIDATE_ABND_FS_EXPECTED_NONFILTERING_SAMPLER, "sg_apply_bindings: shader expected SG_SAMPLERTYPE_NONFILTERING on fragment stage, but sampler has SG_FILTER_LINEAR filters") \ _SG_LOGITEM_XMACRO(VALIDATE_ABND_FS_UNEXPECTED_SAMPLER_BINDING, "sg_apply_bindings: unexpected sampler binding on fragment stage") \ _SG_LOGITEM_XMACRO(VALIDATE_ABND_FS_SMP_EXISTS, "sg_apply_bindings: sampler bound to fragment stage no longer alive") \ + _SG_LOGITEM_XMACRO(VALIDATE_ABND_FS_EXPECTED_STORAGEBUFFER_BINDING, "sg_apply_bindings: storage buffer binding on fragment stage is missing or the buffer handle is invalid") \ + _SG_LOGITEM_XMACRO(VALIDATE_ABND_FS_STORAGEBUFFER_EXISTS, "sg_apply_bindings: storage buffer bound to fragment stage no longer alive") \ + _SG_LOGITEM_XMACRO(VALIDATE_ABND_FS_STORAGEBUFFER_BINDING_BUFFERTYPE, "sg_apply_bindings: buffer bound to frahment stage storage buffer slot is not of type storage buffer") \ + _SG_LOGITEM_XMACRO(VALIDATE_ABND_FS_UNEXPECTED_STORAGEBUFFER_BINDING, "sg_apply_bindings: unexpected storage buffer binding on fragment stage") \ _SG_LOGITEM_XMACRO(VALIDATE_AUB_NO_PIPELINE, "sg_apply_uniforms: must be called after sg_apply_pipeline()") \ _SG_LOGITEM_XMACRO(VALIDATE_AUB_NO_UB_AT_SLOT, "sg_apply_uniforms: no uniform block declaration at this shader stage UB slot") \ _SG_LOGITEM_XMACRO(VALIDATE_AUB_SIZE, "sg_apply_uniforms: data size doesn't match declared uniform block size") \ @@ -3673,11 +3834,6 @@ typedef enum sg_log_item { The sg_desc struct contains configuration values for sokol_gfx, it is used as parameter to the sg_setup() call. - NOTE that all callback function pointers come in two versions, one without - a userdata pointer, and one with a userdata pointer. You would - either initialize one or the other depending on whether you pass data - to your callbacks. - The default configuration is: .buffer_pool_size 128 @@ -3771,7 +3927,7 @@ typedef struct sg_d3d11_environment { } sg_d3d11_environment; typedef struct sg_wgpu_environment { - const void* device; // WGPUDevice + const void* device; } sg_wgpu_environment; typedef struct sg_environment { @@ -3816,8 +3972,9 @@ typedef struct sg_allocator { that without logging function, sokol-gfx will be completely silent, e.g. it will not report errors, warnings and validation layer messages. For maximum error verbosity, - compile in debug mode (e.g. NDEBUG *not* defined) and install - a logger (for instance the standard logging function from sokol_log.h). + compile in debug mode (e.g. NDEBUG *not* defined) and provide a + compatible logger function in the sg_setup() call + (for instance the standard logging function from sokol_log.h). */ typedef struct sg_logger { void (*func)( @@ -4202,8 +4359,8 @@ inline int sg_append_buffer(sg_buffer buf_id, const sg_range& data) { return sg_ #ifdef SOKOL_GFX_IMPL #define SOKOL_GFX_IMPL_INCLUDED (1) -#if !(defined(SOKOL_GLCORE33)||defined(SOKOL_GLES3)||defined(SOKOL_D3D11)||defined(SOKOL_METAL)||defined(SOKOL_WGPU)||defined(SOKOL_DUMMY_BACKEND)) -#error "Please select a backend with SOKOL_GLCORE33, SOKOL_GLES3, SOKOL_D3D11, SOKOL_METAL, SOKOL_WGPU or SOKOL_DUMMY_BACKEND" +#if !(defined(SOKOL_GLCORE)||defined(SOKOL_GLES3)||defined(SOKOL_D3D11)||defined(SOKOL_METAL)||defined(SOKOL_WGPU)||defined(SOKOL_DUMMY_BACKEND)) +#error "Please select a backend with SOKOL_GLCORE, SOKOL_GLES3, SOKOL_D3D11, SOKOL_METAL, SOKOL_WGPU or SOKOL_DUMMY_BACKEND" #endif #if defined(SOKOL_MALLOC) || defined(SOKOL_CALLOC) || defined(SOKOL_FREE) #error "SOKOL_MALLOC/CALLOC/FREE macros are no longer supported, please use sg_desc.allocator to override memory allocation functions" @@ -4320,13 +4477,13 @@ inline int sg_append_buffer(sg_buffer buf_id, const sg_range& data) { return sg_ #if defined(__EMSCRIPTEN__) #include #endif -#elif defined(SOKOL_GLCORE33) || defined(SOKOL_GLES3) +#elif defined(SOKOL_GLCORE) || defined(SOKOL_GLES3) #define _SOKOL_ANY_GL (1) // include platform specific GL headers (or on Win32: use an embedded GL loader) #if !defined(SOKOL_EXTERNAL_GL_LOADER) #if defined(_WIN32) - #if defined(SOKOL_GLCORE33) && !defined(SOKOL_EXTERNAL_GL_LOADER) + #if defined(SOKOL_GLCORE) && !defined(SOKOL_EXTERNAL_GL_LOADER) #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN #endif @@ -4353,7 +4510,7 @@ inline int sg_append_buffer(sg_buffer buf_id, const sg_range& data) { return sg_ #include #endif #elif defined(__linux__) || defined(__unix__) - #if defined(SOKOL_GLCORE33) + #if defined(SOKOL_GLCORE) #define GL_GLEXT_PROTOTYPES #include #else @@ -4610,6 +4767,8 @@ inline int sg_append_buffer(sg_buffer buf_id, const sg_range& data) { return sg_ #define GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT 0x8CD7 #define GL_FRAMEBUFFER_UNSUPPORTED 0x8CDD #define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE 0x8D56 + #define GL_MAJOR_VERSION 0x821B + #define GL_MINOR_VERSION 0x821C #endif #ifndef GL_UNSIGNED_INT_2_10_10_10_REV @@ -4687,6 +4846,12 @@ inline int sg_append_buffer(sg_buffer buf_id, const sg_range& data) { return sg_ #ifndef GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 #define GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 0x9276 #endif + #ifndef GL_COMPRESSED_R11_EAC + #define GL_COMPRESSED_R11_EAC 0x9270 + #endif + #ifndef GL_COMPRESSED_SIGNED_R11_EAC + #define GL_COMPRESSED_SIGNED_R11_EAC 0x9271 + #endif #ifndef GL_COMPRESSED_RG11_EAC #define GL_COMPRESSED_RG11_EAC 0x9272 #endif @@ -4725,6 +4890,12 @@ inline int sg_append_buffer(sg_buffer buf_id, const sg_range& data) { return sg_ #endif #endif +// make some GL constants generally available to simplify compilation, +// use of those constants will be filtered by runtime flags +#ifndef GL_SHADER_STORAGE_BUFFER +#define GL_SHADER_STORAGE_BUFFER 0x90D2 +#endif + // ███████ ████████ ██████ ██ ██ ██████ ████████ ███████ // ██ ██ ██ ██ ██ ██ ██ ██ ██ // ███████ ██ ██████ ██ ██ ██ ██ ███████ @@ -4876,6 +5047,11 @@ typedef struct { size_t size; } _sg_shader_uniform_block_t; +typedef struct { + bool used; + bool readonly; +} _sg_shader_storage_buffer_t; + typedef struct { sg_image_type image_type; sg_image_sample_type sample_type; @@ -4894,10 +5070,12 @@ typedef struct { typedef struct { int num_uniform_blocks; + int num_storage_buffers; int num_images; int num_samplers; int num_image_samplers; _sg_shader_uniform_block_t uniform_blocks[SG_MAX_SHADERSTAGE_UBS]; + _sg_shader_storage_buffer_t storage_buffers[SG_MAX_SHADERSTAGE_STORAGEBUFFERS]; _sg_shader_image_t images[SG_MAX_SHADERSTAGE_IMAGES]; _sg_shader_sampler_t samplers[SG_MAX_SHADERSTAGE_SAMPLERS]; _sg_shader_image_sampler_t image_samplers[SG_MAX_SHADERSTAGE_IMAGESAMPLERPAIRS]; @@ -4952,6 +5130,16 @@ _SOKOL_PRIVATE void _sg_shader_common_init(_sg_shader_common_t* cmn, const sg_sh stage->image_samplers[img_smp_index].sampler_slot = img_smp_desc->sampler_slot; stage->num_image_samplers++; } + SOKOL_ASSERT(stage->num_storage_buffers == 0); + for (int sbuf_index = 0; sbuf_index < SG_MAX_SHADERSTAGE_STORAGEBUFFERS; sbuf_index++) { + const sg_shader_storage_buffer_desc* sbuf_desc = &stage_desc->storage_buffers[sbuf_index]; + if (!sbuf_desc->used) { + break; + } + stage->storage_buffers[sbuf_index].used = sbuf_desc->used; + stage->storage_buffers[sbuf_index].readonly = sbuf_desc->readonly; + stage->num_storage_buffers++; + } } } @@ -5081,6 +5269,10 @@ typedef struct { typedef _sg_dummy_attachments_t _sg_attachments_t; #elif defined(_SOKOL_ANY_GL) + +#define _SG_GL_TEXTURE_SAMPLER_CACHE_SIZE (SG_MAX_SHADERSTAGE_IMAGESAMPLERPAIRS * SG_NUM_SHADER_STAGES) +#define _SG_GL_STORAGEBUFFER_STAGE_INDEX_PITCH (SG_MAX_SHADERSTAGE_STORAGEBUFFERS) + typedef struct { _sg_slot_t slot; _sg_buffer_common_t cmn; @@ -5206,8 +5398,6 @@ typedef struct { GLuint sampler; } _sg_gl_cache_texture_sampler_bind_slot; -#define _SG_GL_TEXTURE_SAMPLER_CACHE_SIZE (SG_MAX_SHADERSTAGE_IMAGESAMPLERPAIRS * SG_NUM_SHADER_STAGES) - typedef struct { sg_depth_state depth; sg_stencil_state stencil; @@ -5222,8 +5412,11 @@ typedef struct { _sg_gl_cache_attr_t attrs[SG_MAX_VERTEX_ATTRIBUTES]; GLuint vertex_buffer; GLuint index_buffer; + GLuint storage_buffer; // general bind point + GLuint stage_storage_buffers[SG_NUM_SHADER_STAGES][SG_MAX_SHADERSTAGE_STORAGEBUFFERS]; GLuint stored_vertex_buffer; GLuint stored_index_buffer; + GLuint stored_storage_buffer; GLuint prog; _sg_gl_cache_texture_sampler_bind_slot texture_samplers[_SG_GL_TEXTURE_SAMPLER_CACHE_SIZE]; _sg_gl_cache_texture_sampler_bind_slot stored_texture_sampler; @@ -5256,6 +5449,7 @@ typedef struct { _sg_buffer_common_t cmn; struct { ID3D11Buffer* buf; + ID3D11ShaderResourceView* srv; } d3d11; } _sg_d3d11_buffer_t; typedef _sg_d3d11_buffer_t _sg_buffer_t; @@ -5471,6 +5665,8 @@ typedef struct { sg_image cur_fs_image_ids[SG_MAX_SHADERSTAGE_IMAGES]; sg_sampler cur_vs_sampler_ids[SG_MAX_SHADERSTAGE_SAMPLERS]; sg_sampler cur_fs_sampler_ids[SG_MAX_SHADERSTAGE_SAMPLERS]; + sg_buffer cur_vs_storagebuffer_ids[SG_MAX_SHADERSTAGE_STORAGEBUFFERS]; + sg_buffer cur_fs_storagebuffer_ids[SG_MAX_SHADERSTAGE_STORAGEBUFFERS]; } _sg_mtl_state_cache_t; typedef struct { @@ -5498,6 +5694,7 @@ typedef struct { #define _SG_WGPU_NUM_BINDGROUPS (2) // 0: uniforms, 1: images and sampler on both shader stages #define _SG_WGPU_UNIFORM_BINDGROUP_INDEX (0) #define _SG_WGPU_IMAGE_SAMPLER_BINDGROUP_INDEX (1) +#define _SG_WGPU_MAX_BINDGROUP_ENTRIES (SG_NUM_SHADER_STAGES * (SG_MAX_SHADERSTAGE_IMAGES + SG_MAX_SHADERSTAGE_SAMPLERS + SG_MAX_SHADERSTAGE_STORAGEBUFFERS)) typedef struct { _sg_slot_t slot; @@ -5586,7 +5783,7 @@ typedef struct { uint32_t id; } _sg_wgpu_bindgroup_handle_t; -#define _SG_WGPU_BINDGROUPSCACHE_NUM_ITEMS (1 + SG_NUM_SHADER_STAGES * (SG_MAX_SHADERSTAGE_IMAGES + SG_MAX_SHADERSTAGE_SAMPLERS)) +#define _SG_WGPU_BINDGROUPSCACHE_NUM_ITEMS (1 + _SG_WGPU_MAX_BINDGROUP_ENTRIES) typedef struct { uint64_t hash; uint32_t items[_SG_WGPU_BINDGROUPSCACHE_NUM_ITEMS]; @@ -5672,16 +5869,20 @@ typedef struct { int num_vbs; int num_vs_imgs; int num_vs_smps; + int num_vs_sbufs; int num_fs_imgs; int num_fs_smps; + int num_fs_sbufs; int vb_offsets[SG_MAX_VERTEX_BUFFERS]; int ib_offset; _sg_buffer_t* vbs[SG_MAX_VERTEX_BUFFERS]; _sg_buffer_t* ib; _sg_image_t* vs_imgs[SG_MAX_SHADERSTAGE_IMAGES]; _sg_sampler_t* vs_smps[SG_MAX_SHADERSTAGE_SAMPLERS]; + _sg_buffer_t* vs_sbufs[SG_MAX_SHADERSTAGE_STORAGEBUFFERS]; _sg_image_t* fs_imgs[SG_MAX_SHADERSTAGE_IMAGES]; _sg_sampler_t* fs_smps[SG_MAX_SHADERSTAGE_SAMPLERS]; + _sg_buffer_t* fs_sbufs[SG_MAX_SHADERSTAGE_STORAGEBUFFERS]; } _sg_bindings_t; typedef struct { @@ -5711,7 +5912,6 @@ typedef struct { } swapchain; } cur_pass; sg_pipeline cur_pipeline; - bool apply_bindings_called; bool next_draw_valid; #if defined(SOKOL_DEBUG) sg_log_item validate_error; @@ -6026,8 +6226,10 @@ _SOKOL_PRIVATE bool _sg_is_compressed_pixel_format(sg_pixel_format fmt) { case SG_PIXELFORMAT_ETC2_RGB8A1: case SG_PIXELFORMAT_ETC2_RGBA8: case SG_PIXELFORMAT_ETC2_SRGB8A8: - case SG_PIXELFORMAT_ETC2_RG11: - case SG_PIXELFORMAT_ETC2_RG11SN: + case SG_PIXELFORMAT_EAC_R11: + case SG_PIXELFORMAT_EAC_R11SN: + case SG_PIXELFORMAT_EAC_RG11: + case SG_PIXELFORMAT_EAC_RG11SN: case SG_PIXELFORMAT_ASTC_4x4_RGBA: case SG_PIXELFORMAT_ASTC_4x4_SRGBA: return true; @@ -6155,6 +6357,8 @@ _SOKOL_PRIVATE int _sg_row_pitch(sg_pixel_format fmt, int width, int row_align) case SG_PIXELFORMAT_ETC2_RGB8: case SG_PIXELFORMAT_ETC2_SRGB8: case SG_PIXELFORMAT_ETC2_RGB8A1: + case SG_PIXELFORMAT_EAC_R11: + case SG_PIXELFORMAT_EAC_R11SN: pitch = ((width + 3) / 4) * 8; pitch = pitch < 8 ? 8 : pitch; break; @@ -6169,8 +6373,8 @@ _SOKOL_PRIVATE int _sg_row_pitch(sg_pixel_format fmt, int width, int row_align) case SG_PIXELFORMAT_BC7_SRGBA: case SG_PIXELFORMAT_ETC2_RGBA8: case SG_PIXELFORMAT_ETC2_SRGB8A8: - case SG_PIXELFORMAT_ETC2_RG11: - case SG_PIXELFORMAT_ETC2_RG11SN: + case SG_PIXELFORMAT_EAC_RG11: + case SG_PIXELFORMAT_EAC_RG11SN: case SG_PIXELFORMAT_ASTC_4x4_RGBA: case SG_PIXELFORMAT_ASTC_4x4_SRGBA: pitch = ((width + 3) / 4) * 16; @@ -6204,8 +6408,10 @@ _SOKOL_PRIVATE int _sg_num_rows(sg_pixel_format fmt, int height) { case SG_PIXELFORMAT_ETC2_RGB8A1: case SG_PIXELFORMAT_ETC2_RGBA8: case SG_PIXELFORMAT_ETC2_SRGB8A8: - case SG_PIXELFORMAT_ETC2_RG11: - case SG_PIXELFORMAT_ETC2_RG11SN: + case SG_PIXELFORMAT_EAC_R11: + case SG_PIXELFORMAT_EAC_R11SN: + case SG_PIXELFORMAT_EAC_RG11: + case SG_PIXELFORMAT_EAC_RG11SN: case SG_PIXELFORMAT_BC2_RGBA: case SG_PIXELFORMAT_BC3_RGBA: case SG_PIXELFORMAT_BC3_SRGBA: @@ -6700,7 +6906,8 @@ _SOKOL_PRIVATE void _sg_dummy_update_image(_sg_image_t* img, const sg_image_data _SG_XMACRO(glSamplerParameteri, void, (GLuint sampler, GLenum pname, GLint param)) \ _SG_XMACRO(glSamplerParameterf, void, (GLuint sampler, GLenum pname, GLfloat param)) \ _SG_XMACRO(glSamplerParameterfv, void, (GLuint sampler, GLenum pname, const GLfloat* params)) \ - _SG_XMACRO(glDeleteSamplers, void, (GLsizei n, const GLuint* samplers)) + _SG_XMACRO(glDeleteSamplers, void, (GLsizei n, const GLuint* samplers)) \ + _SG_XMACRO(glBindBufferBase, void, (GLenum target, GLuint index, GLuint buffer)) // generate GL function pointer typedefs #define _SG_XMACRO(name, ret, args) typedef ret (GL_APIENTRY* PFN_ ## name) args; @@ -6747,6 +6954,7 @@ _SOKOL_PRIVATE GLenum _sg_gl_buffer_target(sg_buffer_type t) { switch (t) { case SG_BUFFERTYPE_VERTEXBUFFER: return GL_ARRAY_BUFFER; case SG_BUFFERTYPE_INDEXBUFFER: return GL_ELEMENT_ARRAY_BUFFER; + case SG_BUFFERTYPE_STORAGEBUFFER: return GL_SHADER_STORAGE_BUFFER; default: SOKOL_UNREACHABLE; return 0; } } @@ -6956,7 +7164,7 @@ _SOKOL_PRIVATE GLenum _sg_gl_mag_filter(sg_filter mag_f) { _SOKOL_PRIVATE GLenum _sg_gl_wrap(sg_wrap w) { switch (w) { case SG_WRAP_CLAMP_TO_EDGE: return GL_CLAMP_TO_EDGE; - #if defined(SOKOL_GLCORE33) + #if defined(SOKOL_GLCORE) case SG_WRAP_CLAMP_TO_BORDER: return GL_CLAMP_TO_BORDER; #else case SG_WRAP_CLAMP_TO_BORDER: return GL_CLAMP_TO_EDGE; @@ -7125,9 +7333,13 @@ _SOKOL_PRIVATE GLenum _sg_gl_teximage_format(sg_pixel_format fmt) { return GL_COMPRESSED_RGBA8_ETC2_EAC; case SG_PIXELFORMAT_ETC2_SRGB8A8: return GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC; - case SG_PIXELFORMAT_ETC2_RG11: + case SG_PIXELFORMAT_EAC_R11: + return GL_COMPRESSED_R11_EAC; + case SG_PIXELFORMAT_EAC_R11SN: + return GL_COMPRESSED_SIGNED_R11_EAC; + case SG_PIXELFORMAT_EAC_RG11: return GL_COMPRESSED_RG11_EAC; - case SG_PIXELFORMAT_ETC2_RG11SN: + case SG_PIXELFORMAT_EAC_RG11SN: return GL_COMPRESSED_SIGNED_RG11_EAC; case SG_PIXELFORMAT_ASTC_4x4_RGBA: return GL_COMPRESSED_RGBA_ASTC_4x4_KHR; @@ -7209,8 +7421,10 @@ _SOKOL_PRIVATE GLenum _sg_gl_teximage_internal_format(sg_pixel_format fmt) { case SG_PIXELFORMAT_ETC2_RGB8A1: return GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2; case SG_PIXELFORMAT_ETC2_RGBA8: return GL_COMPRESSED_RGBA8_ETC2_EAC; case SG_PIXELFORMAT_ETC2_SRGB8A8: return GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC; - case SG_PIXELFORMAT_ETC2_RG11: return GL_COMPRESSED_RG11_EAC; - case SG_PIXELFORMAT_ETC2_RG11SN: return GL_COMPRESSED_SIGNED_RG11_EAC; + case SG_PIXELFORMAT_EAC_R11: return GL_COMPRESSED_R11_EAC; + case SG_PIXELFORMAT_EAC_R11SN: return GL_COMPRESSED_SIGNED_R11_EAC; + case SG_PIXELFORMAT_EAC_RG11: return GL_COMPRESSED_RG11_EAC; + case SG_PIXELFORMAT_EAC_RG11SN: return GL_COMPRESSED_SIGNED_RG11_EAC; case SG_PIXELFORMAT_ASTC_4x4_RGBA: return GL_COMPRESSED_RGBA_ASTC_4x4_KHR; case SG_PIXELFORMAT_ASTC_4x4_SRGBA: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR; default: SOKOL_UNREACHABLE; return 0; @@ -7355,8 +7569,10 @@ _SOKOL_PRIVATE void _sg_gl_init_pixelformats_etc2(void) { _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_ETC2_RGB8A1]); _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_ETC2_RGBA8]); _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_ETC2_SRGB8A8]); - _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_ETC2_RG11]); - _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_ETC2_RG11SN]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_EAC_R11]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_EAC_R11SN]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_EAC_RG11]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_EAC_RG11SN]); } _SOKOL_PRIVATE void _sg_gl_init_pixelformats_astc(void) { @@ -7401,14 +7617,20 @@ _SOKOL_PRIVATE void _sg_gl_init_limits(void) { _sg.limits.gl_max_combined_texture_image_units = gl_int; } -#if defined(SOKOL_GLCORE33) -_SOKOL_PRIVATE void _sg_gl_init_caps_glcore33(void) { - _sg.backend = SG_BACKEND_GLCORE33; +#if defined(SOKOL_GLCORE) +_SOKOL_PRIVATE void _sg_gl_init_caps_glcore(void) { + _sg.backend = SG_BACKEND_GLCORE; + GLint major_version = 0; + GLint minor_version = 0; + glGetIntegerv(GL_MAJOR_VERSION, &major_version); + glGetIntegerv(GL_MINOR_VERSION, &minor_version); + const int version = major_version * 100 + minor_version * 10; _sg.features.origin_top_left = false; _sg.features.image_clamp_to_border = true; _sg.features.mrt_independent_blend_state = false; _sg.features.mrt_independent_write_mask = true; + _sg.features.storage_buffer = version >= 430; // scan extensions bool has_s3tc = false; // BC1..BC3 @@ -7481,6 +7703,7 @@ _SOKOL_PRIVATE void _sg_gl_init_caps_gles3(void) { _sg.features.image_clamp_to_border = false; _sg.features.mrt_independent_blend_state = false; _sg.features.mrt_independent_write_mask = false; + _sg.features.storage_buffer = false; bool has_s3tc = false; // BC1..BC3 bool has_rgtc = false; // BC4 and BC5 @@ -7570,6 +7793,12 @@ _SOKOL_PRIVATE void _sg_gl_init_caps_gles3(void) { #endif //-- state cache implementation ------------------------------------------------ +_SOKOL_PRIVATE GLuint _sg_gl_storagebuffer_bind_index(int stage, int slot) { + SOKOL_ASSERT((stage >= 0) && (stage < SG_NUM_SHADER_STAGES)); + SOKOL_ASSERT((slot >= 0) && (slot < SG_MAX_SHADERSTAGE_STORAGEBUFFERS)); + return (GLuint) (stage * _SG_GL_STORAGEBUFFER_STAGE_INDEX_PITCH + slot); +} + _SOKOL_PRIVATE void _sg_gl_cache_clear_buffer_bindings(bool force) { if (force || (_sg.gl.cache.vertex_buffer != 0)) { glBindBuffer(GL_ARRAY_BUFFER, 0); @@ -7581,30 +7810,77 @@ _SOKOL_PRIVATE void _sg_gl_cache_clear_buffer_bindings(bool force) { _sg.gl.cache.index_buffer = 0; _sg_stats_add(gl.num_bind_buffer, 1); } + if (force || (_sg.gl.cache.storage_buffer != 0)) { + if (_sg.features.storage_buffer) { + glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0); + } + _sg.gl.cache.storage_buffer = 0; + _sg_stats_add(gl.num_bind_buffer, 1); + } + for (int stage = 0; stage < SG_NUM_SHADER_STAGES; stage++) { + for (int i = 0; i < SG_MAX_SHADERSTAGE_STORAGEBUFFERS; i++) { + if (force || (_sg.gl.cache.stage_storage_buffers[stage][i] != 0)) { + const GLuint bind_index = _sg_gl_storagebuffer_bind_index(stage, i); + if (_sg.features.storage_buffer) { + glBindBufferBase(GL_SHADER_STORAGE_BUFFER, bind_index, 0); + } + _sg.gl.cache.stage_storage_buffers[stage][i] = 0; + _sg_stats_add(gl.num_bind_buffer, 1); + } + } + } } _SOKOL_PRIVATE void _sg_gl_cache_bind_buffer(GLenum target, GLuint buffer) { - SOKOL_ASSERT((GL_ARRAY_BUFFER == target) || (GL_ELEMENT_ARRAY_BUFFER == target)); + SOKOL_ASSERT((GL_ARRAY_BUFFER == target) || (GL_ELEMENT_ARRAY_BUFFER == target) || (GL_SHADER_STORAGE_BUFFER == target)); if (target == GL_ARRAY_BUFFER) { if (_sg.gl.cache.vertex_buffer != buffer) { _sg.gl.cache.vertex_buffer = buffer; glBindBuffer(target, buffer); _sg_stats_add(gl.num_bind_buffer, 1); } - } else { + } else if (target == GL_ELEMENT_ARRAY_BUFFER) { if (_sg.gl.cache.index_buffer != buffer) { _sg.gl.cache.index_buffer = buffer; glBindBuffer(target, buffer); _sg_stats_add(gl.num_bind_buffer, 1); } + } else if (target == GL_SHADER_STORAGE_BUFFER) { + if (_sg.gl.cache.storage_buffer != buffer) { + _sg.gl.cache.storage_buffer = buffer; + if (_sg.features.storage_buffer) { + glBindBuffer(target, buffer); + } + _sg_stats_add(gl.num_bind_buffer, 1); + } + } else { + SOKOL_UNREACHABLE; + } +} + +_SOKOL_PRIVATE void _sg_gl_cache_bind_storage_buffer(int stage, int slot, GLuint buffer) { + SOKOL_ASSERT((stage >= 0) && (stage < SG_NUM_SHADER_STAGES)); + SOKOL_ASSERT((slot >= 0) && (slot < SG_MAX_SHADERSTAGE_STORAGEBUFFERS)); + if (_sg.gl.cache.stage_storage_buffers[stage][slot] != buffer) { + _sg.gl.cache.stage_storage_buffers[stage][slot] = buffer; + _sg.gl.cache.storage_buffer = buffer; // not a bug + GLuint bind_index = _sg_gl_storagebuffer_bind_index(stage, slot); + if (_sg.features.storage_buffer) { + glBindBufferBase(GL_SHADER_STORAGE_BUFFER, bind_index, buffer); + } + _sg_stats_add(gl.num_bind_buffer, 1); } } _SOKOL_PRIVATE void _sg_gl_cache_store_buffer_binding(GLenum target) { if (target == GL_ARRAY_BUFFER) { _sg.gl.cache.stored_vertex_buffer = _sg.gl.cache.vertex_buffer; - } else { + } else if (target == GL_ELEMENT_ARRAY_BUFFER) { _sg.gl.cache.stored_index_buffer = _sg.gl.cache.index_buffer; + } else if (target == GL_SHADER_STORAGE_BUFFER) { + _sg.gl.cache.stored_storage_buffer = _sg.gl.cache.storage_buffer; + } else { + SOKOL_UNREACHABLE; } } @@ -7615,12 +7891,20 @@ _SOKOL_PRIVATE void _sg_gl_cache_restore_buffer_binding(GLenum target) { _sg_gl_cache_bind_buffer(target, _sg.gl.cache.stored_vertex_buffer); _sg.gl.cache.stored_vertex_buffer = 0; } - } else { + } else if (target == GL_ELEMENT_ARRAY_BUFFER) { if (_sg.gl.cache.stored_index_buffer != 0) { // we only care about restoring valid ids _sg_gl_cache_bind_buffer(target, _sg.gl.cache.stored_index_buffer); _sg.gl.cache.stored_index_buffer = 0; } + } else if (target == GL_SHADER_STORAGE_BUFFER) { + if (_sg.gl.cache.stored_storage_buffer != 0) { + // we only care about restoring valid ids + _sg_gl_cache_bind_buffer(target, _sg.gl.cache.stored_storage_buffer); + _sg.gl.cache.stored_storage_buffer = 0; + } + } else { + SOKOL_UNREACHABLE; } } @@ -7636,12 +7920,31 @@ _SOKOL_PRIVATE void _sg_gl_cache_invalidate_buffer(GLuint buf) { glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); _sg_stats_add(gl.num_bind_buffer, 1); } + if (buf == _sg.gl.cache.storage_buffer) { + _sg.gl.cache.storage_buffer = 0; + glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0); + _sg_stats_add(gl.num_bind_buffer, 1); + } + for (int stage = 0; stage < SG_NUM_SHADER_STAGES; stage++) { + for (int i = 0; i < SG_MAX_SHADERSTAGE_STORAGEBUFFERS; i++) { + if (buf == _sg.gl.cache.stage_storage_buffers[stage][i]) { + _sg.gl.cache.stage_storage_buffers[stage][i] = 0; + _sg.gl.cache.storage_buffer = 0; // not a bug! + const GLuint bind_index = _sg_gl_storagebuffer_bind_index(stage, i); + glBindBufferBase(GL_SHADER_STORAGE_BUFFER, bind_index, 0); + _sg_stats_add(gl.num_bind_buffer, 1); + } + } + } if (buf == _sg.gl.cache.stored_vertex_buffer) { _sg.gl.cache.stored_vertex_buffer = 0; } if (buf == _sg.gl.cache.stored_index_buffer) { _sg.gl.cache.stored_index_buffer = 0; } + if (buf == _sg.gl.cache.stored_storage_buffer) { + _sg.gl.cache.stored_storage_buffer = 0; + } for (int i = 0; i < SG_MAX_VERTEX_ATTRIBUTES; i++) { if (buf == _sg.gl.cache.attrs[i].gl_vbuf) { _sg.gl.cache.attrs[i].gl_vbuf = 0; @@ -7851,7 +8154,7 @@ _SOKOL_PRIVATE void _sg_gl_reset_state_cache(void) { glEnable(GL_DITHER); glDisable(GL_POLYGON_OFFSET_FILL); _sg_stats_add(gl.num_render_state, 10); - #if defined(SOKOL_GLCORE33) + #if defined(SOKOL_GLCORE) glEnable(GL_MULTISAMPLE); glEnable(GL_PROGRAM_POINT_SIZE); _sg_stats_add(gl.num_render_state, 2); @@ -7872,8 +8175,8 @@ _SOKOL_PRIVATE void _sg_gl_setup_backend(const sg_desc* desc) { #if defined(SOKOL_DEBUG) while (glGetError() != GL_NO_ERROR); #endif - #if defined(SOKOL_GLCORE33) - _sg_gl_init_caps_glcore33(); + #if defined(SOKOL_GLCORE) + _sg_gl_init_caps_glcore(); #elif defined(SOKOL_GLES3) _sg_gl_init_caps_gles3(); #endif @@ -7883,7 +8186,7 @@ _SOKOL_PRIVATE void _sg_gl_setup_backend(const sg_desc* desc) { _SG_GL_CHECK_ERROR(); // incoming texture data is generally expected to be packed tightly glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - #if defined(SOKOL_GLCORE33) + #if defined(SOKOL_GLCORE) // enable seamless cubemap sampling (only desktop GL) glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS); #endif @@ -8074,7 +8377,7 @@ _SOKOL_PRIVATE sg_resource_state _sg_gl_create_sampler(_sg_sampler_t* smp, const glSamplerParameteri(smp->gl.smp, GL_TEXTURE_WRAP_S, (GLint)_sg_gl_wrap(smp->cmn.wrap_u)); glSamplerParameteri(smp->gl.smp, GL_TEXTURE_WRAP_T, (GLint)_sg_gl_wrap(smp->cmn.wrap_v)); glSamplerParameteri(smp->gl.smp, GL_TEXTURE_WRAP_R, (GLint)_sg_gl_wrap(smp->cmn.wrap_w)); - #if defined(SOKOL_GLCORE33) + #if defined(SOKOL_GLCORE) float border[4]; switch (smp->cmn.border_color) { case SG_BORDERCOLOR_TRANSPARENT_BLACK: @@ -8558,13 +8861,13 @@ _SOKOL_PRIVATE void _sg_gl_begin_pass(const sg_pass* pass) { if (atts) { // offscreen pass SOKOL_ASSERT(atts->gl.fb); - #if defined(SOKOL_GLCORE33) + #if defined(SOKOL_GLCORE) glEnable(GL_FRAMEBUFFER_SRGB); #endif glBindFramebuffer(GL_FRAMEBUFFER, atts->gl.fb); } else { // default pass - #if defined(SOKOL_GLCORE33) + #if defined(SOKOL_GLCORE) glDisable(GL_FRAMEBUFFER_SRGB); #endif // NOTE: on some platforms, the default framebuffer of a context @@ -8864,7 +9167,7 @@ _SOKOL_PRIVATE void _sg_gl_apply_pipeline(_sg_pipeline_t* pip) { if (pip->gl.color_write_mask[i] != _sg.gl.cache.color_write_mask[i]) { const sg_color_mask cm = pip->gl.color_write_mask[i]; _sg.gl.cache.color_write_mask[i] = cm; - #ifdef SOKOL_GLCORE33 + #ifdef SOKOL_GLCORE glColorMaski(i, (cm & SG_COLORMASK_R) != 0, (cm & SG_COLORMASK_G) != 0, @@ -8921,7 +9224,7 @@ _SOKOL_PRIVATE void _sg_gl_apply_pipeline(_sg_pipeline_t* pip) { } _sg_stats_add(gl.num_render_state, 1); } - #ifdef SOKOL_GLCORE33 + #ifdef SOKOL_GLCORE if (pip->gl.sample_count != _sg.gl.cache.sample_count) { _sg.gl.cache.sample_count = pip->gl.sample_count; if (pip->gl.sample_count > 1) { @@ -8977,6 +9280,18 @@ _SOKOL_PRIVATE bool _sg_gl_apply_bindings(_sg_bindings_t* bnd) { } _SG_GL_CHECK_ERROR(); + // bind storage buffers + for (int slot = 0; slot < bnd->num_vs_sbufs; slot++) { + _sg_buffer_t* sb = bnd->vs_sbufs[slot]; + GLuint gl_sb = sb->gl.buf[sb->cmn.active_slot]; + _sg_gl_cache_bind_storage_buffer(SG_SHADERSTAGE_VS, slot, gl_sb); + } + for (int slot = 0; slot < bnd->num_fs_sbufs; slot++) { + _sg_buffer_t* sb = bnd->fs_sbufs[slot]; + GLuint gl_sb = sb->gl.buf[sb->cmn.active_slot]; + _sg_gl_cache_bind_storage_buffer(SG_SHADERSTAGE_FS, slot, gl_sb); + } + // index buffer (can be 0) const GLuint gl_ib = bnd->ib ? bnd->ib->gl.buf[bnd->ib->cmn.active_slot] : 0; _sg_gl_cache_bind_buffer(GL_ELEMENT_ARRAY_BUFFER, gl_ib); @@ -9092,19 +9407,20 @@ _SOKOL_PRIVATE void _sg_gl_draw(int base_element, int num_elements, int num_inst SOKOL_ASSERT(_sg.gl.cache.cur_pipeline); const GLenum i_type = _sg.gl.cache.cur_index_type; const GLenum p_type = _sg.gl.cache.cur_primitive_type; + const bool use_instanced_draw = (num_instances > 1) || (_sg.gl.cache.cur_pipeline->cmn.use_instanced_draw); if (0 != i_type) { // indexed rendering const int i_size = (i_type == GL_UNSIGNED_SHORT) ? 2 : 4; const int ib_offset = _sg.gl.cache.cur_ib_offset; const GLvoid* indices = (const GLvoid*)(GLintptr)(base_element*i_size+ib_offset); - if (_sg.gl.cache.cur_pipeline->cmn.use_instanced_draw) { + if (use_instanced_draw) { glDrawElementsInstanced(p_type, num_elements, i_type, indices, num_instances); } else { glDrawElements(p_type, num_elements, i_type, indices); } } else { // non-indexed rendering - if (_sg.gl.cache.cur_pipeline->cmn.use_instanced_draw) { + if (use_instanced_draw) { glDrawArraysInstanced(p_type, base_element, num_elements, num_instances); } else { glDrawArrays(p_type, base_element, num_elements); @@ -9210,6 +9526,10 @@ _SOKOL_PRIVATE void _sg_gl_update_image(_sg_image_t* img, const sg_image_data* d // >>d3d11 backend #elif defined(SOKOL_D3D11) +#define _SG_D3D11_MAX_SHADERSTAGE_SRVS (32) +#define _SG_D3D11_SHADERSTAGE_IMAGE_SRV_OFFSET (0) +#define _SG_D3D11_SHADERSTAGE_BUFFER_SRV_OFFSET (16) + #if defined(__cplusplus) #define _sg_d3d11_AddRef(self) (self)->AddRef() #else @@ -9628,6 +9948,34 @@ _SOKOL_PRIVATE D3D11_USAGE _sg_d3d11_usage(sg_usage usg) { } } +_SOKOL_PRIVATE UINT _sg_d3d11_buffer_bind_flags(sg_buffer_type t) { + switch (t) { + case SG_BUFFERTYPE_VERTEXBUFFER: + return D3D11_BIND_VERTEX_BUFFER; + case SG_BUFFERTYPE_INDEXBUFFER: + return D3D11_BIND_INDEX_BUFFER; + case SG_BUFFERTYPE_STORAGEBUFFER: + // FIXME: for compute shaders we'd want UNORDERED_ACCESS? + return D3D11_BIND_SHADER_RESOURCE; + default: + SOKOL_UNREACHABLE; + return 0; + } +} + +_SOKOL_PRIVATE UINT _sg_d3d11_buffer_misc_flags(sg_buffer_type t) { + switch (t) { + case SG_BUFFERTYPE_VERTEXBUFFER: + case SG_BUFFERTYPE_INDEXBUFFER: + return 0; + case SG_BUFFERTYPE_STORAGEBUFFER: + return D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS; + default: + SOKOL_UNREACHABLE; + return 0; + } +} + _SOKOL_PRIVATE UINT _sg_d3d11_cpu_access_flags(sg_usage usg) { switch (usg) { case SG_USAGE_IMMUTABLE: @@ -9936,6 +10284,7 @@ _SOKOL_PRIVATE void _sg_d3d11_init_caps(void) { _sg.features.image_clamp_to_border = true; _sg.features.mrt_independent_blend_state = true; _sg.features.mrt_independent_write_mask = true; + _sg.features.storage_buffer = true; _sg.limits.max_image_size_2d = 16 * 1024; _sg.limits.max_image_size_cube = 16 * 1024; @@ -9994,13 +10343,15 @@ _SOKOL_PRIVATE sg_resource_state _sg_d3d11_create_buffer(_sg_buffer_t* buf, cons if (injected) { buf->d3d11.buf = (ID3D11Buffer*) desc->d3d11_buffer; _sg_d3d11_AddRef(buf->d3d11.buf); + // FIXME: for storage buffers also need to inject resource view } else { - D3D11_BUFFER_DESC d3d11_desc; - _sg_clear(&d3d11_desc, sizeof(d3d11_desc)); - d3d11_desc.ByteWidth = (UINT)buf->cmn.size; - d3d11_desc.Usage = _sg_d3d11_usage(buf->cmn.usage); - d3d11_desc.BindFlags = buf->cmn.type == SG_BUFFERTYPE_VERTEXBUFFER ? D3D11_BIND_VERTEX_BUFFER : D3D11_BIND_INDEX_BUFFER; - d3d11_desc.CPUAccessFlags = _sg_d3d11_cpu_access_flags(buf->cmn.usage); + D3D11_BUFFER_DESC d3d11_buf_desc; + _sg_clear(&d3d11_buf_desc, sizeof(d3d11_buf_desc)); + d3d11_buf_desc.ByteWidth = (UINT)buf->cmn.size; + d3d11_buf_desc.Usage = _sg_d3d11_usage(buf->cmn.usage); + d3d11_buf_desc.BindFlags = _sg_d3d11_buffer_bind_flags(buf->cmn.type); + d3d11_buf_desc.CPUAccessFlags = _sg_d3d11_cpu_access_flags(buf->cmn.usage); + d3d11_buf_desc.MiscFlags = _sg_d3d11_buffer_misc_flags(buf->cmn.type); D3D11_SUBRESOURCE_DATA* init_data_ptr = 0; D3D11_SUBRESOURCE_DATA init_data; _sg_clear(&init_data, sizeof(init_data)); @@ -10009,11 +10360,30 @@ _SOKOL_PRIVATE sg_resource_state _sg_d3d11_create_buffer(_sg_buffer_t* buf, cons init_data.pSysMem = desc->data.ptr; init_data_ptr = &init_data; } - HRESULT hr = _sg_d3d11_CreateBuffer(_sg.d3d11.dev, &d3d11_desc, init_data_ptr, &buf->d3d11.buf); + HRESULT hr = _sg_d3d11_CreateBuffer(_sg.d3d11.dev, &d3d11_buf_desc, init_data_ptr, &buf->d3d11.buf); if (!(SUCCEEDED(hr) && buf->d3d11.buf)) { _SG_ERROR(D3D11_CREATE_BUFFER_FAILED); return SG_RESOURCESTATE_FAILED; } + + // for storage buffers need to create a view object + if (buf->cmn.type == SG_BUFFERTYPE_STORAGEBUFFER) { + // FIXME: currently only shader-resource-view, in future also UAV + // storage buffer size must be multiple of 4 + SOKOL_ASSERT(_sg_multiple_u64(buf->cmn.size, 4)); + D3D11_SHADER_RESOURCE_VIEW_DESC d3d11_srv_desc; + _sg_clear(&d3d11_srv_desc, sizeof(d3d11_srv_desc)); + d3d11_srv_desc.Format = DXGI_FORMAT_R32_TYPELESS; + d3d11_srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFEREX; + d3d11_srv_desc.BufferEx.FirstElement = 0; + d3d11_srv_desc.BufferEx.NumElements = buf->cmn.size / 4; + d3d11_srv_desc.BufferEx.Flags = D3D11_BUFFEREX_SRV_FLAG_RAW; + hr = _sg_d3d11_CreateShaderResourceView(_sg.d3d11.dev, (ID3D11Resource*)buf->d3d11.buf, &d3d11_srv_desc, &buf->d3d11.srv); + if (!(SUCCEEDED(hr) && buf->d3d11.srv)) { + _SG_ERROR(D3D11_CREATE_BUFFER_SRV_FAILED); + return SG_RESOURCESTATE_FAILED; + } + } _sg_d3d11_setlabel(buf->d3d11.buf, desc->label); } return SG_RESOURCESTATE_VALID; @@ -10024,6 +10394,9 @@ _SOKOL_PRIVATE void _sg_d3d11_discard_buffer(_sg_buffer_t* buf) { if (buf->d3d11.buf) { _sg_d3d11_Release(buf->d3d11.buf); } + if (buf->d3d11.srv) { + _sg_d3d11_Release(buf->d3d11.srv); + } } _SOKOL_PRIVATE void _sg_d3d11_fill_subres_data(const _sg_image_t* img, const sg_image_data* data) { @@ -10488,17 +10861,19 @@ _SOKOL_PRIVATE sg_resource_state _sg_d3d11_create_pipeline(_sg_pipeline_t* pip, pip->d3d11.vb_strides[layout_index] = 0; } } - hr = _sg_d3d11_CreateInputLayout(_sg.d3d11.dev, - d3d11_comps, // pInputElementDesc - (UINT)attr_index, // NumElements - shd->d3d11.vs_blob, // pShaderByteCodeWithInputSignature - shd->d3d11.vs_blob_length, // BytecodeLength - &pip->d3d11.il); - if (!(SUCCEEDED(hr) && pip->d3d11.il)) { - _SG_ERROR(D3D11_CREATE_INPUT_LAYOUT_FAILED); - return SG_RESOURCESTATE_FAILED; + if (attr_index > 0) { + hr = _sg_d3d11_CreateInputLayout(_sg.d3d11.dev, + d3d11_comps, // pInputElementDesc + (UINT)attr_index, // NumElements + shd->d3d11.vs_blob, // pShaderByteCodeWithInputSignature + shd->d3d11.vs_blob_length, // BytecodeLength + &pip->d3d11.il); + if (!(SUCCEEDED(hr) && pip->d3d11.il)) { + _SG_ERROR(D3D11_CREATE_INPUT_LAYOUT_FAILED); + return SG_RESOURCESTATE_FAILED; + } + _sg_d3d11_setlabel(pip->d3d11.il, desc->label); } - _sg_d3d11_setlabel(pip->d3d11.il, desc->label); // create rasterizer state D3D11_RASTERIZER_DESC rs_desc; @@ -10901,7 +11276,7 @@ _SOKOL_PRIVATE void _sg_d3d11_apply_pipeline(_sg_pipeline_t* pip) { SOKOL_ASSERT(pip); SOKOL_ASSERT(pip->shader && (pip->cmn.shader_id.id == pip->shader->slot.id)); SOKOL_ASSERT(_sg.d3d11.ctx); - SOKOL_ASSERT(pip->d3d11.rs && pip->d3d11.bs && pip->d3d11.dss && pip->d3d11.il); + SOKOL_ASSERT(pip->d3d11.rs && pip->d3d11.bs && pip->d3d11.dss); _sg.d3d11.cur_pipeline = pip; _sg.d3d11.cur_pipeline_id.id = pip->slot.id; @@ -10937,8 +11312,8 @@ _SOKOL_PRIVATE bool _sg_d3d11_apply_bindings(_sg_bindings_t* bnd) { ID3D11Buffer* d3d11_ib = bnd->ib ? bnd->ib->d3d11.buf : 0; ID3D11Buffer* d3d11_vbs[SG_MAX_VERTEX_BUFFERS] = {0}; UINT d3d11_vb_offsets[SG_MAX_VERTEX_BUFFERS] = {0}; - ID3D11ShaderResourceView* d3d11_vs_srvs[SG_MAX_SHADERSTAGE_IMAGES] = {0}; - ID3D11ShaderResourceView* d3d11_fs_srvs[SG_MAX_SHADERSTAGE_IMAGES] = {0}; + ID3D11ShaderResourceView* d3d11_vs_srvs[_SG_D3D11_MAX_SHADERSTAGE_SRVS] = {0}; + ID3D11ShaderResourceView* d3d11_fs_srvs[_SG_D3D11_MAX_SHADERSTAGE_SRVS] = {0}; ID3D11SamplerState* d3d11_vs_smps[SG_MAX_SHADERSTAGE_SAMPLERS] = {0}; ID3D11SamplerState* d3d11_fs_smps[SG_MAX_SHADERSTAGE_SAMPLERS] = {0}; for (int i = 0; i < bnd->num_vbs; i++) { @@ -10948,11 +11323,19 @@ _SOKOL_PRIVATE bool _sg_d3d11_apply_bindings(_sg_bindings_t* bnd) { } for (int i = 0; i < bnd->num_vs_imgs; i++) { SOKOL_ASSERT(bnd->vs_imgs[i]->d3d11.srv); - d3d11_vs_srvs[i] = bnd->vs_imgs[i]->d3d11.srv; + d3d11_vs_srvs[_SG_D3D11_SHADERSTAGE_IMAGE_SRV_OFFSET + i] = bnd->vs_imgs[i]->d3d11.srv; + } + for (int i = 0; i < bnd->num_vs_sbufs; i++) { + SOKOL_ASSERT(bnd->vs_sbufs[i]->d3d11.srv); + d3d11_vs_srvs[_SG_D3D11_SHADERSTAGE_BUFFER_SRV_OFFSET + i] = bnd->vs_sbufs[i]->d3d11.srv; } for (int i = 0; i < bnd->num_fs_imgs; i++) { SOKOL_ASSERT(bnd->fs_imgs[i]->d3d11.srv); - d3d11_fs_srvs[i] = bnd->fs_imgs[i]->d3d11.srv; + d3d11_fs_srvs[_SG_D3D11_SHADERSTAGE_IMAGE_SRV_OFFSET + i] = bnd->fs_imgs[i]->d3d11.srv; + } + for (int i = 0; i < bnd->num_fs_sbufs; i++) { + SOKOL_ASSERT(bnd->fs_sbufs[i]->d3d11.srv); + d3d11_fs_srvs[_SG_D3D11_SHADERSTAGE_BUFFER_SRV_OFFSET + i] = bnd->fs_sbufs[i]->d3d11.srv; } for (int i = 0; i < bnd->num_vs_smps; i++) { SOKOL_ASSERT(bnd->vs_smps[i]->d3d11.smp); @@ -10964,8 +11347,8 @@ _SOKOL_PRIVATE bool _sg_d3d11_apply_bindings(_sg_bindings_t* bnd) { } _sg_d3d11_IASetVertexBuffers(_sg.d3d11.ctx, 0, SG_MAX_VERTEX_BUFFERS, d3d11_vbs, bnd->pip->d3d11.vb_strides, d3d11_vb_offsets); _sg_d3d11_IASetIndexBuffer(_sg.d3d11.ctx, d3d11_ib, bnd->pip->d3d11.index_format, (UINT)bnd->ib_offset); - _sg_d3d11_VSSetShaderResources(_sg.d3d11.ctx, 0, SG_MAX_SHADERSTAGE_IMAGES, d3d11_vs_srvs); - _sg_d3d11_PSSetShaderResources(_sg.d3d11.ctx, 0, SG_MAX_SHADERSTAGE_IMAGES, d3d11_fs_srvs); + _sg_d3d11_VSSetShaderResources(_sg.d3d11.ctx, 0, _SG_D3D11_MAX_SHADERSTAGE_SRVS, d3d11_vs_srvs); + _sg_d3d11_PSSetShaderResources(_sg.d3d11.ctx, 0, _SG_D3D11_MAX_SHADERSTAGE_SRVS, d3d11_fs_srvs); _sg_d3d11_VSSetSamplers(_sg.d3d11.ctx, 0, SG_MAX_SHADERSTAGE_SAMPLERS, d3d11_vs_smps); _sg_d3d11_PSSetSamplers(_sg.d3d11.ctx, 0, SG_MAX_SHADERSTAGE_SAMPLERS, d3d11_fs_smps); _sg_stats_add(d3d11.bindings.num_ia_set_vertex_buffers, 1); @@ -10990,8 +11373,9 @@ _SOKOL_PRIVATE void _sg_d3d11_apply_uniforms(sg_shader_stage stage_index, int ub } _SOKOL_PRIVATE void _sg_d3d11_draw(int base_element, int num_elements, int num_instances) { + const bool use_instanced_draw = (num_instances > 1) || (_sg.d3d11.use_instanced_draw); if (_sg.d3d11.use_indexed_draw) { - if (_sg.d3d11.use_instanced_draw) { + if (use_instanced_draw) { _sg_d3d11_DrawIndexedInstanced(_sg.d3d11.ctx, (UINT)num_elements, (UINT)num_instances, (UINT)base_element, 0, 0); _sg_stats_add(d3d11.draw.num_draw_indexed_instanced, 1); } else { @@ -10999,7 +11383,7 @@ _SOKOL_PRIVATE void _sg_d3d11_draw(int base_element, int num_elements, int num_i _sg_stats_add(d3d11.draw.num_draw_indexed, 1); } } else { - if (_sg.d3d11.use_instanced_draw) { + if (use_instanced_draw) { _sg_d3d11_DrawInstanced(_sg.d3d11.ctx, (UINT)num_elements, (UINT)num_instances, (UINT)base_element, 0); _sg_stats_add(d3d11.draw.num_draw_instanced, 1); } else { @@ -11276,8 +11660,10 @@ _SOKOL_PRIVATE MTLPixelFormat _sg_mtl_pixel_format(sg_pixel_format fmt) { case SG_PIXELFORMAT_ETC2_RGB8A1: return MTLPixelFormatETC2_RGB8A1; case SG_PIXELFORMAT_ETC2_RGBA8: return MTLPixelFormatEAC_RGBA8; case SG_PIXELFORMAT_ETC2_SRGB8A8: return MTLPixelFormatEAC_RGBA8_sRGB; - case SG_PIXELFORMAT_ETC2_RG11: return MTLPixelFormatEAC_RG11Unorm; - case SG_PIXELFORMAT_ETC2_RG11SN: return MTLPixelFormatEAC_RG11Snorm; + case SG_PIXELFORMAT_EAC_R11: return MTLPixelFormatEAC_R11Unorm; + case SG_PIXELFORMAT_EAC_R11SN: return MTLPixelFormatEAC_R11Snorm; + case SG_PIXELFORMAT_EAC_RG11: return MTLPixelFormatEAC_RG11Unorm; + case SG_PIXELFORMAT_EAC_RG11SN: return MTLPixelFormatEAC_RG11Snorm; case SG_PIXELFORMAT_ASTC_4x4_RGBA: return MTLPixelFormatASTC_4x4_LDR; case SG_PIXELFORMAT_ASTC_4x4_SRGBA: return MTLPixelFormatASTC_4x4_sRGB; #endif @@ -11617,6 +12003,7 @@ _SOKOL_PRIVATE void _sg_mtl_init_caps(void) { _sg.features.origin_top_left = true; _sg.features.mrt_independent_blend_state = true; _sg.features.mrt_independent_write_mask = true; + _sg.features.storage_buffer = true; _sg.features.image_clamp_to_border = false; #if (MAC_OS_X_VERSION_MAX_ALLOWED >= 120000) || (__IPHONE_OS_VERSION_MAX_ALLOWED >= 140000) @@ -11750,8 +12137,10 @@ _SOKOL_PRIVATE void _sg_mtl_init_caps(void) { _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_ETC2_RGB8A1]); _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_ETC2_RGBA8]); _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_ETC2_SRGB8A8]); - _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_ETC2_RG11]); - _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_ETC2_RG11SN]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_EAC_R11]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_EAC_R11SN]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_EAC_RG11]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_EAC_RG11SN]); _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_ASTC_4x4_RGBA]); _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_ASTC_4x4_SRGBA]); @@ -12721,7 +13110,7 @@ _SOKOL_PRIVATE bool _sg_mtl_apply_bindings(_sg_bindings_t* bnd) { } } - // apply vertex shader images + // apply vertex stage images for (NSUInteger slot = 0; slot < (NSUInteger)bnd->num_vs_imgs; slot++) { const _sg_image_t* img = bnd->vs_imgs[slot]; if (_sg.mtl.state_cache.cur_vs_image_ids[slot].id != img->slot.id) { @@ -12732,7 +13121,7 @@ _SOKOL_PRIVATE bool _sg_mtl_apply_bindings(_sg_bindings_t* bnd) { } } - // apply vertex shader samplers + // apply vertex stage samplers for (NSUInteger slot = 0; slot < (NSUInteger)bnd->num_vs_smps; slot++) { const _sg_sampler_t* smp = bnd->vs_smps[slot]; if (_sg.mtl.state_cache.cur_vs_sampler_ids[slot].id != smp->slot.id) { @@ -12743,7 +13132,19 @@ _SOKOL_PRIVATE bool _sg_mtl_apply_bindings(_sg_bindings_t* bnd) { } } - // apply fragment shader images + // apply vertex stage storage buffers + for (NSUInteger slot = 0; slot < (NSUInteger)bnd->num_vs_sbufs; slot++) { + const _sg_buffer_t* sbuf = bnd->vs_sbufs[slot]; + if (_sg.mtl.state_cache.cur_vs_storagebuffer_ids[slot].id != sbuf->slot.id) { + _sg.mtl.state_cache.cur_vs_storagebuffer_ids[slot].id = sbuf->slot.id; + SOKOL_ASSERT(sbuf->mtl.buf[sbuf->cmn.active_slot] != _SG_MTL_INVALID_SLOT_INDEX); + const NSUInteger mtl_slot = SG_MAX_SHADERSTAGE_UBS + SG_MAX_VERTEX_BUFFERS + slot; + [_sg.mtl.cmd_encoder setVertexBuffer:_sg_mtl_id(sbuf->mtl.buf[sbuf->cmn.active_slot]) offset:0 atIndex:mtl_slot]; + _sg_stats_add(metal.bindings.num_set_vertex_buffer, 1); + } + } + + // apply fragment stage images for (NSUInteger slot = 0; slot < (NSUInteger)bnd->num_fs_imgs; slot++) { const _sg_image_t* img = bnd->fs_imgs[slot]; if (_sg.mtl.state_cache.cur_fs_image_ids[slot].id != img->slot.id) { @@ -12754,7 +13155,7 @@ _SOKOL_PRIVATE bool _sg_mtl_apply_bindings(_sg_bindings_t* bnd) { } } - // apply fragment shader samplers + // apply fragment stage samplers for (NSUInteger slot = 0; slot < (NSUInteger)bnd->num_fs_smps; slot++) { const _sg_sampler_t* smp = bnd->fs_smps[slot]; if (_sg.mtl.state_cache.cur_fs_sampler_ids[slot].id != smp->slot.id) { @@ -12764,6 +13165,19 @@ _SOKOL_PRIVATE bool _sg_mtl_apply_bindings(_sg_bindings_t* bnd) { _sg_stats_add(metal.bindings.num_set_fragment_sampler_state, 1); } } + + // apply fragment stage storage buffers + for (NSUInteger slot = 0; slot < (NSUInteger)bnd->num_fs_sbufs; slot++) { + const _sg_buffer_t* sbuf = bnd->fs_sbufs[slot]; + if (_sg.mtl.state_cache.cur_fs_storagebuffer_ids[slot].id != sbuf->slot.id) { + _sg.mtl.state_cache.cur_fs_storagebuffer_ids[slot].id = sbuf->slot.id; + SOKOL_ASSERT(sbuf->mtl.buf[sbuf->cmn.active_slot] != _SG_MTL_INVALID_SLOT_INDEX); + const NSUInteger mtl_slot = SG_MAX_SHADERSTAGE_UBS + slot; + [_sg.mtl.cmd_encoder setFragmentBuffer:_sg_mtl_id(sbuf->mtl.buf[sbuf->cmn.active_slot]) offset:0 atIndex:mtl_slot]; + _sg_stats_add(metal.bindings.num_set_fragment_buffer, 1); + } + } + return true; } @@ -12882,9 +13296,11 @@ _SOKOL_PRIVATE void _sg_mtl_pop_debug_group(void) { _SOKOL_PRIVATE WGPUBufferUsageFlags _sg_wgpu_buffer_usage(sg_buffer_type t, sg_usage u) { WGPUBufferUsageFlags res = 0; if (SG_BUFFERTYPE_VERTEXBUFFER == t) { - res |= WGPUBufferUsage_Vertex; + res = WGPUBufferUsage_Vertex; + } else if (SG_BUFFERTYPE_STORAGEBUFFER == t) { + res = WGPUBufferUsage_Storage; } else { - res |= WGPUBufferUsage_Index; + res = WGPUBufferUsage_Index; } if (SG_USAGE_IMMUTABLE != u) { res |= WGPUBufferUsage_CopyDst; @@ -13128,8 +13544,10 @@ _SOKOL_PRIVATE WGPUTextureFormat _sg_wgpu_textureformat(sg_pixel_format p) { case SG_PIXELFORMAT_ETC2_RGBA8: return WGPUTextureFormat_ETC2RGBA8Unorm; case SG_PIXELFORMAT_ETC2_SRGB8: return WGPUTextureFormat_ETC2RGB8UnormSrgb; case SG_PIXELFORMAT_ETC2_SRGB8A8: return WGPUTextureFormat_ETC2RGBA8UnormSrgb; - case SG_PIXELFORMAT_ETC2_RG11: return WGPUTextureFormat_EACR11Unorm; - case SG_PIXELFORMAT_ETC2_RG11SN: return WGPUTextureFormat_EACR11Snorm; + case SG_PIXELFORMAT_EAC_R11: return WGPUTextureFormat_EACR11Unorm; + case SG_PIXELFORMAT_EAC_R11SN: return WGPUTextureFormat_EACR11Snorm; + case SG_PIXELFORMAT_EAC_RG11: return WGPUTextureFormat_EACRG11Unorm; + case SG_PIXELFORMAT_EAC_RG11SN: return WGPUTextureFormat_EACRG11Snorm; case SG_PIXELFORMAT_RGB9E5: return WGPUTextureFormat_RGB9E5Ufloat; case SG_PIXELFORMAT_ASTC_4x4_RGBA: return WGPUTextureFormat_ASTC4x4Unorm; case SG_PIXELFORMAT_ASTC_4x4_SRGBA: return WGPUTextureFormat_ASTC4x4UnormSrgb; @@ -13241,15 +13659,17 @@ _SOKOL_PRIVATE WGPUColorWriteMaskFlags _sg_wgpu_colorwritemask(uint8_t m) { // - all images and sampler are in @group(1) // - vertex stage images start at @binding(0) // - vertex stage samplers start at @binding(16) -// - fragment stage images start at @binding(32) -// - fragment stage samplers start at @binding(48) +// - vertex stage storage buffers start at @binding(32) +// - fragment stage images start at @binding(48) +// - fragment stage samplers start at @binding(64) +// - fragment stage storage buffers start at @binding(80) // _SOKOL_PRIVATE uint32_t _sg_wgpu_image_binding(sg_shader_stage stage, int img_slot) { SOKOL_ASSERT((img_slot >= 0) && (img_slot < 16)); if (SG_SHADERSTAGE_VS == stage) { return 0 + (uint32_t)img_slot; } else { - return 32 + (uint32_t)img_slot; + return 48 + (uint32_t)img_slot; } } @@ -13258,7 +13678,16 @@ _SOKOL_PRIVATE uint32_t _sg_wgpu_sampler_binding(sg_shader_stage stage, int smp_ if (SG_SHADERSTAGE_VS == stage) { return 16 + (uint32_t)smp_slot; } else { - return 48 + (uint32_t)smp_slot; + return 64 + (uint32_t)smp_slot; + } +} + +_SOKOL_PRIVATE uint32_t _sg_wgpu_storagebuffer_binding(sg_shader_stage stage, int sbuf_slot) { + SOKOL_ASSERT((sbuf_slot >= 0) && (sbuf_slot < 16)); + if (SG_SHADERSTAGE_VS == stage) { + return 32 + (uint32_t)sbuf_slot; + } else { + return 80 + (uint32_t)sbuf_slot; } } @@ -13276,6 +13705,7 @@ _SOKOL_PRIVATE void _sg_wgpu_init_caps(void) { _sg.features.image_clamp_to_border = false; _sg.features.mrt_independent_blend_state = true; _sg.features.mrt_independent_write_mask = true; + _sg.features.storage_buffer = true; wgpuDeviceGetLimits(_sg.wgpu.dev, &_sg.wgpu.limits); @@ -13356,8 +13786,10 @@ _SOKOL_PRIVATE void _sg_wgpu_init_caps(void) { _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_ETC2_RGB8A1]); _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_ETC2_RGBA8]); _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_ETC2_SRGB8A8]); - _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_ETC2_RG11]); - _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_ETC2_RG11SN]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_EAC_R11]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_EAC_R11SN]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_EAC_RG11]); + _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_EAC_RG11SN]); } if (wgpuDeviceHasFeature(_sg.wgpu.dev, WGPUFeatureName_TextureCompressionASTC)) { @@ -13567,16 +13999,20 @@ _SOKOL_PRIVATE void _sg_wgpu_init_bindgroups_cache_key(_sg_wgpu_bindgroups_cache SOKOL_ASSERT(bnd->pip); SOKOL_ASSERT(bnd->num_vs_imgs <= SG_MAX_SHADERSTAGE_IMAGES); SOKOL_ASSERT(bnd->num_vs_smps <= SG_MAX_SHADERSTAGE_SAMPLERS); + SOKOL_ASSERT(bnd->num_vs_sbufs <= SG_MAX_SHADERSTAGE_STORAGEBUFFERS); SOKOL_ASSERT(bnd->num_fs_imgs <= SG_MAX_SHADERSTAGE_IMAGES); SOKOL_ASSERT(bnd->num_fs_smps <= SG_MAX_SHADERSTAGE_SAMPLERS); + SOKOL_ASSERT(bnd->num_fs_sbufs <= SG_MAX_SHADERSTAGE_STORAGEBUFFERS); _sg_clear(key->items, sizeof(key->items)); key->items[0] = bnd->pip->slot.id; const int vs_imgs_offset = 1; const int vs_smps_offset = vs_imgs_offset + SG_MAX_SHADERSTAGE_IMAGES; - const int fs_imgs_offset = vs_smps_offset + SG_MAX_SHADERSTAGE_SAMPLERS; + const int vs_sbufs_offset = vs_smps_offset + SG_MAX_SHADERSTAGE_SAMPLERS; + const int fs_imgs_offset = vs_sbufs_offset + SG_MAX_SHADERSTAGE_STORAGEBUFFERS; const int fs_smps_offset = fs_imgs_offset + SG_MAX_SHADERSTAGE_IMAGES; - SOKOL_ASSERT((fs_smps_offset + SG_MAX_SHADERSTAGE_SAMPLERS) == _SG_WGPU_BINDGROUPSCACHE_NUM_ITEMS); + const int fs_sbufs_offset = fs_smps_offset + SG_MAX_SHADERSTAGE_SAMPLERS; + SOKOL_ASSERT((fs_sbufs_offset + SG_MAX_SHADERSTAGE_STORAGEBUFFERS) == _SG_WGPU_BINDGROUPSCACHE_NUM_ITEMS); for (int i = 0; i < bnd->num_vs_imgs; i++) { SOKOL_ASSERT(bnd->vs_imgs[i]); key->items[vs_imgs_offset + i] = bnd->vs_imgs[i]->slot.id; @@ -13585,6 +14021,10 @@ _SOKOL_PRIVATE void _sg_wgpu_init_bindgroups_cache_key(_sg_wgpu_bindgroups_cache SOKOL_ASSERT(bnd->vs_smps[i]); key->items[vs_smps_offset + i] = bnd->vs_smps[i]->slot.id; } + for (int i = 0; i < bnd->num_vs_sbufs; i++) { + SOKOL_ASSERT(bnd->vs_sbufs[i]); + key->items[vs_sbufs_offset + i] = bnd->vs_sbufs[i]->slot.id; + } for (int i = 0; i < bnd->num_fs_imgs; i++) { SOKOL_ASSERT(bnd->fs_imgs[i]); key->items[fs_imgs_offset + i] = bnd->fs_imgs[i]->slot.id; @@ -13593,6 +14033,10 @@ _SOKOL_PRIVATE void _sg_wgpu_init_bindgroups_cache_key(_sg_wgpu_bindgroups_cache SOKOL_ASSERT(bnd->fs_smps[i]); key->items[fs_smps_offset + i] = bnd->fs_smps[i]->slot.id; } + for (int i = 0; i < bnd->num_fs_sbufs; i++) { + SOKOL_ASSERT(bnd->fs_sbufs[i]); + key->items[fs_sbufs_offset + i] = bnd->fs_sbufs[i]->slot.id; + } key->hash = _sg_wgpu_hash(&key->items, (int)sizeof(key->items), 0x1234567887654321); } @@ -13623,7 +14067,7 @@ _SOKOL_PRIVATE _sg_wgpu_bindgroup_t* _sg_wgpu_create_bindgroup(_sg_bindings_t* b // create wgpu bindgroup object WGPUBindGroupLayout bgl = bnd->pip->shader->wgpu.bind_group_layout; SOKOL_ASSERT(bgl); - WGPUBindGroupEntry wgpu_entries[SG_NUM_SHADER_STAGES * SG_MAX_SHADERSTAGE_IMAGES + SG_MAX_SHADERSTAGE_SAMPLERS]; + WGPUBindGroupEntry wgpu_entries[_SG_WGPU_MAX_BINDGROUP_ENTRIES]; _sg_clear(&wgpu_entries, sizeof(wgpu_entries)); int bge_index = 0; for (int i = 0; i < bnd->num_vs_imgs; i++) { @@ -13636,6 +14080,12 @@ _SOKOL_PRIVATE _sg_wgpu_bindgroup_t* _sg_wgpu_create_bindgroup(_sg_bindings_t* b wgpu_entry->binding = _sg_wgpu_sampler_binding(SG_SHADERSTAGE_VS, i); wgpu_entry->sampler = bnd->vs_smps[i]->wgpu.smp; } + for (int i = 0; i < bnd->num_vs_sbufs; i++) { + WGPUBindGroupEntry* wgpu_entry = &wgpu_entries[bge_index++]; + wgpu_entry->binding = _sg_wgpu_storagebuffer_binding(SG_SHADERSTAGE_VS, i); + wgpu_entry->buffer = bnd->vs_sbufs[i]->wgpu.buf; + wgpu_entry->size = (uint64_t) bnd->vs_sbufs[i]->cmn.size; + } for (int i = 0; i < bnd->num_fs_imgs; i++) { WGPUBindGroupEntry* wgpu_entry = &wgpu_entries[bge_index++]; wgpu_entry->binding = _sg_wgpu_image_binding(SG_SHADERSTAGE_FS, i); @@ -13646,6 +14096,12 @@ _SOKOL_PRIVATE _sg_wgpu_bindgroup_t* _sg_wgpu_create_bindgroup(_sg_bindings_t* b wgpu_entry->binding = _sg_wgpu_sampler_binding(SG_SHADERSTAGE_FS, i); wgpu_entry->sampler = bnd->fs_smps[i]->wgpu.smp; } + for (int i = 0; i < bnd->num_fs_sbufs; i++) { + WGPUBindGroupEntry* wgpu_entry = &wgpu_entries[bge_index++]; + wgpu_entry->binding = _sg_wgpu_storagebuffer_binding(SG_SHADERSTAGE_FS, i); + wgpu_entry->buffer = bnd->fs_sbufs[i]->wgpu.buf; + wgpu_entry->size = (uint64_t) bnd->fs_sbufs[i]->cmn.size; + } WGPUBindGroupDescriptor bg_desc; _sg_clear(&bg_desc, sizeof(bg_desc)); bg_desc.layout = bgl; @@ -13792,7 +14248,7 @@ _SOKOL_PRIVATE void _sg_wgpu_bindings_cache_bg_update(const _sg_wgpu_bindgroup_t } } -_SOKOL_PRIVATE void _sg_wgpu_set_image_sampler_bindgroup(_sg_wgpu_bindgroup_t* bg) { +_SOKOL_PRIVATE void _sg_wgpu_set_bindings_bindgroup(_sg_wgpu_bindgroup_t* bg) { if (_sg_wgpu_bindings_cache_bg_dirty(bg)) { _sg_wgpu_bindings_cache_bg_update(bg); _sg_stats_add(wgpu.bindings.num_set_bindgroup, 1); @@ -13810,7 +14266,7 @@ _SOKOL_PRIVATE void _sg_wgpu_set_image_sampler_bindgroup(_sg_wgpu_bindgroup_t* b } _SOKOL_PRIVATE bool _sg_wgpu_apply_bindgroup(_sg_bindings_t* bnd) { - if ((bnd->num_vs_imgs + bnd->num_vs_smps + bnd->num_fs_imgs + bnd->num_fs_smps) > 0) { + if ((bnd->num_vs_imgs + bnd->num_vs_smps + bnd->num_vs_sbufs + bnd->num_fs_imgs + bnd->num_fs_smps + bnd->num_fs_sbufs) > 0) { if (!_sg.desc.wgpu_disable_bindgroups_cache) { _sg_wgpu_bindgroup_t* bg = 0; _sg_wgpu_bindgroups_cache_key_t key; @@ -13838,7 +14294,7 @@ _SOKOL_PRIVATE bool _sg_wgpu_apply_bindgroup(_sg_bindings_t* bnd) { _sg_wgpu_bindgroups_cache_set(key.hash, bg->slot.id); } if (bg && bg->slot.state == SG_RESOURCESTATE_VALID) { - _sg_wgpu_set_image_sampler_bindgroup(bg); + _sg_wgpu_set_bindings_bindgroup(bg); } else { return false; } @@ -13847,7 +14303,7 @@ _SOKOL_PRIVATE bool _sg_wgpu_apply_bindgroup(_sg_bindings_t* bnd) { _sg_wgpu_bindgroup_t* bg = _sg_wgpu_create_bindgroup(bnd); if (bg) { if (bg->slot.state == SG_RESOURCESTATE_VALID) { - _sg_wgpu_set_image_sampler_bindgroup(bg); + _sg_wgpu_set_bindings_bindgroup(bg); } _sg_wgpu_discard_bindgroup(bg); } else { @@ -13855,10 +14311,11 @@ _SOKOL_PRIVATE bool _sg_wgpu_apply_bindgroup(_sg_bindings_t* bnd) { } } } else { - _sg_wgpu_set_image_sampler_bindgroup(0); + _sg_wgpu_set_bindings_bindgroup(0); } return true; } + _SOKOL_PRIVATE bool _sg_wgpu_apply_index_buffer(_sg_bindings_t* bnd) { if (_sg_wgpu_bindings_cache_ib_dirty(bnd->ib, bnd->ib_offset)) { _sg_wgpu_bindings_cache_ib_update(bnd->ib, bnd->ib_offset); @@ -14180,8 +14637,7 @@ _SOKOL_PRIVATE sg_resource_state _sg_wgpu_create_shader(_sg_shader_t* shd, const SOKOL_ASSERT(shd && desc); SOKOL_ASSERT(desc->vs.source && desc->fs.source); - #define _sg_wgpu_create_shader_max_bgl_entries (SG_NUM_SHADER_STAGES * (SG_MAX_SHADERSTAGE_IMAGES + SG_MAX_SHADERSTAGE_SAMPLERS)) - WGPUBindGroupLayoutEntry wgpu_bgl_entries[_sg_wgpu_create_shader_max_bgl_entries]; + WGPUBindGroupLayoutEntry wgpu_bgl_entries[_SG_WGPU_MAX_BINDGROUP_ENTRIES]; _sg_clear(wgpu_bgl_entries, sizeof(wgpu_bgl_entries)); int bgl_index = 0; for (int stage_index = 0; stage_index < SG_NUM_SHADER_STAGES; stage_index++) { @@ -14217,8 +14673,13 @@ _SOKOL_PRIVATE sg_resource_state _sg_wgpu_create_shader(_sg_shader_t* shd, const _SG_ERROR(WGPU_SHADER_TOO_MANY_SAMPLERS); return SG_RESOURCESTATE_FAILED; } + const int num_sbufs = cmn_stage->num_storage_buffers; + if (num_sbufs > (int)_sg.wgpu.limits.limits.maxStorageBuffersPerShaderStage) { + _SG_ERROR(WGPU_SHADER_TOO_MANY_STORAGEBUFFERS); + return SG_RESOURCESTATE_FAILED; + } for (int img_index = 0; img_index < num_images; img_index++) { - SOKOL_ASSERT(bgl_index < _sg_wgpu_create_shader_max_bgl_entries); + SOKOL_ASSERT(bgl_index < _SG_WGPU_MAX_BINDGROUP_ENTRIES); WGPUBindGroupLayoutEntry* wgpu_bgl_entry = &wgpu_bgl_entries[bgl_index++]; const sg_shader_image_desc* img_desc = &stage_desc->images[img_index]; wgpu_bgl_entry->binding = _sg_wgpu_image_binding((sg_shader_stage)stage_index, img_index); @@ -14228,13 +14689,21 @@ _SOKOL_PRIVATE sg_resource_state _sg_wgpu_create_shader(_sg_shader_t* shd, const wgpu_bgl_entry->texture.multisampled = img_desc->multisampled; } for (int smp_index = 0; smp_index < num_samplers; smp_index++) { - SOKOL_ASSERT(bgl_index < _sg_wgpu_create_shader_max_bgl_entries); + SOKOL_ASSERT(bgl_index < _SG_WGPU_MAX_BINDGROUP_ENTRIES); WGPUBindGroupLayoutEntry* wgpu_bgl_entry = &wgpu_bgl_entries[bgl_index++]; const sg_shader_sampler_desc* smp_desc = &stage_desc->samplers[smp_index]; - wgpu_bgl_entry->binding =_sg_wgpu_sampler_binding((sg_shader_stage)stage_index, smp_index); + wgpu_bgl_entry->binding = _sg_wgpu_sampler_binding((sg_shader_stage)stage_index, smp_index); wgpu_bgl_entry->visibility = _sg_wgpu_shader_stage((sg_shader_stage)stage_index); wgpu_bgl_entry->sampler.type = _sg_wgpu_sampler_binding_type(smp_desc->sampler_type); } + for (int sbuf_index = 0; sbuf_index < num_sbufs; sbuf_index++) { + SOKOL_ASSERT(bgl_index < _SG_WGPU_MAX_BINDGROUP_ENTRIES); + WGPUBindGroupLayoutEntry* wgpu_bgl_entry = &wgpu_bgl_entries[bgl_index++]; + const sg_shader_storage_buffer_desc* sbuf_desc = &stage_desc->storage_buffers[sbuf_index]; + wgpu_bgl_entry->binding = _sg_wgpu_storagebuffer_binding((sg_shader_stage)stage_index, sbuf_index); + wgpu_bgl_entry->visibility = _sg_wgpu_shader_stage((sg_shader_stage)stage_index); + wgpu_bgl_entry->buffer.type = sbuf_desc->readonly ? WGPUBufferBindingType_ReadOnlyStorage : WGPUBufferBindingType_Storage; + } } WGPUBindGroupLayoutDescriptor wgpu_bgl_desc; @@ -14246,8 +14715,6 @@ _SOKOL_PRIVATE sg_resource_state _sg_wgpu_create_shader(_sg_shader_t* shd, const _SG_ERROR(WGPU_SHADER_CREATE_BINDGROUP_LAYOUT_FAILED); return SG_RESOURCESTATE_FAILED; } - - #undef _sg_wgpu_create_shader_max_bgl_entries return SG_RESOURCESTATE_VALID; } @@ -15625,6 +16092,10 @@ _SOKOL_PRIVATE bool _sg_validate_buffer_desc(const sg_buffer_desc* desc) { } else { _SG_VALIDATE(0 == desc->data.ptr, VALIDATE_BUFFERDESC_NO_DATA); } + if (desc->type == SG_BUFFERTYPE_STORAGEBUFFER) { + _SG_VALIDATE(_sg.features.storage_buffer, VALIDATE_BUFFERDESC_STORAGEBUFFER_SUPPORTED); + _SG_VALIDATE(_sg_multiple_u64(desc->size, 4), VALIDATE_BUFFERDESC_STORAGEBUFFER_SIZE_MULTIPLE_4); + } return _sg_validate_end(); #endif } @@ -15762,10 +16233,7 @@ _SOKOL_PRIVATE bool _sg_validate_shader_desc(const sg_shader_desc* desc) { _sg_validate_begin(); _SG_VALIDATE(desc->_start_canary == 0, VALIDATE_SHADERDESC_CANARY); _SG_VALIDATE(desc->_end_canary == 0, VALIDATE_SHADERDESC_CANARY); - #if defined(SOKOL_D3D11) - _SG_VALIDATE(0 != desc->attrs[0].sem_name, VALIDATE_SHADERDESC_ATTR_SEMANTICS); - #endif - #if defined(SOKOL_GLCORE33) || defined(SOKOL_GLES3) || defined(SOKOL_WGPU) + #if defined(SOKOL_GLCORE) || defined(SOKOL_GLES3) || defined(SOKOL_WGPU) // on GL or WebGPU, must provide shader source code _SG_VALIDATE(0 != desc->vs.source, VALIDATE_SHADERDESC_SOURCE); _SG_VALIDATE(0 != desc->fs.source, VALIDATE_SHADERDESC_SOURCE); @@ -15836,6 +16304,16 @@ _SOKOL_PRIVATE bool _sg_validate_shader_desc(const sg_shader_desc* desc) { uniform_blocks_continuous = false; } } + bool storage_buffers_continuous = true; + for (int sbuf_index = 0; sbuf_index < SG_MAX_SHADERSTAGE_STORAGEBUFFERS; sbuf_index++) { + const sg_shader_storage_buffer_desc* sbuf_desc = &stage_desc->storage_buffers[sbuf_index]; + if (sbuf_desc->used) { + _SG_VALIDATE(storage_buffers_continuous, VALIDATE_SHADERDESC_NO_CONT_STORAGEBUFFERS); + _SG_VALIDATE(sbuf_desc->readonly, VALIDATE_SHADERDESC_STORAGEBUFFER_READONLY); + } else { + storage_buffers_continuous = false; + } + } bool images_continuous = true; int num_images = 0; for (int img_index = 0; img_index < SG_MAX_SHADERSTAGE_IMAGES; img_index++) { @@ -15930,7 +16408,6 @@ _SOKOL_PRIVATE bool _sg_validate_pipeline_desc(const sg_pipeline_desc* desc) { } _SG_VALIDATE(_sg_multiple_u64((uint64_t)l_state->stride, 4), VALIDATE_PIPELINEDESC_LAYOUT_STRIDE4); } - _SG_VALIDATE(desc->layout.attrs[0].format != SG_VERTEXFORMAT_INVALID, VALIDATE_PIPELINEDESC_NO_ATTRS); const _sg_shader_t* shd = _sg_lookup_shader(&_sg.pools, desc->shader.id); _SG_VALIDATE(0 != shd, VALIDATE_PIPELINEDESC_SHADER); if (shd) { @@ -15942,7 +16419,7 @@ _SOKOL_PRIVATE bool _sg_validate_pipeline_desc(const sg_pipeline_desc* desc) { attrs_cont = false; continue; } - _SG_VALIDATE(attrs_cont, VALIDATE_PIPELINEDESC_NO_ATTRS); + _SG_VALIDATE(attrs_cont, VALIDATE_PIPELINEDESC_NO_CONT_ATTRS); SOKOL_ASSERT(a_state->buffer_index < SG_MAX_VERTEX_BUFFERS); #if defined(SOKOL_D3D11) // on D3D11, semantic names (and semantic indices) must be provided @@ -16329,6 +16806,23 @@ _SOKOL_PRIVATE bool _sg_validate_apply_bindings(const sg_bindings* bindings) { } } + // has expected vertex shader storage buffers + for (int i = 0; i < SG_MAX_SHADERSTAGE_STORAGEBUFFERS; i++) { + const _sg_shader_stage_t* stage = &pip->shader->cmn.stage[SG_SHADERSTAGE_VS]; + if (stage->storage_buffers[i].used) { + _SG_VALIDATE(bindings->vs.storage_buffers[i].id != SG_INVALID_ID, VALIDATE_ABND_VS_EXPECTED_STORAGEBUFFER_BINDING); + if (bindings->vs.storage_buffers[i].id != SG_INVALID_ID) { + const _sg_buffer_t* sbuf = _sg_lookup_buffer(&_sg.pools, bindings->vs.storage_buffers[i].id); + _SG_VALIDATE(sbuf != 0, VALIDATE_ABND_VS_STORAGEBUFFER_EXISTS); + if (sbuf) { + _SG_VALIDATE(sbuf->cmn.type == SG_BUFFERTYPE_STORAGEBUFFER, VALIDATE_ABND_VS_STORAGEBUFFER_BINDING_BUFFERTYPE); + } + } + } else { + _SG_VALIDATE(bindings->vs.storage_buffers[i].id == SG_INVALID_ID, VALIDATE_ABND_VS_UNEXPECTED_STORAGEBUFFER_BINDING); + } + } + // has expected fragment shader images for (int i = 0; i < SG_MAX_SHADERSTAGE_IMAGES; i++) { const _sg_shader_stage_t* stage = &pip->shader->cmn.stage[SG_SHADERSTAGE_FS]; @@ -16384,6 +16878,24 @@ _SOKOL_PRIVATE bool _sg_validate_apply_bindings(const sg_bindings* bindings) { _SG_VALIDATE(bindings->fs.samplers[i].id == SG_INVALID_ID, VALIDATE_ABND_FS_UNEXPECTED_SAMPLER_BINDING); } } + + // has expected fragment shader storage buffers + for (int i = 0; i < SG_MAX_SHADERSTAGE_STORAGEBUFFERS; i++) { + const _sg_shader_stage_t* stage = &pip->shader->cmn.stage[SG_SHADERSTAGE_FS]; + if (stage->storage_buffers[i].used) { + _SG_VALIDATE(bindings->fs.storage_buffers[i].id != SG_INVALID_ID, VALIDATE_ABND_FS_EXPECTED_STORAGEBUFFER_BINDING); + if (bindings->fs.storage_buffers[i].id != SG_INVALID_ID) { + const _sg_buffer_t* sbuf = _sg_lookup_buffer(&_sg.pools, bindings->fs.storage_buffers[i].id); + _SG_VALIDATE(sbuf != 0, VALIDATE_ABND_FS_STORAGEBUFFER_EXISTS); + if (sbuf) { + _SG_VALIDATE(sbuf->cmn.type == SG_BUFFERTYPE_STORAGEBUFFER, VALIDATE_ABND_FS_STORAGEBUFFER_BINDING_BUFFERTYPE); + } + } + } else { + _SG_VALIDATE(bindings->fs.storage_buffers[i].id == SG_INVALID_ID, VALIDATE_ABND_FS_UNEXPECTED_STORAGEBUFFER_BINDING); + } + } + return _sg_validate_end(); #endif } @@ -17823,7 +18335,6 @@ SOKOL_API_IMPL void sg_apply_pipeline(sg_pipeline pip_id) { SOKOL_ASSERT(_sg.valid); SOKOL_ASSERT(_sg.cur_pass.in_pass); _sg_stats_add(num_apply_pipeline, 1); - _sg.apply_bindings_called = false; if (!_sg_validate_apply_pipeline(pip_id)) { _sg.next_draw_valid = false; return; @@ -17846,7 +18357,6 @@ SOKOL_API_IMPL void sg_apply_bindings(const sg_bindings* bindings) { SOKOL_ASSERT(bindings); SOKOL_ASSERT((bindings->_start_canary == 0) && (bindings->_end_canary==0)); _sg_stats_add(num_apply_bindings, 1); - _sg.apply_bindings_called = true; if (!_sg_validate_apply_bindings(bindings)) { _sg.next_draw_valid = false; return; @@ -17914,6 +18424,19 @@ SOKOL_API_IMPL void sg_apply_bindings(const sg_bindings* bindings) { } } + for (int i = 0; i < SG_MAX_SHADERSTAGE_STORAGEBUFFERS; i++, bnd.num_vs_sbufs++) { + if (bindings->vs.storage_buffers[i].id) { + bnd.vs_sbufs[i] = _sg_lookup_buffer(&_sg.pools, bindings->vs.storage_buffers[i].id); + if (bnd.vs_sbufs[i]) { + _sg.next_draw_valid &= (SG_RESOURCESTATE_VALID == bnd.vs_sbufs[i]->slot.state); + } else { + _sg.next_draw_valid = false; + } + } else { + break; + } + } + for (int i = 0; i < SG_MAX_SHADERSTAGE_IMAGES; i++, bnd.num_fs_imgs++) { if (bindings->fs.images[i].id) { bnd.fs_imgs[i] = _sg_lookup_image(&_sg.pools, bindings->fs.images[i].id); @@ -17940,6 +18463,18 @@ SOKOL_API_IMPL void sg_apply_bindings(const sg_bindings* bindings) { } } + for (int i = 0; i < SG_MAX_SHADERSTAGE_STORAGEBUFFERS; i++, bnd.num_fs_sbufs++) { + if (bindings->fs.storage_buffers[i].id) { + bnd.fs_sbufs[i] = _sg_lookup_buffer(&_sg.pools, bindings->fs.storage_buffers[i].id); + if (bnd.fs_sbufs[i]) { + _sg.next_draw_valid &= (SG_RESOURCESTATE_VALID == bnd.fs_sbufs[i]->slot.state); + } else { + _sg.next_draw_valid = false; + } + } else { + break; + } + } if (_sg.next_draw_valid) { _sg.next_draw_valid &= _sg_apply_bindings(&bnd); _SG_TRACE_ARGS(apply_bindings, bindings); @@ -17975,20 +18510,12 @@ SOKOL_API_IMPL void sg_draw(int base_element, int num_elements, int num_instance SOKOL_ASSERT(num_elements >= 0); SOKOL_ASSERT(num_instances >= 0); _sg_stats_add(num_draw, 1); - #if defined(SOKOL_DEBUG) - if (!_sg.apply_bindings_called) { - _SG_WARN(DRAW_WITHOUT_BINDINGS); - } - #endif if (!_sg.cur_pass.valid) { return; } if (!_sg.next_draw_valid) { return; } - if (!_sg.apply_bindings_called) { - return; - } /* attempting to draw with zero elements or instances is not technically an error, but might be handled as an error in the backend API (e.g. on Metal) */ diff --git a/src/sokol/c/sokol_gl.h b/src/sokol/c/sokol_gl.h index 997ddea..15b3880 100644 --- a/src/sokol/c/sokol_gl.h +++ b/src/sokol/c/sokol_gl.h @@ -17,7 +17,7 @@ platform-specific embedded shader code (these are the same defines as used by sokol_gfx.h and sokol_app.h): - SOKOL_GLCORE33 + SOKOL_GLCORE SOKOL_GLES3 SOKOL_D3D11 SOKOL_METAL @@ -973,7 +973,7 @@ inline sgl_pipeline sgl_context_make_pipeline(sgl_context ctx, const sg_pipeline /* Embedded source code compiled with: - sokol-shdc -i sgl.glsl -o sgl.h -l glsl330:glsl300es:hlsl4:metal_macos:metal_ios:metal_sim:wgpu -b + sokol-shdc -i sgl.glsl -o sgl.h -l glsl410:glsl300es:hlsl4:metal_macos:metal_ios:metal_sim:wgpu -b (not that for Metal and D3D11 byte code, sokol-shdc must be run on macOS and Windows) @@ -1013,55 +1013,60 @@ inline sgl_pipeline sgl_context_make_pipeline(sgl_context ctx, const sg_pipeline @program sgl vs fs */ -#if defined(SOKOL_GLCORE33) -static const char _sgl_vs_source_glsl330[478] = { - 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x33,0x30,0x0a,0x0a,0x75,0x6e, +#if defined(SOKOL_GLCORE) +static const uint8_t _sgl_vs_source_glsl410[520] = { + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x31,0x30,0x0a,0x0a,0x75,0x6e, 0x69,0x66,0x6f,0x72,0x6d,0x20,0x76,0x65,0x63,0x34,0x20,0x76,0x73,0x5f,0x70,0x61, 0x72,0x61,0x6d,0x73,0x5b,0x38,0x5d,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28, 0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e, 0x20,0x76,0x65,0x63,0x34,0x20,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a, 0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20, 0x3d,0x20,0x33,0x29,0x20,0x69,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x73, - 0x69,0x7a,0x65,0x3b,0x0a,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x75,0x76, - 0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f, - 0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x32,0x20,0x74, - 0x65,0x78,0x63,0x6f,0x6f,0x72,0x64,0x30,0x3b,0x0a,0x6f,0x75,0x74,0x20,0x76,0x65, - 0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74, - 0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x32,0x29,0x20,0x69, - 0x6e,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x0a, - 0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20, - 0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, - 0x6d,0x61,0x74,0x34,0x28,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x30, - 0x5d,0x2c,0x20,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x31,0x5d,0x2c, - 0x20,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x32,0x5d,0x2c,0x20,0x76, - 0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x33,0x5d,0x29,0x20,0x2a,0x20,0x70, - 0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f, - 0x50,0x6f,0x69,0x6e,0x74,0x53,0x69,0x7a,0x65,0x20,0x3d,0x20,0x70,0x73,0x69,0x7a, - 0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x75,0x76,0x20,0x3d,0x20,0x6d,0x61,0x74,0x34, - 0x28,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x34,0x5d,0x2c,0x20,0x76, - 0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x35,0x5d,0x2c,0x20,0x76,0x73,0x5f, - 0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x36,0x5d,0x2c,0x20,0x76,0x73,0x5f,0x70,0x61, - 0x72,0x61,0x6d,0x73,0x5b,0x37,0x5d,0x29,0x20,0x2a,0x20,0x76,0x65,0x63,0x34,0x28, - 0x74,0x65,0x78,0x63,0x6f,0x6f,0x72,0x64,0x30,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20, - 0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20, - 0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, + 0x69,0x7a,0x65,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61, + 0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65, + 0x63,0x34,0x20,0x75,0x76,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f, + 0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x69,0x6e,0x20,0x76, + 0x65,0x63,0x32,0x20,0x74,0x65,0x78,0x63,0x6f,0x6f,0x72,0x64,0x30,0x3b,0x0a,0x6c, + 0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d, + 0x20,0x31,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c, + 0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74, + 0x69,0x6f,0x6e,0x20,0x3d,0x20,0x32,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x34, + 0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d, + 0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50, + 0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x6d,0x61,0x74,0x34,0x28,0x76, + 0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x30,0x5d,0x2c,0x20,0x76,0x73,0x5f, + 0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x31,0x5d,0x2c,0x20,0x76,0x73,0x5f,0x70,0x61, + 0x72,0x61,0x6d,0x73,0x5b,0x32,0x5d,0x2c,0x20,0x76,0x73,0x5f,0x70,0x61,0x72,0x61, + 0x6d,0x73,0x5b,0x33,0x5d,0x29,0x20,0x2a,0x20,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f, + 0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x69,0x6e,0x74,0x53, + 0x69,0x7a,0x65,0x20,0x3d,0x20,0x70,0x73,0x69,0x7a,0x65,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x75,0x76,0x20,0x3d,0x20,0x6d,0x61,0x74,0x34,0x28,0x76,0x73,0x5f,0x70,0x61, + 0x72,0x61,0x6d,0x73,0x5b,0x34,0x5d,0x2c,0x20,0x76,0x73,0x5f,0x70,0x61,0x72,0x61, + 0x6d,0x73,0x5b,0x35,0x5d,0x2c,0x20,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73, + 0x5b,0x36,0x5d,0x2c,0x20,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x37, + 0x5d,0x29,0x20,0x2a,0x20,0x76,0x65,0x63,0x34,0x28,0x74,0x65,0x78,0x63,0x6f,0x6f, + 0x72,0x64,0x30,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f, + 0x72,0x30,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, }; -static const char _sgl_fs_source_glsl330[180] = { - 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x33,0x30,0x0a,0x0a,0x75,0x6e, +static const uint8_t _sgl_fs_source_glsl410[222] = { + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x31,0x30,0x0a,0x0a,0x75,0x6e, 0x69,0x66,0x6f,0x72,0x6d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x32,0x44,0x20, 0x74,0x65,0x78,0x5f,0x73,0x6d,0x70,0x3b,0x0a,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74, 0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x6f, 0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c, - 0x6f,0x72,0x3b,0x0a,0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20,0x75,0x76,0x3b,0x0a, - 0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x0a, - 0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x74, - 0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x74,0x65,0x78,0x5f,0x73,0x6d,0x70,0x2c,0x20, - 0x75,0x76,0x2e,0x78,0x79,0x29,0x20,0x2a,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a, - 0x7d,0x0a,0x0a,0x00, + 0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74, + 0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x34, + 0x20,0x75,0x76,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61, + 0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63, + 0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d, + 0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67, + 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65, + 0x28,0x74,0x65,0x78,0x5f,0x73,0x6d,0x70,0x2c,0x20,0x75,0x76,0x2e,0x78,0x79,0x29, + 0x20,0x2a,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, }; #elif defined(SOKOL_GLES3) -static const char _sgl_vs_source_glsl300es[481] = { +static const uint8_t _sgl_vs_source_glsl300es[481] = { 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x30,0x30,0x20,0x65,0x73,0x0a, 0x0a,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x76,0x65,0x63,0x34,0x20,0x76,0x73, 0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x38,0x5d,0x3b,0x0a,0x6c,0x61,0x79,0x6f, @@ -1094,7 +1099,7 @@ static const char _sgl_vs_source_glsl300es[481] = { 0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x7d,0x0a,0x0a, 0x00, }; -static const char _sgl_fs_source_glsl300es[253] = { +static const uint8_t _sgl_fs_source_glsl300es[253] = { 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x30,0x30,0x20,0x65,0x73,0x0a, 0x70,0x72,0x65,0x63,0x69,0x73,0x69,0x6f,0x6e,0x20,0x6d,0x65,0x64,0x69,0x75,0x6d, 0x70,0x20,0x66,0x6c,0x6f,0x61,0x74,0x3b,0x0a,0x70,0x72,0x65,0x63,0x69,0x73,0x69, @@ -1890,7 +1895,7 @@ static const uint8_t _sgl_fs_bytecode_metal_ios[2809] = { 0x42,0x40,0x29,0x49,0x50,0x20,0x86,0x60,0x01,0x23,0x9f,0xd9,0x06,0x23,0x00,0x32, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, }; -static const char _sgl_vs_source_metal_sim[756] = { +static const uint8_t _sgl_vs_source_metal_sim[756] = { 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, 0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65, 0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a, @@ -1940,7 +1945,7 @@ static const char _sgl_vs_source_metal_sim[756] = { 0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a, 0x7d,0x0a,0x0a,0x00, }; -static const char _sgl_fs_source_metal_sim[439] = { +static const uint8_t _sgl_fs_source_metal_sim[439] = { 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, 0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65, 0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a, @@ -2080,7 +2085,7 @@ static const uint8_t _sgl_fs_bytecode_hlsl4[608] = { }; #elif defined(SOKOL_WGPU) -static const char _sgl_vs_source_wgsl[1162] = { +static const uint8_t _sgl_vs_source_wgsl[1162] = { 0x64,0x69,0x61,0x67,0x6e,0x6f,0x73,0x74,0x69,0x63,0x28,0x6f,0x66,0x66,0x2c,0x20, 0x64,0x65,0x72,0x69,0x76,0x61,0x74,0x69,0x76,0x65,0x5f,0x75,0x6e,0x69,0x66,0x6f, 0x72,0x6d,0x69,0x74,0x79,0x29,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20, @@ -2155,17 +2160,17 @@ static const char _sgl_vs_source_wgsl[1162] = { 0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x2c,0x20,0x75,0x76,0x2c,0x20,0x63,0x6f, 0x6c,0x6f,0x72,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, }; -static const char _sgl_fs_source_wgsl[647] = { +static const uint8_t _sgl_fs_source_wgsl[647] = { 0x64,0x69,0x61,0x67,0x6e,0x6f,0x73,0x74,0x69,0x63,0x28,0x6f,0x66,0x66,0x2c,0x20, 0x64,0x65,0x72,0x69,0x76,0x61,0x74,0x69,0x76,0x65,0x5f,0x75,0x6e,0x69,0x66,0x6f, 0x72,0x6d,0x69,0x74,0x79,0x29,0x3b,0x0a,0x0a,0x76,0x61,0x72,0x3c,0x70,0x72,0x69, 0x76,0x61,0x74,0x65,0x3e,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72, 0x20,0x3a,0x20,0x76,0x65,0x63,0x34,0x66,0x3b,0x0a,0x0a,0x40,0x67,0x72,0x6f,0x75, - 0x70,0x28,0x31,0x29,0x20,0x40,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x28,0x33,0x32, + 0x70,0x28,0x31,0x29,0x20,0x40,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x28,0x34,0x38, 0x29,0x20,0x76,0x61,0x72,0x20,0x74,0x65,0x78,0x20,0x3a,0x20,0x74,0x65,0x78,0x74, 0x75,0x72,0x65,0x5f,0x32,0x64,0x3c,0x66,0x33,0x32,0x3e,0x3b,0x0a,0x0a,0x40,0x67, 0x72,0x6f,0x75,0x70,0x28,0x31,0x29,0x20,0x40,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67, - 0x28,0x34,0x38,0x29,0x20,0x76,0x61,0x72,0x20,0x73,0x6d,0x70,0x20,0x3a,0x20,0x73, + 0x28,0x36,0x34,0x29,0x20,0x76,0x61,0x72,0x20,0x73,0x6d,0x70,0x20,0x3a,0x20,0x73, 0x61,0x6d,0x70,0x6c,0x65,0x72,0x3b,0x0a,0x0a,0x76,0x61,0x72,0x3c,0x70,0x72,0x69, 0x76,0x61,0x74,0x65,0x3e,0x20,0x75,0x76,0x20,0x3a,0x20,0x76,0x65,0x63,0x34,0x66, 0x3b,0x0a,0x0a,0x76,0x61,0x72,0x3c,0x70,0x72,0x69,0x76,0x61,0x74,0x65,0x3e,0x20, @@ -2202,7 +2207,7 @@ static const char _sgl_fs_source_wgsl[647] = { static const char* _sgl_vs_source_dummy = ""; static const char* _sgl_fs_source_dummy = ""; #else -#error "Please define one of SOKOL_GLCORE33, SOKOL_GLES3, SOKOL_D3D11, SOKOL_METAL, SOKOL_WGPU or SOKOL_DUMMY_BACKEND!" +#error "Please define one of SOKOL_GLCORE, SOKOL_GLES3, SOKOL_D3D11, SOKOL_METAL, SOKOL_WGPU or SOKOL_DUMMY_BACKEND!" #endif // ████████ ██ ██ ██████ ███████ ███████ @@ -3284,12 +3289,12 @@ static void _sgl_setup_common(void) { shd_desc.fs.image_sampler_pairs[0].sampler_slot = 0; shd_desc.fs.image_sampler_pairs[0].glsl_name = "tex_smp"; shd_desc.label = "sgl-shader"; - #if defined(SOKOL_GLCORE33) - shd_desc.vs.source = _sgl_vs_source_glsl330; - shd_desc.fs.source = _sgl_fs_source_glsl330; + #if defined(SOKOL_GLCORE) + shd_desc.vs.source = (const char*)_sgl_vs_source_glsl410; + shd_desc.fs.source = (const char*)_sgl_fs_source_glsl410; #elif defined(SOKOL_GLES3) - shd_desc.vs.source = _sgl_vs_source_glsl300es; - shd_desc.fs.source = _sgl_fs_source_glsl300es; + shd_desc.vs.source = (const char*)_sgl_vs_source_glsl300es; + shd_desc.fs.source = (const char*)_sgl_fs_source_glsl300es; #elif defined(SOKOL_METAL) shd_desc.vs.entry = "main0"; shd_desc.fs.entry = "main0"; @@ -3303,16 +3308,16 @@ static void _sgl_setup_common(void) { shd_desc.fs.bytecode = SG_RANGE(_sgl_fs_bytecode_metal_ios); break; default: - shd_desc.vs.source = _sgl_vs_source_metal_sim; - shd_desc.fs.source = _sgl_fs_source_metal_sim; + shd_desc.vs.source = (const char*)_sgl_vs_source_metal_sim; + shd_desc.fs.source = (const char*)_sgl_fs_source_metal_sim; break; } #elif defined(SOKOL_D3D11) shd_desc.vs.bytecode = SG_RANGE(_sgl_vs_bytecode_hlsl4); shd_desc.fs.bytecode = SG_RANGE(_sgl_fs_bytecode_hlsl4); #elif defined(SOKOL_WGPU) - shd_desc.vs.source = _sgl_vs_source_wgsl; - shd_desc.fs.source = _sgl_fs_source_wgsl; + shd_desc.vs.source = (const char*)_sgl_vs_source_wgsl; + shd_desc.fs.source = (const char*)_sgl_fs_source_wgsl; #else shd_desc.vs.source = _sgl_vs_source_dummy; shd_desc.fs.source = _sgl_fs_source_dummy; diff --git a/src/sokol/debugtext.d b/src/sokol/debugtext.d index a7f4772..d1c725d 100644 --- a/src/sokol/debugtext.d +++ b/src/sokol/debugtext.d @@ -13,7 +13,7 @@ enum LogItem { } extern(C) struct Logger { - extern(C) void function(scope const(char)*, uint, uint, scope const(char)*, uint, scope const(char)*, void*) func = null; + extern(C) void function(const(char)*, uint, uint, const(char)*, uint, const(char)*, void*) func = null; void* user_data = null; } extern(C) @@ -58,7 +58,7 @@ struct Desc { Logger logger; } extern(C) void sdtx_setup(const Desc *) @system @nogc nothrow; -void setup(ref Desc desc) @trusted @nogc nothrow { +void setup(scope ref Desc desc) @trusted @nogc nothrow { sdtx_setup(&desc); } extern(C) void sdtx_shutdown() @system @nogc nothrow; @@ -90,7 +90,7 @@ FontDesc fontOric() @trusted @nogc nothrow { return sdtx_font_oric(); } extern(C) Context sdtx_make_context(const ContextDesc *) @system @nogc nothrow; -Context makeContext(ref ContextDesc desc) @trusted @nogc nothrow { +Context makeContext(scope ref ContextDesc desc) @trusted @nogc nothrow { return sdtx_make_context(&desc); } extern(C) void sdtx_destroy_context(Context) @system @nogc nothrow; @@ -197,11 +197,11 @@ extern(C) void sdtx_putc(char) @system @nogc nothrow; void putc(char c) @trusted @nogc nothrow { sdtx_putc(c); } -extern(C) void sdtx_puts(scope const(char)*) @system @nogc nothrow; +extern(C) void sdtx_puts(const(char)*) @system @nogc nothrow; void puts(scope const(char)* str) @trusted @nogc nothrow { sdtx_puts(str); } -extern(C) void sdtx_putr(scope const(char)*, int) @system @nogc nothrow; +extern(C) void sdtx_putr(const(char)*, int) @system @nogc nothrow; void putr(scope const(char)* str, int len) @trusted @nogc nothrow { sdtx_putr(str, len); } diff --git a/src/sokol/gfx.d b/src/sokol/gfx.d index 89d540d..f398ef5 100644 --- a/src/sokol/gfx.d +++ b/src/sokol/gfx.d @@ -39,6 +39,7 @@ enum max_vertex_buffers = 8; enum max_shaderstage_images = 12; enum max_shaderstage_samplers = 8; enum max_shaderstage_imagesamplerpairs = 12; +enum max_shaderstage_storagebuffers = 8; enum max_shaderstage_ubs = 4; enum max_ub_members = 16; enum max_vertex_attributes = 16; @@ -52,7 +53,7 @@ struct Color { float a = 0.0f; } enum Backend { - Glcore33, + Glcore, Gles3, D3d11, Metal_ios, @@ -128,8 +129,10 @@ enum PixelFormat { Etc2_rgb8a1, Etc2_rgba8, Etc2_srgb8a8, - Etc2_rg11, - Etc2_rg11sn, + Eac_r11, + Eac_r11sn, + Eac_rg11, + Eac_rg11sn, Astc_4x4_rgba, Astc_4x4_srgba, Num, @@ -151,6 +154,7 @@ struct Features { bool image_clamp_to_border = false; bool mrt_independent_blend_state = false; bool mrt_independent_write_mask = false; + bool storage_buffer = false; } extern(C) struct Limits { @@ -181,6 +185,7 @@ enum BufferType { Default, Vertexbuffer, Indexbuffer, + Storagebuffer, Num, } enum IndexType { @@ -468,6 +473,7 @@ extern(C) struct StageBindings { Image[12] images; Sampler[8] samplers; + Buffer[8] storage_buffers; } extern(C) struct Bindings { @@ -561,6 +567,11 @@ struct ShaderUniformBlockDesc { ShaderUniformDesc[16] uniforms; } extern(C) +struct ShaderStorageBufferDesc { + bool used = false; + bool readonly = false; +} +extern(C) struct ShaderImageDesc { bool used = false; bool multisampled = false; @@ -586,6 +597,7 @@ struct ShaderStageDesc { const(char)* entry = null; const(char)* d3d11_target = null; ShaderUniformBlockDesc[4] uniform_blocks; + ShaderStorageBufferDesc[8] storage_buffers; ShaderImageDesc[12] images; ShaderSamplerDesc[8] samplers; ShaderImageSamplerPairDesc[12] image_sampler_pairs; @@ -749,7 +761,7 @@ struct TraceHooks { extern(C) void function(Shader, void*) fail_shader = null; extern(C) void function(Pipeline, void*) fail_pipeline = null; extern(C) void function(Attachments, void*) fail_attachments = null; - extern(C) void function(scope const(char)*, void*) push_debug_group = null; + extern(C) void function(const(char)*, void*) push_debug_group = null; extern(C) void function(void*) pop_debug_group = null; } extern(C) @@ -874,6 +886,7 @@ struct FrameStatsMetalBindings { uint num_set_vertex_buffer = 0; uint num_set_vertex_texture = 0; uint num_set_vertex_sampler_state = 0; + uint num_set_fragment_buffer = 0; uint num_set_fragment_texture = 0; uint num_set_fragment_sampler_state = 0; } @@ -953,6 +966,7 @@ enum LogItem { Gl_framebuffer_status_incomplete_multisample, Gl_framebuffer_status_unknown, D3d11_create_buffer_failed, + D3d11_create_buffer_srv_failed, D3d11_create_depth_texture_unsupported_pixel_format, D3d11_create_depth_texture_failed, D3d11_create_2d_texture_unsupported_pixel_format, @@ -999,6 +1013,7 @@ enum LogItem { Wgpu_create_shader_module_failed, Wgpu_shader_too_many_images, Wgpu_shader_too_many_samplers, + Wgpu_shader_too_many_storagebuffers, Wgpu_shader_create_bindgroup_layout_failed, Wgpu_create_pipeline_layout_failed, Wgpu_create_render_pipeline_failed, @@ -1043,6 +1058,8 @@ enum LogItem { Validate_bufferdesc_data, Validate_bufferdesc_data_size, Validate_bufferdesc_no_data, + Validate_bufferdesc_storagebuffer_supported, + Validate_bufferdesc_storagebuffer_size_multiple_4, Validate_imagedata_nodata, Validate_imagedata_data_size, Validate_imagedesc_canary, @@ -1076,6 +1093,8 @@ enum LogItem { Validate_shaderdesc_ub_size_mismatch, Validate_shaderdesc_ub_array_count, Validate_shaderdesc_ub_std140_array_type, + Validate_shaderdesc_no_cont_storagebuffers, + Validate_shaderdesc_storagebuffer_readonly, Validate_shaderdesc_no_cont_images, Validate_shaderdesc_no_cont_samplers, Validate_shaderdesc_image_sampler_pair_image_slot_out_of_range, @@ -1089,11 +1108,10 @@ enum LogItem { Validate_shaderdesc_image_not_referenced_by_image_sampler_pairs, Validate_shaderdesc_sampler_not_referenced_by_image_sampler_pairs, Validate_shaderdesc_no_cont_image_sampler_pairs, - Validate_shaderdesc_attr_semantics, Validate_shaderdesc_attr_string_too_long, Validate_pipelinedesc_canary, Validate_pipelinedesc_shader, - Validate_pipelinedesc_no_attrs, + Validate_pipelinedesc_no_cont_attrs, Validate_pipelinedesc_layout_stride4, Validate_pipelinedesc_attr_semantics, Validate_attachmentsdesc_canary, @@ -1197,6 +1215,10 @@ enum LogItem { Validate_abnd_vs_expected_nonfiltering_sampler, Validate_abnd_vs_unexpected_sampler_binding, Validate_abnd_vs_smp_exists, + Validate_abnd_vs_expected_storagebuffer_binding, + Validate_abnd_vs_storagebuffer_exists, + Validate_abnd_vs_storagebuffer_binding_buffertype, + Validate_abnd_vs_unexpected_storagebuffer_binding, Validate_abnd_fs_expected_image_binding, Validate_abnd_fs_img_exists, Validate_abnd_fs_image_type_mismatch, @@ -1210,6 +1232,10 @@ enum LogItem { Validate_abnd_fs_expected_nonfiltering_sampler, Validate_abnd_fs_unexpected_sampler_binding, Validate_abnd_fs_smp_exists, + Validate_abnd_fs_expected_storagebuffer_binding, + Validate_abnd_fs_storagebuffer_exists, + Validate_abnd_fs_storagebuffer_binding_buffertype, + Validate_abnd_fs_unexpected_storagebuffer_binding, Validate_aub_no_pipeline, Validate_aub_no_ub_at_slot, Validate_aub_size, @@ -1263,7 +1289,7 @@ struct Allocator { } extern(C) struct Logger { - extern(C) void function(scope const(char)*, uint, uint, scope const(char)*, uint, scope const(char)*, void*) func = null; + extern(C) void function(const(char)*, uint, uint, const(char)*, uint, const(char)*, void*) func = null; void* user_data = null; } extern(C) @@ -1288,7 +1314,7 @@ struct Desc { uint _end_canary = 0; } extern(C) void sg_setup(const Desc *) @system @nogc nothrow; -void setup(ref Desc desc) @trusted @nogc nothrow { +void setup(scope ref Desc desc) @trusted @nogc nothrow { sg_setup(&desc); } extern(C) void sg_shutdown() @system @nogc nothrow; @@ -1304,10 +1330,10 @@ void resetStateCache() @trusted @nogc nothrow { sg_reset_state_cache(); } extern(C) TraceHooks sg_install_trace_hooks(const TraceHooks *) @system @nogc nothrow; -TraceHooks installTraceHooks(ref TraceHooks trace_hooks) @trusted @nogc nothrow { +TraceHooks installTraceHooks(scope ref TraceHooks trace_hooks) @trusted @nogc nothrow { return sg_install_trace_hooks(&trace_hooks); } -extern(C) void sg_push_debug_group(scope const(char)*) @system @nogc nothrow; +extern(C) void sg_push_debug_group(const(char)*) @system @nogc nothrow; void pushDebugGroup(scope const(char)* name) @trusted @nogc nothrow { sg_push_debug_group(name); } @@ -1324,27 +1350,27 @@ bool removeCommitListener(CommitListener listener) @trusted @nogc nothrow { return sg_remove_commit_listener(listener); } extern(C) Buffer sg_make_buffer(const BufferDesc *) @system @nogc nothrow; -Buffer makeBuffer(ref BufferDesc desc) @trusted @nogc nothrow { +Buffer makeBuffer(scope ref BufferDesc desc) @trusted @nogc nothrow { return sg_make_buffer(&desc); } extern(C) Image sg_make_image(const ImageDesc *) @system @nogc nothrow; -Image makeImage(ref ImageDesc desc) @trusted @nogc nothrow { +Image makeImage(scope ref ImageDesc desc) @trusted @nogc nothrow { return sg_make_image(&desc); } extern(C) Sampler sg_make_sampler(const SamplerDesc *) @system @nogc nothrow; -Sampler makeSampler(ref SamplerDesc desc) @trusted @nogc nothrow { +Sampler makeSampler(scope ref SamplerDesc desc) @trusted @nogc nothrow { return sg_make_sampler(&desc); } extern(C) Shader sg_make_shader(const ShaderDesc *) @system @nogc nothrow; -Shader makeShader(ref ShaderDesc desc) @trusted @nogc nothrow { +Shader makeShader(scope ref ShaderDesc desc) @trusted @nogc nothrow { return sg_make_shader(&desc); } extern(C) Pipeline sg_make_pipeline(const PipelineDesc *) @system @nogc nothrow; -Pipeline makePipeline(ref PipelineDesc desc) @trusted @nogc nothrow { +Pipeline makePipeline(scope ref PipelineDesc desc) @trusted @nogc nothrow { return sg_make_pipeline(&desc); } extern(C) Attachments sg_make_attachments(const AttachmentsDesc *) @system @nogc nothrow; -Attachments makeAttachments(ref AttachmentsDesc desc) @trusted @nogc nothrow { +Attachments makeAttachments(scope ref AttachmentsDesc desc) @trusted @nogc nothrow { return sg_make_attachments(&desc); } extern(C) void sg_destroy_buffer(Buffer) @system @nogc nothrow; @@ -1372,15 +1398,15 @@ void destroyAttachments(Attachments atts) @trusted @nogc nothrow { sg_destroy_attachments(atts); } extern(C) void sg_update_buffer(Buffer, const Range *) @system @nogc nothrow; -void updateBuffer(Buffer buf, ref Range data) @trusted @nogc nothrow { +void updateBuffer(Buffer buf, scope ref Range data) @trusted @nogc nothrow { sg_update_buffer(buf, &data); } extern(C) void sg_update_image(Image, const ImageData *) @system @nogc nothrow; -void updateImage(Image img, ref ImageData data) @trusted @nogc nothrow { +void updateImage(Image img, scope ref ImageData data) @trusted @nogc nothrow { sg_update_image(img, &data); } extern(C) int sg_append_buffer(Buffer, const Range *) @system @nogc nothrow; -int appendBuffer(Buffer buf, ref Range data) @trusted @nogc nothrow { +int appendBuffer(Buffer buf, scope ref Range data) @trusted @nogc nothrow { return sg_append_buffer(buf, &data); } extern(C) bool sg_query_buffer_overflow(Buffer) @system @nogc nothrow; @@ -1392,7 +1418,7 @@ bool queryBufferWillOverflow(Buffer buf, size_t size) @trusted @nogc nothrow { return sg_query_buffer_will_overflow(buf, size); } extern(C) void sg_begin_pass(const Pass *) @system @nogc nothrow; -void beginPass(ref Pass pass) @trusted @nogc nothrow { +void beginPass(scope ref Pass pass) @trusted @nogc nothrow { sg_begin_pass(&pass); } extern(C) void sg_apply_viewport(int, int, int, int, bool) @system @nogc nothrow; @@ -1416,11 +1442,11 @@ void applyPipeline(Pipeline pip) @trusted @nogc nothrow { sg_apply_pipeline(pip); } extern(C) void sg_apply_bindings(const Bindings *) @system @nogc nothrow; -void applyBindings(ref Bindings bindings) @trusted @nogc nothrow { +void applyBindings(scope ref Bindings bindings) @trusted @nogc nothrow { sg_apply_bindings(&bindings); } extern(C) void sg_apply_uniforms(ShaderStage, uint, const Range *) @system @nogc nothrow; -void applyUniforms(ShaderStage stage, uint ub_index, ref Range data) @trusted @nogc nothrow { +void applyUniforms(ShaderStage stage, uint ub_index, scope ref Range data) @trusted @nogc nothrow { sg_apply_uniforms(stage, ub_index, &data); } extern(C) void sg_draw(uint, uint, uint) @system @nogc nothrow; @@ -1536,27 +1562,27 @@ AttachmentsDesc queryAttachmentsDesc(Attachments atts) @trusted @nogc nothrow { return sg_query_attachments_desc(atts); } extern(C) BufferDesc sg_query_buffer_defaults(const BufferDesc *) @system @nogc nothrow; -BufferDesc queryBufferDefaults(ref BufferDesc desc) @trusted @nogc nothrow { +BufferDesc queryBufferDefaults(scope ref BufferDesc desc) @trusted @nogc nothrow { return sg_query_buffer_defaults(&desc); } extern(C) ImageDesc sg_query_image_defaults(const ImageDesc *) @system @nogc nothrow; -ImageDesc queryImageDefaults(ref ImageDesc desc) @trusted @nogc nothrow { +ImageDesc queryImageDefaults(scope ref ImageDesc desc) @trusted @nogc nothrow { return sg_query_image_defaults(&desc); } extern(C) SamplerDesc sg_query_sampler_defaults(const SamplerDesc *) @system @nogc nothrow; -SamplerDesc querySamplerDefaults(ref SamplerDesc desc) @trusted @nogc nothrow { +SamplerDesc querySamplerDefaults(scope ref SamplerDesc desc) @trusted @nogc nothrow { return sg_query_sampler_defaults(&desc); } extern(C) ShaderDesc sg_query_shader_defaults(const ShaderDesc *) @system @nogc nothrow; -ShaderDesc queryShaderDefaults(ref ShaderDesc desc) @trusted @nogc nothrow { +ShaderDesc queryShaderDefaults(scope ref ShaderDesc desc) @trusted @nogc nothrow { return sg_query_shader_defaults(&desc); } extern(C) PipelineDesc sg_query_pipeline_defaults(const PipelineDesc *) @system @nogc nothrow; -PipelineDesc queryPipelineDefaults(ref PipelineDesc desc) @trusted @nogc nothrow { +PipelineDesc queryPipelineDefaults(scope ref PipelineDesc desc) @trusted @nogc nothrow { return sg_query_pipeline_defaults(&desc); } extern(C) AttachmentsDesc sg_query_attachments_defaults(const AttachmentsDesc *) @system @nogc nothrow; -AttachmentsDesc queryAttachmentsDefaults(ref AttachmentsDesc desc) @trusted @nogc nothrow { +AttachmentsDesc queryAttachmentsDefaults(scope ref AttachmentsDesc desc) @trusted @nogc nothrow { return sg_query_attachments_defaults(&desc); } extern(C) Buffer sg_alloc_buffer() @system @nogc nothrow; @@ -1608,27 +1634,27 @@ void deallocAttachments(Attachments attachments) @trusted @nogc nothrow { sg_dealloc_attachments(attachments); } extern(C) void sg_init_buffer(Buffer, const BufferDesc *) @system @nogc nothrow; -void initBuffer(Buffer buf, ref BufferDesc desc) @trusted @nogc nothrow { +void initBuffer(Buffer buf, scope ref BufferDesc desc) @trusted @nogc nothrow { sg_init_buffer(buf, &desc); } extern(C) void sg_init_image(Image, const ImageDesc *) @system @nogc nothrow; -void initImage(Image img, ref ImageDesc desc) @trusted @nogc nothrow { +void initImage(Image img, scope ref ImageDesc desc) @trusted @nogc nothrow { sg_init_image(img, &desc); } extern(C) void sg_init_sampler(Sampler, const SamplerDesc *) @system @nogc nothrow; -void initSampler(Sampler smg, ref SamplerDesc desc) @trusted @nogc nothrow { +void initSampler(Sampler smg, scope ref SamplerDesc desc) @trusted @nogc nothrow { sg_init_sampler(smg, &desc); } extern(C) void sg_init_shader(Shader, const ShaderDesc *) @system @nogc nothrow; -void initShader(Shader shd, ref ShaderDesc desc) @trusted @nogc nothrow { +void initShader(Shader shd, scope ref ShaderDesc desc) @trusted @nogc nothrow { sg_init_shader(shd, &desc); } extern(C) void sg_init_pipeline(Pipeline, const PipelineDesc *) @system @nogc nothrow; -void initPipeline(Pipeline pip, ref PipelineDesc desc) @trusted @nogc nothrow { +void initPipeline(Pipeline pip, scope ref PipelineDesc desc) @trusted @nogc nothrow { sg_init_pipeline(pip, &desc); } extern(C) void sg_init_attachments(Attachments, const AttachmentsDesc *) @system @nogc nothrow; -void initAttachments(Attachments attachments, ref AttachmentsDesc desc) @trusted @nogc nothrow { +void initAttachments(Attachments attachments, scope ref AttachmentsDesc desc) @trusted @nogc nothrow { sg_init_attachments(attachments, &desc); } extern(C) void sg_uninit_buffer(Buffer) @system @nogc nothrow; @@ -1810,11 +1836,11 @@ struct GlAttachmentsInfo { uint framebuffer = 0; uint[4] msaa_resolve_framebuffer = 0; } -extern(C) scope const(void)* sg_d3d11_device() @system @nogc nothrow; +extern(C) const(void)* sg_d3d11_device() @system @nogc nothrow; scope const(void)* d3d11Device() @trusted @nogc nothrow { return sg_d3d11_device(); } -extern(C) scope const(void)* sg_d3d11_device_context() @system @nogc nothrow; +extern(C) const(void)* sg_d3d11_device_context() @system @nogc nothrow; scope const(void)* d3d11DeviceContext() @trusted @nogc nothrow { return sg_d3d11_device_context(); } @@ -1842,11 +1868,11 @@ extern(C) D3d11AttachmentsInfo sg_d3d11_query_attachments_info(Attachments) @sys D3d11AttachmentsInfo d3d11QueryAttachmentsInfo(Attachments atts) @trusted @nogc nothrow { return sg_d3d11_query_attachments_info(atts); } -extern(C) scope const(void)* sg_mtl_device() @system @nogc nothrow; +extern(C) const(void)* sg_mtl_device() @system @nogc nothrow; scope const(void)* mtlDevice() @trusted @nogc nothrow { return sg_mtl_device(); } -extern(C) scope const(void)* sg_mtl_render_command_encoder() @system @nogc nothrow; +extern(C) const(void)* sg_mtl_render_command_encoder() @system @nogc nothrow; scope const(void)* mtlRenderCommandEncoder() @trusted @nogc nothrow { return sg_mtl_render_command_encoder(); } @@ -1870,19 +1896,19 @@ extern(C) MtlPipelineInfo sg_mtl_query_pipeline_info(Pipeline) @system @nogc not MtlPipelineInfo mtlQueryPipelineInfo(Pipeline pip) @trusted @nogc nothrow { return sg_mtl_query_pipeline_info(pip); } -extern(C) scope const(void)* sg_wgpu_device() @system @nogc nothrow; +extern(C) const(void)* sg_wgpu_device() @system @nogc nothrow; scope const(void)* wgpuDevice() @trusted @nogc nothrow { return sg_wgpu_device(); } -extern(C) scope const(void)* sg_wgpu_queue() @system @nogc nothrow; +extern(C) const(void)* sg_wgpu_queue() @system @nogc nothrow; scope const(void)* wgpuQueue() @trusted @nogc nothrow { return sg_wgpu_queue(); } -extern(C) scope const(void)* sg_wgpu_command_encoder() @system @nogc nothrow; +extern(C) const(void)* sg_wgpu_command_encoder() @system @nogc nothrow; scope const(void)* wgpuCommandEncoder() @trusted @nogc nothrow { return sg_wgpu_command_encoder(); } -extern(C) scope const(void)* sg_wgpu_render_pass_encoder() @system @nogc nothrow; +extern(C) const(void)* sg_wgpu_render_pass_encoder() @system @nogc nothrow; scope const(void)* wgpuRenderPassEncoder() @trusted @nogc nothrow { return sg_wgpu_render_pass_encoder(); } diff --git a/src/sokol/gl.d b/src/sokol/gl.d index 6f022cf..bbaf381 100644 --- a/src/sokol/gl.d +++ b/src/sokol/gl.d @@ -14,7 +14,7 @@ enum LogItem { } extern(C) struct Logger { - extern(C) void function(scope const(char)*, uint, uint, scope const(char)*, uint, scope const(char)*, void*) func = null; + extern(C) void function(const(char)*, uint, uint, const(char)*, uint, const(char)*, void*) func = null; void* user_data = null; } extern(C) @@ -62,7 +62,7 @@ struct Desc { Logger logger; } extern(C) void sgl_setup(const Desc *) @system @nogc nothrow; -void setup(ref Desc desc) @trusted @nogc nothrow { +void setup(scope ref Desc desc) @trusted @nogc nothrow { sgl_setup(&desc); } extern(C) void sgl_shutdown() @system @nogc nothrow; @@ -86,7 +86,7 @@ Error contextError(Context ctx) @trusted @nogc nothrow { return sgl_context_error(ctx); } extern(C) Context sgl_make_context(const ContextDesc *) @system @nogc nothrow; -Context makeContext(ref ContextDesc desc) @trusted @nogc nothrow { +Context makeContext(scope ref ContextDesc desc) @trusted @nogc nothrow { return sgl_make_context(&desc); } extern(C) void sgl_destroy_context(Context) @system @nogc nothrow; @@ -122,11 +122,11 @@ void contextDrawLayer(Context ctx, int layer_id) @trusted @nogc nothrow { sgl_context_draw_layer(ctx, layer_id); } extern(C) Pipeline sgl_make_pipeline(const sg.PipelineDesc *) @system @nogc nothrow; -Pipeline makePipeline(ref sg.PipelineDesc desc) @trusted @nogc nothrow { +Pipeline makePipeline(scope ref sg.PipelineDesc desc) @trusted @nogc nothrow { return sgl_make_pipeline(&desc); } extern(C) Pipeline sgl_context_make_pipeline(Context, const sg.PipelineDesc *) @system @nogc nothrow; -Pipeline contextMakePipeline(Context ctx, ref sg.PipelineDesc desc) @trusted @nogc nothrow { +Pipeline contextMakePipeline(Context ctx, scope ref sg.PipelineDesc desc) @trusted @nogc nothrow { return sgl_context_make_pipeline(ctx, &desc); } extern(C) void sgl_destroy_pipeline(Pipeline) @system @nogc nothrow; @@ -202,19 +202,19 @@ void loadIdentity() @trusted @nogc nothrow { sgl_load_identity(); } extern(C) void sgl_load_matrix(const float *) @system @nogc nothrow; -void loadMatrix(const float * m) @trusted @nogc nothrow { +void loadMatrix(scope const float * m) @trusted @nogc nothrow { sgl_load_matrix(m); } extern(C) void sgl_load_transpose_matrix(const float *) @system @nogc nothrow; -void loadTransposeMatrix(const float * m) @trusted @nogc nothrow { +void loadTransposeMatrix(scope const float * m) @trusted @nogc nothrow { sgl_load_transpose_matrix(m); } extern(C) void sgl_mult_matrix(const float *) @system @nogc nothrow; -void multMatrix(const float * m) @trusted @nogc nothrow { +void multMatrix(scope const float * m) @trusted @nogc nothrow { sgl_mult_matrix(m); } extern(C) void sgl_mult_transpose_matrix(const float *) @system @nogc nothrow; -void multTransposeMatrix(const float * m) @trusted @nogc nothrow { +void multTransposeMatrix(scope const float * m) @trusted @nogc nothrow { sgl_mult_transpose_matrix(m); } extern(C) void sgl_rotate(float, float, float, float) @system @nogc nothrow; diff --git a/src/sokol/log.d b/src/sokol/log.d index cfb0d05..78c89b0 100644 --- a/src/sokol/log.d +++ b/src/sokol/log.d @@ -2,5 +2,5 @@ module sokol.log; -extern(C) void slog_func(scope const(char)*, uint, uint, scope const(char)*, uint, scope const(char)*, void*) @system @nogc nothrow; +extern(C) void slog_func(const(char)*, uint, uint, const(char)*, uint, const(char)*, void*) @system @nogc nothrow; alias func = slog_func; diff --git a/src/sokol/shape.d b/src/sokol/shape.d index e827f4f..e5a015e 100644 --- a/src/sokol/shape.d +++ b/src/sokol/shape.d @@ -103,23 +103,23 @@ struct Torus { Mat4 transform; } extern(C) Buffer sshape_build_plane(const Buffer *, const Plane *) @system @nogc nothrow; -Buffer buildPlane(ref Buffer buf, ref Plane params) @trusted @nogc nothrow { +Buffer buildPlane(scope ref Buffer buf, scope ref Plane params) @trusted @nogc nothrow { return sshape_build_plane(&buf, ¶ms); } extern(C) Buffer sshape_build_box(const Buffer *, const Box *) @system @nogc nothrow; -Buffer buildBox(ref Buffer buf, ref Box params) @trusted @nogc nothrow { +Buffer buildBox(scope ref Buffer buf, scope ref Box params) @trusted @nogc nothrow { return sshape_build_box(&buf, ¶ms); } extern(C) Buffer sshape_build_sphere(const Buffer *, const Sphere *) @system @nogc nothrow; -Buffer buildSphere(ref Buffer buf, ref Sphere params) @trusted @nogc nothrow { +Buffer buildSphere(scope ref Buffer buf, scope ref Sphere params) @trusted @nogc nothrow { return sshape_build_sphere(&buf, ¶ms); } extern(C) Buffer sshape_build_cylinder(const Buffer *, const Cylinder *) @system @nogc nothrow; -Buffer buildCylinder(ref Buffer buf, ref Cylinder params) @trusted @nogc nothrow { +Buffer buildCylinder(scope ref Buffer buf, scope ref Cylinder params) @trusted @nogc nothrow { return sshape_build_cylinder(&buf, ¶ms); } extern(C) Buffer sshape_build_torus(const Buffer *, const Torus *) @system @nogc nothrow; -Buffer buildTorus(ref Buffer buf, ref Torus params) @trusted @nogc nothrow { +Buffer buildTorus(scope ref Buffer buf, scope ref Torus params) @trusted @nogc nothrow { return sshape_build_torus(&buf, ¶ms); } extern(C) Sizes sshape_plane_sizes(uint) @system @nogc nothrow; @@ -143,15 +143,15 @@ Sizes torusSizes(uint sides, uint rings) @trusted @nogc nothrow { return sshape_torus_sizes(sides, rings); } extern(C) ElementRange sshape_element_range(const Buffer *) @system @nogc nothrow; -ElementRange elementRange(ref Buffer buf) @trusted @nogc nothrow { +ElementRange elementRange(scope ref Buffer buf) @trusted @nogc nothrow { return sshape_element_range(&buf); } extern(C) sg.BufferDesc sshape_vertex_buffer_desc(const Buffer *) @system @nogc nothrow; -sg.BufferDesc vertexBufferDesc(ref Buffer buf) @trusted @nogc nothrow { +sg.BufferDesc vertexBufferDesc(scope ref Buffer buf) @trusted @nogc nothrow { return sshape_vertex_buffer_desc(&buf); } extern(C) sg.BufferDesc sshape_index_buffer_desc(const Buffer *) @system @nogc nothrow; -sg.BufferDesc indexBufferDesc(ref Buffer buf) @trusted @nogc nothrow { +sg.BufferDesc indexBufferDesc(scope ref Buffer buf) @trusted @nogc nothrow { return sshape_index_buffer_desc(&buf); } extern(C) sg.VertexBufferLayoutState sshape_vertex_buffer_layout_state() @system @nogc nothrow; @@ -191,10 +191,10 @@ uint color3b(ubyte r, ubyte g, ubyte b) @trusted @nogc nothrow { return sshape_color_3b(r, g, b); } extern(C) Mat4 sshape_mat4(const float *) @system @nogc nothrow; -Mat4 mat4(const float * m) @trusted @nogc nothrow { +Mat4 mat4(scope const float * m) @trusted @nogc nothrow { return sshape_mat4(m); } extern(C) Mat4 sshape_mat4_transpose(const float *) @system @nogc nothrow; -Mat4 mat4Transpose(const float * m) @trusted @nogc nothrow { +Mat4 mat4Transpose(scope const float * m) @trusted @nogc nothrow { return sshape_mat4_transpose(m); } diff --git a/src/sokol/time.d b/src/sokol/time.d index a2f8e18..b5bfee5 100644 --- a/src/sokol/time.d +++ b/src/sokol/time.d @@ -19,7 +19,7 @@ ulong since(ulong start_ticks) @trusted @nogc nothrow { return stm_since(start_ticks); } extern(C) ulong stm_laptime(ulong *) @system @nogc nothrow; -ulong laptime(ulong * last_time) @trusted @nogc nothrow { +ulong laptime(scope ulong * last_time) @trusted @nogc nothrow { return stm_laptime(last_time); } extern(C) ulong stm_round_to_common_refresh_rate(ulong) @system @nogc nothrow; diff --git a/src/sokol/utils.d b/src/sokol/utils.d deleted file mode 100644 index e20ad7c..0000000 --- a/src/sokol/utils.d +++ /dev/null @@ -1,27 +0,0 @@ -module sokol.utils; - -// helper function to convert a C string to a D string -string cStrTod(inout(char)* c_str) nothrow { - auto start = c_str; - auto end = cast(char*) c_str; - for (; *end; end++){} - return cast(string) c_str[0 .. end - start]; -} - -import sokol.gfx:Range; - -// WIP: helper function to convert "anything" to a Range struct -Range asRange(T)(T val) @trusted { - import std.traits; - static if (isPointer!T) { - return Range(val, T.sizeof); - } else static if (is(T == float[]) || is(T == double[])) { - auto arr = val.dup; - return Range(&arr[0], arr.length * arr[0].sizeof); - } else static if (is(T == struct)) { - Range r = {ptr: cast(const(void)*)&val, size: T.sizeof}; - return r; - } else { - static assert(0, "Cannot convert to range"); - } -}