vk_stream_buffer: Respect non coherent access alignment

* Required by nvidia GPUs on MacOS
This commit is contained in:
GPUCode
2023-09-05 17:41:11 +03:00
parent cc9768963a
commit ba89673d77
2 changed files with 13 additions and 0 deletions

View File

@@ -205,6 +205,11 @@ public:
return properties.limits.minUniformBufferOffsetAlignment; return properties.limits.minUniformBufferOffsetAlignment;
} }
/// Returns the minimum alignemt required for accessing host-mapped device memory
vk::DeviceSize NonCoherentAtomSize() const {
return properties.limits.nonCoherentAtomSize;
}
/// Returns the maximum supported elements in a texel buffer /// Returns the maximum supported elements in a texel buffer
u32 MaxTexelBufferElements() const { u32 MaxTexelBufferElements() const {
return properties.limits.maxTexelBufferElements; return properties.limits.maxTexelBufferElements;

View File

@@ -94,6 +94,10 @@ StreamBuffer::~StreamBuffer() {
} }
std::tuple<u8*, u64, bool> StreamBuffer::Map(u64 size, u64 alignment) { std::tuple<u8*, u64, bool> StreamBuffer::Map(u64 size, u64 alignment) {
if (!is_coherent && type == BufferType::Stream) {
size = Common::AlignUp(size, instance.NonCoherentAtomSize());
}
ASSERT(size <= stream_buffer_size); ASSERT(size <= stream_buffer_size);
mapped_size = size; mapped_size = size;
@@ -122,6 +126,10 @@ std::tuple<u8*, u64, bool> StreamBuffer::Map(u64 size, u64 alignment) {
} }
void StreamBuffer::Commit(u64 size) { void StreamBuffer::Commit(u64 size) {
if (!is_coherent && type == BufferType::Stream) {
size = Common::AlignUp(size, instance.NonCoherentAtomSize());
}
ASSERT_MSG(size <= mapped_size, "Reserved size {} is too small compared to {}", mapped_size, ASSERT_MSG(size <= mapped_size, "Reserved size {} is too small compared to {}", mapped_size,
size); size);