From 2e5c64fb13d36fec25ed64bd145478ba08823b9d Mon Sep 17 00:00:00 2001 From: Ben Vanik Date: Mon, 18 Jan 2016 11:51:18 -0800 Subject: [PATCH] Prevent some divide by zeros in shaders. Thanks @vlj! Fixes #518. --- src/xenia/gpu/glsl_shader_translator.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/xenia/gpu/glsl_shader_translator.cc b/src/xenia/gpu/glsl_shader_translator.cc index 3a891316d..442547a9c 100644 --- a/src/xenia/gpu/glsl_shader_translator.cc +++ b/src/xenia/gpu/glsl_shader_translator.cc @@ -1256,7 +1256,8 @@ void GlslShaderTranslator::ProcessScalarAluInstruction( // rcp dest, src0.a case AluScalarOpcode::kRcp: - EmitSourceDepth("ps = 1.0 / src0.x;\n"); + // Prevent divide by zero. + EmitSourceDepth("ps = src0.x != 0.0 ? 1.0 / src0.x : 0.0;\n"); break; // rsqc dest, src0.a @@ -1273,7 +1274,8 @@ void GlslShaderTranslator::ProcessScalarAluInstruction( // rsq dest, src0.a case AluScalarOpcode::kRsq: - EmitSourceDepth("ps = inversesqrt(src0.x);\n"); + // Prevent divide by zero. + EmitSourceDepth("ps = src0.x != 0.0 ? inversesqrt(src0.x) : 0.0;\n"); break; // maxas dest, src0.ab