diff options
Diffstat (limited to 'tools/render-test/slang-support.cpp')
| -rw-r--r-- | tools/render-test/slang-support.cpp | 49 |
1 files changed, 18 insertions, 31 deletions
diff --git a/tools/render-test/slang-support.cpp b/tools/render-test/slang-support.cpp index 77f1436b1..230f78453 100644 --- a/tools/render-test/slang-support.cpp +++ b/tools/render-test/slang-support.cpp @@ -11,19 +11,21 @@ namespace renderer_test { -RefPtr<ShaderProgram> ShaderCompiler::compileProgram( - ShaderCompileRequest const& request) +/* static */ SlangResult ShaderCompilerUtil::compileProgram(SlangSession* session, const Input& input, const ShaderCompileRequest& request, Output& out) { - SlangCompileRequest* slangRequest = spCreateCompileRequest(slangSession); + out.reset(); - spSetCodeGenTarget(slangRequest, target); - spSetTargetProfile(slangRequest, 0, - spFindProfile(slangSession, profile)); + SlangCompileRequest* slangRequest = spCreateCompileRequest(session); + out.request = slangRequest; + out.session = session; + + spSetCodeGenTarget(slangRequest, input.target); + spSetTargetProfile(slangRequest, 0, spFindProfile(session, input.profile)); // Define a macro so that shader code in a test can detect what language we // are nominally working with. char const* langDefine = nullptr; - switch (sourceLanguage) + switch (input.sourceLanguage) { case SLANG_SOURCE_LANGUAGE_GLSL: spAddPreprocessorDefine(slangRequest, "__GLSL__", "1"); @@ -41,14 +43,14 @@ RefPtr<ShaderProgram> ShaderCompiler::compileProgram( break; } - if (passThrough != SLANG_PASS_THROUGH_NONE) + if (input.passThrough != SLANG_PASS_THROUGH_NONE) { - spSetPassThrough(slangRequest, passThrough); + spSetPassThrough(slangRequest, input.passThrough); } // Process any additional command-line options specified for Slang using // the `-xslang <arg>` option to `render-test`. - SLANG_RETURN_NULL_ON_FAIL(spProcessCommandLineArguments(slangRequest, &gOptions.slangArgs[0], gOptions.slangArgCount)); + SLANG_RETURN_ON_FAIL(spProcessCommandLineArguments(slangRequest, input.args, input.argCount)); int computeTranslationUnit = 0; int vertexTranslationUnit = 0; @@ -57,6 +59,8 @@ RefPtr<ShaderProgram> ShaderCompiler::compileProgram( char const* fragmentEntryPointName = request.fragmentShader.name; char const* computeEntryPointName = request.computeShader.name; + const auto sourceLanguage = input.sourceLanguage; + if (sourceLanguage == SLANG_SOURCE_LANGUAGE_GLSL) { // GLSL presents unique challenges because, frankly, it got the whole @@ -91,8 +95,6 @@ RefPtr<ShaderProgram> ShaderCompiler::compileProgram( } - RefPtr<ShaderProgram> shaderProgram; - Slang::List<const char*> rawGlobalTypeNames; for (auto typeName : request.globalGenericTypeArguments) rawGlobalTypeNames.add(typeName.getBuffer()); @@ -146,12 +148,7 @@ RefPtr<ShaderProgram> ShaderCompiler::compileProgram( kernelDesc.codeBegin = code; kernelDesc.codeEnd = code + codeSize; - ShaderProgram::Desc desc; - desc.pipelineType = PipelineType::Compute; - desc.kernels = &kernelDesc; - desc.kernelCount = 1; - - shaderProgram = renderer->createProgram(desc); + out.set(PipelineType::Compute, &kernelDesc, 1); } } else @@ -189,21 +186,11 @@ RefPtr<ShaderProgram> ShaderCompiler::compileProgram( kernelDescs[1].codeBegin = fragmentCode; kernelDescs[1].codeEnd = fragmentCode + fragmentCodeSize; - ShaderProgram::Desc desc; - desc.pipelineType = PipelineType::Graphics; - desc.kernels = &kernelDescs[0]; - desc.kernelCount = kDescCount; - - shaderProgram = renderer->createProgram(desc); + out.set(PipelineType::Graphics, kernelDescs, kDescCount); } } - // We clean up the Slang compilation context and result *after* - // we have run the downstream compiler, because Slang - // owns the memory allocation for the generated text, and will - // free it when we destroy the compilation result. - spDestroyCompileRequest(slangRequest); - - return shaderProgram; + + return SLANG_OK; } } // renderer_test |
