Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metal: Vector compare will now translate correctly. #98

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/glsl/ir_print_metal_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,18 @@ void ir_print_metal_visitor::visit(ir_expression *ir)
}
else if (ir->get_num_operands() == 2)
{
if (ir->operands[0] && ir->operands[1] && ir->operands[0]->type->is_vector() && ir->operands[1]->type->is_vector())
{
if (ir->operation == ir_binop_all_equal)
{
buffer.asprintf_append ("all");
}
else if (ir->operation == ir_binop_any_nequal)
{
buffer.asprintf_append ("any");
}
}

buffer.asprintf_append ("(");
if (ir->operands[0])
{
Expand Down
28 changes: 28 additions & 0 deletions tests/vertex/bug-vector-compare-inES3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#version 300 es

// Metal translation was not producing required any/all
// for comparing vector operands using == or != (which
// GLSL does implicitly according to spec).

uniform highp float u_x;
uniform highp float u_y;
uniform highp vec4 u_u4;
uniform highp vec4 u_v4;

out highp vec3 xlv_out;

void main()
{
if ((u_x == u_y) || (u_u4 == u_v4))
{
xlv_out = vec3(0.0);
}
else if ((u_x != u_y) || (u_u4 != u_v4))
{
xlv_out = vec3(1.0);
}
else
{
xlv_out = vec3(2.0);
}
}
26 changes: 26 additions & 0 deletions tests/vertex/bug-vector-compare-outES3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#version 300 es
uniform highp float u_x;
uniform highp float u_y;
uniform highp vec4 u_u4;
uniform highp vec4 u_v4;
out highp vec3 xlv_out;
void main ()
{
if (((u_x == u_y) || (u_u4 == u_v4))) {
xlv_out = vec3(0.0, 0.0, 0.0);
} else {
if (((u_x != u_y) || (u_u4 != u_v4))) {
xlv_out = vec3(1.0, 1.0, 1.0);
} else {
xlv_out = vec3(2.0, 2.0, 2.0);
};
};
}


// stats: 9 alu 0 tex 2 flow
// uniforms: 4 (total size: 0)
// #0: u_x (high float) 1x1 [-1]
// #1: u_y (high float) 1x1 [-1]
// #2: u_u4 (high float) 4x1 [-1]
// #3: u_v4 (high float) 4x1 [-1]
35 changes: 35 additions & 0 deletions tests/vertex/bug-vector-compare-outES3Metal.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <metal_stdlib>
using namespace metal;
struct xlatMtlShaderInput {
};
struct xlatMtlShaderOutput {
float3 xlv_out;
};
struct xlatMtlShaderUniform {
float u_x;
float u_y;
float4 u_u4;
float4 u_v4;
};
vertex xlatMtlShaderOutput xlatMtlMain (xlatMtlShaderInput _mtl_i [[stage_in]], constant xlatMtlShaderUniform& _mtl_u [[buffer(0)]])
{
xlatMtlShaderOutput _mtl_o;
if (((_mtl_u.u_x == _mtl_u.u_y) || all(_mtl_u.u_u4 == _mtl_u.u_v4))) {
_mtl_o.xlv_out = float3(0.0, 0.0, 0.0);
} else {
if (((_mtl_u.u_x != _mtl_u.u_y) || any(_mtl_u.u_u4 != _mtl_u.u_v4))) {
_mtl_o.xlv_out = float3(1.0, 1.0, 1.0);
} else {
_mtl_o.xlv_out = float3(2.0, 2.0, 2.0);
};
};
return _mtl_o;
}


// stats: 9 alu 0 tex 2 flow
// uniforms: 4 (total size: 48)
// #0: u_x (high float) 1x1 [-1] loc 0
// #1: u_y (high float) 1x1 [-1] loc 4
// #2: u_u4 (high float) 4x1 [-1] loc 16
// #3: u_v4 (high float) 4x1 [-1] loc 32