static void nvc0_set_constant_buffer(struct pipe_context *pipe, enum pipe_shader_type shader, uint index, const struct pipe_constant_buffer *cb) { struct nvc0_context *nvc0 = nvc0_context(pipe); struct pipe_resource *res = cb ? cb->buffer : NULL; const unsigned s = nvc0_shader_stage(shader); const unsigned i = index; if (unlikely(shader == PIPE_SHADER_COMPUTE)) { if (nvc0->constbuf[s][i].user) nvc0->constbuf[s][i].u.buf = NULL; else if (nvc0->constbuf[s][i].u.buf) nouveau_bufctx_reset(nvc0->bufctx_cp, NVC0_BIND_CP_CB(i)); nvc0->dirty_cp |= NVC0_NEW_CP_CONSTBUF; } else { if (nvc0->constbuf[s][i].user) nvc0->constbuf[s][i].u.buf = NULL; else if (nvc0->constbuf[s][i].u.buf) nouveau_bufctx_reset(nvc0->bufctx_3d, NVC0_BIND_3D_CB(s, i)); nvc0->dirty_3d |= NVC0_NEW_3D_CONSTBUF; } nvc0->constbuf_dirty[s] |= 1 << i; if (nvc0->constbuf[s][i].u.buf) nv04_resource(nvc0->constbuf[s][i].u.buf)->cb_bindings[s] &= ~(1 << i); pipe_resource_reference(&nvc0->constbuf[s][i].u.buf, res); nvc0->constbuf[s][i].user = (cb && cb->user_buffer) ? true : false; if (nvc0->constbuf[s][i].user) { nvc0->constbuf[s][i].u.data = cb->user_buffer; nvc0->constbuf[s][i].size = MIN2(cb->buffer_size, 0x10000); nvc0->constbuf_valid[s] |= 1 << i; nvc0->constbuf_coherent[s] &= ~(1 << i); } else if (cb) { nvc0->constbuf[s][i].offset = cb->buffer_offset; nvc0->constbuf[s][i].size = MIN2(align(cb->buffer_size, 0x100), 0x10000); nvc0->constbuf_valid[s] |= 1 << i; if (res && res->flags & PIPE_RESOURCE_FLAG_MAP_COHERENT) nvc0->constbuf_coherent[s] |= 1 << i; else nvc0->constbuf_coherent[s] &= ~(1 << i); } else { nvc0->constbuf_valid[s] &= ~(1 << i); nvc0->constbuf_coherent[s] &= ~(1 << i); } }
static int nvc0_invalidate_resource_storage(struct nouveau_context *ctx, struct pipe_resource *res, int ref) { struct nvc0_context *nvc0 = nvc0_context(&ctx->pipe); unsigned s, i; if (res->bind & PIPE_BIND_RENDER_TARGET) { for (i = 0; i < nvc0->framebuffer.nr_cbufs; ++i) { if (nvc0->framebuffer.cbufs[i] && nvc0->framebuffer.cbufs[i]->texture == res) { nvc0->dirty_3d |= NVC0_NEW_3D_FRAMEBUFFER; nouveau_bufctx_reset(nvc0->bufctx_3d, NVC0_BIND_3D_FB); if (!--ref) return ref; } } } if (res->bind & PIPE_BIND_DEPTH_STENCIL) { if (nvc0->framebuffer.zsbuf && nvc0->framebuffer.zsbuf->texture == res) { nvc0->dirty_3d |= NVC0_NEW_3D_FRAMEBUFFER; nouveau_bufctx_reset(nvc0->bufctx_3d, NVC0_BIND_3D_FB); if (!--ref) return ref; } } if (res->target == PIPE_BUFFER) { for (i = 0; i < nvc0->num_vtxbufs; ++i) { if (nvc0->vtxbuf[i].buffer == res) { nvc0->dirty_3d |= NVC0_NEW_3D_ARRAYS; nouveau_bufctx_reset(nvc0->bufctx_3d, NVC0_BIND_3D_VTX); if (!--ref) return ref; } } if (nvc0->idxbuf.buffer == res) { nvc0->dirty_3d |= NVC0_NEW_3D_IDXBUF; nouveau_bufctx_reset(nvc0->bufctx_3d, NVC0_BIND_3D_IDX); if (!--ref) return ref; } for (s = 0; s < 6; ++s) { for (i = 0; i < nvc0->num_textures[s]; ++i) { if (nvc0->textures[s][i] && nvc0->textures[s][i]->texture == res) { nvc0->textures_dirty[s] |= 1 << i; if (unlikely(s == 5)) { nvc0->dirty_cp |= NVC0_NEW_CP_TEXTURES; nouveau_bufctx_reset(nvc0->bufctx_cp, NVC0_BIND_CP_TEX(i)); } else { nvc0->dirty_3d |= NVC0_NEW_3D_TEXTURES; nouveau_bufctx_reset(nvc0->bufctx_3d, NVC0_BIND_3D_TEX(s, i)); } if (!--ref) return ref; } } } for (s = 0; s < 6; ++s) { for (i = 0; i < NVC0_MAX_PIPE_CONSTBUFS; ++i) { if (!(nvc0->constbuf_valid[s] & (1 << i))) continue; if (!nvc0->constbuf[s][i].user && nvc0->constbuf[s][i].u.buf == res) { nvc0->constbuf_dirty[s] |= 1 << i; if (unlikely(s == 5)) { nvc0->dirty_cp |= NVC0_NEW_CP_CONSTBUF; nouveau_bufctx_reset(nvc0->bufctx_cp, NVC0_BIND_CP_CB(i)); } else { nvc0->dirty_3d |= NVC0_NEW_3D_CONSTBUF; nouveau_bufctx_reset(nvc0->bufctx_3d, NVC0_BIND_3D_CB(s, i)); } if (!--ref) return ref; } } } for (s = 0; s < 6; ++s) { for (i = 0; i < NVC0_MAX_BUFFERS; ++i) { if (nvc0->buffers[s][i].buffer == res) { nvc0->buffers_dirty[s] |= 1 << i; if (unlikely(s == 5)) { nvc0->dirty_cp |= NVC0_NEW_CP_BUFFERS; nouveau_bufctx_reset(nvc0->bufctx_cp, NVC0_BIND_CP_BUF); } else { nvc0->dirty_3d |= NVC0_NEW_3D_BUFFERS; nouveau_bufctx_reset(nvc0->bufctx_3d, NVC0_BIND_3D_BUF); } if (!--ref) return ref; } } } for (s = 0; s < 6; ++s) { for (i = 0; i < NVC0_MAX_IMAGES; ++i) { if (nvc0->images[s][i].resource == res) { nvc0->images_dirty[s] |= 1 << i; if (unlikely(s == 5)) { nvc0->dirty_cp |= NVC0_NEW_CP_SURFACES; nouveau_bufctx_reset(nvc0->bufctx_cp, NVC0_BIND_CP_SUF); } else { nvc0->dirty_3d |= NVC0_NEW_3D_SURFACES; nouveau_bufctx_reset(nvc0->bufctx_3d, NVC0_BIND_3D_SUF); } } if (!--ref) return ref; } } } return ref; }