From 3e743d8cd86c09f68d840604c9df52e0499af64f Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Fri, 18 Jan 2019 15:36:15 -0800 Subject: [PATCH 1/1] v3d: Avoid duplicating limits defines between gallium and v3d core. We don't want to pull the compiler into every include in the gallium driver, so just make a new little header to store the limits. --- src/broadcom/Makefile.sources | 1 + src/broadcom/common/v3d_limits.h | 41 +++++++++++++++++++++++++++ src/broadcom/compiler/v3d_compiler.h | 6 +--- src/gallium/drivers/v3d/v3d_context.c | 1 + src/gallium/drivers/v3d/v3d_context.h | 5 ++-- src/gallium/drivers/v3d/v3d_screen.c | 2 +- src/gallium/drivers/v3d/v3d_screen.h | 6 ---- src/gallium/drivers/v3d/v3dx_draw.c | 2 +- src/gallium/drivers/v3d/v3dx_state.c | 5 ++-- 9 files changed, 52 insertions(+), 17 deletions(-) create mode 100644 src/broadcom/common/v3d_limits.h diff --git a/src/broadcom/Makefile.sources b/src/broadcom/Makefile.sources index f8710c49752..6cec9b81cb1 100644 --- a/src/broadcom/Makefile.sources +++ b/src/broadcom/Makefile.sources @@ -21,6 +21,7 @@ BROADCOM_FILES = \ common/v3d_debug.c \ common/v3d_debug.h \ common/v3d_device_info.h \ + common/v3d_limits.h \ common/v3d_macros.h \ compiler/nir_to_vir.c \ compiler/vir.c \ diff --git a/src/broadcom/common/v3d_limits.h b/src/broadcom/common/v3d_limits.h new file mode 100644 index 00000000000..367806dbe48 --- /dev/null +++ b/src/broadcom/common/v3d_limits.h @@ -0,0 +1,41 @@ +/* + * Copyright © 2019 Broadcom + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#ifndef V3D_LIMITS_H +#define V3D_LIMITS_H + +#define V3D_MAX_FS_INPUTS 64 +#define V3D_MAX_VS_INPUTS 64 + +/* Not specifically a hardware limit, just coordination between compiler and + * driver. + */ +#define V3D_MAX_TEXTURE_SAMPLERS 32 + +#define V3D_MAX_MIP_LEVELS 12 + +#define V3D_MAX_SAMPLES 4 + +#define V3D_MAX_DRAW_BUFFERS 4 + +#endif /* V3D_LIMITS_H */ diff --git a/src/broadcom/compiler/v3d_compiler.h b/src/broadcom/compiler/v3d_compiler.h index a613146d927..127b04136d1 100644 --- a/src/broadcom/compiler/v3d_compiler.h +++ b/src/broadcom/compiler/v3d_compiler.h @@ -34,6 +34,7 @@ #include "util/macros.h" #include "common/v3d_debug.h" #include "common/v3d_device_info.h" +#include "common/v3d_limits.h" #include "compiler/nir/nir.h" #include "util/list.h" #include "util/u_math.h" @@ -41,11 +42,6 @@ #include "qpu/qpu_instr.h" #include "pipe/p_state.h" -#define V3D_MAX_TEXTURE_SAMPLERS 32 -#define V3D_MAX_SAMPLES 4 -#define V3D_MAX_FS_INPUTS 64 -#define V3D_MAX_VS_INPUTS 64 - struct nir_builder; struct v3d_fs_inputs { diff --git a/src/gallium/drivers/v3d/v3d_context.c b/src/gallium/drivers/v3d/v3d_context.c index 7e9bc3d22db..d07ad403590 100644 --- a/src/gallium/drivers/v3d/v3d_context.c +++ b/src/gallium/drivers/v3d/v3d_context.c @@ -37,6 +37,7 @@ #include "v3d_screen.h" #include "v3d_context.h" #include "v3d_resource.h" +#include "broadcom/compiler/v3d_compiler.h" void v3d_flush(struct pipe_context *pctx) diff --git a/src/gallium/drivers/v3d/v3d_context.h b/src/gallium/drivers/v3d/v3d_context.h index 2ced7c8aa31..3ec4940b648 100644 --- a/src/gallium/drivers/v3d/v3d_context.h +++ b/src/gallium/drivers/v3d/v3d_context.h @@ -38,6 +38,7 @@ #include "xf86drm.h" #include "v3d_drm.h" #include "v3d_screen.h" +#include "broadcom/common/v3d_limits.h" struct v3d_job; struct v3d_bo; @@ -190,10 +191,10 @@ struct v3d_vertexbuf_stateobj { }; struct v3d_vertex_stateobj { - struct pipe_vertex_element pipe[V3D_MAX_ATTRIBUTES]; + struct pipe_vertex_element pipe[V3D_MAX_VS_INPUTS / 4]; unsigned num_elements; - uint8_t attrs[16 * V3D_MAX_ATTRIBUTES]; + uint8_t attrs[16 * (V3D_MAX_VS_INPUTS / 4)]; struct pipe_resource *defaults; uint32_t defaults_offset; }; diff --git a/src/gallium/drivers/v3d/v3d_screen.c b/src/gallium/drivers/v3d/v3d_screen.c index 81392c9ff83..bed2c63a64d 100644 --- a/src/gallium/drivers/v3d/v3d_screen.c +++ b/src/gallium/drivers/v3d/v3d_screen.c @@ -262,7 +262,7 @@ v3d_screen_get_shader_param(struct pipe_screen *pscreen, unsigned shader, if (shader == PIPE_SHADER_FRAGMENT) return V3D_MAX_FS_INPUTS / 4; else - return V3D_MAX_ATTRIBUTES; + return V3D_MAX_VS_INPUTS / 4; case PIPE_SHADER_CAP_MAX_OUTPUTS: if (shader == PIPE_SHADER_FRAGMENT) return 4; diff --git a/src/gallium/drivers/v3d/v3d_screen.h b/src/gallium/drivers/v3d/v3d_screen.h index 0975da2032f..94ae8b30f3a 100644 --- a/src/gallium/drivers/v3d/v3d_screen.h +++ b/src/gallium/drivers/v3d/v3d_screen.h @@ -35,12 +35,6 @@ struct v3d_bo; -#define V3D_MAX_MIP_LEVELS 12 -#define V3D_MAX_TEXTURE_SAMPLERS 32 -#define V3D_MAX_SAMPLES 4 -#define V3D_MAX_DRAW_BUFFERS 4 -#define V3D_MAX_ATTRIBUTES 16 - /* These are tunable parameters in the HW design, but all the V3D * implementations agree. */ diff --git a/src/gallium/drivers/v3d/v3dx_draw.c b/src/gallium/drivers/v3d/v3dx_draw.c index 5ad4710876f..2700208e388 100644 --- a/src/gallium/drivers/v3d/v3dx_draw.c +++ b/src/gallium/drivers/v3d/v3dx_draw.c @@ -317,7 +317,7 @@ v3d_emit_gl_shader_state(struct v3d_context *v3d, attr.maximum_index = 0xffffff; #endif } - STATIC_ASSERT(sizeof(vtx->attrs) >= V3D_MAX_ATTRIBUTES * size); + STATIC_ASSERT(sizeof(vtx->attrs) >= V3D_MAX_VS_INPUTS / 4 * size); } if (vtx->num_elements == 0) { diff --git a/src/gallium/drivers/v3d/v3dx_state.c b/src/gallium/drivers/v3d/v3dx_state.c index b66569c25e7..47b7ad03cc3 100644 --- a/src/gallium/drivers/v3d/v3dx_state.c +++ b/src/gallium/drivers/v3d/v3dx_state.c @@ -35,6 +35,7 @@ #include "v3d_context.h" #include "v3d_tiling.h" #include "broadcom/common/v3d_macros.h" +#include "broadcom/compiler/v3d_compiler.h" #include "broadcom/cle/v3dx_pack.h" static void @@ -407,10 +408,10 @@ v3d_vertex_state_create(struct pipe_context *pctx, unsigned num_elements, */ uint32_t *attrs; u_upload_alloc(v3d->state_uploader, 0, - V3D_MAX_ATTRIBUTES * 4 * sizeof(float), 16, + V3D_MAX_VS_INPUTS * sizeof(float), 16, &so->defaults_offset, &so->defaults, (void **)&attrs); - for (int i = 0; i < V3D_MAX_ATTRIBUTES; i++) { + for (int i = 0; i < V3D_MAX_VS_INPUTS / 4; i++) { attrs[i * 4 + 0] = 0; attrs[i * 4 + 1] = 0; attrs[i * 4 + 2] = 0; -- 2.30.2