Fixed uniform offsets, removed a bunch of code from cdefines.h

d3d11
Caleb Cornett 2023-11-05 19:20:37 -06:00 committed by cosmonaut
parent eb956a2f8b
commit a3c8ab6a55
2 changed files with 59 additions and 199 deletions

View File

@ -30,7 +30,9 @@
#define CINTERFACE
#define COBJMACROS
#include <d3d11.h>
#include <d3d11_1.h>
#include <dxgi.h>
#include <dxgi1_6.h>
#include <d3dcompiler.h>
#include "Refresh_Driver.h"
@ -429,7 +431,7 @@ typedef struct D3D11UniformBuffer
typedef struct D3D11CommandBuffer
{
/* D3D11 Object References */
ID3D11DeviceContext *context;
ID3D11DeviceContext1 *context;
D3D11SwapchainData *swapchainData;
/* Render Pass */
@ -457,7 +459,7 @@ typedef struct D3D11Sampler
typedef struct D3D11Renderer
{
ID3D11Device *device;
ID3D11Device1 *device;
ID3D11DeviceContext *immediateContext;
IDXGIFactory1 *factory;
IDXGIAdapter1 *adapter;
@ -493,7 +495,7 @@ typedef struct D3D11Renderer
/* Logging */
static void D3D11_INTERNAL_LogError(
ID3D11Device *device,
ID3D11Device1 *device,
const char *msg,
HRESULT res
) {
@ -631,24 +633,32 @@ static void D3D11_DrawInstancedPrimitives(
uint32_t fragmentParamOffset
) {
D3D11CommandBuffer *d3d11CommandBuffer = (D3D11CommandBuffer*) commandBuffer;
uint32_t vertexOffsetInConstants = vertexParamOffset / 16;
uint32_t fragmentOffsetInConstants = fragmentParamOffset / 16;
uint32_t vertexBlockSizeInConstants = d3d11CommandBuffer->graphicsPipeline->vertexUniformBlockSize / 16;
uint32_t fragmentBlockSizeInConstants = d3d11CommandBuffer->graphicsPipeline->fragmentUniformBlockSize / 16;
if (d3d11CommandBuffer->vertexUniformBuffer != NULL)
{
ID3D11DeviceContext_VSSetConstantBuffers(
ID3D11DeviceContext1_VSSetConstantBuffers1(
d3d11CommandBuffer->context,
0,
1,
&d3d11CommandBuffer->vertexUniformBuffer->d3d11Buffer->handle
&d3d11CommandBuffer->vertexUniformBuffer->d3d11Buffer->handle,
&vertexOffsetInConstants,
&vertexBlockSizeInConstants
);
}
if (d3d11CommandBuffer->fragmentUniformBuffer != NULL)
{
ID3D11DeviceContext_PSSetConstantBuffers(
ID3D11DeviceContext1_PSSetConstantBuffers1(
d3d11CommandBuffer->context,
0,
1,
&d3d11CommandBuffer->fragmentUniformBuffer->d3d11Buffer->handle
&d3d11CommandBuffer->fragmentUniformBuffer->d3d11Buffer->handle,
&fragmentOffsetInConstants,
&fragmentBlockSizeInConstants
);
}
@ -660,8 +670,6 @@ static void D3D11_DrawInstancedPrimitives(
baseVertex,
0
);
/* FIXME: vertex/fragment param offsets */
}
static void D3D11_DrawIndexedPrimitives(
@ -694,24 +702,32 @@ static void D3D11_DrawPrimitives(
uint32_t fragmentParamOffset
) {
D3D11CommandBuffer *d3d11CommandBuffer = (D3D11CommandBuffer*) commandBuffer;
uint32_t vertexOffsetInConstants = vertexParamOffset / 16;
uint32_t fragmentOffsetInConstants = fragmentParamOffset / 16;
uint32_t vertexBlockSizeInConstants = d3d11CommandBuffer->graphicsPipeline->vertexUniformBlockSize / 16;
uint32_t fragmentBlockSizeInConstants = d3d11CommandBuffer->graphicsPipeline->fragmentUniformBlockSize / 16;
if (d3d11CommandBuffer->vertexUniformBuffer != NULL)
{
ID3D11DeviceContext_VSSetConstantBuffers(
ID3D11DeviceContext1_VSSetConstantBuffers1(
d3d11CommandBuffer->context,
0,
1,
&d3d11CommandBuffer->vertexUniformBuffer->d3d11Buffer->handle
&d3d11CommandBuffer->vertexUniformBuffer->d3d11Buffer->handle,
&vertexOffsetInConstants,
&vertexBlockSizeInConstants
);
}
if (d3d11CommandBuffer->fragmentUniformBuffer != NULL)
{
ID3D11DeviceContext_PSSetConstantBuffers(
ID3D11DeviceContext1_PSSetConstantBuffers1(
d3d11CommandBuffer->context,
0,
1,
&d3d11CommandBuffer->fragmentUniformBuffer->d3d11Buffer->handle
&d3d11CommandBuffer->fragmentUniformBuffer->d3d11Buffer->handle,
&fragmentOffsetInConstants,
&fragmentBlockSizeInConstants
);
}
@ -975,6 +991,13 @@ static Refresh_ComputePipeline* D3D11_CreateComputePipeline(
return NULL;
}
static inline uint32_t D3D11_INTERNAL_NextHighestAlignment(
uint32_t n,
uint32_t align
) {
return align * ((n + align - 1) / align);
}
static Refresh_GraphicsPipeline* D3D11_CreateGraphicsPipeline(
Refresh_Renderer *driverData,
Refresh_GraphicsPipelineCreateInfo *pipelineCreateInfo
@ -1068,7 +1091,10 @@ static Refresh_GraphicsPipeline* D3D11_CreateGraphicsPipeline(
}
pipeline->vertexShader = (ID3D11VertexShader*) vertShaderModule->shader;
pipeline->numVertexSamplers = pipelineCreateInfo->vertexShaderInfo.samplerBindingCount;
pipeline->vertexUniformBlockSize = (uint32_t) pipelineCreateInfo->vertexShaderInfo.uniformBufferSize;
pipeline->vertexUniformBlockSize = D3D11_INTERNAL_NextHighestAlignment(
(uint32_t) pipelineCreateInfo->vertexShaderInfo.uniformBufferSize,
256
);
/* Input Layout */
@ -1131,7 +1157,10 @@ static Refresh_GraphicsPipeline* D3D11_CreateGraphicsPipeline(
}
pipeline->fragmentShader = (ID3D11PixelShader*) fragShaderModule->shader;
pipeline->numFragmentSamplers = pipelineCreateInfo->fragmentShaderInfo.samplerBindingCount;
pipeline->fragmentUniformBlockSize = (uint32_t) pipelineCreateInfo->fragmentShaderInfo.uniformBufferSize;
pipeline->fragmentUniformBlockSize = D3D11_INTERNAL_NextHighestAlignment(
(uint32_t) pipelineCreateInfo->vertexShaderInfo.uniformBufferSize,
256
);
return (Refresh_GraphicsPipeline*) pipeline;
}
@ -1681,7 +1710,7 @@ static uint32_t D3D11_PushVertexShaderUniforms(
d3d11CommandBuffer->vertexUniformBuffer->offset,
data,
dataLengthInBytes,
0
0 /* FIXME: Should be NoOverwrite! */
);
d3d11CommandBuffer->vertexUniformBuffer->offset += graphicsPipeline->vertexUniformBlockSize;
@ -1722,7 +1751,7 @@ static uint32_t D3D11_PushFragmentShaderUniforms(
d3d11CommandBuffer->fragmentUniformBuffer->offset,
data,
dataLengthInBytes,
0
0 /* FIXME: Should be NoOverwrite! */
);
d3d11CommandBuffer->fragmentUniformBuffer->offset += graphicsPipeline->fragmentUniformBlockSize;
@ -1893,7 +1922,7 @@ static void D3D11_INTERNAL_AllocateCommandBuffers(
commandBuffer = SDL_malloc(sizeof(D3D11CommandBuffer));
/* Deferred Device Context */
res = ID3D11Device_CreateDeferredContext(
res = ID3D11Device1_CreateDeferredContext1(
renderer->device,
0,
&commandBuffer->context
@ -1958,6 +1987,7 @@ static Refresh_CommandBuffer* D3D11_AcquireCommandBuffer(
commandBuffer->swapchainData = NULL;
commandBuffer->graphicsPipeline = NULL;
commandBuffer->vertexUniformBuffer = NULL;
commandBuffer->fragmentUniformBuffer = NULL;
commandBuffer->dsView = NULL;
for (i = 0; i < MAX_COLOR_TARGET_BINDINGS; i += 1)
{
@ -3122,6 +3152,7 @@ static Refresh_Device* D3D11_CreateDevice(
}
/* Create the device */
ID3D11Device *d3d11Device;
tryCreateDevice:
res = D3D11CreateDeviceFunc(
(IDXGIAdapter*) renderer->adapter,
@ -3131,7 +3162,7 @@ tryCreateDevice:
levels,
SDL_arraysize(levels),
D3D11_SDK_VERSION,
&renderer->device,
&d3d11Device,
&renderer->featureLevel,
&renderer->immediateContext
);
@ -3146,6 +3177,14 @@ tryCreateDevice:
ERROR_CHECK_RETURN("Could not create D3D11 device", NULL);
/* The actual device we want is the ID3D11Device1 interface... */
res = ID3D11Device_QueryInterface(
d3d11Device,
&D3D_IID_ID3D11Device1,
&renderer->device
);
ERROR_CHECK_RETURN("Could not get ID3D11Device1 interface", NULL);
/* Print driver info */
Refresh_LogInfo("Refresh Driver: D3D11");
Refresh_LogInfo("D3D11 Adapter: %S", adapterDesc.Description);

View File

@ -33,183 +33,4 @@ static const IID D3D_IID_IDXGIFactory1 = { 0x770aae78,0xf26f,0x4dba,{0xa8,0x29,0
static const IID D3D_IID_IDXGIFactory6 = { 0xc1b6694f,0xff09,0x44a9,{0xb0,0x3c,0x77,0x90,0x0a,0x0a,0x1d,0x17} };
static const IID D3D_IID_IDXGIAdapter1 = { 0x29038f61,0x3839,0x4626,{0x91,0xfd,0x08,0x68,0x79,0x01,0x1a,0x05} };
static const IID D3D_IID_ID3D11Texture2D = { 0x6f15aaf2,0xd208,0x4e89,{0x9a,0xb4,0x48,0x95,0x35,0xd3,0x4f,0x9c} };
/* IDXGIFactory6 (taken from dxgi1_6.h, cleaned up a bit) */
typedef enum
{
DXGI_FEATURE_PRESENT_ALLOW_TEARING = 0
} DXGI_FEATURE;
typedef enum
{
DXGI_GPU_PREFERENCE_UNSPECIFIED = 0,
DXGI_GPU_PREFERENCE_MINIMUM_POWER = (DXGI_GPU_PREFERENCE_UNSPECIFIED + 1),
DXGI_GPU_PREFERENCE_HIGH_PERFORMANCE = (DXGI_GPU_PREFERENCE_MINIMUM_POWER + 1)
} DXGI_GPU_PREFERENCE;
typedef struct IDXGIFactory6 IDXGIFactory6;
typedef struct IDXGIFactory6Vtbl
{
HRESULT(STDMETHODCALLTYPE* QueryInterface)(
IDXGIFactory6* This,
REFIID riid,
void** ppvObject);
ULONG(STDMETHODCALLTYPE* AddRef)(
IDXGIFactory6* This);
ULONG(STDMETHODCALLTYPE* Release)(
IDXGIFactory6* This);
HRESULT(STDMETHODCALLTYPE* SetPrivateData)(
IDXGIFactory6* This,
REFGUID Name,
UINT DataSize,
const void* pData);
HRESULT(STDMETHODCALLTYPE* SetPrivateDataInterface)(
IDXGIFactory6* This,
REFGUID Name,
const IUnknown* pUnknown);
HRESULT(STDMETHODCALLTYPE* GetPrivateData)(
IDXGIFactory6* This,
REFGUID Name,
UINT* pDataSize,
void* pData);
HRESULT(STDMETHODCALLTYPE* GetParent)(
IDXGIFactory6* This,
REFIID riid,
void** ppParent);
HRESULT(STDMETHODCALLTYPE* EnumAdapters)(
IDXGIFactory6* This,
UINT Adapter,
IDXGIAdapter** ppAdapter);
HRESULT(STDMETHODCALLTYPE* MakeWindowAssociation)(
IDXGIFactory6* This,
HWND WindowHandle,
UINT Flags);
HRESULT(STDMETHODCALLTYPE* GetWindowAssociation)(
IDXGIFactory6* This,
HWND* pWindowHandle);
HRESULT(STDMETHODCALLTYPE* CreateSwapChain)(
IDXGIFactory6* This,
IUnknown* pDevice,
DXGI_SWAP_CHAIN_DESC* pDesc,
IDXGISwapChain** ppSwapChain);
HRESULT(STDMETHODCALLTYPE* CreateSoftwareAdapter)(
IDXGIFactory6* This,
HMODULE Module,
IDXGIAdapter** ppAdapter);
HRESULT(STDMETHODCALLTYPE* EnumAdapters1)(
IDXGIFactory6* This,
UINT Adapter,
IDXGIAdapter1** ppAdapter);
BOOL(STDMETHODCALLTYPE* IsCurrent)(
IDXGIFactory6* This);
BOOL(STDMETHODCALLTYPE* IsWindowedStereoEnabled)(
IDXGIFactory6* This);
HRESULT(STDMETHODCALLTYPE* CreateSwapChainForHwnd)(
IDXGIFactory6* This,
IUnknown* pDevice,
HWND hWnd,
void* pDesc,
void* pFullscreenDesc,
void* pRestrictToOutput,
void** ppSwapChain);
HRESULT(STDMETHODCALLTYPE* CreateSwapChainForCoreWindow)(
IDXGIFactory6* This,
IUnknown* pDevice,
IUnknown* pWindow,
void* pDesc,
void* pRestrictToOutput,
void** ppSwapChain);
HRESULT(STDMETHODCALLTYPE* GetSharedResourceAdapterLuid)(
IDXGIFactory6* This,
HANDLE hResource,
LUID* pLuid);
HRESULT(STDMETHODCALLTYPE* RegisterStereoStatusWindow)(
IDXGIFactory6* This,
HWND WindowHandle,
UINT wMsg,
DWORD* pdwCookie);
HRESULT(STDMETHODCALLTYPE* RegisterStereoStatusEvent)(
IDXGIFactory6* This,
HANDLE hEvent,
DWORD* pdwCookie);
void (STDMETHODCALLTYPE* UnregisterStereoStatus)(
IDXGIFactory6* This,
DWORD dwCookie);
HRESULT(STDMETHODCALLTYPE* RegisterOcclusionStatusWindow)(
IDXGIFactory6* This,
HWND WindowHandle,
UINT wMsg,
DWORD* pdwCookie);
HRESULT(STDMETHODCALLTYPE* RegisterOcclusionStatusEvent)(
IDXGIFactory6* This,
HANDLE hEvent,
DWORD* pdwCookie);
void (STDMETHODCALLTYPE* UnregisterOcclusionStatus)(
IDXGIFactory6* This,
DWORD dwCookie);
HRESULT(STDMETHODCALLTYPE* CreateSwapChainForComposition)(
IDXGIFactory6* This,
IUnknown* pDevice,
void* pDesc,
void* pRestrictToOutput,
void** ppSwapChain);
UINT(STDMETHODCALLTYPE* GetCreationFlags)(
IDXGIFactory6* This);
HRESULT(STDMETHODCALLTYPE* EnumAdapterByLuid)(
IDXGIFactory6* This,
LUID AdapterLuid,
REFIID riid,
void** ppvAdapter);
HRESULT(STDMETHODCALLTYPE* EnumWarpAdapter)(
IDXGIFactory6* This,
REFIID riid,
void** ppvAdapter);
HRESULT(STDMETHODCALLTYPE* CheckFeatureSupport)(
IDXGIFactory6* This,
DXGI_FEATURE Feature,
void* pFeatureSupportData,
UINT FeatureSupportDataSize);
HRESULT(STDMETHODCALLTYPE* EnumAdapterByGpuPreference)(
IDXGIFactory6* This,
UINT Adapter,
DXGI_GPU_PREFERENCE GpuPreference,
REFIID riid,
void** ppvAdapter);
} IDXGIFactory6Vtbl;
struct IDXGIFactory6
{
struct IDXGIFactory6Vtbl* lpVtbl;
};
#define IDXGIFactory6_EnumAdapterByGpuPreference(This,Adapter,GpuPreference,riid,ppvAdapter) \
( (This)->lpVtbl -> EnumAdapterByGpuPreference(This,Adapter,GpuPreference,riid,ppvAdapter) )
static const IID D3D_IID_ID3D11Device1 = { 0xa04bfb29,0x08ef,0x43d6,{0xa4,0x9c,0xa9,0xbd,0xbd,0xcb,0xe6,0x86} };