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); }
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 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); }
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); }
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); } }