GPU: Added the stencil test structure to the Pica Regs struct.
This commit is contained in:
parent
155cc80e3b
commit
1248e291f0
|
@ -176,7 +176,7 @@ void GraphicsFramebufferWidget::OnUpdate()
|
||||||
{
|
{
|
||||||
// TODO: Store a reference to the registers in the debug context instead of accessing them directly...
|
// TODO: Store a reference to the registers in the debug context instead of accessing them directly...
|
||||||
|
|
||||||
auto framebuffer = Pica::registers.framebuffer;
|
const auto& framebuffer = Pica::registers.framebuffer;
|
||||||
|
|
||||||
framebuffer_address = framebuffer.GetColorBufferPhysicalAddress();
|
framebuffer_address = framebuffer.GetColorBufferPhysicalAddress();
|
||||||
framebuffer_width = framebuffer.GetWidth();
|
framebuffer_width = framebuffer.GetWidth();
|
||||||
|
@ -189,7 +189,7 @@ void GraphicsFramebufferWidget::OnUpdate()
|
||||||
|
|
||||||
case Source::DepthBuffer:
|
case Source::DepthBuffer:
|
||||||
{
|
{
|
||||||
auto framebuffer = Pica::registers.framebuffer;
|
const auto& framebuffer = Pica::registers.framebuffer;
|
||||||
|
|
||||||
framebuffer_address = framebuffer.GetDepthBufferPhysicalAddress();
|
framebuffer_address = framebuffer.GetDepthBufferPhysicalAddress();
|
||||||
framebuffer_width = framebuffer.GetWidth();
|
framebuffer_width = framebuffer.GetWidth();
|
||||||
|
|
|
@ -20,9 +20,9 @@ class GraphicsFramebufferWidget : public BreakPointObserverDock {
|
||||||
using Event = Pica::DebugContext::Event;
|
using Event = Pica::DebugContext::Event;
|
||||||
|
|
||||||
enum class Source {
|
enum class Source {
|
||||||
PicaTarget = 0,
|
PicaTarget = 0,
|
||||||
DepthBuffer = 1,
|
DepthBuffer = 1,
|
||||||
Custom = 2,
|
Custom = 2,
|
||||||
|
|
||||||
// TODO: Add GPU framebuffer sources!
|
// TODO: Add GPU framebuffer sources!
|
||||||
};
|
};
|
||||||
|
|
|
@ -81,9 +81,9 @@ inline void Write(u32 addr, const T data) {
|
||||||
if (config.fill_24bit) {
|
if (config.fill_24bit) {
|
||||||
// fill with 24-bit values
|
// fill with 24-bit values
|
||||||
for (u8* ptr = start; ptr < end; ptr += 3) {
|
for (u8* ptr = start; ptr < end; ptr += 3) {
|
||||||
ptr[0] = config.value_24bit_r;
|
ptr[0] = config.value_24bit_b;
|
||||||
ptr[1] = config.value_24bit_g;
|
ptr[1] = config.value_24bit_g;
|
||||||
ptr[2] = config.value_24bit_b;
|
ptr[2] = config.value_24bit_r;
|
||||||
}
|
}
|
||||||
} else if (config.fill_32bit) {
|
} else if (config.fill_32bit) {
|
||||||
// fill with 32-bit values
|
// fill with 32-bit values
|
||||||
|
|
|
@ -100,10 +100,10 @@ struct Regs {
|
||||||
// Set to 1 upon completion.
|
// Set to 1 upon completion.
|
||||||
BitField<0, 1, u32> finished;
|
BitField<0, 1, u32> finished;
|
||||||
|
|
||||||
// If both of these bits are unset, then it will fill the memory with a 16 bit value
|
// 0: fill with 16- or 32-bit wide values; 1: fill with 24-bit wide values
|
||||||
// 1: fill with 24-bit wide values
|
|
||||||
BitField<8, 1, u32> fill_24bit;
|
BitField<8, 1, u32> fill_24bit;
|
||||||
// 1: fill with 32-bit wide values
|
|
||||||
|
// 0: fill with 16-bit wide values; 1: fill with 32-bit wide values
|
||||||
BitField<9, 1, u32> fill_32bit;
|
BitField<9, 1, u32> fill_32bit;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -105,7 +105,7 @@ inline const Math::Vec4<u8> DecodeRGBA4(const u8* bytes) {
|
||||||
* @param bytes Pointer to encoded source value
|
* @param bytes Pointer to encoded source value
|
||||||
* @return Depth value as an u32
|
* @return Depth value as an u32
|
||||||
*/
|
*/
|
||||||
inline const u32 DecodeD16(const u8* bytes) {
|
inline u32 DecodeD16(const u8* bytes) {
|
||||||
return *reinterpret_cast<const u16_le*>(bytes);
|
return *reinterpret_cast<const u16_le*>(bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,7 +114,7 @@ inline const u32 DecodeD16(const u8* bytes) {
|
||||||
* @param bytes Pointer to encoded source value
|
* @param bytes Pointer to encoded source value
|
||||||
* @return Depth value as an u32
|
* @return Depth value as an u32
|
||||||
*/
|
*/
|
||||||
inline const u32 DecodeD24(const u8* bytes) {
|
inline u32 DecodeD24(const u8* bytes) {
|
||||||
return (bytes[2] << 16) | (bytes[1] << 8) | bytes[0];
|
return (bytes[2] << 16) | (bytes[1] << 8) | bytes[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -181,8 +181,8 @@ inline void EncodeRGBA4(const Math::Vec4<u8>& color, u8* bytes) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encode a depth value as D16 format
|
* Encode a 16 bit depth value as D16 format
|
||||||
* @param value Source depth value to encode
|
* @param value 16 bit source depth value to encode
|
||||||
* @param bytes Pointer where to store the encoded value
|
* @param bytes Pointer where to store the encoded value
|
||||||
*/
|
*/
|
||||||
inline void EncodeD16(u32 value, u8* bytes) {
|
inline void EncodeD16(u32 value, u8* bytes) {
|
||||||
|
@ -190,8 +190,8 @@ inline void EncodeD16(u32 value, u8* bytes) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encode a depth value as D24 format
|
* Encode a 24 bit depth value as D24 format
|
||||||
* @param value Source depth value to encode
|
* @param value 24 bit source depth value to encode
|
||||||
* @param bytes Pointer where to store the encoded value
|
* @param bytes Pointer where to store the encoded value
|
||||||
*/
|
*/
|
||||||
inline void EncodeD24(u32 value, u8* bytes) {
|
inline void EncodeD24(u32 value, u8* bytes) {
|
||||||
|
@ -201,9 +201,9 @@ inline void EncodeD24(u32 value, u8* bytes) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encode depth and stencil values as D24S8 format
|
* Encode a 24 bit depth and 8 bit stencil values as D24S8 format
|
||||||
* @param depth Source depth values to encode
|
* @param depth 24 bit source depth value to encode
|
||||||
* @param stencil Source stencil value to encode
|
* @param stencil 8 bit source stencil value to encode
|
||||||
* @param bytes Pointer where to store the encoded value
|
* @param bytes Pointer where to store the encoded value
|
||||||
*/
|
*/
|
||||||
inline void EncodeD24S8(u32 depth, u8 stencil, u8* bytes) {
|
inline void EncodeD24S8(u32 depth, u8 stencil, u8* bytes) {
|
||||||
|
|
|
@ -393,7 +393,15 @@ struct Regs {
|
||||||
BitField< 8, 8, u32> ref;
|
BitField< 8, 8, u32> ref;
|
||||||
} alpha_test;
|
} alpha_test;
|
||||||
|
|
||||||
INSERT_PADDING_WORDS(0x2);
|
union {
|
||||||
|
BitField< 0, 1, u32> stencil_test_enable;
|
||||||
|
BitField< 4, 3, CompareFunc> stencil_test_func;
|
||||||
|
BitField< 8, 8, u32> stencil_replacement_value;
|
||||||
|
BitField<16, 8, u32> stencil_reference_value;
|
||||||
|
BitField<24, 8, u32> stencil_mask;
|
||||||
|
} stencil_test;
|
||||||
|
|
||||||
|
INSERT_PADDING_WORDS(0x1);
|
||||||
|
|
||||||
union {
|
union {
|
||||||
BitField< 0, 1, u32> depth_test_enable;
|
BitField< 0, 1, u32> depth_test_enable;
|
||||||
|
@ -408,6 +416,30 @@ struct Regs {
|
||||||
INSERT_PADDING_WORDS(0x8);
|
INSERT_PADDING_WORDS(0x8);
|
||||||
} output_merger;
|
} output_merger;
|
||||||
|
|
||||||
|
enum DepthFormat : u32 {
|
||||||
|
D16 = 0,
|
||||||
|
|
||||||
|
D24 = 2,
|
||||||
|
D24S8 = 3
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns the number of bytes in the specified depth format
|
||||||
|
*/
|
||||||
|
static u32 BytesPerDepthPixel(DepthFormat format) {
|
||||||
|
switch (format) {
|
||||||
|
case DepthFormat::D16:
|
||||||
|
return 2;
|
||||||
|
case DepthFormat::D24:
|
||||||
|
return 3;
|
||||||
|
case DepthFormat::D24S8:
|
||||||
|
return 4;
|
||||||
|
default:
|
||||||
|
LOG_CRITICAL(HW_GPU, "Unknown depth format %u", format);
|
||||||
|
UNIMPLEMENTED();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
// Components are laid out in reverse byte order, most significant bits first.
|
// Components are laid out in reverse byte order, most significant bits first.
|
||||||
enum ColorFormat : u32 {
|
enum ColorFormat : u32 {
|
||||||
|
@ -418,16 +450,9 @@ struct Regs {
|
||||||
RGBA4 = 4,
|
RGBA4 = 4,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum DepthFormat : u32 {
|
|
||||||
D16 = 0,
|
|
||||||
|
|
||||||
D24 = 2,
|
|
||||||
D24S8 = 3
|
|
||||||
};
|
|
||||||
|
|
||||||
INSERT_PADDING_WORDS(0x6);
|
INSERT_PADDING_WORDS(0x6);
|
||||||
|
|
||||||
u32 depth_format;
|
DepthFormat depth_format;
|
||||||
BitField<16, 3, u32> color_format;
|
BitField<16, 3, u32> color_format;
|
||||||
|
|
||||||
INSERT_PADDING_WORDS(0x4);
|
INSERT_PADDING_WORDS(0x4);
|
||||||
|
|
|
@ -100,24 +100,19 @@ static u32 GetDepth(int x, int y) {
|
||||||
y = (registers.framebuffer.height - y);
|
y = (registers.framebuffer.height - y);
|
||||||
|
|
||||||
const u32 coarse_y = y & ~7;
|
const u32 coarse_y = y & ~7;
|
||||||
|
u32 bytes_per_pixel = Pica::Regs::BytesPerDepthPixel(registers.framebuffer.depth_format);
|
||||||
|
u32 stride = registers.framebuffer.width * bytes_per_pixel;
|
||||||
|
|
||||||
|
u32 src_offset = VideoCore::GetMortonOffset(x, y, bytes_per_pixel) + coarse_y * stride;
|
||||||
|
u8* src_pixel = depth_buffer + src_offset;
|
||||||
|
|
||||||
switch (registers.framebuffer.depth_format) {
|
switch (registers.framebuffer.depth_format) {
|
||||||
case registers.framebuffer.D16:
|
case Pica::Regs::DepthFormat::D16:
|
||||||
{
|
return Color::DecodeD16(src_pixel);
|
||||||
u32 stride = registers.framebuffer.width * 2;
|
case Pica::Regs::DepthFormat::D24:
|
||||||
return Color::DecodeD16(depth_buffer + VideoCore::GetMortonOffset(x, y, 2) + coarse_y * stride);
|
return Color::DecodeD24(src_pixel);
|
||||||
}
|
case Pica::Regs::DepthFormat::D24S8:
|
||||||
case registers.framebuffer.D24:
|
return Color::DecodeD24S8(src_pixel).x;
|
||||||
{
|
|
||||||
u32 stride = registers.framebuffer.width * 3;
|
|
||||||
u8* address = depth_buffer + VideoCore::GetMortonOffset(x, y, 3) + coarse_y * stride;
|
|
||||||
return Color::DecodeD24(address);
|
|
||||||
}
|
|
||||||
case registers.framebuffer.D24S8:
|
|
||||||
{
|
|
||||||
u32 stride = registers.framebuffer.width * 4;
|
|
||||||
return Color::DecodeD24S8(depth_buffer + VideoCore::GetMortonOffset(x, y, 4) + coarse_y * stride).x;
|
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
LOG_CRITICAL(HW_GPU, "Unimplemented depth format %u", registers.framebuffer.depth_format);
|
LOG_CRITICAL(HW_GPU, "Unimplemented depth format %u", registers.framebuffer.depth_format);
|
||||||
UNIMPLEMENTED();
|
UNIMPLEMENTED();
|
||||||
|
@ -132,28 +127,23 @@ static void SetDepth(int x, int y, u32 value) {
|
||||||
y = (registers.framebuffer.height - y);
|
y = (registers.framebuffer.height - y);
|
||||||
|
|
||||||
const u32 coarse_y = y & ~7;
|
const u32 coarse_y = y & ~7;
|
||||||
|
u32 bytes_per_pixel = Pica::Regs::BytesPerDepthPixel(registers.framebuffer.depth_format);
|
||||||
|
u32 stride = registers.framebuffer.width * bytes_per_pixel;
|
||||||
|
|
||||||
|
u32 dst_offset = VideoCore::GetMortonOffset(x, y, bytes_per_pixel) + coarse_y * stride;
|
||||||
|
u8* dst_pixel = depth_buffer + dst_offset;
|
||||||
|
|
||||||
switch (registers.framebuffer.depth_format) {
|
switch (registers.framebuffer.depth_format) {
|
||||||
case registers.framebuffer.D16:
|
case Pica::Regs::DepthFormat::D16:
|
||||||
{
|
Color::EncodeD16(value, dst_pixel);
|
||||||
u32 stride = registers.framebuffer.width * 2;
|
|
||||||
Color::EncodeD16(value, depth_buffer + VideoCore::GetMortonOffset(x, y, 2) + coarse_y * stride);
|
|
||||||
break;
|
break;
|
||||||
}
|
case Pica::Regs::DepthFormat::D24:
|
||||||
case registers.framebuffer.D24:
|
Color::EncodeD24(value, dst_pixel);
|
||||||
{
|
|
||||||
u32 stride = registers.framebuffer.width * 3;
|
|
||||||
u8* address = depth_buffer + VideoCore::GetMortonOffset(x, y, 3) + coarse_y * stride;
|
|
||||||
Color::EncodeD24(value, address);
|
|
||||||
break;
|
break;
|
||||||
}
|
case Pica::Regs::DepthFormat::D24S8:
|
||||||
case registers.framebuffer.D24S8:
|
|
||||||
{
|
|
||||||
u32 stride = registers.framebuffer.width * 4;
|
|
||||||
// TODO(Subv): Implement the stencil buffer
|
// TODO(Subv): Implement the stencil buffer
|
||||||
Color::EncodeD24S8(value, 0, depth_buffer + VideoCore::GetMortonOffset(x, y, 4) + coarse_y * stride);
|
Color::EncodeD24S8(value, 0, dst_pixel);
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
LOG_CRITICAL(HW_GPU, "Unimplemented depth format %u", registers.framebuffer.depth_format);
|
LOG_CRITICAL(HW_GPU, "Unimplemented depth format %u", registers.framebuffer.depth_format);
|
||||||
UNIMPLEMENTED();
|
UNIMPLEMENTED();
|
||||||
|
|
Loading…
Reference in New Issue