Add shader cross-compilation pipeline for Hello examples#2
Merged
Conversation
- 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>
Contributor
There was a problem hiding this comment.
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 viaResourceand 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.cto 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 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 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, | ||
| }); |
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replaces hard-coded MSL string constants in
Hello.c/HelloCompute.cwith 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
shadercrossinstalled to build:Hello.vert.hlslvs_mainHello.frag.hlslfs_mainHelloCompute.comp.hlslcs_mainHelloCompute.vert.hlslvs_mainHelloCompute.frag.hlslfs_mainEach ships as
.msl+.spv(built viaglslc+shadercross)..dxilstubs are committed as empty placeholders pending a DXC-enabledshadercrossbuild.Examples/Shaders/Makefile.ammake shadercrossregenerates all blobs. Rules:glslcHLSL→SPIR-V,shadercrossSPIR-V→MSL,shadercrossHLSL→DXIL.EXTRA_DISTincludes all sources and blobs.all-localsymlinks blobs into the build dir for out-of-tree builds.ObjectivelyGPU-shadercrossXcode aggregate target"Compile Shaders" run-script build phase with declared input/output paths for incremental rebuilds.
ObjectivelyGPU-shadercross.vcxproj(new)VS Utility project with
CustomBuilditems per HLSL file; added toObjectivelyGPU.sln.RenderDevice::loadComputePipeline()Parallel to
loadShader()for compute stages — resolves the platform blob by format priority (MSL → DXIL → SPIR-V), fillscode/code_size/formatinSDL_GPUComputePipelineCreateInfo, and callscreateComputePipeline.Hello.c/HelloCompute.ccreate_shader()helpers removedSDL_GetBasePath() + "Shaders"loadShader("Hello.vert", …)/loadShader("Hello.frag", …)etc.loadComputePipeline("HelloCompute.comp", …)for the compute stageEntry-point convention
HLSL entry points
vs_main/fs_main/cs_mainare preserved verbatim in MSL and SPIR-V output (only a literalmainis renamed tomain0by SPIRV-Cross). NoloadShaderpatching needed.One known gap
DXIL blobs are empty stubs — the installed
shadercrosswas built without DXC support. The Makefile, Xcode, and VS rules are all wired up; they just need a DXC-enabledshadercrossto produce real outputs.