Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
stenzek
GitHub Repository: stenzek/duckstation
Path: blob/master/src/util/d3d11_stream_buffer.h
4223 views
1
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <[email protected]>
2
// SPDX-License-Identifier: CC-BY-NC-ND-4.0
3
4
#pragma once
5
6
#include "common/types.h"
7
#include "common/windows_headers.h"
8
9
#include <d3d11_1.h>
10
#include <wrl/client.h>
11
12
class Error;
13
14
class D3D11StreamBuffer
15
{
16
public:
17
template<typename T>
18
using ComPtr = Microsoft::WRL::ComPtr<T>;
19
20
D3D11StreamBuffer();
21
D3D11StreamBuffer(ComPtr<ID3D11Buffer> buffer);
22
~D3D11StreamBuffer();
23
24
ALWAYS_INLINE ID3D11Buffer* GetD3DBuffer() const { return m_buffer.Get(); }
25
ALWAYS_INLINE ID3D11Buffer* const* GetD3DBufferArray() const { return m_buffer.GetAddressOf(); }
26
ALWAYS_INLINE u32 GetSize() const { return m_size; }
27
ALWAYS_INLINE u32 GetPosition() const { return m_position; }
28
ALWAYS_INLINE bool IsMapped() const { return m_mapped; }
29
ALWAYS_INLINE bool IsUsingMapNoOverwrite() const { return m_use_map_no_overwrite; }
30
31
bool Create(D3D11_BIND_FLAG bind_flags, u32 min_size, u32 max_size, Error* error);
32
void Destroy();
33
34
struct MappingResult
35
{
36
void* pointer;
37
u32 buffer_offset;
38
u32 index_aligned; // offset / alignment, suitable for base vertex
39
u32 space_aligned; // remaining space / alignment
40
};
41
42
MappingResult Map(ID3D11DeviceContext1* context, u32 alignment, u32 min_size);
43
void Unmap(ID3D11DeviceContext1* context, u32 used_size);
44
45
private:
46
ComPtr<ID3D11Buffer> m_buffer;
47
u32 m_size = 0;
48
u32 m_max_size = 0;
49
u32 m_position = 0;
50
bool m_use_map_no_overwrite = false;
51
bool m_mapped = false;
52
};
53
54