• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2024 Valve Corporation
3  * SPDX-License-Identifier: MIT
4  */
5 
6 #pragma once
7 
8 #include "compiler/libcl/libcl.h"
9 
10 enum libagx_tess_partitioning {
11    LIBAGX_TESS_PARTITIONING_FRACTIONAL_ODD,
12    LIBAGX_TESS_PARTITIONING_FRACTIONAL_EVEN,
13    LIBAGX_TESS_PARTITIONING_INTEGER,
14 };
15 
16 enum libagx_tess_mode {
17    /* Do not actually tessellate, just write the index counts */
18    LIBAGX_TESS_MODE_COUNT,
19 
20    /* Tessellate using the count buffers to allocate indices */
21    LIBAGX_TESS_MODE_WITH_COUNTS,
22 };
23 
24 struct libagx_tess_point {
25    uint32_t u;
26    uint32_t v;
27 };
28 static_assert(sizeof(struct libagx_tess_point) == 8);
29 
30 struct libagx_tess_args {
31    /* Heap to allocate tessellator outputs in */
32    DEVICE(struct agx_geometry_state) heap;
33 
34    /* Patch coordinate buffer, indexed as:
35     *
36     *    coord_allocs[patch_ID] + vertex_in_patch
37     */
38    DEVICE(struct libagx_tess_point) patch_coord_buffer;
39 
40    /* Per-patch index within the heap for the tess coords, written by the
41     * tessellator based on the allocated memory.
42     */
43    DEVICE(uint32_t) coord_allocs;
44 
45    /* Space for output draws from the tessellator. API draw calls. */
46    DEVICE(uint32_t) out_draws;
47 
48    /* Tessellation control shader output buffer. */
49    DEVICE(float) tcs_buffer;
50 
51    /* Count buffer. # of indices per patch written here, then prefix summed. */
52    DEVICE(uint32_t) counts;
53 
54    /* Allocated index buffer for all patches, if we're prefix summing counts */
55    DEVICE(uint32_t) index_buffer;
56 
57    /* Address of the tess eval invocation counter for implementing pipeline
58     * statistics, if active. Zero if inactive. Incremented by tessellator.
59     */
60    DEVICE(uint32_t) statistic;
61 
62    /* When geom+tess used together, the buffer containing TES outputs (executed
63     * as a hardware compute shader).
64     */
65    uint64_t tes_buffer;
66 
67    /* Bitfield of TCS per-vertex outputs */
68    uint64_t tcs_per_vertex_outputs;
69 
70    /* Default tess levels used in OpenGL when there is no TCS in the pipeline.
71     * Unused in Vulkan and OpenGL ES.
72     */
73    float tess_level_outer_default[4];
74    float tess_level_inner_default[2];
75 
76    /* Number of vertices in the input patch */
77    uint32_t input_patch_size;
78 
79    /* Number of vertices in the TCS output patch */
80    uint32_t output_patch_size;
81 
82    /* Number of patch constants written by TCS */
83    uint32_t tcs_patch_constants;
84 
85    /* Number of input patches per instance of the VS/TCS */
86    uint32_t patches_per_instance;
87 
88    /* Stride between tessellation facotrs in the TCS output buffer. */
89    uint32_t tcs_stride_el;
90 
91    /* Number of patches being tessellated */
92    uint32_t nr_patches;
93 
94    /* Partitioning and points mode. These affect per-patch setup code but not
95     * the hot tessellation loop so we make them dynamic to reduce tessellator
96     * variants.
97     */
98    enum libagx_tess_partitioning partitioning;
99    uint32_t points_mode;
100 
101    /* When fed into a geometry shader, triangles should be counter-clockwise.
102     * The tessellator always produces clockwise triangles, but we can swap
103     * dynamically in the TES.
104     */
105    uint32_t ccw;
106 } PACKED;
107 static_assert(sizeof(struct libagx_tess_args) == 35 * 4);
108