diff --git a/src/pc/gfx/gfx_cc.c b/src/pc/gfx/gfx_cc.c index 20957d01..7b78b969 100644 --- a/src/pc/gfx/gfx_cc.c +++ b/src/pc/gfx/gfx_cc.c @@ -6,8 +6,6 @@ static u8 sAllowCCPrint = 1; void gfx_cc_get_features(struct ColorCombiner* cc, struct CCFeatures* ccf) { - // DO NOT COMMIT: TODO - need to convert dx and regular gl - // reset ccf memset(ccf, 0, sizeof(struct CCFeatures)); diff --git a/src/pc/gfx/gfx_cc.h b/src/pc/gfx/gfx_cc.h index 4a15f98a..f3b9be7a 100644 --- a/src/pc/gfx/gfx_cc.h +++ b/src/pc/gfx/gfx_cc.h @@ -83,6 +83,7 @@ struct CombineMode { #pragma pack() #define SHADER_CMD_LENGTH 16 +#define CC_MAX_SHADERS 64 struct ColorCombiner { struct CombineMode cm; diff --git a/src/pc/gfx/gfx_direct3d11.cpp b/src/pc/gfx/gfx_direct3d11.cpp index 251faacb..6865f85b 100644 --- a/src/pc/gfx/gfx_direct3d11.cpp +++ b/src/pc/gfx/gfx_direct3d11.cpp @@ -103,8 +103,9 @@ static struct { PerFrameCB per_frame_cb_data; PerDrawCB per_draw_cb_data; - struct ShaderProgramD3D11 shader_program_pool[64]; + struct ShaderProgramD3D11 shader_program_pool[CC_MAX_SHADERS]; uint8_t shader_program_pool_size; + uint8_t shader_program_pool_index; std::vector textures; int current_tile; @@ -355,7 +356,9 @@ static struct ShaderProgram *gfx_d3d11_create_and_load_new_shader(struct ColorCo throw hr; } - struct ShaderProgramD3D11 *prg = &d3d.shader_program_pool[d3d.shader_program_pool_size++]; + struct ShaderProgramD3D11 *prg = &d3d.shader_program_pool[d3d.shader_program_pool_index]; + d3d.shader_program_pool_index = (d3d.shader_program_pool_index + 1) % CC_MAX_SHADERS; + if (d3d.shader_program_pool_size < CC_MAX_SHADERS) { d3d.shader_program_pool_size++; } ThrowIfFailed(d3d.device->CreateVertexShader(vs->GetBufferPointer(), vs->GetBufferSize(), nullptr, prg->vertex_shader.GetAddressOf())); ThrowIfFailed(d3d.device->CreatePixelShader(ps->GetBufferPointer(), ps->GetBufferSize(), nullptr, prg->pixel_shader.GetAddressOf())); diff --git a/src/pc/gfx/gfx_direct3d12.cpp b/src/pc/gfx/gfx_direct3d12.cpp index 0c0d4801..72ad859d 100644 --- a/src/pc/gfx/gfx_direct3d12.cpp +++ b/src/pc/gfx/gfx_direct3d12.cpp @@ -108,8 +108,9 @@ static struct { HMODULE d3dcompiler_module; pD3DCompile D3DCompile; - struct ShaderProgramD3D12 shader_program_pool[64]; + struct ShaderProgramD3D12 shader_program_pool[CC_MAX_SHADERS]; uint8_t shader_program_pool_size; + uint8_t shader_program_pool_index; uint32_t current_width, current_height; @@ -236,7 +237,9 @@ static void gfx_direct3d12_load_shader(struct ShaderProgram *new_prg) { } static struct ShaderProgram *gfx_direct3d12_create_and_load_new_shader(struct ColorCombiner* cc) { - struct ShaderProgramD3D12 *prg = &d3d.shader_program_pool[d3d.shader_program_pool_size++]; + struct ShaderProgramD3D12 *prg = &d3d.shader_program_pool[d3d.shader_program_pool_index]; + d3d.shader_program_pool_index = (d3d.shader_program_pool_index + 1) % CC_MAX_SHADERS; + if (d3d.shader_program_pool_size < CC_MAX_SHADERS) { d3d.shader_program_pool_size++; } CCFeatures cc_features = { 0 }; gfx_cc_get_features(cc, &cc_features); diff --git a/src/pc/gfx/gfx_opengl.c b/src/pc/gfx/gfx_opengl.c index 6212474e..d491b5fb 100644 --- a/src/pc/gfx/gfx_opengl.c +++ b/src/pc/gfx/gfx_opengl.c @@ -61,8 +61,9 @@ struct GLTexture { bool filter; }; -static struct ShaderProgram shader_program_pool[64]; -static uint8_t shader_program_pool_size; +static struct ShaderProgram shader_program_pool[CC_MAX_SHADERS]; +static uint8_t shader_program_pool_size = 0; +static uint8_t shader_program_pool_index = 0; static GLuint opengl_vbo; static int tex_cache_size = 0; @@ -473,7 +474,10 @@ static struct ShaderProgram *gfx_opengl_create_and_load_new_shader(struct ColorC size_t cnt = 0; - struct ShaderProgram *prg = &shader_program_pool[shader_program_pool_size++]; + struct ShaderProgram *prg = &shader_program_pool[shader_program_pool_index]; + shader_program_pool_index = (shader_program_pool_index + 1) % CC_MAX_SHADERS; + if (shader_program_pool_size < CC_MAX_SHADERS) { shader_program_pool_size++; } + prg->attrib_locations[cnt] = glGetAttribLocation(shader_program, "aVtxPos"); prg->attrib_sizes[cnt] = 4; ++cnt; diff --git a/src/pc/gfx/gfx_pc.c b/src/pc/gfx/gfx_pc.c index d8aa012f..da60828a 100644 --- a/src/pc/gfx/gfx_pc.c +++ b/src/pc/gfx/gfx_pc.c @@ -94,8 +94,9 @@ static struct { uint32_t pool_pos; } gfx_texture_cache; -static struct ColorCombiner color_combiner_pool[64] = { 0 }; -static uint8_t color_combiner_pool_size; +static struct ColorCombiner color_combiner_pool[CC_MAX_SHADERS] = { 0 }; +static uint8_t color_combiner_pool_size = 0; +static uint8_t color_combiner_pool_index = 0; static struct RSP { float modelview_matrix_stack[11][4][4]; @@ -345,7 +346,10 @@ static struct ColorCombiner *gfx_lookup_or_create_color_combiner(struct CombineM gfx_flush(); - struct ColorCombiner *comb = &color_combiner_pool[color_combiner_pool_size++]; + struct ColorCombiner *comb = &color_combiner_pool[color_combiner_pool_index]; + color_combiner_pool_index = (color_combiner_pool_index + 1) % CC_MAX_SHADERS; + if (color_combiner_pool_size < CC_MAX_SHADERS) { color_combiner_pool_size++; } + memcpy(&comb->cm, cm, sizeof(struct CombineMode)); gfx_generate_cc(comb);