File tree 4 files changed +30
-7
lines changed
4 files changed +30
-7
lines changed Original file line number Diff line number Diff line change @@ -560,6 +560,9 @@ extern "C"
560
560
/* Skip code generation step, just check the code and generate layout */
561
561
SLANG_COMPILE_FLAG_NO_CODEGEN = 1 << 4 ,
562
562
563
+ /* Obfuscate shader names on release products */
564
+ SLANG_COMPILE_FLAG_OBFUSCATE = 1 << 5 ,
565
+
563
566
/* Deprecated flags: kept around to allow existing applications to
564
567
compile. Note that the relevant features will still be left in
565
568
their default state. */
Original file line number Diff line number Diff line change @@ -1636,6 +1636,9 @@ namespace Slang
1636
1636
//
1637
1637
bool useUnknownImageFormatAsDefault = false ;
1638
1638
1639
+ // Remove name hints to help obfuscate code
1640
+ //
1641
+ bool obfuscateCode = false ;
1639
1642
private:
1640
1643
RefPtr<ComponentType> m_program;
1641
1644
};
Original file line number Diff line number Diff line change @@ -637,23 +637,36 @@ String CLikeSourceEmitter::generateName(IRInst* inst)
637
637
//
638
638
if (auto nameHintDecoration = inst->findDecoration <IRNameHintDecoration>())
639
639
{
640
- // The name we output will basically be:
640
+ // The (non-obfuscated) name we output will basically be:
641
641
//
642
642
// <nameHint>_<uniqueID>
643
643
//
644
644
// Except that we will "scrub" the name hint first,
645
645
// and we will omit the underscore if the (scrubbed)
646
646
// name hint already ends with one.
647
647
//
648
-
649
- String nameHint = nameHintDecoration->getName ();
650
- nameHint = scrubName (nameHint);
648
+ // The obfuscated name we output will simply be:
649
+ //
650
+ // _<uniqueID>
651
+ //
651
652
652
653
StringBuilder sb;
653
- sb.append (nameHint);
654
654
655
- // Avoid introducing a double underscore
656
- if (!nameHint.endsWith (" _" ))
655
+ if (!m_compileRequest->obfuscateCode )
656
+ {
657
+
658
+ String nameHint = nameHintDecoration->getName ();
659
+ nameHint = scrubName (nameHint);
660
+
661
+ sb.append (nameHint);
662
+
663
+ // Avoid introducing a double underscore
664
+ if (!nameHint.endsWith (" _" ))
665
+ {
666
+ sb.append (" _" );
667
+ }
668
+ }
669
+ else
657
670
{
658
671
sb.append (" _" );
659
672
}
Original file line number Diff line number Diff line change @@ -775,6 +775,10 @@ struct OptionsParser
775
775
{
776
776
requestImpl->getBackEndReq ()->useUnknownImageFormatAsDefault = true ;
777
777
}
778
+ else if (argStr == " -obfuscate" )
779
+ {
780
+ requestImpl->getBackEndReq ()->obfuscateCode = true ;
781
+ }
778
782
else if (argStr == " -file-system" )
779
783
{
780
784
String name;
You can’t perform that action at this time.
0 commit comments