|
@@ -48,6 +48,7 @@
|
|
|
#include <dxgi1_6.h>
|
|
|
#include <dxgidebug.h>
|
|
|
#include <d3d12sdklayers.h>
|
|
|
+#include <sdkddkver.h>
|
|
|
#endif
|
|
|
|
|
|
#include "SDL_shaders_d3d12.h"
|
|
@@ -83,6 +84,54 @@
|
|
|
#define D3D_GUID(X) &(X)
|
|
|
#endif
|
|
|
|
|
|
+/*
|
|
|
+ * Older MS Windows SDK headers declare some d3d12 functions with the wrong function prototype.
|
|
|
+ * - ID3D12Heap::GetDesc
|
|
|
+ * - ID3D12Resource::GetDesc
|
|
|
+ * - ID3D12DescriptorHeap::GetDesc
|
|
|
+ * (and 9 more)+
|
|
|
+ * This is fixed in SDKs since WDK_NTDDI_VERSION >= NTDDI_WIN10_FE (0x0A00000A)
|
|
|
+ */
|
|
|
+
|
|
|
+#if !(defined(__MINGW32__) || defined(__XBOXONE__) || defined(__XBOXSERIES__)) \
|
|
|
+ && (WDK_NTDDI_VERSION < 0x0A00000A)
|
|
|
+
|
|
|
+#define D3D_CALL_RET_ID3D12DescriptorHeap_GetCPUDescriptorHandleForHeapStart(THIS, ...) do { \
|
|
|
+ void (STDMETHODCALLTYPE * func)(ID3D12DescriptorHeap * This, D3D12_CPU_DESCRIPTOR_HANDLE * Handle) = \
|
|
|
+ (void*)(THIS)->lpVtbl->GetCPUDescriptorHandleForHeapStart; \
|
|
|
+ func((THIS), ##__VA_ARGS__); \
|
|
|
+ } while (0)
|
|
|
+
|
|
|
+#define D3D_CALL_RET_ID3D12DescriptorHeap_GetGPUDescriptorHandleForHeapStart(THIS, ...) do { \
|
|
|
+ void (STDMETHODCALLTYPE * func)(ID3D12DescriptorHeap * This, D3D12_GPU_DESCRIPTOR_HANDLE * Handle) = \
|
|
|
+ (void*)(THIS)->lpVtbl->GetGPUDescriptorHandleForHeapStart; \
|
|
|
+ func((THIS), ##__VA_ARGS__); \
|
|
|
+ } while (0)
|
|
|
+
|
|
|
+#define D3D_CALL_RET_ID3D12Resource_GetDesc(THIS, ...) do { \
|
|
|
+ void (STDMETHODCALLTYPE * func)(ID3D12Resource * This, D3D12_RESOURCE_DESC * Desc) = \
|
|
|
+ (void*)(THIS)->lpVtbl->GetDesc; \
|
|
|
+ func((THIS), ##__VA_ARGS__); \
|
|
|
+ } while (0)
|
|
|
+
|
|
|
+#else
|
|
|
+
|
|
|
+/*
|
|
|
+ * MinGW has correct function prototypes in the vtables, but defines wrong functions
|
|
|
+ * Xbox just needs these macros defined as used below (because CINTERFACE doesn't exist)
|
|
|
+ */
|
|
|
+
|
|
|
+#define D3D_CALL_RET_ID3D12DescriptorHeap_GetCPUDescriptorHandleForHeapStart(THIS, ...) \
|
|
|
+ D3D_CALL_RET(THIS, GetCPUDescriptorHandleForHeapStart, ##__VA_ARGS__);
|
|
|
+
|
|
|
+#define D3D_CALL_RET_ID3D12DescriptorHeap_GetGPUDescriptorHandleForHeapStart(THIS, ...) \
|
|
|
+ D3D_CALL_RET(THIS, GetGPUDescriptorHandleForHeapStart, ##__VA_ARGS__);
|
|
|
+
|
|
|
+#define D3D_CALL_RET_ID3D12Resource_GetDesc(THIS, ...) \
|
|
|
+ D3D_CALL_RET(THIS, GetDesc, ##__VA_ARGS__);
|
|
|
+
|
|
|
+#endif
|
|
|
+
|
|
|
/* Set up for C function definitions, even when using C++ */
|
|
|
#ifdef __cplusplus
|
|
|
extern "C" {
|
|
@@ -398,10 +447,10 @@ static D3D12_GPU_DESCRIPTOR_HANDLE D3D12_CPUtoGPUHandle(ID3D12DescriptorHeap *he
|
|
|
SIZE_T offset;
|
|
|
|
|
|
/* Calculate the correct offset into the heap */
|
|
|
- D3D_CALL_RET(heap, GetCPUDescriptorHandleForHeapStart, &CPUHeapStart);
|
|
|
+ D3D_CALL_RET_ID3D12DescriptorHeap_GetCPUDescriptorHandleForHeapStart(heap, &CPUHeapStart);
|
|
|
offset = CPUHandle.ptr - CPUHeapStart.ptr;
|
|
|
|
|
|
- D3D_CALL_RET(heap, GetGPUDescriptorHandleForHeapStart, &GPUHandle);
|
|
|
+ D3D_CALL_RET_ID3D12DescriptorHeap_GetGPUDescriptorHandleForHeapStart(heap, &GPUHandle);
|
|
|
GPUHandle.ptr += offset;
|
|
|
|
|
|
return GPUHandle;
|
|
@@ -432,7 +481,7 @@ static D3D12_CPU_DESCRIPTOR_HANDLE D3D12_GetCurrentRenderTargetView(SDL_Renderer
|
|
|
}
|
|
|
|
|
|
SDL_zero(rtvDescriptor);
|
|
|
- D3D_CALL_RET(data->rtvDescriptorHeap, GetCPUDescriptorHandleForHeapStart, &rtvDescriptor);
|
|
|
+ D3D_CALL_RET_ID3D12DescriptorHeap_GetCPUDescriptorHandleForHeapStart(data->rtvDescriptorHeap, &rtvDescriptor);
|
|
|
rtvDescriptor.ptr += data->currentBackBufferIndex * data->rtvDescriptorSize;
|
|
|
return rtvDescriptor;
|
|
|
}
|
|
@@ -1052,7 +1101,7 @@ static HRESULT D3D12_CreateDeviceResources(SDL_Renderer *renderer)
|
|
|
samplerDesc.ComparisonFunc = D3D12_COMPARISON_FUNC_ALWAYS;
|
|
|
samplerDesc.MinLOD = 0.0f;
|
|
|
samplerDesc.MaxLOD = D3D12_FLOAT32_MAX;
|
|
|
- D3D_CALL_RET(data->samplerDescriptorHeap, GetCPUDescriptorHandleForHeapStart, &data->nearestPixelSampler);
|
|
|
+ D3D_CALL_RET_ID3D12DescriptorHeap_GetCPUDescriptorHandleForHeapStart(data->samplerDescriptorHeap, &data->nearestPixelSampler);
|
|
|
D3D_CALL(data->d3dDevice, CreateSampler, &samplerDesc, data->nearestPixelSampler);
|
|
|
|
|
|
samplerDesc.Filter = D3D12_FILTER_MIN_MAG_MIP_LINEAR;
|
|
@@ -1341,7 +1390,7 @@ static HRESULT D3D12_CreateWindowSizeDependentResources(SDL_Renderer *renderer)
|
|
|
rtvDesc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE2D;
|
|
|
|
|
|
SDL_zero(rtvDescriptor);
|
|
|
- D3D_CALL_RET(data->rtvDescriptorHeap, GetCPUDescriptorHandleForHeapStart, &rtvDescriptor);
|
|
|
+ D3D_CALL_RET_ID3D12DescriptorHeap_GetCPUDescriptorHandleForHeapStart(data->rtvDescriptorHeap, &rtvDescriptor);
|
|
|
rtvDescriptor.ptr += i * data->rtvDescriptorSize;
|
|
|
D3D_CALL(data->d3dDevice, CreateRenderTargetView, data->renderTargets[i], &rtvDesc, rtvDescriptor);
|
|
|
}
|
|
@@ -1555,7 +1604,7 @@ static int D3D12_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
|
|
resourceViewDesc.Texture2D.MipLevels = textureDesc.MipLevels;
|
|
|
|
|
|
textureData->mainSRVIndex = D3D12_GetAvailableSRVIndex(renderer);
|
|
|
- D3D_CALL_RET(rendererData->srvDescriptorHeap, GetCPUDescriptorHandleForHeapStart, &textureData->mainTextureResourceView);
|
|
|
+ D3D_CALL_RET_ID3D12DescriptorHeap_GetCPUDescriptorHandleForHeapStart(rendererData->srvDescriptorHeap, &textureData->mainTextureResourceView);
|
|
|
textureData->mainTextureResourceView.ptr += textureData->mainSRVIndex * rendererData->srvDescriptorSize;
|
|
|
|
|
|
D3D_CALL(rendererData->d3dDevice, CreateShaderResourceView,
|
|
@@ -1564,7 +1613,7 @@ static int D3D12_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
|
|
textureData->mainTextureResourceView);
|
|
|
#if SDL_HAVE_YUV
|
|
|
if (textureData->yuv) {
|
|
|
- D3D_CALL_RET(rendererData->srvDescriptorHeap, GetCPUDescriptorHandleForHeapStart, &textureData->mainTextureResourceViewU);
|
|
|
+ D3D_CALL_RET_ID3D12DescriptorHeap_GetCPUDescriptorHandleForHeapStart(rendererData->srvDescriptorHeap, &textureData->mainTextureResourceViewU);
|
|
|
textureData->mainSRVIndexU = D3D12_GetAvailableSRVIndex(renderer);
|
|
|
textureData->mainTextureResourceViewU.ptr += textureData->mainSRVIndexU * rendererData->srvDescriptorSize;
|
|
|
D3D_CALL(rendererData->d3dDevice, CreateShaderResourceView,
|
|
@@ -1572,7 +1621,7 @@ static int D3D12_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
|
|
&resourceViewDesc,
|
|
|
textureData->mainTextureResourceViewU);
|
|
|
|
|
|
- D3D_CALL_RET(rendererData->srvDescriptorHeap, GetCPUDescriptorHandleForHeapStart, &textureData->mainTextureResourceViewV);
|
|
|
+ D3D_CALL_RET_ID3D12DescriptorHeap_GetCPUDescriptorHandleForHeapStart(rendererData->srvDescriptorHeap, &textureData->mainTextureResourceViewV);
|
|
|
textureData->mainSRVIndexV = D3D12_GetAvailableSRVIndex(renderer);
|
|
|
textureData->mainTextureResourceViewV.ptr += textureData->mainSRVIndexV * rendererData->srvDescriptorSize;
|
|
|
D3D_CALL(rendererData->d3dDevice, CreateShaderResourceView,
|
|
@@ -1586,7 +1635,7 @@ static int D3D12_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
|
|
|
|
|
nvResourceViewDesc.Format = DXGI_FORMAT_R8G8_UNORM;
|
|
|
|
|
|
- D3D_CALL_RET(rendererData->srvDescriptorHeap, GetCPUDescriptorHandleForHeapStart, &textureData->mainTextureResourceViewNV);
|
|
|
+ D3D_CALL_RET_ID3D12DescriptorHeap_GetCPUDescriptorHandleForHeapStart(rendererData->srvDescriptorHeap, &textureData->mainTextureResourceViewNV);
|
|
|
textureData->mainSRVIndexNV = D3D12_GetAvailableSRVIndex(renderer);
|
|
|
textureData->mainTextureResourceViewNV.ptr += textureData->mainSRVIndexNV * rendererData->srvDescriptorSize;
|
|
|
D3D_CALL(rendererData->d3dDevice, CreateShaderResourceView,
|
|
@@ -1603,7 +1652,7 @@ static int D3D12_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
|
|
renderTargetViewDesc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE2D;
|
|
|
renderTargetViewDesc.Texture2D.MipSlice = 0;
|
|
|
|
|
|
- D3D_CALL_RET(rendererData->textureRTVDescriptorHeap, GetCPUDescriptorHandleForHeapStart, &textureData->mainTextureRenderTargetView);
|
|
|
+ D3D_CALL_RET_ID3D12DescriptorHeap_GetCPUDescriptorHandleForHeapStart(rendererData->textureRTVDescriptorHeap, &textureData->mainTextureRenderTargetView);
|
|
|
textureData->mainTextureRenderTargetView.ptr += textureData->mainSRVIndex * rendererData->rtvDescriptorSize;
|
|
|
|
|
|
D3D_CALL(rendererData->d3dDevice, CreateRenderTargetView,
|
|
@@ -1668,7 +1717,7 @@ static int D3D12_UpdateTextureInternal(D3D12_RenderData *rendererData, ID3D12Res
|
|
|
|
|
|
/* Create an upload buffer, which will be used to write to the main texture. */
|
|
|
SDL_zero(textureDesc);
|
|
|
- D3D_CALL_RET(texture, GetDesc, &textureDesc);
|
|
|
+ D3D_CALL_RET_ID3D12Resource_GetDesc(texture, &textureDesc);
|
|
|
textureDesc.Width = w;
|
|
|
textureDesc.Height = h;
|
|
|
|
|
@@ -1924,7 +1973,7 @@ static int D3D12_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture,
|
|
|
|
|
|
/* Create an upload buffer, which will be used to write to the main texture. */
|
|
|
SDL_zero(textureDesc);
|
|
|
- D3D_CALL_RET(textureData->mainTexture, GetDesc, &textureDesc);
|
|
|
+ D3D_CALL_RET_ID3D12Resource_GetDesc(textureData->mainTexture, &textureDesc);
|
|
|
textureDesc.Width = rect->w;
|
|
|
textureDesc.Height = rect->h;
|
|
|
|
|
@@ -2033,7 +2082,7 @@ static void D3D12_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
|
|
D3D_CALL(textureData->stagingBuffer, Unmap, 0, NULL);
|
|
|
|
|
|
SDL_zero(textureDesc);
|
|
|
- D3D_CALL_RET(textureData->mainTexture, GetDesc, &textureDesc);
|
|
|
+ D3D_CALL_RET_ID3D12Resource_GetDesc(textureData->mainTexture, &textureDesc);
|
|
|
textureDesc.Width = textureData->lockedRect.w;
|
|
|
textureDesc.Height = textureData->lockedRect.h;
|
|
|
|
|
@@ -2744,7 +2793,7 @@ static int D3D12_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *rect,
|
|
|
|
|
|
/* Create a staging texture to copy the screen's data to: */
|
|
|
SDL_zero(textureDesc);
|
|
|
- D3D_CALL_RET(backBuffer, GetDesc, &textureDesc);
|
|
|
+ D3D_CALL_RET_ID3D12Resource_GetDesc(backBuffer, &textureDesc);
|
|
|
textureDesc.Width = rect->w;
|
|
|
textureDesc.Height = rect->h;
|
|
|
|