diff options
author | Jason Ekstrand <[email protected]> | 2017-09-28 16:25:31 -0700 |
---|---|---|
committer | Jason Ekstrand <[email protected]> | 2017-10-12 22:39:29 -0700 |
commit | 2975e4c56a7aeade5a324aa4d446f18cc176fa06 (patch) | |
tree | f08787f03d0781b1d7823095acabf3e86d5522ec /src/intel/vulkan | |
parent | faad828b16448c1008a1b15ac8d8a72b13005c09 (diff) |
intel: Rewrite the world of push/pull params
This moves us away to the array of pointers model and onto a model where
each param is represented by a generic uint32_t handle. We reserve 2^16
of these handles for builtins that get generated by somewhere inside the
compiler and have well-defined meanings. Generic params have handles
whose meanings are defined by the driver.
The primary downside to this new approach is that it moves a little bit
of the work that we would normally do at compile time to draw time. On
my laptop this hurts OglBatch6 by no more than 1% and doesn't seem to
have any measurable affect on OglBatch7. So, while this may come back
to bite us, it doesn't look too bad.
Reviewed-by: Jordan Justen <[email protected]>
Reviewed-by: Kenneth Graunke <[email protected]>
Diffstat (limited to 'src/intel/vulkan')
-rw-r--r-- | src/intel/vulkan/anv_cmd_buffer.c | 33 | ||||
-rw-r--r-- | src/intel/vulkan/anv_nir_apply_pipeline_layout.c | 25 | ||||
-rw-r--r-- | src/intel/vulkan/anv_pipeline.c | 9 | ||||
-rw-r--r-- | src/intel/vulkan/anv_private.h | 3 |
4 files changed, 42 insertions, 28 deletions
diff --git a/src/intel/vulkan/anv_cmd_buffer.c b/src/intel/vulkan/anv_cmd_buffer.c index 5eec67cb607..64d1417f5b1 100644 --- a/src/intel/vulkan/anv_cmd_buffer.c +++ b/src/intel/vulkan/anv_cmd_buffer.c @@ -629,6 +629,26 @@ anv_cmd_buffer_merge_dynamic(struct anv_cmd_buffer *cmd_buffer, return state; } +static uint32_t +anv_push_constant_value(struct anv_push_constants *data, uint32_t param) +{ + if (BRW_PARAM_IS_BUILTIN(param)) { + switch (param) { + case BRW_PARAM_BUILTIN_ZERO: + return 0; + default: + unreachable("Invalid param builtin"); + } + } else { + uint32_t offset = ANV_PARAM_PUSH_OFFSET(param); + assert(offset % sizeof(uint32_t) == 0); + if (offset < data->size) + return *(uint32_t *)((uint8_t *)data + offset); + else + return 0; + } +} + struct anv_state anv_cmd_buffer_push_constants(struct anv_cmd_buffer *cmd_buffer, gl_shader_stage stage) @@ -653,10 +673,8 @@ anv_cmd_buffer_push_constants(struct anv_cmd_buffer *cmd_buffer, /* Walk through the param array and fill the buffer with data */ uint32_t *u32_map = state.map; - for (unsigned i = 0; i < prog_data->nr_params; i++) { - uint32_t offset = (uintptr_t)prog_data->param[i]; - u32_map[i] = *(uint32_t *)((uint8_t *)data + offset); - } + for (unsigned i = 0; i < prog_data->nr_params; i++) + u32_map[i] = anv_push_constant_value(data, prog_data->param[i]); anv_state_flush(cmd_buffer->device, state); @@ -695,8 +713,7 @@ anv_cmd_buffer_cs_push_constants(struct anv_cmd_buffer *cmd_buffer) for (unsigned i = 0; i < cs_prog_data->push.cross_thread.dwords; i++) { - uint32_t offset = (uintptr_t)prog_data->param[i]; - u32_map[i] = *(uint32_t *)((uint8_t *)data + offset); + u32_map[i] = anv_push_constant_value(data, prog_data->param[i]); } } @@ -708,8 +725,8 @@ anv_cmd_buffer_cs_push_constants(struct anv_cmd_buffer *cmd_buffer) unsigned src = cs_prog_data->push.cross_thread.dwords; for ( ; src < prog_data->nr_params; src++, dst++) { if (src != cs_prog_data->thread_local_id_index) { - uint32_t offset = (uintptr_t)prog_data->param[src]; - u32_map[dst] = *(uint32_t *)((uint8_t *)data + offset); + u32_map[dst] = + anv_push_constant_value(data, prog_data->param[src]); } else { u32_map[dst] = t * cs_prog_data->simd_size; } diff --git a/src/intel/vulkan/anv_nir_apply_pipeline_layout.c b/src/intel/vulkan/anv_nir_apply_pipeline_layout.c index a35687379c8..f5a274d1a53 100644 --- a/src/intel/vulkan/anv_nir_apply_pipeline_layout.c +++ b/src/intel/vulkan/anv_nir_apply_pipeline_layout.c @@ -304,17 +304,13 @@ apply_pipeline_layout_block(nir_block *block, } static void -setup_vec4_uniform_value(const union gl_constant_value **params, - const union gl_constant_value *values, - unsigned n) +setup_vec4_uniform_value(uint32_t *params, uint32_t offset, unsigned n) { - static const gl_constant_value zero = { 0 }; - for (unsigned i = 0; i < n; ++i) - params[i] = &values[i]; + params[i] = ANV_PARAM_PUSH(offset + i * sizeof(uint32_t)); for (unsigned i = n; i < 4; ++i) - params[i] = &zero; + params[i] = BRW_PARAM_BUILTIN_ZERO; } void @@ -478,22 +474,21 @@ anv_nir_apply_pipeline_layout(struct anv_pipeline *pipeline, } struct anv_push_constants *null_data = NULL; - const gl_constant_value **param = - prog_data->param + (shader->num_uniforms / 4); + uint32_t *param = prog_data->param + (shader->num_uniforms / 4); const struct brw_image_param *image_param = null_data->images; for (uint32_t i = 0; i < map->image_count; i++) { setup_vec4_uniform_value(param + BRW_IMAGE_PARAM_SURFACE_IDX_OFFSET, - (const union gl_constant_value *)&image_param->surface_idx, 1); + (uintptr_t)&image_param->surface_idx, 1); setup_vec4_uniform_value(param + BRW_IMAGE_PARAM_OFFSET_OFFSET, - (const union gl_constant_value *)image_param->offset, 2); + (uintptr_t)image_param->offset, 2); setup_vec4_uniform_value(param + BRW_IMAGE_PARAM_SIZE_OFFSET, - (const union gl_constant_value *)image_param->size, 3); + (uintptr_t)image_param->size, 3); setup_vec4_uniform_value(param + BRW_IMAGE_PARAM_STRIDE_OFFSET, - (const union gl_constant_value *)image_param->stride, 4); + (uintptr_t)image_param->stride, 4); setup_vec4_uniform_value(param + BRW_IMAGE_PARAM_TILING_OFFSET, - (const union gl_constant_value *)image_param->tiling, 3); + (uintptr_t)image_param->tiling, 3); setup_vec4_uniform_value(param + BRW_IMAGE_PARAM_SWIZZLING_OFFSET, - (const union gl_constant_value *)image_param->swizzling, 2); + (uintptr_t)image_param->swizzling, 2); param += BRW_IMAGE_PARAM_SIZE; image_param ++; diff --git a/src/intel/vulkan/anv_pipeline.c b/src/intel/vulkan/anv_pipeline.c index 3db9b9a6246..e6a7393a3d3 100644 --- a/src/intel/vulkan/anv_pipeline.c +++ b/src/intel/vulkan/anv_pipeline.c @@ -415,8 +415,7 @@ anv_pipeline_compile(struct anv_pipeline *pipeline, if (prog_data->nr_params > 0) { /* XXX: I think we're leaking this */ - prog_data->param = (const union gl_constant_value **) - malloc(prog_data->nr_params * sizeof(union gl_constant_value *)); + prog_data->param = malloc(prog_data->nr_params * sizeof(uint32_t)); /* We now set the param values to be offsets into a * anv_push_constant_data structure. Since the compiler doesn't @@ -427,8 +426,8 @@ anv_pipeline_compile(struct anv_pipeline *pipeline, if (nir->num_uniforms > 0) { /* Fill out the push constants section of the param array */ for (unsigned i = 0; i < MAX_PUSH_CONSTANTS_SIZE / sizeof(float); i++) - prog_data->param[i] = (const union gl_constant_value *) - &null_data->client_data[i * sizeof(float)]; + prog_data->param[i] = ANV_PARAM_PUSH( + (uintptr_t)&null_data->client_data[i * sizeof(float)]); } } @@ -540,7 +539,7 @@ anv_pipeline_compile_vs(struct anv_pipeline *pipeline, unsigned code_size; const unsigned *shader_code = brw_compile_vs(compiler, NULL, mem_ctx, &key, &prog_data, nir, - NULL, false, -1, &code_size, NULL); + false, -1, &code_size, NULL); if (shader_code == NULL) { ralloc_free(mem_ctx); return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h index b33370c3da1..abc278b40b7 100644 --- a/src/intel/vulkan/anv_private.h +++ b/src/intel/vulkan/anv_private.h @@ -1567,6 +1567,9 @@ struct anv_vertex_binding { VkDeviceSize offset; }; +#define ANV_PARAM_PUSH(offset) ((1 << 16) | (uint32_t)(offset)) +#define ANV_PARAM_PUSH_OFFSET(param) ((param) & 0xffff) + struct anv_push_constants { /* Current allocated size of this push constants data structure. * Because a decent chunk of it may not be used (images on SKL, for |