Skip to content

Commit 3369e31

Browse files
jdolanCopilot
andcommitted
Replace HLSL shaders with GLSL pipeline; rename Mathlib float types to GLSL convention
- Write GLSL (Vulkan 4.5) source shaders for all examples - Pipeline: glslc (GLSL→SPIR-V) + shadercross (SPIR-V→MSL, SDL3-aware) - Update Examples/Makefile.am and Xcode build phase to use new pipeline - Rename Mathlib types: float2→vec2, float3→vec3, float4→vec4, float4x4→mat4 - Update README with shader pipeline documentation and install instructions - Drop HLSL sources and dxil outputs from all build artifacts Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 6341ed1 commit 3369e31

27 files changed

Lines changed: 536 additions & 349 deletions

Examples/Hello-iOS/Hello-iOS.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,23 @@ static const char *vertex_shader_msl =
3434
"using namespace metal;\n"
3535
"\n"
3636
"struct type_UBO {\n"
37-
" float4x4 ModelViewProj;\n"
37+
" mat4 ModelViewProj;\n"
3838
"};\n"
3939
"\n"
4040
"struct main0_out {\n"
41-
" float4 out_color [[user(locn0)]];\n"
42-
" float4 gl_Position [[position]];\n"
41+
" vec4 out_color [[user(locn0)]];\n"
42+
" vec4 gl_Position [[position]];\n"
4343
"};\n"
4444
"\n"
4545
"struct main0_in {\n"
46-
" float3 in_position [[attribute(0)]];\n"
47-
" float3 in_color [[attribute(1)]];\n"
46+
" vec3 in_position [[attribute(0)]];\n"
47+
" vec3 in_color [[attribute(1)]];\n"
4848
"};\n"
4949
"\n"
5050
"vertex main0_out main0(main0_in in [[stage_in]], constant type_UBO& UBO [[buffer(0)]]) {\n"
5151
" main0_out out = {};\n"
52-
" out.out_color = float4(in.in_color, 1.0);\n"
53-
" out.gl_Position = UBO.ModelViewProj * float4(in.in_position, 1.0);\n"
52+
" out.out_color = vec4(in.in_color, 1.0);\n"
53+
" out.gl_Position = UBO.ModelViewProj * vec4(in.in_position, 1.0);\n"
5454
" return out;\n"
5555
"}\n";
5656

@@ -59,10 +59,10 @@ static const char *fragment_shader_msl =
5959
"using namespace metal;\n"
6060
"\n"
6161
"struct main0_in {\n"
62-
" float4 in_color [[user(locn0)]];\n"
62+
" vec4 in_color [[user(locn0)]];\n"
6363
"};\n"
6464
"\n"
65-
"fragment float4 main0(main0_in in [[stage_in]]) {\n"
65+
"fragment vec4 main0(main0_in in [[stage_in]]) {\n"
6666
" return in.in_color;\n"
6767
"}\n";
6868

Examples/Hello.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ typedef struct {
3838
} Scene;
3939

4040
typedef struct {
41-
float3 position;
42-
float3 color;
41+
vec3 position;
42+
vec3 color;
4343
} Vertex;
4444

4545
static const Vertex vertexes[] = {
@@ -62,7 +62,7 @@ static const Vertex vertexes[] = {
6262
*/
6363
static void drawScene(Scene *scene) {
6464

65-
static float2 angles;
65+
static vec2 angles;
6666
static Uint64 lastTicks;
6767

6868
Uint64 ticks = SDL_GetTicks();
@@ -84,12 +84,12 @@ static void drawScene(Scene *scene) {
8484
SwapchainTexture swapchain = { 0 };
8585
$(cmd, waitAndAcquireSwapchainTexture, &swapchain);
8686

87-
float4x4 modelView = float4x4_rotation(angles.x, float3_new(1.f, 0.f, 0.f));
88-
modelView = float4x4_mul(float4x4_rotation(angles.y, float3_new(0.f, 1.f, 0.f)), modelView);
89-
modelView = float4x4_mul(float4x4_translation(float3_new(0.f, 0.f, -2.5f)), modelView);
87+
mat4 modelView = mat4_rotation(angles.x, vec3_new(1.f, 0.f, 0.f));
88+
modelView = mat4_mul(mat4_rotation(angles.y, vec3_new(0.f, 1.f, 0.f)), modelView);
89+
modelView = mat4_mul(mat4_translation(vec3_new(0.f, 0.f, -2.5f)), modelView);
9090

91-
const float4x4 projection = float4x4_perspective(45.f, (float) swapchain.size.w / (float) swapchain.size.h, 0.01f, 100.f);
92-
const float4x4 modelViewProjection = float4x4_mul(projection, modelView);
91+
const mat4 projection = mat4_perspective(45.f, (float) swapchain.size.w / (float) swapchain.size.h, 0.01f, 100.f);
92+
const mat4 modelViewProjection = mat4_mul(projection, modelView);
9393

9494
SDL_GPUColorTargetInfo colorTarget = {
9595
.texture = swapchain.texture,

Examples/Hello.frag.glsl

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* ObjectivelyGPU: SDL3 GPU API wrapper for GNU C.
3+
* Copyright (C) 2014 Jay Dolan <jay@jaydolan.com>
4+
*
5+
* This software is provided 'as-is', without any express or implied
6+
* warranty. In no event will the authors be held liable for any damages
7+
* arising from the use of this software.
8+
*
9+
* Permission is granted to anyone to use this software for any purpose,
10+
* including commercial applications, and to alter it and redistribute it
11+
* freely, subject to the following restrictions:
12+
*
13+
* 1. The origin of this software must not be misrepresented; you must not
14+
* claim that you wrote the original software. If you use this software
15+
* in a product, an acknowledgment in the product documentation would be
16+
* appreciated but is not required.
17+
*
18+
* 2. Altered source versions must be plainly marked as such, and must not be
19+
* misrepresented as being the original software.
20+
*
21+
* 3. This notice may not be removed or altered from any source distribution.
22+
*/
23+
24+
/**
25+
* @file Hello.frag.glsl
26+
* @brief Hello example fragment shader.
27+
*
28+
* Inputs (location 0): vec4 color from vertex stage
29+
* Output : vec4 RGBA
30+
*/
31+
32+
#version 450
33+
34+
layout(location = 0) in vec4 in_color;
35+
36+
layout(location = 0) out vec4 out_color;
37+
38+
void main() {
39+
out_color = in_color;
40+
}

Examples/Hello.frag.hlsl

Lines changed: 0 additions & 14 deletions
This file was deleted.

Examples/Hello.frag.msl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@
33

44
using namespace metal;
55

6-
struct fs_main_out
6+
struct main0_out
77
{
8-
float4 _entryPointOutput [[color(0)]];
8+
float4 out_color [[color(0)]];
99
};
1010

11-
struct fs_main_in
11+
struct main0_in
1212
{
13-
float4 input_color [[user(locn0)]];
13+
float4 in_color [[user(locn0)]];
1414
};
1515

16-
fragment fs_main_out fs_main(fs_main_in in [[stage_in]])
16+
fragment main0_out main0(main0_in in [[stage_in]])
1717
{
18-
fs_main_out out = {};
19-
out._entryPointOutput = in.input_color;
18+
main0_out out = {};
19+
out.out_color = in.in_color;
2020
return out;
2121
}
2222

Examples/Hello.frag.spv

-8 Bytes
Binary file not shown.

Examples/Hello.vert.glsl

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* ObjectivelyGPU: SDL3 GPU API wrapper for GNU C.
3+
* Copyright (C) 2014 Jay Dolan <jay@jaydolan.com>
4+
*
5+
* This software is provided 'as-is', without any express or implied
6+
* warranty. In no event will the authors be held liable for any damages
7+
* arising from the use of this software.
8+
*
9+
* Permission is granted to anyone to use this software for any purpose,
10+
* including commercial applications, and to alter it and redistribute it
11+
* freely, subject to the following restrictions:
12+
*
13+
* 1. The origin of this software must not be misrepresented; you must not
14+
* claim that you wrote the original software. If you use this software
15+
* in a product, an acknowledgment in the product documentation would be
16+
* appreciated but is not required.
17+
*
18+
* 2. Altered source versions must be plainly marked as such, and must not be
19+
* misrepresented as being the original software.
20+
*
21+
* 3. This notice may not be removed or altered from any source distribution.
22+
*/
23+
24+
/**
25+
* @file Hello.vert.glsl
26+
* @brief Hello example vertex shader.
27+
*
28+
* Inputs (location 0): vec3 position
29+
* (location 1): vec3 color
30+
* Uniform (set=1, b=0): mat4 ModelViewProj
31+
* Output : vec4 gl_Position, vec4 color
32+
*/
33+
34+
#version 450
35+
36+
layout(location = 0) in vec3 in_position;
37+
layout(location = 1) in vec3 in_color;
38+
39+
layout(location = 0) out vec4 out_color;
40+
41+
layout(set = 1, binding = 0, std140) uniform UBO {
42+
mat4 ModelViewProj;
43+
};
44+
45+
void main() {
46+
out_color = vec4(in_color, 1.0);
47+
gl_Position = ModelViewProj * vec4(in_position, 1.0);
48+
}

Examples/Hello.vert.hlsl

Lines changed: 0 additions & 29 deletions
This file was deleted.

Examples/Hello.vert.msl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,23 @@ struct UBO
88
float4x4 ModelViewProj;
99
};
1010

11-
struct vs_main_out
11+
struct main0_out
1212
{
13-
float4 _entryPointOutput_color [[user(locn0)]];
13+
float4 out_color [[user(locn0)]];
1414
float4 gl_Position [[position]];
1515
};
1616

17-
struct vs_main_in
17+
struct main0_in
1818
{
19-
float3 input_position [[attribute(0)]];
20-
float3 input_color [[attribute(1)]];
19+
float3 in_position [[attribute(0)]];
20+
float3 in_color [[attribute(1)]];
2121
};
2222

23-
vertex vs_main_out vs_main(vs_main_in in [[stage_in]], constant UBO& _40 [[buffer(0)]])
23+
vertex main0_out main0(main0_in in [[stage_in]], constant UBO& _30 [[buffer(0)]])
2424
{
25-
vs_main_out out = {};
26-
out._entryPointOutput_color = float4(in.input_color, 1.0);
27-
out.gl_Position = _40.ModelViewProj * float4(in.input_position, 1.0);
25+
main0_out out = {};
26+
out.out_color = float4(in.in_color, 1.0);
27+
out.gl_Position = _30.ModelViewProj * float4(in.in_position, 1.0);
2828
return out;
2929
}
3030

Examples/Hello.vert.spv

276 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)