Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VideoCommon: Use std::span for BoundingBox::Write() #12371

Merged
merged 1 commit into from Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions Source/Core/VideoBackends/D3D/D3DBoundingBox.cpp
Expand Up @@ -88,12 +88,12 @@ std::vector<BBoxType> D3DBoundingBox::Read(u32 index, u32 length)
return values;
}

void D3DBoundingBox::Write(u32 index, const std::vector<BBoxType>& values)
void D3DBoundingBox::Write(u32 index, std::span<const BBoxType> values)
{
D3D11_BOX box{index * sizeof(BBoxType),
0,
0,
static_cast<u32>(index + values.size()) * sizeof(BBoxType),
static_cast<u32>((index + values.size()) * sizeof(BBoxType)),
1,
1};
D3D::context->UpdateSubresource(m_buffer.Get(), 0, &box, values.data(), 0, 0);
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/VideoBackends/D3D/D3DBoundingBox.h
Expand Up @@ -19,7 +19,7 @@ class D3DBoundingBox final : public BoundingBox

protected:
std::vector<BBoxType> Read(u32 index, u32 length) override;
void Write(u32 index, const std::vector<BBoxType>& values) override;
void Write(u32 index, std::span<const BBoxType> values) override;

private:
ComPtr<ID3D11Buffer> m_buffer;
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/VideoBackends/D3D12/D3D12BoundingBox.cpp
Expand Up @@ -56,9 +56,9 @@ std::vector<BBoxType> D3D12BoundingBox::Read(u32 index, u32 length)
return values;
}

void D3D12BoundingBox::Write(u32 index, const std::vector<BBoxType>& values)
void D3D12BoundingBox::Write(u32 index, std::span<const BBoxType> values)
{
const u32 copy_size = static_cast<u32>(values.size()) * sizeof(BBoxType);
const u32 copy_size = static_cast<u32>(values.size() * sizeof(BBoxType));
if (!m_upload_buffer.ReserveMemory(copy_size, sizeof(BBoxType)))
{
WARN_LOG_FMT(VIDEO, "Executing command list while waiting for space in bbox stream buffer");
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/VideoBackends/D3D12/D3D12BoundingBox.h
Expand Up @@ -21,7 +21,7 @@ class D3D12BoundingBox final : public BoundingBox

protected:
std::vector<BBoxType> Read(u32 index, u32 length) override;
void Write(u32 index, const std::vector<BBoxType>& values) override;
void Write(u32 index, std::span<const BBoxType> values) override;

private:
static constexpr u32 BUFFER_SIZE = sizeof(BBoxType) * NUM_BBOX_VALUES;
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/VideoBackends/Metal/MTLBoundingBox.h
Expand Up @@ -18,7 +18,7 @@ class BoundingBox final : public ::BoundingBox

protected:
std::vector<BBoxType> Read(u32 index, u32 length) override;
void Write(u32 index, const std::vector<BBoxType>& values) override;
void Write(u32 index, std::span<const BBoxType> values) override;

private:
BBoxType* m_cpu_buffer_ptr;
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/VideoBackends/Metal/MTLBoundingBox.mm
Expand Up @@ -42,7 +42,7 @@
}
}

void Metal::BoundingBox::Write(u32 index, const std::vector<BBoxType>& values)
void Metal::BoundingBox::Write(u32 index, std::span<const BBoxType> values)
{
const u32 size = values.size() * sizeof(BBoxType);
if (!g_state_tracker->HasUnflushedData() && !g_state_tracker->GPUBusy())
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/VideoBackends/Null/NullBoundingBox.h
Expand Up @@ -19,7 +19,7 @@ class NullBoundingBox final : public BoundingBox
{
return std::vector<BBoxType>(length);
}
void Write(u32 index, const std::vector<BBoxType>& values) override {}
void Write(u32 index, std::span<const BBoxType> values) override {}
};

} // namespace Null
2 changes: 1 addition & 1 deletion Source/Core/VideoBackends/OGL/OGLBoundingBox.cpp
Expand Up @@ -66,7 +66,7 @@ std::vector<BBoxType> OGLBoundingBox::Read(u32 index, u32 length)
return values;
}

void OGLBoundingBox::Write(u32 index, const std::vector<BBoxType>& values)
void OGLBoundingBox::Write(u32 index, std::span<const BBoxType> values)
{
glBindBuffer(GL_SHADER_STORAGE_BUFFER, m_buffer_id);
glBufferSubData(GL_SHADER_STORAGE_BUFFER, sizeof(BBoxType) * index,
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/VideoBackends/OGL/OGLBoundingBox.h
Expand Up @@ -19,7 +19,7 @@ class OGLBoundingBox final : public BoundingBox

protected:
std::vector<BBoxType> Read(u32 index, u32 length) override;
void Write(u32 index, const std::vector<BBoxType>& values) override;
void Write(u32 index, std::span<const BBoxType> values) override;

private:
GLuint m_buffer_id = 0;
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/VideoBackends/Software/SWBoundingBox.cpp
Expand Up @@ -55,7 +55,7 @@ std::vector<BBoxType> SWBoundingBox::Read(u32 index, u32 length)
return values;
}

void SWBoundingBox::Write(u32 index, const std::vector<BBoxType>& values)
void SWBoundingBox::Write(u32 index, std::span<const BBoxType> values)
{
for (size_t i = 0; i < values.size(); i++)
{
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/VideoBackends/Software/SWBoundingBox.h
Expand Up @@ -37,7 +37,7 @@ class SWBoundingBox final : public BoundingBox

protected:
std::vector<BBoxType> Read(u32 index, u32 length) override;
void Write(u32 index, const std::vector<BBoxType>& values) override;
void Write(u32 index, std::span<const BBoxType> values) override;
};

} // namespace SW
5 changes: 2 additions & 3 deletions Source/Core/VideoBackends/Vulkan/VKBoundingBox.cpp
Expand Up @@ -77,7 +77,7 @@ std::vector<BBoxType> VKBoundingBox::Read(u32 index, u32 length)
return values;
}

void VKBoundingBox::Write(u32 index, const std::vector<BBoxType>& values)
void VKBoundingBox::Write(u32 index, std::span<const BBoxType> values)
{
// We can't issue vkCmdUpdateBuffer within a render pass.
// However, the writes must be serialized, so we can't put it in the init buffer.
Expand All @@ -91,8 +91,7 @@ void VKBoundingBox::Write(u32 index, const std::vector<BBoxType>& values)

// Write the values to the GPU buffer
vkCmdUpdateBuffer(g_command_buffer_mgr->GetCurrentCommandBuffer(), m_gpu_buffer,
index * sizeof(BBoxType), values.size() * sizeof(BBoxType),
reinterpret_cast<const BBoxType*>(values.data()));
index * sizeof(BBoxType), values.size() * sizeof(BBoxType), values.data());

// Restore fragment shader access to the buffer.
StagingBuffer::BufferMemoryBarrier(
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/VideoBackends/Vulkan/VKBoundingBox.h
Expand Up @@ -26,7 +26,7 @@ class VKBoundingBox final : public BoundingBox

protected:
std::vector<BBoxType> Read(u32 index, u32 length) override;
void Write(u32 index, const std::vector<BBoxType>& values) override;
void Write(u32 index, std::span<const BBoxType> values) override;

private:
bool CreateGPUBuffer();
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/VideoCommon/BoundingBox.cpp
Expand Up @@ -51,7 +51,7 @@ void BoundingBox::Flush()
for (u32 i = start; i < end; ++i)
m_dirty[i] = false;

Write(start, std::vector<BBoxType>(m_values.begin() + start, m_values.begin() + end));
Write(start, std::span(m_values.begin() + start, m_values.begin() + end));
}
}

Expand Down
4 changes: 2 additions & 2 deletions Source/Core/VideoCommon/BoundingBox.h
Expand Up @@ -5,6 +5,7 @@

#include <array>
#include <memory>
#include <span>
#include <vector>

#include "Common/CommonTypes.h"
Expand Down Expand Up @@ -38,8 +39,7 @@ class BoundingBox

protected:
virtual std::vector<BBoxType> Read(u32 index, u32 length) = 0;
// TODO: This can likely use std::span once we're on C++20
virtual void Write(u32 index, const std::vector<BBoxType>& values) = 0;
virtual void Write(u32 index, std::span<const BBoxType> values) = 0;

private:
void Readback();
Expand Down