Change the folder structure of the vulkan backend to better reflect what is going on
This commit is contained in:
parent
4638cc44d2
commit
295eb252ab
37 changed files with 119 additions and 110 deletions
123
src/common/rendering/vulkan/vk_streambuffer.cpp
Normal file
123
src/common/rendering/vulkan/vk_streambuffer.cpp
Normal file
|
|
@ -0,0 +1,123 @@
|
|||
/*
|
||||
** Vulkan backend
|
||||
** Copyright (c) 2016-2020 Magnus Norddahl
|
||||
**
|
||||
** This software is provided 'as-is', without any express or implied
|
||||
** warranty. In no event will the authors be held liable for any damages
|
||||
** arising from the use of this software.
|
||||
**
|
||||
** Permission is granted to anyone to use this software for any purpose,
|
||||
** including commercial applications, and to alter it and redistribute it
|
||||
** freely, subject to the following restrictions:
|
||||
**
|
||||
** 1. The origin of this software must not be misrepresented; you must not
|
||||
** claim that you wrote the original software. If you use this software
|
||||
** in a product, an acknowledgment in the product documentation would be
|
||||
** appreciated but is not required.
|
||||
** 2. Altered source versions must be plainly marked as such, and must not be
|
||||
** misrepresented as being the original software.
|
||||
** 3. This notice may not be removed or altered from any source distribution.
|
||||
**
|
||||
*/
|
||||
|
||||
#include "vk_renderstate.h"
|
||||
#include "vulkan/vk_renderdevice.h"
|
||||
#include "vulkan/vk_streambuffer.h"
|
||||
#include "vulkan/buffers/vk_buffer.h"
|
||||
#include <zvulkan/vulkanbuilders.h>
|
||||
|
||||
VkStreamBufferWriter::VkStreamBufferWriter(VulkanRenderDevice* fb)
|
||||
{
|
||||
mBuffer = fb->GetBufferManager()->StreamBuffer.get();
|
||||
}
|
||||
|
||||
bool VkStreamBufferWriter::Write(const StreamData& data)
|
||||
{
|
||||
mDataIndex++;
|
||||
if (mDataIndex == MAX_STREAM_DATA)
|
||||
{
|
||||
mDataIndex = 0;
|
||||
mStreamDataOffset = mBuffer->NextStreamDataBlock();
|
||||
if (mStreamDataOffset == 0xffffffff)
|
||||
return false;
|
||||
}
|
||||
uint8_t* ptr = (uint8_t*)mBuffer->UniformBuffer->Memory();
|
||||
memcpy(ptr + mStreamDataOffset + sizeof(StreamData) * mDataIndex, &data, sizeof(StreamData));
|
||||
return true;
|
||||
}
|
||||
|
||||
void VkStreamBufferWriter::Reset()
|
||||
{
|
||||
mDataIndex = MAX_STREAM_DATA - 1;
|
||||
mStreamDataOffset = 0;
|
||||
mBuffer->Reset();
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
VkMatrixBufferWriter::VkMatrixBufferWriter(VulkanRenderDevice* fb)
|
||||
{
|
||||
mBuffer = fb->GetBufferManager()->MatrixBuffer.get();
|
||||
mIdentityMatrix.loadIdentity();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static void BufferedSet(bool& modified, T& dst, const T& src)
|
||||
{
|
||||
if (dst == src)
|
||||
return;
|
||||
dst = src;
|
||||
modified = true;
|
||||
}
|
||||
|
||||
static void BufferedSet(bool& modified, VSMatrix& dst, const VSMatrix& src)
|
||||
{
|
||||
if (memcmp(dst.get(), src.get(), sizeof(FLOATTYPE) * 16) == 0)
|
||||
return;
|
||||
dst = src;
|
||||
modified = true;
|
||||
}
|
||||
|
||||
bool VkMatrixBufferWriter::Write(const VSMatrix& modelMatrix, bool modelMatrixEnabled, const VSMatrix& textureMatrix, bool textureMatrixEnabled)
|
||||
{
|
||||
bool modified = (mOffset == 0); // always modified first call
|
||||
|
||||
if (modelMatrixEnabled)
|
||||
{
|
||||
BufferedSet(modified, mMatrices.ModelMatrix, modelMatrix);
|
||||
if (modified)
|
||||
mMatrices.NormalModelMatrix.computeNormalMatrix(modelMatrix);
|
||||
}
|
||||
else
|
||||
{
|
||||
BufferedSet(modified, mMatrices.ModelMatrix, mIdentityMatrix);
|
||||
BufferedSet(modified, mMatrices.NormalModelMatrix, mIdentityMatrix);
|
||||
}
|
||||
|
||||
if (textureMatrixEnabled)
|
||||
{
|
||||
BufferedSet(modified, mMatrices.TextureMatrix, textureMatrix);
|
||||
}
|
||||
else
|
||||
{
|
||||
BufferedSet(modified, mMatrices.TextureMatrix, mIdentityMatrix);
|
||||
}
|
||||
|
||||
if (modified)
|
||||
{
|
||||
mOffset = mBuffer->NextStreamDataBlock();
|
||||
if (mOffset == 0xffffffff)
|
||||
return false;
|
||||
|
||||
uint8_t* ptr = (uint8_t*)mBuffer->UniformBuffer->Memory();
|
||||
memcpy(ptr + mOffset, &mMatrices, sizeof(MatricesUBO));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void VkMatrixBufferWriter::Reset()
|
||||
{
|
||||
mOffset = 0;
|
||||
mBuffer->Reset();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue