2
* Copyright © Microsoft Corporation
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:
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
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
24
#ifndef D3D12_BUFMGR_H
25
#define D3D12_BUFMGR_H
27
#include "pipebuffer/pb_buffer.h"
28
#include "util/u_atomic.h"
29
#include "util/list.h"
32
#include <wsl/winadapter.h>
35
#include <directx/d3d12.h>
40
struct TransitionableResourceState;
42
enum d3d12_residency_status {
45
d3d12_permanently_resident,
51
struct pb_buffer *buffer;
52
struct TransitionableResourceState *trans_state;
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;
62
struct pb_buffer base;
69
static inline struct d3d12_buffer *
70
d3d12_buffer(struct pb_buffer *buf)
73
return (struct d3d12_buffer *)buf;
76
static inline struct d3d12_bo *
77
d3d12_bo_get_base(struct d3d12_bo *bo, uint64_t *offset)
80
struct pb_buffer *base_buffer;
81
pb_get_base_buffer(bo->buffer, &base_buffer, offset);
82
return d3d12_buffer(base_buffer)->bo;
89
static inline uint64_t
90
d3d12_bo_get_size(struct d3d12_bo *bo)
93
return bo->buffer->size;
95
return bo->res->GetDesc().Width;
99
d3d12_bo_is_suballocated(struct d3d12_bo *bo)
101
struct d3d12_bo *base_bo;
107
base_bo = d3d12_bo_get_base(bo, &offset);
108
return d3d12_bo_get_size(base_bo) != d3d12_bo_get_size(bo);
112
d3d12_bo_new(struct d3d12_screen *screen, uint64_t size, uint64_t alignment);
115
d3d12_bo_wrap_res(struct d3d12_screen *screen, ID3D12Resource *res, enum pipe_format format, enum d3d12_residency_status residency);
118
d3d12_bo_wrap_buffer(struct pb_buffer *buf);
121
d3d12_bo_reference(struct d3d12_bo *bo)
123
p_atomic_inc(&bo->refcount);
127
d3d12_bo_unreference(struct d3d12_bo *bo);
130
d3d12_bo_map(struct d3d12_bo *bo, D3D12_RANGE *range);
133
d3d12_bo_unmap(struct d3d12_bo *bo, D3D12_RANGE *range);
136
d3d12_bufmgr_create(struct d3d12_screen *screen);