Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

-dump-ir should print disassembly of downstream target SPIR-V IR for embedded blobs. #6513

Closed
cheneym2 opened this issue Mar 3, 2025 · 2 comments
Assignees
Labels
goal:forward looking Feature needed at a later date, not connected to a specific use case. goal:quality & productivity Quality issues and issues that impact our productivity coding day to day inside slang

Comments

@cheneym2
Copy link
Collaborator

cheneym2 commented Mar 3, 2025

-dump-ir should print disassembly of downstream target IR for embedded blobs

This request is for SPIR-V in particular.

At least one slang-test should demonstrate the capability by using "filecheck" for SPIR-V in a precompiled module, looking at the "-dump-ir" output and looking for one or two key ops, e.g. "OpCapability Linkage" and "OpDecorate... LinkageAttributes ... Export" would be good ones to check for.

@cheneym2 cheneym2 added this to the Q1 2025 (Winter) milestone Mar 3, 2025
@cheneym2 cheneym2 added goal:quality & productivity Quality issues and issues that impact our productivity coding day to day inside slang goal:forward looking Feature needed at a later date, not connected to a specific use case. labels Mar 4, 2025
@cheneym2
Copy link
Collaborator Author

cheneym2 commented Mar 5, 2025

I don't know offhand the correct place to add -dump-ir support which would show embedded downstream IR and decorations, but this hack shows you what the current IR dumping logic does with the decorations:

diff --git a/source/slang/slang-compiler-tu.cpp b/source/slang/slang-compiler-tu.cpp
index 8bfe9a9a..362f786e 100644
--- a/source/slang/slang-compiler-tu.cpp
+++ b/source/slang/slang-compiler-tu.cpp
@@ -212,6 +212,9 @@ Module::precompileForTarget(SlangCompileTarget target, slang::IBlob** outDiagnos
     builder.setInsertInto(module);
     builder.emitEmbeddedDownstreamIR(targetReq->getTarget(), blob);
+
    module->getModuleInst()->dump();
+
     return SLANG_OK;
 }

$ build/Release/bin/slangc tests/library/export-library-generics.slang -o my.slang-module -target spirv -embed-downstream-ir

...
[availableInDownstreamIR(6 : Int)]
[public]
[export("_SR29export_2Dxlibrary_2Dxgenerics21normalFuncUsesGenericp1pi_ii")]
[nameHint("normalFuncUsesGeneric")]
func %normalFuncUsesGeneric	: Func(Int, Int)
{
...
EmbeddedDownstreamIR(6 : Int, <binary blob>)

@cheneym2
Copy link
Collaborator Author

cheneym2 commented Mar 5, 2025

The expectation is that the logic that prints out the "EmbeddedDownstreamIR" instruction is updated. Right now, it just shows an ID operand indicating SPIRV (6), followed by the word "binary blob" that represents the OpBlobLit operand. But ideally the blob would show up as disassembled SPIR-V if the target operand is SLANG_SPIRV (6).

I don't think it's a trivial task, hence the 3 day estimate.

It's an additional task to make it so that -dump-ir shows this post-precompileForTarget output, since "LOWER-TO-IR" is too early. I didn't initially think of that complication when writing the github issue. Maybe the estimate should be 4 days.

Filecheck should naturally be able to check for embedded SPIRV operations then.

mkeshavaNV added a commit to mkeshavaNV/slang that referenced this issue Mar 11, 2025
mkeshavaNV added a commit to mkeshavaNV/slang that referenced this issue Mar 11, 2025
mkeshavaNV added a commit to mkeshavaNV/slang that referenced this issue Mar 11, 2025
When dumping IR that contains embedded downstream SPIR-V code (via
EmbeddedDownstreamIR instructions), display the disassembled SPIR-V
instead of just showing "<binary blob>".

This CL also does:
- Adds a new interface for disassembly and get result.
- Modify export-library-generics.slang test test to check for the
  disassembled SPIR-V

Fixes shader-slang#6513
mkeshavaNV added a commit to mkeshavaNV/slang that referenced this issue Mar 11, 2025
When dumping IR that contains embedded downstream SPIR-V code (via
EmbeddedDownstreamIR instructions), display the disassembled SPIR-V
instead of just showing "<binary blob>".

This CL also does:
- Adds a new interface for disassembly and get result.
- Modify export-library-generics.slang test test to check for the
  disassembled SPIR-V

Fixes shader-slang#6513
mkeshavaNV added a commit to mkeshavaNV/slang that referenced this issue Mar 11, 2025
mkeshavaNV added a commit to mkeshavaNV/slang that referenced this issue Mar 11, 2025
mkeshavaNV added a commit to mkeshavaNV/slang that referenced this issue Mar 11, 2025
cheneym2 added a commit to mkeshavaNV/slang that referenced this issue Mar 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
goal:forward looking Feature needed at a later date, not connected to a specific use case. goal:quality & productivity Quality issues and issues that impact our productivity coding day to day inside slang
Projects
None yet
Development

No branches or pull requests

2 participants