mirror of
https://github.com/izzy2lost/xemu.git
synced 2026-07-06 00:20:22 -07:00
cleanup and fix GL errors
This commit is contained in:
@@ -27,6 +27,21 @@
|
||||
|
||||
#ifdef __ANDROID__
|
||||
#include <android/log.h>
|
||||
|
||||
static void android_log_gl_errors(const char *ctx)
|
||||
{
|
||||
GLenum err;
|
||||
|
||||
while ((err = glGetError()) != GL_NO_ERROR) {
|
||||
__android_log_print(ANDROID_LOG_WARN, "xemu-android",
|
||||
"GL error 0x%X at %s", err, ctx);
|
||||
}
|
||||
}
|
||||
#else
|
||||
static inline void android_log_gl_errors(const char *ctx)
|
||||
{
|
||||
(void)ctx;
|
||||
}
|
||||
#endif
|
||||
|
||||
void pgraph_gl_clear_surface(NV2AState *d, uint32_t parameter)
|
||||
@@ -351,6 +366,8 @@ void pgraph_gl_draw_begin(NV2AState *d)
|
||||
glBeginQuery(GL_SAMPLES_PASSED, gl_query);
|
||||
}
|
||||
#endif
|
||||
|
||||
android_log_gl_errors("pgraph_gl_draw_begin");
|
||||
}
|
||||
|
||||
void pgraph_gl_draw_end(NV2AState *d)
|
||||
@@ -456,6 +473,7 @@ void pgraph_gl_flush_draw(NV2AState *d)
|
||||
pg->draw_arrays_start, pg->draw_arrays_count,
|
||||
pg->draw_arrays_length);
|
||||
}
|
||||
android_log_gl_errors("pgraph_gl_flush_draw: draw_arrays");
|
||||
} else if (pg->inline_elements_length) {
|
||||
NV2A_GL_DPRINTF(false, "Inline Elements");
|
||||
nv2a_profile_inc_counter(NV2A_PROF_INLINE_ELEMENTS);
|
||||
@@ -517,6 +535,7 @@ void pgraph_gl_flush_draw(NV2AState *d)
|
||||
pg->inline_elements_length, GL_UNSIGNED_INT,
|
||||
(void *)0);
|
||||
}
|
||||
android_log_gl_errors("pgraph_gl_flush_draw: inline_elements");
|
||||
} else if (pg->inline_buffer_length) {
|
||||
NV2A_GL_DPRINTF(false, "Inline Buffer");
|
||||
nv2a_profile_inc_counter(NV2A_PROF_INLINE_BUFFERS);
|
||||
@@ -563,6 +582,7 @@ void pgraph_gl_flush_draw(NV2AState *d)
|
||||
glDrawArrays(r->shader_binding->gl_primitive_mode,
|
||||
0, pg->inline_buffer_length);
|
||||
}
|
||||
android_log_gl_errors("pgraph_gl_flush_draw: inline_buffer");
|
||||
} else if (pg->inline_array_length) {
|
||||
NV2A_GL_DPRINTF(false, "Inline Array");
|
||||
nv2a_profile_inc_counter(NV2A_PROF_INLINE_ARRAYS);
|
||||
@@ -584,6 +604,7 @@ void pgraph_gl_flush_draw(NV2AState *d)
|
||||
glDrawArrays(r->shader_binding->gl_primitive_mode,
|
||||
0, index_count);
|
||||
}
|
||||
android_log_gl_errors("pgraph_gl_flush_draw: inline_array");
|
||||
} else {
|
||||
NV2A_GL_DPRINTF(true, "EMPTY NV097_SET_BEGIN_END");
|
||||
NV2A_UNCONFIRMED("EMPTY NV097_SET_BEGIN_END");
|
||||
|
||||
@@ -217,6 +217,11 @@ typedef struct PGRAPHGLState {
|
||||
struct s2t_rndr {
|
||||
GLuint fbo, vao, vbo, prog;
|
||||
GLuint tex_loc, surface_size_loc;
|
||||
#ifdef __ANDROID__
|
||||
GLuint depth_prog;
|
||||
GLuint depth_tex_loc;
|
||||
GLint depth_scale_loc;
|
||||
#endif
|
||||
} s2t_rndr;
|
||||
|
||||
struct disp_rndr {
|
||||
|
||||
@@ -45,6 +45,45 @@ static GLenum get_gl_primitive_mode(enum ShaderPrimitiveMode primitive_mode)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __ANDROID__
|
||||
static void android_log_shader_stage_errors(const char *ctx)
|
||||
{
|
||||
GLenum err;
|
||||
|
||||
while ((err = glGetError()) != GL_NO_ERROR) {
|
||||
__android_log_print(ANDROID_LOG_WARN, "xemu-android",
|
||||
"GL error 0x%X at %s", err, ctx);
|
||||
}
|
||||
}
|
||||
|
||||
static void android_log_apply_uniform_entry_errors(const char *uniform_set)
|
||||
{
|
||||
GLenum err;
|
||||
|
||||
while ((err = glGetError()) != GL_NO_ERROR) {
|
||||
__android_log_print(ANDROID_LOG_WARN, "xemu-android",
|
||||
"GL error 0x%X before apply_uniform_updates:%s",
|
||||
err, uniform_set);
|
||||
}
|
||||
}
|
||||
|
||||
static void android_log_uniform_update_errors(const char *uniform_set,
|
||||
const UniformInfo *info,
|
||||
int loc)
|
||||
{
|
||||
GLenum err;
|
||||
|
||||
while ((err = glGetError()) != GL_NO_ERROR) {
|
||||
__android_log_print(
|
||||
ANDROID_LOG_WARN, "xemu-android",
|
||||
"GL error 0x%X at apply_uniform_updates:%s.%s type=%s count=%zu "
|
||||
"loc=%d",
|
||||
err, uniform_set, info->name,
|
||||
uniform_element_type_to_str[info->type], info->count, loc);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static void log_shader_source_with_line_numbers(const char *name,
|
||||
const char *code)
|
||||
{
|
||||
@@ -734,9 +773,14 @@ void pgraph_gl_shader_cache_to_disk(ShaderBinding *binding)
|
||||
qemu_thread_create(binding->save_thread, name, shader_write_to_disk, binding, QEMU_THREAD_JOINABLE);
|
||||
}
|
||||
|
||||
static void apply_uniform_updates(const UniformInfo *info, int *locs,
|
||||
static void apply_uniform_updates(const char *uniform_set,
|
||||
const UniformInfo *info, int *locs,
|
||||
void *values, size_t count)
|
||||
{
|
||||
#ifdef __ANDROID__
|
||||
android_log_apply_uniform_entry_errors(uniform_set);
|
||||
#endif
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (locs[i] == -1) {
|
||||
continue;
|
||||
@@ -775,13 +819,13 @@ static void apply_uniform_updates(const UniformInfo *info, int *locs,
|
||||
default:
|
||||
g_assert_not_reached();
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __ANDROID__
|
||||
while (glGetError() != GL_NO_ERROR) {
|
||||
/* Ignore uniform update GL errors on Android. */
|
||||
android_log_uniform_update_errors(uniform_set, &info[i], locs[i]);
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
|
||||
#ifndef __ANDROID__
|
||||
assert(glGetError() == GL_NO_ERROR);
|
||||
#endif
|
||||
}
|
||||
@@ -795,7 +839,7 @@ static void update_shader_uniforms(PGRAPHState *pg, ShaderBinding *binding)
|
||||
VshUniformValues vsh_values;
|
||||
pgraph_glsl_set_vsh_uniform_values(pg, &binding->state.vsh,
|
||||
binding->uniform_locs.vsh, &vsh_values);
|
||||
apply_uniform_updates(VshUniformInfo, binding->uniform_locs.vsh,
|
||||
apply_uniform_updates("vsh", VshUniformInfo, binding->uniform_locs.vsh,
|
||||
&vsh_values, VshUniform__COUNT);
|
||||
|
||||
PshUniformValues psh_values;
|
||||
@@ -807,7 +851,7 @@ static void update_shader_uniforms(PGRAPHState *pg, ShaderBinding *binding)
|
||||
psh_values.texScale[i] = scale;
|
||||
}
|
||||
}
|
||||
apply_uniform_updates(PshUniformInfo, binding->uniform_locs.psh,
|
||||
apply_uniform_updates("psh", PshUniformInfo, binding->uniform_locs.psh,
|
||||
&psh_values, PshUniform__COUNT);
|
||||
}
|
||||
|
||||
@@ -853,6 +897,10 @@ void pgraph_gl_bind_shaders(PGRAPHState *pg)
|
||||
if (binding_changed) {
|
||||
nv2a_profile_inc_counter(NV2A_PROF_SHADER_BIND);
|
||||
glUseProgram(r->shader_binding->gl_program);
|
||||
#ifdef __ANDROID__
|
||||
android_log_shader_stage_errors(
|
||||
"pgraph_gl_bind_shaders: binding_changed");
|
||||
#endif
|
||||
}
|
||||
|
||||
NV2A_GL_DGROUP_END();
|
||||
@@ -860,6 +908,10 @@ void pgraph_gl_bind_shaders(PGRAPHState *pg)
|
||||
update_uniforms:
|
||||
assert(r->shader_binding);
|
||||
assert(r->shader_binding->initialized);
|
||||
glUseProgram(r->shader_binding->gl_program);
|
||||
#ifdef __ANDROID__
|
||||
android_log_shader_stage_errors("pgraph_gl_bind_shaders: update_uniforms");
|
||||
#endif
|
||||
update_shader_uniforms(pg, r->shader_binding);
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -28,6 +28,43 @@
|
||||
#include "renderer.h"
|
||||
|
||||
#ifdef __ANDROID__
|
||||
#include <android/log.h>
|
||||
|
||||
static void android_log_gl_errors(const char *ctx)
|
||||
{
|
||||
GLenum err;
|
||||
|
||||
while ((err = glGetError()) != GL_NO_ERROR) {
|
||||
__android_log_print(ANDROID_LOG_WARN, "xemu-android",
|
||||
"GL error 0x%X at %s", err, ctx);
|
||||
}
|
||||
}
|
||||
|
||||
static void android_log_texture_stage_errors(int unit, const char *stage,
|
||||
const TextureShape *shape,
|
||||
GLenum gl_target)
|
||||
{
|
||||
GLenum err;
|
||||
|
||||
while ((err = glGetError()) != GL_NO_ERROR) {
|
||||
if (shape) {
|
||||
__android_log_print(
|
||||
ANDROID_LOG_WARN, "xemu-android",
|
||||
"GL error 0x%X at pgraph_gl_bind_textures[%d]: %s "
|
||||
"target=0x%X dim=%u fmt=0x%X levels=%u border=%d cubemap=%d",
|
||||
err, unit, stage, gl_target, shape->dimensionality,
|
||||
shape->color_format, shape->levels, shape->border,
|
||||
shape->cubemap);
|
||||
} else {
|
||||
__android_log_print(
|
||||
ANDROID_LOG_WARN, "xemu-android",
|
||||
"GL error 0x%X at pgraph_gl_bind_textures[%d]: %s "
|
||||
"target=0x%X",
|
||||
err, unit, stage, gl_target);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static uint8_t android_expand_4_to_8(uint8_t value)
|
||||
{
|
||||
return (value << 4) | value;
|
||||
@@ -515,6 +552,9 @@ void pgraph_gl_bind_textures(NV2AState *d)
|
||||
/* FIXME: What happens if texture is disabled but stage is active? */
|
||||
|
||||
glActiveTexture(GL_TEXTURE0 + i);
|
||||
#ifdef __ANDROID__
|
||||
android_log_texture_stage_errors(i, "after_active_texture", NULL, 0);
|
||||
#endif
|
||||
if (!enabled) {
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
|
||||
#ifndef __ANDROID__
|
||||
@@ -522,6 +562,9 @@ void pgraph_gl_bind_textures(NV2AState *d)
|
||||
#endif
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glBindTexture(GL_TEXTURE_3D, 0);
|
||||
#ifdef __ANDROID__
|
||||
android_log_texture_stage_errors(i, "disabled_unbind", NULL, 0);
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -574,6 +617,11 @@ void pgraph_gl_bind_textures(NV2AState *d)
|
||||
if (reusable) {
|
||||
glBindTexture(r->texture_binding[i]->gl_target,
|
||||
r->texture_binding[i]->gl_texture);
|
||||
#ifdef __ANDROID__
|
||||
android_log_texture_stage_errors(
|
||||
i, "reuse_bind_existing", &state,
|
||||
r->texture_binding[i]->gl_target);
|
||||
#endif
|
||||
apply_texture_parameters(r,
|
||||
r->texture_binding[i],
|
||||
&kelvin_color_format_info_map[state.color_format],
|
||||
@@ -583,6 +631,11 @@ void pgraph_gl_bind_textures(NV2AState *d)
|
||||
state.border,
|
||||
border_color,
|
||||
max_anisotropy);
|
||||
#ifdef __ANDROID__
|
||||
android_log_texture_stage_errors(
|
||||
i, "reuse_apply_texture_parameters", &state,
|
||||
r->texture_binding[i]->gl_target);
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -597,6 +650,10 @@ void pgraph_gl_bind_textures(NV2AState *d)
|
||||
|
||||
if (surf_to_tex && surface->upload_pending) {
|
||||
pgraph_gl_upload_surface_data(d, surface, false);
|
||||
#ifdef __ANDROID__
|
||||
android_log_texture_stage_errors(i, "surface_upload_pending",
|
||||
&state, GL_TEXTURE_2D);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -611,6 +668,10 @@ void pgraph_gl_bind_textures(NV2AState *d)
|
||||
|| texture_vram_offset >= surf_vram_end);
|
||||
if (overlapping) {
|
||||
pgraph_gl_surface_download_if_dirty(d, surface);
|
||||
#ifdef __ANDROID__
|
||||
android_log_texture_stage_errors(i, "download_overlap",
|
||||
&state, GL_TEXTURE_2D);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -667,10 +728,18 @@ void pgraph_gl_bind_textures(NV2AState *d)
|
||||
key_out->binding = generate_texture(state, texture_data, palette_data);
|
||||
key_out->binding->data_hash = tex_data_hash;
|
||||
key_out->binding->scale = 1;
|
||||
#ifdef __ANDROID__
|
||||
android_log_texture_stage_errors(i, "generate_texture", &state,
|
||||
key_out->binding->gl_target);
|
||||
#endif
|
||||
} else {
|
||||
// Saved an upload! Reuse existing texture in graphics memory.
|
||||
glBindTexture(key_out->binding->gl_target,
|
||||
key_out->binding->gl_texture);
|
||||
#ifdef __ANDROID__
|
||||
android_log_texture_stage_errors(i, "reuse_cached_binding", &state,
|
||||
key_out->binding->gl_target);
|
||||
#endif
|
||||
}
|
||||
|
||||
key_out->possibly_dirty = false;
|
||||
@@ -684,6 +753,10 @@ void pgraph_gl_bind_textures(NV2AState *d)
|
||||
pgraph_gl_render_surface_to_texture(d, surface, binding, &state, i);
|
||||
binding->draw_time = surface->draw_time;
|
||||
binding->scale = pg->surface_scale_factor;
|
||||
#ifdef __ANDROID__
|
||||
android_log_texture_stage_errors(i, "render_surface_to_texture",
|
||||
&state, binding->gl_target);
|
||||
#endif
|
||||
}
|
||||
|
||||
apply_texture_parameters(r,
|
||||
@@ -695,16 +768,29 @@ void pgraph_gl_bind_textures(NV2AState *d)
|
||||
state.border,
|
||||
border_color,
|
||||
max_anisotropy);
|
||||
#ifdef __ANDROID__
|
||||
android_log_texture_stage_errors(i, "apply_texture_parameters", &state,
|
||||
binding->gl_target);
|
||||
#endif
|
||||
|
||||
if (r->texture_binding[i]) {
|
||||
if (r->texture_binding[i]->gl_target != binding->gl_target) {
|
||||
glBindTexture(r->texture_binding[i]->gl_target, 0);
|
||||
#ifdef __ANDROID__
|
||||
android_log_texture_stage_errors(
|
||||
i, "unbind_old_target", &state,
|
||||
r->texture_binding[i]->gl_target);
|
||||
#endif
|
||||
}
|
||||
texture_binding_destroy(r->texture_binding[i]);
|
||||
}
|
||||
r->texture_binding[i] = binding;
|
||||
pg->texture_dirty[i] = false;
|
||||
}
|
||||
|
||||
#ifdef __ANDROID__
|
||||
android_log_gl_errors("pgraph_gl_bind_textures");
|
||||
#endif
|
||||
NV2A_GL_DGROUP_END();
|
||||
}
|
||||
|
||||
@@ -1143,8 +1229,21 @@ static TextureBinding* generate_texture(const TextureShape s,
|
||||
}
|
||||
#endif
|
||||
if (apply_swizzle) {
|
||||
#ifdef __ANDROID__
|
||||
/* GLES exposes per-channel texture swizzles, not the desktop RGBA
|
||||
* vector pname. */
|
||||
glTexParameteri(gl_target, GL_TEXTURE_SWIZZLE_R,
|
||||
f.gl_swizzle_mask[0]);
|
||||
glTexParameteri(gl_target, GL_TEXTURE_SWIZZLE_G,
|
||||
f.gl_swizzle_mask[1]);
|
||||
glTexParameteri(gl_target, GL_TEXTURE_SWIZZLE_B,
|
||||
f.gl_swizzle_mask[2]);
|
||||
glTexParameteri(gl_target, GL_TEXTURE_SWIZZLE_A,
|
||||
f.gl_swizzle_mask[3]);
|
||||
#else
|
||||
glTexParameteriv(gl_target, GL_TEXTURE_SWIZZLE_RGBA,
|
||||
(const GLint *)f.gl_swizzle_mask);
|
||||
#endif
|
||||
}
|
||||
|
||||
TextureBinding* ret = (TextureBinding *)g_malloc(sizeof(TextureBinding));
|
||||
|
||||
@@ -24,6 +24,25 @@
|
||||
#include "debug.h"
|
||||
#include "renderer.h"
|
||||
|
||||
#ifdef __ANDROID__
|
||||
#include <android/log.h>
|
||||
|
||||
static void android_log_gl_errors(const char *ctx)
|
||||
{
|
||||
GLenum err;
|
||||
|
||||
while ((err = glGetError()) != GL_NO_ERROR) {
|
||||
__android_log_print(ANDROID_LOG_WARN, "xemu-android",
|
||||
"GL error 0x%X at %s", err, ctx);
|
||||
}
|
||||
}
|
||||
#else
|
||||
static inline void android_log_gl_errors(const char *ctx)
|
||||
{
|
||||
(void)ctx;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void update_memory_buffer(NV2AState *d, hwaddr addr, hwaddr size,
|
||||
bool quick)
|
||||
{
|
||||
@@ -205,6 +224,7 @@ void pgraph_gl_bind_vertex_attributes(NV2AState *d, unsigned int min_element,
|
||||
pgraph_update_inline_value(attr, last_entry);
|
||||
}
|
||||
|
||||
android_log_gl_errors("pgraph_gl_bind_vertex_attributes");
|
||||
NV2A_GL_DGROUP_END();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user