Преглед на файлове

PIX pixel-cost visualizer: Fix byte offset, simplify ReEmitDxilResources (#749)

* byte offset, not element offset => multiply by sizeof(dword)
set uav to r/w
Re-emit meta-data becomes delete then emit

* update test

* re-compute view id state
Jeff Noyle преди 7 години
родител
ревизия
0acdbd9a8c
променени са 3 файла, в които са добавени 6 реда и са изтрити 19 реда
  1. 2 1
      lib/HLSL/DxilAddPixelHitInstrumentation.cpp
  2. 3 17
      lib/HLSL/DxilModule.cpp
  3. 1 1
      tools/clang/test/HLSL/pix/pixelCounterAddPixelCost.hlsl

+ 2 - 1
lib/HLSL/DxilAddPixelHitInstrumentation.cpp

@@ -143,6 +143,7 @@ bool DxilAddPixelHitInstrumentation::runOnModule(Module &M)
     pUAV->SetLowerBound(0);
     pUAV->SetRangeSize(1);
     pUAV->SetKind(DXIL::ResourceKind::RawBuffer);
+    pUAV->SetRW(true);
 
     auto pAnnotation = DM.GetTypeSystem().GetStructAnnotation(UAVStructTy);
     if (pAnnotation == nullptr)
@@ -247,7 +248,7 @@ bool DxilAddPixelHitInstrumentation::runOnModule(Module &M)
           {
             Function* LoadWeight = HlslOP->GetOpFunc(OP::OpCode::BufferLoad, Type::getInt32Ty(Ctx));
             Constant* LoadWeightOpcode = HlslOP->GetU32Const((unsigned)DXIL::OpCode::BufferLoad);
-            Constant* OffsetIntoUAV = HlslOP->GetU32Const(NumPixels * 2);
+            Constant* OffsetIntoUAV = HlslOP->GetU32Const(NumPixels * 2 * 4);
             auto WeightStruct = Builder.CreateCall(LoadWeight, {
               LoadWeightOpcode, // i32 opcode
               HandleForUAV,     // %dx.types.Handle, ; resource handle

+ 3 - 17
lib/HLSL/DxilModule.cpp

@@ -1393,23 +1393,9 @@ MDTuple *DxilModule::EmitDxilResources() {
 }
 
 void DxilModule::ReEmitDxilResources() {
-  MDTuple *pNewResource = EmitDxilResources();
-  m_pMDHelper->UpdateDxilResources(pNewResource);
-  m_pMDHelper->EmitDxilTypeSystem(GetTypeSystem(), m_LLVMUsed);
-  const llvm::NamedMDNode *pEntries = m_pMDHelper->GetDxilEntryPoints();
-  IFTBOOL(pEntries->getNumOperands() == 1, DXC_E_INCORRECT_DXIL_METADATA);
-
-  Function *pEntryFunc;
-  string EntryName;
-  const llvm::MDOperand *pSignatures, *pResources, *pProperties;
-  m_pMDHelper->GetDxilEntryPoint(pEntries->getOperand(0), pEntryFunc, EntryName, pSignatures, pResources, pProperties);
-
-  MDTuple *pMDSignatures = m_pMDHelper->EmitDxilSignatures(*m_EntrySignature);
-  MDTuple *pMDProperties = EmitDxilShaderProperties();
-  MDTuple *pEntry = m_pMDHelper->EmitDxilEntryPointTuple(pEntryFunc, EntryName, pMDSignatures, pNewResource, pMDProperties);
-  vector<MDNode *> Entries;
-  Entries.emplace_back(pEntry);
-  m_pMDHelper->UpdateDxilEntryPoints(Entries);
+  ClearDxilMetadata(*m_pModule);
+  m_pViewIdState->Compute();
+  EmitDxilMetadata();
 }
 
 void DxilModule::LoadDxilResources(const llvm::MDOperand &MDO) {

+ 1 - 1
tools/clang/test/HLSL/pix/pixelCounterAddPixelCost.hlsl

@@ -4,7 +4,7 @@
 // CHECK: %UAVIncResult = call i32 @dx.op.atomicBinOp.i32(i32 78, %dx.types.Handle %PIX_CountUAV_Handle, i32 0, i32 %ByteIndex, i32 undef, i32 undef, i32 1)
 
 // Check for pixel cost instructions:
-// CHECK: %WeightStruct = call %dx.types.ResRet.i32 @dx.op.bufferLoad.i32(i32 68, %dx.types.Handle %PIX_CountUAV_Handle, i32 128, i32 undef)
+// CHECK: %WeightStruct = call %dx.types.ResRet.i32 @dx.op.bufferLoad.i32(i32 68, %dx.types.Handle %PIX_CountUAV_Handle, i32 512, i32 undef)
 // CHECK: %Weight = extractvalue %dx.types.ResRet.i32 %WeightStruct, 0
 // CHECK: %OffsetByteIndex = add i32 %ByteIndex, 256
 // CHECK: %UAVIncResult2 = call i32 @dx.op.atomicBinOp.i32(i32 78, %dx.types.Handle %PIX_CountUAV_Handle, i32 0, i32 %OffsetByteIndex, i32 undef, i32 undef, i32 %Weight)