Make GetVertexBuffer return a pointer to the requested buffer

This avoids a redundancy in the `Draw` function and makes code easier to read
This commit is contained in:
lynxnb 2022-04-20 01:19:04 +02:00
parent 5c3559e888
commit bcaf7dfe1c

View File

@ -1726,19 +1726,19 @@ namespace skyline::gpu::interconnect {
} }
} }
BufferView GetVertexBuffer(size_t index) { VertexBuffer *GetVertexBuffer(size_t index) {
auto &vertexBuffer{vertexBuffers.at(index)}; auto &vertexBuffer{vertexBuffers.at(index)};
if (vertexBuffer.start > vertexBuffer.end || vertexBuffer.start == 0 || vertexBuffer.end == 0) if (vertexBuffer.start > vertexBuffer.end || vertexBuffer.start == 0 || vertexBuffer.end == 0)
return nullptr; return nullptr;
else if (vertexBuffer.view) else if (vertexBuffer.view)
return vertexBuffer.view; return &vertexBuffer;
auto mappings{channelCtx.asCtx->gmmu.TranslateRange(vertexBuffer.start, (vertexBuffer.end + 1) - vertexBuffer.start)}; auto mappings{channelCtx.asCtx->gmmu.TranslateRange(vertexBuffer.start, (vertexBuffer.end + 1) - vertexBuffer.start)};
if (mappings.size() != 1) if (mappings.size() != 1)
Logger::Warn("Multiple buffer mappings ({}) are not supported", mappings.size()); Logger::Warn("Multiple buffer mappings ({}) are not supported", mappings.size());
vertexBuffer.view = gpu.buffer.FindOrCreate(mappings.front(), executor.cycle); vertexBuffer.view = gpu.buffer.FindOrCreate(mappings.front(), executor.cycle);
return vertexBuffer.view; return &vertexBuffer;
} }
/* Input Assembly */ /* Input Assembly */
@ -2619,12 +2619,12 @@ namespace skyline::gpu::interconnect {
boost::container::static_vector<vk::VertexInputBindingDivisorDescriptionEXT, maxwell3d::VertexBufferCount> vertexBindingDivisorsDescriptions{}; boost::container::static_vector<vk::VertexInputBindingDivisorDescriptionEXT, maxwell3d::VertexBufferCount> vertexBindingDivisorsDescriptions{};
for (u32 index{}; index < maxwell3d::VertexBufferCount; index++) { for (u32 index{}; index < maxwell3d::VertexBufferCount; index++) {
auto vertexBufferView{GetVertexBuffer(index)}; auto vertexBuffer{GetVertexBuffer(index)};
if (vertexBufferView) { if (vertexBuffer) {
auto &vertexBuffer{vertexBuffers[index]}; auto &vertexBufferView{vertexBuffer->view};
vertexBindingDescriptions.push_back(vertexBuffer.bindingDescription); vertexBindingDescriptions.push_back(vertexBuffer->bindingDescription);
if (vertexBuffer.bindingDescription.inputRate == vk::VertexInputRate::eInstance) if (vertexBuffer->bindingDescription.inputRate == vk::VertexInputRate::eInstance)
vertexBindingDivisorsDescriptions.push_back(vertexBuffer.bindingDivisorDescription); vertexBindingDivisorsDescriptions.push_back(vertexBuffer->bindingDivisorDescription);
std::scoped_lock vertexBufferLock(vertexBufferView); std::scoped_lock vertexBufferLock(vertexBufferView);
vertexBufferView.RegisterUsage([handle = boundVertexBuffers->handles.data() + index, offset = boundVertexBuffers->offsets.data() + index](const Buffer::BufferViewStorage &view, const std::shared_ptr<Buffer> &buffer) { vertexBufferView.RegisterUsage([handle = boundVertexBuffers->handles.data() + index, offset = boundVertexBuffers->offsets.data() + index](const Buffer::BufferViewStorage &view, const std::shared_ptr<Buffer> &buffer) {