vc4: Keep the validated shader around for the simulator execution.
authorEric Anholt <eric@anholt.net>
Tue, 28 Jul 2015 17:11:08 +0000 (10:11 -0700)
committerEric Anholt <eric@anholt.net>
Wed, 29 Jul 2015 02:35:26 +0000 (19:35 -0700)
This more closely matches the kernel behavior on shader validation now.

src/gallium/drivers/vc4/kernel/vc4_validate.c
src/gallium/drivers/vc4/vc4_simulator.c
src/gallium/drivers/vc4/vc4_simulator_validate.h

index 321e8115f8f4ac5383ecc94b2799f69c2cb8ac10..49bb64838ea448257ff8ed72ece24409a902f3e0 100644 (file)
@@ -750,7 +750,6 @@ validate_gl_shader_rec(struct drm_device *dev,
        struct drm_gem_cma_object *bo[shader_reloc_count + 8];
        uint32_t nr_attributes, nr_relocs, packet_size;
        int i;
-       struct vc4_validated_shader_info *validated_shader = NULL;
 
        nr_attributes = state->addr & 0x7;
        if (nr_attributes == 0)
@@ -799,6 +798,7 @@ validate_gl_shader_rec(struct drm_device *dev,
        }
 
        for (i = 0; i < shader_reloc_count; i++) {
+               struct vc4_validated_shader_info *validated_shader;
                uint32_t o = shader_reloc_offsets[i];
                uint32_t src_offset = *(uint32_t *)(pkt_u + o);
                uint32_t *texture_handles_u;
@@ -810,18 +810,17 @@ validate_gl_shader_rec(struct drm_device *dev,
                if (src_offset != 0) {
                        DRM_ERROR("Shaders must be at offset 0 of "
                                  "the BO.\n");
-                       goto fail;
+                       return -EINVAL;
                }
 
-               kfree(validated_shader);
-               validated_shader = vc4_validate_shader(bo[i]);
+               validated_shader = to_vc4_bo(&bo[i]->base)->validated_shader;
                if (!validated_shader)
-                       goto fail;
+                       return -EINVAL;
 
                if (validated_shader->uniforms_src_size >
                    exec->uniforms_size) {
                        DRM_ERROR("Uniforms src buffer overflow\n");
-                       goto fail;
+                       return -EINVAL;
                }
 
                texture_handles_u = exec->uniforms_u;
@@ -838,7 +837,7 @@ validate_gl_shader_rec(struct drm_device *dev,
                                       uniform_data_u,
                                       &validated_shader->texture_samples[tex],
                                       texture_handles_u[tex])) {
-                               goto fail;
+                               return -EINVAL;
                        }
                }
 
@@ -881,13 +880,7 @@ validate_gl_shader_rec(struct drm_device *dev,
                *(uint32_t *)(pkt_v + o) = vbo->paddr + offset;
        }
 
-       kfree(validated_shader);
-
        return 0;
-
-fail:
-       kfree(validated_shader);
-       return -EINVAL;
 }
 
 int
index b58013dd2ee3e43802df82c7f19dcd7cbe3f195d..4097dce28a786a9f03f26141920dd962dd89d6da 100644 (file)
@@ -79,6 +79,7 @@ vc4_simulator_pin_bos(struct drm_device *dev, struct vc4_exec_info *exec)
                 struct vc4_bo *bo = bos[i];
                 struct drm_gem_cma_object *obj = vc4_wrap_bo_with_cma(dev, bo);
 
+                struct drm_vc4_bo *drm_bo = to_vc4_bo(&obj->base);
 #if 0
                 fprintf(stderr, "bo hindex %d: %s\n", i, bo->name);
 #endif
@@ -87,6 +88,15 @@ vc4_simulator_pin_bos(struct drm_device *dev, struct vc4_exec_info *exec)
                 memcpy(obj->vaddr, bo->map, bo->size);
 
                 exec->bo[i].bo = obj;
+
+                /* The kernel does this validation at shader create ioctl
+                 * time.
+                 */
+                if (strcmp(bo->name, "code") == 0) {
+                        drm_bo->validated_shader = vc4_validate_shader(obj);
+                        if (!drm_bo->validated_shader)
+                                abort();
+                }
         }
         return 0;
 }
index 2bb36b253bba848d66c6ef0b2e71ee029b77eb51..68ace0216aaeffb655952237554a4b3cbd12efe4 100644 (file)
@@ -78,6 +78,7 @@ struct drm_gem_cma_object {
 struct drm_vc4_bo {
         struct drm_gem_cma_object base;
         struct vc4_bo *bo;
+        struct vc4_validated_shader_info *validated_shader;
         struct list_head unref_head;
 };