Skip to content

Commit

Permalink
Merge pull request #1249 from vlj/d3d12-fix
Browse files Browse the repository at this point in the history
Fix d3d12 build.
  • Loading branch information
DHrpcs3 committed Oct 13, 2015
2 parents 97a6774 + ff01e26 commit bbfca3f
Show file tree
Hide file tree
Showing 18 changed files with 600 additions and 866 deletions.
37 changes: 20 additions & 17 deletions rpcs3/Emu/RSX/Common/BufferUtils.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "stdafx.h"
#ifdef DX12_SUPPORT
#include "BufferUtils.h"


Expand All @@ -13,20 +12,22 @@ bool overlaps(const std::pair<size_t, size_t> &range1, const std::pair<size_t, s
return !(range1.second < range2.first || range2.second < range1.first);
}

std::vector<VertexBufferFormat> FormatVertexData(const RSXVertexData *m_vertex_data, size_t *vertex_data_size, size_t base_offset)
std::vector<VertexBufferFormat> FormatVertexData(const rsx::data_array_format_info *vertex_array_desc, const std::vector<u8> *vertex_data, size_t *vertex_data_size, size_t base_offset)
{
std::vector<VertexBufferFormat> Result;
for (size_t i = 0; i < 32; ++i)
for (size_t i = 0; i < rsx::limits::vertex_count; ++i)
{
const RSXVertexData &vertexData = m_vertex_data[i];
if (!vertexData.IsEnabled()) continue;
const rsx::data_array_format_info &vertexData = vertex_array_desc[i];
if (!vertexData.size) continue;

size_t elementCount = ((vertexData.addr) ? vertex_data_size[i] : m_vertex_data[i].data.size()) / (vertexData.size * vertexData.GetTypeSize());
u32 addrRegVal = rsx::method_registers[NV4097_SET_VERTEX_DATA_ARRAY_OFFSET + i];
u32 addr = rsx::get_address(addrRegVal & 0x7fffffff, addrRegVal >> 31);
size_t elementCount = ((vertexData.array) ? vertex_data_size[i] : vertex_data[i].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 start = vertexData.addr + base_offset;
size_t elementSize = rsx::get_vertex_type_size(vertexData.type);
size_t start = 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);
assert(start < end);
Expand Down Expand Up @@ -54,21 +55,24 @@ std::vector<VertexBufferFormat> FormatVertexData(const RSXVertexData *m_vertex_d
return Result;
}

void uploadVertexData(const VertexBufferFormat &vbf, const RSXVertexData *vertexData, size_t baseOffset, void* bufferMap)
void uploadVertexData(const VertexBufferFormat &vbf, const rsx::data_array_format_info *vertex_array_desc, const std::vector<u8> *vertex_data, size_t baseOffset, void* bufferMap)
{
for (int vertex = 0; vertex < vbf.elementCount; vertex++)
{
for (size_t attributeId : vbf.attributeId)
{
if (!vertexData[attributeId].addr)
u32 addrRegVal = rsx::method_registers[NV4097_SET_VERTEX_DATA_ARRAY_OFFSET + attributeId];
u32 addr = rsx::get_address(addrRegVal & 0x7fffffff, addrRegVal >> 31);

if (!vertex_array_desc[attributeId].array)
{
memcpy(bufferMap, vertexData[attributeId].data.data(), vertexData[attributeId].data.size());
memcpy(bufferMap, vertex_data[attributeId].data(), vertex_data[attributeId].size());
continue;
}
size_t offset = (size_t)vertexData[attributeId].addr + baseOffset - vbf.range.first;
size_t tsize = vertexData[attributeId].GetTypeSize();
size_t size = vertexData[attributeId].size;
auto src = vm::get_ptr<const u8>(vertexData[attributeId].addr + (u32)baseOffset + (u32)vbf.stride * vertex);
size_t offset = (size_t)addr + baseOffset - vbf.range.first;
size_t tsize = rsx::get_vertex_type_size(vertex_array_desc[attributeId].type);
size_t size = vertex_array_desc[attributeId].size;
auto src = vm::get_ptr<const u8>(addr + (u32)baseOffset + (u32)vbf.stride * vertex);
char* dst = (char*)bufferMap + offset + vbf.stride * vertex;

switch (tsize)
Expand Down Expand Up @@ -244,5 +248,4 @@ void uploadIndexData(unsigned m_draw_mode, unsigned index_type, void* indexBuffe
return;
}
}
}
#endif
}
8 changes: 3 additions & 5 deletions rpcs3/Emu/RSX/Common/BufferUtils.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#ifdef DX12_SUPPORT
#pragma once
#include <vector>
#include "Emu/Memory/vm.h"
Expand All @@ -18,12 +17,12 @@ struct VertexBufferFormat
* Detect buffer containing interleaved vertex attribute.
* This minimizes memory upload size.
*/
std::vector<VertexBufferFormat> FormatVertexData(const RSXVertexData *m_vertex_data, size_t *vertex_data_size, size_t base_offset);
std::vector<VertexBufferFormat> FormatVertexData(const rsx::data_array_format_info *vertex_array_desc, const std::vector<u8> *vertex_data, size_t *vertex_data_size, size_t base_offset);

/*
* Write vertex attributes to bufferMap, swapping data as required.
*/
void uploadVertexData(const VertexBufferFormat &vbf, const RSXVertexData *vertexData, size_t baseOffset, void* bufferMap);
void uploadVertexData(const VertexBufferFormat &vbf, const rsx::data_array_format_info *vertex_array_desc, const std::vector<u8> *vertex_data, size_t baseOffset, void* bufferMap);

/*
* If primitive mode is not supported and need to be emulated (using an index buffer) returns false.
Expand All @@ -38,5 +37,4 @@ size_t getIndexCount(unsigned m_draw_mode, unsigned initial_index_count);
/*
* Write index information to bufferMap
*/
void uploadIndexData(unsigned m_draw_mode, unsigned index_type, void* indexBuffer, void* bufferMap, unsigned element_count);
#endif
void uploadIndexData(unsigned m_draw_mode, unsigned index_type, void* indexBuffer, void* bufferMap, unsigned element_count);
69 changes: 18 additions & 51 deletions rpcs3/Emu/RSX/Common/TextureUtils.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "stdafx.h"
#ifdef DX12_SUPPORT
#include "Emu/Memory/vm.h"
#include "TextureUtils.h"
#include "../RSXThread.h"
Expand All @@ -8,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
*/
Expand Down Expand Up @@ -102,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;
Expand Down Expand Up @@ -177,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;
Expand Down Expand Up @@ -264,12 +232,12 @@ write16bX4TexelsGeneric(const char *src, char *dst, size_t widthInBlock, size_t
}


size_t getPlacedTextureStorageSpace(const RSXTexture &texture, size_t rowPitchAlignement)
size_t getPlacedTextureStorageSpace(const rsx::texture &texture, size_t rowPitchAlignement)
{
size_t w = texture.GetWidth(), h = texture.GetHeight();
size_t w = texture.width(), h = texture.height();

size_t blockSizeInByte, blockWidthInPixel, blockHeightInPixel;
int format = texture.GetFormat() & ~(CELL_GCM_TEXTURE_LN | CELL_GCM_TEXTURE_UN);
int format = texture.format() & ~(CELL_GCM_TEXTURE_LN | CELL_GCM_TEXTURE_UN);

switch (format)
{
Expand Down Expand Up @@ -391,11 +359,11 @@ size_t getPlacedTextureStorageSpace(const RSXTexture &texture, size_t rowPitchAl
return rowPitch * heightInBlocks * 2; // * 2 for mipmap levels
}

std::vector<MipmapLevelInfo> uploadPlacedTexture(const RSXTexture &texture, size_t rowPitchAlignement, void* textureData)
std::vector<MipmapLevelInfo> uploadPlacedTexture(const rsx::texture &texture, size_t rowPitchAlignement, void* textureData)
{
size_t w = texture.GetWidth(), h = texture.GetHeight();
size_t w = texture.width(), h = texture.height();

int format = texture.GetFormat() & ~(CELL_GCM_TEXTURE_LN | CELL_GCM_TEXTURE_UN);
int format = texture.format() & ~(CELL_GCM_TEXTURE_LN | CELL_GCM_TEXTURE_UN);

size_t blockSizeInByte, blockWidthInPixel, blockHeightInPixel;
switch (format)
Expand Down Expand Up @@ -515,32 +483,31 @@ std::vector<MipmapLevelInfo> uploadPlacedTexture(const RSXTexture &texture, size

std::vector<MipmapLevelInfo> mipInfos;

const u32 texaddr = GetAddress(texture.GetOffset(), texture.GetLocation());
const u32 texaddr = rsx::get_address(texture.offset(), texture.location());
auto pixels = vm::get_ptr<const u8>(texaddr);
bool is_swizzled = !(texture.GetFormat() & CELL_GCM_TEXTURE_LN);
bool is_swizzled = !(texture.format() & CELL_GCM_TEXTURE_LN);
switch (format)
{
case CELL_GCM_TEXTURE_A8R8G8B8:
if (is_swizzled)
return writeTexelsSwizzled((char*)pixels, (char*)textureData, w, h, 4, texture.GetMipmap());
return writeTexelsSwizzled((char*)pixels, (char*)textureData, w, h, 4, texture.mipmap());
else
return writeTexelsGeneric((char*)pixels, (char*)textureData, w, h, 4, texture.GetMipmap());
return writeTexelsGeneric((char*)pixels, (char*)textureData, w, h, 4, texture.mipmap());
case CELL_GCM_TEXTURE_A1R5G5B5:
case CELL_GCM_TEXTURE_A4R4G4B4:
case CELL_GCM_TEXTURE_R5G6B5:
if (is_swizzled)
return write16bTexelsSwizzled((char*)pixels, (char*)textureData, w, h, 2, texture.GetMipmap());
return write16bTexelsSwizzled((char*)pixels, (char*)textureData, w, h, 2, texture.mipmap());
else
return write16bTexelsGeneric((char*)pixels, (char*)textureData, w, h, 2, texture.GetMipmap());
return write16bTexelsGeneric((char*)pixels, (char*)textureData, w, h, 2, texture.mipmap());
case CELL_GCM_TEXTURE_W16_Z16_Y16_X16_FLOAT:
return write16bX4TexelsGeneric((char*)pixels, (char*)textureData, w, h, 8, texture.GetMipmap());
return write16bX4TexelsGeneric((char*)pixels, (char*)textureData, w, h, 8, texture.mipmap());
case CELL_GCM_TEXTURE_COMPRESSED_DXT1:
case CELL_GCM_TEXTURE_COMPRESSED_DXT23:
case CELL_GCM_TEXTURE_COMPRESSED_DXT45:
return writeCompressedTexel((char*)pixels, (char*)textureData, widthInBlocks, blockWidthInPixel, heightInBlocks, blockHeightInPixel, blockSizeInByte, texture.GetMipmap());
return writeCompressedTexel((char*)pixels, (char*)textureData, widthInBlocks, blockWidthInPixel, heightInBlocks, blockHeightInPixel, blockSizeInByte, texture.mipmap());
default:
return writeTexelsGeneric((char*)pixels, (char*)textureData, w, h, blockSizeInByte, texture.GetMipmap());
return writeTexelsGeneric((char*)pixels, (char*)textureData, w, h, blockSizeInByte, texture.mipmap());
}

}
#endif
}
4 changes: 1 addition & 3 deletions rpcs3/Emu/RSX/Common/TextureUtils.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#pragma once
#ifdef DX12_SUPPORT
#include "../RSXTexture.h"
#include <vector>

Expand All @@ -22,5 +21,4 @@ size_t getPlacedTextureStorageSpace(const rsx::texture &texture, size_t rowPitch
* Data are not packed, they are stored per rows using rowPitchAlignement.
* Similarly, offset for every mipmaplevel is aligned to rowPitchAlignement boundary.
*/
std::vector<MipmapLevelInfo> uploadPlacedTexture(const rsx::texture &texture, size_t rowPitchAlignement, void* textureData);
#endif
std::vector<MipmapLevelInfo> uploadPlacedTexture(const rsx::texture &texture, size_t rowPitchAlignement, void* textureData);

0 comments on commit bbfca3f

Please sign in to comment.