mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-24 00:10:10 +01:00
r300: transform fs sin and cos input to [0,1) range in NIR
shader-db stats with RV530 (together with the vs commit): total instructions in shared programs: 65194 -> 64721 (-0.73%) instructions in affected programs: 6718 -> 6245 (-7.04%) total consts in shared programs: 45363 -> 45353 (-0.02%) consts in affected programs: 466 -> 456 (-2.15%) Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/5982 Reviewed-by: Emma Anholt <emma@anholt.net> Signed-off-by: Pavel Ondračka <pavel.ondracka@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14957>
This commit is contained in:
parent
3f97306b95
commit
a04aa4bc08
5 changed files with 21 additions and 1 deletions
|
|
@ -34,6 +34,15 @@ transform_trig_input_vs_r500 = [
|
|||
(('fcos', 'a'), ('fcos', ('fadd', ('fmul', ('ffract', ('fadd', ('fmul', 'a', 1 / (2 * pi)) , 0.5)), 2 * pi), -pi))),
|
||||
]
|
||||
|
||||
# Transform input to range [-PI, PI]:
|
||||
#
|
||||
# y = frac(x / 2PI)
|
||||
#
|
||||
transform_trig_input_fs_r500 = [
|
||||
(('fsin', 'a'), ('fsin', ('ffract', ('fmul', 'a', 1 / (2 * pi))))),
|
||||
(('fcos', 'a'), ('fcos', ('ffract', ('fmul', 'a', 1 / (2 * pi))))),
|
||||
]
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('-p', '--import-path', required=True)
|
||||
|
|
@ -49,6 +58,9 @@ def main():
|
|||
f.write(nir_algebraic.AlgebraicPass("r300_transform_vs_trig_input",
|
||||
transform_trig_input_vs_r500).render())
|
||||
|
||||
f.write(nir_algebraic.AlgebraicPass("r300_transform_fs_trig_input",
|
||||
transform_trig_input_fs_r500).render())
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
|||
|
|
@ -1026,6 +1026,9 @@ int radeonTransformTrigScale(struct radeon_compiler* c,
|
|||
inst->U.I.Opcode != RC_OPCODE_SIN)
|
||||
return 0;
|
||||
|
||||
if (!c->needs_trig_input_transform)
|
||||
return 1;
|
||||
|
||||
temp = rc_find_free_temporary(c);
|
||||
constant = rc_constants_add_immediate_scalar(&c->Program.Constants, RCP_2PI, &constant_swizzle);
|
||||
|
||||
|
|
|
|||
|
|
@ -440,6 +440,7 @@ static void r300_translate_fragment_shader(
|
|||
compiler.Base.has_half_swizzles = TRUE;
|
||||
compiler.Base.has_presub = TRUE;
|
||||
compiler.Base.has_omod = TRUE;
|
||||
compiler.Base.needs_trig_input_transform = DBG_ON(r300, DBG_USE_TGSI);
|
||||
compiler.Base.max_temp_regs =
|
||||
compiler.Base.is_r500 ? 128 : (compiler.Base.is_r400 ? 64 : 32);
|
||||
compiler.Base.max_constants = compiler.Base.is_r500 ? 256 : 32;
|
||||
|
|
|
|||
|
|
@ -1045,6 +1045,8 @@ static void* r300_create_fs_state(struct pipe_context* pipe,
|
|||
fs->state = *shader;
|
||||
|
||||
if (fs->state.type == PIPE_SHADER_IR_NIR) {
|
||||
if (r300->screen->caps.is_r500)
|
||||
NIR_PASS_V(shader->ir.nir, r300_transform_fs_trig_input);
|
||||
fs->state.tokens = nir_to_tgsi(shader->ir.nir, pipe->screen);
|
||||
} else {
|
||||
assert(fs->state.type == PIPE_SHADER_IR_TGSI);
|
||||
|
|
|
|||
|
|
@ -67,6 +67,8 @@ void r300_translate_vertex_shader(struct r300_context *r300,
|
|||
void r300_draw_init_vertex_shader(struct r300_context *r300,
|
||||
struct r300_vertex_shader *vs);
|
||||
|
||||
extern bool r300_transform_trig_input(struct nir_shader *shader);
|
||||
extern bool r300_transform_vs_trig_input(struct nir_shader *shader);
|
||||
|
||||
extern bool r300_transform_fs_trig_input(struct nir_shader *shader);
|
||||
|
||||
#endif /* R300_VS_H */
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue