radeonsi: use shader_info::cs::local_size_variable to clean up some code
[mesa.git] / src / gallium / drivers / freedreno / freedreno_surface.c
1 /*
2 * Copyright (C) 2012 Rob Clark <robclark@freedesktop.org>
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 (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 *
23 * Authors:
24 * Rob Clark <robclark@freedesktop.org>
25 */
26
27 #include "freedreno_surface.h"
28 #include "freedreno_resource.h"
29 #include "freedreno_util.h"
30
31 #include "util/u_memory.h"
32 #include "util/u_inlines.h"
33
34 struct pipe_surface *
35 fd_create_surface(struct pipe_context *pctx,
36 struct pipe_resource *ptex,
37 const struct pipe_surface *surf_tmpl)
38 {
39 // struct fd_resource* tex = fd_resource(ptex);
40 struct fd_surface* surface = CALLOC_STRUCT(fd_surface);
41
42 if (!surface)
43 return NULL;
44
45
46 struct pipe_surface *psurf = &surface->base;
47 unsigned level = surf_tmpl->u.tex.level;
48
49 pipe_reference_init(&psurf->reference, 1);
50 pipe_resource_reference(&psurf->texture, ptex);
51
52 psurf->context = pctx;
53 psurf->format = surf_tmpl->format;
54 psurf->width = u_minify(ptex->width0, level);
55 psurf->height = u_minify(ptex->height0, level);
56 psurf->nr_samples = surf_tmpl->nr_samples;
57
58 if (ptex->target == PIPE_BUFFER) {
59 psurf->u.buf.first_element = surf_tmpl->u.buf.first_element;
60 psurf->u.buf.last_element = surf_tmpl->u.buf.last_element;
61 } else {
62 psurf->u.tex.level = level;
63 psurf->u.tex.first_layer = surf_tmpl->u.tex.first_layer;
64 psurf->u.tex.last_layer = surf_tmpl->u.tex.last_layer;
65 }
66
67 // TODO
68 DBG("TODO: %ux%u", psurf->width, psurf->height);
69
70 return &surface->base;
71 }
72
73 void
74 fd_surface_destroy(struct pipe_context *pctx, struct pipe_surface *psurf)
75 {
76 pipe_resource_reference(&psurf->texture, NULL);
77 FREE(psurf);
78 }