summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--slang.h3
-rw-r--r--source/slang/slang-compiler.h3
-rw-r--r--source/slang/slang-emit-c-like.cpp27
-rw-r--r--source/slang/slang-options.cpp4
4 files changed, 30 insertions, 7 deletions
diff --git a/slang.h b/slang.h
index e31689200..00957227a 100644
--- a/slang.h
+++ b/slang.h
@@ -560,6 +560,9 @@ extern "C"
/* Skip code generation step, just check the code and generate layout */
SLANG_COMPILE_FLAG_NO_CODEGEN = 1 << 4,
+ /* Obfuscate shader names on release products */
+ SLANG_COMPILE_FLAG_OBFUSCATE = 1 << 5,
+
/* Deprecated flags: kept around to allow existing applications to
compile. Note that the relevant features will still be left in
their default state. */
diff --git a/source/slang/slang-compiler.h b/source/slang/slang-compiler.h
index ad90bb5ee..ebde8b6d3 100644
--- a/source/slang/slang-compiler.h
+++ b/source/slang/slang-compiler.h
@@ -1636,6 +1636,9 @@ namespace Slang
//
bool useUnknownImageFormatAsDefault = false;
+ // Remove name hints to help obfuscate code
+ //
+ bool obfuscateCode = false;
private:
RefPtr<ComponentType> m_program;
};
diff --git a/source/slang/slang-emit-c-like.cpp b/source/slang/slang-emit-c-like.cpp
index 6b828085e..991540782 100644
--- a/source/slang/slang-emit-c-like.cpp
+++ b/source/slang/slang-emit-c-like.cpp
@@ -637,7 +637,7 @@ String CLikeSourceEmitter::generateName(IRInst* inst)
//
if(auto nameHintDecoration = inst->findDecoration<IRNameHintDecoration>())
{
- // The name we output will basically be:
+ // The (non-obfuscated) name we output will basically be:
//
// <nameHint>_<uniqueID>
//
@@ -645,15 +645,28 @@ String CLikeSourceEmitter::generateName(IRInst* inst)
// and we will omit the underscore if the (scrubbed)
// name hint already ends with one.
//
-
- String nameHint = nameHintDecoration->getName();
- nameHint = scrubName(nameHint);
+ // The obfuscated name we output will simply be:
+ //
+ // _<uniqueID>
+ //
StringBuilder sb;
- sb.append(nameHint);
- // Avoid introducing a double underscore
- if(!nameHint.endsWith("_"))
+ if (!m_compileRequest->obfuscateCode)
+ {
+
+ String nameHint = nameHintDecoration->getName();
+ nameHint = scrubName(nameHint);
+
+ sb.append(nameHint);
+
+ // Avoid introducing a double underscore
+ if (!nameHint.endsWith("_"))
+ {
+ sb.append("_");
+ }
+ }
+ else
{
sb.append("_");
}
diff --git a/source/slang/slang-options.cpp b/source/slang/slang-options.cpp
index 94f82ef31..31a5c7c7f 100644
--- a/source/slang/slang-options.cpp
+++ b/source/slang/slang-options.cpp
@@ -775,6 +775,10 @@ struct OptionsParser
{
requestImpl->getBackEndReq()->useUnknownImageFormatAsDefault = true;
}
+ else if (argStr == "-obfuscate")
+ {
+ requestImpl->getBackEndReq()->obfuscateCode = true;
+ }
else if (argStr == "-file-system")
{
String name;