summaryrefslogtreecommitdiff
path: root/src/video_core/rasterizer.cpp
diff options
context:
space:
mode:
authorGravatar bunnei2015-03-09 22:06:30 -0400
committerGravatar bunnei2015-03-09 22:06:30 -0400
commitec5bc54575c03bed67e712a0508ee55c06ec652c (patch)
tree0b12d5fe048826ab8411b2ebc38e9200f44c35ab /src/video_core/rasterizer.cpp
parentMerge pull request #647 from neobrain/rip_culling_hack (diff)
parentGPU: Added the stencil test structure to the Pica Regs struct. (diff)
downloadyuzu-ec5bc54575c03bed67e712a0508ee55c06ec652c.tar.gz
yuzu-ec5bc54575c03bed67e712a0508ee55c06ec652c.tar.xz
yuzu-ec5bc54575c03bed67e712a0508ee55c06ec652c.zip
Merge pull request #643 from Subv/dem_feels
GPU: Implemented more depth buffer formats.
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) {
91 } 91 }
92 92
93 return {}; 93 return {};
94 } 94}
95 95
96static u32 GetDepth(int x, int y) { 96static u32 GetDepth(int x, int y) {
97 const PAddr addr = registers.framebuffer.GetDepthBufferPhysicalAddress(); 97 const PAddr addr = registers.framebuffer.GetDepthBufferPhysicalAddress();
@@ -100,23 +100,55 @@ static u32 GetDepth(int x, int y) {
100 y = (registers.framebuffer.height - y); 100 y = (registers.framebuffer.height - y);
101 101
102 const u32 coarse_y = y & ~7; 102 const u32 coarse_y = y & ~7;
103 u32 stride = registers.framebuffer.width * 2; 103 u32 bytes_per_pixel = Pica::Regs::BytesPerDepthPixel(registers.framebuffer.depth_format);
104 104 u32 stride = registers.framebuffer.width * bytes_per_pixel;
105 // Assuming 16-bit depth buffer format until actual format handling is implemented 105
106 return *(u16*)(depth_buffer + VideoCore::GetMortonOffset(x, y, 2) + coarse_y * stride); 106 u32 src_offset = VideoCore::GetMortonOffset(x, y, bytes_per_pixel) + coarse_y * stride;
107 u8* src_pixel = depth_buffer + src_offset;
108
109 switch (registers.framebuffer.depth_format) {
110 case Pica::Regs::DepthFormat::D16:
111 return Color::DecodeD16(src_pixel);
112 case Pica::Regs::DepthFormat::D24:
113 return Color::DecodeD24(src_pixel);
114 case Pica::Regs::DepthFormat::D24S8:
115 return Color::DecodeD24S8(src_pixel).x;
116 default:
117 LOG_CRITICAL(HW_GPU, "Unimplemented depth format %u", registers.framebuffer.depth_format);
118 UNIMPLEMENTED();
119 return 0;
120 }
107} 121}
108 122
109static void SetDepth(int x, int y, u16 value) { 123static void SetDepth(int x, int y, u32 value) {
110 const PAddr addr = registers.framebuffer.GetDepthBufferPhysicalAddress(); 124 const PAddr addr = registers.framebuffer.GetDepthBufferPhysicalAddress();
111 u8* depth_buffer = Memory::GetPointer(PAddrToVAddr(addr)); 125 u8* depth_buffer = Memory::GetPointer(PAddrToVAddr(addr));
112 126
113 y = (registers.framebuffer.height - y); 127 y = (registers.framebuffer.height - y);
114 128
115 const u32 coarse_y = y & ~7; 129 const u32 coarse_y = y & ~7;
116 u32 stride = registers.framebuffer.width * 2; 130 u32 bytes_per_pixel = Pica::Regs::BytesPerDepthPixel(registers.framebuffer.depth_format);
117 131 u32 stride = registers.framebuffer.width * bytes_per_pixel;
118 // Assuming 16-bit depth buffer format until actual format handling is implemented 132
119 *(u16*)(depth_buffer + VideoCore::GetMortonOffset(x, y, 2) + coarse_y * stride) = value; 133 u32 dst_offset = VideoCore::GetMortonOffset(x, y, bytes_per_pixel) + coarse_y * stride;
134 u8* dst_pixel = depth_buffer + dst_offset;
135
136 switch (registers.framebuffer.depth_format) {
137 case Pica::Regs::DepthFormat::D16:
138 Color::EncodeD16(value, dst_pixel);
139 break;
140 case Pica::Regs::DepthFormat::D24:
141 Color::EncodeD24(value, dst_pixel);
142 break;
143 case Pica::Regs::DepthFormat::D24S8:
144 // TODO(Subv): Implement the stencil buffer
145 Color::EncodeD24S8(value, 0, dst_pixel);
146 break;
147 default:
148 LOG_CRITICAL(HW_GPU, "Unimplemented depth format %u", registers.framebuffer.depth_format);
149 UNIMPLEMENTED();
150 break;
151 }
120} 152}
121 153
122// NOTE: Assuming that rasterizer coordinates are 12.4 fixed-point values 154// NOTE: Assuming that rasterizer coordinates are 12.4 fixed-point values
@@ -595,7 +627,7 @@ static void ProcessTriangleInternal(const VertexShader::OutputVertex& v0,
595 u16 z = (u16)((v0.screenpos[2].ToFloat32() * w0 + 627 u16 z = (u16)((v0.screenpos[2].ToFloat32() * w0 +
596 v1.screenpos[2].ToFloat32() * w1 + 628 v1.screenpos[2].ToFloat32() * w1 +
597 v2.screenpos[2].ToFloat32() * w2) * 65535.f / wsum); 629 v2.screenpos[2].ToFloat32() * w2) * 65535.f / wsum);
598 u16 ref_z = GetDepth(x >> 4, y >> 4); 630 u32 ref_z = GetDepth(x >> 4, y >> 4);
599 631
600 bool pass = false; 632 bool pass = false;
601 633