nv50_context.h revision 62ab89785b55e60b978dc2b32995676859299c80
1#ifndef __NV50_CONTEXT_H__ 2#define __NV50_CONTEXT_H__ 3 4#include <stdio.h> 5#include "pipe/p_context.h" 6#include "pipe/p_defines.h" 7#include "pipe/p_state.h" 8#include "pipe/p_compiler.h" 9 10#include "util/u_memory.h" 11#include "util/u_math.h" 12#include "util/u_inlines.h" 13 14#include "draw/draw_vertex.h" 15 16#include "nouveau/nouveau_winsys.h" 17#include "nouveau/nouveau_gldefs.h" 18#include "nouveau/nouveau_stateobj.h" 19#include "nouveau/nouveau_context.h" 20 21#include "nv50_screen.h" 22#include "nv50_program.h" 23 24#define NOUVEAU_ERR(fmt, args...) \ 25 fprintf(stderr, "%s:%d - "fmt, __func__, __LINE__, ##args); 26#define NOUVEAU_MSG(fmt, args...) \ 27 fprintf(stderr, "nouveau: "fmt, ##args); 28 29/* Constant buffer assignment */ 30#define NV50_CB_PMISC 0 31#define NV50_CB_PVP 1 32#define NV50_CB_PFP 2 33#define NV50_CB_PGP 3 34#define NV50_CB_AUX 4 35 36#define NV50_NEW_BLEND (1 << 0) 37#define NV50_NEW_ZSA (1 << 1) 38#define NV50_NEW_BLEND_COLOUR (1 << 2) 39#define NV50_NEW_STIPPLE (1 << 3) 40#define NV50_NEW_SCISSOR (1 << 4) 41#define NV50_NEW_VIEWPORT (1 << 5) 42#define NV50_NEW_RASTERIZER (1 << 6) 43#define NV50_NEW_FRAMEBUFFER (1 << 7) 44#define NV50_NEW_VERTPROG (1 << 8) 45#define NV50_NEW_VERTPROG_CB (1 << 9) 46#define NV50_NEW_FRAGPROG (1 << 10) 47#define NV50_NEW_FRAGPROG_CB (1 << 11) 48#define NV50_NEW_GEOMPROG (1 << 12) 49#define NV50_NEW_GEOMPROG_CB (1 << 13) 50#define NV50_NEW_ARRAYS (1 << 14) 51#define NV50_NEW_SAMPLER (1 << 15) 52#define NV50_NEW_TEXTURE (1 << 16) 53#define NV50_NEW_STENCIL_REF (1 << 17) 54 55struct nv50_blend_stateobj { 56 struct pipe_blend_state pipe; 57 struct nouveau_stateobj *so; 58}; 59 60struct nv50_zsa_stateobj { 61 struct pipe_depth_stencil_alpha_state pipe; 62 struct nouveau_stateobj *so; 63}; 64 65struct nv50_rasterizer_stateobj { 66 struct pipe_rasterizer_state pipe; 67 struct nouveau_stateobj *so; 68}; 69 70struct nv50_sampler_stateobj { 71 boolean normalized; 72 unsigned tsc[8]; 73}; 74 75struct nv50_vtxelt_stateobj { 76 struct pipe_vertex_element pipe[16]; 77 unsigned num_elements; 78 uint32_t hw[16]; 79}; 80 81static INLINE unsigned 82get_tile_height(uint32_t tile_mode) 83{ 84 return 1 << ((tile_mode & 0xf) + 2); 85} 86 87static INLINE unsigned 88get_tile_depth(uint32_t tile_mode) 89{ 90 return 1 << (tile_mode >> 4); 91} 92 93struct nv50_miptree_level { 94 int *image_offset; 95 unsigned pitch; 96 unsigned tile_mode; 97}; 98 99#define NV50_MAX_TEXTURE_LEVELS 16 100 101struct nv50_miptree { 102 struct nouveau_miptree base; 103 104 struct nv50_miptree_level level[NV50_MAX_TEXTURE_LEVELS]; 105 int image_nr; 106 int total_size; 107}; 108 109static INLINE struct nv50_miptree * 110nv50_miptree(struct pipe_texture *pt) 111{ 112 return (struct nv50_miptree *)pt; 113} 114 115struct nv50_surface { 116 struct pipe_surface base; 117}; 118 119static INLINE struct nv50_surface * 120nv50_surface(struct pipe_surface *pt) 121{ 122 return (struct nv50_surface *)pt; 123} 124 125struct nv50_state { 126 struct nouveau_stateobj *hw[64]; 127 uint64_t hw_dirty; 128 129 unsigned scissor_enabled; 130 unsigned miptree_nr[PIPE_SHADER_TYPES]; 131 struct nouveau_stateobj *vtxbuf; 132 struct nouveau_stateobj *vtxattr; 133 struct nouveau_stateobj *instbuf; 134 unsigned vtxelt_nr; 135}; 136 137struct nv50_context { 138 struct pipe_context pipe; 139 140 struct nv50_screen *screen; 141 142 struct draw_context *draw; 143 144 struct nv50_state state; 145 146 unsigned dirty; 147 struct nv50_blend_stateobj *blend; 148 struct nv50_zsa_stateobj *zsa; 149 struct nv50_rasterizer_stateobj *rasterizer; 150 struct pipe_blend_color blend_colour; 151 struct pipe_stencil_ref stencil_ref; 152 struct pipe_poly_stipple stipple; 153 struct pipe_scissor_state scissor; 154 struct pipe_viewport_state viewport; 155 struct pipe_framebuffer_state framebuffer; 156 struct nv50_program *vertprog; 157 struct nv50_program *fragprog; 158 struct nv50_program *geomprog; 159 struct pipe_buffer *constbuf[PIPE_SHADER_TYPES]; 160 struct pipe_vertex_buffer vtxbuf[PIPE_MAX_ATTRIBS]; 161 unsigned vtxbuf_nr; 162 struct nv50_vtxelt_stateobj *vtxelt; 163 struct nv50_sampler_stateobj *sampler[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS]; 164 unsigned sampler_nr[PIPE_SHADER_TYPES]; 165 struct nv50_miptree *miptree[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS]; 166 unsigned miptree_nr[PIPE_SHADER_TYPES]; 167 168 uint16_t vbo_fifo; 169}; 170 171static INLINE struct nv50_context * 172nv50_context(struct pipe_context *pipe) 173{ 174 return (struct nv50_context *)pipe; 175} 176 177extern void nv50_init_surface_functions(struct nv50_context *nv50); 178extern void nv50_init_state_functions(struct nv50_context *nv50); 179extern void nv50_init_query_functions(struct nv50_context *nv50); 180 181extern void nv50_screen_init_miptree_functions(struct pipe_screen *pscreen); 182 183extern int 184nv50_surface_do_copy(struct nv50_screen *screen, struct pipe_surface *dst, 185 int dx, int dy, struct pipe_surface *src, int sx, int sy, 186 int w, int h); 187 188/* nv50_draw.c */ 189extern struct draw_stage *nv50_draw_render_stage(struct nv50_context *nv50); 190 191/* nv50_vbo.c */ 192extern void nv50_draw_arrays(struct pipe_context *, unsigned mode, 193 unsigned start, unsigned count); 194extern void nv50_draw_arrays_instanced(struct pipe_context *, unsigned mode, 195 unsigned start, unsigned count, 196 unsigned startInstance, 197 unsigned instanceCount); 198extern void nv50_draw_elements(struct pipe_context *pipe, 199 struct pipe_buffer *indexBuffer, 200 unsigned indexSize, 201 unsigned mode, unsigned start, 202 unsigned count); 203extern void nv50_draw_elements_instanced(struct pipe_context *pipe, 204 struct pipe_buffer *indexBuffer, 205 unsigned indexSize, 206 unsigned mode, unsigned start, 207 unsigned count, 208 unsigned startInstance, 209 unsigned instanceCount); 210extern void nv50_vtxelt_construct(struct nv50_vtxelt_stateobj *cso); 211extern struct nouveau_stateobj *nv50_vbo_validate(struct nv50_context *nv50); 212 213/* nv50_clear.c */ 214extern void nv50_clear(struct pipe_context *pipe, unsigned buffers, 215 const float *rgba, double depth, unsigned stencil); 216 217/* nv50_program.c */ 218extern struct nouveau_stateobj * 219nv50_vertprog_validate(struct nv50_context *nv50); 220extern struct nouveau_stateobj * 221nv50_fragprog_validate(struct nv50_context *nv50); 222extern struct nouveau_stateobj * 223nv50_geomprog_validate(struct nv50_context *nv50); 224extern struct nouveau_stateobj * 225nv50_fp_linkage_validate(struct nv50_context *nv50); 226extern struct nouveau_stateobj * 227nv50_gp_linkage_validate(struct nv50_context *nv50); 228extern void nv50_program_destroy(struct nv50_context *nv50, 229 struct nv50_program *p); 230 231/* nv50_state_validate.c */ 232extern boolean nv50_state_validate(struct nv50_context *nv50); 233extern void nv50_state_flush_notify(struct nouveau_channel *chan); 234 235extern void nv50_so_init_sifc(struct nv50_context *nv50, 236 struct nouveau_stateobj *so, 237 struct nouveau_bo *bo, unsigned reloc, 238 unsigned offset, unsigned size); 239 240/* nv50_tex.c */ 241extern void nv50_tex_relocs(struct nv50_context *); 242extern struct nouveau_stateobj *nv50_tex_validate(struct nv50_context *); 243 244/* nv50_transfer.c */ 245extern void 246nv50_upload_sifc(struct nv50_context *nv50, 247 struct nouveau_bo *bo, unsigned dst_offset, unsigned reloc, 248 unsigned dst_format, int dst_w, int dst_h, int dst_pitch, 249 void *src, unsigned src_format, int src_pitch, 250 int x, int y, int w, int h, int cpp); 251 252/* nv50_context.c */ 253struct pipe_context * 254nv50_create(struct pipe_screen *pscreen, void *priv); 255 256#endif 257