@@ -118,8 +118,11 @@ class DxilContainerTest : public ::testing::Test {
118118 TEST_METHOD (DxilContainerUnitTest)
119119 TEST_METHOD (DxilContainerCompilerVersionTest)
120120 TEST_METHOD (ContainerBuilder_AddPrivateForceLast)
121-
122121 TEST_METHOD (ReflectionMatchesDXBC_CheckIn)
122+ TEST_METHOD (StripReflectionRemovesStructNames)
123+ TEST_METHOD (StripReflectionRemovesEntryFunctionName)
124+ TEST_METHOD (StripReflectionRemovesGroupsharedNames)
125+ TEST_METHOD (StripReflectionLibraryDoesNotStripNames)
123126 BEGIN_TEST_METHOD (ReflectionMatchesDXBC_Full)
124127 TEST_METHOD_PROPERTY (L" Priority" , L" 1" )
125128 END_TEST_METHOD ()
@@ -607,12 +610,14 @@ class DxilContainerTest : public ::testing::Test {
607610 }
608611
609612 std::string DisassembleProgram (LPCSTR program, LPCWSTR entryPoint,
610- LPCWSTR target) {
613+ LPCWSTR target, LPCWSTR *pArguments = nullptr ,
614+ UINT32 argCount = 0 ) {
611615 CComPtr<IDxcCompiler> pCompiler;
612616 CComPtr<IDxcBlob> pProgram;
613617 CComPtr<IDxcBlobEncoding> pDisassembly;
614618
615- CompileToProgram (program, entryPoint, target, nullptr , 0 , &pProgram);
619+ CompileToProgram (program, entryPoint, target, pArguments, argCount,
620+ &pProgram);
616621 VERIFY_SUCCEEDED (CreateCompiler (&pCompiler));
617622 VERIFY_SUCCEEDED (pCompiler->Disassemble (pProgram, &pDisassembly));
618623 return BlobToUtf8 (pDisassembly);
@@ -3081,3 +3086,90 @@ TEST_F(DxilContainerTest, DxilContainerUnitTest) {
30813086 hlsl::GetDxilProgramHeader (&header, hlsl::DxilFourCC::DFCC_DXIL));
30823087 VERIFY_IS_NULL (hlsl::GetDxilPartByType (&header, hlsl::DxilFourCC::DFCC_DXIL));
30833088}
3089+
3090+ TEST_F (DxilContainerTest, StripReflectionRemovesStructNames) {
3091+ const char *Code = R"(
3092+ struct MyCustomStruct {
3093+ float4 position;
3094+ float4 color;
3095+ };
3096+
3097+ cbuffer MyCBuffer : register(b0) {
3098+ float4 data;
3099+ };
3100+
3101+ float4 main() : SV_Target {
3102+ MyCustomStruct s;
3103+ s.position = float4(0, 0, 0, 1);
3104+ s.color = float4(1, 1, 1, 1);
3105+ return s.color;
3106+ }
3107+ )" ;
3108+
3109+ LPCWSTR StripDebug = L" -Qstrip_debug" ;
3110+
3111+ std::string disassembly =
3112+ DisassembleProgram (Code, L" main" , L" ps_6_0" , &StripDebug, 1 );
3113+
3114+ VERIFY_IS_TRUE (disassembly.find (" MyCustomStruct" ) == std::string::npos);
3115+ }
3116+
3117+ TEST_F (DxilContainerTest, StripReflectionRemovesEntryFunctionName) {
3118+ const char *Code = R"(
3119+ float4 MyCustomEntryPoint() : SV_Target {
3120+ return float4(1, 0, 0, 1);
3121+ }
3122+ )" ;
3123+
3124+ LPCWSTR StripDebug = L" -Qstrip_debug" ;
3125+
3126+ std::string disassembly = DisassembleProgram (Code, L" MyCustomEntryPoint" ,
3127+ L" ps_6_0" , &StripDebug, 1 );
3128+
3129+ VERIFY_IS_TRUE (disassembly.find (" MyCustomEntryPoint" ) == std::string::npos);
3130+ VERIFY_IS_TRUE (disassembly.find (" dx.strip.entry." ) != std::string::npos);
3131+ }
3132+
3133+ TEST_F (DxilContainerTest, StripReflectionRemovesGroupsharedNames) {
3134+ const char *Code = R"(
3135+ groupshared float mySharedData[256];
3136+ groupshared int mySharedCounter;
3137+
3138+ [numthreads(8, 8, 1)]
3139+ void CSMain(uint3 dispatchThreadID : SV_DispatchThreadID) {
3140+ mySharedData[dispatchThreadID.x] = 1.0f;
3141+ mySharedCounter = 42;
3142+ }
3143+ )" ;
3144+
3145+ LPCWSTR StripDebug = L" -Qstrip_debug" ;
3146+
3147+ std::string disassembly =
3148+ DisassembleProgram (Code, L" CSMain" , L" cs_6_0" , &StripDebug, 1 );
3149+
3150+ VERIFY_IS_TRUE (disassembly.find (" mySharedData" ) == std::string::npos);
3151+ VERIFY_IS_TRUE (disassembly.find (" mySharedCounter" ) == std::string::npos);
3152+ VERIFY_IS_TRUE (disassembly.find (" dx.strip.tgsm." ) != std::string::npos);
3153+ }
3154+
3155+ TEST_F (DxilContainerTest, StripReflectionLibraryDoesNotStripNames) {
3156+ const char *Code = R"(
3157+ struct MyLibStruct {
3158+ float val;
3159+ };
3160+
3161+ [shader("raygeneration")]
3162+ void MyRayGenEntry() {
3163+ MyLibStruct s;
3164+ s.val = 1.0f;
3165+ }
3166+ )" ;
3167+
3168+ LPCWSTR StripDebug = L" -Qstrip_debug" ;
3169+
3170+ std::string disassembly =
3171+ DisassembleProgram (Code, L" " , L" lib_6_3" , &StripDebug, 1 );
3172+
3173+ VERIFY_IS_TRUE (disassembly.find (" MyLibStruct" ) != std::string::npos ||
3174+ disassembly.find (" dx.strip.struct." ) == std::string::npos);
3175+ }
0 commit comments