-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IGLU: Add new Sentinel module for sentinel implementations
Summary: This diff adds a new sentintenl IGLU module. This module will hold dummy, sentinel implementations of IGL interfaces. These can be used for safety when otherwise accessing a potentially null pointer to an IGL object. Reviewed By: pixelperfect3, corporateshark Differential Revision: D49357729 fbshipit-source-id: 2c0d677c7503b8d3af147f36869db0f298d38b31
- Loading branch information
1 parent
cffacf8
commit ddc035a
Showing
14 changed files
with
690 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <igl/Common.h> | ||
|
||
#define IGLU_SENTINEL_ASSERT_IF_NOT(shouldAssert) \ | ||
IGL_ASSERT_MSG(!(shouldAssert), "Sentinel implementation should NOT be reached") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <IGLU/sentinel/Buffer.h> | ||
|
||
#include <IGLU/sentinel/Assert.h> | ||
#include <igl/IGL.h> | ||
|
||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <igl/Buffer.h> | ||
|
||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <IGLU/sentinel/CommandBuffer.h> | ||
|
||
#include <IGLU/sentinel/Assert.h> | ||
#include <igl/IGL.h> | ||
|
||
namespace iglu::sentinel { | ||
|
||
CommandBuffer::CommandBuffer(bool shouldAssert) : shouldAssert_(shouldAssert) {} | ||
|
||
std::unique_ptr<igl::IRenderCommandEncoder> CommandBuffer::createRenderCommandEncoder( | ||
const igl::RenderPassDesc& /*renderPass*/, | ||
std::shared_ptr<igl::IFramebuffer> /*framebuffer*/, | ||
igl::Result* IGL_NULLABLE /*outResult*/) { | ||
IGLU_SENTINEL_ASSERT_IF_NOT(shouldAssert_); | ||
return nullptr; | ||
} | ||
|
||
std::unique_ptr<igl::IComputeCommandEncoder> CommandBuffer::createComputeCommandEncoder() { | ||
IGLU_SENTINEL_ASSERT_IF_NOT(shouldAssert_); | ||
return nullptr; | ||
} | ||
|
||
void CommandBuffer::present(std::shared_ptr<igl::ITexture> /*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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <igl/CommandBuffer.h> | ||
|
||
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<igl::IRenderCommandEncoder> createRenderCommandEncoder( | ||
const igl::RenderPassDesc& /*renderPass*/, | ||
std::shared_ptr<igl::IFramebuffer> /*framebuffer*/, | ||
igl::Result* IGL_NULLABLE /*outResult*/) final; | ||
[[nodiscard]] std::unique_ptr<igl::IComputeCommandEncoder> createComputeCommandEncoder() final; | ||
void present(std::shared_ptr<igl::ITexture> /*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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <IGLU/sentinel/CommandQueue.h> | ||
|
||
#include <IGLU/sentinel/Assert.h> | ||
|
||
namespace iglu::sentinel { | ||
|
||
CommandQueue::CommandQueue(bool shouldAssert) : shouldAssert_(shouldAssert) {} | ||
|
||
std::shared_ptr<igl::ICommandBuffer> 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <igl/CommandQueue.h> | ||
|
||
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<igl::ICommandBuffer> 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 |
Oops, something went wrong.