Skip to content

Commit

Permalink
Rework Compile APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
thatcosmonaut committed Nov 7, 2024
1 parent 933e058 commit 3acf9c1
Show file tree
Hide file tree
Showing 3 changed files with 214 additions and 36 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ else()
endif()
endif()

set(DirectXShaderCompiler_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/external/DirectXShaderCompiler-binaries")
find_package(DirectXShaderCompiler REQUIRED)
endif()

Expand Down
59 changes: 48 additions & 11 deletions include/SDL3_gpu_shadercross/SDL_gpu_shadercross.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,25 @@ typedef enum SDL_ShaderCross_ShaderModel
SDL_SHADERCROSS_SHADERMODEL_6_0
} SDL_ShaderCross_ShaderModel;

typedef struct SDL_ShaderCross_ShaderResourceInfo {
Uint32 num_samplers; /**< The number of samplers defined in the shader. */
Uint32 num_storage_textures; /**< The number of storage textures defined in the shader. */
Uint32 num_storage_buffers; /**< The number of storage buffers defined in the shader. */
Uint32 num_uniform_buffers; /**< The number of uniform buffers defined in the shader. */
} SDL_ShaderCross_ShaderResourceInfo;

typedef struct SDL_ShaderCross_ComputeResourceInfo {
Uint32 num_samplers; /**< The number of samplers defined in the shader. */
Uint32 num_readonly_storage_textures; /**< The number of storage textures defined in the shader. */
Uint32 num_readonly_storage_buffers; /**< The number of storage buffers defined in the shader. */
Uint32 num_readwrite_storage_textures; /**< The number of read-write storage textures defined in the shader. */
Uint32 num_readwrite_storage_buffers; /**< The number of read-write storage buffers defined in the shader. */
Uint32 num_uniform_buffers; /**< The number of uniform buffers defined in the shader. */
Uint32 threadcount_x; /**< The number of threads in the X dimension. This should match the value in the shader. */
Uint32 threadcount_y; /**< The number of threads in the Y dimension. This should match the value in the shader. */
Uint32 threadcount_z; /**< The number of threads in the Z dimension. This should match the value in the shader. */
} SDL_ShaderCross_ComputeResourceInfo;

/**
* Initializes SDL_gpu_shadercross
*
Expand Down Expand Up @@ -157,27 +176,42 @@ extern SDL_DECLSPEC void * SDLCALL SDL_ShaderCross_CompileDXILFromSPIRV(
* Compile an SDL GPU shader from SPIRV code.
*
* \param device the SDL GPU device.
* \param createInfo a pointer to an SDL_GPUShaderCreateInfo.
* \param bytecode the SPIRV bytecode.
* \param bytecodeSize the length of the SPIRV bytecode.
* \param entrypoint the entry point function name for the shader in UTF-8.
* \param shaderStage the shader stage to compile the shader with.
* \param resourceInfo a pointer to an SDL_ShaderCross_ShaderResourceInfo.
* \returns a compiled SDL_GPUShader
*
* \threadsafety It is safe to call this function from any thread.
*/
extern SDL_DECLSPEC SDL_GPUShader * SDLCALL SDL_ShaderCross_CompileGraphicsShaderFromSPIRV(
SDL_GPUDevice *device,
const SDL_GPUShaderCreateInfo *createInfo);
const Uint8 *bytecode,
size_t bytecodeSize,
const char *entrypoint,
SDL_GPUShaderStage shaderStage,
const SDL_ShaderCross_ShaderResourceInfo *resourceInfo);

/**
* Compile an SDL GPU compute pipeline from SPIRV code.
*
* \param device the SDL GPU device.
* \param createInfo a pointer to an SDL_GPUComputePipelineCreateInfo.
* \param bytecode the SPIRV bytecode.
* \param bytecodeSize the length of the SPIRV bytecode.
* \param entrypoint the entry point function name for the shader in UTF-8.
* \param resourceInfo a pointer to an SDL_ShaderCross_ShaderResourceInfo.
* \returns a compiled SDL_GPUComputePipeline
*
* \threadsafety It is safe to call this function from any thread.
*/
extern SDL_DECLSPEC SDL_GPUComputePipeline * SDLCALL SDL_ShaderCross_CompileComputePipelineFromSPIRV(
SDL_GPUDevice *device,
const SDL_GPUComputePipelineCreateInfo *createInfo);
const Uint8 *bytecode,
size_t bytecodeSize,
const char *entrypoint,
const SDL_ShaderCross_ComputeResourceInfo *resourceInfo);

#endif /* SDL_GPU_SHADERCROSS_SPIRVCROSS */

#if SDL_GPU_SHADERCROSS_HLSL
Expand Down Expand Up @@ -249,34 +283,37 @@ extern SDL_DECLSPEC void * SDLCALL SDL_ShaderCross_CompileSPIRVFromHLSL(
* Compile an SDL GPU shader from HLSL Shader Model 6.0 code.
*
* \param device the SDL GPU device.
* \param createInfo a pointer to an SDL_GPUShaderCreateInfo.
* \param hlslSource the HLSL source code for the shader.
* \param entrypoint the entry point function name for the shader in UTF-8.
* \param graphicsShaderStage the shader stage to compile the shader with.
* \param resourceInfo a pointer to an SDL_ShaderCross_ShaderResourceInfo.
* \returns a compiled SDL_GPUShader
*
* \threadsafety It is safe to call this function from any thread.
*/
extern SDL_DECLSPEC SDL_GPUShader * SDLCALL SDL_ShaderCross_CompileGraphicsShaderFromHLSL(
SDL_GPUDevice *device,
const SDL_GPUShaderCreateInfo *createInfo,
const char *hlslSource,
SDL_GPUShaderStage graphicsShaderStage);
const char *entrypoint,
SDL_GPUShaderStage graphicsShaderStage,
const SDL_ShaderCross_ShaderResourceInfo *resourceInfo);

/**
* Compile an SDL GPU compute pipeline from HLSL Shader Model 6.0 code.
*
* \param device the SDL GPU device.
* \param createInfo a pointer to an SDL_GPUComputePipelineCreateInfo.
* \param hlslSource the HLSL source code for the shader.
* \param shaderStage the shader stage to compile the shader with.
* \param entrypoint the entry point function name for the shader in UTF-8.
* \param resourceInfo a pointer to an SDL_ShaderCross_ComputeResourceInfo.
* \returns a compiled SDL_GPUComputePipeline
*
* \threadsafety It is safe to call this function from any thread.
*/
extern SDL_DECLSPEC SDL_GPUComputePipeline * SDLCALL SDL_ShaderCross_CompileComputePipelineFromHLSL(
SDL_GPUDevice *device,
const SDL_GPUComputePipelineCreateInfo *createInfo,
const char *hlslSource);
const char *hlslSource,
const char *entrypoint,
const SDL_ShaderCross_ComputeResourceInfo *resourceInfo);

#endif /* SDL_GPU_SHADERCROSS_HLSL */

Expand Down
Loading

0 comments on commit 3acf9c1

Please sign in to comment.