More Refactoring

This commit is contained in:
Dynamitos
2023-11-15 17:42:57 +01:00
parent f8f48352a3
commit 35966cb5b7
60 changed files with 1217 additions and 2332 deletions
+58 -7
View File
@@ -1,10 +1,5 @@
import Common; import Common;
struct VertexShaderInput
{
float3 position;
};
struct VertexShaderOutput struct VertexShaderOutput
{ {
float4 clipPos : SV_Position; float4 clipPos : SV_Position;
@@ -18,13 +13,69 @@ struct SkyboxData
layout(set=1) layout(set=1)
ParameterBlock<SkyboxData> pSkyboxData; ParameterBlock<SkyboxData> pSkyboxData;
float3 vertices[] = {
// Back
float3(-512, -512, 512),
float3(-512, 512, 512),
float3( 512, -512, 512),
float3( 512, -512, 512),
float3(-512, 512, 512),
float3( 512, 512, 512),
// Front
float3( 512, -512, -512),
float3( 512, 512, -512),
float3(-512, -512, -512),
float3(-512, -512, -512),
float3( 512, 512, -512),
float3(-512, 512, -512),
// Top
float3(-512, -512, -512),
float3(-512, -512, 512),
float3( 512, -512, -512),
float3( 512, -512, -512),
float3(-512, -512, 512),
float3( 512, -512, 512),
// Bottom
float3(-512, 512, 512),
float3(-512, 512, -512),
float3( 512, 512, 512),
float3( 512, 512, 512),
float3(-512, 512, -512),
float3( 512, 512, -512),
// Left
float3(-512, -512, -512),
float3(-512, 512, -512),
float3(-512, -512, 512),
float3(-512, -512, 512),
float3(-512, 512, -512),
float3(-512, 512, 512),
// Right
float3( 512, -512, 512),
float3( 512, 512, 512),
float3( 512, -512, -512),
float3( 512, -512, -512),
float3( 512, 512, 512),
float3( 512, 512, -512),
};
[shader("vertex")] [shader("vertex")]
VertexShaderOutput vertexMain( VertexShaderOutput vertexMain(
VertexShaderInput input) uint vertexIndex : SV_VertexId)
{ {
VertexShaderOutput output; VertexShaderOutput output;
float3x3 cameraRotation = float3x3(pViewParams.viewMatrix); float3x3 cameraRotation = float3x3(pViewParams.viewMatrix);
float4 worldPos = float4(mul(cameraRotation, input.position), 1.0f); float4 worldPos = float4(mul(cameraRotation, vertices[vertexIndex]), 1.0f);
//clip(dot(worldPos, clipPlane)); //clip(dot(worldPos, clipPlane));
output.clipPos = mul(pViewParams.projectionMatrix, worldPos); output.clipPos = mul(pViewParams.projectionMatrix, worldPos);
output.texCoords = normalize(input.position); output.texCoords = normalize(input.position);
+17 -8
View File
@@ -13,15 +13,24 @@ ParameterBlock<SamplerState> glyphSampler;
//layout(set = 1) //layout(set = 1)
//ShaderBuffer<GlyphData> glyphData; //ShaderBuffer<GlyphData> glyphData;
ParameterBuffer<Texture2D<uint>[]> pGlyphTextures; ParameterBuffer<Texture2D<uint>[]> pGlyphTextures;
[[vk::push_constant]]
ConstantBuffer<TextData> textData;
struct VertexInput struct GlyphInstanceData
{ {
float2 position; float2 position;
float2 widthHeight; float2 widthHeight;
uint glyphIndex; uint glyphIndex;
};
struct TextRender
{
StructuredBuffer<GlyphInstanceData> instances;
TextData textData;
}
ParameterBuffer<TextRender> pRender;
struct VertexInput
{
uint vertexId : SV_VertexID; uint vertexId : SV_VertexID;
uint instanceId : SV_InstanceID;
}; };
struct VertexOutput struct VertexOutput
@@ -34,11 +43,11 @@ struct VertexOutput
[shader("vertex")] [shader("vertex")]
VertexOutput vertexMain(VertexInput input) VertexOutput vertexMain(VertexInput input)
{ {
float xpos = input.position.x; float xpos = pRender.instances[input.instanceId].position.x;
float ypos = input.position.y; float ypos = pRender.instances[input.instanceId].position.y;
float w = input.widthHeight.x; float w = pRender.instances[input.instanceId].widthHeight.x;
float h = input.widthHeight.y; float h = pRender.instances[input.instanceId].widthHeight.y;
float4 coordinates[4] = { float4 coordinates[4] = {
float4(xpos, ypos, 0, 1), float4(xpos, ypos, 0, 1),
@@ -50,7 +59,7 @@ VertexOutput vertexMain(VertexInput input)
VertexStageOutput output; VertexStageOutput output;
output.texCoords = vertex.zw; output.texCoords = vertex.zw;
output.position = mul(viewData.projectionMatrix, float4(vertex.xy, 0, 1)); output.position = mul(viewData.projectionMatrix, float4(vertex.xy, 0, 1));
output.glyphIndex = input.glyphIndex; output.glyphIndex = pRender.instances[input.instanceId].glyphIndex;
return output; return output;
} }
+3 -2
View File
@@ -1,5 +1,6 @@
#include "MaterialLoader.h" #include "MaterialLoader.h"
#include "Graphics/Graphics.h" #include "Graphics/Graphics.h"
#include "Graphics/Shader.h"
#include "Asset/MaterialAsset.h" #include "Asset/MaterialAsset.h"
#include "Asset/AssetRegistry.h" #include "Asset/AssetRegistry.h"
#include "Material/Material.h" #include "Material/Material.h"
@@ -109,11 +110,11 @@ void MaterialLoader::import(MaterialImportArgs args, PMaterialAsset asset)
parameters.add(p->key); parameters.add(p->key);
expressions.add(std::move(p)); expressions.add(std::move(p));
} }
else if(type.compare("SamplerState") == 0) else if(type.compare("Sampler") == 0)
{ {
OSamplerParameter p = new SamplerParameter(param.key(), 0, bindingCounter); OSamplerParameter p = new SamplerParameter(param.key(), 0, bindingCounter);
layout->addDescriptorBinding(bindingCounter++, Gfx::SE_DESCRIPTOR_TYPE_SAMPLER); layout->addDescriptorBinding(bindingCounter++, Gfx::SE_DESCRIPTOR_TYPE_SAMPLER);
p->data = graphics->createSamplerState({}); p->data = graphics->createSampler({});
parameters.add(p->key); parameters.add(p->key);
expressions.add(std::move(p)); expressions.add(std::move(p));
} }
+1
View File
@@ -107,6 +107,7 @@ AssetRegistry &AssetRegistry::get()
} }
AssetRegistry::AssetRegistry() AssetRegistry::AssetRegistry()
: assetRoot(nullptr)
{ {
} }
+3 -3
View File
@@ -100,13 +100,13 @@ void FontAsset::load(ArchiveBuffer& buffer)
.data = ktxTexture_GetData(ktxTexture(kTexture)), .data = ktxTexture_GetData(ktxTexture(kTexture)),
.owner = Gfx::QueueType::GRAPHICS, .owner = Gfx::QueueType::GRAPHICS,
}, },
.format = Vulkan::cast((VkFormat)kTexture->vkFormat),
.width = kTexture->baseWidth, .width = kTexture->baseWidth,
.height = kTexture->baseHeight, .height = kTexture->baseHeight,
.depth = kTexture->baseDepth, .depth = kTexture->baseDepth,
.bArray = kTexture->isArray,
.arrayLayers = kTexture->isArray ? kTexture->numLayers : kTexture->numFaces,
.mipLevels = kTexture->numLevels, .mipLevels = kTexture->numLevels,
.format = Vulkan::cast((VkFormat)kTexture->vkFormat), .layers = kTexture->numFaces,
.elements = kTexture->numLayers,
.usage = Gfx::SE_IMAGE_USAGE_SAMPLED_BIT, .usage = Gfx::SE_IMAGE_USAGE_SAMPLED_BIT,
}; };
+3 -3
View File
@@ -91,13 +91,13 @@ void TextureAsset::load(ArchiveBuffer& buffer)
.data = ktxTexture_GetData(ktxTexture(kTexture)), .data = ktxTexture_GetData(ktxTexture(kTexture)),
.owner = Gfx::QueueType::DEDICATED_TRANSFER, .owner = Gfx::QueueType::DEDICATED_TRANSFER,
}, },
.format = Vulkan::cast((VkFormat)kTexture->vkFormat),
.width = kTexture->baseWidth, .width = kTexture->baseWidth,
.height = kTexture->baseHeight, .height = kTexture->baseHeight,
.depth = kTexture->baseDepth, .depth = kTexture->baseDepth,
.bArray = kTexture->isArray,
.arrayLayers = kTexture->isArray ? kTexture->numLayers : kTexture->numFaces,
.mipLevels = kTexture->numLevels, .mipLevels = kTexture->numLevels,
.format = Vulkan::cast((VkFormat)kTexture->vkFormat), .layers = kTexture->numFaces,
.elements = kTexture->numLayers,
.usage = Gfx::SE_IMAGE_USAGE_SAMPLED_BIT, .usage = Gfx::SE_IMAGE_USAGE_SAMPLED_BIT,
}; };
if (kTexture->isCubemap) if (kTexture->isCubemap)
+1
View File
@@ -1,5 +1,6 @@
#pragma once #pragma once
#include "Enums.h" #include "Enums.h"
#include "Descriptor.h"
namespace Seele namespace Seele
{ {
+4 -4
View File
@@ -31,11 +31,11 @@ DescriptorBinding& DescriptorBinding::operator=(const DescriptorBinding& other)
return *this; return *this;
} }
DescriptorAllocator::DescriptorAllocator() DescriptorPool::DescriptorPool()
{ {
} }
DescriptorAllocator::~DescriptorAllocator() DescriptorPool::~DescriptorPool()
{ {
} }
@@ -87,12 +87,12 @@ void DescriptorLayout::addDescriptorBinding(uint32 bindingIndex, SeDescriptorTyp
PDescriptorSet DescriptorLayout::allocateDescriptorSet() PDescriptorSet DescriptorLayout::allocateDescriptorSet()
{ {
return allocator->allocateDescriptorSet(); return pool->allocateDescriptorSet();
} }
void DescriptorLayout::reset() void DescriptorLayout::reset()
{ {
allocator->reset(); pool->reset();
} }
PipelineLayout::PipelineLayout() PipelineLayout::PipelineLayout()
+8 -7
View File
@@ -21,15 +21,15 @@ public:
DEFINE_REF(DescriptorBinding) DEFINE_REF(DescriptorBinding)
DECLARE_REF(DescriptorSet) DECLARE_REF(DescriptorSet)
class DescriptorAllocator class DescriptorPool
{ {
public: public:
DescriptorAllocator(); DescriptorPool();
virtual ~DescriptorAllocator(); virtual ~DescriptorPool();
virtual PDescriptorSet allocateDescriptorSet() = 0; virtual PDescriptorSet allocateDescriptorSet() = 0;
virtual void reset() = 0; virtual void reset() = 0;
}; };
DEFINE_REF(DescriptorAllocator) DEFINE_REF(DescriptorPool)
DECLARE_REF(UniformBuffer) DECLARE_REF(UniformBuffer)
DECLARE_REF(ShaderBuffer) DECLARE_REF(ShaderBuffer)
DECLARE_REF(Texture) DECLARE_REF(Texture)
@@ -68,11 +68,11 @@ public:
protected: protected:
Array<DescriptorBinding> descriptorBindings; Array<DescriptorBinding> descriptorBindings;
ODescriptorAllocator allocator; ODescriptorPool pool;
uint32 setIndex; uint32 setIndex;
std::string name; std::string name;
friend class PipelineLayout; friend class PipelineLayout;
friend class DescriptorAllocator; friend class DescriptorPool;
}; };
DEFINE_REF(DescriptorLayout) DEFINE_REF(DescriptorLayout)
class PipelineLayout class PipelineLayout
@@ -85,9 +85,10 @@ public:
virtual void reset() = 0; virtual void reset() = 0;
void addDescriptorLayout(uint32 setIndex, PDescriptorLayout layout); void addDescriptorLayout(uint32 setIndex, PDescriptorLayout layout);
void addPushConstants(const SePushConstantRange& pushConstants); void addPushConstants(const SePushConstantRange& pushConstants);
virtual uint32 getHash() const = 0; constexpr uint32 getHash() const { return layoutHash; }
protected: protected:
uint32 layoutHash;
Array<PDescriptorLayout> descriptorSetLayouts; Array<PDescriptorLayout> descriptorSetLayouts;
Array<SePushConstantRange> pushConstants; Array<SePushConstantRange> pushConstants;
}; };
+3 -1
View File
@@ -29,6 +29,8 @@ DECLARE_REF(UniformBuffer)
DECLARE_REF(PipelineLayout) DECLARE_REF(PipelineLayout)
DECLARE_REF(GraphicsPipeline) DECLARE_REF(GraphicsPipeline)
DECLARE_REF(ComputePipeline) DECLARE_REF(ComputePipeline)
DECLARE_REF(RenderCommand)
DECLARE_REF(ComputeCommand)
class Graphics class Graphics
{ {
public: public:
@@ -75,7 +77,7 @@ public:
virtual PGraphicsPipeline createGraphicsPipeline(LegacyPipelineCreateInfo createInfo) = 0; virtual PGraphicsPipeline createGraphicsPipeline(LegacyPipelineCreateInfo createInfo) = 0;
virtual PGraphicsPipeline createGraphicsPipeline(MeshPipelineCreateInfo createInfo) = 0; virtual PGraphicsPipeline createGraphicsPipeline(MeshPipelineCreateInfo createInfo) = 0;
virtual PComputePipeline createComputePipeline(ComputePipelineCreateInfo createInfo) = 0; virtual PComputePipeline createComputePipeline(ComputePipelineCreateInfo createInfo) = 0;
virtual OSampler createSamplerState(const SamplerCreateInfo& createInfo) = 0; virtual OSampler createSampler(const SamplerCreateInfo& createInfo) = 0;
virtual ODescriptorLayout createDescriptorLayout(const std::string& name = "") = 0; virtual ODescriptorLayout createDescriptorLayout(const std::string& name = "") = 0;
virtual OPipelineLayout createPipelineLayout(PPipelineLayout baseLayout = nullptr) = 0; virtual OPipelineLayout createPipelineLayout(PPipelineLayout baseLayout = nullptr) = 0;
+2 -2
View File
@@ -17,8 +17,8 @@ LegacyPipelineCreateInfo::LegacyPipelineCreateInfo()
, depthStencilState(DepthStencilState{ , depthStencilState(DepthStencilState{
.depthTestEnable = true, .depthTestEnable = true,
.depthWriteEnable = true, .depthWriteEnable = true,
.stencilTestEnable = false,
.depthCompareOp = Gfx::SE_COMPARE_OP_LESS_OR_EQUAL, .depthCompareOp = Gfx::SE_COMPARE_OP_LESS_OR_EQUAL,
.stencilTestEnable = false,
.minDepthBounds = 0.0f, .minDepthBounds = 0.0f,
.maxDepthBounds = 1.0f, .maxDepthBounds = 1.0f,
}) })
@@ -61,8 +61,8 @@ MeshPipelineCreateInfo::MeshPipelineCreateInfo()
, depthStencilState(DepthStencilState{ , depthStencilState(DepthStencilState{
.depthTestEnable = true, .depthTestEnable = true,
.depthWriteEnable = true, .depthWriteEnable = true,
.stencilTestEnable = false,
.depthCompareOp = Gfx::SE_COMPARE_OP_LESS_OR_EQUAL, .depthCompareOp = Gfx::SE_COMPARE_OP_LESS_OR_EQUAL,
.stencilTestEnable = false,
.minDepthBounds = 0.0f, .minDepthBounds = 0.0f,
.maxDepthBounds = 1.0f, .maxDepthBounds = 1.0f,
}) })
+3 -1
View File
@@ -62,7 +62,8 @@ struct TextureCreateInfo
uint32 height = 1; uint32 height = 1;
uint32 depth = 1; uint32 depth = 1;
uint32 mipLevels = 1; uint32 mipLevels = 1;
uint32 arrayLayers = 1; uint32 layers = 1;
uint32 elements = 1;
uint32 samples = 1; uint32 samples = 1;
Gfx::SeImageUsageFlagBits usage = Gfx::SE_IMAGE_USAGE_SAMPLED_BIT; Gfx::SeImageUsageFlagBits usage = Gfx::SE_IMAGE_USAGE_SAMPLED_BIT;
}; };
@@ -105,6 +106,7 @@ struct UniformBufferCreateInfo
struct ShaderBufferCreateInfo struct ShaderBufferCreateInfo
{ {
DataSource sourceData = DataSource(); DataSource sourceData = DataSource();
uint64 numElements = 1;
uint8 dynamic = 0; uint8 dynamic = 0;
}; };
struct ShaderCreateInfo struct ShaderCreateInfo
+1 -1
View File
@@ -4,7 +4,7 @@ using namespace Seele;
using namespace Seele::Gfx; using namespace Seele::Gfx;
GraphicsPipeline::GraphicsPipeline(OPipelineLayout layout) GraphicsPipeline::GraphicsPipeline(OPipelineLayout layout)
: layout(std::move(layout)) {} : layout(std::move(layout))
{ {
} }
+1 -1
View File
@@ -11,6 +11,7 @@
#include "RenderGraph.h" #include "RenderGraph.h"
#include "Material/MaterialInstance.h" #include "Material/MaterialInstance.h"
#include "Graphics/Descriptor.h" #include "Graphics/Descriptor.h"
#include "Graphics/Command.h"
using namespace Seele; using namespace Seele;
@@ -128,7 +129,6 @@ void BasePass::render()
else else
{ {
Gfx::LegacyPipelineCreateInfo pipelineInfo; Gfx::LegacyPipelineCreateInfo pipelineInfo;
pipelineInfo.vertexDeclaration = collection->vertexDeclaration;
pipelineInfo.vertexShader = collection->vertexShader; pipelineInfo.vertexShader = collection->vertexShader;
pipelineInfo.fragmentShader = collection->fragmentShader; pipelineInfo.fragmentShader = collection->fragmentShader;
pipelineInfo.pipelineLayout = std::move(layout); pipelineInfo.pipelineLayout = std::move(layout);
@@ -8,6 +8,7 @@
#include "Actor/CameraActor.h" #include "Actor/CameraActor.h"
#include "Math/Vector.h" #include "Math/Vector.h"
#include "RenderGraph.h" #include "RenderGraph.h"
#include "Graphics/Command.h"
using namespace Seele; using namespace Seele;
@@ -89,7 +90,6 @@ void DepthPrepass::render()
else else
{ {
Gfx::LegacyPipelineCreateInfo pipelineInfo; Gfx::LegacyPipelineCreateInfo pipelineInfo;
pipelineInfo.vertexDeclaration = collection->vertexDeclaration;
pipelineInfo.vertexShader = collection->vertexShader; pipelineInfo.vertexShader = collection->vertexShader;
pipelineInfo.fragmentShader = collection->fragmentShader; pipelineInfo.fragmentShader = collection->fragmentShader;
pipelineInfo.pipelineLayout = std::move(layout); pipelineInfo.pipelineLayout = std::move(layout);
@@ -141,13 +141,14 @@ void DepthPrepass::endFrame()
void DepthPrepass::publishOutputs() void DepthPrepass::publishOutputs()
{ {
TextureCreateInfo depthBufferInfo;
// If we render to a part of an image, the depth buffer itself must // If we render to a part of an image, the depth buffer itself must
// still match the size of the whole image or their coordinate systems go out of sync // still match the size of the whole image or their coordinate systems go out of sync
depthBufferInfo.width = viewport->getOwner()->getWidth(); TextureCreateInfo depthBufferInfo = {
depthBufferInfo.height = viewport->getOwner()->getHeight(); .format = Gfx::SE_FORMAT_D32_SFLOAT,
depthBufferInfo.format = Gfx::SE_FORMAT_D32_SFLOAT; .width = viewport->getOwner()->getWidth(),
depthBufferInfo.usage = Gfx::SE_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; .height = viewport->getOwner()->getHeight(),
.usage = Gfx::SE_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
};
depthBuffer = graphics->createTexture2D(depthBufferInfo); depthBuffer = graphics->createTexture2D(depthBufferInfo);
depthAttachment = depthAttachment =
new Gfx::RenderTargetAttachment(depthBuffer, Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_STORE); new Gfx::RenderTargetAttachment(depthBuffer, Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_STORE);
@@ -4,6 +4,7 @@
#include "Actor/CameraActor.h" #include "Actor/CameraActor.h"
#include "Component/Camera.h" #include "Component/Camera.h"
#include "RenderGraph.h" #include "RenderGraph.h"
#include "Graphics/Command.h"
using namespace Seele; using namespace Seele;
@@ -130,14 +131,13 @@ void LightCullingPass::publishOutputs()
cullingPipeline = graphics->createComputePipeline(std::move(pipelineInfo)); cullingPipeline = graphics->createComputePipeline(std::move(pipelineInfo));
uint32 counterReset = 0; uint32 counterReset = 0;
ShaderBufferCreateInfo structInfo = ShaderBufferCreateInfo structInfo = {
{
.sourceData = { .sourceData = {
.size = sizeof(uint32), .size = sizeof(uint32),
.data = (uint8*)&counterReset, .data = (uint8*)&counterReset,
.owner = Gfx::QueueType::COMPUTE, .owner = Gfx::QueueType::COMPUTE,
}, },
.stride = sizeof(uint32), .numElements = 1,
.dynamic = true, .dynamic = true,
}; };
oLightIndexCounter = graphics->createShaderBuffer(structInfo); oLightIndexCounter = graphics->createShaderBuffer(structInfo);
@@ -151,7 +151,6 @@ void LightCullingPass::publishOutputs()
.data = nullptr, .data = nullptr,
.owner = Gfx::QueueType::COMPUTE .owner = Gfx::QueueType::COMPUTE
}, },
.stride = sizeof(uint32),
.dynamic = false, .dynamic = false,
}; };
oLightIndexList = graphics->createShaderBuffer(structInfo); oLightIndexList = graphics->createShaderBuffer(structInfo);
@@ -160,9 +159,9 @@ void LightCullingPass::publishOutputs()
resources->registerBufferOutput("LIGHTCULLING_TLIGHTLIST", tLightIndexList); resources->registerBufferOutput("LIGHTCULLING_TLIGHTLIST", tLightIndexList);
TextureCreateInfo textureInfo = { TextureCreateInfo textureInfo = {
.format = Gfx::SE_FORMAT_R32G32_UINT,
.width = dispatchParams.numThreadGroups.x, .width = dispatchParams.numThreadGroups.x,
.height = dispatchParams.numThreadGroups.y, .height = dispatchParams.numThreadGroups.y,
.format = Gfx::SE_FORMAT_R32G32_UINT,
.usage = Gfx::SE_IMAGE_USAGE_STORAGE_BIT, .usage = Gfx::SE_IMAGE_USAGE_STORAGE_BIT,
}; };
oLightGrid = graphics->createTexture2D(textureInfo); oLightGrid = graphics->createTexture2D(textureInfo);
@@ -226,7 +225,7 @@ void LightCullingPass::setupFrustums()
.size = sizeof(Frustum) * numThreads.x * numThreads.y * numThreads.z, .size = sizeof(Frustum) * numThreads.x * numThreads.y * numThreads.z,
.data = nullptr, .data = nullptr,
}, },
.stride = sizeof(Frustum), .numElements = numThreads.x * numThreads.y * numThreads.z,
.dynamic = false, .dynamic = false,
}); });
@@ -1,6 +1,6 @@
#pragma once #pragma once
#include "RenderPass.h" #include "RenderPass.h"
#include "Graphics/Resources.h" #include "Graphics/Shader.h"
#include "Scene/Scene.h" #include "Scene/Scene.h"
namespace Seele namespace Seele
@@ -1,6 +1,7 @@
#include "SkyboxRenderPass.h" #include "SkyboxRenderPass.h"
#include "Graphics/Graphics.h" #include "Graphics/Graphics.h"
#include "Asset/AssetRegistry.h" #include "Asset/AssetRegistry.h"
#include "Graphics/Command.h"
using namespace Seele; using namespace Seele;
@@ -13,71 +14,6 @@ SkyboxRenderPass::SkyboxRenderPass(Gfx::PGraphics graphics, PScene scene)
.fogColor = Vector(0.2, 0.1, 0.6), .fogColor = Vector(0.2, 0.1, 0.6),
.blendFactor = 0, .blendFactor = 0,
}; };
Array<Vector> vertices = {
// Back
Vector(-512, -512, 512),
Vector(-512, 512, 512),
Vector( 512, -512, 512),
Vector( 512, -512, 512),
Vector(-512, 512, 512),
Vector( 512, 512, 512),
// Front
Vector( 512, -512, -512),
Vector( 512, 512, -512),
Vector(-512, -512, -512),
Vector(-512, -512, -512),
Vector( 512, 512, -512),
Vector(-512, 512, -512),
// Top
Vector(-512, -512, -512),
Vector(-512, -512, 512),
Vector( 512, -512, -512),
Vector( 512, -512, -512),
Vector(-512, -512, 512),
Vector( 512, -512, 512),
// Bottom
Vector(-512, 512, 512),
Vector(-512, 512, -512),
Vector( 512, 512, 512),
Vector( 512, 512, 512),
Vector(-512, 512, -512),
Vector( 512, 512, -512),
// Left
Vector(-512, -512, -512),
Vector(-512, 512, -512),
Vector(-512, -512, 512),
Vector(-512, -512, 512),
Vector(-512, 512, -512),
Vector(-512, 512, 512),
// Right
Vector( 512, -512, 512),
Vector( 512, 512, 512),
Vector( 512, -512, -512),
Vector( 512, -512, -512),
Vector( 512, 512, 512),
Vector( 512, 512, -512),
};
VertexBufferCreateInfo vertexBufferInfo = {
.sourceData = {
.size = sizeof(Vector) * vertices.size(),
.data = (uint8*)vertices.data(),
},
.vertexSize = sizeof(Vector),
.numVertices = (uint32)vertices.size(),
};
cubeBuffer = graphics->createVertexBuffer(vertexBufferInfo);
} }
SkyboxRenderPass::~SkyboxRenderPass() SkyboxRenderPass::~SkyboxRenderPass()
{ {
@@ -146,7 +82,7 @@ void SkyboxRenderPass::publishOutputs()
textureLayout->addDescriptorBinding(2, Gfx::SE_DESCRIPTOR_TYPE_SAMPLER); textureLayout->addDescriptorBinding(2, Gfx::SE_DESCRIPTOR_TYPE_SAMPLER);
textureLayout->create(); textureLayout->create();
skyboxSampler = graphics->createSamplerState({}); skyboxSampler = graphics->createSampler({});
} }
void SkyboxRenderPass::createRenderPass() void SkyboxRenderPass::createRenderPass()
@@ -169,16 +105,6 @@ void SkyboxRenderPass::createRenderPass()
createInfo.entryPoint = "fragmentMain"; createInfo.entryPoint = "fragmentMain";
fragmentShader = graphics->createFragmentShader(createInfo); fragmentShader = graphics->createFragmentShader(createInfo);
declaration = graphics->createVertexDeclaration({
Gfx::VertexElement {
.binding = 0,
.offset = 0,
.vertexFormat = Gfx::SE_FORMAT_R32G32B32_SFLOAT,
.attributeIndex = 0,
.stride = sizeof(Vector),
}
});
Gfx::OPipelineLayout pipelineLayout = graphics->createPipelineLayout(); Gfx::OPipelineLayout pipelineLayout = graphics->createPipelineLayout();
pipelineLayout->addDescriptorLayout(0, viewParamsLayout); pipelineLayout->addDescriptorLayout(0, viewParamsLayout);
pipelineLayout->addDescriptorLayout(1, skyboxDataLayout); pipelineLayout->addDescriptorLayout(1, skyboxDataLayout);
@@ -186,7 +112,6 @@ void SkyboxRenderPass::createRenderPass()
pipelineLayout->create(); pipelineLayout->create();
Gfx::LegacyPipelineCreateInfo gfxInfo; Gfx::LegacyPipelineCreateInfo gfxInfo;
gfxInfo.vertexDeclaration = declaration;
gfxInfo.vertexShader = vertexShader; gfxInfo.vertexShader = vertexShader;
gfxInfo.fragmentShader = fragmentShader; gfxInfo.fragmentShader = fragmentShader;
gfxInfo.rasterizationState.polygonMode = Gfx::SE_POLYGON_MODE_FILL; gfxInfo.rasterizationState.polygonMode = Gfx::SE_POLYGON_MODE_FILL;
@@ -1,13 +1,10 @@
#pragma once #pragma once
#include "RenderPass.h" #include "RenderPass.h"
#include "Graphics/Resources.h" #include "Graphics/Shader.h"
#include "Component/Skybox.h" #include "Component/Skybox.h"
namespace Seele namespace Seele
{ {
DECLARE_REF(CameraActor)
DECLARE_REF(Scene)
DECLARE_REF(Viewport)
class SkyboxRenderPass : public RenderPass class SkyboxRenderPass : public RenderPass
{ {
public: public:
@@ -27,11 +24,10 @@ private:
Gfx::PDescriptorSet skyboxDataSet; Gfx::PDescriptorSet skyboxDataSet;
Gfx::ODescriptorLayout textureLayout; Gfx::ODescriptorLayout textureLayout;
Gfx::PDescriptorSet textureSet; Gfx::PDescriptorSet textureSet;
Gfx::OVertexDeclaration declaration;
Gfx::OVertexShader vertexShader; Gfx::OVertexShader vertexShader;
Gfx::OFragmentShader fragmentShader; Gfx::OFragmentShader fragmentShader;
Gfx::PGraphicsPipeline pipeline; Gfx::PGraphicsPipeline pipeline;
Gfx::OSamplerState skyboxSampler; Gfx::OSampler skyboxSampler;
Component::Skybox skybox; Component::Skybox skybox;
}; };
DEFINE_REF(SkyboxRenderPass) DEFINE_REF(SkyboxRenderPass)
+7 -36
View File
@@ -2,6 +2,7 @@
#include "RenderGraph.h" #include "RenderGraph.h"
#include "Graphics/Graphics.h" #include "Graphics/Graphics.h"
#include "Graphics/RenderTarget.h" #include "Graphics/RenderTarget.h"
#include "Graphics/Command.h"
using namespace Seele; using namespace Seele;
@@ -43,15 +44,13 @@ void TextPass::beginFrame(const Component::Camera& cam)
}); });
x += (glyph.advance >> 6) * render.scale; x += (glyph.advance >> 6) * render.scale;
} }
VertexBufferCreateInfo vbInfo = { res.instanceBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
.sourceData = { .sourceData = {
.size = static_cast<uint32>(instanceData.size() * sizeof(GlyphInstanceData)), .size = static_cast<uint32>(instanceData.size() * sizeof(GlyphInstanceData)),
.data = reinterpret_cast<uint8*>(instanceData.data()), .data = reinterpret_cast<uint8*>(instanceData.data()),
}, },
.vertexSize = sizeof(GlyphInstanceData), .numElements = instanceData.size(),
.numVertices = static_cast<uint32>(instanceData.size()), });
};
res.vertexBuffer = graphics->createVertexBuffer(vbInfo);
res.textureArraySet = fd.textureArraySet; res.textureArraySet = fd.textureArraySet;
@@ -83,10 +82,10 @@ void TextPass::render()
for(const auto& resource : res) for(const auto& resource : res)
{ {
command->bindDescriptor({generalSet, resource.textureArraySet}); command->bindDescriptor({generalSet, resource.textureArraySet});
command->bindVertexBuffer({resource.vertexBuffer}); //command->bindVertexBuffer({resource.vertexBuffer});
command->pushConstants(layoutRef, Gfx::SE_SHADER_STAGE_VERTEX_BIT | Gfx::SE_SHADER_STAGE_FRAGMENT_BIT, 0, sizeof(TextData), &resource.textData); command->pushConstants(layoutRef, Gfx::SE_SHADER_STAGE_VERTEX_BIT | Gfx::SE_SHADER_STAGE_FRAGMENT_BIT, 0, sizeof(TextData), &resource.textData);
command->draw(4, static_cast<uint32>(resource.vertexBuffer->getNumVertices()), 0, 0); //command->draw(4, static_cast<uint32>(resource.vertexBuffer->getNumVertices()), 0, 0);
} }
commands.add(command); commands.add(command);
} }
@@ -120,33 +119,6 @@ void TextPass::createRenderPass()
createInfo.name = "TextFragment"; createInfo.name = "TextFragment";
createInfo.entryPoint = "fragmentMain"; createInfo.entryPoint = "fragmentMain";
fragmentShader = graphics->createFragmentShader(createInfo); fragmentShader = graphics->createFragmentShader(createInfo);
Array<Gfx::VertexElement> elements;
elements.add({
.binding = 0,
.offset = offsetof(GlyphInstanceData, position),
.vertexFormat = Gfx::SE_FORMAT_R32G32_SFLOAT,
.attributeIndex = 0,
.stride = sizeof(GlyphInstanceData),
.instanced = 1
});
elements.add({
.binding = 0,
.offset = offsetof(GlyphInstanceData, widthHeight),
.vertexFormat = Gfx::SE_FORMAT_R32G32_SFLOAT,
.attributeIndex = 1,
.stride = sizeof(GlyphInstanceData),
.instanced = 1
});
elements.add({
.binding = 0,
.offset = offsetof(GlyphInstanceData, glyphIndex),
.vertexFormat = Gfx::SE_FORMAT_R32_UINT,
.attributeIndex = 2,
.stride = sizeof(GlyphInstanceData),
.instanced = 1
});
declaration = graphics->createVertexDeclaration(elements);
generalLayout = graphics->createDescriptorLayout("TextGeneral"); generalLayout = graphics->createDescriptorLayout("TextGeneral");
generalLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER); generalLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
generalLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_SAMPLER); generalLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_SAMPLER);
@@ -164,7 +136,7 @@ void TextPass::createRenderPass()
.dynamic = true, .dynamic = true,
}); });
glyphSampler = graphics->createSamplerState({ glyphSampler = graphics->createSampler({
.magFilter = Gfx::SE_FILTER_LINEAR, .magFilter = Gfx::SE_FILTER_LINEAR,
.minFilter = Gfx::SE_FILTER_LINEAR, .minFilter = Gfx::SE_FILTER_LINEAR,
.addressModeU = Gfx::SE_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, .addressModeU = Gfx::SE_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
@@ -190,7 +162,6 @@ void TextPass::createRenderPass()
renderPass = graphics->createRenderPass(std::move(layout), viewport); renderPass = graphics->createRenderPass(std::move(layout), viewport);
Gfx::LegacyPipelineCreateInfo pipelineInfo; Gfx::LegacyPipelineCreateInfo pipelineInfo;
pipelineInfo.vertexDeclaration = declaration;
pipelineInfo.vertexShader = vertexShader; pipelineInfo.vertexShader = vertexShader;
pipelineInfo.fragmentShader = fragmentShader; pipelineInfo.fragmentShader = fragmentShader;
pipelineInfo.renderPass = renderPass; pipelineInfo.renderPass = renderPass;
+3 -4
View File
@@ -1,8 +1,8 @@
#pragma once #pragma once
#include "RenderPass.h" #include "RenderPass.h"
#include "UI/RenderHierarchy.h" #include "UI/RenderHierarchy.h"
#include "Graphics/Resources.h"
#include "Asset/FontAsset.h" #include "Asset/FontAsset.h"
#include "Graphics/Shader.h"
namespace Seele namespace Seele
{ {
@@ -58,7 +58,7 @@ private:
struct TextResources struct TextResources
{ {
Gfx::PVertexBuffer vertexBuffer; Gfx::PShaderBuffer instanceBuffer;
Gfx::PDescriptorSet textureArraySet; Gfx::PDescriptorSet textureArraySet;
TextData textData; TextData textData;
}; };
@@ -73,9 +73,8 @@ private:
Gfx::PDescriptorSet generalSet; Gfx::PDescriptorSet generalSet;
Gfx::OUniformBuffer projectionBuffer; Gfx::OUniformBuffer projectionBuffer;
Gfx::OSamplerState glyphSampler; Gfx::OSampler glyphSampler;
Gfx::OVertexDeclaration declaration;
Gfx::OVertexShader vertexShader; Gfx::OVertexShader vertexShader;
Gfx::OFragmentShader fragmentShader; Gfx::OFragmentShader fragmentShader;
Gfx::PPipelineLayout layoutRef; Gfx::PPipelineLayout layoutRef;
+4 -46
View File
@@ -2,6 +2,7 @@
#include "RenderGraph.h" #include "RenderGraph.h"
#include "Graphics/Graphics.h" #include "Graphics/Graphics.h"
#include "Graphics/RenderTarget.h" #include "Graphics/RenderTarget.h"
#include "Graphics/Command.h"
using namespace Seele; using namespace Seele;
@@ -61,9 +62,9 @@ void UIPass::endFrame()
void UIPass::publishOutputs() void UIPass::publishOutputs()
{ {
TextureCreateInfo depthBufferInfo = { TextureCreateInfo depthBufferInfo = {
.format = Gfx::SE_FORMAT_D32_SFLOAT,
.width = viewport->getWidth(), .width = viewport->getWidth(),
.height = viewport->getHeight(), .height = viewport->getHeight(),
.format = Gfx::SE_FORMAT_D32_SFLOAT,
.usage = Gfx::SE_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, .usage = Gfx::SE_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
}; };
@@ -74,9 +75,9 @@ void UIPass::publishOutputs()
resources->registerRenderPassOutput("UIPASS_DEPTH", depthAttachment); resources->registerRenderPassOutput("UIPASS_DEPTH", depthAttachment);
TextureCreateInfo colorBufferInfo = { TextureCreateInfo colorBufferInfo = {
.format = Gfx::SE_FORMAT_R16G16B16A16_SFLOAT,
.width = viewport->getWidth(), .width = viewport->getWidth(),
.height = viewport->getHeight(), .height = viewport->getHeight(),
.format = Gfx::SE_FORMAT_R16G16B16A16_SFLOAT,
.usage = Gfx::SE_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, .usage = Gfx::SE_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
}; };
colorBuffer = graphics->createTexture2D(colorBufferInfo); colorBuffer = graphics->createTexture2D(colorBufferInfo);
@@ -97,48 +98,6 @@ void UIPass::createRenderPass()
createInfo.name = "UIFragment"; createInfo.name = "UIFragment";
createInfo.entryPoint = "fragmentMain"; createInfo.entryPoint = "fragmentMain";
fragmentShader = graphics->createFragmentShader(createInfo); fragmentShader = graphics->createFragmentShader(createInfo);
Array<Gfx::VertexElement> decl;
decl.add({
.binding = 0,
.offset = offsetof(UI::RenderElementStyle, position),
.vertexFormat = Gfx::SE_FORMAT_R32G32B32_SFLOAT,
.attributeIndex = 0,
.stride = sizeof(UI::RenderElementStyle),
.instanced = 1
});
decl.add({
.binding = 0,
.offset = offsetof(UI::RenderElementStyle, backgroundImageIndex),
.vertexFormat = Gfx::SE_FORMAT_R32_UINT,
.attributeIndex = 1,
.stride = sizeof(UI::RenderElementStyle),
.instanced = 1
});
decl.add({
.binding = 0,
.offset = offsetof(UI::RenderElementStyle, backgroundColor),
.vertexFormat = Gfx::SE_FORMAT_R32G32B32_SFLOAT,
.attributeIndex = 2,
.stride = sizeof(UI::RenderElementStyle),
.instanced = 1
});
decl.add({
.binding = 0,
.offset = offsetof(UI::RenderElementStyle, opacity),
.vertexFormat = Gfx::SE_FORMAT_R32_SFLOAT,
.attributeIndex = 3,
.stride = sizeof(UI::RenderElementStyle),
.instanced = 1
});
decl.add({
.binding = 0,
.offset = offsetof(UI::RenderElementStyle, dimensions),
.vertexFormat = Gfx::SE_FORMAT_R32G32_SFLOAT,
.attributeIndex = 4,
.stride = sizeof(UI::RenderElementStyle),
.instanced = 1
});
declaration = graphics->createVertexDeclaration(decl);
descriptorLayout = graphics->createDescriptorLayout("UIDescriptorLayout"); descriptorLayout = graphics->createDescriptorLayout("UIDescriptorLayout");
descriptorLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER); descriptorLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
@@ -156,7 +115,7 @@ void UIPass::createRenderPass()
.dynamic = false, .dynamic = false,
}; };
Gfx::OUniformBuffer uniformBuffer = graphics->createUniformBuffer(info); Gfx::OUniformBuffer uniformBuffer = graphics->createUniformBuffer(info);
Gfx::OSamplerState backgroundSampler = graphics->createSamplerState({}); Gfx::OSampler backgroundSampler = graphics->createSampler({});
info = { info = {
.sourceData = { .sourceData = {
@@ -181,7 +140,6 @@ void UIPass::createRenderPass()
renderPass = graphics->createRenderPass(std::move(layout), viewport); renderPass = graphics->createRenderPass(std::move(layout), viewport);
Gfx::LegacyPipelineCreateInfo pipelineInfo; Gfx::LegacyPipelineCreateInfo pipelineInfo;
pipelineInfo.vertexDeclaration = declaration;
pipelineInfo.vertexShader = vertexShader; pipelineInfo.vertexShader = vertexShader;
pipelineInfo.fragmentShader = fragmentShader; pipelineInfo.fragmentShader = fragmentShader;
pipelineInfo.renderPass = renderPass; pipelineInfo.renderPass = renderPass;
+1 -2
View File
@@ -1,7 +1,7 @@
#pragma once #pragma once
#include "RenderPass.h" #include "RenderPass.h"
#include "UI/RenderHierarchy.h" #include "UI/RenderHierarchy.h"
#include "Graphics/Resources.h" #include "Graphics/Shader.h"
namespace Seele namespace Seele
{ {
@@ -31,7 +31,6 @@ private:
Gfx::OUniformBuffer numTexturesBuffer; Gfx::OUniformBuffer numTexturesBuffer;
Gfx::OVertexBuffer elementBuffer; Gfx::OVertexBuffer elementBuffer;
Gfx::OVertexDeclaration declaration;
Gfx::OVertexShader vertexShader; Gfx::OVertexShader vertexShader;
Gfx::OFragmentShader fragmentShader; Gfx::OFragmentShader fragmentShader;
Gfx::PGraphicsPipeline pipeline; Gfx::PGraphicsPipeline pipeline;
+8 -8
View File
@@ -38,10 +38,10 @@ Matrix4 Viewport::getProjectionMatrix() const
} }
} }
RenderTargetAttachment::RenderTargetAttachment(PTexture2D texture, RenderTargetAttachment::RenderTargetAttachment(PTexture2D texture,
SeAttachmentLoadOp loadOp = SE_ATTACHMENT_LOAD_OP_LOAD, SeAttachmentLoadOp loadOp,
SeAttachmentStoreOp storeOp = SE_ATTACHMENT_STORE_OP_STORE, SeAttachmentStoreOp storeOp,
SeAttachmentLoadOp stencilLoadOp = SE_ATTACHMENT_LOAD_OP_DONT_CARE, SeAttachmentLoadOp stencilLoadOp,
SeAttachmentStoreOp stencilStoreOp = SE_ATTACHMENT_STORE_OP_DONT_CARE) SeAttachmentStoreOp stencilStoreOp)
: clear() : clear()
, componentFlags(0) , componentFlags(0)
, loadOp(loadOp) , loadOp(loadOp)
@@ -57,10 +57,10 @@ RenderTargetAttachment::~RenderTargetAttachment()
} }
SwapchainAttachment::SwapchainAttachment(PWindow owner, SwapchainAttachment::SwapchainAttachment(PWindow owner,
SeAttachmentLoadOp loadOp = SE_ATTACHMENT_LOAD_OP_LOAD, SeAttachmentLoadOp loadOp,
SeAttachmentStoreOp storeOp = SE_ATTACHMENT_STORE_OP_STORE, SeAttachmentStoreOp storeOp,
SeAttachmentLoadOp stencilLoadOp = SE_ATTACHMENT_LOAD_OP_DONT_CARE, SeAttachmentLoadOp stencilLoadOp,
SeAttachmentStoreOp stencilStoreOp = SE_ATTACHMENT_STORE_OP_DONT_CARE) SeAttachmentStoreOp stencilStoreOp)
: RenderTargetAttachment(nullptr, loadOp, storeOp, stencilLoadOp, stencilStoreOp), owner(owner) : RenderTargetAttachment(nullptr, loadOp, storeOp, stencilLoadOp, stencilStoreOp), owner(owner)
{ {
clear.color.float32[0] = 0.0f; clear.color.float32[0] = 0.0f;
+2 -2
View File
@@ -149,7 +149,7 @@ void StaticMeshVertexData::resizeBuffers()
.sourceData = { .sourceData = {
.size = verticesAllocated * sizeof(Vector), .size = verticesAllocated * sizeof(Vector),
}, },
.stride = sizeof(Vector), .numElements = verticesAllocated * 3,
.dynamic = true, .dynamic = true,
}; };
positions = graphics->createShaderBuffer(createInfo); positions = graphics->createShaderBuffer(createInfo);
@@ -158,7 +158,7 @@ void StaticMeshVertexData::resizeBuffers()
biTangents = graphics->createShaderBuffer(createInfo); biTangents = graphics->createShaderBuffer(createInfo);
colors = graphics->createShaderBuffer(createInfo); colors = graphics->createShaderBuffer(createInfo);
createInfo.sourceData.size = verticesAllocated * sizeof(Vector2); createInfo.sourceData.size = verticesAllocated * sizeof(Vector2);
createInfo.stride = sizeof(Vector2); createInfo.numElements = verticesAllocated * 2;
texCoords = graphics->createShaderBuffer(createInfo); texCoords = graphics->createShaderBuffer(createInfo);
positionData.resize(verticesAllocated); positionData.resize(verticesAllocated);
+8 -5
View File
@@ -5,6 +5,7 @@
#include "Graphics/Graphics.h" #include "Graphics/Graphics.h"
#include "Graphics/Descriptor.h" #include "Graphics/Descriptor.h"
#include "Component/Mesh.h" #include "Component/Mesh.h"
#include "Graphics/Shader.h"
using namespace Seele; using namespace Seele;
@@ -62,7 +63,8 @@ void VertexData::createDescriptors()
.size = sizeof(InstanceData) * instanceData.size(), .size = sizeof(InstanceData) * instanceData.size(),
.data = (uint8*)instanceData.data(), .data = (uint8*)instanceData.data(),
}, },
.stride = sizeof(InstanceData) .numElements = instanceData.size(),
.dynamic = false,
}); });
matInst.descriptorSet = instanceDataLayout->allocateDescriptorSet(); matInst.descriptorSet = instanceDataLayout->allocateDescriptorSet();
matInst.descriptorSet->updateBuffer(0, matInst.instanceBuffer); matInst.descriptorSet->updateBuffer(0, matInst.instanceBuffer);
@@ -73,7 +75,8 @@ void VertexData::createDescriptors()
.size = sizeof(MeshData) * meshes.size(), .size = sizeof(MeshData) * meshes.size(),
.data = (uint8*)meshes.data(), .data = (uint8*)meshes.data(),
}, },
.stride = sizeof(MeshData) .numElements = meshes.size(),
.dynamic = false,
}); });
matInst.descriptorSet->updateBuffer(1, matInst.meshDataBuffer); matInst.descriptorSet->updateBuffer(1, matInst.meshDataBuffer);
matInst.descriptorSet->updateBuffer(2, meshletBuffer); matInst.descriptorSet->updateBuffer(2, meshletBuffer);
@@ -123,7 +126,7 @@ void VertexData::loadMesh(MeshId id, Array<Meshlet> loadedMeshlets)
.size = sizeof(MeshletDescription) * meshlets.size(), .size = sizeof(MeshletDescription) * meshlets.size(),
.data = (uint8*)meshlets.data() .data = (uint8*)meshlets.data()
}, },
.stride = sizeof(MeshletDescription), .numElements = meshlets.size(),
.dynamic = true, .dynamic = true,
}); });
vertexIndicesBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{ vertexIndicesBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
@@ -131,7 +134,7 @@ void VertexData::loadMesh(MeshId id, Array<Meshlet> loadedMeshlets)
.size = sizeof(uint32) * vertexIndices.size(), .size = sizeof(uint32) * vertexIndices.size(),
.data = (uint8*)vertexIndices.data(), .data = (uint8*)vertexIndices.data(),
}, },
.stride = sizeof(uint32), .numElements = vertexIndices.size(),
.dynamic = true, .dynamic = true,
}); });
primitiveIndicesBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{ primitiveIndicesBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
@@ -139,7 +142,7 @@ void VertexData::loadMesh(MeshId id, Array<Meshlet> loadedMeshlets)
.size = sizeof(uint8) * primitiveIndices.size(), .size = sizeof(uint8) * primitiveIndices.size(),
.data = (uint8*)primitiveIndices.data(), .data = (uint8*)primitiveIndices.data(),
}, },
.stride = sizeof(uint8), .numElements = primitiveIndices.size(),
.dynamic = true, .dynamic = true,
}); });
} }
+1 -1
View File
@@ -3,7 +3,7 @@
#include "Material/MaterialInstance.h" #include "Material/MaterialInstance.h"
#include "Component/Transform.h" #include "Component/Transform.h"
#include "Containers/List.h" #include "Containers/List.h"
#include "Graphics/Resources.h" #include "Graphics/Command.h"
#include "Graphics/Descriptor.h" #include "Graphics/Descriptor.h"
#include "Graphics/Buffer.h" #include "Graphics/Buffer.h"
+16 -18
View File
@@ -1,7 +1,8 @@
#include "Allocator.h" #include "Allocator.h"
#include "Graphics.h" #include "Graphics.h"
#include "Initializer.h"
#include "Resources.h" #include "Resources.h"
#include "Enums.h"
#include "Command.h"
using namespace Seele::Vulkan; using namespace Seele::Vulkan;
@@ -24,11 +25,6 @@ VkDeviceMemory SubAllocation::getHandle() const
return owner->getHandle(); return owner->getHandle();
} }
bool SubAllocation::isReadable() const
{
return owner->isReadable();
}
void *SubAllocation::map() void *SubAllocation::map()
{ {
return (uint8 *)owner->map() + alignedOffset; return (uint8 *)owner->map() + alignedOffset;
@@ -44,14 +40,14 @@ void SubAllocation::invalidate()
owner->invalidate(); owner->invalidate();
} }
Allocation::Allocation(PGraphics graphics, PAllocator allocator, VkDeviceSize size, uint8 memoryTypeIndex, Allocation::Allocation(PGraphics graphics, PAllocator pool, VkDeviceSize size, uint8 memoryTypeIndex,
VkMemoryPropertyFlags properties, VkMemoryDedicatedAllocateInfo *dedicatedInfo) VkMemoryPropertyFlags properties, VkMemoryDedicatedAllocateInfo *dedicatedInfo)
: device(graphics->getDevice()) : device(graphics->getDevice())
, allocator(allocator) , pool(pool)
, bytesAllocated(0) , bytesAllocated(0)
, bytesUsed(0) , bytesUsed(0)
, canMap((properties & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) == VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT), , canMap((properties & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) == VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT)
, isMapped(false), , isMapped(false)
, properties(properties) , properties(properties)
, memoryTypeIndex(memoryTypeIndex) , memoryTypeIndex(memoryTypeIndex)
{ {
@@ -97,7 +93,7 @@ OSubAllocation Allocation::getSuballocation(VkDeviceSize requestedSize, VkDevice
alignedOffset /= alignment; alignedOffset /= alignment;
alignedOffset *= alignment; alignedOffset *= alignment;
VkDeviceSize allocatedSize = requestedSize + (alignedOffset - lower); VkDeviceSize allocatedSize = requestedSize + (alignedOffset - lower);
if (size <= allocatedSize) if (size >= allocatedSize)
{ {
VkDeviceSize newSize = size - allocatedSize; VkDeviceSize newSize = size - allocatedSize;
VkDeviceSize newLower = lower + allocatedSize; VkDeviceSize newLower = lower + allocatedSize;
@@ -140,7 +136,7 @@ void Allocation::markFree(PSubAllocation allocation)
bytesUsed -= allocation->allocatedSize; bytesUsed -= allocation->allocatedSize;
if (bytesUsed == 0) if (bytesUsed == 0)
{ {
allocator->free(this); pool->free(this);
} }
} }
@@ -209,7 +205,7 @@ OSubAllocation Allocator::allocate(const VkMemoryRequirements2 &memRequirements2
{ {
OAllocation newAllocation = new Allocation(graphics, this, requirements.size, memoryTypeIndex, properties, dedicatedInfo); OAllocation newAllocation = new Allocation(graphics, this, requirements.size, memoryTypeIndex, properties, dedicatedInfo);
heaps[heapIndex].inUse += newAllocation->bytesAllocated; heaps[heapIndex].inUse += newAllocation->bytesAllocated;
//std::cout << "Heap " << heapIndex << ": " << (float)heaps[heapIndex].inUse / heaps[heapIndex].maxSize << "%" << std::endl; std::cout << "Heap " << heapIndex << ": " << (float)heaps[heapIndex].inUse / heaps[heapIndex].maxSize << "%" << std::endl;
heaps[heapIndex].allocations.add(std::move(newAllocation)); heaps[heapIndex].allocations.add(std::move(newAllocation));
return heaps[heapIndex].allocations.back()->getSuballocation(requirements.size, requirements.alignment); return heaps[heapIndex].allocations.back()->getSuballocation(requirements.size, requirements.alignment);
} }
@@ -229,7 +225,7 @@ OSubAllocation Allocator::allocate(const VkMemoryRequirements2 &memRequirements2
// no suitable allocations found, allocate new block // no suitable allocations found, allocate new block
OAllocation newAllocation = new Allocation(graphics, this, (requirements.size > DEFAULT_ALLOCATION) ? requirements.size : DEFAULT_ALLOCATION, memoryTypeIndex, properties, nullptr); OAllocation newAllocation = new Allocation(graphics, this, (requirements.size > DEFAULT_ALLOCATION) ? requirements.size : DEFAULT_ALLOCATION, memoryTypeIndex, properties, nullptr);
heaps[heapIndex].inUse += newAllocation->bytesAllocated; heaps[heapIndex].inUse += newAllocation->bytesAllocated;
//std::cout << "Heap " << heapIndex << ": " << (float)heaps[heapIndex].inUse / heaps[heapIndex].maxSize << "%" << std::endl; std::cout << "Heap " << heapIndex << ": " << (float)heaps[heapIndex].inUse / heaps[heapIndex].maxSize << "%" << std::endl;
heaps[heapIndex].allocations.add(std::move(newAllocation)); heaps[heapIndex].allocations.add(std::move(newAllocation));
return heaps[heapIndex].allocations.back()->getSuballocation(requirements.size, requirements.alignment); return heaps[heapIndex].allocations.back()->getSuballocation(requirements.size, requirements.alignment);
} }
@@ -244,7 +240,7 @@ void Allocator::free(PAllocation allocation)
if (heaps[heapIndex].allocations[alloc] == allocation) if (heaps[heapIndex].allocations[alloc] == allocation)
{ {
heaps[heapIndex].inUse -= allocation->bytesAllocated; heaps[heapIndex].inUse -= allocation->bytesAllocated;
//std::cout << "Heap " << heapIndex << ": " << (float)heaps[heapIndex].inUse / heaps[heapIndex].maxSize << "%" << std::endl; std::cout << "Heap " << heapIndex << ": " << (float)heaps[heapIndex].inUse / heaps[heapIndex].maxSize << "%" << std::endl;
heaps[heapIndex].allocations.removeAt(alloc, false); heaps[heapIndex].allocations.removeAt(alloc, false);
return; return;
} }
@@ -277,6 +273,8 @@ StagingBuffer::~StagingBuffer()
{ {
graphics->getDestructionManager()->queueBuffer( graphics->getDestructionManager()->queueBuffer(
graphics->getDedicatedTransferCommands()->getCommands(), buffer); graphics->getDedicatedTransferCommands()->getCommands(), buffer);
graphics->getDestructionManager()->queueAllocation(
graphics->getDedicatedTransferCommands()->getCommands(), std::move(allocation));
} }
void* StagingBuffer::map() void* StagingBuffer::map()
@@ -314,8 +312,8 @@ void StagingBuffer::executePipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::Se
assert(false); assert(false);
} }
StagingManager::StagingManager(PGraphics graphics, PAllocator allocator) StagingManager::StagingManager(PGraphics graphics, PAllocator pool)
: graphics(graphics), allocator(allocator) : graphics(graphics), pool(pool)
{ {
} }
@@ -358,7 +356,7 @@ OStagingBuffer StagingManager::create(uint64 size)
OStagingBuffer stagingBuffer = new StagingBuffer( OStagingBuffer stagingBuffer = new StagingBuffer(
graphics, graphics,
allocator->allocate(memReqs, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT, buffer), pool->allocate(memReqs, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT, buffer),
buffer, buffer,
size size
); );
+17 -17
View File
@@ -30,8 +30,6 @@ public:
return alignedOffset; return alignedOffset;
} }
bool isReadable() const;
void *map(); void *map();
void flushMemory(); void flushMemory();
void invalidate(); void invalidate();
@@ -49,7 +47,7 @@ DEFINE_REF(SubAllocation)
class Allocation class Allocation
{ {
public: public:
Allocation(PGraphics graphics, PAllocator allocator, VkDeviceSize size, uint8 memoryTypeIndex, Allocation(PGraphics graphics, PAllocator pool, VkDeviceSize size, uint8 memoryTypeIndex,
VkMemoryPropertyFlags properties, VkMemoryDedicatedAllocateInfo *dedicatedInfo = nullptr); VkMemoryPropertyFlags properties, VkMemoryDedicatedAllocateInfo *dedicatedInfo = nullptr);
~Allocation(); ~Allocation();
OSubAllocation getSuballocation(VkDeviceSize size, VkDeviceSize alignment); OSubAllocation getSuballocation(VkDeviceSize size, VkDeviceSize alignment);
@@ -78,16 +76,16 @@ public:
private: private:
VkDevice device; VkDevice device;
PAllocator allocator; PAllocator pool;
VkDeviceSize bytesAllocated; VkDeviceSize bytesAllocated;
VkDeviceSize bytesUsed; VkDeviceSize bytesUsed;
VkDeviceMemory allocatedMemory; VkDeviceMemory allocatedMemory;
Array<PSubAllocation> activeAllocations; Array<PSubAllocation> activeAllocations;
Map<VkDeviceSize, VkDeviceSize> freeRanges; Map<VkDeviceSize, VkDeviceSize> freeRanges;
void *mappedPointer; void *mappedPointer;
uint8 isDedicated : 1;
uint8 canMap : 1; uint8 canMap : 1;
uint8 isMapped : 1; uint8 isMapped : 1;
uint8 isDedicated : 1;
VkMemoryPropertyFlags properties; VkMemoryPropertyFlags properties;
uint8 memoryTypeIndex; uint8 memoryTypeIndex;
friend class Allocator; friend class Allocator;
@@ -104,21 +102,23 @@ public:
OSubAllocation allocate(const VkMemoryRequirements2 &requirements, VkMemoryPropertyFlags props, OSubAllocation allocate(const VkMemoryRequirements2 &requirements, VkMemoryPropertyFlags props,
VkBuffer buffer) VkBuffer buffer)
{ {
VkMemoryDedicatedAllocateInfo allocInfo; VkMemoryDedicatedAllocateInfo allocInfo = {
allocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO; .sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO,
allocInfo.pNext = nullptr; .pNext = nullptr,
allocInfo.buffer = buffer; .image = VK_NULL_HANDLE,
allocInfo.image = VK_NULL_HANDLE; .buffer = buffer,
};
return allocate(requirements, props, &allocInfo); return allocate(requirements, props, &allocInfo);
} }
OSubAllocation allocate(const VkMemoryRequirements2 &requirements, VkMemoryPropertyFlags props, OSubAllocation allocate(const VkMemoryRequirements2 &requirements, VkMemoryPropertyFlags props,
VkImage image) VkImage image)
{ {
VkMemoryDedicatedAllocateInfo allocInfo; VkMemoryDedicatedAllocateInfo allocInfo = {
allocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO; .sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO,
allocInfo.pNext = nullptr; .pNext = nullptr,
allocInfo.buffer = VK_NULL_HANDLE; .image = image,
allocInfo.image = image; .buffer = VK_NULL_HANDLE,
};
return allocate(requirements, props, &allocInfo); return allocate(requirements, props, &allocInfo);
} }
@@ -174,13 +174,13 @@ DEFINE_REF(StagingBuffer)
class StagingManager class StagingManager
{ {
public: public:
StagingManager(PGraphics graphics, PAllocator allocator); StagingManager(PGraphics graphics, PAllocator pool);
~StagingManager(); ~StagingManager();
OStagingBuffer create(uint64 size); OStagingBuffer create(uint64 size);
private: private:
PGraphics graphics; PGraphics graphics;
PAllocator allocator; PAllocator pool;
}; };
DEFINE_REF(StagingManager) DEFINE_REF(StagingManager)
} // namespace Vulkan } // namespace Vulkan
+68 -61
View File
@@ -1,6 +1,5 @@
#include "Buffer.h" #include "Buffer.h"
#include "Initializer.h" #include "Command.h"
#include "CommandBuffer.h"
using namespace Seele; using namespace Seele;
using namespace Seele::Vulkan; using namespace Seele::Vulkan;
@@ -79,15 +78,19 @@ VkDeviceSize Buffer::getOffset() const
void Buffer::executeOwnershipBarrier(Gfx::QueueType newOwner) void Buffer::executeOwnershipBarrier(Gfx::QueueType newOwner)
{ {
VkBufferMemoryBarrier barrier = Gfx::QueueFamilyMapping mapping = graphics->getFamilyMapping();
init::BufferMemoryBarrier(); VkBufferMemoryBarrier barrier = {
PCommandBufferManager sourceManager = graphics->getQueueCommands(owner); .sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,
PCommandBufferManager dstManager = nullptr; .pNext = nullptr,
.srcQueueFamilyIndex = mapping.getQueueTypeFamilyIndex(owner),
.dstQueueFamilyIndex = mapping.getQueueTypeFamilyIndex(newOwner),
.offset = 0,
.size = size,
};
PCommandPool sourcePool = graphics->getQueueCommands(owner);
PCommandPool dstPool = nullptr;
VkPipelineStageFlags srcStage = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT; VkPipelineStageFlags srcStage = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
VkPipelineStageFlags dstStage = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT; VkPipelineStageFlags dstStage = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
Gfx::QueueFamilyMapping mapping = graphics->getFamilyMapping();
barrier.srcQueueFamilyIndex = mapping.getQueueTypeFamilyIndex(owner);
barrier.dstQueueFamilyIndex = mapping.getQueueTypeFamilyIndex(newOwner);
assert(barrier.srcQueueFamilyIndex != barrier.dstQueueFamilyIndex); assert(barrier.srcQueueFamilyIndex != barrier.dstQueueFamilyIndex);
if (owner == Gfx::QueueType::TRANSFER || owner == Gfx::QueueType::DEDICATED_TRANSFER) if (owner == Gfx::QueueType::TRANSFER || owner == Gfx::QueueType::DEDICATED_TRANSFER)
{ {
@@ -108,31 +111,29 @@ void Buffer::executeOwnershipBarrier(Gfx::QueueType newOwner)
{ {
barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT; barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT;
dstStage = VK_PIPELINE_STAGE_TRANSFER_BIT; dstStage = VK_PIPELINE_STAGE_TRANSFER_BIT;
dstManager = graphics->getTransferCommands(); dstPool = graphics->getTransferCommands();
} }
else if (newOwner == Gfx::QueueType::DEDICATED_TRANSFER) else if (newOwner == Gfx::QueueType::DEDICATED_TRANSFER)
{ {
barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT; barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT;
dstStage = VK_PIPELINE_STAGE_TRANSFER_BIT; dstStage = VK_PIPELINE_STAGE_TRANSFER_BIT;
dstManager = graphics->getDedicatedTransferCommands(); dstPool = graphics->getDedicatedTransferCommands();
} }
else if (newOwner == Gfx::QueueType::COMPUTE) else if (newOwner == Gfx::QueueType::COMPUTE)
{ {
barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
dstStage = VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT; dstStage = VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT;
dstManager = graphics->getComputeCommands(); dstPool = graphics->getComputeCommands();
} }
else if (newOwner == Gfx::QueueType::GRAPHICS) else if (newOwner == Gfx::QueueType::GRAPHICS)
{ {
barrier.dstAccessMask = getDestAccessMask(); barrier.dstAccessMask = getDestAccessMask();
dstStage = VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT; dstStage = VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT;
dstManager = graphics->getGraphicsCommands(); dstPool = graphics->getGraphicsCommands();
} }
VkCommandBuffer srcCommand = sourceManager->getCommands()->getHandle(); VkCommandBuffer srcCommand = sourcePool->getCommands()->getHandle();
VkCommandBuffer dstCommand = dstManager->getCommands()->getHandle(); VkCommandBuffer dstCommand = dstPool->getCommands()->getHandle();
VkBufferMemoryBarrier dynamicBarriers[Gfx::numFramesBuffered]; VkBufferMemoryBarrier dynamicBarriers[Gfx::numFramesBuffered];
barrier.offset = 0;
barrier.size = size;
for (uint32 i = 0; i < numBuffers; ++i) for (uint32 i = 0; i < numBuffers; ++i)
{ {
dynamicBarriers[i] = barrier; dynamicBarriers[i] = barrier;
@@ -140,20 +141,23 @@ void Buffer::executeOwnershipBarrier(Gfx::QueueType newOwner)
} }
vkCmdPipelineBarrier(srcCommand, srcStage, srcStage, 0, 0, nullptr, numBuffers, dynamicBarriers, 0, nullptr); vkCmdPipelineBarrier(srcCommand, srcStage, srcStage, 0, 0, nullptr, numBuffers, dynamicBarriers, 0, nullptr);
vkCmdPipelineBarrier(dstCommand, dstStage, dstStage, 0, 0, nullptr, numBuffers, dynamicBarriers, 0, nullptr); vkCmdPipelineBarrier(dstCommand, dstStage, dstStage, 0, 0, nullptr, numBuffers, dynamicBarriers, 0, nullptr);
sourceManager->submitCommands(); sourcePool->submitCommands();
} }
void Buffer::executePipelineBarrier(VkAccessFlags srcAccess, VkPipelineStageFlags srcStage, void Buffer::executePipelineBarrier(VkAccessFlags srcAccess, VkPipelineStageFlags srcStage,
VkAccessFlags dstAccess, VkPipelineStageFlags dstStage) VkAccessFlags dstAccess, VkPipelineStageFlags dstStage)
{ {
PCmdBuffer commandBuffer = graphics->getQueueCommands(owner)->getCommands(); PCommand commandBuffer = graphics->getQueueCommands(owner)->getCommands();
VkBufferMemoryBarrier barrier = init::BufferMemoryBarrier(); VkBufferMemoryBarrier barrier = {
barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; .sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,
barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; .pNext = nullptr,
barrier.dstAccessMask = dstAccess; .srcAccessMask = srcAccess,
barrier.srcAccessMask = srcAccess; .dstAccessMask = dstAccess,
barrier.offset = 0; .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
barrier.size = size; .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.offset = 0,
.size = size,
};
VkBufferMemoryBarrier dynamicBarriers[Gfx::numFramesBuffered]; VkBufferMemoryBarrier dynamicBarriers[Gfx::numFramesBuffered];
for(uint32 i = 0; i < numBuffers; ++i) for(uint32 i = 0; i < numBuffers; ++i)
{ {
@@ -194,35 +198,38 @@ void * Buffer::mapRegion(uint64 regionOffset, uint64 regionSize, bool writeOnly)
if (writeOnly) if (writeOnly)
{ {
//requestOwnershipTransfer(Gfx::QueueType::DEDICATED_TRANSFER); //requestOwnershipTransfer(Gfx::QueueType::DEDICATED_TRANSFER);
OStagingBuffer stagingBuffer = graphics->getStagingManager()->create(regionSize, VK_BUFFER_USAGE_TRANSFER_SRC_BIT); OStagingBuffer stagingBuffer = graphics->getStagingManager()->create(regionSize);
data = stagingBuffer->map(); data = stagingBuffer->map();
pending.stagingBuffer = std::move(stagingBuffer); pending.stagingBuffer = std::move(stagingBuffer);
} }
else else
{ {
PCmdBuffer current = graphics->getQueueCommands(owner)->getCommands(); PCommand current = graphics->getQueueCommands(owner)->getCommands();
current->waitForCommand(); current->waitForCommand();
requestOwnershipTransfer(Gfx::QueueType::DEDICATED_TRANSFER); requestOwnershipTransfer(Gfx::QueueType::DEDICATED_TRANSFER);
VkCommandBuffer handle = graphics->getQueueCommands(owner)->getCommands()->getHandle(); VkCommandBuffer handle = graphics->getQueueCommands(owner)->getCommands()->getHandle();
VkBufferMemoryBarrier barrier = VkBufferMemoryBarrier barrier = {
init::BufferMemoryBarrier(); .sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,
barrier.srcAccessMask = VK_ACCESS_MEMORY_WRITE_BIT; .pNext = nullptr,
barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT; .srcAccessMask = VK_ACCESS_MEMORY_WRITE_BIT,
barrier.buffer = buffers[currentBuffer].buffer; .dstAccessMask = VK_ACCESS_MEMORY_READ_BIT,
barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
barrier.offset = 0; .buffer = buffers[currentBuffer].buffer,
barrier.size = size; .offset = 0,
.size = size,
};
vkCmdPipelineBarrier(handle, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, nullptr, 1, &barrier, 0, nullptr); vkCmdPipelineBarrier(handle, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, nullptr, 1, &barrier, 0, nullptr);
OStagingBuffer stagingBuffer = graphics->getStagingManager()->create(size, VK_BUFFER_USAGE_TRANSFER_DST_BIT, true); OStagingBuffer stagingBuffer = graphics->getStagingManager()->create(size);
VkBufferCopy regions; VkBufferCopy regions = {
regions.size = size; .srcOffset = 0,
regions.srcOffset = 0; .dstOffset = 0,
regions.dstOffset = 0; .size = size,
};
vkCmdCopyBuffer(handle, buffers[currentBuffer].buffer, stagingBuffer->getHandle(), 1, &regions); vkCmdCopyBuffer(handle, buffers[currentBuffer].buffer, stagingBuffer->getHandle(), 1, &regions);
@@ -251,18 +258,18 @@ void Buffer::unmap()
if (pending.writeOnly) if (pending.writeOnly)
{ {
PStagingBuffer stagingBuffer = pending.stagingBuffer; PStagingBuffer stagingBuffer = pending.stagingBuffer;
PCmdBuffer cmdBuffer = graphics->getQueueCommands(owner)->getCommands(); PCommand command = graphics->getQueueCommands(owner)->getCommands();
VkCommandBuffer cmdHandle = cmdBuffer->getHandle(); VkCommandBuffer cmdHandle = command->getHandle();
VkBufferCopy region; VkBufferCopy region = {
std::memset(&region, 0, sizeof(VkBufferCopy)); .srcOffset = 0,
region.size = pending.size; .dstOffset = pending.offset,
region.dstOffset = pending.offset; .size = pending.size,
};
vkCmdCopyBuffer(cmdHandle, stagingBuffer->getHandle(), buffers[currentBuffer].buffer, 1, &region); vkCmdCopyBuffer(cmdHandle, stagingBuffer->getHandle(), buffers[currentBuffer].buffer, 1, &region);
graphics->getQueueCommands(owner)->submitCommands(); graphics->getQueueCommands(owner)->submitCommands();
} }
//requestOwnershipTransfer(pending.prevQueue); //requestOwnershipTransfer(pending.prevQueue);
graphics->getStagingManager()->release(std::move(pending.stagingBuffer));
pendingBuffers.erase(this); pendingBuffers.erase(this);
} }
} }
@@ -274,7 +281,7 @@ UniformBuffer::UniformBuffer(PGraphics graphics, const UniformBufferCreateInfo &
{ {
if(createInfo.dynamic) if(createInfo.dynamic)
{ {
dedicatedStagingBuffer = graphics->getStagingManager()->create(createInfo.sourceData.size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT); dedicatedStagingBuffer = graphics->getStagingManager()->create(createInfo.sourceData.size);
} }
if (createInfo.sourceData.data != nullptr) if (createInfo.sourceData.data != nullptr)
{ {
@@ -286,7 +293,6 @@ UniformBuffer::UniformBuffer(PGraphics graphics, const UniformBufferCreateInfo &
UniformBuffer::~UniformBuffer() UniformBuffer::~UniformBuffer()
{ {
graphics->getStagingManager()->release(std::move(dedicatedStagingBuffer));
} }
bool UniformBuffer::updateContents(const DataSource &sourceData) bool UniformBuffer::updateContents(const DataSource &sourceData)
@@ -315,8 +321,8 @@ void UniformBuffer::unmap()
if(dedicatedStagingBuffer != nullptr) if(dedicatedStagingBuffer != nullptr)
{ {
dedicatedStagingBuffer->flush(); dedicatedStagingBuffer->flush();
PCmdBuffer cmdBuffer = graphics->getQueueCommands(currentOwner)->getCommands(); PCommand command = graphics->getQueueCommands(currentOwner)->getCommands();
VkCommandBuffer cmdHandle = cmdBuffer->getHandle(); VkCommandBuffer cmdHandle = command->getHandle();
VkBufferCopy region; VkBufferCopy region;
std::memset(&region, 0, sizeof(VkBufferCopy)); std::memset(&region, 0, sizeof(VkBufferCopy));
@@ -357,13 +363,13 @@ VkAccessFlags UniformBuffer::getDestAccessMask()
} }
ShaderBuffer::ShaderBuffer(PGraphics graphics, const ShaderBufferCreateInfo &sourceData) ShaderBuffer::ShaderBuffer(PGraphics graphics, const ShaderBufferCreateInfo &sourceData)
: Gfx::ShaderBuffer(graphics->getFamilyMapping(), sourceData.stride, sourceData.sourceData.size / sourceData.stride, sourceData.sourceData) : Gfx::ShaderBuffer(graphics->getFamilyMapping(), sourceData.numElements, sourceData.sourceData)
, Vulkan::Buffer(graphics, sourceData.sourceData.size, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, currentOwner, sourceData.dynamic) , Vulkan::Buffer(graphics, sourceData.sourceData.size, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, currentOwner, sourceData.dynamic)
, dedicatedStagingBuffer(nullptr) , dedicatedStagingBuffer(nullptr)
{ {
if(sourceData.dynamic) if(sourceData.dynamic)
{ {
dedicatedStagingBuffer = graphics->getStagingManager()->create(sourceData.sourceData.size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT); dedicatedStagingBuffer = graphics->getStagingManager()->create(sourceData.sourceData.size);
} }
if (sourceData.sourceData.data != nullptr) if (sourceData.sourceData.data != nullptr)
{ {
@@ -375,7 +381,6 @@ ShaderBuffer::ShaderBuffer(PGraphics graphics, const ShaderBufferCreateInfo &sou
ShaderBuffer::~ShaderBuffer() ShaderBuffer::~ShaderBuffer()
{ {
graphics->getStagingManager()->release(std::move(dedicatedStagingBuffer));
} }
bool ShaderBuffer::updateContents(const DataSource &sourceData) bool ShaderBuffer::updateContents(const DataSource &sourceData)
@@ -402,12 +407,14 @@ void ShaderBuffer::unmap()
if(dedicatedStagingBuffer != nullptr) if(dedicatedStagingBuffer != nullptr)
{ {
dedicatedStagingBuffer->flush(); dedicatedStagingBuffer->flush();
PCmdBuffer cmdBuffer = graphics->getQueueCommands(currentOwner)->getCommands(); PCommand command = graphics->getQueueCommands(currentOwner)->getCommands();
VkCommandBuffer cmdHandle = cmdBuffer->getHandle(); VkCommandBuffer cmdHandle = command->getHandle();
VkBufferCopy region; VkBufferCopy region = {
std::memset(&region, 0, sizeof(VkBufferCopy)); .srcOffset = 0,
region.size = Vulkan::Buffer::size; .dstOffset = 0,
.size = Vulkan::Buffer::size,
};
vkCmdCopyBuffer(cmdHandle, dedicatedStagingBuffer->getHandle(), buffers[currentBuffer].buffer, 1, &region); vkCmdCopyBuffer(cmdHandle, dedicatedStagingBuffer->getHandle(), buffers[currentBuffer].buffer, 1, &region);
graphics->getQueueCommands(currentOwner)->submitCommands(); graphics->getQueueCommands(currentOwner)->submitCommands();
} }
+4 -4
View File
@@ -6,6 +6,8 @@ target_sources(Engine
Buffer.cpp Buffer.cpp
Command.h Command.h
Command.cpp Command.cpp
Debug.h
Debug.cpp
Descriptor.h Descriptor.h
Descriptor.cpp Descriptor.cpp
Enums.h Enums.h
@@ -14,8 +16,6 @@ target_sources(Engine
Framebuffer.cpp Framebuffer.cpp
Graphics.h Graphics.h
Graphics.cpp Graphics.cpp
Initializer.h
Initializer.cpp
Pipeline.h Pipeline.h
Pipeline.cpp Pipeline.cpp
PipelineCache.h PipelineCache.h
@@ -39,11 +39,11 @@ target_sources(Engine
Allocator.h Allocator.h
Buffer.h Buffer.h
Command.h Command.h
DescriptorSets.h Debug.h
Descriptor.h
Enums.h Enums.h
Framebuffer.h Framebuffer.h
Graphics.h Graphics.h
Initializer.h
Pipeline.h Pipeline.h
PipelineCache.h PipelineCache.h
Queue.h Queue.h
+70 -55
View File
@@ -1,12 +1,11 @@
#include "CommandBuffer.h" #include "Command.h"
#include "Initializer.h"
#include "Graphics.h" #include "Graphics.h"
#include "Pipeline.h" #include "Pipeline.h"
#include "Enums.h" #include "Enums.h"
#include "Framebuffer.h" #include "Framebuffer.h"
#include "RenderPass.h" #include "RenderPass.h"
#include "Pipeline.h" #include "Pipeline.h"
#include "DescriptorSets.h" #include "Descriptor.h"
#include "RenderTarget.h" #include "RenderTarget.h"
#include <vulkan/vulkan_core.h> #include <vulkan/vulkan_core.h>
@@ -14,9 +13,9 @@ using namespace Seele;
using namespace Seele::Vulkan; using namespace Seele::Vulkan;
Command::Command(PGraphics graphics, VkCommandPool cmdPool, PCommandBufferManager manager) Command::Command(PGraphics graphics, VkCommandPool cmdPool, PCommandPool pool)
: graphics(graphics) : graphics(graphics)
, manager(manager) , pool(pool)
, owner(cmdPool) , owner(cmdPool)
{ {
VkCommandBufferAllocateInfo allocInfo = { VkCommandBufferAllocateInfo allocInfo = {
@@ -159,7 +158,7 @@ void Command::checkFence()
void Command::waitForCommand(uint32 timeout) void Command::waitForCommand(uint32 timeout)
{ {
manager->submitCommands(); pool->submitCommands();
if (state == State::Begin) if (state == State::Begin)
{ {
// is already done // is already done
@@ -174,9 +173,9 @@ PFence Command::getFence()
return fence; return fence;
} }
PCommandBufferManager Command::getManager() PCommandPool Command::getPool()
{ {
return manager; return pool;
} }
RenderCommand::RenderCommand(PGraphics graphics, VkCommandPool cmdPool) RenderCommand::RenderCommand(PGraphics graphics, VkCommandPool cmdPool)
@@ -203,15 +202,21 @@ void RenderCommand::begin(PRenderPass renderPass, PFramebuffer framebuffer)
{ {
threadId = std::this_thread::get_id(); threadId = std::this_thread::get_id();
ready = false; ready = false;
VkCommandBufferBeginInfo beginInfo = VkCommandBufferInheritanceInfo inheritanceInfo = {
init::CommandBufferBeginInfo(); .sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO,
VkCommandBufferInheritanceInfo inheritanceInfo = .renderPass = renderPass->getHandle(),
init::CommandBufferInheritanceInfo(); .subpass = 0,
inheritanceInfo.framebuffer = framebuffer->getHandle(); .framebuffer = framebuffer->getHandle(),
inheritanceInfo.renderPass = renderPass->getHandle(); .occlusionQueryEnable = 0,
inheritanceInfo.subpass = 0; .queryFlags = 0,
beginInfo.pInheritanceInfo = &inheritanceInfo; .pipelineStatistics = 0,
beginInfo.flags = VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT; };
VkCommandBufferBeginInfo beginInfo = {
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
.pNext = nullptr,
.flags = VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT,
.pInheritanceInfo = &inheritanceInfo,
};
VK_CHECK(vkBeginCommandBuffer(handle, &beginInfo)); VK_CHECK(vkBeginCommandBuffer(handle, &beginInfo));
} }
@@ -236,7 +241,16 @@ void RenderCommand::setViewport(Gfx::PViewport viewport)
{ {
assert(threadId == std::this_thread::get_id()); assert(threadId == std::this_thread::get_id());
VkViewport vp = viewport.cast<Viewport>()->getHandle(); VkViewport vp = viewport.cast<Viewport>()->getHandle();
VkRect2D scissors = init::Rect2D(viewport->getWidth(), viewport->getHeight(), viewport->getOffsetX(), viewport->getOffsetY()); VkRect2D scissors = {
.offset = {
.x = (int32)viewport->getOffsetX(),
.y = (int32)viewport->getOffsetY(),
},
.extent = {
.width = viewport->getWidth(),
.height = viewport->getHeight(),
},
};
vkCmdSetViewport(handle, 0, 1, &vp); vkCmdSetViewport(handle, 0, 1, &vp);
vkCmdSetScissor(handle, 0, 1, &scissors); vkCmdSetScissor(handle, 0, 1, &scissors);
} }
@@ -321,10 +335,13 @@ ComputeCommand::ComputeCommand(PGraphics graphics, VkCommandPool cmdPool)
: graphics(graphics) : graphics(graphics)
, owner(cmdPool) , owner(cmdPool)
{ {
VkCommandBufferAllocateInfo allocInfo = VkCommandBufferAllocateInfo allocInfo = {
init::CommandBufferAllocateInfo(cmdPool, .sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,
VK_COMMAND_BUFFER_LEVEL_SECONDARY, .pNext = nullptr,
1); .commandPool = owner,
.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY,
.commandBufferCount = 1,
};
VK_CHECK(vkAllocateCommandBuffers(graphics->getDevice(), &allocInfo, &handle)); VK_CHECK(vkAllocateCommandBuffers(graphics->getDevice(), &allocInfo, &handle));
} }
@@ -334,18 +351,25 @@ ComputeCommand::~ComputeCommand()
vkFreeCommandBuffers(graphics->getDevice(), owner, 1, &handle); vkFreeCommandBuffers(graphics->getDevice(), owner, 1, &handle);
} }
void ComputeCommand::begin(PCmdBuffer) void ComputeCommand::begin()
{ {
threadId = std::this_thread::get_id(); threadId = std::this_thread::get_id();
ready = false; ready = false;
VkCommandBufferBeginInfo beginInfo = VkCommandBufferInheritanceInfo inheritanceInfo = {
init::CommandBufferBeginInfo(); .sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO,
VkCommandBufferInheritanceInfo inheritanceInfo = .renderPass = VK_NULL_HANDLE,
init::CommandBufferInheritanceInfo(); .subpass = 0,
inheritanceInfo.framebuffer = VK_NULL_HANDLE; .framebuffer = VK_NULL_HANDLE,
inheritanceInfo.renderPass = VK_NULL_HANDLE; .occlusionQueryEnable = 0,
inheritanceInfo.subpass = 0; .queryFlags = 0,
beginInfo.pInheritanceInfo = &inheritanceInfo; .pipelineStatistics = 0,
};
VkCommandBufferBeginInfo beginInfo = {
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
.pNext = nullptr,
.flags = 0,
.pInheritanceInfo = &inheritanceInfo,
};
VK_CHECK(vkBeginCommandBuffer(handle, &beginInfo)); VK_CHECK(vkBeginCommandBuffer(handle, &beginInfo));
} }
@@ -419,16 +443,16 @@ void ComputeCommand::dispatch(uint32 threadX, uint32 threadY, uint32 threadZ)
CommandPool::CommandPool(PGraphics graphics, PQueue queue) CommandPool::CommandPool(PGraphics graphics, PQueue queue)
: graphics(graphics), queue(queue), queueFamilyIndex(queue->getFamilyIndex()) : graphics(graphics), queue(queue), queueFamilyIndex(queue->getFamilyIndex())
{ {
VkCommandPoolCreateInfo info = VkCommandPoolCreateInfo info = {
init::CommandPoolCreateInfo(); .sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,
info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; .pNext = nullptr,
info.queueFamilyIndex = queue->getFamilyIndex(); .flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,
.queueFamilyIndex = queue->getFamilyIndex(),
};
VK_CHECK(vkCreateCommandPool(graphics->getDevice(), &info, nullptr, &commandPool)); VK_CHECK(vkCreateCommandPool(graphics->getDevice(), &info, nullptr, &commandPool));
allocatedBuffers.add(new Command(graphics, commandPool, this)); allocatedBuffers.add(new Command(graphics, commandPool, this));
command = allocatedBuffers.back(); command = allocatedBuffers.back();
command->begin(); command->begin();
} }
@@ -440,60 +464,52 @@ CommandPool::~CommandPool()
queue = nullptr; queue = nullptr;
} }
PCmdBuffer CommandPool::getCommands() PCommand CommandPool::getCommands()
{ {
return command; return command;
} }
PRenderCommand CommandPool::createRenderCommand(PRenderPass renderPass, PFramebuffer framebuffer, const std::string& name) PRenderCommand CommandPool::createRenderCommand(const std::string& name)
{ {
std::scoped_lock lck(allocatedRenderLock);
for (uint32 i = 0; i < allocatedRenderCommands.size(); ++i) for (uint32 i = 0; i < allocatedRenderCommands.size(); ++i)
{ {
PRenderCommand cmdBuffer = allocatedRenderCommands[i]; PRenderCommand cmdBuffer = allocatedRenderCommands[i];
if (cmdBuffer->isReady()) if (cmdBuffer->isReady())
{ {
cmdBuffer->name = name; cmdBuffer->name = name;
cmdBuffer->begin(renderPass, framebuffer); cmdBuffer->begin(command->boundRenderPass, command->boundFramebuffer);
return cmdBuffer; return cmdBuffer;
} }
} }
allocatedRenderCommands.add(new RenderCommand(graphics, commandPool)); allocatedRenderCommands.add(new RenderCommand(graphics, commandPool));
PRenderCommand result = allocatedRenderCommands.back(); PRenderCommand result = allocatedRenderCommands.back();
result->name = name; result->name = name;
result->begin(renderPass, framebuffer); result->begin(command->boundRenderPass, command->boundFramebuffer);
return result; return result;
} }
PComputeCommand CommandPool::createComputeCommand(const std::string& name) PComputeCommand CommandPool::createComputeCommand(const std::string& name)
{ {
std::scoped_lock lck(allocatedComputeLock);
for (uint32 i = 0; i < allocatedComputeCommands.size(); ++i) for (uint32 i = 0; i < allocatedComputeCommands.size(); ++i)
{ {
PComputeCommand cmdBuffer = allocatedComputeCommands[i]; PComputeCommand cmdBuffer = allocatedComputeCommands[i];
if (cmdBuffer->isReady()) if (cmdBuffer->isReady())
{ {
cmdBuffer->name = name; cmdBuffer->name = name;
cmdBuffer->begin(command); cmdBuffer->begin();
return cmdBuffer; return cmdBuffer;
} }
} }
allocatedComputeCommands.add(new ComputeCommand(graphics, commandPool)); allocatedComputeCommands.add(new ComputeCommand(graphics, commandPool));
PComputeCommand result = allocatedComputeCommands.back(); PComputeCommand result = allocatedComputeCommands.back();
result->name = name; result->name = name;
result->begin(command); result->begin();
return result; return result;
} }
void CommandPool::submitCommands(PSemaphore signalSemaphore) void CommandPool::submitCommands(PSemaphore signalSemaphore)
{ {
if (command->state == Command::State::Begin || command->state == Command::State::RenderPass) assert(command->state == Command::State::Begin); // Not in a renderpass
{
if (command->state == Command::State::RenderPass)
{
std::cout << "End of renderpass forced" << std::endl;
command->endRenderPass();
}
command->end(); command->end();
if (signalSemaphore != nullptr) if (signalSemaphore != nullptr)
{ {
@@ -503,11 +519,10 @@ void CommandPool::submitCommands(PSemaphore signalSemaphore)
{ {
queue->submitCommandBuffer(command); queue->submitCommandBuffer(command);
} }
}
std::scoped_lock map(allocatedBufferLock);
for (uint32 i = 0; i < allocatedBuffers.size(); ++i) for (uint32 i = 0; i < allocatedBuffers.size(); ++i)
{ {
PCmdBuffer cmdBuffer = allocatedBuffers[i]; PCommand cmdBuffer = allocatedBuffers[i];
cmdBuffer->checkFence(); cmdBuffer->checkFence();
if (cmdBuffer->state == Command::State::Init) if (cmdBuffer->state == Command::State::Init)
{ {
+9 -7
View File
@@ -1,6 +1,6 @@
#pragma once #pragma once
#include "Queue.h" #include "Queue.h"
#include "DescriptorSets.h" #include "Graphics/Command.h"
#include "Buffer.h" #include "Buffer.h"
namespace Seele namespace Seele
@@ -17,7 +17,7 @@ DECLARE_REF(CommandPool)
class Command class Command
{ {
public: public:
Command(PGraphics graphics, VkCommandPool cmdPool, PCommandBufferManager manager); Command(PGraphics graphics, VkCommandPool cmdPool, PCommandPool pool);
virtual ~Command(); virtual ~Command();
constexpr VkCommandBuffer getHandle() constexpr VkCommandBuffer getHandle()
{ {
@@ -34,7 +34,7 @@ public:
void checkFence(); void checkFence();
void waitForCommand(uint32 timeToWait = 1000000u); void waitForCommand(uint32 timeToWait = 1000000u);
PFence getFence(); PFence getFence();
PCommandBufferManager getManager(); PCommandPool getPool();
enum State enum State
{ {
Init, Init,
@@ -46,13 +46,15 @@ public:
private: private:
PGraphics graphics; PGraphics graphics;
PCommandBufferManager manager; PCommandPool pool;
OFence fence; OFence fence;
State state; State state;
VkViewport currentViewport; VkViewport currentViewport;
VkRect2D currentScissor; VkRect2D currentScissor;
VkCommandBuffer handle; VkCommandBuffer handle;
VkCommandPool owner; VkCommandPool owner;
PRenderPass boundRenderPass;
PFramebuffer boundFramebuffer;
Array<PSemaphore> waitSemaphores; Array<PSemaphore> waitSemaphores;
Array<VkPipelineStageFlags> waitFlags; Array<VkPipelineStageFlags> waitFlags;
Array<PRenderCommand> executingRenders; Array<PRenderCommand> executingRenders;
@@ -112,7 +114,7 @@ public:
{ {
return handle; return handle;
} }
void begin(PCmdBuffer parent); void begin();
void end(); void end();
void reset(); void reset();
virtual bool isReady() override; virtual bool isReady() override;
@@ -144,7 +146,7 @@ public:
return queue; return queue;
} }
PCommand getCommands(); PCommand getCommands();
PRenderCommand createRenderCommand(PRenderPass renderPass, PFramebuffer framebuffer, const std::string& name); PRenderCommand createRenderCommand(const std::string& name);
PComputeCommand createComputeCommand(const std::string& name); PComputeCommand createComputeCommand(const std::string& name);
constexpr VkCommandPool getHandle() const constexpr VkCommandPool getHandle() const
{ {
@@ -158,7 +160,7 @@ private:
PQueue queue; PQueue queue;
uint32 queueFamilyIndex; uint32 queueFamilyIndex;
PCommand command; PCommand command;
Array<OCmdBuffer> allocatedBuffers; Array<OCommand> allocatedBuffers;
Array<ORenderCommand> allocatedRenderCommands; Array<ORenderCommand> allocatedRenderCommands;
Array<OComputeCommand> allocatedComputeCommands; Array<OComputeCommand> allocatedComputeCommands;
}; };
+32
View File
@@ -0,0 +1,32 @@
#include "Debug.h"
#include <iostream>
using namespace Seele::Vulkan;
VkBool32 Seele::Vulkan::debugCallback(VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT, uint64_t, size_t, int32_t, const char *layerPrefix, const char *msg, void *)
{
std::cerr << layerPrefix << ": " << msg << std::endl;
return VK_FALSE;
}
VkResult Seele::Vulkan::CreateDebugReportCallbackEXT(VkInstance instance, const VkDebugReportCallbackCreateInfoEXT *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkDebugReportCallbackEXT *pCallback)
{
auto func = (PFN_vkCreateDebugReportCallbackEXT)vkGetInstanceProcAddr(instance, "vkCreateDebugReportCallbackEXT");
if (func != nullptr)
{
return func(instance, pCreateInfo, pAllocator, pCallback);
}
else
{
return VK_ERROR_EXTENSION_NOT_PRESENT;
}
}
void Seele::Vulkan::DestroyDebugReportCallbackEXT(VkInstance instance, const VkAllocationCallbacks *pAllocator, VkDebugReportCallbackEXT pCallback)
{
auto func = (PFN_vkDestroyDebugReportCallbackEXT)vkGetInstanceProcAddr(instance, "vkDestroyDebugReportCallbackEXT");
if (func != nullptr)
{
func(instance, pCallback, pAllocator);
}
}
+14
View File
@@ -0,0 +1,14 @@
#pragma once
#include "Containers/Array.h"
#include <vulkan/vulkan.h>
namespace Seele
{
namespace Vulkan
{
VkBool32 debugCallback(VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT objType, uint64_t obj, size_t location, int32_t code, const char *layerPrefix, const char *msg, void *userData);
VkResult CreateDebugReportCallbackEXT(VkInstance instance, const VkDebugReportCallbackCreateInfoEXT *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkDebugReportCallbackEXT *pCallback);
void DestroyDebugReportCallbackEXT(VkInstance instance, const VkAllocationCallbacks *pAllocator, VkDebugReportCallbackEXT pCallback);
} // namespace Vulkan
} // namespace Seele
+136 -96
View File
@@ -1,8 +1,7 @@
#include "DescriptorSets.h" #include "Descriptor.h"
#include "Graphics.h" #include "Graphics.h"
#include "Initializer.h"
#include "CommandBuffer.h"
#include "Texture.h" #include "Texture.h"
#include "Buffer.h"
using namespace Seele; using namespace Seele;
using namespace Seele::Vulkan; using namespace Seele::Vulkan;
@@ -31,27 +30,32 @@ void DescriptorLayout::create()
Array<VkDescriptorBindingFlags> bindingFlags(descriptorBindings.size()); Array<VkDescriptorBindingFlags> bindingFlags(descriptorBindings.size());
for (size_t i = 0; i < descriptorBindings.size(); ++i) for (size_t i = 0; i < descriptorBindings.size(); ++i)
{ {
VkDescriptorSetLayoutBinding &binding = bindings[i];
const Gfx::DescriptorBinding &gfxBinding = descriptorBindings[i]; const Gfx::DescriptorBinding &gfxBinding = descriptorBindings[i];
binding.binding = gfxBinding.binding; bindings[i] = {
binding.descriptorCount = gfxBinding.descriptorCount; .binding = gfxBinding.binding,
binding.descriptorType = cast(gfxBinding.descriptorType); .descriptorType = cast(gfxBinding.descriptorType),
binding.stageFlags = gfxBinding.shaderStages; .descriptorCount = gfxBinding.descriptorCount,
binding.pImmutableSamplers = nullptr; .stageFlags = gfxBinding.shaderStages,
.pImmutableSamplers = nullptr,
};
bindingFlags[i] = gfxBinding.bindingFlags; bindingFlags[i] = gfxBinding.bindingFlags;
} }
VkDescriptorSetLayoutCreateInfo createInfo =
init::DescriptorSetLayoutCreateInfo(bindings.data(), (uint32)bindings.size());
VkDescriptorSetLayoutBindingFlagsCreateInfo bindingFlagsInfo = { VkDescriptorSetLayoutBindingFlagsCreateInfo bindingFlagsInfo = {
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_BINDING_FLAGS_CREATE_INFO, .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_BINDING_FLAGS_CREATE_INFO,
.pNext = nullptr, .pNext = nullptr,
.bindingCount = static_cast<uint32>(bindingFlags.size()), .bindingCount = static_cast<uint32>(bindingFlags.size()),
.pBindingFlags = bindingFlags.data(), .pBindingFlags = bindingFlags.data(),
}; };
createInfo.pNext = &bindingFlagsInfo; VkDescriptorSetLayoutCreateInfo createInfo = {
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
.pNext = &bindingFlagsInfo,
.flags = 0,
.bindingCount = (uint32)bindings.size(),
.pBindings = bindings.data(),
};
VK_CHECK(vkCreateDescriptorSetLayout(graphics->getDevice(), &createInfo, nullptr, &layoutHandle)); VK_CHECK(vkCreateDescriptorSetLayout(graphics->getDevice(), &createInfo, nullptr, &layoutHandle));
allocator = new DescriptorAllocator(graphics, *this); pool = new DescriptorPool(graphics, *this);
hash = CRC::Calculate(bindings.data(), sizeof(VkDescriptorSetLayoutBinding) * bindings.size(), CRC::CRC_32()); hash = CRC::Calculate(bindings.data(), sizeof(VkDescriptorSetLayoutBinding) * bindings.size(), CRC::CRC_32());
} }
@@ -60,12 +64,10 @@ PipelineLayout::~PipelineLayout()
{ {
if (layoutHandle != VK_NULL_HANDLE) if (layoutHandle != VK_NULL_HANDLE)
{ {
//vkDestroyPipelineLayout(graphics->getDevice(), layoutHandle, nullptr); vkDestroyPipelineLayout(graphics->getDevice(), layoutHandle, nullptr);
} }
} }
static Map<uint32, VkPipelineLayout> layoutCache;
void PipelineLayout::create() void PipelineLayout::create()
{ {
vulkanDescriptorLayouts.resize(descriptorSetLayouts.size()); vulkanDescriptorLayouts.resize(descriptorSetLayouts.size());
@@ -82,8 +84,6 @@ void PipelineLayout::create()
vulkanDescriptorLayouts[i] = layout->getHandle(); vulkanDescriptorLayouts[i] = layout->getHandle();
} }
VkPipelineLayoutCreateInfo createInfo =
init::PipelineLayoutCreateInfo(vulkanDescriptorLayouts.data(), (uint32)vulkanDescriptorLayouts.size());
Array<VkPushConstantRange> vkPushConstants(pushConstants.size()); Array<VkPushConstantRange> vkPushConstants(pushConstants.size());
for (size_t i = 0; i < pushConstants.size(); i++) for (size_t i = 0; i < pushConstants.size(); i++)
{ {
@@ -91,20 +91,21 @@ void PipelineLayout::create()
vkPushConstants[i].size = pushConstants[i].size; vkPushConstants[i].size = pushConstants[i].size;
vkPushConstants[i].stageFlags = (VkShaderStageFlagBits)pushConstants[i].stageFlags; vkPushConstants[i].stageFlags = (VkShaderStageFlagBits)pushConstants[i].stageFlags;
} }
createInfo.pushConstantRangeCount = (uint32)vkPushConstants.size();
createInfo.pPushConstantRanges = vkPushConstants.data(); VkPipelineLayoutCreateInfo createInfo = {
.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
.pNext = nullptr,
.flags = 0,
.setLayoutCount = (uint32)vulkanDescriptorLayouts.size(),
.pSetLayouts = vulkanDescriptorLayouts.data(),
.pushConstantRangeCount = (uint32)vkPushConstants.size(),
.pPushConstantRanges = vkPushConstants.data(),
};
layoutHash = CRC::Calculate(createInfo.pPushConstantRanges, sizeof(VkPushConstantRange) * createInfo.pushConstantRangeCount, CRC::CRC_32()); layoutHash = CRC::Calculate(createInfo.pPushConstantRanges, sizeof(VkPushConstantRange) * createInfo.pushConstantRangeCount, CRC::CRC_32());
layoutHash = CRC::Calculate(createInfo.pSetLayouts, sizeof(VkDescriptorSetLayout) * createInfo.setLayoutCount, CRC::CRC_32(), layoutHash); layoutHash = CRC::Calculate(createInfo.pSetLayouts, sizeof(VkDescriptorSetLayout) * createInfo.setLayoutCount, CRC::CRC_32(), layoutHash);
if(layoutCache[layoutHash] != VK_NULL_HANDLE)
{
layoutHandle = layoutCache[layoutHash];
return;
}
VK_CHECK(vkCreatePipelineLayout(graphics->getDevice(), &createInfo, nullptr, &layoutHandle)); VK_CHECK(vkCreatePipelineLayout(graphics->getDevice(), &createInfo, nullptr, &layoutHandle));
layoutCache[layoutHash] = layoutHandle;
} }
void PipelineLayout::reset() void PipelineLayout::reset()
@@ -127,10 +128,22 @@ void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PUniformBuffer uniformBu
//std::cout << "uniform data equal, skip" << std::endl; //std::cout << "uniform data equal, skip" << std::endl;
return; return;
} }
bufferInfos.add(init::DescriptorBufferInfo(vulkanBuffer->getHandle(), 0, vulkanBuffer->getSize())); bufferInfos.add(VkDescriptorBufferInfo{
.buffer = vulkanBuffer->getHandle(),
.offset = 0,
.range = vulkanBuffer->getSize(),
});
VkWriteDescriptorSet writeDescriptor = init::WriteDescriptorSet(setHandle, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, binding, &bufferInfos.back()); writeDescriptors.add(VkWriteDescriptorSet{
writeDescriptors.add(writeDescriptor); .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
.pNext = nullptr,
.dstSet = setHandle,
.dstBinding = binding,
.dstArrayElement = 0,
.descriptorCount = 1,
.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
.pBufferInfo = &bufferInfos.back(),
});
cachedData[binding] = vulkanBuffer.getHandle(); cachedData[binding] = vulkanBuffer.getHandle();
} }
@@ -143,55 +156,69 @@ void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PShaderBuffer shaderBuff
{ {
return; return;
} }
bufferInfos.add(init::DescriptorBufferInfo(vulkanBuffer->getHandle(), 0, vulkanBuffer->getSize()));
VkWriteDescriptorSet writeDescriptor = init::WriteDescriptorSet(setHandle, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, binding, &bufferInfos.back()); bufferInfos.add(VkDescriptorBufferInfo{
writeDescriptors.add(writeDescriptor); .buffer = vulkanBuffer->getHandle(),
.offset = 0,
.range = vulkanBuffer->getSize(),
});
writeDescriptors.add(VkWriteDescriptorSet{
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
.pNext = nullptr,
.dstSet = setHandle,
.dstBinding = binding,
.dstArrayElement = 0,
.descriptorCount = 1,
.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
.pBufferInfo = &bufferInfos.back(),
});
cachedData[binding] = vulkanBuffer.getHandle(); cachedData[binding] = vulkanBuffer.getHandle();
} }
void DescriptorSet::updateSampler(uint32_t binding, Gfx::PSamplerState samplerState) void DescriptorSet::updateSampler(uint32_t binding, Gfx::PSampler samplerState)
{ {
PSamplerState vulkanSampler = samplerState.cast<Sampler>(); PSampler vulkanSampler = samplerState.cast<Sampler>();
Sampler* cachedSampler = reinterpret_cast<Sampler*>(cachedData[binding]); Sampler* cachedSampler = reinterpret_cast<Sampler*>(cachedData[binding]);
if(vulkanSampler.getHandle() == cachedSampler) if(vulkanSampler.getHandle() == cachedSampler)
{ {
return; return;
} }
VkDescriptorImageInfo imageInfo = imageInfos.add(VkDescriptorImageInfo{
init::DescriptorImageInfo( .sampler = vulkanSampler->sampler,
vulkanSampler->sampler, .imageView = VK_NULL_HANDLE,
VK_NULL_HANDLE, .imageLayout = VK_IMAGE_LAYOUT_UNDEFINED,
VK_IMAGE_LAYOUT_UNDEFINED); });
imageInfos.add(imageInfo);
VkWriteDescriptorSet writeDescriptor = init::WriteDescriptorSet(setHandle, VK_DESCRIPTOR_TYPE_SAMPLER, binding, &imageInfos.back()); writeDescriptors.add(VkWriteDescriptorSet{
writeDescriptors.add(writeDescriptor); .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
.pNext = nullptr,
.dstSet = setHandle,
.dstBinding = binding,
.dstArrayElement = 0,
.descriptorCount = 1,
.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER,
.pImageInfo = &imageInfos.back(),
});
cachedData[binding] = vulkanSampler.getHandle(); cachedData[binding] = vulkanSampler.getHandle();
} }
void DescriptorSet::updateTexture(uint32_t binding, Gfx::PTexture texture, Gfx::PSamplerState samplerState) void DescriptorSet::updateTexture(uint32_t binding, Gfx::PTexture texture, Gfx::PSampler samplerState)
{ {
TextureHandle* vulkanTexture = TextureBase::cast(texture); TextureBase* vulkanTexture = texture.cast<TextureBase>().getHandle();
TextureHandle* cachedTexture = reinterpret_cast<TextureHandle*>(cachedData[binding]); TextureBase* cachedTexture = reinterpret_cast<TextureBase*>(cachedData[binding]);
if(vulkanTexture == cachedTexture) if(vulkanTexture == cachedTexture)
{ {
return; return;
} }
//It is assumed that the image is in the correct layout //It is assumed that the image is in the correct layout
VkDescriptorImageInfo imageInfo = imageInfos.add(VkDescriptorImageInfo{
init::DescriptorImageInfo( .sampler = samplerState != nullptr ? samplerState.cast<Sampler>()->sampler : VK_NULL_HANDLE,
VK_NULL_HANDLE, .imageView = vulkanTexture->getView(),
vulkanTexture->getView(), .imageLayout = cast(vulkanTexture->getLayout()),
cast(vulkanTexture->getLayout())); });
if (samplerState != nullptr)
{
PSamplerState vulkanSampler = samplerState.cast<Sampler>();
imageInfo.sampler = vulkanSampler->sampler;
}
imageInfos.add(imageInfo);
VkDescriptorType descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; VkDescriptorType descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
if(samplerState != nullptr) if(samplerState != nullptr)
{ {
@@ -201,14 +228,16 @@ void DescriptorSet::updateTexture(uint32_t binding, Gfx::PTexture texture, Gfx::
{ {
descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
} }
VkWriteDescriptorSet writeDescriptor = writeDescriptors.add(VkWriteDescriptorSet{
init::WriteDescriptorSet( .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
setHandle, .pNext = nullptr,
descriptorType, .dstSet = setHandle,
binding, .dstBinding = binding,
&imageInfos.back()); .dstArrayElement = 0,
.descriptorCount = 1,
writeDescriptors.add(writeDescriptor); .descriptorType = descriptorType,
.pImageInfo = &imageInfos.back(),
});
cachedData[binding] = vulkanTexture; cachedData[binding] = vulkanTexture;
} }
@@ -216,28 +245,30 @@ void DescriptorSet::updateTextureArray(uint32_t binding, Array<Gfx::PTexture> te
{ {
// maybe make this a parameter? // maybe make this a parameter?
uint32 arrayElement = 0; uint32 arrayElement = 0;
for(const auto& gfxTexture : textures) for(auto& gfxTexture : textures)
{ {
TextureHandle* vulkanTexture = TextureBase::cast(gfxTexture); TextureBase* vulkanTexture = gfxTexture.cast<TextureBase>().getHandle();
imageInfos.add( imageInfos.add(VkDescriptorImageInfo{
init::DescriptorImageInfo( .sampler = VK_NULL_HANDLE,
VK_NULL_HANDLE, .imageView = vulkanTexture->getView(),
vulkanTexture->getView(), .imageLayout = cast(vulkanTexture->getLayout()),
cast(vulkanTexture->getLayout()))); });
VkDescriptorType descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; VkDescriptorType descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
if (vulkanTexture->getUsage() & VK_IMAGE_USAGE_STORAGE_BIT) if (vulkanTexture->getUsage() & VK_IMAGE_USAGE_STORAGE_BIT)
{ {
descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
} }
VkWriteDescriptorSet& write = writeDescriptors.add( writeDescriptors.add(VkWriteDescriptorSet{
init::WriteDescriptorSet( .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
setHandle, .pNext = nullptr,
descriptorType, .dstSet = setHandle,
binding, .dstBinding = binding,
&imageInfos.back() .dstArrayElement = arrayElement++,
)); .descriptorCount = 1,
write.dstArrayElement = arrayElement++; .descriptorType = descriptorType,
.pImageInfo = &imageInfos.back(),
});
} }
} }
@@ -268,7 +299,7 @@ void DescriptorSet::writeChanges()
} }
} }
DescriptorAllocator::DescriptorAllocator(PGraphics graphics, DescriptorLayout &layout) DescriptorPool::DescriptorPool(PGraphics graphics, DescriptorLayout &layout)
: graphics(graphics) : graphics(graphics)
, layout(layout) , layout(layout)
{ {
@@ -296,15 +327,18 @@ DescriptorAllocator::DescriptorAllocator(PGraphics graphics, DescriptorLayout &l
poolSizes.add(size); poolSizes.add(size);
} }
} }
VkDescriptorPoolCreateInfo createInfo VkDescriptorPoolCreateInfo createInfo = {
= init::DescriptorPoolCreateInfo( .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
(uint32)poolSizes.size(), .pNext = nullptr,
poolSizes.data(), .flags = 0,
maxSets * Gfx::numFramesBuffered); .maxSets = maxSets * Gfx::numFramesBuffered,
.poolSizeCount = (uint32)poolSizes.size(),
.pPoolSizes = poolSizes.data(),
};
VK_CHECK(vkCreateDescriptorPool(graphics->getDevice(), &createInfo, nullptr, &poolHandle)); VK_CHECK(vkCreateDescriptorPool(graphics->getDevice(), &createInfo, nullptr, &poolHandle));
} }
DescriptorAllocator::~DescriptorAllocator() DescriptorPool::~DescriptorPool()
{ {
vkDestroyDescriptorPool(graphics->getDevice(), poolHandle, nullptr); vkDestroyDescriptorPool(graphics->getDevice(), poolHandle, nullptr);
graphics = nullptr; graphics = nullptr;
@@ -314,15 +348,21 @@ DescriptorAllocator::~DescriptorAllocator()
} }
} }
Gfx::PDescriptorSet DescriptorAllocator::allocateDescriptorSet() Gfx::PDescriptorSet DescriptorPool::allocateDescriptorSet()
{ {
VkDescriptorSetLayout layoutHandle = layout.getHandle(); VkDescriptorSetLayout layoutHandle = layout.getHandle();
VkDescriptorSetAllocateInfo allocInfo = VkDescriptorSetVariableDescriptorCountAllocateInfo setCounts = {
init::DescriptorSetAllocateInfo(poolHandle, &layoutHandle, 1); .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_VARIABLE_DESCRIPTOR_COUNT_ALLOCATE_INFO,
VkDescriptorSetVariableDescriptorCountAllocateInfo setCounts = {}; .pNext = nullptr,
setCounts.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_VARIABLE_DESCRIPTOR_COUNT_ALLOCATE_INFO; .descriptorSetCount = 1,
setCounts.pNext = nullptr; };
setCounts.descriptorSetCount = 1; VkDescriptorSetAllocateInfo allocInfo = {
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,
.pNext = nullptr,
.descriptorPool = poolHandle,
.descriptorSetCount = 1,
.pSetLayouts = &layoutHandle,
};
uint32 counts = 0; uint32 counts = 0;
for(const auto& binding : layout.bindings) for(const auto& binding : layout.bindings)
{ {
@@ -364,13 +404,13 @@ Gfx::PDescriptorSet DescriptorAllocator::allocateDescriptorSet()
} }
if(nextAlloc == nullptr) if(nextAlloc == nullptr)
{ {
nextAlloc = new DescriptorAllocator(graphics, layout); nextAlloc = new DescriptorPool(graphics, layout);
} }
return nextAlloc->allocateDescriptorSet(); return nextAlloc->allocateDescriptorSet();
//throw std::logic_error("Out of descriptor sets"); //throw std::logic_error("Out of descriptor sets");
} }
void DescriptorAllocator::reset() void DescriptorPool::reset()
{ {
for(uint32 i = 0; i < cachedHandles.size(); ++i) for(uint32 i = 0; i < cachedHandles.size(); ++i)
{ {
+14 -20
View File
@@ -24,7 +24,7 @@ private:
PGraphics graphics; PGraphics graphics;
Array<VkDescriptorSetLayoutBinding> bindings; Array<VkDescriptorSetLayoutBinding> bindings;
VkDescriptorSetLayout layoutHandle; VkDescriptorSetLayout layoutHandle;
friend class DescriptorAllocator; friend class DescriptorPool;
}; };
DEFINE_REF(DescriptorLayout) DEFINE_REF(DescriptorLayout)
class PipelineLayout : public Gfx::PipelineLayout class PipelineLayout : public Gfx::PipelineLayout
@@ -33,25 +33,19 @@ public:
PipelineLayout(PGraphics graphics, Gfx::PPipelineLayout baseLayout) PipelineLayout(PGraphics graphics, Gfx::PPipelineLayout baseLayout)
: Gfx::PipelineLayout(baseLayout) : Gfx::PipelineLayout(baseLayout)
, graphics(graphics) , graphics(graphics)
, layoutHash(0)
, layoutHandle(VK_NULL_HANDLE) , layoutHandle(VK_NULL_HANDLE)
{} {}
virtual ~PipelineLayout(); virtual ~PipelineLayout();
virtual void create(); virtual void create();
virtual void reset(); virtual void reset();
inline VkPipelineLayout getHandle() const constexpr VkPipelineLayout getHandle() const
{ {
return layoutHandle; return layoutHandle;
} }
virtual uint32 getHash() const
{
return layoutHash;
}
private: private:
Array<VkDescriptorSetLayout> vulkanDescriptorLayouts; Array<VkDescriptorSetLayout> vulkanDescriptorLayouts;
PGraphics graphics; PGraphics graphics;
uint32 layoutHash;
VkPipelineLayout layoutHandle; VkPipelineLayout layoutHandle;
}; };
DEFINE_REF(PipelineLayout) DEFINE_REF(PipelineLayout)
@@ -59,7 +53,7 @@ DEFINE_REF(PipelineLayout)
class DescriptorSet : public Gfx::DescriptorSet class DescriptorSet : public Gfx::DescriptorSet
{ {
public: public:
DescriptorSet(PGraphics graphics, PDescriptorAllocator owner) DescriptorSet(PGraphics graphics, PDescriptorPool owner)
: setHandle(VK_NULL_HANDLE) : setHandle(VK_NULL_HANDLE)
, graphics(graphics) , graphics(graphics)
, owner(owner) , owner(owner)
@@ -71,8 +65,8 @@ public:
virtual void writeChanges(); virtual void writeChanges();
virtual void updateBuffer(uint32_t binding, Gfx::PUniformBuffer uniformBuffer); virtual void updateBuffer(uint32_t binding, Gfx::PUniformBuffer uniformBuffer);
virtual void updateBuffer(uint32_t binding, Gfx::PShaderBuffer uniformBuffer); virtual void updateBuffer(uint32_t binding, Gfx::PShaderBuffer uniformBuffer);
virtual void updateSampler(uint32_t binding, Gfx::PSamplerState samplerState); virtual void updateSampler(uint32_t binding, Gfx::PSampler samplerState);
virtual void updateTexture(uint32_t binding, Gfx::PTexture texture, Gfx::PSamplerState sampler = nullptr); virtual void updateTexture(uint32_t binding, Gfx::PTexture texture, Gfx::PSampler sampler = nullptr);
virtual void updateTextureArray(uint32_t binding, Array<Gfx::PTexture> texture); virtual void updateTextureArray(uint32_t binding, Array<Gfx::PTexture> texture);
virtual bool operator<(Gfx::PDescriptorSet other); virtual bool operator<(Gfx::PDescriptorSet other);
@@ -116,29 +110,29 @@ private:
Array<void*> cachedData; Array<void*> cachedData;
VkDescriptorSet setHandle; VkDescriptorSet setHandle;
PGraphics graphics; PGraphics graphics;
PDescriptorAllocator owner; PDescriptorPool owner;
bool currentlyBound; bool currentlyBound;
bool currentlyInUse; bool currentlyInUse;
friend class DescriptorAllocator; friend class DescriptorPool;
friend class Command; friend class Command;
friend class RenderCommand; friend class RenderCommand;
friend class ComputeCommand; friend class ComputeCommand;
}; };
DEFINE_REF(DescriptorSet) DEFINE_REF(DescriptorSet)
class DescriptorAllocator : public Gfx::DescriptorAllocator class DescriptorPool : public Gfx::DescriptorPool
{ {
public: public:
DescriptorAllocator(PGraphics graphics, DescriptorLayout &layout); DescriptorPool(PGraphics graphics, DescriptorLayout &layout);
virtual ~DescriptorAllocator(); virtual ~DescriptorPool();
virtual Gfx::PDescriptorSet allocateDescriptorSet() override; virtual Gfx::PDescriptorSet allocateDescriptorSet() override;
virtual void reset(); virtual void reset();
inline VkDescriptorPool getHandle() const constexpr VkDescriptorPool getHandle() const
{ {
return poolHandle; return poolHandle;
} }
inline DescriptorLayout& getLayout() const constexpr DescriptorLayout& getLayout() const
{ {
return layout; return layout;
} }
@@ -149,8 +143,8 @@ private:
const static int maxSets = 64; const static int maxSets = 64;
StaticArray<ODescriptorSet, maxSets> cachedHandles; StaticArray<ODescriptorSet, maxSets> cachedHandles;
VkDescriptorPool poolHandle; VkDescriptorPool poolHandle;
DescriptorAllocator* nextAlloc = nullptr; DescriptorPool* nextAlloc = nullptr;
}; };
DEFINE_REF(DescriptorAllocator) DEFINE_REF(DescriptorPool)
} // namespace Vulkan } // namespace Vulkan
} // namespace Seele } // namespace Seele
+19 -18
View File
@@ -1,6 +1,5 @@
#include "Framebuffer.h" #include "Framebuffer.h"
#include "Enums.h" #include "Enums.h"
#include "Initializer.h"
#include "RenderPass.h" #include "RenderPass.h"
#include "Graphics.h" #include "Graphics.h"
#include "Texture.h" #include "Texture.h"
@@ -16,41 +15,43 @@ Framebuffer::Framebuffer(PGraphics graphics, PRenderPass renderPass, Gfx::PRende
FramebufferDescription description; FramebufferDescription description;
std::memset(&description, 0, sizeof(FramebufferDescription)); std::memset(&description, 0, sizeof(FramebufferDescription));
Array<VkImageView> attachments; Array<VkImageView> attachments;
uint32 sizeX = 0; uint32 width = 0;
uint32 sizeY = 0; uint32 height = 0;
for (auto inputAttachment : layout->inputAttachments) for (auto inputAttachment : layout->inputAttachments)
{ {
PTexture2D vkInputAttachment = inputAttachment->getTexture().cast<Texture2D>(); PTexture2D vkInputAttachment = inputAttachment->getTexture().cast<Texture2D>();
attachments.add(vkInputAttachment->getView()); attachments.add(vkInputAttachment->getView());
description.inputAttachments[description.numInputAttachments++] = vkInputAttachment->getView(); description.inputAttachments[description.numInputAttachments++] = vkInputAttachment->getView();
sizeX = std::max(sizeX, vkInputAttachment->getWidth()); width = std::max(width, vkInputAttachment->getWidth());
sizeY = std::max(sizeY, vkInputAttachment->getHeight()); height = std::max(height, vkInputAttachment->getHeight());
} }
for (auto colorAttachment : layout->colorAttachments) for (auto colorAttachment : layout->colorAttachments)
{ {
PTexture2D vkColorAttachment = colorAttachment->getTexture().cast<Texture2D>(); PTexture2D vkColorAttachment = colorAttachment->getTexture().cast<Texture2D>();
attachments.add(vkColorAttachment->getView()); attachments.add(vkColorAttachment->getView());
description.colorAttachments[description.numColorAttachments++] = vkColorAttachment->getView(); description.colorAttachments[description.numColorAttachments++] = vkColorAttachment->getView();
sizeX = std::max(sizeX, vkColorAttachment->getWidth()); width = std::max(width, vkColorAttachment->getWidth());
sizeY = std::max(sizeY, vkColorAttachment->getHeight()); height = std::max(height, vkColorAttachment->getHeight());
} }
if (layout->depthAttachment != nullptr) if (layout->depthAttachment != nullptr)
{ {
PTexture2D vkDepthAttachment = layout->depthAttachment->getTexture().cast<Texture2D>(); PTexture2D vkDepthAttachment = layout->depthAttachment->getTexture().cast<Texture2D>();
attachments.add(vkDepthAttachment->getView()); attachments.add(vkDepthAttachment->getView());
description.depthAttachment = vkDepthAttachment->getView(); description.depthAttachment = vkDepthAttachment->getView();
sizeX = std::max(sizeX, vkDepthAttachment->getWidth()); width = std::max(width, vkDepthAttachment->getWidth());
sizeY = std::max(sizeY, vkDepthAttachment->getHeight()); height = std::max(height, vkDepthAttachment->getHeight());
} }
VkFramebufferCreateInfo createInfo = VkFramebufferCreateInfo createInfo = {
init::FramebufferCreateInfo( .sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,
renderPass->getHandle(), .pNext = nullptr,
(uint32)attachments.size(), .flags = 0,
attachments.data(), .renderPass = renderPass->getHandle(),
sizeX, .attachmentCount = (uint32)attachments.size(),
sizeY, .pAttachments = attachments.data(),
1); .width = width,
.height = height,
.layers = 1,
};
VK_CHECK(vkCreateFramebuffer(graphics->getDevice(), &createInfo, nullptr, &handle)); VK_CHECK(vkCreateFramebuffer(graphics->getDevice(), &createInfo, nullptr, &handle));
hash = CRC::Calculate(&description, sizeof(FramebufferDescription), CRC::CRC_32()); hash = CRC::Calculate(&description, sizeof(FramebufferDescription), CRC::CRC_32());
+4 -4
View File
@@ -10,8 +10,8 @@ namespace Vulkan
DECLARE_REF(RenderPass) DECLARE_REF(RenderPass)
struct FramebufferDescription struct FramebufferDescription
{ {
VkImageView inputAttachments[16]; StaticArray<VkImageView, 16> inputAttachments;
VkImageView colorAttachments[16]; StaticArray<VkImageView, 16> colorAttachments;
VkImageView depthAttachment; VkImageView depthAttachment;
uint32 numInputAttachments; uint32 numInputAttachments;
uint32 numColorAttachments; uint32 numColorAttachments;
@@ -21,11 +21,11 @@ class Framebuffer
public: public:
Framebuffer(PGraphics graphics, PRenderPass renderpass, Gfx::PRenderTargetLayout renderTargetLayout); Framebuffer(PGraphics graphics, PRenderPass renderpass, Gfx::PRenderTargetLayout renderTargetLayout);
virtual ~Framebuffer(); virtual ~Framebuffer();
inline VkFramebuffer getHandle() const constexpr VkFramebuffer getHandle() const
{ {
return handle; return handle;
} }
inline uint32 getHash() const constexpr uint32 getHash() const
{ {
return hash; return hash;
} }
+62 -78
View File
@@ -1,11 +1,11 @@
#include "Containers/Array.h"
#include "Graphics.h" #include "Graphics.h"
#include "Debug.h"
#include "Allocator.h" #include "Allocator.h"
#include "Buffer.h" #include "Buffer.h"
#include "Graphics/Enums.h" #include "Graphics/Enums.h"
#include "PipelineCache.h" #include "PipelineCache.h"
#include "Command.h" #include "Command.h"
#include "Initializer.h" #include "Descriptor.h"
#include "RenderTarget.h" #include "RenderTarget.h"
#include "RenderPass.h" #include "RenderPass.h"
#include "Framebuffer.h" #include "Framebuffer.h"
@@ -17,10 +17,10 @@
using namespace Seele; using namespace Seele;
using namespace Seele::Vulkan; using namespace Seele::Vulkan;
thread_local OCommandBufferManager Seele::Vulkan::Graphics::graphicsCommands = nullptr; thread_local OCommandPool Seele::Vulkan::Graphics::graphicsCommands = nullptr;
thread_local OCommandBufferManager Seele::Vulkan::Graphics::computeCommands = nullptr; thread_local OCommandPool Seele::Vulkan::Graphics::computeCommands = nullptr;
thread_local OCommandBufferManager Seele::Vulkan::Graphics::transferCommands = nullptr; thread_local OCommandPool Seele::Vulkan::Graphics::transferCommands = nullptr;
thread_local OCommandBufferManager Seele::Vulkan::Graphics::dedicatedTransferCommands = nullptr; thread_local OCommandPool Seele::Vulkan::Graphics::dedicatedTransferCommands = nullptr;
Graphics::Graphics() Graphics::Graphics()
: instance(VK_NULL_HANDLE) : instance(VK_NULL_HANDLE)
@@ -32,7 +32,6 @@ Graphics::Graphics()
Graphics::~Graphics() Graphics::~Graphics()
{ {
viewports.clear();
vkDestroyDevice(handle, nullptr); vkDestroyDevice(handle, nullptr);
DestroyDebugReportCallbackEXT(instance, nullptr, callback); DestroyDebugReportCallbackEXT(instance, nullptr, callback);
vkDestroyInstance(instance, nullptr); vkDestroyInstance(instance, nullptr);
@@ -54,21 +53,16 @@ void Graphics::init(GraphicsInitializer initInfo)
Gfx::OWindow Graphics::createWindow(const WindowCreateInfo &createInfo) Gfx::OWindow Graphics::createWindow(const WindowCreateInfo &createInfo)
{ {
OWindow result = new Window(this, createInfo); return new Window(this, createInfo);
return result;
} }
Gfx::OViewport Graphics::createViewport(Gfx::PWindow owner, const ViewportCreateInfo &viewportInfo) Gfx::OViewport Graphics::createViewport(Gfx::PWindow owner, const ViewportCreateInfo &viewportInfo)
{ {
OViewport result = new Viewport(this, owner, viewportInfo); return new Viewport(this, owner, viewportInfo);
std::scoped_lock lock(viewportLock);
viewports.add(result);
return result;
} }
Gfx::ORenderPass Graphics::createRenderPass(Gfx::ORenderTargetLayout layout, Gfx::PViewport renderArea) Gfx::ORenderPass Graphics::createRenderPass(Gfx::ORenderTargetLayout layout, Gfx::PViewport renderArea)
{ {
ORenderPass result = new RenderPass(this, std::move(layout), renderArea); return new RenderPass(this, std::move(layout), renderArea);
return result;
} }
void Graphics::beginRenderPass(Gfx::PRenderPass renderPass) void Graphics::beginRenderPass(Gfx::PRenderPass renderPass)
{ {
@@ -76,7 +70,6 @@ void Graphics::beginRenderPass(Gfx::PRenderPass renderPass)
uint32 framebufferHash = rp->getFramebufferHash(); uint32 framebufferHash = rp->getFramebufferHash();
PFramebuffer framebuffer; PFramebuffer framebuffer;
{ {
std::scoped_lock lock(allocatedFrameBufferLock);
auto found = allocatedFramebuffers.find(framebufferHash); auto found = allocatedFramebuffers.find(framebufferHash);
if (found == allocatedFramebuffers.end()) if (found == allocatedFramebuffers.end())
{ {
@@ -89,18 +82,12 @@ void Graphics::beginRenderPass(Gfx::PRenderPass renderPass)
} }
} }
getGraphicsCommands()->getCommands()->beginRenderPass(rp, framebuffer); getGraphicsCommands()->getCommands()->beginRenderPass(rp, framebuffer);
std::scoped_lock lock(renderPassLock);
activeRenderPass = rp;
activeFramebuffer = framebuffer;
} }
void Graphics::endRenderPass() void Graphics::endRenderPass()
{ {
getGraphicsCommands()->getCommands()->endRenderPass(); getGraphicsCommands()->getCommands()->endRenderPass();
getGraphicsCommands()->submitCommands(); getGraphicsCommands()->submitCommands();
std::scoped_lock lock(renderPassLock);
activeRenderPass = nullptr;
activeFramebuffer = nullptr;
} }
void Graphics::executeCommands(const Array<Gfx::PRenderCommand>& commands) void Graphics::executeCommands(const Array<Gfx::PRenderCommand>& commands)
@@ -148,7 +135,7 @@ Gfx::OIndexBuffer Graphics::createIndexBuffer(const IndexBufferCreateInfo &bulkD
} }
Gfx::PRenderCommand Graphics::createRenderCommand(const std::string& name) Gfx::PRenderCommand Graphics::createRenderCommand(const std::string& name)
{ {
return getGraphicsCommands()->createRenderCommand(activeRenderPass, activeFramebuffer, name); return getGraphicsCommands()->createRenderCommand(name);
} }
Gfx::PComputeCommand Graphics::createComputeCommand(const std::string& name) Gfx::PComputeCommand Graphics::createComputeCommand(const std::string& name)
@@ -156,10 +143,6 @@ Gfx::PComputeCommand Graphics::createComputeCommand(const std::string& name)
return getComputeCommands()->createComputeCommand(name); return getComputeCommands()->createComputeCommand(name);
} }
Gfx::OVertexDeclaration Graphics::createVertexDeclaration(const Array<Gfx::VertexElement>& element)
{
return new VertexDeclaration(element);
}
Gfx::OVertexShader Graphics::createVertexShader(const ShaderCreateInfo& createInfo) Gfx::OVertexShader Graphics::createVertexShader(const ShaderCreateInfo& createInfo)
{ {
@@ -206,27 +189,29 @@ Gfx::PComputePipeline Graphics::createComputePipeline(Gfx::ComputePipelineCreate
return pipelineCache->createPipeline(std::move(createInfo)); return pipelineCache->createPipeline(std::move(createInfo));
} }
Gfx::OSamplerState Graphics::createSamplerState(const SamplerCreateInfo& createInfo) Gfx::OSampler Graphics::createSampler(const SamplerCreateInfo& createInfo)
{ {
OSamplerState sampler = new SamplerState(); OSampler sampler = new Sampler();
VkSamplerCreateInfo vkInfo = VkSamplerCreateInfo vkInfo = {
init::SamplerCreateInfo(); .sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,
vkInfo.addressModeU = cast(createInfo.addressModeU); .pNext = nullptr,
vkInfo.addressModeV = cast(createInfo.addressModeV); .flags = createInfo.flags,
vkInfo.addressModeW = cast(createInfo.addressModeW); .magFilter = cast(createInfo.magFilter),
vkInfo.anisotropyEnable = createInfo.anisotropyEnable; .minFilter = cast(createInfo.minFilter),
vkInfo.borderColor = cast(createInfo.borderColor); .mipmapMode = cast(createInfo.mipmapMode),
vkInfo.compareEnable = createInfo.compareEnable; .addressModeU = cast(createInfo.addressModeU),
vkInfo.compareOp = cast(createInfo.compareOp); .addressModeV = cast(createInfo.addressModeV),
vkInfo.flags = createInfo.flags; .addressModeW = cast(createInfo.addressModeW),
vkInfo.magFilter = cast(createInfo.magFilter); .mipLodBias = createInfo.mipLodBias,
vkInfo.maxAnisotropy = createInfo.maxAnisotropy; .anisotropyEnable = createInfo.anisotropyEnable,
vkInfo.maxLod = createInfo.maxLod; .maxAnisotropy = createInfo.maxAnisotropy,
vkInfo.minFilter = cast(createInfo.minFilter); .compareEnable = createInfo.compareEnable,
vkInfo.minLod = createInfo.minLod; .compareOp = cast(createInfo.compareOp),
vkInfo.mipLodBias = createInfo.mipLodBias; .minLod = createInfo.minLod,
vkInfo.mipmapMode = cast(createInfo.mipmapMode); .maxLod = createInfo.maxLod,
vkInfo.unnormalizedCoordinates = createInfo.unnormalizedCoordinates; .borderColor = cast(createInfo.borderColor),
.unnormalizedCoordinates = createInfo.unnormalizedCoordinates,
};
VK_CHECK(vkCreateSampler(handle, &vkInfo, nullptr, &sampler->sampler)); VK_CHECK(vkCreateSampler(handle, &vkInfo, nullptr, &sampler->sampler));
return sampler; return sampler;
} }
@@ -246,7 +231,7 @@ void Graphics::vkCmdDrawMeshTasksEXT(VkCommandBuffer handle, uint32 groupX, uint
cmdDrawMeshTasks(handle, groupX, groupY, groupZ); cmdDrawMeshTasks(handle, groupX, groupY, groupZ);
} }
PCommandBufferManager Graphics::getQueueCommands(Gfx::QueueType queueType) PCommandPool Graphics::getQueueCommands(Gfx::QueueType queueType)
{ {
switch (queueType) switch (queueType)
{ {
@@ -262,7 +247,7 @@ PCommandBufferManager Graphics::getQueueCommands(Gfx::QueueType queueType)
throw new std::logic_error("invalid queue type"); throw new std::logic_error("invalid queue type");
} }
} }
PCommandBufferManager Graphics::getGraphicsCommands() PCommandPool Graphics::getGraphicsCommands()
{ {
if(graphicsCommands == nullptr) if(graphicsCommands == nullptr)
{ {
@@ -270,7 +255,7 @@ PCommandBufferManager Graphics::getGraphicsCommands()
} }
return graphicsCommands; return graphicsCommands;
} }
PCommandBufferManager Graphics::getComputeCommands() PCommandPool Graphics::getComputeCommands()
{ {
if(computeCommands == nullptr) if(computeCommands == nullptr)
{ {
@@ -278,7 +263,7 @@ PCommandBufferManager Graphics::getComputeCommands()
} }
return computeCommands; return computeCommands;
} }
PCommandBufferManager Graphics::getTransferCommands() PCommandPool Graphics::getTransferCommands()
{ {
if(transferCommands == nullptr) if(transferCommands == nullptr)
{ {
@@ -286,7 +271,7 @@ PCommandBufferManager Graphics::getTransferCommands()
} }
return transferCommands; return transferCommands;
} }
PCommandBufferManager Graphics::getDedicatedTransferCommands() PCommandPool Graphics::getDedicatedTransferCommands()
{ {
if(dedicatedTransferCommands == nullptr) if(dedicatedTransferCommands == nullptr)
{ {
@@ -356,9 +341,13 @@ void Graphics::initInstance(GraphicsInitializer initInfo)
} }
void Graphics::setupDebugCallback() void Graphics::setupDebugCallback()
{ {
VkDebugReportCallbackCreateInfoEXT createInfo = VkDebugReportCallbackCreateInfoEXT createInfo = {
init::DebugReportCallbackCreateInfo( .sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CALLBACK_CREATE_INFO_EXT,
VK_DEBUG_REPORT_ERROR_BIT_EXT | VK_DEBUG_REPORT_WARNING_BIT_EXT | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT); .pNext = nullptr,
.flags = VK_DEBUG_REPORT_ERROR_BIT_EXT | VK_DEBUG_REPORT_WARNING_BIT_EXT,
.pfnCallback = &debugCallback,
.pUserData = nullptr,
};
VK_CHECK(CreateDebugReportCallbackEXT(instance, &createInfo, nullptr, &callback)); VK_CHECK(CreateDebugReportCallbackEXT(instance, &createInfo, nullptr, &callback));
} }
@@ -488,8 +477,13 @@ void Graphics::createDevice(GraphicsInitializer initializer)
} }
if (numQueuesForFamily > 0) if (numQueuesForFamily > 0)
{ {
VkDeviceQueueCreateInfo info = VkDeviceQueueCreateInfo info = {
init::DeviceQueueCreateInfo(familyIndex, numQueuesForFamily); .sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,
.pNext = nullptr,
.flags = 0,
.queueFamilyIndex = familyIndex,
.queueCount = numQueuesForFamily,
};
numPriorities += numQueuesForFamily; numPriorities += numQueuesForFamily;
queueInfos.add(info); queueInfos.add(info);
} }
@@ -507,11 +501,6 @@ void Graphics::createDevice(GraphicsInitializer initializer)
*currentPriority++ = 1.0f; *currentPriority++ = 1.0f;
} }
} }
VkDeviceCreateInfo deviceInfo = init::DeviceCreateInfo(
queueInfos.data(),
(uint32)queueInfos.size(),
nullptr);
VkPhysicalDeviceDescriptorIndexingFeatures descriptorIndexing = { VkPhysicalDeviceDescriptorIndexingFeatures descriptorIndexing = {
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES, .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES,
.shaderSampledImageArrayNonUniformIndexing = VK_TRUE, .shaderSampledImageArrayNonUniformIndexing = VK_TRUE,
@@ -519,17 +508,6 @@ void Graphics::createDevice(GraphicsInitializer initializer)
.descriptorBindingVariableDescriptorCount = VK_TRUE, .descriptorBindingVariableDescriptorCount = VK_TRUE,
.runtimeDescriptorArray = VK_TRUE, .runtimeDescriptorArray = VK_TRUE,
}; };
deviceInfo.pNext = &descriptorIndexing;
#if ENABLE_VALIDATION
VkDeviceDiagnosticsConfigCreateInfoNV crashDiagInfo;
crashDiagInfo.sType = VK_STRUCTURE_TYPE_DEVICE_DIAGNOSTICS_CONFIG_CREATE_INFO_NV;
crashDiagInfo.pNext = nullptr;
crashDiagInfo.flags =
VK_DEVICE_DIAGNOSTICS_CONFIG_ENABLE_RESOURCE_TRACKING_BIT_NV |
VK_DEVICE_DIAGNOSTICS_CONFIG_ENABLE_AUTOMATIC_CHECKPOINTS_BIT_NV |
VK_DEVICE_DIAGNOSTICS_CONFIG_ENABLE_SHADER_DEBUG_INFO_BIT_NV;
descriptorIndexing.pNext = &crashDiagInfo;
#endif
VkPhysicalDeviceMeshShaderFeaturesEXT enabledMeshShaderFeatures = { VkPhysicalDeviceMeshShaderFeaturesEXT enabledMeshShaderFeatures = {
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MESH_SHADER_FEATURES_EXT, .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MESH_SHADER_FEATURES_EXT,
.taskShader = VK_TRUE, .taskShader = VK_TRUE,
@@ -540,11 +518,17 @@ void Graphics::createDevice(GraphicsInitializer initializer)
descriptorIndexing.pNext = &enabledMeshShaderFeatures; descriptorIndexing.pNext = &enabledMeshShaderFeatures;
initializer.deviceExtensions.add("VK_EXT_mesh_shader"); initializer.deviceExtensions.add("VK_EXT_mesh_shader");
} }
deviceInfo.enabledExtensionCount = (uint32)initializer.deviceExtensions.size(); VkDeviceCreateInfo deviceInfo = {
deviceInfo.ppEnabledExtensionNames = initializer.deviceExtensions.data(); .sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO,
deviceInfo.enabledLayerCount = (uint32_t)initializer.layers.size(); .pNext = &descriptorIndexing,
deviceInfo.ppEnabledLayerNames = initializer.layers.data(); .queueCreateInfoCount = (uint32)queueInfos.size(),
deviceInfo.pEnabledFeatures = &features; .pQueueCreateInfos = queueInfos.data(),
.enabledLayerCount = (uint32_t)initializer.layers.size(),
.ppEnabledLayerNames = initializer.layers.data(),
.enabledExtensionCount = (uint32)initializer.deviceExtensions.size(),
.ppEnabledExtensionNames = initializer.deviceExtensions.data(),
.pEnabledFeatures = &features,
};
VK_CHECK(vkCreateDevice(physicalDevice, &deviceInfo, nullptr, &handle)); VK_CHECK(vkCreateDevice(physicalDevice, &deviceInfo, nullptr, &handle));
std::cout << "Vulkan handle: " << handle << std::endl; std::cout << "Vulkan handle: " << handle << std::endl;
+11 -13
View File
@@ -12,6 +12,7 @@ DECLARE_REF(DestructionManager)
DECLARE_REF(CommandPool) DECLARE_REF(CommandPool)
DECLARE_REF(Queue) DECLARE_REF(Queue)
DECLARE_REF(PipelineCache) DECLARE_REF(PipelineCache)
DECLARE_REF(Framebuffer)
class Graphics : public Gfx::Graphics class Graphics : public Gfx::Graphics
{ {
public: public:
@@ -21,11 +22,11 @@ public:
constexpr VkDevice getDevice() const { return handle; }; constexpr VkDevice getDevice() const { return handle; };
constexpr VkPhysicalDevice getPhysicalDevice() const { return physicalDevice; }; constexpr VkPhysicalDevice getPhysicalDevice() const { return physicalDevice; };
PCommandBufferManager getQueueCommands(Gfx::QueueType queueType); PCommandPool getQueueCommands(Gfx::QueueType queueType);
PCommandBufferManager getGraphicsCommands(); PCommandPool getGraphicsCommands();
PCommandBufferManager getComputeCommands(); PCommandPool getComputeCommands();
PCommandBufferManager getTransferCommands(); PCommandPool getTransferCommands();
PCommandBufferManager getDedicatedTransferCommands(); PCommandPool getDedicatedTransferCommands();
PAllocator getAllocator(); PAllocator getAllocator();
PStagingManager getStagingManager(); PStagingManager getStagingManager();
@@ -62,12 +63,11 @@ public:
virtual Gfx::PGraphicsPipeline createGraphicsPipeline(Gfx::LegacyPipelineCreateInfo createInfo) override; virtual Gfx::PGraphicsPipeline createGraphicsPipeline(Gfx::LegacyPipelineCreateInfo createInfo) override;
virtual Gfx::PGraphicsPipeline createGraphicsPipeline(Gfx::MeshPipelineCreateInfo createInfo) override; virtual Gfx::PGraphicsPipeline createGraphicsPipeline(Gfx::MeshPipelineCreateInfo createInfo) override;
virtual Gfx::PComputePipeline createComputePipeline(Gfx::ComputePipelineCreateInfo createInfo) override; virtual Gfx::PComputePipeline createComputePipeline(Gfx::ComputePipelineCreateInfo createInfo) override;
virtual Gfx::OSampler createSamplerState(const SamplerCreateInfo& createInfo) override; virtual Gfx::OSampler createSampler(const SamplerCreateInfo& createInfo) override;
virtual Gfx::ODescriptorLayout createDescriptorLayout(const std::string& name = "") override; virtual Gfx::ODescriptorLayout createDescriptorLayout(const std::string& name = "") override;
virtual Gfx::OPipelineLayout createPipelineLayout(Gfx::PPipelineLayout baseLayout = nullptr) override; virtual Gfx::OPipelineLayout createPipelineLayout(Gfx::PPipelineLayout baseLayout = nullptr) override;
virtual void copyTexture(Gfx::PTexture srcTexture, Gfx::PTexture dstTexture) override;
void vkCmdDrawMeshTasksEXT(VkCommandBuffer handle, uint32 groupX, uint32 groupY, uint32 groupZ); void vkCmdDrawMeshTasksEXT(VkCommandBuffer handle, uint32 groupX, uint32 groupY, uint32 groupZ);
protected: protected:
PFN_vkCmdDrawMeshTasksEXT cmdDrawMeshTasks; PFN_vkCmdDrawMeshTasksEXT cmdDrawMeshTasks;
@@ -86,15 +86,13 @@ protected:
OQueue transferQueue; OQueue transferQueue;
OQueue dedicatedTransferQueue; OQueue dedicatedTransferQueue;
OPipelineCache pipelineCache; OPipelineCache pipelineCache;
thread_local static OCommandBufferManager graphicsCommands; thread_local static OCommandPool graphicsCommands;
thread_local static OCommandBufferManager computeCommands; thread_local static OCommandPool computeCommands;
thread_local static OCommandBufferManager transferCommands; thread_local static OCommandPool transferCommands;
thread_local static OCommandBufferManager dedicatedTransferCommands; thread_local static OCommandPool dedicatedTransferCommands;
VkPhysicalDeviceProperties props; VkPhysicalDeviceProperties props;
VkPhysicalDeviceFeatures features; VkPhysicalDeviceFeatures features;
VkDebugReportCallbackEXT callback; VkDebugReportCallbackEXT callback;
Array<PViewport> viewports;
std::mutex allocatedFrameBufferLock;
Map<uint32, OFramebuffer> allocatedFramebuffers; Map<uint32, OFramebuffer> allocatedFramebuffers;
OAllocator allocator; OAllocator allocator;
OStagingManager stagingManager; OStagingManager stagingManager;
-807
View File
@@ -1,807 +0,0 @@
#include "Initializer.h"
#include <iostream>
#include "Initializer.h"
#include "Initializer.h"
using namespace Seele::Vulkan;
VkApplicationInfo init::ApplicationInfo(const char *appName, uint32_t appVersion, const char *engineName, uint32_t engineVersion, uint32_t apiVersion)
{
VkApplicationInfo info = {};
info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
info.pApplicationName = appName;
info.applicationVersion = appVersion;
info.pEngineName = engineName;
info.engineVersion = engineVersion;
info.apiVersion = apiVersion;
return info;
}
VkInstanceCreateInfo init::InstanceCreateInfo(VkApplicationInfo *appInfo, const Array<const char *> &extensions, const Array<const char *> &layers)
{
VkInstanceCreateInfo info = {};
info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
info.pApplicationInfo = appInfo;
info.enabledExtensionCount = (uint32_t)extensions.size();
info.ppEnabledExtensionNames = extensions.data();
info.enabledLayerCount = (uint32_t)layers.size();
info.ppEnabledLayerNames = layers.data();
return info;
}
VkDebugReportCallbackCreateInfoEXT init::DebugReportCallbackCreateInfo(VkDebugReportFlagsEXT flags)
{
VkDebugReportCallbackCreateInfoEXT createInfo = {};
createInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CALLBACK_CREATE_INFO_EXT;
createInfo.flags = flags;
createInfo.pfnCallback = (PFN_vkDebugReportCallbackEXT)debugCallback;
return createInfo;
}
VkDeviceQueueCreateInfo init::DeviceQueueCreateInfo(int queueFamilyIndex, int queueCount)
{
float priority = 1.0f;
return DeviceQueueCreateInfo(queueFamilyIndex, queueCount, &priority);
}
VkDeviceQueueCreateInfo init::DeviceQueueCreateInfo(int queueFamilyIndex, int queueCount, float *queuePriority)
{
VkDeviceQueueCreateInfo createInfo = {};
createInfo.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
createInfo.queueFamilyIndex = queueFamilyIndex;
createInfo.queueCount = queueCount;
createInfo.pQueuePriorities = queuePriority;
return createInfo;
}
VkDeviceCreateInfo init::DeviceCreateInfo(VkDeviceQueueCreateInfo *queueInfos, uint32_t queueCount, VkPhysicalDeviceFeatures *features)
{
return DeviceCreateInfo(queueInfos, queueCount, features, nullptr, 0, nullptr, 0);
}
VkSwapchainCreateInfoKHR init::SwapchainCreateInfo(VkSurfaceKHR surface, uint32_t minImageCount, VkFormat imageFormat, VkColorSpaceKHR colorSpace, VkExtent2D extent, uint32_t arrayLayers, VkImageUsageFlags usage, VkSurfaceTransformFlagBitsKHR Transform, VkCompositeAlphaFlagBitsKHR alpha, VkPresentModeKHR presentMode, VkBool32 clipped)
{
VkSwapchainCreateInfoKHR createInfo = {};
createInfo.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
createInfo.surface = surface;
createInfo.minImageCount = minImageCount;
createInfo.imageFormat = imageFormat;
createInfo.imageColorSpace = colorSpace;
createInfo.imageExtent = extent;
createInfo.imageArrayLayers = arrayLayers;
createInfo.imageUsage = usage;
createInfo.preTransform = Transform;
createInfo.compositeAlpha = alpha;
createInfo.presentMode = presentMode;
createInfo.clipped = clipped;
return createInfo;
}
VkSwapchainCreateInfoKHR init::SwapchainCreateInfo(VkSurfaceKHR surface, uint32_t minImageCount, VkFormat imageFormat, VkColorSpaceKHR colorSpace, uint32_t width, uint32_t height, uint32_t arrayLayers, VkImageUsageFlags usage, VkSurfaceTransformFlagBitsKHR Transform, VkCompositeAlphaFlagBitsKHR alpha, VkPresentModeKHR presentMode, VkBool32 clipped)
{
VkSwapchainCreateInfoKHR createInfo = {};
createInfo.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
createInfo.surface = surface;
createInfo.minImageCount = minImageCount;
createInfo.imageFormat = imageFormat;
createInfo.imageColorSpace = colorSpace;
createInfo.imageExtent.width = width;
createInfo.imageExtent.height = height;
createInfo.imageArrayLayers = arrayLayers;
createInfo.imageUsage = usage;
createInfo.preTransform = Transform;
createInfo.compositeAlpha = alpha;
createInfo.presentMode = presentMode;
createInfo.clipped = clipped;
return createInfo;
}
VkFramebufferCreateInfo init::FramebufferCreateInfo(VkRenderPass renderPass, uint32_t attachmentCount, VkImageView *attachments, uint32_t width, uint32_t height, uint32_t layers)
{
VkFramebufferCreateInfo frameBufferCreateInfo = {};
frameBufferCreateInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
frameBufferCreateInfo.pNext = nullptr;
frameBufferCreateInfo.renderPass = renderPass;
frameBufferCreateInfo.attachmentCount = attachmentCount;
frameBufferCreateInfo.pAttachments = attachments;
frameBufferCreateInfo.width = width;
frameBufferCreateInfo.height = height;
frameBufferCreateInfo.layers = layers;
return frameBufferCreateInfo;
}
VkAttachmentDescription init::AttachmentDescription(VkFormat format, VkSampleCountFlagBits sample, VkAttachmentLoadOp loadOp, VkAttachmentStoreOp storeOp, VkAttachmentLoadOp stencilLoadOp, VkAttachmentStoreOp stencilStoreOp, VkImageLayout imageLayout, VkImageLayout finalLayout)
{
VkAttachmentDescription desc = {};
desc.format = format;
desc.samples = sample;
desc.loadOp = loadOp;
desc.storeOp = storeOp;
desc.stencilLoadOp = stencilLoadOp;
desc.stencilStoreOp = stencilStoreOp;
desc.initialLayout = imageLayout;
desc.finalLayout = finalLayout;
return desc;
}
VkSubpassDescription init::SubpassDescription(VkPipelineBindPoint bindPoint,
uint32_t colorAttachmentCount, VkAttachmentReference *colorReference,
VkAttachmentReference *depthReference,
uint32_t inputAttachmentCount, VkAttachmentReference *inputReference,
VkAttachmentReference *resolveReference, uint32_t preserveAttachmentCount, uint32_t *preserveReference)
{
VkSubpassDescription desc = {};
desc.pipelineBindPoint = bindPoint;
desc.colorAttachmentCount = colorAttachmentCount;
desc.pColorAttachments = colorReference;
desc.inputAttachmentCount = inputAttachmentCount;
desc.pInputAttachments = inputReference;
desc.pResolveAttachments = resolveReference;
desc.preserveAttachmentCount = preserveAttachmentCount;
desc.pPreserveAttachments = preserveReference;
desc.pDepthStencilAttachment = depthReference;
return desc;
}
VkRenderPassCreateInfo init::RenderPassCreateInfo(uint32_t attachmentCount, const VkAttachmentDescription *attachments, uint32_t subpassCount, const VkSubpassDescription *subpasses, uint32_t dependencyCount, const VkSubpassDependency *subpassDependencies)
{
VkRenderPassCreateInfo info = {};
info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
info.attachmentCount = attachmentCount;
info.pAttachments = attachments;
info.subpassCount = subpassCount;
info.pSubpasses = subpasses;
info.dependencyCount = dependencyCount;
info.pDependencies = subpassDependencies;
return info;
}
VkDeviceCreateInfo init::DeviceCreateInfo(VkDeviceQueueCreateInfo *queueInfos, uint32_t queueCount, VkPhysicalDeviceFeatures *features, const char *const *deviceExtensions, uint32_t deviceExtensionCount, const char *const *layers, uint32_t layerCount)
{
VkDeviceCreateInfo createInfo = {};
createInfo.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
createInfo.pQueueCreateInfos = queueInfos;
createInfo.queueCreateInfoCount = queueCount;
createInfo.pEnabledFeatures = features;
createInfo.ppEnabledExtensionNames = deviceExtensions;
createInfo.enabledExtensionCount = deviceExtensionCount;
#ifdef ENABLE_VALIDATION
createInfo.enabledLayerCount = layerCount;
createInfo.ppEnabledLayerNames = layers;
#else
(void)layers;
(void)layerCount;
createInfo.enabledLayerCount = 0;
layerCount = 0;
layers = nullptr;
#endif // ENABLE_VALIDATION
return createInfo;
}
VkMemoryAllocateInfo init::MemoryAllocateInfo()
{
VkMemoryAllocateInfo memAllocInfo = {};
memAllocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
memAllocInfo.pNext = NULL;
return memAllocInfo;
}
VkCommandBufferAllocateInfo init::CommandBufferAllocateInfo(VkCommandPool commandPool, VkCommandBufferLevel level, uint32_t bufferCount)
{
VkCommandBufferAllocateInfo commandBufferAllocateInfo = {};
commandBufferAllocateInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
commandBufferAllocateInfo.commandPool = commandPool;
commandBufferAllocateInfo.level = level;
commandBufferAllocateInfo.commandBufferCount = bufferCount;
return commandBufferAllocateInfo;
}
VkCommandPoolCreateInfo init::CommandPoolCreateInfo()
{
VkCommandPoolCreateInfo cmdPoolCreateInfo = {};
cmdPoolCreateInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
return cmdPoolCreateInfo;
}
VkCommandBufferBeginInfo init::CommandBufferBeginInfo()
{
VkCommandBufferBeginInfo cmdBufferBeginInfo = {};
cmdBufferBeginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
cmdBufferBeginInfo.pNext = NULL;
return cmdBufferBeginInfo;
}
VkCommandBufferInheritanceInfo init::CommandBufferInheritanceInfo()
{
VkCommandBufferInheritanceInfo cmdBufferInheritanceInfo = {};
cmdBufferInheritanceInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
return cmdBufferInheritanceInfo;
}
VkRenderPassBeginInfo init::RenderPassBeginInfo()
{
VkRenderPassBeginInfo renderPassBeginInfo = {};
renderPassBeginInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
renderPassBeginInfo.pNext = NULL;
return renderPassBeginInfo;
}
VkRenderPassCreateInfo init::RenderPassCreateInfo()
{
VkRenderPassCreateInfo renderPassCreateInfo = {};
renderPassCreateInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
renderPassCreateInfo.pNext = NULL;
return renderPassCreateInfo;
}
VkImageMemoryBarrier init::ImageMemoryBarrier(VkImage image, VkImageLayout oldLayout, VkImageLayout newLayout, uint32_t srcQueue, uint32_t dstQueue)
{
VkImageMemoryBarrier barrier = {};
barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
barrier.oldLayout = oldLayout;
barrier.newLayout = newLayout;
barrier.srcQueueFamilyIndex = srcQueue;
barrier.dstQueueFamilyIndex = dstQueue;
barrier.image = image;
if (newLayout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL)
{
barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
}
else
{
barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
}
barrier.subresourceRange.baseMipLevel = 0;
barrier.subresourceRange.levelCount = 1;
barrier.subresourceRange.baseArrayLayer = 0;
barrier.subresourceRange.layerCount = 1;
if (oldLayout == VK_IMAGE_LAYOUT_PREINITIALIZED && newLayout == VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL)
{
barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT;
}
else if (oldLayout == VK_IMAGE_LAYOUT_PREINITIALIZED && newLayout == VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL)
{
barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
}
else if (oldLayout == VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL && newLayout == VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL)
{
barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
}
else if (oldLayout == VK_IMAGE_LAYOUT_UNDEFINED && newLayout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL)
{
barrier.srcAccessMask = 0;
barrier.dstAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
}
else if (oldLayout == VK_IMAGE_LAYOUT_UNDEFINED && newLayout == VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL)
{
barrier.srcAccessMask = 0;
barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
}
return barrier;
}
VkImageMemoryBarrier init::ImageMemoryBarrier()
{
VkImageMemoryBarrier barrier = {};
barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
barrier.pNext = nullptr;
return barrier;
}
VkBufferMemoryBarrier init::BufferMemoryBarrier()
{
VkBufferMemoryBarrier bufferMemoryBarrier = {};
bufferMemoryBarrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
bufferMemoryBarrier.pNext = NULL;
bufferMemoryBarrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
bufferMemoryBarrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
return bufferMemoryBarrier;
}
VkMemoryBarrier init::MemoryBarrier()
{
VkMemoryBarrier memoryBarrier = {};
memoryBarrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
memoryBarrier.pNext = NULL;
return memoryBarrier;
}
VkImageCreateInfo init::ImageCreateInfo()
{
VkImageCreateInfo imageCreateInfo = {};
imageCreateInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
imageCreateInfo.pNext = NULL;
return imageCreateInfo;
}
VkSamplerCreateInfo init::SamplerCreateInfo()
{
VkSamplerCreateInfo samplerCreateInfo = {};
samplerCreateInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
samplerCreateInfo.pNext = NULL;
samplerCreateInfo.magFilter = VK_FILTER_LINEAR;
samplerCreateInfo.minFilter = VK_FILTER_LINEAR;
samplerCreateInfo.addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT;
samplerCreateInfo.addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT;
samplerCreateInfo.addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT;
samplerCreateInfo.anisotropyEnable = VK_FALSE;
samplerCreateInfo.maxAnisotropy = 1.0f;
samplerCreateInfo.borderColor = VK_BORDER_COLOR_INT_OPAQUE_BLACK;
samplerCreateInfo.unnormalizedCoordinates = VK_FALSE;
samplerCreateInfo.compareEnable = VK_FALSE;
samplerCreateInfo.compareOp = VK_COMPARE_OP_ALWAYS;
samplerCreateInfo.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR;
samplerCreateInfo.mipLodBias = 0.0f;
samplerCreateInfo.minLod = 0.0f;
samplerCreateInfo.maxLod = 0.0f;
return samplerCreateInfo;
}
VkImageViewCreateInfo init::ImageViewCreateInfo()
{
VkImageViewCreateInfo imageViewCreateInfo = {};
imageViewCreateInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
imageViewCreateInfo.pNext = NULL;
return imageViewCreateInfo;
}
VkSemaphoreCreateInfo init::SemaphoreCreateInfo()
{
VkSemaphoreCreateInfo semaphoreCreateInfo = {};
semaphoreCreateInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
semaphoreCreateInfo.pNext = NULL;
semaphoreCreateInfo.flags = 0;
return semaphoreCreateInfo;
}
VkFenceCreateInfo init::FenceCreateInfo(VkFenceCreateFlags flags)
{
VkFenceCreateInfo fenceCreateInfo = {};
fenceCreateInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
fenceCreateInfo.flags = flags;
return fenceCreateInfo;
}
VkEventCreateInfo init::EventCreateInfo()
{
VkEventCreateInfo eventCreateInfo = {};
eventCreateInfo.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
return eventCreateInfo;
}
VkSubmitInfo init::SubmitInfo()
{
VkSubmitInfo submitInfo = {};
submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
submitInfo.pNext = NULL;
return submitInfo;
}
VkImageSubresourceRange init::ImageSubresourceRange(VkImageAspectFlags aspect, uint32_t startMip)
{
VkImageSubresourceRange range;
std::memset(&range, 0, sizeof(VkImageSubresourceRange));
range.aspectMask = aspect;
range.baseMipLevel = startMip;
range.levelCount = 1;
range.baseArrayLayer = 0;
range.layerCount = 1;
return range;
}
VkViewport init::Viewport(
float width,
float height,
float minDepth,
float maxDepth)
{
VkViewport viewport = {};
viewport.width = width;
viewport.height = height;
viewport.minDepth = minDepth;
viewport.maxDepth = maxDepth;
return viewport;
}
VkRect2D init::Rect2D(
int32_t width,
int32_t height,
int32_t offsetX,
int32_t offsetY)
{
VkRect2D rect2D = {};
rect2D.extent.width = width;
rect2D.extent.height = height;
rect2D.offset.x = offsetX;
rect2D.offset.y = offsetY;
return rect2D;
}
VkBufferCreateInfo init::BufferCreateInfo()
{
VkBufferCreateInfo bufCreateInfo = {};
bufCreateInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
return bufCreateInfo;
}
VkBufferCreateInfo init::BufferCreateInfo(
VkBufferUsageFlags usage,
VkDeviceSize size)
{
VkBufferCreateInfo bufCreateInfo = {};
bufCreateInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
bufCreateInfo.pNext = NULL;
bufCreateInfo.usage = usage;
bufCreateInfo.size = size;
bufCreateInfo.flags = 0;
return bufCreateInfo;
}
VkDescriptorPoolCreateInfo init::DescriptorPoolCreateInfo(
uint32_t poolSizeCount,
VkDescriptorPoolSize *pPoolSizes,
uint32_t maxSets)
{
VkDescriptorPoolCreateInfo descriptorPoolInfo = {};
descriptorPoolInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
descriptorPoolInfo.pNext = NULL;
descriptorPoolInfo.poolSizeCount = poolSizeCount;
descriptorPoolInfo.pPoolSizes = pPoolSizes;
descriptorPoolInfo.maxSets = maxSets;
return descriptorPoolInfo;
}
VkDescriptorPoolSize init::DescriptorPoolSize(
VkDescriptorType type,
uint32_t descriptorCount)
{
VkDescriptorPoolSize descriptorPoolSize = {};
descriptorPoolSize.type = type;
descriptorPoolSize.descriptorCount = descriptorCount;
return descriptorPoolSize;
}
VkDescriptorSetLayoutBinding init::DescriptorSetLayoutBinding(
VkDescriptorType type,
VkShaderStageFlags stageFlags,
uint32_t binding,
uint32_t count)
{
VkDescriptorSetLayoutBinding setLayoutBinding = {};
setLayoutBinding.descriptorType = type;
setLayoutBinding.stageFlags = stageFlags;
setLayoutBinding.binding = binding;
setLayoutBinding.descriptorCount = count;
return setLayoutBinding;
}
VkDescriptorSetLayoutCreateInfo init::DescriptorSetLayoutCreateInfo(
const VkDescriptorSetLayoutBinding *pBindings,
uint32_t bindingCount)
{
VkDescriptorSetLayoutCreateInfo descriptorSetLayoutCreateInfo = {};
descriptorSetLayoutCreateInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
descriptorSetLayoutCreateInfo.pNext = NULL;
descriptorSetLayoutCreateInfo.pBindings = pBindings;
descriptorSetLayoutCreateInfo.bindingCount = bindingCount;
return descriptorSetLayoutCreateInfo;
}
VkPipelineLayoutCreateInfo init::PipelineLayoutCreateInfo(
const VkDescriptorSetLayout *pSetLayouts,
uint32_t setLayoutCount)
{
VkPipelineLayoutCreateInfo pipelineLayoutCreateInfo = {};
pipelineLayoutCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
pipelineLayoutCreateInfo.pNext = NULL;
pipelineLayoutCreateInfo.setLayoutCount = setLayoutCount;
pipelineLayoutCreateInfo.pSetLayouts = pSetLayouts;
return pipelineLayoutCreateInfo;
}
VkDescriptorSetAllocateInfo init::DescriptorSetAllocateInfo(
VkDescriptorPool descriptorPool,
const VkDescriptorSetLayout *pSetLayouts,
uint32_t descriptorSetCount)
{
VkDescriptorSetAllocateInfo descriptorSetAllocateInfo = {};
descriptorSetAllocateInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
descriptorSetAllocateInfo.pNext = NULL;
descriptorSetAllocateInfo.descriptorPool = descriptorPool;
descriptorSetAllocateInfo.pSetLayouts = pSetLayouts;
descriptorSetAllocateInfo.descriptorSetCount = descriptorSetCount;
return descriptorSetAllocateInfo;
}
VkDescriptorBufferInfo init::DescriptorBufferInfo(VkBuffer buffer, VkDeviceSize offset, VkDeviceSize range)
{
VkDescriptorBufferInfo bufferInfo = {};
bufferInfo.buffer = buffer;
bufferInfo.offset = offset;
bufferInfo.range = range;
return bufferInfo;
}
VkDescriptorImageInfo init::DescriptorImageInfo(
VkSampler sampler,
VkImageView imageView,
VkImageLayout imageLayout)
{
VkDescriptorImageInfo descriptorImageInfo = {};
descriptorImageInfo.sampler = sampler;
descriptorImageInfo.imageView = imageView;
descriptorImageInfo.imageLayout = imageLayout;
return descriptorImageInfo;
}
VkWriteDescriptorSet init::WriteDescriptorSet(
VkDescriptorSet dstSet,
VkDescriptorType type,
uint32_t binding,
VkDescriptorBufferInfo *bufferInfo)
{
VkWriteDescriptorSet writeDescriptorSet = {};
writeDescriptorSet.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
writeDescriptorSet.pNext = NULL;
writeDescriptorSet.dstSet = dstSet;
writeDescriptorSet.descriptorType = type;
writeDescriptorSet.dstBinding = binding;
writeDescriptorSet.pBufferInfo = bufferInfo;
// Default value in all examples
writeDescriptorSet.descriptorCount = 1;
return writeDescriptorSet;
}
VkWriteDescriptorSet init::WriteDescriptorSet(
VkDescriptorSet dstSet,
VkDescriptorType type,
uint32_t binding,
VkDescriptorImageInfo *bufferInfo)
{
VkWriteDescriptorSet writeDescriptorSet = {};
writeDescriptorSet.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
writeDescriptorSet.pNext = NULL;
writeDescriptorSet.dstSet = dstSet;
writeDescriptorSet.descriptorType = type;
writeDescriptorSet.dstBinding = binding;
writeDescriptorSet.pImageInfo = bufferInfo;
// Default value in all examples
writeDescriptorSet.descriptorCount = 1;
return writeDescriptorSet;
}
VkVertexInputBindingDescription init::VertexInputBindingDescription(
uint32_t binding,
uint32_t stride,
VkVertexInputRate inputRate)
{
VkVertexInputBindingDescription vInputBindDescription = {};
vInputBindDescription.binding = binding;
vInputBindDescription.stride = stride;
vInputBindDescription.inputRate = inputRate;
return vInputBindDescription;
}
VkVertexInputAttributeDescription init::VertexInputAttributeDescription(
uint32_t binding,
uint32_t location,
VkFormat format,
uint32_t offset)
{
VkVertexInputAttributeDescription vInputAttribDescription = {};
vInputAttribDescription.location = location;
vInputAttribDescription.binding = binding;
vInputAttribDescription.format = format;
vInputAttribDescription.offset = offset;
return vInputAttribDescription;
}
VkPipelineVertexInputStateCreateInfo init::PipelineVertexInputStateCreateInfo()
{
VkPipelineVertexInputStateCreateInfo pipelineVertexInputStateCreateInfo = {};
pipelineVertexInputStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
pipelineVertexInputStateCreateInfo.pNext = NULL;
return pipelineVertexInputStateCreateInfo;
}
VkPipelineInputAssemblyStateCreateInfo init::PipelineInputAssemblyStateCreateInfo(
VkPrimitiveTopology topology,
VkPipelineInputAssemblyStateCreateFlags flags,
VkBool32 primitiveRestartEnable)
{
VkPipelineInputAssemblyStateCreateInfo pipelineInputAssemblyStateCreateInfo = {};
pipelineInputAssemblyStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
pipelineInputAssemblyStateCreateInfo.topology = topology;
pipelineInputAssemblyStateCreateInfo.flags = flags;
pipelineInputAssemblyStateCreateInfo.primitiveRestartEnable = primitiveRestartEnable;
return pipelineInputAssemblyStateCreateInfo;
}
VkPipelineRasterizationStateCreateInfo init::PipelineRasterizationStateCreateInfo(
VkPolygonMode polygonMode,
VkCullModeFlags cullMode,
VkFrontFace frontFace,
VkPipelineRasterizationStateCreateFlags flags)
{
VkPipelineRasterizationStateCreateInfo pipelineRasterizationStateCreateInfo = {};
pipelineRasterizationStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
pipelineRasterizationStateCreateInfo.polygonMode = polygonMode;
pipelineRasterizationStateCreateInfo.cullMode = cullMode;
pipelineRasterizationStateCreateInfo.frontFace = frontFace;
pipelineRasterizationStateCreateInfo.flags = flags;
pipelineRasterizationStateCreateInfo.depthClampEnable = VK_FALSE;
pipelineRasterizationStateCreateInfo.lineWidth = 1.0f;
return pipelineRasterizationStateCreateInfo;
}
VkPipelineColorBlendAttachmentState init::PipelineColorBlendAttachmentState(
VkColorComponentFlags colorWriteMask,
VkBool32 blendEnable)
{
VkPipelineColorBlendAttachmentState pipelineColorBlendAttachmentState = {};
pipelineColorBlendAttachmentState.colorWriteMask = colorWriteMask;
pipelineColorBlendAttachmentState.blendEnable = blendEnable;
return pipelineColorBlendAttachmentState;
}
VkPipelineColorBlendStateCreateInfo init::PipelineColorBlendStateCreateInfo(
uint32_t attachmentCount,
const VkPipelineColorBlendAttachmentState *pAttachments)
{
VkPipelineColorBlendStateCreateInfo pipelineColorBlendStateCreateInfo = {};
pipelineColorBlendStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
pipelineColorBlendStateCreateInfo.pNext = NULL;
pipelineColorBlendStateCreateInfo.attachmentCount = attachmentCount;
pipelineColorBlendStateCreateInfo.pAttachments = pAttachments;
return pipelineColorBlendStateCreateInfo;
}
VkPipelineDepthStencilStateCreateInfo init::PipelineDepthStencilStateCreateInfo(
VkBool32 depthTestEnable,
VkBool32 depthWriteEnable,
VkCompareOp depthCompareOp)
{
VkPipelineDepthStencilStateCreateInfo pipelineDepthStencilStateCreateInfo = {};
pipelineDepthStencilStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
pipelineDepthStencilStateCreateInfo.depthTestEnable = depthTestEnable;
pipelineDepthStencilStateCreateInfo.depthWriteEnable = depthWriteEnable;
pipelineDepthStencilStateCreateInfo.depthCompareOp = depthCompareOp;
pipelineDepthStencilStateCreateInfo.front = pipelineDepthStencilStateCreateInfo.back;
pipelineDepthStencilStateCreateInfo.back.compareOp = VK_COMPARE_OP_ALWAYS;
return pipelineDepthStencilStateCreateInfo;
}
VkPipelineViewportStateCreateInfo init::PipelineViewportStateCreateInfo(
uint32_t viewportCount,
uint32_t scissorCount,
VkPipelineViewportStateCreateFlags flags)
{
VkPipelineViewportStateCreateInfo pipelineViewportStateCreateInfo = {};
pipelineViewportStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
pipelineViewportStateCreateInfo.viewportCount = viewportCount;
pipelineViewportStateCreateInfo.scissorCount = scissorCount;
pipelineViewportStateCreateInfo.flags = flags;
return pipelineViewportStateCreateInfo;
}
VkPipelineMultisampleStateCreateInfo init::PipelineMultisampleStateCreateInfo(
VkSampleCountFlagBits rasterizationSamples,
VkPipelineMultisampleStateCreateFlags flags)
{
VkPipelineMultisampleStateCreateInfo pipelineMultisampleStateCreateInfo = {};
pipelineMultisampleStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
pipelineMultisampleStateCreateInfo.flags = flags;
pipelineMultisampleStateCreateInfo.rasterizationSamples = rasterizationSamples;
return pipelineMultisampleStateCreateInfo;
}
VkPipelineDynamicStateCreateInfo init::PipelineDynamicStateCreateInfo(
const VkDynamicState *pDynamicStates,
uint32_t dynamicStateCount,
VkPipelineDynamicStateCreateFlags flags)
{
VkPipelineDynamicStateCreateInfo pipelineDynamicStateCreateInfo = {};
pipelineDynamicStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
pipelineDynamicStateCreateInfo.flags = flags;
pipelineDynamicStateCreateInfo.pDynamicStates = pDynamicStates;
pipelineDynamicStateCreateInfo.dynamicStateCount = dynamicStateCount;
return pipelineDynamicStateCreateInfo;
}
VkPipelineTessellationStateCreateInfo init::PipelineTessellationStateCreateInfo(uint32_t patchControlPoints)
{
VkPipelineTessellationStateCreateInfo pipelineTessellationStateCreateInfo = {};
pipelineTessellationStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
pipelineTessellationStateCreateInfo.patchControlPoints = patchControlPoints;
return pipelineTessellationStateCreateInfo;
}
VkGraphicsPipelineCreateInfo init::PipelineCreateInfo(
VkPipelineLayout layout,
VkRenderPass renderPass,
VkPipelineCreateFlags flags)
{
VkGraphicsPipelineCreateInfo pipelineCreateInfo = {};
pipelineCreateInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
pipelineCreateInfo.pNext = NULL;
pipelineCreateInfo.layout = layout;
pipelineCreateInfo.renderPass = renderPass;
pipelineCreateInfo.flags = flags;
return pipelineCreateInfo;
}
VkComputePipelineCreateInfo init::ComputePipelineCreateInfo(VkPipelineLayout layout, VkPipelineCreateFlags flags)
{
VkComputePipelineCreateInfo computePipelineCreateInfo = {};
computePipelineCreateInfo.sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO;
computePipelineCreateInfo.layout = layout;
computePipelineCreateInfo.flags = flags;
return computePipelineCreateInfo;
}
VkPushConstantRange init::PushConstantRange(
VkShaderStageFlags stageFlags,
uint32_t size,
uint32_t offset)
{
VkPushConstantRange pushConstantRange = {};
pushConstantRange.stageFlags = stageFlags;
pushConstantRange.offset = offset;
pushConstantRange.size = size;
return pushConstantRange;
}
VkPipelineShaderStageCreateInfo init::PipelineShaderStageCreateInfo(VkShaderStageFlagBits stage, VkShaderModule module, const char *entryName)
{
VkPipelineShaderStageCreateInfo info = {};
info.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
info.module = module;
info.stage = stage;
info.pName = entryName;
return info;
}
VkBool32 Seele::Vulkan::debugCallback(VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT, uint64_t, size_t, int32_t, const char *layerPrefix, const char *msg, void *)
{
if(flags & VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT)
{
return VK_FALSE;
}
else
{
std::cerr << layerPrefix << ": " << msg << std::endl;
return VK_FALSE;
}
}
VkResult Seele::Vulkan::CreateDebugReportCallbackEXT(VkInstance instance, const VkDebugReportCallbackCreateInfoEXT *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkDebugReportCallbackEXT *pCallback)
{
auto func = (PFN_vkCreateDebugReportCallbackEXT)vkGetInstanceProcAddr(instance, "vkCreateDebugReportCallbackEXT");
if (func != nullptr)
{
return func(instance, pCreateInfo, pAllocator, pCallback);
}
else
{
return VK_ERROR_EXTENSION_NOT_PRESENT;
}
}
void Seele::Vulkan::DestroyDebugReportCallbackEXT(VkInstance instance, const VkAllocationCallbacks *pAllocator, VkDebugReportCallbackEXT pCallback)
{
auto func = (PFN_vkDestroyDebugReportCallbackEXT)vkGetInstanceProcAddr(instance, "vkDestroyDebugReportCallbackEXT");
if (func != nullptr)
{
func(instance, pCallback, pAllocator);
}
}
-302
View File
@@ -1,302 +0,0 @@
#pragma once
#include "Containers/Array.h"
#include <vulkan/vulkan.h>
namespace Seele
{
namespace Vulkan
{
VkBool32 debugCallback(VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT objType, uint64_t obj, size_t location, int32_t code, const char *layerPrefix, const char *msg, void *userData);
VkResult CreateDebugReportCallbackEXT(VkInstance instance, const VkDebugReportCallbackCreateInfoEXT *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkDebugReportCallbackEXT *pCallback);
void DestroyDebugReportCallbackEXT(VkInstance instance, const VkAllocationCallbacks *pAllocator, VkDebugReportCallbackEXT pCallback);
namespace init
{
VkApplicationInfo ApplicationInfo(
const char *appName,
uint32_t appVersion,
const char *engineName,
uint32_t engineVersion,
uint32_t apiVersion);
VkInstanceCreateInfo InstanceCreateInfo(
VkApplicationInfo *appInfo,
const Array<const char *> &extensions,
const Array<const char *> &layers);
VkDebugReportCallbackCreateInfoEXT DebugReportCallbackCreateInfo(
VkDebugReportFlagsEXT flags);
VkDeviceQueueCreateInfo DeviceQueueCreateInfo(
int queueFamilyIndex,
int queueCount);
VkDeviceQueueCreateInfo DeviceQueueCreateInfo(
int queueFamilyIndex,
int queueCount,
float *queuePriority);
VkDeviceCreateInfo DeviceCreateInfo(
VkDeviceQueueCreateInfo *queueInfos,
uint32_t queueCount,
VkPhysicalDeviceFeatures *features,
const char *const *deviceExtensions,
uint32_t deviceExtensionCount,
const char *const *layers,
uint32_t layerCount);
VkDeviceCreateInfo DeviceCreateInfo(
VkDeviceQueueCreateInfo *queueInfos,
uint32_t queueCount,
VkPhysicalDeviceFeatures *features);
VkSwapchainCreateInfoKHR SwapchainCreateInfo(
VkSurfaceKHR surface,
uint32_t minImageCount,
VkFormat imageFormat,
VkColorSpaceKHR colorSpace,
VkExtent2D extent,
uint32_t arrayLayers,
VkImageUsageFlags usage,
VkSurfaceTransformFlagBitsKHR Transform,
VkCompositeAlphaFlagBitsKHR alpha,
VkPresentModeKHR presentMode,
VkBool32 clipped);
VkSwapchainCreateInfoKHR SwapchainCreateInfo(
VkSurfaceKHR surface,
uint32_t minImageCount,
VkFormat imageFormat,
VkColorSpaceKHR colorSpace,
uint32_t width,
uint32_t height,
uint32_t arrayLayers,
VkImageUsageFlags usage,
VkSurfaceTransformFlagBitsKHR Transform,
VkCompositeAlphaFlagBitsKHR alpha,
VkPresentModeKHR presentMode,
VkBool32 clipped);
VkFramebufferCreateInfo FramebufferCreateInfo(
VkRenderPass renderPass,
uint32_t attachmentCount,
VkImageView *attachments,
uint32_t width,
uint32_t height,
uint32_t layers);
VkAttachmentDescription AttachmentDescription(
VkFormat format,
VkSampleCountFlagBits sample,
VkAttachmentLoadOp loadOp,
VkAttachmentStoreOp storeOp,
VkAttachmentLoadOp stencilLoadOp,
VkAttachmentStoreOp stencilStoreOp,
VkImageLayout imageLayout,
VkImageLayout finalLayout);
VkSubpassDescription SubpassDescription(
VkPipelineBindPoint bindPoint,
uint32_t colorAttachmentCount,
VkAttachmentReference *colorReference,
VkAttachmentReference *depthReference = nullptr,
uint32_t inputAttachmentCount = 0,
VkAttachmentReference *inputReference = nullptr,
VkAttachmentReference *resolveReference = nullptr,
uint32_t preserveAttachmentCount = 0,
uint32_t *preserveReference = nullptr);
VkRenderPassCreateInfo RenderPassCreateInfo(
uint32_t attachmentCount,
const VkAttachmentDescription *attachments,
uint32_t subpassCount,
const VkSubpassDescription *subpasses,
uint32_t dependencyCount,
const VkSubpassDependency *subpassDependencies);
VkMemoryAllocateInfo MemoryAllocateInfo();
VkCommandBufferAllocateInfo CommandBufferAllocateInfo(
VkCommandPool cmdPool,
VkCommandBufferLevel level,
uint32_t bufferCount);
VkCommandPoolCreateInfo CommandPoolCreateInfo();
VkCommandBufferBeginInfo CommandBufferBeginInfo();
VkCommandBufferInheritanceInfo CommandBufferInheritanceInfo();
VkRenderPassBeginInfo RenderPassBeginInfo();
VkRenderPassCreateInfo RenderPassCreateInfo();
VkImageMemoryBarrier ImageMemoryBarrier(VkImage image, VkImageLayout oldLayout, VkImageLayout newLayout, uint32_t srcQueue = VK_QUEUE_FAMILY_IGNORED, uint32_t dstQueue = VK_QUEUE_FAMILY_IGNORED);
VkImageMemoryBarrier ImageMemoryBarrier();
VkBufferMemoryBarrier BufferMemoryBarrier();
VkMemoryBarrier MemoryBarrier();
VkImageCreateInfo ImageCreateInfo();
VkSamplerCreateInfo SamplerCreateInfo();
VkImageViewCreateInfo ImageViewCreateInfo();
VkSemaphoreCreateInfo SemaphoreCreateInfo();
VkFenceCreateInfo FenceCreateInfo(
VkFenceCreateFlags flags);
VkEventCreateInfo EventCreateInfo();
VkSubmitInfo SubmitInfo();
VkImageSubresourceRange ImageSubresourceRange(
VkImageAspectFlags aspect = VK_IMAGE_ASPECT_COLOR_BIT,
uint32_t startMip = 0);
VkViewport Viewport(
float width,
float height,
float minDepth,
float maxDepth);
VkRect2D Rect2D(
int32_t width,
int32_t height,
int32_t offsetX,
int32_t offsetY);
VkBufferCreateInfo BufferCreateInfo();
VkBufferCreateInfo BufferCreateInfo(
VkBufferUsageFlags usage,
VkDeviceSize size);
VkDescriptorPoolCreateInfo DescriptorPoolCreateInfo(
uint32_t poolSizeCount,
VkDescriptorPoolSize *pPoolSizes,
uint32_t maxSets);
VkDescriptorPoolSize DescriptorPoolSize(
VkDescriptorType type,
uint32_t descriptorCount);
VkDescriptorSetLayoutBinding DescriptorSetLayoutBinding(
VkDescriptorType type,
VkShaderStageFlags stageFlags,
uint32_t binding,
uint32_t count);
VkDescriptorSetLayoutCreateInfo DescriptorSetLayoutCreateInfo(
const VkDescriptorSetLayoutBinding *pBindings,
uint32_t bindingCount);
VkPipelineLayoutCreateInfo PipelineLayoutCreateInfo(
const VkDescriptorSetLayout *pSetLayouts,
uint32_t setLayoutCount);
VkDescriptorSetAllocateInfo DescriptorSetAllocateInfo(
VkDescriptorPool descriptorPool,
const VkDescriptorSetLayout *pSetLayouts,
uint32_t descriptorSetCount);
VkDescriptorBufferInfo DescriptorBufferInfo(
VkBuffer buffer,
VkDeviceSize offset,
VkDeviceSize range);
VkDescriptorImageInfo DescriptorImageInfo(
VkSampler sampler,
VkImageView imageView,
VkImageLayout imageLayout);
VkWriteDescriptorSet WriteDescriptorSet(
VkDescriptorSet dstSet,
VkDescriptorType type,
uint32_t binding,
VkDescriptorBufferInfo *bufferInfo);
VkWriteDescriptorSet WriteDescriptorSet(
VkDescriptorSet dstSet,
VkDescriptorType type,
uint32_t binding,
VkDescriptorImageInfo *bufferInfo);
VkVertexInputBindingDescription VertexInputBindingDescription(
uint32_t binding,
uint32_t stride,
VkVertexInputRate inputRate);
VkVertexInputAttributeDescription VertexInputAttributeDescription(
uint32_t binding,
uint32_t location,
VkFormat format,
uint32_t offset);
VkPipelineVertexInputStateCreateInfo PipelineVertexInputStateCreateInfo();
VkPipelineInputAssemblyStateCreateInfo PipelineInputAssemblyStateCreateInfo(
VkPrimitiveTopology topology,
VkPipelineInputAssemblyStateCreateFlags flags,
VkBool32 primitiveRestartEnable);
VkPipelineRasterizationStateCreateInfo PipelineRasterizationStateCreateInfo(
VkPolygonMode polygonMode,
VkCullModeFlags cullMode,
VkFrontFace frontFace,
VkPipelineRasterizationStateCreateFlags flags);
VkPipelineColorBlendAttachmentState PipelineColorBlendAttachmentState(
VkColorComponentFlags colorWriteMask,
VkBool32 blendEnable);
VkPipelineColorBlendStateCreateInfo PipelineColorBlendStateCreateInfo(
uint32_t attachmentCount,
const VkPipelineColorBlendAttachmentState *pAttachments);
VkPipelineDepthStencilStateCreateInfo PipelineDepthStencilStateCreateInfo(
VkBool32 depthTestEnable,
VkBool32 depthWriteEnable,
VkCompareOp depthCompareOp);
VkPipelineViewportStateCreateInfo PipelineViewportStateCreateInfo(
uint32_t viewportCount,
uint32_t scissorCount,
VkPipelineViewportStateCreateFlags flags);
VkPipelineMultisampleStateCreateInfo PipelineMultisampleStateCreateInfo(
VkSampleCountFlagBits rasterizationSamples,
VkPipelineMultisampleStateCreateFlags flags);
VkPipelineDynamicStateCreateInfo PipelineDynamicStateCreateInfo(
const VkDynamicState *pDynamicStates,
uint32_t dynamicStateCount,
VkPipelineDynamicStateCreateFlags flags);
VkPipelineTessellationStateCreateInfo PipelineTessellationStateCreateInfo(
uint32_t patchControlPoints);
VkGraphicsPipelineCreateInfo PipelineCreateInfo(
VkPipelineLayout layout,
VkRenderPass renderPass,
VkPipelineCreateFlags flags);
VkComputePipelineCreateInfo ComputePipelineCreateInfo(
VkPipelineLayout layout,
VkPipelineCreateFlags flags);
VkPushConstantRange PushConstantRange(
VkShaderStageFlags stageFlags,
uint32_t size,
uint32_t offset);
VkPipelineShaderStageCreateInfo PipelineShaderStageCreateInfo(
VkShaderStageFlagBits stage,
VkShaderModule module,
const char *entryName);
} // namespace init
} // namespace Vulkan
} // namespace Seele
+1 -1
View File
@@ -1,5 +1,5 @@
#include "Pipeline.h" #include "Pipeline.h"
#include "DescriptorSets.h" #include "Descriptor.h"
#include "Graphics.h" #include "Graphics.h"
using namespace Seele; using namespace Seele;
+1 -1
View File
@@ -1,6 +1,6 @@
#pragma once #pragma once
#include "Enums.h" #include "Enums.h"
#include "Graphics/Resources.h" #include "Graphics/Pipeline.h"
namespace Seele namespace Seele
{ {
+148 -148
View File
@@ -1,9 +1,8 @@
#include "PipelineCache.h" #include "PipelineCache.h"
#include "Graphics.h" #include "Graphics.h"
#include "Enums.h" #include "Enums.h"
#include "Initializer.h"
#include "RenderPass.h" #include "RenderPass.h"
#include "DescriptorSets.h" #include "Descriptor.h"
#include "Shader.h" #include "Shader.h"
#include <fstream> #include <fstream>
@@ -15,11 +14,12 @@ PipelineCache::PipelineCache(PGraphics graphics, const std::string& cacheFilePat
, cacheFile(cacheFilePath) , cacheFile(cacheFilePath)
{ {
std::ifstream stream(cacheFilePath, std::ios::binary | std::ios::ate); std::ifstream stream(cacheFilePath, std::ios::binary | std::ios::ate);
VkPipelineCacheCreateInfo cacheCreateInfo; VkPipelineCacheCreateInfo cacheCreateInfo = {
cacheCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; .sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO,
cacheCreateInfo.pNext = nullptr; .pNext = nullptr,
cacheCreateInfo.flags = 0; .flags = 0,
cacheCreateInfo.initialDataSize = 0; .initialDataSize = 0,
};
if(stream.good()) if(stream.good())
{ {
Array<uint8> cacheData; Array<uint8> cacheData;
@@ -52,41 +52,11 @@ PGraphicsPipeline PipelineCache::createPipeline(Gfx::LegacyPipelineCreateInfo gf
{ {
PPipelineLayout layout = Gfx::PPipelineLayout(gfxInfo.pipelineLayout).cast<PipelineLayout>(); PPipelineLayout layout = Gfx::PPipelineLayout(gfxInfo.pipelineLayout).cast<PipelineLayout>();
uint32 hash = layout->getHash(); uint32 hash = layout->getHash();
VkPipelineVertexInputStateCreateInfo vertexInput = VkPipelineVertexInputStateCreateInfo vertexInput = {
init::PipelineVertexInputStateCreateInfo(); .sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,
.pNext = nullptr,
Array<VkVertexInputBindingDescription> bindings; .flags = 0,
Array<VkVertexInputAttributeDescription> attributes;
if (gfxInfo.vertexDeclaration != nullptr)
{
PVertexDeclaration decl = gfxInfo.vertexDeclaration.cast<VertexDeclaration>();
for (const auto& elem : decl->elementList)
{
attributes.add(VkVertexInputAttributeDescription{
.location = elem.attributeIndex,
.binding = elem.binding,
.format = cast(elem.vertexFormat),
.offset = elem.offset,
});
auto res = bindings.find([elem](const VkVertexInputBindingDescription& b) {return b.binding == elem.binding; });
if (res == bindings.end())
{
bindings.add({});
res = bindings.end();
}
*res = VkVertexInputBindingDescription{
.binding = elem.binding,
.stride = elem.stride,
.inputRate = elem.instanced ? VK_VERTEX_INPUT_RATE_INSTANCE : VK_VERTEX_INPUT_RATE_VERTEX,
}; };
}
vertexInput.pVertexAttributeDescriptions = attributes.data();
vertexInput.vertexAttributeDescriptionCount = attributes.size();
vertexInput.pVertexBindingDescriptions = bindings.data();
vertexInput.vertexBindingDescriptionCount = bindings.size();
}
hash = CRC::Calculate(bindings.data(), bindings.size() * sizeof(VkVertexInputBindingDescription), CRC::CRC_32(), hash);
hash = CRC::Calculate(attributes.data(), attributes.size() * sizeof(VkVertexInputAttributeDescription), CRC::CRC_32(), hash);
uint32 stageCount = 0; uint32 stageCount = 0;
VkPipelineShaderStageCreateInfo stageInfos[2]; VkPipelineShaderStageCreateInfo stageInfos[2];
@@ -112,52 +82,64 @@ PGraphicsPipeline PipelineCache::createPipeline(Gfx::LegacyPipelineCreateInfo gf
}; };
} }
hash = CRC::Calculate(stageInfos, sizeof(stageInfos), CRC::CRC_32(), hash); hash = CRC::Calculate(stageInfos, sizeof(stageInfos), CRC::CRC_32(), hash);
VkPipelineInputAssemblyStateCreateInfo assemblyInfo = VkPipelineInputAssemblyStateCreateInfo assemblyInfo = {
init::PipelineInputAssemblyStateCreateInfo( .sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
cast(gfxInfo.topology), .pNext = nullptr,
0, .flags = 0,
false .topology = cast(gfxInfo.topology),
); .primitiveRestartEnable = false,
};
hash = CRC::Calculate(&assemblyInfo, sizeof(assemblyInfo), CRC::CRC_32(), hash); hash = CRC::Calculate(&assemblyInfo, sizeof(assemblyInfo), CRC::CRC_32(), hash);
VkPipelineViewportStateCreateInfo viewportInfo = VkPipelineViewportStateCreateInfo viewportInfo = {
init::PipelineViewportStateCreateInfo( .sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO,
1, .pNext = nullptr,
1, .flags = 0,
0 .viewportCount = 1,
); .scissorCount = 1,
};
hash = CRC::Calculate(&viewportInfo, sizeof(viewportInfo), CRC::CRC_32(), hash); hash = CRC::Calculate(&viewportInfo, sizeof(viewportInfo), CRC::CRC_32(), hash);
VkPipelineRasterizationStateCreateInfo rasterizationState = VkPipelineRasterizationStateCreateInfo rasterizationState = {
init::PipelineRasterizationStateCreateInfo( .sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO,
cast(gfxInfo.rasterizationState.polygonMode), .pNext = nullptr,
gfxInfo.rasterizationState.cullMode, .flags = 0,
(VkFrontFace)gfxInfo.rasterizationState.frontFace, .depthClampEnable = gfxInfo.rasterizationState.depthClampEnable,
0 .rasterizerDiscardEnable = gfxInfo.rasterizationState.rasterizerDiscardEnable,
); .polygonMode = cast(gfxInfo.rasterizationState.polygonMode),
rasterizationState.depthBiasEnable = gfxInfo.rasterizationState.depthBiasEnable; .cullMode = gfxInfo.rasterizationState.cullMode,
rasterizationState.depthBiasClamp = gfxInfo.rasterizationState.depthBiasClamp; .frontFace = (VkFrontFace)gfxInfo.rasterizationState.frontFace,
rasterizationState.depthBiasConstantFactor = gfxInfo.rasterizationState.depthBiasConstantFactor; .depthBiasEnable = gfxInfo.rasterizationState.depthBiasEnable,
rasterizationState.depthBiasSlopeFactor = gfxInfo.rasterizationState.depthBiasSlopeFactor; .depthBiasConstantFactor = gfxInfo.rasterizationState.depthBiasConstantFactor,
rasterizationState.depthClampEnable = gfxInfo.rasterizationState.depthClampEnable; .depthBiasClamp = gfxInfo.rasterizationState.depthBiasClamp,
rasterizationState.lineWidth = gfxInfo.rasterizationState.lineWidth; .depthBiasSlopeFactor = gfxInfo.rasterizationState.depthBiasSlopeFactor,
rasterizationState.rasterizerDiscardEnable = gfxInfo.rasterizationState.rasterizerDiscardEnable; .lineWidth = 0,
};
hash = CRC::Calculate(&rasterizationState, sizeof(rasterizationState), CRC::CRC_32(), hash); hash = CRC::Calculate(&rasterizationState, sizeof(rasterizationState), CRC::CRC_32(), hash);
VkPipelineMultisampleStateCreateInfo multisampleState = VkPipelineMultisampleStateCreateInfo multisampleState = {
init::PipelineMultisampleStateCreateInfo( .sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO,
(VkSampleCountFlagBits)gfxInfo.multisampleState.samples, .pNext = nullptr,
0); .flags = 0,
multisampleState.alphaToCoverageEnable = gfxInfo.multisampleState.alphaCoverageEnable; .rasterizationSamples = (VkSampleCountFlagBits)gfxInfo.multisampleState.samples,
multisampleState.alphaToOneEnable = gfxInfo.multisampleState.alphaToOneEnable; .sampleShadingEnable = gfxInfo.multisampleState.sampleShadingEnable,
multisampleState.minSampleShading = gfxInfo.multisampleState.minSampleShading; .minSampleShading = gfxInfo.multisampleState.minSampleShading,
multisampleState.sampleShadingEnable = gfxInfo.multisampleState.sampleShadingEnable; .alphaToCoverageEnable = gfxInfo.multisampleState.alphaCoverageEnable,
.alphaToOneEnable = gfxInfo.multisampleState.alphaToOneEnable,
};
hash = CRC::Calculate(&multisampleState, sizeof(multisampleState), CRC::CRC_32(), hash); hash = CRC::Calculate(&multisampleState, sizeof(multisampleState), CRC::CRC_32(), hash);
VkPipelineDepthStencilStateCreateInfo depthStencilState = VkPipelineDepthStencilStateCreateInfo depthStencilState = {
init::PipelineDepthStencilStateCreateInfo( .sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO,
gfxInfo.depthStencilState.depthTestEnable, .pNext = nullptr,
gfxInfo.depthStencilState.depthWriteEnable, .flags = 0,
cast(gfxInfo.depthStencilState.depthCompareOp) .depthTestEnable = gfxInfo.depthStencilState.depthTestEnable,
); .depthWriteEnable = gfxInfo.depthStencilState.depthWriteEnable,
.depthCompareOp = cast(gfxInfo.depthStencilState.depthCompareOp),
.depthBoundsTestEnable = gfxInfo.depthStencilState.depthBoundsTestEnable,
.front = (VkStencilOp)gfxInfo.depthStencilState.front,
.back = (VkStencilOp)gfxInfo.depthStencilState.back,
.minDepthBounds = gfxInfo.depthStencilState.minDepthBounds,
.maxDepthBounds = gfxInfo.depthStencilState.maxDepthBounds,
};
hash = CRC::Calculate(&depthStencilState, sizeof(depthStencilState), CRC::CRC_32(), hash); hash = CRC::Calculate(&depthStencilState, sizeof(depthStencilState), CRC::CRC_32(), hash);
const auto& colorAttachments = gfxInfo.renderPass->getLayout()->colorAttachments; const auto& colorAttachments = gfxInfo.renderPass->getLayout()->colorAttachments;
@@ -178,14 +160,16 @@ PGraphicsPipeline PipelineCache::createPipeline(Gfx::LegacyPipelineCreateInfo gf
} }
hash = CRC::Calculate(blendAttachments.data(), blendAttachments.size() * sizeof(VkPipelineColorBlendAttachmentState), CRC::CRC_32(), hash); hash = CRC::Calculate(blendAttachments.data(), blendAttachments.size() * sizeof(VkPipelineColorBlendAttachmentState), CRC::CRC_32(), hash);
VkPipelineColorBlendStateCreateInfo blendState = VkPipelineColorBlendStateCreateInfo blendState = {
init::PipelineColorBlendStateCreateInfo( .sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO,
(uint32)blendAttachments.size(), .pNext = nullptr,
blendAttachments.data() .flags = 0,
); .logicOpEnable = gfxInfo.colorBlend.logicOpEnable,
blendState.logicOpEnable = gfxInfo.colorBlend.logicOpEnable; .logicOp = (VkLogicOp)gfxInfo.colorBlend.logicOp,
blendState.logicOp = (VkLogicOp)gfxInfo.colorBlend.logicOp; .attachmentCount = (uint32)blendAttachments.size(),
std::memcpy(blendState.blendConstants, gfxInfo.colorBlend.blendConstants, sizeof(gfxInfo.colorBlend.blendConstants)); .pAttachments = blendAttachments.data(),
};
std::memcpy(blendState.blendConstants, gfxInfo.colorBlend.blendConstants.data(), sizeof(blendState.blendConstants));
uint32 numDynamicEnabled = 0; uint32 numDynamicEnabled = 0;
StaticArray<VkDynamicState, 2> dynamicEnabled; StaticArray<VkDynamicState, 2> dynamicEnabled;
@@ -193,12 +177,12 @@ PGraphicsPipeline PipelineCache::createPipeline(Gfx::LegacyPipelineCreateInfo gf
dynamicEnabled[numDynamicEnabled++] = VK_DYNAMIC_STATE_SCISSOR; dynamicEnabled[numDynamicEnabled++] = VK_DYNAMIC_STATE_SCISSOR;
hash = CRC::Calculate(dynamicEnabled.data(), dynamicEnabled.size() * sizeof(VkDynamicState), CRC::CRC_32(), hash); hash = CRC::Calculate(dynamicEnabled.data(), dynamicEnabled.size() * sizeof(VkDynamicState), CRC::CRC_32(), hash);
VkPipelineDynamicStateCreateInfo dynamicState = VkPipelineDynamicStateCreateInfo dynamicState = {
init::PipelineDynamicStateCreateInfo( .sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO,
dynamicEnabled.data(), .pNext = nullptr,
numDynamicEnabled, .dynamicStateCount = (uint32)dynamicEnabled.size(),
0 .pDynamicStates = dynamicEnabled.data(),
); };
if (graphicsPipelines.contains(hash)) if (graphicsPipelines.contains(hash))
{ {
@@ -278,46 +262,56 @@ PGraphicsPipeline PipelineCache::createPipeline(Gfx::MeshPipelineCreateInfo gfxI
} }
hash = CRC::Calculate(stageInfos, sizeof(stageInfos), CRC::CRC_32(), hash); hash = CRC::Calculate(stageInfos, sizeof(stageInfos), CRC::CRC_32(), hash);
VkPipelineViewportStateCreateInfo viewportInfo = VkPipelineViewportStateCreateInfo viewportInfo = {
init::PipelineViewportStateCreateInfo( .sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO,
1, .pNext = nullptr,
1, .flags = 0,
0 .viewportCount = 1,
); .scissorCount = 1,
};
hash = CRC::Calculate(&viewportInfo, sizeof(viewportInfo), CRC::CRC_32(), hash); hash = CRC::Calculate(&viewportInfo, sizeof(viewportInfo), CRC::CRC_32(), hash);
VkPipelineRasterizationStateCreateInfo rasterizationState = {
VkPipelineRasterizationStateCreateInfo rasterizationState = .sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO,
init::PipelineRasterizationStateCreateInfo( .pNext = nullptr,
cast(gfxInfo.rasterizationState.polygonMode), .flags = 0,
gfxInfo.rasterizationState.cullMode, .depthClampEnable = gfxInfo.rasterizationState.depthClampEnable,
(VkFrontFace)gfxInfo.rasterizationState.frontFace, .rasterizerDiscardEnable = gfxInfo.rasterizationState.rasterizerDiscardEnable,
0 .polygonMode = cast(gfxInfo.rasterizationState.polygonMode),
); .cullMode = gfxInfo.rasterizationState.cullMode,
rasterizationState.depthBiasEnable = gfxInfo.rasterizationState.depthBiasEnable; .frontFace = (VkFrontFace)gfxInfo.rasterizationState.frontFace,
rasterizationState.depthBiasClamp = gfxInfo.rasterizationState.depthBiasClamp; .depthBiasEnable = gfxInfo.rasterizationState.depthBiasEnable,
rasterizationState.depthBiasConstantFactor = gfxInfo.rasterizationState.depthBiasConstantFactor; .depthBiasConstantFactor = gfxInfo.rasterizationState.depthBiasConstantFactor,
rasterizationState.depthBiasSlopeFactor = gfxInfo.rasterizationState.depthBiasSlopeFactor; .depthBiasClamp = gfxInfo.rasterizationState.depthBiasClamp,
rasterizationState.depthClampEnable = gfxInfo.rasterizationState.depthClampEnable; .depthBiasSlopeFactor = gfxInfo.rasterizationState.depthBiasSlopeFactor,
rasterizationState.lineWidth = gfxInfo.rasterizationState.lineWidth; .lineWidth = 0,
rasterizationState.rasterizerDiscardEnable = gfxInfo.rasterizationState.rasterizerDiscardEnable; };
hash = CRC::Calculate(&rasterizationState, sizeof(rasterizationState), CRC::CRC_32(), hash); hash = CRC::Calculate(&rasterizationState, sizeof(rasterizationState), CRC::CRC_32(), hash);
VkPipelineMultisampleStateCreateInfo multisampleState = VkPipelineMultisampleStateCreateInfo multisampleState = {
init::PipelineMultisampleStateCreateInfo( .sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO,
(VkSampleCountFlagBits)gfxInfo.multisampleState.samples, .pNext = nullptr,
0); .flags = 0,
multisampleState.alphaToCoverageEnable = gfxInfo.multisampleState.alphaCoverageEnable; .rasterizationSamples = (VkSampleCountFlagBits)gfxInfo.multisampleState.samples,
multisampleState.alphaToOneEnable = gfxInfo.multisampleState.alphaToOneEnable; .sampleShadingEnable = gfxInfo.multisampleState.sampleShadingEnable,
multisampleState.minSampleShading = gfxInfo.multisampleState.minSampleShading; .minSampleShading = gfxInfo.multisampleState.minSampleShading,
multisampleState.sampleShadingEnable = gfxInfo.multisampleState.sampleShadingEnable; .alphaToCoverageEnable = gfxInfo.multisampleState.alphaCoverageEnable,
.alphaToOneEnable = gfxInfo.multisampleState.alphaToOneEnable,
};
hash = CRC::Calculate(&multisampleState, sizeof(multisampleState), CRC::CRC_32(), hash); hash = CRC::Calculate(&multisampleState, sizeof(multisampleState), CRC::CRC_32(), hash);
VkPipelineDepthStencilStateCreateInfo depthStencilState = VkPipelineDepthStencilStateCreateInfo depthStencilState = {
init::PipelineDepthStencilStateCreateInfo( .sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO,
gfxInfo.depthStencilState.depthTestEnable, .pNext = nullptr,
gfxInfo.depthStencilState.depthWriteEnable, .flags = 0,
cast(gfxInfo.depthStencilState.depthCompareOp) .depthTestEnable = gfxInfo.depthStencilState.depthTestEnable,
); .depthWriteEnable = gfxInfo.depthStencilState.depthWriteEnable,
.depthCompareOp = cast(gfxInfo.depthStencilState.depthCompareOp),
.depthBoundsTestEnable = gfxInfo.depthStencilState.depthBoundsTestEnable,
.front = (VkStencilOp)gfxInfo.depthStencilState.front,
.back = (VkStencilOp)gfxInfo.depthStencilState.back,
.minDepthBounds = gfxInfo.depthStencilState.minDepthBounds,
.maxDepthBounds = gfxInfo.depthStencilState.maxDepthBounds,
};
hash = CRC::Calculate(&depthStencilState, sizeof(depthStencilState), CRC::CRC_32(), hash); hash = CRC::Calculate(&depthStencilState, sizeof(depthStencilState), CRC::CRC_32(), hash);
const auto& colorAttachments = gfxInfo.renderPass->getLayout()->colorAttachments; const auto& colorAttachments = gfxInfo.renderPass->getLayout()->colorAttachments;
@@ -338,14 +332,16 @@ PGraphicsPipeline PipelineCache::createPipeline(Gfx::MeshPipelineCreateInfo gfxI
} }
hash = CRC::Calculate(blendAttachments.data(), blendAttachments.size() * sizeof(VkPipelineColorBlendAttachmentState), CRC::CRC_32(), hash); hash = CRC::Calculate(blendAttachments.data(), blendAttachments.size() * sizeof(VkPipelineColorBlendAttachmentState), CRC::CRC_32(), hash);
VkPipelineColorBlendStateCreateInfo blendState = VkPipelineColorBlendStateCreateInfo blendState = {
init::PipelineColorBlendStateCreateInfo( .sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO,
(uint32)blendAttachments.size(), .pNext = nullptr,
blendAttachments.data() .flags = 0,
); .logicOpEnable = gfxInfo.colorBlend.logicOpEnable,
blendState.logicOpEnable = gfxInfo.colorBlend.logicOpEnable; .logicOp = (VkLogicOp)gfxInfo.colorBlend.logicOp,
blendState.logicOp = (VkLogicOp)gfxInfo.colorBlend.logicOp; .attachmentCount = (uint32)blendAttachments.size(),
std::memcpy(blendState.blendConstants, gfxInfo.colorBlend.blendConstants, sizeof(gfxInfo.colorBlend.blendConstants)); .pAttachments = blendAttachments.data(),
};
std::memcpy(blendState.blendConstants, gfxInfo.colorBlend.blendConstants.data(), sizeof(blendState.blendConstants));
uint32 numDynamicEnabled = 0; uint32 numDynamicEnabled = 0;
StaticArray<VkDynamicState, 2> dynamicEnabled; StaticArray<VkDynamicState, 2> dynamicEnabled;
@@ -353,12 +349,12 @@ PGraphicsPipeline PipelineCache::createPipeline(Gfx::MeshPipelineCreateInfo gfxI
dynamicEnabled[numDynamicEnabled++] = VK_DYNAMIC_STATE_SCISSOR; dynamicEnabled[numDynamicEnabled++] = VK_DYNAMIC_STATE_SCISSOR;
hash = CRC::Calculate(dynamicEnabled.data(), dynamicEnabled.size() * sizeof(VkDynamicState), CRC::CRC_32(), hash); hash = CRC::Calculate(dynamicEnabled.data(), dynamicEnabled.size() * sizeof(VkDynamicState), CRC::CRC_32(), hash);
VkPipelineDynamicStateCreateInfo dynamicState = VkPipelineDynamicStateCreateInfo dynamicState = {
init::PipelineDynamicStateCreateInfo( .sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO,
dynamicEnabled.data(), .pNext = nullptr,
numDynamicEnabled, .dynamicStateCount = (uint32)dynamicEnabled.size(),
0 .pDynamicStates = dynamicEnabled.data(),
); };
if (graphicsPipelines.contains(hash)) if (graphicsPipelines.contains(hash))
{ {
@@ -409,10 +405,14 @@ PComputePipeline PipelineCache::createPipeline(Gfx::ComputePipelineCreateInfo co
.sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO, .sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
.pNext = 0, .pNext = 0,
.flags = 0, .flags = 0,
.stage = init::PipelineShaderStageCreateInfo( .stage = {
VK_SHADER_STAGE_COMPUTE_BIT, .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
computeStage->getModuleHandle(), .pNext = nullptr,
computeStage->getEntryPointName()), .flags = 0,
.stage = VK_SHADER_STAGE_COMPUTE_BIT,
.module = computeStage->getModuleHandle(),
.pName = computeStage->getEntryPointName(),
},
.layout = layout->getHandle(), .layout = layout->getHandle(),
.basePipelineHandle = VK_NULL_HANDLE, .basePipelineHandle = VK_NULL_HANDLE,
.basePipelineIndex = 0, .basePipelineIndex = 0,
+25 -25
View File
@@ -1,8 +1,7 @@
#include "Queue.h" #include "Queue.h"
#include "Initializer.h"
#include "Graphics.h" #include "Graphics.h"
#include "Allocator.h" #include "Allocator.h"
#include "CommandBuffer.h" #include "Command.h"
using namespace Seele; using namespace Seele;
using namespace Seele::Vulkan; using namespace Seele::Vulkan;
@@ -19,45 +18,46 @@ Queue::~Queue()
{ {
} }
void Queue::submitCommandBuffer(PCmdBuffer cmdBuffer, uint32 numSignalSemaphores, VkSemaphore *signalSemaphores) void Queue::submitCommandBuffer(PCommand command, uint32 numSignalSemaphores, VkSemaphore *signalSemaphores)
{ {
std::scoped_lock lck(queueLock); std::unique_lock lock(queueLock);
assert(cmdBuffer->state == Command::State::End); assert(command->state == Command::State::End);
PFence fence = cmdBuffer->fence; PFence fence = command->fence;
assert(!fence->isSignaled()); assert(!fence->isSignaled());
const VkCommandBuffer cmdBuffers[] = {cmdBuffer->handle}; VkCommandBuffer cmdHandle = command->handle;
VkSubmitInfo submitInfo =
init::SubmitInfo();
submitInfo.commandBufferCount = 1;
submitInfo.pCommandBuffers = cmdBuffers;
submitInfo.signalSemaphoreCount = static_cast<uint32>(numSignalSemaphores);
submitInfo.pSignalSemaphores = signalSemaphores;
Array<VkSemaphore> waitSemaphores; Array<VkSemaphore> waitSemaphores;
if (cmdBuffer->waitSemaphores.size() > 0) if (command->waitSemaphores.size() > 0)
{ {
for (PSemaphore semaphore : cmdBuffer->waitSemaphores) for (PSemaphore semaphore : command->waitSemaphores)
{ {
waitSemaphores.add(semaphore->getHandle()); waitSemaphores.add(semaphore->getHandle());
} }
submitInfo.waitSemaphoreCount = static_cast<uint32>(cmdBuffer->waitSemaphores.size());
submitInfo.pWaitSemaphores = waitSemaphores.data();
submitInfo.pWaitDstStageMask = cmdBuffer->waitFlags.data();
} }
VkSubmitInfo submitInfo = {
.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO,
.pNext = nullptr,
.waitSemaphoreCount = static_cast<uint32>(command->waitSemaphores.size()),
.pWaitSemaphores = waitSemaphores.data(),
.pWaitDstStageMask = command->waitFlags.data(),
.commandBufferCount = 1,
.pCommandBuffers = &cmdHandle,
.signalSemaphoreCount = static_cast<uint32>(numSignalSemaphores),
.pSignalSemaphores = signalSemaphores,
};
VK_CHECK(vkQueueSubmit(queue, 1, &submitInfo, fence->getHandle())); VK_CHECK(vkQueueSubmit(queue, 1, &submitInfo, fence->getHandle()));
cmdBuffer->state = Command::State::Submit; command->state = Command::State::Submit;
cmdBuffer->waitFlags.clear(); command->waitFlags.clear();
cmdBuffer->waitSemaphores.clear(); command->waitSemaphores.clear();
if (Gfx::waitIdleOnSubmit) if (Gfx::waitIdleOnSubmit)
{ {
fence->wait(200 * 1000ull); fence->wait(200 * 1000ull);
} }
cmdBuffer->checkFence(); command->checkFence();
graphics->getStagingManager()->clearPending();
} }
+5 -5
View File
@@ -12,16 +12,16 @@ class Queue
public: public:
Queue(PGraphics graphics, Gfx::QueueType queueType, uint32 familyIndex, uint32 queueIndex); Queue(PGraphics graphics, Gfx::QueueType queueType, uint32 familyIndex, uint32 queueIndex);
virtual ~Queue(); virtual ~Queue();
void submitCommandBuffer(PCmdBuffer cmdBuffer, uint32 numSignalSemaphores = 0, VkSemaphore *signalSemaphore = nullptr); void submitCommandBuffer(PCommand command, uint32 numSignalSemaphores = 0, VkSemaphore *signalSemaphore = nullptr);
inline void submitCommandBuffer(PCmdBuffer cmdBuffer, VkSemaphore signalSemaphore) void submitCommandBuffer(PCommand command, VkSemaphore signalSemaphore)
{ {
submitCommandBuffer(cmdBuffer, 1, &signalSemaphore); submitCommandBuffer(command, 1, &signalSemaphore);
} }
uint32 getFamilyIndex() const constexpr uint32 getFamilyIndex() const
{ {
return familyIndex; return familyIndex;
} }
inline VkQueue getHandle() const constexpr VkQueue getHandle() const
{ {
return queue; return queue;
} }
+79 -78
View File
@@ -1,5 +1,4 @@
#include "RenderPass.h" #include "RenderPass.h"
#include "Initializer.h"
#include "Graphics.h" #include "Graphics.h"
#include "Framebuffer.h" #include "Framebuffer.h"
#include "Texture.h" #include "Texture.h"
@@ -25,107 +24,104 @@ RenderPass::RenderPass(PGraphics graphics, Gfx::ORenderTargetLayout _layout, Gfx
for (auto& inputAttachment : layout->inputAttachments) for (auto& inputAttachment : layout->inputAttachments)
{ {
PTexture2D image = inputAttachment->getTexture().cast<Texture2D>(); PTexture2D image = inputAttachment->getTexture().cast<Texture2D>();
VkAttachmentDescription& desc = attachments.add(); VkAttachmentDescription& desc = attachments.add() = {
desc.flags = 0; .flags = 0,
desc.format = cast(image->getFormat()); .format = cast(image->getFormat()),
desc.storeOp = cast(inputAttachment->getStoreOp()); .loadOp = cast(inputAttachment->getLoadOp()),
desc.loadOp = cast(inputAttachment->getLoadOp()); .storeOp = cast(inputAttachment->getStoreOp()),
desc.stencilStoreOp = cast(inputAttachment->getStencilStoreOp()); .stencilLoadOp = cast(inputAttachment->getStencilLoadOp()),
desc.stencilLoadOp = cast(inputAttachment->getStencilLoadOp()); .stencilStoreOp = cast(inputAttachment->getStencilStoreOp()),
desc.initialLayout = image->isDepthStencil() ? VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL : VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; .initialLayout = image->isDepthStencil() ? VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL : VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
desc.finalLayout = desc.initialLayout; .finalLayout = desc.initialLayout,
};
VkAttachmentReference &ref = inputRefs.add(); inputRefs.add() = {
ref.layout = desc.initialLayout; .attachment = attachmentCounter++,
ref.attachment = attachmentCounter; .layout = desc.initialLayout,
attachmentCounter++; };
} }
for (auto& colorAttachment : layout->colorAttachments) for (auto& colorAttachment : layout->colorAttachments)
{ {
VkAttachmentDescription& desc = attachments.add(); attachments.add() = {
desc.flags = 0; .flags = 0,
desc.samples = (VkSampleCountFlagBits)colorAttachment->getNumSamples(); .format = cast(colorAttachment->getFormat()),
desc.format = cast(colorAttachment->getFormat()); .samples = (VkSampleCountFlagBits)colorAttachment->getNumSamples(),
desc.storeOp = cast(colorAttachment->getStoreOp()); .loadOp = cast(colorAttachment->getLoadOp()),
desc.loadOp = cast(colorAttachment->getLoadOp()); .storeOp = cast(colorAttachment->getStoreOp()),
desc.stencilStoreOp = cast(colorAttachment->getStencilStoreOp()); .stencilLoadOp = cast(colorAttachment->getStencilLoadOp()),
desc.stencilLoadOp = cast(colorAttachment->getStencilLoadOp()); .stencilStoreOp = cast(colorAttachment->getStencilStoreOp()),
desc.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; .initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; .finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
};
VkClearValue& clearValue = clearValues.add(); VkClearValue& clearValue = clearValues.add();
if(desc.loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR) if(attachments.back().loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR)
{ {
clearValue = cast(colorAttachment->clear); clearValue = cast(colorAttachment->clear);
} }
VkAttachmentReference &ref = colorRefs.add(); colorRefs.add() = {
ref.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; .attachment = attachmentCounter++,
ref.attachment = attachmentCounter; .layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
attachmentCounter++; };
} }
if (layout->depthAttachment != nullptr) if (layout->depthAttachment != nullptr)
{ {
PTexture2D image = layout->depthAttachment->getTexture().cast<Texture2D>(); PTexture2D image = layout->depthAttachment->getTexture().cast<Texture2D>();
VkAttachmentDescription& desc = attachments.add(); attachments.add() = {
desc.flags = 0; .flags = 0,
desc.samples = (VkSampleCountFlagBits)image->getNumSamples(); .format = cast(image->getFormat()),
desc.format = cast(image->getFormat()); .samples = (VkSampleCountFlagBits)image->getNumSamples(),
desc.storeOp = cast(layout->depthAttachment->getStoreOp()); .loadOp = cast(layout->depthAttachment->getLoadOp()),
desc.loadOp = cast(layout->depthAttachment->getLoadOp()); .storeOp = cast(layout->depthAttachment->getStoreOp()),
desc.stencilStoreOp = cast(layout->depthAttachment->getStencilStoreOp()); .stencilLoadOp = cast(layout->depthAttachment->getStencilLoadOp()),
desc.stencilLoadOp = cast(layout->depthAttachment->getStencilLoadOp()); .stencilStoreOp = cast(layout->depthAttachment->getStencilStoreOp()),
desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; .initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; .finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
};
VkClearValue& clearValue = clearValues.add(); VkClearValue& clearValue = clearValues.add();
if(desc.loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR) if(attachments.back().loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR)
{ {
clearValue = cast(layout->depthAttachment->clear); clearValue = cast(layout->depthAttachment->clear);
} }
VkAttachmentReference &ref = depthRef; depthRef = {
ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; .attachment = attachmentCounter++,
ref.attachment = attachmentCounter; .layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
attachmentCounter++; };
} }
VkSubpassDescription subPassDesc = VkSubpassDescription subPassDesc = {
init::SubpassDescription( .flags = 0,
VK_PIPELINE_BIND_POINT_GRAPHICS, .pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS,
(uint32)colorRefs.size(), .inputAttachmentCount = (uint32)inputRefs.size(),
colorRefs.data(), .pInputAttachments = inputRefs.data(),
&depthRef, .colorAttachmentCount = (uint32)colorRefs.size(),
(uint32)inputRefs.size(), .pColorAttachments = colorRefs.data(),
inputRefs.data()); .pDepthStencilAttachment = &depthRef,
VkSubpassDependency dependency = {}; };
dependency.srcSubpass = VK_SUBPASS_EXTERNAL; VkSubpassDependency dependency = {
dependency.dstSubpass = 0; .srcSubpass = VK_SUBPASS_EXTERNAL,
.dstSubpass = 0,
.srcStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT,
.dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
.srcAccessMask = VK_ACCESS_MEMORY_READ_BIT,
.dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
};
dependency.srcStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT; VkRenderPassCreateInfo info = {
dependency.srcAccessMask = VK_ACCESS_MEMORY_READ_BIT; .sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
.pNext = nullptr,
dependency.dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT; .attachmentCount = (uint32)attachments.size(),
dependency.dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT; .pAttachments = attachments.data(),
.subpassCount = 1,
VkRenderPassCreateInfo info = .pSubpasses = &subPassDesc,
init::RenderPassCreateInfo( .dependencyCount = 1,
(uint32)attachments.size(), .pDependencies = &dependency,
attachments.data(), };
1,
&subPassDesc,
1,
&dependency);
VK_CHECK(vkCreateRenderPass(graphics->getDevice(), &info, nullptr, &renderPass)); VK_CHECK(vkCreateRenderPass(graphics->getDevice(), &info, nullptr, &renderPass));
}
RenderPass::~RenderPass()
{
vkDestroyRenderPass(graphics->getDevice(), renderPass, nullptr);
}
uint32 RenderPass::getFramebufferHash()
{
FramebufferDescription description; FramebufferDescription description;
std::memset(&description, 0, sizeof(FramebufferDescription)); std::memset(&description, 0, sizeof(FramebufferDescription));
for (auto& inputAttachment : layout->inputAttachments) for (auto& inputAttachment : layout->inputAttachments)
@@ -143,6 +139,11 @@ uint32 RenderPass::getFramebufferHash()
PTexture2D tex = layout->depthAttachment->getTexture().cast<Texture2D>(); PTexture2D tex = layout->depthAttachment->getTexture().cast<Texture2D>();
description.depthAttachment = tex->getView(); description.depthAttachment = tex->getView();
} }
return CRC::Calculate(&description, sizeof(FramebufferDescription), CRC::CRC_32()); framebufferHash = CRC::Calculate(&description, sizeof(FramebufferDescription), CRC::CRC_32());
}
RenderPass::~RenderPass()
{
vkDestroyRenderPass(graphics->getDevice(), renderPass, nullptr);
} }
+10 -6
View File
@@ -11,28 +11,32 @@ class RenderPass : public Gfx::RenderPass
public: public:
RenderPass(PGraphics graphics, Gfx::ORenderTargetLayout layout, Gfx::PViewport viewport); RenderPass(PGraphics graphics, Gfx::ORenderTargetLayout layout, Gfx::PViewport viewport);
virtual ~RenderPass(); virtual ~RenderPass();
uint32 getFramebufferHash(); constexpr uint32 getFramebufferHash() const
inline VkRenderPass getHandle() const {
return framebufferHash;
}
constexpr VkRenderPass getHandle() const
{ {
return renderPass; return renderPass;
} }
inline size_t getClearValueCount() const constexpr size_t getClearValueCount() const
{ {
return clearValues.size(); return clearValues.size();
} }
inline VkClearValue *getClearValues() const constexpr VkClearValue *getClearValues() const
{ {
return clearValues.data(); return clearValues.data();
} }
inline VkRect2D getRenderArea() const constexpr VkRect2D getRenderArea() const
{ {
return renderArea; return renderArea;
} }
inline VkSubpassContents getSubpassContents() const constexpr VkSubpassContents getSubpassContents() const
{ {
return subpassContents; return subpassContents;
} }
private: private:
uint32 framebufferHash;
PGraphics graphics; PGraphics graphics;
VkRenderPass renderPass; VkRenderPass renderPass;
Array<VkClearValue> clearValues; Array<VkClearValue> clearValues;
+42 -28
View File
@@ -1,9 +1,8 @@
#include "RenderTarget.h" #include "RenderTarget.h"
#include "Resources.h" #include "Resources.h"
#include "Graphics.h" #include "Graphics.h"
#include "Initializer.h"
#include "Enums.h" #include "Enums.h"
#include "CommandBuffer.h" #include "Command.h"
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
using namespace Seele; using namespace Seele;
@@ -184,11 +183,13 @@ void Window::advanceBackBuffer()
backBufferImages[currentImageIndex]->changeLayout(Gfx::SE_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); backBufferImages[currentImageIndex]->changeLayout(Gfx::SE_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
VkClearColorValue clearColor = {0.0f, 0.0f, 0.0f, 0.0f}; VkClearColorValue clearColor = {0.0f, 0.0f, 0.0f, 0.0f};
PCmdBuffer cmdBuffer = graphics->getGraphicsCommands()->getCommands(); PCommand command = graphics->getGraphicsCommands()->getCommands();
VkImageSubresourceRange range = init::ImageSubresourceRange(VK_IMAGE_ASPECT_COLOR_BIT); VkImageSubresourceRange range = {
.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
};
vkCmdClearColorImage( vkCmdClearColorImage(
cmdBuffer->getHandle(), command->getHandle(),
backBufferImages[currentImageIndex]->getHandle(), backBufferHandles[currentImageIndex],
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
&clearColor, &clearColor,
1, 1,
@@ -264,23 +265,26 @@ void Window::createSwapchain()
throw new std::logic_error("Trying to buffer more than the maximum number of frames"); throw new std::logic_error("Trying to buffer more than the maximum number of frames");
} }
VkExtent2D extent = { VkSwapchainCreateInfoKHR swapchainInfo = {
.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR,
.pNext = nullptr,
.flags = 0,
.surface = surface,
.minImageCount = desiredNumBuffers,
.imageFormat = surfaceFormat.format,
.imageColorSpace = surfaceFormat.colorSpace,
.imageExtent = {
.width = getWidth(), .width = getWidth(),
.height = getHeight(), .height = getHeight(),
},
.imageArrayLayers = 1,
.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE,
.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR,
.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR,
.presentMode = presentMode,
.clipped = VK_TRUE,
}; };
VkSwapchainCreateInfoKHR swapchainInfo =
init::SwapchainCreateInfo(
surface,
desiredNumBuffers,
surfaceFormat.format,
surfaceFormat.colorSpace,
extent,
1,
VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT,
VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR,
VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR,
presentMode,
VK_TRUE);
VK_CHECK(vkCreateSwapchainKHR(graphics->getDevice(), &swapchainInfo, nullptr, &swapchain)); VK_CHECK(vkCreateSwapchainKHR(graphics->getDevice(), &swapchainInfo, nullptr, &swapchain));
uint32 numSwapchainImages; uint32 numSwapchainImages;
@@ -289,24 +293,34 @@ void Window::createSwapchain()
VK_CHECK(vkGetSwapchainImagesKHR(graphics->getDevice(), swapchain, &numSwapchainImages, swapchainImages.data())); VK_CHECK(vkGetSwapchainImagesKHR(graphics->getDevice(), swapchain, &numSwapchainImages, swapchainImages.data()));
TextureCreateInfo backBufferCreateInfo; TextureCreateInfo backBufferCreateInfo = {
backBufferCreateInfo.width = getWidth(); .sourceData = {
backBufferCreateInfo.height = getHeight(); .owner = Gfx::QueueType::GRAPHICS,
backBufferCreateInfo.usage = Gfx::SE_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; },
backBufferCreateInfo.sourceData.owner = Gfx::QueueType::GRAPHICS; .format = cast(surfaceFormat.format),
backBufferCreateInfo.format = cast(surfaceFormat.format); .width = getWidth(),
.height = getHeight(),
.usage = Gfx::SE_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
};
for (uint32 i = 0; i < numSwapchainImages; ++i) for (uint32 i = 0; i < numSwapchainImages; ++i)
{ {
imageAcquired[i] = new Semaphore(graphics); imageAcquired[i] = new Semaphore(graphics);
renderFinished[i] = new Semaphore(graphics); renderFinished[i] = new Semaphore(graphics);
backBufferImages[i] = new Texture2D(graphics, backBufferCreateInfo, swapchainImages[i]); backBufferImages[i] = new Texture2D(graphics, backBufferCreateInfo, swapchainImages[i]);
backBufferHandles[i] = swapchainImages[i];
VkClearColorValue clearColor; VkClearColorValue clearColor;
std::memset(&clearColor, 0, sizeof(VkClearColorValue)); std::memset(&clearColor, 0, sizeof(VkClearColorValue));
backBufferImages[i]->changeLayout(Gfx::SE_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); backBufferImages[i]->changeLayout(Gfx::SE_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
VkImageSubresourceRange range = init::ImageSubresourceRange(VK_IMAGE_ASPECT_COLOR_BIT); VkImageSubresourceRange range = {
.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
.baseMipLevel = 0,
.levelCount = 1,
.baseArrayLayer = 0,
.layerCount = 1,
};
PCommand command = graphics->getGraphicsCommands()->getCommands(); PCommand command = graphics->getGraphicsCommands()->getCommands();
vkCmdClearColorImage(command->getHandle(), backBufferImages[i]->getHandle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &clearColor, 1, &range); vkCmdClearColorImage(command->getHandle(), backBufferHandles[i], VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &clearColor, 1, &range);
backBufferImages[i]->changeLayout(Gfx::SE_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL); backBufferImages[i]->changeLayout(Gfx::SE_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
} }
graphics->getGraphicsCommands()->submitCommands(); graphics->getGraphicsCommands()->submitCommands();
@@ -45,6 +45,7 @@ protected:
void choosePresentMode(const Array<VkPresentModeKHR> &modes); void choosePresentMode(const Array<VkPresentModeKHR> &modes);
OTexture2D backBufferImages[Gfx::numFramesBuffered]; OTexture2D backBufferImages[Gfx::numFramesBuffered];
VkImage backBufferHandles[Gfx::numFramesBuffered];
OSemaphore renderFinished[Gfx::numFramesBuffered]; OSemaphore renderFinished[Gfx::numFramesBuffered];
OSemaphore imageAcquired[Gfx::numFramesBuffered]; OSemaphore imageAcquired[Gfx::numFramesBuffered];
PSemaphore imageAcquiredSemaphore; PSemaphore imageAcquiredSemaphore;
+23 -14
View File
@@ -1,6 +1,5 @@
#include "Resources.h" #include "Resources.h"
#include "Enums.h" #include "Enums.h"
#include "Initializer.h"
#include "Graphics.h" #include "Graphics.h"
using namespace Seele; using namespace Seele;
@@ -79,14 +78,18 @@ void Fence::reset()
void Fence::wait(uint32 timeout) void Fence::wait(uint32 timeout)
{ {
VkFence fences[] = {fence}; VkFence fences[] = {fence};
VkResult res = vkWaitForFences(graphics->getDevice(), 1, fences, true, timeout); VkResult r = vkWaitForFences(graphics->getDevice(), 1, fences, true, timeout);
if (res == VK_SUCCESS) if (r == VK_SUCCESS)
{ {
signaled = true; signaled = true;
} }
if (res != VK_NOT_READY) else if (r == VK_TIMEOUT)
{ {
VK_CHECK(res); return;
}
else if (r != VK_NOT_READY)
{
VK_CHECK(r);
} }
} }
@@ -119,26 +122,32 @@ void DestructionManager::queueSemaphore(PCommand cmd, VkSemaphore sem)
sems[cmd].add(sem); sems[cmd].add(sem);
} }
void DestructionManager::notifyCmdComplete(PCommand cmdbuffer) void DestructionManager::queueAllocation(PCommand cmd, OSubAllocation alloc)
{ {
for(auto buf : buffers[cmdbuffer]) allocs[cmd].add(std::move(alloc));
}
void DestructionManager::notifyCmdComplete(PCommand cmd)
{
for(auto buf : buffers[cmd])
{ {
vkDestroyBuffer(graphics->getDevice(), buf, nullptr); vkDestroyBuffer(graphics->getDevice(), buf, nullptr);
} }
for(auto view : views[cmdbuffer]) for(auto view : views[cmd])
{ {
vkDestroyImageView(graphics->getDevice(), view, nullptr); vkDestroyImageView(graphics->getDevice(), view, nullptr);
} }
for(auto img : images[cmdbuffer]) for(auto img : images[cmd])
{ {
vkDestroyImage(graphics->getDevice(), img, nullptr); vkDestroyImage(graphics->getDevice(), img, nullptr);
} }
for (auto sem : sems[cmdbuffer]) for (auto sem : sems[cmd])
{ {
vkDestroySemaphore(graphics->getDevice(), sem, nullptr); vkDestroySemaphore(graphics->getDevice(), sem, nullptr);
} }
buffers[cmdbuffer].clear(); buffers[cmd].clear();
images[cmdbuffer].clear(); images[cmd].clear();
views[cmdbuffer].clear(); views[cmd].clear();
sems[cmdbuffer].clear(); sems[cmd].clear();
allocs[cmd].clear();
} }
+3 -1
View File
@@ -8,7 +8,7 @@ namespace Seele
{ {
namespace Vulkan namespace Vulkan
{ {
DECLARE_REF(DescriptorAllocator) DECLARE_REF(DescriptorPool)
DECLARE_REF(CommandPool) DECLARE_REF(CommandPool)
DECLARE_REF(Command) DECLARE_REF(Command)
DECLARE_REF(Graphics) DECLARE_REF(Graphics)
@@ -61,6 +61,7 @@ public:
void queueImage(PCommand cmd, VkImage image); void queueImage(PCommand cmd, VkImage image);
void queueImageView(PCommand cmd, VkImageView view); void queueImageView(PCommand cmd, VkImageView view);
void queueSemaphore(PCommand cmd, VkSemaphore sem); void queueSemaphore(PCommand cmd, VkSemaphore sem);
void queueAllocation(PCommand cmd, OSubAllocation alloc);
void notifyCmdComplete(PCommand cmdbuffer); void notifyCmdComplete(PCommand cmdbuffer);
private: private:
PGraphics graphics; PGraphics graphics;
@@ -68,6 +69,7 @@ private:
Map<PCommand, List<VkImage>> images; Map<PCommand, List<VkImage>> images;
Map<PCommand, List<VkImageView>> views; Map<PCommand, List<VkImageView>> views;
Map<PCommand, List<VkSemaphore>> sems; Map<PCommand, List<VkSemaphore>> sems;
Map<PCommand, List<OSubAllocation>> allocs;
}; };
DEFINE_REF(DestructionManager) DEFINE_REF(DestructionManager)
+179 -159
View File
@@ -1,6 +1,5 @@
#include "Texture.h" #include "Texture.h"
#include "Initializer.h" #include "Command.h"
#include "CommandBuffer.h"
#include <math.h> #include <math.h>
using namespace Seele; using namespace Seele;
@@ -26,15 +25,15 @@ VkImageAspectFlags getAspectFromFormat(Gfx::SeFormat format)
} }
} }
TextureHandle::TextureHandle(PGraphics graphics, VkImageViewType viewType, TextureBase::TextureBase(PGraphics graphics, VkImageViewType viewType,
const TextureCreateInfo& createInfo, Gfx::QueueType& owner, VkImage existingImage) const TextureCreateInfo& createInfo, Gfx::QueueType& owner, VkImage existingImage)
: currentOwner(owner) : currentOwner(owner)
, graphics(graphics) , graphics(graphics)
, sizeX(createInfo.width) , width(createInfo.width)
, sizeY(createInfo.height) , height(createInfo.height)
, sizeZ(createInfo.depth) , depth(createInfo.depth)
, arrayCount(createInfo.bArray ? createInfo.arrayLayers : 1) , arrayCount(createInfo.elements)
, layerCount(1) , layerCount(createInfo.layers)
, mipLevels(createInfo.mipLevels) , mipLevels(createInfo.mipLevels)
, samples(createInfo.samples) , samples(createInfo.samples)
, format(createInfo.format) , format(createInfo.format)
@@ -45,64 +44,73 @@ TextureHandle::TextureHandle(PGraphics graphics, VkImageViewType viewType,
{ {
if (existingImage == VK_NULL_HANDLE) if (existingImage == VK_NULL_HANDLE)
{ {
PAllocator allocator = graphics->getAllocator(); PAllocator pool = graphics->getAllocator();
VkImageCreateInfo info = VkImageType type = VK_IMAGE_TYPE_MAX_ENUM;
init::ImageCreateInfo(); VkImageCreateFlags flags = 0;
info.extent.width = sizeX;
info.extent.height = sizeY;
info.extent.depth = sizeZ;
info.format = cast(format);
switch (viewType) switch (viewType)
{ {
case VK_IMAGE_VIEW_TYPE_1D: case VK_IMAGE_VIEW_TYPE_1D:
case VK_IMAGE_VIEW_TYPE_1D_ARRAY: case VK_IMAGE_VIEW_TYPE_1D_ARRAY:
info.imageType = VK_IMAGE_TYPE_1D; type = VK_IMAGE_TYPE_1D;
break; break;
case VK_IMAGE_VIEW_TYPE_2D: case VK_IMAGE_VIEW_TYPE_2D:
case VK_IMAGE_VIEW_TYPE_2D_ARRAY: case VK_IMAGE_VIEW_TYPE_2D_ARRAY:
info.imageType = VK_IMAGE_TYPE_2D; type = VK_IMAGE_TYPE_2D;
break; break;
case VK_IMAGE_VIEW_TYPE_3D: case VK_IMAGE_VIEW_TYPE_3D:
info.imageType = VK_IMAGE_TYPE_3D; type = VK_IMAGE_TYPE_3D;
break; break;
case VK_IMAGE_VIEW_TYPE_CUBE: case VK_IMAGE_VIEW_TYPE_CUBE:
case VK_IMAGE_VIEW_TYPE_CUBE_ARRAY: case VK_IMAGE_VIEW_TYPE_CUBE_ARRAY:
info.flags = VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT; type = VK_IMAGE_TYPE_2D;
info.imageType = VK_IMAGE_TYPE_2D; flags = VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT;
layerCount = 6 * arrayCount; layerCount = 6 * arrayCount;
break; break;
default: default:
break; break;
} }
VkImageCreateInfo info = {
.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
.pNext = nullptr,
.flags = flags,
.imageType = type,
.format = cast(format),
.extent = {
.width = width,
.height = height,
.depth = depth,
},
.mipLevels = mipLevels,
.arrayLayers = arrayCount * layerCount,
.samples = (VkSampleCountFlagBits)samples,
.tiling = VK_IMAGE_TILING_OPTIMAL,
.usage = usage
| VK_IMAGE_USAGE_TRANSFER_DST_BIT
| VK_IMAGE_USAGE_TRANSFER_SRC_BIT
| VK_IMAGE_USAGE_SAMPLED_BIT,
.sharingMode = VK_SHARING_MODE_EXCLUSIVE,
.initialLayout = cast(layout),
};
info.initialLayout = cast(layout);
info.mipLevels = mipLevels;
info.arrayLayers = arrayCount * layerCount;
info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
info.samples = (VkSampleCountFlagBits)samples;
info.tiling = VK_IMAGE_TILING_OPTIMAL;
info.usage = usage;
// Most of these flags will almost always be used
info.usage |= VK_IMAGE_USAGE_TRANSFER_DST_BIT;
info.usage |= VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
info.usage |= VK_IMAGE_USAGE_SAMPLED_BIT;
VK_CHECK(vkCreateImage(graphics->getDevice(), &info, nullptr, &image)); VK_CHECK(vkCreateImage(graphics->getDevice(), &info, nullptr, &image));
VkMemoryDedicatedRequirements memDedicatedRequirements; VkMemoryDedicatedRequirements memDedicatedRequirements = {
memDedicatedRequirements.sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS; .sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS,
memDedicatedRequirements.pNext = nullptr; .pNext = nullptr,
VkImageMemoryRequirementsInfo2 reqInfo; };
reqInfo.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_REQUIREMENTS_INFO_2; VkImageMemoryRequirementsInfo2 reqInfo = {
reqInfo.pNext = nullptr; .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_REQUIREMENTS_INFO_2,
reqInfo.image = image; .pNext = nullptr,
VkMemoryRequirements2 requirements; .image = image,
requirements.sType = VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2; };
requirements.pNext = &memDedicatedRequirements; VkMemoryRequirements2 requirements = {
.sType = VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2,
.pNext = &memDedicatedRequirements,
};
vkGetImageMemoryRequirements2(graphics->getDevice(), &reqInfo, &requirements); vkGetImageMemoryRequirements2(graphics->getDevice(), &reqInfo, &requirements);
allocation = allocator->allocate(requirements, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, image); allocation = pool->allocate(requirements, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, image);
vkBindImageMemory(graphics->getDevice(), image, allocation->getHandle(), allocation->getOffset()); vkBindImageMemory(graphics->getDevice(), image, allocation->getHandle(), allocation->getOffset());
} }
@@ -110,31 +118,39 @@ TextureHandle::TextureHandle(PGraphics graphics, VkImageViewType viewType,
if(sourceData.size > 0) if(sourceData.size > 0)
{ {
changeLayout(Gfx::SE_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); changeLayout(Gfx::SE_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
OStagingBuffer staging = graphics->getStagingManager()->create(sourceData.size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT); OStagingBuffer staging = graphics->getStagingManager()->create(sourceData.size);
void* data = staging->map(); void* data = staging->map();
std::memcpy(data, sourceData.data, sourceData.size); std::memcpy(data, sourceData.data, sourceData.size);
staging->flush(); staging->flush();
PCommandBufferManager cmdBufferManager = graphics->getQueueCommands(currentOwner); PCommandPool commandPool = graphics->getQueueCommands(currentOwner);
VkBufferImageCopy region; VkBufferImageCopy region = {
region.bufferOffset = 0; .bufferOffset = 0,
region.bufferRowLength = 0; .bufferRowLength = 0,
region.bufferImageHeight = 0; .bufferImageHeight = 0,
.imageSubresource = {
.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
.mipLevel = 0,
.baseArrayLayer = 0,
.layerCount = arrayCount * layerCount,
},
.imageOffset = {
.x = 0,
.y = 0,
.z = 0,
},
.imageExtent = {
.width = width,
.height = height,
.depth = depth
},
};
region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; vkCmdCopyBufferToImage(commandPool->getCommands()->getHandle(),
region.imageSubresource.mipLevel = 0;
region.imageSubresource.baseArrayLayer = 0;
region.imageSubresource.layerCount = arrayCount * layerCount;
region.imageOffset = {0, 0, 0};
region.imageExtent = {sizeX, sizeY, sizeZ};
vkCmdCopyBufferToImage(cmdBufferManager->getCommands()->getHandle(),
staging->getHandle(), image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region); staging->getHandle(), image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
// When loading a texture from a file, we will almost always use it as a texture map for fragment shaders // When loading a texture from a file, we will almost always use it as a texture map for fragment shaders
changeLayout(Gfx::SE_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); changeLayout(Gfx::SE_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
graphics->getStagingManager()->release(std::move(staging));
} }
else if(usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) else if(usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT)
{ {
@@ -145,74 +161,62 @@ TextureHandle::TextureHandle(PGraphics graphics, VkImageViewType viewType,
changeLayout(Gfx::SE_IMAGE_LAYOUT_GENERAL); changeLayout(Gfx::SE_IMAGE_LAYOUT_GENERAL);
} }
VkImageViewCreateInfo viewInfo = VkImageViewCreateInfo viewInfo = {
init::ImageViewCreateInfo(); .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
viewInfo.subresourceRange = init::ImageSubresourceRange(aspect); .pNext = nullptr,
viewInfo.viewType = viewType; .flags = 0,
viewInfo.image = image; .image = image,
viewInfo.format = cast(format); .viewType = viewType,
viewInfo.subresourceRange.layerCount = layerCount; .format = cast(format),
viewInfo.subresourceRange.levelCount = mipLevels; .subresourceRange = {
.aspectMask = aspect,
.levelCount = mipLevels,
.layerCount = layerCount,
},
};
VK_CHECK(vkCreateImageView(graphics->getDevice(), &viewInfo, nullptr, &defaultView)); VK_CHECK(vkCreateImageView(graphics->getDevice(), &viewInfo, nullptr, &defaultView));
} }
TextureHandle::~TextureHandle() TextureBase::~TextureBase()
{ {
graphics->getDestructionManager()->queueImage(graphics->getQueueCommands(currentOwner)->getCommands(), image); graphics->getDestructionManager()->queueImage(graphics->getQueueCommands(currentOwner)->getCommands(), image);
graphics->getDestructionManager()->queueImageView(graphics->getQueueCommands(currentOwner)->getCommands(), defaultView); graphics->getDestructionManager()->queueImageView(graphics->getQueueCommands(currentOwner)->getCommands(), defaultView);
} }
TextureHandle* TextureBase::cast(Gfx::PTexture texture)
{
if(texture == nullptr)
{
return nullptr;
}
if(texture->getTexture2D() != nullptr)
{
PTexture2D texture2D = texture.cast<Texture2D>();
return texture2D->textureHandle;
}
if(texture->getTexture3D() != nullptr)
{
PTexture3D texture3D = texture.cast<Texture3D>();
return texture3D->textureHandle;
}
if(texture->getTextureCube() != nullptr)
{
PTextureCube textureCube = texture.cast<TextureCube>();
return textureCube->textureHandle;
}
return nullptr;
}
void TextureHandle::changeLayout(Gfx::SeImageLayout newLayout) void TextureBase::changeLayout(Gfx::SeImageLayout newLayout)
{ {
VkImageMemoryBarrier barrier = VkImageMemoryBarrier barrier = {
init::ImageMemoryBarrier( .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
image, .pNext = nullptr,
cast(layout), .oldLayout = cast(layout),
cast(newLayout)); .newLayout = cast(newLayout),
barrier.subresourceRange = .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
init::ImageSubresourceRange(aspect); .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
barrier.subresourceRange.layerCount = layerCount; .image = image,
PCommandBufferManager cmdManager = graphics->getQueueCommands(currentOwner); .subresourceRange = {
vkCmdPipelineBarrier(cmdManager->getCommands()->getHandle(), .aspectMask = aspect,
.levelCount = 1,
.layerCount = layerCount,
},
};
PCommandPool commandPool = graphics->getQueueCommands(currentOwner);
vkCmdPipelineBarrier(commandPool->getCommands()->getHandle(),
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
0, 0, nullptr, 0, nullptr, 1, &barrier); 0, 0, nullptr, 0, nullptr, 1, &barrier);
cmdManager->submitCommands(); commandPool->submitCommands();
layout = newLayout; layout = newLayout;
} }
void TextureHandle::download(uint32 mipLevel, uint32 arrayLayer, uint32 face, Array<uint8>& buffer) void TextureBase::download(uint32 mipLevel, uint32 arrayLayer, uint32 face, Array<uint8>& buffer)
{ {
uint64 imageSize = sizeX * sizeY * sizeZ * Gfx::getFormatInfo(format).blockSize; uint64 imageSize = width * height * depth * Gfx::getFormatInfo(format).blockSize;
OStagingBuffer stagingbuffer = graphics->getStagingManager()->create(imageSize, VK_BUFFER_USAGE_TRANSFER_DST_BIT, true); OStagingBuffer stagingbuffer = graphics->getStagingManager()->create(imageSize);
auto prevlayout = layout; auto prevlayout = layout;
changeLayout(Gfx::SE_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL); changeLayout(Gfx::SE_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
PCmdBuffer cmdBuffer = graphics->getQueueCommands(currentOwner)->getCommands(); PCommand cmdBuffer = graphics->getQueueCommands(currentOwner)->getCommands();
//Gfx::FormatCompatibilityInfo formatInfo = Gfx::getFormatInfo(format); //Gfx::FormatCompatibilityInfo formatInfo = Gfx::getFormatInfo(format);
VkBufferImageCopy region = { VkBufferImageCopy region = {
.bufferOffset = 0, .bufferOffset = 0,
@@ -224,32 +228,43 @@ void TextureHandle::download(uint32 mipLevel, uint32 arrayLayer, uint32 face, Ar
.baseArrayLayer = arrayLayer * layerCount + face, .baseArrayLayer = arrayLayer * layerCount + face,
.layerCount = 1, .layerCount = 1,
}, },
.imageOffset = { 0, 0, 0 }, .imageOffset = {
.imageExtent = { sizeX, sizeY, sizeZ }, .x = 0,
.y = 0,
.z = 0,
},
.imageExtent = {
.width = width,
.height = height,
.depth = depth
},
}; };
vkCmdCopyImageToBuffer(cmdBuffer->getHandle(), image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, stagingbuffer->getHandle(), 1, &region); vkCmdCopyImageToBuffer(cmdBuffer->getHandle(), image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, stagingbuffer->getHandle(), 1, &region);
changeLayout(prevlayout); changeLayout(prevlayout);
buffer.resize(stagingbuffer->getSize()); buffer.resize(stagingbuffer->getSize());
void* data = stagingbuffer->map(); void* data = stagingbuffer->map();
std::memcpy(buffer.data(), data, buffer.size()); std::memcpy(buffer.data(), data, buffer.size());
graphics->getStagingManager()->release(std::move(stagingbuffer));
} }
void TextureHandle::executeOwnershipBarrier(Gfx::QueueType newOwner) void TextureBase::executeOwnershipBarrier(Gfx::QueueType newOwner)
{ {
VkImageMemoryBarrier imageBarrier = Gfx::QueueFamilyMapping mapping = graphics->getFamilyMapping();
init::ImageMemoryBarrier(); VkImageMemoryBarrier imageBarrier = {
imageBarrier.image = image; .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
imageBarrier.oldLayout = cast(layout); .pNext = nullptr,
imageBarrier.newLayout = cast(layout); .oldLayout = cast(layout),
imageBarrier.subresourceRange = init::ImageSubresourceRange(aspect); .newLayout = cast(layout),
PCommandBufferManager sourceManager = graphics->getQueueCommands(currentOwner); .srcQueueFamilyIndex = mapping.getQueueTypeFamilyIndex(currentOwner),
PCommandBufferManager dstManager = nullptr; .dstQueueFamilyIndex = mapping.getQueueTypeFamilyIndex(newOwner),
.image = image,
.subresourceRange = {
.aspectMask = aspect,
},
};
PCommandPool sourcePool = graphics->getQueueCommands(currentOwner);
PCommandPool dstPool = nullptr;
VkPipelineStageFlags srcStage = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT; VkPipelineStageFlags srcStage = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
VkPipelineStageFlags dstStage = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; VkPipelineStageFlags dstStage = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
Gfx::QueueFamilyMapping mapping = graphics->getFamilyMapping();
imageBarrier.srcQueueFamilyIndex = mapping.getQueueTypeFamilyIndex(currentOwner);
imageBarrier.dstQueueFamilyIndex = mapping.getQueueTypeFamilyIndex(newOwner);
if (currentOwner == Gfx::QueueType::TRANSFER || currentOwner == Gfx::QueueType::DEDICATED_TRANSFER) if (currentOwner == Gfx::QueueType::TRANSFER || currentOwner == Gfx::QueueType::DEDICATED_TRANSFER)
{ {
imageBarrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; imageBarrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
@@ -269,56 +284,61 @@ void TextureHandle::executeOwnershipBarrier(Gfx::QueueType newOwner)
{ {
imageBarrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT; imageBarrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT;
dstStage = VK_PIPELINE_STAGE_TRANSFER_BIT; dstStage = VK_PIPELINE_STAGE_TRANSFER_BIT;
dstManager = graphics->getTransferCommands(); dstPool = graphics->getTransferCommands();
} }
else if (newOwner == Gfx::QueueType::DEDICATED_TRANSFER) else if (newOwner == Gfx::QueueType::DEDICATED_TRANSFER)
{ {
imageBarrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT; imageBarrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT;
dstStage = VK_PIPELINE_STAGE_TRANSFER_BIT; dstStage = VK_PIPELINE_STAGE_TRANSFER_BIT;
dstManager = graphics->getDedicatedTransferCommands(); dstPool = graphics->getDedicatedTransferCommands();
} }
else if (newOwner == Gfx::QueueType::COMPUTE) else if (newOwner == Gfx::QueueType::COMPUTE)
{ {
imageBarrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT; imageBarrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
dstStage = VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT; dstStage = VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT;
dstManager = graphics->getComputeCommands(); dstPool = graphics->getComputeCommands();
} }
else if (newOwner == Gfx::QueueType::GRAPHICS) else if (newOwner == Gfx::QueueType::GRAPHICS)
{ {
imageBarrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT; imageBarrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
dstStage = VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT; dstStage = VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT;
dstManager = graphics->getGraphicsCommands(); dstPool = graphics->getGraphicsCommands();
} }
VkCommandBuffer sourceCmd = sourceManager->getCommands()->getHandle(); VkCommandBuffer sourceCmd = sourcePool->getCommands()->getHandle();
VkCommandBuffer destCmd = dstManager->getCommands()->getHandle(); VkCommandBuffer destCmd = dstPool->getCommands()->getHandle();
vkCmdPipelineBarrier(sourceCmd, srcStage, srcStage, 0, 0, nullptr, 0, nullptr, 1, &imageBarrier); vkCmdPipelineBarrier(sourceCmd, srcStage, srcStage, 0, 0, nullptr, 0, nullptr, 1, &imageBarrier);
vkCmdPipelineBarrier(destCmd, dstStage, dstStage, 0, 0, nullptr, 0, nullptr, 1, &imageBarrier); vkCmdPipelineBarrier(destCmd, dstStage, dstStage, 0, 0, nullptr, 0, nullptr, 1, &imageBarrier);
currentOwner = newOwner; currentOwner = newOwner;
sourceManager->submitCommands(); sourcePool->submitCommands();
} }
void TextureHandle::executePipelineBarrier(VkAccessFlags srcAccess, VkPipelineStageFlags srcStage, void TextureBase::executePipelineBarrier(VkAccessFlags srcAccess, VkPipelineStageFlags srcStage,
VkAccessFlags dstAccess, VkPipelineStageFlags dstStage) VkAccessFlags dstAccess, VkPipelineStageFlags dstStage)
{ {
VkImageMemoryBarrier imageBarrier = VkImageMemoryBarrier barrier = {
init::ImageMemoryBarrier( .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
image, .pNext = nullptr,
cast(layout), .srcAccessMask = srcAccess,
cast(layout) .dstAccessMask = dstAccess,
); .oldLayout = cast(layout),
imageBarrier.srcAccessMask = srcAccess; .newLayout = cast(layout),
imageBarrier.dstAccessMask = dstAccess; .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
imageBarrier.subresourceRange = init::ImageSubresourceRange(aspect); .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
PCmdBuffer cmdBuffer = graphics->getQueueCommands(currentOwner)->getCommands(); .image = image,
vkCmdPipelineBarrier(cmdBuffer->getHandle(), srcStage, dstStage, 0, 0, nullptr, 0, nullptr, 1, &imageBarrier); .subresourceRange = {
.aspectMask = aspect,
},
};
PCommand command = graphics->getQueueCommands(currentOwner)->getCommands();
vkCmdPipelineBarrier(command->getHandle(), srcStage, dstStage, 0, 0, nullptr, 0, nullptr, 1, &barrier);
} }
Texture2D::Texture2D(PGraphics graphics, const TextureCreateInfo& createInfo, VkImage existingImage) Texture2D::Texture2D(PGraphics graphics, const TextureCreateInfo& createInfo, VkImage existingImage)
: Gfx::Texture2D(graphics->getFamilyMapping(), createInfo.sourceData.owner) : Gfx::Texture2D(graphics->getFamilyMapping(), createInfo.sourceData.owner)
, TextureBase(graphics, createInfo.elements > 1 ? VK_IMAGE_VIEW_TYPE_2D_ARRAY : VK_IMAGE_VIEW_TYPE_2D,
createInfo, Gfx::Texture2D::currentOwner, existingImage)
{ {
textureHandle = new TextureHandle(graphics, createInfo.bArray ? VK_IMAGE_VIEW_TYPE_2D_ARRAY : VK_IMAGE_VIEW_TYPE_2D,
createInfo, currentOwner, existingImage);
} }
Texture2D::~Texture2D() Texture2D::~Texture2D()
@@ -327,30 +347,30 @@ Texture2D::~Texture2D()
void Texture2D::changeLayout(Gfx::SeImageLayout newLayout) void Texture2D::changeLayout(Gfx::SeImageLayout newLayout)
{ {
textureHandle->changeLayout(newLayout); TextureBase::changeLayout(newLayout);
} }
void Texture2D::download(uint32 mipLevel, uint32 arrayLayer, uint32 face, Array<uint8>& buffer) void Texture2D::download(uint32 mipLevel, uint32 arrayLayer, uint32 face, Array<uint8>& buffer)
{ {
textureHandle->download(mipLevel, arrayLayer, face, buffer); TextureBase::download(mipLevel, arrayLayer, face, buffer);
} }
void Texture2D::executeOwnershipBarrier(Gfx::QueueType newOwner) void Texture2D::executeOwnershipBarrier(Gfx::QueueType newOwner)
{ {
textureHandle->executeOwnershipBarrier(newOwner); TextureBase::executeOwnershipBarrier(newOwner);
} }
void Texture2D::executePipelineBarrier(VkAccessFlags srcAccess, VkPipelineStageFlags srcStage, void Texture2D::executePipelineBarrier(VkAccessFlags srcAccess, VkPipelineStageFlags srcStage,
VkAccessFlags dstAccess, VkPipelineStageFlags dstStage) VkAccessFlags dstAccess, VkPipelineStageFlags dstStage)
{ {
textureHandle->executePipelineBarrier(srcAccess, srcStage, dstAccess, dstStage); TextureBase::executePipelineBarrier(srcAccess, srcStage, dstAccess, dstStage);
} }
Texture3D::Texture3D(PGraphics graphics, const TextureCreateInfo& createInfo, VkImage existingImage) Texture3D::Texture3D(PGraphics graphics, const TextureCreateInfo& createInfo, VkImage existingImage)
: Gfx::Texture3D(graphics->getFamilyMapping(), createInfo.sourceData.owner) : Gfx::Texture3D(graphics->getFamilyMapping(), createInfo.sourceData.owner)
, TextureBase(graphics, VK_IMAGE_VIEW_TYPE_3D,
createInfo, Gfx::Texture3D::currentOwner, existingImage)
{ {
textureHandle = new TextureHandle(graphics, VK_IMAGE_VIEW_TYPE_3D,
createInfo, currentOwner, existingImage);
} }
Texture3D::~Texture3D() Texture3D::~Texture3D()
@@ -359,29 +379,29 @@ Texture3D::~Texture3D()
void Texture3D::changeLayout(Gfx::SeImageLayout newLayout) void Texture3D::changeLayout(Gfx::SeImageLayout newLayout)
{ {
textureHandle->changeLayout(newLayout); TextureBase::changeLayout(newLayout);
} }
void Texture3D::download(uint32 mipLevel, uint32 arrayLayer, uint32 face, Array<uint8>& buffer) void Texture3D::download(uint32 mipLevel, uint32 arrayLayer, uint32 face, Array<uint8>& buffer)
{ {
textureHandle->download(mipLevel, arrayLayer, face, buffer); TextureBase::download(mipLevel, arrayLayer, face, buffer);
} }
void Texture3D::executeOwnershipBarrier(Gfx::QueueType newOwner) void Texture3D::executeOwnershipBarrier(Gfx::QueueType newOwner)
{ {
textureHandle->executeOwnershipBarrier(newOwner); TextureBase::executeOwnershipBarrier(newOwner);
} }
void Texture3D::executePipelineBarrier(VkAccessFlags srcAccess, VkPipelineStageFlags srcStage, void Texture3D::executePipelineBarrier(VkAccessFlags srcAccess, VkPipelineStageFlags srcStage,
VkAccessFlags dstAccess, VkPipelineStageFlags dstStage) VkAccessFlags dstAccess, VkPipelineStageFlags dstStage)
{ {
textureHandle->executePipelineBarrier(srcAccess, srcStage, dstAccess, dstStage); TextureBase::executePipelineBarrier(srcAccess, srcStage, dstAccess, dstStage);
} }
TextureCube::TextureCube(PGraphics graphics, const TextureCreateInfo& createInfo, VkImage existingImage) TextureCube::TextureCube(PGraphics graphics, const TextureCreateInfo& createInfo, VkImage existingImage)
: Gfx::TextureCube(graphics->getFamilyMapping(), createInfo.sourceData.owner) : Gfx::TextureCube(graphics->getFamilyMapping(), createInfo.sourceData.owner)
, TextureBase(graphics, createInfo.elements > 1? VK_IMAGE_VIEW_TYPE_CUBE_ARRAY : VK_IMAGE_VIEW_TYPE_CUBE,
createInfo, Gfx::TextureCube::currentOwner, existingImage)
{ {
textureHandle = new TextureHandle(graphics, createInfo.bArray ? VK_IMAGE_VIEW_TYPE_CUBE_ARRAY : VK_IMAGE_VIEW_TYPE_CUBE,
createInfo, currentOwner, existingImage);
} }
TextureCube::~TextureCube() TextureCube::~TextureCube()
@@ -390,20 +410,20 @@ TextureCube::~TextureCube()
void TextureCube::changeLayout(Gfx::SeImageLayout newLayout) void TextureCube::changeLayout(Gfx::SeImageLayout newLayout)
{ {
textureHandle->changeLayout(newLayout); TextureBase::changeLayout(newLayout);
} }
void TextureCube::download(uint32 mipLevel, uint32 arrayLayer, uint32 face, Array<uint8>& buffer) void TextureCube::download(uint32 mipLevel, uint32 arrayLayer, uint32 face, Array<uint8>& buffer)
{ {
textureHandle->download(mipLevel, arrayLayer, face, buffer); TextureBase::download(mipLevel, arrayLayer, face, buffer);
} }
void TextureCube::executeOwnershipBarrier(Gfx::QueueType newOwner) void TextureCube::executeOwnershipBarrier(Gfx::QueueType newOwner)
{ {
textureHandle->executeOwnershipBarrier(newOwner); TextureBase::executeOwnershipBarrier(newOwner);
} }
void TextureCube::executePipelineBarrier(VkAccessFlags srcAccess, VkPipelineStageFlags srcStage, void TextureCube::executePipelineBarrier(VkAccessFlags srcAccess, VkPipelineStageFlags srcStage,
VkAccessFlags dstAccess, VkPipelineStageFlags dstStage) VkAccessFlags dstAccess, VkPipelineStageFlags dstStage)
{ {
textureHandle->executePipelineBarrier(srcAccess, srcStage, dstAccess, dstStage); TextureBase::executePipelineBarrier(srcAccess, srcStage, dstAccess, dstStage);
} }
+36 -98
View File
@@ -8,46 +8,46 @@ namespace Seele
namespace Vulkan namespace Vulkan
{ {
class TextureHandle class TextureBase
{ {
public: public:
TextureHandle(PGraphics graphics, VkImageViewType viewType, TextureBase(PGraphics graphics, VkImageViewType viewType,
const TextureCreateInfo& createInfo, Gfx::QueueType& owner, VkImage existingImage = VK_NULL_HANDLE); const TextureCreateInfo& createInfo, Gfx::QueueType& owner, VkImage existingImage = VK_NULL_HANDLE);
virtual ~TextureHandle(); virtual ~TextureBase();
inline VkImage getImage() const constexpr VkImage getImage() const
{ {
return image; return image;
} }
inline VkImageView getView() const constexpr VkImageView getView() const
{ {
return defaultView; return defaultView;
} }
inline Gfx::SeImageLayout getLayout() const constexpr Gfx::SeImageLayout getLayout() const
{ {
return layout; return layout;
} }
inline VkImageAspectFlags getAspect() const constexpr VkImageAspectFlags getAspect() const
{ {
return aspect; return aspect;
} }
inline VkImageUsageFlags getUsage() const constexpr VkImageUsageFlags getUsage() const
{ {
return usage; return usage;
} }
inline Gfx::SeFormat getFormat() const constexpr Gfx::SeFormat getFormat() const
{ {
return format; return format;
} }
inline Gfx::SeSampleCountFlags getNumSamples() const constexpr Gfx::SeSampleCountFlags getNumSamples() const
{ {
return samples; return samples;
} }
inline uint32 getMipLevels() const constexpr uint32 getMipLevels() const
{ {
return mipLevels; return mipLevels;
} }
inline bool isDepthStencil() const constexpr bool isDepthStencil() const
{ {
return aspect & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT); return aspect & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT);
} }
@@ -57,14 +57,14 @@ public:
void changeLayout(Gfx::SeImageLayout newLayout); void changeLayout(Gfx::SeImageLayout newLayout);
void download(uint32 mipLevel, uint32 arrayLayer, uint32 face, Array<uint8>& buffer); void download(uint32 mipLevel, uint32 arrayLayer, uint32 face, Array<uint8>& buffer);
private: protected:
//Updates via reference //Updates via reference
Gfx::QueueType& currentOwner; Gfx::QueueType& currentOwner;
PGraphics graphics; PGraphics graphics;
OSubAllocation allocation; OSubAllocation allocation;
uint32 sizeX; uint32 width;
uint32 sizeY; uint32 height;
uint32 sizeZ; uint32 depth;
uint32 arrayCount; uint32 arrayCount;
uint32 layerCount; uint32 layerCount;
uint32 mipLevels; uint32 mipLevels;
@@ -75,23 +75,9 @@ private:
VkImageView defaultView; VkImageView defaultView;
VkImageAspectFlags aspect; VkImageAspectFlags aspect;
Gfx::SeImageLayout layout; Gfx::SeImageLayout layout;
friend class TextureBase;
friend class Texture2D;
friend class Texture3D;
friend class TextureCube;
friend class Graphics; friend class Graphics;
}; };
class TextureBase
{
public:
static TextureHandle* cast(Gfx::PTexture texture);
protected:
TextureHandle* textureHandle;
friend class Graphics;
};
DECLARE_REF(TextureBase)
class Texture2D : public Gfx::Texture2D, public TextureBase class Texture2D : public Gfx::Texture2D, public TextureBase
{ {
public: public:
@@ -99,46 +85,31 @@ public:
virtual ~Texture2D(); virtual ~Texture2D();
virtual uint32 getWidth() const override virtual uint32 getWidth() const override
{ {
return textureHandle->sizeX; return width;
} }
virtual uint32 getHeight() const override virtual uint32 getHeight() const override
{ {
return textureHandle->sizeY; return height;
} }
virtual uint32 getDepth() const override virtual uint32 getDepth() const override
{ {
return textureHandle->sizeZ; return depth;
} }
virtual Gfx::SeFormat getFormat() const override virtual Gfx::SeFormat getFormat() const override
{ {
return textureHandle->format; return format;
} }
virtual Gfx::SeSampleCountFlags getNumSamples() const override virtual Gfx::SeSampleCountFlags getNumSamples() const override
{ {
return textureHandle->getNumSamples(); return samples;
} }
virtual uint32 getMipLevels() const override virtual uint32 getMipLevels() const override
{ {
return textureHandle->getMipLevels(); return mipLevels;
} }
virtual void changeLayout(Gfx::SeImageLayout newLayout) override; virtual void changeLayout(Gfx::SeImageLayout newLayout) override;
virtual void download(uint32 mipLevel, uint32 arrayLayer, uint32 face, Array<uint8>& buffer) override; virtual void download(uint32 mipLevel, uint32 arrayLayer, uint32 face, Array<uint8>& buffer) override;
virtual void* getNativeHandle() override
{
return textureHandle;
}
inline VkImage getHandle() const
{
return textureHandle->image;
}
inline VkImageView getView() const
{
return textureHandle->defaultView;
}
inline bool isDepthStencil() const
{
return textureHandle->isDepthStencil();
}
protected: protected:
// Inherited via QueueOwnedResource // Inherited via QueueOwnedResource
virtual void executeOwnershipBarrier(Gfx::QueueType newOwner); virtual void executeOwnershipBarrier(Gfx::QueueType newOwner);
@@ -155,46 +126,31 @@ public:
virtual ~Texture3D(); virtual ~Texture3D();
virtual uint32 getWidth() const override virtual uint32 getWidth() const override
{ {
return textureHandle->sizeX; return width;
} }
virtual uint32 getHeight() const override virtual uint32 getHeight() const override
{ {
return textureHandle->sizeY; return height;
} }
virtual uint32 getDepth() const override virtual uint32 getDepth() const override
{ {
return textureHandle->sizeZ; return depth;
} }
virtual Gfx::SeFormat getFormat() const override virtual Gfx::SeFormat getFormat() const override
{ {
return textureHandle->format; return format;
} }
virtual Gfx::SeSampleCountFlags getNumSamples() const override virtual Gfx::SeSampleCountFlags getNumSamples() const override
{ {
return textureHandle->getNumSamples(); return samples;
} }
virtual uint32 getMipLevels() const override virtual uint32 getMipLevels() const override
{ {
return textureHandle->getMipLevels(); return mipLevels;
} }
virtual void changeLayout(Gfx::SeImageLayout newLayout) override; virtual void changeLayout(Gfx::SeImageLayout newLayout) override;
virtual void download(uint32 mipLevel, uint32 arrayLayer, uint32 face, Array<uint8>& buffer) override; virtual void download(uint32 mipLevel, uint32 arrayLayer, uint32 face, Array<uint8>& buffer) override;
virtual void* getNativeHandle() override
{
return textureHandle;
}
inline VkImage getHandle() const
{
return textureHandle->image;
}
inline VkImageView getView() const
{
return textureHandle->defaultView;
}
inline bool isDepthStencil() const
{
return textureHandle->isDepthStencil();
}
protected: protected:
// Inherited via QueueOwnedResource // Inherited via QueueOwnedResource
virtual void executeOwnershipBarrier(Gfx::QueueType newOwner); virtual void executeOwnershipBarrier(Gfx::QueueType newOwner);
@@ -211,54 +167,36 @@ public:
virtual ~TextureCube(); virtual ~TextureCube();
virtual uint32 getWidth() const override virtual uint32 getWidth() const override
{ {
return textureHandle->sizeX; return width;
} }
virtual uint32 getHeight() const override virtual uint32 getHeight() const override
{ {
return textureHandle->sizeY; return height;
} }
virtual uint32 getDepth() const override virtual uint32 getDepth() const override
{ {
return textureHandle->sizeZ; return depth;
} }
virtual Gfx::SeFormat getFormat() const override virtual Gfx::SeFormat getFormat() const override
{ {
return textureHandle->format; return format;
} }
virtual Gfx::SeSampleCountFlags getNumSamples() const override virtual Gfx::SeSampleCountFlags getNumSamples() const override
{ {
return textureHandle->getNumSamples(); return samples;
} }
virtual uint32 getMipLevels() const override virtual uint32 getMipLevels() const override
{ {
return textureHandle->getMipLevels(); return mipLevels;
} }
virtual void changeLayout(Gfx::SeImageLayout newLayout) override; virtual void changeLayout(Gfx::SeImageLayout newLayout) override;
virtual void download(uint32 mipLevel, uint32 arrayLayer, uint32 face, Array<uint8>& buffer) override; virtual void download(uint32 mipLevel, uint32 arrayLayer, uint32 face, Array<uint8>& buffer) override;
virtual void* getNativeHandle() override
{
return textureHandle;
}
inline VkImage getHandle() const
{
return textureHandle->image;
}
inline VkImageView getView() const
{
return textureHandle->defaultView;
}
inline bool isDepthStencil() const
{
return textureHandle->isDepthStencil();
}
protected: protected:
// Inherited via QueueOwnedResource // Inherited via QueueOwnedResource
virtual void executeOwnershipBarrier(Gfx::QueueType newOwner); virtual void executeOwnershipBarrier(Gfx::QueueType newOwner);
virtual void executePipelineBarrier(VkAccessFlags srcAccess, VkPipelineStageFlags srcStage, virtual void executePipelineBarrier(VkAccessFlags srcAccess, VkPipelineStageFlags srcStage,
VkAccessFlags dstAccess, VkPipelineStageFlags dstStage); VkAccessFlags dstAccess, VkPipelineStageFlags dstStage);
}; };
DEFINE_REF(TextureCube) DEFINE_REF(TextureCube)
} }
} }
+1
View File
@@ -2,6 +2,7 @@
#include "Window/WindowManager.h" #include "Window/WindowManager.h"
#include "MaterialInstance.h" #include "MaterialInstance.h"
#include "Graphics/Graphics.h" #include "Graphics/Graphics.h"
#include "Graphics/Shader.h"
using namespace Seele; using namespace Seele;
+2 -2
View File
@@ -223,7 +223,7 @@ void SamplerParameter::save(ArchiveBuffer& buffer) const
void SamplerParameter::load(ArchiveBuffer& buffer) void SamplerParameter::load(ArchiveBuffer& buffer)
{ {
ShaderParameter::load(buffer); ShaderParameter::load(buffer);
data = buffer.getGraphics()->createSamplerState({}); data = buffer.getGraphics()->createSampler({});
} }
CombinedTextureParameter::CombinedTextureParameter(std::string name, uint32 byteOffset, uint32 binding) CombinedTextureParameter::CombinedTextureParameter(std::string name, uint32 byteOffset, uint32 binding)
@@ -260,7 +260,7 @@ void CombinedTextureParameter::load(ArchiveBuffer& buffer)
std::string filename; std::string filename;
Serialization::load(buffer, filename); Serialization::load(buffer, filename);
data = AssetRegistry::findTexture(filename); data = AssetRegistry::findTexture(filename);
sampler = buffer.getGraphics()->createSamplerState({}); sampler = buffer.getGraphics()->createSampler({});
} }
ConstantExpression::ConstantExpression() ConstantExpression::ConstantExpression()
+3 -3
View File
@@ -105,11 +105,11 @@ struct TextureParameter : public ShaderParameter
virtual void load(ArchiveBuffer& buffer) override; virtual void load(ArchiveBuffer& buffer) override;
}; };
DEFINE_REF(TextureParameter) DEFINE_REF(TextureParameter)
DECLARE_NAME_REF(Gfx, SamplerState) DECLARE_NAME_REF(Gfx, Sampler)
struct SamplerParameter : public ShaderParameter struct SamplerParameter : public ShaderParameter
{ {
static constexpr uint64 IDENTIFIER = 0x08; static constexpr uint64 IDENTIFIER = 0x08;
Gfx::OSamplerState data; Gfx::OSampler data;
SamplerParameter() {} SamplerParameter() {}
SamplerParameter(std::string name, uint32 byteOffset, uint32 binding); SamplerParameter(std::string name, uint32 byteOffset, uint32 binding);
virtual ~SamplerParameter(); virtual ~SamplerParameter();
@@ -124,7 +124,7 @@ struct CombinedTextureParameter : public ShaderParameter
{ {
static constexpr uint64 IDENTIFIER = 0x10; static constexpr uint64 IDENTIFIER = 0x10;
PTextureAsset data; PTextureAsset data;
Gfx::PSamplerState sampler; Gfx::PSampler sampler;
CombinedTextureParameter() {} CombinedTextureParameter() {}
CombinedTextureParameter(std::string name, uint32 byteOffset, uint32 binding); CombinedTextureParameter(std::string name, uint32 byteOffset, uint32 binding);
virtual ~CombinedTextureParameter(); virtual ~CombinedTextureParameter();
+2 -2
View File
@@ -23,7 +23,7 @@ LightEnvironment::LightEnvironment(Gfx::PGraphics graphics)
.size = sizeof(Component::DirectionalLight) * MAX_DIRECTIONAL_LIGHTS, .size = sizeof(Component::DirectionalLight) * MAX_DIRECTIONAL_LIGHTS,
.data = nullptr, .data = nullptr,
}, },
.stride = sizeof(Component::DirectionalLight), .numElements = MAX_DIRECTIONAL_LIGHTS,
.dynamic = true, .dynamic = true,
}); });
pointLights = graphics->createShaderBuffer(ShaderBufferCreateInfo{ pointLights = graphics->createShaderBuffer(ShaderBufferCreateInfo{
@@ -31,7 +31,7 @@ LightEnvironment::LightEnvironment(Gfx::PGraphics graphics)
.size = sizeof(Component::PointLight) * MAX_POINT_LIGHTS, .size = sizeof(Component::PointLight) * MAX_POINT_LIGHTS,
.data = nullptr, .data = nullptr,
}, },
.stride = sizeof(Component::PointLight), .numElements = MAX_POINT_LIGHTS,
.dynamic = true, .dynamic = true,
}); });
} }