Common: Fix issues in utility classes for readbacks

This commit is contained in:
Connor McLaughlin 2019-11-14 16:57:58 +10:00
parent 4bab3bffc0
commit 878a76e258
4 changed files with 23 additions and 13 deletions

View file

@ -14,7 +14,7 @@ StagingTexture::~StagingTexture()
bool StagingTexture::Create(ID3D11Device* device, u32 width, u32 height, DXGI_FORMAT format, bool for_uploading)
{
CD3D11_TEXTURE2D_DESC desc(format, width, height, 1, 1, 0, for_uploading ? D3D11_USAGE_DYNAMIC : D3D11_USAGE_STAGING,
0, 1, 0, 0);
for_uploading ? D3D11_CPU_ACCESS_WRITE : D3D11_CPU_ACCESS_READ, 1, 0, 0);
ComPtr<ID3D11Texture2D> texture;
const HRESULT tex_hr = device->CreateTexture2D(&desc, nullptr, texture.GetAddressOf());
@ -54,6 +54,7 @@ void StagingTexture::Unmap(ID3D11DeviceContext* context)
{
Assert(IsMapped());
context->Unmap(m_texture.Get(), 0);
m_map = {};
}
void StagingTexture::CopyToTexture(ID3D11DeviceContext* context, u32 src_x, u32 src_y, ID3D11Texture2D* dst_texture,
@ -88,4 +89,4 @@ void StagingTexture::CopyFromTexture(ID3D11DeviceContext* context, ID3D11Texture
context->CopySubresourceRegion(m_texture.Get(), 0, dst_x, dst_y, 0, src_texture, src_subresource, &box);
}
} // namespace D3D
} // namespace D3D11

View file

@ -54,18 +54,18 @@ public:
{
const u8* src_ptr = static_cast<u8*>(m_map.pData) + (y * m_map.RowPitch) + (x * sizeof(T));
u8* dst_ptr = reinterpret_cast<u8*>(data);
if (m_map.RowPitch != stride)
if (m_map.RowPitch != (sizeof(T) * stride))
{
for (u32 row = 0; row < height; row++)
{
std::memcpy(dst_ptr, src_ptr, sizeof(T) * width);
src_ptr += m_map.RowPitch;
dst_ptr += stride;
dst_ptr += sizeof(T) * stride;
}
}
else
{
std::memcpy(dst_ptr, src_ptr, stride * height);
std::memcpy(dst_ptr, src_ptr, (sizeof(T) * stride) * height);
}
}
@ -74,18 +74,18 @@ public:
{
const u8* src_ptr = reinterpret_cast<const u8*>(data);
u8* dst_ptr = static_cast<u8*>(m_map.pData) + (y * m_map.RowPitch) + (x * sizeof(T));
if (m_map.RowPitch != stride)
if (m_map.RowPitch != (sizeof(T) * stride))
{
for (u32 row = 0; row < height; row++)
{
std::memcpy(dst_ptr, src_ptr, sizeof(T) * width);
src_ptr += stride;
src_ptr += sizeof(T) * stride;
dst_ptr += m_map.RowPitch;
}
}
else
{
std::memcpy(dst_ptr, src_ptr, stride * height);
std::memcpy(dst_ptr, src_ptr, (sizeof(T) * stride) * height);
}
}

View file

@ -1,5 +1,6 @@
#pragma once
#include <algorithm>
#include <cassert>
#include <type_traits>
template<typename T, std::size_t SIZE>
@ -15,7 +16,7 @@ public:
using const_pointer = const T*;
using this_type = HeapArray<T, SIZE>;
HeapArray() { m_data = new T[size]; }
HeapArray() { m_data = new T[SIZE]; }
HeapArray(const this_type& copy)
{
@ -44,8 +45,16 @@ public:
const_pointer cbegin() const { return m_data; }
const_pointer cend() const { return m_data + SIZE; }
const_reference operator[](size_type index) const { return m_data[index]; }
reference operator[](size_type index) { return m_data[index]; }
const_reference operator[](size_type index) const
{
assert(index < SIZE);
return m_data[index];
}
reference operator[](size_type index)
{
assert(index < SIZE);
return m_data[index];
}
const_reference front() const { return m_data[0]; }
const_reference back() const { return m_data[SIZE - 1]; }
@ -71,7 +80,7 @@ public:
}
#define RELATIONAL_OPERATOR(op) \
bool operator op (const this_type& rhs) const \
bool operator op(const this_type& rhs) const \
{ \
for (size_type i = 0; i < SIZE; i++) \
{ \

View file

@ -96,7 +96,7 @@ struct Rectangle
right op## = amount; \
bottom op## = amount; \
} \
constexpr Rectangle operator op(const T amount) \
constexpr Rectangle operator op(const T amount) const \
{ \
return Rectangle(left op amount, top op amount, right op amount, bottom op amount); \
}