-
Notifications
You must be signed in to change notification settings - Fork 259
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
IR: Add SPIR-V disassembly for embedded downstream IR dumps #6529
Conversation
3adbbce
to
0e675ac
Compare
source/slang/CMakeLists.txt
Outdated
@@ -230,6 +230,7 @@ set(slang_link_args | |||
slang-reflect-headers | |||
slang-lookup-tables | |||
SPIRV-Headers | |||
SPIRV-Tools |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
slang-glslang already has spirv-tools support, no need to add this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
source/slang/slang-ir.cpp
Outdated
spv_diagnostic diagnostic = nullptr; | ||
|
||
// Disassemble with friendly names and comments | ||
spv_result_t result = spvBinaryToText( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use existing slang-glslang interface to spvtools, see https://github.com/shader-slang/slang/blob/master/source/slang/slang-emit.cpp#L2097
I think you can request the downstream compiler for "PassThroughMode::SpirvDis" instead, though it will return the same thing either way since the same downstream compiler supports Opt, Dis, Link, etc..
IDownstreamCompiler* compiler = codeGenContext->getSession()->getOrLoadDownstreamCompiler(
PassThroughMode::SpirvOpt,
codeGenContext->getSink());
if (compiler)
{
#if 0
// Dump the unoptimized/unlinked SPIRV after lowering from slang IR -> SPIRV
compiler->disassemble((uint32_t*)spirv.getBuffer(), int(spirv.getCount() / 4));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
// CHECK:let %126 : _ = interface_req_entry(%127, witness_table_t(%x5Fx5FBuiltinRealType)) | ||
// CHECK:let %128 : _ = interface_req_entry(%7, witness_table_t(%IFloat)) | ||
// CHECK:let %129 : _ = interface_req_entry(%130, Func(this_type(%x5Fx5FBuiltinFloatingPointType))) | ||
// CHECK:[availableInDownstreamIR(6 : Int)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
7af2c0d
to
37df7af
Compare
87bb5b7
to
d0ae2fb
Compare
/format |
🌈 Formatted, please merge the changes from this PR |
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
d0ae2fb
to
d49f90d
Compare
/format |
🌈 Formatted, please merge the changes from this PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, just a couple suggestions
source/slang/slang-ir.cpp
Outdated
// Special case EmbeddedDownstreamIR to show SPIR-V disassembly | ||
if (op == kIROp_EmbeddedDownstreamIR) | ||
{ | ||
auto targetInst = inst->getOperand(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you put this logic in a helper function like dumpEmbeddedDownstream()?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
source/slang/slang-ir.cpp
Outdated
} | ||
else | ||
{ | ||
dump(context, "<invalid SPIR-V>"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems misleading, we failed to get a disassembler, no fault of the SPIR-V itself. Maybe "unavailable disassembler" would be more appropriate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
source/slang/slang-ir.cpp
Outdated
} | ||
} | ||
else | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a TODO comment for DXIL disassembly here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
Fixes shader-slang#6517 Adds a new test to verify that dxil and spirv targets are stored separately in the precompiled blob.
41ddf96
to
7c1f412
Compare
7c1f412
to
df91292
Compare
df91292
to
19d24b5
Compare
/format |
🌈 Formatted, please merge the changes from this PR |
When dumping IR that contains embedded downstream SPIR-V code (via EmbeddedDownstreamIR instructions), display the disassembled SPIR-V instead of just showing "". This makes the IR dumps more readable and useful for debugging SPIR-V code generation.
This CL also does: