From 313677160a186efebf83fab4df7d08dd119a5cd2 Mon Sep 17 00:00:00 2001 From: cheneym2 Date: Thu, 5 Sep 2024 14:59:28 -0400 Subject: Initial -embed-spirv support (#4974) * Initial -embed-spirv support Add support for SPIR-V precompilation using the framework established for DXIL. Work on #4883 * SLANG_UNUSED * Add linkage attributes to exported spirv functions * Combine DXIL and SPIRV paths * Whitespace fix * Merge remaining precompiled spirv/dxil paths * Change inst accessors to return codegentarget * Add unit test for precompiled spirv --------- Co-authored-by: Yong He --- tests/library/precompiled-dxil-generics.slang | 4 ++-- tests/library/precompiled-dxil-matrix.slang | 2 +- tests/library/precompiled-dxil.slang | 6 ++--- .../precompiled-module-library-resource.slang | 14 ++++++----- tests/library/precompiled-spirv-generics.slang | 28 ++++++++++++++++++++++ 5 files changed, 42 insertions(+), 12 deletions(-) create mode 100644 tests/library/precompiled-spirv-generics.slang (limited to 'tests') diff --git a/tests/library/precompiled-dxil-generics.slang b/tests/library/precompiled-dxil-generics.slang index f01291a8e..a0b371519 100644 --- a/tests/library/precompiled-dxil-generics.slang +++ b/tests/library/precompiled-dxil-generics.slang @@ -1,12 +1,12 @@ // precompiled-dxil-generics.slang // A test that uses slang-modules with embedded precompiled DXIL and a library containing generics. -// The test compiles a library slang (export-library-generics.slang) with -embed-dxil then links the +// The test compiles a library slang (export-library-generics.slang) with -embed-downstream-ir then links the // library to entrypoint slang (this file). // The test passes if there is no errror thrown. // TODO: Check if final linkage used only the precompiled dxil. -//TEST(windows):COMPILE: tests/library/export-library-generics.slang -o tests/library/export-library-generics.slang-module -embed-dxil -profile lib_6_6 -incomplete-library +//TEST(windows):COMPILE: tests/library/export-library-generics.slang -o tests/library/export-library-generics.slang-module -target dxil -embed-downstream-ir -profile lib_6_6 -incomplete-library //TEST(windows):COMPILE: tests/library/precompiled-dxil-generics.slang -target dxil -stage anyhit -entry anyhit -o tests/library/linked.dxil import "export-library-generics"; diff --git a/tests/library/precompiled-dxil-matrix.slang b/tests/library/precompiled-dxil-matrix.slang index 271a7e214..469eea7c6 100644 --- a/tests/library/precompiled-dxil-matrix.slang +++ b/tests/library/precompiled-dxil-matrix.slang @@ -3,7 +3,7 @@ // This test imports a precompiled module that exports a matrix type, which is known to // cause https://github.com/shader-slang/slang/issues/4880 without driver mitigation. -//TEST(windows):COMPILE: tests/library/module-library-matrix.slang -o tests/library/module-library-matrix.slang-module -embed-dxil -profile lib_6_6 -incomplete-library +//TEST(windows):COMPILE: tests/library/module-library-matrix.slang -o tests/library/module-library-matrix.slang-module -target dxil -embed-downstream-ir -profile lib_6_6 -incomplete-library //TEST(windows):COMPILE: tests/library/precompiled-dxil-matrix.slang -stage anyhit -entry shadow -target dxil -o precompiled-dxil-matrix.dxil import "module-library-matrix"; diff --git a/tests/library/precompiled-dxil.slang b/tests/library/precompiled-dxil.slang index 8cc25bab5..877472394 100644 --- a/tests/library/precompiled-dxil.slang +++ b/tests/library/precompiled-dxil.slang @@ -1,13 +1,13 @@ // precompiled-dxil.slang // A test that uses slang-modules with embedded precompiled DXIL. -// The test compiles both library slang (export-library.slang) and entrypoint slang (this file) to two slang-modules, each with -embed-dxil options. -// The result is two slang-modules that are then linked together in a third slangc invocation. +// The test compiles both library slang (export-library.slang) to a slang-module using -embed-downstream-ir. +// The result is linked together with this module (precompiled-dxil.slang) in a second slangc invocation. // Internally, slang does not use the IR in the modules to link, but rather their embedded DXIL. // The test passes if there is no errror thrown. // TODO: Check if final linkage used only the precompiled dxil. -//TEST(windows):COMPILE: tests/library/export-library.slang -o tests/library/export-library.slang-module -embed-dxil -profile lib_6_6 -incomplete-library +//TEST(windows):COMPILE: tests/library/export-library.slang -o tests/library/export-library.slang-module -target dxil -embed-downstream-ir -profile lib_6_6 -incomplete-library //TEST(windows):COMPILE: tests/library/precompiled-dxil.slang tests/library/export-library.slang-module -target dxil -entry computeMain -profile cs_6_6 -o tests/library/linked.dxil extern int foo(int a); diff --git a/tests/library/precompiled-module-library-resource.slang b/tests/library/precompiled-module-library-resource.slang index 3eeab39d8..35b83b72f 100644 --- a/tests/library/precompiled-module-library-resource.slang +++ b/tests/library/precompiled-module-library-resource.slang @@ -1,9 +1,11 @@ // precompiled-module-library-resource.slang -// Compile this library source with -embed-dxil option. Tests that modules can be -// precompiled to dxil despite having resource parameters or return types. +// Compile this library source with embedded DXIL and SPIRV options. +// Tests that modules can be precompiled to downstream IR despite having resource +// parameters or return types. -//TEST(windows):COMPILE: tests/library/precompiled-module-library-resource.slang -o tests/library/precompiled-module-library-resource.slang-module -embed-dxil -profile lib_6_6 -incomplete-library +//TEST(windows):COMPILE: tests/library/precompiled-module-library-resource.slang -o tests/library/precompiled-module-library-resource-dxil.slang-module -target dxil -embed-downstream-ir -profile lib_6_6 -incomplete-library +//TEST:COMPILE: tests/library/precompiled-module-library-resource.slang -o tests/library/precompiled-module-library-resource-spv.slang-module -target spirv -embed-downstream-ir -incomplete-library module "precompiled-module-library-resource"; @@ -26,13 +28,13 @@ public int resource_in_struct_parameter(ResourceStruct rs) return rs.buffer[0]; } -internal int matrix_in_parameter_internal(int1x1 matrix) +internal float matrix_in_parameter_internal(float2x2 matrix) { return matrix[0][0]; } -public int matrix_in_parameter_public(int a) +public float matrix_in_parameter_public(float a) { - int1x1 matrix = {a}; + float2x2 matrix = {a, .2, .3, .4}; return matrix_in_parameter_internal(matrix); } diff --git a/tests/library/precompiled-spirv-generics.slang b/tests/library/precompiled-spirv-generics.slang new file mode 100644 index 000000000..a55f58513 --- /dev/null +++ b/tests/library/precompiled-spirv-generics.slang @@ -0,0 +1,28 @@ +// precompiled-spirv-generics.slang + +// A test that uses slang-modules with embedded precompiled SPIRV and a library containing generics. +// The test compiles a library slang (export-library-generics.slang) with -embed-downstream-ir then links the +// library to entrypoint slang (this file). +// The test passes if there is no errror thrown. +// TODO: Check if final linkage used only the precompiled spirv. + +//TEST:COMPILE: tests/library/export-library-generics.slang -o tests/library/export-library-generics.slang-module -target spirv -embed-downstream-ir -profile lib_6_6 -incomplete-library +//TEST:COMPILE: tests/library/precompiled-spirv-generics.slang -target spirv -stage anyhit -entry anyhit -o tests/library/linked.spirv + +import "export-library-generics"; + +struct Payload +{ + int val; +} + +struct Attributes +{ + float2 bary; +} + +[shader("anyhit")] +void anyhit(inout Payload payload, Attributes attrib) +{ + payload.val = normalFunc(x * y) + normalFuncUsesGeneric(y); +} -- cgit v1.2.3