xref: /aosp_15_r20/external/mesa3d/src/gallium/drivers/d3d12/d3d12_resource_state.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_RESOURCE_STATE_H
25 #define D3D12_RESOURCE_STATE_H
26 
27 #include <stdbool.h>
28 #include <stdint.h>
29 
30 #include "d3d12_common.h"
31 
32 #include "util/hash_table.h"
33 
34 struct d3d12_context;
35 
36 const D3D12_RESOURCE_STATES RESOURCE_STATE_ALL_WRITE_BITS =
37    D3D12_RESOURCE_STATE_RENDER_TARGET | D3D12_RESOURCE_STATE_UNORDERED_ACCESS | D3D12_RESOURCE_STATE_DEPTH_WRITE |
38    D3D12_RESOURCE_STATE_STREAM_OUT | D3D12_RESOURCE_STATE_COPY_DEST | D3D12_RESOURCE_STATE_RESOLVE_DEST |
39    D3D12_RESOURCE_STATE_VIDEO_DECODE_WRITE | D3D12_RESOURCE_STATE_VIDEO_PROCESS_WRITE;
40 
41 inline bool
d3d12_is_write_state(D3D12_RESOURCE_STATES state)42 d3d12_is_write_state(D3D12_RESOURCE_STATES state)
43 {
44    return (state & RESOURCE_STATE_ALL_WRITE_BITS) != D3D12_RESOURCE_STATE_COMMON;
45 }
46 
47 inline bool
d3d12_resource_supports_simultaneous_access(const D3D12_RESOURCE_DESC * desc)48 d3d12_resource_supports_simultaneous_access(const D3D12_RESOURCE_DESC *desc)
49 {
50    return desc->Dimension == D3D12_RESOURCE_DIMENSION_BUFFER ||
51           (desc->Flags & D3D12_RESOURCE_FLAG_ALLOW_SIMULTANEOUS_ACCESS) != D3D12_RESOURCE_FLAG_NONE;
52 }
53 
54 struct d3d12_subresource_state
55 {
56    D3D12_RESOURCE_STATES state;
57    uint64_t execution_id;
58    bool is_promoted;
59    bool may_decay;
60 };
61 
62 /* Stores the current state of either an entire resource, or each subresource */
63 struct d3d12_resource_state
64 {
65    bool homogenous;
66    bool supports_simultaneous_access;
67    uint32_t num_subresources;
68    d3d12_subresource_state *subresource_states;
69 };
70 
71 /* Stores the current desired state of either an entire resource, or each subresource. */
72 struct d3d12_desired_resource_state
73 {
74    bool homogenous;
75    bool pending_memory_barrier;
76    uint32_t num_subresources;
77    D3D12_RESOURCE_STATES* subresource_states;
78 };
79 
80 struct d3d12_context_state_table_entry
81 {
82    struct d3d12_desired_resource_state desired;
83    struct d3d12_resource_state batch_begin, batch_end;
84 };
85 
86 
87 bool
88 d3d12_resource_state_init(d3d12_resource_state *state, uint32_t subresource_count, bool simultaneous_access);
89 
90 void
91 d3d12_resource_state_cleanup(d3d12_resource_state *state);
92 
93 void
94 d3d12_context_state_table_init(struct d3d12_context *ctx);
95 
96 void
97 d3d12_context_state_table_destroy(struct d3d12_context *ctx);
98 
99 bool
100 d3d12_context_state_resolve_submission(struct d3d12_context *ctx, struct d3d12_batch *batch);
101 
102 void
103 d3d12_destroy_context_state_table_entry(d3d12_context_state_table_entry* entry);
104 
105 #endif // D3D12_RESOURCE_STATE_H
106