This is required by OpenGL. Our hardware supports this.
Example: Bind RGBA32F with offset = 4 bytes.
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=97305
Acked-by: Ilia Mirkin <imirkin@alum.mit.edu>
Acked-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
util_dump_member(stream, ptr, state, texture);
if (state->target == PIPE_BUFFER) {
- util_dump_member(stream, uint, state, u.buf.first_element);
- util_dump_member(stream, uint, state, u.buf.last_element);
+ util_dump_member(stream, uint, state, u.buf.offset);
+ util_dump_member(stream, uint, state, u.buf.size);
}
else {
util_dump_member(stream, uint, state, u.tex.first_layer);
PIPE_BUFFER. In other words, the pointer returned by transfer_map is
always aligned to this value.
* ``PIPE_CAP_TEXTURE_BUFFER_OFFSET_ALIGNMENT``: Describes the required
- alignment for pipe_sampler_view::u.buf.first_element, in bytes.
- If a driver does not support first/last_element, it should return 0.
+ alignment for pipe_sampler_view::u.buf.offset, in bytes.
+ If a driver does not support offset/size, it should return 0.
* ``PIPE_CAP_BUFFER_SAMPLER_VIEW_RGBA_ONLY``: Whether the driver only
supports R, RG, RGB and RGBA formats for PIPE_BUFFER sampler views.
When this is the case it should be assumed that the swizzle parameters
&dummy_view;
struct fd_resource *rsc = fd_resource(view->base.texture);
if (rsc && rsc->base.b.target == PIPE_BUFFER) {
- OUT_RELOC(ring, rsc->bo, view->base.u.buf.first_element *
- util_format_get_blocksize(view->base.format), 0, 0);
+ OUT_RELOC(ring, rsc->bo, view->base.u.buf.offset, 0, 0);
j = 1;
} else {
unsigned start = fd_sampler_first_level(&view->base);
lvl = 0;
so->texconst1 =
A3XX_TEX_CONST_1_FETCHSIZE(fd3_pipe2fetchsize(cso->format)) |
- A3XX_TEX_CONST_1_WIDTH(cso->u.buf.last_element -
- cso->u.buf.first_element + 1) |
+ A3XX_TEX_CONST_1_WIDTH(cso->u.buf.size / util_format_get_blocksize(cso->format)) |
A3XX_TEX_CONST_1_HEIGHT(1);
} else {
unsigned miplevels;
}
if (cso->target == PIPE_BUFFER) {
- unsigned elements = cso->u.buf.last_element -
- cso->u.buf.first_element + 1;
+ unsigned elements = cso->u.buf.size / util_format_get_blocksize(cso->format);
+
lvl = 0;
so->texconst1 =
A4XX_TEX_CONST_1_WIDTH(elements) |
so->texconst2 =
A4XX_TEX_CONST_2_FETCHSIZE(fd4_pipe2fetchsize(cso->format)) |
A4XX_TEX_CONST_2_PITCH(elements * rsc->cpp);
- so->offset = cso->u.buf.first_element *
- util_format_get_blocksize(cso->format);
+ so->offset = cso->u.buf.offset;
} else {
unsigned miplevels;
memset(&info, 0, sizeof(info));
info.vma = ilo_resource_get_vma(res);
- info.offset = templ->u.buf.first_element * info.struct_size;
- info.size = (templ->u.buf.last_element -
- templ->u.buf.first_element + 1) * info.struct_size;
+ info.offset = templ->u.buf.offset;
+ info.size = templ->u.buf.size;
info.access = ILO_STATE_SURFACE_ACCESS_SAMPLER;
info.format = ilo_format_translate_color(dev, templ->format);
info.format_size = util_format_get_blocksize(templ->format);
}
else {
/*
- * For buffers, we don't have first_element, instead adjust
- * last_element (stored as width) plus the base pointer.
+ * For buffers, we don't have "offset", instead adjust
+ * the size (stored as width) plus the base pointer.
*/
unsigned view_blocksize = util_format_get_blocksize(view->format);
/* probably don't really need to fill that out */
jit_tex->img_stride[0] = 0;
/* everything specified in number of elements here. */
- jit_tex->width = view->u.buf.last_element - view->u.buf.first_element + 1;
- jit_tex->base = (uint8_t *)jit_tex->base + view->u.buf.first_element *
- view_blocksize;
+ jit_tex->width = view->u.buf.size / view_blocksize;
+ jit_tex->base = (uint8_t *)jit_tex->base + view->u.buf.offset;
/* XXX Unsure if we need to sanitize parameters? */
- assert(view->u.buf.first_element <= view->u.buf.last_element);
- assert(view->u.buf.last_element * view_blocksize < res->width0);
+ assert(view->u.buf.offset + view->u.buf.size <= res->width0);
}
}
}
img_stride[0] = 0;
/* everything specified in number of elements here. */
- width0 = view->u.buf.last_element - view->u.buf.first_element + 1;
- addr = (uint8_t *)addr + view->u.buf.first_element *
- view_blocksize;
- assert(view->u.buf.first_element <= view->u.buf.last_element);
- assert(view->u.buf.last_element * view_blocksize < res->width0);
+ width0 = view->u.buf.size / view_blocksize;
+ addr = (uint8_t *)addr + view->u.buf.offset;
+ assert(view->u.buf.offset + view->u.buf.size <= res->width0);
}
}
else {
if (unlikely(!nouveau_bo_memtype(nv04_resource(texture)->bo))) {
if (target == PIPE_BUFFER) {
- addr += view->pipe.u.buf.first_element * desc->block.bits / 8;
+ addr += view->pipe.u.buf.offset;
tic[2] |= G80_TIC_2_LAYOUT_PITCH | G80_TIC_2_TEXTURE_TYPE_ONE_D_BUFFER;
tic[3] = 0;
tic[4] = /* width */
- view->pipe.u.buf.last_element - view->pipe.u.buf.first_element + 1;
+ view->pipe.u.buf.size / (desc->block.bits / 8);
tic[5] = 0;
} else {
tic[2] |= G80_TIC_2_LAYOUT_PITCH | G80_TIC_2_TEXTURE_TYPE_TWO_D_NO_MIPMAP;
uint64_t address = res->address;
if (res->base.target != PIPE_BUFFER)
return;
- address += tic->pipe.u.buf.first_element *
- util_format_get_blocksize(tic->pipe.format);
+ address += tic->pipe.u.buf.offset;
if (tic->tic[1] == (uint32_t)address &&
(tic->tic[2] & 0xff) == address >> 32)
return;
if (unlikely(!nouveau_bo_memtype(nv04_resource(texture)->bo))) {
if (texture->target == PIPE_BUFFER) {
assert(!(tic[5] & GM107_TIC2_5_NORMALIZED_COORDS));
- width = view->pipe.u.buf.last_element - view->pipe.u.buf.first_element;
+ width = view->pipe.u.buf.size / (desc->block.bits / 8) - 1;
address +=
- view->pipe.u.buf.first_element * desc->block.bits / 8;
+ view->pipe.u.buf.offset;
tic[2] = GM107_TIC2_2_HEADER_VERSION_ONE_D_BUFFER;
tic[3] |= width >> 16;
tic[4] |= GM107_TIC2_4_TEXTURE_TYPE_ONE_D_BUFFER;
templ.swizzle_a = PIPE_SWIZZLE_W;
if (target == PIPE_BUFFER) {
- templ.u.buf.first_element = view->u.buf.first_element;
- templ.u.buf.last_element = view->u.buf.last_element;
+ templ.u.buf.offset = view->u.buf.first_element *
+ util_format_get_blocksize(view->format);
+ templ.u.buf.size = (view->u.buf.last_element -
+ view->u.buf.first_element + 1) *
+ util_format_get_blocksize(view->format);
} else {
templ.u.tex.first_layer = view->u.tex.first_layer;
templ.u.tex.last_layer = view->u.tex.last_layer;
if (texture->target == PIPE_BUFFER) {
assert(!(tic[2] & G80_TIC_2_NORMALIZED_COORDS));
address +=
- view->pipe.u.buf.first_element * desc->block.bits / 8;
+ view->pipe.u.buf.offset;
tic[2] |= G80_TIC_2_LAYOUT_PITCH | G80_TIC_2_TEXTURE_TYPE_ONE_D_BUFFER;
tic[3] = 0;
tic[4] = /* width */
- view->pipe.u.buf.last_element - view->pipe.u.buf.first_element + 1;
+ view->pipe.u.buf.size / (desc->block.bits / 8);
tic[5] = 0;
} else {
/* must be 2D texture without mip maps */
uint64_t address = res->address;
if (res->base.target != PIPE_BUFFER)
return;
- address += tic->pipe.u.buf.first_element *
- util_format_get_blocksize(tic->pipe.format);
+ address += tic->pipe.u.buf.offset;
if (tic->tic[1] == (uint32_t)address &&
(tic->tic[2] & 0xff) == address >> 32)
return;
unsigned swizzle_res;
unsigned char swizzle[4];
const struct util_format_description *desc;
- unsigned offset = view->base.u.buf.first_element * stride;
- unsigned size = (view->base.u.buf.last_element - view->base.u.buf.first_element + 1) * stride;
+ unsigned offset = view->base.u.buf.offset;
+ unsigned size = view->base.u.buf.size;
swizzle[0] = view->base.swizzle_r;
swizzle[1] = view->base.swizzle_g;
struct r600_texture *tmp = (struct r600_texture*)view->base.texture;
int stride = util_format_get_blocksize(view->base.format);
unsigned format, num_format, format_comp, endian;
- uint64_t offset = view->base.u.buf.first_element * stride;
- unsigned size = (view->base.u.buf.last_element - view->base.u.buf.first_element + 1) * stride;
+ uint64_t offset = view->base.u.buf.offset;
+ unsigned size = view->base.u.buf.size;
r600_vertex_data_type(view->base.format,
&format, &num_format, &format_comp,
/* Texture buffer objects - update the virtual addresses in descriptors. */
LIST_FOR_EACH_ENTRY(view, &rctx->b.texture_buffers, list) {
if (view->base.texture == &rbuffer->b.b) {
- unsigned stride = util_format_get_blocksize(view->base.format);
- uint64_t offset = (uint64_t)view->base.u.buf.first_element * stride;
+ uint64_t offset = view->base.u.buf.offset;
uint64_t va = rbuffer->gpu_address + offset;
view->tex_resource_words[0] = va;
si_make_buffer_descriptor(screen, res,
view->format,
- view->u.buf.first_element,
- view->u.buf.last_element,
+ view->u.buf.first_element *
+ util_format_get_blocksize(view->format),
+ (view->u.buf.last_element -
+ view->u.buf.first_element + 1) *
+ util_format_get_blocksize(view->format),
descs->list + slot * 8);
images->compressed_colortex_mask &= ~(1 << slot);
} else {
void
si_make_buffer_descriptor(struct si_screen *screen, struct r600_resource *buf,
enum pipe_format format,
- unsigned first_element, unsigned last_element,
+ unsigned offset, unsigned size,
uint32_t *state)
{
const struct util_format_description *desc;
desc = util_format_description(format);
first_non_void = util_format_get_first_non_void_channel(format);
stride = desc->block.bits / 8;
- va = buf->gpu_address + first_element * stride;
+ va = buf->gpu_address + offset;
num_format = si_translate_buffer_numformat(&screen->b.b, desc, first_non_void);
data_format = si_translate_buffer_dataformat(&screen->b.b, desc, first_non_void);
- num_records = last_element + 1 - first_element;
+ num_records = size / stride;
num_records = MIN2(num_records, buf->b.b.width0 / stride);
if (screen->b.chip_class >= VI)
si_make_buffer_descriptor(sctx->screen,
(struct r600_resource *)texture,
state->format,
- state->u.buf.first_element,
- state->u.buf.last_element,
+ state->u.buf.offset,
+ state->u.buf.size,
view->state);
LIST_ADDTAIL(&view->list, &sctx->b.texture_buffers);
void
si_make_buffer_descriptor(struct si_screen *screen, struct r600_resource *buf,
enum pipe_format format,
- unsigned first_element, unsigned last_element,
+ unsigned offset, unsigned size,
uint32_t *state);
void
si_make_texture_descriptor(struct si_screen *screen,
img_stride[0] = 0;
/* everything specified in number of elements here. */
- width0 = view->u.buf.last_element - view->u.buf.first_element + 1;
- addr = (uint8_t *)addr + view->u.buf.first_element *
- view_blocksize;
- assert(view->u.buf.first_element <= view->u.buf.last_element);
- assert(view->u.buf.last_element * view_blocksize < res->width0);
+ width0 = view->u.buf.size / view_blocksize;
+ addr = (uint8_t *)addr + view->u.buf.offset;
+ assert(view->u.buf.offset + view->u.buf.size <= res->width0);
}
}
else {
const struct pipe_resource *texture = view->texture;
if (view->target == PIPE_BUFFER) {
- dims[0] = (view->u.buf.last_element - view->u.buf.first_element) + 1;
+ dims[0] = view->u.buf.size / util_format_get_blocksize(view->format);
/* the other values are undefined, but let's avoid potential valgrind
* warnings.
*/
const int width = u_minify(texture->width0, level);
const int height = u_minify(texture->height0, level);
const int depth = u_minify(texture->depth0, level);
+ unsigned elem_size, first_element, last_element;
addr.value = 0;
addr.bits.level = level;
switch (sp_sview->base.target) {
case PIPE_BUFFER:
+ elem_size = util_format_get_blocksize(sp_sview->base.format);
+ first_element = sp_sview->base.u.buf.offset / elem_size;
+ last_element = (sp_sview->base.u.buf.offset +
+ sp_sview->base.u.buf.size) / elem_size - 1;
for (j = 0; j < TGSI_QUAD_SIZE; j++) {
const int x = CLAMP(v_i[j] + offset[0] +
- sp_sview->base.u.buf.first_element,
- sp_sview->base.u.buf.first_element,
- sp_sview->base.u.buf.last_element);
+ first_element,
+ first_element,
+ last_element);
tx = get_texel_2d_no_border(sp_sview, addr, x, 0);
for (c = 0; c < 4; c++) {
rgba[c][j] = tx[c];
#include "pipe/p_defines.h"
#include "util/u_bitmask.h"
+#include "util/u_format.h"
#include "util/u_inlines.h"
#include "util/u_math.h"
#include "util/u_memory.h"
format = svga_sampler_format(format);
if (texture->target == PIPE_BUFFER) {
- viewDesc.buffer.firstElement = sv->base.u.buf.first_element;
- viewDesc.buffer.numElements = (sv->base.u.buf.last_element -
- sv->base.u.buf.first_element + 1);
+ unsigned elem_size = util_format_get_blocksize(sv->base.format);
+
+ viewDesc.buffer.firstElement = sv->base.u.buf.offset / elem_size;
+ viewDesc.buffer.numElements = sv->base.u.buf.size / elem_size;
}
else {
viewDesc.tex.mostDetailedMip = sv->base.u.tex.first_level;
if (target == PIPE_BUFFER) {
trace_dump_member_begin("buf");
trace_dump_struct_begin(""); /* anonymous */
- trace_dump_member(uint, &state->u.buf, first_element);
- trace_dump_member(uint, &state->u.buf, last_element);
+ trace_dump_member(uint, &state->u.buf, offset);
+ trace_dump_member(uint, &state->u.buf, size);
trace_dump_struct_end(); /* anonymous */
trace_dump_member_end(); /* buf */
} else {
*/
#include <stdint.h>
+#include "util/u_format.h"
#include "util/u_memory.h"
#include "util/u_math.h"
#include "pipe/p_state.h"
struct virgl_resource *res,
const struct pipe_sampler_view *state)
{
+ unsigned elem_size = util_format_get_blocksize(state->format);
+
uint32_t tmp;
virgl_encoder_write_cmd_dword(ctx, VIRGL_CMD0(VIRGL_CCMD_CREATE_OBJECT, VIRGL_OBJECT_SAMPLER_VIEW, VIRGL_OBJ_SAMPLER_VIEW_SIZE));
virgl_encoder_write_dword(ctx->cbuf, handle);
virgl_encoder_write_res(ctx, res);
virgl_encoder_write_dword(ctx->cbuf, state->format);
if (res->u.b.target == PIPE_BUFFER) {
- virgl_encoder_write_dword(ctx->cbuf, state->u.buf.first_element);
- virgl_encoder_write_dword(ctx->cbuf, state->u.buf.last_element);
+ virgl_encoder_write_dword(ctx->cbuf, state->u.buf.offset / elem_size);
+ virgl_encoder_write_dword(ctx->cbuf, (state->u.buf.offset + state->u.buf.size) / elem_size - 1);
} else {
virgl_encoder_write_dword(ctx->cbuf, state->u.tex.first_layer | state->u.tex.last_layer << 16);
virgl_encoder_write_dword(ctx->cbuf, state->u.tex.first_level | state->u.tex.last_level << 8);
unsigned last_level:8; /**< last mipmap level to use */
} tex;
struct {
- unsigned first_element;
- unsigned last_element;
+ unsigned offset; /**< offset in bytes */
+ unsigned size; /**< size of the readable sub-range in bytes */
} buf;
} u;
unsigned swizzle_r:3; /**< PIPE_SWIZZLE_x for red component */
if (stObj->pt->target == PIPE_BUFFER) {
unsigned base, size;
- unsigned f, n;
- const struct util_format_description *desc
- = util_format_description(templ.format);
base = stObj->base.BufferOffset;
if (base >= stObj->pt->width0)
return NULL;
size = MIN2(stObj->pt->width0 - base, (unsigned)stObj->base.BufferSize);
-
- f = (base / (desc->block.bits / 8)) * desc->block.width;
- n = (size / (desc->block.bits / 8)) * desc->block.width;
- if (!n)
+ if (!size)
return NULL;
- templ.u.buf.first_element = f;
- templ.u.buf.last_element = f + (n - 1);
+
+ templ.u.buf.offset = base;
+ templ.u.buf.size = size;
} else {
templ.u.tex.first_level = stObj->base.MinLevel + stObj->base.BaseLevel;
templ.u.tex.last_level = last_level(stObj);
memset(&templ, 0, sizeof(templ));
templ.target = PIPE_BUFFER;
templ.format = src_format;
- templ.u.buf.first_element = addr->first_element;
- templ.u.buf.last_element = addr->last_element;
+ templ.u.buf.offset = addr->first_element * addr->bytes_per_pixel;
+ templ.u.buf.size = (addr->last_element - addr->first_element + 1) *
+ addr->bytes_per_pixel;
templ.swizzle_r = PIPE_SWIZZLE_X;
templ.swizzle_g = PIPE_SWIZZLE_Y;
templ.swizzle_b = PIPE_SWIZZLE_Z;