boolean has_stream_out;
boolean has_stencil_export;
boolean has_texture_multisample;
-};
+ /* The Draw module overrides these functions.
+ * Always create the blitter before Draw. */
+ void (*bind_fs_state)(struct pipe_context *, void *);
+ void (*delete_fs_state)(struct pipe_context *, void *);
+};
struct blitter_context *util_blitter_create(struct pipe_context *pipe)
{
ctx->base.pipe = pipe;
ctx->base.draw_rectangle = util_blitter_draw_rectangle;
+ ctx->bind_fs_state = pipe->bind_fs_state;
+ ctx->delete_fs_state = pipe->delete_fs_state;
+
/* init state objects for them to be considered invalid */
ctx->base.saved_blend_state = INVALID_PTR;
ctx->base.saved_dsa_state = INVALID_PTR;
for (i = 0; i < PIPE_MAX_TEXTURE_TYPES; i++) {
if (ctx->fs_texfetch_col[i])
- pipe->delete_fs_state(pipe, ctx->fs_texfetch_col[i]);
+ ctx->delete_fs_state(pipe, ctx->fs_texfetch_col[i]);
if (ctx->fs_texfetch_depth[i])
- pipe->delete_fs_state(pipe, ctx->fs_texfetch_depth[i]);
+ ctx->delete_fs_state(pipe, ctx->fs_texfetch_depth[i]);
if (ctx->fs_texfetch_depthstencil[i])
- pipe->delete_fs_state(pipe, ctx->fs_texfetch_depthstencil[i]);
+ ctx->delete_fs_state(pipe, ctx->fs_texfetch_depthstencil[i]);
if (ctx->fs_texfetch_stencil[i])
- pipe->delete_fs_state(pipe, ctx->fs_texfetch_stencil[i]);
+ ctx->delete_fs_state(pipe, ctx->fs_texfetch_stencil[i]);
}
for (i = 0; i <= PIPE_MAX_COLOR_BUFS; i++) {
if (ctx->fs_col[i])
- pipe->delete_fs_state(pipe, ctx->fs_col[i]);
+ ctx->delete_fs_state(pipe, ctx->fs_col[i]);
if (ctx->fs_col_int[i])
- pipe->delete_fs_state(pipe, ctx->fs_col_int[i]);
+ ctx->delete_fs_state(pipe, ctx->fs_col_int[i]);
}
pipe->delete_sampler_state(pipe, ctx->sampler_state);
struct pipe_context *pipe = ctx->base.pipe;
/* Fragment shader. */
- pipe->bind_fs_state(pipe, ctx->base.saved_fs);
+ ctx->bind_fs_state(pipe, ctx->base.saved_fs);
ctx->base.saved_fs = INVALID_PTR;
/* Depth, stencil, alpha. */
ctx->dst_height = height;
}
-static INLINE
-void *blitter_get_fs_col(struct blitter_context_priv *ctx, unsigned num_cbufs,
- boolean int_format)
+static void *blitter_get_fs_col(struct blitter_context_priv *ctx,
+ unsigned num_cbufs, boolean int_format)
{
struct pipe_context *pipe = ctx->base.pipe;
}
}
-static INLINE
-void *blitter_get_fs_texfetch_col(struct blitter_context_priv *ctx,
- struct pipe_resource *tex)
+static void *blitter_get_fs_texfetch_col(struct blitter_context_priv *ctx,
+ enum pipe_texture_target target,
+ unsigned nr_samples)
{
struct pipe_context *pipe = ctx->base.pipe;
- assert(tex->target < PIPE_MAX_TEXTURE_TYPES);
+ assert(target < PIPE_MAX_TEXTURE_TYPES);
- if (tex->nr_samples > 1) {
- void **shader = &ctx->fs_texfetch_col_msaa[tex->target];
+ if (nr_samples > 1) {
+ void **shader = &ctx->fs_texfetch_col_msaa[target];
/* Create the fragment shader on-demand. */
if (!*shader) {
- unsigned tgsi_tex = util_pipe_tex_to_tgsi_tex(tex->target,
- tex->nr_samples);
+ unsigned tgsi_tex = util_pipe_tex_to_tgsi_tex(target,
+ nr_samples);
*shader = util_make_fs_blit_msaa_color(pipe, tgsi_tex);
}
return *shader;
} else {
- void **shader = &ctx->fs_texfetch_col[tex->target];
+ void **shader = &ctx->fs_texfetch_col[target];
/* Create the fragment shader on-demand. */
if (!*shader) {
- unsigned tgsi_tex = util_pipe_tex_to_tgsi_tex(tex->target, 0);
+ unsigned tgsi_tex = util_pipe_tex_to_tgsi_tex(target, 0);
*shader =
util_make_fragment_tex_shader(pipe, tgsi_tex,
static INLINE
void *blitter_get_fs_texfetch_depth(struct blitter_context_priv *ctx,
- struct pipe_resource *tex)
+ enum pipe_texture_target target,
+ unsigned nr_samples)
{
struct pipe_context *pipe = ctx->base.pipe;
- assert(tex->target < PIPE_MAX_TEXTURE_TYPES);
+ assert(target < PIPE_MAX_TEXTURE_TYPES);
- if (tex->nr_samples > 1) {
- void **shader = &ctx->fs_texfetch_depth_msaa[tex->target];
+ if (nr_samples > 1) {
+ void **shader = &ctx->fs_texfetch_depth_msaa[target];
/* Create the fragment shader on-demand. */
if (!*shader) {
- unsigned tgsi_tex = util_pipe_tex_to_tgsi_tex(tex->target,
- tex->nr_samples);
+ unsigned tgsi_tex = util_pipe_tex_to_tgsi_tex(target,
+ nr_samples);
*shader =
util_make_fs_blit_msaa_depth(pipe, tgsi_tex);
return *shader;
} else {
- void **shader = &ctx->fs_texfetch_depth[tex->target];
+ void **shader = &ctx->fs_texfetch_depth[target];
/* Create the fragment shader on-demand. */
if (!*shader) {
- unsigned tgsi_tex = util_pipe_tex_to_tgsi_tex(tex->target, 0);
+ unsigned tgsi_tex = util_pipe_tex_to_tgsi_tex(target, 0);
*shader =
util_make_fragment_tex_shader_writedepth(pipe, tgsi_tex,
static INLINE
void *blitter_get_fs_texfetch_depthstencil(struct blitter_context_priv *ctx,
- struct pipe_resource *tex)
+ enum pipe_texture_target target,
+ unsigned nr_samples)
{
struct pipe_context *pipe = ctx->base.pipe;
- assert(tex->target < PIPE_MAX_TEXTURE_TYPES);
+ assert(target < PIPE_MAX_TEXTURE_TYPES);
- if (tex->nr_samples > 1) {
- void **shader = &ctx->fs_texfetch_depthstencil_msaa[tex->target];
+ if (nr_samples > 1) {
+ void **shader = &ctx->fs_texfetch_depthstencil_msaa[target];
/* Create the fragment shader on-demand. */
if (!*shader) {
- unsigned tgsi_tex = util_pipe_tex_to_tgsi_tex(tex->target,
- tex->nr_samples);
+ unsigned tgsi_tex = util_pipe_tex_to_tgsi_tex(target,
+ nr_samples);
*shader =
util_make_fs_blit_msaa_depthstencil(pipe, tgsi_tex);
return *shader;
} else {
- void **shader = &ctx->fs_texfetch_depthstencil[tex->target];
+ void **shader = &ctx->fs_texfetch_depthstencil[target];
/* Create the fragment shader on-demand. */
if (!*shader) {
- unsigned tgsi_tex = util_pipe_tex_to_tgsi_tex(tex->target, 0);
+ unsigned tgsi_tex = util_pipe_tex_to_tgsi_tex(target, 0);
*shader =
util_make_fragment_tex_shader_writedepthstencil(pipe, tgsi_tex,
static INLINE
void *blitter_get_fs_texfetch_stencil(struct blitter_context_priv *ctx,
- struct pipe_resource *tex)
+ enum pipe_texture_target target,
+ unsigned nr_samples)
{
struct pipe_context *pipe = ctx->base.pipe;
- assert(tex->target < PIPE_MAX_TEXTURE_TYPES);
+ assert(target < PIPE_MAX_TEXTURE_TYPES);
- if (tex->nr_samples > 1) {
- void **shader = &ctx->fs_texfetch_stencil_msaa[tex->target];
+ if (nr_samples > 1) {
+ void **shader = &ctx->fs_texfetch_stencil_msaa[target];
/* Create the fragment shader on-demand. */
if (!*shader) {
- unsigned tgsi_tex = util_pipe_tex_to_tgsi_tex(tex->target,
- tex->nr_samples);
+ unsigned tgsi_tex = util_pipe_tex_to_tgsi_tex(target,
+ nr_samples);
*shader =
util_make_fs_blit_msaa_stencil(pipe, tgsi_tex);
return *shader;
} else {
- void **shader = &ctx->fs_texfetch_stencil[tex->target];
+ void **shader = &ctx->fs_texfetch_stencil[target];
/* Create the fragment shader on-demand. */
if (!*shader) {
- unsigned tgsi_tex = util_pipe_tex_to_tgsi_tex(tex->target, 0);
+ unsigned tgsi_tex = util_pipe_tex_to_tgsi_tex(target, 0);
*shader =
util_make_fragment_tex_shader_writestencil(pipe, tgsi_tex,
}
}
+void util_blitter_cache_all_shaders(struct blitter_context *blitter)
+{
+ struct blitter_context_priv *ctx = (struct blitter_context_priv*)blitter;
+ struct pipe_screen *screen = blitter->pipe->screen;
+ unsigned num_cbufs, i, target, max_samples;
+ boolean has_arraytex;
+
+ num_cbufs = MAX2(screen->get_param(screen,
+ PIPE_CAP_MAX_RENDER_TARGETS), 1);
+ max_samples = ctx->has_texture_multisample ? 2 : 1;
+ has_arraytex = screen->get_param(screen,
+ PIPE_CAP_MAX_TEXTURE_ARRAY_LAYERS) != 0;
+
+ for (i = 0; i < num_cbufs; i++) {
+ blitter_get_fs_col(ctx, i, FALSE);
+ blitter_get_fs_col(ctx, i, TRUE);
+ }
+
+ /* It only matters if i <= 1 or > 1. */
+ for (i = 1; i <= max_samples; i++) {
+ for (target = PIPE_TEXTURE_1D; target < PIPE_MAX_TEXTURE_TYPES; target++) {
+ if (!has_arraytex &&
+ (target == PIPE_TEXTURE_1D_ARRAY ||
+ target == PIPE_TEXTURE_2D_ARRAY)) {
+ continue;
+ }
+
+ blitter_get_fs_texfetch_col(ctx, target, i);
+ blitter_get_fs_texfetch_depth(ctx, target, i);
+ if (ctx->has_stencil_export) {
+ blitter_get_fs_texfetch_depthstencil(ctx, target, i);
+ blitter_get_fs_texfetch_stencil(ctx, target, i);
+ }
+ }
+ }
+}
+
static void blitter_set_common_draw_rect_state(struct blitter_context_priv *ctx)
{
struct pipe_context *pipe = ctx->base.pipe;
} else {
pipe->bind_vertex_elements_state(pipe, ctx->velem_state);
}
- pipe->bind_fs_state(pipe, blitter_get_fs_col(ctx, num_cbufs, int_format));
+ ctx->bind_fs_state(pipe, blitter_get_fs_col(ctx, num_cbufs, int_format));
pipe->set_sample_mask(pipe, ~0);
blitter_set_common_draw_rect_state(ctx);
if (blit_depth && blit_stencil) {
pipe->bind_depth_stencil_alpha_state(pipe,
ctx->dsa_write_depth_stencil);
- pipe->bind_fs_state(pipe,
- blitter_get_fs_texfetch_depthstencil(ctx, src->texture));
+ ctx->bind_fs_state(pipe,
+ blitter_get_fs_texfetch_depthstencil(ctx, src->texture->target,
+ src->texture->nr_samples));
} else if (blit_depth) {
pipe->bind_depth_stencil_alpha_state(pipe,
ctx->dsa_write_depth_keep_stencil);
- pipe->bind_fs_state(pipe,
- blitter_get_fs_texfetch_depth(ctx, src->texture));
+ ctx->bind_fs_state(pipe,
+ blitter_get_fs_texfetch_depth(ctx, src->texture->target,
+ src->texture->nr_samples));
} else { /* is_stencil */
pipe->bind_depth_stencil_alpha_state(pipe,
ctx->dsa_keep_depth_write_stencil);
- pipe->bind_fs_state(pipe,
- blitter_get_fs_texfetch_stencil(ctx, src->texture));
+ ctx->bind_fs_state(pipe,
+ blitter_get_fs_texfetch_stencil(ctx, src->texture->target,
+ src->texture->nr_samples));
}
fb_state.nr_cbufs = 0;
} else {
pipe->bind_blend_state(pipe, ctx->blend_write_color);
pipe->bind_depth_stencil_alpha_state(pipe, ctx->dsa_keep_depth_stencil);
- pipe->bind_fs_state(pipe,
- blitter_get_fs_texfetch_col(ctx, src->texture));
+ ctx->bind_fs_state(pipe,
+ blitter_get_fs_texfetch_col(ctx, src->texture->target,
+ src->texture->nr_samples));
fb_state.nr_cbufs = 1;
fb_state.cbufs[0] = dst;
/* bind states */
pipe->bind_blend_state(pipe, ctx->blend_write_color);
pipe->bind_depth_stencil_alpha_state(pipe, ctx->dsa_keep_depth_stencil);
- pipe->bind_fs_state(pipe, blitter_get_fs_col(ctx, 1, FALSE));
+ ctx->bind_fs_state(pipe, blitter_get_fs_col(ctx, 1, FALSE));
pipe->bind_vertex_elements_state(pipe, ctx->velem_state);
/* set a framebuffer state */
/* hmm that should be illegal probably, or make it a no-op somewhere */
pipe->bind_depth_stencil_alpha_state(pipe, ctx->dsa_keep_depth_stencil);
- pipe->bind_fs_state(pipe, blitter_get_fs_col(ctx, 0, FALSE));
+ ctx->bind_fs_state(pipe, blitter_get_fs_col(ctx, 0, FALSE));
pipe->bind_vertex_elements_state(pipe, ctx->velem_state);
/* set a framebuffer state */
/* bind states */
pipe->bind_blend_state(pipe, ctx->blend_write_color);
pipe->bind_depth_stencil_alpha_state(pipe, dsa_stage);
- pipe->bind_fs_state(pipe, blitter_get_fs_col(ctx, 0, FALSE));
+ ctx->bind_fs_state(pipe, blitter_get_fs_col(ctx, 0, FALSE));
pipe->bind_vertex_elements_state(pipe, ctx->velem_state);
/* set a framebuffer state */
pipe->bind_blend_state(pipe, custom_blend);
pipe->bind_depth_stencil_alpha_state(pipe, ctx->dsa_keep_depth_stencil);
pipe->bind_vertex_elements_state(pipe, ctx->velem_state);
- pipe->bind_fs_state(pipe, blitter_get_fs_col(ctx, 1, FALSE));
+ ctx->bind_fs_state(pipe, blitter_get_fs_col(ctx, 1, FALSE));
pipe->set_sample_mask(pipe, sample_mask);
memset(&surf_tmpl, 0, sizeof(surf_tmpl));
/* bind states */
pipe->bind_blend_state(pipe, custom_blend);
pipe->bind_depth_stencil_alpha_state(pipe, ctx->dsa_keep_depth_stencil);
- pipe->bind_fs_state(pipe, blitter_get_fs_col(ctx, 1, FALSE));
+ ctx->bind_fs_state(pipe, blitter_get_fs_col(ctx, 1, FALSE));
pipe->bind_vertex_elements_state(pipe, ctx->velem_state);
pipe->set_sample_mask(pipe, (1ull << MAX2(1, dstsurf->texture->nr_samples)) - 1);