diff --git a/examples/README.md b/examples/README.md index 71cf603..e752c8b 100644 --- a/examples/README.md +++ b/examples/README.md @@ -95,7 +95,15 @@ Demonstrates: Demonstrates: * WIP -## Example 8 - Drawing Extension 3D (example_8.c) +## Example 8 - Drawing Extension 3D MSAA (example_8.c) +Demonstrates: +* loading APIs +* hot reloading +* loading extensions +* minimal use of graphics extension +* drawing extension (3D) + +## Example 9 - Drawing Extension 3D (example_9.c) Demonstrates: * loading APIs * hot reloading diff --git a/examples/example_2.c b/examples/example_2.c index 7091d55..e81809b 100644 --- a/examples/example_2.c +++ b/examples/example_2.c @@ -140,7 +140,8 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData) }, .apcDirectories = { "../shaders/" - } + }, + .tFlags = PL_SHADER_FLAGS_AUTO_OUTPUT }; gptShader->initialize(&tDefaultShaderOptions); diff --git a/examples/example_3.c b/examples/example_3.c index 63f3a48..6331b1e 100644 --- a/examples/example_3.c +++ b/examples/example_3.c @@ -152,7 +152,8 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData) }, .apcDirectories = { "../shaders/" - } + }, + .tFlags = PL_SHADER_FLAGS_AUTO_OUTPUT }; gptShader->initialize(&tDefaultShaderOptions); diff --git a/examples/example_4.c b/examples/example_4.c index 61264d5..fd12fc6 100644 --- a/examples/example_4.c +++ b/examples/example_4.c @@ -222,7 +222,8 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData) .apcDirectories = { "../shaders/", "../examples/shaders/" - } + }, + .tFlags = PL_SHADER_FLAGS_AUTO_OUTPUT }; gptShader->initialize(&tDefaultShaderOptions); diff --git a/examples/example_5.c b/examples/example_5.c index 5cb2e32..f8116c0 100644 --- a/examples/example_5.c +++ b/examples/example_5.c @@ -223,7 +223,8 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData) .apcDirectories = { "../shaders/", "../examples/shaders/" - } + }, + .tFlags = PL_SHADER_FLAGS_AUTO_OUTPUT }; gptShader->initialize(&tDefaultShaderOptions); diff --git a/examples/example_6.c b/examples/example_6.c index feb2056..443ab8d 100644 --- a/examples/example_6.c +++ b/examples/example_6.c @@ -253,7 +253,8 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData) .apcDirectories = { "../shaders/", "../examples/shaders/" - } + }, + .tFlags = PL_SHADER_FLAGS_AUTO_OUTPUT }; gptShader->initialize(&tDefaultShaderOptions); diff --git a/examples/example_8.c b/examples/example_8.c index d59d965..0701231 100644 --- a/examples/example_8.c +++ b/examples/example_8.c @@ -241,7 +241,8 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData) }, .apcDirectories = { "../shaders/" - } + }, + .tFlags = PL_SHADER_FLAGS_AUTO_OUTPUT }; gptShader->initialize(&tDefaultShaderOptions); diff --git a/examples/example_9.c b/examples/example_9.c index 2a415f8..0f718f6 100644 --- a/examples/example_9.c +++ b/examples/example_9.c @@ -283,7 +283,8 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData) }, .apcDirectories = { "../shaders/" - } + }, + .tFlags = PL_SHADER_FLAGS_AUTO_OUTPUT }; gptShader->initialize(&tDefaultShaderOptions); diff --git a/extensions/pl_renderer_internal.c b/extensions/pl_renderer_internal.c index 59d6a73..cd4501f 100644 --- a/extensions/pl_renderer_internal.c +++ b/extensions/pl_renderer_internal.c @@ -2289,10 +2289,11 @@ pl_refr_create_global_shaders(void) .apcDirectories = { "../shaders/" }, - #ifndef PL_OFFLINE_SHADERS_ONLY - .tFlags = PL_SHADER_FLAGS_ALWAYS_COMPILE | PL_SHADER_FLAGS_INCLUDE_DEBUG - #endif + .tFlags = PL_SHADER_FLAGS_AUTO_OUTPUT }; + #ifndef PL_OFFLINE_SHADERS_ONLY + tShadowShaderOptions.tFlags |= PL_SHADER_FLAGS_ALWAYS_COMPILE | PL_SHADER_FLAGS_INCLUDE_DEBUG; + #endif plShaderModule tShadowPixelShader = gptShader->load_glsl("shadow.frag", "main", NULL, NULL); plShaderModule tVertexShader = gptShader->load_glsl("shadow.vert", "main", NULL, gptData->bMultiViewportShadows ? &tShadowShaderOptions : NULL); diff --git a/extensions/pl_shader_ext.c b/extensions/pl_shader_ext.c index f376472..a664942 100644 --- a/extensions/pl_shader_ext.c +++ b/extensions/pl_shader_ext.c @@ -140,9 +140,15 @@ pl_initialize_shader_ext(const plShaderOptions* ptShaderOptions) gptShaderCtx->bInitialized = true; gptShaderCtx->tDefaultShaderOptions.tFlags = ptShaderOptions->tFlags; - #ifdef PL_METAL_BACKEND - gptShaderCtx->tDefaultShaderOptions.tFlags |= PL_SHADER_FLAGS_METAL_OUTPUT; - #endif + if(ptShaderOptions->tFlags & PL_SHADER_FLAGS_AUTO_OUTPUT) + { + #ifdef PL_METAL_BACKEND + gptShaderCtx->tDefaultShaderOptions.tFlags |= PL_SHADER_FLAGS_METAL_OUTPUT; + #endif + #ifdef PL_VULKAN_BACKEND + gptShaderCtx->tDefaultShaderOptions.tFlags |= PL_SHADER_FLAGS_SPIRV_OUTPUT; + #endif + } gptShaderCtx->tDefaultShaderOptions.apcIncludeDirectories[0] = "./"; gptShaderCtx->tDefaultShaderOptions._uIncludeDirectoriesCount = 1; @@ -448,10 +454,6 @@ pl_compile_glsl(const char* pcShader, const char* pcEntryFunc, plShaderOptions* if(tModule.puCode) tModule.szCodeSize = strlen((const char*)tModule.puCode); } - else - { - int a = 5; - } #endif // PL_INCLUDE_SPIRV_CROSS pl_temp_allocator_reset(&gptShaderCtx->tTempAllocator2); #endif // PL_OFFLINE_SHADERS_ONLY @@ -480,9 +482,15 @@ pl_load_glsl(const char* pcShader, const char* pcEntryFunc, const char* pcFile, break; } - #ifdef PL_METAL_BACKEND - ptOptions->tFlags |= PL_SHADER_FLAGS_METAL_OUTPUT; - #endif + if(ptOptions->tFlags & PL_SHADER_FLAGS_AUTO_OUTPUT) + { + #ifdef PL_METAL_BACKEND + ptOptions->tFlags |= PL_SHADER_FLAGS_METAL_OUTPUT; + #endif + #ifdef PL_VULKAN_BACKEND + ptOptions->tFlags |= PL_SHADER_FLAGS_SPIRV_OUTPUT; + #endif + } } if(ptOptions == NULL) @@ -556,11 +564,7 @@ pl_load_shader_ext(plApiRegistryI* ptApiRegistry, bool bReload) const plShaderI tApi = { .initialize = pl_initialize_shader_ext, .load_glsl = pl_load_glsl, - #ifdef PL_OFFLINE_SHADERS_ONLY - .compile_glsl = NULL, - #else .compile_glsl = pl_compile_glsl, - #endif .write_to_disk = pl_write_to_disk, .read_from_disk = pl_read_from_disk, }; diff --git a/extensions/pl_shader_ext.h b/extensions/pl_shader_ext.h index 40f0659..1574cbd 100644 --- a/extensions/pl_shader_ext.h +++ b/extensions/pl_shader_ext.h @@ -115,6 +115,8 @@ enum _plShaderFlags PL_SHADER_FLAGS_ALWAYS_COMPILE = 1 << 1, // ignore cached shader modules PL_SHADER_FLAGS_NEVER_CACHE = 1 << 2, // never cache shaders to disk PL_SHADER_FLAGS_METAL_OUTPUT = 1 << 3, // output metal shader + PL_SHADER_FLAGS_SPIRV_OUTPUT = 1 << 4, // output SPIRV shader + PL_SHADER_FLAGS_AUTO_OUTPUT = 1 << 5, // output SPIRV or metal shader code depending on backend }; enum _plShaderOptimizationLevel diff --git a/sandbox/app.c b/sandbox/app.c index 758e207..dafe56b 100644 --- a/sandbox/app.c +++ b/sandbox/app.c @@ -96,17 +96,19 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plEditorData* ptEditorData) ptEditorData->tSelectedEntity.ulData = UINT64_MAX; // initialize shader extension - static const plShaderOptions tDefaultShaderOptions = { + static plShaderOptions tDefaultShaderOptions = { .apcIncludeDirectories = { "../shaders/" }, .apcDirectories = { "../shaders/" }, - #ifndef PL_OFFLINE_SHADERS_ONLY - .tFlags = PL_SHADER_FLAGS_ALWAYS_COMPILE | PL_SHADER_FLAGS_INCLUDE_DEBUG - #endif + .tFlags = PL_SHADER_FLAGS_AUTO_OUTPUT + }; + #ifndef PL_OFFLINE_SHADERS_ONLY + tDefaultShaderOptions.tFlags |= PL_SHADER_FLAGS_ALWAYS_COMPILE | PL_SHADER_FLAGS_INCLUDE_DEBUG; + #endif gptShader->initialize(&tDefaultShaderOptions); // initialize job system