intel/brw: Fold simple_allocator into the shader

This was originally turned into a separate struct for reuse between vec4
and fs backends, that's not needed anymore.

Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/33334>
This commit is contained in:
Caio Oliveira 2025-01-31 14:56:50 -08:00
parent f82bcd56fc
commit b50c925bd6
6 changed files with 33 additions and 80 deletions

View file

@ -838,6 +838,23 @@ bool brw_should_print_shader(const nir_shader *shader, uint64_t debug_flag)
return INTEL_DEBUG(debug_flag) && (!shader->info.internal || NIR_DEBUG(PRINT_INTERNAL));
}
static unsigned
brw_allocate_vgrf_number(fs_visitor &s, unsigned size_in_REGSIZE_units)
{
assert(size_in_REGSIZE_units > 0);
if (s.alloc.capacity <= s.alloc.count) {
unsigned new_cap = MAX2(16, s.alloc.capacity * 2);
s.alloc.sizes = rerzalloc(s.mem_ctx, s.alloc.sizes, unsigned,
s.alloc.capacity, new_cap);
s.alloc.capacity = new_cap;
}
s.alloc.sizes[s.alloc.count] = size_in_REGSIZE_units;
return s.alloc.count++;
}
brw_reg
brw_allocate_vgrf(fs_visitor &s, brw_reg_type type, unsigned count)
{
@ -850,6 +867,6 @@ brw_allocate_vgrf(fs_visitor &s, brw_reg_type type, unsigned count)
brw_reg
brw_allocate_vgrf_units(fs_visitor &s, unsigned units_of_REGSIZE)
{
return brw_vgrf(s.alloc.allocate(units_of_REGSIZE), BRW_TYPE_UD);
return brw_vgrf(brw_allocate_vgrf_number(s, units_of_REGSIZE), BRW_TYPE_UD);
}

View file

@ -31,7 +31,6 @@
#include "brw_cfg.h"
#include "brw_compiler.h"
#include "brw_inst.h"
#include "brw_ir_allocator.h"
#include "compiler/nir/nir.h"
#include "brw_analysis.h"
@ -226,7 +225,16 @@ public:
gl_shader_stage stage;
bool debug_enabled;
brw::simple_allocator alloc;
/* VGRF allocation. */
struct {
/** Array of sizes for each allocation, in REG_SIZE units. */
unsigned *sizes;
/** Total number of VGRFs allocated. */
unsigned count;
unsigned capacity;
} alloc;
const brw_base_prog_key *const key;

View file

@ -446,6 +446,10 @@ fs_visitor::init()
this->gs.control_data_bits_per_vertex = 0;
this->gs.control_data_header_size_bits = 0;
this->alloc.capacity = 0;
this->alloc.sizes = NULL;
this->alloc.count = 0;
}
fs_visitor::~fs_visitor()

View file

@ -3,6 +3,7 @@
* SPDX-License-Identifier: MIT
*/
#include "brw_fs.h"
#include "brw_eu.h"
#include "brw_fs.h"
#include "brw_cfg.h"

View file

@ -1,76 +0,0 @@
/* -*- c++ -*- */
/*
* Copyright © 2010-2014 Intel 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.
*/
#pragma once
#include "util/compiler.h"
#include "util/glheader.h"
#include "util/macros.h"
#include "util/rounding.h"
#include "util/u_math.h"
namespace brw {
/**
* Simple allocator used to keep track of virtual GRFs.
*/
class simple_allocator {
public:
simple_allocator() :
sizes(NULL), count(0), capacity(0)
{
}
~simple_allocator()
{
free(sizes);
}
unsigned
allocate(unsigned size)
{
assert(size > 0);
if (capacity <= count) {
capacity = MAX2(16, capacity * 2);
sizes = (unsigned *)realloc(sizes, capacity * sizeof(unsigned));
}
sizes[count] = size;
return count++;
}
/**
* Array of sizes for each allocation. The allocation unit is up to the
* back-end, but it's expected to be one scalar value in the FS back-end
* and one vec4 in the VEC4 back-end.
*/
unsigned *sizes;
/** Total number of VGRFs allocated. */
unsigned count;
private:
unsigned capacity;
};
}

View file

@ -60,7 +60,6 @@ libintel_compiler_brw_files = files(
'brw_generator.h',
'brw_inst.cpp',
'brw_inst.h',
'brw_ir_allocator.h',
'brw_isa_info.h',
'brw_lower.cpp',
'brw_lower_dpas.cpp',