Home | History | Annotate | Download | only in nv30
      1 /*
      2  * Copyright 2012 Red Hat Inc.
      3  *
      4  * Permission is hereby granted, free of charge, to any person obtaining a
      5  * copy of this software and associated documentation files (the "Software"),
      6  * to deal in the Software without restriction, including without limitation
      7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
      8  * and/or sell copies of the Software, and to permit persons to whom the
      9  * Software is furnished to do so, subject to the following conditions:
     10  *
     11  * The above copyright notice and this permission notice shall be included in
     12  * all copies or substantial portions of the Software.
     13  *
     14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
     17  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
     18  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
     19  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
     20  * OTHER DEALINGS IN THE SOFTWARE.
     21  *
     22  * Authors: Ben Skeggs
     23  *
     24  */
     25 
     26 #include "util/u_format.h"
     27 #include "util/u_inlines.h"
     28 
     29 #include "nv30/nv30_screen.h"
     30 #include "nv30/nv30_context.h"
     31 #include "nv30/nv30_resource.h"
     32 #include "nv30/nv30_transfer.h"
     33 
     34 static void
     35 nv30_memory_barrier(struct pipe_context *pipe, unsigned flags)
     36 {
     37    struct nv30_context *nv30 = nv30_context(pipe);
     38    int i;
     39 
     40    if (flags & PIPE_BARRIER_MAPPED_BUFFER) {
     41       for (i = 0; i < nv30->num_vtxbufs; ++i) {
     42          if (!nv30->vtxbuf[i].buffer)
     43             continue;
     44          if (nv30->vtxbuf[i].buffer->flags & PIPE_RESOURCE_FLAG_MAP_PERSISTENT)
     45             nv30->base.vbo_dirty = true;
     46       }
     47 
     48       if (nv30->idxbuf.buffer &&
     49           nv30->idxbuf.buffer->flags & PIPE_RESOURCE_FLAG_MAP_PERSISTENT)
     50          nv30->base.vbo_dirty = true;
     51    }
     52 }
     53 
     54 static struct pipe_resource *
     55 nv30_resource_create(struct pipe_screen *pscreen,
     56                      const struct pipe_resource *tmpl)
     57 {
     58    switch (tmpl->target) {
     59    case PIPE_BUFFER:
     60       return nouveau_buffer_create(pscreen, tmpl);
     61    default:
     62       return nv30_miptree_create(pscreen, tmpl);
     63    }
     64 }
     65 
     66 static struct pipe_resource *
     67 nv30_resource_from_handle(struct pipe_screen *pscreen,
     68                           const struct pipe_resource *tmpl,
     69                           struct winsys_handle *handle,
     70                           unsigned usage)
     71 {
     72    if (tmpl->target == PIPE_BUFFER)
     73       return NULL;
     74    else
     75       return nv30_miptree_from_handle(pscreen, tmpl, handle);
     76 }
     77 
     78 void
     79 nv30_resource_screen_init(struct pipe_screen *pscreen)
     80 {
     81    pscreen->resource_create = nv30_resource_create;
     82    pscreen->resource_from_handle = nv30_resource_from_handle;
     83    pscreen->resource_get_handle = u_resource_get_handle_vtbl;
     84    pscreen->resource_destroy = u_resource_destroy_vtbl;
     85 }
     86 
     87 void
     88 nv30_resource_init(struct pipe_context *pipe)
     89 {
     90    pipe->transfer_map = u_transfer_map_vtbl;
     91    pipe->transfer_flush_region = u_transfer_flush_region_vtbl;
     92    pipe->transfer_unmap = u_transfer_unmap_vtbl;
     93    pipe->buffer_subdata = u_default_buffer_subdata;
     94    pipe->texture_subdata = u_default_texture_subdata;
     95    pipe->create_surface = nv30_miptree_surface_new;
     96    pipe->surface_destroy = nv30_miptree_surface_del;
     97    pipe->resource_copy_region = nv30_resource_copy_region;
     98    pipe->blit = nv30_blit;
     99    pipe->flush_resource = nv30_flush_resource;
    100    pipe->memory_barrier = nv30_memory_barrier;
    101 }
    102