Branimir Karadžić 8 лет назад
Родитель
Сommit
4026fdc25a
2 измененных файлов с 41 добавлено и 18 удалено
  1. 13 10
      3rdparty/dxsdk/include/d3dx12.h
  2. 28 8
      src/renderer_d3d12.cpp

+ 13 - 10
3rdparty/dxsdk/include/d3dx12.h

@@ -1345,12 +1345,15 @@ inline void MemcpySubresource(
     }
 }
 
-static inline D3D12_RESOURCE_DESC ID3D12ResourceGetDesc(ID3D12Resource *res)
+namespace MinGW_Workaround
 {
-    typedef void (STDMETHODCALLTYPE ID3D12Resource::*GetDesc_f)(D3D12_RESOURCE_DESC *);
-    D3D12_RESOURCE_DESC ret;
-    (res->*(GetDesc_f)(&ID3D12Resource::GetDesc))(&ret);
-    return ret;
+	inline D3D12_RESOURCE_DESC ID3D12ResourceGetDesc(ID3D12Resource* _resource)
+	{
+		typedef void (STDMETHODCALLTYPE ID3D12Resource::*PFN_GET_GET_DESC)(D3D12_RESOURCE_DESC*);
+		D3D12_RESOURCE_DESC desc;
+		(_resource->*(PFN_GET_GET_DESC)(&ID3D12Resource::GetDesc))(&desc);
+		return desc;
+	}
 }
 
 //------------------------------------------------------------------------------------------------
@@ -1360,7 +1363,7 @@ inline UINT64 GetRequiredIntermediateSize(
     _In_range_(0,D3D12_REQ_SUBRESOURCES) UINT FirstSubresource,
     _In_range_(0,D3D12_REQ_SUBRESOURCES-FirstSubresource) UINT NumSubresources)
 {
-    D3D12_RESOURCE_DESC Desc = ID3D12ResourceGetDesc(pDestinationResource);
+    D3D12_RESOURCE_DESC Desc = MinGW_Workaround::ID3D12ResourceGetDesc(pDestinationResource);
     UINT64 RequiredSize = 0;
     
     ID3D12Device* pDevice;
@@ -1386,8 +1389,8 @@ inline UINT64 UpdateSubresources(
     _In_reads_(NumSubresources) const D3D12_SUBRESOURCE_DATA* pSrcData)
 {
     // Minor validation
-    D3D12_RESOURCE_DESC IntermediateDesc = ID3D12ResourceGetDesc(pIntermediate);
-    D3D12_RESOURCE_DESC DestinationDesc = ID3D12ResourceGetDesc(pDestinationResource);
+    D3D12_RESOURCE_DESC IntermediateDesc = MinGW_Workaround::ID3D12ResourceGetDesc(pIntermediate);
+    D3D12_RESOURCE_DESC DestinationDesc = MinGW_Workaround::ID3D12ResourceGetDesc(pDestinationResource);
     if (IntermediateDesc.Dimension != D3D12_RESOURCE_DIMENSION_BUFFER || 
         IntermediateDesc.Width < RequiredSize + pLayouts[0].Offset || 
         RequiredSize > (SIZE_T)-1 || 
@@ -1456,7 +1459,7 @@ inline UINT64 UpdateSubresources(
     UINT64* pRowSizesInBytes = reinterpret_cast<UINT64*>(pLayouts + NumSubresources);
     UINT* pNumRows = reinterpret_cast<UINT*>(pRowSizesInBytes + NumSubresources);
     
-    D3D12_RESOURCE_DESC Desc = ID3D12ResourceGetDesc(pDestinationResource);
+    D3D12_RESOURCE_DESC Desc = MinGW_Workaround::ID3D12ResourceGetDesc(pDestinationResource);
     ID3D12Device* pDevice;
     pDestinationResource->GetDevice(__uuidof(ID3D12Device), reinterpret_cast<void**>(&pDevice));
     pDevice->GetCopyableFootprints(&Desc, FirstSubresource, NumSubresources, IntermediateOffset, pLayouts, pNumRows, pRowSizesInBytes, &RequiredSize);
@@ -1484,7 +1487,7 @@ inline UINT64 UpdateSubresources(
     UINT NumRows[MaxSubresources];
     UINT64 RowSizesInBytes[MaxSubresources];
     
-    D3D12_RESOURCE_DESC Desc = ID3D12ResourceGetDesc(pDestinationResource);
+    D3D12_RESOURCE_DESC Desc = MinGW_Workaround::ID3D12ResourceGetDesc(pDestinationResource);
     ID3D12Device* pDevice;
     pDestinationResource->GetDevice(__uuidof(*pDevice), reinterpret_cast<void**>(&pDevice));
     pDevice->GetCopyableFootprints(&Desc, FirstSubresource, NumSubresources, IntermediateOffset, Layouts, NumRows, RowSizesInBytes, &RequiredSize);

+ 28 - 8
src/renderer_d3d12.cpp

@@ -502,20 +502,40 @@ namespace bgfx { namespace d3d12
 	static PFN_CREATE_EVENT_EX_A CreateEventExA;
 #endif // USE_D3D12_DYNAMIC_LIB
 
-	static D3D12_CPU_DESCRIPTOR_HANDLE getCPUHandleHeapStart(ID3D12DescriptorHeap* _heap) 
+	inline D3D12_CPU_DESCRIPTOR_HANDLE getCPUHandleHeapStart(ID3D12DescriptorHeap* _heap)
 	{
+#if BX_COMPILER_MSVC
+		return _heap->GetCPUDescriptorHandleForHeapStart();
+#else
 		D3D12_CPU_DESCRIPTOR_HANDLE handle;
 		typedef void (WINAPI ID3D12DescriptorHeap::*PFN_GET_CPU_DESCRIPTOR_HANDLE_FOR_HEAP_START)(D3D12_CPU_DESCRIPTOR_HANDLE *);
 		(_heap->*(PFN_GET_CPU_DESCRIPTOR_HANDLE_FOR_HEAP_START)(&ID3D12DescriptorHeap::GetCPUDescriptorHandleForHeapStart) )(&handle);
 		return handle;
+#endif // BX_COMPILER_MSVC
 	}
 
-	static D3D12_GPU_DESCRIPTOR_HANDLE getGPUHandleHeapStart(ID3D12DescriptorHeap* _heap) 
+	inline D3D12_GPU_DESCRIPTOR_HANDLE getGPUHandleHeapStart(ID3D12DescriptorHeap* _heap)
 	{
+#if BX_COMPILER_MSVC
+		return _heap->GetGPUDescriptorHandleForHeapStart();
+#else
 		D3D12_GPU_DESCRIPTOR_HANDLE handle;
 		typedef void (WINAPI ID3D12DescriptorHeap::*PFN_GET_GPU_DESCRIPTOR_HANDLE_FOR_HEAP_START)(D3D12_GPU_DESCRIPTOR_HANDLE *);
 		(_heap->*(PFN_GET_GPU_DESCRIPTOR_HANDLE_FOR_HEAP_START)(&ID3D12DescriptorHeap::GetGPUDescriptorHandleForHeapStart) )(&handle);
 		return handle;
+#endif // BX_COMPILER_MSVC
+	}
+
+	inline D3D12_RESOURCE_DESC getResourceDesc(ID3D12Resource* _resource)
+	{
+#if BX_COMPILER_MSVC
+		return _resource->GetDesc();
+#else
+		typedef void (STDMETHODCALLTYPE ID3D12Resource::*PFN_GET_GET_DESC)(D3D12_RESOURCE_DESC*);
+		D3D12_RESOURCE_DESC desc;
+		(_resource->*(PFN_GET_GET_DESC)(&ID3D12Resource::GetDesc))(&desc);
+		return desc;
+#endif // BX_COMPILER_MSVC
 	}
 
 	struct RendererContextD3D12 : public RendererContextI
@@ -1478,7 +1498,7 @@ namespace bgfx { namespace d3d12
 		{
 			const TextureD3D12& texture = m_textures[_handle.idx];
 
-			D3D12_RESOURCE_DESC desc = ID3D12ResourceGetDesc(texture.m_ptr);
+			D3D12_RESOURCE_DESC desc = getResourceDesc(texture.m_ptr);
 
 			D3D12_PLACED_SUBRESOURCE_FOOTPRINT layout;
 			uint32_t numRows;
@@ -1635,7 +1655,7 @@ namespace bgfx { namespace d3d12
 			m_cmd.finish(m_backBufferColorFence[idx]);
 			ID3D12Resource* backBuffer = m_backBufferColor[idx];
 
-			D3D12_RESOURCE_DESC desc = ID3D12ResourceGetDesc(backBuffer);
+			D3D12_RESOURCE_DESC desc = getResourceDesc(backBuffer);
 
 			const uint32_t width  = (uint32_t)desc.Width;
 			const uint32_t height = (uint32_t)desc.Height;
@@ -4464,7 +4484,7 @@ data.NumQualityLevels = 0;
 		const uint32_t rectpitch = _rect.m_width*bpp/8;
 		const uint32_t srcpitch  = UINT16_MAX == _pitch ? rectpitch : _pitch;
 
-		D3D12_RESOURCE_DESC desc = ID3D12ResourceGetDesc(m_ptr);
+		D3D12_RESOURCE_DESC desc = getResourceDesc(m_ptr);
 
 		desc.Height = _rect.m_height;
 
@@ -4572,7 +4592,7 @@ data.NumQualityLevels = 0;
 
 					if (0 == m_width)
 					{
-						D3D12_RESOURCE_DESC desc = ID3D12ResourceGetDesc(texture.m_ptr);
+						D3D12_RESOURCE_DESC desc = getResourceDesc(texture.m_ptr);
 						m_width  = uint32_t(desc.Width);
 						m_height = uint32_t(desc.Height);
 					}
@@ -4721,10 +4741,10 @@ data.NumQualityLevels = 0;
 			);
 
 		DX_CHECK(s_renderD3D12->m_cmd.m_commandQueue->GetTimestampFrequency(&m_frequency) );
-		
+
 		D3D12_RANGE range = { 0, size };
 		m_readback->Map(0, &range, (void**)&m_queryResult);
-	
+
 		for (uint32_t ii = 0; ii < BX_COUNTOF(m_result); ++ii)
 		{
 			Result& result = m_result[ii];