Path: blob/21.2-virgl/src/gallium/auxiliary/tgsi/tgsi_vpos.c
4565 views
/*1* Copyright 2018 VMware, Inc.2* All Rights Reserved.3*4* Permission is hereby granted, free of charge, to any person obtaining a5* copy of this software and associated documentation files (the6* "Software"), to deal in the Software without restriction, including7* without limitation the rights to use, copy, modify, merge, publish,8* distribute, sub license, and/or sell copies of the Software, and to9* permit persons to whom the Software is furnished to do so, subject to10* the following conditions:11*12* The above copyright notice and this permission notice (including the13* next paragraph) shall be included in all copies or substantial portions14* of the Software.15*16* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS17* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF18* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.19* IN NO EVENT SHALL THE AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR20* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,21* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE22* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.23*/242526/**27* TGSI utility transforms the shader to write imm(0, 0, 0, 1) to vertex28* position29*/3031#include "util/u_debug.h"32#include "util/u_math.h"33#include "tgsi_vpos.h"34#include "tgsi_transform.h"35#include "tgsi_dump.h"36#include "pipe/p_state.h"373839struct write_vpos_context40{41struct tgsi_transform_context base;42unsigned imm_index;43};444546static inline struct write_vpos_context *47write_vpos_context(struct tgsi_transform_context *ctx)48{49return (struct write_vpos_context *) ctx;50}515253/**54* TGSI transform prolog callback.55*/56static void57write_vpos_prolog(struct tgsi_transform_context *ctx)58{59struct write_vpos_context *vc = write_vpos_context(ctx);60struct tgsi_full_instruction inst;6162tgsi_transform_immediate_decl(ctx, 0.0, 0.0, 0.0, 1.0);63tgsi_transform_output_decl(ctx, 0,64TGSI_SEMANTIC_POSITION, 0,650);66inst = tgsi_default_full_instruction();67inst.Instruction.Opcode = TGSI_OPCODE_MOV;68inst.Instruction.NumDstRegs = 1;69tgsi_transform_dst_reg(&inst.Dst[0], TGSI_FILE_OUTPUT,700, TGSI_WRITEMASK_XYZW);71inst.Instruction.NumSrcRegs = 1;72tgsi_transform_src_reg(&inst.Src[0], TGSI_FILE_IMMEDIATE,73vc->imm_index, TGSI_SWIZZLE_X,74TGSI_SWIZZLE_Y, TGSI_SWIZZLE_Z, TGSI_SWIZZLE_W);75ctx->emit_instruction(ctx, &inst);76}777879/**80* TGSI utility writes imm(0, 0, 0, 1) to vertex position81*/82struct tgsi_token *83tgsi_write_vpos(const struct tgsi_token *tokens_in,84unsigned num_immediates)85{86struct write_vpos_context transform;87const uint num_new_tokens = 1000; /* should be enough */88const uint new_len = tgsi_num_tokens(tokens_in) + num_new_tokens;89struct tgsi_token *new_tokens;9091/* setup transformation context */92memset(&transform, 0, sizeof(transform));93transform.base.prolog = write_vpos_prolog;9495transform.imm_index = num_immediates;9697/* allocate new tokens buffer */98new_tokens = tgsi_alloc_tokens(new_len);99if (!new_tokens)100return NULL;101102/* transform the shader */103tgsi_transform_shader(tokens_in, new_tokens, new_len, &transform.base);104105return new_tokens;106}107108109110111