Skip to content

Commit

Permalink
[Graphics]: Fixing bug with shader storage binding location
Browse files Browse the repository at this point in the history
[GUI]: Fixing unique id push
  • Loading branch information
MrFrenik committed Oct 21, 2023
1 parent acbc6f9 commit 18aef07
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 54 deletions.
9 changes: 5 additions & 4 deletions impl/gs_graphics_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ typedef struct gsgl_storage_buffer_t {
int32_t access;
size_t size;
uint32_t block_idx;
uint32_t location;
} gsgl_storage_buffer_t;

/* Pipeline */
Expand Down Expand Up @@ -2249,8 +2250,6 @@ void gs_graphics_command_buffer_submit_impl(gs_command_buffer_t* cb)

gsgl_shader_t shader = gs_slot_array_get(ogl->shaders, sid);

static uint32_t location = UINT32_MAX;

if ((sbo->block_idx == UINT32_MAX && sbo->block_idx != UINT32_MAX - 1))
{
// Get uniform location based on name and bound shader
Expand All @@ -2259,7 +2258,9 @@ void gs_graphics_command_buffer_submit_impl(gs_command_buffer_t* cb)
int32_t params[1];
GLenum props[1] = {GL_BUFFER_BINDING};
glGetProgramResourceiv(shader, GL_SHADER_STORAGE_BLOCK, sbo->block_idx, 1, props, 1, NULL, params);
location = (uint32_t)params[0];
sbo->location = (uint32_t)params[0];
gs_println("Bind Storage Buffer: Binding \"%s\" to location %zu, block index: %zu, binding: %zu",
sbo->name, sbo->location, sbo->block_idx, binding);
);

if (sbo->block_idx >= UINT32_MAX) {
Expand All @@ -2272,7 +2273,7 @@ void gs_graphics_command_buffer_submit_impl(gs_command_buffer_t* cb)
{
// Not sure what this actually does atm...
CHECK_GL_CORE(
glShaderStorageBlockBinding(shader, sbo->block_idx, location);
glShaderStorageBlockBinding(shader, sbo->block_idx, sbo->location);
);
}

Expand Down
14 changes: 9 additions & 5 deletions util/gs_gfxt.h
Original file line number Diff line number Diff line change
Expand Up @@ -1141,7 +1141,7 @@ gs_gfxt_mesh_draw(gs_command_buffer_t* cb, gs_gfxt_mesh_t* mp)
}

GS_API_DECL void
gs_gfxt_mesh_primitive_draw_layout(gs_command_buffer_t* cb, gs_gfxt_mesh_primitive_t* prim, gs_gfxt_mesh_layout_t* layout, size_t layout_size)
gs_gfxt_mesh_primitive_draw_layout(gs_command_buffer_t* cb, gs_gfxt_mesh_primitive_t* prim, gs_gfxt_mesh_layout_t* layout, size_t layout_size, uint32_t instance_count)
{
if (!layout || !layout_size || !prim || !cb)
{
Expand Down Expand Up @@ -1182,6 +1182,7 @@ gs_gfxt_mesh_primitive_draw_layout(gs_command_buffer_t* cb, gs_gfxt_mesh_primiti
gs_graphics_draw_desc_t ddesc = gs_default_val();
ddesc.start = 0;
ddesc.count = prim->count;
ddesc.instances = instance_count;

gs_graphics_apply_bindings(cb, &binds);
gs_graphics_draw(cb, &ddesc);
Expand All @@ -1201,7 +1202,7 @@ gs_gfxt_mesh_draw_layout(gs_command_buffer_t* cb, gs_gfxt_mesh_t* mesh, gs_gfxt_
for (uint32_t i = 0; i < gs_dyn_array_size(mesh->primitives); ++i)
{
gs_gfxt_mesh_primitive_t* prim = &mesh->primitives[i];
gs_gfxt_mesh_primitive_draw_layout(cb, prim, layout, layout_size);
gs_gfxt_mesh_primitive_draw_layout(cb, prim, layout, layout_size, 1);
}
}

Expand Down Expand Up @@ -1235,7 +1236,7 @@ gs_gfxt_mesh_draw_materials(gs_command_buffer_t* cb, gs_gfxt_mesh_t* mesh, gs_gf
// Get pipeline
gs_gfxt_pipeline_t* pip = gs_gfxt_material_get_pipeline(mat);

gs_gfxt_mesh_primitive_draw_layout(cb, prim, pip->mesh_layout, gs_dyn_array_size(pip->mesh_layout) * sizeof(gs_gfxt_mesh_layout_t));
gs_gfxt_mesh_primitive_draw_layout(cb, prim, pip->mesh_layout, gs_dyn_array_size(pip->mesh_layout) * sizeof(gs_gfxt_mesh_layout_t), 1);
}
}

Expand Down Expand Up @@ -1955,7 +1956,8 @@ gs_gfxt_mesh_t gs_gfxt_mesh_unit_quad_generate(gs_gfxt_mesh_import_options_t* op
return mesh;
}

gs_handle(gs_graphics_texture_t) gs_gfxt_texture_generate_default()
GS_API_DECL gs_handle(gs_graphics_texture_t)
gs_gfxt_texture_generate_default()
{
// Generate procedural texture data (checkered texture)
#define GS_GFXT_ROW_COL_CT 5
Expand Down Expand Up @@ -3158,7 +3160,7 @@ char* gs_pipeline_generate_shader_code(gs_gfxt_pipeline_desc_t* pdesc, gs_ppd_t*
#ifdef GS_PLATFORM_WEB
#define _GS_VERSION_STR "#version 300 es\n"
#else
#define _GS_VERSION_STR MAJMINSTR
#define _GS_VERSION_STR "#version 430\n"
#endif

// Source code
Expand Down Expand Up @@ -3300,6 +3302,7 @@ char* gs_pipeline_generate_shader_code(gs_gfxt_pipeline_desc_t* pdesc, gs_ppd_t*

case GS_GRAPHICS_SHADER_STAGE_COMPUTE:
{
/*
gs_snprintfc(TMP, 64, "layout(");
strncat(src, "layout(", 7);
Expand All @@ -3314,6 +3317,7 @@ char* gs_pipeline_generate_shader_code(gs_gfxt_pipeline_desc_t* pdesc, gs_ppd_t*
}
strncat(src, ") in;\n", 7);
*/
} break;

default: break;
Expand Down
Loading

0 comments on commit 18aef07

Please sign in to comment.