Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
hoffstadt committed Dec 12, 2024
1 parent 9321ee7 commit 37f3baf
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 16 deletions.
35 changes: 24 additions & 11 deletions extensions/pl_graphics_metal.m
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,12 @@
{
id<MTLBuffer> tShaderArgumentBuffer;
plBindGroupLayout tLayout;
plTextureHandle atTextureBindings[PL_MAX_TEXTURES_PER_BIND_GROUP];
plBufferHandle atBufferBindings[PL_MAX_BUFFERS_PER_BIND_GROUP];
plSamplerHandle atSamplerBindings[PL_MAX_TEXTURES_PER_BIND_GROUP];
uint32_t uHeapCount;
id<MTLHeap> atRequiredHeaps[PL_MAX_TEXTURES_PER_BIND_GROUP * PL_MAX_BUFFERS_PER_BIND_GROUP];
uint32_t uOffset;
plTextureHandle* sbtTextures;
} plMetalBindGroup;

typedef struct _plMetalShader
Expand Down Expand Up @@ -870,7 +870,9 @@
NSUInteger argumentBufferLength = sizeof(uint64_t) * uDescriptorCount;
MTLSizeAndAlign tSizeAlign = [ptDevice->tDevice heapBufferSizeAndAlignWithLength:argumentBufferLength options:MTLResourceStorageModeShared];

plMetalBindGroup tMetalBindGroup = {0};
plMetalBindGroup tMetalBindGroup = {
.tLayout = *ptLayout
};

tMetalBindGroup.tShaderArgumentBuffer = ptDesc->ptPool->tArgumentBuffer.tBuffer;
tMetalBindGroup.uOffset = ptDesc->ptPool->szCurrentArgumentOffset;
Expand Down Expand Up @@ -927,7 +929,7 @@
plMetalTexture* ptMetalTexture = &ptDevice->sbtTexturesHot[ptUpdate->tTexture.uIndex];
MTLResourceID* pptDestination = (MTLResourceID*)&pulDescriptorStart[ptUpdate->uSlot + ptUpdate->uIndex];
*pptDestination = ptMetalTexture->tTexture.gpuResourceID;
ptMetalBindGroup->atTextureBindings[i] = ptUpdate->tTexture;
pl_sb_push(ptMetalBindGroup->sbtTextures, ptUpdate->tTexture);

bool bHeapFound = false;
for(uint32_t j = 0; j < ptMetalBindGroup->uHeapCount; j++)
Expand Down Expand Up @@ -2034,6 +2036,13 @@
[ptEncoder->tEncoder useHeap:ptBindGroup->atRequiredHeaps[j]];
}

for(uint32_t k = 0; k < pl_sb_size(ptBindGroup->sbtTextures); k++)
{
const plTextureHandle tTextureHandle = ptBindGroup->sbtTextures[k];
plTexture* ptTexture = pl__get_texture(ptDevice, tTextureHandle);
[ptEncoder->tEncoder useResource:ptDevice->sbtTexturesHot[tTextureHandle.uIndex].tTexture usage:MTLResourceUsageRead | MTLResourceUsageWrite];
}

[ptEncoder->tEncoder setBuffer:ptBindGroup->tShaderArgumentBuffer
offset:ptBindGroup->uOffset
atIndex:uFirst + i];
Expand Down Expand Up @@ -2062,9 +2071,9 @@
[ptEncoder->tEncoder useHeap:ptBindGroup->atRequiredHeaps[j] stages:MTLRenderStageVertex | MTLRenderStageFragment];
}

for(uint32_t k = 0; k < ptBindGroup->tLayout._uTextureBindingCount; k++)
for(uint32_t k = 0; k < pl_sb_size(ptBindGroup->sbtTextures); k++)
{
const plTextureHandle tTextureHandle = ptBindGroup->atTextureBindings[k];
const plTextureHandle tTextureHandle = ptBindGroup->sbtTextures[k];
plTexture* ptTexture = pl__get_texture(ptDevice, tTextureHandle);
[ptEncoder->tEncoder useResource:ptDevice->sbtTexturesHot[tTextureHandle.uIndex].tTexture usage:MTLResourceUsageRead stages:MTLRenderStageVertex | MTLRenderStageFragment];
}
Expand Down Expand Up @@ -2265,9 +2274,9 @@
[ptEncoder->tEncoder useHeap:ptMetalBindGroup->atRequiredHeaps[j] stages:MTLRenderStageVertex | MTLRenderStageFragment];
}

for(uint32_t k = 0; k < ptMetalBindGroup->tLayout._uTextureBindingCount; k++)
for(uint32_t k = 0; k < pl_sb_size(ptMetalBindGroup->sbtTextures); k++)
{
const plTextureHandle tTextureHandle = ptMetalBindGroup->atTextureBindings[k];
const plTextureHandle tTextureHandle = ptMetalBindGroup->sbtTextures[k];
plTexture* ptTexture = pl__get_texture(ptDevice, tTextureHandle);
[ptEncoder->tEncoder useResource:ptDevice->sbtTexturesHot[tTextureHandle.uIndex].tTexture usage:MTLResourceUsageRead stages:MTLRenderStageVertex | MTLRenderStageFragment];
}
Expand All @@ -2287,9 +2296,9 @@
[ptEncoder->tEncoder useHeap:ptMetalBindGroup->atRequiredHeaps[j] stages:MTLRenderStageVertex | MTLRenderStageFragment];
}

for(uint32_t k = 0; k < ptMetalBindGroup->tLayout._uTextureBindingCount; k++)
for(uint32_t k = 0; k < pl_sb_size(ptMetalBindGroup->sbtTextures); k++)
{
const plTextureHandle tTextureHandle = ptMetalBindGroup->atTextureBindings[k];
const plTextureHandle tTextureHandle = ptMetalBindGroup->sbtTextures[k];
plTexture* ptTexture = pl__get_texture(ptDevice, tTextureHandle);
[ptEncoder->tEncoder useResource:ptDevice->sbtTexturesHot[tTextureHandle.uIndex].tTexture usage:MTLResourceUsageRead stages:MTLRenderStageVertex | MTLRenderStageFragment];
}
Expand All @@ -2309,9 +2318,13 @@
[ptEncoder->tEncoder useHeap:ptMetalBindGroup->atRequiredHeaps[j] stages:MTLRenderStageVertex | MTLRenderStageFragment];
}

for(uint32_t k = 0; k < ptMetalBindGroup->tLayout._uTextureBindingCount; k++)
for(uint32_t k = 0; k < pl_sb_size(ptMetalBindGroup->sbtTextures); k++)
{
const plTextureHandle tTextureHandle = ptMetalBindGroup->atTextureBindings[k];
const plTextureHandle tTextureHandle = ptMetalBindGroup->sbtTextures[k];
if(tTextureHandle.uIndex > 21 && tTextureHandle.uIndex < 26)
{
int a = 5;
}
[ptEncoder->tEncoder useResource:ptDevice->sbtTexturesHot[tTextureHandle.uIndex].tTexture usage:MTLResourceUsageRead stages:MTLRenderStageVertex | MTLRenderStageFragment];
}

Expand Down
20 changes: 16 additions & 4 deletions extensions/pl_renderer_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -1782,15 +1782,27 @@ pl_refr_load_skybox_from_panorama(uint32_t uSceneHandle, const char* pcPath, int
};

const size_t uMaxFaceSize = (size_t)iResolution * (size_t)iResolution * 4 * sizeof(float);
const plBufferDesc tOutputBufferDesc = {
.tUsage = PL_BUFFER_USAGE_STORAGE,
.szByteSize = uMaxFaceSize,
.pcDebugName = "inner buffer"

static const char* apcBufferNames[] = {
"output buffer 0",
"output buffer 1",
"output buffer 2",
"output buffer 3",
"output buffer 4",
"output buffer 5",
"output buffer 6"
};

plBufferHandle atInnerComputeBuffers[7] = {0};
for(uint32_t j = 0; j < 7; j++)
{
const plBufferDesc tOutputBufferDesc = {
.tUsage = PL_BUFFER_USAGE_STORAGE,
.szByteSize = uMaxFaceSize,
.pcDebugName = apcBufferNames[j]
};
atInnerComputeBuffers[j] = pl__refr_create_local_buffer(&tOutputBufferDesc, "inner buffer", j, NULL);
}

const plBindGroupDesc tFilterComputeBindGroupDesc = {
.ptPool = gptData->aptTempGroupPools[gptGfx->get_current_frame_index()],
Expand Down
2 changes: 1 addition & 1 deletion shaders/filter_environment.comp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pl_write_face(int iPixel, int iFace, vec3 tColorIn)
tFaceOut3.atPixelData[iPixel] = tColor;
else if (iFace == 4)
tFaceOut4.atPixelData[iPixel] = tColor;
else //if(iFace == 5)
else if(iFace == 5)
tFaceOut5.atPixelData[iPixel] = tColor;
}

Expand Down

0 comments on commit 37f3baf

Please sign in to comment.