Skip to content

Commit 5aaa367

Browse files
flibitijibiboTheSpydog
authored andcommitted
Rework texture/buffer location/region structs (#52)
Co-authored-by: Caleb Cornett <caleb.cornett@outlook.com>
1 parent ececc71 commit 5aaa367

File tree

8 files changed

+289
-281
lines changed

8 files changed

+289
-281
lines changed

include/SDL3/SDL_gpu.h

+72-50
Original file line numberDiff line numberDiff line change
@@ -408,13 +408,42 @@ typedef struct SDL_GpuViewport
408408
float maxDepth;
409409
} SDL_GpuViewport;
410410

411+
typedef struct SDL_GpuTextureTransferInfo
412+
{
413+
SDL_GpuTransferBuffer *transferBuffer;
414+
Uint32 offset; /* starting location of the image data */
415+
Uint32 imagePitch; /* number of pixels from one row to the next */
416+
Uint32 imageHeight; /* number of rows from one layer/depth-slice to the next */
417+
} SDL_GpuTextureTransferInfo;
418+
419+
typedef struct SDL_GpuTransferBufferLocation
420+
{
421+
SDL_GpuTransferBuffer *transferBuffer;
422+
Uint32 offset;
423+
} SDL_GpuTransferBufferLocation;
424+
425+
typedef struct SDL_GpuTransferBufferRegion
426+
{
427+
SDL_GpuTransferBuffer *transferBuffer;
428+
Uint32 offset;
429+
Uint32 size;
430+
} SDL_GpuTransferBufferRegion;
431+
411432
typedef struct SDL_GpuTextureSlice
412433
{
413434
SDL_GpuTexture *texture;
414435
Uint32 mipLevel;
415436
Uint32 layer;
416437
} SDL_GpuTextureSlice;
417438

439+
typedef struct SDL_GpuTextureLocation
440+
{
441+
SDL_GpuTextureSlice textureSlice;
442+
Uint32 x;
443+
Uint32 y;
444+
Uint32 z;
445+
} SDL_GpuTextureLocation;
446+
418447
typedef struct SDL_GpuTextureRegion
419448
{
420449
SDL_GpuTextureSlice textureSlice;
@@ -426,19 +455,18 @@ typedef struct SDL_GpuTextureRegion
426455
Uint32 d;
427456
} SDL_GpuTextureRegion;
428457

429-
typedef struct SDL_GpuBufferImageCopy
458+
typedef struct SDL_GpuBufferLocation
430459
{
431-
Uint32 bufferOffset;
432-
Uint32 bufferStride; /* number of pixels from one row to the next */
433-
Uint32 bufferImageHeight; /* number of rows from one layer/depth-slice to the next */
434-
} SDL_GpuBufferImageCopy;
460+
SDL_GpuBuffer *buffer;
461+
Uint32 offset;
462+
} SDL_GpuBufferLocation;
435463

436-
typedef struct SDL_GpuBufferCopy
464+
typedef struct SDL_GpuBufferRegion
437465
{
438-
Uint32 srcOffset;
439-
Uint32 dstOffset;
466+
SDL_GpuBuffer *buffer;
467+
Uint32 offset;
440468
Uint32 size;
441-
} SDL_GpuBufferCopy;
469+
} SDL_GpuBufferRegion;
442470

443471
typedef struct SDL_GpuIndirectDrawCommand
444472
{
@@ -1634,35 +1662,31 @@ extern SDL_DECLSPEC void SDLCALL SDL_GpuUnmapTransferBuffer(
16341662
* Immediately copies data from a pointer to a transfer buffer.
16351663
*
16361664
* \param device a GPU context
1637-
* \param data a pointer to data to copy into the transfer buffer
1638-
* \param transferBuffer a transfer buffer
1639-
* \param copyParams a struct containing parameters specifying copy offsets and size
1665+
* \param source a pointer to data to copy into the transfer buffer
1666+
* \param destination a transfer buffer with offset and size
16401667
* \param cycle if SDL_TRUE, cycles the transfer buffer if it is bound, otherwise overwrites the data.
16411668
*
16421669
* \since This function is available since SDL 3.x.x
16431670
*/
16441671
extern SDL_DECLSPEC void SDLCALL SDL_GpuSetTransferData(
16451672
SDL_GpuDevice *device,
1646-
const void *data,
1647-
SDL_GpuTransferBuffer *transferBuffer,
1648-
SDL_GpuBufferCopy *copyParams,
1673+
const void *source,
1674+
SDL_GpuTransferBufferRegion *destination,
16491675
SDL_bool cycle);
16501676

16511677
/**
16521678
* Immediately copies data from a transfer buffer to a pointer.
16531679
*
16541680
* \param device a GPU context
1655-
* \param transferBuffer a transfer buffer
1656-
* \param data a data pointer
1657-
* \param copyParams a struct containing parameters specifying copy offsets and size
1681+
* \param source a transfer buffer with offset and size
1682+
* \param destination a data pointer
16581683
*
16591684
* \since This function is available since SDL 3.x.x
16601685
*/
16611686
extern SDL_DECLSPEC void SDLCALL SDL_GpuGetTransferData(
16621687
SDL_GpuDevice *device,
1663-
SDL_GpuTransferBuffer *transferBuffer,
1664-
void *data,
1665-
SDL_GpuBufferCopy *copyParams);
1688+
SDL_GpuTransferBufferRegion *source,
1689+
void *destination);
16661690

16671691
/* Copy Pass */
16681692

@@ -1689,18 +1713,16 @@ extern SDL_DECLSPEC SDL_GpuCopyPass *SDLCALL SDL_GpuBeginCopyPass(
16891713
* the texel size of the texture format.
16901714
*
16911715
* \param copyPass a copy pass handle
1692-
* \param source the source transfer buffer
1716+
* \param source the source transfer buffer with image layout information
16931717
* \param destination the destination texture region
1694-
* \param copyParams buffer offset, stride, and height
16951718
* \param cycle if SDL_TRUE, cycles the texture if the texture slice is bound, otherwise overwrites the data.
16961719
*
16971720
* \since This function is available since SDL 3.x.x
16981721
*/
16991722
extern SDL_DECLSPEC void SDLCALL SDL_GpuUploadToTexture(
17001723
SDL_GpuCopyPass *copyPass,
1701-
SDL_GpuTransferBuffer *source,
1724+
SDL_GpuTextureTransferInfo *source,
17021725
SDL_GpuTextureRegion *destination,
1703-
SDL_GpuBufferImageCopy *copyParams,
17041726
SDL_bool cycle);
17051727

17061728
/* Uploads data from a TransferBuffer to a Buffer. */
@@ -1711,18 +1733,16 @@ extern SDL_DECLSPEC void SDLCALL SDL_GpuUploadToTexture(
17111733
* You may assume that the upload has finished in subsequent commands.
17121734
*
17131735
* \param copyPass a copy pass handle
1714-
* \param source the source transfer buffer
1715-
* \param destination the destination buffer
1716-
* \param copyParams buffer offsets and length
1736+
* \param source the source transfer buffer with offset
1737+
* \param destination the destination buffer with offset and size
17171738
* \param cycle if SDL_TRUE, cycles the buffer if it is bound, otherwise overwrites the data.
17181739
*
17191740
* \since This function is available since SDL 3.x.x
17201741
*/
17211742
extern SDL_DECLSPEC void SDLCALL SDL_GpuUploadToBuffer(
17221743
SDL_GpuCopyPass *copyPass,
1723-
SDL_GpuTransferBuffer *source,
1724-
SDL_GpuBuffer *destination,
1725-
SDL_GpuBufferCopy *copyParams,
1744+
SDL_GpuTransferBufferLocation *source,
1745+
SDL_GpuBufferRegion *destination,
17261746
SDL_bool cycle);
17271747

17281748
/**
@@ -1732,15 +1752,21 @@ extern SDL_DECLSPEC void SDLCALL SDL_GpuUploadToBuffer(
17321752
*
17331753
* \param copyPass a copy pass handle
17341754
* \param source a source texture region
1735-
* \param destination must be the same dimensions as the source region
1755+
* \param destination a destination texture region
1756+
* \param w the width of the region to copy
1757+
* \param h the height of the region to copy
1758+
* \param d the depth of the region to copy
17361759
* \param cycle if SDL_TRUE, cycles the destination texture if the destination texture slice is bound, otherwise overwrites the data.
17371760
*
17381761
* \since This function is available since SDL 3.x.x
17391762
*/
17401763
extern SDL_DECLSPEC void SDLCALL SDL_GpuCopyTextureToTexture(
17411764
SDL_GpuCopyPass *copyPass,
1742-
SDL_GpuTextureRegion *source,
1743-
SDL_GpuTextureRegion *destination,
1765+
SDL_GpuTextureLocation *source,
1766+
SDL_GpuTextureLocation *destination,
1767+
Uint32 w,
1768+
Uint32 h,
1769+
Uint32 d,
17441770
SDL_bool cycle);
17451771

17461772
/* Copies data from a buffer to a buffer. */
@@ -1751,18 +1777,18 @@ extern SDL_DECLSPEC void SDLCALL SDL_GpuCopyTextureToTexture(
17511777
* You may assume the copy has finished in subsequent commands.
17521778
*
17531779
* \param copyPass a copy pass handle
1754-
* \param source the buffer to copy from
1755-
* \param destination the buffer to copy to
1756-
* \param copyParams a struct containing offset and length data
1780+
* \param source the buffer and offset to copy from
1781+
* \param destination the buffer and offset to copy to
1782+
* \param size the length of the buffer to copy
17571783
* \param cycle if SDL_TRUE, cycles the destination buffer if it is bound, otherwise overwrites the data.
17581784
*
17591785
* \since This function is available since SDL 3.x.x
17601786
*/
17611787
extern SDL_DECLSPEC void SDLCALL SDL_GpuCopyBufferToBuffer(
17621788
SDL_GpuCopyPass *copyPass,
1763-
SDL_GpuBuffer *source,
1764-
SDL_GpuBuffer *destination,
1765-
SDL_GpuBufferCopy *copyParams,
1789+
SDL_GpuBufferLocation *source,
1790+
SDL_GpuBufferLocation *destination,
1791+
Uint32 size,
17661792
SDL_bool cycle);
17671793

17681794
/**
@@ -1783,33 +1809,29 @@ extern SDL_DECLSPEC void SDLCALL SDL_GpuGenerateMipmaps(
17831809
*
17841810
* \param copyPass a copy pass handle
17851811
* \param source the source texture region
1786-
* \param destination the destination transfer buffer
1787-
* \param copyParams a struct containing parameters specifying buffer offset, stride, and height
1812+
* \param destination the destination transfer buffer with image layout information
17881813
*
17891814
* \since This function is available since SDL 3.x.x
17901815
*/
17911816
extern SDL_DECLSPEC void SDLCALL SDL_GpuDownloadFromTexture(
17921817
SDL_GpuCopyPass *copyPass,
17931818
SDL_GpuTextureRegion *source,
1794-
SDL_GpuTransferBuffer *destination,
1795-
SDL_GpuBufferImageCopy *copyParams);
1819+
SDL_GpuTextureTransferInfo *destination);
17961820

17971821
/**
17981822
* Copies data from a buffer to a transfer buffer on the GPU timeline.
17991823
* This data is not guaranteed to be copied until the command buffer fence is signaled.
18001824
*
18011825
* \param copyPass a copy pass handle
1802-
* \param source the source buffer
1803-
* \param destination the destination transfer buffer
1804-
* \param copyParams a struct containing offsets and length
1826+
* \param source the source buffer with offset and size
1827+
* \param destination the destination transfer buffer with offset
18051828
*
18061829
* \since This function is available since SDL 3.x.x
18071830
*/
18081831
extern SDL_DECLSPEC void SDLCALL SDL_GpuDownloadFromBuffer(
18091832
SDL_GpuCopyPass *copyPass,
1810-
SDL_GpuBuffer *source,
1811-
SDL_GpuTransferBuffer *destination,
1812-
SDL_GpuBufferCopy *copyParams);
1833+
SDL_GpuBufferRegion *source,
1834+
SDL_GpuTransferBufferLocation *destination);
18131835

18141836
/**
18151837
* Ends the current copy pass.

src/dynapi/SDL_dynapi_procs.h

+8-8
Original file line numberDiff line numberDiff line change
@@ -1150,16 +1150,16 @@ SDL_DYNAPI_PROC(void,SDL_GpuDispatchCompute,(SDL_GpuComputePass *a, Uint32 b, Ui
11501150
SDL_DYNAPI_PROC(void,SDL_GpuEndComputePass,(SDL_GpuComputePass *a),(a),)
11511151
SDL_DYNAPI_PROC(void,SDL_GpuMapTransferBuffer,(SDL_GpuDevice *a, SDL_GpuTransferBuffer *b, SDL_bool c, void **d),(a,b,c,d),)
11521152
SDL_DYNAPI_PROC(void,SDL_GpuUnmapTransferBuffer,(SDL_GpuDevice *a, SDL_GpuTransferBuffer *b),(a,b),)
1153-
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),)
1154-
SDL_DYNAPI_PROC(void,SDL_GpuGetTransferData,(SDL_GpuDevice *a, SDL_GpuTransferBuffer *b, void *c, SDL_GpuBufferCopy *d),(a,b,c,d),)
1153+
SDL_DYNAPI_PROC(void,SDL_GpuSetTransferData,(SDL_GpuDevice *a, const void *b, SDL_GpuTransferBufferRegion *c, SDL_bool d),(a,b,c,d),)
1154+
SDL_DYNAPI_PROC(void,SDL_GpuGetTransferData,(SDL_GpuDevice *a, SDL_GpuTransferBufferRegion *b, void *c),(a,b,c),)
11551155
SDL_DYNAPI_PROC(SDL_GpuCopyPass*,SDL_GpuBeginCopyPass,(SDL_GpuCommandBuffer *a),(a),return)
1156-
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),)
1157-
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),)
1158-
SDL_DYNAPI_PROC(void,SDL_GpuCopyTextureToTexture,(SDL_GpuCopyPass *a, SDL_GpuTextureRegion *b, SDL_GpuTextureRegion *c, SDL_bool d),(a,b,c,d),)
1159-
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),)
1156+
SDL_DYNAPI_PROC(void,SDL_GpuUploadToTexture,(SDL_GpuCopyPass *a, SDL_GpuTextureTransferInfo *b, SDL_GpuTextureRegion *c, SDL_bool d),(a,b,c,d),)
1157+
SDL_DYNAPI_PROC(void,SDL_GpuUploadToBuffer,(SDL_GpuCopyPass *a, SDL_GpuTransferBufferLocation *b, SDL_GpuBufferRegion *c, SDL_bool d),(a,b,c,d),)
1158+
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),)
1159+
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),)
11601160
SDL_DYNAPI_PROC(void,SDL_GpuGenerateMipmaps,(SDL_GpuCopyPass *a, SDL_GpuTexture *b),(a,b),)
1161-
SDL_DYNAPI_PROC(void,SDL_GpuDownloadFromTexture,(SDL_GpuCopyPass *a, SDL_GpuTextureRegion *b, SDL_GpuTransferBuffer *c, SDL_GpuBufferImageCopy *d),(a,b,c,d),)
1162-
SDL_DYNAPI_PROC(void,SDL_GpuDownloadFromBuffer,(SDL_GpuCopyPass *a, SDL_GpuBuffer *b, SDL_GpuTransferBuffer *c, SDL_GpuBufferCopy *d),(a,b,c,d),)
1161+
SDL_DYNAPI_PROC(void,SDL_GpuDownloadFromTexture,(SDL_GpuCopyPass *a, SDL_GpuTextureRegion *b, SDL_GpuTextureTransferInfo *c),(a,b,c),)
1162+
SDL_DYNAPI_PROC(void,SDL_GpuDownloadFromBuffer,(SDL_GpuCopyPass *a, SDL_GpuBufferRegion *b, SDL_GpuTransferBufferLocation *c),(a,b,c),)
11631163
SDL_DYNAPI_PROC(void,SDL_GpuEndCopyPass,(SDL_GpuCopyPass *a),(a),)
11641164
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),)
11651165
SDL_DYNAPI_PROC(SDL_bool,SDL_GpuSupportsSwapchainComposition,(SDL_GpuDevice *a, SDL_Window *b, SDL_GpuSwapchainComposition c),(a,b,c),return)

0 commit comments

Comments
 (0)