From 48ed0cb903438a42fa871efcd5a7fa03da8d5679 Mon Sep 17 00:00:00 2001 From: sephiroth99 Date: Thu, 4 Jun 2015 23:32:37 -0400 Subject: [PATCH 1/3] gl4: fix glGetInteger of GL_SAMPLER_BINDING GL_SAMPLER_BINDING returns a single value. On AMD drivers, using the indexed version of glGetInteger to get that value causes a GL_INVALID_ENUM error. Use the non-indexed version. --- src/xenia/gpu/gl4/blitter.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/xenia/gpu/gl4/blitter.cc b/src/xenia/gpu/gl4/blitter.cc index b924c831e..ce4edd912 100644 --- a/src/xenia/gpu/gl4/blitter.cc +++ b/src/xenia/gpu/gl4/blitter.cc @@ -180,7 +180,7 @@ struct SavedState { glGetIntegerv(GL_PROGRAM_PIPELINE_BINDING, &program_pipeline); glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &vertex_array); glGetIntegerv(GL_TEXTURE_BINDING_2D, &texture_0); - glGetIntegeri_v(GL_SAMPLER_BINDING, 0, &sampler_0); + glGetIntegerv(GL_SAMPLER_BINDING, &sampler_0); } void Restore() { From 1139a1b6acbe839826742992b2051500ff37f9f4 Mon Sep 17 00:00:00 2001 From: sephiroth99 Date: Thu, 4 Jun 2015 23:52:47 -0400 Subject: [PATCH 2/3] gl4: fix nullptr dereference in GL4Shader::CompileProgram A nullptr dereference will occur when the disassembly string is not found, which will obviously happen on AMD. Check for the condition and if it is not found, put a message indicating so. --- src/xenia/gpu/gl4/gl4_shader.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/xenia/gpu/gl4/gl4_shader.cc b/src/xenia/gpu/gl4/gl4_shader.cc index e2e20be14..798bd06c5 100644 --- a/src/xenia/gpu/gl4/gl4_shader.cc +++ b/src/xenia/gpu/gl4/gl4_shader.cc @@ -424,7 +424,11 @@ bool GL4Shader::CompileProgram(std::string source) { search_offset = p - search_start; ++search_offset; } - host_disassembly_ = std::string(disasm_start); + if (disasm_start) { + host_disassembly_ = std::string(disasm_start); + } else { + host_disassembly_ = std::string("Shader disassembly not available."); + } // Append to shader dump. if (FLAGS_dump_shaders.size()) { From dd30330d18f996a4d6519ba493d4a8f8fd22b177 Mon Sep 17 00:00:00 2001 From: sephiroth99 Date: Fri, 5 Jun 2015 00:11:23 -0400 Subject: [PATCH 3/3] gl4: fix usage of struct as input/output variables Apparently, structs cannot be used as in/out variables. This causes shader compile errors on AMD (nVidia doesn't seem to care I guess?). Remove the structs and put each struct members as its own variable. --- src/xenia/gpu/gl4/blitter.cc | 22 ++++------- src/xenia/gpu/gl4/gl4_profiler_display.cc | 45 ++++++++++------------- 2 files changed, 28 insertions(+), 39 deletions(-) diff --git a/src/xenia/gpu/gl4/blitter.cc b/src/xenia/gpu/gl4/blitter.cc index ce4edd912..722792942 100644 --- a/src/xenia/gpu/gl4/blitter.cc +++ b/src/xenia/gpu/gl4/blitter.cc @@ -45,9 +45,6 @@ precision highp float; \n\ precision highp int; \n\ layout(std140, column_major) uniform; \n\ layout(std430, column_major) buffer; \n\ -struct VertexData { \n\ - vec2 uv; \n\ -}; \n\ "; const std::string vs_source = header + "\n\ @@ -57,32 +54,29 @@ out gl_PerVertex { \n\ float gl_PointSize; \n\ float gl_ClipDistance[]; \n\ }; \n\ -struct VertexFetch { \n\ - vec2 pos; \n\ -};\n\ -layout(location = 0) in VertexFetch vfetch; \n\ -layout(location = 0) out VertexData vtx; \n\ +layout(location = 0) in vec2 vfetch_pos; \n\ +layout(location = 0) out vec2 vtx_uv; \n\ void main() { \n\ - gl_Position = vec4(vfetch.pos.xy * vec2(2.0, -2.0) - vec2(1.0, -1.0), 0.0, 1.0); \n\ - vtx.uv = vfetch.pos.xy * src_uv.zw + src_uv.xy; \n\ + gl_Position = vec4(vfetch_pos.xy * vec2(2.0, -2.0) - vec2(1.0, -1.0), 0.0, 1.0); \n\ + vtx_uv = vfetch_pos.xy * src_uv.zw + src_uv.xy; \n\ } \n\ "; const std::string color_fs_source = header + "\n\ layout(location = 1) uniform sampler2D src_texture; \n\ -layout(location = 0) in VertexData vtx; \n\ +layout(location = 0) in vec2 vtx_uv; \n\ layout(location = 0) out vec4 oC; \n\ void main() { \n\ - oC = texture(src_texture, vtx.uv); \n\ + oC = texture(src_texture, vtx_uv); \n\ } \n\ "; const std::string depth_fs_source = header + "\n\ layout(location = 1) uniform sampler2D src_texture; \n\ -layout(location = 0) in VertexData vtx; \n\ +layout(location = 0) in vec2 vtx_uv; \n\ layout(location = 0) out vec4 oC; \n\ void main() { \n\ - gl_FragDepth = texture(src_texture, vtx.uv).r; \n\ + gl_FragDepth = texture(src_texture, vtx_uv).r; \n\ } \n\ "; diff --git a/src/xenia/gpu/gl4/gl4_profiler_display.cc b/src/xenia/gpu/gl4/gl4_profiler_display.cc index b21020e09..a5d413ee5 100644 --- a/src/xenia/gpu/gl4/gl4_profiler_display.cc +++ b/src/xenia/gpu/gl4/gl4_profiler_display.cc @@ -252,44 +252,39 @@ precision highp float; \n\ precision highp int; \n\ layout(std140, column_major) uniform; \n\ layout(std430, column_major) buffer; \n\ -struct VertexData { \n\ - vec4 color; \n\ - vec2 uv; \n\ -};\n\ "; const std::string vertex_shader_source = header + "\n\ layout(location = 0) uniform mat4 projection_matrix; \n\ -struct VertexFetch { \n\ - vec2 pos; \n\ - vec4 color; \n\ - vec2 uv; \n\ -}; \n\ -layout(location = 0) in VertexFetch vfetch; \n\ -layout(location = 0) out VertexData vtx; \n\ +layout(location = 0) in vec2 in_pos; \n\ +layout(location = 1) in vec4 in_color; \n\ +layout(location = 2) in vec2 in_uv; \n\ +layout(location = 0) out vec4 vtx_color; \n\ +layout(location = 1) out vec2 vtx_uv; \n\ void main() { \n\ - gl_Position = projection_matrix * vec4(vfetch.pos.xy, 0.0, 1.0); \n\ - vtx.color = vfetch.color; \n\ - vtx.uv = vfetch.uv; \n\ + gl_Position = projection_matrix * vec4(in_pos.xy, 0.0, 1.0); \n\ + vtx_color = in_color; \n\ + vtx_uv = in_uv; \n\ } \n\ "; const std::string fragment_shader_source = header + "\n\ layout(location = 1, bindless_sampler) uniform sampler2D font_texture; \n\ layout(location = 2) uniform float font_height; \n\ -layout(location = 0) in VertexData vtx; \n\ +layout(location = 0) in vec4 vtx_color; \n\ +layout(location = 1) in vec2 vtx_uv; \n\ layout(location = 0) out vec4 oC; \n\ void main() { \n\ - if (vtx.uv.x > 1.0) { \n\ - oC = vtx.color; \n\ - } else { \n\ - vec4 color = texture(font_texture, vtx.uv); \n\ - oC = color.rgba * vtx.color; \n\ - if (color.a < 0.5) { \n\ - vec4 c1 = texture(font_texture, vtx.uv + vec2(0.0, font_height)); \n\ - oC = vec4(0, 0, 0, c1.a); \n\ - } \n\ - } \n\ + if (vtx_uv.x > 1.0) { \n\ + oC = vtx_color; \n\ + } else { \n\ + vec4 color = texture(font_texture, vtx_uv); \n\ + oC = color.rgba * vtx_color; \n\ + if (color.a < 0.5) { \n\ + vec4 c1 = texture(font_texture, vtx_uv + vec2(0.0, font_height)); \n\ + oC = vec4(0, 0, 0, c1.a); \n\ + } \n\ + } \n\ } \n\ ";