mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-30 01:20:17 +01:00
st/mesa: Add a NIR version of the OES_draw_texture built-in shaders.
Reviewed-by: Marek Olšák <marek.olsak@amd.com> Tested-by: Rob Clark <robdclark@gmail.com> Tested-by: Eric Anholt <eric@anholt.net>
This commit is contained in:
parent
be492affa8
commit
a02349b9e7
1 changed files with 62 additions and 7 deletions
|
|
@ -24,6 +24,7 @@
|
|||
#include "st_atom.h"
|
||||
#include "st_cb_bitmap.h"
|
||||
#include "st_cb_drawtex.h"
|
||||
#include "st_nir.h"
|
||||
|
||||
#include "pipe/p_context.h"
|
||||
#include "pipe/p_defines.h"
|
||||
|
|
@ -55,13 +56,46 @@ struct cached_shader
|
|||
static struct cached_shader CachedShaders[MAX_SHADERS];
|
||||
static GLuint NumCachedShaders = 0;
|
||||
|
||||
static gl_vert_attrib
|
||||
semantic_to_vert_attrib(unsigned semantic)
|
||||
{
|
||||
switch (semantic) {
|
||||
case TGSI_SEMANTIC_POSITION:
|
||||
return VERT_ATTRIB_POS;
|
||||
case TGSI_SEMANTIC_COLOR:
|
||||
return VERT_ATTRIB_COLOR0;
|
||||
case TGSI_SEMANTIC_GENERIC:
|
||||
case TGSI_SEMANTIC_TEXCOORD:
|
||||
return VERT_ATTRIB_GENERIC0;
|
||||
default:
|
||||
unreachable("unhandled semantic");
|
||||
}
|
||||
}
|
||||
|
||||
static gl_varying_slot
|
||||
semantic_to_varying_slot(unsigned semantic)
|
||||
{
|
||||
switch (semantic) {
|
||||
case TGSI_SEMANTIC_POSITION:
|
||||
return VARYING_SLOT_POS;
|
||||
case TGSI_SEMANTIC_COLOR:
|
||||
return VARYING_SLOT_COL0;
|
||||
case TGSI_SEMANTIC_GENERIC:
|
||||
case TGSI_SEMANTIC_TEXCOORD:
|
||||
return VARYING_SLOT_TEX0;
|
||||
default:
|
||||
unreachable("unhandled semantic");
|
||||
}
|
||||
}
|
||||
|
||||
static void *
|
||||
lookup_shader(struct pipe_context *pipe,
|
||||
lookup_shader(struct st_context *st,
|
||||
uint num_attribs,
|
||||
const uint *semantic_names,
|
||||
const uint *semantic_indexes)
|
||||
{
|
||||
struct pipe_context *pipe = st->pipe;
|
||||
struct pipe_screen *screen = pipe->screen;
|
||||
GLuint i, j;
|
||||
|
||||
/* look for existing shader with same attributes */
|
||||
|
|
@ -91,11 +125,32 @@ lookup_shader(struct pipe_context *pipe,
|
|||
CachedShaders[i].semantic_indexes[j] = semantic_indexes[j];
|
||||
}
|
||||
|
||||
CachedShaders[i].handle =
|
||||
util_make_vertex_passthrough_shader(pipe,
|
||||
num_attribs,
|
||||
semantic_names,
|
||||
semantic_indexes, FALSE);
|
||||
enum pipe_shader_ir preferred_ir =
|
||||
screen->get_shader_param(screen, MESA_SHADER_VERTEX,
|
||||
PIPE_SHADER_CAP_PREFERRED_IR);
|
||||
|
||||
if (preferred_ir == PIPE_SHADER_IR_NIR) {
|
||||
unsigned inputs[2 + MAX_TEXTURE_UNITS];
|
||||
unsigned outputs[2 + MAX_TEXTURE_UNITS];
|
||||
|
||||
for (int j = 0; j < num_attribs; j++) {
|
||||
inputs[j] = semantic_to_vert_attrib(semantic_names[j]);
|
||||
outputs[j] = semantic_to_varying_slot(semantic_names[j]);
|
||||
}
|
||||
|
||||
CachedShaders[i].handle =
|
||||
st_nir_make_passthrough_shader(st, "st/drawtex VS",
|
||||
MESA_SHADER_VERTEX,
|
||||
num_attribs, inputs,
|
||||
outputs, NULL, 0);
|
||||
} else {
|
||||
CachedShaders[i].handle =
|
||||
util_make_vertex_passthrough_shader(pipe,
|
||||
num_attribs,
|
||||
semantic_names,
|
||||
semantic_indexes, FALSE);
|
||||
}
|
||||
|
||||
NumCachedShaders++;
|
||||
|
||||
return CachedShaders[i].handle;
|
||||
|
|
@ -243,7 +298,7 @@ st_DrawTex(struct gl_context *ctx, GLfloat x, GLfloat y, GLfloat z,
|
|||
CSO_BIT_AUX_VERTEX_BUFFER_SLOT));
|
||||
|
||||
{
|
||||
void *vs = lookup_shader(pipe, numAttribs,
|
||||
void *vs = lookup_shader(st, numAttribs,
|
||||
semantic_names, semantic_indexes);
|
||||
cso_set_vertex_shader_handle(cso, vs);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue