nv04_render.c revision 19c46d3d7bd2dc190bb83855c4ffa65a3bc830d7
1/* 2 * Copyright (C) 2009 Francisco Jerez. 3 * All Rights Reserved. 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining 6 * a 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, sublicense, 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: 12 * 13 * The above copyright notice and this permission notice (including the 14 * next paragraph) shall be included in all copies or substantial 15 * portions of the Software. 16 * 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE 21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 * 25 */ 26 27#include "nouveau_driver.h" 28#include "nouveau_context.h" 29#include "nouveau_util.h" 30#include "nv04_3d.xml.h" 31#include "nv04_driver.h" 32 33#include "tnl/tnl.h" 34#include "tnl/t_pipeline.h" 35#include "tnl/t_vertex.h" 36 37#define NUM_VERTEX_ATTRS 6 38 39static void 40swtnl_update_viewport(struct gl_context *ctx) 41{ 42 float *viewport = to_nv04_context(ctx)->viewport; 43 struct gl_framebuffer *fb = ctx->DrawBuffer; 44 45 get_viewport_scale(ctx, viewport); 46 get_viewport_translate(ctx, &viewport[MAT_TX]); 47 48 /* It wants normalized Z coordinates. */ 49 viewport[MAT_SZ] /= fb->_DepthMaxF; 50 viewport[MAT_TZ] /= fb->_DepthMaxF; 51} 52 53static void 54swtnl_emit_attr(struct gl_context *ctx, struct tnl_attr_map *m, int attr, int emit) 55{ 56 TNLcontext *tnl = TNL_CONTEXT(ctx); 57 58 if (tnl->render_inputs_bitset & BITFIELD64_BIT(attr)) 59 *m = (struct tnl_attr_map) { 60 .attrib = attr, 61 .format = emit, 62 }; 63 else 64 *m = (struct tnl_attr_map) { 65 .format = EMIT_PAD, 66 .offset = _tnl_format_info[emit].attrsize, 67 }; 68} 69 70static void 71swtnl_choose_attrs(struct gl_context *ctx) 72{ 73 TNLcontext *tnl = TNL_CONTEXT(ctx); 74 struct nouveau_grobj *fahrenheit = nv04_context_engine(ctx); 75 struct nv04_context *nctx = to_nv04_context(ctx); 76 static struct tnl_attr_map map[NUM_VERTEX_ATTRS]; 77 int n = 0; 78 79 tnl->vb.AttribPtr[VERT_ATTRIB_POS] = tnl->vb.NdcPtr; 80 81 swtnl_emit_attr(ctx, &map[n++], _TNL_ATTRIB_POS, EMIT_4F_VIEWPORT); 82 swtnl_emit_attr(ctx, &map[n++], _TNL_ATTRIB_COLOR0, EMIT_4UB_4F_BGRA); 83 swtnl_emit_attr(ctx, &map[n++], _TNL_ATTRIB_COLOR1, EMIT_3UB_3F_BGR); 84 swtnl_emit_attr(ctx, &map[n++], _TNL_ATTRIB_FOG, EMIT_1UB_1F); 85 swtnl_emit_attr(ctx, &map[n++], _TNL_ATTRIB_TEX0, EMIT_2F); 86 if (nv04_mtex_engine(fahrenheit)) 87 swtnl_emit_attr(ctx, &map[n++], _TNL_ATTRIB_TEX1, EMIT_2F); 88 89 swtnl_update_viewport(ctx); 90 91 _tnl_install_attrs(ctx, map, n, nctx->viewport, 0); 92} 93 94/* TnL renderer entry points */ 95 96static void 97swtnl_start(struct gl_context *ctx) 98{ 99 swtnl_choose_attrs(ctx); 100} 101 102static void 103swtnl_finish(struct gl_context *ctx) 104{ 105 FIRE_RING(context_chan(ctx)); 106} 107 108static void 109swtnl_primitive(struct gl_context *ctx, GLenum mode) 110{ 111} 112 113static void 114swtnl_reset_stipple(struct gl_context *ctx) 115{ 116} 117 118/* Primitive rendering */ 119 120#define BEGIN_PRIMITIVE(n) \ 121 struct nouveau_channel *chan = context_chan(ctx); \ 122 struct nouveau_grobj *fahrenheit = nv04_context_engine(ctx); \ 123 int vertex_len = TNL_CONTEXT(ctx)->clipspace.vertex_size / 4; \ 124 \ 125 if (nv04_mtex_engine(fahrenheit)) \ 126 BEGIN_RING(chan, fahrenheit, \ 127 NV04_MULTITEX_TRIANGLE_TLMTVERTEX_SX(0), \ 128 n * vertex_len); \ 129 else \ 130 BEGIN_RING(chan, fahrenheit, \ 131 NV04_TEXTURED_TRIANGLE_TLVERTEX_SX(0), \ 132 n * vertex_len); \ 133 134#define OUT_VERTEX(i) \ 135 OUT_RINGp(chan, _tnl_get_vertex(ctx, i), vertex_len); 136 137#define END_PRIMITIVE(draw) \ 138 if (nv04_mtex_engine(fahrenheit)) { \ 139 BEGIN_RING(chan, fahrenheit, \ 140 NV04_MULTITEX_TRIANGLE_DRAWPRIMITIVE(0), 1); \ 141 OUT_RING(chan, draw); \ 142 } else { \ 143 BEGIN_RING(chan, fahrenheit, \ 144 NV04_TEXTURED_TRIANGLE_DRAWPRIMITIVE(0), 1); \ 145 OUT_RING(chan, draw); \ 146 } 147 148static void 149swtnl_points(struct gl_context *ctx, GLuint first, GLuint last) 150{ 151} 152 153static void 154swtnl_line(struct gl_context *ctx, GLuint v1, GLuint v2) 155{ 156} 157 158static void 159swtnl_triangle(struct gl_context *ctx, GLuint v1, GLuint v2, GLuint v3) 160{ 161 BEGIN_PRIMITIVE(3); 162 OUT_VERTEX(v1); 163 OUT_VERTEX(v2); 164 OUT_VERTEX(v3); 165 END_PRIMITIVE(0x102); 166} 167 168static void 169swtnl_quad(struct gl_context *ctx, GLuint v1, GLuint v2, GLuint v3, GLuint v4) 170{ 171 BEGIN_PRIMITIVE(4); 172 OUT_VERTEX(v1); 173 OUT_VERTEX(v2); 174 OUT_VERTEX(v3); 175 OUT_VERTEX(v4); 176 END_PRIMITIVE(0x213103); 177} 178 179/* TnL initialization. */ 180void 181nv04_render_init(struct gl_context *ctx) 182{ 183 TNLcontext *tnl = TNL_CONTEXT(ctx); 184 185 tnl->Driver.RunPipeline = _tnl_run_pipeline; 186 tnl->Driver.Render.Interp = _tnl_interp; 187 tnl->Driver.Render.CopyPV = _tnl_copy_pv; 188 tnl->Driver.Render.ClippedPolygon = _tnl_RenderClippedPolygon; 189 tnl->Driver.Render.ClippedLine = _tnl_RenderClippedLine; 190 tnl->Driver.Render.BuildVertices = _tnl_build_vertices; 191 192 tnl->Driver.Render.Start = swtnl_start; 193 tnl->Driver.Render.Finish = swtnl_finish; 194 tnl->Driver.Render.PrimitiveNotify = swtnl_primitive; 195 tnl->Driver.Render.ResetLineStipple = swtnl_reset_stipple; 196 197 tnl->Driver.Render.Points = swtnl_points; 198 tnl->Driver.Render.Line = swtnl_line; 199 tnl->Driver.Render.Triangle = swtnl_triangle; 200 tnl->Driver.Render.Quad = swtnl_quad; 201 202 _tnl_need_projected_coords(ctx, GL_TRUE); 203 _tnl_init_vertices(ctx, tnl->vb.Size, 204 NUM_VERTEX_ATTRS * 4 * sizeof(GLfloat)); 205 _tnl_allow_pixel_fog(ctx, GL_FALSE); 206 _tnl_wakeup(ctx); 207} 208 209void 210nv04_render_destroy(struct gl_context *ctx) 211{ 212} 213