From b35ab1fd7e71b39513ff8aaf33602844ec81b5a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E9=A3=8E?= Date: Mon, 10 Sep 2018 23:12:36 +0800 Subject: [PATCH] fix warning for gcc 8.2 (#1485) --- 3rdparty/dxsdk/include/d3dx12.h | 7 +++++-- src/renderer_d3d12.cpp | 28 ++++++++++++++++++++-------- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/3rdparty/dxsdk/include/d3dx12.h b/3rdparty/dxsdk/include/d3dx12.h index bc4b6040d..36aebf8a6 100644 --- a/3rdparty/dxsdk/include/d3dx12.h +++ b/3rdparty/dxsdk/include/d3dx12.h @@ -1349,9 +1349,12 @@ namespace MinGW_Workaround { 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); + union { + D3D12_RESOURCE_DESC (STDMETHODCALLTYPE ID3D12Resource::*w)(); + void (STDMETHODCALLTYPE ID3D12Resource::*f)(D3D12_RESOURCE_DESC *); + } conversion = { &ID3D12Resource::GetDesc }; + (_resource->*conversion.f)(&desc); return desc; } } diff --git a/src/renderer_d3d12.cpp b/src/renderer_d3d12.cpp index 8a447b00c..7e09f37fb 100644 --- a/src/renderer_d3d12.cpp +++ b/src/renderer_d3d12.cpp @@ -419,9 +419,12 @@ namespace bgfx { namespace d3d12 static inline D3D12_HEAP_PROPERTIES ID3D12DeviceGetCustomHeapProperties(ID3D12Device *device, UINT nodeMask, D3D12_HEAP_TYPE heapType) { // NOTICE: gcc trick for return struct - typedef void (STDMETHODCALLTYPE ID3D12Device::*GetCustomHeapProperties_f)(D3D12_HEAP_PROPERTIES *, UINT, D3D12_HEAP_TYPE); + union { + D3D12_HEAP_PROPERTIES (STDMETHODCALLTYPE ID3D12Device::*w)(UINT, D3D12_HEAP_TYPE); + void (STDMETHODCALLTYPE ID3D12Device::*f)(D3D12_HEAP_PROPERTIES *, UINT, D3D12_HEAP_TYPE); + } conversion = { &ID3D12Device::GetCustomHeapProperties }; D3D12_HEAP_PROPERTIES ret; - (device->*(GetCustomHeapProperties_f)(&ID3D12Device::GetCustomHeapProperties))(&ret, nodeMask, heapType); + (device->*conversion.f)(&ret, nodeMask, heapType); return ret; } @@ -563,8 +566,11 @@ namespace bgfx { namespace d3d12 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); + union { + D3D12_CPU_DESCRIPTOR_HANDLE (WINAPI ID3D12DescriptorHeap::*w)(); + void (WINAPI ID3D12DescriptorHeap::*f)(D3D12_CPU_DESCRIPTOR_HANDLE *); + } conversion = { &ID3D12DescriptorHeap::GetCPUDescriptorHandleForHeapStart }; + (_heap->*conversion.f)(&handle); return handle; #endif // BX_COMPILER_MSVC } @@ -575,8 +581,11 @@ namespace bgfx { namespace d3d12 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); + union { + D3D12_GPU_DESCRIPTOR_HANDLE (WINAPI ID3D12DescriptorHeap::*w)(); + void (WINAPI ID3D12DescriptorHeap::*f)(D3D12_GPU_DESCRIPTOR_HANDLE *); + } conversion = { &ID3D12DescriptorHeap::GetGPUDescriptorHandleForHeapStart }; + (_heap->*conversion.f)(&handle); return handle; #endif // BX_COMPILER_MSVC } @@ -586,9 +595,12 @@ namespace bgfx { namespace d3d12 #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); + union { + D3D12_RESOURCE_DESC (STDMETHODCALLTYPE ID3D12Resource::*w)(); + void (STDMETHODCALLTYPE ID3D12Resource::*f)(D3D12_RESOURCE_DESC *); + } conversion = { &ID3D12Resource::GetDesc }; + (_resource->*conversion.f)(&desc); return desc; #endif // BX_COMPILER_MSVC }