static void setup_hierz_buffer(struct gl_context *ctx) { struct nouveau_channel *chan = context_chan(ctx); struct nouveau_grobj *celsius = context_eng3d(ctx); struct nouveau_bo_context *bctx = context_bctx(ctx, HIERZ); struct gl_framebuffer *fb = ctx->DrawBuffer; struct nouveau_framebuffer *nfb = to_nouveau_framebuffer(fb); unsigned pitch = align(fb->Width, 128), height = align(fb->Height, 2), size = pitch * height; if (!nfb->hierz.bo || nfb->hierz.bo->size != size) { nouveau_bo_ref(NULL, &nfb->hierz.bo); nouveau_bo_new_tile(context_dev(ctx), NOUVEAU_BO_VRAM, 0, size, 0, NOUVEAU_BO_TILE_ZETA, &nfb->hierz.bo); } nouveau_bo_markl(bctx, celsius, NV17_3D_HIERZ_OFFSET, nfb->hierz.bo, 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_RDWR); WAIT_RING(chan, 9); BEGIN_RING(chan, celsius, NV17_3D_HIERZ_WINDOW_X, 4); OUT_RINGf(chan, - 1792); OUT_RINGf(chan, - 2304 + fb->Height); OUT_RINGf(chan, fb->_DepthMaxF / 2); OUT_RINGf(chan, 0); BEGIN_RING(chan, celsius, NV17_3D_HIERZ_PITCH, 1); OUT_RING(chan, pitch); BEGIN_RING(chan, celsius, NV17_3D_HIERZ_ENABLE, 1); OUT_RING(chan, 1); }
void nv10_emit_viewport(struct gl_context *ctx, int emit) { struct nouveau_channel *chan = context_chan(ctx); struct nouveau_grobj *celsius = context_eng3d(ctx); struct gl_viewport_attrib *vp = &ctx->Viewport; struct gl_framebuffer *fb = ctx->DrawBuffer; float a[4] = {}; get_viewport_translate(ctx, a); a[0] -= 2048; a[1] -= 2048; if (nv10_use_viewport_zclear(ctx)) a[2] = nv10_transform_depth(ctx, (vp->Far + vp->Near) / 2); BEGIN_RING(chan, celsius, NV10_3D_VIEWPORT_TRANSLATE_X, 4); OUT_RINGp(chan, a, 4); BEGIN_RING(chan, celsius, NV10_3D_VIEWPORT_CLIP_HORIZ(0), 1); OUT_RING(chan, (fb->Width - 1) << 16 | 0x08000800); BEGIN_RING(chan, celsius, NV10_3D_VIEWPORT_CLIP_VERT(0), 1); OUT_RING(chan, (fb->Height - 1) << 16 | 0x08000800); context_dirty(ctx, PROJECTION); }
void nv20_emit_tex_gen(GLcontext *ctx, int emit) { const int i = emit - NOUVEAU_STATE_TEX_GEN0; struct nouveau_context *nctx = to_nouveau_context(ctx); struct nouveau_channel *chan = context_chan(ctx); struct nouveau_grobj *kelvin = context_eng3d(ctx); struct gl_texture_unit *unit = &ctx->Texture.Unit[i]; int j; for (j = 0; j < 4; j++) { if (nctx->fallback == HWTNL && (unit->TexGenEnabled & 1 << j)) { struct gl_texgen *coord = get_texgen_coord(unit, j); float *k = get_texgen_coeff(coord); if (k) { BEGIN_RING(chan, kelvin, TX_GEN_COEFF(i, j), 4); OUT_RINGp(chan, k, 4); } BEGIN_RING(chan, kelvin, TX_GEN_MODE(i, j), 1); OUT_RING(chan, nvgl_texgen_mode(coord->Mode)); } else { BEGIN_RING(chan, kelvin, TX_GEN_MODE(i, j), 1); OUT_RING(chan, 0); } } }
static void nv17_zclear(struct gl_context *ctx, GLbitfield *buffers) { struct nouveau_context *nctx = to_nouveau_context(ctx); struct nouveau_channel *chan = context_chan(ctx); struct nouveau_grobj *celsius = context_eng3d(ctx); struct nouveau_framebuffer *nfb = to_nouveau_framebuffer( ctx->DrawBuffer); struct nouveau_surface *s = &to_nouveau_renderbuffer( nfb->base.Attachment[BUFFER_DEPTH].Renderbuffer)->surface; /* Clear the hierarchical depth buffer */ BEGIN_RING(chan, celsius, NV17_3D_HIERZ_FILL_VALUE, 1); OUT_RING(chan, pack_zs_f(s->format, ctx->Depth.Clear, 0)); BEGIN_RING(chan, celsius, NV17_3D_HIERZ_BUFFER_CLEAR, 1); OUT_RING(chan, 1); /* Mark the depth buffer as cleared */ if (use_fast_zclear(ctx, *buffers)) { if (nctx->hierz.clear_seq) *buffers &= ~BUFFER_BIT_DEPTH; nfb->hierz.clear_value = pack_zs_f(s->format, ctx->Depth.Clear, 0); nctx->hierz.clear_seq++; context_dirty(ctx, ZCLEAR); } }
static void nv20_render_set_format(struct gl_context *ctx) { struct nouveau_render_state *render = to_render_state(ctx); struct nouveau_channel *chan = context_chan(ctx); struct nouveau_grobj *kelvin = context_eng3d(ctx); int i, attr, hw_format; FOR_EACH_ATTR(render, i, attr) { if (attr >= 0) { struct nouveau_array *a = &render->attrs[attr]; hw_format = a->stride << 8 | a->fields << 4 | get_hw_format(a->type); } else { /* Unused attribute. */ hw_format = NV20_3D_VTXBUF_FMT_TYPE_FLOAT; } BEGIN_RING(chan, kelvin, NV20_3D_VTXBUF_FMT(i), 1); OUT_RING(chan, hw_format); } }
static struct gl_context * nv10_context_create(struct nouveau_screen *screen, const struct gl_config *visual, struct gl_context *share_ctx) { struct nouveau_context *nctx; struct gl_context *ctx; unsigned celsius_class; int ret; nctx = CALLOC_STRUCT(nouveau_context); if (!nctx) return NULL; ctx = &nctx->base; if (!nouveau_context_init(ctx, screen, visual, share_ctx)) goto fail; driInitExtensions(ctx, nv10_extensions, GL_FALSE); /* GL constants. */ ctx->Const.MaxTextureLevels = 12; ctx->Const.MaxTextureCoordUnits = NV10_TEXTURE_UNITS; ctx->Const.MaxTextureImageUnits = NV10_TEXTURE_UNITS; ctx->Const.MaxTextureUnits = NV10_TEXTURE_UNITS; ctx->Const.MaxTextureMaxAnisotropy = 2; ctx->Const.MaxTextureLodBias = 15; ctx->Driver.Clear = nv10_clear; /* 2D engine. */ ret = nv04_surface_init(ctx); if (!ret) goto fail; /* 3D engine. */ if (context_chipset(ctx) >= 0x17) celsius_class = NV17_3D; else if (context_chipset(ctx) >= 0x11) celsius_class = NV11_3D; else celsius_class = NV10_3D; ret = nouveau_grobj_alloc(context_chan(ctx), 0xbeef0001, celsius_class, &nctx->hw.eng3d); if (ret) goto fail; nv10_hwctx_init(ctx); nv10_vbo_init(ctx); nv10_swtnl_init(ctx); return ctx; fail: nv10_context_destroy(ctx); return NULL; }
void nv10_emit_front_face(GLcontext *ctx, int emit) { struct nouveau_channel *chan = context_chan(ctx); struct nouveau_grobj *celsius = context_eng3d(ctx); BEGIN_RING(chan, celsius, NV10TCL_FRONT_FACE, 1); OUT_RING(chan, ctx->Polygon.FrontFace == GL_CW ? NV10TCL_FRONT_FACE_CW : NV10TCL_FRONT_FACE_CCW); }
void nv10_emit_point_mode(GLcontext *ctx, int emit) { struct nouveau_channel *chan = context_chan(ctx); struct nouveau_grobj *celsius = context_eng3d(ctx); BEGIN_RING(chan, celsius, NV10TCL_POINT_SIZE, 1); OUT_RING(chan, (uint32_t)(ctx->Point.Size * 8)); BEGIN_RING(chan, celsius, NV10TCL_POINT_SMOOTH_ENABLE, 1); OUT_RING(chan, ctx->Point.SmoothFlag ? 1 : 0); }
void nv20_emit_point_mode(GLcontext *ctx, int emit) { struct nouveau_channel *chan = context_chan(ctx); struct nouveau_grobj *kelvin = context_eng3d(ctx); BEGIN_RING(chan, kelvin, NV20TCL_POINT_SIZE, 1); if (context_chipset(ctx) >= 0x25) OUT_RINGf(chan, ctx->Point.Size); else OUT_RING(chan, (uint32_t)(ctx->Point.Size * 8)); }
void nv04_emit_tex_env(struct gl_context *ctx, int emit) { const int i = emit - NOUVEAU_STATE_TEX_ENV0; struct nouveau_channel *chan = context_chan(ctx); struct nouveau_grobj *fahrenheit = nv04_context_engine(ctx); struct combiner_state rc_a = {}, rc_c = {}; if (!nv04_mtex_engine(fahrenheit)) { context_dirty(ctx, BLEND); return; } /* Compute the new combiner state. */ if (ctx->Texture.Unit[i]._ReallyEnabled) { INIT_COMBINER(A, ctx, &rc_a, i); setup_combiner(&rc_a); INIT_COMBINER(RGB, ctx, &rc_c, i); setup_combiner(&rc_c); } else { if (i == 0) { INPUT_SRC(&rc_a, 0, PRIMARY_COLOR, 0); INPUT_SRC(&rc_c, 0, PRIMARY_COLOR, 0); } else { INPUT_SRC(&rc_a, 0, PREVIOUS, 0); INPUT_SRC(&rc_c, 0, PREVIOUS, 0); } INPUT_SRC(&rc_a, 1, ZERO, INVERT); INPUT_SRC(&rc_c, 1, ZERO, INVERT); INPUT_SRC(&rc_a, 2, ZERO, 0); INPUT_SRC(&rc_c, 2, ZERO, 0); INPUT_SRC(&rc_a, 3, ZERO, 0); INPUT_SRC(&rc_c, 3, ZERO, 0); UNSIGNED_OP(&rc_a); UNSIGNED_OP(&rc_c); } /* Write the register combiner state out to the hardware. */ BEGIN_RING(chan, fahrenheit, NV04_MULTITEX_TRIANGLE_COMBINE_ALPHA(i), 2); OUT_RING(chan, rc_a.hw); OUT_RING(chan, rc_c.hw); BEGIN_RING(chan, fahrenheit, NV04_MULTITEX_TRIANGLE_COMBINE_FACTOR, 1); OUT_RING(chan, pack_rgba_f(MESA_FORMAT_ARGB8888, ctx->Texture.Unit[0].EnvColor)); }
void nv10_emit_scissor(struct gl_context *ctx, int emit) { struct nouveau_channel *chan = context_chan(ctx); struct nouveau_grobj *celsius = context_eng3d(ctx); int x, y, w, h; get_scissors(ctx->DrawBuffer, &x, &y, &w, &h); BEGIN_RING(chan, celsius, NV10_3D_RT_HORIZ, 2); OUT_RING(chan, w << 16 | x); OUT_RING(chan, h << 16 | y); }
void nv10_emit_polygon_mode(GLcontext *ctx, int emit) { struct nouveau_channel *chan = context_chan(ctx); struct nouveau_grobj *celsius = context_eng3d(ctx); BEGIN_RING(chan, celsius, NV10TCL_POLYGON_MODE_FRONT, 2); OUT_RING(chan, nvgl_polygon_mode(ctx->Polygon.FrontMode)); OUT_RING(chan, nvgl_polygon_mode(ctx->Polygon.BackMode)); BEGIN_RING(chan, celsius, NV10TCL_POLYGON_SMOOTH_ENABLE, 1); OUT_RING(chan, ctx->Polygon.SmoothFlag ? 1 : 0); }
void nv10_emit_line_mode(GLcontext *ctx, int emit) { struct nouveau_channel *chan = context_chan(ctx); struct nouveau_grobj *celsius = context_eng3d(ctx); GLboolean smooth = ctx->Line.SmoothFlag && ctx->Hint.LineSmooth == GL_NICEST; BEGIN_RING(chan, celsius, NV10TCL_LINE_WIDTH, 1); OUT_RING(chan, MAX2(smooth ? 0 : 1, ctx->Line.Width) * 8); BEGIN_RING(chan, celsius, NV10TCL_LINE_SMOOTH_ENABLE, 1); OUT_RING(chan, smooth ? 1 : 0); }
void nv20_emit_framebuffer(GLcontext *ctx, int emit) { struct nouveau_channel *chan = context_chan(ctx); struct nouveau_grobj *kelvin = context_eng3d(ctx); struct nouveau_bo_context *bctx = context_bctx(ctx, FRAMEBUFFER); struct gl_framebuffer *fb = ctx->DrawBuffer; struct nouveau_surface *s; unsigned rt_format = NV20TCL_RT_FORMAT_TYPE_LINEAR; unsigned rt_pitch = 0, zeta_pitch = 0; unsigned bo_flags = NOUVEAU_BO_VRAM | NOUVEAU_BO_RDWR; if (fb->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) return; /* Render target */ if (fb->_ColorDrawBuffers[0]) { s = &to_nouveau_renderbuffer( fb->_ColorDrawBuffers[0])->surface; rt_format |= get_rt_format(s->format); rt_pitch = s->pitch; nouveau_bo_markl(bctx, kelvin, NV20TCL_COLOR_OFFSET, s->bo, 0, bo_flags); } /* depth/stencil */ if (fb->_DepthBuffer) { s = &to_nouveau_renderbuffer( fb->_DepthBuffer->Wrapped)->surface; rt_format |= get_rt_format(s->format); zeta_pitch = s->pitch; nouveau_bo_markl(bctx, kelvin, NV20TCL_ZETA_OFFSET, s->bo, 0, bo_flags); } else { rt_format |= get_rt_format(MESA_FORMAT_Z24_S8); zeta_pitch = rt_pitch; } BEGIN_RING(chan, kelvin, NV20TCL_RT_FORMAT, 2); OUT_RING(chan, rt_format); OUT_RING(chan, zeta_pitch << 16 | rt_pitch); /* Recompute the viewport/scissor state. */ context_dirty(ctx, VIEWPORT); context_dirty(ctx, SCISSOR); }
void nv04_emit_framebuffer(GLcontext *ctx, int emit) { struct nouveau_channel *chan = context_chan(ctx); struct nouveau_hw_state *hw = &to_nouveau_context(ctx)->hw; struct nouveau_grobj *surf3d = hw->surf3d; struct nouveau_bo_context *bctx = context_bctx(ctx, FRAMEBUFFER); struct gl_framebuffer *fb = ctx->DrawBuffer; struct nouveau_surface *s; uint32_t rt_format = NV04_CONTEXT_SURFACES_3D_FORMAT_TYPE_PITCH; uint32_t rt_pitch = 0, zeta_pitch = 0; unsigned bo_flags = NOUVEAU_BO_VRAM | NOUVEAU_BO_RDWR; if (fb->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) return; /* Render target */ if (fb->_NumColorDrawBuffers) { s = &to_nouveau_renderbuffer( fb->_ColorDrawBuffers[0])->surface; rt_format |= get_rt_format(s->format); zeta_pitch = rt_pitch = s->pitch; nouveau_bo_markl(bctx, surf3d, NV04_CONTEXT_SURFACES_3D_OFFSET_COLOR, s->bo, 0, bo_flags); } /* depth/stencil */ if (fb->_DepthBuffer) { s = &to_nouveau_renderbuffer( fb->_DepthBuffer->Wrapped)->surface; zeta_pitch = s->pitch; nouveau_bo_markl(bctx, surf3d, NV04_CONTEXT_SURFACES_3D_OFFSET_ZETA, s->bo, 0, bo_flags); } BEGIN_RING(chan, surf3d, NV04_CONTEXT_SURFACES_3D_FORMAT, 1); OUT_RING(chan, rt_format); BEGIN_RING(chan, surf3d, NV04_CONTEXT_SURFACES_3D_PITCH, 1); OUT_RING(chan, zeta_pitch << 16 | rt_pitch); /* Recompute the scissor state. */ context_dirty(ctx, SCISSOR); }
void nv10_emit_cull_face(GLcontext *ctx, int emit) { struct nouveau_channel *chan = context_chan(ctx); struct nouveau_grobj *celsius = context_eng3d(ctx); GLenum mode = ctx->Polygon.CullFaceMode; BEGIN_RING(chan, celsius, NV10TCL_CULL_FACE_ENABLE, 1); OUT_RING(chan, ctx->Polygon.CullFlag ? 1 : 0); BEGIN_RING(chan, celsius, NV10TCL_CULL_FACE, 1); OUT_RING(chan, (mode == GL_FRONT ? NV10TCL_CULL_FACE_FRONT : mode == GL_BACK ? NV10TCL_CULL_FACE_BACK : NV10TCL_CULL_FACE_FRONT_AND_BACK)); }
void nv10_emit_polygon_offset(GLcontext *ctx, int emit) { struct nouveau_channel *chan = context_chan(ctx); struct nouveau_grobj *celsius = context_eng3d(ctx); BEGIN_RING(chan, celsius, NV10TCL_POLYGON_OFFSET_POINT_ENABLE, 3); OUT_RING(chan, ctx->Polygon.OffsetPoint ? 1 : 0); OUT_RING(chan, ctx->Polygon.OffsetLine ? 1 : 0); OUT_RING(chan, ctx->Polygon.OffsetFill ? 1 : 0); BEGIN_RING(chan, celsius, NV10TCL_POLYGON_OFFSET_FACTOR, 2); OUT_RINGf(chan, ctx->Polygon.OffsetFactor); OUT_RINGf(chan, ctx->Polygon.OffsetUnits); }
static void nouveau_flush(GLcontext *ctx) { struct nouveau_context *nctx = to_nouveau_context(ctx); struct nouveau_channel *chan = context_chan(ctx); FIRE_RING(chan); if (ctx->DrawBuffer->Name == 0 && ctx->DrawBuffer->_ColorDrawBufferIndexes[0] == BUFFER_FRONT_LEFT) { __DRIscreen *screen = nctx->screen->dri_screen; __DRIdri2LoaderExtension *dri2 = screen->dri2.loader; __DRIdrawable *drawable = nctx->dri_context->driDrawablePriv; dri2->flushFrontBuffer(drawable, drawable->loaderPrivate); } }
void nv04_emit_scissor(GLcontext *ctx, int emit) { struct nouveau_channel *chan = context_chan(ctx); struct nouveau_hw_state *hw = &to_nouveau_context(ctx)->hw; struct nouveau_grobj *surf3d = hw->surf3d; int x, y, w, h; get_scissors(ctx->DrawBuffer, &x, &y, &w, &h); BEGIN_RING(chan, surf3d, NV04_CONTEXT_SURFACES_3D_CLIP_HORIZONTAL, 2); OUT_RING(chan, w << 16 | x); OUT_RING(chan, h << 16 | y); /* Messing with surf3d invalidates some engine state. */ context_dirty(ctx, CONTROL); context_dirty(ctx, BLEND); }
void nv20_emit_tex_shader(GLcontext *ctx, int emit) { struct nouveau_channel *chan = context_chan(ctx); struct nouveau_grobj *kelvin = context_eng3d(ctx); uint32_t tx_shader_op = 0; int i; for (i = 0; i < NV20_TEXTURE_UNITS; i++) { if (!ctx->Texture.Unit[i]._ReallyEnabled) continue; tx_shader_op |= NV20TCL_TX_SHADER_OP_TX0_TEXTURE_2D << 5 * i; } BEGIN_RING(chan, kelvin, NV20TCL_TX_SHADER_OP, 1); OUT_RING(chan, tx_shader_op); }
void nv20_emit_viewport(GLcontext *ctx, int emit) { struct nouveau_channel *chan = context_chan(ctx); struct nouveau_grobj *kelvin = context_eng3d(ctx); struct gl_framebuffer *fb = ctx->DrawBuffer; float a[4] = {}; get_viewport_translate(ctx, a); BEGIN_RING(chan, kelvin, NV20TCL_VIEWPORT_TRANSLATE_X, 4); OUT_RINGp(chan, a, 4); BEGIN_RING(chan, kelvin, NV20TCL_VIEWPORT_CLIP_HORIZ(0), 1); OUT_RING(chan, (fb->Width - 1) << 16); BEGIN_RING(chan, kelvin, NV20TCL_VIEWPORT_CLIP_VERT(0), 1); OUT_RING(chan, (fb->Height - 1) << 16); context_dirty(ctx, PROJECTION); }
void nv20_emit_tex_mat(GLcontext *ctx, int emit) { const int i = emit - NOUVEAU_STATE_TEX_MAT0; struct nouveau_context *nctx = to_nouveau_context(ctx); struct nouveau_channel *chan = context_chan(ctx); struct nouveau_grobj *kelvin = context_eng3d(ctx); if (nctx->fallback == HWTNL && (ctx->Texture._TexMatEnabled & 1 << i)) { BEGIN_RING(chan, kelvin, NV20TCL_TX_MATRIX_ENABLE(i), 1); OUT_RING(chan, 1); BEGIN_RING(chan, kelvin, TX_MATRIX(i), 16); OUT_RINGm(chan, ctx->TextureMatrixStack[i].Top->m); } else { BEGIN_RING(chan, kelvin, NV20TCL_TX_MATRIX_ENABLE(i), 1); OUT_RING(chan, 0); } }
void nv10_emit_zclear(struct gl_context *ctx, int emit) { struct nouveau_context *nctx = to_nouveau_context(ctx); struct nouveau_channel *chan = context_chan(ctx); struct nouveau_grobj *celsius = context_eng3d(ctx); struct nouveau_framebuffer *nfb = to_nouveau_framebuffer(ctx->DrawBuffer); if (nfb->hierz.bo) { BEGIN_RING(chan, celsius, NV17_3D_ZCLEAR_ENABLE, 2); OUT_RINGb(chan, !nctx->hierz.clear_blocked); OUT_RING(chan, nfb->hierz.clear_value | (nctx->hierz.clear_seq & 0xff)); } else { BEGIN_RING(chan, celsius, NV10_3D_DEPTH_RANGE_NEAR, 2); OUT_RINGf(chan, nv10_transform_depth(ctx, 0)); OUT_RINGf(chan, nv10_transform_depth(ctx, 1)); context_dirty(ctx, VIEWPORT); } }
static struct gl_context * nv10_context_create(struct nouveau_screen *screen, const struct gl_config *visual, struct gl_context *share_ctx) { struct nouveau_context *nctx; struct gl_context *ctx; unsigned celsius_class; int ret; nctx = CALLOC_STRUCT(nouveau_context); if (!nctx) return NULL; ctx = &nctx->base; if (!nouveau_context_init(ctx, screen, visual, share_ctx)) goto fail; ctx->Extensions.ARB_texture_env_crossbar = true; ctx->Extensions.ARB_texture_env_combine = true; ctx->Extensions.ARB_texture_env_dot3 = true; ctx->Extensions.NV_fog_distance = true; ctx->Extensions.NV_texture_rectangle = true; if (ctx->Mesa_DXTn) { ctx->Extensions.EXT_texture_compression_s3tc = true; ctx->Extensions.ANGLE_texture_compression_dxt = true; } /* GL constants. */ ctx->Const.MaxTextureLevels = 12; ctx->Const.MaxTextureCoordUnits = NV10_TEXTURE_UNITS; ctx->Const.MaxTextureImageUnits = NV10_TEXTURE_UNITS; ctx->Const.MaxTextureUnits = NV10_TEXTURE_UNITS; ctx->Const.MaxTextureMaxAnisotropy = 2; ctx->Const.MaxTextureLodBias = 15; ctx->Driver.Clear = nv10_clear; /* 2D engine. */ ret = nv04_surface_init(ctx); if (!ret) goto fail; /* 3D engine. */ if (context_chipset(ctx) >= 0x17 && context_chipset(ctx) != 0x1a) celsius_class = NV17_3D_CLASS; else if (context_chipset(ctx) >= 0x11) celsius_class = NV15_3D_CLASS; else celsius_class = NV10_3D_CLASS; ret = nouveau_object_new(context_chan(ctx), 0xbeef0001, celsius_class, NULL, 0, &nctx->hw.eng3d); if (ret) goto fail; nv10_hwctx_init(ctx); nv10_vbo_init(ctx); nv10_swtnl_init(ctx); return ctx; fail: nv10_context_destroy(ctx); return NULL; }
static void nv10_hwctx_init(struct gl_context *ctx) { struct nouveau_channel *chan = context_chan(ctx); struct nouveau_grobj *celsius = context_eng3d(ctx); struct nouveau_hw_state *hw = &to_nouveau_context(ctx)->hw; int i; BEGIN_RING(chan, celsius, NV10_3D_DMA_NOTIFY, 1); OUT_RING(chan, hw->ntfy->handle); BEGIN_RING(chan, celsius, NV10_3D_DMA_TEXTURE0, 3); OUT_RING(chan, chan->vram->handle); OUT_RING(chan, chan->gart->handle); OUT_RING(chan, chan->gart->handle); BEGIN_RING(chan, celsius, NV10_3D_DMA_COLOR, 2); OUT_RING(chan, chan->vram->handle); OUT_RING(chan, chan->vram->handle); BEGIN_RING(chan, celsius, NV04_GRAPH_NOP, 1); OUT_RING(chan, 0); BEGIN_RING(chan, celsius, NV10_3D_RT_HORIZ, 2); OUT_RING(chan, 0); OUT_RING(chan, 0); BEGIN_RING(chan, celsius, NV10_3D_VIEWPORT_CLIP_HORIZ(0), 1); OUT_RING(chan, 0x7ff << 16 | 0x800); BEGIN_RING(chan, celsius, NV10_3D_VIEWPORT_CLIP_VERT(0), 1); OUT_RING(chan, 0x7ff << 16 | 0x800); for (i = 1; i < 8; i++) { BEGIN_RING(chan, celsius, NV10_3D_VIEWPORT_CLIP_HORIZ(i), 1); OUT_RING(chan, 0); BEGIN_RING(chan, celsius, NV10_3D_VIEWPORT_CLIP_VERT(i), 1); OUT_RING(chan, 0); } BEGIN_RING(chan, celsius, 0x290, 1); OUT_RING(chan, 0x10 << 16 | 1); BEGIN_RING(chan, celsius, 0x3f4, 1); OUT_RING(chan, 0); BEGIN_RING(chan, celsius, NV04_GRAPH_NOP, 1); OUT_RING(chan, 0); if (context_chipset(ctx) >= 0x17) { BEGIN_RING(chan, celsius, NV17_3D_UNK01AC, 2); OUT_RING(chan, chan->vram->handle); OUT_RING(chan, chan->vram->handle); BEGIN_RING(chan, celsius, 0xd84, 1); OUT_RING(chan, 0x3); BEGIN_RING(chan, celsius, NV17_3D_COLOR_MASK_ENABLE, 1); OUT_RING(chan, 1); } if (context_chipset(ctx) >= 0x11) { BEGIN_RING(chan, celsius, 0x120, 3); OUT_RING(chan, 0); OUT_RING(chan, 1); OUT_RING(chan, 2); BEGIN_RING(chan, celsius, NV04_GRAPH_NOP, 1); OUT_RING(chan, 0); } BEGIN_RING(chan, celsius, NV04_GRAPH_NOP, 1); OUT_RING(chan, 0); /* Set state */ BEGIN_RING(chan, celsius, NV10_3D_FOG_ENABLE, 1); OUT_RING(chan, 0); BEGIN_RING(chan, celsius, NV10_3D_ALPHA_FUNC_ENABLE, 1); OUT_RING(chan, 0); BEGIN_RING(chan, celsius, NV10_3D_ALPHA_FUNC_FUNC, 2); OUT_RING(chan, 0x207); OUT_RING(chan, 0); BEGIN_RING(chan, celsius, NV10_3D_TEX_ENABLE(0), 2); OUT_RING(chan, 0); OUT_RING(chan, 0); BEGIN_RING(chan, celsius, NV10_3D_BLEND_FUNC_ENABLE, 1); OUT_RING(chan, 0); BEGIN_RING(chan, celsius, NV10_3D_DITHER_ENABLE, 2); OUT_RING(chan, 1); OUT_RING(chan, 0); BEGIN_RING(chan, celsius, NV10_3D_LINE_SMOOTH_ENABLE, 1); OUT_RING(chan, 0); BEGIN_RING(chan, celsius, NV10_3D_VERTEX_WEIGHT_ENABLE, 2); OUT_RING(chan, 0); OUT_RING(chan, 0); BEGIN_RING(chan, celsius, NV10_3D_BLEND_FUNC_SRC, 4); OUT_RING(chan, 1); OUT_RING(chan, 0); OUT_RING(chan, 0); OUT_RING(chan, 0x8006); BEGIN_RING(chan, celsius, NV10_3D_STENCIL_MASK, 8); OUT_RING(chan, 0xff); OUT_RING(chan, 0x207); OUT_RING(chan, 0); OUT_RING(chan, 0xff); OUT_RING(chan, 0x1e00); OUT_RING(chan, 0x1e00); OUT_RING(chan, 0x1e00); OUT_RING(chan, 0x1d01); BEGIN_RING(chan, celsius, NV10_3D_NORMALIZE_ENABLE, 1); OUT_RING(chan, 0); BEGIN_RING(chan, celsius, NV10_3D_FOG_ENABLE, 2); OUT_RING(chan, 0); OUT_RING(chan, 0); BEGIN_RING(chan, celsius, NV10_3D_LIGHT_MODEL, 1); OUT_RING(chan, 0); BEGIN_RING(chan, celsius, NV10_3D_SEPARATE_SPECULAR_ENABLE, 1); OUT_RING(chan, 0); BEGIN_RING(chan, celsius, NV10_3D_ENABLED_LIGHTS, 1); OUT_RING(chan, 0); BEGIN_RING(chan, celsius, NV10_3D_POLYGON_OFFSET_POINT_ENABLE, 3); OUT_RING(chan, 0); OUT_RING(chan, 0); OUT_RING(chan, 0); BEGIN_RING(chan, celsius, NV10_3D_DEPTH_FUNC, 1); OUT_RING(chan, 0x201); BEGIN_RING(chan, celsius, NV10_3D_DEPTH_WRITE_ENABLE, 1); OUT_RING(chan, 0); BEGIN_RING(chan, celsius, NV10_3D_DEPTH_TEST_ENABLE, 1); OUT_RING(chan, 0); BEGIN_RING(chan, celsius, NV10_3D_POLYGON_OFFSET_FACTOR, 2); OUT_RING(chan, 0); OUT_RING(chan, 0); BEGIN_RING(chan, celsius, NV10_3D_POINT_SIZE, 1); OUT_RING(chan, 8); BEGIN_RING(chan, celsius, NV10_3D_POINT_PARAMETERS_ENABLE, 2); OUT_RING(chan, 0); OUT_RING(chan, 0); BEGIN_RING(chan, celsius, NV10_3D_LINE_WIDTH, 1); OUT_RING(chan, 8); BEGIN_RING(chan, celsius, NV10_3D_LINE_SMOOTH_ENABLE, 1); OUT_RING(chan, 0); BEGIN_RING(chan, celsius, NV10_3D_POLYGON_MODE_FRONT, 2); OUT_RING(chan, 0x1b02); OUT_RING(chan, 0x1b02); BEGIN_RING(chan, celsius, NV10_3D_CULL_FACE, 2); OUT_RING(chan, 0x405); OUT_RING(chan, 0x901); BEGIN_RING(chan, celsius, NV10_3D_POLYGON_SMOOTH_ENABLE, 1); OUT_RING(chan, 0); BEGIN_RING(chan, celsius, NV10_3D_CULL_FACE_ENABLE, 1); OUT_RING(chan, 0); BEGIN_RING(chan, celsius, NV10_3D_TEX_GEN_MODE(0, 0), 8); for (i = 0; i < 8; i++) OUT_RING(chan, 0); BEGIN_RING(chan, celsius, NV10_3D_TEX_MATRIX_ENABLE(0), 2); OUT_RING(chan, 0); OUT_RING(chan, 0); BEGIN_RING(chan, celsius, NV10_3D_FOG_COEFF(0), 3); OUT_RING(chan, 0x3fc00000); /* -1.50 */ OUT_RING(chan, 0xbdb8aa0a); /* -0.09 */ OUT_RING(chan, 0); /* 0.00 */ BEGIN_RING(chan, celsius, NV04_GRAPH_NOP, 1); OUT_RING(chan, 0); BEGIN_RING(chan, celsius, NV10_3D_FOG_MODE, 2); OUT_RING(chan, 0x802); OUT_RING(chan, 2); /* for some reason VIEW_MATRIX_ENABLE need to be 6 instead of 4 when * using texturing, except when using the texture matrix */ BEGIN_RING(chan, celsius, NV10_3D_VIEW_MATRIX_ENABLE, 1); OUT_RING(chan, 6); BEGIN_RING(chan, celsius, NV10_3D_COLOR_MASK, 1); OUT_RING(chan, 0x01010101); /* Set vertex component */ BEGIN_RING(chan, celsius, NV10_3D_VERTEX_COL_4F_R, 4); OUT_RINGf(chan, 1.0); OUT_RINGf(chan, 0.0); OUT_RINGf(chan, 0.0); OUT_RINGf(chan, 1.0); BEGIN_RING(chan, celsius, NV10_3D_VERTEX_COL2_3F_R, 3); OUT_RING(chan, 0); OUT_RING(chan, 0); OUT_RING(chan, 0); BEGIN_RING(chan, celsius, NV10_3D_VERTEX_NOR_3F_X, 3); OUT_RING(chan, 0); OUT_RING(chan, 0); OUT_RINGf(chan, 1.0); BEGIN_RING(chan, celsius, NV10_3D_VERTEX_TX0_4F_S, 4); OUT_RINGf(chan, 0.0); OUT_RINGf(chan, 0.0); OUT_RINGf(chan, 0.0); OUT_RINGf(chan, 1.0); BEGIN_RING(chan, celsius, NV10_3D_VERTEX_TX1_4F_S, 4); OUT_RINGf(chan, 0.0); OUT_RINGf(chan, 0.0); OUT_RINGf(chan, 0.0); OUT_RINGf(chan, 1.0); BEGIN_RING(chan, celsius, NV10_3D_VERTEX_FOG_1F, 1); OUT_RINGf(chan, 0.0); BEGIN_RING(chan, celsius, NV10_3D_EDGEFLAG_ENABLE, 1); OUT_RING(chan, 1); BEGIN_RING(chan, celsius, NV10_3D_DEPTH_RANGE_NEAR, 2); OUT_RINGf(chan, 0.0); OUT_RINGf(chan, 16777216.0); FIRE_RING(chan); }
void nv04_emit_tex_obj(struct gl_context *ctx, int emit) { const int i = emit - NOUVEAU_STATE_TEX_OBJ0; struct nouveau_channel *chan = context_chan(ctx); struct nouveau_grobj *fahrenheit = nv04_context_engine(ctx); struct nouveau_bo_context *bctx = context_bctx_i(ctx, TEXTURE, i); const int bo_flags = NOUVEAU_BO_RD | NOUVEAU_BO_GART | NOUVEAU_BO_VRAM; struct nouveau_surface *s; uint32_t format = 0xa0, filter = 0x1010; if (i && !nv04_mtex_engine(fahrenheit)) return; if (ctx->Texture.Unit[i]._ReallyEnabled) { struct gl_texture_object *t = ctx->Texture.Unit[i]._Current; struct gl_texture_image *ti = t->Image[0][t->BaseLevel]; int lod_max = 1, lod_bias = 0; if (!nouveau_texture_validate(ctx, t)) return; s = &to_nouveau_texture(t)->surfaces[t->BaseLevel]; if (t->MinFilter != GL_NEAREST && t->MinFilter != GL_LINEAR) { lod_max = CLAMP(MIN2(t->MaxLod, t->_MaxLambda), 0, 15) + 1; lod_bias = CLAMP(ctx->Texture.Unit[i].LodBias + t->LodBias, -16, 15) * 8; } format |= nvgl_wrap_mode(t->WrapT) << 28 | nvgl_wrap_mode(t->WrapS) << 24 | ti->HeightLog2 << 20 | ti->WidthLog2 << 16 | lod_max << 12 | get_tex_format(ti); filter |= log2i(t->MaxAnisotropy) << 31 | nvgl_filter_mode(t->MagFilter) << 28 | log2i(t->MaxAnisotropy) << 27 | nvgl_filter_mode(t->MinFilter) << 24 | (lod_bias & 0xff) << 16; } else { s = &to_nv04_context(ctx)->dummy_texture; format |= NV04_TEXTURED_TRIANGLE_FORMAT_ADDRESSU_REPEAT | NV04_TEXTURED_TRIANGLE_FORMAT_ADDRESSV_REPEAT | 1 << 12 | NV04_TEXTURED_TRIANGLE_FORMAT_COLOR_A8R8G8B8; filter |= NV04_TEXTURED_TRIANGLE_FILTER_MINIFY_NEAREST | NV04_TEXTURED_TRIANGLE_FILTER_MAGNIFY_NEAREST; } if (nv04_mtex_engine(fahrenheit)) { nouveau_bo_markl(bctx, fahrenheit, NV04_MULTITEX_TRIANGLE_OFFSET(i), s->bo, s->offset, bo_flags); nouveau_bo_mark(bctx, fahrenheit, NV04_MULTITEX_TRIANGLE_FORMAT(i), s->bo, format, 0, NV04_MULTITEX_TRIANGLE_FORMAT_DMA_A, NV04_MULTITEX_TRIANGLE_FORMAT_DMA_B, bo_flags | NOUVEAU_BO_OR); BEGIN_RING(chan, fahrenheit, NV04_MULTITEX_TRIANGLE_FILTER(i), 1); OUT_RING(chan, filter); } else { nouveau_bo_markl(bctx, fahrenheit, NV04_TEXTURED_TRIANGLE_OFFSET, s->bo, s->offset, bo_flags); nouveau_bo_mark(bctx, fahrenheit, NV04_TEXTURED_TRIANGLE_FORMAT, s->bo, format, 0, NV04_TEXTURED_TRIANGLE_FORMAT_DMA_A, NV04_TEXTURED_TRIANGLE_FORMAT_DMA_B, bo_flags | NOUVEAU_BO_OR); BEGIN_RING(chan, fahrenheit, NV04_TEXTURED_TRIANGLE_COLORKEY, 1); OUT_RING(chan, 0); BEGIN_RING(chan, fahrenheit, NV04_TEXTURED_TRIANGLE_FILTER, 1); OUT_RING(chan, filter); } }
void nv20_emit_tex_obj(GLcontext *ctx, int emit) { const int i = emit - NOUVEAU_STATE_TEX_OBJ0; struct nouveau_channel *chan = context_chan(ctx); struct nouveau_grobj *kelvin = context_eng3d(ctx); struct nouveau_bo_context *bctx = context_bctx_i(ctx, TEXTURE, i); const int bo_flags = NOUVEAU_BO_RD | NOUVEAU_BO_GART | NOUVEAU_BO_VRAM; struct gl_texture_object *t; struct nouveau_surface *s; struct gl_texture_image *ti; uint32_t tx_format, tx_filter, tx_wrap, tx_enable; if (!ctx->Texture.Unit[i]._ReallyEnabled) { BEGIN_RING(chan, kelvin, NV20TCL_TX_ENABLE(i), 1); OUT_RING(chan, 0); context_dirty(ctx, TEX_SHADER); return; } t = ctx->Texture.Unit[i]._Current; s = &to_nouveau_texture(t)->surfaces[t->BaseLevel]; ti = t->Image[0][t->BaseLevel]; if (!nouveau_texture_validate(ctx, t)) return; /* Recompute the texturing registers. */ tx_format = ti->DepthLog2 << 28 | ti->HeightLog2 << 24 | ti->WidthLog2 << 20 | NV20TCL_TX_FORMAT_DIMS_2D | NV20TCL_TX_FORMAT_NO_BORDER | 1 << 16; tx_wrap = nvgl_wrap_mode(t->WrapR) << 16 | nvgl_wrap_mode(t->WrapT) << 8 | nvgl_wrap_mode(t->WrapS) << 0; tx_filter = nvgl_filter_mode(t->MagFilter) << 24 | nvgl_filter_mode(t->MinFilter) << 16 | 2 << 12; tx_enable = NV20TCL_TX_ENABLE_ENABLE | log2i(t->MaxAnisotropy) << 4; if (t->Target == GL_TEXTURE_RECTANGLE) { BEGIN_RING(chan, kelvin, NV20TCL_TX_NPOT_PITCH(i), 1); OUT_RING(chan, s->pitch << 16); BEGIN_RING(chan, kelvin, NV20TCL_TX_NPOT_SIZE(i), 1); OUT_RING(chan, s->width << 16 | s->height); tx_format |= get_tex_format_rect(ti); } else { tx_format |= get_tex_format_pot(ti); } if (t->MinFilter != GL_NEAREST && t->MinFilter != GL_LINEAR) { int lod_min = t->MinLod; int lod_max = MIN2(t->MaxLod, t->_MaxLambda); int lod_bias = t->LodBias + ctx->Texture.Unit[i].LodBias; lod_max = CLAMP(lod_max, 0, 15); lod_min = CLAMP(lod_min, 0, 15); lod_bias = CLAMP(lod_bias, 0, 15); tx_format |= NV20TCL_TX_FORMAT_MIPMAP; tx_filter |= lod_bias << 8; tx_enable |= lod_min << 26 | lod_max << 14; } /* Write it to the hardware. */ nouveau_bo_mark(bctx, kelvin, NV20TCL_TX_FORMAT(i), s->bo, tx_format, 0, NV20TCL_TX_FORMAT_DMA0, NV20TCL_TX_FORMAT_DMA1, bo_flags | NOUVEAU_BO_OR); nouveau_bo_markl(bctx, kelvin, NV20TCL_TX_OFFSET(i), s->bo, 0, bo_flags); BEGIN_RING(chan, kelvin, NV20TCL_TX_WRAP(i), 1); OUT_RING(chan, tx_wrap); BEGIN_RING(chan, kelvin, NV20TCL_TX_FILTER(i), 1); OUT_RING(chan, tx_filter); BEGIN_RING(chan, kelvin, NV20TCL_TX_ENABLE(i), 1); OUT_RING(chan, tx_enable); context_dirty(ctx, TEX_SHADER); }
static struct gl_context * nv04_context_create(struct nouveau_screen *screen, const struct gl_config *visual, struct gl_context *share_ctx) { struct nv04_context *nctx; struct nouveau_hw_state *hw; struct gl_context *ctx; int ret; nctx = CALLOC_STRUCT(nv04_context); if (!nctx) return NULL; ctx = &nctx->base.base; hw = &nctx->base.hw; if (!nouveau_context_init(ctx, screen, visual, share_ctx)) goto fail; /* GL constants. */ ctx->Const.MaxTextureLevels = 11; ctx->Const.MaxTextureCoordUnits = NV04_TEXTURE_UNITS; ctx->Const.MaxTextureImageUnits = NV04_TEXTURE_UNITS; ctx->Const.MaxTextureUnits = NV04_TEXTURE_UNITS; ctx->Const.MaxTextureMaxAnisotropy = 2; ctx->Const.MaxTextureLodBias = 15; /* 2D engine. */ ret = nv04_surface_init(ctx); if (!ret) goto fail; /* 3D engine. */ ret = nouveau_object_new(context_chan(ctx), 0xbeef0001, NV04_TEXTURED_TRIANGLE_CLASS, NULL, 0, &hw->eng3d); if (ret) goto fail; ret = nouveau_object_new(context_chan(ctx), 0xbeef0002, NV04_MULTITEX_TRIANGLE_CLASS, NULL, 0, &hw->eng3dm); if (ret) goto fail; ret = nouveau_object_new(context_chan(ctx), 0xbeef0003, NV04_SURFACE_3D_CLASS, NULL, 0, &hw->surf3d); if (ret) goto fail; init_dummy_texture(ctx); nv04_hwctx_init(ctx); nv04_render_init(ctx); return ctx; fail: nv04_context_destroy(ctx); return NULL; }
static struct gl_context * nv20_context_create(struct nouveau_screen *screen, gl_api api, const struct gl_config *visual, struct gl_context *share_ctx) { struct nouveau_context *nctx; struct gl_context *ctx; unsigned kelvin_class; int ret; nctx = CALLOC_STRUCT(nouveau_context); if (!nctx) return NULL; ctx = &nctx->base; if (!nouveau_context_init(ctx, api, screen, visual, share_ctx)) goto fail; ctx->Extensions.ARB_texture_env_crossbar = true; ctx->Extensions.ARB_texture_env_combine = true; ctx->Extensions.ARB_texture_env_dot3 = true; ctx->Extensions.EXT_texture_env_dot3 = true; ctx->Extensions.NV_fog_distance = true; ctx->Extensions.NV_texture_rectangle = true; ctx->Extensions.EXT_texture_compression_s3tc = true; ctx->Extensions.ANGLE_texture_compression_dxt = true; /* GL constants. */ ctx->Const.MaxTextureCoordUnits = NV20_TEXTURE_UNITS; ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxTextureImageUnits = NV20_TEXTURE_UNITS; ctx->Const.MaxTextureUnits = NV20_TEXTURE_UNITS; ctx->Const.MaxTextureMaxAnisotropy = 8; ctx->Const.MaxTextureLodBias = 15; ctx->Driver.Clear = nv20_clear; /* 2D engine. */ ret = nv04_surface_init(ctx); if (!ret) goto fail; /* 3D engine. */ if (context_chipset(ctx) >= 0x25) kelvin_class = NV25_3D_CLASS; else kelvin_class = NV20_3D_CLASS; ret = nouveau_object_new(context_chan(ctx), 0xbeef0001, kelvin_class, NULL, 0, &nctx->hw.eng3d); if (ret) goto fail; nv20_hwctx_init(ctx); nv20_vbo_init(ctx); nv20_swtnl_init(ctx); return ctx; fail: nv20_context_destroy(ctx); return NULL; }
void nv10_emit_framebuffer(struct gl_context *ctx, int emit) { struct nouveau_channel *chan = context_chan(ctx); struct nouveau_grobj *celsius = context_eng3d(ctx); struct nouveau_bo_context *bctx = context_bctx(ctx, FRAMEBUFFER); struct gl_framebuffer *fb = ctx->DrawBuffer; struct nouveau_surface *s; unsigned rt_format = NV10_3D_RT_FORMAT_TYPE_LINEAR; unsigned rt_pitch = 0, zeta_pitch = 0; unsigned bo_flags = NOUVEAU_BO_VRAM | NOUVEAU_BO_RDWR; if (fb->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) return; /* At least nv11 seems to get sad if we don't do this before * swapping RTs.*/ if (context_chipset(ctx) < 0x17) { int i; for (i = 0; i < 6; i++) { BEGIN_RING(chan, celsius, NV04_GRAPH_NOP, 1); OUT_RING(chan, 0); } } /* Render target */ if (fb->_ColorDrawBuffers[0]) { s = &to_nouveau_renderbuffer( fb->_ColorDrawBuffers[0])->surface; rt_format |= get_rt_format(s->format); zeta_pitch = rt_pitch = s->pitch; nouveau_bo_markl(bctx, celsius, NV10_3D_COLOR_OFFSET, s->bo, 0, bo_flags); } /* depth/stencil */ if (fb->Attachment[BUFFER_DEPTH].Renderbuffer) { s = &to_nouveau_renderbuffer( fb->Attachment[BUFFER_DEPTH].Renderbuffer)->surface; rt_format |= get_rt_format(s->format); zeta_pitch = s->pitch; nouveau_bo_markl(bctx, celsius, NV10_3D_ZETA_OFFSET, s->bo, 0, bo_flags); if (context_chipset(ctx) >= 0x17) { setup_hierz_buffer(ctx); context_dirty(ctx, ZCLEAR); } } BEGIN_RING(chan, celsius, NV10_3D_RT_FORMAT, 2); OUT_RING(chan, rt_format); OUT_RING(chan, zeta_pitch << 16 | rt_pitch); context_dirty(ctx, VIEWPORT); context_dirty(ctx, SCISSOR); }