gxm: Sync textures before each draw

This commit is contained in:
pent0 2021-05-23 15:12:08 +07:00 committed by Nicolas Jallamion
parent 7f0ced1f79
commit e189b801e7
3 changed files with 24 additions and 9 deletions

View File

@ -78,6 +78,8 @@ struct GxmRecordState {
SceGxmColorSurface color_surface;
SceGxmDepthStencilSurface depth_stencil_surface;
SceGxmTexture fragment_textures[SCE_GXM_MAX_TEXTURE_UNITS];
SceGxmCullMode cull_mode = SCE_GXM_CULL_NONE;
SceGxmTwoSidedMode two_sided = SCE_GXM_TWO_SIDED_DISABLED;
SceGxmRegionClipMode region_clip_mode = SCE_GXM_REGION_CLIP_OUTSIDE;
@ -114,6 +116,8 @@ struct Context {
std::string last_draw_fragment_program_hash;
std::string last_draw_vertex_program_hash;
std::uint8_t texture_bind_list = 0;
};
struct ShaderProgram {

View File

@ -77,6 +77,16 @@ void draw(GLState &renderer, GLContext &context, const FeatureState &features, S
// Use it
program_id = (*program).get();
context.last_draw_program = program_id;
// Gather what textures to bind
context.texture_bind_list = 0;
const auto frag_params = gxp::program_parameters(fragment_program_gxp);
for (std::uint32_t i = 0; i < fragment_program_gxp.parameter_count; i++) {
if (frag_params[i].category == SCE_GXM_PARAMETER_CATEGORY_SAMPLER) {
context.texture_bind_list |= (1 << frag_params[i].resource_index);
}
}
} else {
program_id = context.last_draw_program;
}
@ -103,6 +113,12 @@ void draw(GLState &renderer, GLContext &context, const FeatureState &features, S
glBindImageTexture(shader::MASK_TEXTURE_SLOT_IMAGE, context.render_target->masktexture[0], 0, GL_FALSE, 0, GL_READ_WRITE, GL_RGBA8);
for (std::uint32_t i = 0; i < SCE_GXM_MAX_TEXTURE_UNITS; i++) {
if (context.texture_bind_list & (1 << i)) {
gl::sync_texture(context, mem, i, context.record.fragment_textures[i], config, base_path, title_id);
}
}
GXMRenderVertUniformBlock vert_ublock;
std::memcpy(vert_ublock.viewport_flip, context.viewport_flip, sizeof(context.viewport_flip));

View File

@ -305,15 +305,10 @@ COMMAND_SET_STATE(fragment_texture) {
const std::uint32_t texture_index = helper.pop<std::uint32_t>();
SceGxmTexture texture = helper.pop<SceGxmTexture>();
switch (renderer.current_backend) {
case Backend::OpenGL:
gl::sync_texture(*reinterpret_cast<gl::GLContext *>(render_context), mem, texture_index, texture,
config, base_path, title_id);
break;
default:
REPORT_MISSING(renderer.current_backend);
break;
if (texture_index >= SCE_GXM_MAX_TEXTURE_UNITS) {
LOG_ERROR("Out of bounds texture index {}", texture_index);
} else {
render_context->record.fragment_textures[texture_index] = texture;
}
}