1 /* -*- c++ -*- */
2 /*
3 * Copyright © 2021 Intel Corporation
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * 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 DEALINGS
22 * IN THE SOFTWARE.
23 */
24
25 #pragma once
26
27 #include "elk_compiler.h"
28
29 #include <variant>
30
31 unsigned elk_required_dispatch_width(const struct shader_info *info);
32
33 static constexpr int SIMD_COUNT = 3;
34
35 struct elk_simd_selection_state {
36 const struct intel_device_info *devinfo;
37
38 std::variant<struct elk_cs_prog_data *,
39 struct elk_bs_prog_data *> prog_data;
40
41 unsigned required_width;
42
43 const char *error[SIMD_COUNT];
44
45 bool compiled[SIMD_COUNT];
46 bool spilled[SIMD_COUNT];
47 };
48
elk_simd_first_compiled(const elk_simd_selection_state & state)49 inline int elk_simd_first_compiled(const elk_simd_selection_state &state)
50 {
51 for (int i = 0; i < SIMD_COUNT; i++) {
52 if (state.compiled[i])
53 return i;
54 }
55 return -1;
56 }
57
elk_simd_any_compiled(const elk_simd_selection_state & state)58 inline bool elk_simd_any_compiled(const elk_simd_selection_state &state)
59 {
60 return elk_simd_first_compiled(state) >= 0;
61 }
62
63 bool elk_simd_should_compile(elk_simd_selection_state &state, unsigned simd);
64
65 void elk_simd_mark_compiled(elk_simd_selection_state &state, unsigned simd, bool spilled);
66
67 int elk_simd_select(const elk_simd_selection_state &state);
68
69 int elk_simd_select_for_workgroup_size(const struct intel_device_info *devinfo,
70 const struct elk_cs_prog_data *prog_data,
71 const unsigned *sizes);
72
73 bool elk_should_print_shader(const nir_shader *shader, uint64_t debug_flag);
74