#include "bifrost_compile.h"
#include "test/bit.h"
-static void
-compile_shader(char **argv)
+static panfrost_program
+compile_shader(char **argv, bool vertex_only)
{
struct gl_shader_program *prog;
nir_shader *nir[2];
unsigned product_id = 0x7212; /* Mali G52 */
bifrost_compile_shader_nir(nir[i], &compiled, product_id);
+
+ if (vertex_only)
+ return compiled;
}
+
+ return compiled;
}
static void
}
static void
-test(void)
+test_vertex(char **argv)
{
void *memctx = NULL; /* TODO */
struct panfrost_device *dev = bit_initialize(memctx);
- bit_sanity_check(dev);
+ bit_vertex(dev, compile_shader(argv, true));
}
int
}
if (strcmp(argv[1], "compile") == 0)
- compile_shader(&argv[2]);
+ compile_shader(&argv[2], false);
else if (strcmp(argv[1], "disasm") == 0)
disassemble(argv[2]);
- else if (strcmp(argv[1], "test") == 0)
- test();
+ else if (strcmp(argv[1], "test-vertex") == 0)
+ test_vertex(&argv[2]);
else
unreachable("Unknown command. Valid: compile/disasm");
#include "bit.h"
#include "panfrost/pandecode/decode.h"
#include "drm-uapi/panfrost_drm.h"
+#include "panfrost/encoder/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. */
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)
+ struct panfrost_bo **bos, size_t bo_count, bool trace)
{
struct mali_job_descriptor_header header = {
.job_descriptor_size = MALI_JOB_64,
uint32_t *bo_handles = calloc(sizeof(uint32_t), bo_count);
for (unsigned i = 0; i < bo_count; ++i)
- bo_handles[i] = bos[i].gem_handle;
+ bo_handles[i] = bos[i]->gem_handle;
uint32_t syncobj = 0;
int ret = 0;
free(bo_handles);
drmSyncobjWait(dev->fd, &syncobj, 1, INT64_MAX, 0, NULL);
- pandecode_jc(submit.jc, true, dev->gpu_id, false);
+ if (trace)
+ pandecode_jc(submit.jc, true, dev->gpu_id, false);
return true;
}
bool
bit_sanity_check(struct panfrost_device *dev)
{
- struct panfrost_bo *scratch = bit_bo_create(dev, 4096);
+ struct panfrost_bo *scratch = bit_bo_create(dev, 65536);
((uint32_t *) scratch->cpu)[0] = 0xAA;
struct mali_payload_write_value payload = {
.value_descriptor = MALI_WRITE_VALUE_ZERO
};
+ struct panfrost_bo *bos[] = { scratch };
bool success = bit_submit(dev, JOB_TYPE_WRITE_VALUE,
- &payload, sizeof(payload), scratch, 1);
+ &payload, sizeof(payload), bos, 1, false);
return success && (((uint8_t *) scratch->cpu)[0] == 0x0);
}
+
+/* Constructs a vertex job */
+
+bool
+bit_vertex(struct panfrost_device *dev, panfrost_program prog)
+{
+
+ struct panfrost_bo *scratchpad = bit_bo_create(dev, 4096);
+ struct panfrost_bo *shader = bit_bo_create(dev, prog.compiled.size);
+ struct panfrost_bo *shader_desc = bit_bo_create(dev, 4096);
+ struct panfrost_bo *ubo = bit_bo_create(dev, 4096);
+ 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
+ };
+
+ union mali_attr vary = {
+ .elements = (var->gpu + 1024) | MALI_ATTR_LINEAR,
+ .size = 1024
+ };
+
+ union mali_attr attr_ = {
+ .elements = (attr->gpu + 1024) | MALI_ATTR_LINEAR,
+ .size = 1024
+ };
+
+ uint64_t my_ubo = MALI_MAKE_UBO(64, ubo->gpu + 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));
+
+ float *fvaryings = (float *) (var->cpu + 1024);
+ float *fubo = (float *) (ubo->cpu + 1024);
+
+ struct panfrost_bo *shmem = bit_bo_create(dev, 4096);
+ struct mali_shared_memory shmemp = {
+ .scratchpad = scratchpad->gpu,
+ .shared_workgroup_count = 0x1f,
+ };
+
+ 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,
+ },
+ };
+
+ 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,
+ },
+ };
+
+ panfrost_pack_work_groups_compute(&payload.prefix,
+ 1, 1, 1,
+ 1, 1, 1,
+ true);
+
+ payload.prefix.workgroups_x_shift_3 = 5;
+
+ 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);
+}