1 /* 2 * Mesa 3-D graphics library 3 * 4 * Copyright (C) 2012-2013 LunarG, Inc. 5 * 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: 12 * 13 * The above copyright notice and this permission notice shall be included 14 * in all copies or substantial portions of the Software. 15 * 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. 23 * 24 * Authors: 25 * Chia-I Wu <olv (at) lunarg.com> 26 */ 27 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" 33 34 static void 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) 38 { 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; 43 44 ilo_cp_set_owner(ilo->cp, INTEL_RING_RENDER, NULL); 45 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; 48 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)); 52 } 53 54 before_space = ilo_cp_space(ilo->cp); 55 56 while (true) { 57 struct ilo_builder_snapshot snapshot; 58 59 ilo_builder_batch_snapshot(&ilo->cp->builder, &snapshot); 60 61 ilo_render_emit_launch_grid(ilo->render, &ilo->state_vector, 62 grid_offset, grid_layout, thread_group_size, input, pc); 63 64 if (!ilo_builder_validate(&ilo->cp->builder, 0, NULL)) { 65 ilo_builder_batch_restore(&ilo->cp->builder, &snapshot); 66 67 /* flush and try again */ 68 if (ilo_builder_batch_used(&ilo->cp->builder)) { 69 ilo_cp_submit(ilo->cp, "out of aperture"); 70 continue; 71 } 72 } 73 74 break; 75 } 76 77 /* sanity check size estimation */ 78 assert(before_space - ilo_cp_space(ilo->cp) <= max_len); 79 } 80 81 static void 82 ilo_launch_grid(struct pipe_context *pipe, const struct pipe_grid_info *info) 83 { 84 struct ilo_context *ilo = ilo_context(pipe); 85 struct ilo_shader_state *cs = ilo->state_vector.cs; 86 struct pipe_constant_buffer input_buf; 87 88 memset(&input_buf, 0, sizeof(input_buf)); 89 90 input_buf.buffer_size = 91 ilo_shader_get_kernel_param(cs, ILO_KERNEL_CS_INPUT_SIZE); 92 if (input_buf.buffer_size) { 93 u_upload_data(ilo->uploader, 0, input_buf.buffer_size, 16, info->input, 94 &input_buf.buffer_offset, &input_buf.buffer); 95 } 96 97 ilo_shader_cache_upload(ilo->shader_cache, &ilo->cp->builder); 98 99 launch_grid(ilo, info->block, info->grid, &input_buf, info->pc); 100 101 ilo_render_invalidate_hw(ilo->render); 102 103 if (ilo_debug & ILO_DEBUG_NOCACHE) 104 ilo_render_emit_flush(ilo->render); 105 106 if (input_buf.buffer_size) 107 pipe_resource_reference(&input_buf.buffer, NULL); 108 } 109 110 /** 111 * Initialize GPGPU-related functions. 112 */ 113 void 114 ilo_init_gpgpu_functions(struct ilo_context *ilo) 115 { 116 ilo->base.launch_grid = ilo_launch_grid; 117 } 118