From d395485e1df44853cdf86b0bd46b7af36c7e1c13 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Thu, 3 Oct 2013 09:55:06 -0700 Subject: [PATCH] i965/vec4: Dynamically assign the VS/GS binding table offsets. Note that the dropped comment in brw_context.h is mostly (better written) in brw_binding_table.c as well. Reviewed-by: Paul Berry --- src/mesa/drivers/dri/i965/brw_context.h | 51 ------------------- src/mesa/drivers/dri/i965/brw_vec4.cpp | 29 +++++++++-- .../drivers/dri/i965/brw_vec4_generator.cpp | 2 +- 3 files changed, 25 insertions(+), 57 deletions(-) diff --git a/src/mesa/drivers/dri/i965/brw_context.h b/src/mesa/drivers/dri/i965/brw_context.h index 4e26460267b..68a78678565 100644 --- a/src/mesa/drivers/dri/i965/brw_context.h +++ b/src/mesa/drivers/dri/i965/brw_context.h @@ -678,62 +678,11 @@ struct brw_gs_prog_data /** Maximum number of actual buffers used for stream output */ #define BRW_MAX_SOL_BUFFERS 4 -/** - * Helpers to create Surface Binding Table indexes for draw buffers, - * textures, and constant buffers. - * - * Shader threads access surfaces via numeric handles, rather than directly - * using pointers. The binding table maps these numeric handles to the - * address of the actual buffer. - * - * For example, a shader might ask to sample from "surface 7." In this case, - * bind[7] would contain a pointer to a texture. - * - * - * Our VS (and Gen7 GS) binding tables are programmed as follows: - * - * +-----+-------------------------+ - * | 0 | Pull Constant Buffer | - * +-----+-------------------------+ - * | 1 | Texture 0 | - * | . | . | - * | : | : | - * | 16 | Texture 15 | - * +-----+-------------------------+ - * | 17 | UBO 0 | - * | . | . | - * | : | : | - * | 28 | UBO 11 | - * |-----|-------------------------| - * | 29 | Shader time buffer | - * |-----|-------------------------| - * | 30 | Gather texture 0 | - * | . | . | - * | : | : | - * | 45 | Gather texture 15 | - * +-------------------------------+ - * - * Our (gen6) GS binding tables are programmed as follows: - * - * +-----+-------------------------+ - * | 0 | SOL Binding 0 | - * | . | . | - * | : | : | - * | 63 | SOL Binding 63 | - * +-----+-------------------------+ - */ #define BRW_MAX_SURFACES (BRW_MAX_DRAW_BUFFERS + \ BRW_MAX_TEX_UNIT * 2 + /* normal, gather */ \ 12 + /* ubo */ \ 2 /* shader time, pull constants */) -#define SURF_INDEX_VEC4_CONST_BUFFER (0) -#define SURF_INDEX_VEC4_TEXTURE(t) (SURF_INDEX_VEC4_CONST_BUFFER + 1 + (t)) -#define SURF_INDEX_VEC4_UBO(u) (SURF_INDEX_VEC4_TEXTURE(BRW_MAX_TEX_UNIT) + u) -#define SURF_INDEX_VEC4_SHADER_TIME (SURF_INDEX_VEC4_UBO(12)) -#define SURF_INDEX_VEC4_GATHER_TEXTURE(t) (SURF_INDEX_VEC4_SHADER_TIME + 1 + (t)) -#define BRW_MAX_VEC4_SURFACES (SURF_INDEX_VEC4_GATHER_TEXTURE(BRW_MAX_TEX_UNIT)) - #define SURF_INDEX_GEN6_SOL_BINDING(t) (t) #define BRW_MAX_GEN6_GS_SURFACES SURF_INDEX_GEN6_SOL_BINDING(BRW_MAX_SOL_BINDINGS) diff --git a/src/mesa/drivers/dri/i965/brw_vec4.cpp b/src/mesa/drivers/dri/i965/brw_vec4.cpp index 14ba251d4fb..6689a3d3c01 100644 --- a/src/mesa/drivers/dri/i965/brw_vec4.cpp +++ b/src/mesa/drivers/dri/i965/brw_vec4.cpp @@ -1424,11 +1424,30 @@ vec4_visitor::emit_shader_time_write(enum shader_time_shader_type type, void vec4_visitor::assign_binding_table_offsets() { - prog_data->base.binding_table.texture_start = SURF_INDEX_VEC4_TEXTURE(0); - prog_data->base.binding_table.ubo_start = SURF_INDEX_VEC4_UBO(0); - prog_data->base.binding_table.shader_time_start = SURF_INDEX_VEC4_SHADER_TIME; - prog_data->base.binding_table.gather_texture_start = SURF_INDEX_VEC4_GATHER_TEXTURE(0); - prog_data->base.binding_table.pull_constants_start = SURF_INDEX_VEC4_CONST_BUFFER; + int num_textures = _mesa_fls(prog->SamplersUsed); + int next = 0; + + prog_data->base.binding_table.texture_start = next; + next += num_textures; + + if (shader) { + prog_data->base.binding_table.ubo_start = next; + next += shader->base.NumUniformBlocks; + } + + if (INTEL_DEBUG & DEBUG_SHADER_TIME) { + prog_data->base.binding_table.shader_time_start = next; + next++; + } + + if (prog->UsesGather) { + prog_data->base.binding_table.gather_texture_start = next; + next += num_textures; + } + + /* This may or may not be used depending on how the compile goes. */ + prog_data->base.binding_table.pull_constants_start = next; + next++; /* prog_data->base.binding_table.size will be set by mark_surface_used. */ } diff --git a/src/mesa/drivers/dri/i965/brw_vec4_generator.cpp b/src/mesa/drivers/dri/i965/brw_vec4_generator.cpp index ca5ac722bee..1b597b55861 100644 --- a/src/mesa/drivers/dri/i965/brw_vec4_generator.cpp +++ b/src/mesa/drivers/dri/i965/brw_vec4_generator.cpp @@ -155,7 +155,7 @@ vec4_generator::~vec4_generator() void vec4_generator::mark_surface_used(unsigned surf_index) { - assert(surf_index < BRW_MAX_VEC4_SURFACES); + assert(surf_index < BRW_MAX_SURFACES); prog_data->base.binding_table.size_bytes = MAX2(prog_data->base.binding_table.size_bytes, (surf_index + 1) * 4); -- 2.30.2