From 2394992a5bd56456c4163c986f2b6a36799f2096 Mon Sep 17 00:00:00 2001
From: Evan Hemsley <[EMAIL REDACTED]>
Date: Wed, 13 Nov 2024 17:11:13 -0800
Subject: [PATCH] Use SDL_SetError instead of SDL_LogError (#59)
---
src/SDL_shadercross.c | 92 +++++++++++++++++------------------
src/cli.c | 109 +++++++++++++++++++++++++++++-------------
2 files changed, 121 insertions(+), 80 deletions(-)
diff --git a/src/SDL_shadercross.c b/src/SDL_shadercross.c
index 71f749e..63ed560 100644
--- a/src/SDL_shadercross.c
+++ b/src/SDL_shadercross.c
@@ -354,7 +354,7 @@ static void *SDL_ShaderCross_INTERNAL_CompileUsingDXC(
#if defined(SDL_PLATFORM_XBOXONE) || defined(SDL_PLATFORM_XBOXSERIES)
if (SDL_DxcCreateInstance == NULL) {
- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s", "DxcCreateInstance function not loaded. Did you forget to call Init?");
+ SDL_SetError("%s", "DxcCreateInstance function not loaded. Did you forget to call Init?");
return NULL;
}
SDL_DxcCreateInstance(
@@ -379,19 +379,19 @@ static void *SDL_ShaderCross_INTERNAL_CompileUsingDXC(
#endif
if (dxcInstance == NULL) {
- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s", "Could not create DXC instance!");
+ SDL_SetError("%s", "Could not create DXC instance!");
return NULL;
}
if (utils == NULL) {
- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s", "Could not create DXC utils instance!");
+ SDL_SetError("%s", "Could not create DXC utils instance!");
dxcInstance->lpVtbl->Release(dxcInstance);
return NULL;
}
utils->lpVtbl->CreateDefaultIncludeHandler(utils, &includeHandler);
if (includeHandler == NULL) {
- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s", "Failed to create a default include handler!");
+ SDL_SetError("%s", "Failed to create a default include handler!");
dxcInstance->lpVtbl->Release(dxcInstance);
utils->lpVtbl->Release(utils);
return NULL;
@@ -399,7 +399,7 @@ static void *SDL_ShaderCross_INTERNAL_CompileUsingDXC(
entryPointUtf16 = (wchar_t *)SDL_iconv_string("WCHAR_T", "UTF-8", entrypoint, entryPointLength);
if (entryPointUtf16 == NULL) {
- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s", "Failed to convert entrypoint to WCHAR_T!");
+ SDL_SetError("%s", "Failed to convert entrypoint to WCHAR_T!");
dxcInstance->lpVtbl->Release(dxcInstance);
utils->lpVtbl->Release(utils);
return NULL;
@@ -422,7 +422,7 @@ static void *SDL_ShaderCross_INTERNAL_CompileUsingDXC(
includeDirUtf16 = (wchar_t *)SDL_iconv_string("WCHAR_T", "UTF-8", includeDir, includeDirLength);
if (includeDirUtf16 == NULL) {
- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s", "Failed to convert include dir to WCHAR_T!");
+ SDL_SetError("%s", "Failed to convert include dir to WCHAR_T!");
dxcInstance->lpVtbl->Release(dxcInstance);
utils->lpVtbl->Release(utils);
SDL_free(entryPointUtf16);
@@ -471,29 +471,28 @@ static void *SDL_ShaderCross_INTERNAL_CompileUsingDXC(
}
if (ret < 0) {
- SDL_LogError(SDL_LOG_CATEGORY_GPU,
- "IDxcShaderCompiler3::Compile failed: %X",
- ret);
+ SDL_SetError("IDxcShaderCompiler3::Compile failed: %X", ret);
dxcInstance->lpVtbl->Release(dxcInstance);
utils->lpVtbl->Release(utils);
return NULL;
} else if (dxcResult == NULL) {
- SDL_LogError(SDL_LOG_CATEGORY_GPU,
- "HLSL compilation failed with no IDxcResult");
+ SDL_SetError("%s", "HLSL compilation failed with no IDxcResult");
dxcInstance->lpVtbl->Release(dxcInstance);
utils->lpVtbl->Release(utils);
return NULL;
}
- dxcResult->lpVtbl->GetOutput(dxcResult,
- DXC_OUT_ERRORS,
- IID_IDxcBlobUtf8,
- (void **)&errors,
- NULL);
+ dxcResult->lpVtbl->GetOutput(
+ dxcResult,
+ DXC_OUT_ERRORS,
+ IID_IDxcBlobUtf8,
+ (void **)&errors,
+ NULL);
+
if (errors != NULL && errors->lpVtbl->GetBufferSize(errors) != 0) {
- SDL_LogError(SDL_LOG_CATEGORY_GPU,
- "HLSL compilation failed: %s",
- (char *)errors->lpVtbl->GetBufferPointer(errors));
+ SDL_SetError(
+ "HLSL compilation failed: %s",
+ (char *)errors->lpVtbl->GetBufferPointer(errors));
dxcResult->lpVtbl->Release(dxcResult);
dxcInstance->lpVtbl->Release(dxcInstance);
utils->lpVtbl->Release(utils);
@@ -506,7 +505,7 @@ static void *SDL_ShaderCross_INTERNAL_CompileUsingDXC(
(void **)&blob,
NULL);
if (ret < 0) {
- SDL_LogError(SDL_LOG_CATEGORY_GPU, "IDxcBlob fetch failed");
+ SDL_SetError("%s", "IDxcBlob fetch failed");
dxcResult->lpVtbl->Release(dxcResult);
dxcInstance->lpVtbl->Release(dxcInstance);
utils->lpVtbl->Release(utils);
@@ -524,7 +523,7 @@ static void *SDL_ShaderCross_INTERNAL_CompileUsingDXC(
return buffer;
#else
- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s", "Shadercross was not built with DXC support, cannot compile using DXC!");
+ SDL_SetError("%s", "Shadercross was not built with DXC support, cannot compile using DXC!");
return NULL;
#endif /* SDL_SHADERCROSS_DXC */
}
@@ -668,7 +667,7 @@ static ID3DBlob *SDL_ShaderCross_INTERNAL_CompileDXBC(
HRESULT ret;
if (SDL_D3DCompile == NULL) {
- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s", "Could not load D3DCompile!");
+ SDL_SetError("%s", "Could not load D3DCompile!");
return NULL;
}
@@ -686,8 +685,7 @@ static ID3DBlob *SDL_ShaderCross_INTERNAL_CompileDXBC(
&errorBlob);
if (ret < 0) {
- SDL_LogError(
- SDL_LOG_CATEGORY_GPU,
+ SDL_SetError(
"HLSL compilation failed: %s",
(char *)errorBlob->lpVtbl->GetBufferPointer(errorBlob));
return NULL;
@@ -798,7 +796,7 @@ static void *SDL_ShaderCross_INTERNAL_CreateShaderFromHLSL(
&bytecodeSize);
if (spirv == NULL) {
- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s", "Failed to compile SPIR-V!");
+ SDL_SetError("%s", "Failed to compile SPIR-V!");
return NULL;
}
@@ -976,14 +974,14 @@ static SPIRVTranspileContext *SDL_ShaderCross_INTERNAL_TranspileFromSPIRV(
spvc_msl_resource_binding binding;
for (size_t i = 0; i < num_texture_samplers; i += 1) {
if (!spvc_compiler_has_decoration(compiler, reflected_resources[i].id, SpvDecorationDescriptorSet) || !spvc_compiler_has_decoration(compiler, reflected_resources[i].id, SpvDecorationBinding)) {
- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s", "Shader resources must have descriptor set and binding index!");
+ SDL_SetError("%s", "Shader resources must have descriptor set and binding index!");
spvc_context_destroy(context);
return NULL;
}
unsigned int descriptor_set_index = spvc_compiler_get_decoration(compiler, reflected_resources[i].id, SpvDecorationDescriptorSet);
if (!(descriptor_set_index == 0 || descriptor_set_index == 2)) {
- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s", "Descriptor set index for graphics texture-sampler must be 0 or 2!");
+ SDL_SetError("%s", "Descriptor set index for graphics texture-sampler must be 0 or 2!");
spvc_context_destroy(context);
return NULL;
}
@@ -1017,14 +1015,14 @@ static SPIRVTranspileContext *SDL_ShaderCross_INTERNAL_TranspileFromSPIRV(
for (size_t i = 0; i < num_storage_textures; i += 1) {
if (!spvc_compiler_has_decoration(compiler, reflected_resources[i].id, SpvDecorationDescriptorSet) || !spvc_compiler_has_decoration(compiler, reflected_resources[i].id, SpvDecorationBinding)) {
- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s", "Shader resources must have descriptor set and binding index!");
+ SDL_SetError("%s", "Shader resources must have descriptor set and binding index!");
spvc_context_destroy(context);
return NULL;
}
unsigned int descriptor_set_index = spvc_compiler_get_decoration(compiler, reflected_resources[i].id, SpvDecorationDescriptorSet);
if (!(descriptor_set_index == 0 || descriptor_set_index == 2)) {
- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s", "Descriptor set index for graphics storage texture must be 0 or 2!");
+ SDL_SetError("%s", "Descriptor set index for graphics storage texture must be 0 or 2!");
spvc_context_destroy(context);
return NULL;
}
@@ -1057,14 +1055,14 @@ static SPIRVTranspileContext *SDL_ShaderCross_INTERNAL_TranspileFromSPIRV(
for (size_t i = 0; i < num_storage_buffers; i += 1) {
if (!spvc_compiler_has_decoration(compiler, reflected_resources[i].id, SpvDecorationDescriptorSet) || !spvc_compiler_has_decoration(compiler, reflected_resources[i].id, SpvDecorationBinding)) {
- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s", "Shader resources must have descriptor set and binding index!");
+ SDL_SetError("%s", "Shader resources must have descriptor set and binding index!");
spvc_context_destroy(context);
return NULL;
}
unsigned int descriptor_set_index = spvc_compiler_get_decoration(compiler, reflected_resources[i].id, SpvDecorationDescriptorSet);
if (!(descriptor_set_index == 0 || descriptor_set_index == 2)) {
- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s", "Descriptor set index for graphics storage buffer must be 0 or 2!");
+ SDL_SetError("%s", "Descriptor set index for graphics storage buffer must be 0 or 2!");
spvc_context_destroy(context);
return NULL;
}
@@ -1097,14 +1095,14 @@ static SPIRVTranspileContext *SDL_ShaderCross_INTERNAL_TranspileFromSPIRV(
for (size_t i = 0; i< num_uniform_buffers; i += 1) {
if (!spvc_compiler_has_decoration(compiler, reflected_resources[i].id, SpvDecorationDescriptorSet) || !spvc_compiler_has_decoration(compiler, reflected_resources[i].id, SpvDecorationBinding)) {
- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s", "Shader resources must have descriptor set and binding index!");
+ SDL_SetError("%s", "Shader resources must have descriptor set and binding index!");
spvc_context_destroy(context);
return NULL;
}
unsigned int descriptor_set_index = spvc_compiler_get_decoration(compiler, reflected_resources[i].id, SpvDecorationDescriptorSet);
if (!(descriptor_set_index == 1 || descriptor_set_index == 3)) {
- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s", "Descriptor set index for graphics uniform buffer must be 1 or 3!");
+ SDL_SetError("%s", "Descriptor set index for graphics uniform buffer must be 1 or 3!");
spvc_context_destroy(context);
return NULL;
}
@@ -1171,14 +1169,14 @@ static SPIRVTranspileContext *SDL_ShaderCross_INTERNAL_TranspileFromSPIRV(
for (size_t i = 0; i < num_texture_samplers; i += 1) {
if (!spvc_compiler_has_decoration(compiler, reflected_resources[i].id, SpvDecorationDescriptorSet) || !spvc_compiler_has_decoration(compiler, reflected_resources[i].id, SpvDecorationBinding)) {
- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s", "Shader resources must have descriptor set and binding index!");
+ SDL_SetError("%s", "Shader resources must have descriptor set and binding index!");
spvc_context_destroy(context);
return NULL;
}
unsigned int descriptor_set_index = spvc_compiler_get_decoration(compiler, reflected_resources[i].id, SpvDecorationDescriptorSet);
if (descriptor_set_index != 0) {
- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s", "Descriptor set index for compute texture-sampler must be 0!");
+ SDL_SetError("%s", "Descriptor set index for compute texture-sampler must be 0!");
spvc_context_destroy(context);
return NULL;
}
@@ -1214,14 +1212,14 @@ static SPIRVTranspileContext *SDL_ShaderCross_INTERNAL_TranspileFromSPIRV(
// Readonly storage textures
for (size_t i = 0; i < num_storage_textures; i += 1) {
if (!spvc_compiler_has_decoration(compiler, reflected_resources[i].id, SpvDecorationDescriptorSet) || !spvc_compiler_has_decoration(compiler, reflected_resources[i].id, SpvDecorationBinding)) {
- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s", "Shader resources must have descriptor set and binding index!");
+ SDL_SetError("%s", "Shader resources must have descriptor set and binding index!");
spvc_context_destroy(context);
return NULL;
}
unsigned int descriptor_set_index = spvc_compiler_get_decoration(compiler, reflected_resources[i].id, SpvDecorationDescriptorSet);
if (!(descriptor_set_index == 0 || descriptor_set_index == 1)) {
- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s", "Descriptor set index for compute storage texture must be 0 or 1!");
+ SDL_SetError("%s", "Descriptor set index for compute storage texture must be 0 or 1!");
spvc_context_destroy(context);
return NULL;
}
@@ -1283,14 +1281,14 @@ static SPIRVTranspileContext *SDL_ShaderCross_INTERNAL_TranspileFromSPIRV(
// Readonly storage buffers
for (size_t i = 0; i < num_storage_buffers; i += 1) {
if (!spvc_compiler_has_decoration(compiler, reflected_resources[i].id, SpvDecorationDescriptorSet) || !spvc_compiler_has_decoration(compiler, reflected_resources[i].id, SpvDecorationBinding)) {
- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s", "Shader resources must have descriptor set and binding index!");
+ SDL_SetError("%s", "Shader resources must have descriptor set and binding index!");
spvc_context_destroy(context);
return NULL;
}
unsigned int descriptor_set_index = spvc_compiler_get_decoration(compiler, reflected_resources[i].id, SpvDecorationDescriptorSet);
if (!(descriptor_set_index == 0 || descriptor_set_index == 1)) {
- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s", "Descriptor set index for compute storage buffer must be 0 or 1!");
+ SDL_SetError("%s", "Descriptor set index for compute storage buffer must be 0 or 1!");
spvc_context_destroy(context);
return NULL;
}
@@ -1351,14 +1349,14 @@ static SPIRVTranspileContext *SDL_ShaderCross_INTERNAL_TranspileFromSPIRV(
for (size_t i = 0; i < num_uniform_buffers; i += 1) {
if (!spvc_compiler_has_decoration(compiler, reflected_resources[i].id, SpvDecorationDescriptorSet) || !spvc_compiler_has_decoration(compiler, reflected_resources[i].id, SpvDecorationBinding)) {
- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s", "Shader resources must have descriptor set and binding index!");
+ SDL_SetError("%s", "Shader resources must have descriptor set and binding index!");
spvc_context_destroy(context);
return NULL;
}
unsigned int descriptor_set_index = spvc_compiler_get_decoration(compiler, reflected_resources[i].id, SpvDecorationDescriptorSet);
if (descriptor_set_index != 2) {
- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s", "Descriptor set index for compute uniform buffer must be 2!");
+ SDL_SetError("%s", "Descriptor set index for compute uniform buffer must be 2!");
spvc_context_destroy(context);
return NULL;
}
@@ -1620,7 +1618,7 @@ static bool SDL_ShaderCross_INTERNAL_ReflectComputeSPIRV(
for (size_t i = 0; i < num_storage_textures; i += 1) {
if (!spvc_compiler_has_decoration(compiler, reflected_resources[i].id, SpvDecorationDescriptorSet) || !spvc_compiler_has_decoration(compiler, reflected_resources[i].id, SpvDecorationBinding)) {
- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s", "Shader resources must have descriptor set and binding index!");
+ SDL_SetError("%s", "Shader resources must have descriptor set and binding index!");
spvc_context_destroy(context);
return false;
}
@@ -1632,7 +1630,7 @@ static bool SDL_ShaderCross_INTERNAL_ReflectComputeSPIRV(
} else if (descriptor_set_index == 1) {
num_readwrite_storage_textures += 1;
} else {
- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s", "Descriptor set index for compute storage texture must be 0 or 1!");
+ SDL_SetError("%s", "Descriptor set index for compute storage texture must be 0 or 1!");
spvc_context_destroy(context);
return false;
}
@@ -1653,14 +1651,14 @@ static bool SDL_ShaderCross_INTERNAL_ReflectComputeSPIRV(
// Readonly storage buffers
for (size_t i = 0; i < num_storage_buffers; i += 1) {
if (!spvc_compiler_has_decoration(compiler, reflected_resources[i].id, SpvDecorationDescriptorSet) || !spvc_compiler_has_decoration(compiler, reflected_resources[i].id, SpvDecorationBinding)) {
- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s", "Shader resources must have descriptor set and binding index!");
+ SDL_SetError("%s", "Shader resources must have descriptor set and binding index!");
spvc_context_destroy(context);
return false;
}
unsigned int descriptor_set_index = spvc_compiler_get_decoration(compiler, reflected_resources[i].id, SpvDecorationDescriptorSet);
if (!(descriptor_set_index == 0 || descriptor_set_index == 1)) {
- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s", "Descriptor set index for compute storage buffer must be 0 or 1!");
+ SDL_SetError("%s", "Descriptor set index for compute storage buffer must be 0 or 1!");
spvc_context_destroy(context);
return false;
}
@@ -1670,7 +1668,7 @@ static bool SDL_ShaderCross_INTERNAL_ReflectComputeSPIRV(
} else if (descriptor_set_index == 1) {
num_readwrite_storage_buffers += 1;
} else {
- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s", "Descriptor set index for compute storage buffer must be 0 or 1!");
+ SDL_SetError("%s", "Descriptor set index for compute storage buffer must be 0 or 1!");
spvc_context_destroy(context);
return false;
}
@@ -1888,7 +1886,7 @@ void *SDL_ShaderCross_CompileDXILFromSPIRV(
size_t *size)
{
#ifndef SDL_SHADERCROSS_DXC
- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s", "Shadercross was not compiled with DXC support, cannot compile to SPIR-V!");
+ SDL_SetError("%s", "Shadercross was not compiled with DXC support, cannot compile to SPIR-V!");
return NULL;
#endif
diff --git a/src/cli.c b/src/cli.c
index 26eaa6e..5a29602 100644
--- a/src/cli.c
+++ b/src/cli.c
@@ -256,6 +256,7 @@ int main(int argc, char *argv[])
}
size_t bytecodeSize;
+ int result = 0;
if (spirvSource) {
switch (destinationFormat) {
@@ -266,8 +267,13 @@ int main(int argc, char *argv[])
entrypointName,
shaderStage,
&bytecodeSize);
- SDL_WriteIO(outputIO, buffer, bytecodeSize);
- SDL_free(buffer);
+ if (buffer == NULL) {
+ SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to compile DXBC from SPIR-V: %s", SDL_GetError());
+ result = 1;
+ } else {
+ SDL_WriteIO(outputIO, buffer, bytecodeSize);
+ SDL_free(buffer);
+ }
break;
}
@@ -278,8 +284,13 @@ int main(int argc, char *argv[])
entrypointName,
shaderStage,
&bytecodeSize);
- SDL_WriteIO(outputIO, buffer, bytecodeSize);
- SDL_free(buffer);
+ if (buffer == NULL) {
+ SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to compile DXIL from SPIR-V: %s", SDL_GetError());
+ result = 1;
+ } else {
+ SDL_WriteIO(outputIO, buffer, bytecodeSize);
+ SDL_free(buffer);
+ }
break;
}
@@ -289,8 +300,13 @@ int main(int argc, char *argv[])
fileSize,
entrypointName,
shaderStage);
- SDL_IOprintf(outputIO, "%s", buffer);
- SDL_free(buffer);
+ if (buffer == NULL) {
+ SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to transpile MSL from SPIR-V: %s", SDL_GetError());
+ result = 1;
+ } else {
+ SDL_IOprintf(outputIO, "%s", buffer);
+ SDL_free(buffer);
+ }
break;
}
@@ -300,24 +316,26 @@ int main(int argc, char *argv[])
fileSize,
entrypointName,
shaderStage);
-
if (buffer == NULL) {
- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s", "Failed to transpile HLSL from SPIRV!");
- return 1;
+ SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to transpile HLSL from SPIRV: %s", SDL_GetError());
+ result = 1;
+ } else {
+ SDL_IOprintf(outputIO, "%s", buffer);
+ SDL_free(buffer);
}
- SDL_IOprintf(outputIO, "%s", buffer);
- SDL_free(buffer);
break;
}
case SHADERFORMAT_SPIRV: {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Input and output are both SPIRV. Did you mean to do that?");
- return 1;
+ result = 1;
+ break;
}
case SHADERFORMAT_INVALID: {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Destination format not provided!");
- return 1;
+ result = 1;
+ break;
}
}
} else {
@@ -329,8 +347,13 @@ int main(int argc, char *argv[])
includeDir,
shaderStage,
&bytecodeSize);
- SDL_WriteIO(outputIO, buffer, bytecodeSize);
- SDL_free(buffer);
+ if (buffer == NULL) {
+ SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to compile DXBC from HLSL: %s", SDL_GetError());
+ result = 1;
+ } else {
+ SDL_WriteIO(outputIO, buffer, bytecodeSize);
+ SDL_free(buffer);
+ }
break;
}
@@ -341,11 +364,17 @@ int main(int argc, char *argv[])
includeDir,
shaderStage,
&bytecodeSize);
- SDL_WriteIO(outputIO, buffer, bytecodeSize);
- SDL_free(buffer);
+ if (buffer == NULL) {
+ SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to compile DXIL from HLSL: %s", SDL_GetError());
+ result = 1;
+ } else {
+ SDL_WriteIO(outputIO, buffer, bytecodeSize);
+ SDL_free(buffer);
+ }
break;
}
+ // TODO: Should we have TranspileMSLFromHLSL?
case SHADERFORMAT_MSL: {
void *spirv = SDL_ShaderCross_CompileSPIRVFromHLSL(
fileData,
@@ -354,17 +383,23 @@ int main(int argc, char *argv[])
shaderStage,
&bytecodeSize);
if (spirv == NULL) {
- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s", "Failed to compile SPIR-V!");
- return 1;
+ SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to transpile MSL from HLSL: %s", SDL_GetError());
+ result = 1;
+ } else {
+ char *buffer = SDL_ShaderCross_TranspileMSLFromSPIRV(
+ spirv,
+ bytecodeSize,
+ entrypointName,
+ shaderStage);
+ if (buffer == NULL) {
+ SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to transpile MSL from HLSL: %s", SDL_GetError());
+ result = 1;
+ } else {
+ SDL_IOprintf(outputIO, "%s", buffer);
+ SDL_free(spirv);
+ SDL_free(buffer);
+ }
}
- char *buffer = SDL_ShaderCross_TranspileMSLFromSPIRV(
- spirv,
- bytecodeSize,
- entrypointName,
- shaderStage);
- SDL_IOprintf(outputIO, "%s", buffer);
- SDL_free(spirv);
- SDL_free(buffer);
break;
}
@@ -375,8 +410,13 @@ int main(int argc, char *argv[])
includeDir,
shaderStage,
&bytecodeSize);
- SDL_WriteIO(outputIO, buffer, bytecodeSize);
- SDL_free(buffer);
+ if (buffer == NULL) {
+ SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to compile SPIR-V From HLSL: %s", SDL_GetError());
+ result = 1;
+ } else {
+ SDL_WriteIO(outputIO, buffer, bytecodeSize);
+ SDL_free(buffer);
+ }
break;
}
@@ -390,7 +430,8 @@ int main(int argc, char *argv[])
if (spirv == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s", "Failed to compile HLSL to SPIRV!");
- return 1;
+ result = 1;
+ break;
}
char *buffer = SDL_ShaderCross_TranspileHLSLFromSPIRV(
@@ -401,7 +442,8 @@ int main(int argc, char *argv[])
if (buffer == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s", "Failed to transpile HLSL from SPIRV!");
- return 1;
+ result = 1;
+ break;
}
SDL_IOprintf(outputIO, "%s", buffer);
@@ -412,7 +454,8 @@ int main(int argc, char *argv[])
case SHADERFORMAT_INVALID: {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Destination format not provided!");
- return 1;
+ result = 1;
+ break;
}
}
}
@@ -420,5 +463,5 @@ int main(int argc, char *argv[])
SDL_CloseIO(outputIO);
SDL_free(fileData);
SDL_ShaderCross_Quit();
- return 0;
+ return result;
}