mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-16 18:28:05 +02:00
So we can use it for Nvidia. Reviewed-by: Georg Lehmann <dadschoorse@gmail.com> Reviewed-by: Mel Henning <mhenning@darkrefraction.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/40541>
30 lines
811 B
C
30 lines
811 B
C
/*
|
|
* Copyright © 2021 Valve Corporation
|
|
*
|
|
* SPDX-License-Identifier: MIT
|
|
*/
|
|
|
|
#include "nir.h"
|
|
#include "nir_builder.h"
|
|
|
|
static bool
|
|
normalize_sin_cos(struct nir_builder *b, nir_alu_instr *sincos, UNUSED void *_)
|
|
{
|
|
if (sincos->op != nir_op_fsin && sincos->op != nir_op_fcos)
|
|
return false;
|
|
|
|
b->cursor = nir_before_instr(&sincos->instr);
|
|
b->fp_math_ctrl = sincos->fp_math_ctrl;
|
|
|
|
nir_def *src = nir_fmul_imm(b, nir_ssa_for_alu_src(b, sincos, 0), 0.15915493667125702);
|
|
nir_def *replace = sincos->op == nir_op_fsin ? nir_fsin_normalized_2_pi(b, src) : nir_fcos_normalized_2_pi(b, src);
|
|
nir_def_replace(&sincos->def, replace);
|
|
|
|
return true;
|
|
}
|
|
|
|
bool
|
|
nir_normalize_sin_cos(nir_shader *shader)
|
|
{
|
|
return nir_shader_alu_pass(shader, normalize_sin_cos, nir_metadata_control_flow, NULL);
|
|
}
|