Skip to content

Commit

Permalink
igl | Implement IBuffer::getBufferType()
Browse files Browse the repository at this point in the history
Summary: Implemented `IBuffer::getBufferType()`.

Reviewed By: mmaurer

Differential Revision: D50860844

fbshipit-source-id: 2ee71dba4681ce56c00f475531fa4e0478080301
  • Loading branch information
corporateshark authored and facebook-github-bot committed Nov 1, 2023
1 parent 85d52e8 commit 626eb93
Show file tree
Hide file tree
Showing 12 changed files with 68 additions and 27 deletions.
5 changes: 5 additions & 0 deletions IGLU/sentinel/Buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,9 @@ uint64_t Buffer::gpuAddress(size_t /*offset*/) const {
return 0;
}

igl::BufferDesc::BufferType Buffer::getBufferType() const {
IGLU_SENTINEL_ASSERT_IF_NOT(shouldAssert_);
return 0;
}

} // namespace iglu::sentinel
1 change: 1 addition & 0 deletions IGLU/sentinel/Buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class Buffer : public igl::IBuffer {
[[nodiscard]] igl::ResourceStorage storage() const noexcept final;
[[nodiscard]] size_t getSizeInBytes() const final;
[[nodiscard]] uint64_t gpuAddress(size_t offset = 0) const final;
[[nodiscard]] igl::BufferDesc::BufferType getBufferType() const final;

private:
size_t size_;
Expand Down
11 changes: 9 additions & 2 deletions src/igl/Buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ struct BufferDesc {
*/
BufferAPIHint hint = 0;
/**
* @brief GLES only. Target binding point for this IBuffer
* @brief A bit mask of BufferTypeBits. All usage types must be specified.
* @See igl::BufferType
*/
BufferType type; // GLES only
BufferType type = 0;

/** @brief Identifier used for debugging */
std::string debugName;
Expand Down Expand Up @@ -171,6 +171,13 @@ class IBuffer : public ITrackedResource<IBuffer> {
*/
virtual uint64_t gpuAddress(size_t offset = 0) const = 0;

/**
* @brief Returns the underlying buffer type which is a mask of igl::BufferDesc::BufferTypeBits
*
* @return igl::BufferDesc::BufferType
*/
virtual BufferDesc::BufferType getBufferType() const = 0;

protected:
IBuffer() = default;
};
Expand Down
11 changes: 9 additions & 2 deletions src/igl/metal/Buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class Buffer : public igl::IBuffer {
Buffer(id<MTLBuffer> value,
MTLResourceOptions options,
BufferDesc::BufferAPIHint requestedApiHints,
BufferDesc::BufferAPIHint acceptedApiHints);
BufferDesc::BufferAPIHint acceptedApiHints,
BufferDesc::BufferType bufferType);

Result upload(const void* data, const BufferRange& range) override;

Expand All @@ -35,6 +36,10 @@ class Buffer : public igl::IBuffer {
size_t getSizeInBytes() const override;
[[nodiscard]] uint64_t gpuAddress(size_t offset) const override;

[[nodiscard]] BufferDesc::BufferType getBufferType() const override {
return bufferType_;
}

IGL_INLINE virtual id<MTLBuffer> get() {
return mtlBuffers_[0];
}
Expand All @@ -44,6 +49,7 @@ class Buffer : public igl::IBuffer {
std::vector<id<MTLBuffer>> mtlBuffers_;
BufferDesc::BufferAPIHint requestedApiHints_;
BufferDesc::BufferAPIHint acceptedApiHints_;
BufferDesc::BufferType bufferType_;
};

// Manages a ring of buffers.
Expand All @@ -54,7 +60,8 @@ class RingBuffer final : public Buffer {
RingBuffer(std::vector<id<MTLBuffer>> ringBuffers,
MTLResourceOptions options,
std::shared_ptr<const BufferSynchronizationManager> syncManager,
BufferDesc::BufferAPIHint requestedApiHints);
BufferDesc::BufferAPIHint requestedApiHints,
BufferDesc::BufferType bufferType);

Result upload(const void* data, const BufferRange& range) override;

Expand Down
11 changes: 7 additions & 4 deletions src/igl/metal/Buffer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,12 @@
Buffer::Buffer(id<MTLBuffer> value,
MTLResourceOptions options,
BufferDesc::BufferAPIHint requestedApiHints,
BufferDesc::BufferAPIHint acceptedApiHints) :
BufferDesc::BufferAPIHint acceptedApiHints,
BufferDesc::BufferType bufferType) :
resourceOptions_(options),
requestedApiHints_(requestedApiHints),
acceptedApiHints_(acceptedApiHints) {
acceptedApiHints_(acceptedApiHints),
bufferType_(bufferType) {
mtlBuffers_.push_back(value);
}

Expand Down Expand Up @@ -152,8 +154,9 @@
RingBuffer::RingBuffer(std::vector<id<MTLBuffer>> ringBuffers,
MTLResourceOptions options,
std::shared_ptr<const BufferSynchronizationManager> syncManager,
BufferDesc::BufferAPIHint requestedApiHints) :
Buffer(nil, options, requestedApiHints, BufferDesc::BufferAPIHintBits::Ring),
BufferDesc::BufferAPIHint requestedApiHints,
BufferDesc::BufferType bufferType) :
Buffer(nil, options, requestedApiHints, BufferDesc::BufferAPIHintBits::Ring, bufferType),
syncManager_(std::move(syncManager)) {
mtlBuffers_ = std::move(ringBuffers);
}
Expand Down
8 changes: 4 additions & 4 deletions src/igl/metal/Device.mm
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@

id<MTLBuffer> metalObject = createMetalBuffer(device_, desc, options);
std::unique_ptr<IBuffer> resource = std::make_unique<Buffer>(
std::move(metalObject), options, desc.hint, 0 /* No accepted hints */);
std::move(metalObject), options, desc.hint, 0 /* No accepted hints */, desc.type);
if (getResourceTracker()) {
resource->initResourceTracker(getResourceTracker());
}
Expand All @@ -94,8 +94,8 @@
id<MTLBuffer> metalObject = createMetalBuffer(device_, desc, options);
bufferRing.push_back(metalObject);
}
std::unique_ptr<IBuffer> resource =
std::make_unique<RingBuffer>(std::move(bufferRing), options, bufferSyncManager_, desc.hint);
std::unique_ptr<IBuffer> resource = std::make_unique<RingBuffer>(
std::move(bufferRing), options, bufferSyncManager_, desc.hint, desc.type);

if (getResourceTracker()) {
resource->initResourceTracker(getResourceTracker());
Expand All @@ -117,7 +117,7 @@
deallocator:deallocator];

std::unique_ptr<IBuffer> resource = std::make_unique<Buffer>(
metalObject, options, desc.hint, BufferDesc::BufferAPIHintBits::NoCopy);
metalObject, options, desc.hint, BufferDesc::BufferAPIHintBits::NoCopy, desc.type);
if (getResourceTracker()) {
resource->initResourceTracker(getResourceTracker());
}
Expand Down
6 changes: 4 additions & 2 deletions src/igl/opengl/Buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ namespace opengl {
// **** ArrayBuffer
// ********************************
// the base buffer object
ArrayBuffer::ArrayBuffer(IContext& context, BufferDesc::BufferAPIHint requestedApiHints) :
Buffer(context, requestedApiHints) {
ArrayBuffer::ArrayBuffer(IContext& context,
BufferDesc::BufferAPIHint requestedApiHints,
BufferDesc::BufferType bufferType) :
Buffer(context, requestedApiHints, bufferType) {
iD_ = 0;
size_ = 0;
isDynamic_ = false;
Expand Down
21 changes: 16 additions & 5 deletions src/igl/opengl/Buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ class Buffer : public WithContext, public IBuffer {
public:
enum class Type : uint8_t { Attribute, Uniform, UniformBlock };

Buffer(IContext& context, BufferDesc::BufferAPIHint requestedApiHints) :
WithContext(context), requestedApiHints_(requestedApiHints) {}
Buffer(IContext& context,
BufferDesc::BufferAPIHint requestedApiHints,
BufferDesc::BufferType bufferType) :
WithContext(context), requestedApiHints_(requestedApiHints), bufferType_(bufferType) {}
uint64_t gpuAddress(size_t) const override {
IGL_ASSERT_NOT_IMPLEMENTED();
return 0;
Expand All @@ -35,13 +37,20 @@ class Buffer : public WithContext, public IBuffer {
return requestedApiHints_;
}

[[nodiscard]] BufferDesc::BufferType getBufferType() const override {
return bufferType_;
}

private:
BufferDesc::BufferAPIHint requestedApiHints_;
BufferDesc::BufferType bufferType_ = 0;
};

class ArrayBuffer : public Buffer {
public:
ArrayBuffer(IContext& context, BufferDesc::BufferAPIHint requestedApiHints);
ArrayBuffer(IContext& context,
BufferDesc::BufferAPIHint requestedApiHints,
BufferDesc::BufferType bufferType);
~ArrayBuffer() override;

Result upload(const void* data, const BufferRange& range) override;
Expand Down Expand Up @@ -98,8 +107,10 @@ class ArrayBuffer : public Buffer {

class UniformBlockBuffer : public ArrayBuffer {
public:
UniformBlockBuffer(IContext& context, BufferDesc::BufferAPIHint requestedApiHints) :
ArrayBuffer(context, requestedApiHints) {}
UniformBlockBuffer(IContext& context,
BufferDesc::BufferAPIHint requestedApiHints,
BufferDesc::BufferType bufferType) :
ArrayBuffer(context, requestedApiHints, bufferType) {}

Type getType() const noexcept override {
return Type::UniformBlock;
Expand Down
6 changes: 3 additions & 3 deletions src/igl/opengl/Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ std::unique_ptr<Buffer> allocateBuffer(BufferDesc::BufferType bufferType,
if ((bufferType & BufferDesc::BufferTypeBits::Index) ||
(bufferType & BufferDesc::BufferTypeBits::Vertex) ||
(bufferType & BufferDesc::BufferTypeBits::Storage)) {
resource = std::make_unique<ArrayBuffer>(context, requestedApiHints);
resource = std::make_unique<ArrayBuffer>(context, requestedApiHints, bufferType);
} else if (bufferType & BufferDesc::BufferTypeBits::Uniform) {
if (requestedApiHints & BufferDesc::BufferAPIHintBits::UniformBlock) {
resource = std::make_unique<UniformBlockBuffer>(context, requestedApiHints);
resource = std::make_unique<UniformBlockBuffer>(context, requestedApiHints, bufferType);
} else {
resource = std::make_unique<UniformBuffer>(context, requestedApiHints);
resource = std::make_unique<UniformBuffer>(context, requestedApiHints, bufferType);
}

} else {
Expand Down
6 changes: 4 additions & 2 deletions src/igl/opengl/UniformBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ enum class UniformBaseType { Invalid = 0, Boolean, Int, Float, FloatMatrix };
// **** Buffer
// ********************************
// the base buffer object
UniformBuffer::UniformBuffer(IContext& context, BufferDesc::BufferAPIHint requestedApiHints) :
Buffer(context, requestedApiHints) {
UniformBuffer::UniformBuffer(IContext& context,
BufferDesc::BufferAPIHint requestedApiHints,
BufferDesc::BufferType bufferType) :
Buffer(context, requestedApiHints, bufferType) {
isDynamic_ = false;
}

Expand Down
4 changes: 3 additions & 1 deletion src/igl/opengl/UniformBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ class RenderPipelineState;

class UniformBuffer final : public Buffer {
public:
UniformBuffer(IContext& context, BufferDesc::BufferAPIHint requestedApiHints);
UniformBuffer(IContext& context,
BufferDesc::BufferAPIHint requestedApiHints,
BufferDesc::BufferType bufferType);
~UniformBuffer() override;

Result upload(const void* data, const BufferRange& range) override;
Expand Down
5 changes: 3 additions & 2 deletions src/igl/vulkan/Buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ class Buffer final : public igl::IBuffer {
size_t getSizeInBytes() const override;
uint64_t gpuAddress(size_t offset) const override;

VkBuffer getVkBuffer() const;
BufferDesc::BufferType getBufferType() const {
BufferDesc::BufferType getBufferType() const override {
return desc_.type;
}

VkBuffer getVkBuffer() const;

private:
Result create(const BufferDesc& desc);
[[nodiscard]] const std::shared_ptr<VulkanBuffer>& currentVulkanBuffer() const;
Expand Down

0 comments on commit 626eb93

Please sign in to comment.