1/*
2 * Copyright 2010 Ben Skeggs
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 */
22
23#ifndef __NV50_PROG_H__
24#define __NV50_PROG_H__
25
26struct nv50_context;
27
28#include "pipe/p_state.h"
29
30struct nv50_varying {
31   uint8_t id; /* tgsi index */
32   uint8_t hw; /* hw index, nv50 wants flat FP inputs last */
33
34   unsigned mask   : 4;
35   unsigned linear : 1;
36   unsigned pad    : 3;
37
38   ubyte sn; /* semantic name */
39   ubyte si; /* semantic index */
40};
41
42struct nv50_stream_output_state
43{
44   uint32_t ctrl;
45   uint16_t stride[4];
46   uint8_t num_attribs[4];
47   uint8_t map_size;
48   uint8_t map[128];
49};
50
51struct nv50_gmem_state {
52   unsigned valid : 1; /* whether there's something there */
53   unsigned image : 1; /* buffer or image */
54   unsigned slot  : 6; /* slot in the relevant resource arrays */
55};
56
57struct nv50_program {
58   struct pipe_shader_state pipe;
59
60   ubyte type;
61   bool translated;
62
63   uint32_t *code;
64   unsigned code_size;
65   unsigned code_base;
66   uint32_t *immd;
67   unsigned parm_size; /* size limit of uniform buffer */
68   uint32_t tls_space; /* required local memory per thread */
69
70   ubyte max_gpr; /* REG_ALLOC_TEMP */
71   ubyte max_out; /* REG_ALLOC_RESULT or FP_RESULT_COUNT */
72
73   ubyte in_nr;
74   ubyte out_nr;
75   struct nv50_varying in[16];
76   struct nv50_varying out[16];
77
78   struct {
79      uint32_t attrs[3]; /* VP_ATTR_EN_0,1 and VP_GP_BUILTIN_ATTR_EN */
80      ubyte psiz;        /* output slot of point size */
81      ubyte bfc[2];      /* indices into varying for FFC (FP) or BFC (VP) */
82      ubyte edgeflag;
83      ubyte clpd[2];     /* output slot of clip distance[i]'s 1st component */
84      ubyte clpd_nr;
85      bool need_vertex_id;
86      uint32_t clip_mode;
87      uint8_t clip_enable; /* mask of defined clip planes */
88      uint8_t cull_enable; /* mask of defined cull distances */
89   } vp;
90
91   struct {
92      uint32_t flags[2]; /* 0x19a8, 196c */
93      uint32_t interp; /* 0x1988 */
94      uint32_t colors; /* 0x1904 */
95      uint8_t has_samplemask;
96      uint8_t force_persample_interp;
97      uint8_t alphatest;
98   } fp;
99
100   struct {
101      uint32_t vert_count;
102      uint8_t prim_type; /* point, line strip or tri strip */
103      uint8_t has_layer;
104      ubyte layerid; /* hw value of layer output */
105      uint8_t has_viewport;
106      ubyte viewportid; /* hw value of viewport index output */
107   } gp;
108
109   struct {
110      uint32_t lmem_size; /* local memory (TGSI PRIVATE resource) size */
111      uint32_t smem_size; /* shared memory (TGSI LOCAL resource) size */
112      struct nv50_gmem_state gmem[NV50_MAX_GLOBALS];
113   } cp;
114
115   bool mul_zero_wins;
116
117   void *fixups; /* relocation records */
118   void *interps; /* interpolation records */
119
120   struct nouveau_heap *mem;
121
122   struct nv50_stream_output_state *so;
123};
124
125bool nv50_program_translate(struct nv50_program *, uint16_t chipset,
126                            struct util_debug_callback *);
127bool nv50_program_upload_code(struct nv50_context *, struct nv50_program *);
128void nv50_program_destroy(struct nv50_context *, struct nv50_program *);
129
130#endif /* __NV50_PROG_H__ */
131