nir: Rename is_arb_asm to use_legacy_math_rules and document its meaning.

On iris and crocus, this flag is used to set "alt mode" math on the shader
as a whole.  Some other drivers have a similar mode for DX9/ARB-program
behavior, so document what it does so we can start using it.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16176>
This commit is contained in:
Emma Anholt 2022-04-26 11:58:14 -07:00 committed by Marge Bot
parent 0d90b168d8
commit cf265c6606
7 changed files with 30 additions and 11 deletions

View File

@ -102,7 +102,7 @@ init_gl_program(struct gl_program *prog, bool is_arb_asm, gl_shader_stage stage)
{
prog->RefCount = 1;
prog->Format = GL_PROGRAM_FORMAT_ASCII_ARB;
prog->info.is_arb_asm = is_arb_asm;
prog->info.use_legacy_math_rules = is_arb_asm;
prog->info.stage = stage;
}

View File

@ -310,9 +310,28 @@ typedef struct shader_info {
bool workgroup_size_variable:1;
/**
* Is this an ARB assembly-style program.
* Set if this shader uses legacy (DX9 or ARB assembly) math rules.
*
* From the ARB_fragment_program specification:
*
* "The following rules apply to multiplication:
*
* 1. <x> * <y> == <y> * <x>, for all <x> and <y>.
* 2. +/-0.0 * <x> = +/-0.0, at least for all <x> that correspond to
* *representable numbers (IEEE "not a number" and "infinity"
* *encodings may be exceptions).
* 3. +1.0 * <x> = <x>, for all <x>.""
*
* However, in effect this was due to DX9 semantics implying that 0*x=0 even
* for inf/nan if the hardware generated them instead of float_min/max. So,
* you should not have an exception for inf/nan to rule 2 above.
*
* One implementation of this behavior would be to flush all generated NaNs
* to zero, at which point 0*Inf=Nan=0. Most DX9/ARB-asm hardware did not
* generate NaNs, and the only way the GPU saw one was to possibly feed it
* in as a uniform.
*/
bool is_arb_asm;
bool use_legacy_math_rules;
union {
struct {

View File

@ -1208,7 +1208,7 @@ crocus_compile_vs(struct crocus_context *ice,
if (key->clamp_pointsize)
nir_lower_point_size(nir, 1.0, 255.0);
prog_data->use_alt_mode = nir->info.is_arb_asm;
prog_data->use_alt_mode = nir->info.use_legacy_math_rules;
crocus_setup_uniforms(compiler, mem_ctx, nir, prog_data, &system_values,
&num_system_values, &num_cbufs);
@ -1858,7 +1858,7 @@ crocus_compile_fs(struct crocus_context *ice,
nir_shader *nir = nir_shader_clone(mem_ctx, ish->nir);
prog_data->use_alt_mode = nir->info.is_arb_asm;
prog_data->use_alt_mode = nir->info.use_legacy_math_rules;
crocus_setup_uniforms(compiler, mem_ctx, nir, prog_data, &system_values,
&num_system_values, &num_cbufs);

View File

@ -1335,7 +1335,7 @@ iris_compile_vs(struct iris_screen *screen,
nir_shader_gather_info(nir, impl);
}
prog_data->use_alt_mode = nir->info.is_arb_asm;
prog_data->use_alt_mode = nir->info.use_legacy_math_rules;
iris_setup_uniforms(compiler, mem_ctx, nir, prog_data, 0, &system_values,
&num_system_values, &num_cbufs);
@ -1967,7 +1967,7 @@ iris_compile_fs(struct iris_screen *screen,
nir_shader *nir = nir_shader_clone(mem_ctx, ish->nir);
const struct iris_fs_prog_key *const key = &shader->key.fs;
prog_data->use_alt_mode = nir->info.is_arb_asm;
prog_data->use_alt_mode = nir->info.use_legacy_math_rules;
iris_setup_uniforms(compiler, mem_ctx, nir, prog_data, 0, &system_values,
&num_system_values, &num_cbufs);

View File

@ -273,7 +273,7 @@ static void si_lower_nir(struct si_screen *sscreen, struct nir_shader *nir)
NIR_PASS_V(nir, nir_lower_discard_or_demote,
(sscreen->debug_flags & DBG(FS_CORRECT_DERIVS_AFTER_KILL)) ||
nir->info.is_arb_asm);
nir->info.use_legacy_math_rules);
/* Lower load constants to scalar and then clean up the mess */
NIR_PASS_V(nir, nir_lower_load_const_to_scalar);

View File

@ -956,7 +956,7 @@ associate_uniform_storage(struct gl_context *ctx,
unsigned columns = 0;
int dmul;
if (ctx->Const.PackedDriverUniformStorage && !prog->info.is_arb_asm) {
if (ctx->Const.PackedDriverUniformStorage && !prog->info.use_legacy_math_rules) {
dmul = storage->type->vector_elements * sizeof(float);
} else {
dmul = 4 * sizeof(float);
@ -1050,7 +1050,7 @@ associate_uniform_storage(struct gl_context *ctx,
* initializers in the source code to be copied over.
*/
unsigned array_elements = MAX2(1, storage->array_elements);
if (ctx->Const.PackedDriverUniformStorage && !prog->info.is_arb_asm &&
if (ctx->Const.PackedDriverUniformStorage && !prog->info.use_legacy_math_rules &&
(storage->is_bindless || !storage->type->contains_opaque())) {
const int dmul = storage->type->is_64bit() ? 2 : 1;
const unsigned components =

View File

@ -196,7 +196,7 @@ _mesa_init_gl_program(struct gl_program *prog, gl_shader_stage stage,
prog->RefCount = 1;
prog->Format = GL_PROGRAM_FORMAT_ASCII_ARB;
prog->info.stage = stage;
prog->info.is_arb_asm = is_arb_asm;
prog->info.use_legacy_math_rules = is_arb_asm;
/* Uniforms that lack an initializer in the shader code have an initial
* value of zero. This includes sampler uniforms.