summaryrefslogtreecommitdiffstats
path: root/src/video_core/rasterizer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/video_core/rasterizer.cpp')
-rw-r--r--src/video_core/rasterizer.cpp54
1 files changed, 43 insertions, 11 deletions
diff --git a/src/video_core/rasterizer.cpp b/src/video_core/rasterizer.cpp
index 5861c1926..dd46f0ec3 100644
--- a/src/video_core/rasterizer.cpp
+++ b/src/video_core/rasterizer.cpp
@@ -91,7 +91,7 @@ static const Math::Vec4<u8> GetPixel(int x, int y) {
}
return {};
- }
+}
static u32 GetDepth(int x, int y) {
const PAddr addr = registers.framebuffer.GetDepthBufferPhysicalAddress();
@@ -100,23 +100,55 @@ static u32 GetDepth(int x, int y) {
y = (registers.framebuffer.height - y);
const u32 coarse_y = y & ~7;
- u32 stride = registers.framebuffer.width * 2;
-
- // Assuming 16-bit depth buffer format until actual format handling is implemented
- return *(u16*)(depth_buffer + VideoCore::GetMortonOffset(x, y, 2) + coarse_y * stride);
+ 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) {
+ case Pica::Regs::DepthFormat::D16:
+ return Color::DecodeD16(src_pixel);
+ case Pica::Regs::DepthFormat::D24:
+ return Color::DecodeD24(src_pixel);
+ case Pica::Regs::DepthFormat::D24S8:
+ return Color::DecodeD24S8(src_pixel).x;
+ default:
+ LOG_CRITICAL(HW_GPU, "Unimplemented depth format %u", registers.framebuffer.depth_format);
+ UNIMPLEMENTED();
+ return 0;
+ }
}
-static void SetDepth(int x, int y, u16 value) {
+static void SetDepth(int x, int y, u32 value) {
const PAddr addr = registers.framebuffer.GetDepthBufferPhysicalAddress();
u8* depth_buffer = Memory::GetPointer(PAddrToVAddr(addr));
y = (registers.framebuffer.height - y);
const u32 coarse_y = y & ~7;
- u32 stride = registers.framebuffer.width * 2;
-
- // Assuming 16-bit depth buffer format until actual format handling is implemented
- *(u16*)(depth_buffer + VideoCore::GetMortonOffset(x, y, 2) + coarse_y * stride) = value;
+ 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) {
+ case Pica::Regs::DepthFormat::D16:
+ Color::EncodeD16(value, dst_pixel);
+ break;
+ case Pica::Regs::DepthFormat::D24:
+ Color::EncodeD24(value, dst_pixel);
+ break;
+ case Pica::Regs::DepthFormat::D24S8:
+ // TODO(Subv): Implement the stencil buffer
+ Color::EncodeD24S8(value, 0, dst_pixel);
+ break;
+ default:
+ LOG_CRITICAL(HW_GPU, "Unimplemented depth format %u", registers.framebuffer.depth_format);
+ UNIMPLEMENTED();
+ break;
+ }
}
// NOTE: Assuming that rasterizer coordinates are 12.4 fixed-point values
@@ -595,7 +627,7 @@ static void ProcessTriangleInternal(const VertexShader::OutputVertex& v0,
u16 z = (u16)((v0.screenpos[2].ToFloat32() * w0 +
v1.screenpos[2].ToFloat32() * w1 +
v2.screenpos[2].ToFloat32() * w2) * 65535.f / wsum);
- u16 ref_z = GetDepth(x >> 4, y >> 4);
+ u32 ref_z = GetDepth(x >> 4, y >> 4);
bool pass = false;