Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
BattleAxeVR committed Apr 23, 2024
2 parents 90d38a6 + 999bca9 commit e0971ba
Show file tree
Hide file tree
Showing 20 changed files with 84 additions and 30 deletions.
2 changes: 1 addition & 1 deletion IGLU/simple_renderer/ShaderUniforms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ void ShaderUniforms::bindBuffer(igl::IDevice& device,
const auto& glPipelineState =
static_cast<const igl::opengl::RenderPipelineState&>(pipelineState);
encoder.bindBuffer(glPipelineState.getUniformBlockBindingPoint(uniformName),
bindTargetForShaderStage(buffer->iglBufferDesc.shaderStage),
igl::BindTarget::kAllGraphics,
buffer->allocation->iglBuffer,
0);
} else {
Expand Down
6 changes: 5 additions & 1 deletion shell/renderSessions/TQMultiRenderPassSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,11 @@ static void render(std::shared_ptr<ICommandBuffer>& buffer,
commands->bindRenderPipelineState(pipelineState);

if (backend != igl::BackendType::OpenGL) {
commands->bindBuffer(0, BindTarget::kFragment, fragmentParamBuffer, 0);
commands->bindBuffer(0,
backend == igl::BackendType::Metal ? BindTarget::kFragment
: BindTarget::kAllGraphics,
fragmentParamBuffer,
0);
} else {
// Bind non block uniforms
for (const auto& uniformDesc : fragmentUniformDescriptors) {
Expand Down
7 changes: 6 additions & 1 deletion src/igl/ComputeCommandEncoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,13 @@ class IComputeCommandEncoder : public ICommandEncoder {
* @param index An index for the buffer argument table.
* @param buffer The buffer to set in the buffer argument table.
* @param offset Where the data begins in bytes from the start of the buffer.
* @param bufferSize The size of the buffer to bind used for additional validation (0 means the
* remaining size starting from `offset`)
*/
virtual void bindBuffer(size_t index, const std::shared_ptr<IBuffer>& buffer, size_t offset) = 0;
virtual void bindBuffer(size_t index,
const std::shared_ptr<IBuffer>& buffer,
size_t offset,
size_t bufferSize = 0) = 0;
/**
* @brief Sets a block of data for the compute function. A buffer will be created behind the
* scenes to hold the input data and bound to the buffer argument table at the specified index.
Expand Down
5 changes: 4 additions & 1 deletion src/igl/RenderCommandEncoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,13 @@ class IRenderCommandEncoder : public ICommandEncoder {
// target is the igl::BindTarget type
//
// bufferOffset is the offset into the buffer where the data starts
// bufferSize is the size of the buffer to bind used for additional validation (0 means the
// remaining size starting from `offset`)
virtual void bindBuffer(int index,
uint8_t target,
const std::shared_ptr<IBuffer>& buffer,
size_t bufferOffset) = 0;
size_t bufferOffset,
size_t bufferSize = 0) = 0;
virtual void bindVertexBuffer(uint32_t index,
const std::shared_ptr<IBuffer>& buffer,
size_t bufferOffset = 0) = 0;
Expand Down
5 changes: 4 additions & 1 deletion src/igl/metal/ComputeCommandEncoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ class ComputeCommandEncoder final : public IComputeCommandEncoder {
void popDebugGroupLabel() const override;
void bindUniform(const UniformDesc& uniformDesc, const void* data) override;
void bindTexture(size_t index, ITexture* texture) override;
void bindBuffer(size_t index, const std::shared_ptr<IBuffer>& buffer, size_t offset) override;
void bindBuffer(size_t index,
const std::shared_ptr<IBuffer>& buffer,
size_t offset,
size_t bufferSize) override;
void bindBytes(size_t index, const void* data, size_t length) override;
void bindPushConstants(const void* data, size_t length, size_t offset) override;

Expand Down
5 changes: 4 additions & 1 deletion src/igl/metal/ComputeCommandEncoder.mm
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@

void ComputeCommandEncoder::bindBuffer(size_t index,
const std::shared_ptr<IBuffer>& buffer,
size_t offset) {
size_t offset,
size_t bufferSize) {
(void)bufferSize;

IGL_ASSERT(encoder_);
if (buffer) {
auto& iglBuffer = static_cast<Buffer&>(*buffer);
Expand Down
3 changes: 2 additions & 1 deletion src/igl/metal/RenderCommandEncoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ class RenderCommandEncoder final : public IRenderCommandEncoder {
void bindBuffer(int index,
uint8_t target,
const std::shared_ptr<IBuffer>& buffer,
size_t bufferOffset) override;
size_t bufferOffset,
size_t bufferSize) override;
void bindVertexBuffer(uint32_t index,
const std::shared_ptr<IBuffer>& buffer,
size_t bufferOffset) override;
Expand Down
5 changes: 4 additions & 1 deletion src/igl/metal/RenderCommandEncoder.mm
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,10 @@
void RenderCommandEncoder::bindBuffer(int index,
uint8_t bindTarget,
const std::shared_ptr<IBuffer>& buffer,
size_t offset) {
size_t offset,
size_t bufferSize) {
(void)bufferSize;

IGL_ASSERT(encoder_);
IGL_ASSERT_MSG(bindTarget == BindTarget::kVertex || bindTarget == BindTarget::kFragment ||
bindTarget == BindTarget::kAllGraphics,
Expand Down
5 changes: 4 additions & 1 deletion src/igl/opengl/ComputeCommandEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,10 @@ void ComputeCommandEncoder::bindTexture(size_t index, ITexture* texture) {

void ComputeCommandEncoder::bindBuffer(size_t index,
const std::shared_ptr<IBuffer>& buffer,
size_t offset) {
size_t offset,
size_t bufferSize) {
(void)bufferSize;

if (IGL_VERIFY(adapter_) && buffer) {
auto glBuffer = std::static_pointer_cast<Buffer>(buffer);
adapter_->setBuffer(glBuffer, offset, static_cast<int>(index));
Expand Down
5 changes: 4 additions & 1 deletion src/igl/opengl/ComputeCommandEncoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ class ComputeCommandEncoder final : public IComputeCommandEncoder, public WithCo
void popDebugGroupLabel() const override;
void bindUniform(const UniformDesc& uniformDesc, const void* data) override;
void bindTexture(size_t index, ITexture* texture) override;
void bindBuffer(size_t index, const std::shared_ptr<IBuffer>& buffer, size_t offset) override;
void bindBuffer(size_t index,
const std::shared_ptr<IBuffer>& buffer,
size_t offset,
size_t bufferSize) override;
void bindBytes(size_t index, const void* data, size_t length) override;
void bindPushConstants(const void* data, size_t length, size_t offset) override;

Expand Down
19 changes: 14 additions & 5 deletions src/igl/opengl/RenderCommandEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,22 @@ void RenderCommandEncoder::bindUniform(const UniformDesc& uniformDesc, const voi
}

void RenderCommandEncoder::bindBuffer(int index,
uint8_t bindTarget,
uint8_t target,
const std::shared_ptr<IBuffer>& buffer,
size_t offset) {
size_t offset,
size_t bufferSize) {
(void)bufferSize;

IGL_ASSERT_MSG(index >= 0, "Invalid index passed to bindBuffer: %d", index);
// bindTarget (which can be BindTarget::kVertex or kFragment) is unused in OGL backend

IGL_ASSERT_MSG(
target == igl::BindTarget::kAllGraphics,
"Use bindVertexBuffer() to bind vertex buffers. The target should be kAllGraphics");

if (!IGL_VERIFY(target == igl::BindTarget::kAllGraphics)) {
return;
}

if (IGL_VERIFY(adapter_) && buffer) {
auto glBuffer = std::static_pointer_cast<Buffer>(buffer);
auto bufferType = glBuffer->getType();
Expand All @@ -244,8 +255,6 @@ void RenderCommandEncoder::bindBuffer(int index,
IGL_ASSERT_NOT_IMPLEMENTED();
} else if (bufferType == Buffer::Type::UniformBlock) {
adapter_->setUniformBuffer(glBuffer, offset, index);
} else if (bufferType == Buffer::Type::Attribute && (bindTarget & BindTarget::kVertex) != 0) {
adapter_->setVertexBuffer(std::move(glBuffer), offset, index);
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/igl/opengl/RenderCommandEncoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ class RenderCommandEncoder final : public IRenderCommandEncoder, public WithCont
void bindBuffer(int index,
uint8_t target,
const std::shared_ptr<IBuffer>& buffer,
size_t bufferOffset) override;
size_t bufferOffset,
size_t bufferSize) override;
void bindVertexBuffer(uint32_t index,
const std::shared_ptr<IBuffer>& buffer,
size_t bufferOffset) override;
Expand Down
1 change: 1 addition & 0 deletions src/igl/vulkan/CommandBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ std::unique_ptr<IRenderCommandEncoder> CommandBuffer::createRenderCommandEncoder
encoder->binder().bindStorageBuffer(
EnhancedShaderDebuggingStore::kBufferIndex,
static_cast<igl::vulkan::Buffer*>(ctx_.enhancedShaderDebuggingStore_->vertexBuffer().get()),
0,
0);
}

Expand Down
3 changes: 2 additions & 1 deletion src/igl/vulkan/CommandQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ void CommandQueue::enhancedShaderDebuggingPass(const igl::vulkan::VulkanContext&
vkEncoder->binder().bindStorageBuffer(
EnhancedShaderDebuggingStore::kBufferIndex,
static_cast<igl::vulkan::Buffer*>(debugger->vertexBuffer().get()),
sizeof(EnhancedShaderDebuggingStore::Header));
sizeof(EnhancedShaderDebuggingStore::Header),
0);

cmdEncoder->pushDebugGroupLabel("Render Debug Lines", kColorDebugLines);
cmdEncoder->bindDepthStencilState(debugger->depthStencilState());
Expand Down
5 changes: 3 additions & 2 deletions src/igl/vulkan/ComputeCommandEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ void ComputeCommandEncoder::bindTexture(size_t index, ITexture* texture) {

void ComputeCommandEncoder::bindBuffer(size_t index,
const std::shared_ptr<IBuffer>& buffer,
size_t offset) {
size_t offset,
size_t bufferSize) {
IGL_PROFILER_FUNCTION();

if (!IGL_VERIFY(buffer != nullptr)) {
Expand All @@ -182,7 +183,7 @@ void ComputeCommandEncoder::bindBuffer(size_t index,
return;
}

binder_.bindStorageBuffer((int)index, buf, offset);
binder_.bindStorageBuffer((int)index, buf, offset, bufferSize);
}

void ComputeCommandEncoder::bindBytes(size_t /*index*/, const void* /*data*/, size_t /*length*/) {
Expand Down
5 changes: 4 additions & 1 deletion src/igl/vulkan/ComputeCommandEncoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ class ComputeCommandEncoder : public IComputeCommandEncoder {
void bindTexture(size_t index, ITexture* texture) override;

/// @brief Binds a buffer. If the buffer is not a storage buffer, this function is a no-op
void bindBuffer(size_t index, const std::shared_ptr<IBuffer>& buffer, size_t offset) override;
void bindBuffer(size_t index,
const std::shared_ptr<IBuffer>& buffer,
size_t offset,
size_t bufferSize) override;

/// @brief Not implemented
void bindBytes(size_t index, const void* data, size_t length) override;
Expand Down
7 changes: 4 additions & 3 deletions src/igl/vulkan/RenderCommandEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,8 @@ void RenderCommandEncoder::bindDepthStencilState(
void RenderCommandEncoder::bindBuffer(int index,
uint8_t target,
const std::shared_ptr<IBuffer>& buffer,
size_t bufferOffset) {
size_t bufferOffset,
size_t bufferSize) {
IGL_PROFILER_FUNCTION();
IGL_PROFILER_ZONE_GPU_VK("bindBuffer()", ctx_.tracyCtx_, cmdBuffer_);

Expand Down Expand Up @@ -494,14 +495,14 @@ void RenderCommandEncoder::bindBuffer(int index,
return;
}
if (isUniformBuffer) {
binder_.bindUniformBuffer(index, buf, bufferOffset);
binder_.bindUniformBuffer(index, buf, bufferOffset, bufferSize);
}
if (isStorageBuffer) {
if (ctx_.enhancedShaderDebuggingStore_) {
IGL_ASSERT_MSG(index < (IGL_UNIFORM_BLOCKS_BINDING_MAX - 1),
"The last buffer index is reserved for enhanced debugging features");
}
binder_.bindStorageBuffer(index, buf, bufferOffset);
binder_.bindStorageBuffer(index, buf, bufferOffset, bufferSize);
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/igl/vulkan/RenderCommandEncoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ class RenderCommandEncoder : public IRenderCommandEncoder {
void bindBuffer(int index,
uint8_t target,
const std::shared_ptr<IBuffer>& buffer,
size_t bufferOffset) override;
size_t bufferOffset,
size_t bufferSize) override;
void bindVertexBuffer(uint32_t index,
const std::shared_ptr<IBuffer>& buffer,
size_t bufferOffset) override;
Expand Down
10 changes: 6 additions & 4 deletions src/igl/vulkan/ResourcesBinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ ResourcesBinder::ResourcesBinder(const std::shared_ptr<CommandBuffer>& commandBu

void ResourcesBinder::bindUniformBuffer(uint32_t index,
igl::vulkan::Buffer* buffer,
size_t bufferOffset) {
size_t bufferOffset,
size_t bufferSize) {
IGL_PROFILER_FUNCTION();

if (!IGL_VERIFY(index < IGL_UNIFORM_BLOCKS_BINDING_MAX)) {
Expand All @@ -43,14 +44,15 @@ void ResourcesBinder::bindUniformBuffer(uint32_t index,
VkDescriptorBufferInfo& slot = bindingsUniformBuffers_.buffers[index];

if (slot.buffer != buf || slot.offset != bufferOffset) {
slot = {buf, bufferOffset, VK_WHOLE_SIZE};
slot = {buf, bufferOffset, bufferSize ? bufferSize : VK_WHOLE_SIZE};
isDirtyFlags_ |= DirtyFlagBits_UniformBuffers;
}
}

void ResourcesBinder::bindStorageBuffer(uint32_t index,
igl::vulkan::Buffer* buffer,
size_t bufferOffset) {
size_t bufferOffset,
size_t bufferSize) {
IGL_PROFILER_FUNCTION();

if (!IGL_VERIFY(index < IGL_UNIFORM_BLOCKS_BINDING_MAX)) {
Expand All @@ -65,7 +67,7 @@ void ResourcesBinder::bindStorageBuffer(uint32_t index,
VkDescriptorBufferInfo& slot = bindingsStorageBuffers_.buffers[index];

if (slot.buffer != buf || slot.offset != bufferOffset) {
slot = {buf, bufferOffset, VK_WHOLE_SIZE};
slot = {buf, bufferOffset, bufferSize ? bufferSize : VK_WHOLE_SIZE};
isDirtyFlags_ |= DirtyFlagBits_StorageBuffers;
}
}
Expand Down
10 changes: 8 additions & 2 deletions src/igl/vulkan/ResourcesBinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,16 @@ class ResourcesBinder final {
VkPipelineBindPoint bindPoint);

/// @brief Binds a uniform buffer with an offset to index equal to `index`
void bindUniformBuffer(uint32_t index, igl::vulkan::Buffer* buffer, size_t bufferOffset);
void bindUniformBuffer(uint32_t index,
igl::vulkan::Buffer* buffer,
size_t bufferOffset,
size_t bufferSize);

/// @brief Binds a storage buffer with an offset to index equal to `index`
void bindStorageBuffer(uint32_t index, igl::vulkan::Buffer* buffer, size_t bufferOffset);
void bindStorageBuffer(uint32_t index,
igl::vulkan::Buffer* buffer,
size_t bufferOffset,
size_t bufferSize);

/// @brief Binds a sampler state to index equal to `index`
void bindSamplerState(uint32_t index, igl::vulkan::SamplerState* samplerState);
Expand Down

0 comments on commit e0971ba

Please sign in to comment.