changes
This commit is contained in:
@@ -75,6 +75,17 @@ class Pool {
|
||||
}
|
||||
}
|
||||
|
||||
/** Calls `fn(handle, item)` for every live item. */
|
||||
template <typename Fn>
|
||||
void forEachWithHandle(Fn&& fn) const {
|
||||
for (u32 index = 0; index < slots.size(); index++) {
|
||||
const Slot& slot = slots[index];
|
||||
if (slot.item) {
|
||||
fn(Handle<T>{index, slot.generation}, *slot.item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Predicate>
|
||||
T* findIf(Predicate&& predicate) {
|
||||
return const_cast<T*>(
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
#include <sophia/util/assert.hpp>
|
||||
#include <utility>
|
||||
|
||||
#include "vulkan/debug_label.hpp"
|
||||
|
||||
namespace sophia {
|
||||
|
||||
ImageRef RenderGraph::importImage(Image& image, Access finalAccess) {
|
||||
@@ -74,6 +76,8 @@ void RenderGraph::flush(vk::CommandBuffer commandBuffer,
|
||||
}
|
||||
|
||||
void RenderGraph::recordPass(vk::CommandBuffer commandBuffer, Pass& pass) {
|
||||
beginDebugLabel(commandBuffer, pass.name.c_str());
|
||||
|
||||
PendingBarriers pending;
|
||||
for (const ImageUse& use : pass.uses) {
|
||||
this->transitionTo(use.image, getAccessState(use.access), pending);
|
||||
@@ -82,9 +86,14 @@ void RenderGraph::recordPass(vk::CommandBuffer commandBuffer, Pass& pass) {
|
||||
|
||||
if (pass.colorAttachments.empty()) {
|
||||
pass.execute(commandBuffer);
|
||||
return;
|
||||
} else {
|
||||
this->recordRendering(commandBuffer, pass);
|
||||
}
|
||||
|
||||
endDebugLabel(commandBuffer);
|
||||
}
|
||||
|
||||
void RenderGraph::recordRendering(vk::CommandBuffer commandBuffer, Pass& pass) {
|
||||
std::vector<vk::RenderingAttachmentInfo> attachments;
|
||||
attachments.reserve(pass.colorAttachments.size());
|
||||
|
||||
|
||||
@@ -67,7 +67,8 @@ class RenderGraph {
|
||||
/**
|
||||
* Adds a pass. `setup` runs immediately and declares what the pass does to
|
||||
* images; `execute` runs later, from execute(), with the barriers already
|
||||
* recorded and (if the pass writes color) rendering begun.
|
||||
* recorded and (if the pass writes color) rendering begun. `name` labels
|
||||
* the pass's commands in debugging tools such as RenderDoc.
|
||||
*/
|
||||
void addPass(std::string name, const SetupFn& setup, ExecuteFn execute);
|
||||
|
||||
@@ -112,6 +113,7 @@ class RenderGraph {
|
||||
PendingBarriers& pending);
|
||||
void flush(vk::CommandBuffer commandBuffer, PendingBarriers& pending);
|
||||
void recordPass(vk::CommandBuffer commandBuffer, Pass& pass);
|
||||
void recordRendering(vk::CommandBuffer commandBuffer, Pass& pass);
|
||||
|
||||
std::vector<ImportedImage> images;
|
||||
std::vector<Pass> passes;
|
||||
|
||||
@@ -12,13 +12,17 @@ struct PushConstantData {
|
||||
};
|
||||
} // namespace
|
||||
|
||||
SceneRenderer::SceneRenderer(ResourceRegistry& resources)
|
||||
: resources{resources} {}
|
||||
SceneRenderer::SceneRenderer(const SceneRegistry& sceneRegistry,
|
||||
ResourceRegistry& resources)
|
||||
: sceneRegistry{sceneRegistry}, resources{resources} {}
|
||||
|
||||
SceneRenderer::~SceneRenderer() {}
|
||||
|
||||
void SceneRenderer::render(const Scene& scene, Entity camera,
|
||||
RenderTargetHandle target) {
|
||||
void SceneRenderer::render(SceneView sceneView) {
|
||||
auto& handle = sceneView.scene;
|
||||
auto& scene = this->sceneRegistry.get(handle);
|
||||
|
||||
auto& camera = sceneView.camera;
|
||||
SOPHIA_ASSERT(camera.hasComponent<CameraComponent>(),
|
||||
"camera does not have camera component!");
|
||||
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <sophia/handles.hpp>
|
||||
#include <sophia/scene.hpp>
|
||||
#include <sophia/scene_registry.hpp>
|
||||
#include <sophia/scene_view.hpp>
|
||||
|
||||
#include "entity.hpp"
|
||||
#include "resources/resource_registry.hpp"
|
||||
|
||||
namespace sophia {
|
||||
@@ -16,12 +15,14 @@ class SceneRenderer {
|
||||
SceneRenderer(const SceneRenderer&) = delete;
|
||||
SceneRenderer& operator=(const SceneRenderer&) = delete;
|
||||
|
||||
SceneRenderer(ResourceRegistry& resources);
|
||||
SceneRenderer(const SceneRegistry& sceneRegistry,
|
||||
ResourceRegistry& resources);
|
||||
~SceneRenderer();
|
||||
|
||||
void render(const Scene& scene, Entity camera, RenderTargetHandle target);
|
||||
void render(SceneView sceneView);
|
||||
|
||||
private:
|
||||
const SceneRegistry& sceneRegistry;
|
||||
ResourceRegistry& resources;
|
||||
};
|
||||
|
||||
|
||||
@@ -32,8 +32,8 @@ void RenderTarget::applyPendingResize() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Earlier frames may still be sampling the old image (e.g. through the UI).
|
||||
this->device.waitIdle();
|
||||
|
||||
destroy();
|
||||
create(extent.width, extent.height);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
#include "vulkan/debug_label.hpp"
|
||||
|
||||
namespace sophia {
|
||||
|
||||
static PFN_vkCmdBeginDebugUtilsLabelEXT cmdBeginDebugUtilsLabel = nullptr;
|
||||
static PFN_vkCmdEndDebugUtilsLabelEXT cmdEndDebugUtilsLabel = nullptr;
|
||||
|
||||
void loadDebugLabelFunctions(vk::Instance instance) {
|
||||
cmdBeginDebugUtilsLabel = reinterpret_cast<PFN_vkCmdBeginDebugUtilsLabelEXT>(
|
||||
vkGetInstanceProcAddr(instance, "vkCmdBeginDebugUtilsLabelEXT"));
|
||||
cmdEndDebugUtilsLabel = reinterpret_cast<PFN_vkCmdEndDebugUtilsLabelEXT>(
|
||||
vkGetInstanceProcAddr(instance, "vkCmdEndDebugUtilsLabelEXT"));
|
||||
}
|
||||
|
||||
void beginDebugLabel(vk::CommandBuffer commandBuffer, const char* name) {
|
||||
if (!cmdBeginDebugUtilsLabel) {
|
||||
return;
|
||||
}
|
||||
|
||||
VkDebugUtilsLabelEXT label{};
|
||||
label.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT;
|
||||
label.pLabelName = name;
|
||||
cmdBeginDebugUtilsLabel(commandBuffer, &label);
|
||||
}
|
||||
|
||||
void endDebugLabel(vk::CommandBuffer commandBuffer) {
|
||||
if (!cmdEndDebugUtilsLabel) {
|
||||
return;
|
||||
}
|
||||
|
||||
cmdEndDebugUtilsLabel(commandBuffer);
|
||||
}
|
||||
|
||||
} // namespace sophia
|
||||
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <vulkan/vulkan.hpp>
|
||||
|
||||
namespace sophia {
|
||||
|
||||
void loadDebugLabelFunctions(vk::Instance instance);
|
||||
|
||||
void beginDebugLabel(vk::CommandBuffer commandBuffer, const char* name);
|
||||
|
||||
void endDebugLabel(vk::CommandBuffer commandBuffer);
|
||||
|
||||
} // namespace sophia
|
||||
@@ -5,6 +5,8 @@
|
||||
#include <set>
|
||||
#include <sophia/util/logger.hpp>
|
||||
|
||||
#include "vulkan/debug_label.hpp"
|
||||
|
||||
namespace sophia {
|
||||
|
||||
static VKAPI_ATTR vk::Bool32 VKAPI_CALL
|
||||
@@ -288,6 +290,8 @@ void Device::setupDebugMessenger() {
|
||||
nullptr, &this->debugMessenger) != VK_SUCCESS) {
|
||||
throw std::runtime_error("failed to set up debug callback!");
|
||||
}
|
||||
|
||||
loadDebugLabelFunctions(*instance);
|
||||
}
|
||||
|
||||
bool Device::checkValidationLayerSupport() {
|
||||
|
||||
Reference in New Issue
Block a user