Skip to content

Commit

Permalink
feat: add spirv-cross & shaderc support
Browse files Browse the repository at this point in the history
  • Loading branch information
hoffstadt committed Jun 8, 2024
1 parent 8eea0d0 commit d68becb
Show file tree
Hide file tree
Showing 76 changed files with 1,649 additions and 5,313 deletions.
16 changes: 12 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ jobs:
- name: Install Dependencies
run: |
Invoke-WebRequest -Uri "https://sdk.lunarg.com/sdk/download/1.3.224.1/windows/VulkanSDK-1.3.224.1-Installer.exe" -OutFile VulkanSDK.exe
./VulkanSDK.exe --accept-licenses --default-answer --confirm-command install
# ./VulkanSDK.exe --help
./VulkanSDK.exe --accept-licenses --default-answer --root D:/a/VulkanSDK --confirm-command install
- name: Build Pilot Light
shell: cmd
run: |
set VULKAN_SDK=C:\VulkanSDK\1.3.224.1
cd $GITHUB_WORKSPACE
set VULKAN_SDK=D:/a/VulkanSDK
cd scripts
python gen_build.py
python gen_examples.py
Expand Down Expand Up @@ -71,6 +71,7 @@ jobs:
if not exist ../out/pl_ref_renderer_ext.dll exit 1
if not exist ../out/pl_draw_ext.dll exit 1
if not exist ../out/pl_ui_ext.dll exit 1
if not exist ../out/pl_shader_ext.dll exit 1
if not exist ../out/pl_script_camera.dll exit 1
if not exist ../out/pilotlight.lib exit 1
Expand Down Expand Up @@ -100,7 +101,12 @@ jobs:

- name: Retrieve submodules
run: git submodule update --init --recursive


- name: Install Dependencies
run: |
curl https://sdk.lunarg.com/sdk/download/1.3.283.0/mac/vulkansdk-macos-1.3.283.0.dmg -o vk.dmg
hdiutil attach vk.dmg
sudo /Volumes/vulkansdk-macos-1.3.283.0/InstallVulkan.app/Contents/MacOS/InstallVulkan --root ~/VulkanSDK/1.3.283.0 --accept-licenses --default-answer --confirm-command install com.lunarg.vulkan.core com.lunarg.vulkan.usr com.lunarg.vulkan.sdl2 com.lunarg.vulkan.glm com.lunarg.vulkan.volk com.lunarg.vulkan.vma com.lunarg.vulkan.ios
- name: Build Pilot Light
run: |
cd $GITHUB_WORKSPACE
Expand Down Expand Up @@ -139,6 +145,7 @@ jobs:
test -f ./out/pl_ref_renderer_ext.dylib || exit 1
test -f ./out/pl_draw_ext.dylib || exit 1
test -f ./out/pl_ui_ext.dylib || exit 1
test -f ./out/pl_shader_ext.dylib || exit 1
test -f ./out/pl_script_camera.dylib || exit 1
test -f ./out/pilotlight.a || exit 1
Expand Down Expand Up @@ -220,6 +227,7 @@ jobs:
test -f ./out/pl_ref_renderer_ext.so || exit 1
test -f ./out/pl_draw_ext.so || exit 1
test -f ./out/pl_ui_ext.so || exit 1
test -f ./out/pl_shader_ext.so || exit 1
test -f ./out/pl_script_camera.so || exit 1
test -f ./out/pilotlight.a || exit 1
Expand Down
48 changes: 15 additions & 33 deletions apps/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,14 @@ typedef struct plAppData_t
bool bShowUiDebug;
bool bShowUiStyle;
bool bShowEntityWindow;
bool bReloadSwapchain;
bool bResize;
bool bFrustumCulling;
bool bAlwaysResize;


// selected entityes
bool bUpdateEntitySelection;
plEntity tSelectedEntity;


// scene
bool bDrawAllBoundingBoxes;
bool bDrawVisibleBoundingBoxes;
bool bFreezeCullCamera;
plEntity tCullCamera;
plEntity tMainCamera;
Expand Down Expand Up @@ -151,8 +145,6 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
ptAppData = PL_ALLOC(sizeof(plAppData));
memset(ptAppData, 0, sizeof(plAppData));

ptAppData->bFrustumCulling = true;

ptDataRegistry->set_data("profile", ptProfileCtx);
ptDataRegistry->set_data("log", ptLogCtx);

Expand Down Expand Up @@ -314,25 +306,15 @@ pl_app_update(plAppData* ptAppData)
plGraphics* ptGraphics = gptRenderer->get_graphics();
plIO* ptIO = gptIO->get_io();

if(ptAppData->bReloadSwapchain)
{
ptAppData->bReloadSwapchain = false;
gptGfx->resize(ptGraphics);
pl_end_profile_sample();
pl_end_profile_frame();
return;
}

if(ptAppData->bResize || ptAppData->bAlwaysResize)
{
// gptOS->sleep(32);
gptRenderer->resize_view(ptAppData->uSceneHandle0, ptAppData->uViewHandle0, (plVec2){ptIO->afMainViewportSize[0], ptIO->afMainViewportSize[1]});
ptAppData->bResize = false;
}

if(!gptGfx->begin_frame(ptGraphics))
if(!gptRenderer->begin_frame())
{
gptGfx->resize(ptGraphics);
pl_end_profile_sample();
pl_end_profile_frame();
return;
Expand Down Expand Up @@ -378,19 +360,13 @@ pl_app_update(plAppData* ptAppData)
ptAppData->tSelectedEntity = tNextSelectedEntity;
}

plViewOptions tViewOptions = {
.bShowAllBoundingBoxes = ptAppData->bDrawAllBoundingBoxes,
.bShowVisibleBoundingBoxes = ptAppData->bDrawVisibleBoundingBoxes,
.bShowOrigin = true,
.bCullStats = true,
const plViewOptions tViewOptions = {
.ptViewCamera = &ptAppData->tMainCamera,
.ptCullCamera = ptAppData->bFrustumCulling ? &ptAppData->tMainCamera : NULL,
.ptCullCamera = ptAppData->bFreezeCullCamera ? &ptAppData->tCullCamera : NULL,
.ptSunLight = &ptAppData->tSunlight
};
gptRenderer->render_scene(ptAppData->uSceneHandle0, ptAppData->uViewHandle0, tViewOptions);



gptUi->set_next_window_pos((plVec2){0, 0}, PL_UI_COND_ONCE);

if(gptUi->begin_window("Pilot Light", NULL, false))
Expand All @@ -414,19 +390,25 @@ pl_app_update(plAppData* ptAppData)

gptUi->end_collapsing_header();
}
if(gptUi->collapsing_header("General Options"))
if(gptUi->collapsing_header("App Options"))
{
if(gptUi->checkbox("VSync", &ptGraphics->tSwapchain.bVSync))
ptAppData->bReloadSwapchain = true;
gptUi->checkbox("Frustum Culling", &ptAppData->bFrustumCulling);
if(gptUi->checkbox("Freeze Culling Camera", &ptAppData->bFreezeCullCamera))
{
*ptCullCamera = *ptCamera;
}
gptUi->checkbox("Draw All Bounding Boxes", &ptAppData->bDrawAllBoundingBoxes);
gptUi->checkbox("Draw Visible Bounding Boxes", &ptAppData->bDrawVisibleBoundingBoxes);

plLightComponent* ptLight = gptEcs->get_component(ptMainComponentLibrary, PL_COMPONENT_TYPE_LIGHT, ptAppData->tSunlight);
int iCascadeCount = (int)ptLight->uCascadeCount;
if(gptUi->slider_int("Sunlight Cascades", &iCascadeCount, 1, 4))
{
ptLight->uCascadeCount = (uint32_t)iCascadeCount;
}

gptUi->end_collapsing_header();
}

gptRenderer->show_graphics_options();

if(gptUi->collapsing_header("Tools"))
{
gptUi->checkbox("Device Memory Analyzer", &ptAppData->tDebugInfo.bShowDeviceMemoryAnalyzer);
Expand Down
20 changes: 13 additions & 7 deletions examples/example_4.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Index of this file:

// extensions
#include "pl_graphics_ext.h"
#include "pl_shader_ext.h"

//-----------------------------------------------------------------------------
// [SECTION] structs
Expand Down Expand Up @@ -66,6 +67,7 @@ const plIOI* gptIO = NULL;
const plWindowI* gptWindows = NULL;
const plGraphicsI* gptGfx = NULL;
const plDeviceI* gptDevice = NULL;
const plShaderI* gptShader = NULL;

//-----------------------------------------------------------------------------
// [SECTION] pl_app_load
Expand Down Expand Up @@ -100,6 +102,7 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
gptWindows = ptApiRegistry->first(PL_API_WINDOW);
gptGfx = ptApiRegistry->first(PL_API_GRAPHICS);
gptDevice = ptApiRegistry->first(PL_API_DEVICE);
gptShader = ptApiRegistry->first(PL_API_SHADER);

return ptAppData;
}
Expand Down Expand Up @@ -127,12 +130,14 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)

// load graphics extension (provides graphics & device apis)
ptExtensionRegistry->load("pl_graphics_ext", NULL, NULL, false);
ptExtensionRegistry->load("pl_shader_ext", NULL, NULL, false);

// load required apis (NULL if not available)
gptIO = ptApiRegistry->first(PL_API_IO);
gptWindows = ptApiRegistry->first(PL_API_WINDOW);
gptGfx = ptApiRegistry->first(PL_API_GRAPHICS);
gptDevice = ptApiRegistry->first(PL_API_DEVICE);
gptShader = ptApiRegistry->first(PL_API_SHADER);

// use window API to create a window
const plWindowDesc tWindowDesc = {
Expand All @@ -150,6 +155,12 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
};
gptGfx->initialize(ptAppData->ptWindow, &tGraphicsDesc, &ptAppData->tGraphics);

// initialize shader extension
const plShaderExtInit tShaderInit = {
.pcIncludeDirectory = "../examples/shaders/"
};
gptShader->initialize(&tShaderInit);

// for convience
plDevice* ptDevice = &ptAppData->tGraphics.tDevice;

Expand Down Expand Up @@ -195,13 +206,8 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~shaders~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

const plShaderDescription tShaderDesc = {
#ifdef PL_METAL_BACKEND
.pcVertexShader = "../examples/shaders/example_4.metal",
.pcPixelShader = "../examples/shaders/example_4.metal",
#else
.pcVertexShader = "example_4.vert.spv",
.pcPixelShader = "example_4.frag.spv",
#endif
.tVertexShader = gptShader->compile_glsl("../examples/shaders/example_4.vert", "main"),
.tPixelShader = gptShader->compile_glsl("../examples/shaders/example_4.frag", "main"),
.tGraphicsState = {
.ulDepthWriteEnabled = 0,
.ulDepthMode = PL_COMPARE_MODE_ALWAYS,
Expand Down
20 changes: 13 additions & 7 deletions examples/example_5.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Index of this file:

// extensions
#include "pl_graphics_ext.h"
#include "pl_shader_ext.h"

//-----------------------------------------------------------------------------
// [SECTION] structs
Expand Down Expand Up @@ -70,6 +71,7 @@ const plIOI* gptIO = NULL;
const plWindowI* gptWindows = NULL;
const plGraphicsI* gptGfx = NULL;
const plDeviceI* gptDevice = NULL;
const plShaderI* gptShader = NULL;

//-----------------------------------------------------------------------------
// [SECTION] pl_app_load
Expand Down Expand Up @@ -104,6 +106,7 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
gptWindows = ptApiRegistry->first(PL_API_WINDOW);
gptGfx = ptApiRegistry->first(PL_API_GRAPHICS);
gptDevice = ptApiRegistry->first(PL_API_DEVICE);
gptShader = ptApiRegistry->first(PL_API_SHADER);

return ptAppData;
}
Expand Down Expand Up @@ -131,12 +134,14 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)

// load graphics extension (provides graphics & device apis)
ptExtensionRegistry->load("pl_graphics_ext", NULL, NULL, false);
ptExtensionRegistry->load("pl_shader_ext", NULL, NULL, false);

// load required apis (NULL if not available)
gptIO = ptApiRegistry->first(PL_API_IO);
gptWindows = ptApiRegistry->first(PL_API_WINDOW);
gptGfx = ptApiRegistry->first(PL_API_GRAPHICS);
gptDevice = ptApiRegistry->first(PL_API_DEVICE);
gptShader = ptApiRegistry->first(PL_API_SHADER);

// use window API to create a window
const plWindowDesc tWindowDesc = {
Expand All @@ -154,6 +159,12 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
};
gptGfx->initialize(ptAppData->ptWindow, &tGraphicsDesc, &ptAppData->tGraphics);

// initialize shader extension
const plShaderExtInit tShaderInit = {
.pcIncludeDirectory = "../examples/shaders/"
};
gptShader->initialize(&tShaderInit);

// for convience
plDevice* ptDevice = &ptAppData->tGraphics.tDevice;

Expand Down Expand Up @@ -265,13 +276,8 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~shaders~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

const plShaderDescription tShaderDesc = {
#ifdef PL_METAL_BACKEND
.pcVertexShader = "../examples/shaders/example_4.metal",
.pcPixelShader = "../examples/shaders/example_4.metal",
#else
.pcVertexShader = "example_4.vert.spv",
.pcPixelShader = "example_4.frag.spv",
#endif
.tVertexShader = gptShader->compile_glsl("../examples/shaders/example_4.vert", "main"),
.tPixelShader = gptShader->compile_glsl("../examples/shaders/example_4.frag", "main"),
.tGraphicsState = {
.ulDepthWriteEnabled = 0,
.ulDepthMode = PL_COMPARE_MODE_ALWAYS,
Expand Down
20 changes: 13 additions & 7 deletions examples/example_6.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Index of this file:
// extensions
#include "pl_graphics_ext.h"
#include "pl_image_ext.h"
#include "pl_shader_ext.h"

//-----------------------------------------------------------------------------
// [SECTION] structs
Expand Down Expand Up @@ -81,6 +82,7 @@ const plWindowI* gptWindows = NULL;
const plGraphicsI* gptGfx = NULL;
const plDeviceI* gptDevice = NULL;
const plImageI* gptImage = NULL;
const plShaderI* gptShader = NULL;

//-----------------------------------------------------------------------------
// [SECTION] pl_app_load
Expand Down Expand Up @@ -116,6 +118,7 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
gptGfx = ptApiRegistry->first(PL_API_GRAPHICS);
gptDevice = ptApiRegistry->first(PL_API_DEVICE);
gptImage = ptApiRegistry->first(PL_API_IMAGE);
gptShader = ptApiRegistry->first(PL_API_SHADER);

return ptAppData;
}
Expand Down Expand Up @@ -144,13 +147,15 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
// load extensions
ptExtensionRegistry->load("pl_graphics_ext", NULL, NULL, false);
ptExtensionRegistry->load("pl_image_ext", NULL, NULL, false);
ptExtensionRegistry->load("pl_shader_ext", NULL, NULL, false);

// load required apis (NULL if not available)
gptIO = ptApiRegistry->first(PL_API_IO);
gptWindows = ptApiRegistry->first(PL_API_WINDOW);
gptGfx = ptApiRegistry->first(PL_API_GRAPHICS);
gptDevice = ptApiRegistry->first(PL_API_DEVICE);
gptImage = ptApiRegistry->first(PL_API_IMAGE);
gptShader = ptApiRegistry->first(PL_API_SHADER);

// use window API to create a window
const plWindowDesc tWindowDesc = {
Expand All @@ -168,6 +173,12 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
};
gptGfx->initialize(ptAppData->ptWindow, &tGraphicsDesc, &ptAppData->tGraphics);

// initialize shader extension
const plShaderExtInit tShaderInit = {
.pcIncludeDirectory = "../examples/shaders/"
};
gptShader->initialize(&tShaderInit);

// for convience
plDevice* ptDevice = &ptAppData->tGraphics.tDevice;

Expand Down Expand Up @@ -383,13 +394,8 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~shaders~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

const plShaderDescription tShaderDesc = {
#ifdef PL_METAL_BACKEND
.pcVertexShader = "../examples/shaders/example_6.metal",
.pcPixelShader = "../examples/shaders/example_6.metal",
#else
.pcVertexShader = "example_6.vert.spv",
.pcPixelShader = "example_6.frag.spv",
#endif
.tVertexShader = gptShader->compile_glsl("../examples/shaders/example_6.vert", "main"),
.tPixelShader = gptShader->compile_glsl("../examples/shaders/example_6.frag", "main"),
.tGraphicsState = {
.ulDepthWriteEnabled = 0,
.ulDepthMode = PL_COMPARE_MODE_ALWAYS,
Expand Down
Loading

0 comments on commit d68becb

Please sign in to comment.