aco: use monotonic_buffer_resource for instructions
As monotonic_buffer_resource is not thread-safe, we use a thread_local instance which gets allocated once. This change reduces the compile time spent in ACO by approximately 10%. Reviewed-by: Timur Kristóf <timur.kristof@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18112>
This commit is contained in:
committed by
Marge Bot
parent
15b3cc73bf
commit
a128d444cb
@@ -257,6 +257,8 @@ aco_compile_shader(const struct aco_compiler_options* options,
|
||||
if (program->collect_statistics)
|
||||
stats_size = aco::num_statistics * sizeof(uint32_t);
|
||||
|
||||
aco::instruction_buffer.release();
|
||||
|
||||
(*build_binary)(binary,
|
||||
shaders[shader_count - 1]->info.stage,
|
||||
args->is_gs_copy_shader,
|
||||
@@ -308,6 +310,8 @@ aco_compile_vs_prolog(const struct aco_compiler_options* options,
|
||||
if (get_disasm)
|
||||
disasm = get_disasm_string(program.get(), code, exec_size);
|
||||
|
||||
aco::instruction_buffer.release();
|
||||
|
||||
(*build_prolog)(binary,
|
||||
config.num_sgprs,
|
||||
config.num_vgprs,
|
||||
@@ -353,6 +357,8 @@ aco_compile_ps_epilog(const struct aco_compiler_options* options,
|
||||
if (get_disasm)
|
||||
disasm = get_disasm_string(program.get(), code, exec_size);
|
||||
|
||||
aco::instruction_buffer.release();
|
||||
|
||||
(*build_epilog)(binary,
|
||||
config.num_sgprs,
|
||||
config.num_vgprs,
|
||||
|
||||
@@ -32,6 +32,8 @@
|
||||
|
||||
namespace aco {
|
||||
|
||||
thread_local aco::monotonic_buffer_resource instruction_buffer(65536);
|
||||
|
||||
uint64_t debug_flags = 0;
|
||||
|
||||
static const struct debug_control aco_debug_options[] = {{"validateir", DEBUG_VALIDATE_IR},
|
||||
|
||||
@@ -1774,8 +1774,13 @@ struct Pseudo_reduction_instruction : public Instruction {
|
||||
static_assert(sizeof(Pseudo_reduction_instruction) == sizeof(Instruction) + 4,
|
||||
"Unexpected padding");
|
||||
|
||||
extern thread_local aco::monotonic_buffer_resource instruction_buffer;
|
||||
|
||||
struct instr_deleter_functor {
|
||||
void operator()(void* p) { free(p); }
|
||||
/* Don't yet free any instructions. They will be de-allocated
|
||||
* all at once after compilation finished.
|
||||
*/
|
||||
void operator()(void* p) { return; }
|
||||
};
|
||||
|
||||
template <typename T> using aco_ptr = std::unique_ptr<T, instr_deleter_functor>;
|
||||
@@ -1787,7 +1792,8 @@ create_instruction(aco_opcode opcode, Format format, uint32_t num_operands,
|
||||
{
|
||||
std::size_t size =
|
||||
sizeof(T) + num_operands * sizeof(Operand) + num_definitions * sizeof(Definition);
|
||||
void* data = calloc(1, size);
|
||||
void* data = instruction_buffer.allocate(size, alignof(uint32_t));
|
||||
memset(data, 0, size);
|
||||
T* inst = (T*)data;
|
||||
|
||||
inst->opcode = opcode;
|
||||
|
||||
Reference in New Issue
Block a user