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