1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Copyright © Microsoft Corporation
3bf215546Sopenharmony_ci *
4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation
7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
10bf215546Sopenharmony_ci *
11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next
12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the
13bf215546Sopenharmony_ci * Software.
14bf215546Sopenharmony_ci *
15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20bf215546Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21bf215546Sopenharmony_ci * IN THE SOFTWARE.
22bf215546Sopenharmony_ci */
23bf215546Sopenharmony_ci
24bf215546Sopenharmony_ci#include "d3d12_bufmgr.h"
25bf215546Sopenharmony_ci#include "d3d12_context.h"
26bf215546Sopenharmony_ci#include "d3d12_format.h"
27bf215546Sopenharmony_ci#include "d3d12_screen.h"
28bf215546Sopenharmony_ci
29bf215546Sopenharmony_ci#include "pipebuffer/pb_buffer.h"
30bf215546Sopenharmony_ci#include "pipebuffer/pb_bufmgr.h"
31bf215546Sopenharmony_ci
32bf215546Sopenharmony_ci#include "util/format/u_format.h"
33bf215546Sopenharmony_ci#include "util/u_memory.h"
34bf215546Sopenharmony_ci
35bf215546Sopenharmony_ci#include <dxguids/dxguids.h>
36bf215546Sopenharmony_ci
37bf215546Sopenharmony_cistruct d3d12_bufmgr {
38bf215546Sopenharmony_ci   struct pb_manager base;
39bf215546Sopenharmony_ci
40bf215546Sopenharmony_ci   struct d3d12_screen *screen;
41bf215546Sopenharmony_ci};
42bf215546Sopenharmony_ci
43bf215546Sopenharmony_ciextern const struct pb_vtbl d3d12_buffer_vtbl;
44bf215546Sopenharmony_ci
45bf215546Sopenharmony_cistatic inline struct d3d12_bufmgr *
46bf215546Sopenharmony_cid3d12_bufmgr(struct pb_manager *mgr)
47bf215546Sopenharmony_ci{
48bf215546Sopenharmony_ci   assert(mgr);
49bf215546Sopenharmony_ci
50bf215546Sopenharmony_ci   return (struct d3d12_bufmgr *)mgr;
51bf215546Sopenharmony_ci}
52bf215546Sopenharmony_ci
53bf215546Sopenharmony_cistatic void
54bf215546Sopenharmony_cidescribe_direct_bo(char *buf, struct d3d12_bo *ptr)
55bf215546Sopenharmony_ci{
56bf215546Sopenharmony_ci   sprintf(buf, "d3d12_bo<direct,%p,0x%x>", ptr->res, (unsigned)ptr->estimated_size);
57bf215546Sopenharmony_ci}
58bf215546Sopenharmony_ci
59bf215546Sopenharmony_cistatic void
60bf215546Sopenharmony_cidescribe_suballoc_bo(char *buf, struct d3d12_bo *ptr)
61bf215546Sopenharmony_ci{
62bf215546Sopenharmony_ci   char res[128];
63bf215546Sopenharmony_ci   uint64_t offset;
64bf215546Sopenharmony_ci   d3d12_bo *base = d3d12_bo_get_base(ptr, &offset);
65bf215546Sopenharmony_ci   describe_direct_bo(res, base);
66bf215546Sopenharmony_ci   sprintf(buf, "d3d12_bo<suballoc<%s>,0x%x,0x%x>", res,
67bf215546Sopenharmony_ci           (unsigned)ptr->buffer->size, (unsigned)offset);
68bf215546Sopenharmony_ci}
69bf215546Sopenharmony_ci
70bf215546Sopenharmony_civoid
71bf215546Sopenharmony_cid3d12_debug_describe_bo(char *buf, struct d3d12_bo *ptr)
72bf215546Sopenharmony_ci{
73bf215546Sopenharmony_ci   if (ptr->buffer)
74bf215546Sopenharmony_ci      describe_suballoc_bo(buf, ptr);
75bf215546Sopenharmony_ci   else
76bf215546Sopenharmony_ci      describe_direct_bo(buf, ptr);
77bf215546Sopenharmony_ci}
78bf215546Sopenharmony_ci
79bf215546Sopenharmony_cistruct d3d12_bo *
80bf215546Sopenharmony_cid3d12_bo_wrap_res(struct d3d12_screen *screen, ID3D12Resource *res, enum d3d12_residency_status residency)
81bf215546Sopenharmony_ci{
82bf215546Sopenharmony_ci   struct d3d12_bo *bo;
83bf215546Sopenharmony_ci
84bf215546Sopenharmony_ci   bo = CALLOC_STRUCT(d3d12_bo);
85bf215546Sopenharmony_ci   if (!bo)
86bf215546Sopenharmony_ci      return NULL;
87bf215546Sopenharmony_ci
88bf215546Sopenharmony_ci   D3D12_RESOURCE_DESC desc = GetDesc(res);
89bf215546Sopenharmony_ci   unsigned array_size = desc.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D ? 1 : desc.DepthOrArraySize;
90bf215546Sopenharmony_ci   unsigned total_subresources = desc.MipLevels * array_size * d3d12_non_opaque_plane_count(desc.Format);
91bf215546Sopenharmony_ci   bool supports_simultaneous_access = d3d12_resource_supports_simultaneous_access(&desc);
92bf215546Sopenharmony_ci
93bf215546Sopenharmony_ci   pipe_reference_init(&bo->reference, 1);
94bf215546Sopenharmony_ci   bo->screen = screen;
95bf215546Sopenharmony_ci   bo->res = res;
96bf215546Sopenharmony_ci   bo->unique_id = p_atomic_inc_return(&screen->resource_id_generator);
97bf215546Sopenharmony_ci   if (!supports_simultaneous_access)
98bf215546Sopenharmony_ci      d3d12_resource_state_init(&bo->global_state, total_subresources, false);
99bf215546Sopenharmony_ci
100bf215546Sopenharmony_ci   bo->residency_status = residency;
101bf215546Sopenharmony_ci   bo->last_used_timestamp = 0;
102bf215546Sopenharmony_ci   screen->dev->GetCopyableFootprints(&desc, 0, total_subresources, 0, nullptr, nullptr, nullptr, &bo->estimated_size);
103bf215546Sopenharmony_ci   if (residency != d3d12_evicted) {
104bf215546Sopenharmony_ci      mtx_lock(&screen->submit_mutex);
105bf215546Sopenharmony_ci      list_add(&bo->residency_list_entry, &screen->residency_list);
106bf215546Sopenharmony_ci      mtx_unlock(&screen->submit_mutex);
107bf215546Sopenharmony_ci   }
108bf215546Sopenharmony_ci
109bf215546Sopenharmony_ci   return bo;
110bf215546Sopenharmony_ci}
111bf215546Sopenharmony_ci
112bf215546Sopenharmony_cistruct d3d12_bo *
113bf215546Sopenharmony_cid3d12_bo_new(struct d3d12_screen *screen, uint64_t size, const pb_desc *pb_desc)
114bf215546Sopenharmony_ci{
115bf215546Sopenharmony_ci   ID3D12Device *dev = screen->dev;
116bf215546Sopenharmony_ci   ID3D12Resource *res;
117bf215546Sopenharmony_ci
118bf215546Sopenharmony_ci   D3D12_RESOURCE_DESC res_desc;
119bf215546Sopenharmony_ci   res_desc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER;
120bf215546Sopenharmony_ci   res_desc.Format = DXGI_FORMAT_UNKNOWN;
121bf215546Sopenharmony_ci   res_desc.Alignment = 0;
122bf215546Sopenharmony_ci   res_desc.Width = size;
123bf215546Sopenharmony_ci   res_desc.Height = 1;
124bf215546Sopenharmony_ci   res_desc.DepthOrArraySize = 1;
125bf215546Sopenharmony_ci   res_desc.MipLevels = 1;
126bf215546Sopenharmony_ci   res_desc.SampleDesc.Count = 1;
127bf215546Sopenharmony_ci   res_desc.SampleDesc.Quality = 0;
128bf215546Sopenharmony_ci   res_desc.Flags = D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS;
129bf215546Sopenharmony_ci   res_desc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR;
130bf215546Sopenharmony_ci
131bf215546Sopenharmony_ci   D3D12_HEAP_TYPE heap_type = D3D12_HEAP_TYPE_DEFAULT;
132bf215546Sopenharmony_ci   if (pb_desc->usage & PB_USAGE_CPU_READ)
133bf215546Sopenharmony_ci      heap_type = D3D12_HEAP_TYPE_READBACK;
134bf215546Sopenharmony_ci   else if (pb_desc->usage & PB_USAGE_CPU_WRITE)
135bf215546Sopenharmony_ci      heap_type = D3D12_HEAP_TYPE_UPLOAD;
136bf215546Sopenharmony_ci
137bf215546Sopenharmony_ci   D3D12_HEAP_FLAGS heap_flags = screen->support_create_not_resident ?
138bf215546Sopenharmony_ci      D3D12_HEAP_FLAG_CREATE_NOT_RESIDENT : D3D12_HEAP_FLAG_NONE;
139bf215546Sopenharmony_ci   enum d3d12_residency_status init_residency = screen->support_create_not_resident ?
140bf215546Sopenharmony_ci      d3d12_evicted : d3d12_resident;
141bf215546Sopenharmony_ci
142bf215546Sopenharmony_ci   D3D12_HEAP_PROPERTIES heap_pris = GetCustomHeapProperties(dev, heap_type);
143bf215546Sopenharmony_ci   HRESULT hres = dev->CreateCommittedResource(&heap_pris,
144bf215546Sopenharmony_ci                                               heap_flags,
145bf215546Sopenharmony_ci                                               &res_desc,
146bf215546Sopenharmony_ci                                               D3D12_RESOURCE_STATE_COMMON,
147bf215546Sopenharmony_ci                                               NULL,
148bf215546Sopenharmony_ci                                               IID_PPV_ARGS(&res));
149bf215546Sopenharmony_ci
150bf215546Sopenharmony_ci   if (FAILED(hres))
151bf215546Sopenharmony_ci      return NULL;
152bf215546Sopenharmony_ci
153bf215546Sopenharmony_ci   return d3d12_bo_wrap_res(screen, res, init_residency);
154bf215546Sopenharmony_ci}
155bf215546Sopenharmony_ci
156bf215546Sopenharmony_cistruct d3d12_bo *
157bf215546Sopenharmony_cid3d12_bo_wrap_buffer(struct d3d12_screen *screen, struct pb_buffer *buf)
158bf215546Sopenharmony_ci{
159bf215546Sopenharmony_ci   struct d3d12_bo *bo;
160bf215546Sopenharmony_ci
161bf215546Sopenharmony_ci   bo = CALLOC_STRUCT(d3d12_bo);
162bf215546Sopenharmony_ci   if (!bo)
163bf215546Sopenharmony_ci      return NULL;
164bf215546Sopenharmony_ci
165bf215546Sopenharmony_ci   pipe_reference_init(&bo->reference, 1);
166bf215546Sopenharmony_ci   bo->screen = screen;
167bf215546Sopenharmony_ci   bo->buffer = buf;
168bf215546Sopenharmony_ci   bo->unique_id = p_atomic_inc_return(&screen->resource_id_generator);
169bf215546Sopenharmony_ci   bo->residency_status = d3d12_evicted;
170bf215546Sopenharmony_ci
171bf215546Sopenharmony_ci   return bo;
172bf215546Sopenharmony_ci}
173bf215546Sopenharmony_ci
174bf215546Sopenharmony_civoid
175bf215546Sopenharmony_cid3d12_bo_unreference(struct d3d12_bo *bo)
176bf215546Sopenharmony_ci{
177bf215546Sopenharmony_ci   if (bo == NULL)
178bf215546Sopenharmony_ci      return;
179bf215546Sopenharmony_ci
180bf215546Sopenharmony_ci   assert(pipe_is_referenced(&bo->reference));
181bf215546Sopenharmony_ci
182bf215546Sopenharmony_ci   if (pipe_reference_described(&bo->reference, NULL,
183bf215546Sopenharmony_ci                                (debug_reference_descriptor)
184bf215546Sopenharmony_ci                                d3d12_debug_describe_bo)) {
185bf215546Sopenharmony_ci      if (bo->buffer)
186bf215546Sopenharmony_ci         pb_reference(&bo->buffer, NULL);
187bf215546Sopenharmony_ci
188bf215546Sopenharmony_ci      mtx_lock(&bo->screen->submit_mutex);
189bf215546Sopenharmony_ci
190bf215546Sopenharmony_ci      if (bo->residency_status != d3d12_evicted)
191bf215546Sopenharmony_ci         list_del(&bo->residency_list_entry);
192bf215546Sopenharmony_ci
193bf215546Sopenharmony_ci      /* MSVC's offsetof fails when the name is ambiguous between struct and function */
194bf215546Sopenharmony_ci      typedef struct d3d12_context d3d12_context_type;
195bf215546Sopenharmony_ci      list_for_each_entry(d3d12_context_type, ctx, &bo->screen->context_list, context_list_entry)
196bf215546Sopenharmony_ci         util_dynarray_append(&ctx->recently_destroyed_bos, uint64_t, bo->unique_id);
197bf215546Sopenharmony_ci
198bf215546Sopenharmony_ci      mtx_unlock(&bo->screen->submit_mutex);
199bf215546Sopenharmony_ci
200bf215546Sopenharmony_ci      d3d12_resource_state_cleanup(&bo->global_state);
201bf215546Sopenharmony_ci      if (bo->res)
202bf215546Sopenharmony_ci         bo->res->Release();
203bf215546Sopenharmony_ci      FREE(bo);
204bf215546Sopenharmony_ci   }
205bf215546Sopenharmony_ci}
206bf215546Sopenharmony_ci
207bf215546Sopenharmony_civoid *
208bf215546Sopenharmony_cid3d12_bo_map(struct d3d12_bo *bo, D3D12_RANGE *range)
209bf215546Sopenharmony_ci{
210bf215546Sopenharmony_ci   struct d3d12_bo *base_bo;
211bf215546Sopenharmony_ci   D3D12_RANGE offset_range = {0, 0};
212bf215546Sopenharmony_ci   uint64_t offset;
213bf215546Sopenharmony_ci   void *ptr;
214bf215546Sopenharmony_ci
215bf215546Sopenharmony_ci   base_bo = d3d12_bo_get_base(bo, &offset);
216bf215546Sopenharmony_ci
217bf215546Sopenharmony_ci   if (!range || range->Begin >= range->End) {
218bf215546Sopenharmony_ci      offset_range.Begin = offset;
219bf215546Sopenharmony_ci      offset_range.End = offset + d3d12_bo_get_size(bo);
220bf215546Sopenharmony_ci      range = &offset_range;
221bf215546Sopenharmony_ci   } else {
222bf215546Sopenharmony_ci      offset_range.Begin = range->Begin + offset;
223bf215546Sopenharmony_ci      offset_range.End = range->End + offset;
224bf215546Sopenharmony_ci      range = &offset_range;
225bf215546Sopenharmony_ci   }
226bf215546Sopenharmony_ci
227bf215546Sopenharmony_ci   if (FAILED(base_bo->res->Map(0, range, &ptr)))
228bf215546Sopenharmony_ci      return NULL;
229bf215546Sopenharmony_ci
230bf215546Sopenharmony_ci   return (uint8_t *)ptr + (range ? range->Begin : 0);
231bf215546Sopenharmony_ci}
232bf215546Sopenharmony_ci
233bf215546Sopenharmony_civoid
234bf215546Sopenharmony_cid3d12_bo_unmap(struct d3d12_bo *bo, D3D12_RANGE *range)
235bf215546Sopenharmony_ci{
236bf215546Sopenharmony_ci   struct d3d12_bo *base_bo;
237bf215546Sopenharmony_ci   D3D12_RANGE offset_range = {0, 0};
238bf215546Sopenharmony_ci   uint64_t offset;
239bf215546Sopenharmony_ci
240bf215546Sopenharmony_ci   base_bo = d3d12_bo_get_base(bo, &offset);
241bf215546Sopenharmony_ci
242bf215546Sopenharmony_ci   if (!range || range->Begin >= range->End) {
243bf215546Sopenharmony_ci      offset_range.Begin = offset;
244bf215546Sopenharmony_ci      offset_range.End = offset + d3d12_bo_get_size(bo);
245bf215546Sopenharmony_ci      range = &offset_range;
246bf215546Sopenharmony_ci   } else {
247bf215546Sopenharmony_ci      offset_range.Begin = range->Begin + offset;
248bf215546Sopenharmony_ci      offset_range.End = range->End + offset;
249bf215546Sopenharmony_ci      range = &offset_range;
250bf215546Sopenharmony_ci   }
251bf215546Sopenharmony_ci
252bf215546Sopenharmony_ci   base_bo->res->Unmap(0, range);
253bf215546Sopenharmony_ci}
254bf215546Sopenharmony_ci
255bf215546Sopenharmony_cistatic void
256bf215546Sopenharmony_cid3d12_buffer_destroy(void *winsys, struct pb_buffer *pbuf)
257bf215546Sopenharmony_ci{
258bf215546Sopenharmony_ci   struct d3d12_buffer *buf = d3d12_buffer(pbuf);
259bf215546Sopenharmony_ci
260bf215546Sopenharmony_ci   if (buf->map)
261bf215546Sopenharmony_ci      d3d12_bo_unmap(buf->bo, &buf->range);
262bf215546Sopenharmony_ci   d3d12_bo_unreference(buf->bo);
263bf215546Sopenharmony_ci   FREE(buf);
264bf215546Sopenharmony_ci}
265bf215546Sopenharmony_ci
266bf215546Sopenharmony_cistatic void *
267bf215546Sopenharmony_cid3d12_buffer_map(struct pb_buffer *pbuf,
268bf215546Sopenharmony_ci                 enum pb_usage_flags flags,
269bf215546Sopenharmony_ci                 void *flush_ctx)
270bf215546Sopenharmony_ci{
271bf215546Sopenharmony_ci   return d3d12_buffer(pbuf)->map;
272bf215546Sopenharmony_ci}
273bf215546Sopenharmony_ci
274bf215546Sopenharmony_cistatic void
275bf215546Sopenharmony_cid3d12_buffer_unmap(struct pb_buffer *pbuf)
276bf215546Sopenharmony_ci{
277bf215546Sopenharmony_ci}
278bf215546Sopenharmony_ci
279bf215546Sopenharmony_cistatic void
280bf215546Sopenharmony_cid3d12_buffer_get_base_buffer(struct pb_buffer *buf,
281bf215546Sopenharmony_ci                             struct pb_buffer **base_buf,
282bf215546Sopenharmony_ci                             pb_size *offset)
283bf215546Sopenharmony_ci{
284bf215546Sopenharmony_ci   *base_buf = buf;
285bf215546Sopenharmony_ci   *offset = 0;
286bf215546Sopenharmony_ci}
287bf215546Sopenharmony_ci
288bf215546Sopenharmony_cistatic enum pipe_error
289bf215546Sopenharmony_cid3d12_buffer_validate(struct pb_buffer *pbuf,
290bf215546Sopenharmony_ci                      struct pb_validate *vl,
291bf215546Sopenharmony_ci                      enum pb_usage_flags flags )
292bf215546Sopenharmony_ci{
293bf215546Sopenharmony_ci   /* Always pinned */
294bf215546Sopenharmony_ci   return PIPE_OK;
295bf215546Sopenharmony_ci}
296bf215546Sopenharmony_ci
297bf215546Sopenharmony_cistatic void
298bf215546Sopenharmony_cid3d12_buffer_fence(struct pb_buffer *pbuf,
299bf215546Sopenharmony_ci                   struct pipe_fence_handle *fence )
300bf215546Sopenharmony_ci{
301bf215546Sopenharmony_ci}
302bf215546Sopenharmony_ci
303bf215546Sopenharmony_ciconst struct pb_vtbl d3d12_buffer_vtbl = {
304bf215546Sopenharmony_ci   d3d12_buffer_destroy,
305bf215546Sopenharmony_ci   d3d12_buffer_map,
306bf215546Sopenharmony_ci   d3d12_buffer_unmap,
307bf215546Sopenharmony_ci   d3d12_buffer_validate,
308bf215546Sopenharmony_ci   d3d12_buffer_fence,
309bf215546Sopenharmony_ci   d3d12_buffer_get_base_buffer
310bf215546Sopenharmony_ci};
311bf215546Sopenharmony_ci
312bf215546Sopenharmony_cistatic struct pb_buffer *
313bf215546Sopenharmony_cid3d12_bufmgr_create_buffer(struct pb_manager *pmgr,
314bf215546Sopenharmony_ci                           pb_size size,
315bf215546Sopenharmony_ci                           const struct pb_desc *pb_desc)
316bf215546Sopenharmony_ci{
317bf215546Sopenharmony_ci   struct d3d12_bufmgr *mgr = d3d12_bufmgr(pmgr);
318bf215546Sopenharmony_ci   struct d3d12_buffer *buf;
319bf215546Sopenharmony_ci
320bf215546Sopenharmony_ci   buf = CALLOC_STRUCT(d3d12_buffer);
321bf215546Sopenharmony_ci   if (!buf)
322bf215546Sopenharmony_ci      return NULL;
323bf215546Sopenharmony_ci
324bf215546Sopenharmony_ci   // Align the buffer to D3D12_CONSTANT_BUFFER_DATA_PLACEMENT_ALIGNMENT
325bf215546Sopenharmony_ci   // in case it is to be used as a CBV.
326bf215546Sopenharmony_ci   size = align64(size, D3D12_CONSTANT_BUFFER_DATA_PLACEMENT_ALIGNMENT);
327bf215546Sopenharmony_ci
328bf215546Sopenharmony_ci   pipe_reference_init(&buf->base.reference, 1);
329bf215546Sopenharmony_ci   buf->base.alignment_log2 = util_logbase2(pb_desc->alignment);
330bf215546Sopenharmony_ci   buf->base.usage = pb_desc->usage;
331bf215546Sopenharmony_ci   buf->base.vtbl = &d3d12_buffer_vtbl;
332bf215546Sopenharmony_ci   buf->base.size = size;
333bf215546Sopenharmony_ci   buf->range.Begin = 0;
334bf215546Sopenharmony_ci   buf->range.End = size;
335bf215546Sopenharmony_ci
336bf215546Sopenharmony_ci   buf->bo = d3d12_bo_new(mgr->screen, size, pb_desc);
337bf215546Sopenharmony_ci   if (!buf->bo) {
338bf215546Sopenharmony_ci      FREE(buf);
339bf215546Sopenharmony_ci      return NULL;
340bf215546Sopenharmony_ci   }
341bf215546Sopenharmony_ci
342bf215546Sopenharmony_ci   if (pb_desc->usage & PB_USAGE_CPU_READ_WRITE) {
343bf215546Sopenharmony_ci      buf->map = d3d12_bo_map(buf->bo, &buf->range);
344bf215546Sopenharmony_ci      if (!buf->map) {
345bf215546Sopenharmony_ci         d3d12_bo_unreference(buf->bo);
346bf215546Sopenharmony_ci         FREE(buf);
347bf215546Sopenharmony_ci         return NULL;
348bf215546Sopenharmony_ci      }
349bf215546Sopenharmony_ci   }
350bf215546Sopenharmony_ci
351bf215546Sopenharmony_ci   return &buf->base;
352bf215546Sopenharmony_ci}
353bf215546Sopenharmony_ci
354bf215546Sopenharmony_cistatic void
355bf215546Sopenharmony_cid3d12_bufmgr_flush(struct pb_manager *mgr)
356bf215546Sopenharmony_ci{
357bf215546Sopenharmony_ci   /* No-op */
358bf215546Sopenharmony_ci}
359bf215546Sopenharmony_ci
360bf215546Sopenharmony_cistatic void
361bf215546Sopenharmony_cid3d12_bufmgr_destroy(struct pb_manager *_mgr)
362bf215546Sopenharmony_ci{
363bf215546Sopenharmony_ci   struct d3d12_bufmgr *mgr = d3d12_bufmgr(_mgr);
364bf215546Sopenharmony_ci   FREE(mgr);
365bf215546Sopenharmony_ci}
366bf215546Sopenharmony_ci
367bf215546Sopenharmony_cistatic boolean
368bf215546Sopenharmony_cid3d12_bufmgr_is_buffer_busy(struct pb_manager *_mgr, struct pb_buffer *_buf)
369bf215546Sopenharmony_ci{
370bf215546Sopenharmony_ci   /* We're only asked this on buffers that are known not busy */
371bf215546Sopenharmony_ci   return false;
372bf215546Sopenharmony_ci}
373bf215546Sopenharmony_ci
374bf215546Sopenharmony_cistruct pb_manager *
375bf215546Sopenharmony_cid3d12_bufmgr_create(struct d3d12_screen *screen)
376bf215546Sopenharmony_ci{
377bf215546Sopenharmony_ci   struct d3d12_bufmgr *mgr;
378bf215546Sopenharmony_ci
379bf215546Sopenharmony_ci   mgr = CALLOC_STRUCT(d3d12_bufmgr);
380bf215546Sopenharmony_ci   if (!mgr)
381bf215546Sopenharmony_ci      return NULL;
382bf215546Sopenharmony_ci
383bf215546Sopenharmony_ci   mgr->base.destroy = d3d12_bufmgr_destroy;
384bf215546Sopenharmony_ci   mgr->base.create_buffer = d3d12_bufmgr_create_buffer;
385bf215546Sopenharmony_ci   mgr->base.flush = d3d12_bufmgr_flush;
386bf215546Sopenharmony_ci   mgr->base.is_buffer_busy = d3d12_bufmgr_is_buffer_busy;
387bf215546Sopenharmony_ci
388bf215546Sopenharmony_ci   mgr->screen = screen;
389bf215546Sopenharmony_ci
390bf215546Sopenharmony_ci   return &mgr->base;
391bf215546Sopenharmony_ci}
392