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 c5a0e1e commit c49a6ea
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 26 deletions.
15 changes: 9 additions & 6 deletions extensions/pl_renderer_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ pl_refr_create_scene(void)
},
.atTextureBindings = {
{.uSlot = 4, .tStages = PL_STAGE_VERTEX | PL_STAGE_PIXEL, .tType = PL_TEXTURE_BINDING_TYPE_SAMPLED, .uDescriptorCount = 4096, ._bVariableDescriptorCount = true},
{.uSlot = 5, .tStages = PL_STAGE_VERTEX | PL_STAGE_PIXEL, .tType = PL_TEXTURE_BINDING_TYPE_SAMPLED, .uDescriptorCount = 4096, ._bVariableDescriptorCount = true}
}
};

Expand Down Expand Up @@ -544,8 +545,8 @@ pl_refr_create_scene(void)
gptGfx->update_bind_group(gptData->ptDevice, ptScene->tGlobalBindGroup, &tGlobalBindGroupData);

ptScene->uGGXLUT = pl__get_bindless_texture_index(uSceneHandle, gptData->tDummyTexture);
ptScene->uLambertianEnvSampler = pl__get_bindless_texture_index(uSceneHandle, gptData->tDummyTextureCube);
ptScene->uGGXEnvSampler = pl__get_bindless_texture_index(uSceneHandle, gptData->tDummyTextureCube);
ptScene->uLambertianEnvSampler = pl__get_bindless_cube_texture_index(uSceneHandle, gptData->tDummyTextureCube);
ptScene->uGGXEnvSampler = pl__get_bindless_cube_texture_index(uSceneHandle, gptData->tDummyTextureCube);

return uSceneHandle;
}
Expand Down Expand Up @@ -1875,8 +1876,8 @@ pl_refr_load_skybox_from_panorama(uint32_t uSceneHandle, const char* pcPath, int
}

ptScene->uGGXLUT = pl__get_bindless_texture_index(uSceneHandle, ptScene->tGGXLUTTexture);
ptScene->uLambertianEnvSampler = pl__get_bindless_texture_index(uSceneHandle, ptScene->tLambertianEnvTexture);
ptScene->uGGXEnvSampler = pl__get_bindless_texture_index(uSceneHandle, ptScene->tGGXEnvTexture);
ptScene->uLambertianEnvSampler = pl__get_bindless_cube_texture_index(uSceneHandle, ptScene->tLambertianEnvTexture);
ptScene->uGGXEnvSampler = pl__get_bindless_cube_texture_index(uSceneHandle, ptScene->tGGXEnvTexture);

pl_end_cpu_sample(gptProfile, 0);
pl_end_cpu_sample(gptProfile, 0);
Expand Down Expand Up @@ -2206,7 +2207,8 @@ pl_refr_reload_scene_shaders(uint32_t uSceneHandle)
{.uSlot = 3, .tStages = PL_STAGE_VERTEX | PL_STAGE_PIXEL}
},
.atTextureBindings = {
{.uSlot = 4, .tStages = PL_STAGE_VERTEX | PL_STAGE_PIXEL, .tType = PL_TEXTURE_BINDING_TYPE_SAMPLED, .uDescriptorCount = 4096, ._bVariableDescriptorCount = true}
{.uSlot = 4, .tStages = PL_STAGE_VERTEX | PL_STAGE_PIXEL, .tType = PL_TEXTURE_BINDING_TYPE_SAMPLED, .uDescriptorCount = 4096, ._bVariableDescriptorCount = true},
{.uSlot = 5, .tStages = PL_STAGE_VERTEX | PL_STAGE_PIXEL, .tType = PL_TEXTURE_BINDING_TYPE_SAMPLED, .uDescriptorCount = 4096, ._bVariableDescriptorCount = true}
}
},
{
Expand Down Expand Up @@ -2775,7 +2777,8 @@ pl_refr_finalize_scene(uint32_t uSceneHandle)
{.uSlot = 3, .tStages = PL_STAGE_VERTEX | PL_STAGE_PIXEL}
},
.atTextureBindings = {
{.uSlot = 4, .tStages = PL_STAGE_VERTEX | PL_STAGE_PIXEL, .tType = PL_TEXTURE_BINDING_TYPE_SAMPLED, .uDescriptorCount = 4096, ._bVariableDescriptorCount = true}
{.uSlot = 4, .tStages = PL_STAGE_VERTEX | PL_STAGE_PIXEL, .tType = PL_TEXTURE_BINDING_TYPE_SAMPLED, .uDescriptorCount = 4096, ._bVariableDescriptorCount = true},
{.uSlot = 5, .tStages = PL_STAGE_VERTEX | PL_STAGE_PIXEL, .tType = PL_TEXTURE_BINDING_TYPE_SAMPLED, .uDescriptorCount = 4096, ._bVariableDescriptorCount = true}
}
},
{
Expand Down
48 changes: 44 additions & 4 deletions extensions/pl_renderer_internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -1193,7 +1193,8 @@ pl_refr_create_global_shaders(void)
{.uSlot = 3, .tStages = PL_STAGE_VERTEX | PL_STAGE_PIXEL}
},
.atTextureBindings = {
{.uSlot = 4, .tStages = PL_STAGE_VERTEX | PL_STAGE_PIXEL, .tType = PL_TEXTURE_BINDING_TYPE_SAMPLED, .uDescriptorCount = 4096, ._bVariableDescriptorCount = true}
{.uSlot = 4, .tStages = PL_STAGE_VERTEX | PL_STAGE_PIXEL, .tType = PL_TEXTURE_BINDING_TYPE_SAMPLED, .uDescriptorCount = 4096, ._bVariableDescriptorCount = true},
{.uSlot = 5, .tStages = PL_STAGE_VERTEX | PL_STAGE_PIXEL, .tType = PL_TEXTURE_BINDING_TYPE_SAMPLED, .uDescriptorCount = 4096, ._bVariableDescriptorCount = true}
}
},
{
Expand Down Expand Up @@ -1261,7 +1262,8 @@ pl_refr_create_global_shaders(void)
{.uSlot = 3, .tStages = PL_STAGE_VERTEX | PL_STAGE_PIXEL}
},
.atTextureBindings = {
{.uSlot = 4, .tStages = PL_STAGE_VERTEX | PL_STAGE_PIXEL, .tType = PL_TEXTURE_BINDING_TYPE_SAMPLED, .uDescriptorCount = 4096, ._bVariableDescriptorCount = true}
{.uSlot = 4, .tStages = PL_STAGE_VERTEX | PL_STAGE_PIXEL, .tType = PL_TEXTURE_BINDING_TYPE_SAMPLED, .uDescriptorCount = 4096, ._bVariableDescriptorCount = true},
{.uSlot = 5, .tStages = PL_STAGE_VERTEX | PL_STAGE_PIXEL, .tType = PL_TEXTURE_BINDING_TYPE_SAMPLED, .uDescriptorCount = 4096, ._bVariableDescriptorCount = true}
}
},
{
Expand Down Expand Up @@ -1333,7 +1335,8 @@ pl_refr_create_global_shaders(void)
{.uSlot = 3, .tStages = PL_STAGE_VERTEX | PL_STAGE_PIXEL}
},
.atTextureBindings = {
{.uSlot = 4, .tStages = PL_STAGE_VERTEX | PL_STAGE_PIXEL, .tType = PL_TEXTURE_BINDING_TYPE_SAMPLED, .uDescriptorCount = 4096, ._bVariableDescriptorCount = true}
{.uSlot = 4, .tStages = PL_STAGE_VERTEX | PL_STAGE_PIXEL, .tType = PL_TEXTURE_BINDING_TYPE_SAMPLED, .uDescriptorCount = 4096, ._bVariableDescriptorCount = true},
{.uSlot = 5, .tStages = PL_STAGE_VERTEX | PL_STAGE_PIXEL, .tType = PL_TEXTURE_BINDING_TYPE_SAMPLED, .uDescriptorCount = 4096, ._bVariableDescriptorCount = true}
}
},
{
Expand Down Expand Up @@ -1950,4 +1953,41 @@ pl__get_bindless_texture_index(uint32_t uSceneHandle, plTextureHandle tTexture)
gptGfx->update_bind_group(gptData->ptDevice, ptScene->tGlobalBindGroup, &tGlobalBindGroupData);

return (uint32_t)ulValue;
}
}

static uint32_t
pl__get_bindless_cube_texture_index(uint32_t uSceneHandle, plTextureHandle tTexture)
{
plRefScene* ptScene = &gptData->sbtScenes[uSceneHandle];

if(pl_hm_has_key(ptScene->ptCubeTextureIndexHashmap, tTexture.uData))
{
return (uint32_t)pl_hm_lookup(ptScene->ptCubeTextureIndexHashmap, tTexture.uData);
}

uint64_t ulValue = pl_hm_get_free_index(ptScene->ptCubeTextureIndexHashmap);
if(ulValue == UINT64_MAX)
{
ulValue = ptScene->uCubeTextureIndexCount++;

// TODO: handle when greater than 4096
}

const plBindGroupUpdateTextureData tGlobalTextureData[] = {
{
.tTexture = tTexture,
.uSlot = 5,
.uIndex = (uint32_t)ulValue,
.tType = PL_TEXTURE_BINDING_TYPE_SAMPLED
},
};

plBindGroupUpdateData tGlobalBindGroupData = {
.uTextureCount = 1,
.atTextureBindings = tGlobalTextureData
};

gptGfx->update_bind_group(gptData->ptDevice, ptScene->tGlobalBindGroup, &tGlobalBindGroupData);

return (uint32_t)ulValue;
}
3 changes: 3 additions & 0 deletions extensions/pl_renderer_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,9 @@ typedef struct _plRefScene

// bindless texture system
uint32_t uTextureIndexCount;
uint32_t uCubeTextureIndexCount;
plHashMap* ptTextureIndexHashmap; // texture handle <-> index
plHashMap* ptCubeTextureIndexHashmap; // texture handle <-> index
plBindGroupHandle tGlobalBindGroup;

// material hashmaps (material component <-> GPU material)
Expand Down Expand Up @@ -521,6 +523,7 @@ static void pl_refr_create_global_shaders(void);
static size_t pl__get_data_type_size2(plDataType tType);
static plBlendState pl__get_blend_state(plBlendMode tBlendMode);
static uint32_t pl__get_bindless_texture_index(uint32_t uSceneHandle, plTextureHandle);
static uint32_t pl__get_bindless_cube_texture_index(uint32_t uSceneHandle, plTextureHandle);


#endif // PL_RENDERER_INTERNAL_EXT_H
4 changes: 2 additions & 2 deletions shaders/lighting.frag
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ layout(set = 0, binding = 1) readonly buffer plMaterialInfo
} tMaterialInfo;
layout(set = 0, binding = 2) uniform sampler tDefaultSampler;
layout(set = 0, binding = 3) uniform sampler tEnvSampler;
layout(set = 0, binding = 4) uniform texture2D at2DTextures[];
layout(set = 0, binding = 4) uniform textureCube atCubeTextures[];
layout(set = 0, binding = 4) uniform texture2D at2DTextures[1];
layout(set = 0, binding = 5) uniform textureCube atCubeTextures[1];

//-----------------------------------------------------------------------------
// [SECTION] bind group 1
Expand Down
4 changes: 2 additions & 2 deletions shaders/lighting.vert
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ layout(set = 0, binding = 1) readonly buffer plMaterialInfo
layout(set = 0, binding = 2) uniform sampler tDefaultSampler;
layout(set = 0, binding = 3) uniform sampler tEnvSampler;

layout(set = 0, binding = 4) uniform texture2D at2DTextures[];
layout(set = 0, binding = 4) uniform textureCube atCubeTextures[];
layout(set = 0, binding = 4) uniform texture2D at2DTextures[1];
layout(set = 0, binding = 5) uniform textureCube atCubeTextures[1];

//-----------------------------------------------------------------------------
// [SECTION] dynamic bind group
Expand Down
4 changes: 2 additions & 2 deletions shaders/primitive.frag
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ layout(set = 0, binding = 1) readonly buffer plMaterialInfo

layout(set = 0, binding = 2) uniform sampler tDefaultSampler;
layout(set = 0, binding = 3) uniform sampler tEnvSampler;
layout(set = 0, binding = 4) uniform texture2D at2DTextures[];
layout(set = 0, binding = 4) uniform textureCube atCubeTextures[];
layout(set = 0, binding = 4) uniform texture2D at2DTextures[1];
layout(set = 0, binding = 5) uniform textureCube atCubeTextures[1];

//-----------------------------------------------------------------------------
// [SECTION] bind group 1
Expand Down
4 changes: 2 additions & 2 deletions shaders/primitive.vert
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ layout(set = 0, binding = 1) readonly buffer plMaterialInfo

layout(set = 0, binding = 2) uniform sampler tDefaultSampler;
layout(set = 0, binding = 3) uniform sampler tEnvSampler;
layout(set = 0, binding = 4) uniform texture2D at2DTextures[];
layout(set = 0, binding = 4) uniform textureCube atCubeTextures[];
layout(set = 0, binding = 4) uniform texture2D at2DTextures[1];
layout(set = 0, binding = 5) uniform textureCube atCubeTextures[1];

//-----------------------------------------------------------------------------
// [SECTION] bind group 2
Expand Down
4 changes: 2 additions & 2 deletions shaders/shadow.frag
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ layout(set = 0, binding = 1) readonly buffer plMaterialInfo

layout(set = 0, binding = 2) uniform sampler tDefaultSampler;
layout(set = 0, binding = 3) uniform sampler tEnvSampler;
layout(set = 0, binding = 4) uniform texture2D at2DTextures[];
layout(set = 0, binding = 4) uniform textureCube atCubeTextures[];
layout(set = 0, binding = 4) uniform texture2D at2DTextures[1];
layout(set = 0, binding = 5) uniform textureCube atCubeTextures[1];

//-----------------------------------------------------------------------------
// [SECTION] bind group 1
Expand Down
4 changes: 2 additions & 2 deletions shaders/shadow.vert
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ layout(set = 0, binding = 1) readonly buffer plMaterialInfo

layout(set = 0, binding = 2) uniform sampler tDefaultSampler;
layout(set = 0, binding = 3) uniform sampler tEnvSampler;
layout(set = 0, binding = 4) uniform texture2D at2DTextures[];
layout(set = 0, binding = 4) uniform textureCube atCubeTextures[];
layout(set = 0, binding = 4) uniform texture2D at2DTextures[1];
layout(set = 0, binding = 5) uniform textureCube atCubeTextures[1];

//-----------------------------------------------------------------------------
// [SECTION] bind group 0
Expand Down
4 changes: 2 additions & 2 deletions shaders/transparent.frag
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ layout(set = 0, binding = 1) readonly buffer plMaterialInfo

layout(set = 0, binding = 2) uniform sampler tDefaultSampler;
layout(set = 0, binding = 3) uniform sampler tEnvSampler;
layout(set = 0, binding = 4) uniform texture2D at2DTextures[];
layout(set = 0, binding = 4) uniform textureCube atCubeTextures[];
layout(set = 0, binding = 4) uniform texture2D at2DTextures[1];
layout(set = 0, binding = 5) uniform textureCube atCubeTextures[1];

//-----------------------------------------------------------------------------
// [SECTION] bind group 1
Expand Down
4 changes: 2 additions & 2 deletions shaders/transparent.vert
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ layout(set = 0, binding = 1) readonly buffer plMaterialInfo

layout(set = 0, binding = 2) uniform sampler tDefaultSampler;
layout(set = 0, binding = 3) uniform sampler tEnvSampler;
layout(set = 0, binding = 4) uniform texture2D at2DTextures[];
layout(set = 0, binding = 4) uniform textureCube atCubeTextures[];
layout(set = 0, binding = 4) uniform texture2D at2DTextures[1];
layout(set = 0, binding = 5) uniform textureCube atCubeTextures[1];

//-----------------------------------------------------------------------------
// [SECTION] bind group 1
Expand Down

0 comments on commit c49a6ea

Please sign in to comment.