Skip to content

Added GPU API example, made simple modifications to SDL3 bindings #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Niminem
Copy link

@Niminem Niminem commented Feb 20, 2025

Added GPU API example for rendering a basic triangle, and made simple modifications to SDL3 bindings to support the example.

There's still work to be had with the bindings, at least for the GPU API. Will make more PRs as I move along with my prototyping unless you get to them first.

@transmutrix
Copy link
Owner

Nice! I'll give this a go on Linux and then maybe see about getting Shadercross working on my Mac to test there.

@Niminem
Copy link
Author

Niminem commented Feb 20, 2025

@transmutrix good luck with Shadercross it was a bitch and a half to build right. I tried to do this on my mac but unfortunately mine was too old and isn't supported (the actual GPU API). Let me know if you want my notes on building it, I documented the process.

@transmutrix
Copy link
Owner

transmutrix commented Feb 21, 2025

I gave the example a go on Fedora yesterday and it worked fine, will try to get to macOS in short order. Notes could be helpful, if sharing is convenient, sure! ^_^

@Niminem
Copy link
Author

Niminem commented Feb 22, 2025

It's ugly but this is what I used, I followed this in general to get it to work on Mac as well but like I said I wasn't able to get the GPU API working, so I didn't even run Shadercross on the mac at all to even see if it worked:

# https://github.com/libsdl-org/SDL_shadercross/

# This is a library for translating shaders to different formats, intended for use
# with SDL's GPU API.

# It takes SPIRV or HLSL as the source and outputs DXBC, DXIL, SPIRV, MSL, or HLSL.

# This library can perform runtime translation and conveniently returns compiled
# SDL GPU shader objects from HLSL or SPIRV source.

# This library also provides a command line interface for offline translation of shaders.

# For SPIRV translation, this library depends on SPIRV-Cross. spirv-cross-c-shared.dll
# (or your platform's equivalent) can be obtained in the Vulkan SDK. For compiling to DXIL,
# dxcompiler.dll and dxil.dll (or your platform's equivalent) are required.
# DXIL dependencies obtained here: https://github.com/microsoft/DirectXShaderCompiler/releases
# It is strongly recommended that you ship SPIRV-Cross and DXIL dependencies along with your
# application. For compiling to DXBC, d3dcompiler_47 is shipped with Windows.
# Other platforms require vkd3d-utils.

# https://vulkan.lunarg.com/
# 0.) Download Vulkan. We'll need this if we want to compile GLSL to SPIRV (glslc tool).
# - ex: glslc shader.glsl.frag -o shader.spv.frag
# - we can, in theory, then use shadercross to convert SPIRV to HLSL or MSL (pretty cool)

# https://github.com/libsdl-org/SDL
# 1.) need to build and install SDL3. Process:
# (currently for Nim bindings, it's built on /releases/tag/preview-3.1.8)
# git clone https://github.com/libsdl-org/SDL.git SDL3
# cd SDL3
# mkdir build
# cd build
# cmake .. -DCMAKE_INSTALL_PREFIX="C:/SDL3-installed" -DSDL_SHARED=ON -DSDL_STATIC=ON
# cmake --build . --config Release
# cmake --install .
# now add the following to your PATH environment variable:
# C:\SDL3-installed\bin

# https://github.com/microsoft/DirectXShaderCompiler
# get release (pre-built) and add to same parent folder as SDL3
# https://github.com/microsoft/DirectXShaderCompiler/releases

# https://github.com/KhronosGroup/SPIRV-Cross
# 2.) need to build and install SPIRV-Cross. Process:
# git clone https://github.com/KhronosGroup/SPIRV-Cross/tree/vulkan-sdk-{version}
# cd SPIRV-Cross
# mkdir build
# cd build
# cmake .. -DCMAKE_INSTALL_PREFIX="C:/spirv-cross-installed" -DSPIRV_CROSS_STATIC=ON -DSPIRV_CROSS_SHARED=ON -DSPIRV_CROSS_CLI=ON
# cmake --build . --config Release
# cmake --install .

# https://github.com/libsdl-org/SDL_shadercross/
# cmake .. `
#          -DCMAKE_INSTALL_PREFIX="C:/SDL_shadercross" `
#          -DSDLSHADERCROSS_SHARED=ON `
#          -DSDLSHADERCROSS_STATIC=ON `
#          -Dspirv_cross_c_shared_DIR="C:\spirv-cross-installed\share\spirv_cross_c_shared\cmake" `
#          -DSDL3_DIR="C:/SDL3-installed/cmake" `
#          -DDirectXShaderCompiler_INCLUDE_PATH="C:\DXC\inc" `
#          -DDirectXShaderCompiler_dxcompiler_LIBRARY="C:/DXC/lib/x64/dxcompiler.lib" `
#          -DDirectXShaderCompiler_dxil_BINARY="C:/DXC/bin/x64/dxil.dll" `
#          -DSDLSHADERCROSS_INSTALL=ON
# cmake --build . --config Release
# cmake --install .

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