2 * Mesa 3-D graphics library
4 * Copyright (C) 2012-2013 LunarG, Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
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 NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
25 * Chia-I Wu <olv@lunarg.com>
28 #include "util/u_upload_mgr.h"
29 #include "ilo_context.h"
30 #include "ilo_render.h"
31 #include "ilo_shader.h"
32 #include "ilo_gpgpu.h"
35 launch_grid(struct ilo_context
*ilo
,
36 const uint
*block_layout
, const uint
*grid_layout
,
37 const struct pipe_constant_buffer
*input
, uint32_t pc
)
39 const unsigned grid_offset
[3] = { 0, 0, 0 };
40 const unsigned thread_group_size
=
41 block_layout
[0] * block_layout
[1] * block_layout
[2];
42 int max_len
, before_space
;
44 ilo_cp_set_owner(ilo
->cp
, INTEL_RING_RENDER
, NULL
);
46 max_len
= ilo_render_get_launch_grid_len(ilo
->render
, &ilo
->state_vector
);
47 max_len
+= ilo_render_get_flush_len(ilo
->render
) * 2;
49 if (max_len
> ilo_cp_space(ilo
->cp
)) {
50 ilo_cp_submit(ilo
->cp
, "out of space");
51 assert(max_len
<= ilo_cp_space(ilo
->cp
));
54 before_space
= ilo_cp_space(ilo
->cp
);
57 struct ilo_builder_snapshot snapshot
;
59 ilo_builder_batch_snapshot(&ilo
->cp
->builder
, &snapshot
);
61 ilo_render_emit_launch_grid(ilo
->render
, &ilo
->state_vector
,
62 grid_offset
, grid_layout
, thread_group_size
, input
, pc
);
64 if (!ilo_builder_validate(&ilo
->cp
->builder
, 0, NULL
)) {
65 ilo_builder_batch_restore(&ilo
->cp
->builder
, &snapshot
);
67 /* flush and try again */
68 if (ilo_builder_batch_used(&ilo
->cp
->builder
)) {
69 ilo_cp_submit(ilo
->cp
, "out of aperture");
77 /* sanity check size estimation */
78 assert(before_space
- ilo_cp_space(ilo
->cp
) <= max_len
);
82 ilo_launch_grid(struct pipe_context
*pipe
,
83 const uint
*block_layout
, const uint
*grid_layout
,
84 uint32_t pc
, const void *input
)
86 struct ilo_context
*ilo
= ilo_context(pipe
);
87 struct ilo_shader_state
*cs
= ilo
->state_vector
.cs
;
88 struct pipe_constant_buffer input_buf
;
90 memset(&input_buf
, 0, sizeof(input_buf
));
92 input_buf
.buffer_size
=
93 ilo_shader_get_kernel_param(cs
, ILO_KERNEL_CS_INPUT_SIZE
);
94 if (input_buf
.buffer_size
) {
95 u_upload_data(ilo
->uploader
, 0, input_buf
.buffer_size
, 16, input
,
96 &input_buf
.buffer_offset
, &input_buf
.buffer
);
99 ilo_shader_cache_upload(ilo
->shader_cache
, &ilo
->cp
->builder
);
101 launch_grid(ilo
, block_layout
, grid_layout
, &input_buf
, pc
);
103 ilo_render_invalidate_hw(ilo
->render
);
105 if (ilo_debug
& ILO_DEBUG_NOCACHE
)
106 ilo_render_emit_flush(ilo
->render
);
108 if (input_buf
.buffer_size
)
109 pipe_resource_reference(&input_buf
.buffer
, NULL
);
113 * Initialize GPGPU-related functions.
116 ilo_init_gpgpu_functions(struct ilo_context
*ilo
)
118 ilo
->base
.launch_grid
= ilo_launch_grid
;