broadcom: move HW-dependant constants to v3d_device_info

Right now we have some HW-dependant constants that we are accessing
using the same mechanism that some hw-dependant functions, through a
macro (V3DV_X macro).

But this means that each time that we need to get those constant
values, we need to do a hw version check. Also, right now both the
macro and the defines with each HW value are duplicated on v3d and
v3dv. Also that macro is ugly and has a ugly name.

This commit moves those values to the already common v3d_device_info
structure.

Reviewed-by: Jose Maria Casanova Crespo <jmcasanova@igalia.com>
Reviewed-by: Iago Toral Quiroga <itoral@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29535>
This commit is contained in:
Alejandro Piñeiro
2024-06-04 10:01:58 +02:00
committed by Marge Bot
parent b0f3923d8a
commit 5eee101477
9 changed files with 44 additions and 89 deletions

View File

@@ -71,15 +71,22 @@ v3d_get_device_info(int fd, struct v3d_device_info* devinfo, v3d_ioctl_fun drm_i
devinfo->has_accumulators = devinfo->ver < 71;
switch (devinfo->ver) {
case 42:
case 71:
break;
default:
fprintf(stderr,
"V3D %d.%d not supported by this version of Mesa.\n",
devinfo->ver / 10,
devinfo->ver % 10);
return false;
case 42:
devinfo->clipper_xy_granularity = 256.0f;
devinfo->cle_readahead = 256u;
devinfo->cle_buffer_min_size = 4096u;
break;
case 71:
devinfo->clipper_xy_granularity = 64.0f;
devinfo->cle_readahead = 1024u;
devinfo->cle_buffer_min_size = 16384u;
break;
default:
fprintf(stderr,
"V3D %d.%d not supported by this version of Mesa.\n",
devinfo->ver / 10,
devinfo->ver % 10);
return false;
}
ret = drm_ioctl(fd, DRM_IOCTL_V3D_GET_PARAM, &hub_ident3);

View File

@@ -51,6 +51,20 @@ struct v3d_device_info {
/** If the hw has accumulator registers */
bool has_accumulators;
/** Granularity for the Clipper XY Scaling */
float clipper_xy_granularity;
/** The Control List Executor (CLE) pre-fetches V3D_CLE_READAHEAD
* bytes from the Control List buffer. The usage of these last bytes
* should be avoided or the CLE would pre-fetch the data after the
* end of the CL buffer, reporting the kernel "MMU error from client
* CLE".
*/
uint32_t cle_readahead;
/** Minimum size for a buffer storing the Control List Executor (CLE) */
uint32_t cle_buffer_min_size;
};
typedef int (*v3d_ioctl_fun)(int fd, unsigned long request, void *arg);

View File

@@ -31,16 +31,6 @@
#include "broadcom/common/v3d_macros.h"
#include "broadcom/cle/v3dx_pack.h"
/* The Control List Executor (CLE) pre-fetches V3D_CLE_READAHEAD bytes from
* the Control List buffer. The usage of these last bytes should be avoided or
* the CLE would pre-fetch the data after the end of the CL buffer, reporting
* the kernel "MMU error from client CLE".
*/
#define V3D42_CLE_READAHEAD 256u
#define V3D42_CLE_BUFFER_MIN_SIZE 4096u
#define V3D71_CLE_READAHEAD 1024u
#define V3D71_CLE_BUFFER_MIN_SIZE 16384u
void
v3dv_cl_init(struct v3dv_job *job, struct v3dv_cl *cl)
{
@@ -83,8 +73,9 @@ cl_alloc_bo(struct v3dv_cl *cl, uint32_t space, enum
* calling cl_submit to use this reserved space.
*/
uint32_t unusable_space = 0;
uint32_t cle_readahead = V3DV_X(cl->job->device, CLE_READAHEAD);
uint32_t cle_buffer_min_size = V3DV_X(cl->job->device, CLE_BUFFER_MIN_SIZE);
struct v3d_device_info *devinfo = &cl->job->device->devinfo;
uint32_t cle_readahead = devinfo->cle_readahead;
uint32_t cle_buffer_min_size = devinfo->cle_buffer_min_size;
switch (chain_type) {
case V3D_CL_BO_CHAIN_WITH_BRANCH:
unusable_space = cle_readahead + cl_packet_length(BRANCH);

View File

@@ -2627,24 +2627,6 @@ u64_compare(const void *key1, const void *key2)
v3d_X_thing; \
})
/* Helper to get hw-specific macro values */
#define V3DV_X(device, thing) ({ \
__typeof(V3D42_##thing) V3D_X_THING; \
switch (device->devinfo.ver) { \
case 42: \
V3D_X_THING = V3D42_##thing; \
break; \
case 71: \
V3D_X_THING = V3D71_##thing; \
break; \
default: \
unreachable("Unsupported hardware generation"); \
} \
V3D_X_THING; \
})
/* v3d_macros from common requires v3dX and V3DX definitions. Below we need to
* define v3dX for each version supported, because when we compile code that
* is not version-specific, all version-specific macros need to be already

View File

@@ -468,6 +468,7 @@ v3dv_write_uniforms_wg_offsets(struct v3dv_cmd_buffer *cmd_buffer,
struct v3dv_job *job = cmd_buffer->state.job;
assert(job);
assert(job->cmd_buffer == cmd_buffer);
struct v3d_device_info *devinfo = &cmd_buffer->device->devinfo;
struct texture_bo_list tex_bos = { 0 };
struct state_bo_list state_bos = { 0 };
@@ -508,14 +509,14 @@ v3dv_write_uniforms_wg_offsets(struct v3dv_cmd_buffer *cmd_buffer,
break;
case QUNIFORM_VIEWPORT_X_SCALE: {
float clipper_xy_granularity = V3DV_X(cmd_buffer->device, CLIPPER_XY_GRANULARITY);
cl_aligned_f(&uniforms, dynamic->viewport.scale[0][0] * clipper_xy_granularity);
cl_aligned_f(&uniforms, dynamic->viewport.scale[0][0] *
devinfo->clipper_xy_granularity);
break;
}
case QUNIFORM_VIEWPORT_Y_SCALE: {
float clipper_xy_granularity = V3DV_X(cmd_buffer->device, CLIPPER_XY_GRANULARITY);
cl_aligned_f(&uniforms, dynamic->viewport.scale[0][1] * clipper_xy_granularity);
cl_aligned_f(&uniforms, dynamic->viewport.scale[0][1] *
devinfo->clipper_xy_granularity);
break;
}

View File

@@ -361,9 +361,6 @@ uint32_t
v3dX(clamp_for_format_and_type)(uint32_t rt_type,
VkFormat vk_format);
#define V3D42_CLIPPER_XY_GRANULARITY 256.0f
#define V3D71_CLIPPER_XY_GRANULARITY 64.0f
uint32_t
v3dX(clamp_for_format_and_type)(uint32_t rt_type,
VkFormat vk_format);

View File

@@ -32,16 +32,6 @@
#include "broadcom/common/v3d_macros.h"
#include "broadcom/cle/v3dx_pack.h"
/* The Control List Executor (CLE) pre-fetches V3D_CLE_READAHEAD bytes from
* the Control List buffer. The usage of these last bytes should be avoided or
* the CLE would pre-fetch the data after the end of the CL buffer, reporting
* the kernel "MMU error from client CLE".
*/
#define V3D42_CLE_READAHEAD 256u
#define V3D42_CLE_BUFFER_MIN_SIZE 4096u
#define V3D71_CLE_READAHEAD 1024u
#define V3D71_CLE_BUFFER_MIN_SIZE 16384u
void
v3d_init_cl(struct v3d_job *job, struct v3d_cl *cl)
{
@@ -61,10 +51,9 @@ v3d_cl_ensure_space(struct v3d_cl *cl, uint32_t space, uint32_t alignment)
return offset;
}
struct v3d_device_info *devinfo = &cl->job->v3d->screen->devinfo;
uint32_t cle_buffer_min_size = V3DV_X(devinfo, CLE_BUFFER_MIN_SIZE);
v3d_bo_unreference(&cl->bo);
cl->bo = v3d_bo_alloc(cl->job->v3d->screen,
align(space, cle_buffer_min_size),
align(space, devinfo->cle_buffer_min_size),
"CL");
cl->base = v3d_bo_map(cl->bo);
cl->size = cl->bo->size;
@@ -87,19 +76,17 @@ v3d_cl_ensure_space_with_branch(struct v3d_cl *cl, uint32_t space)
* reserved space.
*/
struct v3d_device_info *devinfo = &cl->job->v3d->screen->devinfo;
uint32_t cle_readahead = V3DV_X(devinfo, CLE_READAHEAD);
uint32_t cle_buffer_min_size = V3DV_X(devinfo, CLE_BUFFER_MIN_SIZE);
uint32_t unusable_size = cle_readahead + cl_packet_length(BRANCH);
uint32_t unusable_size = devinfo->cle_readahead + cl_packet_length(BRANCH);
struct v3d_bo *new_bo = v3d_bo_alloc(cl->job->v3d->screen,
align(space + unusable_size,
cle_buffer_min_size),
devinfo->cle_buffer_min_size),
"CL");
assert(space + unusable_size <= new_bo->size);
/* Chain to the new BO from the old one. */
if (cl->bo) {
cl->size += cl_packet_length(BRANCH);
assert(cl->size + cle_readahead <= cl->bo->size);
assert(cl->size + devinfo->cle_readahead <= cl->bo->size);
cl_emit(cl, BRANCH, branch) {
branch.address = cl_address(new_bo, 0);
}

View File

@@ -853,28 +853,6 @@ void v3d_disk_cache_store(struct v3d_context *v3d,
v3d_X_thing; \
})
/* FIXME: The same for vulkan/opengl. Common place? define it at the
* v3d_packet files?
*/
#define V3D42_CLIPPER_XY_GRANULARITY 256.0f
#define V3D71_CLIPPER_XY_GRANULARITY 64.0f
/* Helper to get hw-specific macro values */
#define V3DV_X(devinfo, thing) ({ \
__typeof(V3D42_##thing) V3D_X_THING; \
switch (devinfo->ver) { \
case 42: \
V3D_X_THING = V3D42_##thing; \
break; \
case 71: \
V3D_X_THING = V3D71_##thing; \
break; \
default: \
unreachable("Unsupported hardware generation"); \
} \
V3D_X_THING; \
})
#ifdef v3dX
# include "v3dx_context.h"
#else

View File

@@ -246,13 +246,11 @@ v3d_write_uniforms(struct v3d_context *v3d, struct v3d_job *job,
cl_aligned_u32(&uniforms, gallium_uniforms[data]);
break;
case QUNIFORM_VIEWPORT_X_SCALE: {
float clipper_xy_granularity = V3DV_X(devinfo, CLIPPER_XY_GRANULARITY);
cl_aligned_f(&uniforms, v3d->viewport.scale[0] * clipper_xy_granularity);
cl_aligned_f(&uniforms, v3d->viewport.scale[0] * devinfo->clipper_xy_granularity);
break;
}
case QUNIFORM_VIEWPORT_Y_SCALE: {
float clipper_xy_granularity = V3DV_X(devinfo, CLIPPER_XY_GRANULARITY);
cl_aligned_f(&uniforms, v3d->viewport.scale[1] * clipper_xy_granularity);
cl_aligned_f(&uniforms, v3d->viewport.scale[1] * devinfo->clipper_xy_granularity);
break;
}
case QUNIFORM_VIEWPORT_Z_OFFSET: