Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
vkShaderBuffer.cpp
Go to the documentation of this file.
1
2
5
8
11
13
14namespace Divide
15{
17 : ShaderBuffer( context, descriptor )
18 {
19 const size_t targetElementSize = Util::GetAlignmentCorrected( _params._elementSize, _alignmentRequirement );
20 if ( targetElementSize > _params._elementSize )
21 {
22 DIVIDE_ASSERT( (_params._elementSize * _params._elementCount) % _alignmentRequirement == 0u,
23 "ERROR: vkShaderBuffer - element size and count combo is less than the minimum alignment requirement for current hardware! Pad the element size and or count a bit" );
24 }
25 else
26 {
27 DIVIDE_ASSERT( _params._elementSize == targetElementSize,
28 "ERROR: vkShaderBuffer - element size is less than the minimum alignment requirement for current hardware! Pad the element size a bit" );
29 }
30
31 _alignedBufferSize = static_cast<ptrdiff_t>(realign_offset( _params._elementCount * _params._elementSize, _alignmentRequirement ));
32
33 const string bufferName = _name.empty() ? Util::StringFormat( "DVD_GENERAL_SHADER_BUFFER_{}", getGUID() ) : (_name + "_SHADER_BUFFER");
34
35 _bufferImpl = std::make_unique<vkBufferImpl>( _params,
36 _alignedBufferSize,
38 descriptor._initialData,
39 bufferName.c_str() );
40 }
41
43 {
44 if ( !_bufferImpl->waitForLockedRange( range ) )
45 {
47 }
48
49 const bool isCommandBuffer = getUsage() == BufferUsageType::COMMAND_BUFFER;
50 const VkAccessFlags2 dstAccessMask = VK_ACCESS_SHADER_READ_BIT | (isCommandBuffer ? VK_ACCESS_INDIRECT_COMMAND_READ_BIT : VK_ACCESS_NONE);
51 const VkPipelineStageFlags2 dstStageMask = VK_API::ALL_SHADER_STAGES | VK_PIPELINE_STAGE_TRANSFER_BIT | (isCommandBuffer ? VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT : VK_PIPELINE_STAGE_NONE);
52
53 LockGuard<Mutex> w_lock( _implLock );
54 return _bufferImpl->writeBytes(range, dstAccessMask, dstStageMask, data);
55 }
56
57 void vkShaderBuffer::readBytesInternal( BufferRange range, std::pair<bufferPtr, size_t> outData ) noexcept
58 {
59 if ( !_bufferImpl->waitForLockedRange( range ) )
60 {
62 }
63
64 range._length = std::min( std::min( range._length, outData.second ), _alignedBufferSize - range._startOffset );
65
66 LockGuard<Mutex> w_lock( _implLock );
67 _bufferImpl->readBytes(range, outData);
68 }
69
71 {
72 return _bufferImpl.get();
73 }
74
75}; //namespace Divide
#define DIVIDE_ASSERT(...)
#define DIVIDE_UNEXPECTED_CALL()
Rough around the edges Adapter pattern abstracting the actual rendering API and access to the GPU.
Definition: GFXDevice.h:215
FORCE_INLINE I64 getGUID() const noexcept
Definition: GUIDWrapper.h:51
U16 queueLength() const noexcept
Definition: RingBuffer.h:46
BufferParams _params
Definition: ShaderBuffer.h:92
static constexpr VkPipelineStageFlagBits2 ALL_SHADER_STAGES
Definition: VKWrapper.h:60
void readBytesInternal(BufferRange range, std::pair< bufferPtr, size_t > outData) noexcept override
LockableBuffer * getBufferImpl() override final
vkBufferImpl_uptr _bufferImpl
vkShaderBuffer(GFXDevice &context, const ShaderBufferDescriptor &descriptor)
BufferLock writeBytesInternal(BufferRange range, const bufferPtr data) noexcept override
Str StringFormat(const char *fmt, Args &&...args)
FORCE_INLINE size_t GetAlignmentCorrected(const size_t value, const size_t alignment) noexcept
Definition: MathHelper.inl:783
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
std::lock_guard< mutex > LockGuard
Definition: SharedMutex.h:55
constexpr size_t realign_offset(const size_t offset, const size_t align) noexcept
void * bufferPtr
size_t _elementSize
Buffer primitive size in bytes.
Definition: BufferParams.h:50
std::pair< bufferPtr, size_t > _initialData
Definition: ShaderBuffer.h:103