Commit 8f9cc6cd authored by Alyssa Rosenzweig's avatar Alyssa Rosenzweig 💜

CSOify sampler

parent bf090164
......@@ -241,6 +241,9 @@ trans_invalidate_frame(struct panfrost_context *ctx)
/* XXX: Framebuffer update the right way */
trans_new_frag_framebuffer(ctx);
/* XXX */
ctx->dirty |= PAN_DIRTY_SAMPLERS;
}
void
......@@ -411,18 +414,7 @@ trans_emit_tiler_payload(struct panfrost_context *ctx)
.texture = &rsrc
};
struct pipe_sampler_state _sampler_state = {
.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE,
.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE,
.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE,
.compare_func = PIPE_FUNC_LEQUAL,
.min_img_filter = PIPE_TEX_FILTER_LINEAR,
.mag_img_filter = PIPE_TEX_FILTER_LINEAR,
.border_color = { .f = { 0.0, 0.0, 0.0, 0.0 } },
};
struct pipe_sampler_view *sampler_view = &_sampler_view;
struct pipe_sampler_state *sampler_state = &_sampler_state;
/* TODO: Other types of textures */
assert(sampler_view->target == PIPE_TEXTURE_2D);
......@@ -448,27 +440,7 @@ trans_emit_tiler_payload(struct panfrost_context *ctx)
uint64_t texture_trampoline = panfrost_upload(&ctx->cmdstream, &texture_descriptor, sizeof(texture_descriptor), false);
struct mali_sampler_descriptor sampler_descriptor = {
.filter_mode = MALI_GL_TEX_MIN(translate_tex_filter(sampler_state->min_img_filter))
| MALI_GL_TEX_MAG(translate_tex_filter(sampler_state->mag_img_filter))
| 0x20,
.wrap_s = translate_tex_wrap(sampler_state->wrap_s),
.wrap_t = translate_tex_wrap(sampler_state->wrap_t),
.wrap_r = translate_tex_wrap(sampler_state->wrap_r),
.compare_func = trans_translate_alt_compare_func(sampler_state->compare_func),
.border_color = {
sampler_state->border_color.f[0],
sampler_state->border_color.f[1],
sampler_state->border_color.f[2],
sampler_state->border_color.f[3]
},
.unknown2 = 1,
.unknown1 = 0x10000,
};
ctx->payload_tiler.texture_trampoline = panfrost_upload(&ctx->cmdstream, &texture_trampoline, sizeof(uint64_t), false);
ctx->payload_tiler.sampler_descriptor = panfrost_upload(&ctx->cmdstream, &sampler_descriptor, sizeof(sampler_descriptor), false);
}
void
......@@ -902,6 +874,12 @@ trans_emit_for_draw(struct panfrost_context *ctx)
ctx->payload_tiler.viewport = panfrost_upload(&ctx->cmdstream, &ctx->viewport, sizeof(struct mali_viewport), false);
}
if ((ctx->dirty & PAN_DIRTY_SAMPLERS) && ctx->sampler_count /* XXX */) {
assert(ctx->sampler_count == 1);
ctx->payload_tiler.sampler_descriptor = panfrost_upload(&ctx->cmdstream, &ctx->samplers[PIPE_SHADER_FRAGMENT][0]->hw, sizeof(struct mali_sampler_descriptor), false);
}
for (int i = 0; i < PIPE_SHADER_TYPES; ++i) {
struct panfrost_constant_buffer *buf = &ctx->constant_buffer[i];
......@@ -1316,6 +1294,62 @@ panfrost_delete_shader_state(
free(so);
}
static void *
panfrost_create_sampler_state(
struct pipe_context *pctx,
const struct pipe_sampler_state *cso)
{
struct panfrost_sampler_state *so = CALLOC_STRUCT(panfrost_sampler_state);
so->base = *cso;
/* sampler_state corresponds to mali_sampler_descriptor, which we can generate entirely here */
struct mali_sampler_descriptor sampler_descriptor = {
.filter_mode = MALI_GL_TEX_MIN(translate_tex_filter(cso->min_img_filter))
| MALI_GL_TEX_MAG(translate_tex_filter(cso->mag_img_filter))
| 0x20,
.wrap_s = translate_tex_wrap(cso->wrap_s),
.wrap_t = translate_tex_wrap(cso->wrap_t),
.wrap_r = translate_tex_wrap(cso->wrap_r),
.compare_func = trans_translate_alt_compare_func(cso->compare_func),
.border_color = {
cso->border_color.f[0],
cso->border_color.f[1],
cso->border_color.f[2],
cso->border_color.f[3]
},
.unknown2 = 1,
.unknown1 = 0x10000,
};
so->hw = sampler_descriptor;
return so;
}
static void
panfrost_bind_sampler_states(
struct pipe_context *pctx,
enum pipe_shader_type shader,
unsigned start_slot, unsigned num_sampler,
void **sampler)
{
/* TODO: Investigate textures in other shader types */
assert(shader == PIPE_SHADER_FRAGMENT);
assert(start_slot == 0);
assert(num_sampler == 1);
struct panfrost_context *ctx = panfrost_context(pctx);
/* XXX: Should upload, not just copy? */
ctx->sampler_count = num_sampler;
ctx->samplers[shader] = calloc(num_sampler, sizeof (void *)); /* XXX: leak */
memcpy(ctx->samplers[shader], sampler, num_sampler * sizeof (void *));
ctx->dirty |= PAN_DIRTY_SAMPLERS;
}
static void
panfrost_bind_fs_state(
struct pipe_context *pctx,
......@@ -1620,6 +1654,10 @@ panfrost_create_context(struct pipe_screen *screen, void *priv, unsigned flags)
gallium->delete_vs_state = panfrost_delete_shader_state;
gallium->bind_vs_state = panfrost_bind_vs_state;
gallium->create_sampler_state = panfrost_create_sampler_state;
gallium->delete_sampler_state = panfrost_generic_cso_delete;
gallium->bind_sampler_states = panfrost_bind_sampler_states;
/* Prepare for render! */
trans_setup_hardware(ctx);
trans_invalidate_frame(ctx);
......
......@@ -37,6 +37,7 @@
#define PAN_DIRTY_VERTEX (1 << 5)
#define PAN_DIRTY_VERT_BUF (1 << 6)
#define PAN_DIRTY_VIEWPORT (1 << 7)
#define PAN_DIRTY_SAMPLERS (1 << 8)
struct panfrost_constant_buffer {
bool dirty;
......@@ -126,6 +127,9 @@ struct panfrost_context {
struct pipe_vertex_buffer *vertex_buffers;
int vertex_buffer_count;
struct panfrost_sampler_state **samplers[PIPE_SHADER_TYPES];
int sampler_count;
};
/* Corresponds to the CSO */
......@@ -152,6 +156,11 @@ struct panfrost_vertex_state {
struct mali_attr_meta hw[PIPE_MAX_ATTRIBS];
};
struct panfrost_sampler_state {
struct pipe_sampler_state base;
struct mali_sampler_descriptor hw;
};
/* Corresponds to pipe_resource for our hacky pre-DRM interface */
struct panfrost_resource {
......
......@@ -108,6 +108,23 @@ int main(int argc, const char **argv)
gallium->bind_rasterizer_state(gallium,
gallium->create_rasterizer_state(gallium, &state));
struct pipe_sampler_state sampler_state = {
.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE,
.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE,
.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE,
.compare_func = PIPE_FUNC_LEQUAL,
.min_img_filter = PIPE_TEX_FILTER_LINEAR,
.mag_img_filter = PIPE_TEX_FILTER_LINEAR,
.border_color = { .f = { 0.0, 0.0, 0.0, 0.0 } },
};
void *samp = gallium->create_sampler_state(gallium, &sampler_state);
gallium->bind_sampler_states(gallium,
PIPE_SHADER_FRAGMENT,
0, 1,
&samp);
for (int i = 0; i < 600; ++i) {
const struct pipe_rasterizer_state stat = {
.line_width = 10.0f,
......
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