Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
ShaderBuffer.h
Go to the documentation of this file.
1/*
2Copyright (c) 2018 DIVIDE-Studio
3Copyright (c) 2009 Ionut Cava
4
5This file is part of DIVIDE Framework.
6
7Permission is hereby granted, free of charge, to any person obtaining a copy of
8this software
9and associated documentation files (the "Software"), to deal in the Software
10without restriction,
11including without limitation the rights to use, copy, modify, merge, publish,
12distribute, sublicense,
13and/or sell copies of the Software, and to permit persons to whom the Software
14is furnished to do so,
15subject to the following conditions:
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21IMPLIED,
22INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23PARTICULAR PURPOSE AND NONINFRINGEMENT.
24IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25DAMAGES OR OTHER LIABILITY,
26WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
27CONNECTION WITH THE SOFTWARE
28OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30*/
31
32#pragma once
33#ifndef DVD_SHADER_BUFFER_H_
34#define DVD_SHADER_BUFFER_H_
35
39namespace Divide {
40
41struct ShaderBufferDescriptor;
42
43namespace Attorney {
44 class ShaderBufferBind;
45};
46
47class ShaderProgram;
49 public GraphicsResource,
51
52{
53 friend class Attorney::ShaderBufferBind;
54
55 public:
56 explicit ShaderBuffer(GFXDevice& context, const ShaderBufferDescriptor& descriptor);
57
58 void readData(BufferRange range, std::pair<bufferPtr, size_t> outData);
59 void readBytes(BufferRange range, std::pair<bufferPtr, size_t> outData);
60 [[nodiscard]] BufferLock clearData(BufferRange range);
61 [[nodiscard]] BufferLock clearBytes(BufferRange range);
62 [[nodiscard]] BufferLock writeData(BufferRange range, const bufferPtr data);
63 [[nodiscard]] BufferLock writeBytes(BufferRange range, const bufferPtr data);
64
65 [[nodiscard]] BufferUpdateUsage getUpdateUsage() const noexcept;
66 [[nodiscard]] BufferUpdateFrequency getUpdateFrequency() const noexcept;
67
68 [[nodiscard]] FORCE_INLINE I32 getStartIndex(const bool read) const noexcept { return (read ? queueReadIndex() : queueWriteIndex()); }
69 [[nodiscard]] FORCE_INLINE size_t getStartOffset(const bool read) const noexcept { return to_size(std::max(0, getStartIndex(read))) * _alignedBufferSize; }
70 [[nodiscard]] FORCE_INLINE U32 getPrimitiveCount() const noexcept { return _params._elementCount; }
71 [[nodiscard]] FORCE_INLINE size_t getPrimitiveSize() const noexcept { return _params._elementSize; }
72 [[nodiscard]] FORCE_INLINE BufferUsageType getUsage() const noexcept { return _params._flags._usageType; }
73
74 FORCE_INLINE BufferLock writeData(const bufferPtr data) { return writeData({ 0u, _params._elementCount }, data); }
75 FORCE_INLINE BufferLock clearData() { return clearData({ 0u, _params._elementCount }); }
76
77 [[nodiscard]] virtual LockableBuffer* getBufferImpl() = 0;
78
79 [[nodiscard]] static size_t AlignmentRequirement( BufferUsageType usage) noexcept;
80
81 PROPERTY_R(size_t, alignedBufferSize, 0u);
82 PROPERTY_R(size_t, alignmentRequirement, sizeof(U32));
83
84 PROPERTY_R(string, name);
85 PROPERTY_R(U64, lastWrittenFrame, 0u);
86 PROPERTY_R(U64, lastReadFrame, 0u);
87 protected:
88 virtual void readBytesInternal(BufferRange range, std::pair<bufferPtr, size_t> outData) = 0;
89 virtual BufferLock writeBytesInternal(BufferRange range, const bufferPtr data) = 0;
90
91 protected:
93 size_t _maxSize{ 0u };
94 U64 _lastWriteFrameNumber{ 0u };
95};
96
103 std::pair<bufferPtr, size_t> _initialData{nullptr, 0u};
104 string _name{ "" };
106 bool _separateReadWrite{ false };
107};
108
109FWD_DECLARE_MANAGED_CLASS(ShaderBuffer);
110
111}; // namespace Divide
112#endif //DVD_SHADER_BUFFER_H_
#define FWD_DECLARE_MANAGED_CLASS(T)
#define NOINITVTABLE
#define FORCE_INLINE
Rough around the edges Adapter pattern abstracting the actual rendering API and access to the GPU.
Definition: GFXDevice.h:215
Utility class that adds basic GUID management to objects.
Definition: GUIDWrapper.h:44
virtual void readBytesInternal(BufferRange range, std::pair< bufferPtr, size_t > outData)=0
PROPERTY_R(U64, lastReadFrame, 0u)
PROPERTY_R(size_t, alignmentRequirement, sizeof(U32))
FORCE_INLINE BufferLock writeData(const bufferPtr data)
Definition: ShaderBuffer.h:74
FORCE_INLINE BufferUsageType getUsage() const noexcept
Definition: ShaderBuffer.h:72
FORCE_INLINE U32 getPrimitiveCount() const noexcept
Definition: ShaderBuffer.h:70
virtual LockableBuffer * getBufferImpl()=0
PROPERTY_R(size_t, alignedBufferSize, 0u)
FORCE_INLINE size_t getPrimitiveSize() const noexcept
Definition: ShaderBuffer.h:71
FORCE_INLINE size_t getStartOffset(const bool read) const noexcept
Definition: ShaderBuffer.h:69
virtual BufferLock writeBytesInternal(BufferRange range, const bufferPtr data)=0
BufferParams _params
Definition: ShaderBuffer.h:92
FORCE_INLINE BufferLock clearData()
Definition: ShaderBuffer.h:75
PROPERTY_R(U64, lastWrittenFrame, 0u)
PROPERTY_R(string, name)
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
BufferUpdateFrequency
int32_t I32
uint16_t U16
constexpr size_t to_size(const T value)
uint32_t U32
void * bufferPtr
uint64_t U64
std::pair< bufferPtr, size_t > _initialData
Definition: ShaderBuffer.h:103
bool _separateReadWrite
Use a separate read/write index based on queue length.
Definition: ShaderBuffer.h:106