#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.
*
* 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;
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
#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);
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);
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]);
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),
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 |
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;
/* 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;
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;
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) {
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. */
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);
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))
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;
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);
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);
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 */
}
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;
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) {
}
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;
}
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);
}
/* 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);
#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
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.
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;
}
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;
}
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
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);
}
}
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);