Skip to content

Commit c4914ca

Browse files
committed
Fix issues with imgui
1 parent 5bcca7b commit c4914ca

File tree

2 files changed

+27
-22
lines changed

2 files changed

+27
-22
lines changed

examples_tests

src/nbl/ext/ImGui/ImGui.cpp

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,13 @@ namespace nbl::ext::imgui
131131
smart_refctd_ptr<IGPUDescriptorSetLayout> UI::CreateDescriptorSetLayout()
132132
{
133133
static constexpr int Count = 1;
134-
IGPUDescriptorSetLayout::SBinding bindings[1];
134+
IGPUDescriptorSetLayout::SBinding bindings[Count] = {};
135135
{
136136
bindings[0].binding = 0;
137137
bindings[0].type = asset::IDescriptor::E_TYPE::ET_COMBINED_IMAGE_SAMPLER;
138138
bindings[0].count = 1;
139139
bindings[0].stageFlags = IShader::ESS_FRAGMENT;
140-
bindings[0].samplers = &m_fontSampler;
140+
//bindings[0].samplers = &m_fontSampler;
141141
};
142142
return m_device->createDescriptorSetLayout(bindings, bindings + Count);
143143
}
@@ -164,6 +164,7 @@ namespace nbl::ext::imgui
164164
// Create Descriptor Set:
165165
// Original number was 1 , Now it creates as many as swap_chain_image_count
166166
m_gpuDescriptorSet = m_descriptorPool->createDescriptorSet(descriptorSetLayout);
167+
assert(m_gpuDescriptorSet);
167168

168169
auto pipelineLayout = m_device->createPipelineLayout(
169170
pushConstantRanges,
@@ -177,7 +178,7 @@ namespace nbl::ext::imgui
177178

178179
memcpy(vertCpuBuffer->getPointer(), vertexShaderSpv, vertCpuBuffer->getSize()); // TODO: Can we avoid this copy ?
179180

180-
smart_refctd_ptr<ICPUShader> cpuVertShader = make_smart_refctd_ptr<ICPUShader>(std::move(vertCpuBuffer), IShader::ESS_VERTEX, IShader::E_CONTENT_TYPE::ECT_GLSL, "");
181+
smart_refctd_ptr<ICPUShader> cpuVertShader = make_smart_refctd_ptr<ICPUShader>(std::move(vertCpuBuffer), IShader::ESS_VERTEX, IShader::E_CONTENT_TYPE::ECT_SPIRV, "");
181182

182183
auto const unSpecVertexShader = m_device->createShader(std::move(cpuVertShader));
183184

@@ -193,7 +194,7 @@ namespace nbl::ext::imgui
193194

194195
memcpy(cpuFragBuffer->getPointer(), fragmentShaderSpv, cpuFragBuffer->getSize()); // TODO: Can we avoid this copy ?
195196

196-
smart_refctd_ptr<ICPUShader> cpuFragShader = make_smart_refctd_ptr<ICPUShader>(std::move(cpuFragBuffer), IShader::ESS_FRAGMENT, IShader::E_CONTENT_TYPE::ECT_GLSL, "");
197+
smart_refctd_ptr<ICPUShader> cpuFragShader = make_smart_refctd_ptr<ICPUShader>(std::move(cpuFragBuffer), IShader::ESS_FRAGMENT, IShader::E_CONTENT_TYPE::ECT_SPIRV, "");
197198

198199
auto const unSpecFragmentShader = m_device->createShader(std::move(cpuFragShader));
199200

@@ -436,12 +437,13 @@ namespace nbl::ext::imgui
436437
void UI::CreateDescriptorPool()
437438
{
438439
static constexpr int TotalSetCount = 1;
439-
IDescriptorPool::SCreateInfo createInfo;
440+
IDescriptorPool::SCreateInfo createInfo = {};
440441
createInfo.maxDescriptorCount[static_cast<uint32_t>(asset::IDescriptor::E_TYPE::ET_COMBINED_IMAGE_SAMPLER)] = TotalSetCount;
441442
createInfo.maxSets = 1;
442443
createInfo.flags = IDescriptorPool::E_CREATE_FLAGS::ECF_NONE;
443444

444445
m_descriptorPool = m_device->createDescriptorPool(std::move(createInfo));
446+
assert(m_descriptorPool);
445447
}
446448

447449
//-------------------------------------------------------------------------------------------------
@@ -594,22 +596,15 @@ namespace nbl::ext::imgui
594596
vertexBuffer = m_device->createBuffer(std::move(vertexCreationParams));
595597

596598
video::IDeviceMemoryBacked::SDeviceMemoryRequirements memReq = vertexBuffer->getMemoryReqs();
597-
memReq.memoryTypeBits &= m_device->getPhysicalDevice()->getDownStreamingMemoryTypeBits();
599+
memReq.memoryTypeBits &= m_device->getPhysicalDevice()->getUpStreamingMemoryTypeBits();
598600
auto memOffset = m_device->allocate(memReq, vertexBuffer.get());
599601
assert(memOffset.isValid());
600-
video::IDeviceMemoryAllocation::MappedMemoryRange range;
601-
{
602-
range.memory = vertexBuffer->getBoundMemory();
603-
range.offset = 0u;
604-
range.length = vertexSize;
605-
}
606-
m_device->mapMemory(range, video::IDeviceMemoryAllocation::EMCAF_READ);
607-
assert(vertexBuffer->getBoundMemory()->isCurrentlyMapped());
608602
}
609603

610604
IGPUBuffer::SCreationParams indexCreationParams = {};
611-
vertexCreationParams.usage = nbl::core::bitflag(nbl::asset::IBuffer::EUF_VERTEX_BUFFER_BIT) | nbl::asset::IBuffer::EUF_INLINE_UPDATE_VIA_CMDBUF;
612-
vertexCreationParams.size = indexSize;
605+
indexCreationParams.usage = nbl::core::bitflag(nbl::asset::IBuffer::EUF_VERTEX_BUFFER_BIT) | nbl::asset::IBuffer::EUF_INDEX_BUFFER_BIT
606+
| nbl::asset::IBuffer::EUF_INLINE_UPDATE_VIA_CMDBUF;
607+
indexCreationParams.size = indexSize;
613608

614609
auto & indexBuffer = m_indexBuffers[frameIndex];
615610

@@ -618,20 +613,30 @@ namespace nbl::ext::imgui
618613
indexBuffer = m_device->createBuffer(std::move(indexCreationParams));
619614

620615
video::IDeviceMemoryBacked::SDeviceMemoryRequirements memReq = indexBuffer->getMemoryReqs();
621-
memReq.memoryTypeBits &= m_device->getPhysicalDevice()->getDownStreamingMemoryTypeBits();
616+
memReq.memoryTypeBits &= m_device->getPhysicalDevice()->getUpStreamingMemoryTypeBits();
622617
auto memOffset = m_device->allocate(memReq, indexBuffer.get());
623618
assert(memOffset.isValid());
624-
video::IDeviceMemoryAllocation::MappedMemoryRange range;
619+
}
620+
621+
{
625622
{
623+
video::IDeviceMemoryAllocation::MappedMemoryRange range;
624+
range.memory = vertexBuffer->getBoundMemory();
625+
range.offset = 0u;
626+
range.length = vertexSize;
627+
m_device->mapMemory(range, video::IDeviceMemoryAllocation::EMCAF_READ);
628+
}
629+
{
630+
video::IDeviceMemoryAllocation::MappedMemoryRange range;
626631
range.memory = indexBuffer->getBoundMemory();
627632
range.offset = 0u;
628633
range.length = indexSize;
634+
m_device->mapMemory(range, video::IDeviceMemoryAllocation::EMCAF_READ);
629635
}
630-
m_device->mapMemory(range, video::IDeviceMemoryAllocation::EMCAF_READ);
636+
631637
assert(indexBuffer->getBoundMemory()->isCurrentlyMapped());
632-
}
638+
assert(vertexBuffer->getBoundMemory()->isCurrentlyMapped());
633639

634-
{
635640
auto* vertex_ptr = static_cast<ImDrawVert*>(vertexBuffer->getBoundMemory()->getMappedPointer());
636641
auto* index_ptr = static_cast<ImDrawIdx*>(indexBuffer->getBoundMemory()->getMappedPointer());
637642

0 commit comments

Comments
 (0)