summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnders Leino <aleino@nvidia.com>2025-02-28 16:12:03 +0200
committerGitHub <noreply@github.com>2025-02-28 14:12:03 +0000
commite4b960024972420dfc96a758bfc35e8fcbf28273 (patch)
tree74bdcdf525ddf02a3ff18f948af8801d38d672bd
parentceb3af59f797ec60249debd614db13dd6902de12 (diff)
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
-rw-r--r--tests/compute/dump-repro.slang16
-rw-r--r--tools/render-test/slang-support.cpp216
-rw-r--r--tools/render-test/slang-support.h2
3 files changed, 108 insertions, 126 deletions
diff --git a/tests/compute/dump-repro.slang b/tests/compute/dump-repro.slang
deleted file mode 100644
index 9065c29fc..000000000
--- a/tests/compute/dump-repro.slang
+++ /dev/null
@@ -1,16 +0,0 @@
-//DISABLE_TEST(compute):SIMPLE:-profile cs_5_0 -entry computeMain -target dxbc -dump-repro repro.slang-repro
-//TEST:COMPILE:tests/compute/dump-repro.slang -profile cs_5_0 -entry computeMain -target dxbc -dump-repro repro.slang-repro
-//TEST(compute):COMPARE_COMPUTE_EX:-dx11 -compute -no-default-entry-point -compile-arg -load-repro -compile-arg repro.slang-repro -shaderobj
-// We only want to run on one API to test load worked
-//DISABLE_TEST(compute):COMPARE_COMPUTE:-dx12 -load-repro repro.slang-repro -shaderobj
-
-//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0 0 0], stride=4):out,name outputBuffer
-RWStructuredBuffer<int> outputBuffer;
-
-[numthreads(8, 1, 1)]
-void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
-{
- int index = int(dispatchThreadID.x);
-
- outputBuffer[index] = index * 2 + 1;
-}
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<SlangCompileRequest> m_requestDEPRECATED = nullptr;
- SlangSession* session = nullptr;
+ slang::IGlobalSession* globalSession = nullptr;
};
struct OutputAndLayout