Skip to content

Commit f8b1903

Browse files
committed
WIP
1 parent 8ba4e66 commit f8b1903

24 files changed

+732
-704
lines changed

extensions/pl_debug_ext.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Index of this file:
2020
// core
2121
#include <float.h>
2222
#include "pl.h"
23-
#include "pl_ds.h"
23+
2424
#include "pl_debug_ext.h"
2525
#define PL_MATH_INCLUDE_FUNCTIONS
2626
#include "pl_math.h"
@@ -103,6 +103,8 @@ static plDebugContext* gptDebugCtx = NULL;
103103

104104
#endif
105105

106+
#include "pl_ds.h"
107+
106108
//-----------------------------------------------------------------------------
107109
// [SECTION] internal api
108110
//-----------------------------------------------------------------------------

extensions/pl_draw_backend_ext.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ Index of this file:
2020
#include <float.h>
2121
#include "pl.h"
2222
#include "pl_memory.h"
23-
#include "pl_ds.h"
2423
#define PL_MATH_INCLUDE_FUNCTIONS
2524
#include "pl_math.h"
2625

@@ -33,8 +32,21 @@ Index of this file:
3332

3433
#ifdef PL_UNITY_BUILD
3534
#include "pl_unity_ext.inc"
35+
#else
36+
static const plMemoryI* gptMemory = NULL;
37+
#define PL_ALLOC(x) gptMemory->tracked_realloc(NULL, (x), __FILE__, __LINE__)
38+
#define PL_REALLOC(x, y) gptMemory->tracked_realloc((x), (y), __FILE__, __LINE__)
39+
#define PL_FREE(x) gptMemory->tracked_realloc((x), 0, __FILE__, __LINE__)
40+
41+
#ifndef PL_DS_ALLOC
42+
#define PL_DS_ALLOC(x) gptMemory->tracked_realloc(NULL, (x), __FILE__, __LINE__)
43+
#define PL_DS_ALLOC_INDIRECT(x, FILE, LINE) gptMemory->tracked_realloc(NULL, (x), FILE, LINE)
44+
#define PL_DS_FREE(x) gptMemory->tracked_realloc((x), 0, __FILE__, __LINE__)
45+
#endif
3646
#endif
3747

48+
#include "pl_ds.h"
49+
3850
//-----------------------------------------------------------------------------
3951
// [SECTION] internal structs
4052
//-----------------------------------------------------------------------------
@@ -85,18 +97,6 @@ typedef struct _plDrawBackendContext
8597

8698
static plDrawBackendContext* gptDrawBackendCtx = NULL;
8799

88-
#ifndef PL_UNITY_BUILD
89-
static const plMemoryI* gptMemory = NULL;
90-
#define PL_ALLOC(x) gptMemory->tracked_realloc(NULL, (x), __FILE__, __LINE__)
91-
#define PL_REALLOC(x, y) gptMemory->tracked_realloc((x), (y), __FILE__, __LINE__)
92-
#define PL_FREE(x) gptMemory->tracked_realloc((x), 0, __FILE__, __LINE__)
93-
94-
static const plGraphicsI* gptGfx = NULL;
95-
static const plStatsI* gptStats = NULL;
96-
static const plDrawI* gptDraw = NULL;
97-
static const plShaderI* gptShader = NULL;
98-
#endif
99-
100100
//-----------------------------------------------------------------------------
101101
// [SECTION] internal api
102102
//-----------------------------------------------------------------------------

extensions/pl_ecs_ext.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ Index of this file:
2121
#define PL_MATH_INCLUDE_FUNCTIONS
2222
#include "pl.h"
2323
#include "pl_ecs_ext.h"
24-
#include "pl_ds.h"
2524
#include "pl_math.h"
2625

2726
// extensions
@@ -51,6 +50,8 @@ Index of this file:
5150
static const plLogI* gptLog = NULL;
5251
#endif
5352

53+
#include "pl_ds.h"
54+
5455
//-----------------------------------------------------------------------------
5556
// [SECTION] structs
5657
//-----------------------------------------------------------------------------

extensions/pl_gpu_allocators_ext.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ Index of this file:
2020
#include "pl_graphics_ext.h"
2121
#define PL_MATH_INCLUDE_FUNCTIONS
2222
#include "pl_math.h"
23-
#include "pl_ds.h"
2423

2524
#ifdef PL_UNITY_BUILD
2625
#include "pl_unity_ext.inc"
@@ -40,6 +39,8 @@ Index of this file:
4039
static const plDataRegistryI* gptDataRegistry = NULL;
4140
#endif
4241

42+
#include "pl_ds.h"
43+
4344
//-----------------------------------------------------------------------------
4445
// [SECTION] defines
4546
//-----------------------------------------------------------------------------

extensions/pl_graphics_ext.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,7 @@ pl_load_graphics_ext(plApiRegistryI* ptApiRegistry, bool bReload)
716716
.present = pl_present,
717717
.copy_buffer_to_texture = pl_copy_buffer_to_texture,
718718
.copy_texture_to_buffer = pl_copy_texture_to_buffer,
719+
.copy_texture = pl_copy_texture,
719720
.generate_mipmaps = pl_generate_mipmaps,
720721
.copy_buffer = pl_copy_buffer,
721722
.signal_semaphore = pl_signal_semaphore,

extensions/pl_graphics_ext.h

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Index of this file:
4848
// [SECTION] apis
4949
//-----------------------------------------------------------------------------
5050

51-
#define plGraphicsI_version (plVersion){1, 2, 0}
51+
#define plGraphicsI_version (plVersion){1, 2, 1}
5252

5353
//-----------------------------------------------------------------------------
5454
// [SECTION] includes
@@ -95,6 +95,7 @@ typedef struct _plRenderEncoder plRenderEncoder; // opaque type for
9595
typedef struct _plComputeEncoder plComputeEncoder; // opaque type for command buffer encoder for compute ops
9696
typedef struct _plBlitEncoder plBlitEncoder; // opaque type for command buffer encoder for blit ops
9797
typedef struct _plBufferImageCopy plBufferImageCopy; // used for copying between buffers & textures with blit encoder
98+
typedef struct _plImageCopy plImageCopy; // used for copying between textures with blit encoder
9899
typedef struct _plPassTextureResource plPassTextureResource;
99100
typedef struct _plPassBufferResource plPassBufferResource;
100101
typedef struct _plPassResources plPassResources;
@@ -299,6 +300,7 @@ typedef struct _plGraphicsI
299300
void (*set_texture_usage) (plBlitEncoder*, plTextureHandle, plTextureUsage tNewUsage, plTextureUsage tOldUsage);
300301
void (*copy_buffer_to_texture) (plBlitEncoder*, plBufferHandle, plTextureHandle, uint32_t regionCount, const plBufferImageCopy*);
301302
void (*copy_texture_to_buffer) (plBlitEncoder*, plTextureHandle, plBufferHandle, uint32_t regionCount, const plBufferImageCopy*);
303+
void (*copy_texture) (plBlitEncoder*, plTextureHandle, plTextureHandle, uint32_t regionCount, const plImageCopy*);
302304
void (*generate_mipmaps) (plBlitEncoder*, plTextureHandle);
303305
void (*copy_buffer) (plBlitEncoder*, plBufferHandle source, plBufferHandle destination, uint32_t sourceOffset, uint32_t destinationOffset, size_t);
304306

@@ -556,8 +558,10 @@ typedef struct _plBindGroupUpdateBufferData
556558
{
557559
plBufferHandle tBuffer;
558560
uint32_t uSlot;
559-
size_t szOffset;
560561
size_t szBufferRange;
562+
563+
// [INTERNAL]
564+
size_t _szOffset; // vulkan only :(
561565
} plBindGroupUpdateBufferData;
562566

563567
typedef struct _plBindGroupUpdateData
@@ -885,6 +889,30 @@ typedef struct _plBufferImageCopy
885889
plTextureUsage tCurrentImageUsage;
886890
} plBufferImageCopy;
887891

892+
typedef struct _plImageCopy
893+
{
894+
// source info
895+
int iSourceOffsetX;
896+
int iSourceOffsetY;
897+
int iSourceOffsetZ;
898+
uint32_t uSourceExtentX;
899+
uint32_t uSourceExtentY;
900+
uint32_t uSourceExtentZ;
901+
uint32_t uSourceMipLevel;
902+
uint32_t uSourceBaseArrayLayer;
903+
uint32_t uSourceLayerCount;
904+
plTextureUsage tSourceImageUsage;
905+
906+
// destination offset
907+
int iDestinationOffsetX;
908+
int iDestinationOffsetY;
909+
int iDestinationOffsetZ;
910+
uint32_t uDestinationMipLevel;
911+
uint32_t uDestinationBaseArrayLayer;
912+
uint32_t uDestinationLayerCount;
913+
plTextureUsage tDestinationImageUsage;
914+
} plImageCopy;
915+
888916
typedef struct _plDrawArea
889917
{
890918
plRenderViewport atViewports[PL_MAX_VIEWPORTS];

extensions/pl_graphics_vulkan.c

Lines changed: 110 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,115 @@ pl_copy_texture_to_buffer(plBlitEncoder* ptEncoder, plTextureHandle tTextureHand
627627
pl_temp_allocator_reset(&gptGraphics->tTempAllocator);
628628
}
629629

630+
void
631+
pl_copy_texture(plBlitEncoder* ptEncoder, plTextureHandle tSrcHandle, plTextureHandle tDstHandle, uint32_t uRegionCount, const plImageCopy* ptRegions)
632+
{
633+
plCommandBuffer* ptCmdBuffer = ptEncoder->ptCommandBuffer;
634+
plDevice* ptDevice = ptCmdBuffer->ptDevice;
635+
636+
// allocate temporary memory
637+
VkImageCopy* atCopyRegions = pl_temp_allocator_alloc(&gptGraphics->tTempAllocator, sizeof(VkImageCopy) * uRegionCount);
638+
memset(atCopyRegions, 0, sizeof(VkImageCopy) * uRegionCount);
639+
640+
VkImageSubresourceRange* atSubResourceRanges = pl_temp_allocator_alloc(&gptGraphics->tTempAllocator, sizeof(VkImageSubresourceRange) * uRegionCount);
641+
memset(atSubResourceRanges, 0, sizeof(VkImageSubresourceRange) * uRegionCount * 2);
642+
643+
// setup copy regions
644+
plTexture* ptColdSrcTexture = pl__get_texture(ptDevice, tSrcHandle);
645+
plTexture* ptColdDstTexture = pl__get_texture(ptDevice, tDstHandle);
646+
647+
uint32_t uCurrentSrcBaseArrayLevel = UINT32_MAX;
648+
uint32_t uCurrentSrcMipLevel = UINT32_MAX;
649+
650+
uint32_t uCurrentDestBaseArrayLevel = UINT32_MAX;
651+
uint32_t uCurrentDestMipLevel = UINT32_MAX;
652+
653+
for (uint32_t i = 0; i < uRegionCount; i++)
654+
{
655+
656+
atSubResourceRanges[i].aspectMask = ptColdSrcTexture->tDesc.tUsage & PL_TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT ? VK_IMAGE_ASPECT_DEPTH_BIT : VK_IMAGE_ASPECT_COLOR_BIT;
657+
atSubResourceRanges[i].baseMipLevel = ptRegions[i].uSourceMipLevel;
658+
atSubResourceRanges[i].levelCount = ptRegions[i].uSourceLayerCount;
659+
atSubResourceRanges[i].baseArrayLayer = ptRegions[i].uSourceBaseArrayLayer;
660+
atSubResourceRanges[i].layerCount = ptRegions[i].uSourceLayerCount;
661+
662+
atSubResourceRanges[i + uRegionCount].aspectMask = ptColdDstTexture->tDesc.tUsage & PL_TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT ? VK_IMAGE_ASPECT_DEPTH_BIT : VK_IMAGE_ASPECT_COLOR_BIT;
663+
atSubResourceRanges[i + uRegionCount].baseMipLevel = ptRegions[i].uDestinationMipLevel;
664+
atSubResourceRanges[i + uRegionCount].levelCount = ptRegions[i].uDestinationLayerCount;
665+
atSubResourceRanges[i + uRegionCount].baseArrayLayer = ptRegions[i].uDestinationBaseArrayLayer;
666+
atSubResourceRanges[i + uRegionCount].layerCount = ptRegions[i].uDestinationLayerCount;
667+
668+
669+
if(uCurrentSrcBaseArrayLevel != atSubResourceRanges[i].baseArrayLayer || uCurrentSrcMipLevel != atSubResourceRanges[i].baseMipLevel)
670+
{
671+
pl__transition_image_layout(ptCmdBuffer->tCmdBuffer, ptDevice->sbtTexturesHot[tSrcHandle.uIndex].tImage, pl__vulkan_layout(ptRegions[i].tSourceImageUsage), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, atSubResourceRanges[i], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT);
672+
uCurrentSrcBaseArrayLevel = atSubResourceRanges[i].baseArrayLayer;
673+
uCurrentSrcMipLevel = atSubResourceRanges[i].baseMipLevel;
674+
}
675+
676+
if(uCurrentDestBaseArrayLevel != atSubResourceRanges[i + uRegionCount].baseArrayLayer || uCurrentDestMipLevel != atSubResourceRanges[i + uRegionCount].baseMipLevel)
677+
{
678+
pl__transition_image_layout(ptCmdBuffer->tCmdBuffer, ptDevice->sbtTexturesHot[tDstHandle.uIndex].tImage, pl__vulkan_layout(ptRegions[i].tDestinationImageUsage), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, atSubResourceRanges[i + uRegionCount], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT);
679+
uCurrentDestBaseArrayLevel = atSubResourceRanges[i + uRegionCount].baseArrayLayer;
680+
uCurrentDestMipLevel = atSubResourceRanges[i + uRegionCount].baseMipLevel;
681+
}
682+
683+
684+
atCopyRegions[i].srcOffset.x = ptRegions[i].iSourceOffsetX;
685+
atCopyRegions[i].srcOffset.y = ptRegions[i].iSourceOffsetY;
686+
atCopyRegions[i].srcOffset.z = ptRegions[i].iSourceOffsetZ;
687+
688+
atCopyRegions[i].extent.width = ptRegions[i].uSourceExtentX;
689+
atCopyRegions[i].extent.height = ptRegions[i].uSourceExtentY;
690+
atCopyRegions[i].extent.depth = ptRegions[i].uSourceExtentZ;
691+
692+
atCopyRegions[i].srcSubresource.baseArrayLayer = ptRegions[i].uSourceBaseArrayLayer;
693+
atCopyRegions[i].srcSubresource.layerCount = ptRegions[i].uSourceLayerCount;
694+
atCopyRegions[i].srcSubresource.mipLevel = ptRegions[i].uSourceMipLevel;
695+
atCopyRegions[i].srcSubresource.aspectMask = ptColdSrcTexture->tDesc.tUsage & PL_TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT ? VK_IMAGE_ASPECT_DEPTH_BIT : VK_IMAGE_ASPECT_COLOR_BIT;
696+
697+
atCopyRegions[i].dstOffset.x = ptRegions[i].iDestinationOffsetX;
698+
atCopyRegions[i].dstOffset.y = ptRegions[i].iDestinationOffsetY;
699+
atCopyRegions[i].dstOffset.z = ptRegions[i].iDestinationOffsetZ;
700+
701+
atCopyRegions[i].dstSubresource.baseArrayLayer = ptRegions[i].uDestinationBaseArrayLayer;
702+
atCopyRegions[i].dstSubresource.layerCount = ptRegions[i].uDestinationLayerCount;
703+
atCopyRegions[i].dstSubresource.mipLevel = ptRegions[i].uDestinationMipLevel;
704+
atCopyRegions[i].dstSubresource.aspectMask = ptColdDstTexture->tDesc.tUsage & PL_TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT ? VK_IMAGE_ASPECT_DEPTH_BIT : VK_IMAGE_ASPECT_COLOR_BIT;
705+
}
706+
707+
vkCmdCopyImage(ptCmdBuffer->tCmdBuffer,
708+
ptDevice->sbtTexturesHot[tSrcHandle.uIndex].tImage,
709+
VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
710+
ptDevice->sbtTexturesHot[tDstHandle.uIndex].tImage,
711+
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
712+
uRegionCount,
713+
atCopyRegions);
714+
715+
uCurrentSrcBaseArrayLevel = UINT32_MAX;
716+
uCurrentSrcMipLevel = UINT32_MAX;
717+
uCurrentDestBaseArrayLevel = UINT32_MAX;
718+
uCurrentDestMipLevel = UINT32_MAX;
719+
720+
for (uint32_t i = 0; i < uRegionCount; i++)
721+
{
722+
if(uCurrentSrcBaseArrayLevel != atSubResourceRanges[i].baseArrayLayer || uCurrentSrcMipLevel != atSubResourceRanges[i].baseMipLevel)
723+
{
724+
pl__transition_image_layout(ptCmdBuffer->tCmdBuffer, ptDevice->sbtTexturesHot[tSrcHandle.uIndex].tImage, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, pl__vulkan_layout(ptRegions[i].tSourceImageUsage), atSubResourceRanges[i], VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
725+
uCurrentSrcBaseArrayLevel = atSubResourceRanges[i].baseArrayLayer;
726+
uCurrentSrcMipLevel = atSubResourceRanges[i].baseMipLevel;
727+
}
728+
if(uCurrentDestBaseArrayLevel != atSubResourceRanges[i + uRegionCount].baseArrayLayer || uCurrentDestMipLevel != atSubResourceRanges[i + uRegionCount].baseMipLevel)
729+
{
730+
pl__transition_image_layout(ptCmdBuffer->tCmdBuffer, ptDevice->sbtTexturesHot[tDstHandle.uIndex].tImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, pl__vulkan_layout(ptRegions[i].tDestinationImageUsage), atSubResourceRanges[i + uRegionCount], VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
731+
uCurrentDestBaseArrayLevel = atSubResourceRanges[i + uRegionCount].baseArrayLayer;
732+
uCurrentDestMipLevel = atSubResourceRanges[i + uRegionCount].baseMipLevel;
733+
}
734+
}
735+
736+
pl_temp_allocator_reset(&gptGraphics->tTempAllocator);
737+
}
738+
630739
void
631740
pl_generate_mipmaps(plBlitEncoder* ptEncoder, plTextureHandle tTexture)
632741
{
@@ -946,7 +1055,7 @@ pl_update_bind_group(plDevice* ptDevice, plBindGroupHandle tHandle, const plBind
9461055
const plVulkanBuffer* ptVulkanBuffer = &ptDevice->sbtBuffersHot[ptData->atBufferBindings[i].tBuffer.uIndex];
9471056

9481057
sbtBufferDescInfos[i].buffer = ptVulkanBuffer->tBuffer;
949-
sbtBufferDescInfos[i].offset = ptData->atBufferBindings[i].szOffset;
1058+
sbtBufferDescInfos[i].offset = ptData->atBufferBindings[i]._szOffset;
9501059
sbtBufferDescInfos[i].range = ptData->atBufferBindings[i].szBufferRange == 0 ? VK_WHOLE_SIZE : ptData->atBufferBindings[i].szBufferRange;
9511060

9521061
sbtWrites[uCurrentWrite].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;

extensions/pl_model_loader_ext.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ Index of this file:
2020
#include "pl.h"
2121
#include "pl_model_loader_ext.h"
2222
#include "pl_stl.h"
23-
#include "pl_ds.h"
2423
#include "pl_string.h"
2524
#define PL_MATH_INCLUDE_FUNCTIONS
2625
#include "pl_math.h"
@@ -49,6 +48,8 @@ Index of this file:
4948
static const plFileI* gptFile = NULL;
5049
#endif
5150

51+
#include "pl_ds.h"
52+
5253
// misc
5354
#include "cgltf.h"
5455

0 commit comments

Comments
 (0)