1 /**************************************************************************
3 * Copyright 2016 Samuel Pitoiset
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
28 #include "main/state.h"
30 #include "st_context.h"
31 #include "st_cb_bitmap.h"
32 #include "st_cb_bufferobjects.h"
33 #include "st_cb_compute.h"
35 #include "pipe/p_context.h"
37 static void st_dispatch_compute_common(struct gl_context
*ctx
,
38 const GLuint
*num_groups
,
39 const GLuint
*group_size
,
40 struct pipe_resource
*indirect
,
41 GLintptr indirect_offset
)
43 struct gl_program
*prog
=
44 ctx
->_Shader
->CurrentProgram
[MESA_SHADER_COMPUTE
];
45 struct st_context
*st
= st_context(ctx
);
46 struct pipe_context
*pipe
= st
->pipe
;
47 struct pipe_grid_info info
= { 0 };
49 st_flush_bitmap_cache(st
);
50 st_invalidate_readpix_cache(st
);
53 _mesa_update_state(ctx
);
55 if ((st
->dirty
| ctx
->NewDriverState
) & ST_PIPELINE_COMPUTE_STATE_MASK
||
56 st
->compute_shader_may_be_dirty
)
57 st_validate_state(st
, ST_PIPELINE_COMPUTE
);
59 for (unsigned i
= 0; i
< 3; i
++) {
60 info
.block
[i
] = group_size
? group_size
[i
] : prog
->info
.cs
.local_size
[i
];
61 info
.grid
[i
] = num_groups
? num_groups
[i
] : 0;
65 info
.indirect
= indirect
;
66 info
.indirect_offset
= indirect_offset
;
69 pipe
->launch_grid(pipe
, &info
);
72 static void st_dispatch_compute(struct gl_context
*ctx
,
73 const GLuint
*num_groups
)
75 st_dispatch_compute_common(ctx
, num_groups
, NULL
, NULL
, 0);
78 static void st_dispatch_compute_indirect(struct gl_context
*ctx
,
79 GLintptr indirect_offset
)
81 struct gl_buffer_object
*indirect_buffer
= ctx
->DispatchIndirectBuffer
;
82 struct pipe_resource
*indirect
= st_buffer_object(indirect_buffer
)->buffer
;
84 st_dispatch_compute_common(ctx
, NULL
, NULL
, indirect
, indirect_offset
);
87 static void st_dispatch_compute_group_size(struct gl_context
*ctx
,
88 const GLuint
*num_groups
,
89 const GLuint
*group_size
)
91 st_dispatch_compute_common(ctx
, num_groups
, group_size
, NULL
, 0);
94 void st_init_compute_functions(struct dd_function_table
*functions
)
96 functions
->DispatchCompute
= st_dispatch_compute
;
97 functions
->DispatchComputeIndirect
= st_dispatch_compute_indirect
;
98 functions
->DispatchComputeGroupSize
= st_dispatch_compute_group_size
;