From 593517a775a6f3e9a85c4c5d192edc9295b1f0d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Tue, 29 Sep 2020 17:35:47 -0400 Subject: [PATCH] gallium: add pipe_context::set_inlinable_constants Reviewed-by: Timothy Arceri Part-of: --- docs/gallium/context.rst | 16 ++++++++++ .../auxiliary/driver_noop/noop_state.c | 7 +++++ .../auxiliary/util/u_threaded_context.c | 30 +++++++++++++++++++ .../auxiliary/util/u_threaded_context_calls.h | 1 + src/gallium/include/pipe/p_context.h | 20 +++++++++++++ 5 files changed, 74 insertions(+) diff --git a/docs/gallium/context.rst b/docs/gallium/context.rst index c0667f8d296..f061cade531 100644 --- a/docs/gallium/context.rst +++ b/docs/gallium/context.rst @@ -49,6 +49,22 @@ buffers, surfaces) are bound to the driver. multiple ones to be set, and binding a specific one later, though drivers are mostly restricted to the first one right now). +* ``set_inlinable_constants`` sets inlinable constants for constant buffer 0. + +These are constants that the driver would like to inline in the IR +of the current shader and recompile it. Drivers can determine which +constants they prefer to inline in finalize_nir and store that +information in shader_info::*inlinable_uniform*. When the state tracker +or frontend uploads constants to a constant buffer, it can pass +inlinable constants separately via this call. + +Any ``set_constant_buffer`` call invalidates inlinable constants, so +``set_inlinable_constants`` must be called after it. Binding a shader also +invalidates this state. + +There is no ``PIPE_CAP`` for this. Drivers shouldn't set the shader_info +fields if they don't implement ``set_inlinable_constants``. + * ``set_framebuffer_state`` * ``set_vertex_buffers`` diff --git a/src/gallium/auxiliary/driver_noop/noop_state.c b/src/gallium/auxiliary/driver_noop/noop_state.c index 2ab18b55255..056d4be6b19 100644 --- a/src/gallium/auxiliary/driver_noop/noop_state.c +++ b/src/gallium/auxiliary/driver_noop/noop_state.c @@ -166,6 +166,12 @@ static void noop_set_constant_buffer(struct pipe_context *ctx, { } +static void noop_set_inlinable_constants(struct pipe_context *ctx, + enum pipe_shader_type shader, + uint num_values, uint32_t *values) +{ +} + static void noop_sampler_view_destroy(struct pipe_context *ctx, struct pipe_sampler_view *state) @@ -296,6 +302,7 @@ void noop_init_state_functions(struct pipe_context *ctx) ctx->set_blend_color = noop_set_blend_color; ctx->set_clip_state = noop_set_clip_state; ctx->set_constant_buffer = noop_set_constant_buffer; + ctx->set_inlinable_constants = noop_set_inlinable_constants; ctx->set_sampler_views = noop_set_sampler_views; ctx->set_framebuffer_state = noop_set_framebuffer_state; ctx->set_polygon_stipple = noop_set_polygon_stipple; diff --git a/src/gallium/auxiliary/util/u_threaded_context.c b/src/gallium/auxiliary/util/u_threaded_context.c index 5b2968b9855..f9d22c3bcb9 100644 --- a/src/gallium/auxiliary/util/u_threaded_context.c +++ b/src/gallium/auxiliary/util/u_threaded_context.c @@ -30,6 +30,7 @@ #include "util/u_inlines.h" #include "util/u_memory.h" #include "util/u_upload_mgr.h" +#include "compiler/shader_info.h" /* 0 = disabled, 1 = assertions, 2 = printfs */ #define TC_DEBUG 0 @@ -705,6 +706,34 @@ tc_set_constant_buffer(struct pipe_context *_pipe, } } +struct tc_inlinable_constants { + ubyte shader; + ubyte num_values; + uint32_t values[MAX_INLINABLE_UNIFORMS]; +}; + +static void +tc_call_set_inlinable_constants(struct pipe_context *pipe, union tc_payload *payload) +{ + struct tc_inlinable_constants *p = (struct tc_inlinable_constants *)payload; + + pipe->set_inlinable_constants(pipe, p->shader, p->num_values, p->values); +} + +static void +tc_set_inlinable_constants(struct pipe_context *_pipe, + enum pipe_shader_type shader, + uint num_values, uint32_t *values) +{ + struct threaded_context *tc = threaded_context(_pipe); + struct tc_inlinable_constants *p = + tc_add_struct_typed_call(tc, TC_CALL_set_inlinable_constants, + tc_inlinable_constants); + p->shader = shader; + p->num_values = num_values; + memcpy(p->values, values, num_values * 4); +} + struct tc_scissors { ubyte start, count; struct pipe_scissor_state slot[0]; /* more will be allocated if needed */ @@ -2750,6 +2779,7 @@ threaded_context_create(struct pipe_context *pipe, CTX_INIT(set_min_samples); CTX_INIT(set_clip_state); CTX_INIT(set_constant_buffer); + CTX_INIT(set_inlinable_constants); CTX_INIT(set_framebuffer_state); CTX_INIT(set_polygon_stipple); CTX_INIT(set_scissor_states); diff --git a/src/gallium/auxiliary/util/u_threaded_context_calls.h b/src/gallium/auxiliary/util/u_threaded_context_calls.h index c7a12df2c37..3bd43d9803a 100644 --- a/src/gallium/auxiliary/util/u_threaded_context_calls.h +++ b/src/gallium/auxiliary/util/u_threaded_context_calls.h @@ -11,6 +11,7 @@ CALL(bind_sampler_states) CALL(set_framebuffer_state) CALL(set_tess_state) CALL(set_constant_buffer) +CALL(set_inlinable_constants) CALL(set_scissor_states) CALL(set_viewport_states) CALL(set_window_rectangles) diff --git a/src/gallium/include/pipe/p_context.h b/src/gallium/include/pipe/p_context.h index 9553636ac02..d7fa3156b6c 100644 --- a/src/gallium/include/pipe/p_context.h +++ b/src/gallium/include/pipe/p_context.h @@ -320,6 +320,26 @@ struct pipe_context { enum pipe_shader_type shader, uint index, const struct pipe_constant_buffer *buf ); + /** + * Set inlinable constants for constant buffer 0. + * + * These are constants that the driver would like to inline in the IR + * of the current shader and recompile it. Drivers can determine which + * constants they prefer to inline in finalize_nir and store that + * information in shader_info::*inlinable_uniform*. When the state tracker + * or frontend uploads constants to a constant buffer, it can pass + * inlinable constants separately via this call. + * + * Any set_constant_buffer call invalidates this state, so this function + * must be called after it. Binding a shader also invalidates this state. + * + * There is no PIPE_CAP for this. Drivers shouldn't set the shader_info + * fields if they don't want this or if they don't implement this. + */ + void (*set_inlinable_constants)( struct pipe_context *, + enum pipe_shader_type shader, + uint num_values, uint32_t *values ); + void (*set_framebuffer_state)( struct pipe_context *, const struct pipe_framebuffer_state * );