move linear to swizzle and get_size_type

symbol undef though
This commit is contained in:
Vincent Lejeune 2015-10-08 17:07:23 +02:00
parent 3de47c201c
commit 6f71d04aa4
7 changed files with 76 additions and 71 deletions

View File

@ -20,11 +20,11 @@ std::vector<VertexBufferFormat> FormatVertexData(const RSXVertexData *m_vertex_d
const RSXVertexData &vertexData = m_vertex_data[i];
if (!vertexData.IsEnabled()) continue;
size_t elementCount = ((vertexData.addr) ? vertex_data_size[i] : m_vertex_data[i].data.size()) / (vertexData.size * vertexData.GetTypeSize());
size_t elementCount = ((vertexData.addr) ? vertex_data_size[i] : m_vertex_data[i].data.size()) / (vertexData.size * rsx::get_vertex_type_size(vertexData.type));
// If there is a single element, stride is 0, use the size of element instead
size_t stride = vertexData.stride;
size_t elementSize = vertexData.GetTypeSize();
size_t elementSize = rsx::get_vertex_type_size(vertexData.type);
size_t start = vertexData.addr + base_offset;
size_t end = start + elementSize * vertexData.size + (elementCount - 1) * stride - 1;
std::pair<size_t, size_t> range = std::make_pair(start, end);
@ -65,7 +65,7 @@ void uploadVertexData(const VertexBufferFormat &vbf, const RSXVertexData *vertex
continue;
}
size_t offset = (size_t)vertexData[attributeId].addr + baseOffset - vbf.range.first;
size_t tsize = vertexData[attributeId].GetTypeSize();
size_t tsize = rsx::get_vertex_type_size(vertexData[attributeId].type);
size_t size = vertexData[attributeId].size;
auto src = vm::get_ptr<const u8>(vertexData[attributeId].addr + (u32)baseOffset + (u32)vbf.stride * vertex);
char* dst = (char*)bufferMap + offset + vbf.stride * vertex;

View File

@ -7,37 +7,6 @@
#define MAX2(a, b) ((a) > (b)) ? (a) : (b)
unsigned LinearToSwizzleAddress(unsigned x, unsigned y, unsigned z, unsigned log2_width, unsigned log2_height, unsigned log2_depth)
{
unsigned offset = 0;
unsigned shift_count = 0;
while (log2_width | log2_height | log2_depth) {
if (log2_width)
{
offset |= (x & 0x01) << shift_count;
x >>= 1;
++shift_count;
--log2_width;
}
if (log2_height)
{
offset |= (y & 0x01) << shift_count;
y >>= 1;
++shift_count;
--log2_height;
}
if (log2_depth)
{
offset |= (z & 0x01) << shift_count;
z >>= 1;
++shift_count;
--log2_depth;
}
}
return offset;
}
/**
* Write data, assume src pixels are packed but not mipmaplevel
*/
@ -101,7 +70,7 @@ writeTexelsSwizzled(const char *src, char *dst, size_t widthInBlock, size_t heig
for (int row = 0; row < currentHeight; row++)
for (int j = 0; j < currentWidth; j++)
castedDst[(row * rowPitch / 4) + j] = castedSrc[LinearToSwizzleAddress(j, row, 0, log2width, log2height, 0)];
castedDst[(row * rowPitch / 4) + j] = castedSrc[rsx::linear_to_swizzle(j, row, 0, log2width, log2height, 0)];
offsetInDst += currentHeight * rowPitch;
offsetInSrc += currentHeight * widthInBlock * blockSize;
@ -176,7 +145,7 @@ write16bTexelsSwizzled(const char *src, char *dst, size_t widthInBlock, size_t h
for (int row = 0; row < currentHeight; row++)
for (int j = 0; j < currentWidth; j++)
castedDst[(row * rowPitch / 2) + j] = castedSrc[LinearToSwizzleAddress(j, row, 0, log2width, log2height, 0)];
castedDst[(row * rowPitch / 2) + j] = castedSrc[rsx::linear_to_swizzle(j, row, 0, log2width, log2height, 0)];
offsetInDst += currentHeight * rowPitch;
offsetInSrc += currentHeight * widthInBlock * blockSize;

View File

@ -10,8 +10,6 @@ struct MipmapLevelInfo
size_t rowPitch;
};
unsigned LinearToSwizzleAddress(unsigned x, unsigned y, unsigned z, unsigned log2_width, unsigned log2_height, unsigned log2_depth);
/**
* Get size to store texture in a linear fashion.
* Storage is assumed to use a rowPitchAlignement boundary for every row of texture.

View File

@ -399,7 +399,7 @@ void D3D12GSRender::Draw()
if (!m_vertex_data[i].IsEnabled()) continue;
if (!m_vertex_data[i].addr) continue;
const u32 tsize = m_vertex_data[i].GetTypeSize();
const u32 tsize = rsx::get_vertex_type_size(m_vertex_data[i].type);
m_vertexBufferSize[i] = (m_indexed_array.index_min + m_indexed_array.index_max - m_indexed_array.index_min + 1) * tsize * m_vertex_data[i].size;
}
}
@ -410,7 +410,7 @@ void D3D12GSRender::Draw()
if (!m_vertex_data[i].IsEnabled()) continue;
if (!m_vertex_data[i].addr) continue;
const u32 tsize = m_vertex_data[i].GetTypeSize();
const u32 tsize = rsx::get_vertex_type_size(m_vertex_data[i].type);
m_vertexBufferSize[i] = (draw_array_first + draw_array_count) * tsize * m_vertex_data[i].size;
}
}

View File

@ -182,7 +182,7 @@ void GLTexture::Init(rsx::texture& tex)
{
for (int j = 0; j < tex.width(); j++)
{
dst[(i * tex.width()) + j] = src[LinearToSwizzleAddress(j, i, 0, log2width, log2height, 0)];
dst[(i * tex.width()) + j] = src[rsx::linear_to_swizzle(j, i, 0, log2width, log2height, 0)];
}
}
}
@ -841,7 +841,7 @@ void GLGSRender::EnableVertexData(bool indexed_draw)
offset_list[i] = cur_offset;
if (!m_vertex_data[i].IsEnabled()) continue;
const size_t item_size = m_vertex_data[i].GetTypeSize() * m_vertex_data[i].size;
const size_t item_size = rsx::get_vertex_type_size(m_vertex_data[i].type) * m_vertex_data[i].size;
const size_t data_size = m_vertex_data[i].data.size() - data_offset * item_size;
const u32 pos = m_vdata.size();
@ -1654,7 +1654,7 @@ void GLGSRender::Draw()
if (!i.size)
continue;
u32 vertex_size = i.data.size() / (i.size * i.GetTypeSize());
u32 vertex_size = i.data.size() / (i.size * rsx::get_vertex_type_size(i.type));
if (min_vertex_size > vertex_size)
min_vertex_size = vertex_size;

View File

@ -28,29 +28,66 @@ namespace rsx
{
u32 method_registers[0x10000 >> 2];
u32 linear_to_swizzle(u32 x, u32 y, u32 z, u32 log2_width, u32 log2_height, u32 log2_depth)
{
u32 offset = 0;
u32 shift_count = 0;
while (log2_width | log2_height | log2_depth)
{
if (log2_width)
{
offset |= (x & 0x01) << shift_count;
x >>= 1;
++shift_count;
--log2_width;
}
if (log2_height)
{
offset |= (y & 0x01) << shift_count;
y >>= 1;
++shift_count;
--log2_height;
}
if (log2_depth)
{
offset |= (z & 0x01) << shift_count;
z >>= 1;
++shift_count;
--log2_depth;
}
}
return offset;
}
u32 get_address(u32 offset, u32 location)
{
u32 res = 0;
switch (location)
{
case CELL_GCM_CONTEXT_DMA_MEMORY_FRAME_BUFFER:
case CELL_GCM_LOCATION_LOCAL:
{
//TODO: don't use not named constants like 0xC0000000
res = 0xC0000000 + offset;
break;
}
case CELL_GCM_CONTEXT_DMA_MEMORY_HOST_BUFFER:
case CELL_GCM_LOCATION_MAIN:
{
res = RSXIOMem.RealAddr(offset); // TODO: Error Check?
res = (u32)RSXIOMem.RealAddr(offset); // TODO: Error Check?
if (res == 0)
{
throw EXCEPTION("RSXIO memory not mapped (offset=0x%x)", offset);
throw fmt::format("GetAddress(offset=0x%x, location=0x%x): RSXIO memory not mapped", offset, location);
}
if (Emu.GetGSManager().GetRender().strict_ordering[offset >> 20])
{
_mm_mfence(); // probably doesn't have any effect on current implementation
}
//if (Emu.GetGSManager().GetRender().strict_ordering[offset >> 20])
//{
// _mm_mfence(); // probably doesn't have any effect on current implementation
//}
break;
}
@ -62,6 +99,25 @@ namespace rsx
return res;
}
u32 get_vertex_type_size(u32 type)
{
switch (type)
{
case CELL_GCM_VERTEX_S1: return sizeof(u16);
case CELL_GCM_VERTEX_F: return sizeof(f32);
case CELL_GCM_VERTEX_SF: return sizeof(f16);
case CELL_GCM_VERTEX_UB: return sizeof(u8);
case CELL_GCM_VERTEX_S32K: return sizeof(u32);
case CELL_GCM_VERTEX_CMP: return sizeof(u32);
case CELL_GCM_VERTEX_UB256: return sizeof(u8) * 4;
default:
LOG_ERROR(RSX, "RSXVertexData::GetTypeSize: Bad vertex data type (%d)!", type);
assert(0);
return 1;
}
}
}
RSXVertexData::RSXVertexData()
@ -88,7 +144,7 @@ void RSXVertexData::Load(u32 start, u32 count, u32 baseOffset, u32 baseIndex = 0
{
if (!addr) return;
const u32 tsize = GetTypeSize();
const u32 tsize = rsx::get_vertex_type_size(type);
data.resize((start + count) * tsize * size);
@ -124,24 +180,6 @@ void RSXVertexData::Load(u32 start, u32 count, u32 baseOffset, u32 baseIndex = 0
}
}
u32 RSXVertexData::GetTypeSize() const
{
switch (type)
{
case CELL_GCM_VERTEX_S1: return 2;
case CELL_GCM_VERTEX_F: return 4;
case CELL_GCM_VERTEX_SF: return 2;
case CELL_GCM_VERTEX_UB: return 1;
case CELL_GCM_VERTEX_S32K: return 2;
case CELL_GCM_VERTEX_CMP: return 4;
case CELL_GCM_VERTEX_UB256: return 1;
default:
LOG_ERROR(RSX, "RSXVertexData::GetTypeSize: Bad vertex data type (%d)!", type);
return 1;
}
}
u32 RSXThread::OutOfArgsCount(const uint x, const u32 cmd, const u32 count, const u32 args_addr)
{
auto args = vm::ps3::ptr<u32>::make(args_addr);
@ -1038,7 +1076,7 @@ void RSXThread::DoCmd(const u32 fcmd, const u32 cmd, const u32 args_addr, const
if (!i.size)
continue;
u32 vertex_size = i.data.size() / (i.size * i.GetTypeSize());
u32 vertex_size = i.data.size() / (i.size * rsx::get_vertex_type_size(i.type));
if (min_vertex_size > vertex_size)
min_vertex_size = vertex_size;

View File

@ -29,7 +29,9 @@ namespace rsx
extern u32 method_registers[0x10000 >> 2];
u32 get_address(u32 offset, u32 location);
u32 linear_to_swizzle(u32 x, u32 y, u32 z, u32 log2_width, u32 log2_height, u32 log2_depth);
u32 get_vertex_type_size(u32 type);
}
enum Method
@ -56,8 +58,6 @@ struct RSXVertexData
void Reset();
bool IsEnabled() const { return size > 0; }
void Load(u32 start, u32 count, u32 baseOffset, u32 baseIndex);
u32 GetTypeSize() const;
};
struct RSXIndexArrayData