~mmach/netext73/mesa-haswell

« back to all changes in this revision

Viewing changes to src/gallium/drivers/d3d12/d3d12_bufmgr.h

  • Committer: mmach
  • Date: 2022-09-22 19:56:13 UTC
  • Revision ID: netbit73@gmail.com-20220922195613-wtik9mmy20tmor0i
2022-09-22 21:17:09

Show diffs side-by-side

added added

removed removed

Lines of Context:
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_BUFMGR_H
25
 
#define D3D12_BUFMGR_H
26
 
 
27
 
#include "pipebuffer/pb_buffer.h"
28
 
#include "util/u_atomic.h"
29
 
#include "util/list.h"
30
 
 
31
 
#ifndef _WIN32
32
 
#include <wsl/winadapter.h>
33
 
#endif
34
 
 
35
 
#include <directx/d3d12.h>
36
 
 
37
 
struct d3d12_bufmgr;
38
 
struct d3d12_screen;
39
 
struct pb_manager;
40
 
struct TransitionableResourceState;
41
 
 
42
 
enum d3d12_residency_status {
43
 
   d3d12_evicted,
44
 
   d3d12_resident,
45
 
   d3d12_permanently_resident,
46
 
};
47
 
 
48
 
struct d3d12_bo {
49
 
   int refcount;
50
 
   ID3D12Resource *res;
51
 
   struct pb_buffer *buffer;
52
 
   struct TransitionableResourceState *trans_state;
53
 
 
54
 
   struct list_head residency_list_entry;
55
 
   uint64_t estimated_size;
56
 
   int64_t last_used_timestamp;
57
 
   uint64_t last_used_fence;
58
 
   enum d3d12_residency_status residency_status;
59
 
};
60
 
 
61
 
struct d3d12_buffer {
62
 
   struct pb_buffer base;
63
 
 
64
 
   struct d3d12_bo *bo;
65
 
   D3D12_RANGE range;
66
 
   void *map;
67
 
};
68
 
 
69
 
static inline struct d3d12_buffer *
70
 
d3d12_buffer(struct pb_buffer *buf)
71
 
{
72
 
   assert(buf);
73
 
   return (struct d3d12_buffer *)buf;
74
 
}
75
 
 
76
 
static inline struct d3d12_bo *
77
 
d3d12_bo_get_base(struct d3d12_bo *bo, uint64_t *offset)
78
 
{
79
 
   if (bo->buffer) {
80
 
      struct pb_buffer *base_buffer;
81
 
      pb_get_base_buffer(bo->buffer, &base_buffer, offset);
82
 
      return d3d12_buffer(base_buffer)->bo;
83
 
   } else {
84
 
      *offset = 0;
85
 
      return bo;
86
 
   }
87
 
}
88
 
 
89
 
static inline uint64_t
90
 
d3d12_bo_get_size(struct d3d12_bo *bo)
91
 
{
92
 
   if (bo->buffer)
93
 
      return bo->buffer->size;
94
 
   else
95
 
      return bo->res->GetDesc().Width;
96
 
}
97
 
 
98
 
static inline bool
99
 
d3d12_bo_is_suballocated(struct d3d12_bo *bo)
100
 
{
101
 
   struct d3d12_bo *base_bo;
102
 
   uint64_t offset;
103
 
 
104
 
   if (!bo->buffer)
105
 
      return false;
106
 
 
107
 
   base_bo = d3d12_bo_get_base(bo, &offset);
108
 
   return d3d12_bo_get_size(base_bo) != d3d12_bo_get_size(bo);
109
 
}
110
 
 
111
 
struct d3d12_bo *
112
 
d3d12_bo_new(struct d3d12_screen *screen, uint64_t size, uint64_t alignment);
113
 
 
114
 
struct d3d12_bo *
115
 
d3d12_bo_wrap_res(struct d3d12_screen *screen, ID3D12Resource *res, enum pipe_format format, enum d3d12_residency_status residency);
116
 
 
117
 
struct d3d12_bo *
118
 
d3d12_bo_wrap_buffer(struct pb_buffer *buf);
119
 
 
120
 
static inline void
121
 
d3d12_bo_reference(struct d3d12_bo *bo)
122
 
{
123
 
   p_atomic_inc(&bo->refcount);
124
 
}
125
 
 
126
 
void
127
 
d3d12_bo_unreference(struct d3d12_bo *bo);
128
 
 
129
 
void *
130
 
d3d12_bo_map(struct d3d12_bo *bo, D3D12_RANGE *range);
131
 
 
132
 
void
133
 
d3d12_bo_unmap(struct d3d12_bo *bo, D3D12_RANGE *range);
134
 
 
135
 
struct pb_manager *
136
 
d3d12_bufmgr_create(struct d3d12_screen *screen);
137
 
 
138
 
#endif