GLSL: Fix round/roundEven for legacy GLSL.

This commit is contained in:
rdb 2020-11-06 17:34:38 +01:00
parent a20c768698
commit 9e6e5d2738
10 changed files with 126 additions and 3 deletions

View File

@ -0,0 +1,12 @@
#version 450
layout(location = 0) out vec4 FragColor;
layout(location = 0) in vec4 vA;
layout(location = 1) in float vB;
void main()
{
FragColor = roundEven(vA);
FragColor *= roundEven(vB);
}

View File

@ -0,0 +1,12 @@
#version 450
layout(location = 0) out vec4 FragColor;
layout(location = 0) in vec4 vA;
layout(location = 1) in float vB;
void main()
{
FragColor = round(vA);
FragColor *= round(vB);
}

View File

@ -0,0 +1,13 @@
#version 100
precision mediump float;
precision highp int;
varying highp vec4 vA;
varying highp float vB;
void main()
{
gl_FragData[0] = floor(vA + vec4(0.5));
gl_FragData[0] *= floor(vB + float(0.5));
}

View File

@ -0,0 +1,12 @@
#version 450
layout(location = 0) out vec4 FragColor;
layout(location = 0) in vec4 vA;
layout(location = 1) in float vB;
void main()
{
FragColor = roundEven(vA);
FragColor *= roundEven(vB);
}

View File

@ -0,0 +1,12 @@
#version 450
layout(location = 0) out vec4 FragColor;
layout(location = 0) in vec4 vA;
layout(location = 1) in float vB;
void main()
{
FragColor = round(vA);
FragColor *= round(vB);
}

View File

@ -0,0 +1,13 @@
#version 100
precision mediump float;
precision highp int;
varying highp vec4 vA;
varying highp float vB;
void main()
{
gl_FragData[0] = floor(vA + vec4(0.5));
gl_FragData[0] *= floor(vB + float(0.5));
}

View File

@ -0,0 +1,11 @@
#version 450
layout(location = 0) in vec4 vA;
layout(location = 1) in float vB;
layout(location = 0) out vec4 FragColor;
void main()
{
FragColor = roundEven(vA);
FragColor *= roundEven(vB);
}

11
shaders/frag/round.frag Normal file
View File

@ -0,0 +1,11 @@
#version 450
layout(location = 0) in vec4 vA;
layout(location = 1) in float vB;
layout(location = 0) out vec4 FragColor;
void main()
{
FragColor = round(vA);
FragColor *= round(vB);
}

View File

@ -0,0 +1,11 @@
#version 450
layout(location = 0) in vec4 vA;
layout(location = 1) in float vB;
layout(location = 0) out vec4 FragColor;
void main()
{
FragColor = round(vA);
FragColor *= round(vB);
}

View File

@ -6725,14 +6725,30 @@ void CompilerGLSL::emit_glsl_op(uint32_t result_type, uint32_t id, uint32_t eop,
{
// FP fiddling
case GLSLstd450Round:
emit_unary_func_op(result_type, id, args[0], "round");
if (!is_legacy())
emit_unary_func_op(result_type, id, args[0], "round");
else
{
auto op0 = to_enclosed_expression(args[0]);
auto &op0_type = expression_type(args[0]);
auto expr = join("floor(", op0, " + ", type_to_glsl_constructor(op0_type), "(0.5))");
bool forward = should_forward(args[0]);
emit_op(result_type, id, expr, forward);
inherit_expression_dependencies(id, args[0]);
}
break;
case GLSLstd450RoundEven:
if ((options.es && options.version >= 300) || (!options.es && options.version >= 130))
if (!is_legacy())
emit_unary_func_op(result_type, id, args[0], "roundEven");
else if (!options.es)
{
// This extension provides round() with round-to-even semantics.
require_extension_internal("GL_EXT_gpu_shader4");
emit_unary_func_op(result_type, id, args[0], "round");
}
else
SPIRV_CROSS_THROW("roundEven supported only in ESSL 300 and GLSL 130 and up.");
SPIRV_CROSS_THROW("roundEven supported only in ESSL 300.");
break;
case GLSLstd450Trunc: