Skip to content

Commit

Permalink
WIP2
Browse files Browse the repository at this point in the history
  • Loading branch information
hoffstadt committed Jun 6, 2024
1 parent 12fda58 commit e52813f
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 10 deletions.
44 changes: 41 additions & 3 deletions extensions/pl_ref_renderer_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ Index of this file:
#include "pl_draw_ext.h"
#include "pl_ui_ext.h"

#include "shaderc/shaderc.h"

#define PL_MAX_VIEWS_PER_SCENE 4
#define PL_MAX_LIGHTS 1000

Expand Down Expand Up @@ -454,6 +456,29 @@ static plBufferHandle pl__refr_create_local_buffer (const plBufferDescr
// [SECTION] implementation
//-----------------------------------------------------------------------------

shaderc_include_result*
pl_shaderc_include_resolve_fn(void* user_data, const char* requested_source, int type, const char* requesting_source, size_t include_depth)
{
shaderc_include_result* result = PL_ALLOC(sizeof(shaderc_include_result));
uint32_t uVertexShaderSize = 0;
gptFile->read(requested_source, &uVertexShaderSize, NULL, "rb");
uint8_t* puVertexShaderCode = PL_ALLOC((size_t)uVertexShaderSize);
gptFile->read(requested_source, &uVertexShaderSize, puVertexShaderCode, "rb");

result->source_name = requested_source;
result->source_name_length = strlen(requested_source);
result->content = (const char*)puVertexShaderCode;
result->content_length = (size_t)uVertexShaderSize;
result->user_data = user_data;
return result;

}

void pl_shaderc_include_result_release_fn(void* user_data, shaderc_include_result* include_result)
{

}

static void
pl_refr_initialize(plWindow* ptWindow)
{
Expand Down Expand Up @@ -666,7 +691,12 @@ pl_refr_initialize(plWindow* ptWindow)
const char* pcShader = "../shaders/metal/primitive.metal";
#else
const char* pcVertexShader = "primitive.vert.spv";
const char* pcPixelShader = "primitive.frag.spv";
// const char* pcPixelShader = "primitive.frag.spv";
const char* pcPixelShader = "../shaders/glsl/primitive.frag";

shaderc_compiler_t tBlah = shaderc_compiler_initialize();
shaderc_compile_options_t tOptions = shaderc_compile_options_initialize();
shaderc_compile_options_set_include_callbacks(tOptions, pl_shaderc_include_resolve_fn, pl_shaderc_include_result_release_fn, NULL);

gptFile->read(pcVertexShader, &uVertexShaderSize, NULL, "rb");
gptFile->read(pcPixelShader, &uPixelShaderSize, NULL, "rb");
Expand All @@ -676,13 +706,21 @@ pl_refr_initialize(plWindow* ptWindow)
gptFile->read(pcPixelShader, &uPixelShaderSize, puPixelShaderCode, "rb");
pl_sb_push(gptData->sbptShaderBytecodeCache, puVertexShaderCode);
pl_sb_push(gptData->sbptShaderBytecodeCache, puPixelShaderCode);

shaderc_compilation_result_t tresult = shaderc_compile_into_spv(tBlah, (const char*)puPixelShaderCode, (size_t)uPixelShaderSize, shaderc_glsl_fragment_shader, "primitive.frag", "main", tOptions);
size_t uNumErrors = shaderc_result_get_num_errors(tresult);
if(uNumErrors)
{
printf("%s\n", shaderc_result_get_error_message(tresult));
}
#endif

plShaderDescription tOpaqueShaderDescription = {
.szVertexShaderByteCodeSize = uVertexShaderSize,
.szPixelShaderByteCodeSize = uPixelShaderSize,
.szPixelShaderByteCodeSize = shaderc_result_get_length(tresult),
.puVertexShaderByteCode = puVertexShaderCode,
.puPixelShaderByteCode = puPixelShaderCode,
.puPixelShaderByteCode = (uint8_t*)shaderc_result_get_bytes(tresult),

.tGraphicsState = {
.ulDepthWriteEnabled = 1,
.ulDepthMode = PL_COMPARE_MODE_LESS,
Expand Down
12 changes: 7 additions & 5 deletions scripts/gen_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

def add_plugin_to_vulkan_app(name, reloadable, binary_name = None, directory = "../extensions/", *kwargs):

pl.push_profile(pl.Profile.VULKAN)
pl.push_definitions("PL_VULKAN_BACKEND")
with pl.target(name, pl.TargetType.DYNAMIC_LIBRARY, reloadable):
if binary_name is None:
pl.push_output_binary(name)
Expand All @@ -35,8 +33,6 @@ def add_plugin_to_vulkan_app(name, reloadable, binary_name = None, directory = "
pass
pl.pop_output_binary()
pl.pop_source_files()
pl.pop_profile()
pl.pop_definitions()

def add_plugin_to_metal_app(name, reloadable, objc = False, binary_name = None, directory = "../extensions/"):

Expand Down Expand Up @@ -118,7 +114,6 @@ def add_plugin_to_metal_app(name, reloadable, objc = False, binary_name = None,
add_plugin_to_vulkan_app("pl_draw_ext", True)
add_plugin_to_vulkan_app("pl_debug_ext", False)
add_plugin_to_vulkan_app("pl_image_ext", False)
add_plugin_to_vulkan_app("pl_graphics_vulkan", False, "pl_graphics_ext")
add_plugin_to_vulkan_app("pl_stats_ext", False)
add_plugin_to_vulkan_app("pl_job_ext", False)
add_plugin_to_vulkan_app("pl_model_loader_ext", False)
Expand All @@ -128,6 +123,12 @@ def add_plugin_to_metal_app(name, reloadable, objc = False, binary_name = None,
add_plugin_to_vulkan_app("pl_ref_renderer_ext", True)
add_plugin_to_vulkan_app("pl_ui_ext", True, None)

pl.push_profile(pl.Profile.VULKAN)
pl.push_definitions("PL_VULKAN_BACKEND")
add_plugin_to_vulkan_app("pl_graphics_vulkan", False, "pl_graphics_ext")
pl.pop_profile()
pl.pop_definitions()

add_plugin_to_metal_app("pl_draw_ext", True)
add_plugin_to_metal_app("pl_debug_ext", False)
add_plugin_to_metal_app("pl_image_ext", False)
Expand Down Expand Up @@ -218,6 +219,7 @@ def add_plugin_to_metal_app(name, reloadable, objc = False, binary_name = None,
with pl.platform(pl.PlatformType.WIN32):
with pl.compiler("msvc", pl.CompilerType.MSVC):
pl.add_definition("PL_VULKAN_BACKEND")
pl.add_link_library("shaderc_combined.lib")
with pl.platform(pl.PlatformType.LINUX):
with pl.compiler("gcc", pl.CompilerType.GCC):
pl.add_definition("PL_VULKAN_BACKEND")
Expand Down
4 changes: 2 additions & 2 deletions shaders/glsl/primitive.frag
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#version 450
#extension GL_ARB_separate_shader_objects : enable

#include "defines.glsl"
#include "material.glsl"
#include "../shaders/glsl/defines.glsl"
#include "../shaders/glsl/material.glsl"

//-----------------------------------------------------------------------------
// [SECTION] specialication constants
Expand Down

0 comments on commit e52813f

Please sign in to comment.