Skip to content

Commit

Permalink
igl | Initial interface for texture dependencies
Browse files Browse the repository at this point in the history
Summary:
Implemented initial interface for texture dependencies.

This is necessary to ensure automatic layout conversions and barriers for external textures.

Reviewed By: pixelperfect3

Differential Revision: D49475720

fbshipit-source-id: 9250ee723db893205758f2cbd5d6717a4164d5fd
  • Loading branch information
corporateshark authored and facebook-github-bot committed Sep 25, 2023
1 parent d70fa96 commit f2f18b4
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 3 deletions.
1 change: 1 addition & 0 deletions IGLU/sentinel/CommandBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ CommandBuffer::CommandBuffer(bool shouldAssert) : shouldAssert_(shouldAssert) {}
std::unique_ptr<igl::IRenderCommandEncoder> CommandBuffer::createRenderCommandEncoder(
const igl::RenderPassDesc& /*renderPass*/,
std::shared_ptr<igl::IFramebuffer> /*framebuffer*/,
const igl::Dependencies& /*dependencies*/,
igl::Result* IGL_NULLABLE /*outResult*/) {
IGLU_SENTINEL_ASSERT_IF_NOT(shouldAssert_);
return nullptr;
Expand Down
1 change: 1 addition & 0 deletions IGLU/sentinel/CommandBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class CommandBuffer final : public igl::ICommandBuffer {
[[nodiscard]] std::unique_ptr<igl::IRenderCommandEncoder> createRenderCommandEncoder(
const igl::RenderPassDesc& /*renderPass*/,
std::shared_ptr<igl::IFramebuffer> /*framebuffer*/,
const igl::Dependencies& /*dependencies*/,
igl::Result* IGL_NULLABLE /*outResult*/) final;
[[nodiscard]] std::unique_ptr<igl::IComputeCommandEncoder> createComputeCommandEncoder() final;
void present(std::shared_ptr<igl::ITexture> /*surface*/) const final;
Expand Down
3 changes: 2 additions & 1 deletion IGLU/simple_renderer/ForwardRenderPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ void ForwardRenderPass::begin(std::shared_ptr<igl::IFramebuffer> target,

igl::CommandBufferDesc cbDesc;
_commandBuffer = _commandQueue->createCommandBuffer(cbDesc, nullptr);
_commandEncoder = _commandBuffer->createRenderCommandEncoder(*finalDesc, _framebuffer);
_commandEncoder =
_commandBuffer->createRenderCommandEncoder(*finalDesc, _framebuffer, {}, nullptr);
}

void ForwardRenderPass::draw(drawable::Drawable& drawable, igl::IDevice& device) const {
Expand Down
12 changes: 11 additions & 1 deletion src/igl/CommandBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ struct CommandBufferStatistics {
uint32_t currentDrawCount = 0;
};

/**
* Dependencies are used to issue proper memory barriers for external resources, such as textures
* modified by non-IGL code (Skia, Qt, etc), and synchronize between graphics and compute pipelines.
*/
struct Dependencies {
static constexpr uint32_t IGL_MAX_TEXTURE_DEPENDENCIES = 4;
ITexture* IGL_NULLABLE textures[IGL_MAX_TEXTURE_DEPENDENCIES] = {};
};

/**
* @brief ICommandBuffer represents an object which accepts and stores commands to be executed on
* the GPU.
Expand Down Expand Up @@ -61,13 +70,14 @@ class ICommandBuffer {
virtual std::unique_ptr<IRenderCommandEncoder> createRenderCommandEncoder(
const RenderPassDesc& renderPass,
std::shared_ptr<IFramebuffer> framebuffer,
const Dependencies& dependencies,
Result* IGL_NULLABLE outResult) = 0;

// Use an overload here instead of a default parameter in a pure virtual function.
std::unique_ptr<IRenderCommandEncoder> createRenderCommandEncoder(
const RenderPassDesc& renderPass,
std::shared_ptr<IFramebuffer> framebuffer) {
return createRenderCommandEncoder(renderPass, std::move(framebuffer), nullptr);
return createRenderCommandEncoder(renderPass, std::move(framebuffer), Dependencies{}, nullptr);
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/igl/metal/CommandBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class CommandBuffer final : public ICommandBuffer,
std::unique_ptr<IRenderCommandEncoder> createRenderCommandEncoder(
const RenderPassDesc& renderPass,
std::shared_ptr<IFramebuffer> framebuffer,
const Dependencies& dependencies,
Result* outResult) override;

void present(std::shared_ptr<ITexture> surface) const override;
Expand Down
1 change: 1 addition & 0 deletions src/igl/metal/CommandBuffer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
std::unique_ptr<IRenderCommandEncoder> CommandBuffer::createRenderCommandEncoder(
const RenderPassDesc& renderPass,
std::shared_ptr<IFramebuffer> framebuffer,
const Dependencies& /*dependencies*/,
Result* outResult) {
return RenderCommandEncoder::create(shared_from_this(), renderPass, framebuffer, outResult);
}
Expand Down
4 changes: 3 additions & 1 deletion src/igl/opengl/CommandBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ CommandBuffer::~CommandBuffer() = default;
std::unique_ptr<IRenderCommandEncoder> CommandBuffer::createRenderCommandEncoder(
const RenderPassDesc& renderPass,
std::shared_ptr<IFramebuffer> framebuffer,
const Dependencies& dependencies,
Result* outResult) {
return RenderCommandEncoder::create(shared_from_this(), renderPass, framebuffer, outResult);
return RenderCommandEncoder::create(
shared_from_this(), renderPass, framebuffer, dependencies, outResult);
}

std::unique_ptr<IComputeCommandEncoder> CommandBuffer::createComputeCommandEncoder() {
Expand Down
1 change: 1 addition & 0 deletions src/igl/opengl/CommandBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class CommandBuffer final : public ICommandBuffer,
std::unique_ptr<IRenderCommandEncoder> createRenderCommandEncoder(
const RenderPassDesc& renderPass,
std::shared_ptr<IFramebuffer> framebuffer,
const Dependencies& dependencies,
Result* outResult) override;

std::unique_ptr<IComputeCommandEncoder> createComputeCommandEncoder() override;
Expand Down
3 changes: 3 additions & 0 deletions src/igl/opengl/RenderCommandEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ std::unique_ptr<RenderCommandEncoder> RenderCommandEncoder::create(
const std::shared_ptr<CommandBuffer>& commandBuffer,
const RenderPassDesc& renderPass,
const std::shared_ptr<IFramebuffer>& framebuffer,
const Dependencies& dependencies,
Result* outResult) {
(void)dependencies; // not used in OpenGL

if (!commandBuffer) {
Result::setResult(outResult, Result::Code::ArgumentNull, "commandBuffer was null");
return {};
Expand Down
2 changes: 2 additions & 0 deletions src/igl/opengl/RenderCommandEncoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class IDepthStencilState;
class IRenderPipelineState;
class ISamplerState;
class ITexture;
struct Dependencies;
namespace opengl {

class RenderCommandAdapter;
Expand All @@ -30,6 +31,7 @@ class RenderCommandEncoder final : public IRenderCommandEncoder, public WithCont
const std::shared_ptr<CommandBuffer>& commandBuffer,
const RenderPassDesc& renderPass,
const std::shared_ptr<IFramebuffer>& framebuffer,
const Dependencies& dependencies,
Result* outResult);

~RenderCommandEncoder() override;
Expand Down
3 changes: 3 additions & 0 deletions src/igl/vulkan/CommandBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,13 @@ void transitionToColorAttachment(VkCommandBuffer buffer,
std::unique_ptr<IRenderCommandEncoder> CommandBuffer::createRenderCommandEncoder(
const RenderPassDesc& renderPass,
std::shared_ptr<IFramebuffer> framebuffer,
const Dependencies& dependencies,
Result* outResult) {
IGL_PROFILER_FUNCTION();
IGL_ASSERT(framebuffer);

(void)dependencies; // will be implemented later

framebuffer_ = framebuffer;

// prepare all the color attachments
Expand Down
1 change: 1 addition & 0 deletions src/igl/vulkan/CommandBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class CommandBuffer final : public ICommandBuffer,
virtual std::unique_ptr<IRenderCommandEncoder> createRenderCommandEncoder(
const RenderPassDesc& renderPass,
std::shared_ptr<IFramebuffer> framebuffer,
const Dependencies& dependencies,
Result* outResult) override;

void present(std::shared_ptr<ITexture> surface) const override;
Expand Down

0 comments on commit f2f18b4

Please sign in to comment.