fill in a bit more d3d11 behavior
continuous-integration/drone/push Build is failing Details

d3d11
cosmonaut 2024-03-05 14:55:53 -08:00
parent 5c84debb50
commit 5ed41a7de2
4 changed files with 78 additions and 111 deletions

View File

@ -1260,26 +1260,6 @@ REFRESHAPI void Refresh_CopyTextureToTexture(
Refresh_WriteOptions writeOption Refresh_WriteOptions writeOption
); );
/* Copies image data from a texture slice into a buffer. */
REFRESHAPI void Refresh_CopyTextureToBuffer(
Refresh_Device *device,
Refresh_CommandBuffer *commandBuffer,
Refresh_TextureRegion *textureRegion,
Refresh_GpuBuffer *gpuBuffer,
Refresh_BufferImageCopy *copyParams,
Refresh_WriteOptions writeOption
);
/* Copies data from a buffer to a texture slice. */
REFRESHAPI void Refresh_CopyBufferToTexture(
Refresh_Device *device,
Refresh_CommandBuffer *commandBuffer,
Refresh_GpuBuffer *gpuBuffer,
Refresh_TextureRegion *textureRegion,
Refresh_BufferImageCopy *copyParams,
Refresh_WriteOptions writeOption
);
/* Copies data from a buffer to a buffer. */ /* Copies data from a buffer to a buffer. */
REFRESHAPI void Refresh_CopyBufferToBuffer( REFRESHAPI void Refresh_CopyBufferToBuffer(
Refresh_Device *device, Refresh_Device *device,

View File

@ -879,44 +879,6 @@ void Refresh_CopyTextureToTexture(
); );
} }
void Refresh_CopyTextureToBuffer(
Refresh_Device *device,
Refresh_CommandBuffer *commandBuffer,
Refresh_TextureRegion *textureRegion,
Refresh_GpuBuffer *gpuBuffer,
Refresh_BufferImageCopy *copyParameters,
Refresh_WriteOptions writeOption
) {
NULL_RETURN(device);
device->CopyTextureToBuffer(
device->driverData,
commandBuffer,
textureRegion,
gpuBuffer,
copyParameters,
writeOption
);
}
void Refresh_CopyBufferToTexture(
Refresh_Device *device,
Refresh_CommandBuffer *commandBuffer,
Refresh_GpuBuffer *gpuBuffer,
Refresh_TextureRegion *textureRegion,
Refresh_BufferImageCopy *copyParams,
Refresh_WriteOptions writeOption
) {
NULL_RETURN(device);
device->CopyBufferToTexture(
device->driverData,
commandBuffer,
gpuBuffer,
textureRegion,
copyParams,
writeOption
);
}
void Refresh_CopyBufferToBuffer( void Refresh_CopyBufferToBuffer(
Refresh_Device *device, Refresh_Device *device,
Refresh_CommandBuffer *commandBuffer, Refresh_CommandBuffer *commandBuffer,

View File

@ -532,24 +532,6 @@ struct Refresh_Device
Refresh_WriteOptions writeOption Refresh_WriteOptions writeOption
); );
void (*CopyTextureToBuffer)(
Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer,
Refresh_TextureRegion *textureSlice,
Refresh_GpuBuffer *gpuBuffer,
Refresh_BufferImageCopy *copyParams,
Refresh_WriteOptions writeOption
);
void (*CopyBufferToTexture)(
Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer,
Refresh_GpuBuffer *gpuBuffer,
Refresh_TextureRegion *textureSlice,
Refresh_BufferImageCopy *copyParams,
Refresh_WriteOptions writeOption
);
void (*CopyBufferToBuffer)( void (*CopyBufferToBuffer)(
Refresh_Renderer *driverData, Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer, Refresh_CommandBuffer *commandBuffer,
@ -689,8 +671,6 @@ struct Refresh_Device
ASSIGN_DRIVER_FUNC(DownloadFromTexture, name) \ ASSIGN_DRIVER_FUNC(DownloadFromTexture, name) \
ASSIGN_DRIVER_FUNC(DownloadFromBuffer, name) \ ASSIGN_DRIVER_FUNC(DownloadFromBuffer, name) \
ASSIGN_DRIVER_FUNC(CopyTextureToTexture, name) \ ASSIGN_DRIVER_FUNC(CopyTextureToTexture, name) \
ASSIGN_DRIVER_FUNC(CopyTextureToBuffer, name) \
ASSIGN_DRIVER_FUNC(CopyBufferToTexture, name) \
ASSIGN_DRIVER_FUNC(CopyBufferToBuffer, name) \ ASSIGN_DRIVER_FUNC(CopyBufferToBuffer, name) \
ASSIGN_DRIVER_FUNC(GenerateMipmaps, name) \ ASSIGN_DRIVER_FUNC(GenerateMipmaps, name) \
ASSIGN_DRIVER_FUNC(EndCopyPass, name) \ ASSIGN_DRIVER_FUNC(EndCopyPass, name) \

View File

@ -1,4 +1,4 @@
/* Refresh - XNA-inspired 3D Graphics Library with modern capabilities /* Refresh - XNA-inspired 3D Graphics Library with modern capabilities
* *
* Copyright (c) 2020 Evan Hemsley * Copyright (c) 2020 Evan Hemsley
* *
@ -1865,27 +1865,8 @@ static D3D11TransferBuffer* D3D11_INTERNAL_CreateTransferBuffer(
D3D11Renderer *renderer, D3D11Renderer *renderer,
uint32_t sizeInBytes uint32_t sizeInBytes
) { ) {
D3D11TransferBuffer *transferBuffer; D3D11TransferBuffer *transferBuffer = (D3D11TransferBuffer*) SDL_malloc(sizeof(D3D11TransferBuffer));
D3D11_BUFFER_DESC bufferDesc;
ID3D11Buffer *bufferHandle;
HRESULT res;
bufferDesc.ByteWidth = sizeInBytes;
bufferDesc.Usage = D3D11_USAGE_STAGING;
bufferDesc.BindFlags = 0;
bufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE | D3D11_CPU_ACCESS_READ;
bufferDesc.MiscFlags = 0;
bufferDesc.StructureByteStride = 0;
res = ID3D11Device_CreateBuffer(
renderer->device,
&bufferDesc,
NULL,
&bufferHandle
);
ERROR_CHECK_RETURN("Could not create buffer", NULL);
transferBuffer = (D3D11TransferBuffer*) SDL_malloc(sizeof(D3D11TransferBuffer));
transferBuffer->data = (uint8_t*) SDL_malloc(sizeInBytes); transferBuffer->data = (uint8_t*) SDL_malloc(sizeInBytes);
transferBuffer->size = sizeInBytes; transferBuffer->size = sizeInBytes;
SDL_AtomicSet(&transferBuffer->referenceCount, 0); SDL_AtomicSet(&transferBuffer->referenceCount, 0);
@ -2289,13 +2270,13 @@ static void D3D11_CopyTextureToTexture(
Refresh_WriteOptions writeOption Refresh_WriteOptions writeOption
) { ) {
D3D11CommandBuffer *d3d11CommandBuffer = (D3D11CommandBuffer*) commandBuffer; D3D11CommandBuffer *d3d11CommandBuffer = (D3D11CommandBuffer*) commandBuffer;
D3D11Texture *srcTexture = source->textureSlice.texture; D3D11Texture *srcTexture = (D3D11Texture*) source->textureSlice.texture;
uint32_t srcSubresourceIndex = D3D11_INTERNAL_CalcSubresource( uint32_t srcSubresourceIndex = D3D11_INTERNAL_CalcSubresource(
source->textureSlice.mipLevel, source->textureSlice.mipLevel,
source->textureSlice.layer, source->textureSlice.layer,
srcTexture->levelCount srcTexture->levelCount
); );
D3D11Texture *dstTexture = destination->textureSlice.texture; D3D11Texture *dstTexture = (D3D11Texture*) destination->textureSlice.texture;
uint32_t dstSubresourceIndex = D3D11_INTERNAL_CalcSubresource( uint32_t dstSubresourceIndex = D3D11_INTERNAL_CalcSubresource(
destination->textureSlice.mipLevel, destination->textureSlice.mipLevel,
destination->textureSlice.layer, destination->textureSlice.layer,
@ -2344,6 +2325,21 @@ static void D3D11_CopyBufferToBuffer(
); );
} }
static void D3D11_GenerateMipmaps(
Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer,
Refresh_Texture *texture
) {
D3D11Renderer *renderer = (D3D11Renderer*) driverData;
D3D11CommandBuffer *d3d11CommandBuffer = (D3D11CommandBuffer*) commandBuffer;
D3D11Texture *d3d11Texture = (D3D11Texture*) texture;
ID3D11DeviceContext1_GenerateMips(
d3d11CommandBuffer->context,
d3d11Texture->shaderView
);
}
static void D3D11_EndCopyPass( static void D3D11_EndCopyPass(
Refresh_Renderer *driverData, Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer Refresh_CommandBuffer *commandBuffer
@ -2728,6 +2724,19 @@ static void D3D11_QueueDestroyGpuBuffer(
SDL_free(d3d11Buffer); SDL_free(d3d11Buffer);
} }
static void D3D11_QueueDestroyTransferBuffer(
Refresh_Renderer *driverData,
Refresh_TransferBuffer *transferBuffer
) {
D3D11TransferBufferContainer *container = (D3D11TransferBufferContainer*) transferBuffer;
for (uint32_t i = 0; i < container->bufferCount; i += 1)
{
SDL_free(container->buffers[i]);
}
SDL_free(container->buffers);
}
static void D3D11_QueueDestroyShaderModule( static void D3D11_QueueDestroyShaderModule(
Refresh_Renderer *driverData, Refresh_Renderer *driverData,
Refresh_ShaderModule *shaderModule Refresh_ShaderModule *shaderModule
@ -3312,6 +3321,13 @@ static void D3D11_BindIndexBuffer(
/* Compute State */ /* Compute State */
static void D3D11_BeginComputePass(
Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer
) {
/* no-op */
}
static void D3D11_BindComputePipeline( static void D3D11_BindComputePipeline(
Refresh_Renderer *driverData, Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer, Refresh_CommandBuffer *commandBuffer,
@ -3404,6 +3420,13 @@ static void D3D11_BindComputeTextures(
); );
} }
static void D3D11_EndComputePass(
Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer
) {
/* no-op */
}
/* Window and Swapchain Management */ /* Window and Swapchain Management */
static D3D11WindowData* D3D11_INTERNAL_FetchWindowData( static D3D11WindowData* D3D11_INTERNAL_FetchWindowData(
@ -3419,8 +3442,10 @@ static uint8_t D3D11_INTERNAL_InitializeSwapchainTexture(
) { ) {
ID3D11Texture2D *swapchainTexture; ID3D11Texture2D *swapchainTexture;
D3D11_RENDER_TARGET_VIEW_DESC rtvDesc; D3D11_RENDER_TARGET_VIEW_DESC rtvDesc;
D3D11_UNORDERED_ACCESS_VIEW_DESC uavDesc;
D3D11_TEXTURE2D_DESC textureDesc; D3D11_TEXTURE2D_DESC textureDesc;
ID3D11RenderTargetView *rtv; ID3D11RenderTargetView *rtv;
ID3D11UnorderedAccessView *uav;
HRESULT res; HRESULT res;
/* Clear all the texture data */ /* Clear all the texture data */
@ -3453,14 +3478,32 @@ static uint8_t D3D11_INTERNAL_InitializeSwapchainTexture(
return 0; return 0;
} }
uavDesc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2D;
uavDesc.Texture2D.MipSlice = 0;
res = ID3D11Device_CreateUnorderedAccessView(
renderer->device,
(ID3D11Resource *)swapchainTexture,
&uavDesc,
&uav
);
if (FAILED(res))
{
ID3D11RenderTargetView_Release(rtv);
ID3D11Texture2D_Release(swapchainTexture);
D3D11_INTERNAL_LogError(renderer->device, "Swapchain UAV creation failed", res);
return 0;
}
/* Fill out the texture struct */ /* Fill out the texture struct */
pTexture->handle = NULL; /* The texture does not "own" the swapchain texture, and it can change dynamically. */ pTexture->handle = NULL; /* The texture does not "own" the swapchain texture, and it can change dynamically. */
pTexture->shaderView = NULL; pTexture->shaderView = NULL;
pTexture->unorderedAccessView = NULL; pTexture->subresources = SDL_malloc(sizeof(D3D11TextureSubresource));
pTexture->targetViewCapacity = 1; pTexture->subresources[0].targetView = rtv;
pTexture->targetViewCount = 1; pTexture->subresources[0].uav = uav;
pTexture->targetViews = SDL_calloc(1, sizeof(D3D11TargetView)); pTexture->subresources[0].msaaHandle = NULL;
pTexture->targetViews[0].view = (ID3D11View*) rtv; pTexture->subresources[0].layer = 0;
pTexture->subresources[0].level = 0;
ID3D11Texture2D_GetDesc(swapchainTexture, &textureDesc); ID3D11Texture2D_GetDesc(swapchainTexture, &textureDesc);
pTexture->levelCount = textureDesc.MipLevels; pTexture->levelCount = textureDesc.MipLevels;
@ -3600,9 +3643,10 @@ static uint8_t D3D11_INTERNAL_ResizeSwapchain(
int32_t width, int32_t width,
int32_t height int32_t height
) { ) {
/* Release the old RTV */ /* Release the old views */
ID3D11RenderTargetView_Release(windowData->texture.targetViews[0].view); ID3D11RenderTargetView_Release(windowData->texture.subresources[0].targetView);
SDL_free(windowData->texture.targetViews); ID3D11UnorderedAccessView_Release(windowData->texture.subresources[0].uav);
SDL_free(windowData->texture.subresources);
/* Resize the swapchain */ /* Resize the swapchain */
HRESULT res = IDXGISwapChain_ResizeBuffers( HRESULT res = IDXGISwapChain_ResizeBuffers(
@ -3685,8 +3729,9 @@ static void D3D11_UnclaimWindow(
D3D11_Wait(driverData); D3D11_Wait(driverData);
ID3D11RenderTargetView_Release(windowData->texture.targetViews[0].view); ID3D11RenderTargetView_Release(windowData->texture.subresources[0].targetView);
SDL_free(windowData->texture.targetViews); ID3D11UnorderedAccessView_Release(windowData->texture.subresources[0].uav);
SDL_free(windowData->texture.subresources);
IDXGISwapChain_Release(windowData->swapchain); IDXGISwapChain_Release(windowData->swapchain);
SDL_LockMutex(renderer->windowLock); SDL_LockMutex(renderer->windowLock);