More folder adjustments
This commit is contained in:
parent
295eb252ab
commit
cd35a0ad76
10 changed files with 15 additions and 13 deletions
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
#include "vk_buffer.h"
|
||||
#include "vk_hwbuffer.h"
|
||||
#include "vulkan/vk_streambuffer.h"
|
||||
#include "vk_streambuffer.h"
|
||||
#include "hwrenderer/data/shaderuniforms.h"
|
||||
|
||||
VkBufferManager::VkBufferManager(VulkanRenderDevice* fb) : fb(fb)
|
||||
|
|
|
|||
123
src/common/rendering/vulkan/buffers/vk_streambuffer.cpp
Normal file
123
src/common/rendering/vulkan/buffers/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_streambuffer.h"
|
||||
#include "vulkan/vk_renderstate.h"
|
||||
#include "vulkan/vk_renderdevice.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();
|
||||
}
|
||||
42
src/common/rendering/vulkan/buffers/vk_streambuffer.h
Normal file
42
src/common/rendering/vulkan/buffers/vk_streambuffer.h
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "vulkan/buffers/vk_hwbuffer.h"
|
||||
#include "vulkan/shaders/vk_shader.h"
|
||||
|
||||
class VkStreamBuffer;
|
||||
class VkMatrixBuffer;
|
||||
|
||||
class VkStreamBufferWriter
|
||||
{
|
||||
public:
|
||||
VkStreamBufferWriter(VulkanRenderDevice* fb);
|
||||
|
||||
bool Write(const StreamData& data);
|
||||
void Reset();
|
||||
|
||||
uint32_t DataIndex() const { return mDataIndex; }
|
||||
uint32_t StreamDataOffset() const { return mStreamDataOffset; }
|
||||
|
||||
private:
|
||||
VkStreamBuffer* mBuffer;
|
||||
uint32_t mDataIndex = MAX_STREAM_DATA - 1;
|
||||
uint32_t mStreamDataOffset = 0;
|
||||
};
|
||||
|
||||
class VkMatrixBufferWriter
|
||||
{
|
||||
public:
|
||||
VkMatrixBufferWriter(VulkanRenderDevice* fb);
|
||||
|
||||
bool Write(const VSMatrix& modelMatrix, bool modelMatrixEnabled, const VSMatrix& textureMatrix, bool textureMatrixEnabled);
|
||||
void Reset();
|
||||
|
||||
uint32_t Offset() const { return mOffset; }
|
||||
|
||||
private:
|
||||
VkStreamBuffer* mBuffer;
|
||||
MatricesUBO mMatrices = {};
|
||||
VSMatrix mIdentityMatrix;
|
||||
uint32_t mOffset = 0;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue