xref: /aosp_15_r20/external/mesa3d/src/gallium/drivers/d3d12/d3d12_compute_transforms.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright © Microsoft Corporation
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21  * IN THE SOFTWARE.
22  */
23 
24 #ifndef D3D12_COMPUTE_TRANSFORMS_H
25 #define D3D12_COMPUTE_TRANSFORMS_H
26 
27 #include "d3d12_context.h"
28 #include "d3d12_compiler.h"
29 
30 enum class d3d12_compute_transform_type
31 {
32    /* Extract vertex shader draw params (base vertex, instance, draw ID) from
33     * a stream of indirect draw (indexed) params
34     */
35    base_vertex,
36    /* Given an SO buffer's declaration in the key, copy filled items from a fake (multiplied)
37     * buffer into the original SO buffer, after the original filled size (loaded from the indirect
38     * arg buffer double-bound as a UBO), making sure to skip gaps
39     */
40    fake_so_buffer_copy_back,
41    /* Append a fake SO buffer filed size with (vertex count, 1, 1, original filled size)
42     * for an indirect dispatch of the fake_so_buffer_copy_back transform, and also update
43     * the original filled size with the fake filled size
44     */
45    fake_so_buffer_vertex_count,
46    /* Append a buffer filled size with (vertex count, 1, 0, 0) */
47    draw_auto,
48    /* Accumulate queries together and write a 32-bit or 64-bit result */
49    query_resolve,
50    max,
51 };
52 
53 struct d3d12_compute_transform_key
54 {
55    d3d12_compute_transform_type type;
56 
57    union
58    {
59       struct {
60          unsigned indexed : 1;
61          unsigned dynamic_count : 1;
62       } base_vertex;
63 
64       struct {
65          uint16_t stride;
66          uint16_t num_ranges;
67          struct {
68             uint16_t offset;
69             uint16_t size;
70          } ranges[PIPE_MAX_SO_OUTPUTS];
71       } fake_so_buffer_copy_back;
72 
73       struct {
74          /* true means the accumulation should be done as uint64, else uint32. */
75          uint8_t is_64bit : 1;
76          /* Indicates how many subqueries to accumulate together into a final result. When
77           * set to 1, single_subquery_index determines where the data comes from. */
78          uint8_t num_subqueries : 3;
79          uint8_t pipe_query_type : 4;
80          /* true means output is written where input[0] was, else output is a separate buffer.
81           * true also means all fields are accumulated, else single_result_field_offset determines
82           * which field is resolved. Implies num_subqueries == 1. */
83          uint8_t is_resolve_in_place : 1;
84          uint8_t single_subquery_index : 2;
85          uint8_t single_result_field_offset : 4;
86          uint8_t is_signed : 1;
87          float timestamp_multiplier;
88       } query_resolve;
89    };
90 };
91 
92 d3d12_shader_selector *
93 d3d12_get_compute_transform(struct d3d12_context *ctx, const d3d12_compute_transform_key *key);
94 
95 void
96 d3d12_compute_transform_cache_init(struct d3d12_context *ctx);
97 
98 void
99 d3d12_compute_transform_cache_destroy(struct d3d12_context *ctx);
100 
101 struct d3d12_compute_transform_save_restore
102 {
103    struct d3d12_shader_selector *cs;
104    struct pipe_constant_buffer cbuf0;
105    struct pipe_shader_buffer ssbos[5];
106    bool queries_disabled;
107 };
108 
109 void
110 d3d12_save_compute_transform_state(struct d3d12_context *ctx, d3d12_compute_transform_save_restore *save);
111 
112 void
113 d3d12_restore_compute_transform_state(struct d3d12_context *ctx, d3d12_compute_transform_save_restore *save);
114 
115 #endif
116