diff options
author | Sarah <9856269+sarahM0@users.noreply.github.com> | 2019-07-30 21:39:00 -0400 |
---|---|---|
committer | David Neto <dneto@google.com> | 2019-07-30 21:39:00 -0400 |
commit | cc67e6a2ee90bd3faa73ab1791e8e56011e808d8 (patch) | |
tree | e7ea96ba279bbeb46c733ec96bd4d10e523aee63 /src/buffer.cc | |
parent | 00748dfc1acdb885d930a8139c552e45189cfb89 (diff) | |
download | amber-cc67e6a2ee90bd3faa73ab1791e8e56011e808d8.tar.gz |
[Dawn] Implement DoCompute support in dawn backend and fix sparse descriptor set support (#585)
Also adds Buffer::RecalculateMaxSizeInBytes
Diffstat (limited to 'src/buffer.cc')
-rw-r--r-- | src/buffer.cc | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/buffer.cc b/src/buffer.cc index ce33b1a..617ff7a 100644 --- a/src/buffer.cc +++ b/src/buffer.cc @@ -115,6 +115,26 @@ Result Buffer::SetData(const std::vector<Value>& data) { return SetDataWithOffset(data, 0); } +Result Buffer::RecalculateMaxSizeInBytes(const std::vector<Value>& data, + uint32_t offset) { + // Multiply by the input needed because the value count will use the needed + // input as the multiplier + uint32_t value_count = + ((offset / format_->SizeInBytes()) * format_->InputNeededPerElement()) + + static_cast<uint32_t>(data.size()); + uint32_t element_count = value_count; + if (format_->GetPackSize() == 0) { + // This divides by the needed input values, not the values per element. + // The assumption being the values coming in are read from the input, + // where components are specified. The needed values maybe less then the + // values per element. + element_count = value_count / format_->InputNeededPerElement(); + } + if (GetMaxSizeInBytes() < element_count * format_->SizeInBytes()) + SetMaxSizeInBytes(element_count * format_->SizeInBytes()); + return {}; +} + Result Buffer::SetDataWithOffset(const std::vector<Value>& data, uint32_t offset) { // Multiply by the input needed because the value count will use the needed @@ -223,6 +243,23 @@ void Buffer::ResizeTo(uint32_t element_count) { bytes_.resize(element_count * format_->SizeInBytes()); } +void Buffer::SetSizeInBytes(uint32_t size_in_bytes) { + assert(size_in_bytes % format_->SizeInBytes() == 0); + element_count_ = size_in_bytes / format_->SizeInBytes(); + bytes_.resize(size_in_bytes); +} + +void Buffer::SetMaxSizeInBytes(uint32_t max_size_in_bytes) { + max_size_in_bytes_ = max_size_in_bytes; +} + +uint32_t Buffer::GetMaxSizeInBytes() const { + if (max_size_in_bytes_ != 0) + return max_size_in_bytes_; + else + return GetSizeInBytes(); +} + Result Buffer::SetDataFromBuffer(const Buffer* src, uint32_t offset) { if (bytes_.size() < offset + src->bytes_.size()) bytes_.resize(offset + src->bytes_.size()); |