gallium: inline struct u_suballocator to remove dereferences
Reviewed-by: Eric Anholt <eric@anholt.net> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7901>
This commit is contained in:
@@ -36,21 +36,6 @@
|
||||
|
||||
#include "u_suballoc.h"
|
||||
|
||||
|
||||
struct u_suballocator {
|
||||
struct pipe_context *pipe;
|
||||
|
||||
unsigned size; /* Size of the whole buffer, in bytes. */
|
||||
unsigned bind; /* Bitmask of PIPE_BIND_* flags. */
|
||||
enum pipe_resource_usage usage;
|
||||
unsigned flags; /* bitmask of PIPE_RESOURCE_FLAG_x */
|
||||
boolean zero_buffer_memory; /* If the buffer contents should be zeroed. */
|
||||
|
||||
struct pipe_resource *buffer; /* The buffer we suballocate from. */
|
||||
unsigned offset; /* Aligned offset pointing at the first unused byte. */
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Create a suballocator.
|
||||
*
|
||||
@@ -59,14 +44,14 @@ struct u_suballocator {
|
||||
* cleared to 0 after the allocation.
|
||||
*
|
||||
*/
|
||||
struct u_suballocator *
|
||||
u_suballocator_create(struct pipe_context *pipe, unsigned size, unsigned bind,
|
||||
enum pipe_resource_usage usage, unsigned flags,
|
||||
boolean zero_buffer_memory)
|
||||
void
|
||||
u_suballocator_init(struct u_suballocator *allocator,
|
||||
struct pipe_context *pipe,
|
||||
unsigned size, unsigned bind,
|
||||
enum pipe_resource_usage usage, unsigned flags,
|
||||
boolean zero_buffer_memory)
|
||||
{
|
||||
struct u_suballocator *allocator = CALLOC_STRUCT(u_suballocator);
|
||||
if (!allocator)
|
||||
return NULL;
|
||||
memset(allocator, 0, sizeof(*allocator));
|
||||
|
||||
allocator->pipe = pipe;
|
||||
allocator->size = size;
|
||||
@@ -74,14 +59,12 @@ u_suballocator_create(struct pipe_context *pipe, unsigned size, unsigned bind,
|
||||
allocator->usage = usage;
|
||||
allocator->flags = flags;
|
||||
allocator->zero_buffer_memory = zero_buffer_memory;
|
||||
return allocator;
|
||||
}
|
||||
|
||||
void
|
||||
u_suballocator_destroy(struct u_suballocator *allocator)
|
||||
{
|
||||
pipe_resource_reference(&allocator->buffer, NULL);
|
||||
FREE(allocator);
|
||||
}
|
||||
|
||||
void
|
||||
|
@@ -31,16 +31,31 @@
|
||||
#ifndef U_SUBALLOC
|
||||
#define U_SUBALLOC
|
||||
|
||||
struct u_suballocator;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct u_suballocator *
|
||||
u_suballocator_create(struct pipe_context *pipe, unsigned size, unsigned bind,
|
||||
enum pipe_resource_usage usage, unsigned flags,
|
||||
boolean zero_buffer_memory);
|
||||
struct pipe_context;
|
||||
|
||||
struct u_suballocator {
|
||||
struct pipe_context *pipe;
|
||||
|
||||
unsigned size; /* Size of the whole buffer, in bytes. */
|
||||
unsigned bind; /* Bitmask of PIPE_BIND_* flags. */
|
||||
enum pipe_resource_usage usage;
|
||||
unsigned flags; /* bitmask of PIPE_RESOURCE_FLAG_x */
|
||||
boolean zero_buffer_memory; /* If the buffer contents should be zeroed. */
|
||||
|
||||
struct pipe_resource *buffer; /* The buffer we suballocate from. */
|
||||
unsigned offset; /* Aligned offset pointing at the first unused byte. */
|
||||
};
|
||||
|
||||
void
|
||||
u_suballocator_init(struct u_suballocator *allocator,
|
||||
struct pipe_context *pipe,
|
||||
unsigned size, unsigned bind,
|
||||
enum pipe_resource_usage usage, unsigned flags,
|
||||
boolean zero_buffer_memory);
|
||||
|
||||
void
|
||||
u_suballocator_destroy(struct u_suballocator *allocator);
|
||||
|
@@ -76,7 +76,7 @@ d3d12_context_destroy(struct pipe_context *pctx)
|
||||
d3d12_gfx_pipeline_state_cache_destroy(ctx);
|
||||
d3d12_root_signature_cache_destroy(ctx);
|
||||
|
||||
u_suballocator_destroy(ctx->query_allocator);
|
||||
u_suballocator_destroy(&ctx->query_allocator);
|
||||
|
||||
if (pctx->stream_uploader)
|
||||
u_upload_destroy(pctx->stream_uploader);
|
||||
@@ -1354,7 +1354,7 @@ d3d12_set_stream_output_targets(struct pipe_context *pctx,
|
||||
|
||||
if (target) {
|
||||
/* Sub-allocate a new fill buffer each time to avoid GPU/CPU synchronization */
|
||||
u_suballocator_alloc(ctx->so_allocator, sizeof(uint64_t), 4,
|
||||
u_suballocator_alloc(&ctx->so_allocator, sizeof(uint64_t), 4,
|
||||
&target->fill_buffer_offset, &target->fill_buffer);
|
||||
fill_stream_output_buffer_view(&ctx->so_buffer_views[i], target);
|
||||
pipe_so_target_reference(&ctx->so_targets[i], targets[i]);
|
||||
@@ -1407,7 +1407,7 @@ d3d12_enable_fake_so_buffers(struct d3d12_context *ctx, unsigned factor)
|
||||
PIPE_BIND_STREAM_OUTPUT,
|
||||
PIPE_USAGE_STAGING,
|
||||
target->base.buffer->width0 * factor);
|
||||
u_suballocator_alloc(ctx->so_allocator, sizeof(uint64_t), 4,
|
||||
u_suballocator_alloc(&ctx->so_allocator, sizeof(uint64_t), 4,
|
||||
&fake_target->fill_buffer_offset, &fake_target->fill_buffer);
|
||||
pipe_buffer_read(&ctx->base, target->fill_buffer,
|
||||
target->fill_buffer_offset, sizeof(uint64_t),
|
||||
@@ -1913,9 +1913,9 @@ d3d12_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags)
|
||||
|
||||
ctx->base.stream_uploader = u_upload_create_default(&ctx->base);
|
||||
ctx->base.const_uploader = u_upload_create_default(&ctx->base);
|
||||
ctx->so_allocator = u_suballocator_create(&ctx->base, 4096, 0,
|
||||
PIPE_USAGE_DEFAULT,
|
||||
0, true);
|
||||
u_suballocator_init(&ctx->so_allocator, &ctx->base, 4096, 0,
|
||||
PIPE_USAGE_DEFAULT,
|
||||
0, true);
|
||||
|
||||
struct primconvert_config cfg;
|
||||
cfg.primtypes_mask = 1 << PIPE_PRIM_POINTS |
|
||||
|
@@ -166,8 +166,8 @@ struct d3d12_context {
|
||||
struct slab_child_pool transfer_pool;
|
||||
struct primconvert_context *primconvert;
|
||||
struct blitter_context *blitter;
|
||||
struct u_suballocator *query_allocator;
|
||||
struct u_suballocator *so_allocator;
|
||||
struct u_suballocator query_allocator;
|
||||
struct u_suballocator so_allocator;
|
||||
struct hash_table *pso_cache;
|
||||
struct hash_table *root_signature_cache;
|
||||
struct hash_table *gs_variant_cache;
|
||||
|
@@ -144,7 +144,7 @@ d3d12_create_query(struct pipe_context *pctx,
|
||||
|
||||
/* Query result goes into a readback buffer */
|
||||
size_t buffer_size = query->query_size * query->num_queries;
|
||||
u_suballocator_alloc(ctx->query_allocator, buffer_size, 256,
|
||||
u_suballocator_alloc(&ctx->query_allocator, buffer_size, 256,
|
||||
&query->buffer_offset, &query->buffer);
|
||||
|
||||
return (struct pipe_query *)query;
|
||||
@@ -509,9 +509,8 @@ d3d12_context_query_init(struct pipe_context *pctx)
|
||||
struct d3d12_context *ctx = d3d12_context(pctx);
|
||||
list_inithead(&ctx->active_queries);
|
||||
|
||||
ctx->query_allocator =
|
||||
u_suballocator_create(&ctx->base, 4096, 0, PIPE_USAGE_STAGING,
|
||||
0, true);
|
||||
u_suballocator_init(&ctx->query_allocator, &ctx->base, 4096, 0, PIPE_USAGE_STAGING,
|
||||
0, true);
|
||||
|
||||
pctx->create_query = d3d12_create_query;
|
||||
pctx->destroy_query = d3d12_destroy_query;
|
||||
|
@@ -2765,7 +2765,7 @@ void *r600_create_vertex_fetch_shader(struct pipe_context *ctx,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
u_suballocator_alloc(rctx->allocator_fetch_shader, fs_size, 256,
|
||||
u_suballocator_alloc(&rctx->allocator_fetch_shader, fs_size, 256,
|
||||
&shader->offset,
|
||||
(struct pipe_resource**)&shader->buffer);
|
||||
if (!shader->buffer) {
|
||||
|
@@ -451,7 +451,7 @@ void r600_emit_pfp_sync_me(struct r600_context *rctx)
|
||||
uint64_t va;
|
||||
|
||||
/* 16-byte address alignment is required by WAIT_REG_MEM. */
|
||||
u_suballocator_alloc(rctx->b.allocator_zeroed_memory, 4, 16,
|
||||
u_suballocator_alloc(&rctx->b.allocator_zeroed_memory, 4, 16,
|
||||
&offset, (struct pipe_resource**)&buf);
|
||||
if (!buf) {
|
||||
/* This is too heavyweight, but will work. */
|
||||
|
@@ -118,9 +118,7 @@ static void r600_destroy_context(struct pipe_context *context)
|
||||
if (rctx->blitter) {
|
||||
util_blitter_destroy(rctx->blitter);
|
||||
}
|
||||
if (rctx->allocator_fetch_shader) {
|
||||
u_suballocator_destroy(rctx->allocator_fetch_shader);
|
||||
}
|
||||
u_suballocator_destroy(&rctx->allocator_fetch_shader);
|
||||
|
||||
r600_release_command_buffer(&rctx->start_cs_cmd);
|
||||
|
||||
@@ -215,11 +213,8 @@ static struct pipe_context *r600_create_context(struct pipe_screen *screen,
|
||||
r600_context_gfx_flush, rctx, false);
|
||||
rctx->b.gfx.flush = r600_context_gfx_flush;
|
||||
|
||||
rctx->allocator_fetch_shader =
|
||||
u_suballocator_create(&rctx->b.b, 64 * 1024,
|
||||
0, PIPE_USAGE_DEFAULT, 0, FALSE);
|
||||
if (!rctx->allocator_fetch_shader)
|
||||
goto fail;
|
||||
u_suballocator_init(&rctx->allocator_fetch_shader, &rctx->b.b, 64 * 1024,
|
||||
0, PIPE_USAGE_DEFAULT, 0, FALSE);
|
||||
|
||||
rctx->isa = calloc(1, sizeof(struct r600_isa));
|
||||
if (!rctx->isa || r600_isa_init(rctx, rctx->isa))
|
||||
|
@@ -490,7 +490,7 @@ struct r600_context {
|
||||
struct r600_common_context b;
|
||||
struct r600_screen *screen;
|
||||
struct blitter_context *blitter;
|
||||
struct u_suballocator *allocator_fetch_shader;
|
||||
struct u_suballocator allocator_fetch_shader;
|
||||
|
||||
/* Hardware info. */
|
||||
boolean has_vertex_cache;
|
||||
|
@@ -617,11 +617,8 @@ bool r600_common_context_init(struct r600_common_context *rctx,
|
||||
r600_query_init(rctx);
|
||||
cayman_init_msaa(&rctx->b);
|
||||
|
||||
rctx->allocator_zeroed_memory =
|
||||
u_suballocator_create(&rctx->b, rscreen->info.gart_page_size,
|
||||
0, PIPE_USAGE_DEFAULT, 0, true);
|
||||
if (!rctx->allocator_zeroed_memory)
|
||||
return false;
|
||||
u_suballocator_init(&rctx->allocator_zeroed_memory, &rctx->b, rscreen->info.gart_page_size,
|
||||
0, PIPE_USAGE_DEFAULT, 0, true);
|
||||
|
||||
rctx->b.stream_uploader = u_upload_create(&rctx->b, 1024 * 1024,
|
||||
0, PIPE_USAGE_STREAM, 0);
|
||||
@@ -667,9 +664,7 @@ void r600_common_context_cleanup(struct r600_common_context *rctx)
|
||||
slab_destroy_child(&rctx->pool_transfers);
|
||||
slab_destroy_child(&rctx->pool_transfers_unsync);
|
||||
|
||||
if (rctx->allocator_zeroed_memory) {
|
||||
u_suballocator_destroy(rctx->allocator_zeroed_memory);
|
||||
}
|
||||
u_suballocator_destroy(&rctx->allocator_zeroed_memory);
|
||||
rctx->ws->fence_reference(&rctx->last_gfx_fence, NULL);
|
||||
rctx->ws->fence_reference(&rctx->last_sdma_fence, NULL);
|
||||
r600_resource_reference(&rctx->eop_bug_scratch, NULL);
|
||||
|
@@ -508,7 +508,7 @@ struct r600_common_context {
|
||||
unsigned last_num_draw_calls;
|
||||
|
||||
struct threaded_context *tc;
|
||||
struct u_suballocator *allocator_zeroed_memory;
|
||||
struct u_suballocator allocator_zeroed_memory;
|
||||
struct slab_child_pool pool_transfers;
|
||||
struct slab_child_pool pool_transfers_unsync; /* for threaded_context */
|
||||
|
||||
|
@@ -1637,7 +1637,7 @@ static void r600_query_hw_get_result_resource(struct r600_common_context *rctx,
|
||||
}
|
||||
|
||||
if (query->buffer.previous) {
|
||||
u_suballocator_alloc(rctx->allocator_zeroed_memory, 16, 256,
|
||||
u_suballocator_alloc(&rctx->allocator_zeroed_memory, 16, 256,
|
||||
&tmp_buffer_offset, &tmp_buffer);
|
||||
if (!tmp_buffer)
|
||||
return;
|
||||
|
@@ -51,7 +51,7 @@ r600_create_so_target(struct pipe_context *ctx,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
u_suballocator_alloc(rctx->allocator_zeroed_memory, 4, 4,
|
||||
u_suballocator_alloc(&rctx->allocator_zeroed_memory, 4, 4,
|
||||
&t->buf_filled_size_offset,
|
||||
(struct pipe_resource**)&t->buf_filled_size);
|
||||
if (!t->buf_filled_size) {
|
||||
|
@@ -341,7 +341,7 @@ static void gfx10_sh_query_get_result_resource(struct si_context *sctx, struct s
|
||||
}
|
||||
|
||||
if (query->first != query->last) {
|
||||
u_suballocator_alloc(sctx->allocator_zeroed_memory, 16, 16, &tmp_buffer_offset, &tmp_buffer);
|
||||
u_suballocator_alloc(&sctx->allocator_zeroed_memory, 16, 16, &tmp_buffer_offset, &tmp_buffer);
|
||||
if (!tmp_buffer)
|
||||
return;
|
||||
}
|
||||
|
@@ -305,8 +305,7 @@ static void si_destroy_context(struct pipe_context *context)
|
||||
slab_destroy_child(&sctx->pool_transfers);
|
||||
slab_destroy_child(&sctx->pool_transfers_unsync);
|
||||
|
||||
if (sctx->allocator_zeroed_memory)
|
||||
u_suballocator_destroy(sctx->allocator_zeroed_memory);
|
||||
u_suballocator_destroy(&sctx->allocator_zeroed_memory);
|
||||
|
||||
sctx->ws->fence_reference(&sctx->last_gfx_fence, NULL);
|
||||
sctx->ws->fence_reference(&sctx->last_sdma_fence, NULL);
|
||||
@@ -488,11 +487,9 @@ static struct pipe_context *si_create_context(struct pipe_screen *screen, unsign
|
||||
}
|
||||
|
||||
/* Initialize context allocators. */
|
||||
sctx->allocator_zeroed_memory =
|
||||
u_suballocator_create(&sctx->b, 128 * 1024, 0, PIPE_USAGE_DEFAULT,
|
||||
SI_RESOURCE_FLAG_UNMAPPABLE | SI_RESOURCE_FLAG_CLEAR, false);
|
||||
if (!sctx->allocator_zeroed_memory)
|
||||
goto fail;
|
||||
u_suballocator_init(&sctx->allocator_zeroed_memory, &sctx->b, 128 * 1024, 0,
|
||||
PIPE_USAGE_DEFAULT,
|
||||
SI_RESOURCE_FLAG_UNMAPPABLE | SI_RESOURCE_FLAG_CLEAR, false);
|
||||
|
||||
sctx->b.stream_uploader =
|
||||
u_upload_create(&sctx->b, 1024 * 1024, 0, PIPE_USAGE_STREAM, SI_RESOURCE_FLAG_READ_ONLY);
|
||||
|
@@ -29,6 +29,7 @@
|
||||
#include "si_state.h"
|
||||
#include "util/u_dynarray.h"
|
||||
#include "util/u_idalloc.h"
|
||||
#include "util/u_suballoc.h"
|
||||
#include "util/u_threaded_context.h"
|
||||
|
||||
#if UTIL_ARCH_BIG_ENDIAN
|
||||
@@ -252,7 +253,6 @@ enum si_coherency
|
||||
struct si_compute;
|
||||
struct si_shader_context;
|
||||
struct hash_table;
|
||||
struct u_suballocator;
|
||||
|
||||
/* Only 32-bit buffer allocations are supported, gallium doesn't support more
|
||||
* at the moment.
|
||||
@@ -910,7 +910,7 @@ struct si_context {
|
||||
struct si_resource *eop_bug_scratch_tmz;
|
||||
struct u_upload_mgr *cached_gtt_allocator;
|
||||
struct threaded_context *tc;
|
||||
struct u_suballocator *allocator_zeroed_memory;
|
||||
struct u_suballocator allocator_zeroed_memory;
|
||||
struct slab_child_pool pool_transfers;
|
||||
struct slab_child_pool pool_transfers_unsync; /* for threaded_context */
|
||||
struct pipe_device_reset_callback device_reset_callback;
|
||||
|
@@ -1466,7 +1466,7 @@ static void si_query_hw_get_result_resource(struct si_context *sctx, struct si_q
|
||||
}
|
||||
|
||||
if (query->buffer.previous) {
|
||||
u_suballocator_alloc(sctx->allocator_zeroed_memory, 16, 16, &tmp_buffer_offset, &tmp_buffer);
|
||||
u_suballocator_alloc(&sctx->allocator_zeroed_memory, 16, 16, &tmp_buffer_offset, &tmp_buffer);
|
||||
if (!tmp_buffer)
|
||||
return;
|
||||
}
|
||||
@@ -1605,7 +1605,7 @@ static void si_render_condition(struct pipe_context *ctx, struct pipe_query *que
|
||||
bool old_force_off = sctx->render_cond_force_off;
|
||||
sctx->render_cond_force_off = true;
|
||||
|
||||
u_suballocator_alloc(sctx->allocator_zeroed_memory, 8, 8, &squery->workaround_offset,
|
||||
u_suballocator_alloc(&sctx->allocator_zeroed_memory, 8, 8, &squery->workaround_offset,
|
||||
(struct pipe_resource **)&squery->workaround_buf);
|
||||
|
||||
/* Reset to NULL to avoid a redundant SET_PREDICATION
|
||||
|
@@ -1147,7 +1147,7 @@ void si_prim_discard_signal_next_compute_ib_start(struct si_context *sctx)
|
||||
return;
|
||||
|
||||
if (!sctx->barrier_buf) {
|
||||
u_suballocator_alloc(sctx->allocator_zeroed_memory, 4, 4, &sctx->barrier_buf_offset,
|
||||
u_suballocator_alloc(&sctx->allocator_zeroed_memory, 4, 4, &sctx->barrier_buf_offset,
|
||||
(struct pipe_resource **)&sctx->barrier_buf);
|
||||
}
|
||||
|
||||
|
@@ -49,7 +49,7 @@ static struct pipe_stream_output_target *si_create_so_target(struct pipe_context
|
||||
}
|
||||
|
||||
unsigned buf_filled_size_size = sctx->screen->use_ngg_streamout ? 8 : 4;
|
||||
u_suballocator_alloc(sctx->allocator_zeroed_memory, buf_filled_size_size, 4,
|
||||
u_suballocator_alloc(&sctx->allocator_zeroed_memory, buf_filled_size_size, 4,
|
||||
&t->buf_filled_size_offset, (struct pipe_resource **)&t->buf_filled_size);
|
||||
if (!t->buf_filled_size) {
|
||||
FREE(t);
|
||||
|
Reference in New Issue
Block a user