Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/gallium/drivers/d3d12/d3d12_resource.h
4570 views
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_H
25
#define D3D12_RESOURCE_H
26
27
struct pipe_screen;
28
#include "d3d12_bufmgr.h"
29
#include "util/u_range.h"
30
#include "util/u_transfer.h"
31
32
#include <directx/d3d12.h>
33
34
enum d3d12_resource_binding_type {
35
D3D12_RESOURCE_BINDING_TYPE_SRV,
36
D3D12_RESOURCE_BINDING_TYPE_CBV,
37
D3D12_RESOURCE_BINDING_TYPES
38
};
39
40
struct d3d12_resource {
41
struct pipe_resource base;
42
struct d3d12_bo *bo;
43
DXGI_FORMAT dxgi_format;
44
unsigned mip_levels;
45
struct sw_displaytarget *dt;
46
unsigned dt_stride;
47
struct util_range valid_buffer_range;
48
uint32_t bind_counts[PIPE_SHADER_TYPES][D3D12_RESOURCE_BINDING_TYPES];
49
};
50
51
struct d3d12_transfer {
52
struct pipe_transfer base;
53
struct pipe_resource *staging_res;
54
void *data;
55
};
56
57
static inline struct d3d12_resource *
58
d3d12_resource(struct pipe_resource *r)
59
{
60
return (struct d3d12_resource *)r;
61
}
62
63
/* Returns the underlying ID3D12Resource and offset for this resource */
64
static inline ID3D12Resource *
65
d3d12_resource_underlying(struct d3d12_resource *res, uint64_t *offset)
66
{
67
if (!res->bo)
68
return NULL;
69
70
return d3d12_bo_get_base(res->bo, offset)->res;
71
}
72
73
/* Returns the underlying ID3D12Resource for this resource. */
74
static inline ID3D12Resource *
75
d3d12_resource_resource(struct d3d12_resource *res)
76
{
77
ID3D12Resource *ret;
78
uint64_t offset;
79
ret = d3d12_resource_underlying(res, &offset);
80
return ret;
81
}
82
83
static inline struct TransitionableResourceState *
84
d3d12_resource_state(struct d3d12_resource *res)
85
{
86
uint64_t offset;
87
if (!res->bo)
88
return NULL;
89
return d3d12_bo_get_base(res->bo, &offset)->trans_state;
90
}
91
92
static inline D3D12_GPU_VIRTUAL_ADDRESS
93
d3d12_resource_gpu_virtual_address(struct d3d12_resource *res)
94
{
95
uint64_t offset;
96
ID3D12Resource *base_res = d3d12_resource_underlying(res, &offset);
97
return base_res->GetGPUVirtualAddress() + offset;
98
}
99
100
static inline bool
101
d3d12_subresource_id_uses_layer(enum pipe_texture_target target)
102
{
103
return target == PIPE_TEXTURE_CUBE ||
104
target == PIPE_TEXTURE_1D_ARRAY ||
105
target == PIPE_TEXTURE_2D_ARRAY;
106
}
107
108
void
109
d3d12_resource_release(struct d3d12_resource *res);
110
111
void
112
d3d12_resource_wait_idle(struct d3d12_context *ctx,
113
struct d3d12_resource *res);
114
115
void
116
d3d12_resource_make_writeable(struct pipe_context *pctx,
117
struct pipe_resource *pres);
118
119
void
120
d3d12_screen_resource_init(struct pipe_screen *pscreen);
121
122
void
123
d3d12_context_resource_init(struct pipe_context *pctx);
124
125
#endif
126
127