2 * Copyright 2018 VMware, Inc.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sub license, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
20 * IN NO EVENT SHALL THE AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR
21 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 * TGSI utility transforms the shader to write imm(0, 0, 0, 1) to vertex
32 #include "util/u_debug.h"
33 #include "util/u_math.h"
34 #include "tgsi_vpos.h"
35 #include "tgsi_transform.h"
36 #include "tgsi_dump.h"
37 #include "pipe/p_state.h"
40 struct write_vpos_context
42 struct tgsi_transform_context base
;
47 static inline struct write_vpos_context
*
48 write_vpos_context(struct tgsi_transform_context
*ctx
)
50 return (struct write_vpos_context
*) ctx
;
55 * TGSI transform prolog callback.
58 write_vpos_prolog(struct tgsi_transform_context
*ctx
)
60 struct write_vpos_context
*vc
= write_vpos_context(ctx
);
61 struct tgsi_full_instruction inst
;
63 tgsi_transform_immediate_decl(ctx
, 0.0, 0.0, 0.0, 1.0);
64 tgsi_transform_output_decl(ctx
, 0,
65 TGSI_SEMANTIC_POSITION
, 0,
67 inst
= tgsi_default_full_instruction();
68 inst
.Instruction
.Opcode
= TGSI_OPCODE_MOV
;
69 inst
.Instruction
.NumDstRegs
= 1;
70 tgsi_transform_dst_reg(&inst
.Dst
[0], TGSI_FILE_OUTPUT
,
71 0, TGSI_WRITEMASK_XYZW
);
72 inst
.Instruction
.NumSrcRegs
= 1;
73 tgsi_transform_src_reg(&inst
.Src
[0], TGSI_FILE_IMMEDIATE
,
74 vc
->imm_index
, TGSI_SWIZZLE_X
,
75 TGSI_SWIZZLE_Y
, TGSI_SWIZZLE_Z
, TGSI_SWIZZLE_W
);
76 ctx
->emit_instruction(ctx
, &inst
);
81 * TGSI utility writes imm(0, 0, 0, 1) to vertex position
84 tgsi_write_vpos(const struct tgsi_token
*tokens_in
,
85 unsigned num_immediates
)
87 struct write_vpos_context transform
;
88 const uint num_new_tokens
= 1000; /* should be enough */
89 const uint new_len
= tgsi_num_tokens(tokens_in
) + num_new_tokens
;
90 struct tgsi_token
*new_tokens
;
92 /* setup transformation context */
93 memset(&transform
, 0, sizeof(transform
));
94 transform
.base
.prolog
= write_vpos_prolog
;
96 transform
.imm_index
= num_immediates
;
98 /* allocate new tokens buffer */
99 new_tokens
= tgsi_alloc_tokens(new_len
);
103 /* transform the shader */
104 tgsi_transform_shader(tokens_in
, new_tokens
, new_len
, &transform
.base
);