Created
March 8, 2015 22:32
-
-
Save Subv/872bb1fce41fb9263e64 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/video_core/rasterizer.cpp b/src/video_core/rasterizer.cpp | |
index 5861c19..41a2048 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,66 @@ 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); | |
+ switch (registers.framebuffer.depth_format) { | |
+ case registers.framebuffer.DEPTH16: | |
+ { | |
+ u32 stride = registers.framebuffer.width * 2; | |
+ return *(u16_le*)(depth_buffer + VideoCore::GetMortonOffset(x, y, 2) + coarse_y * stride); | |
+ } | |
+ case registers.framebuffer.DEPTH24: | |
+ { | |
+ u32 stride = registers.framebuffer.width * 3; | |
+ u8* address = depth_buffer + VideoCore::GetMortonOffset(x, y, 3) + coarse_y * stride; | |
+ return (address[2] << 16) | (address[1] << 8) | address[0]; | |
+ } | |
+ case registers.framebuffer.DEPTH24_STENCIL8: | |
+ { | |
+ u32 stride = registers.framebuffer.width * 4; | |
+ return *(u32_le*)(depth_buffer + VideoCore::GetMortonOffset(x, y, 4) + coarse_y * stride); | |
+ } | |
+ 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; | |
+ switch (registers.framebuffer.depth_format) { | |
+ case registers.framebuffer.DEPTH16: | |
+ { | |
+ u32 stride = registers.framebuffer.width * 2; | |
+ *(u16_le*)(depth_buffer + VideoCore::GetMortonOffset(x, y, 2) + coarse_y * stride) = value; | |
+ break; | |
+ } | |
+ case registers.framebuffer.DEPTH24: | |
+ { | |
+ u32 stride = registers.framebuffer.width * 3; | |
+ u8* address = depth_buffer + VideoCore::GetMortonOffset(x, y, 3) + coarse_y * stride; | |
+ address[0] = value & 0xFF; | |
+ address[1] = (value >> 8) & 0xFF; | |
+ address[2] = (value >> 16) & 0xFF; | |
+ break; | |
+ } | |
+ case registers.framebuffer.DEPTH24_STENCIL8: | |
+ { | |
+ u32 stride = registers.framebuffer.width * 4; | |
+ *(u32_le*)(depth_buffer + VideoCore::GetMortonOffset(x, y, 4) + coarse_y * stride) = value; | |
+ 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 +638,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; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment