Browse Source

[spirv] Remove -fvk-ignore-unused-resources (#1246)

Lei Zhang 7 years ago
parent
commit
23be4804b6

+ 0 - 3
docs/SPIR-V.rst

@@ -2692,9 +2692,6 @@ codegen for Vulkan:
 - ``-fvk-t-shift N M``, similar to ``-fvk-b-shift``, but for t-type registers.
 - ``-fvk-s-shift N M``, similar to ``-fvk-b-shift``, but for s-type registers.
 - ``-fvk-u-shift N M``, similar to ``-fvk-b-shift``, but for u-type registers.
-- ``-fvk-ignore-unused-resources``: Avoids emitting SPIR-V code for resources
-  defined but not statically referenced by the call tree of the entry point
-  in question.
 - ``-fvk-use-gl-layout``: Uses strict OpenGL ``std140``/``std430``
   layout rules for resources.
 - ``-fvk-use-dx-layout``: Uses DirectX layout rules for resources.

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

@@ -161,7 +161,6 @@ public:
   // SPIRV Change Starts
 #ifdef ENABLE_SPIRV_CODEGEN
   bool GenSPIRV;                           // OPT_spirv
-  bool VkIgnoreUnusedResources;            // OPT_fvk_ignore_used_resources
   bool VkInvertY;                          // OPT_fvk_invert_y
   bool VkUseGlLayout;                      // OPT_fvk_use_gl_layout
   bool VkUseDxLayout;                      // OPT_fvk_use_dx_layout

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

@@ -236,8 +236,6 @@ def ignore_line_directives : Flag<["-", "/"], "ignore-line-directives">, HelpTex
 // SPIRV Change Starts
 def spirv : Flag<["-"], "spirv">, Group<spirv_Group>, Flags<[CoreOption, DriverOption]>,
   HelpText<"Generate SPIR-V code">;
-def fvk_ignore_unused_resources : Flag<["-"], "fvk-ignore-unused-resources">, Group<spirv_Group>, Flags<[CoreOption, DriverOption]>,
-  HelpText<"Do not emit SPIR-V code for unused resources">;
 def fvk_stage_io_order_EQ : Joined<["-"], "fvk-stage-io-order=">, Group<spirv_Group>, Flags<[CoreOption, DriverOption, HelpHidden]>,
   HelpText<"Specify Vulkan stage I/O location assignment order">;
 def fvk_b_shift : MultiArg<["-"], "fvk-b-shift", 2>, MetaVarName<"<shift> <space>">, Group<spirv_Group>, Flags<[CoreOption, DriverOption]>,

+ 1 - 3
lib/DxcSupport/HLSLOptions.cpp

@@ -456,7 +456,7 @@ int ReadDxcOpts(const OptTable *optionTable, unsigned flagsToInclude,
     if (opts.AllResourcesBound || opts.AvoidFlowControl ||
         opts.CodeGenHighLevel || opts.DebugInfo || opts.DefaultColMajor ||
         opts.DefaultRowMajor || opts.Defines.size() != 0 ||
-        opts.DisableOptimizations || 
+        opts.DisableOptimizations ||
         !opts.EntryPoint.empty() || !opts.ForceRootSigVer.empty() ||
         opts.PreferFlowControl || !opts.TargetProfile.empty()) {
       errors << "Cannot specify compilation options when reading a binary file.";
@@ -487,7 +487,6 @@ int ReadDxcOpts(const OptTable *optionTable, unsigned flagsToInclude,
   opts.VkUseGlLayout = Args.hasFlag(OPT_fvk_use_gl_layout, OPT_INVALID, false);
   opts.VkUseDxLayout = Args.hasFlag(OPT_fvk_use_dx_layout, OPT_INVALID, false);
   opts.SpvEnableReflect = Args.hasFlag(OPT_fspv_reflect, OPT_INVALID, false);
-  opts.VkIgnoreUnusedResources = Args.hasFlag(OPT_fvk_ignore_unused_resources, OPT_INVALID, false);
 
   // Collects the arguments for -fvk-{b|s|t|u}-shift.
   const auto handleVkShiftArgs =
@@ -552,7 +551,6 @@ int ReadDxcOpts(const OptTable *optionTable, unsigned flagsToInclude,
       Args.hasFlag(OPT_fvk_use_gl_layout, OPT_INVALID, false) ||
       Args.hasFlag(OPT_fvk_use_dx_layout, OPT_INVALID, false) ||
       Args.hasFlag(OPT_fspv_reflect, OPT_INVALID, false) ||
-      Args.hasFlag(OPT_fvk_ignore_unused_resources, OPT_INVALID, false) ||
       !Args.getLastArgValue(OPT_fvk_stage_io_order_EQ).empty() ||
       !Args.getLastArgValue(OPT_fspv_extension_EQ).empty() ||
       !Args.getLastArgValue(OPT_fspv_target_env_EQ).empty() ||

+ 0 - 1
tools/clang/include/clang/SPIRV/EmitSPIRVOptions.h

@@ -35,7 +35,6 @@ struct EmitSPIRVOptions {
   bool invertY;
   bool useGlLayout;
   bool useDxLayout;
-  bool ignoreUnusedResources;
   bool enable16BitTypes;
   bool enableReflect;
   bool enableDebugInfo;

+ 1 - 5
tools/clang/lib/SPIRV/DeclResultIdMapper.cpp

@@ -282,8 +282,7 @@ DeclResultIdMapper::getDeclSpirvInfo(const ValueDecl *decl) const {
   return nullptr;
 }
 
-SpirvEvalInfo DeclResultIdMapper::getDeclEvalInfo(const ValueDecl *decl,
-                                                  bool checkRegistered) {
+SpirvEvalInfo DeclResultIdMapper::getDeclEvalInfo(const ValueDecl *decl) {
   if (const auto *info = getDeclSpirvInfo(decl))
     if (info->indexInCTBuffer >= 0) {
       // If this is a VarDecl inside a HLSLBufferDecl, we need to do an extra
@@ -306,15 +305,12 @@ SpirvEvalInfo DeclResultIdMapper::getDeclEvalInfo(const ValueDecl *decl,
       return *info;
     }
 
-  if (checkRegistered) {
     emitFatalError("found unregistered decl", decl->getLocation())
         << decl->getName();
     emitNote("please file a bug report on "
              "https://github.com/Microsoft/DirectXShaderCompiler/issues with "
              "source code if possible",
              {});
-  }
-
   return 0;
 }
 

+ 3 - 6
tools/clang/lib/SPIRV/DeclResultIdMapper.h

@@ -363,13 +363,10 @@ private:
   const DeclSpirvInfo *getDeclSpirvInfo(const ValueDecl *decl) const;
 
 public:
-  /// \brief Returns the information for the given decl. If the decl is not
-  /// registered previously, return an invalid SpirvEvalInfo.
+  /// \brief Returns the information for the given decl.
   ///
-  /// This method will emit a fatal error if checkRegistered is true and the
-  /// decl is not registered.
-  SpirvEvalInfo getDeclEvalInfo(const ValueDecl *decl,
-                                bool checkRegistered = true);
+  /// This method will panic if the given decl is not registered.
+  SpirvEvalInfo getDeclEvalInfo(const ValueDecl *decl);
 
   /// \brief Returns the <result-id> for the given function if already
   /// registered; otherwise, treats the given function as a normal decl and

+ 2 - 21
tools/clang/lib/SPIRV/SPIRVEmitter.cpp

@@ -587,11 +587,7 @@ void SPIRVEmitter::HandleTranslationUnit(ASTContext &context) {
         workQueue.insert(funcDecl);
       }
     } else {
-      // If ignoring unused resources, defer Decl handling inside
-      // TranslationUnit to the time of first referencing.
-      if (!spirvOptions.ignoreUnusedResources) {
-        doDecl(decl);
-      }
+      doDecl(decl);
     }
   }
 
@@ -749,21 +745,6 @@ void SPIRVEmitter::doStmt(const Stmt *stmt,
   }
 }
 
-SpirvEvalInfo SPIRVEmitter::doDeclRefExpr(const DeclRefExpr *expr) {
-  const auto *decl = expr->getDecl();
-  auto id = declIdMapper.getDeclEvalInfo(decl, false);
-
-  if (spirvOptions.ignoreUnusedResources && !id) {
-    // First time referencing a Decl inside TranslationUnit. Register
-    // into DeclResultIdMapper and emit SPIR-V for it and then query
-    // again.
-    doDecl(decl);
-    id = declIdMapper.getDeclEvalInfo(decl);
-  }
-
-  return id;
-}
-
 SpirvEvalInfo SPIRVEmitter::doExpr(const Expr *expr) {
   SpirvEvalInfo result(/*id*/ 0);
 
@@ -774,7 +755,7 @@ SpirvEvalInfo SPIRVEmitter::doExpr(const Expr *expr) {
   expr = expr->IgnoreParens();
 
   if (const auto *declRefExpr = dyn_cast<DeclRefExpr>(expr)) {
-    result = doDeclRefExpr(declRefExpr);
+    result = declIdMapper.getDeclEvalInfo(declRefExpr->getDecl());
   } else if (const auto *memberExpr = dyn_cast<MemberExpr>(expr)) {
     result = doMemberExpr(memberExpr);
   } else if (const auto *castExpr = dyn_cast<CastExpr>(expr)) {

+ 0 - 1
tools/clang/lib/SPIRV/SPIRVEmitter.h

@@ -100,7 +100,6 @@ private:
   SpirvEvalInfo doConditionalOperator(const ConditionalOperator *expr);
   SpirvEvalInfo doCXXMemberCallExpr(const CXXMemberCallExpr *expr);
   SpirvEvalInfo doCXXOperatorCallExpr(const CXXOperatorCallExpr *expr);
-  SpirvEvalInfo doDeclRefExpr(const DeclRefExpr *expr);
   SpirvEvalInfo doExtMatrixElementExpr(const ExtMatrixElementExpr *expr);
   SpirvEvalInfo doHLSLVectorElementExpr(const HLSLVectorElementExpr *expr);
   SpirvEvalInfo doInitListExpr(const InitListExpr *expr);

+ 0 - 73
tools/clang/test/CodeGenSPIRV/vk.cloption.ignore-unused-resources.hlsl

@@ -1,73 +0,0 @@
-// Run: %dxc -T ps_6_0 -E main -fvk-ignore-unused-resources
-
-SamplerState gSampler;
-
-// CHECK:      %gRWBuffer1 = OpVariable
-// CHECK-NOT:  %gRWBuffer2 = OpVariable
-// CHECK-NOT:  %gRWBuffer3 = OpVariable
-// CHECK:      %gRWBuffer4 = OpVariable
-RWBuffer<float4> gRWBuffer1;
-RWBuffer<float4> gRWBuffer2;
-RWBuffer<float4> gRWBuffer3;
-RWBuffer<float4> gRWBuffer4;
-
-// CHECK-NOT:  %gTex2D1 = OpVariable
-// CHECK:      %gTex2D2 = OpVariable
-// CHECK:      %gTex2D3 = OpVariable
-// CHECK-NOT:  %gTex2D4 = OpVariable
-Texture2D gTex2D1;
-Texture2D gTex2D2;
-Texture2D gTex2D3;
-Texture2D gTex2D4;
-
-// CHECK-NOT: %gCBuffer1 = OpVariable
-cbuffer gCBuffer1 {
-    float4 cb_f;
-};
-
-// CHECK:     %gTBuffer1 = OpVariable
-tbuffer gTBuffer1 {
-    float4 tb_f;
-};
-
-struct S {
-    float4 f;
-};
-
-// CHECK:     %gCBuffer2 = OpVariable
-// CHECK-NOT: %gTBuffer1 = OpVariable
-ConstantBuffer<S> gCBuffer2;
-TextureBuffer<S> gTBuffer2;
-
-// CHECK:     %gASBuffer1 = OpVariable
-// CHECK-NOT: %gASBuffer2 = OpVariable
-AppendStructuredBuffer<S> gASBuffer1;
-AppendStructuredBuffer<S> gASBuffer2;
-
-// CHECK-NOT: %gCSBuffer1 = OpVariable
-// CHECK:     %gCSBuffer2 = OpVariable
-ConsumeStructuredBuffer<S> gCSBuffer1;
-ConsumeStructuredBuffer<S> gCSBuffer2;
-
-float4 foo(float4 param) {
-    return param;
-}
-
-float4 bar(float4 param) {
-    return param;
-}
-
-float4 main() : SV_Target {
-    S val = {1., 2., 3., 4.};
-
-    float4 ret =
-        gRWBuffer1.Load(0) + gRWBuffer4[1] +
-        gTex2D2.Sample(gSampler, 2.) + gTex2D3[float2(3., 4.)] +
-        tb_f + gCBuffer2.f;
-
-    gASBuffer1.Append(val);
-
-    ret += gCSBuffer2.Consume().f;
-
-    return ret;
-}

+ 0 - 1
tools/clang/tools/dxcompiler/dxcompilerobj.cpp

@@ -472,7 +472,6 @@ public:
           spirvOpts.useGlLayout = opts.VkUseGlLayout;
           spirvOpts.useDxLayout = opts.VkUseDxLayout;
           spirvOpts.enableReflect = opts.SpvEnableReflect;
-          spirvOpts.ignoreUnusedResources = opts.VkIgnoreUnusedResources;
           spirvOpts.defaultRowMajor = opts.DefaultRowMajor;
           spirvOpts.stageIoOrder = opts.VkStageIoOrder;
           spirvOpts.bShift = opts.VkBShift;

+ 0 - 4
tools/clang/unittests/SPIRV/CodeGenSPIRVTest.cpp

@@ -1277,10 +1277,6 @@ TEST_F(FileTest, VulkanAttributeInvalidUsages) {
   runFileTest("vk.attribute.invalid.hlsl", Expect::Failure);
 }
 
-TEST_F(FileTest, VulkanCLOptionIgnoreUnusedResources) {
-  runFileTest("vk.cloption.ignore-unused-resources.hlsl");
-}
-
 TEST_F(FileTest, VulkanCLOptionInvertYVS) {
   runFileTest("vk.cloption.invert-y.vs.hlsl");
 }