Пример #1
0
static void
nvc0_set_constant_buffer(struct pipe_context *pipe, uint shader, uint index,
                         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)) {
      assert(!cb || !cb->user_buffer);
      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_CB(s, i));

      nvc0->dirty |= NVC0_NEW_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;
   } 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;
   }
   else {
      nvc0->constbuf_valid[s] &= ~(1 << i);
   }
}
Пример #2
0
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 |= NVC0_NEW_FRAMEBUFFER;
                nouveau_bufctx_reset(nvc0->bufctx_3d, NVC0_BIND_FB);
                if (!--ref)
                    return ref;
            }
        }
    }
    if (res->bind & PIPE_BIND_DEPTH_STENCIL) {
        if (nvc0->framebuffer.zsbuf &&
                nvc0->framebuffer.zsbuf->texture == res) {
            nvc0->dirty |= NVC0_NEW_FRAMEBUFFER;
            nouveau_bufctx_reset(nvc0->bufctx_3d, NVC0_BIND_FB);
            if (!--ref)
                return ref;
        }
    }

    if (res->bind & (PIPE_BIND_VERTEX_BUFFER |
                     PIPE_BIND_INDEX_BUFFER |
                     PIPE_BIND_CONSTANT_BUFFER |
                     PIPE_BIND_STREAM_OUTPUT |
                     PIPE_BIND_COMMAND_ARGS_BUFFER |
                     PIPE_BIND_SAMPLER_VIEW)) {
        for (i = 0; i < nvc0->num_vtxbufs; ++i) {
            if (nvc0->vtxbuf[i].buffer == res) {
                nvc0->dirty |= NVC0_NEW_ARRAYS;
                nouveau_bufctx_reset(nvc0->bufctx_3d, NVC0_BIND_VTX);
                if (!--ref)
                    return ref;
            }
        }

        if (nvc0->idxbuf.buffer == res) {
            nvc0->dirty |= NVC0_NEW_IDXBUF;
            nouveau_bufctx_reset(nvc0->bufctx_3d, NVC0_BIND_IDX);
            if (!--ref)
                return ref;
        }

        for (s = 0; s < 5; ++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;
                    nvc0->dirty |= NVC0_NEW_TEXTURES;
                    nouveau_bufctx_reset(nvc0->bufctx_3d, NVC0_BIND_TEX(s, i));
                    if (!--ref)
                        return ref;
                }
            }
        }

        for (s = 0; s < 5; ++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->dirty |= NVC0_NEW_CONSTBUF;
                    nvc0->constbuf_dirty[s] |= 1 << i;
                    nouveau_bufctx_reset(nvc0->bufctx_3d, NVC0_BIND_CB(s, i));
                    if (!--ref)
                        return ref;
                }
            }
        }
    }

    return ref;
}