st/mesa: Replace mesa_to_tgsi() with prog_to_nir() and nir_to_tgsi().

This introduces NIR optimizations to ARB programs in all gallium drivers,
while deleting code.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7927>
This commit is contained in:
Eric Anholt 2020-08-24 11:14:52 -07:00
parent e11513b740
commit cf3fc79cd0
7 changed files with 145 additions and 1253 deletions

View File

@ -544,8 +544,6 @@ STATETRACKER_FILES = \
state_tracker/st_glsl_to_tgsi_temprename.h \
state_tracker/st_manager.c \
state_tracker/st_manager.h \
state_tracker/st_mesa_to_tgsi.c \
state_tracker/st_mesa_to_tgsi.h \
state_tracker/st_nir.h \
state_tracker/st_nir_builtins.c \
state_tracker/st_nir_lower_builtin.c \

View File

@ -581,8 +581,6 @@ files_libmesa_gallium = files(
'state_tracker/st_glsl_to_tgsi_temprename.h',
'state_tracker/st_manager.c',
'state_tracker/st_manager.h',
'state_tracker/st_mesa_to_tgsi.c',
'state_tracker/st_mesa_to_tgsi.h',
'state_tracker/st_nir.h',
'state_tracker/st_nir_builtins.c',
'state_tracker/st_nir_lower_builtin.c',

View File

@ -43,7 +43,6 @@
#include "st_context.h"
#include "st_debug.h"
#include "st_program.h"
#include "st_mesa_to_tgsi.h"
#include "st_cb_program.h"
#include "st_glsl_to_ir.h"
#include "st_atifs_to_tgsi.h"

View File

@ -50,7 +50,6 @@
#include "util/u_math.h"
#include "util/u_memory.h"
#include "st_program.h"
#include "st_mesa_to_tgsi.h"
#include "st_format.h"
#include "st_glsl_to_tgsi_temprename.h"
@ -433,6 +432,85 @@ swizzle_for_size(int size)
}
/**
* Map mesa texture target to TGSI texture target.
*/
static enum tgsi_texture_type
st_translate_texture_target(gl_texture_index textarget, GLboolean shadow)
{
if (shadow) {
switch (textarget) {
case TEXTURE_1D_INDEX:
return TGSI_TEXTURE_SHADOW1D;
case TEXTURE_2D_INDEX:
return TGSI_TEXTURE_SHADOW2D;
case TEXTURE_RECT_INDEX:
return TGSI_TEXTURE_SHADOWRECT;
case TEXTURE_1D_ARRAY_INDEX:
return TGSI_TEXTURE_SHADOW1D_ARRAY;
case TEXTURE_2D_ARRAY_INDEX:
return TGSI_TEXTURE_SHADOW2D_ARRAY;
case TEXTURE_CUBE_INDEX:
return TGSI_TEXTURE_SHADOWCUBE;
case TEXTURE_CUBE_ARRAY_INDEX:
return TGSI_TEXTURE_SHADOWCUBE_ARRAY;
default:
break;
}
}
switch (textarget) {
case TEXTURE_2D_MULTISAMPLE_INDEX:
return TGSI_TEXTURE_2D_MSAA;
case TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX:
return TGSI_TEXTURE_2D_ARRAY_MSAA;
case TEXTURE_BUFFER_INDEX:
return TGSI_TEXTURE_BUFFER;
case TEXTURE_1D_INDEX:
return TGSI_TEXTURE_1D;
case TEXTURE_2D_INDEX:
return TGSI_TEXTURE_2D;
case TEXTURE_3D_INDEX:
return TGSI_TEXTURE_3D;
case TEXTURE_CUBE_INDEX:
return TGSI_TEXTURE_CUBE;
case TEXTURE_CUBE_ARRAY_INDEX:
return TGSI_TEXTURE_CUBE_ARRAY;
case TEXTURE_RECT_INDEX:
return TGSI_TEXTURE_RECT;
case TEXTURE_1D_ARRAY_INDEX:
return TGSI_TEXTURE_1D_ARRAY;
case TEXTURE_2D_ARRAY_INDEX:
return TGSI_TEXTURE_2D_ARRAY;
case TEXTURE_EXTERNAL_INDEX:
return TGSI_TEXTURE_2D;
default:
debug_assert(!"unexpected texture target index");
return TGSI_TEXTURE_1D;
}
}
/**
* Map GLSL base type to TGSI return type.
*/
static enum tgsi_return_type
st_translate_texture_type(enum glsl_base_type type)
{
switch (type) {
case GLSL_TYPE_INT:
return TGSI_RETURN_TYPE_SINT;
case GLSL_TYPE_UINT:
return TGSI_RETURN_TYPE_UINT;
case GLSL_TYPE_FLOAT:
return TGSI_RETURN_TYPE_FLOAT;
default:
assert(!"unexpected texture type");
return TGSI_RETURN_TYPE_UNKNOWN;
}
}
glsl_to_tgsi_instruction *
glsl_to_tgsi_visitor::emit_asm(ir_instruction *ir, enum tgsi_opcode op,
st_dst_reg dst, st_dst_reg dst1,

File diff suppressed because it is too large Load Diff

View File

@ -1,77 +0,0 @@
/**************************************************************************
*
* Copyright 2007 VMware, Inc.
* All Rights Reserved.
*
* 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, sub license, 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 NON-INFRINGEMENT.
* IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS 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.
*
**************************************************************************/
#ifndef ST_MESA_TO_TGSI_H
#define ST_MESA_TO_TGSI_H
#include "main/glheader.h"
#include "main/mtypes.h"
#include "pipe/p_compiler.h"
#include "pipe/p_defines.h"
#include "compiler/glsl_types.h"
#if defined __cplusplus
extern "C" {
#endif
struct gl_context;
struct gl_program;
struct tgsi_token;
struct ureg_program;
enum pipe_error
st_translate_mesa_program(
struct gl_context *ctx,
uint procType,
struct ureg_program *ureg,
const struct gl_program *program,
GLuint numInputs,
const ubyte inputMapping[],
const ubyte inputSemanticName[],
const ubyte inputSemanticIndex[],
const ubyte interpMode[],
GLuint numOutputs,
const ubyte outputMapping[],
const ubyte outputSemanticName[],
const ubyte outputSemanticIndex[]);
enum tgsi_texture_type
st_translate_texture_target(gl_texture_index textarget, GLboolean shadow);
enum tgsi_return_type
st_translate_texture_type(enum glsl_base_type type);
#if defined __cplusplus
} /* extern "C" */
#endif
#endif /* ST_MESA_TO_TGSI_H */

View File

@ -52,6 +52,7 @@
#include "tgsi/tgsi_emulate.h"
#include "tgsi/tgsi_parse.h"
#include "tgsi/tgsi_ureg.h"
#include "nir/nir_to_tgsi.h"
#include "util/u_memory.h"
@ -62,7 +63,6 @@
#include "st_tgsi_lower_depth_clamp.h"
#include "st_tgsi_lower_yuv.h"
#include "st_program.h"
#include "st_mesa_to_tgsi.h"
#include "st_atifs_to_tgsi.h"
#include "st_nir.h"
#include "st_shader_cache.h"
@ -379,11 +379,11 @@ st_translate_prog_to_nir(struct st_context *st, struct gl_program *prog,
gl_shader_stage stage)
{
struct pipe_screen *screen = st->screen;
const struct gl_shader_compiler_options *options =
&st->ctx->Const.ShaderCompilerOptions[stage];
const struct nir_shader_compiler_options *options =
st_get_nir_compiler_options(st, prog->info.stage);
/* Translate to NIR */
nir_shader *nir = prog_to_nir(prog, options->NirOptions);
nir_shader *nir = prog_to_nir(prog, options);
NIR_PASS_V(nir, nir_lower_regs_to_ssa); /* turn registers into SSA */
nir_validate_shader(nir, "after st/ptn lower_regs_to_ssa");
@ -511,29 +511,21 @@ st_translate_vertex_program(struct st_context *st,
if (stp->Base.Parameters->NumParameters)
stp->affected_states |= ST_NEW_VS_CONSTANTS;
/* Translate to NIR if preferred. */
if (PIPE_SHADER_IR_NIR ==
st->screen->get_shader_param(st->screen,
PIPE_SHADER_VERTEX,
PIPE_SHADER_CAP_PREFERRED_IR)) {
assert(!stp->glsl_to_tgsi);
if (stp->Base.nir)
ralloc_free(stp->Base.nir);
if (stp->Base.nir)
ralloc_free(stp->Base.nir);
if (stp->serialized_nir) {
free(stp->serialized_nir);
stp->serialized_nir = NULL;
}
stp->state.type = PIPE_SHADER_IR_NIR;
stp->Base.nir = st_translate_prog_to_nir(st, &stp->Base,
MESA_SHADER_VERTEX);
stp->Base.info = stp->Base.nir->info;
st_prepare_vertex_program(stp);
return true;
if (stp->serialized_nir) {
free(stp->serialized_nir);
stp->serialized_nir = NULL;
}
stp->state.type = PIPE_SHADER_IR_NIR;
stp->Base.nir = st_translate_prog_to_nir(st, &stp->Base,
MESA_SHADER_VERTEX);
stp->Base.info = stp->Base.nir->info;
st_prepare_vertex_program(stp);
return true;
}
st_prepare_vertex_program(stp);
@ -567,47 +559,30 @@ st_translate_vertex_program(struct st_context *st,
struct st_vertex_program *stvp = (struct st_vertex_program *)stp;
if (stp->glsl_to_tgsi) {
error = st_translate_program(st->ctx,
PIPE_SHADER_VERTEX,
ureg,
stp->glsl_to_tgsi,
&stp->Base,
/* inputs */
stvp->num_inputs,
stvp->input_to_index,
NULL, /* inputSlotToAttr */
NULL, /* input semantic name */
NULL, /* input semantic index */
NULL, /* interp mode */
/* outputs */
num_outputs,
stvp->result_to_output,
output_semantic_name,
output_semantic_index);
error = st_translate_program(st->ctx,
PIPE_SHADER_VERTEX,
ureg,
stp->glsl_to_tgsi,
&stp->Base,
/* inputs */
stvp->num_inputs,
stvp->input_to_index,
NULL, /* inputSlotToAttr */
NULL, /* input semantic name */
NULL, /* input semantic index */
NULL, /* interp mode */
/* outputs */
num_outputs,
stvp->result_to_output,
output_semantic_name,
output_semantic_index);
st_translate_stream_output_info(&stp->Base);
st_translate_stream_output_info(&stp->Base);
free_glsl_to_tgsi_visitor(stp->glsl_to_tgsi);
} else
error = st_translate_mesa_program(st->ctx,
PIPE_SHADER_VERTEX,
ureg,
&stp->Base,
/* inputs */
stvp->num_inputs,
stvp->input_to_index,
NULL, /* input semantic name */
NULL, /* input semantic index */
NULL,
/* outputs */
num_outputs,
stvp->result_to_output,
output_semantic_name,
output_semantic_index);
free_glsl_to_tgsi_visitor(stp->glsl_to_tgsi);
if (error) {
debug_printf("%s: failed to translate Mesa program:\n", __func__);
debug_printf("%s: failed to translate GLSL IR program:\n", __func__);
_mesa_print_program(&stp->Base);
debug_assert(0);
return false;
@ -616,10 +591,8 @@ st_translate_vertex_program(struct st_context *st,
stp->state.tokens = ureg_get_tokens(ureg, NULL);
ureg_destroy(ureg);
if (stp->glsl_to_tgsi) {
stp->glsl_to_tgsi = NULL;
st_store_ir_in_disk_cache(st, &stp->Base, false);
}
stp->glsl_to_tgsi = NULL;
st_store_ir_in_disk_cache(st, &stp->Base, false);
return stp->state.tokens != NULL;
}
@ -641,7 +614,7 @@ get_nir_shader(struct st_context *st, struct st_program *stp)
struct blob_reader blob_reader;
const struct nir_shader_compiler_options *options =
st->ctx->Const.ShaderCompilerOptions[stp->Base.info.stage].NirOptions;
st_get_nir_compiler_options(st, stp->Base.info.stage);
blob_reader_init(&blob_reader, stp->serialized_nir, stp->serialized_nir_size);
return nir_deserialize(NULL, options, &blob_reader);
@ -746,6 +719,17 @@ st_create_vp_variant(struct st_context *st,
if (ST_DEBUG & DEBUG_PRINT_IR)
nir_print_shader(state.ir.nir, stderr);
/* If the driver wants TGSI, then translate before handing off. */
if (st->pipe->screen->get_shader_param(st->pipe->screen,
PIPE_SHADER_VERTEX,
PIPE_SHADER_CAP_PREFERRED_IR) !=
PIPE_SHADER_IR_NIR) {
nir_shader *s = state.ir.nir;
state.tokens = nir_to_tgsi(s, st->pipe->screen);
state.type = PIPE_SHADER_IR_TGSI;
ralloc_free(s);
}
if (key->is_draw_shader)
vpv->base.driver_shader = draw_create_vertex_shader(st->draw, &state);
else
@ -879,11 +863,7 @@ st_translate_fragment_program(struct st_context *st,
}
/* Translate to NIR. */
if (!stfp->ati_fs &&
PIPE_SHADER_IR_NIR ==
st->screen->get_shader_param(st->screen,
PIPE_SHADER_FRAGMENT,
PIPE_SHADER_CAP_PREFERRED_IR)) {
if (!stfp->ati_fs) {
nir_shader *nir =
st_translate_prog_to_nir(st, &stfp->Base, MESA_SHADER_FRAGMENT);
@ -1162,7 +1142,8 @@ st_translate_fragment_program(struct st_context *st,
fs_output_semantic_index);
free_glsl_to_tgsi_visitor(stfp->glsl_to_tgsi);
} else if (stfp->ati_fs)
} else {
assert(stfp->ati_fs);
st_translate_atifs_program(ureg,
stfp->ati_fs,
&stfp->Base,
@ -1177,22 +1158,7 @@ st_translate_fragment_program(struct st_context *st,
outputMapping,
fs_output_semantic_name,
fs_output_semantic_index);
else
st_translate_mesa_program(st->ctx,
PIPE_SHADER_FRAGMENT,
ureg,
&stfp->Base,
/* inputs */
fs_num_inputs,
inputMapping,
input_semantic_name,
input_semantic_index,
interpMode,
/* outputs */
fs_num_outputs,
outputMapping,
fs_output_semantic_name,
fs_output_semantic_index);
}
stfp->state.tokens = ureg_get_tokens(ureg, NULL);
ureg_destroy(ureg);
@ -1361,6 +1327,17 @@ st_create_fp_variant(struct st_context *st,
if (ST_DEBUG & DEBUG_PRINT_IR)
nir_print_shader(state.ir.nir, stderr);
/* If the driver wants TGSI, then translate before handing off. */
if (st->pipe->screen->get_shader_param(st->pipe->screen,
PIPE_SHADER_FRAGMENT,
PIPE_SHADER_CAP_PREFERRED_IR) !=
PIPE_SHADER_IR_NIR) {
nir_shader *s = state.ir.nir;
state.tokens = nir_to_tgsi(s, st->pipe->screen);
state.type = PIPE_SHADER_IR_TGSI;
ralloc_free(s);
}
variant->base.driver_shader = pipe->create_fs_state(pipe, &state);
variant->key = *key;