mirror of
https://github.com/antopilo/Nuake.git
synced 2025-12-30 21:49:06 +03:00
Compare commits
4 Commits
7cb7a72630
...
3fc503ee79
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3fc503ee79 | ||
|
|
6f9d0f2818 | ||
|
|
958287f6b1 | ||
|
|
60819fe1d3 |
@@ -45,6 +45,7 @@ struct Material
|
||||
int receiveShadow;
|
||||
int castShadow;
|
||||
int unlit;
|
||||
int alphaScissor;
|
||||
};
|
||||
[[vk::binding(0, 3)]]
|
||||
StructuredBuffer<Material> material;
|
||||
|
||||
@@ -36,7 +36,7 @@ PSOutput main(PSInput input)
|
||||
{
|
||||
int depthTexture = pushConstants.DepthTextureID;
|
||||
float upSampledDepth = textures[depthTexture].Sample(mySampler[0], input.UV).r;
|
||||
float3 upSampledColor = textures[pushConstants.VolumetricTextureID].Sample(mySampler[0], input.UV).rgb;
|
||||
float3 upSampledColor = textures[pushConstants.VolumetricTextureID].Sample(mySampler[1], input.UV).rgb;
|
||||
float3 color = 0.0f.xxx;
|
||||
float totalWeight = 0.0f;
|
||||
|
||||
@@ -53,7 +53,7 @@ PSOutput main(PSInput input)
|
||||
{
|
||||
float2 uvOffset = float2(offsets[i].x * 4.0, offsets[i].y * 4.0) ;
|
||||
uvOffset = PixelToUV(uvOffset, textures[pushConstants.DepthTextureID]);
|
||||
float3 downscaledColor = textures[pushConstants.VolumetricTextureID].Sample(mySampler[0], input.UV + uvOffset).rgb;
|
||||
float3 downscaledColor = textures[pushConstants.VolumetricTextureID].Sample(mySampler[1], input.UV + uvOffset).rgb;
|
||||
float downscaledDepth = textures[pushConstants.DepthTextureID].Sample(mySampler[0], input.UV + uvOffset).r;
|
||||
|
||||
float currentWeight = 1.0f;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
struct PSInput
|
||||
{
|
||||
float4 Position : SV_Position;
|
||||
float2 UV : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct ModelPushConstant
|
||||
@@ -17,4 +18,14 @@ ModelPushConstant pushConstants;
|
||||
|
||||
void main(PSInput input)
|
||||
{
|
||||
Material inMaterial = material[pushConstants.materialIndex];
|
||||
if(inMaterial.alphaScissor == 1)
|
||||
{
|
||||
SamplerState samplerr = mySampler[inMaterial.samplingType];
|
||||
float albedoAlpha = textures[inMaterial.albedoTextureId].Sample(samplerr, input.UV).a;
|
||||
if(albedoAlpha < 0.1f)
|
||||
{
|
||||
discard;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@ ModelPushConstant pushConstants;
|
||||
struct VSOutput
|
||||
{
|
||||
float4 Position : SV_Position;
|
||||
float2 UV : TEXCOORD0;
|
||||
};
|
||||
|
||||
float LinearizeDepth(float depth, float nearPlane, float farPlane, bool reverseDepth)
|
||||
@@ -43,6 +44,7 @@ VSOutput main(uint vertexIndex : SV_VertexID)
|
||||
|
||||
// Output the position of each vertex
|
||||
output.Position = mul(camView.Projection, mul(camView.View,mul(modelData.model, float4(v.position, 1.0f))));
|
||||
output.UV = float2(v.uv_x, v.uv_y);
|
||||
|
||||
//output.Position.z = LinearizeDepth(output.Position.z, camView.Near, camView.Far, false);
|
||||
return output;
|
||||
|
||||
@@ -37,6 +37,23 @@ PSOutput main(PSInput input)
|
||||
Material inMaterial = material[pushConstants.materialIndex];
|
||||
|
||||
SamplerState samplerr = mySampler[inMaterial.samplingType];
|
||||
|
||||
// ALBEDO COLOR
|
||||
float4 albedoColor = float4(inMaterial.albedo.xyz, 1.0f);
|
||||
if(inMaterial.hasAlbedo == 1)
|
||||
{
|
||||
float4 albedoSample = textures[inMaterial.albedoTextureId].Sample(samplerr, input.UV);
|
||||
|
||||
// Alpha cutout?
|
||||
if(inMaterial.alphaScissor == 1 && albedoSample.a < 0.001f)
|
||||
{
|
||||
discard;
|
||||
}
|
||||
|
||||
albedoColor.xyz = albedoSample.xyz * albedoColor.xyz;
|
||||
}
|
||||
output.oColor0 = albedoColor;
|
||||
|
||||
// NORMAL
|
||||
// TODO use TBN matrix
|
||||
float3 T = input.Tangent.xyz;
|
||||
@@ -63,21 +80,7 @@ PSOutput main(PSInput input)
|
||||
|
||||
// MATERIAL
|
||||
|
||||
// ALBEDO COLOR
|
||||
float4 albedoColor = float4(inMaterial.albedo.xyz, 1.0f);
|
||||
if(inMaterial.hasAlbedo == 1)
|
||||
{
|
||||
float4 albedoSample = textures[inMaterial.albedoTextureId].Sample(samplerr, input.UV);
|
||||
|
||||
// Alpha cutout?
|
||||
if(albedoSample.a < 0.001f)
|
||||
{
|
||||
discard;
|
||||
}
|
||||
|
||||
albedoColor.xyz = albedoSample.xyz;
|
||||
}
|
||||
output.oColor0 = albedoColor;
|
||||
|
||||
// MATERIAL PROPERTIES
|
||||
float metalnessValue = inMaterial.metalnessValue;
|
||||
|
||||
@@ -21,6 +21,8 @@ public:
|
||||
const UUID viewId = componentPtr->CameraInstance->ID;
|
||||
|
||||
previewViewport = vkRenderer.CreateViewport(viewId, { 200, 200 });
|
||||
previewViewport->SetDebugName("CameraPreviewViewport");
|
||||
|
||||
vkRenderer.RegisterSceneViewport(scene->Shared(), previewViewport->GetID());
|
||||
}
|
||||
if (componentPtr == nullptr)
|
||||
|
||||
@@ -26,6 +26,9 @@ enum class Shapes
|
||||
|
||||
Shapes currentShape = Shapes::Sphere;
|
||||
|
||||
Ref<Nuake::Viewport> MaterialEditor::SceneViewport = nullptr;
|
||||
Ref<Nuake::Scene> MaterialEditor::PreviewScene = nullptr;
|
||||
|
||||
void MaterialEditor::Enable()
|
||||
{
|
||||
SceneViewport->SetActive(true);
|
||||
@@ -40,33 +43,61 @@ MaterialEditor::MaterialEditor()
|
||||
{
|
||||
using namespace Nuake;
|
||||
|
||||
PreviewScene = CreateRef<Nuake::Scene>();
|
||||
PreviewScene->GetEnvironment()->mVolumetric->SetFogAmount(1.0f);
|
||||
if (!SceneViewport)
|
||||
{
|
||||
PreviewScene = CreateRef<Nuake::Scene>();
|
||||
PreviewScene->GetEnvironment()->mVolumetric->SetFogAmount(1.0f);
|
||||
|
||||
auto camera = PreviewScene->CreateEntity("Camera");
|
||||
camera.GetComponent<Nuake::TransformComponent>().Translation = Nuake::Vector3(-2, 0, -2);
|
||||
auto& camComponent = camera.AddComponent<Nuake::CameraComponent>();
|
||||
camComponent.CameraInstance->Fov = 44.0f;
|
||||
auto light = PreviewScene->CreateEntity("Light");
|
||||
auto& lightC = light.AddComponent<LightComponent>();
|
||||
auto& lightT = light.AddComponent<TransformComponent>();
|
||||
lightC.CastShadows = false;
|
||||
lightC.Type = LightType::Directional;
|
||||
|
||||
auto camera = PreviewScene->CreateEntity("Camera");
|
||||
camera.GetComponent<Nuake::TransformComponent>().Translation = Nuake::Vector3(-2, 0, -2);
|
||||
auto& camComponent = camera.AddComponent<Nuake::CameraComponent>();
|
||||
camComponent.CameraInstance->Fov = 44.0f;
|
||||
auto light = PreviewScene->CreateEntity("Light");
|
||||
auto& lightC = light.AddComponent<LightComponent>();
|
||||
auto& lightT = light.AddComponent<TransformComponent>();
|
||||
lightC.CastShadows = false;
|
||||
lightC.Type = LightType::Directional;
|
||||
glm::vec3 forward = glm::normalize(Vector3(.33, -.33, -.33));
|
||||
glm::vec3 up = glm::vec3(0, 1, 0);
|
||||
|
||||
glm::vec3 forward = glm::normalize(Vector3(.33, -.33, -.33));
|
||||
glm::vec3 up = glm::vec3(0, 1, 0);
|
||||
// Prevent up being colinear with forward
|
||||
if (glm::abs(glm::dot(forward, up)) > 0.999f)
|
||||
up = glm::vec3(1, 0, 0);
|
||||
|
||||
// Prevent up being colinear with forward
|
||||
if (glm::abs(glm::dot(forward, up)) > 0.999f)
|
||||
up = glm::vec3(1, 0, 0);
|
||||
glm::vec3 right = glm::normalize(glm::cross(up, forward));
|
||||
up = glm::cross(forward, right);
|
||||
|
||||
glm::vec3 right = glm::normalize(glm::cross(up, forward));
|
||||
up = glm::cross(forward, right);
|
||||
glm::mat3 rotationMatrix(right, up, forward);
|
||||
|
||||
glm::mat3 rotationMatrix(right, up, forward);
|
||||
//auto& lightT = light.GetComponent<TransformComponent>();
|
||||
lightT.GlobalRotation = glm::quat_cast(rotationMatrix);
|
||||
|
||||
//auto& lightT = light.GetComponent<TransformComponent>();
|
||||
lightT.GlobalRotation = glm::quat_cast(rotationMatrix);
|
||||
auto& vkRenderer = Nuake::VkRenderer::Get();
|
||||
const UUID viewId = camComponent.CameraInstance->ID;
|
||||
|
||||
SceneViewport = vkRenderer.CreateViewport(viewId, { 200, 200 });
|
||||
SceneViewport->SetActive(false);
|
||||
SceneViewport->SetDebugName("MaterialPreview");
|
||||
SceneViewport->GetOnDebugDraw().AddStatic([](DebugCmd& cmd) {
|
||||
Matrix4 transform = Matrix4(1.0f);
|
||||
//cmd.DrawQuad(transform);
|
||||
});
|
||||
SceneViewport->GetOnLineDraw().AddStatic([](DebugLineCmd& cmd) {
|
||||
Matrix4 transform = Matrix4(1.0f);
|
||||
|
||||
auto cam = cmd.GetScene()->GetEntity("Camera");
|
||||
auto& camc = cam.GetComponent<CameraComponent>();
|
||||
auto& cami = camc.CameraInstance;
|
||||
auto proj = cami->GetPerspective();
|
||||
auto view = cami->GetTransform();
|
||||
//cmd.DrawSphere(proj * view * transform, { 1, 0, 0, 1 }, 2.0f, false);
|
||||
});
|
||||
|
||||
//PreviewScene->GetEnvironment()->AmbientColor = { 0, 0, 0, 0 };
|
||||
vkRenderer.RegisterSceneViewport(PreviewScene, SceneViewport->GetID());
|
||||
}
|
||||
|
||||
|
||||
auto sphere = PreviewScene->CreateEntity("Sphere");
|
||||
auto& modelComponent = sphere.AddComponent<Nuake::ModelComponent>();
|
||||
@@ -223,27 +254,7 @@ MaterialEditor::MaterialEditor()
|
||||
ResourceManager::RegisterResource(cubeModel);
|
||||
modelComponent.ModelResource = cubeModel->ID;
|
||||
|
||||
auto& vkRenderer = Nuake::VkRenderer::Get();
|
||||
const UUID viewId = camComponent.CameraInstance->ID;
|
||||
|
||||
SceneViewport = vkRenderer.CreateViewport(viewId, {200, 200});
|
||||
SceneViewport->GetOnDebugDraw().AddStatic([](DebugCmd& cmd) {
|
||||
Matrix4 transform = Matrix4(1.0f);
|
||||
//cmd.DrawQuad(transform);
|
||||
});
|
||||
SceneViewport->GetOnLineDraw().AddStatic([](DebugLineCmd& cmd) {
|
||||
Matrix4 transform = Matrix4(1.0f);
|
||||
|
||||
auto cam = cmd.GetScene()->GetEntity("Camera");
|
||||
auto& camc = cam.GetComponent<CameraComponent>();
|
||||
auto& cami = camc.CameraInstance;
|
||||
auto proj = cami->GetPerspective();
|
||||
auto view = cami->GetTransform();
|
||||
//cmd.DrawSphere(proj * view * transform, { 1, 0, 0, 1 }, 2.0f, false);
|
||||
});
|
||||
|
||||
//PreviewScene->GetEnvironment()->AmbientColor = { 0, 0, 0, 0 };
|
||||
vkRenderer.RegisterSceneViewport(PreviewScene, SceneViewport->GetID());
|
||||
|
||||
}
|
||||
|
||||
void MaterialEditor::Draw(Ref<Nuake::Material> material)
|
||||
@@ -491,6 +502,16 @@ void MaterialEditor::Draw(Ref<Nuake::Material> material)
|
||||
ImGui::TableNextColumn();
|
||||
}
|
||||
|
||||
{
|
||||
ImGui::Text("Alpha Scissoring");
|
||||
ImGui::TableNextColumn();
|
||||
|
||||
ImGui::Checkbox("##AlphaScissor", &material->m_AlphaScissor);
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::TableNextColumn();
|
||||
}
|
||||
|
||||
{
|
||||
ImGui::Text("Unlit");
|
||||
ImGui::TableNextColumn();
|
||||
|
||||
@@ -4,11 +4,13 @@
|
||||
#include <Nuake/Scene/Scene.h>
|
||||
|
||||
#include "Nuake/Rendering/Vulkan/SceneViewport.h"
|
||||
|
||||
class MaterialEditor
|
||||
{
|
||||
private:
|
||||
Ref<Nuake::Scene> PreviewScene;
|
||||
Ref<Nuake::Viewport> SceneViewport;
|
||||
static Ref<Nuake::Scene> PreviewScene;
|
||||
static Ref<Nuake::Viewport> SceneViewport;
|
||||
|
||||
public:
|
||||
MaterialEditor();
|
||||
~MaterialEditor() = default;
|
||||
|
||||
@@ -139,7 +139,7 @@ namespace Nuake {
|
||||
|
||||
Logger::Log("Loading imgui from mem", "window", VERBOSE);
|
||||
using namespace Nuake::StaticResources;
|
||||
ImGui::LoadIniSettingsFromMemory((const char*)StaticResources::Data_default_layout_ini);
|
||||
ImGui::LoadIniSettingsFromMemory((const char*)StaticResources::Data_default_layout_ini, StaticResources::Data_default_layout_ini_len);
|
||||
|
||||
virtualCamera = CreateRef<FrameBuffer>(true, Vector2{ 640, 360 });
|
||||
//ScriptingContext::Get().Initialize();
|
||||
@@ -2693,6 +2693,12 @@ namespace Nuake {
|
||||
GPUResources& gpu = GPUResources::Get();
|
||||
auto buffers = gpu.GetAllBuffers();
|
||||
|
||||
ImGui::Text("Render Info");
|
||||
|
||||
auto stats = VkRenderer::Get().Stats;
|
||||
ImGui::Text(("View rendered: " + std::to_string(stats.ViewRenderers)).c_str());
|
||||
ImGui::Text(("View skipped: " + std::to_string(stats.ViewRenderSkipped)).c_str());
|
||||
|
||||
ImGui::Text("General Info");
|
||||
|
||||
const size_t textureCount = gpu.GetAllTextures().size();
|
||||
|
||||
@@ -80,6 +80,7 @@ void SceneEditorWindow::Draw()
|
||||
ImGui::DockSpace(dockspaceId, ImGui::GetContentRegionAvail(), ImGuiDockNodeFlags_None, &localSceneEditorClass);
|
||||
for (auto& widget : widgets)
|
||||
{
|
||||
widget->OnVisible();
|
||||
widget->Draw();
|
||||
}
|
||||
|
||||
@@ -100,6 +101,11 @@ void SceneEditorWindow::Draw()
|
||||
else
|
||||
{
|
||||
this->isFocused = false;
|
||||
|
||||
for (auto& widget : widgets)
|
||||
{
|
||||
widget->OnHidden();
|
||||
}
|
||||
}
|
||||
ImGui::End();
|
||||
if (!layoutInitialized)
|
||||
|
||||
@@ -8,6 +8,7 @@ class IEditorWidget
|
||||
{
|
||||
protected:
|
||||
EditorContext& editorContext;
|
||||
bool visible;
|
||||
|
||||
private:
|
||||
std::string widgetName;
|
||||
@@ -22,6 +23,14 @@ public:
|
||||
|
||||
virtual void OnSceneChanged(Ref<Nuake::Scene> scene) {}
|
||||
|
||||
void SetVisible(bool isVisible)
|
||||
{
|
||||
visible = isVisible;
|
||||
}
|
||||
|
||||
virtual void OnVisible() {}
|
||||
virtual void OnHidden() {}
|
||||
|
||||
void DockTo(uint32_t dockId)
|
||||
{
|
||||
ImGui::DockBuilderDockWindow(widgetName.c_str(), dockId);
|
||||
|
||||
@@ -59,6 +59,16 @@ void ViewportWidget::Update(float ts)
|
||||
}
|
||||
}
|
||||
|
||||
void ViewportWidget::OnVisible()
|
||||
{
|
||||
sceneViewport->SetActive(true);
|
||||
}
|
||||
|
||||
void ViewportWidget::OnHidden()
|
||||
{
|
||||
sceneViewport->SetActive(false);
|
||||
}
|
||||
|
||||
void ViewportWidget::Draw()
|
||||
{
|
||||
auto oldTarget = overlayOpacity.TargetValue;
|
||||
@@ -270,6 +280,7 @@ void ViewportWidget::OnSceneChanged(Ref<Nuake::Scene> scene)
|
||||
// Create new viewport with same reoslution
|
||||
const UUID viewId = editorContext.GetScene()->GetCurrentCamera()->ID;
|
||||
auto viewport = vkRenderer.CreateViewport(viewId, currentResolution);
|
||||
viewport->SetDebugName("ViewportWidget(" + scene->GetName() + ")");
|
||||
vkRenderer.RegisterSceneViewport(scene, viewport->GetID());
|
||||
|
||||
sceneViewport = viewport;
|
||||
|
||||
@@ -50,6 +50,9 @@ public:
|
||||
void Draw() override;
|
||||
void OnSceneChanged(Ref<Nuake::Scene> scene) override;
|
||||
|
||||
void OnVisible() override;
|
||||
void OnHidden() override;
|
||||
|
||||
void OnLineDraw(Nuake::DebugLineCmd& lineCmd);
|
||||
void OnDebugDraw(Nuake::DebugCmd& debugCmd);
|
||||
|
||||
|
||||
@@ -83,6 +83,7 @@ namespace Nuake
|
||||
CullingType m_CullingType = CullingType::Back;
|
||||
bool m_ReceiveShadows = true;
|
||||
bool m_CastShadows = true;
|
||||
bool m_AlphaScissor = false;
|
||||
|
||||
Ref<Texture> m_Albedo;
|
||||
Ref<Texture> m_AO;
|
||||
|
||||
@@ -20,10 +20,42 @@ namespace Nuake
|
||||
Cmd(VkCommandBuffer cmdBuffer) : CmdBuffer(cmdBuffer) {}
|
||||
VkCommandBuffer GetCmdBuffer() { return CmdBuffer; }
|
||||
|
||||
class DebugMarkerScope
|
||||
{
|
||||
private:
|
||||
VkCommandBuffer cmd;
|
||||
|
||||
public:
|
||||
DebugMarkerScope(VkCommandBuffer inCmd, const std::string& name, Color color = Color(1, 0, 0, 1)) :
|
||||
cmd(inCmd)
|
||||
{
|
||||
VkDebugUtilsLabelEXT labelInfo{};
|
||||
labelInfo.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT;
|
||||
labelInfo.pLabelName = name.c_str();
|
||||
labelInfo.color[0] = color.r; // Red
|
||||
labelInfo.color[1] = color.g;
|
||||
labelInfo.color[2] = color.b;
|
||||
labelInfo.color[3] = color.a; // Alpha
|
||||
|
||||
vkCmdBeginDebugUtilsLabelEXT(cmd, &labelInfo);
|
||||
}
|
||||
|
||||
~DebugMarkerScope()
|
||||
{
|
||||
vkCmdEndDebugUtilsLabelEXT(cmd);
|
||||
}
|
||||
};
|
||||
|
||||
public:
|
||||
void BeginRendering(VkRenderingInfo renderInfo);
|
||||
void EndRendering();
|
||||
|
||||
DebugMarkerScope DebugScope(const std::string& name, Color color = Color(1, 0, 0, 1))
|
||||
{
|
||||
return DebugMarkerScope(CmdBuffer, name, color);
|
||||
}
|
||||
|
||||
void DebugMarker(const std::string& name, Color color = Color(1, 0, 0, 1));
|
||||
void BindPipeline(VkPipeline pipeline) const;
|
||||
void SetViewport(const Vector2& size) const;
|
||||
void SetScissor(const Vector2& size) const;
|
||||
|
||||
@@ -70,6 +70,8 @@ void RenderPass::Execute(PassRenderContext& ctx, PassAttachments& inputs)
|
||||
|
||||
void RenderPass::ClearAttachments(PassRenderContext& ctx, PassAttachments& inputs)
|
||||
{
|
||||
auto marker = ctx.commandBuffer.DebugScope("Clear Attachments");
|
||||
|
||||
// Clear all color attachments
|
||||
int attachmentIndex = 0;
|
||||
for (int i = 0; i < std::size(inputs); i++)
|
||||
@@ -96,6 +98,7 @@ void RenderPass::ClearAttachments(PassRenderContext& ctx, PassAttachments& input
|
||||
|
||||
void RenderPass::TransitionAttachments(PassRenderContext& ctx, PassAttachments& inputs)
|
||||
{
|
||||
auto marker = ctx.commandBuffer.DebugScope("Transition Attachments");
|
||||
// Transition all color attachments
|
||||
for (auto& attachment : inputs)
|
||||
{
|
||||
@@ -108,6 +111,8 @@ void RenderPass::TransitionAttachments(PassRenderContext& ctx, PassAttachments&
|
||||
|
||||
void RenderPass::UntransitionAttachments(PassRenderContext& ctx, PassAttachments& inputs)
|
||||
{
|
||||
auto marker = ctx.commandBuffer.DebugScope("Detransition Attachments");
|
||||
|
||||
for (auto& attachment : inputs)
|
||||
{
|
||||
// Transform from color attachment to transfer src for next pass
|
||||
@@ -122,6 +127,7 @@ void RenderPass::Render(PassRenderContext& ctx, PassAttachments& inputs)
|
||||
|
||||
if (PreRender)
|
||||
{
|
||||
auto marker = ctx.commandBuffer.DebugScope("Pre Render");
|
||||
PreRender(ctx);
|
||||
}
|
||||
|
||||
@@ -162,6 +168,7 @@ void RenderPass::Render(PassRenderContext& ctx, PassAttachments& inputs)
|
||||
|
||||
if (RenderCb)
|
||||
{
|
||||
auto marker = ctx.commandBuffer.DebugScope("Render");
|
||||
RenderCb(ctx);
|
||||
}
|
||||
}
|
||||
@@ -169,6 +176,7 @@ void RenderPass::Render(PassRenderContext& ctx, PassAttachments& inputs)
|
||||
|
||||
if (PostRender)
|
||||
{
|
||||
auto marker = ctx.commandBuffer.DebugScope("Post Render");
|
||||
PostRender(ctx);
|
||||
}
|
||||
}
|
||||
@@ -278,6 +286,7 @@ void RenderPass::Build()
|
||||
|
||||
VK_CALL(vkCreatePipelineLayout(VkRenderer::Get().GetDevice(), &pipeline_layout_info, nullptr, &PipelineLayout));
|
||||
|
||||
VulkanUtil::SetDebugName(PipelineLayout, Name + "PipelineLayout");
|
||||
// Create pipeline
|
||||
const size_t attachmentCount = Attachments.size();
|
||||
|
||||
@@ -314,7 +323,7 @@ void RenderPass::Build()
|
||||
}
|
||||
|
||||
Pipeline = pipelineBuilder.BuildPipeline(VkRenderer::Get().GetDevice());
|
||||
|
||||
VulkanUtil::SetDebugName(Pipeline, Name + "Pipeline");
|
||||
IsBuilt = true;
|
||||
}
|
||||
|
||||
@@ -381,6 +390,7 @@ void RenderPipeline::Execute(PassRenderContext& ctx, PipelineAttachments& inputs
|
||||
int passIndex = 0;
|
||||
for (auto& pass : RenderPasses)
|
||||
{
|
||||
auto marker = ctx.commandBuffer.DebugScope(pass.GetName() + " Execute");
|
||||
pass.Execute(ctx, inputs[passIndex]);
|
||||
|
||||
passIndex++;
|
||||
|
||||
@@ -49,6 +49,7 @@ ShadowRenderPipeline::ShadowRenderPipeline()
|
||||
auto& cmd = ctx.commandBuffer;
|
||||
auto& scene = ctx.scene;
|
||||
auto& vk = VkRenderer::Get();
|
||||
auto& res = GPUResources::Get();
|
||||
|
||||
ZoneScopedN("Render Models");
|
||||
auto view = scene->m_Registry.view<TransformComponent, ModelComponent, VisibilityComponent>();
|
||||
@@ -72,14 +73,16 @@ ShadowRenderPipeline::ShadowRenderPipeline()
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
gbufferConstant.MaterialIndex = res.MeshMaterialMapping[vkMesh->GetID()];
|
||||
}
|
||||
|
||||
gbufferConstant.Index = GPUResources::Get().GetBindlessTransformID(entityId);
|
||||
gbufferConstant.CameraID = ctx.cameraID;
|
||||
|
||||
|
||||
cmd.PushConstants(ctx.renderPass->PipelineLayout, sizeof(GBufferConstant), &gbufferConstant);
|
||||
cmd.BindIndexBuffer(vkMesh->GetIndexBuffer()->GetBuffer());
|
||||
cmd.DrawIndexed(vkMesh->GetIndexBuffer()->GetSize() / sizeof(uint32_t));
|
||||
cmd.DrawIndexed(vkMesh->GetIndexBuffer()->GetSize() / sizeof(uint32_t));
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -145,6 +148,8 @@ SceneRenderPipeline::SceneRenderPipeline()
|
||||
memcpy(mappedData, ssaoKernelSamples.data(), buffer->GetSize());
|
||||
VkRenderer::Get().ImmediateSubmit([&](VkCommandBuffer cmd)
|
||||
{
|
||||
auto command = Cmd(cmd);
|
||||
command.DebugScope("SSAO Kernel CopyBuffer");
|
||||
VkBufferCopy copy{ 0 };
|
||||
copy.dstOffset = 0;
|
||||
copy.srcOffset = 0;
|
||||
@@ -316,7 +321,10 @@ void SceneRenderPipeline::Render(PassRenderContext& ctx)
|
||||
{ LineCombineOutput },
|
||||
};
|
||||
|
||||
GBufferPipeline.Execute(ctx, pipelineInputs);
|
||||
{
|
||||
auto marker = ctx.commandBuffer.DebugScope("GBufferPipeline Execute");
|
||||
GBufferPipeline.Execute(ctx, pipelineInputs);
|
||||
}
|
||||
|
||||
// Mouse Picking requests
|
||||
if (!mousePickingRequests.empty())
|
||||
@@ -334,6 +342,7 @@ void SceneRenderPipeline::Render(PassRenderContext& ctx)
|
||||
VkRenderer::Get().ImmediateSubmit([&](VkCommandBuffer cmd)
|
||||
{
|
||||
Cmd command(cmd);
|
||||
command.DebugScope("Mouse picking GPU to CPU copy");
|
||||
command.TransitionImageLayout(GBufferEntityID, VkImageLayout::VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
|
||||
command.CopyImageToBuffer(GBufferEntityID, stagingBuffer, request.mousePosition);
|
||||
command.TransitionImageLayout(GBufferEntityID, VkImageLayout::VK_IMAGE_LAYOUT_GENERAL);
|
||||
|
||||
@@ -29,18 +29,18 @@ bool Viewport::Resize()
|
||||
viewportSize = queuedResize;
|
||||
|
||||
auto newRenderTarget = CreateRef<VulkanImage>(ImageFormat::RGBA16F, viewportSize);
|
||||
VkRenderer::Get().ImmediateSubmit([&](VkCommandBuffer cmd)
|
||||
VkRenderer::Get().ImmediateSubmit([&, newRenderTarget](VkCommandBuffer cmd)
|
||||
{
|
||||
Cmd command(cmd);
|
||||
command.DebugScope("Viewport Resize GPGPU copy");
|
||||
command.TransitionImageLayout(renderTarget, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
|
||||
command.TransitionImageLayout(newRenderTarget, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
|
||||
command.CopyImageToImage(renderTarget, newRenderTarget);
|
||||
command.TransitionImageLayout(renderTarget, VK_IMAGE_LAYOUT_GENERAL);
|
||||
command.TransitionImageLayout(newRenderTarget, VK_IMAGE_LAYOUT_GENERAL);
|
||||
renderTarget = newRenderTarget;
|
||||
});
|
||||
|
||||
renderTarget = newRenderTarget;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace Nuake
|
||||
class Viewport
|
||||
{
|
||||
private:
|
||||
std::string Name;
|
||||
bool Active;
|
||||
UUID id;
|
||||
Vector2 queuedResize;
|
||||
@@ -33,6 +34,8 @@ namespace Nuake
|
||||
void SetActive(bool isActive) { Active = isActive; }
|
||||
bool IsActive() const { return Active; }
|
||||
|
||||
void SetDebugName(const std::string& name) { Name = name; }
|
||||
const std::string& GetDebugName() const { return Name; }
|
||||
UUID GetID() const { return id; }
|
||||
UUID GetViewID() const { return viewId; }
|
||||
void SetViewID(UUID inViewID) { this->viewId = inViewID; }
|
||||
|
||||
@@ -165,7 +165,7 @@ Ref<VulkanShader> ShaderCompiler::CompileShader(const std::string& path)
|
||||
|
||||
Logger::Log("Shader compilation failed: " + errorMsgStr, "DXC", CRITICAL);
|
||||
|
||||
throw std::runtime_error("Shader compilation failed: " + errorMsgStr);
|
||||
throw std::runtime_error("Shader compilation failed: " + errorMsgStr);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "VulkanRenderer.h"
|
||||
#include "VulkanAllocator.h"
|
||||
#include "VulkanInit.h"
|
||||
|
||||
using namespace Nuake;
|
||||
|
||||
@@ -36,6 +37,8 @@ void VkMesh::UploadToGPU(const std::vector<Vertex>& vertices, const std::vector<
|
||||
memcpy((char*)mappedData + VertexBuffer->GetSize(), indices.data(), IndexBuffer->GetSize());
|
||||
|
||||
VkRenderer::Get().ImmediateSubmit([&](VkCommandBuffer cmd) {
|
||||
auto command = Cmd(cmd);
|
||||
command.DebugScope("VkMesh UploadToGPU");
|
||||
VkBufferCopy vertexCopy{ 0 };
|
||||
vertexCopy.dstOffset = 0;
|
||||
vertexCopy.srcOffset = 0;
|
||||
@@ -65,6 +68,9 @@ void VkMesh::CreateDescriptorSet()
|
||||
builder.AddBinding(0, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
||||
DescriptorLayout = builder.Build(device, VK_SHADER_STAGE_ALL_GRAPHICS);
|
||||
DescriptorSet = vk.GetDescriptorAllocator().Allocate(device, DescriptorLayout);
|
||||
|
||||
VulkanUtil::SetDebugName(DescriptorLayout, "VkMesh " + std::to_string(ID) + " DescriptorLayout");
|
||||
VulkanUtil::SetDebugName(DescriptorSet, "VkMesh " + std::to_string(ID) + " DescriptorSet");
|
||||
}
|
||||
|
||||
VkDescriptorBufferInfo bufferInfo{};
|
||||
|
||||
@@ -46,6 +46,8 @@ namespace Nuake
|
||||
int ReceiveShadow;
|
||||
int CastShadow;
|
||||
int Unlit;
|
||||
int AlphaScissor;
|
||||
int pad[3];
|
||||
};
|
||||
|
||||
// This is the *whole* buffer
|
||||
@@ -91,7 +93,7 @@ namespace Nuake
|
||||
|
||||
constexpr uint32_t MAX_MODEL_MATRIX = 3000;
|
||||
constexpr uint32_t MAX_MATERIAL = 3000;
|
||||
constexpr uint32_t MAX_TEXTURES = 1000;
|
||||
constexpr uint32_t MAX_TEXTURES = 3000;
|
||||
constexpr uint32_t MAX_CAMERAS = 1000;
|
||||
constexpr uint32_t MAX_LIGHTS = 100;
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "VulkanRenderer.h"
|
||||
|
||||
#include "vk_mem_alloc.h"
|
||||
#include "VulkanInit.h"
|
||||
#include "VkResources.h"
|
||||
using namespace Nuake;
|
||||
|
||||
@@ -33,6 +34,8 @@ AllocatedBuffer::AllocatedBuffer(const std::string& name, size_t inSize, BufferU
|
||||
AllocatedBuffer::AllocatedBuffer(inSize, inFlags, inUsage)
|
||||
{
|
||||
Name = name.empty() ? std::to_string(ID) : name; // Default name is just ID
|
||||
|
||||
VulkanUtil::SetDebugName(Buffer, "Name");
|
||||
}
|
||||
|
||||
AllocatedBuffer::~AllocatedBuffer()
|
||||
|
||||
@@ -62,13 +62,19 @@ VulkanImage::VulkanImage(const std::string & path) :
|
||||
|
||||
vmaCreateImage(VulkanAllocator::Get().GetAllocator(), &imgCreateInfo, &imgAllocInfo, &Image, &Allocation, nullptr);
|
||||
|
||||
VulkanUtil::SetDebugName(Image, path + "Image");
|
||||
|
||||
VkImageViewCreateInfo imageViewCreateInfo = VulkanInit::ImageviewCreateInfo(static_cast<VkFormat>(Format), Image, VK_IMAGE_ASPECT_COLOR_BIT);
|
||||
|
||||
VK_CALL(vkCreateImageView(VkRenderer::Get().GetDevice(), &imageViewCreateInfo, nullptr, &ImageView));
|
||||
|
||||
VulkanUtil::SetDebugName(ImageView, path + "ImageView");
|
||||
|
||||
// Transition image and copy data to GPU
|
||||
VkRenderer::Get().ImmediateSubmit([&](VkCommandBuffer cmd)
|
||||
{
|
||||
Cmd command(cmd);
|
||||
command.DebugScope("Image CPU to GPU Copy");
|
||||
TransitionLayout(cmd, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
|
||||
//VulkanUtil::TransitionImage(cmd, Image, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
|
||||
|
||||
@@ -225,6 +231,7 @@ VulkanImage::VulkanImage(void* inData, ImageFormat inFormat, Vector2 inSize) : V
|
||||
Layout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||
VkRenderer::Get().ImmediateSubmit([&](VkCommandBuffer cmd)
|
||||
{
|
||||
|
||||
TransitionLayout(cmd, VK_IMAGE_LAYOUT_GENERAL);
|
||||
TransitionLayout(cmd, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
|
||||
VkBufferImageCopy copyRegion = {};
|
||||
@@ -296,7 +303,6 @@ VulkanImage::VulkanImage(void* inData, size_t inSize) :
|
||||
|
||||
vmaCreateImage(VulkanAllocator::Get().GetAllocator(), &imgCreateInfo, &imgAllocInfo, &Image, &Allocation, nullptr);
|
||||
|
||||
|
||||
VkImageViewCreateInfo imageViewCreateInfo = VulkanInit::ImageviewCreateInfo(static_cast<VkFormat>(Format), Image, VK_IMAGE_ASPECT_COLOR_BIT);
|
||||
|
||||
VK_CALL(vkCreateImageView(VkRenderer::Get().GetDevice(), &imageViewCreateInfo, nullptr, &ImageView));
|
||||
@@ -336,7 +342,8 @@ VulkanImage::~VulkanImage()
|
||||
void VulkanImage::SetDebugName(const std::string& name)
|
||||
{
|
||||
GPUManaged::SetDebugName(name);
|
||||
|
||||
VulkanUtil::SetDebugName(Image, name);
|
||||
VulkanUtil::SetDebugName(ImageView, name);
|
||||
vmaSetAllocationName(VulkanAllocator::Get().GetAllocator(), Allocation, GetDebugName().data());
|
||||
}
|
||||
|
||||
@@ -401,6 +408,7 @@ VkDescriptorSet& VulkanImage::GetImGuiDescriptorSet()
|
||||
|
||||
ImGuiDescriptorSetGenerated = true;
|
||||
|
||||
|
||||
struct cleanUpData
|
||||
{
|
||||
VkDescriptorSet descriptorSet;
|
||||
@@ -413,6 +421,8 @@ VkDescriptorSet& VulkanImage::GetImGuiDescriptorSet()
|
||||
Sampler
|
||||
};
|
||||
|
||||
|
||||
|
||||
AddGPUCleanUpFunc([=]() {
|
||||
cleanUpData data = dataToCleanUp;
|
||||
ImGui_ImplVulkan_RemoveTexture(data.descriptorSet);
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
|
||||
#include <volk/volk.h>
|
||||
#include "Nuake/Core/Maths.h"
|
||||
#include "Nuake/Rendering/Vulkan/VulkanRenderer.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace Nuake
|
||||
@@ -46,5 +48,80 @@ namespace Nuake
|
||||
|
||||
static void TransitionImage(VkCommandBuffer cmd, VkImage image, VkImageLayout currentLayout, VkImageLayout newLayout, bool isDepth = false);
|
||||
static void CopyImageToImage(VkCommandBuffer cmd, VkImage source, VkImage destination, Vector2 srcSize, Vector2 dstSize);
|
||||
|
||||
template<typename VulkanHandleType>
|
||||
static constexpr VkObjectType GetVkObjectType()
|
||||
{
|
||||
if constexpr (std::is_same_v<VulkanHandleType, VkBuffer>) {
|
||||
return VK_OBJECT_TYPE_BUFFER;
|
||||
}
|
||||
else if constexpr (std::is_same_v<VulkanHandleType, VkImage>) {
|
||||
return VK_OBJECT_TYPE_IMAGE;
|
||||
}
|
||||
else if constexpr (std::is_same_v<VulkanHandleType, VkShaderModule>) {
|
||||
return VK_OBJECT_TYPE_SHADER_MODULE;
|
||||
}
|
||||
else if constexpr (std::is_same_v<VulkanHandleType, VkPipeline>) {
|
||||
return VK_OBJECT_TYPE_PIPELINE;
|
||||
}
|
||||
else if constexpr (std::is_same_v<VulkanHandleType, VkDescriptorSet>) {
|
||||
return VK_OBJECT_TYPE_DESCRIPTOR_SET;
|
||||
}
|
||||
else if constexpr (std::is_same_v<VulkanHandleType, VkPipelineLayout>) {
|
||||
return VK_OBJECT_TYPE_PIPELINE_LAYOUT;
|
||||
}
|
||||
else if constexpr (std::is_same_v<VulkanHandleType, VkRenderPass>) {
|
||||
return VK_OBJECT_TYPE_RENDER_PASS;
|
||||
}
|
||||
else if constexpr (std::is_same_v<VulkanHandleType, VkFramebuffer>) {
|
||||
return VK_OBJECT_TYPE_FRAMEBUFFER;
|
||||
}
|
||||
else if constexpr (std::is_same_v<VulkanHandleType, VkDescriptorSetLayout>) {
|
||||
return VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT;
|
||||
}
|
||||
else if constexpr (std::is_same_v<VulkanHandleType, VkBufferView>) {
|
||||
return VK_OBJECT_TYPE_BUFFER_VIEW;
|
||||
}
|
||||
else if constexpr (std::is_same_v<VulkanHandleType, VkImageView>) {
|
||||
return VK_OBJECT_TYPE_IMAGE_VIEW;
|
||||
}
|
||||
else if constexpr (std::is_same_v<VulkanHandleType, VkSampler>) {
|
||||
return VK_OBJECT_TYPE_SAMPLER;
|
||||
}
|
||||
else if constexpr (std::is_same_v<VulkanHandleType, VkSamplerYcbcrConversion>) {
|
||||
return VK_OBJECT_TYPE_SAMPLER_YCBCR_CONVERSION;
|
||||
}
|
||||
else if constexpr (std::is_same_v<VulkanHandleType, VkPipelineCache>) {
|
||||
return VK_OBJECT_TYPE_PIPELINE_CACHE;
|
||||
}
|
||||
else if constexpr (std::is_same_v<VulkanHandleType, VkQueryPool>) {
|
||||
return VK_OBJECT_TYPE_QUERY_POOL;
|
||||
}
|
||||
else if constexpr (std::is_same_v<VulkanHandleType, VkEvent>) {
|
||||
return VK_OBJECT_TYPE_EVENT;
|
||||
}
|
||||
else if constexpr (std::is_same_v<VulkanHandleType, VkFence>) {
|
||||
return VK_OBJECT_TYPE_FENCE;
|
||||
}
|
||||
else if constexpr (std::is_same_v<VulkanHandleType, VkSemaphore>) {
|
||||
return VK_OBJECT_TYPE_SEMAPHORE;
|
||||
}
|
||||
else {
|
||||
static_assert(false, "Unknown Vulkan object type.");
|
||||
return VK_OBJECT_TYPE_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename VulkanHandleType>
|
||||
static void SetDebugName(VulkanHandleType object, const std::string& name)
|
||||
{
|
||||
VkDebugUtilsObjectNameInfoEXT info{};
|
||||
info.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT;
|
||||
info.objectType = GetVkObjectType<VulkanHandleType>();
|
||||
info.objectHandle = reinterpret_cast<uint64_t>(object);
|
||||
info.pObjectName = name.c_str();
|
||||
|
||||
vkSetDebugUtilsObjectNameEXT(VkRenderer::Get().GetDevice(), &info);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -179,6 +179,7 @@ void VkRenderer::GetInstance()
|
||||
//make the vulkan instance, with basic debug features
|
||||
auto instRet = builder.set_app_name("Nuake Engine")
|
||||
.request_validation_layers(NKUseValidationLayer)
|
||||
.enable_extension(VK_EXT_DEBUG_UTILS_EXTENSION_NAME)
|
||||
.use_default_debug_messenger()
|
||||
.require_api_version(1, 3, 0)
|
||||
.build();
|
||||
@@ -209,7 +210,7 @@ void VkRenderer::SelectGPU()
|
||||
{
|
||||
VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME,
|
||||
VK_KHR_LINE_RASTERIZATION_EXTENSION_NAME,
|
||||
VK_EXT_EXTENDED_DYNAMIC_STATE_3_EXTENSION_NAME
|
||||
VK_EXT_EXTENDED_DYNAMIC_STATE_3_EXTENSION_NAME,
|
||||
};
|
||||
|
||||
auto systemInfoRet = vkb::SystemInfo::get_system_info();
|
||||
@@ -219,9 +220,9 @@ void VkRenderer::SelectGPU()
|
||||
{
|
||||
if (!systemInfo.is_extension_available(extension))
|
||||
{
|
||||
std::string errMessage = "No GPU found who supports the required Vulkan extension: " + std::string(extension);
|
||||
errMessage += "\nConsider updating drivers.";
|
||||
Logger::Log(errMessage, "vulkan", CRITICAL);
|
||||
//std::string errMessage = "No GPU found who supports the required Vulkan extension: " + std::string(extension);
|
||||
//errMessage += "\nConsider updating drivers.";
|
||||
//Logger::Log(errMessage, "vulkan", CRITICAL);
|
||||
//OS::ShowMessageBox("Vulkan Error", errMessage);
|
||||
}
|
||||
}
|
||||
@@ -233,7 +234,7 @@ void VkRenderer::SelectGPU()
|
||||
.set_required_features_12(features12)
|
||||
.set_required_features(VkPhysicalDeviceFeatures{
|
||||
.fillModeNonSolid = VK_TRUE,
|
||||
.wideLines = VK_TRUE
|
||||
.wideLines = VK_TRUE,
|
||||
})
|
||||
.set_surface(Surface)
|
||||
.add_required_extensions(requiredExtensions)
|
||||
@@ -451,6 +452,11 @@ void VkRenderer::DrawScenes()
|
||||
ctx.SelectedEntityID = viewport->GetSelectedEntityID();
|
||||
|
||||
SceneRenderers[view]->DrawSceneView(ctx);
|
||||
Stats.ViewRenderers++;
|
||||
}
|
||||
else
|
||||
{
|
||||
Stats.ViewRenderSkipped++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -737,6 +743,8 @@ void VkRenderer::BeginScene(const UUID& camera)
|
||||
|
||||
bool VkRenderer::Draw()
|
||||
{
|
||||
Stats = {};
|
||||
|
||||
VK_CALL(vkWaitForFences(Device, 1, &GetCurrentFrame().RenderFence, true, 1000000000));
|
||||
|
||||
if (SurfaceSize != Window::Get()->GetSize())
|
||||
@@ -798,7 +806,6 @@ bool VkRenderer::Draw()
|
||||
std::mutex queueMutex;
|
||||
void VkRenderer::EndDraw()
|
||||
{
|
||||
|
||||
std::lock_guard<std::mutex> lock(queueMutex);
|
||||
if (FrameSkipped)
|
||||
{
|
||||
@@ -894,7 +901,9 @@ void VkRenderer::ImmediateSubmit(std::function<void(VkCommandBuffer cmd)>&& func
|
||||
VK_CALL(vkResetCommandBuffer(ImguiCommandBuffer, 0));
|
||||
|
||||
VkCommandBuffer cmd = ImguiCommandBuffer;
|
||||
Cmd command(cmd);
|
||||
|
||||
command.DebugScope("Immediate Submit", Color(1, 1, 0, 1));
|
||||
VkCommandBufferBeginInfo cmdBeginInfo = VulkanInit::CommandBufferBeginInfo(VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT);
|
||||
|
||||
VK_CALL(vkBeginCommandBuffer(cmd, &cmdBeginInfo));
|
||||
@@ -927,8 +936,6 @@ void DescriptorAllocator::InitPool(VkDevice device, uint32_t maxSets, std::span<
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
VkDescriptorPoolCreateInfo pool_info = { .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO };
|
||||
pool_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
|
||||
pool_info.maxSets = maxSets;
|
||||
|
||||
@@ -134,6 +134,13 @@ namespace Nuake
|
||||
|
||||
class Viewport;
|
||||
|
||||
struct RendererStats
|
||||
{
|
||||
int ViewRenderers = 0;
|
||||
int ViewRenderSkipped = 0;
|
||||
int DrawCalls = 0;
|
||||
};
|
||||
|
||||
class VkRenderer
|
||||
{
|
||||
private:
|
||||
@@ -165,6 +172,7 @@ namespace Nuake
|
||||
DescriptorAllocator GlobalDescriptorAllocator;
|
||||
|
||||
public:
|
||||
RendererStats Stats;
|
||||
uint32_t FrameNumber = 0;
|
||||
VkDescriptorSet DrawImageDescriptors;
|
||||
VkDescriptorSetLayout DrawImageDescriptorLayout;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "VulkanAllocator.h"
|
||||
|
||||
#include "GPUManaged.h"
|
||||
#include "VulkanInit.h"
|
||||
|
||||
using namespace Nuake;
|
||||
|
||||
@@ -228,6 +229,7 @@ void GPUResources::CreateBindlessLayout()
|
||||
DescriptorLayoutBuilder builder;
|
||||
builder.AddBinding(0, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
||||
ModelDescriptorLayout = builder.Build(device, VK_SHADER_STAGE_ALL_GRAPHICS);
|
||||
VulkanUtil::SetDebugName(ModelDescriptorLayout, "ModelDescriptorLayout");
|
||||
}
|
||||
|
||||
// Triangles
|
||||
@@ -235,6 +237,7 @@ void GPUResources::CreateBindlessLayout()
|
||||
DescriptorLayoutBuilder builder;
|
||||
builder.AddBinding(0, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
||||
TriangleBufferDescriptorLayout = builder.Build(device, VK_SHADER_STAGE_ALL_GRAPHICS);
|
||||
VulkanUtil::SetDebugName(TriangleBufferDescriptorLayout, "TriangleBufferDescriptorLayout");
|
||||
}
|
||||
|
||||
// SSAO kernel
|
||||
@@ -242,6 +245,7 @@ void GPUResources::CreateBindlessLayout()
|
||||
DescriptorLayoutBuilder builder;
|
||||
builder.AddBinding(0, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
||||
SSAOKernelDescriptorLayout = builder.Build(device, VK_SHADER_STAGE_ALL_GRAPHICS);
|
||||
VulkanUtil::SetDebugName(SSAOKernelDescriptorLayout, "SSAOKernelDescriptorLayout");
|
||||
}
|
||||
|
||||
// Samplers
|
||||
@@ -249,6 +253,7 @@ void GPUResources::CreateBindlessLayout()
|
||||
DescriptorLayoutBuilder builder;
|
||||
builder.AddBinding(0, VK_DESCRIPTOR_TYPE_SAMPLER, 2);
|
||||
SamplerDescriptorLayout = builder.Build(device, VK_SHADER_STAGE_ALL_GRAPHICS);
|
||||
VulkanUtil::SetDebugName(SamplerDescriptorLayout, "SamplerDescriptorLayout");
|
||||
}
|
||||
|
||||
// Material
|
||||
@@ -256,6 +261,7 @@ void GPUResources::CreateBindlessLayout()
|
||||
DescriptorLayoutBuilder builder;
|
||||
builder.AddBinding(0, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
||||
MaterialDescriptorLayout = builder.Build(device, VK_SHADER_STAGE_ALL_GRAPHICS);
|
||||
VulkanUtil::SetDebugName(MaterialDescriptorLayout, "MaterialDescriptorLayout");
|
||||
}
|
||||
|
||||
// Textures
|
||||
@@ -263,6 +269,7 @@ void GPUResources::CreateBindlessLayout()
|
||||
DescriptorLayoutBuilder builder;
|
||||
builder.AddBinding(0, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, MAX_TEXTURES);
|
||||
TexturesDescriptorLayout = builder.Build(device, VK_SHADER_STAGE_ALL_GRAPHICS);
|
||||
VulkanUtil::SetDebugName(TexturesDescriptorLayout, "TexturesDescriptorLayout");
|
||||
}
|
||||
|
||||
// bindless lights
|
||||
@@ -270,6 +277,7 @@ void GPUResources::CreateBindlessLayout()
|
||||
DescriptorLayoutBuilder builder;
|
||||
builder.AddBinding(0, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
||||
LightsDescriptorLayout = builder.Build(device, VK_SHADER_STAGE_ALL_GRAPHICS);
|
||||
VulkanUtil::SetDebugName(LightsDescriptorLayout, "LightsDescriptorLayout");
|
||||
}
|
||||
|
||||
// bindless cameras
|
||||
@@ -277,6 +285,7 @@ void GPUResources::CreateBindlessLayout()
|
||||
DescriptorLayoutBuilder builder;
|
||||
builder.AddBinding(0, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
||||
CamerasDescriptorLayout = builder.Build(device, VK_SHADER_STAGE_ALL_GRAPHICS);
|
||||
VulkanUtil::SetDebugName(CamerasDescriptorLayout, "CamerasDescriptorLayout");
|
||||
}
|
||||
|
||||
auto allocator = vk.GetDescriptorAllocator();
|
||||
@@ -289,6 +298,14 @@ void GPUResources::CreateBindlessLayout()
|
||||
MaterialDescriptor = allocator.Allocate(device, MaterialDescriptorLayout);
|
||||
SSAOKernelDescriptor = allocator.Allocate(device, SSAOKernelDescriptorLayout);
|
||||
|
||||
VulkanUtil::SetDebugName(TexturesDescriptor, "TextureDescriptor");
|
||||
VulkanUtil::SetDebugName(CamerasDescriptor, "CamerasDescriptor");
|
||||
VulkanUtil::SetDebugName(TriangleBufferDescriptor, "TriangleBufferDescriptor");
|
||||
VulkanUtil::SetDebugName(ModelDescriptor, "ModelDescriptor");
|
||||
VulkanUtil::SetDebugName(LightsDescriptor, "LightsDescriptor");
|
||||
VulkanUtil::SetDebugName(MaterialDescriptor, "MaterialDescriptor");
|
||||
VulkanUtil::SetDebugName(SSAOKernelDescriptor, "SSAOKernelDescriptor");
|
||||
|
||||
// Samplers
|
||||
VkPhysicalDeviceProperties properties{};
|
||||
vkGetPhysicalDeviceProperties(VkRenderer::Get().GetPhysicalDevice(), &properties);
|
||||
|
||||
@@ -555,7 +555,8 @@ void VkSceneRenderer::PrepareScenes(const std::vector<Ref<Scene>>& scenes, Rende
|
||||
.SamplerType = static_cast<int>(material->m_SamplingType),
|
||||
.ReceiveShadow = material->m_ReceiveShadows,
|
||||
.CastShadow = material->m_CastShadows,
|
||||
.Unlit = material->data.u_Unlit
|
||||
.Unlit = material->data.u_Unlit,
|
||||
.AlphaScissor = static_cast<int>(material->m_AlphaScissor)
|
||||
};
|
||||
|
||||
// Save bindless mapping index
|
||||
|
||||
Reference in New Issue
Block a user