static struct pipe_resource * buf_create(struct pipe_screen *screen, const struct pipe_resource *templ) { struct ilo_buffer *buf; buf = CALLOC_STRUCT(ilo_buffer); if (!buf) return NULL; buf->base = *templ; buf->base.screen = screen; pipe_reference_init(&buf->base.reference, 1); buf->bo_size = templ->width0; buf->bo_flags = 0; /* * 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 (!buf_create_bo(buf)) { FREE(buf); return NULL; } return &buf->base; }
static struct pipe_resource * buf_create(struct pipe_screen *screen, const struct pipe_resource *templ) { const struct ilo_screen *is = ilo_screen(screen); struct ilo_buffer *buf; buf = CALLOC_STRUCT(ilo_buffer); if (!buf) return NULL; buf->base = *templ; 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_translate_format(), 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); } if (buf->bo_size < templ->width0 || buf->bo_size > ilo_max_resource_size || !buf_create_bo(buf)) { FREE(buf); return NULL; } return &buf->base; }
bool ilo_buffer_rename_bo(struct ilo_buffer *buf) { struct intel_bo *old_bo = buf->bo; if (buf_create_bo(buf)) { intel_bo_unreference(old_bo); return true; } else { buf->bo = old_bo; return false; } }
bool ilo_buffer_alloc_bo(struct ilo_buffer *buf) { return buf_create_bo(buf); }