panfrost: s/PAN_ALLOCATE_/PAN_BO_/
[mesa.git] / src / gallium / drivers / panfrost / pan_assemble.c
index 4d69cd136bd5bea5ee04529c841b69b87887d6be..cc4822a2361536a66161e78dde525c715488767e 100644 (file)
 #include "tgsi/tgsi_dump.h"
 
 void
-panfrost_shader_compile(struct panfrost_context *ctx, struct mali_shader_meta *meta, const char *src, int type, struct panfrost_shader_state *state)
+panfrost_shader_compile(
+                struct panfrost_context *ctx,
+                struct mali_shader_meta *meta,
+                enum pipe_shader_ir ir_type,
+                const void *ir,
+                gl_shader_stage stage,
+                struct panfrost_shader_state *state,
+                uint64_t *outputs_written)
 {
+        struct panfrost_screen *screen = pan_screen(ctx->base.screen);
         uint8_t *dst;
 
         nir_shader *s;
 
-        struct pipe_shader_state *cso = state->base;
-
-        if (cso->type == PIPE_SHADER_IR_NIR) {
-                s = nir_shader_clone(NULL, cso->ir.nir);
+        if (ir_type == PIPE_SHADER_IR_NIR) {
+                s = nir_shader_clone(NULL, ir);
         } else {
-                assert (cso->type == PIPE_SHADER_IR_TGSI);
-                //tgsi_dump(cso->tokens, 0);
-                s = tgsi_to_nir(cso->tokens, ctx->base.screen);
+                assert (ir_type == PIPE_SHADER_IR_TGSI);
+                s = tgsi_to_nir(ir, ctx->base.screen);
         }
 
-        s->info.stage = type == JOB_TYPE_VERTEX ? MESA_SHADER_VERTEX : MESA_SHADER_FRAGMENT;
+        s->info.stage = stage;
 
-        if (s->info.stage == MESA_SHADER_FRAGMENT) {
+        if (stage == MESA_SHADER_FRAGMENT) {
                 /* Inject the alpha test now if we need to */
 
                 if (state->alpha_state.enabled) {
@@ -77,7 +82,9 @@ panfrost_shader_compile(struct panfrost_context *ctx, struct mali_shader_meta *m
          * I bet someone just thought that would be a cute pun. At least,
          * that's how I'd do it. */
 
-        meta->shader = panfrost_upload(&ctx->shaders, dst, size) | program.first_tag;
+        state->bo = panfrost_bo_create(screen, size, PAN_BO_EXECUTE);
+        memcpy(state->bo->cpu, dst, size);
+        meta->shader = state->bo->gpu | program.first_tag;
 
         util_dynarray_fini(&program.compiled);
 
@@ -89,7 +96,7 @@ panfrost_shader_compile(struct panfrost_context *ctx, struct mali_shader_meta *m
         meta->midgard1.uniform_count = MIN2(program.uniform_count, program.uniform_cutoff);
         meta->midgard1.work_count = program.work_register_count;
 
-        switch (s->info.stage) {
+        switch (stage) {
         case MESA_SHADER_VERTEX:
                 meta->attribute_count = util_bitcount64(s->info.inputs_read);
                 meta->varying_count = util_bitcount64(s->info.outputs_written);
@@ -98,6 +105,11 @@ panfrost_shader_compile(struct panfrost_context *ctx, struct mali_shader_meta *m
                 meta->attribute_count = 0;
                 meta->varying_count = util_bitcount64(s->info.inputs_read);
                 break;
+        case MESA_SHADER_COMPUTE:
+                /* TODO: images */
+                meta->attribute_count = 0;
+                meta->varying_count = 0;
+                break;
         default:
                 unreachable("Unknown shader state");
         }
@@ -107,6 +119,9 @@ panfrost_shader_compile(struct panfrost_context *ctx, struct mali_shader_meta *m
         state->reads_point_coord = false;
         state->helper_invocations = s->info.fs.needs_helper_invocations;
 
+        if (outputs_written)
+                *outputs_written = s->info.outputs_written;
+
         /* Separate as primary uniform count is truncated */
         state->uniform_count = program.uniform_count;
 
@@ -130,28 +145,25 @@ panfrost_shader_compile(struct panfrost_context *ctx, struct mali_shader_meta *m
                 /* Check for special cases, otherwise assume general varying */
 
                 if (location == VARYING_SLOT_POS) {
-                        v.index = 1;
-                        v.format = MALI_VARYING_POS;
+                        if (stage == MESA_SHADER_FRAGMENT)
+                                state->reads_frag_coord = true;
+                        else
+                                v.format = MALI_VARYING_POS;
                 } else if (location == VARYING_SLOT_PSIZ) {
-                        v.index = 2;
                         v.format = MALI_R16F;
                         v.swizzle = default_vec1_swizzle;
 
                         state->writes_point_size = true;
                 } else if (location == VARYING_SLOT_PNTC) {
-                        v.index = 3;
                         v.format = MALI_RG16F;
                         v.swizzle = default_vec2_swizzle;
 
                         state->reads_point_coord = true;
                 } else if (location == VARYING_SLOT_FACE) {
-                        v.index = 4;
                         v.format = MALI_R32I;
                         v.swizzle = default_vec1_swizzle;
 
                         state->reads_face = true;
-                } else {
-                        v.index = 0;
                 }
 
                 state->varyings[i] = v;