[Mesa-dev] [PATCH 49/68] i965: add image param shader cache support
Timothy Arceri
timothy.arceri at collabora.com
Wed Jun 1 06:23:30 UTC 2016
---
src/mesa/drivers/dri/i965/brw_shader_cache.c | 60 +++++++++++++++++++++++++---
1 file changed, 55 insertions(+), 5 deletions(-)
diff --git a/src/mesa/drivers/dri/i965/brw_shader_cache.c b/src/mesa/drivers/dri/i965/brw_shader_cache.c
index 7945b16..850e1e8 100644
--- a/src/mesa/drivers/dri/i965/brw_shader_cache.c
+++ b/src/mesa/drivers/dri/i965/brw_shader_cache.c
@@ -28,6 +28,7 @@
#include <compiler/glsl/ir_uniform.h>
#include <compiler/glsl/cache.h>
#include <compiler/glsl/blob.h>
+#include <compiler/nir_types.h>
#include "brw_state.h"
#include "brw_wm.h"
@@ -56,7 +57,8 @@ upload_cached_program(struct brw_context *brw)
size_t vs_prog_data_size, wm_prog_data_size;
intptr_t parameter_values_base;
intptr_t uniform_data_slots_base;
- uint32_t nr_params, nr_pull_params;
+ intptr_t image_params_base;
+ uint32_t nr_params, nr_pull_params, nr_image_params;
cache = brw->ctx.Cache;
if (cache == NULL)
@@ -121,9 +123,31 @@ upload_cached_program(struct brw_context *brw)
printf("Allocating %d prog_data->params (%p)\n",
prog_data->nr_params, prog_data->param);
+ nr_image_params = blob_read_uint32(&binary);
+ assert(nr_image_params == prog_data->nr_image_params);
+
+ prog_data->image_param = rzalloc_array(NULL, struct brw_image_param,
+ nr_image_params);
+
+ image_params_base = blob_read_intptr(&binary);
+
+ /* calculate image bounds */
+ unsigned image_upper_boundary = 0;
+ for (unsigned u = 0; u < prog->NumUniformStorage; u++) {
+ struct gl_uniform_storage *storage = &prog->UniformStorage[u];
+
+ if (storage->builtin)
+ continue;
+
+ if (glsl_get_base_type(storage->type) == GLSL_TYPE_IMAGE) {
+ image_upper_boundary +=
+ BRW_IMAGE_PARAM_SIZE * MAX2(storage->array_elements, 1);
+ }
+ }
+
for (i = 0; i < nr_params; i++) {
intptr_t param = blob_read_intptr(&binary);
- ptrdiff_t p_offset, u_offset;
+ ptrdiff_t p_offset, u_offset, i_offset;
struct gl_program_parameter_list *param_list =
prog->_LinkedShaders[MESA_SHADER_VERTEX] ?
prog->_LinkedShaders[MESA_SHADER_VERTEX]->Program->Parameters :
@@ -131,6 +155,7 @@ upload_cached_program(struct brw_context *brw)
p_offset = (param - parameter_values_base) / sizeof(gl_constant_value);
u_offset = (param - uniform_data_slots_base) / sizeof(gl_constant_value);
+ i_offset = (param - image_params_base) / sizeof(gl_constant_value);
if (param_list && p_offset >= 0 &&
p_offset < 4 * param_list->NumParameters) {
@@ -138,6 +163,9 @@ upload_cached_program(struct brw_context *brw)
((gl_constant_value *) param_list->ParameterValues) + p_offset;
} else if (u_offset >= 0 && u_offset < prog->NumUniformDataSlots) {
prog_data->param[i] = prog->UniformDataSlots + u_offset;
+ } else if (i_offset >= 0 && i_offset < image_upper_boundary) {
+ prog_data->param[i] =
+ ((gl_constant_value *) prog_data->image_param) + i_offset;
} else {
printf("Error: Failed to fixup vs pointer value %p\n", (void *) param);
ralloc_free(prog_data->param);
@@ -160,6 +188,7 @@ upload_cached_program(struct brw_context *brw)
struct brw_vertex_program *vp =
(struct brw_vertex_program *)brw->vertex_program;
+
brw_upload_cache(&brw->cache, BRW_CACHE_VS_PROG,
&vs_key, sizeof(struct brw_vs_prog_key),
vs_program, vs_program_size,
@@ -188,9 +217,17 @@ upload_cached_program(struct brw_context *brw)
printf("Allocating %d prog_data->params (%p)\n",
prog_data->nr_params, prog_data->param);
+ nr_image_params = blob_read_uint32(&binary);
+ assert(nr_image_params == prog_data->nr_image_params);
+
+ prog_data->image_param = rzalloc_array(NULL, struct brw_image_param,
+ nr_image_params);
+
+ image_params_base = blob_read_intptr(&binary);
+
for (i = 0; i < nr_params; i++) {
intptr_t param = blob_read_intptr(&binary);
- ptrdiff_t p_offset, u_offset;
+ ptrdiff_t p_offset, u_offset, i_offset;
struct gl_program_parameter_list *param_list =
prog->_LinkedShaders[MESA_SHADER_FRAGMENT] ?
prog->_LinkedShaders[MESA_SHADER_FRAGMENT]->Program->Parameters :
@@ -198,6 +235,7 @@ upload_cached_program(struct brw_context *brw)
p_offset = (param - parameter_values_base) / sizeof(gl_constant_value);
u_offset = (param - uniform_data_slots_base) / sizeof(gl_constant_value);
+ i_offset = (param - image_params_base) / sizeof(gl_constant_value);
if (param_list && p_offset >= 0 &&
p_offset < 4 * param_list->NumParameters) {
@@ -205,6 +243,9 @@ upload_cached_program(struct brw_context *brw)
((gl_constant_value *) param_list->ParameterValues) + p_offset;
} else if (u_offset >= 0 && u_offset < prog->NumUniformDataSlots) {
prog_data->param[i] = prog->UniformDataSlots + u_offset;
+ } else if (i_offset >= 0 && i_offset < image_upper_boundary) {
+ prog_data->param[i] =
+ ((gl_constant_value *) prog_data->image_param) + i_offset;
} else {
printf("Error: Failed to fixup fs pointer value %p\n", (void *) param);
ralloc_free(prog_data->param);
@@ -219,7 +260,6 @@ upload_cached_program(struct brw_context *brw)
prog_data->pull_param = rzalloc_array(NULL, const gl_constant_value *,
nr_pull_params);
-
for (i = 0; i < nr_pull_params; i++) {
intptr_t pull_param = blob_read_intptr(&binary);
/* FIXME: We need to fixup pull_params pointers here. */
@@ -227,6 +267,7 @@ upload_cached_program(struct brw_context *brw)
struct brw_fragment_program *wp =
(struct brw_fragment_program *)brw->fragment_program;
+
brw_upload_cache(&brw->cache, BRW_CACHE_FS_PROG,
&wm_key, sizeof(struct brw_wm_prog_key),
wm_program, wm_program_size,
@@ -258,7 +299,7 @@ write_cached_program(struct brw_context *brw)
struct blob *binary;
uint8_t *blob_cursor;
size_t vs_program_size, wm_program_size;
- uint32_t nr_params, nr_pull_params;
+ uint32_t nr_params, nr_pull_params, nr_image_params;
struct gl_shader_program *prog;
struct program_cache *cache;
char buf[41];
@@ -314,6 +355,11 @@ write_cached_program(struct brw_context *brw)
nr_params = brw->vs.prog_data->base.base.nr_params;
blob_write_uint32(binary, nr_params);
+ nr_image_params = brw->vs.prog_data->base.base.nr_image_params;
+ blob_write_uint32(binary, nr_image_params);
+ blob_write_intptr(binary,
+ (intptr_t) brw->vs.prog_data->base.base.image_param);
+
for (i = 0; i < nr_params; i++) {
blob_write_intptr(binary,
(intptr_t) brw->vs.prog_data->base.base.param[i]);
@@ -354,6 +400,10 @@ write_cached_program(struct brw_context *brw)
nr_params = brw->wm.prog_data->base.nr_params;
blob_write_uint32(binary, nr_params);
+ nr_image_params = brw->wm.prog_data->base.nr_image_params;
+ blob_write_uint32(binary, nr_image_params);
+ blob_write_intptr(binary, (intptr_t) brw->wm.prog_data->base.image_param);
+
for (i = 0; i < nr_params; i++) {
blob_write_intptr(binary,
(intptr_t) brw->wm.prog_data->base.param[i]);
--
2.5.5
More information about the mesa-dev
mailing list