slang icon indicating copy to clipboard operation
slang copied to clipboard

[SPIR-V] Support emit linkage module

Open GinShio opened this issue 5 months ago • 2 comments

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.

GinShio avatar Jun 15 '25 12:06 GinShio

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Jun 15 '25 12:06 CLAassistant

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.

GinShio avatar Jun 21 '25 14:06 GinShio

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.

GinShio avatar Jul 05 '25 08:07 GinShio

@csyonghe Can you take a look at the latest iteration of this patch?

jhelferty-nv avatar Jul 23 '25 18:07 jhelferty-nv

@GinShio - Can you please resolve the conflicts so that the CI can run.

mkeshavaNV avatar Sep 18 '25 06:09 mkeshavaNV

Approved CIs to run.

mkeshavaNV avatar Sep 29 '25 06:09 mkeshavaNV

⚠️ 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 changes
  • k_maxSupportedModuleVersion: Should be incremented when adding new instructions

These version numbers help ensure compatibility between different versions of compiled modules.

slangbot avatar Sep 30 '25 11:09 slangbot

@GinShio - It seems need conflict resolution before continuing further. Could you help to update the slang-ir-insts-stable-names.lua ? Thanks.

szihs avatar Oct 07 '25 09:10 szihs

@GinShio Just checking in. Have you had a chance to review @tangent-vector's feedback? Do you have any questions/concerns?

jhelferty-nv avatar Nov 17 '25 19:11 jhelferty-nv