panfrost: Remove mali_vertex_tiler_postfix
[mesa.git] / src / panfrost / bifrost / test / bi_submit.c
index 17b7a3600cd4e8417ca34b1a7ebd17b87d13a34f..1b7f65d2c9d331046a5d9fe84788852c42c54e96 100644 (file)
@@ -25,9 +25,9 @@
  */
 
 #include "bit.h"
-#include "panfrost/pandecode/decode.h"
+#include "panfrost/lib/decode.h"
 #include "drm-uapi/panfrost_drm.h"
-#include "panfrost/encoder/pan_encoder.h"
+#include "panfrost/lib/pan_encoder.h"
 
 /* Standalone compiler tests submitting jobs directly to the hardware. Uses the
  * `bit` prefix for `BIfrost Tests` and because bit sounds wicked cool. */
@@ -61,7 +61,7 @@ static bool
 bit_submit(struct panfrost_device *dev,
                 enum mali_job_type T,
                 void *payload, size_t payload_size,
-                struct panfrost_bo **bos, size_t bo_count, bool trace)
+                struct panfrost_bo **bos, size_t bo_count, enum bit_debug debug)
 {
         struct mali_job_descriptor_header header = {
                 .job_descriptor_size = MALI_JOB_64,
@@ -96,7 +96,7 @@ bit_submit(struct panfrost_device *dev,
         free(bo_handles);
 
         drmSyncobjWait(dev->fd, &syncobj, 1, INT64_MAX, 0, NULL);
-        if (trace)
+        if (debug >= BIT_DEBUG_ALL)
                 pandecode_jc(submit.jc, true, dev->gpu_id, false);
         return true;
 }
@@ -117,7 +117,7 @@ bit_sanity_check(struct panfrost_device *dev)
         };
 
         struct panfrost_bo *bos[] = { scratch };
-        bool success = bit_submit(dev, JOB_TYPE_WRITE_VALUE,
+        bool success = bit_submit(dev, MALI_JOB_TYPE_WRITE_VALUE,
                         &payload, sizeof(payload), bos, 1, false);
 
         return success && (((uint8_t *) scratch->cpu)[0] == 0x0);
@@ -126,7 +126,10 @@ bit_sanity_check(struct panfrost_device *dev)
 /* Constructs a vertex job */
 
 bool
-bit_vertex(struct panfrost_device *dev, panfrost_program prog)
+bit_vertex(struct panfrost_device *dev, panfrost_program prog,
+                uint32_t *iubo, size_t sz_ubo,
+                uint32_t *iattr, size_t sz_attr,
+                uint32_t *expected, size_t sz_expected, enum bit_debug debug)
 {
 
         struct panfrost_bo *scratchpad = bit_bo_create(dev, 4096);
@@ -136,31 +139,29 @@ bit_vertex(struct panfrost_device *dev, panfrost_program prog)
         struct panfrost_bo *var = bit_bo_create(dev, 4096);
         struct panfrost_bo *attr = bit_bo_create(dev, 4096);
 
-        struct mali_attr_meta vmeta = {
-                .index = 0,
-                .format = MALI_RGBA32F
-        };
+        pan_pack(var->cpu, ATTRIBUTE, cfg) {
+                cfg.format = (MALI_RGBA32UI << 12);
+                cfg.unknown = true;
+        }
 
-        union mali_attr vary = {
-                .elements = (var->gpu + 1024) | MALI_ATTR_LINEAR,
-                .size = 1024
-        };
+        pan_pack(attr->cpu, ATTRIBUTE, cfg)
+                cfg.format = (MALI_RGBA32UI << 12);
 
-        union mali_attr attr_ = {
-                .elements = (attr->gpu + 1024) | MALI_ATTR_LINEAR,
-                .size = 1024
-        };
+        pan_pack(var->cpu + 256, ATTRIBUTE_BUFFER, cfg) {
+                cfg.pointer = (var->gpu + 1024);
+                cfg.size = 1024;
+        }
 
-        uint64_t my_ubo = MALI_MAKE_UBO(64, ubo->gpu + 1024);
+        pan_pack(attr->cpu + 256, ATTRIBUTE_BUFFER, cfg) {
+                cfg.pointer = (attr->gpu + 1024);
+                cfg.size = 1024;
+        }
 
-        memcpy(ubo->cpu, &my_ubo, sizeof(my_ubo));
-        memcpy(var->cpu, &vmeta, sizeof(vmeta));
-        memcpy(attr->cpu, &vmeta, sizeof(vmeta));
-        memcpy(var->cpu + 256, &vary, sizeof(vary));
-        memcpy(attr->cpu + 256, &attr_, sizeof(vary));
+        if (sz_ubo)
+                memcpy(ubo->cpu + 1024, iubo, sz_ubo);
 
-        float *fvaryings = (float *) (var->cpu + 1024);
-        float *fubo = (float *) (ubo->cpu + 1024);
+        if (sz_attr)
+                memcpy(attr->cpu + 1024, iattr, sz_attr);
 
         struct panfrost_bo *shmem = bit_bo_create(dev, 4096);
         struct mali_shared_memory shmemp = {
@@ -170,53 +171,85 @@ bit_vertex(struct panfrost_device *dev, panfrost_program prog)
 
         memcpy(shmem->cpu, &shmemp, sizeof(shmemp));
 
-        struct mali_shader_meta meta = {
-                .shader = shader->gpu,
-                .attribute_count = 1,
-                .varying_count = 1,
-                .bifrost1 = {
-                        .unk1 = 0x800200,
-                },
-                .bifrost2 = {
-                        .unk3 = 0x0,
-                        .preload_regs = 0xc0,
-                        .uniform_count = 0,
-                        .unk4 = 0x0,
-                },
-        };
+        pan_pack(shader_desc->cpu, STATE, cfg) {
+                cfg.shader.shader = shader->gpu;
+                cfg.shader.attribute_count = cfg.shader.varying_count = 1;
+                cfg.properties = 0x80020001;
+                cfg.preload.uniform_count = (sz_ubo / 16);
+        }
 
-        memcpy(shader_desc->cpu, &meta, sizeof(meta));
         memcpy(shader->cpu, prog.compiled.data, prog.compiled.size);
 
         struct bifrost_payload_vertex payload = {
                 .prefix = {
-                },
-                .vertex = {
-                        .unk2 = 0x2,
-                },
-                .postfix = {
-                        .shared_memory = shmem->gpu,
-                        .shader = shader_desc->gpu,
-                        .uniforms = ubo->gpu + 1024,
-                        .uniform_buffers = ubo->gpu,
-                        .attribute_meta = attr->gpu,
-                        .attributes = var->gpu + 256,
-                        .varying_meta = var->gpu,
-                        .varyings = var->gpu + 256,
+                        .primitive = {
+                                .opaque = { (5) << 26 }
+                        }
                 },
         };
 
-        panfrost_pack_work_groups_compute(&payload.prefix,
+        struct mali_draw_packed draw;
+        struct mali_invocation_packed invocation;
+
+        pan_pack(&draw, DRAW, cfg) {
+                cfg.unknown_1 = 0x2;
+                cfg.shared = shmem->gpu;
+                cfg.state = shader_desc->gpu;
+                cfg.push_uniforms = ubo->gpu + 1024;
+                cfg.uniform_buffers = ubo->gpu;
+                cfg.attributes = attr->gpu;
+                cfg.attribute_buffers = attr->gpu + 256;
+                cfg.varyings = var->gpu;
+                cfg.varying_buffers = var->gpu + 256;
+        }
+
+        panfrost_pack_work_groups_compute(&invocation,
                         1, 1, 1,
                         1, 1, 1,
                         true);
 
-        payload.prefix.workgroups_x_shift_3 = 5;
+        payload.prefix.invocation = invocation;
+        payload.postfix = draw;
 
         struct panfrost_bo *bos[] = {
                 scratchpad, shmem, shader, shader_desc, ubo, var, attr
         };
 
-        return bit_submit(dev, JOB_TYPE_VERTEX, &payload,
-                        sizeof(payload), bos, ARRAY_SIZE(bos), true);
+        bool succ = bit_submit(dev, MALI_JOB_TYPE_VERTEX, &payload,
+                        sizeof(payload), bos, ARRAY_SIZE(bos), debug);
+
+        /* Check the output varyings */
+
+        uint32_t *output = (uint32_t *) (var->cpu + 1024);
+        float *foutput = (float *) output;
+        float *fexpected = (float *) expected;
+
+        if (sz_expected) {
+                unsigned comp = memcmp(output, expected, sz_expected);
+                succ &= (comp == 0);
+
+                if (comp && (debug >= BIT_DEBUG_FAIL)) {
+                        fprintf(stderr, "expected [");
+
+                        for (unsigned i = 0; i < (sz_expected >> 2); ++i)
+                                fprintf(stderr, "%08X /* %f */ ", expected[i], fexpected[i]);
+
+                        fprintf(stderr, "], got [");
+
+                        for (unsigned i = 0; i < (sz_expected >> 2); ++i)
+                                fprintf(stderr, "%08X /* %f */ ", output[i], foutput[i]);
+
+                        fprintf(stderr, "\n");
+                }
+        } else if (debug == BIT_DEBUG_ALL) {
+                fprintf(stderr, "got [");
+
+                for (unsigned i = 0; i < 4; ++i)
+                        fprintf(stderr, "%08X /* %f */ ", output[i], foutput[i]);
+
+                fprintf(stderr, "\n");
+        }
+
+        return succ;
 }