Fix a lot of redundant code when loading flattened composites.
This commit is contained in:
parent
0f59016635
commit
e1367e609a
@ -18,8 +18,9 @@ void main()
|
|||||||
vColor = vec4(0.0);
|
vColor = vec4(0.0);
|
||||||
for (int _96 = 0; _96 < 4; )
|
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;
|
Light _52 = Light(UBO[_96 * 2 + 4].xyz, UBO[_96 * 2 + 4].w, UBO[_96 * 2 + 5]);
|
||||||
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)));
|
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++;
|
_96++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
14
reference/opt/shaders/flatten/matrix-conversion.flatten.frag
Normal file
14
reference/opt/shaders/flatten/matrix-conversion.flatten.frag
Normal file
@ -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()
|
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;
|
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)));
|
||||||
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;
|
V0 = v0 * _20.MVP0;
|
||||||
|
V1 = v1 * _20.MVP1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,10 +18,11 @@ void main()
|
|||||||
vColor = vec4(0.0);
|
vColor = vec4(0.0);
|
||||||
for (int i = 0; i < 4; i++)
|
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 light;
|
||||||
light.Position = Light(UBO[i * 2 + 4].xyz, UBO[i * 2 + 4].w, UBO[i * 2 + 5]).Position;
|
light.Position = _52.Position;
|
||||||
light.Radius = Light(UBO[i * 2 + 4].xyz, UBO[i * 2 + 4].w, UBO[i * 2 + 5]).Radius;
|
light.Radius = _52.Radius;
|
||||||
light.Color = Light(UBO[i * 2 + 4].xyz, UBO[i * 2 + 4].w, UBO[i * 2 + 5]).Color;
|
light.Color = _52.Color;
|
||||||
vec3 L = aVertex.xyz - light.Position;
|
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)));
|
vColor += ((UBO[i * 2 + 5] * clamp(1.0 - (length(L) / light.Radius), 0.0, 1.0)) * dot(aNormal, normalize(L)));
|
||||||
}
|
}
|
||||||
|
14
reference/shaders/flatten/matrix-conversion.flatten.frag
Normal file
14
reference/shaders/flatten/matrix-conversion.flatten.frag
Normal file
@ -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()
|
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;
|
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.MVP0 = _20.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.MVP1 = _20.MVP1;
|
||||||
vec3 a = v0 * f.MVP0;
|
vec3 a = v0 * f.MVP0;
|
||||||
vec3 b = v1 * f.MVP1;
|
vec3 b = v1 * f.MVP1;
|
||||||
V0 = a;
|
V0 = a;
|
||||||
|
14
shaders/flatten/matrix-conversion.flatten.frag
Normal file
14
shaders/flatten/matrix-conversion.flatten.frag
Normal file
@ -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)
|
if (ptr_expression)
|
||||||
ptr_expression->need_transpose = old_need_transpose;
|
ptr_expression->need_transpose = old_need_transpose;
|
||||||
|
|
||||||
// Suppress usage tracking since using same expression multiple times does not imply any extra work.
|
// By default, suppress usage tracking since using same expressio multiple times does not imply any extra work.
|
||||||
auto &e = emit_op(result_type, id, expr, forward, true);
|
// 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;
|
e.need_transpose = need_transpose;
|
||||||
register_read(id, ptr, forward);
|
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 the base is immutable, the access chain pointer must also be.
|
||||||
// If an expression is mutable and forwardable, we speculate that it is immutable.
|
// 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 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 &expr = set<SPIRExpression>(ops[1], move(e), ops[0], should_forward(ops[2]));
|
||||||
|
|
||||||
auto *backing_variable = maybe_get_backing_variable(ops[2]);
|
auto *backing_variable = maybe_get_backing_variable(ops[2]);
|
||||||
|
Loading…
Reference in New Issue
Block a user