summaryrefslogtreecommitdiff
path: root/lib/mesa/src/gallium/drivers/vc4
diff options
context:
space:
mode:
authorJonathan Gray <jsg@cvs.openbsd.org>2023-11-02 04:53:47 +0000
committerJonathan Gray <jsg@cvs.openbsd.org>2023-11-02 04:53:47 +0000
commitb44518130b33cadb5c1d619e9e936ae0e0dbf7cb (patch)
tree6069eb03c39fbc79808a7d94f857118cce75cbe3 /lib/mesa/src/gallium/drivers/vc4
parent32aeb3c41fedbbd7b11aacfec48e8f699d16bff0 (diff)
Merge Mesa 23.1.9
Diffstat (limited to 'lib/mesa/src/gallium/drivers/vc4')
-rw-r--r--lib/mesa/src/gallium/drivers/vc4/vc4_bufmgr.c15
-rw-r--r--lib/mesa/src/gallium/drivers/vc4/vc4_context.c3
-rw-r--r--lib/mesa/src/gallium/drivers/vc4/vc4_program.c17
-rw-r--r--lib/mesa/src/gallium/drivers/vc4/vc4_resource.c71
-rw-r--r--lib/mesa/src/gallium/drivers/vc4/vc4_screen.c16
-rw-r--r--lib/mesa/src/gallium/drivers/vc4/vc4_screen.h6
6 files changed, 76 insertions, 52 deletions
diff --git a/lib/mesa/src/gallium/drivers/vc4/vc4_bufmgr.c b/lib/mesa/src/gallium/drivers/vc4/vc4_bufmgr.c
index 7a366caf6..7c1195e3f 100644
--- a/lib/mesa/src/gallium/drivers/vc4/vc4_bufmgr.c
+++ b/lib/mesa/src/gallium/drivers/vc4/vc4_bufmgr.c
@@ -382,9 +382,11 @@ vc4_bo_open_handle(struct vc4_screen *screen,
{
struct vc4_bo *bo;
- assert(size);
+ /* Note: the caller is responsible for locking screen->bo_handles_mutex.
+ * This allows the lock to cover the actual BO import, avoiding a race.
+ */
- mtx_lock(&screen->bo_handles_mutex);
+ assert(size);
bo = util_hash_table_get(screen->bo_handles, (void*)(uintptr_t)handle);
if (bo) {
@@ -418,10 +420,14 @@ vc4_bo_open_name(struct vc4_screen *screen, uint32_t name)
struct drm_gem_open o = {
.name = name
};
+
+ mtx_lock(&screen->bo_handles_mutex);
+
int ret = vc4_ioctl(screen->fd, DRM_IOCTL_GEM_OPEN, &o);
if (ret) {
fprintf(stderr, "Failed to open bo %d: %s\n",
name, strerror(errno));
+ mtx_unlock(&screen->bo_handles_mutex);
return NULL;
}
@@ -432,10 +438,14 @@ struct vc4_bo *
vc4_bo_open_dmabuf(struct vc4_screen *screen, int fd)
{
uint32_t handle;
+
+ mtx_lock(&screen->bo_handles_mutex);
+
int ret = drmPrimeFDToHandle(screen->fd, fd, &handle);
int size;
if (ret) {
fprintf(stderr, "Failed to get vc4 handle for dmabuf %d\n", fd);
+ mtx_unlock(&screen->bo_handles_mutex);
return NULL;
}
@@ -443,6 +453,7 @@ vc4_bo_open_dmabuf(struct vc4_screen *screen, int fd)
size = lseek(fd, 0, SEEK_END);
if (size == -1) {
fprintf(stderr, "Couldn't get size of dmabuf fd %d.\n", fd);
+ mtx_unlock(&screen->bo_handles_mutex);
return NULL;
}
diff --git a/lib/mesa/src/gallium/drivers/vc4/vc4_context.c b/lib/mesa/src/gallium/drivers/vc4/vc4_context.c
index f03cf57cc..472a3e1b0 100644
--- a/lib/mesa/src/gallium/drivers/vc4/vc4_context.c
+++ b/lib/mesa/src/gallium/drivers/vc4/vc4_context.c
@@ -116,8 +116,7 @@ vc4_context_destroy(struct pipe_context *pctx)
slab_destroy_child(&vc4->transfer_pool);
- pipe_surface_reference(&vc4->framebuffer.cbufs[0], NULL);
- pipe_surface_reference(&vc4->framebuffer.zsbuf, NULL);
+ util_unreference_framebuffer_state(&vc4->framebuffer);
if (vc4->yuv_linear_blit_vs)
pctx->delete_vs_state(pctx, vc4->yuv_linear_blit_vs);
diff --git a/lib/mesa/src/gallium/drivers/vc4/vc4_program.c b/lib/mesa/src/gallium/drivers/vc4/vc4_program.c
index 426512c31..67a05b994 100644
--- a/lib/mesa/src/gallium/drivers/vc4/vc4_program.c
+++ b/lib/mesa/src/gallium/drivers/vc4/vc4_program.c
@@ -806,14 +806,7 @@ add_output(struct vc4_compile *c,
static bool
ntq_src_is_only_ssa_def_user(nir_src *src)
{
- if (!src->is_ssa)
- return false;
-
- if (!list_is_empty(&src->ssa->if_uses))
- return false;
-
- return (src->ssa->uses.next == &src->use_link &&
- src->ssa->uses.next->next == &src->ssa->uses);
+ return src->is_ssa && list_is_singular(&src->ssa->uses);
}
/**
@@ -1146,13 +1139,6 @@ ntq_emit_alu(struct vc4_compile *c, nir_alu_instr *instr)
case nir_op_b2i32:
result = qir_AND(c, src[0], qir_uniform_ui(c, 1));
break;
- case nir_op_i2b32:
- case nir_op_f2b32:
- qir_SF(c, src[0]);
- result = qir_MOV(c, qir_SEL(c, QPU_COND_ZC,
- qir_uniform_ui(c, ~0),
- qir_uniform_ui(c, 0)));
- break;
case nir_op_iadd:
result = qir_ADD(c, src[0], src[1]);
@@ -2057,6 +2043,7 @@ static void ntq_emit_cf_list(struct vc4_compile *c, struct exec_list *list);
static void
ntq_emit_loop(struct vc4_compile *c, nir_loop *loop)
{
+ assert(!nir_loop_has_continue_construct(loop));
if (!c->vc4->screen->has_control_flow) {
fprintf(stderr,
"loop support requires updated kernel.\n");
diff --git a/lib/mesa/src/gallium/drivers/vc4/vc4_resource.c b/lib/mesa/src/gallium/drivers/vc4/vc4_resource.c
index ab918a05c..65bf7ca53 100644
--- a/lib/mesa/src/gallium/drivers/vc4/vc4_resource.c
+++ b/lib/mesa/src/gallium/drivers/vc4/vc4_resource.c
@@ -95,34 +95,13 @@ vc4_resource_transfer_unmap(struct pipe_context *pctx,
slab_free(&vc4->transfer_pool, ptrans);
}
-static void *
-vc4_resource_transfer_map(struct pipe_context *pctx,
- struct pipe_resource *prsc,
- unsigned level, unsigned usage,
- const struct pipe_box *box,
- struct pipe_transfer **pptrans)
+static void
+vc4_map_usage_prep(struct pipe_context *pctx,
+ struct pipe_resource *prsc,
+ unsigned usage)
{
struct vc4_context *vc4 = vc4_context(pctx);
struct vc4_resource *rsc = vc4_resource(prsc);
- struct vc4_transfer *trans;
- struct pipe_transfer *ptrans;
- enum pipe_format format = prsc->format;
- char *buf;
-
- /* Upgrade DISCARD_RANGE to WHOLE_RESOURCE if the whole resource is
- * being mapped.
- */
- if ((usage & PIPE_MAP_DISCARD_RANGE) &&
- !(usage & PIPE_MAP_UNSYNCHRONIZED) &&
- !(prsc->flags & PIPE_RESOURCE_FLAG_MAP_PERSISTENT) &&
- prsc->last_level == 0 &&
- prsc->width0 == box->width &&
- prsc->height0 == box->height &&
- prsc->depth0 == box->depth &&
- prsc->array_size == 1 &&
- rsc->bo->private) {
- usage |= PIPE_MAP_DISCARD_WHOLE_RESOURCE;
- }
if (usage & PIPE_MAP_DISCARD_WHOLE_RESOURCE) {
if (vc4_resource_bo_alloc(rsc)) {
@@ -131,6 +110,8 @@ vc4_resource_transfer_map(struct pipe_context *pctx,
*/
if (prsc->bind & PIPE_BIND_VERTEX_BUFFER)
vc4->dirty |= VC4_DIRTY_VTXBUF;
+ if (prsc->bind & PIPE_BIND_CONSTANT_BUFFER)
+ vc4->dirty |= VC4_DIRTY_CONSTBUF;
} else {
/* If we failed to reallocate, flush users so that we
* don't violate any syncing requirements.
@@ -139,7 +120,7 @@ vc4_resource_transfer_map(struct pipe_context *pctx,
}
} else if (!(usage & PIPE_MAP_UNSYNCHRONIZED)) {
/* If we're writing and the buffer is being used by the CL, we
- * have to flush the CL first. If we're only reading, we need
+ * have to flush the CL first. If we're only reading, we need
* to flush if the CL has written our buffer.
*/
if (usage & PIPE_MAP_WRITE)
@@ -152,6 +133,38 @@ vc4_resource_transfer_map(struct pipe_context *pctx,
rsc->writes++;
rsc->initialized_buffers = ~0;
}
+}
+
+static void *
+vc4_resource_transfer_map(struct pipe_context *pctx,
+ struct pipe_resource *prsc,
+ unsigned level, unsigned usage,
+ const struct pipe_box *box,
+ struct pipe_transfer **pptrans)
+{
+ struct vc4_context *vc4 = vc4_context(pctx);
+ struct vc4_resource *rsc = vc4_resource(prsc);
+ struct vc4_transfer *trans;
+ struct pipe_transfer *ptrans;
+ enum pipe_format format = prsc->format;
+ char *buf;
+
+ /* Upgrade DISCARD_RANGE to WHOLE_RESOURCE if the whole resource is
+ * being mapped.
+ */
+ if ((usage & PIPE_MAP_DISCARD_RANGE) &&
+ !(usage & PIPE_MAP_UNSYNCHRONIZED) &&
+ !(prsc->flags & PIPE_RESOURCE_FLAG_MAP_PERSISTENT) &&
+ prsc->last_level == 0 &&
+ prsc->width0 == box->width &&
+ prsc->height0 == box->height &&
+ prsc->depth0 == box->depth &&
+ prsc->array_size == 1 &&
+ rsc->bo->private) {
+ usage |= PIPE_MAP_DISCARD_WHOLE_RESOURCE;
+ }
+
+ vc4_map_usage_prep(pctx, prsc, usage);
trans = slab_zalloc(&vc4->transfer_pool);
if (!trans)
@@ -240,8 +253,12 @@ vc4_texture_subdata(struct pipe_context *pctx,
}
/* Otherwise, map and store the texture data directly into the tiled
- * texture.
+ * texture. Note that gallium's texture_subdata may be called with
+ * obvious usage flags missing!
*/
+ vc4_map_usage_prep(pctx, prsc, usage | (PIPE_MAP_WRITE |
+ PIPE_MAP_DISCARD_RANGE));
+
void *buf;
if (usage & PIPE_MAP_UNSYNCHRONIZED)
buf = vc4_bo_map_unsynchronized(rsc->bo);
diff --git a/lib/mesa/src/gallium/drivers/vc4/vc4_screen.c b/lib/mesa/src/gallium/drivers/vc4/vc4_screen.c
index aec151168..4a0e34956 100644
--- a/lib/mesa/src/gallium/drivers/vc4/vc4_screen.c
+++ b/lib/mesa/src/gallium/drivers/vc4/vc4_screen.c
@@ -69,7 +69,7 @@ static const struct debug_named_value vc4_debug_options[] = {
{ "dump", VC4_DEBUG_DUMP,
"Write a GPU command stream trace file" },
#endif
- { NULL }
+ DEBUG_NAMED_VALUE_END
};
DEBUG_GET_ONCE_FLAGS_OPTION(vc4_debug, "VC4_DEBUG", vc4_debug_options, 0)
@@ -294,8 +294,6 @@ vc4_screen_get_shader_param(struct pipe_screen *pscreen,
case PIPE_SHADER_CAP_INT16:
case PIPE_SHADER_CAP_GLSL_16BIT_CONSTS:
case PIPE_SHADER_CAP_DROUND_SUPPORTED:
- case PIPE_SHADER_CAP_DFRACEXP_DLDEXP_SUPPORTED:
- case PIPE_SHADER_CAP_LDEXP_SUPPORTED:
case PIPE_SHADER_CAP_TGSI_ANY_INOUT_DECL_RANGE:
return 0;
case PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS:
@@ -537,8 +535,17 @@ vc4_get_chip_info(struct vc4_screen *screen)
return true;
}
+static int
+vc4_screen_get_fd(struct pipe_screen *pscreen)
+{
+ struct vc4_screen *screen = vc4_screen(pscreen);
+
+ return screen->fd;
+}
+
struct pipe_screen *
-vc4_screen_create(int fd, struct renderonly *ro)
+vc4_screen_create(int fd, const struct pipe_screen_config *config,
+ struct renderonly *ro)
{
struct vc4_screen *screen = rzalloc(NULL, struct vc4_screen);
uint64_t syncobj_cap = 0;
@@ -548,6 +555,7 @@ vc4_screen_create(int fd, struct renderonly *ro)
pscreen = &screen->base;
pscreen->destroy = vc4_screen_destroy;
+ pscreen->get_screen_fd = vc4_screen_get_fd;
pscreen->get_param = vc4_screen_get_param;
pscreen->get_paramf = vc4_screen_get_paramf;
pscreen->get_shader_param = vc4_screen_get_shader_param;
diff --git a/lib/mesa/src/gallium/drivers/vc4/vc4_screen.h b/lib/mesa/src/gallium/drivers/vc4/vc4_screen.h
index 52e19a32b..aa4506eb5 100644
--- a/lib/mesa/src/gallium/drivers/vc4/vc4_screen.h
+++ b/lib/mesa/src/gallium/drivers/vc4/vc4_screen.h
@@ -26,7 +26,7 @@
#include "pipe/p_screen.h"
#include "renderonly/renderonly.h"
-#include "os/os_thread.h"
+#include "util/u_thread.h"
#include "frontend/drm_driver.h"
#include "util/list.h"
#include "util/slab.h"
@@ -114,7 +114,9 @@ vc4_screen(struct pipe_screen *screen)
return (struct vc4_screen *)screen;
}
-struct pipe_screen *vc4_screen_create(int fd, struct renderonly *ro);
+struct pipe_screen *vc4_screen_create(int fd,
+ const struct pipe_screen_config *config,
+ struct renderonly *ro);
const void *
vc4_screen_get_compiler_options(struct pipe_screen *pscreen,