Commit 48a7456f authored by Neha Bhende's avatar Neha Bhende Committed by Marge Bot

util: Add util functionality for GL4.1 support

This patch adds the following tgsi utilities

* tgsi_dynamic_indexing: This utility flattens out the dyanamic indexing of constant buffers
* tgsi_vpos: This utility writes zeros to position at index 0 in vertex shader.
  This utility can be used if there is no shader output in vertex shader
* util_make_tess_ctrl_passthrough_shader: This adds passthough tessellation control shader.
  Input of passthrough tess ctrl shader is output of vertex shader
  and output is input of tessellation eval shader.
  If program has tessellation eval shader but no tessellation control shader,
  this utility can be used to create passthrough tessellation control shader.
Reviewed-by: Brian Paul's avatarBrian Paul <brianp@vmware.com>
Reviewed-by: Charmaine Lee's avatarCharmaine Lee <charmainel@vmware.com>
Signed-off-by: Neha Bhende's avatarNeha Bhende <bhenden@vmware.com>
Part-of: <!5317>
parent f1f81abf
......@@ -183,6 +183,7 @@ files_libgallium = files(
'tgsi/tgsi_build.h',
'tgsi/tgsi_dump.c',
'tgsi/tgsi_dump.h',
'tgsi/tgsi_dynamic_indexing.c',
'tgsi/tgsi_exec.c',
'tgsi/tgsi_exec.h',
'tgsi/tgsi_emulate.c',
......@@ -217,6 +218,7 @@ files_libgallium = files(
'tgsi/tgsi_ureg.h',
'tgsi/tgsi_util.c',
'tgsi/tgsi_util.h',
'tgsi/tgsi_vpos.c',
'translate/translate.c',
'translate/translate.h',
'translate/translate_cache.c',
......
This diff is collapsed.
/*
* Copyright 2018 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 THE AUTHORS 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 TGSI_DYNAMIC_INDEXING_H
#define TGSI_DYNAMIC_INDEXING_H
struct tgsi_token;
struct tgsi_shader_info;
struct tgsi_token *
tgsi_remove_dynamic_indexing(const struct tgsi_token *tokens_in,
unsigned const_buffers_declared,
unsigned samplers_declared,
unsigned imm_count);
#endif /* TGSI_DYNAMIC_INDEXING_H */
......@@ -223,6 +223,24 @@ tgsi_transform_immediate_decl(struct tgsi_transform_context *ctx,
ctx->emit_immediate(ctx, &immed);
}
static inline void
tgsi_transform_immediate_int_decl(struct tgsi_transform_context *ctx,
int x, int y, int z, int w)
{
struct tgsi_full_immediate immed;
unsigned size = 4;
immed = tgsi_default_full_immediate();
immed.Immediate.DataType = TGSI_IMM_INT32;
immed.Immediate.NrTokens = 1 + size; /* one for the token itself */
immed.u[0].Int = x;
immed.u[1].Int = y;
immed.u[2].Int = z;
immed.u[3].Int = w;
ctx->emit_immediate(ctx, &immed);
}
static inline void
tgsi_transform_dst_reg(struct tgsi_full_dst_register *reg,
unsigned file, unsigned index, unsigned writemask)
......
/*
* Copyright 2018 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 THE AUTHORS 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.
*/
/**
* TGSI utility transforms the shader to write imm(0, 0, 0, 1) to vertex
* position
*/
#include "util/u_debug.h"
#include "util/u_math.h"
#include "tgsi_vpos.h"
#include "tgsi_transform.h"
#include "tgsi_dump.h"
#include "pipe/p_state.h"
struct write_vpos_context
{
struct tgsi_transform_context base;
unsigned imm_index;
};
static inline struct write_vpos_context *
write_vpos_context(struct tgsi_transform_context *ctx)
{
return (struct write_vpos_context *) ctx;
}
/**
* TGSI transform prolog callback.
*/
static void
write_vpos_prolog(struct tgsi_transform_context *ctx)
{
struct write_vpos_context *vc = write_vpos_context(ctx);
struct tgsi_full_instruction inst;
tgsi_transform_immediate_decl(ctx, 0.0, 0.0, 0.0, 1.0);
tgsi_transform_output_decl(ctx, 0,
TGSI_SEMANTIC_POSITION, 0,
0);
inst = tgsi_default_full_instruction();
inst.Instruction.Opcode = TGSI_OPCODE_MOV;
inst.Instruction.NumDstRegs = 1;
tgsi_transform_dst_reg(&inst.Dst[0], TGSI_FILE_OUTPUT,
0, TGSI_WRITEMASK_XYZW);
inst.Instruction.NumSrcRegs = 1;
tgsi_transform_src_reg(&inst.Src[0], TGSI_FILE_IMMEDIATE,
vc->imm_index, TGSI_SWIZZLE_X,
TGSI_SWIZZLE_Y, TGSI_SWIZZLE_Z, TGSI_SWIZZLE_W);
ctx->emit_instruction(ctx, &inst);
}
/**
* TGSI utility writes imm(0, 0, 0, 1) to vertex position
*/
struct tgsi_token *
tgsi_write_vpos(const struct tgsi_token *tokens_in,
unsigned num_immediates)
{
struct write_vpos_context transform;
const uint num_new_tokens = 1000; /* should be enough */
const uint new_len = tgsi_num_tokens(tokens_in) + num_new_tokens;
struct tgsi_token *new_tokens;
/* setup transformation context */
memset(&transform, 0, sizeof(transform));
transform.base.prolog = write_vpos_prolog;
transform.imm_index = num_immediates;
/* allocate new tokens buffer */
new_tokens = tgsi_alloc_tokens(new_len);
if (!new_tokens)
return NULL;
/* transform the shader */
tgsi_transform_shader(tokens_in, new_tokens, new_len, &transform.base);
return new_tokens;
}
/*
* Copyright 2018 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 THE AUTHORS 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 TGSI_WRITE_VPOS_H
#define TGSI_WRITE_VPOS_H
struct tgsi_token;
struct tgsi_token *
tgsi_write_vpos(const struct tgsi_token *tokens_in,
unsigned num_immediates);
#endif /* TGSI_WRIE_VPOS_H */
......@@ -895,6 +895,7 @@ util_make_geometry_passthrough_shader(struct pipe_context *pipe,
return ureg_create_shader_and_destroy(ureg, pipe);
}
/**
* Blit from color to ZS or from ZS to color in a manner that is equivalent
* to memcpy.
......@@ -1056,3 +1057,110 @@ util_make_fs_pack_color_zs(struct pipe_context *pipe,
return ureg_create_shader_and_destroy(ureg, pipe);
}
/**
* Create passthrough tessellation control shader.
* Passthrough tessellation control shader has output of vertex shader
* as input and input of tessellation eval shader as output.
*/
void *
util_make_tess_ctrl_passthrough_shader(struct pipe_context *pipe,
uint num_vs_outputs,
uint num_tes_inputs,
const ubyte *vs_semantic_names,
const ubyte *vs_semantic_indexes,
const ubyte *tes_semantic_names,
const ubyte *tes_semantic_indexes,
const unsigned vertices_per_patch)
{
unsigned i, j;
unsigned num_regs;
struct ureg_program *ureg;
struct ureg_dst temp, addr;
struct ureg_src invocationID;
struct ureg_dst dst[PIPE_MAX_SHADER_OUTPUTS];
struct ureg_src src[PIPE_MAX_SHADER_INPUTS];
ureg = ureg_create(PIPE_SHADER_TESS_CTRL);
if (!ureg)
return NULL;
ureg_property(ureg, TGSI_PROPERTY_TCS_VERTICES_OUT, vertices_per_patch);
num_regs = 0;
for (i = 0; i < num_tes_inputs; i++) {
switch (tes_semantic_names[i]) {
case TGSI_SEMANTIC_POSITION:
case TGSI_SEMANTIC_PSIZE:
case TGSI_SEMANTIC_COLOR:
case TGSI_SEMANTIC_BCOLOR:
case TGSI_SEMANTIC_CLIPDIST:
case TGSI_SEMANTIC_CLIPVERTEX:
case TGSI_SEMANTIC_TEXCOORD:
case TGSI_SEMANTIC_FOG:
case TGSI_SEMANTIC_GENERIC:
for (j = 0; j < num_vs_outputs; j++) {
if (tes_semantic_names[i] == vs_semantic_names[j] &&
tes_semantic_indexes[i] == vs_semantic_indexes[j]) {
dst[num_regs] = ureg_DECL_output(ureg,
tes_semantic_names[i],
tes_semantic_indexes[i]);
src[num_regs] = ureg_DECL_input(ureg, vs_semantic_names[j],
vs_semantic_indexes[j],
0, 1);
if (tes_semantic_names[i] == TGSI_SEMANTIC_GENERIC ||
tes_semantic_names[i] == TGSI_SEMANTIC_POSITION) {
src[num_regs] = ureg_src_dimension(src[num_regs], 0);
dst[num_regs] = ureg_dst_dimension(dst[num_regs], 0);
}
num_regs++;
break;
}
}
break;
default:
break;
}
}
dst[num_regs] = ureg_DECL_output(ureg, TGSI_SEMANTIC_TESSOUTER,
num_regs);
src[num_regs] = ureg_DECL_constant(ureg, 0);
num_regs++;
dst[num_regs] = ureg_DECL_output(ureg, TGSI_SEMANTIC_TESSINNER,
num_regs);
src[num_regs] = ureg_DECL_constant(ureg, 1);
num_regs++;
if (vertices_per_patch > 1) {
invocationID = ureg_DECL_system_value(ureg,
TGSI_SEMANTIC_INVOCATIONID, 0);
temp = ureg_DECL_local_temporary(ureg);
addr = ureg_DECL_address(ureg);
ureg_UARL(ureg, ureg_writemask(addr, TGSI_WRITEMASK_X),
ureg_scalar(invocationID, TGSI_SWIZZLE_X));
}
for (i = 0; i < num_regs; i++) {
if (dst[i].Dimension && vertices_per_patch > 1) {
struct ureg_src addr_x = ureg_scalar(ureg_src(addr), TGSI_SWIZZLE_X);
ureg_MOV(ureg, temp, ureg_src_dimension_indirect(src[i],
addr_x, 0));
ureg_MOV(ureg, ureg_dst_dimension_indirect(dst[i],
addr_x, 0), ureg_src(temp));
}
else
ureg_MOV(ureg, dst[i], src[i]);
}
ureg_END(ureg);
return ureg_create_shader_and_destroy(ureg, pipe);
}
......@@ -159,6 +159,15 @@ util_make_fs_pack_color_zs(struct pipe_context *pipe,
enum pipe_format zs_format,
bool dst_is_color);
extern void *
util_make_tess_ctrl_passthrough_shader(struct pipe_context *pipe,
uint num_vs_outputs,
uint num_tes_inputs,
const ubyte *vs_semantic_names,
const ubyte *vs_semantic_indexes,
const ubyte *tes_semantic_names,
const ubyte *tes_semantic_indexes,
const unsigned vertices_per_patch);
#ifdef __cplusplus
}
#endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment