Skip to content

Commit

Permalink
Added a mechanism to validate object creation.
Browse files Browse the repository at this point in the history
Previously, object creation was not validated automatically upon creation. Now, each object creation is validated and an backend error is thrown in the case of an error.
  • Loading branch information
DhirajWishal committed Mar 25, 2022
1 parent 2b32948 commit fa81778
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 6 deletions.
2 changes: 2 additions & 0 deletions Include/Firefly/Source/Buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ namespace Firefly
std::shared_ptr<Buffer> Buffer::create(const std::shared_ptr<Engine>& pEngine, const uint64_t size, const BufferType type)
{
const auto pointer = std::make_shared<Buffer>(pEngine, size, type);
FIREFLY_VALIDATE_OBJECT(pointer);

pointer->initialize();

return pointer;
Expand Down
5 changes: 4 additions & 1 deletion Include/Firefly/Source/CommandBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ namespace Firefly

std::shared_ptr<CommandBuffer> CommandBuffer::create(const std::shared_ptr<Engine>& pEngine, const VkCommandPool vCommandPool, const VkCommandBuffer vCommandBuffer)
{
return std::make_shared<CommandBuffer>(pEngine, vCommandPool, vCommandBuffer);
const auto pointer = std::make_shared<CommandBuffer>(pEngine, vCommandPool, vCommandBuffer);
FIREFLY_VALIDATE_OBJECT(pointer);

return pointer;
}

void CommandBuffer::begin()
Expand Down
4 changes: 3 additions & 1 deletion Include/Firefly/Source/Decoder/Decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ namespace Firefly

std::shared_ptr<Decoder> Decoder::create(const std::shared_ptr<Instance>& pInstance)
{
auto pointer = std::make_shared<Decoder>(pInstance);
const auto pointer = std::make_shared<Decoder>(pInstance);
FIREFLY_VALIDATE_OBJECT(pointer);

pointer->initialize(VkQueueFlagBits::VK_QUEUE_VIDEO_DECODE_BIT_KHR, { VK_KHR_VIDEO_QUEUE_EXTENSION_NAME , VK_KHR_SYNCHRONIZATION_2_EXTENSION_NAME, VK_KHR_VIDEO_DECODE_QUEUE_EXTENSION_NAME, VK_EXT_VIDEO_DECODE_H264_EXTENSION_NAME });

return pointer;
Expand Down
4 changes: 3 additions & 1 deletion Include/Firefly/Source/Encoder/Encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ namespace Firefly

std::shared_ptr<Encoder> Encoder::create(const std::shared_ptr<Instance>& pInstance)
{
auto pointer = std::make_shared<Encoder>(pInstance);
const auto pointer = std::make_shared<Encoder>(pInstance);
FIREFLY_VALIDATE_OBJECT(pointer);

pointer->initialize(VkQueueFlagBits::VK_QUEUE_VIDEO_ENCODE_BIT_KHR, { VK_KHR_VIDEO_QUEUE_EXTENSION_NAME , VK_KHR_SYNCHRONIZATION_2_EXTENSION_NAME, VK_KHR_VIDEO_ENCODE_QUEUE_EXTENSION_NAME, VK_EXT_VIDEO_ENCODE_H264_EXTENSION_NAME });

return pointer;
Expand Down
4 changes: 3 additions & 1 deletion Include/Firefly/Source/Graphics/GraphicsEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ namespace Firefly

std::shared_ptr<GraphicsEngine> GraphicsEngine::create(const std::shared_ptr<Instance>& pInstance)
{
auto pointer = std::make_shared<GraphicsEngine>(pInstance);
const auto pointer = std::make_shared<GraphicsEngine>(pInstance);
FIREFLY_VALIDATE_OBJECT(pointer);

pointer->initialize(VkQueueFlagBits::VK_QUEUE_GRAPHICS_BIT, {}, GetFeatures());

return pointer;
Expand Down
2 changes: 2 additions & 0 deletions Include/Firefly/Source/Graphics/GraphicsPipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ namespace Firefly
std::shared_ptr<GraphicsPipeline> GraphicsPipeline::create(const std::shared_ptr<GraphicsEngine>& pEngine, const std::string& pipelineName, const std::vector<std::shared_ptr<Shader>>& pShaders, const std::shared_ptr<RenderTarget>& pRenderTarget, const GraphicsPipelineSpecification& specification)
{
const auto pointer = std::make_shared<GraphicsPipeline>(pEngine, pipelineName, pShaders, pRenderTarget, specification);
FIREFLY_VALIDATE_OBJECT(pointer);

pointer->initialize();

return pointer;
Expand Down
2 changes: 2 additions & 0 deletions Include/Firefly/Source/Graphics/RenderTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ namespace Firefly
std::shared_ptr<RenderTarget> RenderTarget::create(const std::shared_ptr<GraphicsEngine>& pEngine, const VkExtent3D extent, const VkFormat vColorFormat, const uint8_t frameCount)
{
const auto pointer = std::make_shared<RenderTarget>(pEngine, extent, frameCount);
FIREFLY_VALIDATE_OBJECT(pointer);

pointer->initialize(vColorFormat);

return pointer;
Expand Down
2 changes: 2 additions & 0 deletions Include/Firefly/Source/Graphics/Surface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ namespace Firefly
std::shared_ptr<Surface> Surface::create(const std::shared_ptr<Instance>& pInstance, const uint32_t width, const uint32_t height, std::string&& title)
{
const auto pointer = std::make_shared<Surface>(pInstance, width, height, std::move(title));
FIREFLY_VALIDATE_OBJECT(pointer);

pointer->initialize();

return pointer;
Expand Down
4 changes: 3 additions & 1 deletion Include/Firefly/Source/Image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,9 @@ namespace Firefly

std::shared_ptr<Firefly::Image> Image::create(const std::shared_ptr<Engine>& pEngine, const VkExtent3D extent, const VkFormat format, const ImageType type, const uint32_t layers /*= 1*/, const VkImageUsageFlags usageFlags /*= VkImageUsageFlagBits::VK_IMAGE_USAGE_SAMPLED_BIT | VkImageUsageFlagBits::VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VkImageUsageFlagBits::VK_IMAGE_USAGE_TRANSFER_DST_BIT*/)
{
auto pointer = std::make_shared<Image>(pEngine, extent, format, type, layers, usageFlags);
const auto pointer = std::make_shared<Image>(pEngine, extent, format, type, layers, usageFlags);
FIREFLY_VALIDATE_OBJECT(pointer);

pointer->initialize();

return pointer;
Expand Down
4 changes: 3 additions & 1 deletion Include/Firefly/Source/Instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ namespace Firefly

std::shared_ptr<Instance> Instance::create(const uint32_t vulkanAPIVersion, bool enableValidation)
{
auto pointer = std::make_shared<Instance>(vulkanAPIVersion, enableValidation);
const auto pointer = std::make_shared<Instance>(vulkanAPIVersion, enableValidation);
FIREFLY_VALIDATE_OBJECT(pointer);

pointer->initialize();

return pointer;
Expand Down
4 changes: 4 additions & 0 deletions Include/Firefly/Source/Shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ namespace Firefly
std::shared_ptr<Shader> Shader::create(const std::shared_ptr<Engine>& pEngine, const std::filesystem::path& file, const VkShaderStageFlags flags)
{
const auto pointer = std::make_shared<Shader>(pEngine, flags);
FIREFLY_VALIDATE_OBJECT(pointer);

pointer->initialize(file);

return pointer;
Expand All @@ -251,6 +253,8 @@ namespace Firefly
std::shared_ptr<Shader> Shader::create(const std::shared_ptr<Engine>& pEngine, const ShaderCode& shaderCode, const VkShaderStageFlags flags)
{
const auto pointer = std::make_shared<Shader>(pEngine, flags);
FIREFLY_VALIDATE_OBJECT(pointer);

pointer->initialize(shaderCode);

return pointer;
Expand Down
2 changes: 2 additions & 0 deletions Include/Firefly/Utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#define FIREFLY_NO_COPY(name) name(const name&) = delete; name& operator=(const name&) = delete
#define FIREFLY_NO_MOVE(name) name(name&&) = delete; name& operator=(name&&) = delete

#define FIREFLY_VALIDATE_OBJECT(pointer) if(!pointer) throw ::Firefly::BackendError("Failed to create the object!")

namespace Firefly
{
namespace Utility
Expand Down

0 comments on commit fa81778

Please sign in to comment.