asahi: Lift streamout scaffolding from Panfrost
authorAlyssa Rosenzweig <alyssa@rosenzweig.io>
Mon, 31 May 2021 20:10:40 +0000 (16:10 -0400)
committerMarge Bot <eric+marge@anholt.net>
Tue, 1 Jun 2021 01:31:02 +0000 (01:31 +0000)
Trying to fake ES3 for dEQP-GLES3.

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11086>

src/gallium/drivers/asahi/agx_pipe.c
src/gallium/drivers/asahi/agx_state.c
src/gallium/drivers/asahi/agx_state.h

index da80a98..ef486f1 100644 (file)
@@ -627,6 +627,8 @@ agx_get_name(struct pipe_screen* pscreen)
 static int
 agx_get_param(struct pipe_screen* pscreen, enum pipe_cap param)
 {
+   bool is_deqp = agx_device(pscreen)->debug & AGX_DBG_DEQP;
+
    switch (param) {
    case PIPE_CAP_NPOT_TEXTURES:
    case PIPE_CAP_MIXED_COLOR_DEPTH_BITS:
@@ -669,6 +671,20 @@ agx_get_param(struct pipe_screen* pscreen, enum pipe_cap param)
    case PIPE_CAP_COPY_BETWEEN_COMPRESSED_AND_PLAIN_FORMATS:
       return 0;
 
+   case PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS:
+      return is_deqp ? PIPE_MAX_SO_BUFFERS : 0;
+
+   case PIPE_CAP_MAX_STREAM_OUTPUT_SEPARATE_COMPONENTS:
+   case PIPE_CAP_MAX_STREAM_OUTPUT_INTERLEAVED_COMPONENTS:
+      return is_deqp ? PIPE_MAX_SO_OUTPUTS : 0;
+
+   case PIPE_CAP_STREAM_OUTPUT_PAUSE_RESUME:
+   case PIPE_CAP_STREAM_OUTPUT_INTERLEAVE_BUFFERS:
+      return is_deqp ? 1 : 0;
+   case PIPE_CAP_MAX_TEXTURE_ARRAY_LAYERS:
+      return is_deqp ? 256 : 0;
+
    case PIPE_CAP_GLSL_FEATURE_LEVEL:
    case PIPE_CAP_GLSL_FEATURE_LEVEL_COMPATIBILITY:
       return 130;
index 348de06..5e5da9b 100644 (file)
 #include "asahi/lib/agx_pack.h"
 #include "asahi/lib/agx_formats.h"
 
+static struct pipe_stream_output_target *
+agx_create_stream_output_target(struct pipe_context *pctx,
+                                struct pipe_resource *prsc,
+                                unsigned buffer_offset,
+                                unsigned buffer_size)
+{
+   struct pipe_stream_output_target *target;
+
+   target = &rzalloc(pctx, struct agx_streamout_target)->base;
+
+   if (!target)
+      return NULL;
+
+   pipe_reference_init(&target->reference, 1);
+   pipe_resource_reference(&target->buffer, prsc);
+
+   target->context = pctx;
+   target->buffer_offset = buffer_offset;
+   target->buffer_size = buffer_size;
+
+   return target;
+}
+
+static void
+agx_stream_output_target_destroy(struct pipe_context *pctx,
+                                 struct pipe_stream_output_target *target)
+{
+   pipe_resource_reference(&target->buffer, NULL);
+   ralloc_free(target);
+}
+
+static void
+agx_set_stream_output_targets(struct pipe_context *pctx,
+                              unsigned num_targets,
+                              struct pipe_stream_output_target **targets,
+                              const unsigned *offsets)
+{
+   struct agx_context *ctx = agx_context(pctx);
+   struct agx_streamout *so = &ctx->streamout;
+
+   assert(num_targets <= ARRAY_SIZE(so->targets));
+
+   for (unsigned i = 0; i < num_targets; i++) {
+      if (offsets[i] != -1)
+         agx_so_target(targets[i])->offset = offsets[i];
+
+      pipe_so_target_reference(&so->targets[i], targets[i]);
+   }
+
+   for (unsigned i = 0; i < so->num_targets; i++)
+      pipe_so_target_reference(&so->targets[i], NULL);
+
+   so->num_targets = num_targets;
+}
+
 static void
 agx_set_blend_color(struct pipe_context *pctx,
                     const struct pipe_blend_color *state)
@@ -1412,4 +1467,7 @@ agx_init_state_functions(struct pipe_context *ctx)
    ctx->sampler_view_destroy = agx_sampler_view_destroy;
    ctx->surface_destroy = agx_surface_destroy;
    ctx->draw_vbo = agx_draw_vbo;
+   ctx->create_stream_output_target = agx_create_stream_output_target;
+   ctx->stream_output_target_destroy = agx_stream_output_target_destroy;
+   ctx->set_stream_output_targets = agx_set_stream_output_targets;
 }
index 220708d..eb9c821 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright 2021 Alyssa Rosenzweig
+ * Copyright (C) 2019-2021 Collabora, Ltd.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
 #include "util/hash_table.h"
 #include "util/bitset.h"
 
+struct agx_streamout_target {
+   struct pipe_stream_output_target base;
+   uint32_t offset;
+};
+
+struct agx_streamout {
+   struct pipe_stream_output_target *targets[PIPE_MAX_SO_BUFFERS];
+   unsigned num_targets;
+};
+
+static inline struct agx_streamout_target *
+agx_so_target(struct pipe_stream_output_target *target)
+{
+   return (struct agx_streamout_target *)target;
+}
+
 struct agx_compiled_shader {
    /* Mapped executable memory */
    struct agx_bo *bo;
@@ -146,6 +163,7 @@ struct agx_context {
    struct pipe_blend_color blend_color;
    struct pipe_viewport_state viewport;
    struct pipe_scissor_state scissor;
+   struct agx_streamout streamout;
 
    uint8_t render_target[8][AGX_RENDER_TARGET_LENGTH];
 };