Fix a lot of redundant code when loading flattened composites.

This commit is contained in:
Hans-Kristian Arntzen 2018-07-06 10:57:23 +02:00
Родитель 0f59016635
Коммит e1367e609a
8 изменённых файлов: 66 добавлений и 12 удалений

Просмотреть файл

@ -18,8 +18,9 @@ void main()
vColor = vec4(0.0);
for (int _96 = 0; _96 < 4; )
{
vec3 _68 = aVertex.xyz - Light(UBO[_96 * 2 + 4].xyz, UBO[_96 * 2 + 4].w, UBO[_96 * 2 + 5]).Position;
vColor += ((UBO[_96 * 2 + 5] * clamp(1.0 - (length(_68) / Light(UBO[_96 * 2 + 4].xyz, UBO[_96 * 2 + 4].w, UBO[_96 * 2 + 5]).Radius), 0.0, 1.0)) * dot(aNormal, normalize(_68)));
Light _52 = Light(UBO[_96 * 2 + 4].xyz, UBO[_96 * 2 + 4].w, UBO[_96 * 2 + 5]);
vec3 _68 = aVertex.xyz - _52.Position;
vColor += ((UBO[_96 * 2 + 5] * clamp(1.0 - (length(_68) / _52.Radius), 0.0, 1.0)) * dot(aNormal, normalize(_68)));
_96++;
continue;
}

Просмотреть файл

@ -0,0 +1,14 @@
#version 310 es
precision mediump float;
precision highp int;
uniform vec4 UBO[4];
layout(location = 0) out vec3 FragColor;
layout(location = 0) flat in vec3 vNormal;
void main()
{
mat4 _19 = mat4(UBO[0], UBO[1], UBO[2], UBO[3]);
FragColor = mat3(vec3(_19[0].x, _19[0].y, _19[0].z), vec3(_19[1].x, _19[1].y, _19[1].z), vec3(_19[2].x, _19[2].y, _19[2].z)) * vNormal;
}

Просмотреть файл

@ -14,7 +14,8 @@ layout(location = 1) out vec3 V1;
void main()
{
V0 = v0 * Foo(transpose(mat4x3(UBO[0].xyz, UBO[1].xyz, UBO[2].xyz, UBO[3].xyz)), transpose(mat4x3(UBO[4].xyz, UBO[5].xyz, UBO[6].xyz, UBO[7].xyz))).MVP0;
V1 = v1 * Foo(transpose(mat4x3(UBO[0].xyz, UBO[1].xyz, UBO[2].xyz, UBO[3].xyz)), transpose(mat4x3(UBO[4].xyz, UBO[5].xyz, UBO[6].xyz, UBO[7].xyz))).MVP1;
Foo _20 = Foo(transpose(mat4x3(UBO[0].xyz, UBO[1].xyz, UBO[2].xyz, UBO[3].xyz)), transpose(mat4x3(UBO[4].xyz, UBO[5].xyz, UBO[6].xyz, UBO[7].xyz)));
V0 = v0 * _20.MVP0;
V1 = v1 * _20.MVP1;
}

Просмотреть файл

@ -18,10 +18,11 @@ void main()
vColor = vec4(0.0);
for (int i = 0; i < 4; i++)
{
Light _52 = Light(UBO[i * 2 + 4].xyz, UBO[i * 2 + 4].w, UBO[i * 2 + 5]);
Light light;
light.Position = Light(UBO[i * 2 + 4].xyz, UBO[i * 2 + 4].w, UBO[i * 2 + 5]).Position;
light.Radius = Light(UBO[i * 2 + 4].xyz, UBO[i * 2 + 4].w, UBO[i * 2 + 5]).Radius;
light.Color = Light(UBO[i * 2 + 4].xyz, UBO[i * 2 + 4].w, UBO[i * 2 + 5]).Color;
light.Position = _52.Position;
light.Radius = _52.Radius;
light.Color = _52.Color;
vec3 L = aVertex.xyz - light.Position;
vColor += ((UBO[i * 2 + 5] * clamp(1.0 - (length(L) / light.Radius), 0.0, 1.0)) * dot(aNormal, normalize(L)));
}

Просмотреть файл

@ -0,0 +1,14 @@
#version 310 es
precision mediump float;
precision highp int;
uniform vec4 UBO[4];
layout(location = 0) out vec3 FragColor;
layout(location = 0) flat in vec3 vNormal;
void main()
{
mat4 _19 = mat4(UBO[0], UBO[1], UBO[2], UBO[3]);
FragColor = mat3(vec3(_19[0].x, _19[0].y, _19[0].z), vec3(_19[1].x, _19[1].y, _19[1].z), vec3(_19[2].x, _19[2].y, _19[2].z)) * vNormal;
}

Просмотреть файл

@ -14,9 +14,10 @@ layout(location = 1) out vec3 V1;
void main()
{
Foo _20 = Foo(transpose(mat4x3(UBO[0].xyz, UBO[1].xyz, UBO[2].xyz, UBO[3].xyz)), transpose(mat4x3(UBO[4].xyz, UBO[5].xyz, UBO[6].xyz, UBO[7].xyz)));
Foo f;
f.MVP0 = Foo(transpose(mat4x3(UBO[0].xyz, UBO[1].xyz, UBO[2].xyz, UBO[3].xyz)), transpose(mat4x3(UBO[4].xyz, UBO[5].xyz, UBO[6].xyz, UBO[7].xyz))).MVP0;
f.MVP1 = Foo(transpose(mat4x3(UBO[0].xyz, UBO[1].xyz, UBO[2].xyz, UBO[3].xyz)), transpose(mat4x3(UBO[4].xyz, UBO[5].xyz, UBO[6].xyz, UBO[7].xyz))).MVP1;
f.MVP0 = _20.MVP0;
f.MVP1 = _20.MVP1;
vec3 a = v0 * f.MVP0;
vec3 b = v1 * f.MVP1;
V0 = a;

Просмотреть файл

@ -0,0 +1,14 @@
#version 310 es
precision mediump float;
layout(location = 0) out vec3 FragColor;
layout(location = 0) flat in vec3 vNormal;
layout(binding = 0, std140) uniform UBO
{
mat4 m;
};
void main()
{
FragColor = mat3(m) * vNormal;
}

Просмотреть файл

@ -6147,8 +6147,14 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
if (ptr_expression)
ptr_expression->need_transpose = old_need_transpose;
// Suppress usage tracking since using same expression multiple times does not imply any extra work.
auto &e = emit_op(result_type, id, expr, forward, true);
// By default, suppress usage tracking since using same expressio multiple times does not imply any extra work.
// However, if we try to load a complex, composite object from a flattened buffer,
// we should avoid emitting the same code over and over and lower the result to a temporary.
auto &type = get<SPIRType>(result_type);
bool usage_tracking = ptr_expression && flattened_buffer_blocks.count(ptr_expression->loaded_from) != 0 &&
(type.basetype == SPIRType::Struct || (type.columns > 1));
auto &e = emit_op(result_type, id, expr, forward, !usage_tracking);
e.need_transpose = need_transpose;
register_read(id, ptr, forward);
@ -6168,8 +6174,10 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
// If the base is immutable, the access chain pointer must also be.
// If an expression is mutable and forwardable, we speculate that it is immutable.
bool need_transpose, result_is_packed;
bool need_transpose = false;
bool result_is_packed = false;
auto e = access_chain(ops[2], &ops[3], length - 3, get<SPIRType>(ops[0]), &need_transpose, &result_is_packed);
auto &expr = set<SPIRExpression>(ops[1], move(e), ops[0], should_forward(ops[2]));
auto *backing_variable = maybe_get_backing_variable(ops[2]);