Renderer: RenderWindow now requires a RenderDevice

This commit is contained in:
Lynix
2021-05-16 23:13:00 +02:00
parent 40772f2137
commit 13feaf4aab
30 changed files with 132 additions and 107 deletions

View File

@@ -16,8 +16,8 @@ namespace Nz
m_attachmentToTextureMapping(std::move(attachmentIdToTextureMapping)),
m_passIdToPhysicalPassMapping(std::move(passIdToPhysicalPassMapping))
{
RenderDevice& renderDevice = Graphics::Instance()->GetRenderDevice();
m_commandPool = renderDevice.InstantiateCommandPool(QueueType::Graphics);
const std::shared_ptr<RenderDevice>& renderDevice = Graphics::Instance()->GetRenderDevice();
m_commandPool = renderDevice->InstantiateCommandPool(QueueType::Graphics);
}
void BakedFrameGraph::Execute(RenderFrame& renderFrame)
@@ -115,7 +115,7 @@ namespace Nz
void BakedFrameGraph::Resize(unsigned int width, unsigned int height)
{
RenderDevice& renderDevice = Graphics::Instance()->GetRenderDevice();
const std::shared_ptr<RenderDevice>& renderDevice = Graphics::Instance()->GetRenderDevice();
// Delete previous textures to make some room in VRAM
for (auto& passData : m_passes)
@@ -136,7 +136,7 @@ namespace Nz
textureCreationParams.usageFlags = textureData.usage;
textureCreationParams.pixelFormat = textureData.format;
textureData.texture = renderDevice.InstantiateTexture(textureCreationParams);
textureData.texture = renderDevice->InstantiateTexture(textureCreationParams);
}
std::vector<std::shared_ptr<Texture>> textures;
@@ -160,7 +160,7 @@ namespace Nz
passData.renderRect.Set(0, 0, int(framebufferWidth), int(framebufferHeight));
passData.framebuffer = renderDevice.InstantiateFramebuffer(framebufferWidth, framebufferHeight, passData.renderPass, textures);
passData.framebuffer = renderDevice->InstantiateFramebuffer(framebufferWidth, framebufferHeight, passData.renderPass, textures);
}
}
}

View File

@@ -612,7 +612,7 @@ namespace Nz
void FrameGraph::BuildPhysicalPasses()
{
RenderDevice& renderDevice = Graphics::Instance()->GetRenderDevice();
const std::shared_ptr<RenderDevice>& renderDevice = Graphics::Instance()->GetRenderDevice();
std::unordered_map<std::size_t /*textureId*/, TextureLayout> textureLayouts;
@@ -845,7 +845,7 @@ namespace Nz
BuildPhysicalPassDependencies(colorAttachmentCount, depthStencilAttachmentIndex.has_value(), renderPassAttachments, subpassesDesc, subpassesDeps);
m_pending.renderPasses.push_back(renderDevice.InstantiateRenderPass(std::move(renderPassAttachments), std::move(subpassesDesc), std::move(subpassesDeps)));
m_pending.renderPasses.push_back(renderDevice->InstantiateRenderPass(std::move(renderPassAttachments), std::move(subpassesDesc), std::move(subpassesDeps)));
physicalPassIndex++;
}

View File

@@ -15,7 +15,7 @@ namespace Nz
{
assert(mesh->GetAnimationType() == AnimationType_Static);
RenderDevice& renderDevice = Graphics::Instance()->GetRenderDevice();
const std::shared_ptr<RenderDevice>& renderDevice = Graphics::Instance()->GetRenderDevice();
m_subMeshes.reserve(mesh->GetSubMeshCount());
for (std::size_t i = 0; i < mesh->GetSubMeshCount(); ++i)
@@ -34,7 +34,7 @@ namespace Nz
const SoftwareBuffer* vertexBufferContent = static_cast<const SoftwareBuffer*>(vertexBuffer->GetBuffer()->GetImpl());
auto& submeshData = m_subMeshes.emplace_back();
submeshData.indexBuffer = renderDevice.InstantiateBuffer(BufferType_Index);
submeshData.indexBuffer = renderDevice->InstantiateBuffer(BufferType_Index);
if (!submeshData.indexBuffer->Initialize(indexBuffer->GetStride() * indexBuffer->GetIndexCount(), BufferUsage_DeviceLocal))
throw std::runtime_error("failed to create index buffer");
@@ -43,7 +43,7 @@ namespace Nz
submeshData.indexCount = indexBuffer->GetIndexCount();
submeshData.vertexBuffer = renderDevice.InstantiateBuffer(BufferType_Vertex);
submeshData.vertexBuffer = renderDevice->InstantiateBuffer(BufferType_Vertex);
if (!submeshData.vertexBuffer->Initialize(vertexBuffer->GetStride() * vertexBuffer->GetVertexCount(), BufferUsage_DeviceLocal))
throw std::runtime_error("failed to create vertex buffer");

View File

@@ -19,7 +19,6 @@ namespace Nz
ModuleBase("Graphics", this)
{
Renderer* renderer = Renderer::Instance();
RendererImpl* rendererImpl = renderer->GetRendererImpl(); //< FIXME
std::vector<RenderDeviceInfo> renderDeviceInfo = rendererImpl->QueryRenderDevices();
if (renderDeviceInfo.empty())
throw std::runtime_error("no render device available");
@@ -35,7 +34,7 @@ namespace Nz
}
}
m_renderDevice = rendererImpl->InstanciateRenderDevice(bestRenderDeviceIndex);
m_renderDevice = renderer->InstanciateRenderDevice(bestRenderDeviceIndex);
if (!m_renderDevice)
throw std::runtime_error("failed to instantiate render device");

View File

@@ -43,7 +43,7 @@ namespace Nz
{
auto& uniformBuffer = m_uniformBuffers.emplace_back();
uniformBuffer.buffer = Graphics::Instance()->GetRenderDevice().InstantiateBuffer(Nz::BufferType_Uniform);
uniformBuffer.buffer = Graphics::Instance()->GetRenderDevice()->InstantiateBuffer(Nz::BufferType_Uniform);
if (!uniformBuffer.buffer->Initialize(uniformBufferInfo.blockSize, BufferUsage_Dynamic))
throw std::runtime_error("failed to initialize UBO memory");

View File

@@ -56,7 +56,7 @@ namespace Nz
renderPipelineInfo.vertexBuffers = vertexBuffers;
return m_renderPipelines.emplace_back(Graphics::Instance()->GetRenderDevice().InstantiateRenderPipeline(std::move(renderPipelineInfo)));
return m_renderPipelines.emplace_back(Graphics::Instance()->GetRenderDevice()->InstantiateRenderPipeline(std::move(renderPipelineInfo)));
}
/*!
* \brief Returns a reference to a MaterialPipeline built with MaterialPipelineInfo

View File

@@ -15,7 +15,7 @@ namespace Nz
{
Nz::PredefinedInstanceData instanceUboOffsets = Nz::PredefinedInstanceData::GetOffsets();
m_instanceDataBuffer = Graphics::Instance()->GetRenderDevice().InstantiateBuffer(BufferType_Uniform);
m_instanceDataBuffer = Graphics::Instance()->GetRenderDevice()->InstantiateBuffer(BufferType_Uniform);
if (!m_instanceDataBuffer->Initialize(instanceUboOffsets.totalSize, Nz::BufferUsage_DeviceLocal | Nz::BufferUsage_Dynamic))
throw std::runtime_error("failed to initialize viewer data UBO");

View File

@@ -61,7 +61,7 @@ namespace Nz
states.enabledOptions = combination;
states.sanitized = true;
std::shared_ptr<ShaderModule> stage = Graphics::Instance()->GetRenderDevice().InstantiateShaderModule(m_shaderStage, m_shaderAst, std::move(states));
std::shared_ptr<ShaderModule> stage = Graphics::Instance()->GetRenderDevice()->InstantiateShaderModule(m_shaderStage, m_shaderAst, std::move(states));
it = m_combinations.emplace(combination, std::move(stage)).first;
}