summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2018-07-06 11:51:19 -0400
committerGitHub <noreply@github.com>2018-07-06 11:51:19 -0400
commit7b2a549fcf04263e07127315d72c8570e8063828 (patch)
tree8dd94dc20d8537f1c8406f5a9e561c9a68d599db /tools
parent338a7701b37fe133eba2f72455ba7c1790a8a1f5 (diff)
spCompile/spProcessCommandLineArguments return SlangResult (#610)
* * Make spCompile return SlangResult * Make spProcessCommandLineArguments return SlangResult (and not internally exit) * Remove calls to exit() * Fix typos * Make all output from spProcessCommandLineArguments get sent to diagnostic sink.
Diffstat (limited to 'tools')
-rw-r--r--tools/render-test/slang-support.cpp20
-rw-r--r--tools/slang-eval-test/main.cpp20
-rw-r--r--tools/slang-reflection-test/main.cpp42
3 files changed, 46 insertions, 36 deletions
diff --git a/tools/render-test/slang-support.cpp b/tools/render-test/slang-support.cpp
index d69060449..a6c252843 100644
--- a/tools/render-test/slang-support.cpp
+++ b/tools/render-test/slang-support.cpp
@@ -47,9 +47,9 @@ ShaderProgram* ShaderCompiler::compileProgram(
spSetPassThrough(slangRequest, passThrough);
}
- // Preocess any additional command-line options specified for Slang using
+ // Process any additional command-line options specified for Slang using
// the `-xslang <arg>` option to `render-test`.
- spProcessCommandLineArguments(slangRequest, &gOptions.slangArgs[0], gOptions.slangArgCount);
+ SLANG_RETURN_NULL_ON_FAIL(spProcessCommandLineArguments(slangRequest, &gOptions.slangArgs[0], gOptions.slangArgCount));
int computeTranslationUnit = 0;
int vertexTranslationUnit = 0;
@@ -92,7 +92,7 @@ ShaderProgram* ShaderCompiler::compileProgram(
}
- ShaderProgram * result = nullptr;
+ ShaderProgram * shaderProgram = nullptr;
Slang::List<const char*> rawTypeNames;
for (auto typeName : request.entryPointTypeArguments)
rawTypeNames.Add(typeName.Buffer());
@@ -105,12 +105,12 @@ ShaderProgram* ShaderCompiler::compileProgram(
rawTypeNames.Buffer());
spSetLineDirectiveMode(slangRequest, SLANG_LINE_DIRECTIVE_MODE_NONE);
- int compileErr = spCompile(slangRequest);
+ const SlangResult res = spCompile(slangRequest);
if (auto diagnostics = spGetDiagnosticOutput(slangRequest))
{
fprintf(stderr, "%s", diagnostics);
}
- if (!compileErr)
+ if (SLANG_SUCCEEDED(res))
{
size_t codeSize = 0;
char const* code = (char const*) spGetEntryPointCode(slangRequest, computeEntryPoint, &codeSize);
@@ -125,7 +125,7 @@ ShaderProgram* ShaderCompiler::compileProgram(
desc.kernels = &kernelDesc;
desc.kernelCount = 1;
- result = renderer->createProgram(desc);
+ shaderProgram = renderer->createProgram(desc);
}
}
else
@@ -133,14 +133,14 @@ ShaderProgram* ShaderCompiler::compileProgram(
int vertexEntryPoint = spAddEntryPointEx(slangRequest, vertexTranslationUnit, vertexEntryPointName, SLANG_STAGE_VERTEX, (int)rawTypeNames.Count(), rawTypeNames.Buffer());
int fragmentEntryPoint = spAddEntryPointEx(slangRequest, fragmentTranslationUnit, fragmentEntryPointName, SLANG_STAGE_FRAGMENT, (int)rawTypeNames.Count(), rawTypeNames.Buffer());
- int compileErr = spCompile(slangRequest);
+ const SlangResult res = spCompile(slangRequest);
if (auto diagnostics = spGetDiagnosticOutput(slangRequest))
{
// TODO(tfoley): re-enable when I get a logging solution in place
// OutputDebugStringA(diagnostics);
fprintf(stderr, "%s", diagnostics);
}
- if (!compileErr)
+ if (SLANG_SUCCEEDED(res))
{
size_t vertexCodeSize = 0;
char const* vertexCode = (char const*) spGetEntryPointCode(slangRequest, vertexEntryPoint, &vertexCodeSize);
@@ -165,7 +165,7 @@ ShaderProgram* ShaderCompiler::compileProgram(
desc.kernels = &kernelDescs[0];
desc.kernelCount = kDescCount;
- result = renderer->createProgram(desc);
+ shaderProgram = renderer->createProgram(desc);
}
}
// We clean up the Slang compilation context and result *after*
@@ -175,7 +175,7 @@ ShaderProgram* ShaderCompiler::compileProgram(
spDestroyCompileRequest(slangRequest);
spDestroySession(slangSession);
- return result;
+ return shaderProgram;
}
} // renderer_test
diff --git a/tools/slang-eval-test/main.cpp b/tools/slang-eval-test/main.cpp
index e01d4441b..ff2ebed34 100644
--- a/tools/slang-eval-test/main.cpp
+++ b/tools/slang-eval-test/main.cpp
@@ -6,9 +6,7 @@
#include "../../source/core/secure-crt.h"
#include <slang.h>
-int main(
- int argc,
- char** argv)
+static SlangResult innerMain(int argc, char*const* argv)
{
// TODO: parse arguments
@@ -24,7 +22,7 @@ int main(
size_t inputSize = ftell(inputFile);
fseek(inputFile, 0, SEEK_SET);
- char* inputText = (char*) malloc(inputSize + 1);
+ char* inputText = (char*)malloc(inputSize + 1);
fread(inputText, inputSize, 1, inputFile);
inputText[inputSize] = 0;
fclose(inputFile);
@@ -59,11 +57,11 @@ int main(
"main",
spFindProfile(session, "cs_5_0"));
- if( spCompile(request) != 0 )
+ if (SLANG_FAILED(spCompile(request)))
{
char const* output = spGetDiagnosticOutput(request);
fputs(output, stderr);
- exit(1);
+ return SLANG_FAIL;
}
// Things compiled, so now we need to run them...
@@ -129,5 +127,13 @@ int main(
spDestroyCompileRequest(request);
spDestroySession(session);
- return 0;
+ return SLANG_OK;
+}
+
+int main(
+ int argc,
+ char** argv)
+{
+ SlangResult res = innerMain(argc, argv);
+ return SLANG_FAILED(res) ? 1 : 0;
}
diff --git a/tools/slang-reflection-test/main.cpp b/tools/slang-reflection-test/main.cpp
index b900f3f62..667a0ddf7 100644
--- a/tools/slang-reflection-test/main.cpp
+++ b/tools/slang-reflection-test/main.cpp
@@ -6,6 +6,7 @@
#include <string.h>
#include <slang.h>
+#include <slang-com-helper.h>
struct PrettyWriter
{
@@ -854,10 +855,17 @@ void emitReflectionJSON(
emitReflectionJSON(writer, programReflection);
}
+static SlangResult maybeDumpDiagnostic(SlangResult res, SlangCompileRequest* request)
+{
+ const char* diagnostic;
+ if (SLANG_FAILED(res) && (diagnostic = spGetDiagnosticOutput(request)))
+ {
+ fputs(diagnostic, stderr);
+ }
+ return res;
+}
-int main(
- int argc,
- char** argv)
+static SlangResult innerMain(int argc, char*const*argv)
{
// Parse any command-line options
@@ -865,22 +873,10 @@ int main(
SlangCompileRequest* request = spCreateCompileRequest(session);
char const* appName = "slang-reflection-test";
- if(argc > 0) appName = argv[0];
-
- int err = spProcessCommandLineArguments(request, &argv[1], argc - 1);
- if( err )
- {
- char const* output = spGetDiagnosticOutput(request);
- fputs(output, stderr);
- exit(1);
- }
+ if (argc > 0) appName = argv[0];
- if( spCompile(request) != 0 )
- {
- char const* output = spGetDiagnosticOutput(request);
- fputs(output, stderr);
- exit(1);
- }
+ SLANG_RETURN_ON_FAIL(maybeDumpDiagnostic(spProcessCommandLineArguments(request, &argv[1], argc - 1), request));
+ SLANG_RETURN_ON_FAIL(maybeDumpDiagnostic(spCompile(request), request));
// Okay, let's go through and emit reflection info on whatever
// we have.
@@ -891,5 +887,13 @@ int main(
spDestroyCompileRequest(request);
spDestroySession(session);
- return 0;
+ return SLANG_OK;
+}
+
+int main(
+ int argc,
+ char** argv)
+{
+ SlangResult res = innerMain(argc, argv);
+ return SLANG_FAILED(res) ? 1 : 0;
}