3700 FPS here we go
This commit is contained in:
@@ -265,6 +265,18 @@ UniformBuffer::~UniformBuffer()
|
||||
{
|
||||
}
|
||||
|
||||
bool UniformBuffer::updateContents(const BulkResourceData &resourceData)
|
||||
{
|
||||
if(!Gfx::UniformBuffer::updateContents(resourceData))
|
||||
{
|
||||
// no update was performed, skip
|
||||
return false;
|
||||
}
|
||||
void* data = lock();
|
||||
std::memcpy(data, resourceData.data, resourceData.size);
|
||||
unlock();
|
||||
return true;
|
||||
}
|
||||
void* UniformBuffer::lock(bool bWriteOnly)
|
||||
{
|
||||
if(dedicatedStagingBuffer != nullptr)
|
||||
|
||||
@@ -92,11 +92,9 @@ void CmdBuffer::executeCommands(Array<Gfx::PRenderCommand> commands)
|
||||
{
|
||||
auto command = commands[i].cast<SecondaryCmdBuffer>();
|
||||
// Cache array and size to save on pointer access
|
||||
DescriptorSet** boundDescriptors = command->boundDescriptors.data();
|
||||
size_t numDescriptors = command->boundDescriptors.size();
|
||||
for(size_t i = 0; i < numDescriptors; ++i)
|
||||
for(auto boundDescriptor : command->boundDescriptors)
|
||||
{
|
||||
boundDescriptors[i]->currentlyBound = true;
|
||||
boundDescriptor->currentlyBound = this;
|
||||
}
|
||||
command->end();
|
||||
executingCommands.add(command);
|
||||
@@ -182,11 +180,9 @@ void SecondaryCmdBuffer::end()
|
||||
void SecondaryCmdBuffer::reset()
|
||||
{
|
||||
vkResetCommandBuffer(handle, VK_COMMAND_BUFFER_RESET_RELEASE_RESOURCES_BIT);
|
||||
size_t numBoundDescriptors = boundDescriptors.size();
|
||||
DescriptorSet** boundDescriptorSets = boundDescriptors.data();
|
||||
for(size_t i = 0; i < numBoundDescriptors; ++i)
|
||||
for(auto boundDescriptor : boundDescriptors)
|
||||
{
|
||||
boundDescriptorSets[i]->currentlyBound = false;
|
||||
boundDescriptor->currentlyBound = nullptr;
|
||||
}
|
||||
boundDescriptors.clear();
|
||||
ready = true;
|
||||
|
||||
@@ -116,16 +116,17 @@ void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PUniformBuffer uniformBu
|
||||
{
|
||||
PUniformBuffer vulkanBuffer = uniformBuffer.cast<UniformBuffer>();
|
||||
UniformBuffer* cachedBuffer = reinterpret_cast<UniformBuffer*>(cachedData[Gfx::currentFrameIndex][binding]);
|
||||
if(vulkanBuffer->isDataEquals(cachedBuffer))
|
||||
/*if(vulkanBuffer->isDataEquals(cachedBuffer))
|
||||
{
|
||||
std::cout << "uniform data equal, skip" << std::endl;
|
||||
return;
|
||||
}
|
||||
}*/
|
||||
bufferInfos.add(init::DescriptorBufferInfo(vulkanBuffer->getHandle(), 0, vulkanBuffer->getSize()));
|
||||
|
||||
VkWriteDescriptorSet writeDescriptor = init::WriteDescriptorSet(setHandle[Gfx::currentFrameIndex], VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, binding, &bufferInfos.back());
|
||||
writeDescriptors.add(writeDescriptor);
|
||||
|
||||
cachedData[Gfx::currentFrameIndex][binding] = vulkanBuffer.getHandle();
|
||||
cachedData[Gfx::currentFrameIndex][binding] = new UniformBuffer(*vulkanBuffer.getHandle());
|
||||
}
|
||||
|
||||
void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PStructuredBuffer uniformBuffer)
|
||||
@@ -171,10 +172,8 @@ void DescriptorSet::updateTexture(uint32_t binding, Gfx::PTexture texture, Gfx::
|
||||
TextureHandle* cachedTexture = reinterpret_cast<TextureHandle*>(cachedData[Gfx::currentFrameIndex][binding]);
|
||||
if(vulkanTexture == cachedTexture)
|
||||
{
|
||||
std::cout << "Cached texture is same as new one, skipping update" << std::endl;
|
||||
return;
|
||||
}
|
||||
std::cout << "Texture changed, updating" << std::endl;
|
||||
//It is assumed that the image is in the correct layout
|
||||
VkDescriptorImageInfo imageInfo =
|
||||
init::DescriptorImageInfo(
|
||||
@@ -187,7 +186,12 @@ void DescriptorSet::updateTexture(uint32_t binding, Gfx::PTexture texture, Gfx::
|
||||
imageInfo.sampler = vulkanSampler->sampler;
|
||||
}
|
||||
imageInfos.add(imageInfo);
|
||||
VkWriteDescriptorSet writeDescriptor = init::WriteDescriptorSet(setHandle[Gfx::currentFrameIndex], samplerState != nullptr ? VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER : VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, binding, &imageInfos.back());
|
||||
VkWriteDescriptorSet writeDescriptor =
|
||||
init::WriteDescriptorSet(
|
||||
setHandle[Gfx::currentFrameIndex],
|
||||
samplerState != nullptr ? VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER : VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
|
||||
binding,
|
||||
&imageInfos.back());
|
||||
if (vulkanTexture->getUsage() & VK_IMAGE_USAGE_STORAGE_BIT)
|
||||
{
|
||||
writeDescriptor.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
|
||||
@@ -212,7 +216,11 @@ void DescriptorSet::writeChanges()
|
||||
{
|
||||
if (writeDescriptors.size() > 0)
|
||||
{
|
||||
assert(!isCurrentlyBound());
|
||||
if(isCurrentlyBound())
|
||||
{
|
||||
graphics->getGraphicsCommands()->waitForCommands(currentlyBound);
|
||||
currentlyBound = nullptr;
|
||||
}
|
||||
vkUpdateDescriptorSets(graphics->getDevice(), (uint32)writeDescriptors.size(), writeDescriptors.data(), 0, nullptr);
|
||||
writeDescriptors.clear();
|
||||
imageInfos.clear();
|
||||
|
||||
@@ -73,7 +73,7 @@ public:
|
||||
|
||||
inline bool isCurrentlyBound() const
|
||||
{
|
||||
return currentlyBound;
|
||||
return currentlyBound != nullptr;
|
||||
}
|
||||
inline bool isCurrentlyInUse() const
|
||||
{
|
||||
@@ -90,8 +90,8 @@ public:
|
||||
virtual uint32 getSetIndex() const;
|
||||
|
||||
private:
|
||||
Array<VkDescriptorImageInfo> imageInfos;
|
||||
Array<VkDescriptorBufferInfo> bufferInfos;
|
||||
List<VkDescriptorImageInfo> imageInfos;
|
||||
List<VkDescriptorBufferInfo> bufferInfos;
|
||||
Array<VkWriteDescriptorSet> writeDescriptors;
|
||||
// contains the previously bound resources at every binding
|
||||
// since the layout is fixed, trying to bind a texture to a buffer
|
||||
@@ -100,7 +100,7 @@ private:
|
||||
VkDescriptorSet setHandle[Gfx::numFramesBuffered];
|
||||
PGraphics graphics;
|
||||
PDescriptorAllocator owner;
|
||||
bool currentlyBound;
|
||||
PCmdBuffer currentlyBound;
|
||||
bool currentlyInUse;
|
||||
friend class DescriptorAllocator;
|
||||
friend class CmdBuffer;
|
||||
|
||||
@@ -49,13 +49,6 @@ void QueueOwnedResourceDeletion::run()
|
||||
}
|
||||
}
|
||||
|
||||
void UniformBuffer::updateContents(const BulkResourceData &resourceData)
|
||||
{
|
||||
Gfx::UniformBuffer::updateContents(resourceData);
|
||||
void* data = lock();
|
||||
std::memcpy(data, resourceData.data, resourceData.size);
|
||||
unlock();
|
||||
}
|
||||
|
||||
Semaphore::Semaphore(PGraphics graphics)
|
||||
: graphics(graphics)
|
||||
|
||||
@@ -133,7 +133,7 @@ class UniformBuffer : public Gfx::UniformBuffer, public ShaderBuffer
|
||||
public:
|
||||
UniformBuffer(PGraphics graphics, const UniformBufferCreateInfo &resourceData);
|
||||
virtual ~UniformBuffer();
|
||||
virtual void updateContents(const BulkResourceData &resourceData);
|
||||
virtual bool updateContents(const BulkResourceData &resourceData);
|
||||
|
||||
virtual void* lock(bool bWriteOnly = true) override;
|
||||
virtual void unlock() override;
|
||||
|
||||
@@ -213,6 +213,11 @@ void Window::present()
|
||||
presentResult = vkQueuePresentKHR(graphics->getGraphicsCommands()->getQueue()->getHandle(), &info);
|
||||
}
|
||||
Gfx::currentFrameIndex = (Gfx::currentFrameIndex + 1)%Gfx::numFramesBuffered;
|
||||
static double lastFrameTime = 0.f;
|
||||
double currentTime = glfwGetTime();
|
||||
double currentDelta = currentTime - lastFrameTime;
|
||||
Gfx::currentFrameDelta = currentDelta;
|
||||
lastFrameTime = currentTime;
|
||||
}
|
||||
|
||||
void Window::createSwapchain()
|
||||
|
||||
Reference in New Issue
Block a user