Skip to content

Commit 2b2385d

Browse files
committed
WIP
1 parent f8b1903 commit 2b2385d

File tree

7 files changed

+81
-25
lines changed

7 files changed

+81
-25
lines changed

extensions/pl_draw_ext.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ Index of this file:
2323
#include "pl.h"
2424
#define PL_MATH_INCLUDE_FUNCTIONS
2525
#include "pl_draw_ext.h"
26-
#include "pl_ds.h"
2726
#include "pl_memory.h"
2827
#include "pl_string.h"
2928

@@ -140,6 +139,8 @@ static unsigned char* ptrDOut_ = NULL;
140139
static const plFileI* gptFile = NULL;
141140
#endif
142141

142+
#include "pl_ds.h"
143+
143144
//-----------------------------------------------------------------------------
144145
// [SECTION] internal api
145146
//-----------------------------------------------------------------------------

extensions/pl_graphics_ext.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,7 @@ typedef struct _plBindGroup
634634

635635
// [INTERNAL]
636636
uint16_t _uGeneration;
637+
plTextureHandle* _sbtTextures;
637638
} plBindGroup;
638639

639640
//-------------------------------shaders---------------------------------------

extensions/pl_graphics_internal.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#define PL_GRAPHICS_INTERNAL_EXT_H
33

44
#include "pl.h"
5-
#include "pl_ds.h"
65
#include "pl_log_ext.h"
76
#include "pl_threads_ext.h"
87
#include "pl_graphics_ext.h"
@@ -34,6 +33,8 @@
3433
static plIO* gptIO = NULL;
3534
#endif
3635

36+
#include "pl_ds.h"
37+
3738
//-----------------------------------------------------------------------------
3839
// [SECTION] global data
3940
//-----------------------------------------------------------------------------

extensions/pl_graphics_metal.m

Lines changed: 68 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@
148148
plSamplerHandle atSamplerBindings[PL_MAX_TEXTURES_PER_BIND_GROUP];
149149
uint64_t uHeapUsageMask;
150150
uint32_t uOffset;
151-
plTextureHandle* sbtTextures;
152151
} plMetalBindGroup;
153152

154153
typedef struct _plMetalShader
@@ -549,6 +548,44 @@
549548
}
550549
}
551550

551+
void
552+
pl_copy_texture(plBlitEncoder* ptEncoder, plTextureHandle tSrcHandle, plTextureHandle tDstHandle, uint32_t uRegionCount, const plImageCopy* ptRegions)
553+
{
554+
plCommandBuffer* ptCmdBuffer = ptEncoder->ptCommandBuffer;
555+
plDevice* ptDevice = ptCmdBuffer->ptDevice;
556+
const plMetalTexture* ptMetalSrcTexture = &ptDevice->sbtTexturesHot[tSrcHandle.uIndex];
557+
const plMetalTexture* ptMetalDstTexture = &ptDevice->sbtTexturesHot[tDstHandle.uIndex];
558+
559+
for(uint32_t i = 0; i < uRegionCount; i++)
560+
{
561+
562+
MTLOrigin tSrcOrigin;
563+
tSrcOrigin.x = ptRegions[i].iSourceOffsetX;
564+
tSrcOrigin.y = ptRegions[i].iSourceOffsetY;
565+
tSrcOrigin.z = ptRegions[i].iSourceOffsetZ;
566+
567+
MTLOrigin tDestOrigin;
568+
tDestOrigin.x = ptRegions[i].iDestinationOffsetX;
569+
tDestOrigin.y = ptRegions[i].iDestinationOffsetY;
570+
tDestOrigin.z = ptRegions[i].iDestinationOffsetZ;
571+
572+
MTLSize tSourceSize;
573+
tSourceSize.width = ptRegions[i].uSourceExtentX;
574+
tSourceSize.height = ptRegions[i].uSourceExtentY;
575+
tSourceSize.depth = ptRegions[i].uSourceExtentZ;
576+
577+
[ptEncoder->tEncoder copyFromTexture:ptMetalSrcTexture->tTexture
578+
sourceSlice:ptRegions[i].uSourceBaseArrayLayer
579+
sourceLevel:ptRegions[i].uSourceMipLevel
580+
sourceOrigin:tSrcOrigin
581+
sourceSize:tSourceSize
582+
toTexture:ptMetalDstTexture->tTexture
583+
destinationSlice:ptRegions[i].uDestinationBaseArrayLayer
584+
destinationLevel:ptRegions[i].uDestinationMipLevel
585+
destinationOrigin:tDestOrigin];
586+
}
587+
}
588+
552589
static void
553590
pl_copy_texture_to_buffer(plBlitEncoder* ptEncoder, plTextureHandle tTextureHandle, plBufferHandle tBufferHandle, uint32_t uRegionCount, const plBufferImageCopy* ptRegions)
554591
{
@@ -900,6 +937,8 @@
900937
plBindGroup* ptBindGroup = pl__get_bind_group(ptDevice, tHandle);
901938
const char* pcDescriptorStart = ptMetalBindGroup->tShaderArgumentBuffer.contents;
902939

940+
pl_sb_reset(ptBindGroup->_sbtTextures);
941+
903942
uint64_t* pulDescriptorStart = (uint64_t*)&pcDescriptorStart[ptMetalBindGroup->uOffset];
904943

905944
for(uint32_t i = 0; i < ptData->uBufferCount; i++)
@@ -922,7 +961,7 @@
922961
int iCommonBits = ptTexture->tDesc.tUsage & (PL_TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT | PL_TEXTURE_USAGE_COLOR_ATTACHMENT |PL_TEXTURE_USAGE_INPUT_ATTACHMENT | PL_TEXTURE_USAGE_STORAGE);
923962
if(iCommonBits)
924963
{
925-
pl_sb_push(ptMetalBindGroup->sbtTextures, ptUpdate->tTexture);
964+
pl_sb_push(ptBindGroup->_sbtTextures, ptUpdate->tTexture);
926965
}
927966

928967
ptMetalBindGroup->uHeapUsageMask |= (1ULL << ptMetalTexture->uHeap);
@@ -2167,9 +2206,10 @@
21672206

21682207
for(uint32_t i = 0; i < uCount; i++)
21692208
{
2170-
plMetalBindGroup* ptBindGroup = &ptDevice->sbtBindGroupsHot[atBindGroups[i].uIndex];
2209+
plBindGroup* ptBindGroup = &ptDevice->sbtBindGroupsCold[atBindGroups[i].uIndex];
2210+
plMetalBindGroup* ptMetalBindGroup = &ptDevice->sbtBindGroupsHot[atBindGroups[i].uIndex];
21712211

2172-
ptEncoder->uHeapUsageMask |= ptBindGroup->uHeapUsageMask;
2212+
ptEncoder->uHeapUsageMask |= ptMetalBindGroup->uHeapUsageMask;
21732213

21742214
for(uint64_t k = 0; k < 64; k++)
21752215
{
@@ -2179,10 +2219,10 @@
21792219
}
21802220
}
21812221

2182-
const uint32_t uTextureCount = pl_sb_size(ptBindGroup->sbtTextures);
2222+
const uint32_t uTextureCount = pl_sb_size(ptBindGroup->_sbtTextures);
21832223
for(uint32_t k = 0; k < uTextureCount; k++)
21842224
{
2185-
const plTextureHandle tTextureHandle = ptBindGroup->sbtTextures[k];
2225+
const plTextureHandle tTextureHandle = ptBindGroup->_sbtTextures[k];
21862226
plTexture* ptTexture = pl__get_texture(ptDevice, tTextureHandle);
21872227
if(ptTexture->tDesc.tUsage & PL_TEXTURE_USAGE_STORAGE)
21882228
{
@@ -2194,8 +2234,8 @@
21942234
}
21952235
}
21962236

2197-
[ptEncoder->tEncoder setBuffer:ptBindGroup->tShaderArgumentBuffer
2198-
offset:ptBindGroup->uOffset
2237+
[ptEncoder->tEncoder setBuffer:ptMetalBindGroup->tShaderArgumentBuffer
2238+
offset:ptMetalBindGroup->uOffset
21992239
atIndex:uFirst + i];
22002240
}
22012241
}
@@ -2215,9 +2255,10 @@
22152255

22162256
for(uint32_t i = 0; i < uCount; i++)
22172257
{
2218-
plMetalBindGroup* ptBindGroup = &ptDevice->sbtBindGroupsHot[atBindGroups[i].uIndex];
2258+
plBindGroup* ptBindGroup = &ptDevice->sbtBindGroupsCold[atBindGroups[i].uIndex];
2259+
plMetalBindGroup* ptMetalBindGroup = &ptDevice->sbtBindGroupsHot[atBindGroups[i].uIndex];
22192260

2220-
ptEncoder->uHeapUsageMask |= ptBindGroup->uHeapUsageMask;
2261+
ptEncoder->uHeapUsageMask |= ptMetalBindGroup->uHeapUsageMask;
22212262

22222263
for(uint64_t k = 0; k < 64; k++)
22232264
{
@@ -2227,16 +2268,16 @@
22272268
}
22282269
}
22292270

2230-
const uint32_t uTextureCount = pl_sb_size(ptBindGroup->sbtTextures);
2271+
const uint32_t uTextureCount = pl_sb_size(ptBindGroup->_sbtTextures);
22312272
for(uint32_t k = 0; k < uTextureCount; k++)
22322273
{
2233-
const plTextureHandle tTextureHandle = ptBindGroup->sbtTextures[k];
2274+
const plTextureHandle tTextureHandle = ptBindGroup->_sbtTextures[k];
22342275
plTexture* ptTexture = pl__get_texture(ptDevice, tTextureHandle);
22352276
[ptEncoder->tEncoder useResource:ptDevice->sbtTexturesHot[tTextureHandle.uIndex].tTexture usage:MTLResourceUsageRead stages:MTLRenderStageVertex | MTLRenderStageFragment];
22362277
}
22372278

2238-
[ptEncoder->tEncoder setVertexBuffer:ptBindGroup->tShaderArgumentBuffer offset:ptBindGroup->uOffset atIndex:uFirst + i];
2239-
[ptEncoder->tEncoder setFragmentBuffer:ptBindGroup->tShaderArgumentBuffer offset:ptBindGroup->uOffset atIndex:uFirst + i];
2279+
[ptEncoder->tEncoder setVertexBuffer:ptMetalBindGroup->tShaderArgumentBuffer offset:ptMetalBindGroup->uOffset atIndex:uFirst + i];
2280+
[ptEncoder->tEncoder setFragmentBuffer:ptMetalBindGroup->tShaderArgumentBuffer offset:ptMetalBindGroup->uOffset atIndex:uFirst + i];
22402281
}
22412282
}
22422283

@@ -2438,6 +2479,7 @@
24382479
if(uDirtyMask & PL_DRAW_STREAM_BIT_BINDGROUP_0)
24392480
{
24402481
const plBindGroupHandle tBindGroupHandle = {.uData = ptStream->_auStream[uCurrentStreamIndex] };
2482+
plBindGroup* ptBindGroup = &ptDevice->sbtBindGroupsCold[tBindGroupHandle.uIndex];
24412483
plMetalBindGroup* ptMetalBindGroup = &ptDevice->sbtBindGroupsHot[tBindGroupHandle.uIndex];
24422484

24432485
ptEncoder->uHeapUsageMask |= ptMetalBindGroup->uHeapUsageMask;
@@ -2451,10 +2493,10 @@
24512493
}
24522494
}
24532495

2454-
const uint32_t uTextureCount = pl_sb_size(ptMetalBindGroup->sbtTextures);
2496+
const uint32_t uTextureCount = pl_sb_size(ptBindGroup->_sbtTextures);
24552497
for(uint32_t k = 0; k < uTextureCount; k++)
24562498
{
2457-
const plTextureHandle tTextureHandle = ptMetalBindGroup->sbtTextures[k];
2499+
const plTextureHandle tTextureHandle = ptBindGroup->_sbtTextures[k];
24582500
plTexture* ptTexture = pl__get_texture(ptDevice, tTextureHandle);
24592501
[ptEncoder->tEncoder useResource:ptDevice->sbtTexturesHot[tTextureHandle.uIndex].tTexture usage:MTLResourceUsageRead stages:MTLRenderStageVertex | MTLRenderStageFragment];
24602502
}
@@ -2468,6 +2510,7 @@
24682510
{
24692511
const plBindGroupHandle tBindGroupHandle = {.uData = ptStream->_auStream[uCurrentStreamIndex] };
24702512
plMetalBindGroup* ptMetalBindGroup = &ptDevice->sbtBindGroupsHot[tBindGroupHandle.uIndex];
2513+
plBindGroup* ptBindGroup = &ptDevice->sbtBindGroupsCold[tBindGroupHandle.uIndex];
24712514

24722515
ptEncoder->uHeapUsageMask |= ptMetalBindGroup->uHeapUsageMask;
24732516

@@ -2480,10 +2523,10 @@
24802523
}
24812524
}
24822525

2483-
const uint32_t uTextureCount = pl_sb_size(ptMetalBindGroup->sbtTextures);
2526+
const uint32_t uTextureCount = pl_sb_size(ptBindGroup->_sbtTextures);
24842527
for(uint32_t k = 0; k < uTextureCount; k++)
24852528
{
2486-
const plTextureHandle tTextureHandle = ptMetalBindGroup->sbtTextures[k];
2529+
const plTextureHandle tTextureHandle = ptBindGroup->_sbtTextures[k];
24872530
plTexture* ptTexture = pl__get_texture(ptDevice, tTextureHandle);
24882531
[ptEncoder->tEncoder useResource:ptDevice->sbtTexturesHot[tTextureHandle.uIndex].tTexture usage:MTLResourceUsageRead stages:MTLRenderStageVertex | MTLRenderStageFragment];
24892532
}
@@ -2497,6 +2540,7 @@
24972540
{
24982541
const plBindGroupHandle tBindGroupHandle = {.uData = ptStream->_auStream[uCurrentStreamIndex] };
24992542
plMetalBindGroup* ptMetalBindGroup = &ptDevice->sbtBindGroupsHot[tBindGroupHandle.uIndex];
2543+
plBindGroup* ptBindGroup = &ptDevice->sbtBindGroupsCold[tBindGroupHandle.uIndex];
25002544

25012545
ptEncoder->uHeapUsageMask |= ptMetalBindGroup->uHeapUsageMask;
25022546

@@ -2509,10 +2553,10 @@
25092553
}
25102554
}
25112555

2512-
const uint32_t uTextureCount = pl_sb_size(ptMetalBindGroup->sbtTextures);
2556+
const uint32_t uTextureCount = pl_sb_size(ptBindGroup->_sbtTextures);
25132557
for(uint32_t k = 0; k < uTextureCount; k++)
25142558
{
2515-
const plTextureHandle tTextureHandle = ptMetalBindGroup->sbtTextures[k];
2559+
const plTextureHandle tTextureHandle = ptBindGroup->_sbtTextures[k];
25162560
[ptEncoder->tEncoder useResource:ptDevice->sbtTexturesHot[tTextureHandle.uIndex].tTexture usage:MTLResourceUsageRead stages:MTLRenderStageVertex | MTLRenderStageFragment];
25172561
}
25182562

@@ -3143,8 +3187,9 @@
31433187
for(uint32_t i = 0; i < pl_sb_size(ptGarbage->sbtBindGroups); i++)
31443188
{
31453189
const uint16_t iBindGroupIndex = ptGarbage->sbtBindGroups[i].uIndex;
3190+
plBindGroup* ptResource = &ptDevice->sbtBindGroupsCold[iBindGroupIndex];
31463191
plMetalBindGroup* ptMetalResource = &ptDevice->sbtBindGroupsHot[iBindGroupIndex];
3147-
pl_sb_reset(ptMetalResource->sbtTextures);
3192+
pl_sb_reset(ptResource->_sbtTextures);
31483193
[ptMetalResource->tShaderArgumentBuffer release];
31493194
ptMetalResource->tShaderArgumentBuffer = nil;
31503195
pl_sb_push(ptDevice->sbtBindGroupFreeIndices, iBindGroupIndex);
@@ -3319,6 +3364,8 @@
33193364
pl_sb_push(ptDevice->sbtBindGroupFreeIndices, tHandle.uIndex);
33203365

33213366
plMetalBindGroup* ptMetalResource = &ptDevice->sbtBindGroupsHot[tHandle.uIndex];
3367+
plBindGroup* ptResource = &ptDevice->sbtBindGroupsCold[tHandle.uIndex];
3368+
pl_sb_free(ptResource->_sbtTextures);
33223369
[ptMetalResource->tShaderArgumentBuffer release];
33233370
ptMetalResource->tShaderArgumentBuffer = nil;
33243371
}

extensions/pl_graphics_vulkan.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ Index of this file:
1919
//-----------------------------------------------------------------------------
2020

2121
#include "pl.h"
22-
#include "pl_ds.h"
2322
#include "pl_string.h"
2423
#include "pl_memory.h"
2524
#include "pl_graphics_internal.h"

extensions/pl_shader_ext.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ Index of this file:
3333
#define PL_REALLOC(x, y) gptMemory->tracked_realloc((x), (y), __FILE__, __LINE__)
3434
#define PL_FREE(x) gptMemory->tracked_realloc((x), 0, __FILE__, __LINE__)
3535

36+
#ifndef PL_DS_ALLOC
37+
#define PL_DS_ALLOC(x) gptMemory->tracked_realloc(NULL, (x), __FILE__, __LINE__)
38+
#define PL_DS_ALLOC_INDIRECT(x, FILE, LINE) gptMemory->tracked_realloc(NULL, (x), FILE, LINE)
39+
#define PL_DS_FREE(x) gptMemory->tracked_realloc((x), 0, __FILE__, __LINE__)
40+
#endif
41+
3642
static const plFileI* gptFile = NULL;
3743
#endif
3844

extensions/pl_ui_internal.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ Index of this file:
5050

5151
#define PL_MATH_INCLUDE_FUNCTIONS
5252
#include "pl_math.h"
53-
#include "pl_ds.h"
5453

5554
#ifdef PL_UNITY_BUILD
5655
#include "pl_unity_ext.inc"
@@ -72,6 +71,8 @@ Index of this file:
7271
static plIO* gptIO = NULL;
7372
#endif
7473

74+
#include "pl_ds.h"
75+
7576
//-----------------------------------------------------------------------------
7677
// [SECTION] helper macros
7778
//-----------------------------------------------------------------------------

0 commit comments

Comments
 (0)