Browse Source

Fix microcom and build issues, add missing .rc files

- fix microcom.h macros to allow for custom constructor and other issues
- fix 32/64-bit build issues in ShaderOpTest
- add missing .rc files for dxl, dxlib_sample, and dxc_batch
Young Kim 7 years ago
parent
commit
ecdde943f7

+ 13 - 6
include/dxc/Support/microcom.h

@@ -88,9 +88,10 @@ public:
 
 template <typename T, typename... Args>
 inline T *CreateOnMalloc(IMalloc * pMalloc, Args&&... args) {
-  void *P = pMalloc->Alloc(sizeof(T)); \
-  if (P) new (P)T(pMalloc, std::forward<Args>(args)...); \
-  return (T *)P; \
+  void *P = pMalloc->Alloc(sizeof(T));
+  try { if (P) new (P)T(pMalloc, std::forward<Args>(args)...); }
+  catch (...) { pMalloc->Free(P); throw; }
+  return (T *)P;
 }
 
 template<typename T>
@@ -116,10 +117,16 @@ void DxcCallDestructor(T *obj) {
       return result; \
     }
 #define DXC_MICROCOM_TM_CTOR(T) \
-  T(IMalloc *pMalloc) : m_dwRef(0), m_pMalloc(pMalloc) { } \
-  static T* Alloc(IMalloc *pMalloc) { \
+  DXC_MICROCOM_TM_CTOR_ONLY(T) \
+  DXC_MICROCOM_TM_ALLOC(T)
+#define DXC_MICROCOM_TM_CTOR_ONLY(T) \
+  T(IMalloc *pMalloc) : m_dwRef(0), m_pMalloc(pMalloc) { }
+#define DXC_MICROCOM_TM_ALLOC(T) \
+  template <typename... Args> \
+  static T* Alloc(IMalloc *pMalloc, Args&&... args) { \
     void *P = pMalloc->Alloc(sizeof(T)); \
-    try { if (P) new (P)T(pMalloc); } catch (...) { operator delete(P); throw; } \
+    try { if (P) new (P)T(pMalloc, std::forward<Args>(args)...); } \
+    catch (...) { pMalloc->Free(P); throw; } \
     return (T *)P; \
   }
 

+ 13 - 0
tools/clang/tools/dxl/dxl.rc

@@ -0,0 +1,13 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+//
+
+#include <windows.h>
+#include <ntverp.h>
+
+#define VER_FILETYPE                  VFT_DLL
+#define VER_FILESUBTYPE               VFT_UNKNOWN
+#define VER_FILEDESCRIPTION_STR       "DX Linker"
+#define VER_INTERNALNAME_STR          "DX Linker"
+#define VER_ORIGINALFILENAME_STR      "dxl.exe"
+
+#include <common.ver>

+ 13 - 0
tools/clang/tools/dxlib-sample/dxlib_sample.rc

@@ -0,0 +1,13 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+//
+
+#include <windows.h>
+#include <ntverp.h>
+
+#define VER_FILETYPE                  VFT_DLL
+#define VER_FILESUBTYPE               VFT_UNKNOWN
+#define VER_FILEDESCRIPTION_STR       "DX Library Sample"
+#define VER_INTERNALNAME_STR          "DX Library Sample"
+#define VER_ORIGINALFILENAME_STR      "dxlib_sample.dll"
+
+#include <common.ver>

+ 12 - 11
tools/clang/unittests/HLSL/ShaderOpTest.cpp

@@ -259,12 +259,12 @@ void ShaderOpTest::CopyBackResources() {
       pList->CopyResource(D.ReadBack, D.Resource);
     }
     else {
-      UINT rowPitch = Desc.Width * GetByteSizeForFormat(Desc.Format);
+      UINT64 rowPitch = Desc.Width * GetByteSizeForFormat(Desc.Format);
       if (rowPitch % D3D12_TEXTURE_DATA_PITCH_ALIGNMENT)
         rowPitch += D3D12_TEXTURE_DATA_PITCH_ALIGNMENT - (rowPitch % D3D12_TEXTURE_DATA_PITCH_ALIGNMENT);
       D3D12_PLACED_SUBRESOURCE_FOOTPRINT Footprint;
       Footprint.Offset = 0;
-      Footprint.Footprint = CD3DX12_SUBRESOURCE_FOOTPRINT(Desc.Format, Desc.Width, Desc.Height, 1, rowPitch);
+      Footprint.Footprint = CD3DX12_SUBRESOURCE_FOOTPRINT(Desc.Format, (UINT)Desc.Width, Desc.Height, 1, (UINT)rowPitch);
       CD3DX12_TEXTURE_COPY_LOCATION DstLoc(D.ReadBack, Footprint);
       CD3DX12_TEXTURE_COPY_LOCATION SrcLoc(D.Resource, 0);
       pList->CopyTextureRegion(&DstLoc, 0, 0, 0, &SrcLoc, nullptr);
@@ -329,7 +329,7 @@ void ShaderOpTest::CreateDescriptorHeaps() {
       else if (0 == _stricmp(D.Kind, "CBV")) {
         D3D12_CONSTANT_BUFFER_VIEW_DESC cbvDesc;
         cbvDesc.BufferLocation = Data.Resource->GetGPUVirtualAddress();
-        cbvDesc.SizeInBytes = Data.Resource->GetDesc().Width;
+        cbvDesc.SizeInBytes = (UINT)Data.Resource->GetDesc().Width;
         m_pDevice->CreateConstantBufferView(&cbvDesc, cpuHandle);
       }
 
@@ -417,10 +417,10 @@ void ShaderOpTest::CreatePipelineState() {
     ZeroMemory(&GDesc, sizeof(GDesc));
     InitByteCode(&GDesc.VS, pVS);
     InitByteCode(&GDesc.PS, pPS);
-    GDesc.InputLayout.NumElements = m_pShaderOp->InputElements.size();
+    GDesc.InputLayout.NumElements = (UINT)m_pShaderOp->InputElements.size();
     GDesc.InputLayout.pInputElementDescs = m_pShaderOp->InputElements.data();
     GDesc.PrimitiveTopologyType = m_pShaderOp->PrimitiveTopologyType;
-    GDesc.NumRenderTargets = m_pShaderOp->RenderTargets.size();
+    GDesc.NumRenderTargets = (UINT)m_pShaderOp->RenderTargets.size();
     GDesc.SampleMask = m_pShaderOp->SampleMask;
     for (size_t i = 0; i < m_pShaderOp->RenderTargets.size(); ++i) {
       ShaderOpResource *R = m_pShaderOp->GetResourceByName(m_pShaderOp->RenderTargets[i]);
@@ -768,19 +768,19 @@ void ShaderOpTest::RunCommandList() {
       D3D12_RECT scissorRect;
 
       memset(&viewport, 0, sizeof(viewport));
-      viewport.Height = R->Desc.Height;
-      viewport.Width = R->Desc.Width;
+      viewport.Height = (FLOAT)R->Desc.Height;
+      viewport.Width = (FLOAT)R->Desc.Width;
       viewport.MaxDepth = 1.0f;
       memset(&scissorRect, 0, sizeof(scissorRect));
-      scissorRect.right = viewport.Width;
-      scissorRect.bottom = viewport.Height;
+      scissorRect.right = (LONG)viewport.Width;
+      scissorRect.bottom = (LONG)viewport.Height;
       pList->RSSetViewports(1, &viewport);
       pList->RSSetScissorRects(1, &scissorRect);
     }
 
     // Indicate that the buffers will be used as render targets.
     D3D12_CPU_DESCRIPTOR_HANDLE rtvHandles[8];
-    UINT rtvHandleCount = m_pShaderOp->RenderTargets.size();
+    UINT rtvHandleCount = (UINT)m_pShaderOp->RenderTargets.size();
     for (size_t i = 0; i < rtvHandleCount; ++i) {
       auto &rt = m_pShaderOp->RenderTargets[i];
       ShaderOpDescriptorData &DData = m_DescriptorData[rt];
@@ -817,7 +817,7 @@ void ShaderOpTest::RunCommandList() {
     D3D12_VERTEX_BUFFER_VIEW vertexBufferView;
     vertexBufferView.BufferLocation = VBufferData.Resource->GetGPUVirtualAddress();
     vertexBufferView.StrideInBytes = strideInBytes;
-    vertexBufferView.SizeInBytes = VBufferData.ShaderOpRes->Desc.Width;
+    vertexBufferView.SizeInBytes = (UINT)VBufferData.ShaderOpRes->Desc.Width;
     pList->IASetVertexBuffers(0, 1, &vertexBufferView);
     UINT vertexCount = vertexBufferView.SizeInBytes / vertexBufferView.StrideInBytes;
     UINT instanceCount = 1;
@@ -971,6 +971,7 @@ void ShaderOpTest::SetupRenderTarget(ShaderOp *pShaderOp, ID3D12Device *pDevice,
 void ShaderOpTest::PresentRenderTarget(ShaderOp *pShaderOp,
                                        ID3D12CommandQueue *pCommandQueue,
                                        ID3D12Resource *pRenderTarget) {
+  UNREFERENCED_PARAMETER(pShaderOp);
   CommandListRefs ResCommandList;
   ResCommandList.Queue = pCommandQueue;
   ResCommandList.CreateForDevice(m_pDevice, m_pShaderOp->IsCompute());

+ 13 - 0
tools/clang/unittests/dxc_batch/dxc_batch.rc

@@ -0,0 +1,13 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+//
+
+#include <windows.h>
+#include <ntverp.h>
+
+#define VER_FILETYPE                  VFT_DLL
+#define VER_FILESUBTYPE               VFT_UNKNOWN
+#define VER_FILEDESCRIPTION_STR       "DX Assembler"
+#define VER_INTERNALNAME_STR          "DX Assembler"
+#define VER_ORIGINALFILENAME_STR      "dxa.exe"
+
+#include <common.ver>