slang
slang copied to clipboard
[SPIR-V] Support emit linkage module
Spir-V supports compiling shaders into libraries that users can link later. This patch supports emitting spir-v modules directly without using slang modules.
slangc -capability SPIRV_1_6 -target spirv -incomplete-library -o lib.spv lib.slang
Note that, Spir-V code emitted by embed-downstream-ir is incorrect if using export, due to emit linkage decoration twice for one function.
Sorry, it looks a spirv-opt issue.
slangc -target spirv -emit-spirv-directly tests/compute/dynamic-dispatch-14.slang -O0 -o test.spv
spirv-val --target-env spv1.6 test.spv
spirv-opt --legalize-hlsl test.spv -o test2.spv # Crash
spirv-opt crashes.
spirv-opt: /home/ginshio/Projects/khronos3d/spirv-tools/source/opt/instruction.cpp:179: uint32_t spvtools::opt::Instruction::GetSingleWordOperand(uint32_t) const: Assertion `words.size() == 1 && "expected the operand only taking one word"' failed.
fish: Job 1, '$HOME/Projects/khronos3d/spirv-…' terminated by signal SIGABRT (Abort)
Crash on:
(lldb) p inst.Dump()
OpDecorate %77 LinkageAttributes "_ST6MyImpl" Export
Seems to spirv-opt doesn't handle linkage decoration. Fix in https://github.com/KhronosGroup/SPIRV-Tools/pull/6191.
Thanks. Makes sense to me. Well, map extern to [SPIRVExtern] and export to [SPIRVExport].
I think I need to take more times to consider how to implement it and don't conflict with Downstream decoration.
@csyonghe Can you take a look at the latest iteration of this patch?
@GinShio - Can you please resolve the conflicts so that the CI can run.
Approved CIs to run.
⚠️ IR Instruction Files Changed
This PR modifies IR instruction definition files. Please review if you need to update the following constants in source/slang/slang-ir.h:
k_minSupportedModuleVersion: Should be incremented if you're removing instructions or making breaking changesk_maxSupportedModuleVersion: Should be incremented when adding new instructions
These version numbers help ensure compatibility between different versions of compiled modules.
@GinShio - It seems need conflict resolution before continuing further. Could you help to update the slang-ir-insts-stable-names.lua ? Thanks.
@GinShio Just checking in. Have you had a chance to review @tangent-vector's feedback? Do you have any questions/concerns?