st/mesa: invalidate readpixels cache
[mesa.git] / src / mesa / state_tracker / st_cb_compute.c
1 /**************************************************************************
2 *
3 * Copyright 2016 Samuel Pitoiset
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 #include "main/state.h"
29 #include "st_atom.h"
30 #include "st_context.h"
31 #include "st_cb_bitmap.h"
32 #include "st_cb_bufferobjects.h"
33 #include "st_cb_compute.h"
34
35 #include "pipe/p_context.h"
36
37 static void st_dispatch_compute_common(struct gl_context *ctx,
38 const GLuint *num_groups,
39 struct pipe_resource *indirect,
40 GLintptr indirect_offset)
41 {
42 struct gl_shader_program *prog =
43 ctx->_Shader->CurrentProgram[MESA_SHADER_COMPUTE];
44 struct st_context *st = st_context(ctx);
45 struct pipe_context *pipe = st->pipe;
46 struct pipe_grid_info info = { 0 };
47
48 st_flush_bitmap_cache(st);
49 st_invalidate_readpix_cache(st);
50
51 if (ctx->NewState)
52 _mesa_update_state(ctx);
53
54 if (st->dirty_cp.st || st->dirty_cp.mesa || ctx->NewDriverState)
55 st_validate_state(st, ST_PIPELINE_COMPUTE);
56
57 for (unsigned i = 0; i < 3; i++) {
58 info.block[i] = prog->Comp.LocalSize[i];
59 info.grid[i] = num_groups ? num_groups[i] : 0;
60 }
61
62 if (indirect) {
63 info.indirect = indirect;
64 info.indirect_offset = indirect_offset;
65 }
66
67 pipe->launch_grid(pipe, &info);
68 }
69
70 static void st_dispatch_compute(struct gl_context *ctx,
71 const GLuint *num_groups)
72 {
73 st_dispatch_compute_common(ctx, num_groups, NULL, 0);
74 }
75
76 static void st_dispatch_compute_indirect(struct gl_context *ctx,
77 GLintptr indirect_offset)
78 {
79 struct gl_buffer_object *indirect_buffer = ctx->DispatchIndirectBuffer;
80 struct pipe_resource *indirect = st_buffer_object(indirect_buffer)->buffer;
81
82 st_dispatch_compute_common(ctx, NULL, indirect, indirect_offset);
83 }
84
85 void st_init_compute_functions(struct dd_function_table *functions)
86 {
87 functions->DispatchCompute = st_dispatch_compute;
88 functions->DispatchComputeIndirect = st_dispatch_compute_indirect;
89 }