From e4b960024972420dfc96a758bfc35e8fcbf28273 Mon Sep 17 00:00:00 2001 From: Anders Leino Date: Fri, 28 Feb 2025 16:12:03 +0200 Subject: Prepare for render test api migration (#6498) * Remove tests/compute/dump-repro The -load-repro option is no longer maintained. This helps to address issue #4760. * Rename ShaderCompilerUtil::Output::session to globalSession * Remove the load-repro codepath * Lifetime bugfix --- tools/render-test/slang-support.cpp | 216 ++++++++++++++++++------------------ tools/render-test/slang-support.h | 2 +- 2 files changed, 108 insertions(+), 110 deletions(-) (limited to 'tools/render-test') diff --git a/tools/render-test/slang-support.cpp b/tools/render-test/slang-support.cpp index 22a745d1f..5f9ae5a7f 100644 --- a/tools/render-test/slang-support.cpp +++ b/tools/render-test/slang-support.cpp @@ -35,7 +35,7 @@ void ShaderCompilerUtil::Output::reset() desc.slangGlobalScope = nullptr; } - session = nullptr; + globalSession = nullptr; m_requestDEPRECATED = nullptr; } @@ -58,9 +58,7 @@ static SlangResult _compileProgramImpl( globalSession->createCompileRequest(slangRequest.writeRef()); SLANG_ALLOW_DEPRECATED_END out.m_requestDEPRECATED = slangRequest; - out.session = globalSession; - - bool hasRepro = false; + out.globalSession = globalSession; // Parse all the extra args { @@ -68,8 +66,9 @@ static SlangResult _compileProgramImpl( for (const auto& arg : options.downstreamArgs.getArgsByName("slang")) { args.add(arg.value.getBuffer()); - if (arg.value == "-load-repro") - hasRepro = true; + // The -load-repro feature is not maintained, and not supported by the new compile API. + // TODO: Remove this when the feature has been deprecated. + SLANG_ASSERT(arg.value != "-load-repro"); } // If there are additional args parse them @@ -89,126 +88,122 @@ static SlangResult _compileProgramImpl( } } - // Only proceed if the command line arguments are not loading a repro. - if (!hasRepro) - { - spSetCodeGenTarget(slangRequest, input.target); - if (input.profile.getLength()) // do not set profile unless requested - spSetTargetProfile( - slangRequest, - 0, - spFindProfile(out.session, input.profile.getBuffer())); - if (options.generateSPIRVDirectly) - spSetTargetFlags(slangRequest, 0, SLANG_TARGET_FLAG_GENERATE_SPIRV_DIRECTLY); - else - spSetTargetFlags(slangRequest, 0, 0); + spSetCodeGenTarget(slangRequest, input.target); + if (input.profile.getLength()) // do not set profile unless requested + spSetTargetProfile( + slangRequest, + 0, + spFindProfile(out.globalSession, input.profile.getBuffer())); + if (options.generateSPIRVDirectly) + spSetTargetFlags(slangRequest, 0, SLANG_TARGET_FLAG_GENERATE_SPIRV_DIRECTLY); + else + spSetTargetFlags(slangRequest, 0, 0); - slangRequest->setAllowGLSLInput(options.allowGLSL); + slangRequest->setAllowGLSLInput(options.allowGLSL); - // Define a macro so that shader code in a test can detect what language we - // are nominally working with. - char const* langDefine = nullptr; - switch (input.sourceLanguage) - { - case SLANG_SOURCE_LANGUAGE_GLSL: - spAddPreprocessorDefine(slangRequest, "__GLSL__", "1"); - break; + // Define a macro so that shader code in a test can detect what language we + // are nominally working with. + char const* langDefine = nullptr; + switch (input.sourceLanguage) + { + case SLANG_SOURCE_LANGUAGE_GLSL: + spAddPreprocessorDefine(slangRequest, "__GLSL__", "1"); + break; - case SLANG_SOURCE_LANGUAGE_SLANG: - spAddPreprocessorDefine(slangRequest, "__SLANG__", "1"); - // fall through - case SLANG_SOURCE_LANGUAGE_HLSL: - spAddPreprocessorDefine(slangRequest, "__HLSL__", "1"); - break; - case SLANG_SOURCE_LANGUAGE_C: - spAddPreprocessorDefine(slangRequest, "__C__", "1"); - break; - case SLANG_SOURCE_LANGUAGE_CPP: - spAddPreprocessorDefine(slangRequest, "__CPP__", "1"); - break; - case SLANG_SOURCE_LANGUAGE_CUDA: - spAddPreprocessorDefine(slangRequest, "__CUDA__", "1"); - break; - case SLANG_SOURCE_LANGUAGE_WGSL: - spAddPreprocessorDefine(slangRequest, "__WGSL__", "1"); - break; + case SLANG_SOURCE_LANGUAGE_SLANG: + spAddPreprocessorDefine(slangRequest, "__SLANG__", "1"); + // fall through + case SLANG_SOURCE_LANGUAGE_HLSL: + spAddPreprocessorDefine(slangRequest, "__HLSL__", "1"); + break; + case SLANG_SOURCE_LANGUAGE_C: + spAddPreprocessorDefine(slangRequest, "__C__", "1"); + break; + case SLANG_SOURCE_LANGUAGE_CPP: + spAddPreprocessorDefine(slangRequest, "__CPP__", "1"); + break; + case SLANG_SOURCE_LANGUAGE_CUDA: + spAddPreprocessorDefine(slangRequest, "__CUDA__", "1"); + break; + case SLANG_SOURCE_LANGUAGE_WGSL: + spAddPreprocessorDefine(slangRequest, "__WGSL__", "1"); + break; - default: - assert(!"unexpected"); - break; - } + default: + assert(!"unexpected"); + break; + } - if (input.passThrough != SLANG_PASS_THROUGH_NONE) - { - spSetPassThrough(slangRequest, input.passThrough); - } - else - { - spSetCompileFlags(slangRequest, SLANG_COMPILE_FLAG_NO_CODEGEN); - } + if (input.passThrough != SLANG_PASS_THROUGH_NONE) + { + spSetPassThrough(slangRequest, input.passThrough); + } + else + { + spSetCompileFlags(slangRequest, SLANG_COMPILE_FLAG_NO_CODEGEN); + } - const auto sourceLanguage = input.sourceLanguage; + const auto sourceLanguage = input.sourceLanguage; - int translationUnitIndex = 0; - { - translationUnitIndex = spAddTranslationUnit(slangRequest, sourceLanguage, nullptr); - spAddTranslationUnitSourceString( - slangRequest, - translationUnitIndex, - request.source.path, - request.source.dataBegin); - } + int translationUnitIndex = 0; + { + translationUnitIndex = spAddTranslationUnit(slangRequest, sourceLanguage, nullptr); + spAddTranslationUnitSourceString( + slangRequest, + translationUnitIndex, + request.source.path, + request.source.dataBegin); + } + + const int globalSpecializationArgCount = int(request.globalSpecializationArgs.getCount()); + for (int ii = 0; ii < globalSpecializationArgCount; ++ii) + { + spSetTypeNameForGlobalExistentialTypeParam( + slangRequest, + ii, + request.globalSpecializationArgs[ii].getBuffer()); + } - const int globalSpecializationArgCount = int(request.globalSpecializationArgs.getCount()); - for (int ii = 0; ii < globalSpecializationArgCount; ++ii) + const int entryPointSpecializationArgCount = + int(request.entryPointSpecializationArgs.getCount()); + auto setEntryPointSpecializationArgs = [&](int entryPoint) + { + for (int ii = 0; ii < entryPointSpecializationArgCount; ++ii) { - spSetTypeNameForGlobalExistentialTypeParam( + spSetTypeNameForEntryPointExistentialTypeParam( slangRequest, + entryPoint, ii, - request.globalSpecializationArgs[ii].getBuffer()); + request.entryPointSpecializationArgs[ii].getBuffer()); } + }; - const int entryPointSpecializationArgCount = - int(request.entryPointSpecializationArgs.getCount()); - auto setEntryPointSpecializationArgs = [&](int entryPoint) - { - for (int ii = 0; ii < entryPointSpecializationArgCount; ++ii) - { - spSetTypeNameForEntryPointExistentialTypeParam( - slangRequest, - entryPoint, - ii, - request.entryPointSpecializationArgs[ii].getBuffer()); - } - }; - - Index explicitEntryPointCount = request.entryPoints.getCount(); - for (Index ee = 0; ee < explicitEntryPointCount; ++ee) + Index explicitEntryPointCount = request.entryPoints.getCount(); + for (Index ee = 0; ee < explicitEntryPointCount; ++ee) + { + if (options.dontAddDefaultEntryPoints) { - if (options.dontAddDefaultEntryPoints) - { - // If default entry points are not to be added, then - // the `request.entryPoints` array should have been - // left empty. - // - SLANG_ASSERT(false); - } - - auto& entryPointInfo = request.entryPoints[ee]; - int entryPointIndex = spAddEntryPoint( - slangRequest, - translationUnitIndex, - entryPointInfo.name, - entryPointInfo.slangStage); - SLANG_ASSERT(entryPointIndex == ee); - - setEntryPointSpecializationArgs(entryPointIndex); + // If default entry points are not to be added, then + // the `request.entryPoints` array should have been + // left empty. + // + SLANG_ASSERT(false); } - spSetLineDirectiveMode(slangRequest, SLANG_LINE_DIRECTIVE_MODE_NONE); + auto& entryPointInfo = request.entryPoints[ee]; + int entryPointIndex = spAddEntryPoint( + slangRequest, + translationUnitIndex, + entryPointInfo.name, + entryPointInfo.slangStage); + SLANG_ASSERT(entryPointIndex == ee); + + setEntryPointSpecializationArgs(entryPointIndex); } + spSetLineDirectiveMode(slangRequest, SLANG_LINE_DIRECTIVE_MODE_NONE); + if (options.generateSPIRVDirectly) { if (options.disableDebugInfo) @@ -354,9 +349,12 @@ static SlangResult compileProgram( SLANG_RETURN_ON_FAIL(_compileProgramImpl(globalSession, options, input, request, out)); out.m_requestDEPRECATED = slangOutput.m_requestDEPRECATED; - out.desc.slangGlobalScope = slangOutput.desc.slangGlobalScope; + // slangOutput.desc.slangGlobalScope and slangOutput.slangProgram are the same object, but + // the latter is a ComPtr while the former isn't. Therefore we need to detach so that the + // object doesn't get destroyed. + SLANG_ASSERT(slangOutput.desc.slangGlobalScope == slangOutput.slangProgram.get()); + out.desc.slangGlobalScope = slangOutput.slangProgram.detach(); slangOutput.m_requestDEPRECATED = nullptr; - return SLANG_OK; } } diff --git a/tools/render-test/slang-support.h b/tools/render-test/slang-support.h index e105b6b86..60e63b57f 100644 --- a/tools/render-test/slang-support.h +++ b/tools/render-test/slang-support.h @@ -69,7 +69,7 @@ struct ShaderCompilerUtil ComPtr m_requestDEPRECATED = nullptr; - SlangSession* session = nullptr; + slang::IGlobalSession* globalSession = nullptr; }; struct OutputAndLayout -- cgit v1.2.3