Rename the original ilo_buffer to ilo_buffer_resource to avoid name conflict.
C_SOURCES := \
+ core/ilo_buffer.h \
core/ilo_core.h \
core/ilo_debug.c \
core/ilo_debug.h \
--- /dev/null
+/*
+ * Mesa 3-D graphics library
+ *
+ * Copyright (C) 2012-2013 LunarG, Inc.
+ *
+ * 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 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.
+ *
+ * Authors:
+ * Chia-I Wu <olv@lunarg.com>
+ */
+
+#ifndef ILO_BUFFER_H
+#define ILO_BUFFER_H
+
+#include "intel_winsys.h"
+
+#include "ilo_core.h"
+#include "ilo_dev.h"
+
+struct ilo_buffer {
+ unsigned bo_size;
+
+ struct intel_bo *bo;
+};
+
+static inline void
+ilo_buffer_init(struct ilo_buffer *buf, const struct ilo_dev *dev,
+ unsigned size, uint32_t bind, uint32_t flags)
+{
+ buf->bo_size = size;
+
+ /*
+ * From the Sandy Bridge PRM, volume 1 part 1, page 118:
+ *
+ * "For buffers, which have no inherent "height," padding requirements
+ * are different. A buffer must be padded to the next multiple of 256
+ * array elements, with an additional 16 bytes added beyond that to
+ * account for the L1 cache line."
+ */
+ if (bind & PIPE_BIND_SAMPLER_VIEW)
+ buf->bo_size = align(buf->bo_size, 256) + 16;
+
+ if ((bind & PIPE_BIND_VERTEX_BUFFER) && ilo_dev_gen(dev) < ILO_GEN(7.5)) {
+ /*
+ * As noted in ilo_format_translate(), we treat some 3-component formats
+ * as 4-component formats to work around hardware limitations. Imagine
+ * the case where the vertex buffer holds a single
+ * PIPE_FORMAT_R16G16B16_FLOAT vertex, and buf->bo_size is 6. The
+ * hardware would fail to fetch it at boundary check because the vertex
+ * buffer is expected to hold a PIPE_FORMAT_R16G16B16A16_FLOAT vertex
+ * and that takes at least 8 bytes.
+ *
+ * For the workaround to work, we should add 2 to the bo size. But that
+ * would waste a page when the bo size is already page aligned. Let's
+ * round it to page size for now and revisit this when needed.
+ */
+ buf->bo_size = align(buf->bo_size, 4096);
+ }
+}
+
+static inline void
+ilo_buffer_cleanup(struct ilo_buffer *buf)
+{
+ intel_bo_unref(buf->bo);
+}
+
+static inline void
+ilo_buffer_set_bo(struct ilo_buffer *buf, struct intel_bo *bo)
+{
+ intel_bo_unref(buf->bo);
+ buf->bo = intel_bo_ref(bo);
+}
+
+#endif /* ILO_BUFFER_H */
}
static bool
-buf_create_bo(struct ilo_buffer *buf)
+buf_create_bo(struct ilo_buffer_resource *buf)
{
struct ilo_screen *is = ilo_screen(buf->base.screen);
const char *name = resource_get_bo_name(&buf->base);
const bool cpu_init = resource_get_cpu_init(&buf->base);
+ struct intel_bo *bo;
+
+ bo = intel_winsys_alloc_bo(is->dev.winsys, name,
+ buf->buffer.bo_size, cpu_init);
+ if (!bo)
+ return false;
- buf->bo = intel_winsys_alloc_bo(is->dev.winsys, name, buf->bo_size, cpu_init);
+ ilo_buffer_set_bo(&buf->buffer, bo);
+ intel_bo_unref(bo);
- return (buf->bo != NULL);
+ return true;
}
static void
-buf_destroy(struct ilo_buffer *buf)
+buf_destroy(struct ilo_buffer_resource *buf)
{
- intel_bo_unref(buf->bo);
+ ilo_buffer_cleanup(&buf->buffer);
FREE(buf);
}
buf_create(struct pipe_screen *screen, const struct pipe_resource *templ)
{
const struct ilo_screen *is = ilo_screen(screen);
- struct ilo_buffer *buf;
+ struct ilo_buffer_resource *buf;
- buf = CALLOC_STRUCT(ilo_buffer);
+ buf = CALLOC_STRUCT(ilo_buffer_resource);
if (!buf)
return NULL;
buf->base.screen = screen;
pipe_reference_init(&buf->base.reference, 1);
- buf->bo_size = templ->width0;
-
- /*
- * From the Sandy Bridge PRM, volume 1 part 1, page 118:
- *
- * "For buffers, which have no inherent "height," padding requirements
- * are different. A buffer must be padded to the next multiple of 256
- * array elements, with an additional 16 bytes added beyond that to
- * account for the L1 cache line."
- */
- if (templ->bind & PIPE_BIND_SAMPLER_VIEW)
- buf->bo_size = align(buf->bo_size, 256) + 16;
-
- if ((templ->bind & PIPE_BIND_VERTEX_BUFFER) &&
- ilo_dev_gen(&is->dev) < ILO_GEN(7.5)) {
- /*
- * As noted in ilo_format_translate(), we treat some 3-component formats
- * as 4-component formats to work around hardware limitations. Imagine
- * the case where the vertex buffer holds a single
- * PIPE_FORMAT_R16G16B16_FLOAT vertex, and buf->bo_size is 6. The
- * hardware would fail to fetch it at boundary check because the vertex
- * buffer is expected to hold a PIPE_FORMAT_R16G16B16A16_FLOAT vertex
- * and that takes at least 8 bytes.
- *
- * For the workaround to work, we should add 2 to the bo size. But that
- * would waste a page when the bo size is already page aligned. Let's
- * round it to page size for now and revisit this when needed.
- */
- buf->bo_size = align(buf->bo_size, 4096);
- }
+ ilo_buffer_init(&buf->buffer, &is->dev,
+ templ->width0, templ->bind, templ->flags);
- if (buf->bo_size < templ->width0 ||
- buf->bo_size > ilo_max_resource_size ||
+ if (buf->buffer.bo_size < templ->width0 ||
+ buf->buffer.bo_size > ilo_max_resource_size ||
!buf_create_bo(buf)) {
FREE(buf);
return NULL;
struct pipe_resource *res)
{
if (res->target == PIPE_BUFFER)
- buf_destroy(ilo_buffer(res));
+ buf_destroy((struct ilo_buffer_resource *) res);
else
tex_destroy(ilo_texture(res));
}
}
bool
-ilo_buffer_rename_bo(struct ilo_buffer *buf)
+ilo_resource_rename_bo(struct pipe_resource *res)
{
- struct intel_bo *old_bo = buf->bo;
-
- if (buf_create_bo(buf)) {
- intel_bo_unref(old_bo);
- return true;
- }
- else {
- buf->bo = old_bo;
- return false;
- }
-}
+ if (res->target == PIPE_BUFFER) {
+ return buf_create_bo((struct ilo_buffer_resource *) res);
+ } else {
+ struct ilo_texture *tex = ilo_texture(res);
-bool
-ilo_texture_rename_bo(struct ilo_texture *tex)
-{
- /* an imported texture cannot be renamed */
- if (tex->imported)
- return false;
+ /* an imported texture cannot be renamed */
+ if (tex->imported)
+ return false;
- return tex_create_bo(tex);
+ return tex_create_bo(tex);
+ }
}
#define ILO_RESOURCE_H
#include "core/intel_winsys.h"
+#include "core/ilo_buffer.h"
#include "core/ilo_image.h"
#include "ilo_common.h"
ILO_TEXTURE_HIZ = 1 << 7,
};
-struct ilo_buffer {
- struct pipe_resource base;
-
- struct intel_bo *bo;
- unsigned bo_size;
-};
-
/**
* A 3D image slice, cube face, or array layer.
*/
struct ilo_texture *separate_s8;
};
+struct ilo_buffer_resource {
+ struct pipe_resource base;
+
+ struct ilo_buffer buffer;
+};
+
static inline struct ilo_buffer *
ilo_buffer(struct pipe_resource *res)
{
- return (struct ilo_buffer *)
- ((res && res->target == PIPE_BUFFER) ? res : NULL);
+ return (res && res->target == PIPE_BUFFER) ?
+ &((struct ilo_buffer_resource *) res)->buffer : NULL;
}
static inline struct ilo_texture *
ilo_init_resource_functions(struct ilo_screen *is);
bool
-ilo_buffer_rename_bo(struct ilo_buffer *buf);
-
-bool
-ilo_texture_rename_bo(struct ilo_texture *tex);
+ilo_resource_rename_bo(struct pipe_resource *res);
/**
* Return the bo of the resource.
return true;
}
-/**
- * Rename the bo of the resource.
- */
-static bool
-resource_rename_bo(struct pipe_resource *res)
-{
- return (res->target == PIPE_BUFFER) ?
- ilo_buffer_rename_bo(ilo_buffer(res)) :
- ilo_texture_rename_bo(ilo_texture(res));
-}
-
/**
* Return true if usage allows the use of staging bo to avoid blocking.
*/
unblocked = true;
}
else if ((xfer->base.usage & PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE) &&
- resource_rename_bo(res)) {
+ ilo_resource_rename_bo(res)) {
renamed = true;
unblocked = true;
}
}
static void
-buf_pwrite(struct ilo_context *ilo, struct ilo_buffer *buf,
+buf_pwrite(struct ilo_context *ilo, struct pipe_resource *res,
unsigned usage, int offset, int size, const void *data)
{
+ struct ilo_buffer *buf = ilo_buffer(res);
bool need_submit;
/* see if we can avoid blocking */
bool unblocked = false;
if ((usage & PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE) &&
- ilo_buffer_rename_bo(buf)) {
- ilo_state_vector_resource_renamed(&ilo->state_vector, &buf->base);
+ ilo_resource_rename_bo(res)) {
+ ilo_state_vector_resource_renamed(&ilo->state_vector, res);
unblocked = true;
}
else {
* allocate a staging buffer to hold the data and pipelined copy it
* over
*/
- templ = buf->base;
+ templ = *res;
templ.width0 = size;
templ.usage = PIPE_USAGE_STAGING;
templ.bind = PIPE_BIND_TRANSFER_WRITE;
u_box_1d(0, size, &staging_box);
ilo_blitter_blt_copy_resource(ilo->blitter,
- &buf->base, 0, offset, 0, 0,
+ res, 0, offset, 0, 0,
staging, 0, &staging_box);
pipe_resource_reference(&staging, NULL);
assert(box->height == 1);
assert(box->depth == 1);
- buf_pwrite(ilo_context(pipe), ilo_buffer(res),
+ buf_pwrite(ilo_context(pipe), res,
usage, box->x, box->width, data);
}
else {