| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 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" |
| 38 |
|
| 39 |
|
| 40 |
struct write_vpos_context |
| 41 |
{ |
| 42 |
struct tgsi_transform_context base; |
| 43 |
unsigned imm_index; |
| 44 |
}; |
| 45 |
|
| 46 |
|
| 47 |
static inline struct write_vpos_context * |
| 48 |
write_vpos_context(struct tgsi_transform_context *ctx) |
| 49 |
{ |
| 50 |
return (struct write_vpos_context *) ctx; |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
static void |
| 58 |
write_vpos_prolog(struct tgsi_transform_context *ctx) |
| 59 |
{ |
| 60 |
struct write_vpos_context *vc = write_vpos_context(ctx); |
| 61 |
struct tgsi_full_instruction inst; |
| 62 |
|
| 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, |
| 66 |
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); |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
struct tgsi_token * |
| 84 |
tgsi_write_vpos(const struct tgsi_token *tokens_in, |
| 85 |
unsigned num_immediates) |
| 86 |
{ |
| 87 |
struct write_vpos_context transform; |
| 88 |
const unsigned num_new_tokens = 1000; |
| 89 |
const unsigned new_len = tgsi_num_tokens(tokens_in) + num_new_tokens; |
| 90 |
|
| 91 |
|
| 92 |
memset(&transform, 0, sizeof(transform)); |
| 93 |
transform.base.prolog = write_vpos_prolog; |
| 94 |
|
| 95 |
transform.imm_index = num_immediates; |
| 96 |
|
| 97 |
return tgsi_transform_shader(tokens_in, new_len, &transform.base); |
| 98 |
} |
| 99 |
|
| 100 |
|