mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-06 11:38:05 +02:00
r300: transform vs sin and cos input to [-PI,PI] range in NIR
The python generator is mostly copy-pasted from lima. Reviewed-by: Emma Anholt <emma@anholt.net> Reviewed-by: Dylan Baker <dylan@pnwbakers.com> 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
1109381e0e
commit
3f97306b95
7 changed files with 80 additions and 2 deletions
54
src/gallium/drivers/r300/compiler/r300_nir_algebraic.py
Normal file
54
src/gallium/drivers/r300/compiler/r300_nir_algebraic.py
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
#
|
||||
# Copyright (C) 2019 Vasily Khoruzhick <anarsoul@gmail.com>
|
||||
# Copyright (C) 2021 Pavel Ondračka
|
||||
#
|
||||
# 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.
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
from math import pi
|
||||
|
||||
# Transform input to range [-PI, PI]:
|
||||
#
|
||||
# y = frac(x / 2PI + 0.5) * 2PI - PI
|
||||
#
|
||||
transform_trig_input_vs_r500 = [
|
||||
(('fsin', 'a'), ('fsin', ('fadd', ('fmul', ('ffract', ('fadd', ('fmul', 'a', 1 / (2 * pi)) , 0.5)), 2 * pi), -pi))),
|
||||
(('fcos', 'a'), ('fcos', ('fadd', ('fmul', ('ffract', ('fadd', ('fmul', 'a', 1 / (2 * pi)) , 0.5)), 2 * pi), -pi))),
|
||||
]
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('-p', '--import-path', required=True)
|
||||
parser.add_argument('output')
|
||||
args = parser.parse_args()
|
||||
sys.path.insert(0, args.import_path)
|
||||
|
||||
import nir_algebraic # pylint: disable=import-error
|
||||
|
||||
with open(args.output, 'w') as f:
|
||||
f.write('#include "r300_vs.h"')
|
||||
|
||||
f.write(nir_algebraic.AlgebraicPass("r300_transform_vs_trig_input",
|
||||
transform_trig_input_vs_r500).render())
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
@ -55,6 +55,7 @@ struct radeon_compiler {
|
|||
unsigned has_presub:1;
|
||||
unsigned has_omod:1;
|
||||
unsigned disable_optimizations:1;
|
||||
unsigned needs_trig_input_transform:1;
|
||||
unsigned max_temp_regs;
|
||||
unsigned max_constants;
|
||||
int max_alu_insts;
|
||||
|
|
|
|||
|
|
@ -1055,6 +1055,9 @@ int r300_transform_trig_scale_vertex(struct radeon_compiler *c,
|
|||
inst->U.I.Opcode != RC_OPCODE_SIN)
|
||||
return 0;
|
||||
|
||||
if (!c->needs_trig_input_transform)
|
||||
return 1;
|
||||
|
||||
/* Repeat x in the range [-PI, PI]:
|
||||
*
|
||||
* repeat(x) = frac(x / 2PI + 0.5) * 2PI - PI
|
||||
|
|
|
|||
|
|
@ -118,9 +118,21 @@ files_r300 = files(
|
|||
'compiler/radeon_vert_fc.c',
|
||||
)
|
||||
|
||||
r300_nir_algebraic_c = custom_target(
|
||||
'r300_nir_algebraic.c',
|
||||
input : 'compiler/r300_nir_algebraic.py',
|
||||
output : 'r300_nir_algebraic.c',
|
||||
command : [
|
||||
prog_python, '@INPUT@',
|
||||
'-p', join_paths(meson.source_root(), 'src/compiler/nir/'),
|
||||
'@OUTPUT@',
|
||||
],
|
||||
depend_files : nir_algebraic_py,
|
||||
)
|
||||
|
||||
libr300 = static_library(
|
||||
'r300',
|
||||
files_r300,
|
||||
files_r300, r300_nir_algebraic_c,
|
||||
include_directories : [
|
||||
inc_src, inc_include, inc_gallium, inc_gallium_aux, inc_gallium_drivers,
|
||||
inc_mesa,
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@
|
|||
#include "r300_fs.h"
|
||||
#include "r300_texture.h"
|
||||
#include "r300_vs.h"
|
||||
#include "nir.h"
|
||||
#include "nir/nir_to_tgsi.h"
|
||||
|
||||
/* r300_state: Functions used to initialize state context by translating
|
||||
|
|
@ -1953,8 +1954,10 @@ static void* r300_create_vs_state(struct pipe_context* pipe,
|
|||
};
|
||||
const struct nir_to_tgsi_options *ntt_options;
|
||||
if (r300->screen->caps.has_tcl) {
|
||||
if (r300->screen->caps.is_r500)
|
||||
if (r300->screen->caps.is_r500) {
|
||||
ntt_options = &hwtcl_r500_options;
|
||||
NIR_PASS_V(shader->ir.nir, r300_transform_vs_trig_input);
|
||||
}
|
||||
else
|
||||
ntt_options = &hwtcl_r300_options;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -223,6 +223,7 @@ void r300_translate_vertex_shader(struct r300_context *r300,
|
|||
compiler.Base.has_half_swizzles = FALSE;
|
||||
compiler.Base.has_presub = FALSE;
|
||||
compiler.Base.has_omod = FALSE;
|
||||
compiler.Base.needs_trig_input_transform = DBG_ON(r300, DBG_USE_TGSI);
|
||||
compiler.Base.max_temp_regs = 32;
|
||||
compiler.Base.max_constants = 256;
|
||||
compiler.Base.max_alu_insts = r300->screen->caps.is_r500 ? 1024 : 256;
|
||||
|
|
|
|||
|
|
@ -56,6 +56,8 @@ struct r300_vertex_shader {
|
|||
void *draw_vs;
|
||||
};
|
||||
|
||||
struct nir_shader;
|
||||
|
||||
void r300_init_vs_outputs(struct r300_context *r300,
|
||||
struct r300_vertex_shader *vs);
|
||||
|
||||
|
|
@ -65,4 +67,6 @@ 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);
|
||||
|
||||
#endif /* R300_VS_H */
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue