[Mesa-dev] [PATCH] gallium: add basevertex and vertexid_zerobase semantics
Marek Olšák
maraeo at gmail.com
Mon Oct 13 02:14:55 PDT 2014
radeonsi supports VERTEXID_ZEROBASE and BASEVERTEX. VERTEXID can be
implemented trivially using the two. I don't think we need any cap
bits, because this is required by OpenGL. In the worst case, drivers
will have to store BASEVERTEX in a constant buffer.
Marek
On Mon, Oct 13, 2014 at 9:45 AM, <sroland at vmware.com> wrote:
> From: Roland Scheidegger <sroland at vmware.com>
>
> Just like in core mesa, expose a separate vertexid which doesn't include
> the base vertex (aka d3d10 style). And expose basevertex too (vertexid is
> basevertex + vertexid_zerobase). This will be needed to fix the piglit
> vertexid failures in draw due to it following d3d10 semantics with vertexid
> (this patch does not actually fix that yet).
>
> XXX: what cap bits do we want?
> ---
> src/gallium/auxiliary/draw/draw_llvm.c | 8 +++++-
> src/gallium/auxiliary/gallivm/lp_bld_tgsi.h | 1 +
> src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c | 5 ++++
> src/gallium/auxiliary/tgsi/tgsi_strings.c | 2 ++
> src/gallium/docs/source/tgsi.rst | 36 +++++++++++++++++++++++++
> src/gallium/include/pipe/p_shader_tokens.h | 4 ++-
> src/mesa/state_tracker/st_glsl_to_tgsi.cpp | 8 ++++--
> 7 files changed, 60 insertions(+), 4 deletions(-)
>
> diff --git a/src/gallium/auxiliary/draw/draw_llvm.c b/src/gallium/auxiliary/draw/draw_llvm.c
> index 14c802b..073b8ef 100644
> --- a/src/gallium/auxiliary/draw/draw_llvm.c
> +++ b/src/gallium/auxiliary/draw/draw_llvm.c
> @@ -1653,7 +1653,11 @@ draw_llvm_generate(struct draw_llvm *llvm, struct draw_llvm_variant *variant,
> lp_build_printf(gallivm, " --- io %d = %p, loop counter %d\n",
> io_itr, io, lp_loop.counter);
> #endif
> - system_values.vertex_id = lp_build_zero(gallivm, lp_type_uint_vec(32, 32*vector_length));
> + system_values.vertex_id = lp_build_zero(gallivm,
> + lp_type_uint_vec(32, 32*vector_length));
> + system_values.basevertex = lp_build_broadcast(gallivm, lp_build_vec_type(gallivm,
> + lp_type_uint_vec(32, 32*vector_length)),
> + vertex_id_offset);
> for (i = 0; i < vector_length; ++i) {
> LLVMValueRef vert_index =
> LLVMBuildAdd(builder,
> @@ -1714,6 +1718,8 @@ draw_llvm_generate(struct draw_llvm *llvm, struct draw_llvm_variant *variant,
> * the primitive was split (we split rendering into chunks of at
> * most 4095-vertices) we need to back out the original start
> * index out of our vertex id here.
> + * XXX this is only true for d3d10 style vertex id otherwise should
> + * skip the sub.
> */
> vertex_id = LLVMBuildSub(builder, true_index, vertex_id_offset, "");
>
> diff --git a/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h b/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h
> index 029ca3c..43a0feb 100644
> --- a/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h
> +++ b/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h
> @@ -163,6 +163,7 @@ struct lp_bld_tgsi_system_values {
> LLVMValueRef instance_id;
> LLVMValueRef vertex_id;
> LLVMValueRef prim_id;
> + LLVMValueRef basevertex;
> };
>
>
> diff --git a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c
> index 05618bc..32c5a6f 100644
> --- a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c
> +++ b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c
> @@ -1538,6 +1538,11 @@ emit_fetch_system_value(
> atype = TGSI_TYPE_UNSIGNED;
> break;
>
> + case TGSI_SEMANTIC_BASEVERTEX:
> + res = bld->system_values.basevertex;
> + atype = TGSI_TYPE_UNSIGNED;
> + break;
> +
> case TGSI_SEMANTIC_PRIMID:
> res = bld->system_values.prim_id;
> atype = TGSI_TYPE_UNSIGNED;
> diff --git a/src/gallium/auxiliary/tgsi/tgsi_strings.c b/src/gallium/auxiliary/tgsi/tgsi_strings.c
> index f84cd79..77ef04c 100644
> --- a/src/gallium/auxiliary/tgsi/tgsi_strings.c
> +++ b/src/gallium/auxiliary/tgsi/tgsi_strings.c
> @@ -86,6 +86,8 @@ const char *tgsi_semantic_names[TGSI_SEMANTIC_COUNT] =
> "SAMPLEPOS",
> "SAMPLEMASK",
> "INVOCATIONID",
> + "VERTEXID_ZEROBASE",
> + "BASEVERTEX",
> };
>
> const char *tgsi_texture_names[TGSI_TEXTURE_COUNT] =
> diff --git a/src/gallium/docs/source/tgsi.rst b/src/gallium/docs/source/tgsi.rst
> index 7d5918f..d53e563 100644
> --- a/src/gallium/docs/source/tgsi.rst
> +++ b/src/gallium/docs/source/tgsi.rst
> @@ -2839,6 +2839,42 @@ For geometry shaders, this semantic label indicates that a system value
> contains the current invocation id (i.e. gl_InvocationID). Only the X value is
> used.
>
> +TGSI_SEMANTIC_INSTANCEID
> +""""""""""""""""""""""""
> +
> +For vertex shaders, this semantic label indicates that a system value contains
> +the current instance id (i.e. gl_InstanceID). It does not include the base
> +instance. Only the X value is used.
> +
> +TGSI_SEMANTIC_VERTEXID
> +""""""""""""""""""""""
> +
> +For vertex shaders, this semantic label indicates that a system value contains
> +the current vertex id (i.e. gl_VertexID). It does (unlike in d3d10) include the
> +base vertex. Only the X value is used.
> +
> +TGSI_SEMANTIC_VERTEXID_ZEROBASE
> +"""""""""""""""""""""""""""""""
> +
> +For vertex shaders, this semantic label indicates that a system value contains
> +the current vertex id without including the base vertex (this corresponds to
> +d3d10 vertex id, so TGSI_SEMANTIC_VERTEXID_ZEROBASE + TGSI_SEMANTIC_BASEVERTEX
> +== TGSI_SEMANTIC_VERTEXID). Only the X value is used.
> +
> +TGSI_SEMANTIC_BASEVERTEX
> +""""""""""""""""""""""""
> +
> +For vertex shaders, this semantic label indicates that a system value contains
> +the base vertex (i.e. gl_BaseVertex). Only the X value is used.
> +
> +TGSI_SEMANTIC_PRIMID
> +""""""""""""""""""""
> +
> +For geometry and fragment shaders, this semantic label indicates the value
> +contains the primitive id (i.e. gl_PrimitiveID). Only the X value is used.
> +FIXME: This right now can be either a ordinary input or a system value...
> +
> +
> Declaration Interpolate
> ^^^^^^^^^^^^^^^^^^^^^^^
>
> diff --git a/src/gallium/include/pipe/p_shader_tokens.h b/src/gallium/include/pipe/p_shader_tokens.h
> index df154a2..7a68387 100644
> --- a/src/gallium/include/pipe/p_shader_tokens.h
> +++ b/src/gallium/include/pipe/p_shader_tokens.h
> @@ -176,7 +176,9 @@ struct tgsi_declaration_interp
> #define TGSI_SEMANTIC_SAMPLEPOS 25
> #define TGSI_SEMANTIC_SAMPLEMASK 26
> #define TGSI_SEMANTIC_INVOCATIONID 27
> -#define TGSI_SEMANTIC_COUNT 28 /**< number of semantic values */
> +#define TGSI_SEMANTIC_VERTEXID_ZEROBASE 28
> +#define TGSI_SEMANTIC_BASEVERTEX 29
> +#define TGSI_SEMANTIC_COUNT 30 /**< number of semantic values */
>
> struct tgsi_declaration_semantic
> {
> diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
> index a0da9f6..872724c 100644
> --- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
> +++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
> @@ -4165,8 +4165,8 @@ const unsigned _mesa_sysval_to_semantic[SYSTEM_VALUE_MAX] = {
> */
> TGSI_SEMANTIC_VERTEXID,
> TGSI_SEMANTIC_INSTANCEID,
> - 0,
> - 0,
> + TGSI_SEMANTIC_VERTEXID_ZEROBASE,
> + TGSI_SEMANTIC_BASEVERTEX,
>
> /* Geometry shader
> */
> @@ -4866,6 +4866,10 @@ st_translate_program(
> TGSI_SEMANTIC_SAMPLEMASK);
> assert(_mesa_sysval_to_semantic[SYSTEM_VALUE_INVOCATION_ID] ==
> TGSI_SEMANTIC_INVOCATIONID);
> + assert(_mesa_sysval_to_semantic[SYSTEM_VALUE_VERTEX_ID_ZERO_BASE] ==
> + TGSI_SEMANTIC_VERTEXID_ZEROBASE);
> + assert(_mesa_sysval_to_semantic[SYSTEM_VALUE_BASE_VERTEX] ==
> + TGSI_SEMANTIC_BASEVERTEX);
>
> t = CALLOC_STRUCT(st_translate);
> if (!t) {
> --
> 1.9.1
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev
More information about the mesa-dev
mailing list