*/
#include "bit.h"
-#include "panfrost/pandecode/decode.h"
+#include "panfrost/lib/decode.h"
#include "drm-uapi/panfrost_drm.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. */
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, enum bit_debug debug)
{
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 (debug >= BIT_DEBUG_ALL)
+ 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
};
- bool success = bit_submit(dev, JOB_TYPE_WRITE_VALUE,
- &payload, sizeof(payload), scratch, 1);
+ struct panfrost_bo *bos[] = { scratch };
+ bool success = bit_submit(dev, MALI_JOB_TYPE_WRITE_VALUE,
+ &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,
+ 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);
+ 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);
+
+ pan_pack(var->cpu, ATTRIBUTE, cfg) {
+ cfg.format = (MALI_RGBA32UI << 12);
+ cfg.unknown = true;
+ }
+
+ pan_pack(attr->cpu, ATTRIBUTE, cfg)
+ cfg.format = (MALI_RGBA32UI << 12);
+
+ pan_pack(var->cpu + 256, ATTRIBUTE_BUFFER, cfg) {
+ cfg.pointer = (var->gpu + 1024);
+ cfg.size = 1024;
+ }
+
+ pan_pack(attr->cpu + 256, ATTRIBUTE_BUFFER, cfg) {
+ cfg.pointer = (attr->gpu + 1024);
+ cfg.size = 1024;
+ }
+
+ if (sz_ubo)
+ memcpy(ubo->cpu + 1024, iubo, sz_ubo);
+
+ if (sz_attr)
+ memcpy(attr->cpu + 1024, iattr, sz_attr);
+
+ 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));
+
+ 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->cpu, prog.compiled.data, prog.compiled.size);
+
+ struct bifrost_payload_vertex payload = {
+ .prefix = {
+ .primitive = {
+ .opaque = { (5) << 26 }
+ }
+ },
+ };
+
+ 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.invocation = invocation;
+ payload.postfix = draw;
+
+ struct panfrost_bo *bos[] = {
+ scratchpad, shmem, shader, shader_desc, ubo, var, attr
+ };
+
+ 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;
+}