Commit e2f037e9 authored by Neil Roberts's avatar Neil Roberts

v3d: Split the creating of TEXTURE_SHADER_STATE into a helper function

This extracts the part of v3d_create_sampler_view that creates and fills
in the buffer for the TEXTURE_SHADER_STATE record into a helper
function. This will be used in a later patch to update the record when
the information changes.

v2: Also put the part that creates the buffer into the helper function
    so that it won’t override the contents of an inflight buffer.
Reviewed-by: Eric Anholt's avatarEric Anholt <eric@anholt.net>
Part-of: <!6914>
parent d25504da
......@@ -216,6 +216,16 @@ v3d_flag_dirty_sampler_state(struct v3d_context *v3d,
}
}
void
v3d_create_texture_shader_state_bo(struct v3d_context *v3d,
struct v3d_sampler_view *so)
{
if (v3d->screen->devinfo.ver >= 41)
v3d41_create_texture_shader_state_bo(v3d, so);
else
v3d33_create_texture_shader_state_bo(v3d, so);
}
static void
v3d_context_destroy(struct pipe_context *pctx)
{
......
......@@ -706,6 +706,9 @@ float v3d_get_real_line_width(struct v3d_context *v3d);
void v3d_flag_dirty_sampler_state(struct v3d_context *v3d,
enum pipe_shader_type shader);
void v3d_create_texture_shader_state_bo(struct v3d_context *v3d,
struct v3d_sampler_view *so);
#ifdef v3dX
# include "v3dx_context.h"
#else
......
......@@ -33,6 +33,8 @@ void v3dX(emit_state)(struct pipe_context *pctx);
void v3dX(emit_rcl)(struct v3d_job *job);
void v3dX(draw_init)(struct pipe_context *pctx);
void v3dX(state_init)(struct pipe_context *pctx);
void v3dX(create_texture_shader_state_bo)(struct v3d_context *v3d,
struct v3d_sampler_view *so);
void v3dX(bcl_epilogue)(struct v3d_context *v3d, struct v3d_job *job);
......
......@@ -894,6 +894,93 @@ v3d_setup_texture_shader_state(struct V3DX(TEXTURE_SHADER_STATE) *tex,
#endif /* V3D_VERSION >= 40 */
}
void
v3dX(create_texture_shader_state_bo)(struct v3d_context *v3d,
struct v3d_sampler_view *so)
{
struct pipe_resource *prsc = so->texture;
const struct pipe_sampler_view *cso = &so->base;
struct v3d_screen *screen = v3d->screen;
void *map;
#if V3D_VERSION >= 40
v3d_bo_unreference(&so->bo);
so->bo = v3d_bo_alloc(v3d->screen,
cl_packet_length(TEXTURE_SHADER_STATE), "sampler");
map = v3d_bo_map(so->bo);
#else /* V3D_VERSION < 40 */
STATIC_ASSERT(sizeof(so->texture_shader_state) >=
cl_packet_length(TEXTURE_SHADER_STATE));
map = &so->texture_shader_state;
#endif
v3dx_pack(map, TEXTURE_SHADER_STATE, tex) {
v3d_setup_texture_shader_state(&tex, prsc,
cso->u.tex.first_level,
cso->u.tex.last_level,
cso->u.tex.first_layer,
cso->u.tex.last_layer);
tex.srgb = util_format_is_srgb(cso->format);
#if V3D_VERSION >= 40
tex.swizzle_r = translate_swizzle(so->swizzle[0]);
tex.swizzle_g = translate_swizzle(so->swizzle[1]);
tex.swizzle_b = translate_swizzle(so->swizzle[2]);
tex.swizzle_a = translate_swizzle(so->swizzle[3]);
#endif
if (prsc->nr_samples > 1 && V3D_VERSION < 40) {
/* Using texture views to reinterpret formats on our
* MSAA textures won't work, because we don't lay out
* the bits in memory as it's expected -- for example,
* RGBA8 and RGB10_A2 are compatible in the
* ARB_texture_view spec, but in HW we lay them out as
* 32bpp RGBA8 and 64bpp RGBA16F. Just assert for now
* to catch failures.
*
* We explicitly allow remapping S8Z24 to RGBA8888 for
* v3d_blit.c's stencil blits.
*/
assert((util_format_linear(cso->format) ==
util_format_linear(prsc->format)) ||
(prsc->format == PIPE_FORMAT_S8_UINT_Z24_UNORM &&
cso->format == PIPE_FORMAT_R8G8B8A8_UNORM));
uint32_t output_image_format =
v3d_get_rt_format(&screen->devinfo, cso->format);
uint32_t internal_type;
uint32_t internal_bpp;
v3d_get_internal_type_bpp_for_output_format(&screen->devinfo,
output_image_format,
&internal_type,
&internal_bpp);
switch (internal_type) {
case V3D_INTERNAL_TYPE_8:
tex.texture_type = TEXTURE_DATA_FORMAT_RGBA8;
break;
case V3D_INTERNAL_TYPE_16F:
tex.texture_type = TEXTURE_DATA_FORMAT_RGBA16F;
break;
default:
unreachable("Bad MSAA texture type");
}
/* sRGB was stored in the tile buffer as linear and
* would have been encoded to sRGB on resolved tile
* buffer store. Note that this means we would need
* shader code if we wanted to read an MSAA sRGB
* texture without sRGB decode.
*/
tex.srgb = false;
} else {
tex.texture_type = v3d_get_tex_format(&screen->devinfo,
cso->format);
}
};
}
static struct pipe_sampler_view *
v3d_create_sampler_view(struct pipe_context *pctx, struct pipe_resource *prsc,
const struct pipe_sampler_view *cso)
......@@ -1045,81 +1132,7 @@ v3d_create_sampler_view(struct pipe_context *pctx, struct pipe_resource *prsc,
pipe_resource_reference(&so->texture, prsc);
}
void *map;
#if V3D_VERSION >= 40
so->bo = v3d_bo_alloc(v3d->screen,
cl_packet_length(TEXTURE_SHADER_STATE), "sampler");
map = v3d_bo_map(so->bo);
#else /* V3D_VERSION < 40 */
STATIC_ASSERT(sizeof(so->texture_shader_state) >=
cl_packet_length(TEXTURE_SHADER_STATE));
map = &so->texture_shader_state;
#endif
v3dx_pack(map, TEXTURE_SHADER_STATE, tex) {
v3d_setup_texture_shader_state(&tex, prsc,
cso->u.tex.first_level,
cso->u.tex.last_level,
cso->u.tex.first_layer,
cso->u.tex.last_layer);
tex.srgb = util_format_is_srgb(cso->format);
#if V3D_VERSION >= 40
tex.swizzle_r = translate_swizzle(so->swizzle[0]);
tex.swizzle_g = translate_swizzle(so->swizzle[1]);
tex.swizzle_b = translate_swizzle(so->swizzle[2]);
tex.swizzle_a = translate_swizzle(so->swizzle[3]);
#endif
if (prsc->nr_samples > 1 && V3D_VERSION < 40) {
/* Using texture views to reinterpret formats on our
* MSAA textures won't work, because we don't lay out
* the bits in memory as it's expected -- for example,
* RGBA8 and RGB10_A2 are compatible in the
* ARB_texture_view spec, but in HW we lay them out as
* 32bpp RGBA8 and 64bpp RGBA16F. Just assert for now
* to catch failures.
*
* We explicitly allow remapping S8Z24 to RGBA8888 for
* v3d_blit.c's stencil blits.
*/
assert((util_format_linear(cso->format) ==
util_format_linear(prsc->format)) ||
(prsc->format == PIPE_FORMAT_S8_UINT_Z24_UNORM &&
cso->format == PIPE_FORMAT_R8G8B8A8_UNORM));
uint32_t output_image_format =
v3d_get_rt_format(&screen->devinfo, cso->format);
uint32_t internal_type;
uint32_t internal_bpp;
v3d_get_internal_type_bpp_for_output_format(&screen->devinfo,
output_image_format,
&internal_type,
&internal_bpp);
switch (internal_type) {
case V3D_INTERNAL_TYPE_8:
tex.texture_type = TEXTURE_DATA_FORMAT_RGBA8;
break;
case V3D_INTERNAL_TYPE_16F:
tex.texture_type = TEXTURE_DATA_FORMAT_RGBA16F;
break;
default:
unreachable("Bad MSAA texture type");
}
/* sRGB was stored in the tile buffer as linear and
* would have been encoded to sRGB on resolved tile
* buffer store. Note that this means we would need
* shader code if we wanted to read an MSAA sRGB
* texture without sRGB decode.
*/
tex.srgb = false;
} else {
tex.texture_type = v3d_get_tex_format(&screen->devinfo,
cso->format);
}
};
v3d_create_texture_shader_state_bo(v3d, so);
return &so->base;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment