lvmpipe/cs: Add support for 2d images created from buffers

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20378>
This commit is contained in:
Antonio Gomes 2022-12-12 18:22:31 -03:00 committed by Marge Bot
parent 9cbdf3673b
commit 7839341d8f
3 changed files with 53 additions and 18 deletions

View file

@ -117,7 +117,12 @@ lp_sampler_static_texture_state(struct lp_static_texture_state *state,
assert(state->swizzle_b < PIPE_SWIZZLE_NONE);
assert(state->swizzle_a < PIPE_SWIZZLE_NONE);
state->target = view->target;
/* check if it is a tex2d created from buf */
if (view->is_tex2d_from_buf)
state->target = PIPE_TEXTURE_2D;
else
state->target = view->target;
state->pot_width = util_is_power_of_two_or_zero(texture->width0);
state->pot_height = util_is_power_of_two_or_zero(texture->height0);
state->pot_depth = util_is_power_of_two_or_zero(texture->depth0);

View file

@ -36,6 +36,7 @@
#define LP_BLD_SAMPLE_H
#include "pipe/p_state.h"
#include "util/format/u_formats.h"
#include "util/u_debug.h"
#include "gallivm/lp_bld.h"
@ -46,10 +47,6 @@
extern "C" {
#endif
struct pipe_resource;
struct pipe_sampler_view;
struct pipe_sampler_state;
struct pipe_image_view;
struct util_format_description;
struct lp_type;
struct lp_build_context;
@ -529,7 +526,6 @@ apply_sampler_swizzle(struct lp_build_sample_context *bld,
lp_build_swizzle_soa_inplace(&bld->texel_bld, texel, swizzles);
}
/*
* not really dimension as such, this indicates the amount of
* "normal" texture coords subject to minification, wrapping etc.

View file

@ -1052,20 +1052,34 @@ lp_csctx_set_sampler_views(struct lp_cs_context *csctx,
}
} else {
/*
* For buffers, we don't have "offset", instead adjust
* the size (stored as width) plus the base pointer.
* For tex2d_from_buf, adjust width and height with application
* values. If is_tex2d_from_buf is false (1D images),
* adjust using size value (stored as width).
*/
unsigned view_blocksize = util_format_get_blocksize(view->format);
/* probably don't really need to fill that out */
jit_tex->mip_offsets[0] = 0;
jit_tex->row_stride[0] = 0;
jit_tex->img_stride[0] = 0;
/* everything specified in number of elements here. */
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.offset + view->u.buf.size <= res->width0);
/* If it's not a 2D texture view of a buffer, adjust using size. */
if (!view->is_tex2d_from_buf) {
/* everything specified in number of elements here. */
jit_tex->width = view->u.buf.size / view_blocksize;
jit_tex->row_stride[0] = 0;
/* Adjust base pointer with offset. */
jit_tex->base = (uint8_t *)jit_tex->base + view->u.buf.offset;
/* XXX Unsure if we need to sanitize parameters? */
assert(view->u.buf.offset + view->u.buf.size <= res->width0);
} else {
jit_tex->width = view->u.tex2d_from_buf.width;
jit_tex->height = view->u.tex2d_from_buf.height;
jit_tex->row_stride[0] = view->u.tex2d_from_buf.row_stride * view_blocksize;
jit_tex->base = (uint8_t *)jit_tex->base +
view->u.tex2d_from_buf.offset * view_blocksize;
}
}
}
} else {
@ -1219,9 +1233,29 @@ lp_csctx_set_cs_images(struct lp_cs_context *csctx,
jit_image->sample_stride = lp_res->sample_stride;
jit_image->base = (uint8_t *)jit_image->base + mip_offset;
} else {
unsigned view_blocksize = util_format_get_blocksize(image->format);
jit_image->width = image->u.buf.size / view_blocksize;
jit_image->base = (uint8_t *)jit_image->base + image->u.buf.offset;
unsigned image_blocksize = util_format_get_blocksize(image->format);
jit_image->img_stride = 0;
/* If it's not a 2D image view of a buffer, adjust using size. */
if (!(image->access & PIPE_IMAGE_ACCESS_TEX2D_FROM_BUFFER)) {
/* everything specified in number of elements here. */
jit_image->width = image->u.buf.size / image_blocksize;
jit_image->row_stride = 0;
/* Adjust base pointer with offset. */
jit_image->base = (uint8_t *)jit_image->base + image->u.buf.offset;
/* XXX Unsure if we need to sanitize parameters? */
assert(image->u.buf.offset + image->u.buf.size <= res->width0);
} else {
jit_image->width = image->u.tex2d_from_buf.width;
jit_image->height = image->u.tex2d_from_buf.height;
jit_image->row_stride = image->u.tex2d_from_buf.row_stride * image_blocksize;
jit_image->base = (uint8_t *)jit_image->base +
image->u.tex2d_from_buf.offset * image_blocksize;
}
}
}
}