vc4: Simplify vc4_use_bo and make sure it's not a shader.
authorEric Anholt <eric@anholt.net>
Tue, 28 Jul 2015 17:20:10 +0000 (10:20 -0700)
committerEric Anholt <eric@anholt.net>
Wed, 29 Jul 2015 02:35:26 +0000 (19:35 -0700)
Since the conversion to keeping validated shaders around for the BO's
lifetime, we haven't been checking that rendering doesn't happen to
shaders.  Make vc4_use_bo check that always, and just don't use it for the
VC4_MODE_SHADER case (so now modes are unused)

src/gallium/drivers/vc4/kernel/vc4_drv.h
src/gallium/drivers/vc4/kernel/vc4_render_cl.c
src/gallium/drivers/vc4/kernel/vc4_validate.c
src/gallium/drivers/vc4/vc4_simulator.c

index 127a366fb3c845b41f6f4068dd61e19978b0998f..ffc973735ae934780f8b97d808ae7d085cb4b43a 100644 (file)
 
 #include "vc4_simulator_validate.h"
 
-enum vc4_bo_mode {
-       VC4_MODE_UNDECIDED,
-       VC4_MODE_RENDER,
-       VC4_MODE_SHADER,
-};
-
-struct vc4_bo_exec_state {
-       struct drm_gem_cma_object *bo;
-       enum vc4_bo_mode mode;
-};
-
 struct vc4_exec_info {
        /* Sequence number for this bin/render job. */
        uint64_t seqno;
@@ -47,7 +36,7 @@ struct vc4_exec_info {
        /* This is the array of BOs that were looked up at the start of exec.
         * Command validation will use indices into this array.
         */
-       struct vc4_bo_exec_state *bo;
+       struct drm_gem_cma_object **bo;
        uint32_t bo_count;
 
        /* List of other BOs used in the job that need to be released
@@ -172,8 +161,7 @@ struct vc4_validated_shader_info *
 vc4_validate_shader(struct drm_gem_cma_object *shader_obj);
 
 struct drm_gem_cma_object *vc4_use_bo(struct vc4_exec_info *exec,
-                                     uint32_t hindex,
-                                     enum vc4_bo_mode mode);
+                                     uint32_t hindex);
 
 int vc4_get_rcl(struct drm_device *dev, struct vc4_exec_info *exec);
 
index a0681042155f797bb936fe3bc5578e80731bb753..b827eb7e9e1f147daf4f10afb33755cea52a451a 100644 (file)
@@ -286,7 +286,7 @@ static int vc4_rcl_surface_setup(struct vc4_exec_info *exec,
        if (surf->hindex == ~0)
                return 0;
 
-       *obj = vc4_use_bo(exec, surf->hindex, VC4_MODE_RENDER);
+       *obj = vc4_use_bo(exec, surf->hindex);
        if (!*obj)
                return -EINVAL;
 
@@ -366,7 +366,7 @@ vc4_rcl_ms_surface_setup(struct vc4_exec_info *exec,
        if (surf->hindex == ~0)
                return 0;
 
-       *obj = vc4_use_bo(exec, surf->hindex, VC4_MODE_RENDER);
+       *obj = vc4_use_bo(exec, surf->hindex);
        if (!*obj)
                return -EINVAL;
 
index 49bb64838ea448257ff8ed72ece24409a902f3e0..e81dd9935ca410159919e2ed4e3308498b5ed1d8 100644 (file)
@@ -95,38 +95,32 @@ size_is_lt(uint32_t width, uint32_t height, int cpp)
 }
 
 struct drm_gem_cma_object *
-vc4_use_bo(struct vc4_exec_info *exec,
-          uint32_t hindex,
-          enum vc4_bo_mode mode)
+vc4_use_bo(struct vc4_exec_info *exec, uint32_t hindex)
 {
        struct drm_gem_cma_object *obj;
+       struct drm_vc4_bo *bo;
 
        if (hindex >= exec->bo_count) {
                DRM_ERROR("BO index %d greater than BO count %d\n",
                          hindex, exec->bo_count);
                return NULL;
        }
-       obj = exec->bo[hindex].bo;
+       obj = exec->bo[hindex];
+       bo = to_vc4_bo(&obj->base);
 
-       if (exec->bo[hindex].mode != mode) {
-               if (exec->bo[hindex].mode == VC4_MODE_UNDECIDED) {
-                       exec->bo[hindex].mode = mode;
-               } else {
-                       DRM_ERROR("BO index %d reused with mode %d vs %d\n",
-                                 hindex, exec->bo[hindex].mode, mode);
-                       return NULL;
-               }
+       if (bo->validated_shader) {
+               DRM_ERROR("Trying to use shader BO as something other than "
+                         "a shader\n");
+               return NULL;
        }
 
        return obj;
 }
 
 static struct drm_gem_cma_object *
-vc4_use_handle(struct vc4_exec_info *exec,
-              uint32_t gem_handles_packet_index,
-              enum vc4_bo_mode mode)
+vc4_use_handle(struct vc4_exec_info *exec, uint32_t gem_handles_packet_index)
 {
-       return vc4_use_bo(exec, exec->bo_index[gem_handles_packet_index], mode);
+       return vc4_use_bo(exec, exec->bo_index[gem_handles_packet_index]);
 }
 
 static bool
@@ -270,7 +264,7 @@ validate_indexed_prim_list(VALIDATE_ARGS)
        if (max_index > shader_state->max_index)
                shader_state->max_index = max_index;
 
-       ib = vc4_use_handle(exec, 0, VC4_MODE_RENDER);
+       ib = vc4_use_handle(exec, 0);
        if (!ib)
                return -EINVAL;
 
@@ -588,7 +582,7 @@ reloc_tex(struct vc4_exec_info *exec,
        uint32_t cube_map_stride = 0;
        enum vc4_texture_data_type type;
 
-       tex = vc4_use_bo(exec, texture_handle_index, VC4_MODE_RENDER);
+       tex = vc4_use_bo(exec, texture_handle_index);
        if (!tex)
                return false;
 
@@ -787,12 +781,17 @@ validate_gl_shader_rec(struct drm_device *dev,
        exec->shader_rec_size -= packet_size;
 
        for (i = 0; i < shader_reloc_count; i++) {
-               bo[i] = vc4_use_bo(exec, src_handles[i], VC4_MODE_SHADER);
+               if (src_handles[i] > exec->bo_count) {
+                       DRM_ERROR("Shader handle %d too big\n", src_handles[i]);
+                       return false;
+               }
+
+               bo[i] = exec->bo[src_handles[i]];
                if (!bo[i])
                        return false;
        }
        for (i = shader_reloc_count; i < nr_relocs; i++) {
-               bo[i] = vc4_use_bo(exec, src_handles[i], VC4_MODE_RENDER);
+               bo[i] = vc4_use_bo(exec, src_handles[i]);
                if (!bo[i])
                        return false;
        }
index 4097dce28a786a9f03f26141920dd962dd89d6da..7cfd236349d3fc6b09a1bf7d4af69ab89e49b3d4 100644 (file)
@@ -74,7 +74,7 @@ vc4_simulator_pin_bos(struct drm_device *dev, struct vc4_exec_info *exec)
         struct vc4_bo **bos = vc4->bo_pointers.base;
 
         exec->bo_count = args->bo_handle_count;
-        exec->bo = calloc(exec->bo_count, sizeof(struct vc4_bo_exec_state));
+        exec->bo = calloc(exec->bo_count, sizeof(void *));
         for (int i = 0; i < exec->bo_count; i++) {
                 struct vc4_bo *bo = bos[i];
                 struct drm_gem_cma_object *obj = vc4_wrap_bo_with_cma(dev, bo);
@@ -87,7 +87,7 @@ vc4_simulator_pin_bos(struct drm_device *dev, struct vc4_exec_info *exec)
                 vc4_bo_map(bo);
                 memcpy(obj->vaddr, bo->map, bo->size);
 
-                exec->bo[i].bo = obj;
+                exec->bo[i] = obj;
 
                 /* The kernel does this validation at shader create ioctl
                  * time.
@@ -105,7 +105,7 @@ static int
 vc4_simulator_unpin_bos(struct vc4_exec_info *exec)
 {
         for (int i = 0; i < exec->bo_count; i++) {
-                struct drm_gem_cma_object *obj = exec->bo[i].bo;
+                struct drm_gem_cma_object *obj = exec->bo[i];
                 struct vc4_bo *bo = to_vc4_bo(&obj->base)->bo;
 
                 memcpy(bo->map, obj->vaddr, bo->size);