Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
hoffstadt committed Jan 23, 2025
1 parent ad7b705 commit 013a43b
Show file tree
Hide file tree
Showing 21 changed files with 1,025 additions and 834 deletions.
74 changes: 72 additions & 2 deletions docs/features.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,84 @@ Reference Renderer:
* Edge outline (Jump flood with compute shaders)
* Pixel perfect picking
* Directional lights + cascaded shadow maps
* Point lights
* Point lights + cubemap shadows
* Spot lights + shadows
* Soft shadows (PCF)
* Gamma correct, HDR rendering
* Deferred + forward rendering
* Reversed Z-buffer
* Vertex skinning (compute shaders)
* Panorama to cubemap calculations (compute shaders)
* Environment filtering (compute shaders)
* Parallax-corrected environment maps
* Dynamic environment mapping
* Cube map reflections (static and real time)
* Tonemapping
* gltf model loading
* stl model loading

Wishlist (from Wicked Engine):
* Morph target animation (with sparse accessor)
* Animated texturing
* Displacement mapping
* Parallax occlusion mapping
* Real time planar reflections
* Refractions (screen space, blurred)
* Interactive Water
* Bloom
* Motion Blur
* Lens Flare
* Light shafts
* Bokeh Depth of Field
* Chromatic aberration
* Multithreaded rendering
* Tessellation (silhouette smoothing, displacement mapping)
* GPU-based particles (emit from point, mesh, animated mesh)
* Soft particles
* Hair particle systems (grass/vegetation)
* Instanced rendering
* MSAA
* FXAA
* TAA (Temporal Antialiasing)
* Supersampling
* Physics: rigid body, soft body, ragdoll
* 3D Audio
* Input: keyboard, mouse, controller (rawinput, xinput), touch
* Controller feedback (vibration, LED)
* Backlog: log,input,scripting
* Gamma correct, HDR rendering
* Screen Space Ambient Occlusion (SSAO, HBAO, MSAO)
* Stochastic Screen Space Reflections
* Color Grading
* Sharpen filter
* Eye adaption
* Lua Scripting
* Impostor system
* Tiled forward (Forward+) rendering (+2.5D culling)
* Occlusion culling with gpu queries
* Tiled decals
* Frame Profiler
* Voxel Global Illumination
* Force Fields GPU simulation
* Particle - Depth Buffer collisions
* Ocean simulation (FFT)
* Translucent colored shadows
* Refraction caustics
* Volumetric light scattering
* Smooth Particle Hydrodynamics (SPH) Fluid Simulation
* Ray tracing, path tracing (on GPU)
* Lightmap baking (with GPU path tracing)
* Springs, Colliders
* Variable Rate Shading
* Real time ray tracing: ambient occlusion, shadows, reflections (DXR and Vulkan raytracing)
* Screen Space Contact Shadows
* Stochastic alphatest transparency
* Surfel GI
* HDR display output
* Dynamic Diffuse Global Illumination (DDGI)
* Procedural terrain generator
* Virtual textures
* Animation retargeting
* Video decoding: H264
* 3D path finding
* Screen Space Global Illumination (SSGI)
* Texture streaming
2 changes: 1 addition & 1 deletion extensions/pl_debug_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@ pl__show_device_memory(bool* bValue)
const char* apcAllocatorNames[] = {
"Device Memory: Local Buddy",
"Device Memory: Local Dedicated",
"Device Memory: Staging Uncached",
"Device Memory: Staging Uncached Buddy",
"Device Memory: Staging Cached"
};

Expand Down
5 changes: 5 additions & 0 deletions extensions/pl_draw_backend_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ Index of this file:
#define PL_DS_ALLOC_INDIRECT(x, FILE, LINE) gptMemory->tracked_realloc(NULL, (x), FILE, LINE)
#define PL_DS_FREE(x) gptMemory->tracked_realloc((x), 0, __FILE__, __LINE__)
#endif

static const plGraphicsI* gptGfx = NULL;
static const plStatsI* gptStats = NULL;
static const plDrawI* gptDraw = NULL;
static const plShaderI* gptShader = NULL;
#endif

#include "pl_ds.h"
Expand Down
1 change: 1 addition & 0 deletions extensions/pl_draw_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Index of this file:
//-----------------------------------------------------------------------------

#include <float.h>
#include <stdlib.h>
#include "pl.h"
#define PL_MATH_INCLUDE_FUNCTIONS
#include "pl_draw_ext.h"
Expand Down
21 changes: 11 additions & 10 deletions extensions/pl_ecs_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -897,8 +897,8 @@ pl_ecs_create_object(plComponentLibrary* ptLibrary, const char* pcName, plObject
plEntity tNewEntity = pl_ecs_create_tag(ptLibrary, pcName);

plObjectComponent* ptObject = pl_ecs_add_component(ptLibrary, PL_COMPONENT_TYPE_OBJECT, tNewEntity);
pl_ecs_add_component(ptLibrary, PL_COMPONENT_TYPE_TRANSFORM, tNewEntity);
pl_ecs_add_component(ptLibrary, PL_COMPONENT_TYPE_MESH, tNewEntity);
(void)pl_ecs_add_component(ptLibrary, PL_COMPONENT_TYPE_TRANSFORM, tNewEntity);
(void)pl_ecs_add_component(ptLibrary, PL_COMPONENT_TYPE_MESH, tNewEntity);

ptObject->tTransform = tNewEntity;
ptObject->tMesh = tNewEntity;
Expand Down Expand Up @@ -1137,17 +1137,17 @@ pl__object_update_job(plInvocationData tInvoData, void* pData)
};

// calculate AABB
ptMesh->tAABBFinal.tMax = (plVec3){-FLT_MAX, -FLT_MAX, -FLT_MAX};
ptMesh->tAABBFinal.tMin = (plVec3){FLT_MAX, FLT_MAX, FLT_MAX};
ptObject->tAABB.tMax = (plVec3){-FLT_MAX, -FLT_MAX, -FLT_MAX};
ptObject->tAABB.tMin = (plVec3){FLT_MAX, FLT_MAX, FLT_MAX};

for(uint32_t i = 0; i < 8; i++)
{
if(tVerticies[i].x > ptMesh->tAABBFinal.tMax.x) ptMesh->tAABBFinal.tMax.x = tVerticies[i].x;
if(tVerticies[i].y > ptMesh->tAABBFinal.tMax.y) ptMesh->tAABBFinal.tMax.y = tVerticies[i].y;
if(tVerticies[i].z > ptMesh->tAABBFinal.tMax.z) ptMesh->tAABBFinal.tMax.z = tVerticies[i].z;
if(tVerticies[i].x < ptMesh->tAABBFinal.tMin.x) ptMesh->tAABBFinal.tMin.x = tVerticies[i].x;
if(tVerticies[i].y < ptMesh->tAABBFinal.tMin.y) ptMesh->tAABBFinal.tMin.y = tVerticies[i].y;
if(tVerticies[i].z < ptMesh->tAABBFinal.tMin.z) ptMesh->tAABBFinal.tMin.z = tVerticies[i].z;
if(tVerticies[i].x > ptObject->tAABB.tMax.x) ptObject->tAABB.tMax.x = tVerticies[i].x;
if(tVerticies[i].y > ptObject->tAABB.tMax.y) ptObject->tAABB.tMax.y = tVerticies[i].y;
if(tVerticies[i].z > ptObject->tAABB.tMax.z) ptObject->tAABB.tMax.z = tVerticies[i].z;
if(tVerticies[i].x < ptObject->tAABB.tMin.x) ptObject->tAABB.tMin.x = tVerticies[i].x;
if(tVerticies[i].y < ptObject->tAABB.tMin.y) ptObject->tAABB.tMin.y = tVerticies[i].y;
if(tVerticies[i].z < ptObject->tAABB.tMin.z) ptObject->tAABB.tMin.z = tVerticies[i].z;
}
}

Expand Down Expand Up @@ -1288,6 +1288,7 @@ pl_run_probe_update_system(plComponentLibrary* ptLibrary)
plEnvironmentProbeComponent* ptProbe = &sbtComponents[i];
plTransformComponent* ptTransform = pl_ecs_get_component(ptLibrary, PL_COMPONENT_TYPE_TRANSFORM, tEntity);
ptProbe->tPosition = ptTransform->tWorld.col[3].xyz;
ptTransform->tWorld = pl_mat4_translate_vec3(ptProbe->tPosition);

// TODO: direction
}
Expand Down
10 changes: 6 additions & 4 deletions extensions/pl_ecs_ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,11 @@ enum _plHumanoidBone

enum _plEnvironmentProbeFlags
{
PL_ENVIRONMENT_PROBE_FLAGS_NONE = 0,
PL_ENVIRONMENT_PROBE_FLAGS_DIRTY = 1 << 0,
PL_ENVIRONMENT_PROBE_FLAGS_REALTIME = 1 << 1
PL_ENVIRONMENT_PROBE_FLAGS_NONE = 0,
PL_ENVIRONMENT_PROBE_FLAGS_DIRTY = 1 << 0,
PL_ENVIRONMENT_PROBE_FLAGS_REALTIME = 1 << 1,
PL_ENVIRONMENT_PROBE_FLAGS_INCLUDE_SKY = 1 << 2,
PL_ENVIRONMENT_PROBE_FLAGS_PARALLAX_CORRECTION_BOX = 1 << 3,
};

//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -507,6 +509,7 @@ typedef struct _plObjectComponent
{
plEntity tMesh;
plEntity tTransform;
plAABB tAABB;
} plObjectComponent;

typedef struct _plHierarchyComponent
Expand Down Expand Up @@ -565,7 +568,6 @@ typedef struct _plMeshComponent
plVec2* sbtVertexTextureCoordinates[8];
uint32_t* sbuIndices;
plAABB tAABB;
plAABB tAABBFinal;
} plMeshComponent;

typedef struct _plSkinComponent
Expand Down
86 changes: 34 additions & 52 deletions extensions/pl_gpu_allocators_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -553,72 +553,48 @@ pl_free_buddy(struct plDeviceMemoryAllocatorO* ptInst, plDeviceMemoryAllocation*
}

static plDeviceMemoryAllocation
pl_allocate_staging_uncached(
pl_allocate_staging_uncached_buddy(
struct plDeviceMemoryAllocatorO* ptInst, uint32_t uTypeFilter,
uint64_t ulSize, uint64_t ulAlignment, const char* pcName)
{
plDeviceAllocatorData* ptData = (plDeviceAllocatorData*)ptInst;

plDeviceMemoryAllocation tBlock = gptGfx->allocate_memory(ptData->ptDevice, ulSize,
PL_MEMORY_GPU_CPU, uTypeFilter, pcName);
if(ulAlignment > 0)
ulSize = ulSize + (ulAlignment - 1);

const uint32_t uLevel = pl__get_buddy_level(ulSize);
const uint32_t uNode = pl__get_device_node(ptInst, uLevel, 0);
PL_ASSERT(uNode != UINT32_MAX);

plDeviceAllocationRange* ptNode = &ptData->sbtNodes[uNode];
strncpy(ptNode->acName, pcName, PL_MAX_NAME_LENGTH);
ptNode->ulUsedSize = ulSize;

const uint32_t uBlockCount = pl_sb_size(ptData->sbtBlocks);
plDeviceMemoryAllocation* ptBlock = &ptData->sbtBlocks[ptNode->ulBlockIndex];

plDeviceMemoryAllocation tAllocation = {
.pHostMapped = tBlock.pHostMapped,
.uHandle = tBlock.uHandle,
.ulOffset = 0,
.pHostMapped = NULL,
.uHandle = (uint64_t)ptBlock->uHandle,
.ulOffset = ptNode->ulOffset,
.ulSize = ulSize,
.ptAllocator = ptData->ptAllocator,
.tMemoryMode = PL_MEMORY_GPU_CPU
};

uint32_t uBlockIndex = pl_sb_size(ptData->sbtBlocks);
if(pl_sb_size(ptData->sbtFreeBlockIndices) > 0)
uBlockIndex = pl_sb_pop(ptData->sbtFreeBlockIndices);
else
pl_sb_add(ptData->sbtBlocks);

plDeviceAllocationRange tRange = {
.ulOffset = 0,
.ulTotalSize = ulSize,
.ulUsedSize = ulSize,
.ulBlockIndex = uBlockIndex
};
pl_sprintf(tRange.acName, "%s", pcName);

pl_sb_push(ptData->sbtNodes, tRange);
ptData->sbtBlocks[uBlockIndex] = tBlock;
return tAllocation;
}

static void
pl_free_staging_uncached(struct plDeviceMemoryAllocatorO* ptInst, plDeviceMemoryAllocation* ptAllocation)
{
plDeviceAllocatorData* ptData = (plDeviceAllocatorData*)ptInst;
if(ulAlignment > 0)
tAllocation.ulOffset = (((tAllocation.ulOffset) + ((ulAlignment)-1)) & ~((ulAlignment)-1));

uint32_t uBlockIndex = 0;
uint32_t uNodeIndex = 0;
for(uint32_t i = 0; i < pl_sb_size(ptData->sbtNodes); i++)
if(tAllocation.uHandle == 0)
{
plDeviceAllocationRange* ptNode = &ptData->sbtNodes[i];
plDeviceMemoryAllocation* ptBlock = &ptData->sbtBlocks[ptNode->ulBlockIndex];

if(ptBlock->uHandle == ptAllocation->uHandle)
{
uNodeIndex = i;
uBlockIndex = (uint32_t)ptNode->ulBlockIndex;
ptBlock->ulSize = 0;
break;
}
plDeviceMemoryAllocation tActualAllocation = gptGfx->allocate_memory(ptData->ptDevice, PL_DEVICE_BUDDY_BLOCK_SIZE, PL_MEMORY_GPU_CPU, uTypeFilter, "Staging Uncached Buddy Heap");
ptBlock->uHandle = tActualAllocation.uHandle;
ptBlock->pHostMapped = tActualAllocation.pHostMapped;
tAllocation.uHandle = (uint64_t)ptBlock->uHandle;
}
pl_sb_del_swap(ptData->sbtNodes, uNodeIndex);
pl_sb_push(ptData->sbtFreeBlockIndices, uBlockIndex);
tAllocation.pHostMapped = &ptBlock->pHostMapped[tAllocation.ulOffset];

gptGfx->free_memory(ptData->ptDevice, &ptData->sbtBlocks[uBlockIndex]);

ptAllocation->pHostMapped = NULL;
ptAllocation->uHandle = 0;
ptAllocation->ulOffset = 0;
ptAllocation->ulSize = 0;
return tAllocation;
}

static plDeviceMemoryAllocation
Expand Down Expand Up @@ -787,10 +763,16 @@ pl_get_staging_uncached_allocator(plDevice* ptDevice)

ptAllocatorData = &gtAllocatorData;
ptAllocator = &gtAllocator;

if(ptAllocatorData->auFreeList[0] == 0)
{
for(uint32_t i = 0; i < PL_DEVICE_LOCAL_LEVELS; i++)
ptAllocatorData->auFreeList[i] = UINT32_MAX;
}
}
}
ptAllocator->allocate = pl_allocate_staging_uncached;
ptAllocator->free = pl_free_staging_uncached;
ptAllocator->allocate = pl_allocate_staging_uncached_buddy;
ptAllocator->free = pl_free_buddy;
return ptAllocator;
}

Expand Down
Loading

0 comments on commit 013a43b

Please sign in to comment.