mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-01-15 11:25:13 +00:00
renderer_vulkan: Fix null buffer views with wrong format. (#2079)
This commit is contained in:
parent
39b511070a
commit
c08fc85b72
|
@ -34,21 +34,10 @@ BufferCache::BufferCache(const Vulkan::Instance& instance_, Vulkan::Scheduler& s
|
||||||
|
|
||||||
// Ensure the first slot is used for the null buffer
|
// Ensure the first slot is used for the null buffer
|
||||||
const auto null_id =
|
const auto null_id =
|
||||||
slot_buffers.insert(instance, scheduler, MemoryUsage::DeviceLocal, 0, ReadFlags, 1);
|
slot_buffers.insert(instance, scheduler, MemoryUsage::DeviceLocal, 0, ReadFlags, 16);
|
||||||
ASSERT(null_id.index == 0);
|
ASSERT(null_id.index == 0);
|
||||||
const vk::Buffer& null_buffer = slot_buffers[null_id].buffer;
|
const vk::Buffer& null_buffer = slot_buffers[null_id].buffer;
|
||||||
Vulkan::SetObjectName(instance.GetDevice(), null_buffer, "Null Buffer");
|
Vulkan::SetObjectName(instance.GetDevice(), null_buffer, "Null Buffer");
|
||||||
|
|
||||||
const vk::BufferViewCreateInfo null_view_ci = {
|
|
||||||
.buffer = null_buffer,
|
|
||||||
.format = vk::Format::eR8Unorm,
|
|
||||||
.offset = 0,
|
|
||||||
.range = VK_WHOLE_SIZE,
|
|
||||||
};
|
|
||||||
const auto [null_view_result, null_view] = instance.GetDevice().createBufferView(null_view_ci);
|
|
||||||
ASSERT_MSG(null_view_result == vk::Result::eSuccess, "Failed to create null buffer view.");
|
|
||||||
null_buffer_view = null_view;
|
|
||||||
Vulkan::SetObjectName(instance.GetDevice(), null_buffer_view, "Null Buffer View");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BufferCache::~BufferCache() = default;
|
BufferCache::~BufferCache() = default;
|
||||||
|
|
|
@ -71,10 +71,6 @@ public:
|
||||||
return slot_buffers[id];
|
return slot_buffers[id];
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] vk::BufferView& NullBufferView() {
|
|
||||||
return null_buffer_view;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Invalidates any buffer in the logical page range.
|
/// Invalidates any buffer in the logical page range.
|
||||||
void InvalidateMemory(VAddr device_addr, u64 size);
|
void InvalidateMemory(VAddr device_addr, u64 size);
|
||||||
|
|
||||||
|
@ -160,7 +156,6 @@ private:
|
||||||
std::shared_mutex mutex;
|
std::shared_mutex mutex;
|
||||||
Common::SlotVector<Buffer> slot_buffers;
|
Common::SlotVector<Buffer> slot_buffers;
|
||||||
RangeSet gpu_modified_ranges;
|
RangeSet gpu_modified_ranges;
|
||||||
vk::BufferView null_buffer_view;
|
|
||||||
MemoryTracker memory_tracker;
|
MemoryTracker memory_tracker;
|
||||||
PageTable page_table;
|
PageTable page_table;
|
||||||
};
|
};
|
||||||
|
|
|
@ -537,6 +537,7 @@ void Rasterizer::BindBuffers(const Shader::Info& stage, Shader::Backend::Binding
|
||||||
}
|
}
|
||||||
|
|
||||||
// Second pass to re-bind buffers that were updated after binding
|
// Second pass to re-bind buffers that were updated after binding
|
||||||
|
auto& null_buffer = buffer_cache.GetBuffer(VideoCore::NULL_BUFFER_ID);
|
||||||
for (u32 i = 0; i < buffer_bindings.size(); i++) {
|
for (u32 i = 0; i < buffer_bindings.size(); i++) {
|
||||||
const auto& [buffer_id, vsharp] = buffer_bindings[i];
|
const auto& [buffer_id, vsharp] = buffer_bindings[i];
|
||||||
const auto& desc = stage.buffers[i];
|
const auto& desc = stage.buffers[i];
|
||||||
|
@ -548,7 +549,6 @@ void Rasterizer::BindBuffers(const Shader::Info& stage, Shader::Backend::Binding
|
||||||
} else if (instance.IsNullDescriptorSupported()) {
|
} else if (instance.IsNullDescriptorSupported()) {
|
||||||
buffer_infos.emplace_back(VK_NULL_HANDLE, 0, VK_WHOLE_SIZE);
|
buffer_infos.emplace_back(VK_NULL_HANDLE, 0, VK_WHOLE_SIZE);
|
||||||
} else {
|
} else {
|
||||||
auto& null_buffer = buffer_cache.GetBuffer(VideoCore::NULL_BUFFER_ID);
|
|
||||||
buffer_infos.emplace_back(null_buffer.Handle(), 0, VK_WHOLE_SIZE);
|
buffer_infos.emplace_back(null_buffer.Handle(), 0, VK_WHOLE_SIZE);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -582,17 +582,19 @@ void Rasterizer::BindBuffers(const Shader::Info& stage, Shader::Backend::Binding
|
||||||
++binding.buffer;
|
++binding.buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto null_buffer_view =
|
|
||||||
instance.IsNullDescriptorSupported() ? VK_NULL_HANDLE : buffer_cache.NullBufferView();
|
|
||||||
for (u32 i = 0; i < texbuffer_bindings.size(); i++) {
|
for (u32 i = 0; i < texbuffer_bindings.size(); i++) {
|
||||||
const auto& [buffer_id, vsharp] = texbuffer_bindings[i];
|
const auto& [buffer_id, vsharp] = texbuffer_bindings[i];
|
||||||
const auto& desc = stage.texture_buffers[i];
|
const auto& desc = stage.texture_buffers[i];
|
||||||
vk::BufferView& buffer_view = buffer_views.emplace_back(null_buffer_view);
|
// Fallback format for null buffer view; never used in valid buffer case.
|
||||||
|
const auto data_fmt = vsharp.GetDataFmt() != AmdGpu::DataFormat::FormatInvalid
|
||||||
|
? vsharp.GetDataFmt()
|
||||||
|
: AmdGpu::DataFormat::Format8;
|
||||||
|
const u32 fmt_stride = AmdGpu::NumBits(data_fmt) >> 3;
|
||||||
|
vk::BufferView buffer_view;
|
||||||
if (buffer_id) {
|
if (buffer_id) {
|
||||||
const u32 alignment = instance.TexelBufferMinAlignment();
|
const u32 alignment = instance.TexelBufferMinAlignment();
|
||||||
const auto [vk_buffer, offset] = buffer_cache.ObtainBuffer(
|
const auto [vk_buffer, offset] = buffer_cache.ObtainBuffer(
|
||||||
vsharp.base_address, vsharp.GetSize(), desc.is_written, true, buffer_id);
|
vsharp.base_address, vsharp.GetSize(), desc.is_written, true, buffer_id);
|
||||||
const u32 fmt_stride = AmdGpu::NumBits(vsharp.GetDataFmt()) >> 3;
|
|
||||||
const u32 buf_stride = vsharp.GetStride();
|
const u32 buf_stride = vsharp.GetStride();
|
||||||
ASSERT_MSG(buf_stride % fmt_stride == 0,
|
ASSERT_MSG(buf_stride % fmt_stride == 0,
|
||||||
"Texel buffer stride must match format stride");
|
"Texel buffer stride must match format stride");
|
||||||
|
@ -600,9 +602,8 @@ void Rasterizer::BindBuffers(const Shader::Info& stage, Shader::Backend::Binding
|
||||||
const u32 adjust = offset - offset_aligned;
|
const u32 adjust = offset - offset_aligned;
|
||||||
ASSERT(adjust % fmt_stride == 0);
|
ASSERT(adjust % fmt_stride == 0);
|
||||||
push_data.AddTexelOffset(binding.buffer, buf_stride / fmt_stride, adjust / fmt_stride);
|
push_data.AddTexelOffset(binding.buffer, buf_stride / fmt_stride, adjust / fmt_stride);
|
||||||
buffer_view =
|
buffer_view = vk_buffer->View(offset_aligned, vsharp.GetSize() + adjust,
|
||||||
vk_buffer->View(offset_aligned, vsharp.GetSize() + adjust, desc.is_written,
|
desc.is_written, data_fmt, vsharp.GetNumberFmt());
|
||||||
vsharp.GetDataFmt(), vsharp.GetNumberFmt());
|
|
||||||
if (auto barrier =
|
if (auto barrier =
|
||||||
vk_buffer->GetBarrier(desc.is_written ? vk::AccessFlagBits2::eShaderWrite
|
vk_buffer->GetBarrier(desc.is_written ? vk::AccessFlagBits2::eShaderWrite
|
||||||
: vk::AccessFlagBits2::eShaderRead,
|
: vk::AccessFlagBits2::eShaderRead,
|
||||||
|
@ -612,6 +613,11 @@ void Rasterizer::BindBuffers(const Shader::Info& stage, Shader::Backend::Binding
|
||||||
if (desc.is_written) {
|
if (desc.is_written) {
|
||||||
texture_cache.InvalidateMemoryFromGPU(vsharp.base_address, vsharp.GetSize());
|
texture_cache.InvalidateMemoryFromGPU(vsharp.base_address, vsharp.GetSize());
|
||||||
}
|
}
|
||||||
|
} else if (instance.IsNullDescriptorSupported()) {
|
||||||
|
buffer_view = VK_NULL_HANDLE;
|
||||||
|
} else {
|
||||||
|
buffer_view =
|
||||||
|
null_buffer.View(0, fmt_stride, desc.is_written, data_fmt, vsharp.GetNumberFmt());
|
||||||
}
|
}
|
||||||
|
|
||||||
set_writes.push_back({
|
set_writes.push_back({
|
||||||
|
@ -621,7 +627,7 @@ void Rasterizer::BindBuffers(const Shader::Info& stage, Shader::Backend::Binding
|
||||||
.descriptorCount = 1,
|
.descriptorCount = 1,
|
||||||
.descriptorType = desc.is_written ? vk::DescriptorType::eStorageTexelBuffer
|
.descriptorType = desc.is_written ? vk::DescriptorType::eStorageTexelBuffer
|
||||||
: vk::DescriptorType::eUniformTexelBuffer,
|
: vk::DescriptorType::eUniformTexelBuffer,
|
||||||
.pTexelBufferView = &buffer_view,
|
.pTexelBufferView = &buffer_views.emplace_back(buffer_view),
|
||||||
});
|
});
|
||||||
++binding.buffer;
|
++binding.buffer;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue