summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorcheneym2 <acheney@nvidia.com>2024-08-15 12:36:41 -0400
committerGitHub <noreply@github.com>2024-08-15 12:36:41 -0400
commit27b2229baa635f4cd6316d987a05ae8979ceab68 (patch)
tree1d25f4c1225e8f0782c0bdf2d082ff859ffe178d /tools
parent99673d783761d954e7e8333110d104144ae1d51a (diff)
Make precompileForTargets work with Slang API (#4845)
* Make precompileForTargets work with Slang API precompileForTargets, renamed to precompileForTarget, does not need an EndToEndCompileRequest and some objects created from it are not necessary either. Take only a target enum and a diagnostic blob as input and handle everything else internally, such as creating the TargetReq with chosen profile. Fixes #4790 * Update slang-module.cpp * Update slang-module.cpp
Diffstat (limited to 'tools')
-rw-r--r--tools/gfx-unit-test/precompiled-module-2.cpp36
1 files changed, 33 insertions, 3 deletions
diff --git a/tools/gfx-unit-test/precompiled-module-2.cpp b/tools/gfx-unit-test/precompiled-module-2.cpp
index 3da77e05c..93b9d1b89 100644
--- a/tools/gfx-unit-test/precompiled-module-2.cpp
+++ b/tools/gfx-unit-test/precompiled-module-2.cpp
@@ -17,7 +17,8 @@ namespace gfx_test
static Slang::Result precompileProgram(
gfx::IDevice* device,
ISlangMutableFileSystem* fileSys,
- const char* shaderModuleName)
+ const char* shaderModuleName,
+ bool precompileToTarget)
{
Slang::ComPtr<slang::ISession> slangSession;
SLANG_RETURN_ON_FAIL(device->getSlangSession(slangSession.writeRef()));
@@ -34,6 +35,20 @@ namespace gfx_test
if (!module)
return SLANG_FAIL;
+ if (precompileToTarget)
+ {
+ SlangCompileTarget target;
+ switch (device->getDeviceInfo().deviceType)
+ {
+ case gfx::DeviceType::DirectX12:
+ target = SLANG_DXIL;
+ break;
+ default:
+ return SLANG_FAIL;
+ }
+ module->precompileForTarget(target, diagnosticsBlob.writeRef());
+ }
+
// Write loaded modules to memory file system.
for (SlangInt i = 0; i < slangSession->getLoadedModuleCount(); i++)
{
@@ -50,7 +65,7 @@ namespace gfx_test
return SLANG_OK;
}
- void precompiledModule2TestImpl(IDevice* device, UnitTestContext* context)
+ void precompiledModule2TestImplCommon(IDevice* device, UnitTestContext* context, bool precompileToTarget)
{
Slang::ComPtr<ITransientResourceHeap> transientHeap;
ITransientResourceHeap::Desc transientHeapDesc = {};
@@ -63,7 +78,7 @@ namespace gfx_test
ComPtr<IShaderProgram> shaderProgram;
slang::ProgramLayout* slangReflection;
- GFX_CHECK_CALL_ABORT(precompileProgram(device, memoryFileSystem.get(), "precompiled-module-imported"));
+ GFX_CHECK_CALL_ABORT(precompileProgram(device, memoryFileSystem.get(), "precompiled-module-imported", precompileToTarget));
// Next, load the precompiled slang program.
Slang::ComPtr<slang::ISession> slangSession;
@@ -168,11 +183,26 @@ namespace gfx_test
Slang::makeArray<float>(3.0f, 3.0f, 3.0f, 3.0f));
}
+ void precompiledModule2TestImpl(IDevice* device, UnitTestContext* context)
+ {
+ precompiledModule2TestImplCommon(device, context, false);
+ }
+
+ void precompiledTargetModule2TestImpl(IDevice* device, UnitTestContext* context)
+ {
+ precompiledModule2TestImplCommon(device, context, true);
+ }
+
SLANG_UNIT_TEST(precompiledModule2D3D12)
{
runTestImpl(precompiledModule2TestImpl, unitTestContext, Slang::RenderApiFlag::D3D12);
}
+ SLANG_UNIT_TEST(precompiledTargetModule2D3D12)
+ {
+ runTestImpl(precompiledTargetModule2TestImpl, unitTestContext, Slang::RenderApiFlag::D3D12);
+ }
+
SLANG_UNIT_TEST(precompiledModule2Vulkan)
{
runTestImpl(precompiledModule2TestImpl, unitTestContext, Slang::RenderApiFlag::Vulkan);