Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
hoffstadt committed Feb 13, 2025
1 parent 8c1a6e4 commit 8bb79b5
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 29 deletions.
10 changes: 9 additions & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion examples/example_2.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
},
.apcDirectories = {
"../shaders/"
}
},
.tFlags = PL_SHADER_FLAGS_AUTO_OUTPUT
};
gptShader->initialize(&tDefaultShaderOptions);

Expand Down
3 changes: 2 additions & 1 deletion examples/example_3.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
},
.apcDirectories = {
"../shaders/"
}
},
.tFlags = PL_SHADER_FLAGS_AUTO_OUTPUT
};
gptShader->initialize(&tDefaultShaderOptions);

Expand Down
3 changes: 2 additions & 1 deletion examples/example_4.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
.apcDirectories = {
"../shaders/",
"../examples/shaders/"
}
},
.tFlags = PL_SHADER_FLAGS_AUTO_OUTPUT
};
gptShader->initialize(&tDefaultShaderOptions);

Expand Down
3 changes: 2 additions & 1 deletion examples/example_5.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
.apcDirectories = {
"../shaders/",
"../examples/shaders/"
}
},
.tFlags = PL_SHADER_FLAGS_AUTO_OUTPUT
};
gptShader->initialize(&tDefaultShaderOptions);

Expand Down
3 changes: 2 additions & 1 deletion examples/example_6.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
.apcDirectories = {
"../shaders/",
"../examples/shaders/"
}
},
.tFlags = PL_SHADER_FLAGS_AUTO_OUTPUT
};
gptShader->initialize(&tDefaultShaderOptions);

Expand Down
3 changes: 2 additions & 1 deletion examples/example_8.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,8 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
},
.apcDirectories = {
"../shaders/"
}
},
.tFlags = PL_SHADER_FLAGS_AUTO_OUTPUT
};
gptShader->initialize(&tDefaultShaderOptions);

Expand Down
3 changes: 2 additions & 1 deletion examples/example_9.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,8 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
},
.apcDirectories = {
"../shaders/"
}
},
.tFlags = PL_SHADER_FLAGS_AUTO_OUTPUT
};
gptShader->initialize(&tDefaultShaderOptions);

Expand Down
7 changes: 4 additions & 3 deletions extensions/pl_renderer_internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
32 changes: 18 additions & 14 deletions extensions/pl_shader_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
};
Expand Down
2 changes: 2 additions & 0 deletions extensions/pl_shader_ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions sandbox/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8bb79b5

Please sign in to comment.