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/glheader.h"
28 #include "main/mtypes.h"
29 #include "main/state.h"
30 #include "brw_context.h"
32 #include "brw_state.h"
33 #include "intel_batchbuffer.h"
37 brw_emit_gpgpu_walker(struct brw_context
*brw
, const GLuint
*num_groups
)
39 _mesa_problem(&brw
->ctx
, "TODO: implement brw_emit_gpgpu_walker");
44 brw_dispatch_compute(struct gl_context
*ctx
, const GLuint
*num_groups
)
46 struct brw_context
*brw
= brw_context(ctx
);
47 int estimated_buffer_space_needed
;
48 bool fail_next
= false;
50 if (!_mesa_check_conditional_render(ctx
))
54 _mesa_update_state(ctx
);
56 brw_validate_textures(brw
);
58 const int sampler_state_size
= 16; /* 16 bytes */
59 estimated_buffer_space_needed
= 512; /* batchbuffer commands */
60 estimated_buffer_space_needed
+= (BRW_MAX_TEX_UNIT
*
62 sizeof(struct gen5_sampler_default_color
)));
63 estimated_buffer_space_needed
+= 1024; /* push constants */
64 estimated_buffer_space_needed
+= 512; /* misc. pad */
66 /* Flush the batch if it's approaching full, so that we don't wrap while
67 * we've got validated state that needs to be in the same batch as the
70 intel_batchbuffer_require_space(brw
, estimated_buffer_space_needed
,
72 intel_batchbuffer_save_state(brw
);
75 brw
->no_batch_wrap
= true;
76 brw_upload_compute_state(brw
);
78 brw_emit_gpgpu_walker(brw
, num_groups
);
80 brw
->no_batch_wrap
= false;
82 if (dri_bufmgr_check_aperture_space(&brw
->batch
.bo
, 1)) {
84 intel_batchbuffer_reset_to_saved(brw
);
85 intel_batchbuffer_flush(brw
);
89 if (intel_batchbuffer_flush(brw
) == -ENOSPC
) {
90 static bool warned
= false;
93 fprintf(stderr
, "i965: Single compute shader dispatch "
94 "exceeded available aperture space\n");
101 /* Now that we know we haven't run out of aperture space, we can safely
102 * reset the dirty bits.
104 brw_compute_state_finished(brw
);
106 if (brw
->always_flush_batch
)
107 intel_batchbuffer_flush(brw
);
109 brw_state_cache_check_size(brw
);
111 /* Note: since compute shaders can't write to framebuffers, there's no need
112 * to call brw_postdraw_set_buffers_need_resolve().
118 brw_init_compute_functions(struct dd_function_table
*functions
)
120 functions
->DispatchCompute
= brw_dispatch_compute
;