mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-05 16:08:04 +02:00
svga: Add support for requesting NIR and translating to TGSI.
I'm working on switching mesa/st to no longer produce TGSI on its own, and so we need a way to test SVGA against that future. Reviewed-by: Alyssa Rosenzweig <alyssa@collabora.com> Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com> Reviewed-by: Charmaine Lee <charmainel@vmware.com> Reviewed-by: Neha Bhende <bhenden@vmware.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14160>
This commit is contained in:
parent
0cfc01fe83
commit
3cdb200f10
10 changed files with 77 additions and 16 deletions
|
|
@ -30,6 +30,7 @@
|
|||
#include "tgsi/tgsi_dump.h"
|
||||
#include "tgsi/tgsi_from_mesa.h"
|
||||
#include "tgsi/tgsi_info.h"
|
||||
#include "tgsi/tgsi_parse.h"
|
||||
#include "tgsi/tgsi_ureg.h"
|
||||
#include "tgsi/tgsi_util.h"
|
||||
#include "util/debug.h"
|
||||
|
|
@ -3914,3 +3915,17 @@ nir_to_tgsi_get_compiler_options(struct pipe_screen *pscreen,
|
|||
assert(ir == PIPE_SHADER_IR_NIR);
|
||||
return &nir_to_tgsi_compiler_options;
|
||||
}
|
||||
|
||||
/** Helper for getting TGSI tokens to store for a pipe_shader_state CSO. */
|
||||
const void *
|
||||
pipe_shader_state_to_tgsi_tokens(struct pipe_screen *screen,
|
||||
const struct pipe_shader_state *cso)
|
||||
{
|
||||
if (cso->type == PIPE_SHADER_IR_NIR) {
|
||||
return nir_to_tgsi((nir_shader *)cso->ir.nir, screen);
|
||||
} else {
|
||||
assert(cso->type == PIPE_SHADER_IR_TGSI);
|
||||
/* we need to keep a local copy of the tokens */
|
||||
return tgsi_dup_tokens(cso->tokens);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,9 +25,11 @@
|
|||
#define NIR_TO_TGSI_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "pipe/p_defines.h"
|
||||
|
||||
struct nir_shader;
|
||||
struct pipe_screen;
|
||||
struct pipe_shader_state;
|
||||
|
||||
struct nir_to_tgsi_options {
|
||||
bool lower_cmp;
|
||||
|
|
@ -48,4 +50,8 @@ nir_to_tgsi_get_compiler_options(struct pipe_screen *pscreen,
|
|||
enum pipe_shader_ir ir,
|
||||
unsigned shader);
|
||||
|
||||
const void *
|
||||
pipe_shader_state_to_tgsi_tokens(struct pipe_screen *screen,
|
||||
const struct pipe_shader_state *cso);
|
||||
|
||||
#endif /* NIR_TO_TGSI_H */
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ libsvga = static_library(
|
|||
inc_src, inc_include, inc_gallium, inc_gallium_aux,
|
||||
include_directories('include')
|
||||
],
|
||||
dependencies : idep_mesautil,
|
||||
dependencies : [idep_mesautil, idep_nir],
|
||||
)
|
||||
|
||||
svga_deps = [libsvga]
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@
|
|||
*
|
||||
**********************************************************/
|
||||
|
||||
#include "nir/nir_to_tgsi.h"
|
||||
#include "util/u_inlines.h"
|
||||
#include "util/u_memory.h"
|
||||
#include "util/u_bitmask.h"
|
||||
|
|
@ -53,8 +54,13 @@ svga_create_compute_state(struct pipe_context *pipe,
|
|||
|
||||
SVGA_STATS_TIME_PUSH(svga_sws(svga), SVGA_STATS_TIME_CREATECS);
|
||||
|
||||
assert(templ->ir_type == PIPE_SHADER_IR_TGSI);
|
||||
cs->base.tokens = tgsi_dup_tokens(templ->prog);
|
||||
if (templ->ir_type == PIPE_SHADER_IR_NIR) {
|
||||
cs->base.tokens = nir_to_tgsi((void *)templ->prog, pipe->screen);
|
||||
} else {
|
||||
assert(templ->ir_type == PIPE_SHADER_IR_TGSI);
|
||||
/* we need to keep a local copy of the tokens */
|
||||
cs->base.tokens = tgsi_dup_tokens(templ->prog);
|
||||
}
|
||||
|
||||
/* Collect shader basic info */
|
||||
tgsi_scan_shader(cs->base.tokens, &cs->base.info);
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@
|
|||
*
|
||||
**********************************************************/
|
||||
|
||||
#include "nir/nir_to_tgsi.h"
|
||||
#include "util/u_inlines.h"
|
||||
#include "util/u_math.h"
|
||||
#include "util/u_memory.h"
|
||||
|
|
@ -50,7 +51,7 @@ svga_create_fs_state(struct pipe_context *pipe,
|
|||
|
||||
SVGA_STATS_TIME_PUSH(svga_sws(svga), SVGA_STATS_TIME_CREATEFS);
|
||||
|
||||
fs->base.tokens = tgsi_dup_tokens(templ->tokens);
|
||||
fs->base.tokens = pipe_shader_state_to_tgsi_tokens(pipe->screen, templ);
|
||||
|
||||
/* Collect basic info that we'll need later:
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@
|
|||
**********************************************************/
|
||||
|
||||
#include "draw/draw_context.h"
|
||||
#include "nir/nir_to_tgsi.h"
|
||||
#include "util/u_inlines.h"
|
||||
#include "util/u_memory.h"
|
||||
#include "util/u_bitmask.h"
|
||||
|
|
@ -48,7 +49,7 @@ svga_create_gs_state(struct pipe_context *pipe,
|
|||
|
||||
SVGA_STATS_TIME_PUSH(svga_sws(svga), SVGA_STATS_TIME_CREATEGS);
|
||||
|
||||
gs->base.tokens = tgsi_dup_tokens(templ->tokens);
|
||||
gs->base.tokens = pipe_shader_state_to_tgsi_tokens(pipe->screen, templ);
|
||||
|
||||
/* Collect basic info that we'll need later:
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@
|
|||
*
|
||||
**********************************************************/
|
||||
|
||||
#include "nir/nir_to_tgsi.h"
|
||||
#include "pipe/p_context.h"
|
||||
#include "util/u_memory.h"
|
||||
#include "tgsi/tgsi_parse.h"
|
||||
|
|
@ -69,7 +70,7 @@ svga_create_tcs_state(struct pipe_context *pipe,
|
|||
|
||||
SVGA_STATS_TIME_PUSH(svga_sws(svga), SVGA_STATS_TIME_CREATETCS);
|
||||
|
||||
tcs->base.tokens = tgsi_dup_tokens(templ->tokens);
|
||||
tcs->base.tokens = pipe_shader_state_to_tgsi_tokens(pipe->screen, templ);
|
||||
|
||||
/* Collect basic info that we'll need later:
|
||||
*/
|
||||
|
|
@ -153,7 +154,7 @@ svga_create_tes_state(struct pipe_context *pipe,
|
|||
|
||||
SVGA_STATS_TIME_PUSH(svga_sws(svga), SVGA_STATS_TIME_CREATETES);
|
||||
|
||||
tes->base.tokens = tgsi_dup_tokens(templ->tokens);
|
||||
tes->base.tokens = pipe_shader_state_to_tgsi_tokens(pipe->screen, templ);
|
||||
|
||||
/* Collect basic info that we'll need later:
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@
|
|||
**********************************************************/
|
||||
|
||||
#include "draw/draw_context.h"
|
||||
#include "nir/nir_to_tgsi.h"
|
||||
#include "util/u_inlines.h"
|
||||
#include "util/u_math.h"
|
||||
#include "util/u_memory.h"
|
||||
|
|
@ -46,6 +47,7 @@ static const struct tgsi_token *
|
|||
substitute_vs(unsigned shader_id, const struct tgsi_token *old_tokens)
|
||||
{
|
||||
#if 0
|
||||
FREE(old_tokens);
|
||||
if (shader_id == 12) {
|
||||
static struct tgsi_token tokens[300];
|
||||
|
||||
|
|
@ -108,8 +110,8 @@ svga_create_vs_state(struct pipe_context *pipe,
|
|||
|
||||
/* substitute a debug shader?
|
||||
*/
|
||||
vs->base.tokens = tgsi_dup_tokens(substitute_vs(svga->debug.shader_id,
|
||||
templ->tokens));
|
||||
vs->base.tokens = substitute_vs(svga->debug.shader_id,
|
||||
pipe_shader_state_to_tgsi_tokens(pipe->screen, templ));
|
||||
|
||||
/* Collect basic info that we'll need later:
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@
|
|||
**********************************************************/
|
||||
|
||||
#include "git_sha1.h" /* For MESA_GIT_SHA1 */
|
||||
#include "compiler/nir/nir.h"
|
||||
#include "util/format/u_format.h"
|
||||
#include "util/u_memory.h"
|
||||
#include "util/u_inlines.h"
|
||||
|
|
@ -541,9 +542,9 @@ vgpu9_get_shader_param(struct pipe_screen *screen,
|
|||
case PIPE_SHADER_CAP_MAX_SAMPLER_VIEWS:
|
||||
return 16;
|
||||
case PIPE_SHADER_CAP_PREFERRED_IR:
|
||||
return PIPE_SHADER_IR_TGSI;
|
||||
return svgascreen->debug.nir ? PIPE_SHADER_IR_NIR : PIPE_SHADER_IR_TGSI;
|
||||
case PIPE_SHADER_CAP_SUPPORTED_IRS:
|
||||
return 1 << PIPE_SHADER_IR_TGSI;
|
||||
return (1 << PIPE_SHADER_IR_TGSI) | (svgascreen->debug.nir ? (1 << PIPE_SHADER_IR_NIR) : 0);
|
||||
case PIPE_SHADER_CAP_DROUND_SUPPORTED:
|
||||
case PIPE_SHADER_CAP_DFRACEXP_DLDEXP_SUPPORTED:
|
||||
case PIPE_SHADER_CAP_LDEXP_SUPPORTED:
|
||||
|
|
@ -612,9 +613,9 @@ vgpu9_get_shader_param(struct pipe_screen *screen,
|
|||
case PIPE_SHADER_CAP_MAX_SAMPLER_VIEWS:
|
||||
return 0;
|
||||
case PIPE_SHADER_CAP_PREFERRED_IR:
|
||||
return PIPE_SHADER_IR_TGSI;
|
||||
return svgascreen->debug.nir ? PIPE_SHADER_IR_NIR : PIPE_SHADER_IR_TGSI;
|
||||
case PIPE_SHADER_CAP_SUPPORTED_IRS:
|
||||
return 1 << PIPE_SHADER_IR_TGSI;
|
||||
return (1 << PIPE_SHADER_IR_TGSI) | (svgascreen->debug.nir ? (1 << PIPE_SHADER_IR_NIR) : 0);
|
||||
case PIPE_SHADER_CAP_DROUND_SUPPORTED:
|
||||
case PIPE_SHADER_CAP_DFRACEXP_DLDEXP_SUPPORTED:
|
||||
case PIPE_SHADER_CAP_LDEXP_SUPPORTED:
|
||||
|
|
@ -725,10 +726,10 @@ vgpu10_get_shader_param(struct pipe_screen *screen,
|
|||
case PIPE_SHADER_CAP_MAX_SAMPLER_VIEWS:
|
||||
return sws->have_gl43 ? PIPE_MAX_SAMPLERS : SVGA3D_DX_MAX_SAMPLERS;
|
||||
case PIPE_SHADER_CAP_PREFERRED_IR:
|
||||
return PIPE_SHADER_IR_TGSI;
|
||||
return svgascreen->debug.nir ? PIPE_SHADER_IR_NIR : PIPE_SHADER_IR_TGSI;
|
||||
case PIPE_SHADER_CAP_SUPPORTED_IRS:
|
||||
if (sws->have_gl43)
|
||||
return 1 << PIPE_SHADER_IR_TGSI;
|
||||
return (1 << PIPE_SHADER_IR_TGSI) | (svgascreen->debug.nir ? (1 << PIPE_SHADER_IR_NIR) : 0);
|
||||
else
|
||||
return 0;
|
||||
case PIPE_SHADER_CAP_DROUND_SUPPORTED:
|
||||
|
|
@ -765,6 +766,30 @@ vgpu10_get_shader_param(struct pipe_screen *screen,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static const nir_shader_compiler_options svga_compiler_options = {
|
||||
.lower_extract_byte = true,
|
||||
.lower_extract_word = true,
|
||||
.lower_insert_byte = true,
|
||||
.lower_insert_word = true,
|
||||
.lower_fdph = true,
|
||||
.lower_flrp64 = true,
|
||||
.lower_rotate = true,
|
||||
.lower_uniforms_to_ubo = true,
|
||||
.lower_vector_cmp = true,
|
||||
|
||||
.max_unroll_iterations = 32,
|
||||
.use_interpolated_input_intrinsics = true,
|
||||
};
|
||||
|
||||
static const void *
|
||||
svga_get_compiler_options(struct pipe_screen *pscreen,
|
||||
enum pipe_shader_ir ir,
|
||||
enum pipe_shader_type shader)
|
||||
{
|
||||
assert(ir == PIPE_SHADER_IR_NIR);
|
||||
|
||||
return &svga_compiler_options;
|
||||
}
|
||||
|
||||
static int
|
||||
svga_get_shader_param(struct pipe_screen *screen, enum pipe_shader_type shader,
|
||||
|
|
@ -1034,6 +1059,8 @@ svga_screen_create(struct svga_winsys_screen *sws)
|
|||
debug_get_bool_option("SVGA_NO_SAMPLER_VIEW", FALSE);
|
||||
svgascreen->debug.no_cache_index_buffers =
|
||||
debug_get_bool_option("SVGA_NO_CACHE_INDEX_BUFFERS", FALSE);
|
||||
svgascreen->debug.nir =
|
||||
debug_get_bool_option("SVGA_NIR", FALSE);
|
||||
|
||||
screen = &svgascreen->screen;
|
||||
|
||||
|
|
@ -1043,6 +1070,7 @@ svga_screen_create(struct svga_winsys_screen *sws)
|
|||
screen->get_device_vendor = svga_get_vendor; // TODO actual device vendor
|
||||
screen->get_param = svga_get_param;
|
||||
screen->get_shader_param = svga_get_shader_param;
|
||||
screen->get_compiler_options = svga_get_compiler_options;
|
||||
screen->get_paramf = svga_get_paramf;
|
||||
screen->get_timestamp = NULL;
|
||||
screen->is_format_supported = svga_is_format_supported;
|
||||
|
|
|
|||
|
|
@ -72,7 +72,8 @@ struct svga_screen
|
|||
unsigned no_cache_index_buffers:1;
|
||||
unsigned tessellation:1;
|
||||
unsigned sampler_state_mapping:1;
|
||||
unsigned pad:24;
|
||||
unsigned nir:1;
|
||||
unsigned pad:23;
|
||||
} debug;
|
||||
|
||||
unsigned texture_timestamp;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue