diff --git a/IGLU/CMakeLists.txt b/IGLU/CMakeLists.txt index cf443672c3..dcf694774b 100644 --- a/IGLU/CMakeLists.txt +++ b/IGLU/CMakeLists.txt @@ -21,6 +21,7 @@ endmacro() add_iglu_module(imgui) add_iglu_module(managedUniformBuffer) +add_iglu_module(sentinel) add_iglu_module(simple_renderer) add_iglu_module(state_pool) add_iglu_module(texture_accessor) diff --git a/IGLU/sentinel/Assert.h b/IGLU/sentinel/Assert.h new file mode 100644 index 0000000000..15c1a06e00 --- /dev/null +++ b/IGLU/sentinel/Assert.h @@ -0,0 +1,13 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#pragma once + +#include + +#define IGLU_SENTINEL_ASSERT_IF_NOT(shouldAssert) \ + IGL_ASSERT_MSG(!(shouldAssert), "Sentinel implementation should NOT be reached") diff --git a/IGLU/sentinel/Buffer.cpp b/IGLU/sentinel/Buffer.cpp new file mode 100644 index 0000000000..ca3ff02db1 --- /dev/null +++ b/IGLU/sentinel/Buffer.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#include + +#include +#include + +namespace iglu::sentinel { + +Buffer::Buffer(bool shouldAssert) : shouldAssert_(shouldAssert) {} + +igl::Result Buffer::upload(const void* IGL_NULLABLE /*data*/, const igl::BufferRange& /*range*/) { + IGLU_SENTINEL_ASSERT_IF_NOT(shouldAssert_); + return igl::Result(igl::Result::Code::Unimplemented, "Not Implemented"); +} + +void* IGL_NULLABLE Buffer::map(const igl::BufferRange& /*range*/, + igl::Result* IGL_NULLABLE /*outResult*/) { + IGLU_SENTINEL_ASSERT_IF_NOT(shouldAssert_); + return nullptr; +} + +void Buffer::unmap() { + IGLU_SENTINEL_ASSERT_IF_NOT(shouldAssert_); +} + +igl::BufferDesc::BufferAPIHint Buffer::requestedApiHints() const noexcept { + IGLU_SENTINEL_ASSERT_IF_NOT(shouldAssert_); + return 0; +} + +igl::BufferDesc::BufferAPIHint Buffer::acceptedApiHints() const noexcept { + IGLU_SENTINEL_ASSERT_IF_NOT(shouldAssert_); + return 0; +} + +igl::ResourceStorage Buffer::storage() const noexcept { + IGLU_SENTINEL_ASSERT_IF_NOT(shouldAssert_); + return igl::ResourceStorage::Invalid; +} + +size_t Buffer::getSizeInBytes() const { + IGLU_SENTINEL_ASSERT_IF_NOT(shouldAssert_); + return 0; +} + +uint64_t Buffer::gpuAddress(size_t /*offset*/) const { + IGLU_SENTINEL_ASSERT_IF_NOT(shouldAssert_); + return 0; +} + +} // namespace iglu::sentinel diff --git a/IGLU/sentinel/Buffer.h b/IGLU/sentinel/Buffer.h new file mode 100644 index 0000000000..400593a367 --- /dev/null +++ b/IGLU/sentinel/Buffer.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#pragma once + +#include + +namespace iglu::sentinel { + +/** + * Sentinel Buffer intended for safe use where access to a real buffer is not available. + * Use cases include returning a reference to a buffer from a raw pointer when a valid buffer is not + * available. + * All methods return nullptr, the default value or an error. + */ +class Buffer : public igl::IBuffer { + public: + explicit Buffer(bool shouldAssert = true); + + [[nodiscard]] igl::Result upload(const void* IGL_NULLABLE data, + const igl::BufferRange& range) final; + void* IGL_NULLABLE map(const igl::BufferRange& range, igl::Result* IGL_NULLABLE outResult) final; + void unmap() final; + [[nodiscard]] igl::BufferDesc::BufferAPIHint requestedApiHints() const noexcept final; + [[nodiscard]] igl::BufferDesc::BufferAPIHint acceptedApiHints() const noexcept final; + [[nodiscard]] igl::ResourceStorage storage() const noexcept final; + [[nodiscard]] size_t getSizeInBytes() const final; + [[nodiscard]] uint64_t gpuAddress(size_t offset = 0) const final; + + private: + [[maybe_unused]] bool shouldAssert_; +}; + +} // namespace iglu::sentinel diff --git a/IGLU/sentinel/CommandBuffer.cpp b/IGLU/sentinel/CommandBuffer.cpp new file mode 100644 index 0000000000..6b91ae4adc --- /dev/null +++ b/IGLU/sentinel/CommandBuffer.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#include + +#include +#include + +namespace iglu::sentinel { + +CommandBuffer::CommandBuffer(bool shouldAssert) : shouldAssert_(shouldAssert) {} + +std::unique_ptr CommandBuffer::createRenderCommandEncoder( + const igl::RenderPassDesc& /*renderPass*/, + std::shared_ptr /*framebuffer*/, + igl::Result* IGL_NULLABLE /*outResult*/) { + IGLU_SENTINEL_ASSERT_IF_NOT(shouldAssert_); + return nullptr; +} + +std::unique_ptr CommandBuffer::createComputeCommandEncoder() { + IGLU_SENTINEL_ASSERT_IF_NOT(shouldAssert_); + return nullptr; +} + +void CommandBuffer::present(std::shared_ptr /*surface*/) const { + IGLU_SENTINEL_ASSERT_IF_NOT(shouldAssert_); +} + +void CommandBuffer::waitUntilScheduled() { + IGLU_SENTINEL_ASSERT_IF_NOT(shouldAssert_); +} + +void CommandBuffer::waitUntilCompleted() { + IGLU_SENTINEL_ASSERT_IF_NOT(shouldAssert_); +} + +void CommandBuffer::pushDebugGroupLabel(const std::string& /*label*/, + const igl::Color& /*color*/) const { + IGLU_SENTINEL_ASSERT_IF_NOT(shouldAssert_); +} + +void CommandBuffer::popDebugGroupLabel() const { + IGLU_SENTINEL_ASSERT_IF_NOT(shouldAssert_); +} + +} // namespace iglu::sentinel diff --git a/IGLU/sentinel/CommandBuffer.h b/IGLU/sentinel/CommandBuffer.h new file mode 100644 index 0000000000..2de428db9a --- /dev/null +++ b/IGLU/sentinel/CommandBuffer.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#pragma once + +#include + +namespace iglu::sentinel { + +/** + * Sentinel CommandBuffer intended for safe use where access to a real command buffer is not + * available. + * Use cases include returning a reference to a command buffer from a raw pointer when a + * valid command buffer is not available. + * All methods return nullptr, the default value or an error. + */ +class CommandBuffer final : public igl::ICommandBuffer { + public: + explicit CommandBuffer(bool shouldAssert = true); + + [[nodiscard]] std::unique_ptr createRenderCommandEncoder( + const igl::RenderPassDesc& /*renderPass*/, + std::shared_ptr /*framebuffer*/, + igl::Result* IGL_NULLABLE /*outResult*/) final; + [[nodiscard]] std::unique_ptr createComputeCommandEncoder() final; + void present(std::shared_ptr /*surface*/) const final; + void waitUntilScheduled() final; + void waitUntilCompleted() final; + void pushDebugGroupLabel(const std::string& /*label*/, + const igl::Color& /*color*/ = igl::Color(1, 1, 1, 1)) const final; + void popDebugGroupLabel() const final; + + private: + [[maybe_unused]] bool shouldAssert_; +}; + +} // namespace iglu::sentinel diff --git a/IGLU/sentinel/CommandQueue.cpp b/IGLU/sentinel/CommandQueue.cpp new file mode 100644 index 0000000000..6daeb6af13 --- /dev/null +++ b/IGLU/sentinel/CommandQueue.cpp @@ -0,0 +1,30 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#include + +#include + +namespace iglu::sentinel { + +CommandQueue::CommandQueue(bool shouldAssert) : shouldAssert_(shouldAssert) {} + +std::shared_ptr CommandQueue::createCommandBuffer( + const igl::CommandBufferDesc& /*desc*/, + igl::Result* IGL_NULLABLE + /*outResult*/) { + IGLU_SENTINEL_ASSERT_IF_NOT(shouldAssert_); + return nullptr; +} + +igl::SubmitHandle CommandQueue::submit(const igl::ICommandBuffer& /*commandBuffer*/, + bool /*endOfFrame*/) { + IGLU_SENTINEL_ASSERT_IF_NOT(shouldAssert_); + return 0; +} + +} // namespace iglu::sentinel diff --git a/IGLU/sentinel/CommandQueue.h b/IGLU/sentinel/CommandQueue.h new file mode 100644 index 0000000000..c7c26e5e35 --- /dev/null +++ b/IGLU/sentinel/CommandQueue.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#pragma once + +#include + +namespace iglu::sentinel { + +/** + * Sentinel CommandQueue intended for safe use where access to a real command queue is not + * available. + * Use cases include returning a reference to a command queue from a raw pointer when a + * valid command queue is not available. + * All methods return nullptr, the default value or an error. + */ +class CommandQueue final : public igl::ICommandQueue { + public: + explicit CommandQueue(bool shouldAssert = true); + + [[nodiscard]] std::shared_ptr createCommandBuffer( + const igl::CommandBufferDesc& desc, + igl::Result* IGL_NULLABLE outResult) final; + igl::SubmitHandle submit(const igl::ICommandBuffer& commandBuffer, bool endOfFrame = false) final; + + private: + [[maybe_unused]] bool shouldAssert_; +}; + +} // namespace iglu::sentinel diff --git a/IGLU/sentinel/Device.cpp b/IGLU/sentinel/Device.cpp new file mode 100644 index 0000000000..821fcf2db1 --- /dev/null +++ b/IGLU/sentinel/Device.cpp @@ -0,0 +1,154 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#include + +#include +#include +#include + +namespace iglu::sentinel { + +Device::Device(bool shouldAssert) : platformDevice_(shouldAssert), shouldAssert_(shouldAssert) {} + +bool Device::hasFeature(igl::DeviceFeatures /*feature*/) const { + IGLU_SENTINEL_ASSERT_IF_NOT(shouldAssert_); + return false; +} + +bool Device::hasRequirement(igl::DeviceRequirement /*requirement*/) const { + IGLU_SENTINEL_ASSERT_IF_NOT(shouldAssert_); + return false; +} + +igl::ICapabilities::TextureFormatCapabilities Device::getTextureFormatCapabilities( + igl::TextureFormat /*format*/) const { + IGLU_SENTINEL_ASSERT_IF_NOT(shouldAssert_); + return TextureFormatCapabilityBits::Unsupported; +} + +bool Device::getFeatureLimits(igl::DeviceFeatureLimits /*featureLimits*/, + size_t& /*result*/) const { + IGLU_SENTINEL_ASSERT_IF_NOT(shouldAssert_); + return false; +} + +igl::ShaderVersion Device::getShaderVersion() const { + IGLU_SENTINEL_ASSERT_IF_NOT(shouldAssert_); + return {}; +} + +std::shared_ptr Device::createCommandQueue( + const igl::CommandQueueDesc& /*desc*/, + igl::Result* IGL_NULLABLE /*outResult*/) { + IGLU_SENTINEL_ASSERT_IF_NOT(shouldAssert_); + return nullptr; +} + +std::unique_ptr Device::createBuffer( + const igl::BufferDesc& /*desc*/, + igl::Result* IGL_NULLABLE /*outResult*/) const noexcept { + IGLU_SENTINEL_ASSERT_IF_NOT(shouldAssert_); + return nullptr; +} + +std::shared_ptr Device::createDepthStencilState( + const igl::DepthStencilStateDesc& /*desc*/, + igl::Result* IGL_NULLABLE /*outResult*/) const { + IGLU_SENTINEL_ASSERT_IF_NOT(shouldAssert_); + return nullptr; +} + +std::shared_ptr Device::createSamplerState( + const igl::SamplerStateDesc& /*desc*/, + igl::Result* IGL_NULLABLE + /*outResult*/) const { + IGLU_SENTINEL_ASSERT_IF_NOT(shouldAssert_); + return nullptr; +} + +std::shared_ptr Device::createTexture(const igl::TextureDesc& /*desc*/, + igl::Result* IGL_NULLABLE + /*outResult*/) const noexcept { + IGLU_SENTINEL_ASSERT_IF_NOT(shouldAssert_); + return nullptr; +} + +std::shared_ptr Device::createVertexInputState( + const igl::VertexInputStateDesc& /*desc*/, + igl::Result* IGL_NULLABLE /*outResult*/) const { + IGLU_SENTINEL_ASSERT_IF_NOT(shouldAssert_); + return nullptr; +} + +std::shared_ptr Device::createComputePipeline( + const igl::ComputePipelineDesc& /*desc*/, + igl::Result* IGL_NULLABLE /*outResult*/) const { + IGLU_SENTINEL_ASSERT_IF_NOT(shouldAssert_); + return nullptr; +} + +std::shared_ptr Device::createRenderPipeline( + const igl::RenderPipelineDesc& /*desc*/, + igl::Result* IGL_NULLABLE /*outResult*/) const { + IGLU_SENTINEL_ASSERT_IF_NOT(shouldAssert_); + return nullptr; +} + +std::shared_ptr Device::createShaderModule( + const igl::ShaderModuleDesc& /*desc*/, + igl::Result* IGL_NULLABLE + /*outResult*/) const { + IGLU_SENTINEL_ASSERT_IF_NOT(shouldAssert_); + return nullptr; +} + +std::shared_ptr Device::createFramebuffer( + const igl::FramebufferDesc& /*desc*/, + igl::Result* IGL_NULLABLE /*outResult*/) { + IGLU_SENTINEL_ASSERT_IF_NOT(shouldAssert_); + return nullptr; +} + +const igl::IPlatformDevice& Device::getPlatformDevice() const noexcept { + IGLU_SENTINEL_ASSERT_IF_NOT(shouldAssert_); + return platformDevice_; +} + +bool Device::verifyScope() { + IGLU_SENTINEL_ASSERT_IF_NOT(shouldAssert_); + return false; +} + +igl::BackendType Device::getBackendType() const { + IGLU_SENTINEL_ASSERT_IF_NOT(shouldAssert_); + return igl::BackendType::Invalid; +} + +size_t Device::getCurrentDrawCount() const { + IGLU_SENTINEL_ASSERT_IF_NOT(shouldAssert_); + return 0; +} + +std::unique_ptr Device::createShaderLibrary( + const igl::ShaderLibraryDesc& /*desc*/, + igl::Result* IGL_NULLABLE + /*outResult*/) const { + IGLU_SENTINEL_ASSERT_IF_NOT(shouldAssert_); + return nullptr; +} + +void Device::updateSurface(void* IGL_NONNULL /*nativeWindowType*/) {} +std::unique_ptr Device::createShaderStages( + const igl::ShaderStagesDesc& /*desc*/, + igl::Result* IGL_NULLABLE + /*outResult*/) const { + IGLU_SENTINEL_ASSERT_IF_NOT(shouldAssert_); + return nullptr; +} + +} // namespace iglu::sentinel diff --git a/IGLU/sentinel/Device.h b/IGLU/sentinel/Device.h new file mode 100644 index 0000000000..0e0261541e --- /dev/null +++ b/IGLU/sentinel/Device.h @@ -0,0 +1,79 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#pragma once + +#include +#include + +namespace iglu::sentinel { + +/** + * Sentinel Device intended for safe use where access to a real device is not available. + * Use cases include returning a reference to a device from a raw pointer when a valid device is not + * available. + * All methods return nullptr, the default value or an error. + */ +class Device final : public igl::IDevice { + public: + explicit Device(bool shouldAssert = true); + + [[nodiscard]] bool hasFeature(igl::DeviceFeatures feature) const final; + [[nodiscard]] bool hasRequirement(igl::DeviceRequirement requirement) const final; + [[nodiscard]] TextureFormatCapabilities getTextureFormatCapabilities( + igl::TextureFormat format) const final; + [[nodiscard]] bool getFeatureLimits(igl::DeviceFeatureLimits featureLimits, + size_t& result) const final; + [[nodiscard]] igl::ShaderVersion getShaderVersion() const final; + [[nodiscard]] std::shared_ptr createCommandQueue( + const igl::CommandQueueDesc& desc, + igl::Result* IGL_NULLABLE outResult) final; + [[nodiscard]] std::unique_ptr createBuffer(const igl::BufferDesc& desc, + igl::Result* IGL_NULLABLE + outResult) const noexcept final; + [[nodiscard]] std::shared_ptr createDepthStencilState( + const igl::DepthStencilStateDesc& desc, + igl::Result* IGL_NULLABLE outResult) const final; + [[nodiscard]] std::shared_ptr createSamplerState( + const igl::SamplerStateDesc& desc, + igl::Result* IGL_NULLABLE outResult) const final; + [[nodiscard]] std::shared_ptr createTexture(const igl::TextureDesc& desc, + igl::Result* IGL_NULLABLE + outResult) const noexcept final; + [[nodiscard]] std::shared_ptr createVertexInputState( + const igl::VertexInputStateDesc& desc, + igl::Result* IGL_NULLABLE outResult) const final; + [[nodiscard]] std::shared_ptr createComputePipeline( + const igl::ComputePipelineDesc& desc, + igl::Result* IGL_NULLABLE outResult) const final; + [[nodiscard]] std::shared_ptr createRenderPipeline( + const igl::RenderPipelineDesc& desc, + igl::Result* IGL_NULLABLE outResult) const final; + [[nodiscard]] std::shared_ptr createShaderModule( + const igl::ShaderModuleDesc& desc, + igl::Result* IGL_NULLABLE outResult) const final; + [[nodiscard]] std::shared_ptr createFramebuffer( + const igl::FramebufferDesc& desc, + igl::Result* IGL_NULLABLE outResult) final; + [[nodiscard]] const igl::IPlatformDevice& getPlatformDevice() const noexcept final; + [[nodiscard]] bool verifyScope() final; + [[nodiscard]] igl::BackendType getBackendType() const final; + [[nodiscard]] size_t getCurrentDrawCount() const final; + [[nodiscard]] std::unique_ptr createShaderLibrary( + const igl::ShaderLibraryDesc& desc, + igl::Result* IGL_NULLABLE outResult) const final; + void updateSurface(void* IGL_NONNULL nativeWindowType) final; + [[nodiscard]] std::unique_ptr createShaderStages( + const igl::ShaderStagesDesc& desc, + igl::Result* IGL_NULLABLE outResult) const final; + + private: + PlatformDevice platformDevice_; + [[maybe_unused]] bool shouldAssert_; +}; + +} // namespace iglu::sentinel diff --git a/IGLU/sentinel/Framebuffer.cpp b/IGLU/sentinel/Framebuffer.cpp new file mode 100644 index 0000000000..e0afe80612 --- /dev/null +++ b/IGLU/sentinel/Framebuffer.cpp @@ -0,0 +1,86 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#include + +#include + +namespace iglu::sentinel { + +Framebuffer::Framebuffer(bool shouldAssert) : shouldAssert_(shouldAssert) {} + +std::vector Framebuffer::getColorAttachmentIndices() const { + IGLU_SENTINEL_ASSERT_IF_NOT(shouldAssert_); + return {}; +} + +std::shared_ptr Framebuffer::getColorAttachment(size_t /*index*/) const { + IGLU_SENTINEL_ASSERT_IF_NOT(shouldAssert_); + return nullptr; +} + +std::shared_ptr Framebuffer::getResolveColorAttachment(size_t /*index*/) const { + IGLU_SENTINEL_ASSERT_IF_NOT(shouldAssert_); + return nullptr; +} + +std::shared_ptr Framebuffer::getDepthAttachment() const { + IGLU_SENTINEL_ASSERT_IF_NOT(shouldAssert_); + return nullptr; +} + +std::shared_ptr Framebuffer::getResolveDepthAttachment() const { + IGLU_SENTINEL_ASSERT_IF_NOT(shouldAssert_); + return nullptr; +} + +std::shared_ptr Framebuffer::getStencilAttachment() const { + IGLU_SENTINEL_ASSERT_IF_NOT(shouldAssert_); + return nullptr; +} + +igl::FramebufferMode Framebuffer::getMode() const { + IGLU_SENTINEL_ASSERT_IF_NOT(shouldAssert_); + return igl::FramebufferMode::Mono; +} + +void Framebuffer::copyBytesColorAttachment(igl::ICommandQueue& /*cmdQueue*/, + size_t /*index*/, + void* /*pixelBytes*/, + const igl::TextureRangeDesc& /*range*/, + size_t /*bytesPerRow*/) const { + IGLU_SENTINEL_ASSERT_IF_NOT(shouldAssert_); +} + +void Framebuffer::copyBytesDepthAttachment(igl::ICommandQueue& /*cmdQueue*/, + void* /*pixelBytes*/, + const igl::TextureRangeDesc& /*range*/, + size_t /*bytesPerRow*/) const { + IGLU_SENTINEL_ASSERT_IF_NOT(shouldAssert_); +} + +void Framebuffer::copyBytesStencilAttachment(igl::ICommandQueue& /*cmdQueue*/, + void* /*pixelBytes*/, + const igl::TextureRangeDesc& /*range*/, + size_t /*bytesPerRow*/) const { + IGLU_SENTINEL_ASSERT_IF_NOT(shouldAssert_); +} + +void Framebuffer::copyTextureColorAttachment(igl::ICommandQueue& /*cmdQueue*/, + size_t /*index*/, + std::shared_ptr /*destTexture*/, + const igl::TextureRangeDesc& /*range*/) const { + IGLU_SENTINEL_ASSERT_IF_NOT(shouldAssert_); +} + +std::shared_ptr Framebuffer::updateDrawable( + std::shared_ptr /*texture*/) { + IGLU_SENTINEL_ASSERT_IF_NOT(shouldAssert_); + return nullptr; +} + +} // namespace iglu::sentinel diff --git a/IGLU/sentinel/Framebuffer.h b/IGLU/sentinel/Framebuffer.h new file mode 100644 index 0000000000..fc311bc419 --- /dev/null +++ b/IGLU/sentinel/Framebuffer.h @@ -0,0 +1,55 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#pragma once + +#include + +namespace iglu::sentinel { + +/** + * Sentinel Frambuffer intended for safe use where access to a real framebuffer is not available. + * Use cases include returning a reference to a framebuffer from a raw pointer when a + * valid framebuffer is not available. + * All methods return nullptr, the default value or an error. + */ +class Framebuffer : public igl::IFramebuffer { + public: + explicit Framebuffer(bool shouldAssert = true); + + [[nodiscard]] std::vector getColorAttachmentIndices() const final; + [[nodiscard]] std::shared_ptr getColorAttachment(size_t index) const final; + [[nodiscard]] std::shared_ptr getResolveColorAttachment(size_t index) const final; + [[nodiscard]] std::shared_ptr getDepthAttachment() const final; + [[nodiscard]] std::shared_ptr getResolveDepthAttachment() const final; + [[nodiscard]] std::shared_ptr getStencilAttachment() const final; + [[nodiscard]] igl::FramebufferMode getMode() const final; + void copyBytesColorAttachment(igl::ICommandQueue& cmdQueue, + size_t index, + void* pixelBytes, + const igl::TextureRangeDesc& range, + size_t bytesPerRow = 0) const final; + void copyBytesDepthAttachment(igl::ICommandQueue& cmdQueue, + void* pixelBytes, + const igl::TextureRangeDesc& range, + size_t bytesPerRow = 0) const final; + void copyBytesStencilAttachment(igl::ICommandQueue& cmdQueue, + void* pixelBytes, + const igl::TextureRangeDesc& range, + size_t bytesPerRow = 0) const final; + void copyTextureColorAttachment(igl::ICommandQueue& cmdQueue, + size_t index, + std::shared_ptr destTexture, + const igl::TextureRangeDesc& range) const final; + [[nodiscard]] std::shared_ptr updateDrawable( + std::shared_ptr texture) final; + + private: + [[maybe_unused]] bool shouldAssert_; +}; + +} // namespace iglu::sentinel diff --git a/IGLU/sentinel/PlatformDevice.cpp b/IGLU/sentinel/PlatformDevice.cpp new file mode 100644 index 0000000000..c11b1c73fb --- /dev/null +++ b/IGLU/sentinel/PlatformDevice.cpp @@ -0,0 +1,21 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#include + +#include + +namespace iglu::sentinel { + +PlatformDevice::PlatformDevice(bool shouldAssert) : shouldAssert_(shouldAssert) {} + +bool PlatformDevice::isType(igl::PlatformDeviceType /*t*/) const noexcept { + IGLU_SENTINEL_ASSERT_IF_NOT(shouldAssert_); + return false; +} + +} // namespace iglu::sentinel diff --git a/IGLU/sentinel/PlatformDevice.h b/IGLU/sentinel/PlatformDevice.h new file mode 100644 index 0000000000..f53b3dcab8 --- /dev/null +++ b/IGLU/sentinel/PlatformDevice.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#pragma once + +#include + +namespace iglu::sentinel { + +/** + * Sentinel PlatformDevice intended for safe use where access to a real platform device is not + * available. + * Use cases include returning a reference to a platform device from a raw pointer when a + * valid platform device is not available. + * All methods return nullptr, the default value or an error. + */ +class PlatformDevice final : public igl::IPlatformDevice { + public: + explicit PlatformDevice(bool shouldAssert = true); + [[nodiscard]] bool isType(igl::PlatformDeviceType t) const noexcept final; + + private: + [[maybe_unused]] bool shouldAssert_; +}; + +} // namespace iglu::sentinel