فهرست منبع

Support -line-directive in dxr. (#3027)

* Support -line-directive in dxr.
Xiang Li 5 سال پیش
والد
کامیت
4211802b9a

+ 1 - 0
include/dxc/Support/HLSLOptions.h

@@ -96,6 +96,7 @@ struct RewriterOpts {
   bool ExtractEntryUniforms = false;        // OPT_rw_extract_entry_uniforms
   bool ExtractEntryUniforms = false;        // OPT_rw_extract_entry_uniforms
   bool RemoveUnusedGlobals = false;         // OPT_rw_remove_unused_globals
   bool RemoveUnusedGlobals = false;         // OPT_rw_remove_unused_globals
   bool RemoveUnusedFunctions = false;         // OPT_rw_remove_unused_functions
   bool RemoveUnusedFunctions = false;         // OPT_rw_remove_unused_functions
+  bool WithLineDirective = false;       // OPT_rw_line_directive
 };
 };
 
 
 /// Use this class to capture all options.
 /// Use this class to capture all options.

+ 2 - 0
include/dxc/Support/HLSLOptions.td

@@ -457,5 +457,7 @@ def rw_remove_unused_globals : Flag<["-", "/"], "remove-unused-globals">, Group<
   HelpText<"Remove unused static globals and functions">;
   HelpText<"Remove unused static globals and functions">;
 def rw_remove_unused_functions : Flag<["-", "/"], "remove-unused-functions">, Group<hlslrewrite_Group>, Flags<[RewriteOption]>,
 def rw_remove_unused_functions : Flag<["-", "/"], "remove-unused-functions">, Group<hlslrewrite_Group>, Flags<[RewriteOption]>,
   HelpText<"Remove unused functions and types">;
   HelpText<"Remove unused functions and types">;
+def rw_line_directive : Flag<["-", "/"], "line-directive">, Group<hlslrewrite_Group>, Flags<[RewriteOption]>,
+  HelpText<"Add line directive">;
 // Also removed: compress, decompress, /Gch (child effect), /Gpp (partial precision)
 // Also removed: compress, decompress, /Gch (child effect), /Gpp (partial precision)
 // /Op - no support for preshaders.
 // /Op - no support for preshaders.

+ 1 - 1
lib/DxcSupport/HLSLOptions.cpp

@@ -904,7 +904,7 @@ int ReadDxcOpts(const OptTable *optionTable, unsigned flagsToInclude,
     opts.RWOpt.ExtractEntryUniforms = Args.hasFlag(OPT_rw_extract_entry_uniforms, OPT_INVALID, false);
     opts.RWOpt.ExtractEntryUniforms = Args.hasFlag(OPT_rw_extract_entry_uniforms, OPT_INVALID, false);
     opts.RWOpt.RemoveUnusedGlobals = Args.hasFlag(OPT_rw_remove_unused_globals, OPT_INVALID, false);
     opts.RWOpt.RemoveUnusedGlobals = Args.hasFlag(OPT_rw_remove_unused_globals, OPT_INVALID, false);
     opts.RWOpt.RemoveUnusedFunctions = Args.hasFlag(OPT_rw_remove_unused_functions, OPT_INVALID, false);
     opts.RWOpt.RemoveUnusedFunctions = Args.hasFlag(OPT_rw_remove_unused_functions, OPT_INVALID, false);
-
+    opts.RWOpt.WithLineDirective = Args.hasFlag(OPT_rw_line_directive, OPT_INVALID, false);
     if (opts.EntryPoint.empty() &&
     if (opts.EntryPoint.empty() &&
         (opts.RWOpt.RemoveUnusedGlobals || opts.RWOpt.ExtractEntryUniforms ||
         (opts.RWOpt.RemoveUnusedGlobals || opts.RWOpt.ExtractEntryUniforms ||
          opts.RWOpt.RemoveUnusedFunctions)) {
          opts.RWOpt.RemoveUnusedFunctions)) {

+ 24 - 0
tools/clang/test/HLSLFileCheck/rewriter/header.h

@@ -0,0 +1,24 @@
+struct A {
+  float a;
+};
+
+struct B : A {
+  float b;
+};
+struct X {
+float a;
+};
+// test macro
+#ifdef TEST
+float bbb;
+#endif
+
+struct C {
+  B b;
+  float c;
+  float Get() { return c + b.b + b.a; }
+};
+
+struct D {
+  C c;
+};

+ 28 - 0
tools/clang/test/HLSLFileCheck/rewriter/line_directive.hlsl

@@ -0,0 +1,28 @@
+// RUN: %dxr -Emain -remove-unused-globals  -line-directive %s | FileCheck %s
+
+#include "header.h"
+
+StructuredBuffer<C> buf : register(t0, space6);
+
+float foo() {
+  return 3;
+}
+
+float main(uint i:I) : SV_Target {
+  float m = 2;
+  float n = sin(i);  return buf[i].c * m + n;
+}
+
+// CHECK:#line 1 {{.*}}line_directive.hlsl
+// CHECK:#line 1 {{.*}}header.h
+// CHECK-NEXT:struct A
+// CHECK-NOT:struct X
+// CHECK-NOT:bbb
+// CHECK:#line 16 {{.*}}header.h
+// CHECK-NEXT:struct C
+// CHECK-NOT:struct D
+// CHECK:#line 5 {{.*}}line_directive.hlsl
+// CHECK-NEXT:StructuredBuffer<C> buf
+// CHECK-NOT:foo
+// CHECK:#line 11 {{.*}}line_directive.hlsl
+// CHECK-NEXT:float main

+ 2 - 2
tools/clang/test/HLSLFileCheck/rewriter/overload3.hlsl

@@ -1,7 +1,7 @@
 // RUN: %dxr -E main -remove-unused-globals %s | FileCheck %s
 // RUN: %dxr -E main -remove-unused-globals %s | FileCheck %s
 
 
-// CHECK:foo
-// CHECK-NOT:foo
+// CHECK:float foo
+// CHECK-NOT:float2 foo
 // CHECK:float main
 // CHECK:float main
 // CHECK:foo(1.2)
 // CHECK:foo(1.2)
 
 

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 640 - 323
tools/clang/tools/libclang/dxcrewriteunused.cpp


برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است