2020-09-03 12:36:58 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright © 2018 Valve Corporation
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
|
* Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
|
|
|
* IN THE SOFTWARE.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2021-06-09 15:40:03 +02:00
|
|
|
#ifndef ACO_INSTRUCTION_SELECTION_H
|
|
|
|
|
#define ACO_INSTRUCTION_SELECTION_H
|
|
|
|
|
|
2020-09-03 12:36:58 +02:00
|
|
|
#include "aco_ir.h"
|
2021-06-09 15:40:03 +02:00
|
|
|
|
2020-09-03 12:36:58 +02:00
|
|
|
#include "vulkan/radv_shader_args.h"
|
|
|
|
|
|
2021-06-09 15:40:03 +02:00
|
|
|
#include <array>
|
|
|
|
|
#include <unordered_map>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
2020-09-03 12:36:58 +02:00
|
|
|
namespace aco {
|
|
|
|
|
|
2022-06-24 16:03:52 +02:00
|
|
|
enum aco_color_output_type {
|
|
|
|
|
ACO_TYPE_ANY32,
|
|
|
|
|
ACO_TYPE_FLOAT16,
|
|
|
|
|
ACO_TYPE_INT16,
|
|
|
|
|
ACO_TYPE_UINT16,
|
|
|
|
|
};
|
|
|
|
|
|
2020-09-03 12:36:58 +02:00
|
|
|
struct shader_io_state {
|
|
|
|
|
uint8_t mask[VARYING_SLOT_MAX];
|
|
|
|
|
Temp temps[VARYING_SLOT_MAX * 4u];
|
|
|
|
|
|
2021-06-09 10:14:54 +02:00
|
|
|
shader_io_state()
|
|
|
|
|
{
|
2020-09-03 12:36:58 +02:00
|
|
|
memset(mask, 0, sizeof(mask));
|
|
|
|
|
std::fill_n(temps, VARYING_SLOT_MAX * 4u, Temp(0, RegClass::v1));
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct isel_context {
|
2022-05-16 14:54:05 +10:00
|
|
|
const struct aco_compiler_options* options;
|
2021-10-05 10:32:55 +02:00
|
|
|
const struct radv_shader_args* args;
|
2021-06-09 10:14:54 +02:00
|
|
|
Program* program;
|
|
|
|
|
nir_shader* shader;
|
2020-09-03 12:36:58 +02:00
|
|
|
uint32_t constant_data_offset;
|
2021-06-09 10:14:54 +02:00
|
|
|
Block* block;
|
2020-10-08 15:11:12 +01:00
|
|
|
uint32_t first_temp_id;
|
2021-06-09 10:14:54 +02:00
|
|
|
std::unordered_map<unsigned, std::array<Temp, NIR_MAX_VEC_COMPONENTS>> allocated_vec;
|
2020-10-05 17:50:37 +02:00
|
|
|
Stage stage;
|
2020-09-03 12:36:58 +02:00
|
|
|
struct {
|
|
|
|
|
bool has_branch;
|
|
|
|
|
struct {
|
|
|
|
|
unsigned header_idx;
|
|
|
|
|
Block* exit;
|
|
|
|
|
bool has_divergent_continue = false;
|
|
|
|
|
bool has_divergent_branch = false;
|
|
|
|
|
} parent_loop;
|
|
|
|
|
struct {
|
|
|
|
|
bool is_divergent = false;
|
|
|
|
|
} parent_if;
|
aco/gfx11: fix FS input loads in quad-divergent control flow
This is not ideal and it would be great to somehow make it better some
day.
fossil-db (gfx1100):
Totals from 5208 (3.86% of 135032) affected shaders:
MaxWaves: 127058 -> 126962 (-0.08%); split: +0.01%, -0.09%
Instrs: 3983440 -> 4072736 (+2.24%); split: -0.00%, +2.24%
CodeSize: 21872468 -> 22230852 (+1.64%); split: -0.00%, +1.64%
VGPRs: 206688 -> 206984 (+0.14%); split: -0.05%, +0.20%
Latency: 37447383 -> 37491197 (+0.12%); split: -0.05%, +0.17%
InvThroughput: 6421955 -> 6422348 (+0.01%); split: -0.03%, +0.03%
VClause: 71579 -> 71545 (-0.05%); split: -0.09%, +0.04%
SClause: 148289 -> 147146 (-0.77%); split: -0.84%, +0.07%
Copies: 259011 -> 258084 (-0.36%); split: -0.61%, +0.25%
Branches: 101366 -> 101314 (-0.05%); split: -0.10%, +0.05%
PreSGPRs: 223482 -> 223460 (-0.01%); split: -0.21%, +0.20%
PreVGPRs: 184448 -> 184744 (+0.16%)
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19370>
2022-10-26 21:11:31 +01:00
|
|
|
bool had_divergent_discard = false;
|
2021-06-09 10:14:54 +02:00
|
|
|
bool exec_potentially_empty_discard =
|
|
|
|
|
false; /* set to false when loop_nest_depth==0 && parent_if.is_divergent==false */
|
2020-09-03 12:36:58 +02:00
|
|
|
uint16_t exec_potentially_empty_break_depth = UINT16_MAX;
|
|
|
|
|
/* Set to false when loop_nest_depth==exec_potentially_empty_break_depth
|
|
|
|
|
* and parent_if.is_divergent==false. Called _break but it's also used for
|
|
|
|
|
* loop continues. */
|
|
|
|
|
bool exec_potentially_empty_break = false;
|
|
|
|
|
std::unique_ptr<unsigned[]> nir_to_aco; /* NIR block index to ACO block index */
|
|
|
|
|
} cf_info;
|
|
|
|
|
|
2020-11-02 14:01:38 +01:00
|
|
|
/* NIR range analysis. */
|
2021-06-09 10:14:54 +02:00
|
|
|
struct hash_table* range_ht;
|
2020-11-02 14:01:38 +01:00
|
|
|
nir_unsigned_upper_bound_config ub_config;
|
|
|
|
|
|
2020-09-03 12:36:58 +02:00
|
|
|
Temp arg_temps[AC_MAX_ARGS];
|
|
|
|
|
|
|
|
|
|
/* FS inputs */
|
|
|
|
|
Temp persp_centroid, linear_centroid;
|
|
|
|
|
|
|
|
|
|
/* GS inputs */
|
|
|
|
|
Temp gs_wave_id;
|
|
|
|
|
|
|
|
|
|
/* VS output information */
|
|
|
|
|
bool export_clip_dists;
|
|
|
|
|
unsigned num_clip_distances;
|
|
|
|
|
unsigned num_cull_distances;
|
|
|
|
|
|
|
|
|
|
/* tessellation information */
|
|
|
|
|
uint64_t tcs_temp_only_inputs;
|
|
|
|
|
bool tcs_in_out_eq = false;
|
|
|
|
|
|
2022-06-24 16:03:52 +02:00
|
|
|
/* Fragment color output information */
|
|
|
|
|
uint16_t output_color_types;
|
|
|
|
|
|
2020-09-03 12:36:58 +02:00
|
|
|
/* I/O information */
|
|
|
|
|
shader_io_state inputs;
|
|
|
|
|
shader_io_state outputs;
|
|
|
|
|
};
|
|
|
|
|
|
2021-06-09 10:14:54 +02:00
|
|
|
inline Temp
|
|
|
|
|
get_arg(isel_context* ctx, struct ac_arg arg)
|
2020-09-03 12:36:58 +02:00
|
|
|
{
|
|
|
|
|
assert(arg.used);
|
|
|
|
|
return ctx->arg_temps[arg.arg_index];
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-09 10:14:54 +02:00
|
|
|
void init_context(isel_context* ctx, nir_shader* shader);
|
|
|
|
|
void cleanup_context(isel_context* ctx);
|
2020-09-03 12:36:58 +02:00
|
|
|
|
2021-06-09 10:14:54 +02:00
|
|
|
isel_context setup_isel_context(Program* program, unsigned shader_count,
|
|
|
|
|
struct nir_shader* const* shaders, ac_shader_config* config,
|
2022-05-16 14:54:05 +10:00
|
|
|
const struct aco_compiler_options* options,
|
2022-05-05 13:34:41 +10:00
|
|
|
const struct aco_shader_info* info,
|
2022-07-14 18:53:46 +02:00
|
|
|
const struct radv_shader_args* args,
|
|
|
|
|
bool is_gs_copy_shader, bool is_ps_epilog);
|
2020-09-03 12:36:58 +02:00
|
|
|
|
2021-06-09 15:40:03 +02:00
|
|
|
} // namespace aco
|
|
|
|
|
|
|
|
|
|
#endif /* ACO_INSTRUCTION_SELECTION_H */
|