mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-04-26 15:30:40 +02:00
llvmpipe: asst. clean-ups in lp_state_sampler.c
Signed-off-by: Brian Paul <brianp@vmware.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19289>
This commit is contained in:
parent
6954599821
commit
0dfc90d81b
1 changed files with 60 additions and 70 deletions
|
|
@ -1,5 +1,5 @@
|
|||
/**************************************************************************
|
||||
*
|
||||
*
|
||||
* Copyright 2007 VMware, Inc.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
|
|
@ -10,11 +10,11 @@
|
|||
* distribute, sub license, 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 (including the
|
||||
* next paragraph) 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 NON-INFRINGEMENT.
|
||||
|
|
@ -22,7 +22,7 @@
|
|||
* 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:
|
||||
|
|
@ -50,7 +50,7 @@ llvmpipe_create_sampler_state(struct pipe_context *pipe,
|
|||
|
||||
if (LP_PERF & PERF_NO_MIP_LINEAR) {
|
||||
if (state->min_mip_filter == PIPE_TEX_MIPFILTER_LINEAR)
|
||||
state->min_mip_filter = PIPE_TEX_MIPFILTER_NEAREST;
|
||||
state->min_mip_filter = PIPE_TEX_MIPFILTER_NEAREST;
|
||||
}
|
||||
|
||||
if (LP_PERF & PERF_NO_MIPMAPS)
|
||||
|
|
@ -73,7 +73,6 @@ llvmpipe_bind_sampler_states(struct pipe_context *pipe,
|
|||
void **samplers)
|
||||
{
|
||||
struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe);
|
||||
unsigned i;
|
||||
|
||||
assert(shader < PIPE_SHADER_TYPES);
|
||||
assert(start + num <= ARRAY_SIZE(llvmpipe->samplers[shader]));
|
||||
|
|
@ -81,11 +80,11 @@ llvmpipe_bind_sampler_states(struct pipe_context *pipe,
|
|||
draw_flush(llvmpipe->draw);
|
||||
|
||||
/* set the new samplers */
|
||||
for (i = 0; i < num; i++) {
|
||||
for (unsigned i = 0; i < num; i++) {
|
||||
void *sampler = NULL;
|
||||
|
||||
if (samplers && samplers[i])
|
||||
sampler = samplers[i];
|
||||
sampler = samplers[i];
|
||||
llvmpipe->samplers[shader][start + i] = sampler;
|
||||
}
|
||||
|
||||
|
|
@ -105,8 +104,7 @@ llvmpipe_bind_sampler_states(struct pipe_context *pipe,
|
|||
shader,
|
||||
llvmpipe->samplers[shader],
|
||||
llvmpipe->num_samplers[shader]);
|
||||
}
|
||||
else if (shader == PIPE_SHADER_COMPUTE) {
|
||||
} else if (shader == PIPE_SHADER_COMPUTE) {
|
||||
llvmpipe->cs_dirty |= LP_CSNEW_SAMPLER;
|
||||
} else {
|
||||
llvmpipe->dirty |= LP_NEW_SAMPLER;
|
||||
|
|
@ -138,7 +136,8 @@ llvmpipe_set_sampler_views(struct pipe_context *pipe,
|
|||
struct pipe_sampler_view *view = NULL;
|
||||
|
||||
if (views && views[i])
|
||||
view = views[i];
|
||||
view = views[i];
|
||||
|
||||
/*
|
||||
* Warn if someone tries to set a view created in a different context
|
||||
* (which is why we need the hack above in the first place).
|
||||
|
|
@ -183,11 +182,9 @@ llvmpipe_set_sampler_views(struct pipe_context *pipe,
|
|||
shader,
|
||||
llvmpipe->sampler_views[shader],
|
||||
llvmpipe->num_sampler_views[shader]);
|
||||
}
|
||||
else if (shader == PIPE_SHADER_COMPUTE) {
|
||||
} else if (shader == PIPE_SHADER_COMPUTE) {
|
||||
llvmpipe->cs_dirty |= LP_CSNEW_SAMPLER_VIEW;
|
||||
}
|
||||
else if (shader == PIPE_SHADER_FRAGMENT) {
|
||||
} else if (shader == PIPE_SHADER_FRAGMENT) {
|
||||
llvmpipe->dirty |= LP_NEW_SAMPLER_VIEW;
|
||||
lp_setup_set_fragment_sampler_views(llvmpipe->setup,
|
||||
llvmpipe->num_sampler_views[PIPE_SHADER_FRAGMENT],
|
||||
|
|
@ -267,19 +264,16 @@ static void
|
|||
llvmpipe_delete_sampler_state(struct pipe_context *pipe,
|
||||
void *sampler)
|
||||
{
|
||||
FREE( sampler );
|
||||
FREE(sampler);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
prepare_shader_sampling(
|
||||
struct llvmpipe_context *lp,
|
||||
unsigned num,
|
||||
struct pipe_sampler_view **views,
|
||||
enum pipe_shader_type shader_type)
|
||||
prepare_shader_sampling(struct llvmpipe_context *lp,
|
||||
unsigned num,
|
||||
struct pipe_sampler_view **views,
|
||||
enum pipe_shader_type shader_type)
|
||||
{
|
||||
|
||||
unsigned i;
|
||||
uint32_t row_stride[PIPE_MAX_TEXTURE_LEVELS];
|
||||
uint32_t img_stride[PIPE_MAX_TEXTURE_LEVELS];
|
||||
uint32_t mip_offsets[PIPE_MAX_TEXTURE_LEVELS];
|
||||
|
|
@ -289,7 +283,7 @@ prepare_shader_sampling(
|
|||
if (!num)
|
||||
return;
|
||||
|
||||
for (i = 0; i < num; i++) {
|
||||
for (unsigned i = 0; i < num; i++) {
|
||||
struct pipe_sampler_view *view = i < num ? views[i] : NULL;
|
||||
|
||||
if (view) {
|
||||
|
|
@ -305,7 +299,6 @@ prepare_shader_sampling(
|
|||
if (!lp_tex->dt) {
|
||||
/* regular texture - setup array of mipmap level offsets */
|
||||
struct pipe_resource *res = view->texture;
|
||||
int j;
|
||||
|
||||
if (llvmpipe_resource_is_texture(res)) {
|
||||
first_level = view->u.tex.first_level;
|
||||
|
|
@ -316,7 +309,7 @@ prepare_shader_sampling(
|
|||
|
||||
sample_stride = lp_tex->sample_stride;
|
||||
|
||||
for (j = first_level; j <= last_level; j++) {
|
||||
for (unsigned j = first_level; j <= last_level; j++) {
|
||||
mip_offsets[j] = lp_tex->mip_offsets[j];
|
||||
row_stride[j] = lp_tex->row_stride[j];
|
||||
img_stride[j] = lp_tex->img_stride[j];
|
||||
|
|
@ -326,7 +319,7 @@ prepare_shader_sampling(
|
|||
tex->target == PIPE_TEXTURE_CUBE ||
|
||||
tex->target == PIPE_TEXTURE_CUBE_ARRAY) {
|
||||
num_layers = view->u.tex.last_layer - view->u.tex.first_layer + 1;
|
||||
for (j = first_level; j <= last_level; j++) {
|
||||
for (unsigned j = first_level; j <= last_level; j++) {
|
||||
mip_offsets[j] += view->u.tex.first_layer *
|
||||
lp_tex->img_stride[j];
|
||||
}
|
||||
|
|
@ -337,8 +330,7 @@ prepare_shader_sampling(
|
|||
assert(view->u.tex.first_layer <= view->u.tex.last_layer);
|
||||
assert(view->u.tex.last_layer < res->array_size);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
unsigned view_blocksize = util_format_get_blocksize(view->format);
|
||||
addr = lp_tex->data;
|
||||
/* probably don't really need to fill that out */
|
||||
|
|
@ -351,8 +343,7 @@ prepare_shader_sampling(
|
|||
addr = (uint8_t *)addr + view->u.buf.offset;
|
||||
assert(view->u.buf.offset + view->u.buf.size <= res->width0);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
/* display target texture/surface */
|
||||
addr = llvmpipe_resource_map(tex, 0, 0, LP_TEX_USAGE_READ);
|
||||
row_stride[0] = lp_tex->row_stride[0];
|
||||
|
|
@ -396,44 +387,45 @@ llvmpipe_prepare_geometry_sampling(struct llvmpipe_context *lp,
|
|||
prepare_shader_sampling(lp, num, views, PIPE_SHADER_GEOMETRY);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Called whenever we're about to draw (no dirty flag, FIXME?).
|
||||
*/
|
||||
void
|
||||
llvmpipe_prepare_tess_ctrl_sampling(struct llvmpipe_context *lp,
|
||||
unsigned num,
|
||||
struct pipe_sampler_view **views)
|
||||
unsigned num,
|
||||
struct pipe_sampler_view **views)
|
||||
{
|
||||
prepare_shader_sampling(lp, num, views, PIPE_SHADER_TESS_CTRL);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Called whenever we're about to draw (no dirty flag, FIXME?).
|
||||
*/
|
||||
void
|
||||
llvmpipe_prepare_tess_eval_sampling(struct llvmpipe_context *lp,
|
||||
unsigned num,
|
||||
struct pipe_sampler_view **views)
|
||||
unsigned num,
|
||||
struct pipe_sampler_view **views)
|
||||
{
|
||||
prepare_shader_sampling(lp, num, views, PIPE_SHADER_TESS_EVAL);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
llvmpipe_cleanup_stage_sampling(struct llvmpipe_context *ctx,
|
||||
enum pipe_shader_type stage)
|
||||
{
|
||||
unsigned num, i;
|
||||
struct pipe_sampler_view **views;
|
||||
assert(ctx);
|
||||
assert(stage < ARRAY_SIZE(ctx->num_sampler_views));
|
||||
assert(stage < ARRAY_SIZE(ctx->sampler_views));
|
||||
|
||||
num = ctx->num_sampler_views[stage];
|
||||
views = ctx->sampler_views[stage];
|
||||
unsigned num = ctx->num_sampler_views[stage];
|
||||
struct pipe_sampler_view **views = ctx->sampler_views[stage];
|
||||
|
||||
assert(num <= PIPE_MAX_SHADER_SAMPLER_VIEWS);
|
||||
|
||||
for (i = 0; i < num; i++) {
|
||||
for (unsigned i = 0; i < num; i++) {
|
||||
struct pipe_sampler_view *view = views[i];
|
||||
if (view) {
|
||||
struct pipe_resource *tex = view->texture;
|
||||
|
|
@ -443,25 +435,18 @@ llvmpipe_cleanup_stage_sampling(struct llvmpipe_context *ctx,
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
prepare_shader_images(
|
||||
struct llvmpipe_context *lp,
|
||||
unsigned num,
|
||||
struct pipe_image_view *views,
|
||||
enum pipe_shader_type shader_type)
|
||||
prepare_shader_images(struct llvmpipe_context *lp,
|
||||
unsigned num,
|
||||
struct pipe_image_view *views,
|
||||
enum pipe_shader_type shader_type)
|
||||
{
|
||||
|
||||
unsigned i;
|
||||
uint32_t row_stride;
|
||||
uint32_t img_stride;
|
||||
uint32_t sample_stride;
|
||||
const void *addr;
|
||||
|
||||
assert(num <= PIPE_MAX_SHADER_SAMPLER_VIEWS);
|
||||
if (!num)
|
||||
return;
|
||||
|
||||
for (i = 0; i < num; i++) {
|
||||
for (unsigned i = 0; i < num; i++) {
|
||||
struct pipe_image_view *view = i < num ? &views[i] : NULL;
|
||||
|
||||
if (view) {
|
||||
|
|
@ -478,6 +463,11 @@ prepare_shader_images(
|
|||
width = u_minify(width, view->u.tex.level);
|
||||
height = u_minify(height, view->u.tex.level);
|
||||
|
||||
uint32_t row_stride;
|
||||
uint32_t img_stride;
|
||||
uint32_t sample_stride;
|
||||
const void *addr;
|
||||
|
||||
if (!lp_img->dt) {
|
||||
/* regular texture - setup array of mipmap level offsets */
|
||||
struct pipe_resource *res = view->resource;
|
||||
|
|
@ -491,18 +481,20 @@ prepare_shader_images(
|
|||
img->target == PIPE_TEXTURE_3D ||
|
||||
img->target == PIPE_TEXTURE_CUBE ||
|
||||
img->target == PIPE_TEXTURE_CUBE_ARRAY) {
|
||||
num_layers = view->u.tex.last_layer - view->u.tex.first_layer + 1;
|
||||
num_layers = view->u.tex.last_layer -
|
||||
view->u.tex.first_layer + 1;
|
||||
assert(view->u.tex.first_layer <= view->u.tex.last_layer);
|
||||
mip_offset += view->u.tex.first_layer * lp_img->img_stride[view->u.tex.level];
|
||||
mip_offset += view->u.tex.first_layer *
|
||||
lp_img->img_stride[view->u.tex.level];
|
||||
}
|
||||
|
||||
row_stride = lp_img->row_stride[view->u.tex.level];
|
||||
img_stride = lp_img->img_stride[view->u.tex.level];
|
||||
sample_stride = lp_img->sample_stride;
|
||||
addr = (uint8_t *)addr + mip_offset;
|
||||
}
|
||||
else {
|
||||
unsigned view_blocksize = util_format_get_blocksize(view->format);
|
||||
} else {
|
||||
unsigned view_blocksize =
|
||||
util_format_get_blocksize(view->format);
|
||||
addr = lp_img->data;
|
||||
/* probably don't really need to fill that out */
|
||||
row_stride = 0;
|
||||
|
|
@ -514,8 +506,7 @@ prepare_shader_images(
|
|||
addr = (uint8_t *)addr + view->u.buf.offset;
|
||||
assert(view->u.buf.offset + view->u.buf.size <= res->width0);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
/* display target texture/surface */
|
||||
addr = llvmpipe_resource_map(img, 0, 0, LP_TEX_USAGE_READ);
|
||||
row_stride = lp_img->row_stride[0];
|
||||
|
|
@ -523,12 +514,9 @@ prepare_shader_images(
|
|||
sample_stride = 0;
|
||||
assert(addr);
|
||||
}
|
||||
draw_set_mapped_image(lp->draw,
|
||||
shader_type,
|
||||
i,
|
||||
draw_set_mapped_image(lp->draw, shader_type, i,
|
||||
width, height, num_layers,
|
||||
addr,
|
||||
row_stride, img_stride,
|
||||
addr, row_stride, img_stride,
|
||||
num_samples, sample_stride);
|
||||
}
|
||||
}
|
||||
|
|
@ -558,6 +546,7 @@ llvmpipe_prepare_geometry_images(struct llvmpipe_context *lp,
|
|||
prepare_shader_images(lp, num, views, PIPE_SHADER_GEOMETRY);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Called whenever we're about to draw (no dirty flag, FIXME?).
|
||||
*/
|
||||
|
|
@ -569,6 +558,7 @@ llvmpipe_prepare_tess_ctrl_images(struct llvmpipe_context *lp,
|
|||
prepare_shader_images(lp, num, views, PIPE_SHADER_TESS_CTRL);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Called whenever we're about to draw (no dirty flag, FIXME?).
|
||||
*/
|
||||
|
|
@ -580,22 +570,21 @@ llvmpipe_prepare_tess_eval_images(struct llvmpipe_context *lp,
|
|||
prepare_shader_images(lp, num, views, PIPE_SHADER_TESS_EVAL);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
llvmpipe_cleanup_stage_images(struct llvmpipe_context *ctx,
|
||||
enum pipe_shader_type stage)
|
||||
{
|
||||
unsigned num, i;
|
||||
struct pipe_image_view *views;
|
||||
assert(ctx);
|
||||
assert(stage < ARRAY_SIZE(ctx->num_images));
|
||||
assert(stage < ARRAY_SIZE(ctx->images));
|
||||
|
||||
num = ctx->num_images[stage];
|
||||
views = ctx->images[stage];
|
||||
unsigned num = ctx->num_images[stage];
|
||||
struct pipe_image_view *views = ctx->images[stage];
|
||||
|
||||
assert(num <= LP_MAX_TGSI_SHADER_IMAGES);
|
||||
|
||||
for (i = 0; i < num; i++) {
|
||||
for (unsigned i = 0; i < num; i++) {
|
||||
struct pipe_image_view *view = &views[i];
|
||||
assert(view);
|
||||
struct pipe_resource *img = view->resource;
|
||||
|
|
@ -604,6 +593,7 @@ llvmpipe_cleanup_stage_images(struct llvmpipe_context *ctx,
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
llvmpipe_init_sampler_funcs(struct llvmpipe_context *llvmpipe)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue