Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: chrome/browser/android/vr_shell/vr_shell_renderer.cc

Issue 2833823002: WebVR: Add explicit precision to all shaders to avoid Mali GPU crash (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/android/vr_shell/mailbox_to_surface_bridge.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/android/vr_shell/vr_shell_renderer.h" 5 #include "chrome/browser/android/vr_shell/vr_shell_renderer.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 #include <algorithm> 8 #include <algorithm>
9 #include <string> 9 #include <string>
10 10
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 #define VOID_OFFSET(x) reinterpret_cast<void*>(x) 70 #define VOID_OFFSET(x) reinterpret_cast<void*>(x)
71 71
72 const char* GetShaderSource(vr_shell::ShaderID shader) { 72 const char* GetShaderSource(vr_shell::ShaderID shader) {
73 switch (shader) { 73 switch (shader) {
74 case vr_shell::ShaderID::TEXTURE_QUAD_VERTEX_SHADER: 74 case vr_shell::ShaderID::TEXTURE_QUAD_VERTEX_SHADER:
75 case vr_shell::ShaderID::RETICLE_VERTEX_SHADER: 75 case vr_shell::ShaderID::RETICLE_VERTEX_SHADER:
76 case vr_shell::ShaderID::LASER_VERTEX_SHADER: 76 case vr_shell::ShaderID::LASER_VERTEX_SHADER:
77 case vr_shell::ShaderID::CONTROLLER_VERTEX_SHADER: 77 case vr_shell::ShaderID::CONTROLLER_VERTEX_SHADER:
78 return SHADER( 78 return SHADER(
79 /* clang-format off */ 79 /* clang-format off */
80 precision mediump float;
80 uniform mat4 u_ModelViewProjMatrix; 81 uniform mat4 u_ModelViewProjMatrix;
81 attribute vec4 a_Position; 82 attribute vec4 a_Position;
82 attribute vec2 a_TexCoordinate; 83 attribute vec2 a_TexCoordinate;
83 varying vec2 v_TexCoordinate; 84 varying vec2 v_TexCoordinate;
84 85
85 void main() { 86 void main() {
86 v_TexCoordinate = a_TexCoordinate; 87 v_TexCoordinate = a_TexCoordinate;
87 gl_Position = u_ModelViewProjMatrix * a_Position; 88 gl_Position = u_ModelViewProjMatrix * a_Position;
88 } 89 }
89 /* clang-format on */); 90 /* clang-format on */);
90 case vr_shell::ShaderID::GRADIENT_QUAD_VERTEX_SHADER: 91 case vr_shell::ShaderID::GRADIENT_QUAD_VERTEX_SHADER:
91 case vr_shell::ShaderID::GRADIENT_GRID_VERTEX_SHADER: 92 case vr_shell::ShaderID::GRADIENT_GRID_VERTEX_SHADER:
92 return SHADER( 93 return SHADER(
93 /* clang-format off */ 94 /* clang-format off */
95 precision mediump float;
94 uniform mat4 u_ModelViewProjMatrix; 96 uniform mat4 u_ModelViewProjMatrix;
95 uniform float u_SceneRadius; 97 uniform float u_SceneRadius;
96 attribute vec4 a_Position; 98 attribute vec4 a_Position;
97 varying vec2 v_GridPosition; 99 varying vec2 v_GridPosition;
98 100
99 void main() { 101 void main() {
100 v_GridPosition = a_Position.xy / u_SceneRadius; 102 v_GridPosition = a_Position.xy / u_SceneRadius;
101 gl_Position = u_ModelViewProjMatrix * a_Position; 103 gl_Position = u_ModelViewProjMatrix * a_Position;
102 } 104 }
103 /* clang-format on */); 105 /* clang-format on */);
(...skipping 11 matching lines...) Expand all
115 vec2 scaledTex = 117 vec2 scaledTex =
116 vec2(u_CopyRect[0] + v_TexCoordinate.x * u_CopyRect[2], 118 vec2(u_CopyRect[0] + v_TexCoordinate.x * u_CopyRect[2],
117 u_CopyRect[1] + v_TexCoordinate.y * u_CopyRect[3]); 119 u_CopyRect[1] + v_TexCoordinate.y * u_CopyRect[3]);
118 lowp vec4 color = texture2D(u_Texture, scaledTex); 120 lowp vec4 color = texture2D(u_Texture, scaledTex);
119 gl_FragColor = vec4(color.xyz, color.w * opacity); 121 gl_FragColor = vec4(color.xyz, color.w * opacity);
120 } 122 }
121 /* clang-format on */); 123 /* clang-format on */);
122 case vr_shell::ShaderID::WEBVR_VERTEX_SHADER: 124 case vr_shell::ShaderID::WEBVR_VERTEX_SHADER:
123 return SHADER( 125 return SHADER(
124 /* clang-format off */ 126 /* clang-format off */
127 precision mediump float;
125 attribute vec3 a_Position; 128 attribute vec3 a_Position;
126 attribute vec2 a_TexCoordinate; 129 attribute vec2 a_TexCoordinate;
127 varying vec2 v_TexCoordinate; 130 varying highp vec2 v_TexCoordinate;
128 131
129 void main() { 132 void main() {
130 v_TexCoordinate = a_TexCoordinate; 133 v_TexCoordinate = a_TexCoordinate;
131 gl_Position = vec4(a_Position * 2.0, 1.0); 134 gl_Position = vec4(a_Position * 2.0, 1.0);
132 } 135 }
133 /* clang-format on */); 136 /* clang-format on */);
134 case vr_shell::ShaderID::WEBVR_FRAGMENT_SHADER: 137 case vr_shell::ShaderID::WEBVR_FRAGMENT_SHADER:
135 return OEIE_SHADER( 138 return OEIE_SHADER(
136 /* clang-format off */ 139 /* clang-format off */
137 precision highp float; 140 precision highp float;
138 uniform samplerExternalOES u_Texture; 141 uniform samplerExternalOES u_Texture;
139 varying vec2 v_TexCoordinate; 142 varying vec2 v_TexCoordinate;
140 143
141 void main() { 144 void main() {
142 gl_FragColor = texture2D(u_Texture, v_TexCoordinate); 145 gl_FragColor = texture2D(u_Texture, v_TexCoordinate);
143 } 146 }
144 /* clang-format on */); 147 /* clang-format on */);
145 case vr_shell::ShaderID::RETICLE_FRAGMENT_SHADER: 148 case vr_shell::ShaderID::RETICLE_FRAGMENT_SHADER:
146 return SHADER( 149 return SHADER(
147 /* clang-format off */ 150 /* clang-format off */
151 precision mediump float;
148 varying mediump vec2 v_TexCoordinate; 152 varying mediump vec2 v_TexCoordinate;
149 uniform lowp vec4 color; 153 uniform lowp vec4 color;
150 uniform mediump float ring_diameter; 154 uniform mediump float ring_diameter;
151 uniform mediump float inner_hole; 155 uniform mediump float inner_hole;
152 uniform mediump float inner_ring_end; 156 uniform mediump float inner_ring_end;
153 uniform mediump float inner_ring_thickness; 157 uniform mediump float inner_ring_thickness;
154 uniform mediump float mid_ring_end; 158 uniform mediump float mid_ring_end;
155 uniform mediump float mid_ring_opacity; 159 uniform mediump float mid_ring_opacity;
156 160
157 void main() { 161 void main() {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 void main() { 215 void main() {
212 float edgeColorWeight = clamp(length(v_GridPosition), 0.0, 1.0); 216 float edgeColorWeight = clamp(length(v_GridPosition), 0.0, 1.0);
213 float centerColorWeight = 1.0 - edgeColorWeight; 217 float centerColorWeight = 1.0 - edgeColorWeight;
214 gl_FragColor = (u_CenterColor * centerColorWeight + 218 gl_FragColor = (u_CenterColor * centerColorWeight +
215 u_EdgeColor * edgeColorWeight) * vec4(1.0, 1.0, 1.0, u_Opacity); 219 u_EdgeColor * edgeColorWeight) * vec4(1.0, 1.0, 1.0, u_Opacity);
216 } 220 }
217 /* clang-format on */); 221 /* clang-format on */);
218 case vr_shell::ShaderID::CONTROLLER_FRAGMENT_SHADER: 222 case vr_shell::ShaderID::CONTROLLER_FRAGMENT_SHADER:
219 return SHADER( 223 return SHADER(
220 /* clang-format off */ 224 /* clang-format off */
225 precision mediump float;
221 uniform sampler2D u_texture; 226 uniform sampler2D u_texture;
222 varying vec2 v_TexCoordinate; 227 varying vec2 v_TexCoordinate;
223 228
224 void main() { 229 void main() {
225 gl_FragColor = texture2D(u_texture, v_TexCoordinate); 230 gl_FragColor = texture2D(u_texture, v_TexCoordinate);
226 } 231 }
227 /* clang-format on */); 232 /* clang-format on */);
228 default: 233 default:
229 LOG(ERROR) << "Shader source requested for unknown shader"; 234 LOG(ERROR) << "Shader source requested for unknown shader";
230 return ""; 235 return "";
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after
735 laser_renderer_(base::MakeUnique<LaserRenderer>()), 740 laser_renderer_(base::MakeUnique<LaserRenderer>()),
736 controller_renderer_(base::MakeUnique<ControllerRenderer>()), 741 controller_renderer_(base::MakeUnique<ControllerRenderer>()),
737 gradient_quad_renderer_(base::MakeUnique<GradientQuadRenderer>()), 742 gradient_quad_renderer_(base::MakeUnique<GradientQuadRenderer>()),
738 gradient_grid_renderer_(base::MakeUnique<GradientGridRenderer>()) { 743 gradient_grid_renderer_(base::MakeUnique<GradientGridRenderer>()) {
739 BaseQuadRenderer::SetVertexBuffer(); 744 BaseQuadRenderer::SetVertexBuffer();
740 } 745 }
741 746
742 VrShellRenderer::~VrShellRenderer() = default; 747 VrShellRenderer::~VrShellRenderer() = default;
743 748
744 } // namespace vr_shell 749 } // namespace vr_shell
OLDNEW
« no previous file with comments | « chrome/browser/android/vr_shell/mailbox_to_surface_bridge.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698