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 3497f97 commit c5a0e1e
Show file tree
Hide file tree
Showing 18 changed files with 605 additions and 580 deletions.
7 changes: 4 additions & 3 deletions extensions/pl_graphics_vulkan.c
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ pl_create_bind_group(plDevice* ptDevice, const plBindGroupDesc* ptDesc)
atDescriptorSetLayoutFlags[uCurrentBinding] = 0;
if (ptLayout->atTextureBindings[i]._bVariableDescriptorCount)
{
atDescriptorSetLayoutFlags[uCurrentBinding] |= VK_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT_EXT | VK_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT_EXT | VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT_EXT;
atDescriptorSetLayoutFlags[uCurrentBinding] |= VK_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT_EXT | VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT_EXT;
bHasVariableDescriptors = true;
}
atDescriptorSetLayoutBindings[uCurrentBinding++] = tBinding;
Expand Down Expand Up @@ -903,7 +903,8 @@ pl_create_bind_group(plDevice* ptDevice, const plBindGroupDesc* ptDesc)
.descriptorPool = ptDesc->ptPool->tDescriptorPool,
.descriptorSetCount = 1,
.pSetLayouts = &tDescriptorSetLayout,
.pNext = bHasVariableDescriptors ? &tVariableDescriptorCountAllocInfo : NULL
// .pNext = bHasVariableDescriptors ? &tVariableDescriptorCountAllocInfo : NULL
.pNext = NULL
};
PL_VULKAN(vkAllocateDescriptorSets(ptDevice->tLogicalDevice, &tAllocInfo, &tVulkanBindGroup.tDescriptorSet));

Expand Down Expand Up @@ -4045,7 +4046,7 @@ pl__create_bind_group_layout(plDevice* ptDevice, plBindGroupLayout* ptLayout, co
tBinding.descriptorCount = 1;
atDescriptorSetLayoutFlags[uCurrentBinding] = 0;
if (ptLayout->atTextureBindings[i]._bVariableDescriptorCount)
atDescriptorSetLayoutFlags[uCurrentBinding] |= VK_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT_EXT | VK_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT_EXT | VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT_EXT;
atDescriptorSetLayoutFlags[uCurrentBinding] |= VK_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT_EXT | VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT_EXT;
atDescriptorSetLayoutBindings[uCurrentBinding++] = tBinding;
}

Expand Down
413 changes: 223 additions & 190 deletions extensions/pl_renderer_ext.c

Large diffs are not rendered by default.

249 changes: 103 additions & 146 deletions extensions/pl_renderer_internal.c

Large diffs are not rendered by default.

59 changes: 40 additions & 19 deletions extensions/pl_renderer_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,19 +123,17 @@ typedef struct _plSkinData

typedef struct _plDrawable
{
plEntity tEntity;
plBindGroupHandle tMaterialBindGroup;
plBindGroupHandle tShadowMaterialBindGroup;
uint32_t uDataOffset;
uint32_t uVertexOffset;
uint32_t uVertexCount;
uint32_t uIndexOffset;
uint32_t uIndexCount;
uint32_t uMaterialIndex;
plShaderHandle tShader;
plShaderHandle tShadowShader;
uint32_t uSkinIndex;
bool bCulled;
plEntity tEntity;
uint32_t uDataOffset;
uint32_t uVertexOffset;
uint32_t uVertexCount;
uint32_t uIndexOffset;
uint32_t uIndexCount;
uint32_t uMaterialIndex;
plShaderHandle tShader;
plShaderHandle tShadowShader;
uint32_t uSkinIndex;
bool bCulled;
} plDrawable;

typedef struct _plGPUMaterial
Expand All @@ -154,15 +152,18 @@ typedef struct _plGPUMaterial
// Alpha mode
float fAlphaCutoff;
float fOcclusionStrength;
int _unused1[2];

int iBaseColorUVSet;
int iNormalUVSet;

int iEmissiveUVSet;
int iOcclusionUVSet;

int iMetallicRoughnessUVSet;
int _unused2[3];
int iBaseColorTexIdx;

int iNormalTexIdx;
int iEmissiveTexIdx;
int iMetallicRoughnessTexIdx;
int iOcclusionTexIdx;
} plGPUMaterial;

typedef struct _plGPULight
Expand Down Expand Up @@ -194,6 +195,11 @@ typedef struct _BindGroup_0
plMat4 tCameraView;
plMat4 tCameraProjection;
plMat4 tCameraViewProjection;

uint32_t uLambertianEnvSampler;
uint32_t uGGXEnvSampler;
uint32_t uGGXLUT;
uint32_t _uUnUsed;
} BindGroup_0;

typedef struct _DynamicData
Expand Down Expand Up @@ -277,9 +283,13 @@ typedef struct _plRefScene
plTextureHandle tSkyboxTexture;
plBindGroupHandle tSkyboxBindGroup;
plTextureHandle tGGXLUTTexture;
uint32_t uGGXLUT;
plTextureHandle tLambertianEnvTexture;
uint32_t uLambertianEnvSampler;
plTextureHandle tGGXEnvTexture;
uint32_t uGGXEnvSampler;


// shared bind groups
plBindGroupHandle tSkinBindGroup0;

Expand Down Expand Up @@ -317,8 +327,14 @@ typedef struct _plRefScene
plHashMap* ptDeferredHashmap;
plHashMap* ptForwardHashmap;

// material bindgroup reuse hashmaps
plHashMap* ptShadowBindgroupHashmap;
// bindless texture system
uint32_t uTextureIndexCount;
plHashMap* ptTextureIndexHashmap; // texture handle <-> index
plBindGroupHandle tGlobalBindGroup;

// material hashmaps (material component <-> GPU material)
plMaterialComponent* sbtMaterials;
plHashMap* ptMaterialHashmap;

} plRefScene;

Expand Down Expand Up @@ -408,6 +424,10 @@ typedef struct _plRefRendererData
// dynamic buffer system
plDynamicDataBlock tCurrentDynamicDataBlock;

// texture lookup (resource handle <-> texture handle)
plTextureHandle* sbtTextureHandles;
plHashMap* ptTextureHashmap;

// graphics options
bool bReloadSwapchain;
bool bVSync;
Expand Down Expand Up @@ -500,6 +520,7 @@ static void pl__add_drawable_data_to_global_buffer(plRefScene
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);


#endif // PL_RENDERER_INTERNAL_EXT_H
56 changes: 32 additions & 24 deletions shaders/lighting.frag
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#version 450
#extension GL_ARB_separate_shader_objects : enable
#extension GL_EXT_nonuniform_qualifier : enable

#include "defines.glsl"
#include "material.glsl"
Expand All @@ -17,29 +18,19 @@ layout(constant_id = 1) const int iLightCount = 1;
// [SECTION] bind group 0
//-----------------------------------------------------------------------------

layout(set = 0, binding = 0) uniform _plGlobalInfo
{
vec4 tViewportSize;
vec4 tCameraPos;
mat4 tCameraView;
mat4 tCameraProjection;
mat4 tCameraViewProjection;
} tGlobalInfo;

layout(std140, set = 0, binding = 1) readonly buffer _tVertexBuffer
layout(std140, set = 0, binding = 0) readonly buffer _tVertexBuffer
{
vec4 atVertexData[];
} tVertexBuffer;

layout(set = 0, binding = 2) readonly buffer plMaterialInfo
layout(set = 0, binding = 1) readonly buffer plMaterialInfo
{
tMaterial atMaterials[];
} tMaterialInfo;
layout(set = 0, binding = 3) uniform sampler tDefaultSampler;
layout(set = 0, binding = 4) uniform sampler tEnvSampler;
layout (set = 0, binding = 5) uniform textureCube u_LambertianEnvSampler;
layout (set = 0, binding = 6) uniform textureCube u_GGXEnvSampler;
layout (set = 0, binding = 7) uniform texture2D u_GGXLUT;
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[];

//-----------------------------------------------------------------------------
// [SECTION] bind group 1
Expand All @@ -54,18 +45,31 @@ layout(input_attachment_index = 0, set = 1, binding = 3) uniform subpassInput t
// [SECTION] bind group 2
//-----------------------------------------------------------------------------

layout(set = 2, binding = 0) uniform _plLightInfo
layout(set = 2, binding = 0) uniform _plGlobalInfo
{
vec4 tViewportSize;
vec4 tCameraPos;
mat4 tCameraView;
mat4 tCameraProjection;
mat4 tCameraViewProjection;
uint uLambertianEnvSampler;
uint uGGXEnvSampler;
uint uGGXLUT;
uint _uUnUsed;
} tGlobalInfo;

layout(set = 2, binding = 1) uniform _plLightInfo
{
plLightData atData[1000];
} tLightInfo;

layout(set = 2, binding = 1) readonly buffer plShadowData
layout(set = 2, binding = 2) readonly buffer plShadowData
{
plLightShadowData atData[];
} tShadowData;

layout (set = 2, binding = 2) uniform texture2D shadowmap[4];
layout(set = 2, binding = 6) uniform sampler tShadowSampler;
layout (set = 2, binding = 3) uniform texture2D shadowmap[4];
layout(set = 2, binding = 7) uniform sampler tShadowSampler;

//-----------------------------------------------------------------------------
// [SECTION] dynamic bind group
Expand Down Expand Up @@ -159,14 +163,16 @@ vec3 BRDF_specularGGX(vec3 f0, vec3 f90, float alphaRoughness, float specularWei
vec3 getDiffuseLight(vec3 n)
{
// n.z = -n.z; uncomment if not reverse z
return texture(samplerCube(u_LambertianEnvSampler, tEnvSampler), n).rgb;
// return texture(samplerCube(u_LambertianEnvSampler, tEnvSampler), n).rgb;
return texture(samplerCube(atCubeTextures[nonuniformEXT(tGlobalInfo.uLambertianEnvSampler)], tEnvSampler), n).rgb;
}


vec4 getSpecularSample(vec3 reflection, float lod)
{
// reflection.z = -reflection.z; // uncomment if not reverse z
return textureLod(samplerCube(u_GGXEnvSampler, tEnvSampler), reflection, lod);
// return textureLod(samplerCube(u_GGXEnvSampler, tEnvSampler), reflection, lod);
return textureLod(samplerCube(atCubeTextures[nonuniformEXT(tGlobalInfo.uGGXEnvSampler)], tEnvSampler), reflection, lod);
}

vec3 getIBLRadianceGGX(vec3 n, vec3 v, float roughness, vec3 F0, float specularWeight, int u_MipCount)
Expand All @@ -178,7 +184,8 @@ vec3 getIBLRadianceGGX(vec3 n, vec3 v, float roughness, vec3 F0, float specularW

float NdotV = clampedDot(n, v);
vec2 brdfSamplePoint = clamp(vec2(NdotV, roughness), vec2(0.0, 0.0), vec2(1.0, 1.0));
vec2 f_ab = texture(sampler2D(u_GGXLUT, tEnvSampler), brdfSamplePoint).rg;
// vec2 f_ab = texture(sampler2D(u_GGXLUT, tEnvSampler), brdfSamplePoint).rg;
vec2 f_ab = texture(sampler2D(at2DTextures[nonuniformEXT(tGlobalInfo.uGGXLUT)], tEnvSampler), brdfSamplePoint).rg;

vec3 specularLight = specularSample.rgb;

Expand All @@ -196,7 +203,8 @@ vec3 getIBLRadianceLambertian(vec3 n, vec3 v, float roughness, vec3 diffuseColor

float NdotV = clampedDot(n, v);
vec2 brdfSamplePoint = clamp(vec2(NdotV, roughness), vec2(0.0, 0.0), vec2(1.0, 1.0));
vec2 f_ab = texture(sampler2D(u_GGXLUT, tEnvSampler), brdfSamplePoint).rg;
// vec2 f_ab = texture(sampler2D(u_GGXLUT, tEnvSampler), brdfSamplePoint).rg;
vec2 f_ab = texture(sampler2D(at2DTextures[nonuniformEXT(tGlobalInfo.uGGXLUT)], tEnvSampler), brdfSamplePoint).rg;

// see https://bruop.github.io/ibl/#single_scattering_results at Single Scattering Results
// Roughness dependent fresnel, from Fdez-Aguera
Expand Down
24 changes: 8 additions & 16 deletions shaders/lighting.vert
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#version 450
#extension GL_ARB_separate_shader_objects : enable
#extension GL_EXT_nonuniform_qualifier : enable

struct tMaterial
{
Expand Down Expand Up @@ -79,30 +80,21 @@ struct tMaterial
int IridescenceThicknessUVSet;
};

layout(set = 0, binding = 0) uniform _plGlobalInfo
{
vec4 tViewportSize;
vec4 tCameraPos;
mat4 tCameraView;
mat4 tCameraProjection;
mat4 tCameraViewProjection;
} tGlobalInfo;

layout(std140, set = 0, binding = 1) readonly buffer _tVertexBuffer
layout(std140, set = 0, binding = 0) readonly buffer _tVertexBuffer
{
vec4 atVertexData[];
} tVertexBuffer;

layout(set = 0, binding = 2) readonly buffer plMaterialInfo
layout(set = 0, binding = 1) readonly buffer plMaterialInfo
{
tMaterial atMaterials[];
} tMaterialInfo;

layout(set = 0, binding = 3) uniform sampler tDefaultSampler;
layout(set = 0, binding = 4) uniform sampler tEnvSampler;
layout (set = 0, binding = 5) uniform textureCube u_LambertianEnvSampler;
layout (set = 0, binding = 6) uniform textureCube u_GGXEnvSampler;
layout (set = 0, binding = 7) uniform texture2D u_GGXLUT;
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[];

//-----------------------------------------------------------------------------
// [SECTION] dynamic bind group
Expand Down
16 changes: 8 additions & 8 deletions shaders/material.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@ struct tMaterial
// Alpha mode
float u_AlphaCutoff;
float u_OcclusionStrength;
float u_Unused0;
float u_Unused1;
//-------------------------- ( 16 bytes )

int BaseColorUVSet;
int NormalUVSet;
//-------------------------- ( 16 bytes )

int EmissiveUVSet;
int OcclusionUVSet;
int MetallicRoughnessUVSet;
int iBaseColorTexIdx;
//-------------------------- ( 16 bytes )

int MetallicRoughnessUVSet;
float u_Unused2;
float u_Unused3;
float u_Unused4;
int iNormalTexIdx;
int iEmissiveTexIdx;
int iMetallicRoughnessTexIdx;
int iOcclusionTexIdx;
//-------------------------- ( 16 bytes )
};

Expand Down
7 changes: 5 additions & 2 deletions shaders/outline.frag
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ layout(set = 0, binding = 0) uniform _plGlobalInfo
mat4 tCameraView;
mat4 tCameraProjection;
mat4 tCameraViewProjection;
uint uLambertianEnvSampler;
uint uGGXEnvSampler;
uint uGGXLUT;
uint _uUnUsed;
} tGlobalInfo;

layout(std140, set = 0, binding = 1) readonly buffer _tVertexBuffer
Expand Down Expand Up @@ -46,8 +50,7 @@ layout(set = 3, binding = 0) uniform PL_DYNAMIC_DATA
// output
layout(location = 0) out vec4 outColor;

void
main()
void main()
{
outColor = tObjectInfo.tColor;
}
4 changes: 4 additions & 0 deletions shaders/outline.vert
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ layout(set = 0, binding = 0) uniform _plGlobalInfo
mat4 tCameraView;
mat4 tCameraProjection;
mat4 tCameraViewProjection;
uint uLambertianEnvSampler;
uint uGGXEnvSampler;
uint uGGXLUT;
uint _uUnUsed;
} tGlobalInfo;

layout(std140, set = 0, binding = 1) readonly buffer _tVertexBuffer
Expand Down
4 changes: 4 additions & 0 deletions shaders/picking.vert
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ layout(set = 0, binding = 0) uniform _plGlobalInfo
mat4 tCameraView;
mat4 tCameraProjection;
mat4 tCameraViewProjection;
uint uLambertianEnvSampler;
uint uGGXEnvSampler;
uint uGGXLUT;
uint _uUnUsed;
} tGlobalInfo;

//-----------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit c5a0e1e

Please sign in to comment.