Skip to content

Add shader cross-compilation pipeline for Hello examples#2

Merged
jdolan merged 9 commits into
mainfrom
jdolan-shader-cross-compilation-pipeline
Jun 27, 2026
Merged

Add shader cross-compilation pipeline for Hello examples#2
jdolan merged 9 commits into
mainfrom
jdolan-shader-cross-compilation-pipeline

Conversation

@jdolan

@jdolan jdolan commented Jun 27, 2026

Copy link
Copy Markdown
Owner

Replaces hard-coded MSL string constants in Hello.c / HelloCompute.c with a proper cross-platform HLSL→blob pipeline.

What's new

Examples/Shaders/ (new subdirectory)

Five HLSL sources + pre-compiled blobs versioned in the repo so consumers never need shadercross installed to build:

Shader Stage Entry point
Hello.vert.hlsl vertex vs_main
Hello.frag.hlsl fragment fs_main
HelloCompute.comp.hlsl compute cs_main
HelloCompute.vert.hlsl vertex vs_main
HelloCompute.frag.hlsl fragment fs_main

Each ships as .msl + .spv (built via glslc + shadercross). .dxil stubs are committed as empty placeholders pending a DXC-enabled shadercross build.

Examples/Shaders/Makefile.am

make shadercross regenerates all blobs. Rules: glslc HLSL→SPIR-V, shadercross SPIR-V→MSL, shadercross HLSL→DXIL. EXTRA_DIST includes all sources and blobs. all-local symlinks blobs into the build dir for out-of-tree builds.

ObjectivelyGPU-shadercross Xcode aggregate target

"Compile Shaders" run-script build phase with declared input/output paths for incremental rebuilds.

ObjectivelyGPU-shadercross.vcxproj (new)

VS Utility project with CustomBuild items per HLSL file; added to ObjectivelyGPU.sln.

RenderDevice::loadComputePipeline()

Parallel to loadShader() for compute stages — resolves the platform blob by format priority (MSL → DXIL → SPIR-V), fills code/code_size/format in SDL_GPUComputePipelineCreateInfo, and calls createComputePipeline.

Hello.c / HelloCompute.c

  • All inline MSL constants and create_shader() helpers removed
  • Resource path set at startup: SDL_GetBasePath() + "Shaders"
  • loadShader("Hello.vert", …) / loadShader("Hello.frag", …) etc.
  • loadComputePipeline("HelloCompute.comp", …) for the compute stage

Entry-point convention

HLSL entry points vs_main / fs_main / cs_main are preserved verbatim in MSL and SPIR-V output (only a literal main is renamed to main0 by SPIRV-Cross). No loadShader patching needed.

One known gap

DXIL blobs are empty stubs — the installed shadercross was built without DXC support. The Makefile, Xcode, and VS rules are all wired up; they just need a DXC-enabled shadercross to produce real outputs.

- Add Examples/Shaders/ subdirectory with HLSL sources and pre-compiled
  blobs (.msl, .spv) for Hello and HelloCompute examples
  (DXIL stubs pending DXC-enabled shadercross)
- Add Examples/Shaders/Makefile.am with 'make shadercross' target that
  regenerates all blobs via glslc (HLSL→SPIR-V) + shadercross (SPIR-V→MSL)
  and shadercross (HLSL→DXIL); blobs are versioned so consumers do not
  need shadercross installed
- Add ObjectivelyGPU-shadercross Xcode aggregate target with Compile
  Shaders run-script build phase; input/output paths declared for
  incremental rebuilds
- Add ObjectivelyGPU-shadercross VS utility project with CustomBuild
  items per HLSL file; add to ObjectivelyGPU.sln
- Add RenderDevice::loadComputePipeline(), parallel to loadShader() for
  compute stages; selects MSL/DXIL/SPIR-V blob by supported format
- Rewrite Hello.c and HelloCompute.c to load shaders via
  RenderDevice::loadShader / loadComputePipeline with a resource path
  of SDL_GetBasePath() + "Shaders"; remove all inline MSL constants
- Add Examples/Shaders/Makefile to configure.ac AC_CONFIG_FILES
- Add SUBDIRS = Shaders to Examples/Makefile.am

Entry-point convention: vs_main / fs_main / cs_main in HLSL.
SPIR-V and MSL preserve these names verbatim (only a literal 'main'
would be renamed to 'main0' by SPIRV-Cross).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 27, 2026 00:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR replaces inline Metal shader source in the Hello examples with a versioned, cross-platform shader asset pipeline (HLSL sources + precompiled blobs), and adds a RenderDevice helper for compute pipelines to load compiled blobs via the Resource system.

Changes:

  • Added RenderDevice::loadComputePipeline() to load compute shader blobs via Resource and create compute pipelines.
  • Added Examples/Shaders/ with HLSL sources plus committed platform blobs, and build-system wiring (Autotools + Xcode aggregate target + VS utility project) to regenerate them.
  • Updated Hello.c / HelloCompute.c to load shaders/pipelines from the shader assets directory at runtime.

Reviewed changes

Copilot reviewed 20 out of 30 changed files in this pull request and generated 11 comments.

Show a summary per file
File Description
Sources/ObjectivelyGPU/RenderDevice.h Adds public interface + Doxygen for loadComputePipeline.
Sources/ObjectivelyGPU/RenderDevice.c Implements loadComputePipeline and wires it into the class interface.
ObjectivelyGPU.xcodeproj/project.pbxproj Adds ObjectivelyGPU-shadercross aggregate target and a “Compile Shaders” run-script phase with declared inputs/outputs.
ObjectivelyGPU.vs15/ObjectivelyGPU.sln Adds the ObjectivelyGPU-shadercross utility project to the solution.
ObjectivelyGPU.vs15/ObjectivelyGPU-shadercross.vcxproj Adds per-shader CustomBuild steps to run shadercross for SPIR-V/MSL/DXIL.
Examples/Shaders/Makefile.am Adds make shadercross rules, EXTRA_DIST, and out-of-tree symlink behavior for blob discovery.
Examples/Shaders/Hello.vert.hlsl New HLSL source for Hello vertex stage.
Examples/Shaders/Hello.frag.hlsl New HLSL source for Hello fragment stage.
Examples/Shaders/HelloCompute.comp.hlsl New HLSL source for HelloCompute compute stage.
Examples/Shaders/HelloCompute.vert.hlsl New HLSL source for HelloCompute vertex stage.
Examples/Shaders/HelloCompute.frag.hlsl New HLSL source for HelloCompute fragment stage.
Examples/Shaders/Hello.vert.msl New precompiled MSL blob for Hello vertex stage.
Examples/Shaders/Hello.frag.msl New precompiled MSL blob for Hello fragment stage.
Examples/Shaders/HelloCompute.comp.msl New precompiled MSL blob for HelloCompute compute stage.
Examples/Shaders/HelloCompute.vert.msl New precompiled MSL blob for HelloCompute vertex stage.
Examples/Shaders/HelloCompute.frag.msl New precompiled MSL blob for HelloCompute fragment stage.
Examples/Shaders/Hello.vert.dxil Empty DXIL placeholder blob (stub).
Examples/Shaders/Hello.frag.dxil Empty DXIL placeholder blob (stub).
Examples/Shaders/HelloCompute.comp.dxil Empty DXIL placeholder blob (stub).
Examples/Shaders/HelloCompute.vert.dxil Empty DXIL placeholder blob (stub).
Examples/Shaders/HelloCompute.frag.dxil Empty DXIL placeholder blob (stub).
Examples/Makefile.am Adds Shaders subdir so shader assets are included in the examples build/install flow.
Examples/Hello.c Switches to Resource-based shader loading and sets shader resource path at startup.
Examples/HelloCompute.c Switches to Resource-based shader + compute pipeline loading and sets shader resource path at startup.
configure.ac Registers Examples/Shaders/Makefile for Autotools generation.

Comment thread Sources/ObjectivelyGPU/RenderDevice.c
Comment thread Sources/ObjectivelyGPU/RenderDevice.c Outdated
Comment thread Examples/Hello.c Outdated
Comment thread Examples/HelloCompute.c Outdated
Comment thread ObjectivelyGPU.vs15/ObjectivelyGPU-shadercross.vcxproj
Comment thread ObjectivelyGPU.vs15/ObjectivelyGPU-shadercross.vcxproj
Comment thread ObjectivelyGPU.vs15/ObjectivelyGPU-shadercross.vcxproj
Comment thread ObjectivelyGPU.vs15/ObjectivelyGPU-shadercross.vcxproj
Comment thread Examples/Hello.c
Comment on lines +189 to +197
vertexShader = $(renderDevice, loadShader, "Hello.vert", &(SDL_GPUShaderCreateInfo) {
.entrypoint = "vs_main",
.stage = SDL_GPU_SHADERSTAGE_VERTEX,
.num_uniform_buffers = 1,
});
fragmentShader = $(renderDevice, loadShader, "Hello.frag", &(SDL_GPUShaderCreateInfo) {
.entrypoint = "fs_main",
.stage = SDL_GPU_SHADERSTAGE_FRAGMENT,
});
Comment thread Examples/HelloCompute.c
Comment on lines +88 to +96
vertexShader = $(renderDevice, loadShader, "HelloCompute.vert", &(SDL_GPUShaderCreateInfo) {
.entrypoint = "vs_main",
.stage = SDL_GPU_SHADERSTAGE_VERTEX,
.num_storage_buffers = 1,
});
fragmentShader = $(renderDevice, loadShader, "HelloCompute.frag", &(SDL_GPUShaderCreateInfo) {
.entrypoint = "fs_main",
.stage = SDL_GPU_SHADERSTAGE_FRAGMENT,
});
jdolan and others added 8 commits June 26, 2026 21:20
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@jdolan
jdolan merged commit d58967c into main Jun 27, 2026
1 of 3 checks passed
@jdolan
jdolan deleted the jdolan-shader-cross-compilation-pipeline branch June 27, 2026 01:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants