/
BoundingBox.h
50 lines (40 loc) · 1.36 KB
/
BoundingBox.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright 2019 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#pragma once
#include <memory>
#include "VideoBackends/D3D12/D3DBase.h"
#include "VideoBackends/D3D12/DescriptorHeapManager.h"
namespace DX12
{
class StreamBuffer;
class BoundingBox
{
public:
~BoundingBox();
static std::unique_ptr<BoundingBox> Create();
const DescriptorHandle& GetGPUDescriptor() const { return m_gpu_descriptor; }
s32 Get(size_t index);
void Set(size_t index, s32 value);
void Invalidate();
void Flush();
private:
static const u32 NUM_VALUES = 4;
static const u32 BUFFER_SIZE = sizeof(u32) * NUM_VALUES;
static const u32 MAX_UPDATES_PER_FRAME = 128;
static const u32 STREAM_BUFFER_SIZE = BUFFER_SIZE * MAX_UPDATES_PER_FRAME;
BoundingBox();
bool CreateBuffers();
void Readback();
// Three buffers: One on the GPU for read/write, one on the CPU for reading back, and a third for
// streaming changes. We use a stream buffer so we don't need to block when two bbox updates are
// within a single command buffer.
ComPtr<ID3D12Resource> m_gpu_buffer;
ComPtr<ID3D12Resource> m_readback_buffer;
std::unique_ptr<StreamBuffer> m_stream_buffer;
DescriptorHandle m_gpu_descriptor;
std::array<s32, NUM_VALUES> m_values = {};
std::array<bool, NUM_VALUES> m_dirty = {};
bool m_valid = true;
};
}; // namespace DX12