Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reference renderer work #12

Merged
merged 16 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 41 additions & 17 deletions apps/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)

plProfileContext* ptProfileCtx = pl_create_profile_context();
plLogContext* ptLogCtx = pl_create_log_context();

pl_begin_profile_frame();

// add some context to data registry
ptAppData = PL_ALLOC(sizeof(plAppData));
Expand Down Expand Up @@ -218,12 +220,20 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
for(uint32_t i = 0; i < PL_FRAMES_IN_FLIGHT; i++)
ptAppData->atSempahore[i] = gptDevice->create_semaphore(&gptRenderer->get_graphics()->tDevice, false);

// create offscreen view (temporary API)
ptAppData->uSceneHandle0 = gptRenderer->create_scene();
ptAppData->uSceneHandle1 = gptRenderer->create_scene();

pl_begin_profile_sample("load environments");
const plMat4 tTransform0 = pl_mat4_translate_xyz(2.0f, 1.0f, 0.0f);
gptRenderer->load_skybox_from_panorama(ptAppData->uSceneHandle0, "../data/glTF-Sample-Environments-main/field.jpg", 1024);
gptRenderer->load_skybox_from_panorama(ptAppData->uSceneHandle1, "../data/glTF-Sample-Environments-main/field.jpg", 1024);
pl_end_profile_sample();

pl_begin_profile_sample("create scene views");
ptAppData->uViewHandle0 = gptRenderer->create_view(ptAppData->uSceneHandle0, (plVec2){ptIO->afMainViewportSize[0] , ptIO->afMainViewportSize[1]});
ptAppData->uViewHandle1 = gptRenderer->create_view(ptAppData->uSceneHandle0, (plVec2){500.0f, 500.0f});
ptAppData->uViewHandle2 = gptRenderer->create_view(ptAppData->uSceneHandle1, (plVec2){500.0f, 500.0f});
pl_end_profile_sample();

// temporary draw layer for submitting fullscreen quad of offscreen render
ptAppData->ptDrawLayer = pl_request_layer(pl_get_draw_list(NULL), "draw layer");
Expand All @@ -245,19 +255,14 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
gptCamera->update(gptEcs->get_component(ptSecondaryComponentLibrary, PL_COMPONENT_TYPE_CAMERA, ptAppData->tMainCamera2));

// load models
pl_begin_profile_frame();

pl_begin_profile_sample("load skyboxes");
const plMat4 tTransform0 = pl_mat4_translate_xyz(2.0f, 1.0f, 0.0f);
gptRenderer->load_skybox_from_panorama(ptAppData->uSceneHandle0, "../data/glTF-Sample-Environments-main/ennis.jpg", 1024);
gptRenderer->load_skybox_from_panorama(ptAppData->uSceneHandle1, "../data/glTF-Sample-Environments-main/ennis.jpg", 1024);
pl_end_profile_sample();


plModelLoaderData tLoaderData0 = {0};

pl_begin_profile_sample("load models 0");
gptModelLoader->load_gltf(ptMainComponentLibrary, "../data/glTF-Sample-Assets-main/Models/Sponza/glTF/Sponza.gltf", NULL, &tLoaderData0);
// gptModelLoader->load_gltf(ptMainComponentLibrary, "../data/glTF-Sample-Assets-main/Models/FlightHelmet/glTF/FlightHelmet.gltf", NULL, &tLoaderData0);
gptModelLoader->load_gltf(ptMainComponentLibrary, "../data/glTF-Sample-Assets-main/Models/CesiumMan/glTF/CesiumMan.gltf", NULL, &tLoaderData0);
// gptModelLoader->load_gltf(ptMainComponentLibrary, "../data/glTF-Sample-Assets-main/Models/DamagedHelmet/glTF/DamagedHelmet.gltf", NULL, &tLoaderData0);
gptModelLoader->load_gltf(ptMainComponentLibrary, "../data/glTF-Sample-Assets-main/Models/Sponza/glTF/Sponza.gltf", NULL, &tLoaderData0);
gptModelLoader->load_stl(ptMainComponentLibrary, "../data/pilotlight-assets-master/meshes/monkey.stl", (plVec4){1.0f, 1.0f, 0.0f, 0.80f}, &tTransform0, &tLoaderData0);
gptRenderer->add_drawable_objects_to_scene(ptAppData->uSceneHandle0, tLoaderData0.uOpaqueCount, tLoaderData0.atOpaqueObjects, tLoaderData0.uTransparentCount, tLoaderData0.atTransparentObjects);
gptModelLoader->free_data(&tLoaderData0);
Expand Down Expand Up @@ -418,7 +423,8 @@ pl_app_update(plAppData* ptAppData)
uint64_t ulValue1 = ulValue0 + 1;
uint64_t ulValue2 = ulValue0 + 2;
uint64_t ulValue3 = ulValue0 + 3;
ptAppData->aulNextTimelineValue[ptGraphics->uCurrentFrameIndex] = ulValue3;
uint64_t ulValue4 = ulValue0 + 4;
ptAppData->aulNextTimelineValue[ptGraphics->uCurrentFrameIndex] = ulValue4;


// first set of work
Expand All @@ -431,8 +437,8 @@ pl_app_update(plAppData* ptAppData)

plCommandBuffer tCommandBuffer = gptGfx->begin_command_recording(ptGraphics, &tBeginInfo0);

gptRenderer->update_scene(tCommandBuffer, ptAppData->uSceneHandle0);
gptRenderer->update_scene(tCommandBuffer, ptAppData->uSceneHandle1);
gptRenderer->update_skin_textures(tCommandBuffer, ptAppData->uSceneHandle0);
gptRenderer->update_skin_textures(tCommandBuffer, ptAppData->uSceneHandle1);
gptGfx->end_command_recording(ptGraphics, &tCommandBuffer);

const plSubmitInfo tSubmitInfo0 = {
Expand All @@ -442,6 +448,24 @@ pl_app_update(plAppData* ptAppData)
};
gptGfx->submit_command_buffer(ptGraphics, &tCommandBuffer, &tSubmitInfo0);

const plBeginCommandInfo tBeginInfo00 = {
.uWaitSemaphoreCount = 1,
.atWaitSempahores = {ptAppData->atSempahore[ptGraphics->uCurrentFrameIndex]},
.auWaitSemaphoreValues = {ulValue1},
};
tCommandBuffer = gptGfx->begin_command_recording(ptGraphics, &tBeginInfo00);

gptRenderer->perform_skinning(tCommandBuffer, ptAppData->uSceneHandle0);
gptRenderer->perform_skinning(tCommandBuffer, ptAppData->uSceneHandle1);
gptGfx->end_command_recording(ptGraphics, &tCommandBuffer);

const plSubmitInfo tSubmitInfo00 = {
.uSignalSemaphoreCount = 1,
.atSignalSempahores = {ptAppData->atSempahore[ptGraphics->uCurrentFrameIndex]},
.auSignalSemaphoreValues = {ulValue2}
};
gptGfx->submit_command_buffer(ptGraphics, &tCommandBuffer, &tSubmitInfo00);

plViewOptions tViewOptions = {
.bShowAllBoundingBoxes = ptAppData->bDrawAllBoundingBoxes,
.bShowVisibleBoundingBoxes = ptAppData->bDrawVisibleBoundingBoxes,
Expand Down Expand Up @@ -469,7 +493,7 @@ pl_app_update(plAppData* ptAppData)
const plBeginCommandInfo tBeginInfo1 = {
.uWaitSemaphoreCount = 1,
.atWaitSempahores = {ptAppData->atSempahore[ptGraphics->uCurrentFrameIndex]},
.auWaitSemaphoreValues = {ulValue1}
.auWaitSemaphoreValues = {ulValue2}
};
tCommandBuffer = gptGfx->begin_command_recording(ptGraphics, &tBeginInfo1);
gptRenderer->render_scene(tCommandBuffer, ptAppData->uSceneHandle0, ptAppData->uViewHandle0, tViewOptions);
Expand All @@ -481,7 +505,7 @@ pl_app_update(plAppData* ptAppData)
const plSubmitInfo tSubmitInfo1 = {
.uSignalSemaphoreCount = 1,
.atSignalSempahores = {ptAppData->atSempahore[ptGraphics->uCurrentFrameIndex]},
.auSignalSemaphoreValues = {ulValue2}
.auSignalSemaphoreValues = {ulValue3}
};
gptGfx->submit_command_buffer(ptGraphics, &tCommandBuffer, &tSubmitInfo1);

Expand All @@ -490,7 +514,7 @@ pl_app_update(plAppData* ptAppData)
const plBeginCommandInfo tBeginInfo2 = {
.uWaitSemaphoreCount = 1,
.atWaitSempahores = {ptAppData->atSempahore[ptGraphics->uCurrentFrameIndex]},
.auWaitSemaphoreValues = {ulValue2},
.auWaitSemaphoreValues = {ulValue3},
};
tCommandBuffer = gptGfx->begin_command_recording(ptGraphics, &tBeginInfo2);

Expand Down Expand Up @@ -597,7 +621,7 @@ pl_app_update(plAppData* ptAppData)
const plSubmitInfo tSubmitInfo2 = {
.uSignalSemaphoreCount = 1,
.atSignalSempahores = {ptAppData->atSempahore[ptGraphics->uCurrentFrameIndex]},
.auSignalSemaphoreValues = {ulValue3},
.auSignalSemaphoreValues = {ulValue4},
};
gptGfx->end_command_recording(ptGraphics, &tCommandBuffer);
if(!gptGfx->present(ptGraphics, &tCommandBuffer, &tSubmitInfo2))
Expand Down
4 changes: 0 additions & 4 deletions extensions/pl_ecs_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -1347,8 +1347,6 @@ pl_camera_rotate(plCameraComponent* ptCamera, float fDPitch, float fDYaw)
static void
pl_camera_update(plCameraComponent* ptCamera)
{
pl_begin_profile_sample(__FUNCTION__);

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~update view~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// world space
Expand Down Expand Up @@ -1398,8 +1396,6 @@ pl_camera_update(plCameraComponent* ptCamera)
ptCamera->tProjMat.col[2].z = 1 / (ptCamera->fFarZ - ptCamera->fNearZ);
ptCamera->tProjMat.col[3].w = 1.0f;
}

pl_end_profile_sample();
}

static void
Expand Down
6 changes: 1 addition & 5 deletions extensions/pl_ecs_ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,8 @@ enum _plTextureSlot
PL_TEXTURE_SLOT_CLEARCOAT_MAP,
PL_TEXTURE_SLOT_CLEARCOAT_ROUGHNESS_MAP,
PL_TEXTURE_SLOT_CLEARCOAT_NORMAL_MAP,
PL_TEXTURE_SLOT_SHEEN_COLOR_MAP,
PL_TEXTURE_SLOT_SHEEN_ROUGHNESS_MAP,
PL_TEXTURE_SLOT_TRANSMISSION_MAP,
PL_TEXTURE_SLOT_SPECULAR_MAP,
PL_TEXTURE_SLOT_SPECULAR_COLOR_MAP,
PL_TEXTURE_SLOT_ANISOTROPY_MAP,
PL_TEXTURE_SLOT_SURFACE_MAP,
PL_TEXTURE_SLOT_IRIDESCENCE_MAP,
PL_TEXTURE_SLOT_IRIDESCENCE_THICKNESS_MAP,

Expand All @@ -221,6 +216,7 @@ enum _plMaterialFlags
{
PL_MATERIAL_FLAG_NONE = 0,
PL_MATERIAL_FLAG_DOUBLE_SIDED = 1 << 0,
PL_MATERIAL_FLAG_OUTLINE = 1 << 1,
};

enum _plBlendMode
Expand Down
5 changes: 3 additions & 2 deletions extensions/pl_graphics_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ typedef struct _plFrameGarbage
static plFrameGarbage*
pl__get_frame_garbage(plGraphics* ptGraphics)
{
return &ptGraphics->sbtGarbage[ptGraphics->uCurrentFrameIndex];

return &ptGraphics->sbtGarbage[ptGraphics->uCurrentFrameIndex];
}

static size_t
Expand Down Expand Up @@ -678,6 +677,7 @@ pl__cleanup_common_graphics(plGraphics* ptGraphics)
pl_sb_free(ptGraphics->tSwapchain.sbtSwapchainTextureViews);
pl_sb_free(ptGraphics->sbtShadersCold);
pl_sb_free(ptGraphics->sbtBuffersCold);
pl_sb_free(ptGraphics->sbtShaderFreeIndices);
pl_sb_free(ptGraphics->sbtBufferFreeIndices);
pl_sb_free(ptGraphics->sbtTexturesCold);
pl_sb_free(ptGraphics->sbtSamplersCold);
Expand All @@ -698,6 +698,7 @@ pl__cleanup_common_graphics(plGraphics* ptGraphics)
pl_sb_free(ptGraphics->sbtSemaphoreGenerations);
pl_sb_free(ptGraphics->sbtSemaphoreFreeIndices);
pl_sb_free(ptGraphics->sbtSamplerFreeIndices);
pl_sb_free(ptGraphics->sbtComputeShaderFreeIndices);

PL_FREE(ptGraphics->_pInternalData);
PL_FREE(ptGraphics->tDevice._pInternalData);
Expand Down
18 changes: 14 additions & 4 deletions extensions/pl_graphics_ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ typedef int plLoadOp; // -> enum _plLoadOp // Enum:
typedef int plStoreOp; // -> enum _plStoreOp // Enum:
typedef int plBlendOp; // -> enum _plBlendOp // Enum:
typedef int plBlendFactor; // -> enum _plBlendFactor // Enum:
typedef int plMipmapMode; // -> enum _plMipmapMode // Enum:

// external
typedef struct _plDrawList plDrawList;
Expand Down Expand Up @@ -327,9 +328,9 @@ typedef struct _plGraphicsI
// compute encoder
plComputeEncoder (*begin_compute_pass) (plGraphics*, plCommandBuffer*);
void (*end_compute_pass) (plComputeEncoder*);
void (*dispatch) (plComputeEncoder*, uint32_t uDispatchCount, plDispatch*);
void (*dispatch) (plComputeEncoder*, uint32_t uDispatchCount, const plDispatch*);
void (*bind_compute_shader) (plComputeEncoder*, plComputeShaderHandle);
void (*bind_compute_bind_groups)(plComputeEncoder*, plComputeShaderHandle, uint32_t uFirst, uint32_t uCount, const plBindGroupHandle*);
void (*bind_compute_bind_groups)(plComputeEncoder*, plComputeShaderHandle, uint32_t uFirst, uint32_t uCount, const plBindGroupHandle*, plDynamicBinding*);

// blit encoder
plBlitEncoder (*begin_blit_pass) (plGraphics*, plCommandBuffer*);
Expand Down Expand Up @@ -447,13 +448,14 @@ typedef struct _plGraphicsState
uint64_t ulWireframe : 1; // bool
uint64_t ulDepthWriteEnabled : 1; // bool
uint64_t ulCullMode : 2; // PL_CULL_MODE_*
uint64_t ulStencilTestEnabled : 1; // bool
uint64_t ulStencilMode : 4;
uint64_t ulStencilRef : 8;
uint64_t ulStencilMask : 8;
uint64_t ulStencilOpFail : 3;
uint64_t ulStencilOpDepthFail : 3;
uint64_t ulStencilOpPass : 3;
uint64_t _ulUnused : 27;
uint64_t _ulUnused : 26;
};
uint64_t ulValue;
};
Expand Down Expand Up @@ -545,6 +547,7 @@ typedef struct _plTextureViewDesc
typedef struct _plSamplerDesc
{
plFilter tFilter;
plMipmapMode tMipmapMode;
plCompareMode tCompare;
plWrapMode tHorizontalWrap;
plWrapMode tVerticalWrap;
Expand Down Expand Up @@ -782,7 +785,8 @@ typedef struct _plComputeShaderDescription
{
const char* pcShader;
const char* pcShaderEntryFunc;
plBindGroupLayout tBindGroupLayout;
plBindGroupLayout atBindGroupLayouts[3];
uint32_t uBindGroupLayoutCount;
plSpecializationConstant atConstants[PL_MAX_SHADER_SPECIALIZATION_CONSTANTS];
uint32_t uConstantCount;
const void* pTempConstantData;
Expand Down Expand Up @@ -1139,6 +1143,12 @@ enum _plLoadOperation
PL_LOAD_OPERATION_CLEAR
};

enum _plMipmapMode
{
PL_MIPMAP_MODE_LINEAR,
PL_MIPMAP_MODE_NEAREST
};

enum _plDataType
{
PL_DATA_TYPE_BOOL,
Expand Down
6 changes: 6 additions & 0 deletions extensions/pl_job_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ static void
pl__dispatch_batch(uint32_t uJobCount, uint32_t uGroupSize, plJobDesc tJobDesc, plAtomicCounter** pptCounter)
{

if(uJobCount == 0)
return;

plAtomicCounter* ptCounter = NULL;

// find optimal group size
Expand Down Expand Up @@ -288,6 +291,9 @@ pl__dispatch_batch(uint32_t uJobCount, uint32_t uGroupSize, plJobDesc tJobDesc,
static void
pl__wait_for_counter(plAtomicCounter* ptCounter)
{
if(ptCounter == NULL)
return;

const uint32_t uValue = 0;

// wait for counter to reach value (or less)
Expand Down
Loading
Loading