diff options
| author | cheneym2 <acheney@nvidia.com> | 2024-08-30 02:23:26 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-29 23:23:26 -0700 |
| commit | ddf4a323be5ae4e59dce742f618dbbdee4ed28d8 (patch) | |
| tree | fc391cb7dc902536280d5fa044292131614db163 /tests | |
| parent | 87d3d4f73a2b3af3ec00f221350864602d12321d (diff) | |
Support mixture of precompiled and non-precompiled modules (#4860)
* Support mixture of precompiled and non-precompiled modules
This changes the implementation of precompile DXIL modules to
accept combinations of modules with precompiled DXIL, ones without,
and ones with a mixture of precompiled DXIL and Slang IR.
During precompilation, module IR is analyzed to find public functions
which appear to be capable of being compiled as HLSL, and those
functions are given a HLSLExport decoration, ensuring they are emitted
as HLSL and preserved in the precompiled DXIL blob. The IR for those
functions is then tagged with a new decoration AvailableInDXIL, which
marks that their implementation is present in the embedded DXIL blob.
The DXIL blob is attached to the IR as before, inside a EmbeddedDXIL
BlobLit instruction.
The logic that determines whether or not functions should be
precompiled to DXIL is a placeholder at this point, returning true
always. A subsequent change will add selection criteria.
During module linking, the full module IR is available, as well
as the optional EmbeddedDXIL blob. The IR for functions implemented
by the blob are tagged with AvailableInDXIL in the module IR.
After linking the IR for all modules to program level IR, the IR for
the functions marked AvailableInDXIL are deleted from the linked IR,
prior to emitting HLSL and compiling linking the result.
This change also changes the point of time when the module IR is
checked for EmbeddedDXIL blobs. Instead of happening at load time
as before, it happens during immediately before final linking, meaning
that the blob does not need to be independently stored with the module
separate from the IR as was done previously.
Work on #4792
* Clean up debug prints
* Call isSimpleHLSLDataType stub
* Address feedback on precompiled dxil support
Allow for IR filtering both before and after linking.
Only mark AvailableInDXIL those functions which pass
both filtering stages. Functions are corrlated using
mangled function names.
Rather than delete functions entirely when linking with
libraries that include precompiled DXIL, instead convert
the IR function definitions to declarations by gutting
them, removing child blocks.
* Use artifact metadata and name list instead of linkedir hack
* Use String instead of UnownedStringSlice
* Update tests
* Renaming
* Minor edits
* Don't fully remove functions post-link
* Unexport before collecting metadata
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/library/export-library-generics.slang | 39 | ||||
| -rw-r--r-- | tests/library/module-library-matrix.slang | 8 | ||||
| -rw-r--r-- | tests/library/precompiled-dxil-generics.slang | 28 | ||||
| -rw-r--r-- | tests/library/precompiled-dxil-matrix.slang | 26 | ||||
| -rw-r--r-- | tests/library/precompiled-dxil.slang | 3 | ||||
| -rw-r--r-- | tests/library/precompiled-module-library-resource.slang | 33 |
6 files changed, 135 insertions, 2 deletions
diff --git a/tests/library/export-library-generics.slang b/tests/library/export-library-generics.slang new file mode 100644 index 000000000..f88541da3 --- /dev/null +++ b/tests/library/export-library-generics.slang @@ -0,0 +1,39 @@ +//TEST_IGNORE_FILE: + +// export-library-generics.slang + +module "export-library-generics"; + +public cbuffer Constants { + public float x; + public float y; +} + +interface MyInterface +{ + int myMethod(int a); +} + +struct MyType : MyInterface +{ + int myMethod(int a) + { + return a * 3; + } +} + +int genericFunc<T: MyInterface>(T arg) +{ + return arg.myMethod(3); +} + +public int normalFuncUsesGeneric(int a) +{ + MyType obj; + return genericFunc(obj); +} + +public int normalFunc(int a) +{ + return a - 2; +} diff --git a/tests/library/module-library-matrix.slang b/tests/library/module-library-matrix.slang new file mode 100644 index 000000000..85e4685cc --- /dev/null +++ b/tests/library/module-library-matrix.slang @@ -0,0 +1,8 @@ +//TEST_IGNORE_FILE: + +module "module-library-matrix"; + +public float4x4 to4x4(float3x4 source) +{ + return float4x4(source[0], source[1], source[2], float4(0.0f, 0.0f, 0.0f, 1.0f)); +} diff --git a/tests/library/precompiled-dxil-generics.slang b/tests/library/precompiled-dxil-generics.slang new file mode 100644 index 000000000..f01291a8e --- /dev/null +++ b/tests/library/precompiled-dxil-generics.slang @@ -0,0 +1,28 @@ +// 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 +// 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/precompiled-dxil-generics.slang -target dxil -stage anyhit -entry anyhit -o tests/library/linked.dxil + +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); +} diff --git a/tests/library/precompiled-dxil-matrix.slang b/tests/library/precompiled-dxil-matrix.slang new file mode 100644 index 000000000..271a7e214 --- /dev/null +++ b/tests/library/precompiled-dxil-matrix.slang @@ -0,0 +1,26 @@ +// precompiled-dxil-matrix.slang + +// 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/precompiled-dxil-matrix.slang -stage anyhit -entry shadow -target dxil -o precompiled-dxil-matrix.dxil + +import "module-library-matrix"; + +struct ShadowHitInfo +{ + bool isHit; + uint seed; +}; + +struct Attributes +{ + float2 bary; +}; + +[shader("anyhit")] +void shadow(inout ShadowHitInfo payload, Attributes attrib) +{ + IgnoreHit(); +} diff --git a/tests/library/precompiled-dxil.slang b/tests/library/precompiled-dxil.slang index 19f67b075..8cc25bab5 100644 --- a/tests/library/precompiled-dxil.slang +++ b/tests/library/precompiled-dxil.slang @@ -8,8 +8,7 @@ // 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/precompiled-dxil.slang -o tests/library/precompiled-dxil.slang-module -embed-dxil -profile lib_6_6 -incomplete-library -//TEST(windows):COMPILE: tests/library/export-library.slang-module tests/library/precompiled-dxil.slang-module -target dxil -entry computeMain -profile cs_6_6 -o tests/library/linked.dxil +//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 new file mode 100644 index 000000000..79c3daaa1 --- /dev/null +++ b/tests/library/precompiled-module-library-resource.slang @@ -0,0 +1,33 @@ +// 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. + +//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 + +module "precompiled-module-library-resource"; + +public struct ResourceStruct { + public StructuredBuffer<int> buffer; +}; + +public int resource_in_parameter(StructuredBuffer<int> buffer) +{ + return buffer[0]; +} + +public int resource_in_struct_parameter(ResourceStruct rs) +{ + return rs.buffer[0]; +} + +internal int matrix_in_parameter_internal(int1x1 matrix) +{ + return matrix[0][0]; +} + +public int matrix_in_parameter_public(int a) +{ + int1x1 matrix = {a}; + return matrix_in_parameter_internal(matrix); +} |
