Skip to content

Commit

Permalink
refac: remove explicit include directory count in shader ext
Browse files Browse the repository at this point in the history
  • Loading branch information
hoffstadt committed Nov 22, 2024
1 parent a6e1e25 commit 0b0b6a4
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 24 deletions.
2 changes: 1 addition & 1 deletion examples/example_1.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
// between extensions & the runtime
const plDataRegistryI* ptDataRegistry = pl_get_api_latest(ptApiRegistry, plDataRegistryI);

// load required apis (NULL if not available)
// load required apis
gptIO = pl_get_api_latest(ptApiRegistry, plIOI);
gptWindows = pl_get_api_latest(ptApiRegistry, plWindowI);

Expand Down
3 changes: 1 addition & 2 deletions examples/example_2.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
// load extensions
ptExtensionRegistry->load("pl_unity_ext", NULL, NULL, true);

// load required apis (NULL if not available)
// load required apis
gptIO = pl_get_api_latest(ptApiRegistry, plIOI);
gptWindows = pl_get_api_latest(ptApiRegistry, plWindowI);
gptGfx = pl_get_api_latest(ptApiRegistry, plGraphicsI);
Expand All @@ -135,7 +135,6 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)

// initialize shader compiler
static const plShaderOptions tDefaultShaderOptions = {
.uIncludeDirectoriesCount = 1,
.apcIncludeDirectories = {
"../shaders/"
}
Expand Down
3 changes: 1 addition & 2 deletions examples/example_3.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
// load extensions
ptExtensionRegistry->load("pl_unity_ext", NULL, NULL, true);

// load required apis (NULL if not available)
// load required apis
gptIO = pl_get_api_latest(ptApiRegistry, plIOI);
gptWindows = pl_get_api_latest(ptApiRegistry, plWindowI);
gptGfx = pl_get_api_latest(ptApiRegistry, plGraphicsI);
Expand All @@ -147,7 +147,6 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)

// initialize shader compiler
static const plShaderOptions tDefaultShaderOptions = {
.uIncludeDirectoriesCount = 1,
.apcIncludeDirectories = {
"../shaders/"
}
Expand Down
3 changes: 1 addition & 2 deletions examples/example_4.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
// load extensions
ptExtensionRegistry->load("pl_unity_ext", NULL, NULL, true);

// load required apis (NULL if not available)
// load required apis
gptIO = pl_get_api_latest(ptApiRegistry, plIOI);
gptWindows = pl_get_api_latest(ptApiRegistry, plWindowI);
gptGfx = pl_get_api_latest(ptApiRegistry, plGraphicsI);
Expand Down Expand Up @@ -216,7 +216,6 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)

// initialize shader extension
static const plShaderOptions tDefaultShaderOptions = {
.uIncludeDirectoriesCount = 1,
.apcIncludeDirectories = {
"../examples/shaders/"
}
Expand Down
3 changes: 1 addition & 2 deletions examples/example_5.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
// load extensions
ptExtensionRegistry->load("pl_unity_ext", NULL, NULL, true);

// load required apis (NULL if not available)
// load required apis
gptIO = pl_get_api_latest(ptApiRegistry, plIOI);
gptWindows = pl_get_api_latest(ptApiRegistry, plWindowI);
gptGfx = pl_get_api_latest(ptApiRegistry, plGraphicsI);
Expand Down Expand Up @@ -217,7 +217,6 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)

// initialize shader extension
static const plShaderOptions tDefaultShaderOptions = {
.uIncludeDirectoriesCount = 1,
.apcIncludeDirectories = {
"../examples/shaders/"
}
Expand Down
3 changes: 1 addition & 2 deletions examples/example_6.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
// load extensions
ptExtensionRegistry->load("pl_unity_ext", NULL, NULL, true);

// load required apis (NULL if not available)
// load required apis
gptIO = pl_get_api_latest(ptApiRegistry, plIOI);
gptWindows = pl_get_api_latest(ptApiRegistry, plWindowI);
gptGfx = pl_get_api_latest(ptApiRegistry, plGraphicsI);
Expand Down Expand Up @@ -247,7 +247,6 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)

// initialize shader extension
static const plShaderOptions tDefaultShaderOptions = {
.uIncludeDirectoriesCount = 1,
.apcIncludeDirectories = {
"../examples/shaders/"
}
Expand Down
3 changes: 1 addition & 2 deletions examples/example_8.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
// load extensions (makes their APIs available)
ptExtensionRegistry->load("pl_unity_ext", NULL, NULL, true);

// load required apis (NULL if not available)
// load required apis
gptIO = pl_get_api_latest(ptApiRegistry, plIOI);
gptWindows = pl_get_api_latest(ptApiRegistry, plWindowI);
gptGfx = pl_get_api_latest(ptApiRegistry, plGraphicsI);
Expand Down Expand Up @@ -236,7 +236,6 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)

// initialize shader extension
static const plShaderOptions tDefaultShaderOptions = {
.uIncludeDirectoriesCount = 1,
.apcIncludeDirectories = {
"../examples/shaders/"
}
Expand Down
3 changes: 1 addition & 2 deletions examples/example_9.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
// load extensions (makes their APIs available)
ptExtensionRegistry->load("pl_unity_ext", NULL, NULL, true);

// load required apis (NULL if not available)
// load required apis
gptIO = pl_get_api_latest(ptApiRegistry, plIOI);
gptWindows = pl_get_api_latest(ptApiRegistry, plWindowI);
gptGfx = pl_get_api_latest(ptApiRegistry, plGraphicsI);
Expand Down Expand Up @@ -278,7 +278,6 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)

// initialize shader extension
static const plShaderOptions tDefaultShaderOptions = {
.uIncludeDirectoriesCount = 1,
.apcIncludeDirectories = {
"../examples/shaders/"
}
Expand Down
28 changes: 23 additions & 5 deletions extensions/pl_shader_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pl_shaderc_include_resolve_fn(void* pUserData, const char* pcRequestedSource, in
{
plShaderOptions* ptOptions = pUserData;
const char** apcIncludeDirectories = ptOptions ? ptOptions->apcIncludeDirectories : gptShaderCtx->tDefaultShaderOptions.apcIncludeDirectories;
const uint32_t uIncludeDirectoriesCount = ptOptions ? ptOptions->uIncludeDirectoriesCount : gptShaderCtx->tDefaultShaderOptions.uIncludeDirectoriesCount;
const uint32_t uIncludeDirectoriesCount = ptOptions ? ptOptions->_uIncludeDirectoriesCount : gptShaderCtx->tDefaultShaderOptions._uIncludeDirectoriesCount;

shaderc_include_result* ptResult = pl_temp_allocator_alloc(&gptShaderCtx->tTempAllocator, sizeof(shaderc_include_result));
ptResult->user_data = ptOptions;
Expand Down Expand Up @@ -132,16 +132,21 @@ pl_initialize_shader_ext(const plShaderOptions* ptShaderOptions)
return true;
gptShaderCtx->bInitialized = true;



gptShaderCtx->tDefaultShaderOptions.apcIncludeDirectories[0] = "./";
gptShaderCtx->tDefaultShaderOptions.uIncludeDirectoriesCount = 1;
gptShaderCtx->tDefaultShaderOptions._uIncludeDirectoriesCount = 1;

if(ptShaderOptions)
{
for(uint32_t i = 0; i < ptShaderOptions->uIncludeDirectoriesCount; i++)
for(uint32_t i = 0; i < 16; i++)
{
gptShaderCtx->tDefaultShaderOptions.apcIncludeDirectories[i + 1] = ptShaderOptions->apcIncludeDirectories[i];
if(ptShaderOptions->apcIncludeDirectories[i])
gptShaderCtx->tDefaultShaderOptions.apcIncludeDirectories[i + 1] = ptShaderOptions->apcIncludeDirectories[i];
else
break;
gptShaderCtx->tDefaultShaderOptions._uIncludeDirectoriesCount++;
}
gptShaderCtx->tDefaultShaderOptions.uIncludeDirectoriesCount = ptShaderOptions->uIncludeDirectoriesCount + 1;
}

#ifndef PL_OFFLINE_SHADERS_ONLY
Expand Down Expand Up @@ -184,6 +189,19 @@ pl_compile_glsl(const char* pcShader, const char* pcEntryFunc, plShaderOptions*
#ifndef PL_OFFLINE_SHADERS_ONLY
shaderc_compiler_t tCompiler = shaderc_compiler_initialize();
shaderc_compile_options_t tOptions = shaderc_compile_options_initialize();

if(ptOptions)
{
ptOptions->_uIncludeDirectoriesCount = 0;
for(uint32_t i = 0; i < 16; i++)
{
if(ptOptions->apcIncludeDirectories[i])
ptOptions->_uIncludeDirectoriesCount++;
else
break;
}
}

shaderc_compile_options_set_include_callbacks(tOptions, pl_shaderc_include_resolve_fn, pl_shaderc_include_result_release_fn, ptOptions);

if(ptOptions == NULL)
Expand Down
4 changes: 3 additions & 1 deletion extensions/pl_shader_ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ typedef struct _plShaderOptions
const plShaderMacroDefinition* ptMacroDefinitions;
uint32_t uMacroDefinitionCount;
const char* apcIncludeDirectories[PL_MAX_SHADER_INCLUDE_DIRECTORIES];
uint32_t uIncludeDirectoriesCount;

// [INTERNAL]
uint32_t _uIncludeDirectoriesCount;
} plShaderOptions;

//-----------------------------------------------------------------------------
Expand Down
1 change: 0 additions & 1 deletion sandbox/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plEditorData* ptEditorData)

// initialize shader extension
static const plShaderOptions tDefaultShaderOptions = {
.uIncludeDirectoriesCount = 1,
.apcIncludeDirectories = {
"../shaders/"
}
Expand Down
3 changes: 1 addition & 2 deletions scripts/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@
"pl_shader_ext",
"pl_stats_ext",
"pl_string_intern_ext",
"pl_ui_ext",
"app",
"pl_ui_ext"
]

if debug_package:
Expand Down

0 comments on commit 0b0b6a4

Please sign in to comment.