-
Notifications
You must be signed in to change notification settings - Fork 810
Strip struct, entry and groupshared names from DXIL #7868
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
d396c42
d0baee2
6caaa41
3e87657
4fe6315
449e0aa
a8a7120
8089204
2b30dc0
0eb9285
6fb53fb
c57e18c
34c30da
33e384a
e300412
98720f7
5770aa0
76a0d61
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -118,8 +118,11 @@ class DxilContainerTest : public ::testing::Test { | |
| TEST_METHOD(DxilContainerUnitTest) | ||
| TEST_METHOD(DxilContainerCompilerVersionTest) | ||
| TEST_METHOD(ContainerBuilder_AddPrivateForceLast) | ||
|
|
||
| TEST_METHOD(ReflectionMatchesDXBC_CheckIn) | ||
| TEST_METHOD(StripReflectionRemovesStructNames) | ||
| TEST_METHOD(StripReflectionRemovesEntryFunctionName) | ||
| TEST_METHOD(StripReflectionRemovesGroupsharedNames) | ||
| TEST_METHOD(StripReflectionLibraryDoesNotStripNames) | ||
| BEGIN_TEST_METHOD(ReflectionMatchesDXBC_Full) | ||
| TEST_METHOD_PROPERTY(L"Priority", L"1") | ||
| END_TEST_METHOD() | ||
|
|
@@ -607,12 +610,14 @@ class DxilContainerTest : public ::testing::Test { | |
| } | ||
|
|
||
| std::string DisassembleProgram(LPCSTR program, LPCWSTR entryPoint, | ||
| LPCWSTR target) { | ||
| LPCWSTR target, LPCWSTR *pArguments = nullptr, | ||
| UINT32 argCount = 0) { | ||
| CComPtr<IDxcCompiler> pCompiler; | ||
| CComPtr<IDxcBlob> pProgram; | ||
| CComPtr<IDxcBlobEncoding> pDisassembly; | ||
|
|
||
| CompileToProgram(program, entryPoint, target, nullptr, 0, &pProgram); | ||
| CompileToProgram(program, entryPoint, target, pArguments, argCount, | ||
| &pProgram); | ||
| VERIFY_SUCCEEDED(CreateCompiler(&pCompiler)); | ||
| VERIFY_SUCCEEDED(pCompiler->Disassemble(pProgram, &pDisassembly)); | ||
| return BlobToUtf8(pDisassembly); | ||
|
|
@@ -3081,3 +3086,90 @@ TEST_F(DxilContainerTest, DxilContainerUnitTest) { | |
| hlsl::GetDxilProgramHeader(&header, hlsl::DxilFourCC::DFCC_DXIL)); | ||
| VERIFY_IS_NULL(hlsl::GetDxilPartByType(&header, hlsl::DxilFourCC::DFCC_DXIL)); | ||
| } | ||
|
|
||
| TEST_F(DxilContainerTest, StripReflectionRemovesStructNames) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Regarding testing, ideally we could use the LIT/Filecheck infrastructure for directly comparing the modified LLVM IR before and after the new pass. The For instance, we would have an llvm ir module and have the run line be something like: It would demonstrate the names being present before the pass and then use Similar to here. |
||
| const char *Code = R"( | ||
| struct MyCustomStruct { | ||
| float4 position; | ||
| float4 color; | ||
| }; | ||
|
|
||
| cbuffer MyCBuffer : register(b0) { | ||
| float4 data; | ||
| }; | ||
|
|
||
| float4 main() : SV_Target { | ||
| MyCustomStruct s; | ||
| s.position = float4(0, 0, 0, 1); | ||
| s.color = float4(1, 1, 1, 1); | ||
| return s.color; | ||
| } | ||
| )"; | ||
|
|
||
| LPCWSTR StripDebug = L"-Qstrip_debug"; | ||
|
|
||
| std::string disassembly = | ||
| DisassembleProgram(Code, L"main", L"ps_6_0", &StripDebug, 1); | ||
|
|
||
| VERIFY_IS_TRUE(disassembly.find("MyCustomStruct") == std::string::npos); | ||
GlassBeaver marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| TEST_F(DxilContainerTest, StripReflectionRemovesEntryFunctionName) { | ||
| const char *Code = R"( | ||
| float4 MyCustomEntryPoint() : SV_Target { | ||
| return float4(1, 0, 0, 1); | ||
| } | ||
| )"; | ||
|
|
||
| LPCWSTR StripDebug = L"-Qstrip_debug"; | ||
|
|
||
| std::string disassembly = DisassembleProgram(Code, L"MyCustomEntryPoint", | ||
| L"ps_6_0", &StripDebug, 1); | ||
|
|
||
| VERIFY_IS_TRUE(disassembly.find("MyCustomEntryPoint") == std::string::npos); | ||
| VERIFY_IS_TRUE(disassembly.find("dx.strip.entry.") != std::string::npos); | ||
| } | ||
|
|
||
| TEST_F(DxilContainerTest, StripReflectionRemovesGroupsharedNames) { | ||
| const char *Code = R"( | ||
| groupshared float mySharedData[256]; | ||
| groupshared int mySharedCounter; | ||
|
|
||
| [numthreads(8, 8, 1)] | ||
| void CSMain(uint3 dispatchThreadID : SV_DispatchThreadID) { | ||
| mySharedData[dispatchThreadID.x] = 1.0f; | ||
| mySharedCounter = 42; | ||
| } | ||
| )"; | ||
|
|
||
| LPCWSTR StripDebug = L"-Qstrip_debug"; | ||
|
|
||
| std::string disassembly = | ||
| DisassembleProgram(Code, L"CSMain", L"cs_6_0", &StripDebug, 1); | ||
|
|
||
| VERIFY_IS_TRUE(disassembly.find("mySharedData") == std::string::npos); | ||
| VERIFY_IS_TRUE(disassembly.find("mySharedCounter") == std::string::npos); | ||
| VERIFY_IS_TRUE(disassembly.find("dx.strip.tgsm.") != std::string::npos); | ||
| } | ||
|
|
||
| TEST_F(DxilContainerTest, StripReflectionLibraryDoesNotStripNames) { | ||
| const char *Code = R"( | ||
| struct MyLibStruct { | ||
| float val; | ||
| }; | ||
|
|
||
| [shader("raygeneration")] | ||
| void MyRayGenEntry() { | ||
| MyLibStruct s; | ||
| s.val = 1.0f; | ||
| } | ||
| )"; | ||
|
|
||
| LPCWSTR StripDebug = L"-Qstrip_debug"; | ||
|
|
||
| std::string disassembly = | ||
| DisassembleProgram(Code, L"", L"lib_6_3", &StripDebug, 1); | ||
|
|
||
| VERIFY_IS_TRUE(disassembly.find("MyLibStruct") != std::string::npos || | ||
| disassembly.find("dx.strip.struct.") == std::string::npos); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.