#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include "pan_bo.h"
#include "pan_context.h"
+#include "pan_format.h"
+#include "pan_util.h"
#include "compiler/nir/nir.h"
#include "nir/tgsi_to_nir.h"
s->info.stage = stage;
- if (stage == MESA_SHADER_FRAGMENT) {
- /* Inject the alpha test now if we need to */
-
- if (state->alpha_state.enabled) {
- NIR_PASS_V(s, nir_lower_alpha_test, state->alpha_state.func, false);
- }
- }
-
/* Call out to Midgard compiler given the above NIR */
midgard_program program = {
.alpha_ref = state->alpha_state.ref_value
};
- midgard_compile_shader_nir(&ctx->compiler, s, &program, false);
+ midgard_compile_shader_nir(s, &program, false, 0, screen->gpu_id,
+ pan_debug & PAN_DBG_PRECOMPILE);
/* Prepare the compiled binary for upload */
int size = program.compiled.size;
* I bet someone just thought that would be a cute pun. At least,
* that's how I'd do it. */
- state->bo = panfrost_bo_create(screen, size, PAN_ALLOCATE_EXECUTE);
- memcpy(state->bo->cpu, dst, size);
- meta->shader = state->bo->gpu | program.first_tag;
+ if (size) {
+ state->bo = panfrost_bo_create(screen, size, PAN_BO_EXECUTE);
+ memcpy(state->bo->cpu, dst, size);
+ meta->shader = state->bo->gpu | program.first_tag;
+ } else {
+ /* no shader */
+ meta->shader = 0x0;
+ }
util_dynarray_fini(&program.compiled);
meta->midgard1.uniform_count = MIN2(program.uniform_count, program.uniform_cutoff);
meta->midgard1.work_count = program.work_register_count;
+ bool vertex_id = s->info.system_values_read & (1 << SYSTEM_VALUE_VERTEX_ID);
+ bool instance_id = s->info.system_values_read & (1 << SYSTEM_VALUE_INSTANCE_ID);
+
switch (stage) {
case MESA_SHADER_VERTEX:
meta->attribute_count = util_bitcount64(s->info.inputs_read);
meta->varying_count = util_bitcount64(s->info.outputs_written);
+
+ if (vertex_id)
+ meta->attribute_count = MAX2(meta->attribute_count, PAN_VERTEX_ID + 1);
+
+ if (instance_id)
+ meta->attribute_count = MAX2(meta->attribute_count, PAN_INSTANCE_ID + 1);
+
break;
case MESA_SHADER_FRAGMENT:
meta->attribute_count = 0;
meta->varying_count = util_bitcount64(s->info.inputs_read);
+ if (s->info.outputs_written & BITFIELD64_BIT(FRAG_RESULT_DEPTH))
+ state->writes_depth = true;
+ if (s->info.outputs_written & BITFIELD64_BIT(FRAG_RESULT_STENCIL))
+ state->writes_stencil = true;
break;
case MESA_SHADER_COMPUTE:
/* TODO: images */
state->writes_point_size = program.writes_point_size;
state->reads_point_coord = false;
state->helper_invocations = s->info.fs.needs_helper_invocations;
+ state->stack_size = program.tls_size;
if (outputs_written)
*outputs_written = s->info.outputs_written;
/* Separate as primary uniform count is truncated */
state->uniform_count = program.uniform_count;
- meta->midgard1.unknown2 = 8; /* XXX */
+ meta->midgard1.flags_hi = 8; /* XXX */
unsigned default_vec1_swizzle = panfrost_get_default_swizzle(1);
unsigned default_vec2_swizzle = panfrost_get_default_swizzle(2);
/* Default to a vec4 varying */
struct mali_attr_meta v = {
- .format = MALI_RGBA32F,
+ .format = program.varying_type[i],
.swizzle = default_vec4_swizzle,
.unknown1 = 0x2,
};