forked from MoonsideGames/Refresh
Compare commits
2 Commits
55eb8375df
...
63edebef6d
Author | SHA1 | Date |
---|---|---|
Caleb Cornett | 63edebef6d | |
Caleb Cornett | 764b710cc9 |
|
@ -988,7 +988,6 @@ REFRESHAPI void Refresh_QueueDestroyGraphicsPipeline(
|
||||||
* The area affected by the render pass.
|
* The area affected by the render pass.
|
||||||
* All load, store and resolve operations are restricted
|
* All load, store and resolve operations are restricted
|
||||||
* to the given rectangle.
|
* to the given rectangle.
|
||||||
* If NULL, a sensible default will be chosen.
|
|
||||||
* colorAttachmentInfos:
|
* colorAttachmentInfos:
|
||||||
* A pointer to an array of Refresh_ColorAttachmentInfo structures
|
* A pointer to an array of Refresh_ColorAttachmentInfo structures
|
||||||
* that contains render targets and clear values. May be NULL.
|
* that contains render targets and clear values. May be NULL.
|
||||||
|
|
|
@ -36,17 +36,9 @@
|
||||||
#include "Refresh_Driver_D3D11_cdefines.h"
|
#include "Refresh_Driver_D3D11_cdefines.h"
|
||||||
|
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
#include <SDL_syswm.h>
|
|
||||||
|
|
||||||
/* Defines */
|
|
||||||
|
|
||||||
#define D3D11_DLL "d3d11.dll"
|
#define D3D11_DLL "d3d11.dll"
|
||||||
#define DXGI_DLL "dxgi.dll"
|
#define DXGI_DLL "dxgi.dll"
|
||||||
#define WINDOW_SWAPCHAIN_DATA "Refresh_D3D11Swapchain"
|
|
||||||
|
|
||||||
#define NOT_IMPLEMENTED SDL_assert(0 && "Not implemented!");
|
|
||||||
|
|
||||||
/* Macros */
|
|
||||||
|
|
||||||
#define ERROR_CHECK(msg) \
|
#define ERROR_CHECK(msg) \
|
||||||
if (FAILED(res)) \
|
if (FAILED(res)) \
|
||||||
|
@ -86,7 +78,9 @@
|
||||||
); \
|
); \
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Conversions */
|
#define NOT_IMPLEMENTED SDL_assert(0 && "Not implemented!");
|
||||||
|
|
||||||
|
/* Conversions */
|
||||||
|
|
||||||
static DXGI_FORMAT RefreshToD3D11_SurfaceFormat[] =
|
static DXGI_FORMAT RefreshToD3D11_SurfaceFormat[] =
|
||||||
{
|
{
|
||||||
|
@ -241,26 +235,13 @@ static D3D11_TEXTURE_ADDRESS_MODE RefreshToD3D11_SamplerAddressMode[] =
|
||||||
|
|
||||||
/* Structs */
|
/* Structs */
|
||||||
|
|
||||||
typedef struct D3D11Texture
|
|
||||||
{
|
|
||||||
ID3D11RenderTargetView *rtv;
|
|
||||||
} D3D11Texture;
|
|
||||||
|
|
||||||
typedef struct D3D11SwapchainData
|
|
||||||
{
|
|
||||||
IDXGISwapChain* swapchain;
|
|
||||||
D3D11Texture refreshTexture;
|
|
||||||
void* windowHandle;
|
|
||||||
} D3D11SwapchainData;
|
|
||||||
|
|
||||||
typedef struct D3D11CommandBuffer
|
typedef struct D3D11CommandBuffer
|
||||||
{
|
{
|
||||||
ID3D11DeviceContext *context;
|
ID3D11DeviceContext *context;
|
||||||
ID3D11CommandList *commandList;
|
|
||||||
D3D11SwapchainData *swapchainData;
|
|
||||||
SDL_threadID threadID;
|
SDL_threadID threadID;
|
||||||
uint8_t recording;
|
uint8_t recording;
|
||||||
uint8_t fixed;
|
uint8_t fixed;
|
||||||
|
ID3D11CommandList *commandList;
|
||||||
} D3D11CommandBuffer;
|
} D3D11CommandBuffer;
|
||||||
|
|
||||||
typedef struct D3D11CommandBufferPool
|
typedef struct D3D11CommandBufferPool
|
||||||
|
@ -272,6 +253,7 @@ typedef struct D3D11CommandBufferPool
|
||||||
|
|
||||||
typedef struct D3D11Renderer
|
typedef struct D3D11Renderer
|
||||||
{
|
{
|
||||||
|
/* Persistent D3D11 Objects*/
|
||||||
ID3D11Device *device;
|
ID3D11Device *device;
|
||||||
ID3D11DeviceContext *immediateContext;
|
ID3D11DeviceContext *immediateContext;
|
||||||
IDXGIFactory1 *factory;
|
IDXGIFactory1 *factory;
|
||||||
|
@ -279,22 +261,18 @@ typedef struct D3D11Renderer
|
||||||
void *d3d11_dll;
|
void *d3d11_dll;
|
||||||
void *dxgi_dll;
|
void *dxgi_dll;
|
||||||
|
|
||||||
|
/* Deferred Contexts */
|
||||||
D3D11CommandBufferPool *commandBufferPool;
|
D3D11CommandBufferPool *commandBufferPool;
|
||||||
|
|
||||||
D3D11SwapchainData** swapchainDatas;
|
/* Blend State */
|
||||||
uint32_t swapchainDataCount;
|
|
||||||
uint32_t swapchainDataCapacity;
|
|
||||||
|
|
||||||
Refresh_Vec4 blendFactor;
|
Refresh_Vec4 blendFactor;
|
||||||
|
|
||||||
|
/* Capabilities */
|
||||||
uint8_t debugMode;
|
uint8_t debugMode;
|
||||||
D3D_FEATURE_LEVEL featureLevel;
|
D3D_FEATURE_LEVEL featureLevel;
|
||||||
|
|
||||||
} D3D11Renderer;
|
} D3D11Renderer;
|
||||||
|
|
||||||
/* Predeclarations */
|
|
||||||
|
|
||||||
static void D3D11_Wait(Refresh_Renderer* driverData);
|
|
||||||
|
|
||||||
/* Logging */
|
/* Logging */
|
||||||
|
|
||||||
static void D3D11_INTERNAL_LogError(
|
static void D3D11_INTERNAL_LogError(
|
||||||
|
@ -353,187 +331,6 @@ static void D3D11_INTERNAL_LogError(
|
||||||
Refresh_LogError("%s! Error Code: %s (0x%08X)", msg, wszMsgBuff, res);
|
Refresh_LogError("%s! Error Code: %s (0x%08X)", msg, wszMsgBuff, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Swapchain Management */
|
|
||||||
|
|
||||||
static uint8_t D3D11_INTERNAL_CreateSwapchain(
|
|
||||||
D3D11Renderer *renderer,
|
|
||||||
void *windowHandle
|
|
||||||
) {
|
|
||||||
IDXGIFactory1 *pParent;
|
|
||||||
DXGI_MODE_DESC swapchainBufferDesc;
|
|
||||||
DXGI_SWAP_CHAIN_DESC swapchainDesc;
|
|
||||||
IDXGISwapChain *swapchain;
|
|
||||||
D3D11SwapchainData *swapchainData;
|
|
||||||
SDL_SysWMinfo info;
|
|
||||||
HWND dxgiHandle;
|
|
||||||
ID3D11Texture2D *swapchainTexture;
|
|
||||||
D3D11_RENDER_TARGET_VIEW_DESC swapchainViewDesc;
|
|
||||||
HRESULT res;
|
|
||||||
|
|
||||||
SDL_VERSION(&info.version);
|
|
||||||
SDL_GetWindowWMInfo((SDL_Window*) windowHandle, &info);
|
|
||||||
dxgiHandle = info.info.win.window;
|
|
||||||
|
|
||||||
/* Initialize swapchain buffer descriptor */
|
|
||||||
swapchainBufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
|
||||||
swapchainBufferDesc.Width = 0;
|
|
||||||
swapchainBufferDesc.Height = 0;
|
|
||||||
swapchainBufferDesc.RefreshRate.Numerator = 0;
|
|
||||||
swapchainBufferDesc.RefreshRate.Denominator = 0;
|
|
||||||
swapchainBufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
|
|
||||||
swapchainBufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
|
|
||||||
|
|
||||||
/* Initialize the swapchain descriptor */
|
|
||||||
swapchainDesc.BufferDesc = swapchainBufferDesc;
|
|
||||||
swapchainDesc.BufferCount = 3;
|
|
||||||
swapchainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
|
|
||||||
swapchainDesc.OutputWindow = dxgiHandle;
|
|
||||||
swapchainDesc.Flags = 0;
|
|
||||||
swapchainDesc.SampleDesc.Count = 1;
|
|
||||||
swapchainDesc.SampleDesc.Quality = 0;
|
|
||||||
swapchainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
|
|
||||||
swapchainDesc.Windowed = 1;
|
|
||||||
|
|
||||||
/* Create the swapchain! */
|
|
||||||
res = IDXGIFactory1_CreateSwapChain(
|
|
||||||
renderer->factory,
|
|
||||||
(IUnknown*) renderer->device,
|
|
||||||
&swapchainDesc,
|
|
||||||
&swapchain
|
|
||||||
);
|
|
||||||
ERROR_CHECK_RETURN("Could not create swap chain", 0);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* The swapchain's parent is a separate factory from the factory that
|
|
||||||
* we used to create the swapchain, and only that parent can be used to
|
|
||||||
* set the window association. Trying to set an association on our factory
|
|
||||||
* will silently fail and doesn't even verify arguments or return errors.
|
|
||||||
* See https://gamedev.net/forums/topic/634235-dxgidisabling-altenter/4999955/
|
|
||||||
*/
|
|
||||||
res = IDXGISwapChain_GetParent(
|
|
||||||
swapchain,
|
|
||||||
&D3D_IID_IDXGIFactory1,
|
|
||||||
(void**) &pParent
|
|
||||||
);
|
|
||||||
if (FAILED(res))
|
|
||||||
{
|
|
||||||
Refresh_LogWarn(
|
|
||||||
"Could not get swapchain parent! Error Code: %08X",
|
|
||||||
res
|
|
||||||
);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Disable DXGI window crap */
|
|
||||||
res = IDXGIFactory1_MakeWindowAssociation(
|
|
||||||
pParent,
|
|
||||||
dxgiHandle,
|
|
||||||
DXGI_MWA_NO_WINDOW_CHANGES
|
|
||||||
);
|
|
||||||
if (FAILED(res))
|
|
||||||
{
|
|
||||||
Refresh_LogWarn(
|
|
||||||
"MakeWindowAssociation failed! Error Code: %08X",
|
|
||||||
res
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Set up the swapchain data */
|
|
||||||
swapchainData = (D3D11SwapchainData*) SDL_malloc(sizeof(D3D11SwapchainData));
|
|
||||||
swapchainData->swapchain = swapchain;
|
|
||||||
swapchainData->windowHandle = windowHandle;
|
|
||||||
swapchainData->refreshTexture.rtv = NULL;
|
|
||||||
SDL_SetWindowData((SDL_Window*) windowHandle, WINDOW_SWAPCHAIN_DATA, swapchainData);
|
|
||||||
if (renderer->swapchainDataCount >= renderer->swapchainDataCapacity)
|
|
||||||
{
|
|
||||||
renderer->swapchainDataCapacity *= 2;
|
|
||||||
renderer->swapchainDatas = SDL_realloc(
|
|
||||||
renderer->swapchainDatas,
|
|
||||||
renderer->swapchainDataCapacity * sizeof(D3D11SwapchainData*)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
renderer->swapchainDatas[renderer->swapchainDataCount] = swapchainData;
|
|
||||||
renderer->swapchainDataCount += 1;
|
|
||||||
|
|
||||||
/* Create the RTV for the swapchain */
|
|
||||||
swapchainViewDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
|
||||||
swapchainViewDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
|
|
||||||
swapchainViewDesc.Texture2D.MipSlice = 0;
|
|
||||||
|
|
||||||
res = IDXGISwapChain_GetBuffer(
|
|
||||||
swapchainData->swapchain,
|
|
||||||
0,
|
|
||||||
&D3D_IID_ID3D11Texture2D,
|
|
||||||
(void**) &swapchainTexture
|
|
||||||
);
|
|
||||||
ERROR_CHECK_RETURN("Could not get buffer from swapchain", 0);
|
|
||||||
|
|
||||||
res = ID3D11Device_CreateRenderTargetView(
|
|
||||||
renderer->device,
|
|
||||||
(ID3D11Resource*) swapchainTexture,
|
|
||||||
&swapchainViewDesc,
|
|
||||||
&swapchainData->refreshTexture.rtv
|
|
||||||
);
|
|
||||||
ERROR_CHECK_RETURN("Swapchain RT view creation failed", 0);
|
|
||||||
|
|
||||||
/* Cleanup */
|
|
||||||
ID3D11Texture2D_Release(swapchainTexture);
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static uint8_t D3D11_INTERNAL_ResizeSwapchain(
|
|
||||||
D3D11Renderer *renderer,
|
|
||||||
D3D11SwapchainData *swapchainData
|
|
||||||
) {
|
|
||||||
ID3D11Texture2D *swapchainTexture;
|
|
||||||
D3D11_RENDER_TARGET_VIEW_DESC swapchainViewDesc;
|
|
||||||
int w, h;
|
|
||||||
HRESULT res;
|
|
||||||
|
|
||||||
/* Release the old RTV */
|
|
||||||
ID3D11RenderTargetView_Release(swapchainData->refreshTexture.rtv);
|
|
||||||
|
|
||||||
/* Resize the swapchain */
|
|
||||||
SDL_GetWindowSize((SDL_Window*) swapchainData->windowHandle, &w, &h);
|
|
||||||
res = IDXGISwapChain_ResizeBuffers(
|
|
||||||
swapchainData->swapchain,
|
|
||||||
0, /* Keep buffer count the same */
|
|
||||||
w,
|
|
||||||
h,
|
|
||||||
DXGI_FORMAT_UNKNOWN, /* Keep the old format */
|
|
||||||
0
|
|
||||||
);
|
|
||||||
ERROR_CHECK_RETURN("Could not resize swapchain buffers", 0);
|
|
||||||
|
|
||||||
/* Recreate the RTV using the new swapchain buffer */
|
|
||||||
swapchainViewDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
|
||||||
swapchainViewDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
|
|
||||||
swapchainViewDesc.Texture2D.MipSlice = 0;
|
|
||||||
|
|
||||||
res = IDXGISwapChain_GetBuffer(
|
|
||||||
swapchainData->swapchain,
|
|
||||||
0,
|
|
||||||
&D3D_IID_ID3D11Texture2D,
|
|
||||||
&swapchainTexture
|
|
||||||
);
|
|
||||||
ERROR_CHECK_RETURN("Could not get buffer from swapchain", 0);
|
|
||||||
|
|
||||||
res = ID3D11Device_CreateRenderTargetView(
|
|
||||||
renderer->device,
|
|
||||||
(ID3D11Resource*) swapchainTexture,
|
|
||||||
&swapchainViewDesc,
|
|
||||||
&swapchainData->refreshTexture.rtv
|
|
||||||
);
|
|
||||||
ERROR_CHECK_RETURN("Could not create render target view for swapchain", 0);
|
|
||||||
|
|
||||||
/* Cleanup */
|
|
||||||
ID3D11Texture2D_Release(swapchainTexture);
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Quit */
|
/* Quit */
|
||||||
|
|
||||||
static void D3D11_DestroyDevice(
|
static void D3D11_DestroyDevice(
|
||||||
|
@ -557,15 +354,6 @@ static void D3D11_DestroyDevice(
|
||||||
SDL_free(renderer->commandBufferPool->elements);
|
SDL_free(renderer->commandBufferPool->elements);
|
||||||
SDL_free(renderer->commandBufferPool);
|
SDL_free(renderer->commandBufferPool);
|
||||||
|
|
||||||
/* Release swapchain */
|
|
||||||
for (i = 0; i < renderer->swapchainDataCount; i += 1)
|
|
||||||
{
|
|
||||||
ID3D11RenderTargetView_Release(renderer->swapchainDatas[i]->refreshTexture.rtv);
|
|
||||||
IDXGISwapChain_Release(renderer->swapchainDatas[i]->swapchain);
|
|
||||||
SDL_free(renderer->swapchainDatas[i]);
|
|
||||||
}
|
|
||||||
SDL_free(renderer->swapchainDatas);
|
|
||||||
|
|
||||||
/* Release persistent D3D11 objects */
|
/* Release persistent D3D11 objects */
|
||||||
ID3D11DeviceContext_Release(renderer->immediateContext);
|
ID3D11DeviceContext_Release(renderer->immediateContext);
|
||||||
ID3D11Device_Release(renderer->device);
|
ID3D11Device_Release(renderer->device);
|
||||||
|
@ -988,79 +776,24 @@ static Refresh_CommandBuffer* D3D11_AcquireCommandBuffer(
|
||||||
commandBuffer->threadID = SDL_ThreadID();
|
commandBuffer->threadID = SDL_ThreadID();
|
||||||
commandBuffer->recording = 1;
|
commandBuffer->recording = 1;
|
||||||
commandBuffer->fixed = fixed;
|
commandBuffer->fixed = fixed;
|
||||||
commandBuffer->swapchainData = NULL;
|
|
||||||
commandBuffer->commandList = NULL;
|
commandBuffer->commandList = NULL;
|
||||||
|
|
||||||
return (Refresh_CommandBuffer*) commandBuffer;
|
return (Refresh_CommandBuffer*) commandBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
static D3D11SwapchainData* D3D11_INTERNAL_FetchSwapchainData(
|
Refresh_Texture* D3D11_AcquireSwapchainTexture(
|
||||||
D3D11Renderer* renderer,
|
Refresh_Renderer* driverData,
|
||||||
|
Refresh_CommandBuffer* commandBuffer,
|
||||||
void* windowHandle
|
void* windowHandle
|
||||||
) {
|
) {
|
||||||
D3D11SwapchainData* swapchainData = NULL;
|
NOT_IMPLEMENTED
|
||||||
|
|
||||||
swapchainData = (D3D11SwapchainData*) SDL_GetWindowData(windowHandle, WINDOW_SWAPCHAIN_DATA);
|
|
||||||
|
|
||||||
if (swapchainData == NULL)
|
|
||||||
{
|
|
||||||
if (D3D11_INTERNAL_CreateSwapchain(renderer, windowHandle))
|
|
||||||
{
|
|
||||||
swapchainData = (D3D11SwapchainData*) SDL_GetWindowData(windowHandle, WINDOW_SWAPCHAIN_DATA);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return swapchainData;
|
|
||||||
}
|
|
||||||
|
|
||||||
Refresh_Texture* D3D11_AcquireSwapchainTexture(
|
|
||||||
Refresh_Renderer *driverData,
|
|
||||||
Refresh_CommandBuffer *commandBuffer,
|
|
||||||
void *windowHandle
|
|
||||||
) {
|
|
||||||
D3D11Renderer *renderer = (D3D11Renderer*) driverData;
|
|
||||||
D3D11CommandBuffer *cmdbuf = (D3D11CommandBuffer*) commandBuffer;
|
|
||||||
D3D11SwapchainData *swapchainData;
|
|
||||||
DXGI_SWAP_CHAIN_DESC swapchainDesc;
|
|
||||||
int w, h;
|
|
||||||
HRESULT res;
|
|
||||||
|
|
||||||
/* Fetch the swapchain data, creating a new swapchain if needed. */
|
|
||||||
swapchainData = D3D11_INTERNAL_FetchSwapchainData(renderer, windowHandle);
|
|
||||||
if (swapchainData == NULL)
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Check for window size changes and resize the swapchain if needed. */
|
|
||||||
IDXGISwapChain_GetDesc(swapchainData->swapchain, &swapchainDesc);
|
|
||||||
SDL_GetWindowSize((SDL_Window*) windowHandle, &w, &h);
|
|
||||||
|
|
||||||
if (w != swapchainDesc.BufferDesc.Width || h != swapchainDesc.BufferDesc.Height)
|
|
||||||
{
|
|
||||||
res = D3D11_INTERNAL_ResizeSwapchain(renderer, swapchainData);
|
|
||||||
ERROR_CHECK_RETURN("Could not resize swapchain", NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Let's try this again... */
|
|
||||||
swapchainData = D3D11_INTERNAL_FetchSwapchainData(renderer, windowHandle);
|
|
||||||
if (swapchainData == NULL)
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Let the command buffer know it's associated with this swapchain. */
|
|
||||||
cmdbuf->swapchainData = swapchainData;
|
|
||||||
|
|
||||||
/* Return the swapchain texture */
|
|
||||||
return (Refresh_Texture*) &swapchainData->refreshTexture;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Refresh_TextureFormat D3D11_GetSwapchainFormat(
|
Refresh_TextureFormat D3D11_GetSwapchainFormat(
|
||||||
Refresh_Renderer* driverData,
|
Refresh_Renderer* driverData,
|
||||||
void* windowHandle
|
void* windowHandle
|
||||||
) {
|
) {
|
||||||
return DXGI_FORMAT_R8G8B8A8_UNORM;
|
NOT_IMPLEMENTED
|
||||||
}
|
}
|
||||||
|
|
||||||
static void D3D11_Submit(
|
static void D3D11_Submit(
|
||||||
|
@ -1081,7 +814,6 @@ static void D3D11_Submit(
|
||||||
|
|
||||||
if (commandBuffer->fixed && !commandBuffer->recording)
|
if (commandBuffer->fixed && !commandBuffer->recording)
|
||||||
{
|
{
|
||||||
/* Grab the prerecorded command list. */
|
|
||||||
commandList = commandBuffer->commandList;
|
commandList = commandBuffer->commandList;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1115,16 +847,6 @@ static void D3D11_Submit(
|
||||||
|
|
||||||
/* Mark the command buffer as not-recording so that it can be used to record again. */
|
/* Mark the command buffer as not-recording so that it can be used to record again. */
|
||||||
commandBuffer->recording = 0;
|
commandBuffer->recording = 0;
|
||||||
|
|
||||||
/* Present, if applicable */
|
|
||||||
if (commandBuffer->swapchainData)
|
|
||||||
{
|
|
||||||
IDXGISwapChain_Present(
|
|
||||||
commandBuffer->swapchainData->swapchain,
|
|
||||||
1, /* FIXME: Assumes vsync! */
|
|
||||||
0
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1280,18 +1002,6 @@ tryCreateDevice:
|
||||||
|
|
||||||
result->driverData = (Refresh_Renderer*) renderer;
|
result->driverData = (Refresh_Renderer*) renderer;
|
||||||
|
|
||||||
/* Create the initial swapchain */
|
|
||||||
renderer->swapchainDataCapacity = 1;
|
|
||||||
renderer->swapchainDataCount = 0;
|
|
||||||
renderer->swapchainDatas = SDL_malloc(
|
|
||||||
renderer->swapchainDataCapacity * sizeof(D3D11SwapchainData*)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!D3D11_INTERNAL_CreateSwapchain(renderer, presentationParameters->deviceWindowHandle))
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,6 @@ typedef HRESULT(WINAPI* PFN_CREATE_DXGI_FACTORY)(const GUID* riid, void** ppFact
|
||||||
static const IID D3D_IID_IDXGIFactory1 = { 0x770aae78,0xf26f,0x4dba,{0xa8,0x29,0x25,0x3c,0x83,0xd1,0xb3,0x87} };
|
static const IID D3D_IID_IDXGIFactory1 = { 0x770aae78,0xf26f,0x4dba,{0xa8,0x29,0x25,0x3c,0x83,0xd1,0xb3,0x87} };
|
||||||
static const IID D3D_IID_IDXGIFactory6 = { 0xc1b6694f,0xff09,0x44a9,{0xb0,0x3c,0x77,0x90,0x0a,0x0a,0x1d,0x17} };
|
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_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) */
|
/* IDXGIFactory6 (taken from dxgi1_6.h, cleaned up a bit) */
|
||||||
typedef enum
|
typedef enum
|
||||||
|
|
|
@ -37,7 +37,6 @@
|
||||||
static TEMPLATE_SURFACE_FORMAT_TYPE RefreshToTEMPLATE_SurfaceFormat[] =
|
static TEMPLATE_SURFACE_FORMAT_TYPE RefreshToTEMPLATE_SurfaceFormat[] =
|
||||||
{
|
{
|
||||||
0, /* R8G8B8A8 */
|
0, /* R8G8B8A8 */
|
||||||
0, /* B8G8R8A8 */
|
|
||||||
0, /* R5G6B5 */
|
0, /* R5G6B5 */
|
||||||
0, /* A1R5G5B5 */
|
0, /* A1R5G5B5 */
|
||||||
0, /* B4G4R4A4 */
|
0, /* B4G4R4A4 */
|
||||||
|
@ -97,6 +96,7 @@ static TEMPLATE_POLYGON_MODE_TYPE RefreshToTEMPLATE_PolygonMode[] =
|
||||||
{
|
{
|
||||||
0, /* FILL */
|
0, /* FILL */
|
||||||
0, /* LINE */
|
0, /* LINE */
|
||||||
|
0 /* POINT */
|
||||||
};
|
};
|
||||||
|
|
||||||
static TEMPLATE_CULL_MODE_TYPE RefreshToTEMPLATE_CullMode[] =
|
static TEMPLATE_CULL_MODE_TYPE RefreshToTEMPLATE_CullMode[] =
|
||||||
|
@ -104,6 +104,7 @@ static TEMPLATE_CULL_MODE_TYPE RefreshToTEMPLATE_CullMode[] =
|
||||||
0, /* NONE */
|
0, /* NONE */
|
||||||
0, /* FRONT */
|
0, /* FRONT */
|
||||||
0, /* BACK */
|
0, /* BACK */
|
||||||
|
0 /* FRONT_AND_BACK */
|
||||||
};
|
};
|
||||||
|
|
||||||
static TEMPLATE_FRONT_FACE_TYPE RefreshToTEMPLATE_FrontFace[] =
|
static TEMPLATE_FRONT_FACE_TYPE RefreshToTEMPLATE_FrontFace[] =
|
||||||
|
@ -126,6 +127,8 @@ static TEMPLATE_BLEND_FACTOR_TYPE RefreshToTEMPLATE_BlendFactor[] =
|
||||||
0, /* ONE_MINUS_DST_ALPHA */
|
0, /* ONE_MINUS_DST_ALPHA */
|
||||||
0, /* CONSTANT_COLOR */
|
0, /* CONSTANT_COLOR */
|
||||||
0, /* ONE_MINUS_CONSTANT_COLOR */
|
0, /* ONE_MINUS_CONSTANT_COLOR */
|
||||||
|
0, /* CONSTANT_ALPHA */
|
||||||
|
0, /* ONE_MINUS_CONSTANT_ALPHA */
|
||||||
0, /* SRC_ALPHA_SATURATE */
|
0, /* SRC_ALPHA_SATURATE */
|
||||||
0, /* SRC1_COLOR */
|
0, /* SRC1_COLOR */
|
||||||
0, /* ONE_MINUS_SRC1_COLOR */
|
0, /* ONE_MINUS_SRC1_COLOR */
|
||||||
|
@ -142,6 +145,26 @@ static TEMPLATE_BLEND_OP_TYPE RefreshToTEMPLATE_BlendOp[] =
|
||||||
0 /* MAX */
|
0 /* MAX */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static TEMPLATE_LOGIC_OP_TYPE RefreshToTEMPLATE_LogicOp[] =
|
||||||
|
{
|
||||||
|
0, /* CLEAR */
|
||||||
|
0, /* AND */
|
||||||
|
0, /* AND_REVERSE */
|
||||||
|
0, /* COPY */
|
||||||
|
0, /* AND_INVERTED */
|
||||||
|
0, /* NO_OP */
|
||||||
|
0, /* XOR */
|
||||||
|
0, /* OR */
|
||||||
|
0, /* NOR */
|
||||||
|
0, /* EQUIVALENT */
|
||||||
|
0, /* INVERT */
|
||||||
|
0, /* OR_REVERSE */
|
||||||
|
0, /* COPY_INVERTED */
|
||||||
|
0, /* OR_INVERTED */
|
||||||
|
0, /* NAND */
|
||||||
|
0 /* SET */
|
||||||
|
};
|
||||||
|
|
||||||
static TEMPLATE_COMPARE_OP_TYPE RefreshToTEMPLATE_CompareOp[] =
|
static TEMPLATE_COMPARE_OP_TYPE RefreshToTEMPLATE_CompareOp[] =
|
||||||
{
|
{
|
||||||
0, /* NEVER */
|
0, /* NEVER */
|
||||||
|
@ -200,6 +223,7 @@ static TEMPLATE_FILTER_TYPE RefreshToTEMPLATE_Filter[] =
|
||||||
{
|
{
|
||||||
0, /* NEAREST */
|
0, /* NEAREST */
|
||||||
0, /* LINEAR */
|
0, /* LINEAR */
|
||||||
|
0 /* CUBIC */
|
||||||
};
|
};
|
||||||
|
|
||||||
static TEMPLATE_SAMPLER_MIPMAP_MODE_TYPE RefreshToTEMPLATE_SamplerMipmapMode[] =
|
static TEMPLATE_SAMPLER_MIPMAP_MODE_TYPE RefreshToTEMPLATE_SamplerMipmapMode[] =
|
||||||
|
@ -300,7 +324,7 @@ static void TEMPLATE_DispatchCompute(
|
||||||
|
|
||||||
static Refresh_ComputePipeline* TEMPLATE_CreateComputePipeline(
|
static Refresh_ComputePipeline* TEMPLATE_CreateComputePipeline(
|
||||||
Refresh_Renderer *driverData,
|
Refresh_Renderer *driverData,
|
||||||
Refresh_ComputeShaderInfo *computeShaderInfo
|
Refresh_ComputePipelineCreateInfo *pipelineCreateInfo
|
||||||
) {
|
) {
|
||||||
NOT_IMPLEMENTED
|
NOT_IMPLEMENTED
|
||||||
}
|
}
|
||||||
|
@ -333,6 +357,14 @@ static Refresh_Texture* TEMPLATE_CreateTexture(
|
||||||
NOT_IMPLEMENTED
|
NOT_IMPLEMENTED
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Refresh_RenderTarget* TEMPLATE_CreateRenderTarget(
|
||||||
|
Refresh_Renderer *driverData,
|
||||||
|
Refresh_TextureSlice *textureSlice,
|
||||||
|
Refresh_SampleCount multisampleCount
|
||||||
|
) {
|
||||||
|
NOT_IMPLEMENTED
|
||||||
|
}
|
||||||
|
|
||||||
static Refresh_Buffer* TEMPLATE_CreateBuffer(
|
static Refresh_Buffer* TEMPLATE_CreateBuffer(
|
||||||
Refresh_Renderer *driverData,
|
Refresh_Renderer *driverData,
|
||||||
Refresh_BufferUsageFlags usageFlags,
|
Refresh_BufferUsageFlags usageFlags,
|
||||||
|
@ -459,6 +491,7 @@ static void TEMPLATE_GetBufferData(
|
||||||
|
|
||||||
static void TEMPLATE_QueueDestroyTexture(
|
static void TEMPLATE_QueueDestroyTexture(
|
||||||
Refresh_Renderer *driverData,
|
Refresh_Renderer *driverData,
|
||||||
|
Refresh_CommandBuffer *commandBuffer,
|
||||||
Refresh_Texture *texture
|
Refresh_Texture *texture
|
||||||
) {
|
) {
|
||||||
NOT_IMPLEMENTED
|
NOT_IMPLEMENTED
|
||||||
|
@ -466,6 +499,7 @@ static void TEMPLATE_QueueDestroyTexture(
|
||||||
|
|
||||||
static void TEMPLATE_QueueDestroySampler(
|
static void TEMPLATE_QueueDestroySampler(
|
||||||
Refresh_Renderer *driverData,
|
Refresh_Renderer *driverData,
|
||||||
|
Refresh_CommandBuffer *commandBuffer,
|
||||||
Refresh_Sampler *sampler
|
Refresh_Sampler *sampler
|
||||||
) {
|
) {
|
||||||
NOT_IMPLEMENTED
|
NOT_IMPLEMENTED
|
||||||
|
@ -473,20 +507,33 @@ static void TEMPLATE_QueueDestroySampler(
|
||||||
|
|
||||||
static void TEMPLATE_QueueDestroyBuffer(
|
static void TEMPLATE_QueueDestroyBuffer(
|
||||||
Refresh_Renderer *driverData,
|
Refresh_Renderer *driverData,
|
||||||
|
Refresh_CommandBuffer *commandBuffer,
|
||||||
Refresh_Buffer *buffer
|
Refresh_Buffer *buffer
|
||||||
) {
|
) {
|
||||||
NOT_IMPLEMENTED
|
NOT_IMPLEMENTED
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void TEMPLATE_QueueDestroyRenderTarget(
|
||||||
|
Refresh_Renderer *driverData,
|
||||||
|
Refresh_CommandBuffer *commandBuffer,
|
||||||
|
Refresh_RenderTarget *renderTarget
|
||||||
|
) {
|
||||||
|
NOT_IMPLEMENTED
|
||||||
|
}
|
||||||
|
|
||||||
static void TEMPLATE_QueueDestroyShaderModule(
|
static void TEMPLATE_QueueDestroyShaderModule(
|
||||||
Refresh_Renderer *driverData,
|
Refresh_Renderer *driverData,
|
||||||
|
Refresh_CommandBuffer *commandBuffer,
|
||||||
|
|
||||||
Refresh_ShaderModule *shaderModule
|
Refresh_ShaderModule *shaderModule
|
||||||
) {
|
) {
|
||||||
NOT_IMPLEMENTED
|
NOT_IMPLEMENTED
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void TEMPLATE_QueueDestroyComputePipeline(
|
static void TEMPLATE_QueueDestroyComputePipeline(
|
||||||
Refresh_Renderer *driverData,
|
Refresh_Renderer *driverData,
|
||||||
|
Refresh_CommandBuffer *commandBuffer,
|
||||||
Refresh_ComputePipeline *computePipeline
|
Refresh_ComputePipeline *computePipeline
|
||||||
) {
|
) {
|
||||||
NOT_IMPLEMENTED
|
NOT_IMPLEMENTED
|
||||||
|
@ -494,6 +541,7 @@ static void TEMPLATE_QueueDestroyComputePipeline(
|
||||||
|
|
||||||
static void TEMPLATE_QueueDestroyGraphicsPipeline(
|
static void TEMPLATE_QueueDestroyGraphicsPipeline(
|
||||||
Refresh_Renderer *driverData,
|
Refresh_Renderer *driverData,
|
||||||
|
Refresh_CommandBuffer *commandBuffer,
|
||||||
Refresh_GraphicsPipeline *graphicsPipeline
|
Refresh_GraphicsPipeline *graphicsPipeline
|
||||||
) {
|
) {
|
||||||
NOT_IMPLEMENTED
|
NOT_IMPLEMENTED
|
||||||
|
@ -527,22 +575,6 @@ static void TEMPLATE_BindGraphicsPipeline(
|
||||||
NOT_IMPLEMENTED
|
NOT_IMPLEMENTED
|
||||||
}
|
}
|
||||||
|
|
||||||
static void TEMPLATE_SetViewport(
|
|
||||||
Refresh_Renderer *driverData,
|
|
||||||
Refresh_CommandBuffer *commandBuffer,
|
|
||||||
Refresh_Viewport *viewport
|
|
||||||
) {
|
|
||||||
NOT_IMPLEMENTED
|
|
||||||
}
|
|
||||||
|
|
||||||
static void TEMPLATE_SetScissor(
|
|
||||||
Refresh_Renderer *driverData,
|
|
||||||
Refresh_CommandBuffer *commandBuffer,
|
|
||||||
Refresh_Rect *scissor
|
|
||||||
) {
|
|
||||||
NOT_IMPLEMENTED
|
|
||||||
}
|
|
||||||
|
|
||||||
static void TEMPLATE_BindVertexBuffers(
|
static void TEMPLATE_BindVertexBuffers(
|
||||||
Refresh_Renderer *driverData,
|
Refresh_Renderer *driverData,
|
||||||
Refresh_CommandBuffer *commandBuffer,
|
Refresh_CommandBuffer *commandBuffer,
|
||||||
|
@ -595,16 +627,12 @@ static Refresh_CommandBuffer* TEMPLATE_AcquireCommandBuffer(
|
||||||
NOT_IMPLEMENTED
|
NOT_IMPLEMENTED
|
||||||
}
|
}
|
||||||
|
|
||||||
Refresh_Texture* TEMPLATE_AcquireSwapchainTexture(
|
static void TEMPLATE_QueuePresent(
|
||||||
Refresh_Renderer *driverData,
|
Refresh_Renderer *driverData,
|
||||||
Refresh_CommandBuffer *commandBuffer,
|
Refresh_CommandBuffer *commandBuffer,
|
||||||
void *windowHandle
|
Refresh_TextureSlice *textureSlice,
|
||||||
) {
|
Refresh_Rect *destinationRectangle,
|
||||||
NOT_IMPLEMENTED
|
Refresh_Filter filter,
|
||||||
}
|
|
||||||
|
|
||||||
Refresh_TextureFormat TEMPLATE_GetSwapchainFormat(
|
|
||||||
Refresh_Renderer *driverData,
|
|
||||||
void *windowHandle
|
void *windowHandle
|
||||||
) {
|
) {
|
||||||
NOT_IMPLEMENTED
|
NOT_IMPLEMENTED
|
||||||
|
|
|
@ -169,6 +169,13 @@ typedef enum VulkanResourceAccessType
|
||||||
RESOURCE_ACCESS_TYPES_COUNT
|
RESOURCE_ACCESS_TYPES_COUNT
|
||||||
} VulkanResourceAccessType;
|
} VulkanResourceAccessType;
|
||||||
|
|
||||||
|
typedef enum CreateSwapchainResult
|
||||||
|
{
|
||||||
|
CREATE_SWAPCHAIN_FAIL,
|
||||||
|
CREATE_SWAPCHAIN_SUCCESS,
|
||||||
|
CREATE_SWAPCHAIN_SURFACE_ZERO,
|
||||||
|
} CreateSwapchainResult;
|
||||||
|
|
||||||
/* Conversions */
|
/* Conversions */
|
||||||
|
|
||||||
static const uint8_t DEVICE_PRIORITY[] =
|
static const uint8_t DEVICE_PRIORITY[] =
|
||||||
|
@ -744,12 +751,6 @@ typedef struct VulkanRenderTarget
|
||||||
VkSampleCountFlags multisampleCount;
|
VkSampleCountFlags multisampleCount;
|
||||||
} VulkanRenderTarget;
|
} VulkanRenderTarget;
|
||||||
|
|
||||||
typedef struct VulkanFramebuffer
|
|
||||||
{
|
|
||||||
VkFramebuffer framebuffer;
|
|
||||||
SDL_atomic_t referenceCount;
|
|
||||||
} VulkanFramebuffer;
|
|
||||||
|
|
||||||
typedef struct VulkanSwapchainData
|
typedef struct VulkanSwapchainData
|
||||||
{
|
{
|
||||||
/* Window surface */
|
/* Window surface */
|
||||||
|
@ -768,6 +769,9 @@ typedef struct VulkanSwapchainData
|
||||||
VulkanTexture *textures;
|
VulkanTexture *textures;
|
||||||
uint32_t imageCount;
|
uint32_t imageCount;
|
||||||
|
|
||||||
|
/* Recreate flag */
|
||||||
|
uint8_t needsRecreate;
|
||||||
|
|
||||||
/* Synchronization primitives */
|
/* Synchronization primitives */
|
||||||
VkSemaphore imageAvailableSemaphore;
|
VkSemaphore imageAvailableSemaphore;
|
||||||
VkSemaphore renderFinishedSemaphore;
|
VkSemaphore renderFinishedSemaphore;
|
||||||
|
@ -1047,7 +1051,7 @@ typedef struct FramebufferHash
|
||||||
typedef struct FramebufferHashMap
|
typedef struct FramebufferHashMap
|
||||||
{
|
{
|
||||||
FramebufferHash key;
|
FramebufferHash key;
|
||||||
VulkanFramebuffer *value;
|
VkFramebuffer value;
|
||||||
} FramebufferHashMap;
|
} FramebufferHashMap;
|
||||||
|
|
||||||
typedef struct FramebufferHashArray
|
typedef struct FramebufferHashArray
|
||||||
|
@ -1099,7 +1103,7 @@ static inline uint8_t FramebufferHash_Compare(
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline VulkanFramebuffer* FramebufferHashArray_Fetch(
|
static inline VkFramebuffer FramebufferHashArray_Fetch(
|
||||||
FramebufferHashArray *arr,
|
FramebufferHashArray *arr,
|
||||||
FramebufferHash *key
|
FramebufferHash *key
|
||||||
) {
|
) {
|
||||||
|
@ -1120,7 +1124,7 @@ static inline VulkanFramebuffer* FramebufferHashArray_Fetch(
|
||||||
static inline void FramebufferHashArray_Insert(
|
static inline void FramebufferHashArray_Insert(
|
||||||
FramebufferHashArray *arr,
|
FramebufferHashArray *arr,
|
||||||
FramebufferHash key,
|
FramebufferHash key,
|
||||||
VulkanFramebuffer *value
|
VkFramebuffer value
|
||||||
) {
|
) {
|
||||||
FramebufferHashMap map;
|
FramebufferHashMap map;
|
||||||
map.key = key;
|
map.key = key;
|
||||||
|
@ -1516,10 +1520,6 @@ typedef struct VulkanCommandBuffer
|
||||||
uint32_t usedComputePipelineCount;
|
uint32_t usedComputePipelineCount;
|
||||||
uint32_t usedComputePipelineCapacity;
|
uint32_t usedComputePipelineCapacity;
|
||||||
|
|
||||||
VulkanFramebuffer **usedFramebuffers;
|
|
||||||
uint32_t usedFramebufferCount;
|
|
||||||
uint32_t usedFramebufferCapacity;
|
|
||||||
|
|
||||||
/* Shader modules have references tracked by pipelines */
|
/* Shader modules have references tracked by pipelines */
|
||||||
|
|
||||||
VkFence inFlightFence;
|
VkFence inFlightFence;
|
||||||
|
@ -1697,10 +1697,6 @@ typedef struct VulkanRenderer
|
||||||
uint32_t shaderModulesToDestroyCount;
|
uint32_t shaderModulesToDestroyCount;
|
||||||
uint32_t shaderModulesToDestroyCapacity;
|
uint32_t shaderModulesToDestroyCapacity;
|
||||||
|
|
||||||
VulkanFramebuffer **framebuffersToDestroy;
|
|
||||||
uint32_t framebuffersToDestroyCount;
|
|
||||||
uint32_t framebuffersToDestroyCapacity;
|
|
||||||
|
|
||||||
SDL_mutex *allocatorLock;
|
SDL_mutex *allocatorLock;
|
||||||
SDL_mutex *disposeLock;
|
SDL_mutex *disposeLock;
|
||||||
SDL_mutex *submitLock;
|
SDL_mutex *submitLock;
|
||||||
|
@ -2723,57 +2719,10 @@ static void VULKAN_INTERNAL_TrackComputePipeline(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void VULKAN_INTERNAL_TrackFramebuffer(
|
|
||||||
VulkanRenderer *renderer,
|
|
||||||
VulkanCommandBuffer *commandBuffer,
|
|
||||||
VulkanFramebuffer *framebuffer
|
|
||||||
) {
|
|
||||||
TRACK_RESOURCE(
|
|
||||||
framebuffer,
|
|
||||||
VulkanFramebuffer*,
|
|
||||||
usedFramebuffers,
|
|
||||||
usedFramebufferCount,
|
|
||||||
usedFramebufferCapacity
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#undef TRACK_RESOURCE
|
#undef TRACK_RESOURCE
|
||||||
|
|
||||||
/* Resource Disposal */
|
/* Resource Disposal */
|
||||||
|
|
||||||
static void VULKAN_INTERNAL_QueueDestroyFramebuffer(
|
|
||||||
VulkanRenderer *renderer,
|
|
||||||
VulkanFramebuffer *framebuffer
|
|
||||||
) {
|
|
||||||
SDL_LockMutex(renderer->disposeLock);
|
|
||||||
|
|
||||||
EXPAND_ARRAY_IF_NEEDED(
|
|
||||||
renderer->framebuffersToDestroy,
|
|
||||||
VulkanFramebuffer*,
|
|
||||||
renderer->framebuffersToDestroyCount + 1,
|
|
||||||
renderer->framebuffersToDestroyCapacity,
|
|
||||||
renderer->framebuffersToDestroyCapacity * 2
|
|
||||||
)
|
|
||||||
|
|
||||||
renderer->framebuffersToDestroy[renderer->framebuffersToDestroyCount] = framebuffer;
|
|
||||||
renderer->framebuffersToDestroyCount += 1;
|
|
||||||
|
|
||||||
SDL_UnlockMutex(renderer->disposeLock);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void VULKAN_INTERNAL_DestroyFramebuffer(
|
|
||||||
VulkanRenderer *renderer,
|
|
||||||
VulkanFramebuffer *framebuffer
|
|
||||||
) {
|
|
||||||
renderer->vkDestroyFramebuffer(
|
|
||||||
renderer->logicalDevice,
|
|
||||||
framebuffer->framebuffer,
|
|
||||||
NULL
|
|
||||||
);
|
|
||||||
|
|
||||||
SDL_free(framebuffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void VULKAN_INTERNAL_RemoveFramebuffersContainingView(
|
static void VULKAN_INTERNAL_RemoveFramebuffersContainingView(
|
||||||
VulkanRenderer *renderer,
|
VulkanRenderer *renderer,
|
||||||
VkImageView view
|
VkImageView view
|
||||||
|
@ -2791,9 +2740,10 @@ static void VULKAN_INTERNAL_RemoveFramebuffersContainingView(
|
||||||
{
|
{
|
||||||
if (hash->colorAttachmentViews[i] == view)
|
if (hash->colorAttachmentViews[i] == view)
|
||||||
{
|
{
|
||||||
VULKAN_INTERNAL_QueueDestroyFramebuffer(
|
renderer->vkDestroyFramebuffer(
|
||||||
renderer,
|
renderer->logicalDevice,
|
||||||
renderer->framebufferHashArray.elements[i].value
|
renderer->framebufferHashArray.elements[i].value,
|
||||||
|
NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
FramebufferHashArray_Remove(
|
FramebufferHashArray_Remove(
|
||||||
|
@ -2995,7 +2945,6 @@ static void VULKAN_INTERNAL_DestroyCommandPool(
|
||||||
SDL_free(commandBuffer->usedSamplers);
|
SDL_free(commandBuffer->usedSamplers);
|
||||||
SDL_free(commandBuffer->usedGraphicsPipelines);
|
SDL_free(commandBuffer->usedGraphicsPipelines);
|
||||||
SDL_free(commandBuffer->usedComputePipelines);
|
SDL_free(commandBuffer->usedComputePipelines);
|
||||||
SDL_free(commandBuffer->usedFramebuffers);
|
|
||||||
|
|
||||||
SDL_free(commandBuffer);
|
SDL_free(commandBuffer);
|
||||||
}
|
}
|
||||||
|
@ -4088,7 +4037,7 @@ static uint8_t VULKAN_INTERNAL_ChooseSwapPresentMode(
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint8_t VULKAN_INTERNAL_CreateSwapchain(
|
static CreateSwapchainResult VULKAN_INTERNAL_CreateSwapchain(
|
||||||
VulkanRenderer *renderer,
|
VulkanRenderer *renderer,
|
||||||
void *windowHandle
|
void *windowHandle
|
||||||
) {
|
) {
|
||||||
|
@ -4117,7 +4066,7 @@ static uint8_t VULKAN_INTERNAL_CreateSwapchain(
|
||||||
"SDL_Vulkan_CreateSurface failed: %s",
|
"SDL_Vulkan_CreateSurface failed: %s",
|
||||||
SDL_GetError()
|
SDL_GetError()
|
||||||
);
|
);
|
||||||
return 0;
|
return CREATE_SWAPCHAIN_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!VULKAN_INTERNAL_QuerySwapChainSupport(
|
if (!VULKAN_INTERNAL_QuerySwapChainSupport(
|
||||||
|
@ -4142,7 +4091,7 @@ static uint8_t VULKAN_INTERNAL_CreateSwapchain(
|
||||||
}
|
}
|
||||||
SDL_free(swapchainData);
|
SDL_free(swapchainData);
|
||||||
Refresh_LogError("Device does not support swap chain creation");
|
Refresh_LogError("Device does not support swap chain creation");
|
||||||
return 0;
|
return CREATE_SWAPCHAIN_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
swapchainData->swapchainFormat = VK_FORMAT_R8G8B8A8_UNORM;
|
swapchainData->swapchainFormat = VK_FORMAT_R8G8B8A8_UNORM;
|
||||||
|
@ -4184,7 +4133,7 @@ static uint8_t VULKAN_INTERNAL_CreateSwapchain(
|
||||||
}
|
}
|
||||||
SDL_free(swapchainData);
|
SDL_free(swapchainData);
|
||||||
Refresh_LogError("Device does not support swap chain format");
|
Refresh_LogError("Device does not support swap chain format");
|
||||||
return 0;
|
return CREATE_SWAPCHAIN_FAIL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4209,7 +4158,7 @@ static uint8_t VULKAN_INTERNAL_CreateSwapchain(
|
||||||
}
|
}
|
||||||
SDL_free(swapchainData);
|
SDL_free(swapchainData);
|
||||||
Refresh_LogError("Device does not support swap chain present mode");
|
Refresh_LogError("Device does not support swap chain present mode");
|
||||||
return 0;
|
return CREATE_SWAPCHAIN_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_Vulkan_GetDrawableSize(
|
SDL_Vulkan_GetDrawableSize(
|
||||||
|
@ -4240,8 +4189,7 @@ static uint8_t VULKAN_INTERNAL_CreateSwapchain(
|
||||||
SDL_free(swapchainSupportDetails.presentModes);
|
SDL_free(swapchainSupportDetails.presentModes);
|
||||||
}
|
}
|
||||||
SDL_free(swapchainData);
|
SDL_free(swapchainData);
|
||||||
/* Not an error, just Windows minimize behavior! */
|
return CREATE_SWAPCHAIN_SURFACE_ZERO;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (swapchainSupportDetails.capabilities.currentExtent.width != UINT32_MAX)
|
if (swapchainSupportDetails.capabilities.currentExtent.width != UINT32_MAX)
|
||||||
|
@ -4274,7 +4222,7 @@ static uint8_t VULKAN_INTERNAL_CreateSwapchain(
|
||||||
}
|
}
|
||||||
SDL_free(swapchainData);
|
SDL_free(swapchainData);
|
||||||
Refresh_LogError("No fallback swapchain size available!");
|
Refresh_LogError("No fallback swapchain size available!");
|
||||||
return 0;
|
return CREATE_SWAPCHAIN_FAIL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4347,7 +4295,7 @@ static uint8_t VULKAN_INTERNAL_CreateSwapchain(
|
||||||
);
|
);
|
||||||
SDL_free(swapchainData);
|
SDL_free(swapchainData);
|
||||||
LogVulkanResultAsError("vkCreateSwapchainKHR", vulkanResult);
|
LogVulkanResultAsError("vkCreateSwapchainKHR", vulkanResult);
|
||||||
return 0;
|
return CREATE_SWAPCHAIN_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
renderer->vkGetSwapchainImagesKHR(
|
renderer->vkGetSwapchainImagesKHR(
|
||||||
|
@ -4370,7 +4318,7 @@ static uint8_t VULKAN_INTERNAL_CreateSwapchain(
|
||||||
NULL
|
NULL
|
||||||
);
|
);
|
||||||
SDL_free(swapchainData);
|
SDL_free(swapchainData);
|
||||||
return 0;
|
return CREATE_SWAPCHAIN_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
swapchainImages = SDL_stack_alloc(VkImage, swapchainData->imageCount);
|
swapchainImages = SDL_stack_alloc(VkImage, swapchainData->imageCount);
|
||||||
|
@ -4418,7 +4366,7 @@ static uint8_t VULKAN_INTERNAL_CreateSwapchain(
|
||||||
SDL_free(swapchainData->textures);
|
SDL_free(swapchainData->textures);
|
||||||
SDL_free(swapchainData);
|
SDL_free(swapchainData);
|
||||||
LogVulkanResultAsError("vkCreateImageView", vulkanResult);
|
LogVulkanResultAsError("vkCreateImageView", vulkanResult);
|
||||||
return 0;
|
return CREATE_SWAPCHAIN_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
swapchainData->textures[i].resourceAccessType = RESOURCE_ACCESS_NONE;
|
swapchainData->textures[i].resourceAccessType = RESOURCE_ACCESS_NONE;
|
||||||
|
@ -4460,6 +4408,8 @@ static uint8_t VULKAN_INTERNAL_CreateSwapchain(
|
||||||
&swapchainData->renderFinishedSemaphore
|
&swapchainData->renderFinishedSemaphore
|
||||||
);
|
);
|
||||||
|
|
||||||
|
swapchainData->needsRecreate = 0;
|
||||||
|
|
||||||
SDL_SetWindowData(windowHandle, WINDOW_SWAPCHAIN_DATA, swapchainData);
|
SDL_SetWindowData(windowHandle, WINDOW_SWAPCHAIN_DATA, swapchainData);
|
||||||
|
|
||||||
if (renderer->swapchainDataCount >= renderer->swapchainDataCapacity)
|
if (renderer->swapchainDataCount >= renderer->swapchainDataCapacity)
|
||||||
|
@ -4474,16 +4424,26 @@ static uint8_t VULKAN_INTERNAL_CreateSwapchain(
|
||||||
renderer->swapchainDatas[renderer->swapchainDataCount] = swapchainData;
|
renderer->swapchainDatas[renderer->swapchainDataCount] = swapchainData;
|
||||||
renderer->swapchainDataCount += 1;
|
renderer->swapchainDataCount += 1;
|
||||||
|
|
||||||
return 1;
|
return CREATE_SWAPCHAIN_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void VULKAN_INTERNAL_RecreateSwapchain(
|
static void VULKAN_INTERNAL_RecreateSwapchain(
|
||||||
VulkanRenderer* renderer,
|
VulkanRenderer* renderer,
|
||||||
void *windowHandle
|
void *windowHandle
|
||||||
) {
|
) {
|
||||||
VULKAN_Wait((Refresh_Renderer*) renderer);
|
CreateSwapchainResult createSwapchainResult;
|
||||||
|
|
||||||
|
VULKAN_Wait((Refresh_Renderer*)renderer);
|
||||||
|
|
||||||
VULKAN_INTERNAL_DestroySwapchain(renderer, windowHandle);
|
VULKAN_INTERNAL_DestroySwapchain(renderer, windowHandle);
|
||||||
VULKAN_INTERNAL_CreateSwapchain(renderer, windowHandle);
|
createSwapchainResult = VULKAN_INTERNAL_CreateSwapchain(renderer, windowHandle);
|
||||||
|
|
||||||
|
if (createSwapchainResult == CREATE_SWAPCHAIN_FAIL)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
VULKAN_Wait((Refresh_Renderer*)renderer);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Command Buffers */
|
/* Command Buffers */
|
||||||
|
@ -4556,15 +4516,6 @@ static void VULKAN_DestroyDevice(
|
||||||
|
|
||||||
VULKAN_Wait(device->driverData);
|
VULKAN_Wait(device->driverData);
|
||||||
|
|
||||||
for (i = renderer->swapchainDataCount - 1; i >= 0; i -= 1)
|
|
||||||
{
|
|
||||||
VULKAN_INTERNAL_DestroySwapchain(renderer, renderer->swapchainDatas[i]->windowHandle);
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_free(renderer->swapchainDatas);
|
|
||||||
|
|
||||||
VULKAN_Wait(device->driverData);
|
|
||||||
|
|
||||||
SDL_free(renderer->submittedCommandBuffers);
|
SDL_free(renderer->submittedCommandBuffers);
|
||||||
|
|
||||||
VULKAN_INTERNAL_DestroyBuffer(renderer, renderer->dummyVertexUniformBuffer->vulkanBuffer);
|
VULKAN_INTERNAL_DestroyBuffer(renderer, renderer->dummyVertexUniformBuffer->vulkanBuffer);
|
||||||
|
@ -4724,11 +4675,19 @@ static void VULKAN_DestroyDevice(
|
||||||
VULKAN_INTERNAL_DestroyUniformBufferPool(renderer, renderer->fragmentUniformBufferPool);
|
VULKAN_INTERNAL_DestroyUniformBufferPool(renderer, renderer->fragmentUniformBufferPool);
|
||||||
VULKAN_INTERNAL_DestroyUniformBufferPool(renderer, renderer->computeUniformBufferPool);
|
VULKAN_INTERNAL_DestroyUniformBufferPool(renderer, renderer->computeUniformBufferPool);
|
||||||
|
|
||||||
|
for (i = renderer->swapchainDataCount - 1; i >= 0; i -= 1)
|
||||||
|
{
|
||||||
|
VULKAN_INTERNAL_DestroySwapchain(renderer, renderer->swapchainDatas[i]->windowHandle);
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_free(renderer->swapchainDatas);
|
||||||
|
|
||||||
for (i = 0; i < renderer->framebufferHashArray.count; i += 1)
|
for (i = 0; i < renderer->framebufferHashArray.count; i += 1)
|
||||||
{
|
{
|
||||||
VULKAN_INTERNAL_DestroyFramebuffer(
|
renderer->vkDestroyFramebuffer(
|
||||||
renderer,
|
renderer->logicalDevice,
|
||||||
renderer->framebufferHashArray.elements[i].value
|
renderer->framebufferHashArray.elements[i].value,
|
||||||
|
NULL
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7820,7 +7779,7 @@ static VkRenderPass VULKAN_INTERNAL_FetchRenderPass(
|
||||||
return renderPass;
|
return renderPass;
|
||||||
}
|
}
|
||||||
|
|
||||||
static VulkanFramebuffer* VULKAN_INTERNAL_FetchFramebuffer(
|
static VkFramebuffer VULKAN_INTERNAL_FetchFramebuffer(
|
||||||
VulkanRenderer *renderer,
|
VulkanRenderer *renderer,
|
||||||
VkRenderPass renderPass,
|
VkRenderPass renderPass,
|
||||||
Refresh_ColorAttachmentInfo *colorAttachmentInfos,
|
Refresh_ColorAttachmentInfo *colorAttachmentInfos,
|
||||||
|
@ -7829,7 +7788,7 @@ static VulkanFramebuffer* VULKAN_INTERNAL_FetchFramebuffer(
|
||||||
uint32_t width,
|
uint32_t width,
|
||||||
uint32_t height
|
uint32_t height
|
||||||
) {
|
) {
|
||||||
VulkanFramebuffer *vulkanFramebuffer;
|
VkFramebuffer framebuffer;
|
||||||
VkFramebufferCreateInfo framebufferInfo;
|
VkFramebufferCreateInfo framebufferInfo;
|
||||||
VkResult result;
|
VkResult result;
|
||||||
VkImageView imageViewAttachments[2 * MAX_COLOR_TARGET_BINDINGS + 1];
|
VkImageView imageViewAttachments[2 * MAX_COLOR_TARGET_BINDINGS + 1];
|
||||||
|
@ -7891,21 +7850,17 @@ static VulkanFramebuffer* VULKAN_INTERNAL_FetchFramebuffer(
|
||||||
hash.width = width;
|
hash.width = width;
|
||||||
hash.height = height;
|
hash.height = height;
|
||||||
|
|
||||||
vulkanFramebuffer = FramebufferHashArray_Fetch(
|
framebuffer = FramebufferHashArray_Fetch(
|
||||||
&renderer->framebufferHashArray,
|
&renderer->framebufferHashArray,
|
||||||
&hash
|
&hash
|
||||||
);
|
);
|
||||||
|
|
||||||
if (vulkanFramebuffer != NULL)
|
if (framebuffer != VK_NULL_HANDLE)
|
||||||
{
|
{
|
||||||
SDL_UnlockMutex(renderer->framebufferFetchLock);
|
SDL_UnlockMutex(renderer->framebufferFetchLock);
|
||||||
return vulkanFramebuffer;
|
return framebuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
vulkanFramebuffer = SDL_malloc(sizeof(VulkanFramebuffer));
|
|
||||||
|
|
||||||
SDL_AtomicSet(&vulkanFramebuffer->referenceCount, 0);
|
|
||||||
|
|
||||||
/* Create a new framebuffer */
|
/* Create a new framebuffer */
|
||||||
|
|
||||||
for (i = 0; i < colorAttachmentCount; i += 1)
|
for (i = 0; i < colorAttachmentCount; i += 1)
|
||||||
|
@ -7963,7 +7918,7 @@ static VulkanFramebuffer* VULKAN_INTERNAL_FetchFramebuffer(
|
||||||
renderer->logicalDevice,
|
renderer->logicalDevice,
|
||||||
&framebufferInfo,
|
&framebufferInfo,
|
||||||
NULL,
|
NULL,
|
||||||
&vulkanFramebuffer->framebuffer
|
&framebuffer
|
||||||
);
|
);
|
||||||
|
|
||||||
if (result == VK_SUCCESS)
|
if (result == VK_SUCCESS)
|
||||||
|
@ -7971,18 +7926,17 @@ static VulkanFramebuffer* VULKAN_INTERNAL_FetchFramebuffer(
|
||||||
FramebufferHashArray_Insert(
|
FramebufferHashArray_Insert(
|
||||||
&renderer->framebufferHashArray,
|
&renderer->framebufferHashArray,
|
||||||
hash,
|
hash,
|
||||||
vulkanFramebuffer
|
framebuffer
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LogVulkanResultAsError("vkCreateFramebuffer", result);
|
LogVulkanResultAsError("vkCreateFramebuffer", result);
|
||||||
SDL_free(vulkanFramebuffer);
|
framebuffer = VK_NULL_HANDLE;
|
||||||
vulkanFramebuffer = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_UnlockMutex(renderer->framebufferFetchLock);
|
SDL_UnlockMutex(renderer->framebufferFetchLock);
|
||||||
return vulkanFramebuffer;
|
return framebuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void VULKAN_INTERNAL_SetCurrentViewport(
|
static void VULKAN_INTERNAL_SetCurrentViewport(
|
||||||
|
@ -8074,7 +8028,7 @@ static void VULKAN_BeginRenderPass(
|
||||||
VulkanRenderer* renderer = (VulkanRenderer*) driverData;
|
VulkanRenderer* renderer = (VulkanRenderer*) driverData;
|
||||||
VulkanCommandBuffer *vulkanCommandBuffer = (VulkanCommandBuffer*) commandBuffer;
|
VulkanCommandBuffer *vulkanCommandBuffer = (VulkanCommandBuffer*) commandBuffer;
|
||||||
VkRenderPass renderPass;
|
VkRenderPass renderPass;
|
||||||
VulkanFramebuffer *framebuffer;
|
VkFramebuffer framebuffer;
|
||||||
|
|
||||||
VulkanTexture *texture;
|
VulkanTexture *texture;
|
||||||
VkClearValue *clearValues;
|
VkClearValue *clearValues;
|
||||||
|
@ -8141,8 +8095,6 @@ static void VULKAN_BeginRenderPass(
|
||||||
framebufferHeight
|
framebufferHeight
|
||||||
);
|
);
|
||||||
|
|
||||||
VULKAN_INTERNAL_TrackFramebuffer(renderer, vulkanCommandBuffer, framebuffer);
|
|
||||||
|
|
||||||
/* Layout transitions */
|
/* Layout transitions */
|
||||||
|
|
||||||
for (i = 0; i < colorAttachmentCount; i += 1)
|
for (i = 0; i < colorAttachmentCount; i += 1)
|
||||||
|
@ -8217,26 +8169,15 @@ static void VULKAN_BeginRenderPass(
|
||||||
VkRenderPassBeginInfo renderPassBeginInfo;
|
VkRenderPassBeginInfo renderPassBeginInfo;
|
||||||
renderPassBeginInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
|
renderPassBeginInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
|
||||||
renderPassBeginInfo.pNext = NULL;
|
renderPassBeginInfo.pNext = NULL;
|
||||||
renderPassBeginInfo.renderPass = renderPass;
|
renderPassBeginInfo.renderPass = (VkRenderPass) renderPass;
|
||||||
renderPassBeginInfo.framebuffer = framebuffer->framebuffer;
|
renderPassBeginInfo.framebuffer = framebuffer;
|
||||||
|
renderPassBeginInfo.renderArea.extent.width = renderArea->w;
|
||||||
|
renderPassBeginInfo.renderArea.extent.height = renderArea->h;
|
||||||
|
renderPassBeginInfo.renderArea.offset.x = renderArea->x;
|
||||||
|
renderPassBeginInfo.renderArea.offset.y = renderArea->y;
|
||||||
renderPassBeginInfo.pClearValues = clearValues;
|
renderPassBeginInfo.pClearValues = clearValues;
|
||||||
renderPassBeginInfo.clearValueCount = clearCount;
|
renderPassBeginInfo.clearValueCount = clearCount;
|
||||||
|
|
||||||
if (renderArea != NULL)
|
|
||||||
{
|
|
||||||
renderPassBeginInfo.renderArea.extent.width = renderArea->w;
|
|
||||||
renderPassBeginInfo.renderArea.extent.height = renderArea->h;
|
|
||||||
renderPassBeginInfo.renderArea.offset.x = renderArea->x;
|
|
||||||
renderPassBeginInfo.renderArea.offset.y = renderArea->y;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
renderPassBeginInfo.renderArea.extent.width = framebufferWidth;
|
|
||||||
renderPassBeginInfo.renderArea.extent.height = framebufferHeight;
|
|
||||||
renderPassBeginInfo.renderArea.offset.x = 0;
|
|
||||||
renderPassBeginInfo.renderArea.offset.y = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
renderer->vkCmdBeginRenderPass(
|
renderer->vkCmdBeginRenderPass(
|
||||||
vulkanCommandBuffer->commandBuffer,
|
vulkanCommandBuffer->commandBuffer,
|
||||||
&renderPassBeginInfo,
|
&renderPassBeginInfo,
|
||||||
|
@ -8774,12 +8715,6 @@ static void VULKAN_INTERNAL_AllocateCommandBuffers(
|
||||||
commandBuffer->usedComputePipelineCapacity * sizeof(VulkanComputePipeline*)
|
commandBuffer->usedComputePipelineCapacity * sizeof(VulkanComputePipeline*)
|
||||||
);
|
);
|
||||||
|
|
||||||
commandBuffer->usedFramebufferCapacity = 4;
|
|
||||||
commandBuffer->usedFramebufferCount = 0;
|
|
||||||
commandBuffer->usedFramebuffers = SDL_malloc(
|
|
||||||
commandBuffer->usedFramebufferCapacity * sizeof(VulkanFramebuffer*)
|
|
||||||
);
|
|
||||||
|
|
||||||
vulkanCommandPool->inactiveCommandBuffers[
|
vulkanCommandPool->inactiveCommandBuffers[
|
||||||
vulkanCommandPool->inactiveCommandBufferCount
|
vulkanCommandPool->inactiveCommandBufferCount
|
||||||
] = commandBuffer;
|
] = commandBuffer;
|
||||||
|
@ -8932,25 +8867,6 @@ static Refresh_CommandBuffer* VULKAN_AcquireCommandBuffer(
|
||||||
return (Refresh_CommandBuffer*) commandBuffer;
|
return (Refresh_CommandBuffer*) commandBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
static VulkanSwapchainData* VULKAN_INTERNAL_FetchSwapchainData(
|
|
||||||
VulkanRenderer *renderer,
|
|
||||||
void *windowHandle
|
|
||||||
) {
|
|
||||||
VulkanSwapchainData *swapchainData = NULL;
|
|
||||||
|
|
||||||
swapchainData = (VulkanSwapchainData*) SDL_GetWindowData(windowHandle, WINDOW_SWAPCHAIN_DATA);
|
|
||||||
|
|
||||||
if (swapchainData == NULL)
|
|
||||||
{
|
|
||||||
if (VULKAN_INTERNAL_CreateSwapchain(renderer, windowHandle))
|
|
||||||
{
|
|
||||||
swapchainData = (VulkanSwapchainData*) SDL_GetWindowData(windowHandle, WINDOW_SWAPCHAIN_DATA);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return swapchainData;
|
|
||||||
}
|
|
||||||
|
|
||||||
static Refresh_Texture* VULKAN_AcquireSwapchainTexture(
|
static Refresh_Texture* VULKAN_AcquireSwapchainTexture(
|
||||||
Refresh_Renderer *driverData,
|
Refresh_Renderer *driverData,
|
||||||
Refresh_CommandBuffer *commandBuffer,
|
Refresh_CommandBuffer *commandBuffer,
|
||||||
|
@ -8959,39 +8875,35 @@ static Refresh_Texture* VULKAN_AcquireSwapchainTexture(
|
||||||
VulkanRenderer *renderer = (VulkanRenderer*) driverData;
|
VulkanRenderer *renderer = (VulkanRenderer*) driverData;
|
||||||
VulkanCommandBuffer *vulkanCommandBuffer = (VulkanCommandBuffer*) commandBuffer;
|
VulkanCommandBuffer *vulkanCommandBuffer = (VulkanCommandBuffer*) commandBuffer;
|
||||||
uint32_t swapchainImageIndex;
|
uint32_t swapchainImageIndex;
|
||||||
VulkanSwapchainData *swapchainData;
|
VulkanSwapchainData *swapchainData = NULL;
|
||||||
|
CreateSwapchainResult createSwapchainResult = 0;
|
||||||
|
uint8_t validSwapchainExists = 1;
|
||||||
VkResult acquireResult = VK_SUCCESS;
|
VkResult acquireResult = VK_SUCCESS;
|
||||||
VulkanTexture *swapchainTexture = NULL;
|
VulkanTexture *swapchainTexture = NULL;
|
||||||
VulkanPresentData *presentData;
|
VulkanPresentData *presentData;
|
||||||
|
|
||||||
swapchainData = VULKAN_INTERNAL_FetchSwapchainData(renderer, windowHandle);
|
swapchainData = (VulkanSwapchainData*) SDL_GetWindowData(windowHandle, WINDOW_SWAPCHAIN_DATA);
|
||||||
|
|
||||||
if (swapchainData == NULL)
|
if (swapchainData == NULL)
|
||||||
{
|
{
|
||||||
return NULL;
|
createSwapchainResult = VULKAN_INTERNAL_CreateSwapchain(renderer, windowHandle);
|
||||||
|
|
||||||
|
if (createSwapchainResult == CREATE_SWAPCHAIN_FAIL)
|
||||||
|
{
|
||||||
|
validSwapchainExists = 0;
|
||||||
|
}
|
||||||
|
else if (createSwapchainResult == CREATE_SWAPCHAIN_SURFACE_ZERO)
|
||||||
|
{
|
||||||
|
validSwapchainExists = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
swapchainData = (VulkanSwapchainData*) SDL_GetWindowData(windowHandle, WINDOW_SWAPCHAIN_DATA);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
acquireResult = renderer->vkAcquireNextImageKHR(
|
if (validSwapchainExists)
|
||||||
renderer->logicalDevice,
|
|
||||||
swapchainData->swapchain,
|
|
||||||
UINT64_MAX,
|
|
||||||
swapchainData->imageAvailableSemaphore,
|
|
||||||
VK_NULL_HANDLE,
|
|
||||||
&swapchainImageIndex
|
|
||||||
);
|
|
||||||
|
|
||||||
/* Swapchain is suboptimal, let's try to recreate */
|
|
||||||
if (acquireResult == VK_SUBOPTIMAL_KHR)
|
|
||||||
{
|
{
|
||||||
VULKAN_INTERNAL_RecreateSwapchain(renderer, windowHandle);
|
|
||||||
|
|
||||||
swapchainData = VULKAN_INTERNAL_FetchSwapchainData(renderer, windowHandle);
|
|
||||||
|
|
||||||
if (swapchainData == NULL)
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
acquireResult = renderer->vkAcquireNextImageKHR(
|
acquireResult = renderer->vkAcquireNextImageKHR(
|
||||||
renderer->logicalDevice,
|
renderer->logicalDevice,
|
||||||
swapchainData->swapchain,
|
swapchainData->swapchain,
|
||||||
|
@ -9001,71 +8913,74 @@ static Refresh_Texture* VULKAN_AcquireSwapchainTexture(
|
||||||
&swapchainImageIndex
|
&swapchainImageIndex
|
||||||
);
|
);
|
||||||
|
|
||||||
if (acquireResult != VK_SUCCESS)
|
if (acquireResult == VK_SUCCESS || acquireResult == VK_SUBOPTIMAL_KHR)
|
||||||
{
|
{
|
||||||
return NULL;
|
swapchainTexture = &swapchainData->textures[swapchainImageIndex];
|
||||||
|
|
||||||
|
VULKAN_INTERNAL_ImageMemoryBarrier(
|
||||||
|
renderer,
|
||||||
|
vulkanCommandBuffer->commandBuffer,
|
||||||
|
RESOURCE_ACCESS_COLOR_ATTACHMENT_WRITE,
|
||||||
|
VK_IMAGE_ASPECT_COLOR_BIT,
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
0,
|
||||||
|
swapchainTexture->image,
|
||||||
|
&swapchainTexture->resourceAccessType
|
||||||
|
);
|
||||||
|
|
||||||
|
/* Set up present struct */
|
||||||
|
|
||||||
|
if (vulkanCommandBuffer->presentDataCount == vulkanCommandBuffer->presentDataCapacity)
|
||||||
|
{
|
||||||
|
vulkanCommandBuffer->presentDataCapacity += 1;
|
||||||
|
vulkanCommandBuffer->presentDatas = SDL_realloc(
|
||||||
|
vulkanCommandBuffer->presentDatas,
|
||||||
|
vulkanCommandBuffer->presentDataCapacity * sizeof(VkPresentInfoKHR)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
presentData = &vulkanCommandBuffer->presentDatas[vulkanCommandBuffer->presentDataCount];
|
||||||
|
vulkanCommandBuffer->presentDataCount += 1;
|
||||||
|
|
||||||
|
presentData->swapchainData = swapchainData;
|
||||||
|
presentData->swapchainImageIndex = swapchainImageIndex;
|
||||||
|
|
||||||
|
/* Set up present semaphores */
|
||||||
|
|
||||||
|
if (vulkanCommandBuffer->waitSemaphoreCount == vulkanCommandBuffer->waitSemaphoreCapacity)
|
||||||
|
{
|
||||||
|
vulkanCommandBuffer->waitSemaphoreCapacity += 1;
|
||||||
|
vulkanCommandBuffer->waitSemaphores = SDL_realloc(
|
||||||
|
vulkanCommandBuffer->waitSemaphores,
|
||||||
|
vulkanCommandBuffer->waitSemaphoreCapacity * sizeof(VkSemaphore)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
vulkanCommandBuffer->waitSemaphores[vulkanCommandBuffer->waitSemaphoreCount] = swapchainData->imageAvailableSemaphore;
|
||||||
|
vulkanCommandBuffer->waitSemaphoreCount += 1;
|
||||||
|
|
||||||
|
if (vulkanCommandBuffer->signalSemaphoreCount == vulkanCommandBuffer->signalSemaphoreCapacity)
|
||||||
|
{
|
||||||
|
vulkanCommandBuffer->signalSemaphoreCapacity += 1;
|
||||||
|
vulkanCommandBuffer->signalSemaphores = SDL_realloc(
|
||||||
|
vulkanCommandBuffer->signalSemaphores,
|
||||||
|
vulkanCommandBuffer->signalSemaphoreCapacity * sizeof(VkSemaphore)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
vulkanCommandBuffer->signalSemaphores[vulkanCommandBuffer->signalSemaphoreCount] = swapchainData->renderFinishedSemaphore;
|
||||||
|
vulkanCommandBuffer->signalSemaphoreCount += 1;
|
||||||
|
|
||||||
|
if (acquireResult == VK_SUBOPTIMAL_KHR)
|
||||||
|
{
|
||||||
|
swapchainData->needsRecreate = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
swapchainTexture = &swapchainData->textures[swapchainImageIndex];
|
|
||||||
|
|
||||||
VULKAN_INTERNAL_ImageMemoryBarrier(
|
|
||||||
renderer,
|
|
||||||
vulkanCommandBuffer->commandBuffer,
|
|
||||||
RESOURCE_ACCESS_COLOR_ATTACHMENT_WRITE,
|
|
||||||
VK_IMAGE_ASPECT_COLOR_BIT,
|
|
||||||
0,
|
|
||||||
1,
|
|
||||||
0,
|
|
||||||
1,
|
|
||||||
0,
|
|
||||||
swapchainTexture->image,
|
|
||||||
&swapchainTexture->resourceAccessType
|
|
||||||
);
|
|
||||||
|
|
||||||
/* Set up present struct */
|
|
||||||
|
|
||||||
if (vulkanCommandBuffer->presentDataCount == vulkanCommandBuffer->presentDataCapacity)
|
|
||||||
{
|
|
||||||
vulkanCommandBuffer->presentDataCapacity += 1;
|
|
||||||
vulkanCommandBuffer->presentDatas = SDL_realloc(
|
|
||||||
vulkanCommandBuffer->presentDatas,
|
|
||||||
vulkanCommandBuffer->presentDataCapacity * sizeof(VkPresentInfoKHR)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
presentData = &vulkanCommandBuffer->presentDatas[vulkanCommandBuffer->presentDataCount];
|
|
||||||
vulkanCommandBuffer->presentDataCount += 1;
|
|
||||||
|
|
||||||
presentData->swapchainData = swapchainData;
|
|
||||||
presentData->swapchainImageIndex = swapchainImageIndex;
|
|
||||||
|
|
||||||
/* Set up present semaphores */
|
|
||||||
|
|
||||||
if (vulkanCommandBuffer->waitSemaphoreCount == vulkanCommandBuffer->waitSemaphoreCapacity)
|
|
||||||
{
|
|
||||||
vulkanCommandBuffer->waitSemaphoreCapacity += 1;
|
|
||||||
vulkanCommandBuffer->waitSemaphores = SDL_realloc(
|
|
||||||
vulkanCommandBuffer->waitSemaphores,
|
|
||||||
vulkanCommandBuffer->waitSemaphoreCapacity * sizeof(VkSemaphore)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
vulkanCommandBuffer->waitSemaphores[vulkanCommandBuffer->waitSemaphoreCount] = swapchainData->imageAvailableSemaphore;
|
|
||||||
vulkanCommandBuffer->waitSemaphoreCount += 1;
|
|
||||||
|
|
||||||
if (vulkanCommandBuffer->signalSemaphoreCount == vulkanCommandBuffer->signalSemaphoreCapacity)
|
|
||||||
{
|
|
||||||
vulkanCommandBuffer->signalSemaphoreCapacity += 1;
|
|
||||||
vulkanCommandBuffer->signalSemaphores = SDL_realloc(
|
|
||||||
vulkanCommandBuffer->signalSemaphores,
|
|
||||||
vulkanCommandBuffer->signalSemaphoreCapacity * sizeof(VkSemaphore)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
vulkanCommandBuffer->signalSemaphores[vulkanCommandBuffer->signalSemaphoreCount] = swapchainData->renderFinishedSemaphore;
|
|
||||||
vulkanCommandBuffer->signalSemaphoreCount += 1;
|
|
||||||
|
|
||||||
return (Refresh_Texture*) swapchainTexture;
|
return (Refresh_Texture*) swapchainTexture;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9189,20 +9104,6 @@ static void VULKAN_INTERNAL_PerformPendingDestroys(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = renderer->framebuffersToDestroyCount - 1; i >= 0; i -= 1)
|
|
||||||
{
|
|
||||||
if (SDL_AtomicGet(&renderer->framebuffersToDestroy[i]->referenceCount) == 0)
|
|
||||||
{
|
|
||||||
VULKAN_INTERNAL_DestroyFramebuffer(
|
|
||||||
renderer,
|
|
||||||
renderer->framebuffersToDestroy[i]
|
|
||||||
);
|
|
||||||
|
|
||||||
renderer->framebuffersToDestroy[i] = renderer->framebuffersToDestroy[renderer->framebuffersToDestroyCount - 1];
|
|
||||||
renderer->framebuffersToDestroyCount -= 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_UnlockMutex(renderer->disposeLock);
|
SDL_UnlockMutex(renderer->disposeLock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9316,12 +9217,6 @@ static void VULKAN_INTERNAL_CleanCommandBuffer(
|
||||||
}
|
}
|
||||||
commandBuffer->usedComputePipelineCount = 0;
|
commandBuffer->usedComputePipelineCount = 0;
|
||||||
|
|
||||||
for (i = 0; i < commandBuffer->usedFramebufferCount; i += 1)
|
|
||||||
{
|
|
||||||
SDL_AtomicDecRef(&commandBuffer->usedFramebuffers[i]->referenceCount);
|
|
||||||
}
|
|
||||||
commandBuffer->usedFramebufferCount = 0;
|
|
||||||
|
|
||||||
/* Return command buffer to pool */
|
/* Return command buffer to pool */
|
||||||
|
|
||||||
SDL_LockMutex(renderer->acquireCommandBufferLock);
|
SDL_LockMutex(renderer->acquireCommandBufferLock);
|
||||||
|
@ -9483,7 +9378,7 @@ static void VULKAN_Submit(
|
||||||
&presentInfo
|
&presentInfo
|
||||||
);
|
);
|
||||||
|
|
||||||
if (presentResult != VK_SUCCESS)
|
if (presentResult != VK_SUCCESS || presentData->swapchainData->needsRecreate)
|
||||||
{
|
{
|
||||||
VULKAN_INTERNAL_RecreateSwapchain(renderer, presentData->swapchainData->windowHandle);
|
VULKAN_INTERNAL_RecreateSwapchain(renderer, presentData->swapchainData->windowHandle);
|
||||||
}
|
}
|
||||||
|
@ -10344,7 +10239,7 @@ static Refresh_Device* VULKAN_CreateDevice(
|
||||||
renderer->swapchainDataCapacity * sizeof(VulkanSwapchainData*)
|
renderer->swapchainDataCapacity * sizeof(VulkanSwapchainData*)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!VULKAN_INTERNAL_CreateSwapchain(renderer, presentationParameters->deviceWindowHandle))
|
if (VULKAN_INTERNAL_CreateSwapchain(renderer, presentationParameters->deviceWindowHandle) != CREATE_SWAPCHAIN_SUCCESS)
|
||||||
{
|
{
|
||||||
Refresh_LogError("Failed to create swapchain");
|
Refresh_LogError("Failed to create swapchain");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -10729,13 +10624,6 @@ static Refresh_Device* VULKAN_CreateDevice(
|
||||||
renderer->shaderModulesToDestroyCapacity
|
renderer->shaderModulesToDestroyCapacity
|
||||||
);
|
);
|
||||||
|
|
||||||
renderer->framebuffersToDestroyCapacity = 16;
|
|
||||||
renderer->framebuffersToDestroyCount = 0;
|
|
||||||
renderer->framebuffersToDestroy = SDL_malloc(
|
|
||||||
sizeof(VulkanFramebuffer*) *
|
|
||||||
renderer->framebuffersToDestroyCapacity
|
|
||||||
);
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue