xref: /aosp_15_r20/external/mesa3d/src/gallium/drivers/d3d12/d3d12_batch.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_BATCH_H
25 #define D3D12_BATCH_H
26 
27 #include "util/u_dynarray.h"
28 #include "util/hash_table.h"
29 #include "pipe/p_state.h"
30 #include <stdint.h>
31 
32 #include "d3d12_common.h"
33 
34 struct d3d12_bo;
35 struct d3d12_descriptor_heap;
36 struct d3d12_fence;
37 
38 
39 struct d3d12_sampler_desc_table_key
40 {
41    D3D12_CPU_DESCRIPTOR_HANDLE descs[PIPE_MAX_SHADER_SAMPLER_VIEWS];
42    unsigned count;
43 };
44 
45 struct d3d12_batch {
46    struct d3d12_fence *fence;
47 
48    struct hash_table *bos;
49    struct util_dynarray local_bos;
50    struct hash_table *sampler_tables;
51    struct set *sampler_views;
52    struct set *surfaces;
53    struct set *objects;
54    struct set *queries;
55 
56    struct util_dynarray zombie_samplers;
57 
58    ID3D12CommandAllocator *cmdalloc;
59    struct d3d12_descriptor_heap *sampler_heap;
60    struct d3d12_descriptor_heap *view_heap;
61    bool has_errors;
62    bool pending_memory_barrier;
63 
64    uint64_t submit_id;
65    uint32_t ctx_id, ctx_index;
66 };
67 
68 bool
69 d3d12_init_batch(struct d3d12_context *ctx, struct d3d12_batch *batch);
70 
71 void
72 d3d12_destroy_batch(struct d3d12_context *ctx, struct d3d12_batch *batch);
73 
74 void
75 d3d12_start_batch(struct d3d12_context *ctx, struct d3d12_batch *batch);
76 
77 void
78 d3d12_end_batch(struct d3d12_context *ctx, struct d3d12_batch *batch);
79 
80 bool
81 d3d12_reset_batch(struct d3d12_context *ctx, struct d3d12_batch *batch, uint64_t timeout_ns);
82 
83 bool
84 d3d12_batch_has_references(struct d3d12_batch *batch,
85                            struct d3d12_bo *bo,
86                            bool want_to_write);
87 
88 void
89 d3d12_batch_reference_resource(struct d3d12_batch *batch,
90                                struct d3d12_resource *res,
91                                bool write);
92 
93 void
94 d3d12_batch_reference_sampler_view(struct d3d12_batch *batch,
95                                    struct d3d12_sampler_view *sv);
96 
97 void
98 d3d12_batch_reference_surface_texture(struct d3d12_batch *batch,
99                               struct d3d12_surface *surf);
100 
101 void
102 d3d12_batch_reference_object(struct d3d12_batch *batch,
103                              ID3D12Object *object);
104 
105 void
106 d3d12_batch_reference_query(struct d3d12_batch *batch,
107                             struct d3d12_query *query);
108 
109 #endif
110