2 * Copyright © 2014 Intel Corporation
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:
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
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
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
24 #include <sys/errno.h>
26 #include "main/condrender.h"
27 #include "main/mtypes.h"
28 #include "main/state.h"
29 #include "brw_context.h"
31 #include "brw_state.h"
32 #include "intel_batchbuffer.h"
33 #include "intel_buffer_objects.h"
34 #include "brw_defines.h"
38 brw_dispatch_compute_common(struct gl_context
*ctx
)
40 struct brw_context
*brw
= brw_context(ctx
);
43 if (!_mesa_check_conditional_render(ctx
))
47 _mesa_update_state(ctx
);
49 brw_validate_textures(brw
);
51 brw_predraw_resolve_inputs(brw
, false, NULL
);
53 /* Flush the batch if the batch/state buffers are nearly full. We can
54 * grow them if needed, but this is not free, so we'd like to avoid it.
56 intel_batchbuffer_require_space(brw
, 600);
57 brw_require_statebuffer_space(brw
, 2500);
58 intel_batchbuffer_save_state(brw
);
59 fail_next
= intel_batchbuffer_saved_state_is_empty(brw
);
62 brw
->batch
.no_wrap
= true;
63 brw_upload_compute_state(brw
);
65 brw
->vtbl
.emit_compute_walker(brw
);
67 brw
->batch
.no_wrap
= false;
69 if (!brw_batch_has_aperture_space(brw
, 0)) {
71 intel_batchbuffer_reset_to_saved(brw
);
72 intel_batchbuffer_flush(brw
);
76 int ret
= intel_batchbuffer_flush(brw
);
77 WARN_ONCE(ret
== -ENOSPC
,
78 "i965: Single compute shader dispatch "
79 "exceeded available aperture space\n");
83 /* Now that we know we haven't run out of aperture space, we can safely
84 * reset the dirty bits.
86 brw_compute_state_finished(brw
);
88 if (brw
->always_flush_batch
)
89 intel_batchbuffer_flush(brw
);
91 brw_program_cache_check_size(brw
);
93 /* Note: since compute shaders can't write to framebuffers, there's no need
94 * to call brw_postdraw_set_buffers_need_resolve().
99 brw_dispatch_compute(struct gl_context
*ctx
, const GLuint
*num_groups
) {
100 struct brw_context
*brw
= brw_context(ctx
);
102 brw
->compute
.num_work_groups_bo
= NULL
;
103 brw
->compute
.num_work_groups
= num_groups
;
104 ctx
->NewDriverState
|= BRW_NEW_CS_WORK_GROUPS
;
106 brw_dispatch_compute_common(ctx
);
110 brw_dispatch_compute_indirect(struct gl_context
*ctx
, GLintptr indirect
)
112 struct brw_context
*brw
= brw_context(ctx
);
113 static const GLuint indirect_group_counts
[3] = { 0, 0, 0 };
114 struct gl_buffer_object
*indirect_buffer
= ctx
->DispatchIndirectBuffer
;
116 intel_bufferobj_buffer(brw
,
117 intel_buffer_object(indirect_buffer
),
118 indirect
, 3 * sizeof(GLuint
), false);
120 brw
->compute
.num_work_groups_bo
= bo
;
121 brw
->compute
.num_work_groups_offset
= indirect
;
122 brw
->compute
.num_work_groups
= indirect_group_counts
;
123 ctx
->NewDriverState
|= BRW_NEW_CS_WORK_GROUPS
;
125 brw_dispatch_compute_common(ctx
);
129 brw_init_compute_functions(struct dd_function_table
*functions
)
131 functions
->DispatchCompute
= brw_dispatch_compute
;
132 functions
->DispatchComputeIndirect
= brw_dispatch_compute_indirect
;