Skip to content

Commit

Permalink
update shaders based on
Browse files Browse the repository at this point in the history
  • Loading branch information
kassane committed Jan 12, 2024
1 parent e607e44 commit 92b555d
Show file tree
Hide file tree
Showing 13 changed files with 3,780 additions and 21 deletions.
9 changes: 5 additions & 4 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ fn buildShaders(b: *Build) void {
"-o",
shaders_dir ++ shader[0 .. shader.len - 5] ++ ".d",
"-l",
"glsl330:metal_macos:hlsl4",
"glsl330:metal_macos:hlsl4:glsl300es:wgsl",
"-f",
"sokol_d",
});
Expand Down Expand Up @@ -332,8 +332,6 @@ fn buildLDC(b: *Build, lib: *CompileStep, config: ldcConfig) !*RunStep {
if (config.target.result.os.tag == .windows)
try cmds.append("--dllimport=defaultLibsOnly");
try cmds.append("-fvisibility=hidden");
// remove object files after archiving to static lib, and put them in a unique temp directory
try cmds.append("--cleanup-obj");
}
}

Expand All @@ -344,7 +342,7 @@ fn buildLDC(b: *Build, lib: *CompileStep, config: ldcConfig) !*RunStep {
// betterC disable druntime and phobos
if (config.betterC)
try cmds.append("--betterC")
else if (lib.linkage == .dynamic)
else if (lib.linkage == .dynamic or config.linkage == .dynamic)
// linking the druntime/Phobos as dynamic libraries
try cmds.append("-link-defaultlib-shared");

Expand Down Expand Up @@ -388,6 +386,9 @@ fn buildLDC(b: *Build, lib: *CompileStep, config: ldcConfig) !*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
try cmds.append("--cleanup-obj");

// disable LLVM-IR verifier
// https://llvm.org/docs/Passes.html#verify-module-verifier
try cmds.append("--disable-verify");
Expand Down
3 changes: 2 additions & 1 deletion src/examples/mrt.d
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ void frame()

void event(const app.Event* ev)
{
if(ev.type == app.EventType.Resized){
if(ev.type == app.EventType.Resized)
{
createOffscreenPass(ev.framebuffer_width, ev.framebuffer_height);
}
}
Expand Down
468 changes: 467 additions & 1 deletion src/shaders/blend.d

Large diffs are not rendered by default.

201 changes: 200 additions & 1 deletion src/shaders/bufferoffsets.d
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ extern(C):
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 -f sokol_d
Cmdline: sokol-shdc -i src/shaders/bufferoffsets.glsl -o src/shaders/bufferoffsets.d -l glsl330:metal_macos:hlsl4:glsl300es:wgsl -f sokol_d
Overview:
Expand Down Expand Up @@ -71,6 +71,61 @@ __gshared char[114] FS_SOURCE_GLSL330 = [
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;
Expand Down Expand Up @@ -309,6 +364,134 @@ __gshared char[315] FS_SOURCE_METAL_MACOS = [
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<private> position_1 : vec4f;
var<private> color : vec4f;
var<private> color0 : vec4f;
var<private> 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<private> frag_color : vec4f;
var<private> 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 bufferoffsets_shader_desc(sg.Backend backend) @trusted @nogc nothrow {
sg.ShaderDesc desc;
Expand All @@ -322,6 +505,15 @@ sg.ShaderDesc bufferoffsets_shader_desc(sg.Backend backend) @trusted @nogc nothr
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;
Expand All @@ -342,6 +534,13 @@ sg.ShaderDesc bufferoffsets_shader_desc(sg.Backend backend) @trusted @nogc nothr
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;
}
Expand Down
Loading

0 comments on commit 92b555d

Please sign in to comment.