From 4eb4e8533d73b9463374ec8786ebf018c360fb7e Mon Sep 17 00:00:00 2001 From: Ethan Lee Date: Fri, 21 Jun 2024 14:35:34 -0400 Subject: [PATCH] Rework texture/buffer location/region structs (#52) Co-authored-by: Caleb Cornett --- include/SDL3/SDL_gpu.h | 122 +++++++++++++++++++------------- src/dynapi/SDL_dynapi_procs.h | 16 ++--- src/gpu/SDL_gpu.c | 62 ++++++++-------- src/gpu/SDL_gpu_driver.h | 39 +++++----- src/gpu/d3d11/SDL_gpu_d3d11.c | 106 +++++++++++++-------------- src/gpu/metal/SDL_gpu_metal.m | 97 ++++++++++++------------- src/gpu/vulkan/SDL_gpu_vulkan.c | 109 +++++++++++++--------------- test/testgpu_spinning_cube.c | 19 +++-- 8 files changed, 289 insertions(+), 281 deletions(-) diff --git a/include/SDL3/SDL_gpu.h b/include/SDL3/SDL_gpu.h index 43d20b6bc4009..0cbcfedf58496 100644 --- a/include/SDL3/SDL_gpu.h +++ b/include/SDL3/SDL_gpu.h @@ -408,6 +408,27 @@ typedef struct SDL_GpuViewport float maxDepth; } SDL_GpuViewport; +typedef struct SDL_GpuTextureTransferInfo +{ + SDL_GpuTransferBuffer *transferBuffer; + Uint32 offset; /* starting location of the image data */ + Uint32 imagePitch; /* number of pixels from one row to the next */ + Uint32 imageHeight; /* number of rows from one layer/depth-slice to the next */ +} SDL_GpuTextureTransferInfo; + +typedef struct SDL_GpuTransferBufferLocation +{ + SDL_GpuTransferBuffer *transferBuffer; + Uint32 offset; +} SDL_GpuTransferBufferLocation; + +typedef struct SDL_GpuTransferBufferRegion +{ + SDL_GpuTransferBuffer *transferBuffer; + Uint32 offset; + Uint32 size; +} SDL_GpuTransferBufferRegion; + typedef struct SDL_GpuTextureSlice { SDL_GpuTexture *texture; @@ -415,6 +436,14 @@ typedef struct SDL_GpuTextureSlice Uint32 layer; } SDL_GpuTextureSlice; +typedef struct SDL_GpuTextureLocation +{ + SDL_GpuTextureSlice textureSlice; + Uint32 x; + Uint32 y; + Uint32 z; +} SDL_GpuTextureLocation; + typedef struct SDL_GpuTextureRegion { SDL_GpuTextureSlice textureSlice; @@ -426,19 +455,18 @@ typedef struct SDL_GpuTextureRegion Uint32 d; } SDL_GpuTextureRegion; -typedef struct SDL_GpuBufferImageCopy +typedef struct SDL_GpuBufferLocation { - Uint32 bufferOffset; - Uint32 bufferStride; /* number of pixels from one row to the next */ - Uint32 bufferImageHeight; /* number of rows from one layer/depth-slice to the next */ -} SDL_GpuBufferImageCopy; + SDL_GpuBuffer *buffer; + Uint32 offset; +} SDL_GpuBufferLocation; -typedef struct SDL_GpuBufferCopy +typedef struct SDL_GpuBufferRegion { - Uint32 srcOffset; - Uint32 dstOffset; + SDL_GpuBuffer *buffer; + Uint32 offset; Uint32 size; -} SDL_GpuBufferCopy; +} SDL_GpuBufferRegion; typedef struct SDL_GpuIndirectDrawCommand { @@ -1634,35 +1662,31 @@ extern SDL_DECLSPEC void SDLCALL SDL_GpuUnmapTransferBuffer( * Immediately copies data from a pointer to a transfer buffer. * * \param device a GPU context - * \param data a pointer to data to copy into the transfer buffer - * \param transferBuffer a transfer buffer - * \param copyParams a struct containing parameters specifying copy offsets and size + * \param source a pointer to data to copy into the transfer buffer + * \param destination a transfer buffer with offset and size * \param cycle if SDL_TRUE, cycles the transfer buffer if it is bound, otherwise overwrites the data. * * \since This function is available since SDL 3.x.x */ extern SDL_DECLSPEC void SDLCALL SDL_GpuSetTransferData( SDL_GpuDevice *device, - const void *data, - SDL_GpuTransferBuffer *transferBuffer, - SDL_GpuBufferCopy *copyParams, + const void *source, + SDL_GpuTransferBufferRegion *destination, SDL_bool cycle); /** * Immediately copies data from a transfer buffer to a pointer. * * \param device a GPU context - * \param transferBuffer a transfer buffer - * \param data a data pointer - * \param copyParams a struct containing parameters specifying copy offsets and size + * \param source a transfer buffer with offset and size + * \param destination a data pointer * * \since This function is available since SDL 3.x.x */ extern SDL_DECLSPEC void SDLCALL SDL_GpuGetTransferData( SDL_GpuDevice *device, - SDL_GpuTransferBuffer *transferBuffer, - void *data, - SDL_GpuBufferCopy *copyParams); + SDL_GpuTransferBufferRegion *source, + void *destination); /* Copy Pass */ @@ -1689,18 +1713,16 @@ extern SDL_DECLSPEC SDL_GpuCopyPass *SDLCALL SDL_GpuBeginCopyPass( * the texel size of the texture format. * * \param copyPass a copy pass handle - * \param source the source transfer buffer + * \param source the source transfer buffer with image layout information * \param destination the destination texture region - * \param copyParams buffer offset, stride, and height * \param cycle if SDL_TRUE, cycles the texture if the texture slice is bound, otherwise overwrites the data. * * \since This function is available since SDL 3.x.x */ extern SDL_DECLSPEC void SDLCALL SDL_GpuUploadToTexture( SDL_GpuCopyPass *copyPass, - SDL_GpuTransferBuffer *source, + SDL_GpuTextureTransferInfo *source, SDL_GpuTextureRegion *destination, - SDL_GpuBufferImageCopy *copyParams, SDL_bool cycle); /* Uploads data from a TransferBuffer to a Buffer. */ @@ -1711,18 +1733,16 @@ extern SDL_DECLSPEC void SDLCALL SDL_GpuUploadToTexture( * You may assume that the upload has finished in subsequent commands. * * \param copyPass a copy pass handle - * \param source the source transfer buffer - * \param destination the destination buffer - * \param copyParams buffer offsets and length + * \param source the source transfer buffer with offset + * \param destination the destination buffer with offset and size * \param cycle if SDL_TRUE, cycles the buffer if it is bound, otherwise overwrites the data. * * \since This function is available since SDL 3.x.x */ extern SDL_DECLSPEC void SDLCALL SDL_GpuUploadToBuffer( SDL_GpuCopyPass *copyPass, - SDL_GpuTransferBuffer *source, - SDL_GpuBuffer *destination, - SDL_GpuBufferCopy *copyParams, + SDL_GpuTransferBufferLocation *source, + SDL_GpuBufferRegion *destination, SDL_bool cycle); /** @@ -1732,15 +1752,21 @@ extern SDL_DECLSPEC void SDLCALL SDL_GpuUploadToBuffer( * * \param copyPass a copy pass handle * \param source a source texture region - * \param destination must be the same dimensions as the source region + * \param destination a destination texture region + * \param w the width of the region to copy + * \param h the height of the region to copy + * \param d the depth of the region to copy * \param cycle if SDL_TRUE, cycles the destination texture if the destination texture slice is bound, otherwise overwrites the data. * * \since This function is available since SDL 3.x.x */ extern SDL_DECLSPEC void SDLCALL SDL_GpuCopyTextureToTexture( SDL_GpuCopyPass *copyPass, - SDL_GpuTextureRegion *source, - SDL_GpuTextureRegion *destination, + SDL_GpuTextureLocation *source, + SDL_GpuTextureLocation *destination, + Uint32 w, + Uint32 h, + Uint32 d, SDL_bool cycle); /* Copies data from a buffer to a buffer. */ @@ -1751,18 +1777,18 @@ extern SDL_DECLSPEC void SDLCALL SDL_GpuCopyTextureToTexture( * You may assume the copy has finished in subsequent commands. * * \param copyPass a copy pass handle - * \param source the buffer to copy from - * \param destination the buffer to copy to - * \param copyParams a struct containing offset and length data + * \param source the buffer and offset to copy from + * \param destination the buffer and offset to copy to + * \param size the length of the buffer to copy * \param cycle if SDL_TRUE, cycles the destination buffer if it is bound, otherwise overwrites the data. * * \since This function is available since SDL 3.x.x */ extern SDL_DECLSPEC void SDLCALL SDL_GpuCopyBufferToBuffer( SDL_GpuCopyPass *copyPass, - SDL_GpuBuffer *source, - SDL_GpuBuffer *destination, - SDL_GpuBufferCopy *copyParams, + SDL_GpuBufferLocation *source, + SDL_GpuBufferLocation *destination, + Uint32 size, SDL_bool cycle); /** @@ -1783,33 +1809,29 @@ extern SDL_DECLSPEC void SDLCALL SDL_GpuGenerateMipmaps( * * \param copyPass a copy pass handle * \param source the source texture region - * \param destination the destination transfer buffer - * \param copyParams a struct containing parameters specifying buffer offset, stride, and height + * \param destination the destination transfer buffer with image layout information * * \since This function is available since SDL 3.x.x */ extern SDL_DECLSPEC void SDLCALL SDL_GpuDownloadFromTexture( SDL_GpuCopyPass *copyPass, SDL_GpuTextureRegion *source, - SDL_GpuTransferBuffer *destination, - SDL_GpuBufferImageCopy *copyParams); + SDL_GpuTextureTransferInfo *destination); /** * Copies data from a buffer to a transfer buffer on the GPU timeline. * This data is not guaranteed to be copied until the command buffer fence is signaled. * * \param copyPass a copy pass handle - * \param source the source buffer - * \param destination the destination transfer buffer - * \param copyParams a struct containing offsets and length + * \param source the source buffer with offset and size + * \param destination the destination transfer buffer with offset * * \since This function is available since SDL 3.x.x */ extern SDL_DECLSPEC void SDLCALL SDL_GpuDownloadFromBuffer( SDL_GpuCopyPass *copyPass, - SDL_GpuBuffer *source, - SDL_GpuTransferBuffer *destination, - SDL_GpuBufferCopy *copyParams); + SDL_GpuBufferRegion *source, + SDL_GpuTransferBufferLocation *destination); /** * Ends the current copy pass. diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h index 4dc4ac0af7d00..c71c9a196ec76 100644 --- a/src/dynapi/SDL_dynapi_procs.h +++ b/src/dynapi/SDL_dynapi_procs.h @@ -1141,16 +1141,16 @@ SDL_DYNAPI_PROC(void,SDL_GpuDispatchCompute,(SDL_GpuComputePass *a, Uint32 b, Ui SDL_DYNAPI_PROC(void,SDL_GpuEndComputePass,(SDL_GpuComputePass *a),(a),) SDL_DYNAPI_PROC(void,SDL_GpuMapTransferBuffer,(SDL_GpuDevice *a, SDL_GpuTransferBuffer *b, SDL_bool c, void **d),(a,b,c,d),) SDL_DYNAPI_PROC(void,SDL_GpuUnmapTransferBuffer,(SDL_GpuDevice *a, SDL_GpuTransferBuffer *b),(a,b),) -SDL_DYNAPI_PROC(void,SDL_GpuSetTransferData,(SDL_GpuDevice *a, const void *b, SDL_GpuTransferBuffer *c, SDL_GpuBufferCopy *d, SDL_bool e),(a,b,c,d,e),) -SDL_DYNAPI_PROC(void,SDL_GpuGetTransferData,(SDL_GpuDevice *a, SDL_GpuTransferBuffer *b, void *c, SDL_GpuBufferCopy *d),(a,b,c,d),) +SDL_DYNAPI_PROC(void,SDL_GpuSetTransferData,(SDL_GpuDevice *a, const void *b, SDL_GpuTransferBufferRegion *c, SDL_bool d),(a,b,c,d),) +SDL_DYNAPI_PROC(void,SDL_GpuGetTransferData,(SDL_GpuDevice *a, SDL_GpuTransferBufferRegion *b, void *c),(a,b,c),) SDL_DYNAPI_PROC(SDL_GpuCopyPass*,SDL_GpuBeginCopyPass,(SDL_GpuCommandBuffer *a),(a),return) -SDL_DYNAPI_PROC(void,SDL_GpuUploadToTexture,(SDL_GpuCopyPass *a, SDL_GpuTransferBuffer *b, SDL_GpuTextureRegion *c, SDL_GpuBufferImageCopy *d, SDL_bool e),(a,b,c,d,e),) -SDL_DYNAPI_PROC(void,SDL_GpuUploadToBuffer,(SDL_GpuCopyPass *a, SDL_GpuTransferBuffer *b, SDL_GpuBuffer *c, SDL_GpuBufferCopy *d, SDL_bool e),(a,b,c,d,e),) -SDL_DYNAPI_PROC(void,SDL_GpuCopyTextureToTexture,(SDL_GpuCopyPass *a, SDL_GpuTextureRegion *b, SDL_GpuTextureRegion *c, SDL_bool d),(a,b,c,d),) -SDL_DYNAPI_PROC(void,SDL_GpuCopyBufferToBuffer,(SDL_GpuCopyPass *a, SDL_GpuBuffer *b, SDL_GpuBuffer *c, SDL_GpuBufferCopy *d, SDL_bool e),(a,b,c,d,e),) +SDL_DYNAPI_PROC(void,SDL_GpuUploadToTexture,(SDL_GpuCopyPass *a, SDL_GpuTextureTransferInfo *b, SDL_GpuTextureRegion *c, SDL_bool d),(a,b,c,d),) +SDL_DYNAPI_PROC(void,SDL_GpuUploadToBuffer,(SDL_GpuCopyPass *a, SDL_GpuTransferBufferLocation *b, SDL_GpuBufferRegion *c, SDL_bool d),(a,b,c,d),) +SDL_DYNAPI_PROC(void,SDL_GpuCopyTextureToTexture,(SDL_GpuCopyPass *a, SDL_GpuTextureLocation *b, SDL_GpuTextureLocation *c, Uint32 d, Uint32 e, Uint32 f, SDL_bool g),(a,b,c,d,e,f,g),) +SDL_DYNAPI_PROC(void,SDL_GpuCopyBufferToBuffer,(SDL_GpuCopyPass *a, SDL_GpuBufferLocation *b, SDL_GpuBufferLocation *c, Uint32 d, SDL_bool e),(a,b,c,d,e),) SDL_DYNAPI_PROC(void,SDL_GpuGenerateMipmaps,(SDL_GpuCopyPass *a, SDL_GpuTexture *b),(a,b),) -SDL_DYNAPI_PROC(void,SDL_GpuDownloadFromTexture,(SDL_GpuCopyPass *a, SDL_GpuTextureRegion *b, SDL_GpuTransferBuffer *c, SDL_GpuBufferImageCopy *d),(a,b,c,d),) -SDL_DYNAPI_PROC(void,SDL_GpuDownloadFromBuffer,(SDL_GpuCopyPass *a, SDL_GpuBuffer *b, SDL_GpuTransferBuffer *c, SDL_GpuBufferCopy *d),(a,b,c,d),) +SDL_DYNAPI_PROC(void,SDL_GpuDownloadFromTexture,(SDL_GpuCopyPass *a, SDL_GpuTextureRegion *b, SDL_GpuTextureTransferInfo *c),(a,b,c),) +SDL_DYNAPI_PROC(void,SDL_GpuDownloadFromBuffer,(SDL_GpuCopyPass *a, SDL_GpuBufferRegion *b, SDL_GpuTransferBufferLocation *c),(a,b,c),) SDL_DYNAPI_PROC(void,SDL_GpuEndCopyPass,(SDL_GpuCopyPass *a),(a),) SDL_DYNAPI_PROC(void,SDL_GpuBlit,(SDL_GpuCommandBuffer *a, SDL_GpuTextureRegion *b, SDL_GpuTextureRegion *c, SDL_GpuFilter d, SDL_bool e),(a,b,c,d,e),) SDL_DYNAPI_PROC(SDL_bool,SDL_GpuSupportsSwapchainComposition,(SDL_GpuDevice *a, SDL_Window *b, SDL_GpuSwapchainComposition c),(a,b,c),return) diff --git a/src/gpu/SDL_gpu.c b/src/gpu/SDL_gpu.c index abb4fc13d936f..49b6ecbabdfe1 100644 --- a/src/gpu/SDL_gpu.c +++ b/src/gpu/SDL_gpu.c @@ -1035,32 +1035,28 @@ void SDL_GpuUnmapTransferBuffer( void SDL_GpuSetTransferData( SDL_GpuDevice *device, - const void *data, - SDL_GpuTransferBuffer *transferBuffer, - SDL_GpuBufferCopy *copyParams, + const void *source, + SDL_GpuTransferBufferRegion *destination, SDL_bool cycle) { NULL_ASSERT(device) device->SetTransferData( device->driverData, - data, - transferBuffer, - copyParams, + source, + destination, cycle); } void SDL_GpuGetTransferData( SDL_GpuDevice *device, - SDL_GpuTransferBuffer *transferBuffer, - void *data, - SDL_GpuBufferCopy *copyParams) + SDL_GpuTransferBufferRegion *source, + void *destination) { NULL_ASSERT(device) device->GetTransferData( device->driverData, - transferBuffer, - data, - copyParams); + source, + destination); } /* Copy Pass */ @@ -1082,9 +1078,8 @@ SDL_GpuCopyPass *SDL_GpuBeginCopyPass( void SDL_GpuUploadToTexture( SDL_GpuCopyPass *copyPass, - SDL_GpuTransferBuffer *source, + SDL_GpuTextureTransferInfo *source, SDL_GpuTextureRegion *destination, - SDL_GpuBufferImageCopy *copyParams, SDL_bool cycle) { NULL_ASSERT(copyPass) @@ -1093,15 +1088,13 @@ void SDL_GpuUploadToTexture( COPYPASS_COMMAND_BUFFER, source, destination, - copyParams, cycle); } void SDL_GpuUploadToBuffer( SDL_GpuCopyPass *copyPass, - SDL_GpuTransferBuffer *source, - SDL_GpuBuffer *destination, - SDL_GpuBufferCopy *copyParams, + SDL_GpuTransferBufferLocation *source, + SDL_GpuBufferRegion *destination, SDL_bool cycle) { NULL_ASSERT(copyPass) @@ -1109,14 +1102,16 @@ void SDL_GpuUploadToBuffer( COPYPASS_COMMAND_BUFFER, source, destination, - copyParams, cycle); } void SDL_GpuCopyTextureToTexture( SDL_GpuCopyPass *copyPass, - SDL_GpuTextureRegion *source, - SDL_GpuTextureRegion *destination, + SDL_GpuTextureLocation *source, + SDL_GpuTextureLocation *destination, + Uint32 w, + Uint32 h, + Uint32 d, SDL_bool cycle) { NULL_ASSERT(copyPass) @@ -1124,14 +1119,17 @@ void SDL_GpuCopyTextureToTexture( COPYPASS_COMMAND_BUFFER, source, destination, + w, + h, + d, cycle); } void SDL_GpuCopyBufferToBuffer( SDL_GpuCopyPass *copyPass, - SDL_GpuBuffer *source, - SDL_GpuBuffer *destination, - SDL_GpuBufferCopy *copyParams, + SDL_GpuBufferLocation *source, + SDL_GpuBufferLocation *destination, + Uint32 size, SDL_bool cycle) { NULL_ASSERT(copyPass) @@ -1139,7 +1137,7 @@ void SDL_GpuCopyBufferToBuffer( COPYPASS_COMMAND_BUFFER, source, destination, - copyParams, + size, cycle); } @@ -1156,29 +1154,25 @@ void SDL_GpuGenerateMipmaps( void SDL_GpuDownloadFromTexture( SDL_GpuCopyPass *copyPass, SDL_GpuTextureRegion *source, - SDL_GpuTransferBuffer *destination, - SDL_GpuBufferImageCopy *copyParams) + SDL_GpuTextureTransferInfo *destination) { NULL_ASSERT(copyPass); COPYPASS_DEVICE->DownloadFromTexture( COPYPASS_COMMAND_BUFFER, source, - destination, - copyParams); + destination); } void SDL_GpuDownloadFromBuffer( SDL_GpuCopyPass *copyPass, - SDL_GpuBuffer *source, - SDL_GpuTransferBuffer *destination, - SDL_GpuBufferCopy *copyParams) + SDL_GpuBufferRegion *source, + SDL_GpuTransferBufferLocation *destination) { NULL_ASSERT(copyPass); COPYPASS_DEVICE->DownloadFromBuffer( COPYPASS_COMMAND_BUFFER, source, - destination, - copyParams); + destination); } void SDL_GpuEndCopyPass( diff --git a/src/gpu/SDL_gpu_driver.h b/src/gpu/SDL_gpu_driver.h index e6f08fa3f9029..ccad9f587f5be 100644 --- a/src/gpu/SDL_gpu_driver.h +++ b/src/gpu/SDL_gpu_driver.h @@ -449,16 +449,14 @@ struct SDL_GpuDevice void (*SetTransferData)( SDL_GpuRenderer *driverData, - const void *data, - SDL_GpuTransferBuffer *transferBuffer, - SDL_GpuBufferCopy *copyParams, + const void *source, + SDL_GpuTransferBufferRegion *destination, SDL_bool cycle); void (*GetTransferData)( SDL_GpuRenderer *driverData, - SDL_GpuTransferBuffer *transferBuffer, - void *data, - SDL_GpuBufferCopy *copyParams); + SDL_GpuTransferBufferRegion *source, + void *destination); /* Copy Pass */ @@ -467,29 +465,30 @@ struct SDL_GpuDevice void (*UploadToTexture)( SDL_GpuCommandBuffer *commandBuffer, - SDL_GpuTransferBuffer *source, + SDL_GpuTextureTransferInfo *source, SDL_GpuTextureRegion *destination, - SDL_GpuBufferImageCopy *copyParams, SDL_bool cycle); void (*UploadToBuffer)( SDL_GpuCommandBuffer *commandBuffer, - SDL_GpuTransferBuffer *source, - SDL_GpuBuffer *destination, - SDL_GpuBufferCopy *copyParams, + SDL_GpuTransferBufferLocation *source, + SDL_GpuBufferRegion *destination, SDL_bool cycle); void (*CopyTextureToTexture)( SDL_GpuCommandBuffer *commandBuffer, - SDL_GpuTextureRegion *source, - SDL_GpuTextureRegion *destination, + SDL_GpuTextureLocation *source, + SDL_GpuTextureLocation *destination, + Uint32 w, + Uint32 h, + Uint32 d, SDL_bool cycle); void (*CopyBufferToBuffer)( SDL_GpuCommandBuffer *commandBuffer, - SDL_GpuBuffer *source, - SDL_GpuBuffer *destination, - SDL_GpuBufferCopy *copyParams, + SDL_GpuBufferLocation *source, + SDL_GpuBufferLocation *destination, + Uint32 size, SDL_bool cycle); void (*GenerateMipmaps)( @@ -499,14 +498,12 @@ struct SDL_GpuDevice void (*DownloadFromTexture)( SDL_GpuCommandBuffer *commandBuffer, SDL_GpuTextureRegion *source, - SDL_GpuTransferBuffer *destination, - SDL_GpuBufferImageCopy *copyParams); + SDL_GpuTextureTransferInfo *destination); void (*DownloadFromBuffer)( SDL_GpuCommandBuffer *commandBuffer, - SDL_GpuBuffer *source, - SDL_GpuTransferBuffer *destination, - SDL_GpuBufferCopy *copyParams); + SDL_GpuBufferRegion *source, + SDL_GpuTransferBufferLocation *destination); void (*EndCopyPass)( SDL_GpuCommandBuffer *commandBuffer); diff --git a/src/gpu/d3d11/SDL_gpu_d3d11.c b/src/gpu/d3d11/SDL_gpu_d3d11.c index 2fef227c56e85..fccdcd72acc92 100644 --- a/src/gpu/d3d11/SDL_gpu_d3d11.c +++ b/src/gpu/d3d11/SDL_gpu_d3d11.c @@ -2716,38 +2716,35 @@ static void D3D11_UnmapTransferBuffer( static void D3D11_SetTransferData( SDL_GpuRenderer *driverData, - const void *data, - SDL_GpuTransferBuffer *transferBuffer, - SDL_GpuBufferCopy *copyParams, + const void *source, + SDL_GpuTransferBufferRegion *destination, SDL_bool cycle) { - D3D11TransferBufferContainer *container = (D3D11TransferBufferContainer *)transferBuffer; + D3D11TransferBufferContainer *container = (D3D11TransferBufferContainer *)destination->transferBuffer; void *dataPtr; - D3D11_MapTransferBuffer(driverData, transferBuffer, cycle, &dataPtr); + D3D11_MapTransferBuffer(driverData, destination->transferBuffer, cycle, &dataPtr); SDL_memcpy( - ((Uint8 *)container->activeBuffer->data) + copyParams->dstOffset, - ((Uint8 *)data) + copyParams->srcOffset, - copyParams->size); + ((Uint8 *)container->activeBuffer->data) + destination->offset, + source, + destination->size); - D3D11_UnmapTransferBuffer(driverData, transferBuffer); + D3D11_UnmapTransferBuffer(driverData, destination->transferBuffer); } static void D3D11_GetTransferData( SDL_GpuRenderer *driverData, - SDL_GpuTransferBuffer *transferBuffer, - void *data, - SDL_GpuBufferCopy *copyParams) + SDL_GpuTransferBufferRegion *source, + void *destination) { - (void)driverData; - D3D11TransferBufferContainer *container = (D3D11TransferBufferContainer *)transferBuffer; - D3D11TransferBuffer *d3d11TransferBuffer = container->activeBuffer; + (void)driverData; + D3D11TransferBufferContainer *container = (D3D11TransferBufferContainer *)source->transferBuffer; SDL_memcpy( - ((Uint8 *)data) + copyParams->dstOffset, - d3d11TransferBuffer->data + copyParams->srcOffset, - copyParams->size + destination, + ((Uint8 *)container->activeBuffer->data) + source->offset, + source->size ); } @@ -2761,18 +2758,17 @@ static void D3D11_BeginCopyPass( static void D3D11_UploadToTexture( SDL_GpuCommandBuffer *commandBuffer, - SDL_GpuTransferBuffer *source, + SDL_GpuTextureTransferInfo *source, SDL_GpuTextureRegion *destination, - SDL_GpuBufferImageCopy *copyParams, SDL_bool cycle) { D3D11CommandBuffer *d3d11CommandBuffer = (D3D11CommandBuffer *)commandBuffer; D3D11Renderer *renderer = (D3D11Renderer *)d3d11CommandBuffer->renderer; - D3D11TransferBufferContainer *transferContainer = (D3D11TransferBufferContainer *)source; + D3D11TransferBufferContainer *transferContainer = (D3D11TransferBufferContainer *)source->transferBuffer; D3D11TransferBuffer *d3d11TransferBuffer = transferContainer->activeBuffer; D3D11TextureContainer *d3d11TextureContainer = (D3D11TextureContainer *)destination->textureSlice.texture; - Uint32 bufferStride = copyParams->bufferStride; - Uint32 bufferImageHeight = copyParams->bufferImageHeight; + Uint32 bufferStride = source->imagePitch; + Uint32 bufferImageHeight = source->imageHeight; Sint32 w = destination->w; Sint32 h = destination->h; D3D11Texture *stagingTexture; @@ -2812,7 +2808,7 @@ static void D3D11_UploadToTexture( stagingTextureCreateInfo.sampleCount = SDL_GPU_SAMPLECOUNT_1; stagingTextureCreateInfo.format = ((D3D11TextureContainer *)destination->textureSlice.texture)->createInfo.format; - initialData.pSysMem = d3d11TransferBuffer->data + copyParams->bufferOffset; + initialData.pSysMem = d3d11TransferBuffer->data + source->offset; initialData.SysMemPitch = bufferStride; initialData.SysMemSlicePitch = bufferStride * bufferImageHeight; @@ -2848,16 +2844,15 @@ static void D3D11_UploadToTexture( static void D3D11_UploadToBuffer( SDL_GpuCommandBuffer *commandBuffer, - SDL_GpuTransferBuffer *source, - SDL_GpuBuffer *destination, - SDL_GpuBufferCopy *copyParams, + SDL_GpuTransferBufferLocation *source, + SDL_GpuBufferRegion *destination, SDL_bool cycle) { D3D11CommandBuffer *d3d11CommandBuffer = (D3D11CommandBuffer *)commandBuffer; D3D11Renderer *renderer = (D3D11Renderer *)d3d11CommandBuffer->renderer; - D3D11TransferBufferContainer *transferContainer = (D3D11TransferBufferContainer *)source; + D3D11TransferBufferContainer *transferContainer = (D3D11TransferBufferContainer *)source->transferBuffer; D3D11TransferBuffer *d3d11TransferBuffer = transferContainer->activeBuffer; - D3D11BufferContainer *bufferContainer = (D3D11BufferContainer *)destination; + D3D11BufferContainer *bufferContainer = (D3D11BufferContainer *)destination->buffer; D3D11Buffer *d3d11Buffer = D3D11_INTERNAL_PrepareBufferForWrite( renderer, bufferContainer, @@ -2868,14 +2863,14 @@ static void D3D11_UploadToBuffer( HRESULT res; /* Upload to staging buffer immediately */ - stagingBufferDesc.ByteWidth = copyParams->size; + stagingBufferDesc.ByteWidth = destination->size; stagingBufferDesc.Usage = D3D11_USAGE_STAGING; stagingBufferDesc.BindFlags = 0; stagingBufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; stagingBufferDesc.MiscFlags = 0; stagingBufferDesc.StructureByteStride = 0; - stagingBufferData.pSysMem = d3d11TransferBuffer->data + copyParams->srcOffset; + stagingBufferData.pSysMem = d3d11TransferBuffer->data + source->offset; stagingBufferData.SysMemPitch = 0; stagingBufferData.SysMemSlicePitch = 0; @@ -2892,7 +2887,7 @@ static void D3D11_UploadToBuffer( d3d11CommandBuffer->context, (ID3D11Resource *)d3d11Buffer->handle, 0, - copyParams->dstOffset, + destination->offset, 0, 0, (ID3D11Resource *)stagingBuffer, @@ -2910,12 +2905,11 @@ static void D3D11_UploadToBuffer( static void D3D11_DownloadFromTexture( SDL_GpuCommandBuffer *commandBuffer, SDL_GpuTextureRegion *source, - SDL_GpuTransferBuffer *destination, - SDL_GpuBufferImageCopy *copyParams) + SDL_GpuTextureTransferInfo *destination) { D3D11CommandBuffer *d3d11CommandBuffer = (D3D11CommandBuffer *)commandBuffer; D3D11Renderer *renderer = d3d11CommandBuffer->renderer; - D3D11TransferBufferContainer *container = (D3D11TransferBufferContainer *)destination; + D3D11TransferBufferContainer *container = (D3D11TransferBufferContainer *)destination->transferBuffer; D3D11TransferBuffer *d3d11TransferBuffer = container->activeBuffer; D3D11TextureContainer *d3d11TextureContainer = (D3D11TextureContainer *)source->textureSlice.texture; D3D11_TEXTURE2D_DESC stagingDesc2D; @@ -2925,8 +2919,8 @@ static void D3D11_DownloadFromTexture( source->textureSlice.layer, source->textureSlice.mipLevel); D3D11TextureDownload *textureDownload; - Uint32 bufferStride = copyParams->bufferStride; - Uint32 bufferImageHeight = copyParams->bufferImageHeight; + Uint32 bufferStride = destination->imagePitch; + Uint32 bufferImageHeight = destination->imageHeight; Uint32 bytesPerRow, bytesPerDepthSlice; D3D11_BOX srcBox = { source->x, source->y, source->z, source->x + source->w, source->y + source->h, 1 }; HRESULT res; @@ -2990,7 +2984,7 @@ static void D3D11_DownloadFromTexture( textureDownload->width = source->w; textureDownload->height = source->h; textureDownload->depth = source->d; - textureDownload->bufferOffset = copyParams->bufferOffset; + textureDownload->bufferOffset = destination->offset; textureDownload->bytesPerRow = bytesPerRow; textureDownload->bytesPerDepthSlice = bytesPerDepthSlice; @@ -3012,17 +3006,16 @@ static void D3D11_DownloadFromTexture( static void D3D11_DownloadFromBuffer( SDL_GpuCommandBuffer *commandBuffer, - SDL_GpuBuffer *source, - SDL_GpuTransferBuffer *destination, - SDL_GpuBufferCopy *copyParams) + SDL_GpuBufferRegion *source, + SDL_GpuTransferBufferLocation *destination) { D3D11CommandBuffer *d3d11CommandBuffer = (D3D11CommandBuffer *)commandBuffer; D3D11Renderer *renderer = d3d11CommandBuffer->renderer; - D3D11TransferBufferContainer *container = (D3D11TransferBufferContainer *)destination; + D3D11TransferBufferContainer *container = (D3D11TransferBufferContainer *)destination->transferBuffer; D3D11TransferBuffer *d3d11TransferBuffer = container->activeBuffer; - D3D11BufferContainer *d3d11BufferContainer = (D3D11BufferContainer *)source; + D3D11BufferContainer *d3d11BufferContainer = (D3D11BufferContainer *)source->buffer; D3D11BufferDownload *bufferDownload; - D3D11_BOX srcBox = { copyParams->srcOffset, 0, 0, copyParams->size, 1, 1 }; + D3D11_BOX srcBox = { source->offset, 0, 0, source->size, 1, 1 }; D3D11_BUFFER_DESC stagingBufferDesc; HRESULT res; @@ -3037,7 +3030,7 @@ static void D3D11_DownloadFromBuffer( bufferDownload = &d3d11TransferBuffer->bufferDownloads[d3d11TransferBuffer->bufferDownloadCount]; d3d11TransferBuffer->bufferDownloadCount += 1; - stagingBufferDesc.ByteWidth = copyParams->size; + stagingBufferDesc.ByteWidth = source->size; stagingBufferDesc.Usage = D3D11_USAGE_STAGING; stagingBufferDesc.BindFlags = 0; stagingBufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ; @@ -3064,8 +3057,8 @@ static void D3D11_DownloadFromBuffer( &srcBox, D3D11_COPY_NO_OVERWRITE); - bufferDownload->dstOffset = copyParams->dstOffset; - bufferDownload->size = copyParams->size; + bufferDownload->dstOffset = destination->offset; + bufferDownload->size = source->size; D3D11_INTERNAL_TrackBuffer(d3d11CommandBuffer, d3d11BufferContainer->activeBuffer); D3D11_INTERNAL_TrackTransferBuffer(d3d11CommandBuffer, d3d11TransferBuffer); @@ -3073,8 +3066,11 @@ static void D3D11_DownloadFromBuffer( static void D3D11_CopyTextureToTexture( SDL_GpuCommandBuffer *commandBuffer, - SDL_GpuTextureRegion *source, - SDL_GpuTextureRegion *destination, + SDL_GpuTextureLocation *source, + SDL_GpuTextureLocation *destination, + Uint32 w, + Uint32 h, + Uint32 d, SDL_bool cycle) { D3D11CommandBuffer *d3d11CommandBuffer = (D3D11CommandBuffer *)commandBuffer; @@ -3082,7 +3078,7 @@ static void D3D11_CopyTextureToTexture( D3D11TextureContainer *srcContainer = (D3D11TextureContainer *)source->textureSlice.texture; D3D11TextureContainer *dstContainer = (D3D11TextureContainer *)destination->textureSlice.texture; - D3D11_BOX srcBox = { source->x, source->y, source->z, source->x + source->w, source->y + source->h, 1 }; + D3D11_BOX srcBox = { source->x, source->y, source->z, source->x + w, source->y + h, 1 }; D3D11TextureSubresource *srcSubresource = D3D11_INTERNAL_FetchTextureSubresource( srcContainer->activeTexture, @@ -3114,16 +3110,16 @@ static void D3D11_CopyTextureToTexture( static void D3D11_CopyBufferToBuffer( SDL_GpuCommandBuffer *commandBuffer, - SDL_GpuBuffer *source, - SDL_GpuBuffer *destination, - SDL_GpuBufferCopy *copyParams, + SDL_GpuBufferLocation *source, + SDL_GpuBufferLocation *destination, + Uint32 size, SDL_bool cycle) { D3D11CommandBuffer *d3d11CommandBuffer = (D3D11CommandBuffer *)commandBuffer; D3D11Renderer *renderer = (D3D11Renderer *)d3d11CommandBuffer->renderer; D3D11BufferContainer *srcBufferContainer = (D3D11BufferContainer *)source; D3D11BufferContainer *dstBufferContainer = (D3D11BufferContainer *)destination; - D3D11_BOX srcBox = { copyParams->srcOffset, 0, 0, copyParams->srcOffset + copyParams->size, 1, 1 }; + D3D11_BOX srcBox = { source->offset, 0, 0, source->offset + size, 1, 1 }; D3D11Buffer *srcBuffer = srcBufferContainer->activeBuffer; D3D11Buffer *dstBuffer = D3D11_INTERNAL_PrepareBufferForWrite( @@ -3135,7 +3131,7 @@ static void D3D11_CopyBufferToBuffer( d3d11CommandBuffer->context, (ID3D11Resource *)dstBuffer->handle, 0, - copyParams->dstOffset, + destination->offset, 0, 0, (ID3D11Resource *)srcBuffer->handle, diff --git a/src/gpu/metal/SDL_gpu_metal.m b/src/gpu/metal/SDL_gpu_metal.m index db1b8bf724043..2f95e166374e5 100644 --- a/src/gpu/metal/SDL_gpu_metal.m +++ b/src/gpu/metal/SDL_gpu_metal.m @@ -1554,13 +1554,12 @@ static void METAL_UnmapTransferBuffer( static void METAL_SetTransferData( SDL_GpuRenderer *driverData, - const void *data, - SDL_GpuTransferBuffer *transferBuffer, - SDL_GpuBufferCopy *copyParams, + const void *source, + SDL_GpuTransferBufferRegion *destination, SDL_bool cycle) { MetalRenderer *renderer = (MetalRenderer *)driverData; - MetalBufferContainer *container = (MetalBufferContainer *)transferBuffer; + MetalBufferContainer *container = (MetalBufferContainer *)destination->transferBuffer; MetalBuffer *buffer = container->activeBuffer; /* Rotate the transfer buffer if necessary */ @@ -1572,29 +1571,28 @@ static void METAL_SetTransferData( } SDL_memcpy( - ((Uint8 *)buffer->handle.contents) + copyParams->dstOffset, - ((Uint8 *)data) + copyParams->srcOffset, - copyParams->size); + ((Uint8 *)buffer->handle.contents) + destination->offset, + ((Uint8 *)source), + destination->size); #ifdef SDL_PLATFORM_MACOS /* FIXME: Is this necessary? */ if (buffer->handle.storageMode == MTLStorageModeManaged) { - [buffer->handle didModifyRange:NSMakeRange(copyParams->dstOffset, copyParams->size)]; + [buffer->handle didModifyRange:NSMakeRange(destination->offset, destination->size)]; } #endif } static void METAL_GetTransferData( SDL_GpuRenderer *driverData, - SDL_GpuTransferBuffer *transferBuffer, - void *data, - SDL_GpuBufferCopy *copyParams) + SDL_GpuTransferBufferRegion *source, + void *destination) { - MetalBufferContainer *transferBufferContainer = (MetalBufferContainer *)transferBuffer; + MetalBufferContainer *transferBufferContainer = (MetalBufferContainer *)source->transferBuffer; SDL_memcpy( - ((Uint8 *)data) + copyParams->dstOffset, - ((Uint8 *)transferBufferContainer->activeBuffer->handle.contents) + copyParams->srcOffset, - copyParams->size); + ((Uint8 *)destination), + ((Uint8 *)transferBufferContainer->activeBuffer->handle.contents) + source->offset, + source->size); } /* Copy Pass */ @@ -1608,21 +1606,20 @@ static void METAL_BeginCopyPass( static void METAL_UploadToTexture( SDL_GpuCommandBuffer *commandBuffer, - SDL_GpuTransferBuffer *source, + SDL_GpuTextureTransferInfo *source, SDL_GpuTextureRegion *destination, - SDL_GpuBufferImageCopy *copyParams, SDL_bool cycle) { MetalCommandBuffer *metalCommandBuffer = (MetalCommandBuffer *)commandBuffer; MetalRenderer *renderer = metalCommandBuffer->renderer; - MetalBufferContainer *bufferContainer = (MetalBufferContainer *)source; + MetalBufferContainer *bufferContainer = (MetalBufferContainer *)source->transferBuffer; MetalTextureContainer *textureContainer = (MetalTextureContainer *)destination->textureSlice.texture; MetalTexture *metalTexture = METAL_INTERNAL_PrepareTextureForWrite(renderer, textureContainer, cycle); [metalCommandBuffer->blitEncoder copyFromBuffer:bufferContainer->activeBuffer->handle - sourceOffset:copyParams->bufferOffset + sourceOffset:source->offset sourceBytesPerRow:BytesPerRow(destination->w, textureContainer->createInfo.format) sourceBytesPerImage:BytesPerImage(destination->w, destination->h, textureContainer->createInfo.format) sourceSize:MTLSizeMake(destination->w, destination->h, destination->d) @@ -1637,15 +1634,14 @@ static void METAL_UploadToTexture( static void METAL_UploadToBuffer( SDL_GpuCommandBuffer *commandBuffer, - SDL_GpuTransferBuffer *source, - SDL_GpuBuffer *destination, - SDL_GpuBufferCopy *copyParams, + SDL_GpuTransferBufferLocation *source, + SDL_GpuBufferRegion *destination, SDL_bool cycle) { MetalCommandBuffer *metalCommandBuffer = (MetalCommandBuffer *)commandBuffer; MetalRenderer *renderer = metalCommandBuffer->renderer; - MetalBufferContainer *transferContainer = (MetalBufferContainer *)source; - MetalBufferContainer *bufferContainer = (MetalBufferContainer *)destination; + MetalBufferContainer *transferContainer = (MetalBufferContainer *)source->transferBuffer; + MetalBufferContainer *bufferContainer = (MetalBufferContainer *)destination->buffer; MetalBuffer *metalBuffer = METAL_INTERNAL_PrepareBufferForWrite( renderer, @@ -1654,10 +1650,10 @@ static void METAL_UploadToBuffer( [metalCommandBuffer->blitEncoder copyFromBuffer:transferContainer->activeBuffer->handle - sourceOffset:copyParams->srcOffset + sourceOffset:source->offset toBuffer:metalBuffer->handle - destinationOffset:copyParams->dstOffset - size:copyParams->size]; + destinationOffset:destination->offset + size:destination->size]; METAL_INTERNAL_TrackBuffer(metalCommandBuffer, metalBuffer); METAL_INTERNAL_TrackBuffer(metalCommandBuffer, transferContainer->activeBuffer); @@ -1665,8 +1661,11 @@ static void METAL_UploadToBuffer( static void METAL_CopyTextureToTexture( SDL_GpuCommandBuffer *commandBuffer, - SDL_GpuTextureRegion *source, - SDL_GpuTextureRegion *destination, + SDL_GpuTextureLocation *source, + SDL_GpuTextureLocation *destination, + Uint32 w, + Uint32 h, + Uint32 d, SDL_bool cycle) { MetalCommandBuffer *metalCommandBuffer = (MetalCommandBuffer *)commandBuffer; @@ -1685,7 +1684,7 @@ static void METAL_CopyTextureToTexture( sourceSlice:source->textureSlice.layer sourceLevel:source->textureSlice.mipLevel sourceOrigin:MTLOriginMake(source->x, source->y, source->z) - sourceSize:MTLSizeMake(source->w, source->h, source->d) + sourceSize:MTLSizeMake(w, h, d) toTexture:dstTexture->handle destinationSlice:destination->textureSlice.layer destinationLevel:destination->textureSlice.mipLevel @@ -1697,9 +1696,9 @@ static void METAL_CopyTextureToTexture( static void METAL_CopyBufferToBuffer( SDL_GpuCommandBuffer *commandBuffer, - SDL_GpuBuffer *source, - SDL_GpuBuffer *destination, - SDL_GpuBufferCopy *copyParams, + SDL_GpuBufferLocation *source, + SDL_GpuBufferLocation *destination, + Uint32 size, SDL_bool cycle) { MetalCommandBuffer *metalCommandBuffer = (MetalCommandBuffer *)commandBuffer; @@ -1715,10 +1714,10 @@ static void METAL_CopyBufferToBuffer( [metalCommandBuffer->blitEncoder copyFromBuffer:srcBuffer->handle - sourceOffset:copyParams->srcOffset + sourceOffset:source->offset toBuffer:dstBuffer->handle - destinationOffset:copyParams->dstOffset - size:copyParams->size]; + destinationOffset:destination->offset + size:size]; METAL_INTERNAL_TrackBuffer(metalCommandBuffer, srcBuffer); METAL_INTERNAL_TrackBuffer(metalCommandBuffer, dstBuffer); @@ -1746,17 +1745,16 @@ static void METAL_GenerateMipmaps( static void METAL_DownloadFromTexture( SDL_GpuCommandBuffer *commandBuffer, SDL_GpuTextureRegion *source, - SDL_GpuTransferBuffer *destination, - SDL_GpuBufferImageCopy *copyParams) + SDL_GpuTextureTransferInfo *destination) { MetalCommandBuffer *metalCommandBuffer = (MetalCommandBuffer *)commandBuffer; MetalRenderer *renderer = metalCommandBuffer->renderer; SDL_GpuTextureSlice *textureSlice = &source->textureSlice; MetalTextureContainer *textureContainer = (MetalTextureContainer *)textureSlice->texture; MetalTexture *metalTexture = textureContainer->activeTexture; - MetalBufferContainer *bufferContainer = (MetalBufferContainer *)destination; - Uint32 bufferStride = copyParams->bufferStride; - Uint32 bufferImageHeight = copyParams->bufferImageHeight; + MetalBufferContainer *bufferContainer = (MetalBufferContainer *)destination->transferBuffer; + Uint32 bufferStride = destination->imagePitch; + Uint32 bufferImageHeight = destination->imageHeight; Uint32 bytesPerRow, bytesPerDepthSlice; MetalBuffer *dstBuffer = METAL_INTERNAL_PrepareBufferForWrite( @@ -1789,7 +1787,7 @@ static void METAL_DownloadFromTexture( sourceOrigin:regionOrigin sourceSize:regionSize toBuffer:dstBuffer->handle - destinationOffset:copyParams->bufferOffset + destinationOffset:destination->offset destinationBytesPerRow:bytesPerRow destinationBytesPerImage:bytesPerDepthSlice]; @@ -1799,15 +1797,18 @@ static void METAL_DownloadFromTexture( static void METAL_DownloadFromBuffer( SDL_GpuCommandBuffer *commandBuffer, - SDL_GpuBuffer *buffer, - SDL_GpuTransferBuffer *destination, - SDL_GpuBufferCopy *copyParams) + SDL_GpuBufferRegion *source, + SDL_GpuTransferBufferLocation *destination) { + SDL_GpuBufferLocation sourceLocation; + sourceLocation.buffer = source->buffer; + sourceLocation.offset = source->offset; + METAL_CopyBufferToBuffer( commandBuffer, - (SDL_GpuBuffer *)destination, - buffer, - copyParams, + &sourceLocation, + (SDL_GpuBufferLocation *)destination, + source->size, SDL_FALSE); } diff --git a/src/gpu/vulkan/SDL_gpu_vulkan.c b/src/gpu/vulkan/SDL_gpu_vulkan.c index 2d68e582ba6d2..7ae8d66ae8174 100644 --- a/src/gpu/vulkan/SDL_gpu_vulkan.c +++ b/src/gpu/vulkan/SDL_gpu_vulkan.c @@ -8469,13 +8469,12 @@ static void VULKAN_UnmapTransferBuffer( static void VULKAN_SetTransferData( SDL_GpuRenderer *driverData, - const void *data, - SDL_GpuTransferBuffer *transferBuffer, - SDL_GpuBufferCopy *copyParams, + const void *source, + SDL_GpuTransferBufferRegion *destination, SDL_bool cycle) { VulkanRenderer *renderer = (VulkanRenderer *)driverData; - VulkanBufferContainer *transferBufferContainer = (VulkanBufferContainer *)transferBuffer; + VulkanBufferContainer *transferBufferContainer = (VulkanBufferContainer *)destination->transferBuffer; if ( cycle && @@ -8488,33 +8487,26 @@ static void VULKAN_SetTransferData( Uint8 *bufferPointer = transferBufferContainer->activeBufferHandle->vulkanBuffer->usedRegion->allocation->mapPointer + transferBufferContainer->activeBufferHandle->vulkanBuffer->usedRegion->resourceOffset + - copyParams->dstOffset; + destination->offset; - SDL_memcpy( - bufferPointer, - ((Uint8 *)data) + copyParams->srcOffset, - copyParams->size); + SDL_memcpy(bufferPointer, source, destination->size); } static void VULKAN_GetTransferData( SDL_GpuRenderer *driverData, - SDL_GpuTransferBuffer *transferBuffer, - void *data, - SDL_GpuBufferCopy *copyParams) + SDL_GpuTransferBufferRegion *source, + void *destination) { (void)driverData; /* used by other backends */ - VulkanBufferContainer *transferBufferContainer = (VulkanBufferContainer *)transferBuffer; + VulkanBufferContainer *transferBufferContainer = (VulkanBufferContainer *)source->transferBuffer; VulkanBuffer *vulkanBuffer = transferBufferContainer->activeBufferHandle->vulkanBuffer; Uint8 *bufferPointer = vulkanBuffer->usedRegion->allocation->mapPointer + vulkanBuffer->usedRegion->resourceOffset + - copyParams->srcOffset; + source->offset; - SDL_memcpy( - ((Uint8 *)data) + copyParams->dstOffset, - bufferPointer, - copyParams->size); + SDL_memcpy(destination, bufferPointer, source->size); } static void VULKAN_BeginCopyPass( @@ -8526,14 +8518,13 @@ static void VULKAN_BeginCopyPass( static void VULKAN_UploadToTexture( SDL_GpuCommandBuffer *commandBuffer, - SDL_GpuTransferBuffer *source, + SDL_GpuTextureTransferInfo *source, SDL_GpuTextureRegion *destination, - SDL_GpuBufferImageCopy *copyParams, SDL_bool cycle) { VulkanCommandBuffer *vulkanCommandBuffer = (VulkanCommandBuffer *)commandBuffer; VulkanRenderer *renderer = (VulkanRenderer *)vulkanCommandBuffer->renderer; - VulkanBufferContainer *transferBufferContainer = (VulkanBufferContainer *)source; + VulkanBufferContainer *transferBufferContainer = (VulkanBufferContainer *)source->transferBuffer; VulkanTextureContainer *vulkanTextureContainer = (VulkanTextureContainer *)destination->textureSlice.texture; VulkanTextureSlice *vulkanTextureSlice; VkBufferImageCopy imageCopy; @@ -8559,9 +8550,9 @@ static void VULKAN_UploadToTexture( imageCopy.imageSubresource.baseArrayLayer = destination->textureSlice.layer; imageCopy.imageSubresource.layerCount = 1; imageCopy.imageSubresource.mipLevel = destination->textureSlice.mipLevel; - imageCopy.bufferOffset = copyParams->bufferOffset; - imageCopy.bufferRowLength = copyParams->bufferStride; - imageCopy.bufferImageHeight = copyParams->bufferImageHeight; + imageCopy.bufferOffset = source->offset; + imageCopy.bufferRowLength = source->imagePitch; + imageCopy.bufferImageHeight = source->imageHeight; renderer->vkCmdCopyBufferToImage( vulkanCommandBuffer->commandBuffer, @@ -8583,15 +8574,14 @@ static void VULKAN_UploadToTexture( static void VULKAN_UploadToBuffer( SDL_GpuCommandBuffer *commandBuffer, - SDL_GpuTransferBuffer *source, - SDL_GpuBuffer *destination, - SDL_GpuBufferCopy *copyParams, + SDL_GpuTransferBufferLocation *source, + SDL_GpuBufferRegion *destination, SDL_bool cycle) { VulkanCommandBuffer *vulkanCommandBuffer = (VulkanCommandBuffer *)commandBuffer; VulkanRenderer *renderer = (VulkanRenderer *)vulkanCommandBuffer->renderer; - VulkanBufferContainer *transferBufferContainer = (VulkanBufferContainer *)source; - VulkanBufferContainer *bufferContainer = (VulkanBufferContainer *)destination; + VulkanBufferContainer *transferBufferContainer = (VulkanBufferContainer *)source->transferBuffer; + VulkanBufferContainer *bufferContainer = (VulkanBufferContainer *)destination->buffer; VkBufferCopy bufferCopy; /* Note that the transfer buffer does not need a barrier, as it is synced by the client */ @@ -8603,9 +8593,9 @@ static void VULKAN_UploadToBuffer( cycle, VULKAN_BUFFER_USAGE_MODE_COPY_DESTINATION); - bufferCopy.srcOffset = copyParams->srcOffset; - bufferCopy.dstOffset = copyParams->dstOffset; - bufferCopy.size = copyParams->size; + bufferCopy.srcOffset = source->offset; + bufferCopy.dstOffset = destination->offset; + bufferCopy.size = destination->size; renderer->vkCmdCopyBuffer( vulkanCommandBuffer->commandBuffer, @@ -8629,13 +8619,12 @@ static void VULKAN_UploadToBuffer( static void VULKAN_DownloadFromTexture( SDL_GpuCommandBuffer *commandBuffer, SDL_GpuTextureRegion *source, - SDL_GpuTransferBuffer *destination, - SDL_GpuBufferImageCopy *copyParams) + SDL_GpuTextureTransferInfo *destination) { VulkanCommandBuffer *vulkanCommandBuffer = (VulkanCommandBuffer *)commandBuffer; VulkanRenderer *renderer = vulkanCommandBuffer->renderer; VulkanTextureSlice *vulkanTextureSlice; - VulkanBufferContainer *transferBufferContainer = (VulkanBufferContainer *)destination; + VulkanBufferContainer *transferBufferContainer = (VulkanBufferContainer *)destination->transferBuffer; VkBufferImageCopy imageCopy; vulkanTextureSlice = VULKAN_INTERNAL_SDLToVulkanTextureSlice(&source->textureSlice); @@ -8657,9 +8646,9 @@ static void VULKAN_DownloadFromTexture( imageCopy.imageSubresource.baseArrayLayer = source->textureSlice.layer; imageCopy.imageSubresource.layerCount = 1; imageCopy.imageSubresource.mipLevel = source->textureSlice.mipLevel; - imageCopy.bufferOffset = copyParams->bufferOffset; - imageCopy.bufferRowLength = copyParams->bufferStride; - imageCopy.bufferImageHeight = copyParams->bufferImageHeight; + imageCopy.bufferOffset = destination->offset; + imageCopy.bufferRowLength = destination->imagePitch; + imageCopy.bufferImageHeight = destination->imageHeight; renderer->vkCmdCopyImageToBuffer( vulkanCommandBuffer->commandBuffer, @@ -8681,14 +8670,13 @@ static void VULKAN_DownloadFromTexture( static void VULKAN_DownloadFromBuffer( SDL_GpuCommandBuffer *commandBuffer, - SDL_GpuBuffer *source, - SDL_GpuTransferBuffer *destination, - SDL_GpuBufferCopy *copyParams) + SDL_GpuBufferRegion *source, + SDL_GpuTransferBufferLocation *destination) { VulkanCommandBuffer *vulkanCommandBuffer = (VulkanCommandBuffer *)commandBuffer; VulkanRenderer *renderer = vulkanCommandBuffer->renderer; - VulkanBufferContainer *bufferContainer = (VulkanBufferContainer *)source; - VulkanBufferContainer *transferBufferContainer = (VulkanBufferContainer *)destination; + VulkanBufferContainer *bufferContainer = (VulkanBufferContainer *)source->buffer; + VulkanBufferContainer *transferBufferContainer = (VulkanBufferContainer *)destination->transferBuffer; VkBufferCopy bufferCopy; /* Note that transfer buffer does not need a barrier, as it is synced by the client */ @@ -8699,9 +8687,9 @@ static void VULKAN_DownloadFromBuffer( VULKAN_BUFFER_USAGE_MODE_COPY_SOURCE, bufferContainer->activeBufferHandle->vulkanBuffer); - bufferCopy.srcOffset = copyParams->srcOffset; - bufferCopy.dstOffset = copyParams->dstOffset; - bufferCopy.size = copyParams->size; + bufferCopy.srcOffset = source->offset; + bufferCopy.dstOffset = destination->offset; + bufferCopy.size = source->size; renderer->vkCmdCopyBuffer( vulkanCommandBuffer->commandBuffer, @@ -8722,8 +8710,11 @@ static void VULKAN_DownloadFromBuffer( static void VULKAN_CopyTextureToTexture( SDL_GpuCommandBuffer *commandBuffer, - SDL_GpuTextureRegion *source, - SDL_GpuTextureRegion *destination, + SDL_GpuTextureLocation *source, + SDL_GpuTextureLocation *destination, + Uint32 w, + Uint32 h, + Uint32 d, SDL_bool cycle) { VulkanCommandBuffer *vulkanCommandBuffer = (VulkanCommandBuffer *)commandBuffer; @@ -8764,9 +8755,9 @@ static void VULKAN_CopyTextureToTexture( imageCopy.dstSubresource.baseArrayLayer = destination->textureSlice.layer; imageCopy.dstSubresource.layerCount = 1; imageCopy.dstSubresource.mipLevel = destination->textureSlice.mipLevel; - imageCopy.extent.width = source->w; - imageCopy.extent.height = source->h; - imageCopy.extent.depth = source->d; + imageCopy.extent.width = w; + imageCopy.extent.height = h; + imageCopy.extent.depth = d; renderer->vkCmdCopyImage( vulkanCommandBuffer->commandBuffer, @@ -8795,15 +8786,15 @@ static void VULKAN_CopyTextureToTexture( static void VULKAN_CopyBufferToBuffer( SDL_GpuCommandBuffer *commandBuffer, - SDL_GpuBuffer *source, - SDL_GpuBuffer *destination, - SDL_GpuBufferCopy *copyParams, + SDL_GpuBufferLocation *source, + SDL_GpuBufferLocation *destination, + Uint32 size, SDL_bool cycle) { VulkanCommandBuffer *vulkanCommandBuffer = (VulkanCommandBuffer *)commandBuffer; VulkanRenderer *renderer = (VulkanRenderer *)vulkanCommandBuffer->renderer; - VulkanBufferContainer *srcContainer = (VulkanBufferContainer *)source; - VulkanBufferContainer *dstContainer = (VulkanBufferContainer *)destination; + VulkanBufferContainer *srcContainer = (VulkanBufferContainer *)source->buffer; + VulkanBufferContainer *dstContainer = (VulkanBufferContainer *)destination->buffer; VkBufferCopy bufferCopy; VulkanBuffer *dstBuffer = VULKAN_INTERNAL_PrepareBufferForWrite( @@ -8819,9 +8810,9 @@ static void VULKAN_CopyBufferToBuffer( VULKAN_BUFFER_USAGE_MODE_COPY_SOURCE, srcContainer->activeBufferHandle->vulkanBuffer); - bufferCopy.srcOffset = copyParams->srcOffset; - bufferCopy.dstOffset = copyParams->dstOffset; - bufferCopy.size = copyParams->size; + bufferCopy.srcOffset = source->offset; + bufferCopy.dstOffset = destination->offset; + bufferCopy.size = size; renderer->vkCmdCopyBuffer( vulkanCommandBuffer->commandBuffer, diff --git a/test/testgpu_spinning_cube.c b/test/testgpu_spinning_cube.c index dac2a214e4a42..45c08482c0e01 100644 --- a/test/testgpu_spinning_cube.c +++ b/test/testgpu_spinning_cube.c @@ -410,7 +410,9 @@ init_render_state(void) { SDL_GpuCommandBuffer *cmd; SDL_GpuTransferBuffer *buf_transfer; - SDL_GpuBufferCopy copy_params; + SDL_GpuTransferBufferRegion buf_region; + SDL_GpuTransferBufferLocation buf_location; + SDL_GpuBufferRegion dst_region; SDL_GpuCopyPass *copy_pass; SDL_GpuGraphicsPipelineCreateInfo pipelinedesc; SDL_GpuColorAttachmentDescription color_attachment_desc; @@ -461,14 +463,19 @@ init_render_state(void) CHECK_CREATE(buf_transfer, "Vertex transfer buffer") /* We just need to upload the static data once. */ - copy_params.srcOffset = 0; - copy_params.dstOffset = 0; - copy_params.size = sizeof(vertex_data); - SDL_GpuSetTransferData(gpu_device, (void*) vertex_data, buf_transfer, ©_params, SDL_FALSE); + buf_region.transferBuffer = buf_transfer; + buf_region.offset = 0; + buf_region.size = sizeof(vertex_data); + SDL_GpuSetTransferData(gpu_device, (void*) vertex_data, &buf_region, SDL_FALSE); cmd = SDL_GpuAcquireCommandBuffer(gpu_device); copy_pass = SDL_GpuBeginCopyPass(cmd); - SDL_GpuUploadToBuffer(copy_pass, buf_transfer, render_state.buf_vertex, ©_params, SDL_FALSE); + buf_location.transferBuffer = buf_transfer; + buf_location.offset = 0; + dst_region.buffer = render_state.buf_vertex; + dst_region.offset = 0; + dst_region.size = sizeof(vertex_data); + SDL_GpuUploadToBuffer(copy_pass, &buf_location, &dst_region, SDL_FALSE); SDL_GpuEndCopyPass(copy_pass); SDL_GpuSubmit(cmd);