i915: Use the sin/cos lowering in nir_opt_algebraic.py

It's nearly identical.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15539>
This commit is contained in:
Jason Ekstrand 2022-03-23 17:42:46 -05:00 committed by Marge Bot
parent d0e99e566f
commit 729f95a110
5 changed files with 1 additions and 86 deletions

View File

@ -287,6 +287,4 @@ extern void i915_optimize_free(struct i915_token_list *tokens);
extern uint32_t i915_coord_mask(enum tgsi_opcode opcode, enum tgsi_texture_type tex);
extern bool i915_nir_lower_sincos(struct nir_shader *s);
#endif

View File

@ -1,81 +0,0 @@
/*
* Copyright © 2021 Emma Anholt
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#include "compiler/nir/nir.h"
#include "compiler/nir/nir_builder.h"
#include "i915_fpc.h"
static bool
i915_sincos_filter(const nir_instr *instr, const void *data)
{
if (instr->type != nir_instr_type_alu)
return false;
switch (nir_instr_as_alu(instr)->op) {
case nir_op_fcos:
case nir_op_fsin:
return true;
default:
return false;
}
}
/* Compute sin using a quadratic and quartic. It gives continuity
* that repeating the Taylor series lacks every 2*pi, and has
* reduced error.
*
* The idea was described at:
* https://web.archive.org/web/20100613230051/http://www.devmaster.net/forums/showthread.php?t=5784
*/
static nir_ssa_def *
i915_sincos_lower(nir_builder *b, nir_instr *instr, void *data)
{
nir_alu_instr *alu = nir_instr_as_alu(instr);
nir_ssa_def *x = nir_ssa_for_alu_src(b, alu, 0);
/* Reduce range from repeating about [-pi,pi] to [-1,1] */
x = nir_fmul_imm(b, x, M_1_PI / 2.0);
if (alu->op == nir_op_fsin)
x = nir_fadd_imm(b, x, 0.5);
else
x = nir_fadd_imm(b, x, 0.75);
x = nir_ffract(b, x);
x = nir_fadd_imm(b, nir_fmul_imm(b, x, 2.0), -1.0);
nir_ssa_def *x_absx = nir_fmul(b, x, nir_fabs(b, x));
/* y is the first approximation of the result. */
nir_ssa_def *y =
nir_fadd(b, nir_fmul_imm(b, x, 4.0), nir_fmul_imm(b, x_absx, -4.0));
/* improve the accuracy. */
nir_ssa_def *y_absy = nir_fmul(b, y, nir_fabs(b, y));
return nir_fadd(b, nir_fmul_imm(b, nir_fsub(b, y_absy, y), 0.225), y);
}
bool
i915_nir_lower_sincos(nir_shader *s)
{
return nir_shader_lower_instructions(s, i915_sincos_filter,
i915_sincos_lower, NULL);
}

View File

@ -116,6 +116,7 @@ static const nir_shader_compiler_options i915_compiler_options = {
.lower_flrp32 = true,
.lower_fmod = true,
.lower_rotate = true,
.lower_sincos = true,
.lower_uniforms_to_ubo = true,
.lower_vector_cmp = true,
.use_interpolated_input_intrinsics = true,

View File

@ -548,8 +548,6 @@ i915_create_fs_state(struct pipe_context *pipe,
if (templ->type == PIPE_SHADER_IR_NIR) {
nir_shader *s = templ->ir.nir;
NIR_PASS_V(s, i915_nir_lower_sincos);
static const struct nir_to_tgsi_options ntt_options = {
.lower_fabs = true,
};

View File

@ -35,7 +35,6 @@ files_i915 = files(
'i915_fpc.h',
'i915_fpc_optimize.c',
'i915_fpc_translate.c',
'i915_nir.c',
'i915_prim_emit.c',
'i915_prim_vbuf.c',
'i915_public.h',