2e6d2361497ed57c6ed63dd8beeea9d13caf4335
[mesa.git] / src / mesa / state_tracker / st_pbo.c
1 /*
2 * Copyright 2007 VMware, Inc.
3 * Copyright 2016 Advanced Micro Devices, Inc.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * on the rights to use, copy, modify, merge, publish, distribute, sub
9 * license, and/or sell copies of the Software, and to permit persons to whom
10 * the Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22 * USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25 /**
26 * \file
27 *
28 * Common helper functions for PBO up- and downloads.
29 */
30
31 #include "state_tracker/st_context.h"
32 #include "state_tracker/st_pbo.h"
33
34 #include "pipe/p_context.h"
35 #include "pipe/p_defines.h"
36 #include "pipe/p_screen.h"
37 #include "cso_cache/cso_context.h"
38
39 void
40 st_init_pbo_helpers(struct st_context *st)
41 {
42 struct pipe_context *pipe = st->pipe;
43 struct pipe_screen *screen = pipe->screen;
44
45 st->pbo_upload.enabled =
46 screen->get_param(screen, PIPE_CAP_TEXTURE_BUFFER_OBJECTS) &&
47 screen->get_param(screen, PIPE_CAP_TEXTURE_BUFFER_OFFSET_ALIGNMENT) >= 1 &&
48 screen->get_shader_param(screen, PIPE_SHADER_FRAGMENT, PIPE_SHADER_CAP_INTEGERS);
49 if (!st->pbo_upload.enabled)
50 return;
51
52 st->pbo_upload.rgba_only =
53 screen->get_param(screen, PIPE_CAP_BUFFER_SAMPLER_VIEW_RGBA_ONLY);
54
55 if (screen->get_param(screen, PIPE_CAP_TGSI_INSTANCEID)) {
56 if (screen->get_param(screen, PIPE_CAP_TGSI_VS_LAYER_VIEWPORT)) {
57 st->pbo_upload.upload_layers = true;
58 } else if (screen->get_param(screen, PIPE_CAP_MAX_GEOMETRY_OUTPUT_VERTICES) >= 3) {
59 st->pbo_upload.upload_layers = true;
60 st->pbo_upload.use_gs = true;
61 }
62 }
63
64 /* Blend state */
65 memset(&st->pbo_upload.blend, 0, sizeof(struct pipe_blend_state));
66 st->pbo_upload.blend.rt[0].colormask = PIPE_MASK_RGBA;
67
68 /* Rasterizer state */
69 memset(&st->pbo_upload.raster, 0, sizeof(struct pipe_rasterizer_state));
70 st->pbo_upload.raster.half_pixel_center = 1;
71 }
72
73 void
74 st_destroy_pbo_helpers(struct st_context *st)
75 {
76 if (st->pbo_upload.fs) {
77 cso_delete_fragment_shader(st->cso_context, st->pbo_upload.fs);
78 st->pbo_upload.fs = NULL;
79 }
80
81 if (st->pbo_upload.gs) {
82 cso_delete_geometry_shader(st->cso_context, st->pbo_upload.gs);
83 st->pbo_upload.gs = NULL;
84 }
85
86 if (st->pbo_upload.vs) {
87 cso_delete_vertex_shader(st->cso_context, st->pbo_upload.vs);
88 st->pbo_upload.vs = NULL;
89 }
90 }