Skip to content

Commit

Permalink
Fixed the metal pipeline and made the Metal backend the default on macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
tanis2000 committed Oct 11, 2024
1 parent 6791d20 commit b872b9e
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 31 deletions.
4 changes: 2 additions & 2 deletions assets/shaders/dst/gl33/default.glsl_default_glsl410_vs.glsl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#version 410

uniform vec4 vs_params[12];
layout(location = 0) in vec2 vertexPosition;
layout(location = 0) in vec3 vertexPosition;
layout(location = 0) out vec2 tcoord;
layout(location = 2) in vec2 vertexTCoord;
layout(location = 1) out vec4 color;
Expand All @@ -10,7 +10,7 @@ layout(location = 3) in vec3 vertexNormal;

void main()
{
gl_Position = ((mat4(vs_params[0], vs_params[1], vs_params[2], vs_params[3]) * mat4(vs_params[4], vs_params[5], vs_params[6], vs_params[7])) * mat4(vs_params[8], vs_params[9], vs_params[10], vs_params[11])) * vec4(vertexPosition, 1.0, 1.0);
gl_Position = ((mat4(vs_params[0], vs_params[1], vs_params[2], vs_params[3]) * mat4(vs_params[4], vs_params[5], vs_params[6], vs_params[7])) * mat4(vs_params[8], vs_params[9], vs_params[10], vs_params[11])) * vec4(vertexPosition, 1.0);
tcoord = vertexTCoord;
color = vertexColor;
gl_PointSize = 1.0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#version 300 es

uniform vec4 vs_params[12];
layout(location = 0) in vec2 vertexPosition;
layout(location = 0) in vec3 vertexPosition;
out vec2 tcoord;
layout(location = 2) in vec2 vertexTCoord;
out vec4 color;
Expand All @@ -10,7 +10,7 @@ layout(location = 3) in vec3 vertexNormal;

void main()
{
gl_Position = ((mat4(vs_params[0], vs_params[1], vs_params[2], vs_params[3]) * mat4(vs_params[4], vs_params[5], vs_params[6], vs_params[7])) * mat4(vs_params[8], vs_params[9], vs_params[10], vs_params[11])) * vec4(vertexPosition, 1.0, 1.0);
gl_Position = ((mat4(vs_params[0], vs_params[1], vs_params[2], vs_params[3]) * mat4(vs_params[4], vs_params[5], vs_params[6], vs_params[7])) * mat4(vs_params[8], vs_params[9], vs_params[10], vs_params[11])) * vec4(vertexPosition, 1.0);
tcoord = vertexTCoord;
color = vertexColor;
gl_PointSize = 1.0;
Expand Down
6 changes: 3 additions & 3 deletions assets/shaders/dst/hlsl/default.glsl_default_hlsl4_vs.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ cbuffer vs_params : register(b0)

static float4 gl_Position;
static float gl_PointSize;
static float2 vertexPosition;
static float3 vertexPosition;
static float2 tcoord;
static float2 vertexTCoord;
static float4 color;
Expand All @@ -17,7 +17,7 @@ static float3 vertexNormal;

struct SPIRV_Cross_Input
{
float2 vertexPosition : TEXCOORD0;
float3 vertexPosition : TEXCOORD0;
float4 vertexColor : TEXCOORD1;
float2 vertexTCoord : TEXCOORD2;
float3 vertexNormal : TEXCOORD3;
Expand All @@ -32,7 +32,7 @@ struct SPIRV_Cross_Output

void vert_main()
{
gl_Position = mul(float4(vertexPosition, 1.0f, 1.0f), mul(_19_modelMatrix, mul(_19_viewMatrix, _19_projectionMatrix)));
gl_Position = mul(float4(vertexPosition, 1.0f), mul(_19_modelMatrix, mul(_19_viewMatrix, _19_projectionMatrix)));
tcoord = vertexTCoord;
color = vertexColor;
gl_PointSize = 1.0f;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ struct main0_out

struct main0_in
{
float2 vertexPosition [[attribute(0)]];
float3 vertexPosition [[attribute(0)]];
float4 vertexColor [[attribute(1)]];
float2 vertexTCoord [[attribute(2)]];
};

vertex main0_out main0(main0_in in [[stage_in]], constant vs_params& _19 [[buffer(0)]])
{
main0_out out = {};
out.gl_Position = ((_19.projectionMatrix * _19.viewMatrix) * _19.modelMatrix) * float4(in.vertexPosition, 1.0, 1.0);
out.gl_Position = ((_19.projectionMatrix * _19.viewMatrix) * _19.modelMatrix) * float4(in.vertexPosition, 1.0);
out.tcoord = in.vertexTCoord;
out.color = in.vertexColor;
out.gl_PointSize = 1.0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ struct main0_out

struct main0_in
{
float2 vertexPosition [[attribute(0)]];
float3 vertexPosition [[attribute(0)]];
float4 vertexColor [[attribute(1)]];
float2 vertexTCoord [[attribute(2)]];
};

vertex main0_out main0(main0_in in [[stage_in]], constant vs_params& _19 [[buffer(0)]])
{
main0_out out = {};
out.gl_Position = ((_19.projectionMatrix * _19.viewMatrix) * _19.modelMatrix) * float4(in.vertexPosition, 1.0, 1.0);
out.gl_Position = ((_19.projectionMatrix * _19.viewMatrix) * _19.modelMatrix) * float4(in.vertexPosition, 1.0);
out.tcoord = in.vertexTCoord;
out.color = in.vertexColor;
out.gl_PointSize = 1.0;
Expand Down
4 changes: 2 additions & 2 deletions assets/shaders/src/default.glsl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma sokol @vs vs
in vec2 vertexPosition;
in vec3 vertexPosition;
in vec4 vertexColor;
in vec2 vertexTCoord;
in vec3 vertexNormal;
Expand All @@ -14,7 +14,7 @@ uniform vs_params {
};

void main(void) {
gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(vertexPosition, 1.0, 1.0);
gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(vertexPosition, 1.0);
tcoord = vertexTCoord;
color = vertexColor;
vec3 n = vertexNormal;
Expand Down
8 changes: 6 additions & 2 deletions example/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ int main(int argc, char *argv[])
sprintf(filename, "%s%s", binocle_data_dir, "player.png");
sg_image ball_image = binocle_image_load(filename);

// Default shader
// Default shader (off-screen texture)
char vert[1024];
sprintf(vert, "%sshaders/%s/%s", binocle_data_dir, SHADER_PATH, DEFAULT_VS_FILENAME);
char frag[1024];
Expand All @@ -502,7 +502,7 @@ int main(int argc, char *argv[])
binocle_sdl_load_text_file(frag, &shader_fs_src, &shader_fs_src_size);

sg_shader_desc default_shader_desc = {

.label = "default-shader",
.vs.source = shader_vs_src,
#if defined(BINOCLE_METAL)
.vs.entry = "main0",
Expand All @@ -515,6 +515,7 @@ int main(int argc, char *argv[])
},
.vs.uniform_blocks[0] = {
.size = sizeof(default_shader_params_t),
.layout = SG_UNIFORMLAYOUT_STD140,
.uniforms = {
[0] = { .name = "vs_params", .type = SG_UNIFORMTYPE_FLOAT4, .array_count = 12},
}
Expand Down Expand Up @@ -556,6 +557,7 @@ int main(int argc, char *argv[])
binocle_log_info("done reading screen shader");

sg_shader_desc screen_shader_desc = {
.label = "screen-shader",
.vs.source = screen_shader_vs_src,
#if defined(BINOCLE_METAL)
.vs.entry = "main0",
Expand All @@ -567,6 +569,7 @@ int main(int argc, char *argv[])
},
.vs.uniform_blocks[0] = {
.size = sizeof(screen_shader_vs_params_t),
.layout = SG_UNIFORMLAYOUT_STD140,
.uniforms = {
[0] = { .name = "vs_params", .type = SG_UNIFORMTYPE_FLOAT4, .array_count = 4},
},
Expand All @@ -592,6 +595,7 @@ int main(int argc, char *argv[])
},
.fs.uniform_blocks[0] = {
.size = sizeof(screen_shader_fs_params_t),
.layout = SG_UNIFORMLAYOUT_STD140,
.uniforms = {
[0] = { .name = "fs_params", .type = SG_UNIFORMTYPE_FLOAT4, .array_count = 2 },
},
Expand Down
32 changes: 16 additions & 16 deletions src/binocle/core/binocle_gd.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,14 @@ void binocle_gd_setup_default_pipeline(binocle_gd *gd, uint32_t offscreen_width,
.shader = offscreen_shader,
// .index_type = SG_INDEXTYPE_UINT16,
.index_type = SG_INDEXTYPE_NONE,
.depth = {
.pixel_format = SG_PIXELFORMAT_NONE,
.compare = SG_COMPAREFUNC_NEVER,
.write_enabled = false,
},
.stencil = {
.enabled = false,
},
// .depth = {
// .pixel_format = SG_PIXELFORMAT_NONE,
// .compare = SG_COMPAREFUNC_NEVER,
// .write_enabled = false,
// },
// .stencil = {
// .enabled = false,
// },
.colors = {
[0] = {
#ifdef BINOCLE_GL
Expand Down Expand Up @@ -288,14 +288,14 @@ void binocle_gd_setup_default_pipeline(binocle_gd *gd, uint32_t offscreen_width,
.shader = display_shader,
.index_type = SG_INDEXTYPE_UINT16,
#if !defined(BINOCLE_GL)
.depth = {
.pixel_format = SG_PIXELFORMAT_NONE,
.compare = SG_COMPAREFUNC_NEVER,
.write_enabled = false,
},
.stencil = {
.enabled = false,
},
// .depth = {
// .pixel_format = SG_PIXELFORMAT_NONE,
// .compare = SG_COMPAREFUNC_NEVER,
// .write_enabled = false,
// },
// .stencil = {
// .enabled = false,
// },
#endif
.colors = {
#ifdef BINOCLE_GL
Expand Down

0 comments on commit b872b9e

Please sign in to comment.