mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-09 10:47:53 +02:00
Fixed vertex and index buffers
This commit is contained in:
parent
1e6d3b7be4
commit
f026e40e9f
8 changed files with 151 additions and 15 deletions
|
@ -19,6 +19,7 @@
|
|||
// For hash_combine
|
||||
#include <RegisteredMetaTypes.h>
|
||||
|
||||
#include <gpu/TextureTable.h>
|
||||
#include <vk/Helpers.h>
|
||||
#include <vk/Version.h>
|
||||
#include <vk/Pipelines.h>
|
||||
|
@ -313,6 +314,8 @@ struct Cache {
|
|||
VK_CHECK_RESULT(vkCreateDescriptorSetLayout(context.device->logicalDevice, &descriptorSetLayoutCI, nullptr, &descriptorSetLayout));
|
||||
layouts.push_back(descriptorSetLayout);
|
||||
layout.textureLayout = descriptorSetLayout;
|
||||
} else {
|
||||
printf("empty");
|
||||
}
|
||||
if (!stoLayout.empty()) {
|
||||
VkDescriptorSetLayoutCreateInfo descriptorSetLayoutCI = vks::initializers::descriptorSetLayoutCreateInfo(stoLayout.data(), stoLayout.size());
|
||||
|
@ -482,6 +485,7 @@ struct Cache {
|
|||
// Input assembly
|
||||
{
|
||||
auto& ia = builder.inputAssemblyState;
|
||||
// VKTODO: this looks unfinished
|
||||
// ia.primitiveRestartEnable = ???
|
||||
// ia.topology = vk::PrimitiveTopology::eTriangleList; ???
|
||||
}
|
||||
|
@ -602,9 +606,13 @@ void VKBackend::executeFrame(const FramePointer& frame) {
|
|||
// Create descriptor pool
|
||||
// VKTODO: delete descriptor pool after it's not needed
|
||||
//_frameData._descriptorPool
|
||||
int batch_count = 0;
|
||||
{
|
||||
const auto& commandBuffer = _currentCommandBuffer;
|
||||
for (const auto& batchPtr : frame->batches) {
|
||||
if (batch_count == 6) {//12
|
||||
return;
|
||||
}
|
||||
const auto& batch = *batchPtr;
|
||||
cmdBeginLabel(commandBuffer, "batch:" + batch.getName(), glm::vec4{ 1, 1, 0, 1 });
|
||||
const auto& commands = batch.getCommands();
|
||||
|
@ -737,6 +745,7 @@ void VKBackend::executeFrame(const FramePointer& frame) {
|
|||
renderpassActive = false;
|
||||
}
|
||||
cmdEndLabel(commandBuffer);
|
||||
batch_count++;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -838,7 +847,16 @@ void VKBackend::TransformStageState::bindCurrentCamera(int eye, VKBackend::Unifo
|
|||
}
|
||||
|
||||
void VKBackend::do_resetStages(const Batch& batch, size_t paramOffset) {
|
||||
//VKTODO
|
||||
//VKTODO: make sure all stages are reset
|
||||
//VKTODO: should inout stage be reset here?
|
||||
resetUniformStage();
|
||||
resetTextureStage();
|
||||
resetResourceStage();
|
||||
resetQueryStage();
|
||||
//resetInputStage();
|
||||
//resetPipelineStage();
|
||||
//resetTransformStage();
|
||||
//resetOutputStage();
|
||||
}
|
||||
|
||||
void VKBackend::do_disableContextViewCorrection(const Batch& batch, size_t paramOffset) {
|
||||
|
@ -1059,6 +1077,45 @@ void VKBackend::releaseUniformBuffer(uint32_t slot) {
|
|||
bufferState.reset();
|
||||
}
|
||||
|
||||
void VKBackend::resetUniformStage() {
|
||||
for (auto &buffer: _uniform._buffers) {
|
||||
buffer.reset();
|
||||
}
|
||||
}
|
||||
|
||||
void VKBackend::bindResourceTexture(uint32_t slot, const gpu::TexturePointer& texture) {
|
||||
qDebug() << "bindResourceTexture: " << slot;
|
||||
if (!texture) {
|
||||
releaseResourceTexture(slot);
|
||||
return;
|
||||
}
|
||||
// check cache before thinking
|
||||
if (_resource._textures[slot].texture == texture.get()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// One more True texture bound
|
||||
_stats._RSNumTextureBounded++;
|
||||
|
||||
// Always make sure the VKObject is in sync
|
||||
// VKTODO
|
||||
//VKTexture* object = syncGPUObject(resourceTexture);
|
||||
//if (object) {
|
||||
//uint32_t to = object->_texture;
|
||||
//uint32_t target = object->_target;
|
||||
//glActiveTexture(VK_TEXTURE0 + slot);
|
||||
//glBindTexture(target, to);
|
||||
|
||||
_resource._textures[slot].texture = texture.get();
|
||||
|
||||
//_stats._RSAmountTextureMemoryBounded += object->size();
|
||||
|
||||
//} else {
|
||||
// releaseResourceTexture(slot);
|
||||
// return;
|
||||
//}
|
||||
}
|
||||
|
||||
void VKBackend::releaseResourceTexture(uint32_t slot) {
|
||||
auto& textureState = _resource._textures[slot];
|
||||
if (valid(textureState.texture)) {
|
||||
|
@ -1070,6 +1127,12 @@ void VKBackend::releaseResourceTexture(uint32_t slot) {
|
|||
}
|
||||
}
|
||||
|
||||
void VKBackend::resetTextureStage() {
|
||||
for (auto &texture : _resource._textures) {
|
||||
texture.reset();
|
||||
}
|
||||
}
|
||||
|
||||
void VKBackend::releaseResourceBuffer(uint32_t slot) {
|
||||
auto& bufferReference = _resource._buffers[slot].buffer;
|
||||
auto buffer = acquire(bufferReference);
|
||||
|
@ -1084,6 +1147,16 @@ void VKBackend::releaseResourceBuffer(uint32_t slot) {
|
|||
}
|
||||
}
|
||||
|
||||
void VKBackend::resetResourceStage() {
|
||||
for (auto &buffer : _resource._buffers) {
|
||||
buffer.reset();
|
||||
}
|
||||
}
|
||||
|
||||
void VKBackend::resetQueryStage() {
|
||||
_queryStage._rangeQueryDepth = 0;
|
||||
}
|
||||
|
||||
void VKBackend::renderPassTransfer(const Batch& batch) {
|
||||
const size_t numCommands = batch.getCommands().size();
|
||||
const Batch::Commands::value_type* command = batch.getCommands().data();
|
||||
|
@ -1092,12 +1165,12 @@ void VKBackend::renderPassTransfer(const Batch& batch) {
|
|||
_inRenderTransferPass = true;
|
||||
{ // Sync all the buffers
|
||||
PROFILE_RANGE(gpu_vk_detail, "syncGPUBuffer");
|
||||
|
||||
for (auto& cached : batch._buffers._items) {
|
||||
// VKTODO: this is filling entire GPU VRAM for some reason
|
||||
/*for (auto& cached : batch._buffers._items) {
|
||||
if (cached._data) {
|
||||
syncGPUObject(*cached._data);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
{ // Sync all the buffers
|
||||
|
@ -1534,7 +1607,7 @@ void VKBackend::createDescriptorPool() {
|
|||
VkDescriptorPoolCreateInfo descriptorPoolCI = {};
|
||||
descriptorPoolCI.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
|
||||
descriptorPoolCI.flags = 0;
|
||||
descriptorPoolCI.maxSets = 1000;
|
||||
descriptorPoolCI.maxSets = 10000;
|
||||
descriptorPoolCI.poolSizeCount = (uint32_t)poolSizes.size();
|
||||
descriptorPoolCI.pPoolSizes = poolSizes.data();
|
||||
|
||||
|
@ -2407,6 +2480,19 @@ void VKBackend::do_setResourceTexture(const Batch& batch, size_t paramOffset) {
|
|||
//}
|
||||
}
|
||||
|
||||
void VKBackend::do_setResourceTextureTable(const gpu::Batch& batch, size_t paramOffset) {
|
||||
const auto& textureTablePointer = batch._textureTables.get(batch._params[paramOffset]._uint);
|
||||
if (!textureTablePointer) {
|
||||
return;
|
||||
}
|
||||
|
||||
const auto& textureTable = *textureTablePointer;
|
||||
const auto& textures = textureTable.getTextures();
|
||||
for (uint32_t slot = 0; slot < textures.size(); ++slot) {
|
||||
bindResourceTexture(slot, textures[slot]);
|
||||
}
|
||||
}
|
||||
|
||||
void VKBackend::do_setResourceFramebufferSwapChainTexture(const Batch& batch, size_t paramOffset) {
|
||||
/*uint32_t slot = batch._params[paramOffset + 1]._uint;
|
||||
if (slot >= MAX_NUM_RESOURCE_TEXTURES) {
|
||||
|
|
|
@ -210,15 +210,25 @@ protected:
|
|||
|
||||
void updateVkDescriptorWriteSetsUniform(VkDescriptorSet target);
|
||||
void releaseUniformBuffer(uint32_t slot);
|
||||
void resetUniformStage();
|
||||
|
||||
// VKTODO
|
||||
struct ResourceStageState {
|
||||
struct TextureState {
|
||||
TextureReference texture{};
|
||||
TextureState& operator=(const TextureState& other) = delete;
|
||||
void reset() {
|
||||
gpu::reset(texture);
|
||||
}
|
||||
};
|
||||
struct BufferState {
|
||||
BufferReference buffer{};
|
||||
vks::Buffer *vksBuffer{};
|
||||
BufferState& operator=(const BufferState& other) = delete;
|
||||
void reset() {
|
||||
gpu::reset(buffer);
|
||||
gpu::reset(vksBuffer);
|
||||
}
|
||||
};
|
||||
std::array<BufferState, MAX_NUM_RESOURCE_BUFFERS> _buffers{};
|
||||
std::array<TextureState, MAX_NUM_RESOURCE_TEXTURES> _textures{};
|
||||
|
@ -226,10 +236,13 @@ protected:
|
|||
} _resource;
|
||||
|
||||
void updateVkDescriptorWriteSetsTexture(VkDescriptorSet target);
|
||||
void bindResourceTexture(uint32_t slot, const TexturePointer& texture);
|
||||
void releaseResourceTexture(uint32_t slot);
|
||||
void resetTextureStage();
|
||||
|
||||
void updateVkDescriptorWriteSetsStorage(VkDescriptorSet target);
|
||||
void releaseResourceBuffer(uint32_t slot);
|
||||
void resetResourceStage();
|
||||
|
||||
// VKTODO
|
||||
struct OutputStageState {
|
||||
|
@ -238,11 +251,11 @@ protected:
|
|||
} _output;
|
||||
|
||||
// VKTODO
|
||||
void resetQueryStage();
|
||||
struct QueryStageState {
|
||||
uint32_t _rangeQueryDepth{ 0 };
|
||||
} _queryStage;
|
||||
|
||||
void resetQueryStage();
|
||||
|
||||
// VKTODO: one instance per each frame
|
||||
// Contains objects that are created per frame and need to be deleted after the frame is rendered
|
||||
|
@ -323,7 +336,7 @@ public:
|
|||
// Resource Stage
|
||||
virtual void do_setResourceBuffer(const Batch& batch, size_t paramOffset) final;
|
||||
virtual void do_setResourceTexture(const Batch& batch, size_t paramOffset) final;
|
||||
virtual void do_setResourceTextureTable(const Batch& batch, size_t paramOffset) {};
|
||||
virtual void do_setResourceTextureTable(const Batch& batch, size_t paramOffset) final;
|
||||
virtual void do_setResourceFramebufferSwapChainTexture(const Batch& batch, size_t paramOffset) final;
|
||||
|
||||
// Pipeline Stage
|
||||
|
|
|
@ -25,6 +25,7 @@ VKBuffer* VKBuffer::sync(VKBackend& backend, const gpu::Buffer& buffer) {
|
|||
if (!object || object->_stamp != buffer._renderSysmem.getStamp()) {
|
||||
object = new VKBuffer(backend, buffer);
|
||||
}
|
||||
// VKTODO: delete the old buffer after rendering the frame
|
||||
|
||||
return object;
|
||||
}
|
||||
|
@ -45,6 +46,10 @@ VKBuffer::VKBuffer(VKBackend& backend, const gpu::Buffer& gpuBuffer) : VKObject(
|
|||
// VKTODO:
|
||||
(vks::Buffer&)(*this) =
|
||||
backend._context.createBuffer(usageFlags, gpuBuffer.getSize(), VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
|
||||
map();
|
||||
copy(gpuBuffer.getSize(), gpuBuffer.getData());
|
||||
flush(VK_WHOLE_SIZE);
|
||||
unmap();
|
||||
|
||||
Backend::bufferCount.increment();
|
||||
Backend::bufferGPUMemSize.update(0, size);
|
||||
|
|
|
@ -195,7 +195,10 @@ void VKAttachmentTexture::createTexture() {
|
|||
imageCI.arrayLayers = _gpuObject.isArray() ? _gpuObject.getNumSlices() : 1;
|
||||
imageCI.samples = VK_SAMPLE_COUNT_1_BIT;
|
||||
imageCI.tiling = VK_IMAGE_TILING_OPTIMAL;
|
||||
if (_gpuObject.isColorRenderTarget() || _gpuObject.getTexelFormat().getSemantic() == gpu::R11G11B10) {
|
||||
if (_gpuObject.isColorRenderTarget()
|
||||
|| _gpuObject.getTexelFormat().getSemantic() == gpu::R11G11B10
|
||||
|| _gpuObject.getTexelFormat().getSemantic() == gpu::SRGB
|
||||
|| _gpuObject.getTexelFormat().getSemantic() == gpu::SRGBA) {
|
||||
imageCI.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
|
||||
} else if (_gpuObject.isDepthStencilRenderTarget()) {
|
||||
imageCI.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
|
||||
|
|
|
@ -534,11 +534,13 @@ Buffer Context::createBuffer(const VkBufferUsageFlags& usageFlags,
|
|||
};
|
||||
|
||||
#if VULKAN_USE_VMA
|
||||
VmaAllocationCreateInfo allocInfo = {};
|
||||
allocInfo.requiredFlags = memoryPropertyFlags;
|
||||
VmaAllocationCreateInfo allocationCI = {};
|
||||
//allocationCI.requiredFlags = memoryPropertyFlags; //VKTODO: this will replace allocationCI.usage probably
|
||||
allocationCI.usage = VMA_MEMORY_USAGE_CPU_TO_GPU; // VKTODO: different kind will be required later for device-local memory
|
||||
allocationCI.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT;
|
||||
auto pCreateInfo = &createInfo;
|
||||
auto pBuffer = &result.buffer;
|
||||
VK_CHECK_RESULT(vmaCreateBuffer(Allocation::getAllocator(), pCreateInfo, &allocInfo,
|
||||
VK_CHECK_RESULT(vmaCreateBuffer(Allocation::getAllocator(), pCreateInfo, &allocationCI,
|
||||
pBuffer, &result.allocation, nullptr));
|
||||
#else
|
||||
result.descriptor.buffer = result.buffer = device.createBuffer(bufferCreateInfo);
|
||||
|
|
|
@ -108,9 +108,11 @@ namespace vks {
|
|||
VkPipelineDepthStencilStateCreateInfo{} {
|
||||
sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
|
||||
if (depthEnable) {
|
||||
depthTestEnable = VK_TRUE;
|
||||
//depthTestEnable = VK_TRUE; //VKTODO
|
||||
depthTestEnable = VK_FALSE;
|
||||
depthWriteEnable = VK_TRUE;
|
||||
depthCompareOp = VK_COMPARE_OP_LESS_OR_EQUAL;
|
||||
//depthCompareOp = VK_COMPARE_OP_LESS_OR_EQUAL; //VKTODO
|
||||
depthCompareOp = VK_COMPARE_OP_ALWAYS;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -16,6 +16,10 @@
|
|||
#include <gl/QOpenGLContextWrapper.h>
|
||||
#endif
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include "/home/ksuprynowicz/programy/renderdoc_1.35/include/renderdoc_app.h"
|
||||
RENDERDOC_API_1_1_2 *rdoc_api = NULL;
|
||||
|
||||
void RenderThread::submitFrame(const gpu::FramePointer& frame) {
|
||||
std::unique_lock<std::mutex> lock(_frameLock);
|
||||
_pendingFrames.push(frame);
|
||||
|
@ -32,6 +36,13 @@ void RenderThread::move(const glm::vec3& v) {
|
|||
}
|
||||
|
||||
void RenderThread::initialize(QWindow* window) {
|
||||
if(void *mod = dlopen("/home/ksuprynowicz/programy/renderdoc_1.35/lib/librenderdoc.so", RTLD_NOW | RTLD_NOLOAD))
|
||||
{
|
||||
pRENDERDOC_GetAPI RENDERDOC_GetAPI = (pRENDERDOC_GetAPI)dlsym(mod, "RENDERDOC_GetAPI");
|
||||
int ret = RENDERDOC_GetAPI(eRENDERDOC_API_Version_1_1_2, (void **)&rdoc_api);
|
||||
assert(ret == 1);
|
||||
}
|
||||
|
||||
std::unique_lock<std::mutex> lock(_frameLock);
|
||||
setObjectName("RenderThread");
|
||||
Parent::initialize();
|
||||
|
@ -132,6 +143,10 @@ void RenderThread::shutdown() {
|
|||
}
|
||||
|
||||
void RenderThread::renderFrame(gpu::FramePointer& frame) {
|
||||
if (frame && !frame->batches.empty()) {
|
||||
if (rdoc_api)
|
||||
rdoc_api->StartFrameCapture(NULL, NULL);
|
||||
}
|
||||
#ifdef USE_GL
|
||||
PROFILE_RANGE(render_gpu_gl, __FUNCTION__);
|
||||
#else
|
||||
|
@ -212,7 +227,8 @@ void RenderThread::renderFrame(gpu::FramePointer& frame) {
|
|||
// VKTODO: this is a temporary workaround, until render passes are selected inside Vulkan backend
|
||||
//vkCmdBeginRenderPass(commandBuffer, &beginInfo, VK_SUBPASS_CONTENTS_INLINE);
|
||||
_gpuContext->executeFrame(frame);
|
||||
vkCmdEndRenderPass(commandBuffer);
|
||||
_renderedFrameCount++;
|
||||
//vkCmdEndRenderPass(commandBuffer);
|
||||
}
|
||||
|
||||
#ifdef USE_GL
|
||||
|
@ -264,9 +280,14 @@ void RenderThread::renderFrame(gpu::FramePointer& frame) {
|
|||
vkCreateFence(_vkcontext.device->logicalDevice, &fenceCI, nullptr, &frameFence);
|
||||
vkQueueSubmit(_vkcontext.graphicsQueue, 1, &submitInfo, frameFence);
|
||||
_swapchain.queuePresent(_vkcontext.graphicsQueue, swapchainIndex, renderComplete);
|
||||
_vkcontext.trashCommandBuffers({ commandBuffer });
|
||||
//VKTODO _vkcontext.trashCommandBuffers({ commandBuffer });
|
||||
_vkcontext.emptyDumpster(frameFence);
|
||||
_vkcontext.recycle();
|
||||
if (frame && !frame->batches.empty()) {
|
||||
if (rdoc_api)
|
||||
rdoc_api->EndFrameCapture(NULL, NULL);
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -300,6 +321,9 @@ bool RenderThread::process() {
|
|||
}
|
||||
|
||||
renderFrame(_activeFrame);
|
||||
if (_renderedFrameCount == 1) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -63,6 +63,7 @@ public:
|
|||
void move(const glm::vec3& v);
|
||||
glm::mat4 _correction;
|
||||
gpu::PipelinePointer _presentPipeline;
|
||||
int _renderedFrameCount{ 0 };
|
||||
|
||||
void resize(const QSize& newSize);
|
||||
void setup() override;
|
||||
|
|
Loading…
Reference in a new issue