* Chia-I Wu <olv@lunarg.com>
*/
+#include "util/u_upload_mgr.h"
#include "intel_chipset.h"
#include "ilo_3d.h"
if (ilo->last_cp_bo)
intel_bo_unreference(ilo->last_cp_bo);
- util_slab_destroy(&ilo->transfer_mempool);
+ if (ilo->uploader)
+ u_upload_destroy(ilo->uploader);
if (ilo->blitter)
ilo_blitter_destroy(ilo->blitter);
if (ilo->cp)
ilo_cp_destroy(ilo->cp);
+ util_slab_destroy(&ilo->transfer_mempool);
+
FREE(ilo);
}
ilo->winsys = is->winsys;
ilo->dev = &is->dev;
+ /*
+ * initialize first, otherwise it may not be safe to call
+ * ilo_context_destroy() on errors
+ */
+ util_slab_create(&ilo->transfer_mempool,
+ sizeof(struct ilo_transfer), 64, UTIL_SLAB_SINGLETHREADED);
+
ilo->cp = ilo_cp_create(ilo->winsys, is->dev.has_llc);
ilo->shader_cache = ilo_shader_cache_create();
if (ilo->cp)
return NULL;
}
+ ilo->uploader = u_upload_create(&ilo->base, 1024 * 1024, 16,
+ PIPE_BIND_CONSTANT_BUFFER);
+ if (!ilo->uploader) {
+ ilo_context_destroy(&ilo->base);
+ return NULL;
+ }
+
ilo_cp_set_flush_callback(ilo->cp,
ilo_context_cp_flushed, (void *) ilo);
- util_slab_create(&ilo->transfer_mempool,
- sizeof(struct ilo_transfer), 64, UTIL_SLAB_SINGLETHREADED);
-
ilo->base.screen = screen;
ilo->base.priv = priv;
#include "util/u_framebuffer.h"
#include "util/u_helpers.h"
+#include "util/u_upload_mgr.h"
#include "ilo_context.h"
#include "ilo_resource.h"
static void
finalize_constant_buffers(struct ilo_context *ilo)
{
- int sh;
+ int sh, i;
if (!(ilo->dirty & ILO_DIRTY_CONSTANT_BUFFER))
return;
+ /* TODO push constants? */
for (sh = 0; sh < PIPE_SHADER_TYPES; sh++) {
- int last_cbuf = Elements(ilo->cbuf[sh].cso) - 1;
+ int last_cbuf = -1;
- /* find the last cbuf */
- while (last_cbuf >= 0 &&
- !ilo->cbuf[sh].cso[last_cbuf].resource)
- last_cbuf--;
+ for (i = 0; i < Elements(ilo->cbuf[sh].cso); i++) {
+ struct ilo_cbuf_cso *cbuf = &ilo->cbuf[sh].cso[i];
+
+ /* upload user buffer */
+ if (cbuf->user_buffer) {
+ const enum pipe_format elem_format =
+ PIPE_FORMAT_R32G32B32A32_FLOAT;
+ unsigned offset;
+
+ u_upload_data(ilo->uploader, 0, cbuf->user_buffer_size,
+ cbuf->user_buffer, &offset, &cbuf->resource);
+
+ ilo_gpe_init_view_surface_for_buffer(ilo->dev,
+ ilo_buffer(cbuf->resource),
+ offset, cbuf->user_buffer_size,
+ util_format_get_blocksize(elem_format), elem_format,
+ false, false, &cbuf->surface);
+
+ cbuf->user_buffer = NULL;
+ cbuf->user_buffer_size = 0;
+ }
+
+ if (cbuf->resource)
+ last_cbuf = i;
+ }
ilo->cbuf[sh].count = last_cbuf + 1;
}
{
finalize_shader_states(ilo);
finalize_constant_buffers(ilo);
+
+ u_upload_unmap(ilo->uploader);
}
static void *
static void
ilo_set_constant_buffer(struct pipe_context *pipe,
uint shader, uint index,
- struct pipe_constant_buffer *buf)
+ struct pipe_constant_buffer *state)
{
struct ilo_context *ilo = ilo_context(pipe);
struct ilo_cbuf_cso *cbuf;
cbuf = &ilo->cbuf[shader].cso[index];
- if (buf) {
- const enum pipe_format elem_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
+ if (state) {
+ pipe_resource_reference(&cbuf->resource, state->buffer);
+
+ if (state->buffer) {
+ const enum pipe_format elem_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
- /* no PIPE_CAP_USER_CONSTANT_BUFFERS */
- assert(!buf->user_buffer);
+ ilo_gpe_init_view_surface_for_buffer(ilo->dev,
+ ilo_buffer(cbuf->resource),
+ state->buffer_offset, state->buffer_size,
+ util_format_get_blocksize(elem_format), elem_format,
+ false, false, &cbuf->surface);
- pipe_resource_reference(&cbuf->resource, buf->buffer);
+ cbuf->user_buffer = NULL;
+ cbuf->user_buffer_size = 0;
+ }
+ else {
+ assert(state->user_buffer);
+
+ cbuf->surface.bo = NULL;
- ilo_gpe_init_view_surface_for_buffer(ilo->dev, ilo_buffer(buf->buffer),
- buf->buffer_offset, buf->buffer_size,
- util_format_get_blocksize(elem_format), elem_format,
- false, false, &cbuf->surface);
+ /* state->buffer_offset does not apply for user buffer */
+ cbuf->user_buffer = state->user_buffer;
+ cbuf->user_buffer_size = state->buffer_size;
+ }
}
else {
pipe_resource_reference(&cbuf->resource, NULL);
cbuf->surface.bo = NULL;
+
+ cbuf->user_buffer = NULL;
+ cbuf->user_buffer_size = 0;
}
/* the correct value will be set in ilo_finalize_states() */