d3d11_stream_buffer.h (1506B)
1 // SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com> 2 // SPDX-License-Identifier: (GPL-3.0 OR PolyForm-Strict-1.0.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 D3D11StreamBuffer 13 { 14 public: 15 template<typename T> 16 using ComPtr = Microsoft::WRL::ComPtr<T>; 17 18 D3D11StreamBuffer(); 19 D3D11StreamBuffer(ComPtr<ID3D11Buffer> buffer); 20 ~D3D11StreamBuffer(); 21 22 ALWAYS_INLINE ID3D11Buffer* GetD3DBuffer() const { return m_buffer.Get(); } 23 ALWAYS_INLINE ID3D11Buffer* const* GetD3DBufferArray() const { return m_buffer.GetAddressOf(); } 24 ALWAYS_INLINE u32 GetSize() const { return m_size; } 25 ALWAYS_INLINE u32 GetPosition() const { return m_position; } 26 ALWAYS_INLINE bool IsMapped() const { return m_mapped; } 27 ALWAYS_INLINE bool IsUsingMapNoOverwrite() const { return m_use_map_no_overwrite; } 28 29 bool Create(D3D11_BIND_FLAG bind_flags, u32 min_size, u32 max_size); 30 void Destroy(); 31 32 struct MappingResult 33 { 34 void* pointer; 35 u32 buffer_offset; 36 u32 index_aligned; // offset / alignment, suitable for base vertex 37 u32 space_aligned; // remaining space / alignment 38 }; 39 40 MappingResult Map(ID3D11DeviceContext1* context, u32 alignment, u32 min_size); 41 void Unmap(ID3D11DeviceContext1* context, u32 used_size); 42 43 private: 44 ComPtr<ID3D11Buffer> m_buffer; 45 u32 m_size = 0; 46 u32 m_max_size = 0; 47 u32 m_position = 0; 48 bool m_use_map_no_overwrite = false; 49 bool m_mapped = false; 50 };