Skip to content

Commit e7c0c12

Browse files
committed
chore: begin better shader interop support for renderer
1 parent ad6e25c commit e7c0c12

24 files changed

+805
-994
lines changed

extensions/pl_renderer_ext.c

Lines changed: 41 additions & 41 deletions
Large diffs are not rendered by default.

extensions/pl_renderer_ext.h

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,10 @@ Index of this file:
6767
// [SECTION] includes
6868
//-----------------------------------------------------------------------------
6969

70-
#include "pl_ecs_ext.inl" // plEntity
71-
#include "pl_resource_ext.inl" // plResourceHandle
72-
#include "pl_math.h" // plVec3, plMat4
70+
#include "pl_ecs_ext.inl" // plEntity
71+
#include "pl_resource_ext.inl" // plResourceHandle
72+
#include "pl_math.h" // plVec3, plMat4
73+
#include "pl_shader_interop_renderer.h" // plLightType
7374

7475
//-----------------------------------------------------------------------------
7576
// [SECTION] forward declarations
@@ -94,7 +95,6 @@ typedef int plShaderType;
9495
typedef int plMaterialFlags;
9596
typedef int plBlendMode;
9697
typedef int plLightFlags;
97-
typedef int plLightType;
9898
typedef int plEnvironmentProbeFlags;
9999
typedef int plObjectFlags;
100100
typedef int plTextureSlot;
@@ -258,6 +258,7 @@ enum _plTextureSlot
258258
PL_TEXTURE_SLOT_EMISSIVE_MAP,
259259
PL_TEXTURE_SLOT_OCCLUSION_MAP,
260260
PL_TEXTURE_SLOT_METAL_ROUGHNESS_MAP,
261+
261262
PL_TEXTURE_SLOT_COUNT
262263
};
263264

@@ -297,13 +298,6 @@ enum _plLightFlags
297298
PL_LIGHT_FLAG_VISUALIZER = 1 << 2,
298299
};
299300

300-
enum _plLightType
301-
{
302-
PL_LIGHT_TYPE_DIRECTIONAL,
303-
PL_LIGHT_TYPE_POINT,
304-
PL_LIGHT_TYPE_SPOT
305-
};
306-
307301
enum _plEnvironmentProbeFlags
308302
{
309303
PL_ENVIRONMENT_PROBE_FLAGS_NONE = 0,

extensions/pl_renderer_internal.c

Lines changed: 37 additions & 37 deletions
Large diffs are not rendered by default.

extensions/pl_renderer_internal.h

Lines changed: 14 additions & 189 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ Index of this file:
6060
#include "pl_vfs_ext.h"
6161
#include "pl_starter_ext.h"
6262

63+
// shader interop
64+
#include "pl_shader_interop_renderer.h"
65+
6366
//-----------------------------------------------------------------------------
6467
// [SECTION] defines
6568
//-----------------------------------------------------------------------------
@@ -110,7 +113,7 @@ Index of this file:
110113
static const plBVHI* gptBvh = NULL;
111114
static const plAnimationI* gptAnimation = NULL;
112115
static const plMeshI* gptMesh = NULL;
113-
static const plShaderVariantI* gptShaderVariant = NULL;
116+
static const plShaderVariantI* gptShaderVariant = NULL;
114117

115118
static struct _plIO* gptIO = 0;
116119
#endif
@@ -131,35 +134,19 @@ typedef struct _plRendererStagingBuffer plRendererStagingBuffer;
131134
typedef struct _plCullData plCullData;
132135
typedef struct _plMemCpyJobData plMemCpyJobData;
133136
typedef struct _plOBB plOBB;
137+
typedef struct _plEnvironmentProbeData plEnvironmentProbeData;
134138

135139
// shader variants
136140
typedef struct _plShaderVariant plShaderVariant;
137141
typedef struct _plComputeShaderVariant plComputeShaderVariant;
138142

139143
// gpu buffers
140-
typedef struct _plGPUProbeData plGPUProbeData;
141-
typedef struct _plGPUMaterial plGPUMaterial;
142-
typedef struct _plGPULight plGPULight;
143-
typedef struct _plGPULightShadowData plGPULightShadowData;
144144
typedef struct _plShadowInstanceBufferData plShadowInstanceBufferData;
145-
typedef struct _plEnvironmentProbeData plEnvironmentProbeData;
146-
147-
// gpu dynamic data types
148-
typedef struct _SkinDynamicData SkinDynamicData;
149-
typedef struct _BindGroup_0 BindGroup_0;
150-
typedef struct _DynamicData DynamicData;
151-
typedef struct _plShadowDynamicData plShadowDynamicData;
152-
typedef struct _plSkyboxDynamicData plSkyboxDynamicData;
153145
typedef struct _plDirectionLightShadowData plDirectionLightShadowData;
154-
typedef struct _plLightingDynamicData plLightingDynamicData;
155-
typedef struct _plPickDynamicData plPickDynamicData;
156-
typedef struct _plPostProcessOptions plPostProcessOptions;
157-
typedef struct _FilterShaderSpecData FilterShaderSpecData;
158146

159147
// enums & flags
160148
typedef int plDrawableFlags;
161149
typedef int plTextureMappingFlags;
162-
typedef int plMaterialInfoFlags;
163150
typedef int plRenderingFlags;
164151

165152
//-----------------------------------------------------------------------------
@@ -174,19 +161,6 @@ enum _plDrawableFlags
174161
PL_DRAWABLE_FLAG_PROBE = 1 << 2
175162
};
176163

177-
enum _plTextureMappingFlags
178-
{
179-
PL_HAS_BASE_COLOR_MAP = 1 << 0,
180-
PL_HAS_NORMAL_MAP = 1 << 1,
181-
PL_HAS_EMISSIVE_MAP = 1 << 2,
182-
PL_HAS_OCCLUSION_MAP = 1 << 3,
183-
PL_HAS_METALLIC_ROUGHNESS_MAP = 1 << 4
184-
};
185-
186-
enum _plMaterialInfoFlags
187-
{
188-
PL_INFO_MATERIAL_METALLICROUGHNESS = 1 << 0,
189-
};
190164

191165
enum _plRenderingFlags
192166
{
@@ -199,46 +173,13 @@ enum _plRenderingFlags
199173
// [SECTION] structs
200174
//-----------------------------------------------------------------------------
201175

202-
typedef struct _FilterShaderSpecData
203-
{
204-
int iResolution;
205-
float fRoughness;
206-
int iSampleCount;
207-
int iWidth;
208-
float fLodBias;
209-
int iDistribution;
210-
int iIsGeneratingLut;
211-
int iCurrentMipLevel;
212-
} FilterShaderSpecData;
213-
214-
typedef struct _plPostProcessOptions
215-
{
216-
float fTargetWidth;
217-
int _padding[3];
218-
plVec4 tOutlineColor;
219-
} plPostProcessOptions;
220-
221176
typedef struct _plOBB
222177
{
223178
plVec3 tCenter;
224179
plVec3 tExtents;
225180
plVec3 atAxes[3]; // Orthonormal basis
226181
} plOBB;
227182

228-
typedef struct _plLightingDynamicData
229-
{
230-
uint32_t uGlobalIndex;
231-
uint32_t uUnused[3];
232-
} plLightingDynamicData;
233-
234-
typedef struct _plPickDynamicData
235-
{
236-
uint32_t uID;
237-
uint32_t _unused[3];
238-
plVec4 tMousePos;
239-
plMat4 tModel;
240-
} plPickDynamicData;
241-
242183
typedef struct _plRendererStagingBuffer
243184
{
244185
plBufferHandle tStagingBufferHandle;
@@ -247,15 +188,6 @@ typedef struct _plRendererStagingBuffer
247188
double dLastTimeActive;
248189
} plRendererStagingBuffer;
249190

250-
typedef struct _SkinDynamicData
251-
{
252-
int iSourceDataOffset;
253-
int iDestDataOffset;
254-
int iDestVertexOffset;
255-
uint32_t uMaxSize;
256-
plMat4 tInverseWorld;
257-
} SkinDynamicData;
258-
259191
typedef struct _plSkinData
260192
{
261193
plEntity tEntity;
@@ -293,125 +225,19 @@ typedef struct _plDrawable
293225
bool bCulled;
294226
} plDrawable;
295227

296-
typedef struct _plGPUProbeData
297-
{
298-
plVec3 tPosition;
299-
float fRangeSqr;
300-
301-
uint32_t uLambertianEnvSampler;
302-
uint32_t uGGXEnvSampler;
303-
uint32_t uGGXLUT;
304-
int iParallaxCorrection;
305-
306-
plVec4 tMin;
307-
plVec4 tMax;
308-
} plGPUProbeData;
309-
310-
typedef struct _plGPUMaterial
311-
{
312-
// Metallic Roughness
313-
float fMetallicFactor;
314-
float fRoughnessFactor;
315-
int _unused0[2];
316-
plVec4 tBaseColorFactor;
317-
318-
// Emissive Strength
319-
plVec3 tEmissiveFactor;
320-
float fEmissiveStrength;
321-
322-
// Alpha mode
323-
float fAlphaCutoff;
324-
float fOcclusionStrength;
325-
int iBaseColorUVSet;
326-
int iNormalUVSet;
327-
328-
int iEmissiveUVSet;
329-
int iOcclusionUVSet;
330-
int iMetallicRoughnessUVSet;
331-
int iBaseColorTexIdx;
332-
333-
int iNormalTexIdx;
334-
int iEmissiveTexIdx;
335-
int iMetallicRoughnessTexIdx;
336-
int iOcclusionTexIdx;
337-
} plGPUMaterial;
338-
339-
typedef struct _plGPULight
340-
{
341-
plVec3 tPosition;
342-
float fIntensity;
343-
344-
plVec3 tDirection;
345-
float fInnerConeCos;
346-
347-
plVec3 tColor;
348-
float fRange;
349-
350-
int iShadowIndex;
351-
int iCascadeCount;
352-
int iCastShadow;
353-
float fOuterConeCos;
354-
355-
int iType;
356-
int _unused[3];
357-
} plGPULight;
358-
359-
typedef struct _plGPULightShadowData
360-
{
361-
plVec4 tCascadeSplits;
362-
plMat4 viewProjMat[6];
363-
int iShadowMapTexIdx;
364-
float fFactor;
365-
float fXOffset;
366-
float fYOffset;
367-
} plGPULightShadowData;
368-
369-
typedef struct _BindGroup_0
370-
{
371-
plVec4 tViewportSize;
372-
plVec4 tViewportInfo;
373-
plVec4 tCameraPos;
374-
plMat4 tCameraView;
375-
plMat4 tCameraProjection;
376-
plMat4 tCameraViewProjection;
377-
} BindGroup_0;
378-
379-
typedef struct _DynamicData
380-
{
381-
int iDataOffset;
382-
int iVertexOffset;
383-
int iMaterialOffset;
384-
uint32_t uGlobalIndex;
385-
} DynamicData;
386-
387228
typedef struct _plShadowInstanceBufferData
388229
{
389230
uint32_t uTransformIndex;
390231
int32_t iViewportIndex;
391232
} plShadowInstanceBufferData;
392233

393-
typedef struct _plShadowDynamicData
394-
{
395-
int iIndex;
396-
int iDataOffset;
397-
int iVertexOffset;
398-
int iMaterialIndex;
399-
} plShadowDynamicData;
400-
401-
typedef struct _plSkyboxDynamicData
402-
{
403-
uint32_t uGlobalIndex;
404-
uint32_t _auUnused[3];
405-
plMat4 tModel;
406-
} plSkyboxDynamicData;
407-
408234
typedef struct _plDirectionLightShadowData
409235
{
410-
plBufferHandle atDShadowCameraBuffers[PL_MAX_FRAMES_IN_FLIGHT];
411-
plBufferHandle atDLightShadowDataBuffer[PL_MAX_FRAMES_IN_FLIGHT];
412-
plGPULightShadowData* sbtDLightShadowData;
413-
uint32_t uOffset;
414-
uint32_t uOffsetIndex;
236+
plBufferHandle atDShadowCameraBuffers[PL_MAX_FRAMES_IN_FLIGHT];
237+
plBufferHandle atDLightShadowDataBuffer[PL_MAX_FRAMES_IN_FLIGHT];
238+
plGpuLightShadow* sbtDLightShadowData;
239+
uint32_t uOffset;
240+
uint32_t uOffsetIndex;
415241
} plDirectionLightShadowData;
416242

417243
typedef struct _plEnvironmentProbeData
@@ -539,9 +365,9 @@ typedef struct _plScene
539365
plVec3* sbtVertexPosBuffer;
540366
plVec4* sbtVertexDataBuffer;
541367
uint32_t* sbuIndexBuffer;
542-
plGPUMaterial* sbtMaterialBuffer;
368+
plGpuMaterial* sbtMaterialBuffer;
543369
plVec4* sbtSkinVertexDataBuffer;
544-
plGPULight* sbtLightData;
370+
plGpuLight* sbtLightData;
545371

546372
// GPU buffers
547373
plBufferHandle tVertexBuffer;
@@ -604,7 +430,7 @@ typedef struct _plScene
604430
// shadows
605431
plBufferHandle atShadowCameraBuffers[PL_MAX_FRAMES_IN_FLIGHT];
606432
plBufferHandle atLightShadowDataBuffer[PL_MAX_FRAMES_IN_FLIGHT];
607-
plGPULightShadowData* sbtLightShadowData;
433+
plGpuLightShadow* sbtLightShadowData;
608434
uint32_t uShadowOffset;
609435
uint32_t uShadowIndex;
610436
uint32_t uDShadowOffset;
@@ -613,7 +439,7 @@ typedef struct _plScene
613439
// environment probes
614440
plEntity tProbeMesh;
615441
plEnvironmentProbeData* sbtProbeData;
616-
plGPUProbeData* sbtGPUProbeData;
442+
plGpuProbe* sbtGPUProbeData;
617443
plBufferHandle atGPUProbeDataBuffers[PL_MAX_FRAMES_IN_FLIGHT];
618444
plBufferHandle atFilterWorkingBuffers[7]; // used for runtime filtering
619445

@@ -754,7 +580,6 @@ static void pl__renderer_post_process_scene(plCommandBuffer*, plView*, const plM
754580
static inline plDynamicBinding pl__allocate_dynamic_data(plDevice* ptDevice){ return pl_allocate_dynamic_data(gptGfx, gptData->ptDevice, &gptData->tCurrentDynamicDataBlock);}
755581
static void pl__renderer_add_drawable_skin_data_to_global_buffers(plScene*, uint32_t uDrawableIndex);
756582
static void pl__renderer_add_drawable_data_to_global_buffer(plScene*, uint32_t uDrawableIndex);
757-
static size_t pl__renderer_get_data_type_size2(plDataType tType);
758583
static plBlendState pl__renderer_get_blend_state(plBlendMode tBlendMode);
759584
static uint32_t pl__renderer_get_bindless_texture_index(plScene*, plTextureHandle);
760585
static uint32_t pl__renderer_get_bindless_cube_texture_index(plScene*, plTextureHandle);

0 commit comments

Comments
 (0)