mirror of
https://github.com/yuzu-mirror/yuzu
synced 2024-11-24 07:33:02 +00:00
VideoCore: Split framebuffer regs from Regs struct
This commit is contained in:
parent
9017093f58
commit
23713d5dee
11 changed files with 503 additions and 457 deletions
|
@ -414,30 +414,30 @@ void GraphicsSurfaceWidget::OnUpdate() {
|
||||||
// TODO: Store a reference to the registers in the debug context instead of accessing them
|
// TODO: Store a reference to the registers in the debug context instead of accessing them
|
||||||
// directly...
|
// directly...
|
||||||
|
|
||||||
const auto& framebuffer = Pica::g_state.regs.framebuffer;
|
const auto& framebuffer = Pica::g_state.regs.framebuffer.framebuffer;
|
||||||
|
|
||||||
surface_address = framebuffer.GetColorBufferPhysicalAddress();
|
surface_address = framebuffer.GetColorBufferPhysicalAddress();
|
||||||
surface_width = framebuffer.GetWidth();
|
surface_width = framebuffer.GetWidth();
|
||||||
surface_height = framebuffer.GetHeight();
|
surface_height = framebuffer.GetHeight();
|
||||||
|
|
||||||
switch (framebuffer.color_format) {
|
switch (framebuffer.color_format) {
|
||||||
case Pica::Regs::ColorFormat::RGBA8:
|
case Pica::FramebufferRegs::ColorFormat::RGBA8:
|
||||||
surface_format = Format::RGBA8;
|
surface_format = Format::RGBA8;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Pica::Regs::ColorFormat::RGB8:
|
case Pica::FramebufferRegs::ColorFormat::RGB8:
|
||||||
surface_format = Format::RGB8;
|
surface_format = Format::RGB8;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Pica::Regs::ColorFormat::RGB5A1:
|
case Pica::FramebufferRegs::ColorFormat::RGB5A1:
|
||||||
surface_format = Format::RGB5A1;
|
surface_format = Format::RGB5A1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Pica::Regs::ColorFormat::RGB565:
|
case Pica::FramebufferRegs::ColorFormat::RGB565:
|
||||||
surface_format = Format::RGB565;
|
surface_format = Format::RGB565;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Pica::Regs::ColorFormat::RGBA4:
|
case Pica::FramebufferRegs::ColorFormat::RGBA4:
|
||||||
surface_format = Format::RGBA4;
|
surface_format = Format::RGBA4;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -450,22 +450,22 @@ void GraphicsSurfaceWidget::OnUpdate() {
|
||||||
}
|
}
|
||||||
|
|
||||||
case Source::DepthBuffer: {
|
case Source::DepthBuffer: {
|
||||||
const auto& framebuffer = Pica::g_state.regs.framebuffer;
|
const auto& framebuffer = Pica::g_state.regs.framebuffer.framebuffer;
|
||||||
|
|
||||||
surface_address = framebuffer.GetDepthBufferPhysicalAddress();
|
surface_address = framebuffer.GetDepthBufferPhysicalAddress();
|
||||||
surface_width = framebuffer.GetWidth();
|
surface_width = framebuffer.GetWidth();
|
||||||
surface_height = framebuffer.GetHeight();
|
surface_height = framebuffer.GetHeight();
|
||||||
|
|
||||||
switch (framebuffer.depth_format) {
|
switch (framebuffer.depth_format) {
|
||||||
case Pica::Regs::DepthFormat::D16:
|
case Pica::FramebufferRegs::DepthFormat::D16:
|
||||||
surface_format = Format::D16;
|
surface_format = Format::D16;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Pica::Regs::DepthFormat::D24:
|
case Pica::FramebufferRegs::DepthFormat::D24:
|
||||||
surface_format = Format::D24;
|
surface_format = Format::D24;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Pica::Regs::DepthFormat::D24S8:
|
case Pica::FramebufferRegs::DepthFormat::D24S8:
|
||||||
surface_format = Format::D24X8;
|
surface_format = Format::D24X8;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -478,14 +478,14 @@ void GraphicsSurfaceWidget::OnUpdate() {
|
||||||
}
|
}
|
||||||
|
|
||||||
case Source::StencilBuffer: {
|
case Source::StencilBuffer: {
|
||||||
const auto& framebuffer = Pica::g_state.regs.framebuffer;
|
const auto& framebuffer = Pica::g_state.regs.framebuffer.framebuffer;
|
||||||
|
|
||||||
surface_address = framebuffer.GetDepthBufferPhysicalAddress();
|
surface_address = framebuffer.GetDepthBufferPhysicalAddress();
|
||||||
surface_width = framebuffer.GetWidth();
|
surface_width = framebuffer.GetWidth();
|
||||||
surface_height = framebuffer.GetHeight();
|
surface_height = framebuffer.GetHeight();
|
||||||
|
|
||||||
switch (framebuffer.depth_format) {
|
switch (framebuffer.depth_format) {
|
||||||
case Pica::Regs::DepthFormat::D24S8:
|
case Pica::FramebufferRegs::DepthFormat::D24S8:
|
||||||
surface_format = Format::X24S8;
|
surface_format = Format::X24S8;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@ set(HEADERS
|
||||||
primitive_assembly.h
|
primitive_assembly.h
|
||||||
rasterizer.h
|
rasterizer.h
|
||||||
rasterizer_interface.h
|
rasterizer_interface.h
|
||||||
|
regs_framebuffer.h
|
||||||
regs_rasterizer.h
|
regs_rasterizer.h
|
||||||
regs_texturing.h
|
regs_texturing.h
|
||||||
renderer_base.h
|
renderer_base.h
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "common/logging/log.h"
|
#include "common/logging/log.h"
|
||||||
#include "common/vector_math.h"
|
#include "common/vector_math.h"
|
||||||
|
#include "video_core/regs_framebuffer.h"
|
||||||
#include "video_core/regs_rasterizer.h"
|
#include "video_core/regs_rasterizer.h"
|
||||||
#include "video_core/regs_texturing.h"
|
#include "video_core/regs_texturing.h"
|
||||||
|
|
||||||
|
@ -51,268 +52,7 @@ struct Regs {
|
||||||
INSERT_PADDING_WORDS(0x2f);
|
INSERT_PADDING_WORDS(0x2f);
|
||||||
RasterizerRegs rasterizer;
|
RasterizerRegs rasterizer;
|
||||||
TexturingRegs texturing;
|
TexturingRegs texturing;
|
||||||
|
FramebufferRegs framebuffer;
|
||||||
enum class LogicOp : u32 {
|
|
||||||
Clear = 0,
|
|
||||||
And = 1,
|
|
||||||
AndReverse = 2,
|
|
||||||
Copy = 3,
|
|
||||||
Set = 4,
|
|
||||||
CopyInverted = 5,
|
|
||||||
NoOp = 6,
|
|
||||||
Invert = 7,
|
|
||||||
Nand = 8,
|
|
||||||
Or = 9,
|
|
||||||
Nor = 10,
|
|
||||||
Xor = 11,
|
|
||||||
Equiv = 12,
|
|
||||||
AndInverted = 13,
|
|
||||||
OrReverse = 14,
|
|
||||||
OrInverted = 15,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class BlendEquation : u32 {
|
|
||||||
Add = 0,
|
|
||||||
Subtract = 1,
|
|
||||||
ReverseSubtract = 2,
|
|
||||||
Min = 3,
|
|
||||||
Max = 4,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class BlendFactor : u32 {
|
|
||||||
Zero = 0,
|
|
||||||
One = 1,
|
|
||||||
SourceColor = 2,
|
|
||||||
OneMinusSourceColor = 3,
|
|
||||||
DestColor = 4,
|
|
||||||
OneMinusDestColor = 5,
|
|
||||||
SourceAlpha = 6,
|
|
||||||
OneMinusSourceAlpha = 7,
|
|
||||||
DestAlpha = 8,
|
|
||||||
OneMinusDestAlpha = 9,
|
|
||||||
ConstantColor = 10,
|
|
||||||
OneMinusConstantColor = 11,
|
|
||||||
ConstantAlpha = 12,
|
|
||||||
OneMinusConstantAlpha = 13,
|
|
||||||
SourceAlphaSaturate = 14,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class CompareFunc : u32 {
|
|
||||||
Never = 0,
|
|
||||||
Always = 1,
|
|
||||||
Equal = 2,
|
|
||||||
NotEqual = 3,
|
|
||||||
LessThan = 4,
|
|
||||||
LessThanOrEqual = 5,
|
|
||||||
GreaterThan = 6,
|
|
||||||
GreaterThanOrEqual = 7,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class StencilAction : u32 {
|
|
||||||
Keep = 0,
|
|
||||||
Zero = 1,
|
|
||||||
Replace = 2,
|
|
||||||
Increment = 3,
|
|
||||||
Decrement = 4,
|
|
||||||
Invert = 5,
|
|
||||||
IncrementWrap = 6,
|
|
||||||
DecrementWrap = 7,
|
|
||||||
};
|
|
||||||
|
|
||||||
struct {
|
|
||||||
union {
|
|
||||||
// If false, logic blending is used
|
|
||||||
BitField<8, 1, u32> alphablend_enable;
|
|
||||||
};
|
|
||||||
|
|
||||||
union {
|
|
||||||
BitField<0, 8, BlendEquation> blend_equation_rgb;
|
|
||||||
BitField<8, 8, BlendEquation> blend_equation_a;
|
|
||||||
|
|
||||||
BitField<16, 4, BlendFactor> factor_source_rgb;
|
|
||||||
BitField<20, 4, BlendFactor> factor_dest_rgb;
|
|
||||||
|
|
||||||
BitField<24, 4, BlendFactor> factor_source_a;
|
|
||||||
BitField<28, 4, BlendFactor> factor_dest_a;
|
|
||||||
} alpha_blending;
|
|
||||||
|
|
||||||
union {
|
|
||||||
BitField<0, 4, LogicOp> logic_op;
|
|
||||||
};
|
|
||||||
|
|
||||||
union {
|
|
||||||
u32 raw;
|
|
||||||
BitField<0, 8, u32> r;
|
|
||||||
BitField<8, 8, u32> g;
|
|
||||||
BitField<16, 8, u32> b;
|
|
||||||
BitField<24, 8, u32> a;
|
|
||||||
} blend_const;
|
|
||||||
|
|
||||||
union {
|
|
||||||
BitField<0, 1, u32> enable;
|
|
||||||
BitField<4, 3, CompareFunc> func;
|
|
||||||
BitField<8, 8, u32> ref;
|
|
||||||
} alpha_test;
|
|
||||||
|
|
||||||
struct {
|
|
||||||
union {
|
|
||||||
// Raw value of this register
|
|
||||||
u32 raw_func;
|
|
||||||
|
|
||||||
// If true, enable stencil testing
|
|
||||||
BitField<0, 1, u32> enable;
|
|
||||||
|
|
||||||
// Comparison operation for stencil testing
|
|
||||||
BitField<4, 3, CompareFunc> func;
|
|
||||||
|
|
||||||
// Mask used to control writing to the stencil buffer
|
|
||||||
BitField<8, 8, u32> write_mask;
|
|
||||||
|
|
||||||
// Value to compare against for stencil testing
|
|
||||||
BitField<16, 8, u32> reference_value;
|
|
||||||
|
|
||||||
// Mask to apply on stencil test inputs
|
|
||||||
BitField<24, 8, u32> input_mask;
|
|
||||||
};
|
|
||||||
|
|
||||||
union {
|
|
||||||
// Raw value of this register
|
|
||||||
u32 raw_op;
|
|
||||||
|
|
||||||
// Action to perform when the stencil test fails
|
|
||||||
BitField<0, 3, StencilAction> action_stencil_fail;
|
|
||||||
|
|
||||||
// Action to perform when stencil testing passed but depth testing fails
|
|
||||||
BitField<4, 3, StencilAction> action_depth_fail;
|
|
||||||
|
|
||||||
// Action to perform when both stencil and depth testing pass
|
|
||||||
BitField<8, 3, StencilAction> action_depth_pass;
|
|
||||||
};
|
|
||||||
} stencil_test;
|
|
||||||
|
|
||||||
union {
|
|
||||||
BitField<0, 1, u32> depth_test_enable;
|
|
||||||
BitField<4, 3, CompareFunc> depth_test_func;
|
|
||||||
BitField<8, 1, u32> red_enable;
|
|
||||||
BitField<9, 1, u32> green_enable;
|
|
||||||
BitField<10, 1, u32> blue_enable;
|
|
||||||
BitField<11, 1, u32> alpha_enable;
|
|
||||||
BitField<12, 1, u32> depth_write_enable;
|
|
||||||
};
|
|
||||||
|
|
||||||
INSERT_PADDING_WORDS(0x8);
|
|
||||||
} output_merger;
|
|
||||||
|
|
||||||
// Components are laid out in reverse byte order, most significant bits first.
|
|
||||||
enum class ColorFormat : u32 {
|
|
||||||
RGBA8 = 0,
|
|
||||||
RGB8 = 1,
|
|
||||||
RGB5A1 = 2,
|
|
||||||
RGB565 = 3,
|
|
||||||
RGBA4 = 4,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class DepthFormat : u32 {
|
|
||||||
D16 = 0,
|
|
||||||
D24 = 2,
|
|
||||||
D24S8 = 3,
|
|
||||||
};
|
|
||||||
|
|
||||||
// Returns the number of bytes in the specified color format
|
|
||||||
static unsigned BytesPerColorPixel(ColorFormat format) {
|
|
||||||
switch (format) {
|
|
||||||
case ColorFormat::RGBA8:
|
|
||||||
return 4;
|
|
||||||
case ColorFormat::RGB8:
|
|
||||||
return 3;
|
|
||||||
case ColorFormat::RGB5A1:
|
|
||||||
case ColorFormat::RGB565:
|
|
||||||
case ColorFormat::RGBA4:
|
|
||||||
return 2;
|
|
||||||
default:
|
|
||||||
LOG_CRITICAL(HW_GPU, "Unknown color format %u", format);
|
|
||||||
UNIMPLEMENTED();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct FramebufferConfig {
|
|
||||||
INSERT_PADDING_WORDS(0x3);
|
|
||||||
|
|
||||||
union {
|
|
||||||
BitField<0, 4, u32> allow_color_write; // 0 = disable, else enable
|
|
||||||
};
|
|
||||||
|
|
||||||
INSERT_PADDING_WORDS(0x1);
|
|
||||||
|
|
||||||
union {
|
|
||||||
BitField<0, 2, u32> allow_depth_stencil_write; // 0 = disable, else enable
|
|
||||||
};
|
|
||||||
|
|
||||||
DepthFormat depth_format; // TODO: Should be a BitField!
|
|
||||||
BitField<16, 3, ColorFormat> color_format;
|
|
||||||
|
|
||||||
INSERT_PADDING_WORDS(0x4);
|
|
||||||
|
|
||||||
u32 depth_buffer_address;
|
|
||||||
u32 color_buffer_address;
|
|
||||||
|
|
||||||
union {
|
|
||||||
// Apparently, the framebuffer width is stored as expected,
|
|
||||||
// while the height is stored as the actual height minus one.
|
|
||||||
// Hence, don't access these fields directly but use the accessors
|
|
||||||
// GetWidth() and GetHeight() instead.
|
|
||||||
BitField<0, 11, u32> width;
|
|
||||||
BitField<12, 10, u32> height;
|
|
||||||
};
|
|
||||||
|
|
||||||
INSERT_PADDING_WORDS(0x1);
|
|
||||||
|
|
||||||
inline u32 GetColorBufferPhysicalAddress() const {
|
|
||||||
return DecodeAddressRegister(color_buffer_address);
|
|
||||||
}
|
|
||||||
inline u32 GetDepthBufferPhysicalAddress() const {
|
|
||||||
return DecodeAddressRegister(depth_buffer_address);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline u32 GetWidth() const {
|
|
||||||
return width;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline u32 GetHeight() const {
|
|
||||||
return height + 1;
|
|
||||||
}
|
|
||||||
} framebuffer;
|
|
||||||
|
|
||||||
// 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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns the number of bits per depth component of the specified depth format
|
|
||||||
static u32 DepthBitsPerPixel(DepthFormat format) {
|
|
||||||
switch (format) {
|
|
||||||
case DepthFormat::D16:
|
|
||||||
return 16;
|
|
||||||
case DepthFormat::D24:
|
|
||||||
case DepthFormat::D24S8:
|
|
||||||
return 24;
|
|
||||||
default:
|
|
||||||
LOG_CRITICAL(HW_GPU, "Unknown depth format %u", format);
|
|
||||||
UNIMPLEMENTED();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
INSERT_PADDING_WORDS(0x20);
|
|
||||||
|
|
||||||
enum class LightingSampler {
|
enum class LightingSampler {
|
||||||
Distribution0 = 0,
|
Distribution0 = 0,
|
||||||
|
@ -957,8 +697,10 @@ ASSERT_REG_POSITION(texturing.tev_stage4, 0xf0);
|
||||||
ASSERT_REG_POSITION(texturing.tev_stage5, 0xf8);
|
ASSERT_REG_POSITION(texturing.tev_stage5, 0xf8);
|
||||||
ASSERT_REG_POSITION(texturing.tev_combiner_buffer_color, 0xfd);
|
ASSERT_REG_POSITION(texturing.tev_combiner_buffer_color, 0xfd);
|
||||||
|
|
||||||
ASSERT_REG_POSITION(output_merger, 0x100);
|
ASSERT_REG_POSITION(framebuffer, 0x100);
|
||||||
ASSERT_REG_POSITION(framebuffer, 0x110);
|
ASSERT_REG_POSITION(framebuffer.output_merger, 0x100);
|
||||||
|
ASSERT_REG_POSITION(framebuffer.framebuffer, 0x110);
|
||||||
|
|
||||||
ASSERT_REG_POSITION(lighting, 0x140);
|
ASSERT_REG_POSITION(lighting, 0x140);
|
||||||
ASSERT_REG_POSITION(vertex_attributes, 0x200);
|
ASSERT_REG_POSITION(vertex_attributes, 0x200);
|
||||||
ASSERT_REG_POSITION(index_array, 0x227);
|
ASSERT_REG_POSITION(index_array, 0x227);
|
||||||
|
|
|
@ -29,7 +29,7 @@ namespace Pica {
|
||||||
namespace Rasterizer {
|
namespace Rasterizer {
|
||||||
|
|
||||||
static void DrawPixel(int x, int y, const Math::Vec4<u8>& color) {
|
static void DrawPixel(int x, int y, const Math::Vec4<u8>& color) {
|
||||||
const auto& framebuffer = g_state.regs.framebuffer;
|
const auto& framebuffer = g_state.regs.framebuffer.framebuffer;
|
||||||
const PAddr addr = framebuffer.GetColorBufferPhysicalAddress();
|
const PAddr addr = framebuffer.GetColorBufferPhysicalAddress();
|
||||||
|
|
||||||
// Similarly to textures, the render framebuffer is laid out from bottom to top, too.
|
// Similarly to textures, the render framebuffer is laid out from bottom to top, too.
|
||||||
|
@ -44,23 +44,23 @@ static void DrawPixel(int x, int y, const Math::Vec4<u8>& color) {
|
||||||
u8* dst_pixel = Memory::GetPhysicalPointer(addr) + dst_offset;
|
u8* dst_pixel = Memory::GetPhysicalPointer(addr) + dst_offset;
|
||||||
|
|
||||||
switch (framebuffer.color_format) {
|
switch (framebuffer.color_format) {
|
||||||
case Regs::ColorFormat::RGBA8:
|
case FramebufferRegs::ColorFormat::RGBA8:
|
||||||
Color::EncodeRGBA8(color, dst_pixel);
|
Color::EncodeRGBA8(color, dst_pixel);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Regs::ColorFormat::RGB8:
|
case FramebufferRegs::ColorFormat::RGB8:
|
||||||
Color::EncodeRGB8(color, dst_pixel);
|
Color::EncodeRGB8(color, dst_pixel);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Regs::ColorFormat::RGB5A1:
|
case FramebufferRegs::ColorFormat::RGB5A1:
|
||||||
Color::EncodeRGB5A1(color, dst_pixel);
|
Color::EncodeRGB5A1(color, dst_pixel);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Regs::ColorFormat::RGB565:
|
case FramebufferRegs::ColorFormat::RGB565:
|
||||||
Color::EncodeRGB565(color, dst_pixel);
|
Color::EncodeRGB565(color, dst_pixel);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Regs::ColorFormat::RGBA4:
|
case FramebufferRegs::ColorFormat::RGBA4:
|
||||||
Color::EncodeRGBA4(color, dst_pixel);
|
Color::EncodeRGBA4(color, dst_pixel);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ static void DrawPixel(int x, int y, const Math::Vec4<u8>& color) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static const Math::Vec4<u8> GetPixel(int x, int y) {
|
static const Math::Vec4<u8> GetPixel(int x, int y) {
|
||||||
const auto& framebuffer = g_state.regs.framebuffer;
|
const auto& framebuffer = g_state.regs.framebuffer.framebuffer;
|
||||||
const PAddr addr = framebuffer.GetColorBufferPhysicalAddress();
|
const PAddr addr = framebuffer.GetColorBufferPhysicalAddress();
|
||||||
|
|
||||||
y = framebuffer.height - y;
|
y = framebuffer.height - y;
|
||||||
|
@ -85,19 +85,19 @@ static const Math::Vec4<u8> GetPixel(int x, int y) {
|
||||||
u8* src_pixel = Memory::GetPhysicalPointer(addr) + src_offset;
|
u8* src_pixel = Memory::GetPhysicalPointer(addr) + src_offset;
|
||||||
|
|
||||||
switch (framebuffer.color_format) {
|
switch (framebuffer.color_format) {
|
||||||
case Regs::ColorFormat::RGBA8:
|
case FramebufferRegs::ColorFormat::RGBA8:
|
||||||
return Color::DecodeRGBA8(src_pixel);
|
return Color::DecodeRGBA8(src_pixel);
|
||||||
|
|
||||||
case Regs::ColorFormat::RGB8:
|
case FramebufferRegs::ColorFormat::RGB8:
|
||||||
return Color::DecodeRGB8(src_pixel);
|
return Color::DecodeRGB8(src_pixel);
|
||||||
|
|
||||||
case Regs::ColorFormat::RGB5A1:
|
case FramebufferRegs::ColorFormat::RGB5A1:
|
||||||
return Color::DecodeRGB5A1(src_pixel);
|
return Color::DecodeRGB5A1(src_pixel);
|
||||||
|
|
||||||
case Regs::ColorFormat::RGB565:
|
case FramebufferRegs::ColorFormat::RGB565:
|
||||||
return Color::DecodeRGB565(src_pixel);
|
return Color::DecodeRGB565(src_pixel);
|
||||||
|
|
||||||
case Regs::ColorFormat::RGBA4:
|
case FramebufferRegs::ColorFormat::RGBA4:
|
||||||
return Color::DecodeRGBA4(src_pixel);
|
return Color::DecodeRGBA4(src_pixel);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -110,25 +110,25 @@ static const Math::Vec4<u8> GetPixel(int x, int y) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static u32 GetDepth(int x, int y) {
|
static u32 GetDepth(int x, int y) {
|
||||||
const auto& framebuffer = g_state.regs.framebuffer;
|
const auto& framebuffer = g_state.regs.framebuffer.framebuffer;
|
||||||
const PAddr addr = framebuffer.GetDepthBufferPhysicalAddress();
|
const PAddr addr = framebuffer.GetDepthBufferPhysicalAddress();
|
||||||
u8* depth_buffer = Memory::GetPhysicalPointer(addr);
|
u8* depth_buffer = Memory::GetPhysicalPointer(addr);
|
||||||
|
|
||||||
y = framebuffer.height - y;
|
y = framebuffer.height - y;
|
||||||
|
|
||||||
const u32 coarse_y = y & ~7;
|
const u32 coarse_y = y & ~7;
|
||||||
u32 bytes_per_pixel = Regs::BytesPerDepthPixel(framebuffer.depth_format);
|
u32 bytes_per_pixel = FramebufferRegs::BytesPerDepthPixel(framebuffer.depth_format);
|
||||||
u32 stride = framebuffer.width * bytes_per_pixel;
|
u32 stride = framebuffer.width * bytes_per_pixel;
|
||||||
|
|
||||||
u32 src_offset = VideoCore::GetMortonOffset(x, y, bytes_per_pixel) + coarse_y * stride;
|
u32 src_offset = VideoCore::GetMortonOffset(x, y, bytes_per_pixel) + coarse_y * stride;
|
||||||
u8* src_pixel = depth_buffer + src_offset;
|
u8* src_pixel = depth_buffer + src_offset;
|
||||||
|
|
||||||
switch (framebuffer.depth_format) {
|
switch (framebuffer.depth_format) {
|
||||||
case Regs::DepthFormat::D16:
|
case FramebufferRegs::DepthFormat::D16:
|
||||||
return Color::DecodeD16(src_pixel);
|
return Color::DecodeD16(src_pixel);
|
||||||
case Regs::DepthFormat::D24:
|
case FramebufferRegs::DepthFormat::D24:
|
||||||
return Color::DecodeD24(src_pixel);
|
return Color::DecodeD24(src_pixel);
|
||||||
case Regs::DepthFormat::D24S8:
|
case FramebufferRegs::DepthFormat::D24S8:
|
||||||
return Color::DecodeD24S8(src_pixel).x;
|
return Color::DecodeD24S8(src_pixel).x;
|
||||||
default:
|
default:
|
||||||
LOG_CRITICAL(HW_GPU, "Unimplemented depth format %u", framebuffer.depth_format);
|
LOG_CRITICAL(HW_GPU, "Unimplemented depth format %u", framebuffer.depth_format);
|
||||||
|
@ -138,21 +138,21 @@ static u32 GetDepth(int x, int y) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static u8 GetStencil(int x, int y) {
|
static u8 GetStencil(int x, int y) {
|
||||||
const auto& framebuffer = g_state.regs.framebuffer;
|
const auto& framebuffer = g_state.regs.framebuffer.framebuffer;
|
||||||
const PAddr addr = framebuffer.GetDepthBufferPhysicalAddress();
|
const PAddr addr = framebuffer.GetDepthBufferPhysicalAddress();
|
||||||
u8* depth_buffer = Memory::GetPhysicalPointer(addr);
|
u8* depth_buffer = Memory::GetPhysicalPointer(addr);
|
||||||
|
|
||||||
y = framebuffer.height - y;
|
y = framebuffer.height - y;
|
||||||
|
|
||||||
const u32 coarse_y = y & ~7;
|
const u32 coarse_y = y & ~7;
|
||||||
u32 bytes_per_pixel = Pica::Regs::BytesPerDepthPixel(framebuffer.depth_format);
|
u32 bytes_per_pixel = Pica::FramebufferRegs::BytesPerDepthPixel(framebuffer.depth_format);
|
||||||
u32 stride = framebuffer.width * bytes_per_pixel;
|
u32 stride = framebuffer.width * bytes_per_pixel;
|
||||||
|
|
||||||
u32 src_offset = VideoCore::GetMortonOffset(x, y, bytes_per_pixel) + coarse_y * stride;
|
u32 src_offset = VideoCore::GetMortonOffset(x, y, bytes_per_pixel) + coarse_y * stride;
|
||||||
u8* src_pixel = depth_buffer + src_offset;
|
u8* src_pixel = depth_buffer + src_offset;
|
||||||
|
|
||||||
switch (framebuffer.depth_format) {
|
switch (framebuffer.depth_format) {
|
||||||
case Regs::DepthFormat::D24S8:
|
case FramebufferRegs::DepthFormat::D24S8:
|
||||||
return Color::DecodeD24S8(src_pixel).y;
|
return Color::DecodeD24S8(src_pixel).y;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -165,29 +165,29 @@ static u8 GetStencil(int x, int y) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void SetDepth(int x, int y, u32 value) {
|
static void SetDepth(int x, int y, u32 value) {
|
||||||
const auto& framebuffer = g_state.regs.framebuffer;
|
const auto& framebuffer = g_state.regs.framebuffer.framebuffer;
|
||||||
const PAddr addr = framebuffer.GetDepthBufferPhysicalAddress();
|
const PAddr addr = framebuffer.GetDepthBufferPhysicalAddress();
|
||||||
u8* depth_buffer = Memory::GetPhysicalPointer(addr);
|
u8* depth_buffer = Memory::GetPhysicalPointer(addr);
|
||||||
|
|
||||||
y = framebuffer.height - y;
|
y = framebuffer.height - y;
|
||||||
|
|
||||||
const u32 coarse_y = y & ~7;
|
const u32 coarse_y = y & ~7;
|
||||||
u32 bytes_per_pixel = Regs::BytesPerDepthPixel(framebuffer.depth_format);
|
u32 bytes_per_pixel = FramebufferRegs::BytesPerDepthPixel(framebuffer.depth_format);
|
||||||
u32 stride = framebuffer.width * bytes_per_pixel;
|
u32 stride = framebuffer.width * bytes_per_pixel;
|
||||||
|
|
||||||
u32 dst_offset = VideoCore::GetMortonOffset(x, y, bytes_per_pixel) + coarse_y * stride;
|
u32 dst_offset = VideoCore::GetMortonOffset(x, y, bytes_per_pixel) + coarse_y * stride;
|
||||||
u8* dst_pixel = depth_buffer + dst_offset;
|
u8* dst_pixel = depth_buffer + dst_offset;
|
||||||
|
|
||||||
switch (framebuffer.depth_format) {
|
switch (framebuffer.depth_format) {
|
||||||
case Regs::DepthFormat::D16:
|
case FramebufferRegs::DepthFormat::D16:
|
||||||
Color::EncodeD16(value, dst_pixel);
|
Color::EncodeD16(value, dst_pixel);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Regs::DepthFormat::D24:
|
case FramebufferRegs::DepthFormat::D24:
|
||||||
Color::EncodeD24(value, dst_pixel);
|
Color::EncodeD24(value, dst_pixel);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Regs::DepthFormat::D24S8:
|
case FramebufferRegs::DepthFormat::D24S8:
|
||||||
Color::EncodeD24X8(value, dst_pixel);
|
Color::EncodeD24X8(value, dst_pixel);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -199,26 +199,26 @@ static void SetDepth(int x, int y, u32 value) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void SetStencil(int x, int y, u8 value) {
|
static void SetStencil(int x, int y, u8 value) {
|
||||||
const auto& framebuffer = g_state.regs.framebuffer;
|
const auto& framebuffer = g_state.regs.framebuffer.framebuffer;
|
||||||
const PAddr addr = framebuffer.GetDepthBufferPhysicalAddress();
|
const PAddr addr = framebuffer.GetDepthBufferPhysicalAddress();
|
||||||
u8* depth_buffer = Memory::GetPhysicalPointer(addr);
|
u8* depth_buffer = Memory::GetPhysicalPointer(addr);
|
||||||
|
|
||||||
y = framebuffer.height - y;
|
y = framebuffer.height - y;
|
||||||
|
|
||||||
const u32 coarse_y = y & ~7;
|
const u32 coarse_y = y & ~7;
|
||||||
u32 bytes_per_pixel = Pica::Regs::BytesPerDepthPixel(framebuffer.depth_format);
|
u32 bytes_per_pixel = Pica::FramebufferRegs::BytesPerDepthPixel(framebuffer.depth_format);
|
||||||
u32 stride = framebuffer.width * bytes_per_pixel;
|
u32 stride = framebuffer.width * bytes_per_pixel;
|
||||||
|
|
||||||
u32 dst_offset = VideoCore::GetMortonOffset(x, y, bytes_per_pixel) + coarse_y * stride;
|
u32 dst_offset = VideoCore::GetMortonOffset(x, y, bytes_per_pixel) + coarse_y * stride;
|
||||||
u8* dst_pixel = depth_buffer + dst_offset;
|
u8* dst_pixel = depth_buffer + dst_offset;
|
||||||
|
|
||||||
switch (framebuffer.depth_format) {
|
switch (framebuffer.depth_format) {
|
||||||
case Pica::Regs::DepthFormat::D16:
|
case Pica::FramebufferRegs::DepthFormat::D16:
|
||||||
case Pica::Regs::DepthFormat::D24:
|
case Pica::FramebufferRegs::DepthFormat::D24:
|
||||||
// Nothing to do
|
// Nothing to do
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Pica::Regs::DepthFormat::D24S8:
|
case Pica::FramebufferRegs::DepthFormat::D24S8:
|
||||||
Color::EncodeX24S8(value, dst_pixel);
|
Color::EncodeX24S8(value, dst_pixel);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -229,32 +229,32 @@ static void SetStencil(int x, int y, u8 value) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static u8 PerformStencilAction(Regs::StencilAction action, u8 old_stencil, u8 ref) {
|
static u8 PerformStencilAction(FramebufferRegs::StencilAction action, u8 old_stencil, u8 ref) {
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case Regs::StencilAction::Keep:
|
case FramebufferRegs::StencilAction::Keep:
|
||||||
return old_stencil;
|
return old_stencil;
|
||||||
|
|
||||||
case Regs::StencilAction::Zero:
|
case FramebufferRegs::StencilAction::Zero:
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
case Regs::StencilAction::Replace:
|
case FramebufferRegs::StencilAction::Replace:
|
||||||
return ref;
|
return ref;
|
||||||
|
|
||||||
case Regs::StencilAction::Increment:
|
case FramebufferRegs::StencilAction::Increment:
|
||||||
// Saturated increment
|
// Saturated increment
|
||||||
return std::min<u8>(old_stencil, 254) + 1;
|
return std::min<u8>(old_stencil, 254) + 1;
|
||||||
|
|
||||||
case Regs::StencilAction::Decrement:
|
case FramebufferRegs::StencilAction::Decrement:
|
||||||
// Saturated decrement
|
// Saturated decrement
|
||||||
return std::max<u8>(old_stencil, 1) - 1;
|
return std::max<u8>(old_stencil, 1) - 1;
|
||||||
|
|
||||||
case Regs::StencilAction::Invert:
|
case FramebufferRegs::StencilAction::Invert:
|
||||||
return ~old_stencil;
|
return ~old_stencil;
|
||||||
|
|
||||||
case Regs::StencilAction::IncrementWrap:
|
case FramebufferRegs::StencilAction::IncrementWrap:
|
||||||
return old_stencil + 1;
|
return old_stencil + 1;
|
||||||
|
|
||||||
case Regs::StencilAction::DecrementWrap:
|
case FramebufferRegs::StencilAction::DecrementWrap:
|
||||||
return old_stencil - 1;
|
return old_stencil - 1;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -400,9 +400,10 @@ static void ProcessTriangleInternal(const Vertex& v0, const Vertex& v1, const Ve
|
||||||
auto textures = regs.texturing.GetTextures();
|
auto textures = regs.texturing.GetTextures();
|
||||||
auto tev_stages = regs.texturing.GetTevStages();
|
auto tev_stages = regs.texturing.GetTevStages();
|
||||||
|
|
||||||
bool stencil_action_enable = g_state.regs.output_merger.stencil_test.enable &&
|
bool stencil_action_enable =
|
||||||
g_state.regs.framebuffer.depth_format == Regs::DepthFormat::D24S8;
|
g_state.regs.framebuffer.output_merger.stencil_test.enable &&
|
||||||
const auto stencil_test = g_state.regs.output_merger.stencil_test;
|
g_state.regs.framebuffer.framebuffer.depth_format == FramebufferRegs::DepthFormat::D24S8;
|
||||||
|
const auto stencil_test = g_state.regs.framebuffer.output_merger.stencil_test;
|
||||||
|
|
||||||
// Enter rasterization loop, starting at the center of the topleft bounding box corner.
|
// Enter rasterization loop, starting at the center of the topleft bounding box corner.
|
||||||
// TODO: Not sure if looping through x first might be faster
|
// TODO: Not sure if looping through x first might be faster
|
||||||
|
@ -879,41 +880,41 @@ static void ProcessTriangleInternal(const Vertex& v0, const Vertex& v1, const Ve
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto& output_merger = regs.output_merger;
|
const auto& output_merger = regs.framebuffer.output_merger;
|
||||||
// TODO: Does alpha testing happen before or after stencil?
|
// TODO: Does alpha testing happen before or after stencil?
|
||||||
if (output_merger.alpha_test.enable) {
|
if (output_merger.alpha_test.enable) {
|
||||||
bool pass = false;
|
bool pass = false;
|
||||||
|
|
||||||
switch (output_merger.alpha_test.func) {
|
switch (output_merger.alpha_test.func) {
|
||||||
case Regs::CompareFunc::Never:
|
case FramebufferRegs::CompareFunc::Never:
|
||||||
pass = false;
|
pass = false;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Regs::CompareFunc::Always:
|
case FramebufferRegs::CompareFunc::Always:
|
||||||
pass = true;
|
pass = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Regs::CompareFunc::Equal:
|
case FramebufferRegs::CompareFunc::Equal:
|
||||||
pass = combiner_output.a() == output_merger.alpha_test.ref;
|
pass = combiner_output.a() == output_merger.alpha_test.ref;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Regs::CompareFunc::NotEqual:
|
case FramebufferRegs::CompareFunc::NotEqual:
|
||||||
pass = combiner_output.a() != output_merger.alpha_test.ref;
|
pass = combiner_output.a() != output_merger.alpha_test.ref;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Regs::CompareFunc::LessThan:
|
case FramebufferRegs::CompareFunc::LessThan:
|
||||||
pass = combiner_output.a() < output_merger.alpha_test.ref;
|
pass = combiner_output.a() < output_merger.alpha_test.ref;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Regs::CompareFunc::LessThanOrEqual:
|
case FramebufferRegs::CompareFunc::LessThanOrEqual:
|
||||||
pass = combiner_output.a() <= output_merger.alpha_test.ref;
|
pass = combiner_output.a() <= output_merger.alpha_test.ref;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Regs::CompareFunc::GreaterThan:
|
case FramebufferRegs::CompareFunc::GreaterThan:
|
||||||
pass = combiner_output.a() > output_merger.alpha_test.ref;
|
pass = combiner_output.a() > output_merger.alpha_test.ref;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Regs::CompareFunc::GreaterThanOrEqual:
|
case FramebufferRegs::CompareFunc::GreaterThanOrEqual:
|
||||||
pass = combiner_output.a() >= output_merger.alpha_test.ref;
|
pass = combiner_output.a() >= output_merger.alpha_test.ref;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -959,10 +960,10 @@ static void ProcessTriangleInternal(const Vertex& v0, const Vertex& v1, const Ve
|
||||||
u8 old_stencil = 0;
|
u8 old_stencil = 0;
|
||||||
|
|
||||||
auto UpdateStencil = [stencil_test, x, y,
|
auto UpdateStencil = [stencil_test, x, y,
|
||||||
&old_stencil](Pica::Regs::StencilAction action) {
|
&old_stencil](Pica::FramebufferRegs::StencilAction action) {
|
||||||
u8 new_stencil =
|
u8 new_stencil =
|
||||||
PerformStencilAction(action, old_stencil, stencil_test.reference_value);
|
PerformStencilAction(action, old_stencil, stencil_test.reference_value);
|
||||||
if (g_state.regs.framebuffer.allow_depth_stencil_write != 0)
|
if (g_state.regs.framebuffer.framebuffer.allow_depth_stencil_write != 0)
|
||||||
SetStencil(x >> 4, y >> 4, (new_stencil & stencil_test.write_mask) |
|
SetStencil(x >> 4, y >> 4, (new_stencil & stencil_test.write_mask) |
|
||||||
(old_stencil & ~stencil_test.write_mask));
|
(old_stencil & ~stencil_test.write_mask));
|
||||||
};
|
};
|
||||||
|
@ -974,35 +975,35 @@ static void ProcessTriangleInternal(const Vertex& v0, const Vertex& v1, const Ve
|
||||||
|
|
||||||
bool pass = false;
|
bool pass = false;
|
||||||
switch (stencil_test.func) {
|
switch (stencil_test.func) {
|
||||||
case Regs::CompareFunc::Never:
|
case FramebufferRegs::CompareFunc::Never:
|
||||||
pass = false;
|
pass = false;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Regs::CompareFunc::Always:
|
case FramebufferRegs::CompareFunc::Always:
|
||||||
pass = true;
|
pass = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Regs::CompareFunc::Equal:
|
case FramebufferRegs::CompareFunc::Equal:
|
||||||
pass = (ref == dest);
|
pass = (ref == dest);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Regs::CompareFunc::NotEqual:
|
case FramebufferRegs::CompareFunc::NotEqual:
|
||||||
pass = (ref != dest);
|
pass = (ref != dest);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Regs::CompareFunc::LessThan:
|
case FramebufferRegs::CompareFunc::LessThan:
|
||||||
pass = (ref < dest);
|
pass = (ref < dest);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Regs::CompareFunc::LessThanOrEqual:
|
case FramebufferRegs::CompareFunc::LessThanOrEqual:
|
||||||
pass = (ref <= dest);
|
pass = (ref <= dest);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Regs::CompareFunc::GreaterThan:
|
case FramebufferRegs::CompareFunc::GreaterThan:
|
||||||
pass = (ref > dest);
|
pass = (ref > dest);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Regs::CompareFunc::GreaterThanOrEqual:
|
case FramebufferRegs::CompareFunc::GreaterThanOrEqual:
|
||||||
pass = (ref >= dest);
|
pass = (ref >= dest);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1014,7 +1015,8 @@ static void ProcessTriangleInternal(const Vertex& v0, const Vertex& v1, const Ve
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert float to integer
|
// Convert float to integer
|
||||||
unsigned num_bits = Regs::DepthBitsPerPixel(regs.framebuffer.depth_format);
|
unsigned num_bits =
|
||||||
|
FramebufferRegs::DepthBitsPerPixel(regs.framebuffer.framebuffer.depth_format);
|
||||||
u32 z = (u32)(depth * ((1 << num_bits) - 1));
|
u32 z = (u32)(depth * ((1 << num_bits) - 1));
|
||||||
|
|
||||||
if (output_merger.depth_test_enable) {
|
if (output_merger.depth_test_enable) {
|
||||||
|
@ -1023,35 +1025,35 @@ static void ProcessTriangleInternal(const Vertex& v0, const Vertex& v1, const Ve
|
||||||
bool pass = false;
|
bool pass = false;
|
||||||
|
|
||||||
switch (output_merger.depth_test_func) {
|
switch (output_merger.depth_test_func) {
|
||||||
case Regs::CompareFunc::Never:
|
case FramebufferRegs::CompareFunc::Never:
|
||||||
pass = false;
|
pass = false;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Regs::CompareFunc::Always:
|
case FramebufferRegs::CompareFunc::Always:
|
||||||
pass = true;
|
pass = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Regs::CompareFunc::Equal:
|
case FramebufferRegs::CompareFunc::Equal:
|
||||||
pass = z == ref_z;
|
pass = z == ref_z;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Regs::CompareFunc::NotEqual:
|
case FramebufferRegs::CompareFunc::NotEqual:
|
||||||
pass = z != ref_z;
|
pass = z != ref_z;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Regs::CompareFunc::LessThan:
|
case FramebufferRegs::CompareFunc::LessThan:
|
||||||
pass = z < ref_z;
|
pass = z < ref_z;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Regs::CompareFunc::LessThanOrEqual:
|
case FramebufferRegs::CompareFunc::LessThanOrEqual:
|
||||||
pass = z <= ref_z;
|
pass = z <= ref_z;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Regs::CompareFunc::GreaterThan:
|
case FramebufferRegs::CompareFunc::GreaterThan:
|
||||||
pass = z > ref_z;
|
pass = z > ref_z;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Regs::CompareFunc::GreaterThanOrEqual:
|
case FramebufferRegs::CompareFunc::GreaterThanOrEqual:
|
||||||
pass = z >= ref_z;
|
pass = z >= ref_z;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1063,8 +1065,11 @@ static void ProcessTriangleInternal(const Vertex& v0, const Vertex& v1, const Ve
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (regs.framebuffer.allow_depth_stencil_write != 0 && output_merger.depth_write_enable)
|
if (regs.framebuffer.framebuffer.allow_depth_stencil_write != 0 &&
|
||||||
|
output_merger.depth_write_enable) {
|
||||||
|
|
||||||
SetDepth(x >> 4, y >> 4, z);
|
SetDepth(x >> 4, y >> 4, z);
|
||||||
|
}
|
||||||
|
|
||||||
// The stencil depth_pass action is executed even if depth testing is disabled
|
// The stencil depth_pass action is executed even if depth testing is disabled
|
||||||
if (stencil_action_enable)
|
if (stencil_action_enable)
|
||||||
|
@ -1076,7 +1081,8 @@ static void ProcessTriangleInternal(const Vertex& v0, const Vertex& v1, const Ve
|
||||||
if (output_merger.alphablend_enable) {
|
if (output_merger.alphablend_enable) {
|
||||||
auto params = output_merger.alpha_blending;
|
auto params = output_merger.alpha_blending;
|
||||||
|
|
||||||
auto LookupFactor = [&](unsigned channel, Regs::BlendFactor factor) -> u8 {
|
auto LookupFactor = [&](unsigned channel,
|
||||||
|
FramebufferRegs::BlendFactor factor) -> u8 {
|
||||||
DEBUG_ASSERT(channel < 4);
|
DEBUG_ASSERT(channel < 4);
|
||||||
|
|
||||||
const Math::Vec4<u8> blend_const = {
|
const Math::Vec4<u8> blend_const = {
|
||||||
|
@ -1087,49 +1093,49 @@ static void ProcessTriangleInternal(const Vertex& v0, const Vertex& v1, const Ve
|
||||||
};
|
};
|
||||||
|
|
||||||
switch (factor) {
|
switch (factor) {
|
||||||
case Regs::BlendFactor::Zero:
|
case FramebufferRegs::BlendFactor::Zero:
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
case Regs::BlendFactor::One:
|
case FramebufferRegs::BlendFactor::One:
|
||||||
return 255;
|
return 255;
|
||||||
|
|
||||||
case Regs::BlendFactor::SourceColor:
|
case FramebufferRegs::BlendFactor::SourceColor:
|
||||||
return combiner_output[channel];
|
return combiner_output[channel];
|
||||||
|
|
||||||
case Regs::BlendFactor::OneMinusSourceColor:
|
case FramebufferRegs::BlendFactor::OneMinusSourceColor:
|
||||||
return 255 - combiner_output[channel];
|
return 255 - combiner_output[channel];
|
||||||
|
|
||||||
case Regs::BlendFactor::DestColor:
|
case FramebufferRegs::BlendFactor::DestColor:
|
||||||
return dest[channel];
|
return dest[channel];
|
||||||
|
|
||||||
case Regs::BlendFactor::OneMinusDestColor:
|
case FramebufferRegs::BlendFactor::OneMinusDestColor:
|
||||||
return 255 - dest[channel];
|
return 255 - dest[channel];
|
||||||
|
|
||||||
case Regs::BlendFactor::SourceAlpha:
|
case FramebufferRegs::BlendFactor::SourceAlpha:
|
||||||
return combiner_output.a();
|
return combiner_output.a();
|
||||||
|
|
||||||
case Regs::BlendFactor::OneMinusSourceAlpha:
|
case FramebufferRegs::BlendFactor::OneMinusSourceAlpha:
|
||||||
return 255 - combiner_output.a();
|
return 255 - combiner_output.a();
|
||||||
|
|
||||||
case Regs::BlendFactor::DestAlpha:
|
case FramebufferRegs::BlendFactor::DestAlpha:
|
||||||
return dest.a();
|
return dest.a();
|
||||||
|
|
||||||
case Regs::BlendFactor::OneMinusDestAlpha:
|
case FramebufferRegs::BlendFactor::OneMinusDestAlpha:
|
||||||
return 255 - dest.a();
|
return 255 - dest.a();
|
||||||
|
|
||||||
case Regs::BlendFactor::ConstantColor:
|
case FramebufferRegs::BlendFactor::ConstantColor:
|
||||||
return blend_const[channel];
|
return blend_const[channel];
|
||||||
|
|
||||||
case Regs::BlendFactor::OneMinusConstantColor:
|
case FramebufferRegs::BlendFactor::OneMinusConstantColor:
|
||||||
return 255 - blend_const[channel];
|
return 255 - blend_const[channel];
|
||||||
|
|
||||||
case Regs::BlendFactor::ConstantAlpha:
|
case FramebufferRegs::BlendFactor::ConstantAlpha:
|
||||||
return blend_const.a();
|
return blend_const.a();
|
||||||
|
|
||||||
case Regs::BlendFactor::OneMinusConstantAlpha:
|
case FramebufferRegs::BlendFactor::OneMinusConstantAlpha:
|
||||||
return 255 - blend_const.a();
|
return 255 - blend_const.a();
|
||||||
|
|
||||||
case Regs::BlendFactor::SourceAlphaSaturate:
|
case FramebufferRegs::BlendFactor::SourceAlphaSaturate:
|
||||||
// Returns 1.0 for the alpha channel
|
// Returns 1.0 for the alpha channel
|
||||||
if (channel == 3)
|
if (channel == 3)
|
||||||
return 255;
|
return 255;
|
||||||
|
@ -1147,36 +1153,37 @@ static void ProcessTriangleInternal(const Vertex& v0, const Vertex& v1, const Ve
|
||||||
static auto EvaluateBlendEquation = [](
|
static auto EvaluateBlendEquation = [](
|
||||||
const Math::Vec4<u8>& src, const Math::Vec4<u8>& srcfactor,
|
const Math::Vec4<u8>& src, const Math::Vec4<u8>& srcfactor,
|
||||||
const Math::Vec4<u8>& dest, const Math::Vec4<u8>& destfactor,
|
const Math::Vec4<u8>& dest, const Math::Vec4<u8>& destfactor,
|
||||||
Regs::BlendEquation equation) {
|
FramebufferRegs::BlendEquation equation) {
|
||||||
|
|
||||||
Math::Vec4<int> result;
|
Math::Vec4<int> result;
|
||||||
|
|
||||||
auto src_result = (src * srcfactor).Cast<int>();
|
auto src_result = (src * srcfactor).Cast<int>();
|
||||||
auto dst_result = (dest * destfactor).Cast<int>();
|
auto dst_result = (dest * destfactor).Cast<int>();
|
||||||
|
|
||||||
switch (equation) {
|
switch (equation) {
|
||||||
case Regs::BlendEquation::Add:
|
case FramebufferRegs::BlendEquation::Add:
|
||||||
result = (src_result + dst_result) / 255;
|
result = (src_result + dst_result) / 255;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Regs::BlendEquation::Subtract:
|
case FramebufferRegs::BlendEquation::Subtract:
|
||||||
result = (src_result - dst_result) / 255;
|
result = (src_result - dst_result) / 255;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Regs::BlendEquation::ReverseSubtract:
|
case FramebufferRegs::BlendEquation::ReverseSubtract:
|
||||||
result = (dst_result - src_result) / 255;
|
result = (dst_result - src_result) / 255;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// TODO: How do these two actually work?
|
// TODO: How do these two actually work?
|
||||||
// OpenGL doesn't include the blend factors in the min/max computations,
|
// OpenGL doesn't include the blend factors in the min/max computations,
|
||||||
// but is this what the 3DS actually does?
|
// but is this what the 3DS actually does?
|
||||||
case Regs::BlendEquation::Min:
|
case FramebufferRegs::BlendEquation::Min:
|
||||||
result.r() = std::min(src.r(), dest.r());
|
result.r() = std::min(src.r(), dest.r());
|
||||||
result.g() = std::min(src.g(), dest.g());
|
result.g() = std::min(src.g(), dest.g());
|
||||||
result.b() = std::min(src.b(), dest.b());
|
result.b() = std::min(src.b(), dest.b());
|
||||||
result.a() = std::min(src.a(), dest.a());
|
result.a() = std::min(src.a(), dest.a());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Regs::BlendEquation::Max:
|
case FramebufferRegs::BlendEquation::Max:
|
||||||
result.r() = std::max(src.r(), dest.r());
|
result.r() = std::max(src.r(), dest.r());
|
||||||
result.g() = std::max(src.g(), dest.g());
|
result.g() = std::max(src.g(), dest.g());
|
||||||
result.b() = std::max(src.b(), dest.b());
|
result.b() = std::max(src.b(), dest.b());
|
||||||
|
@ -1209,54 +1216,54 @@ static void ProcessTriangleInternal(const Vertex& v0, const Vertex& v1, const Ve
|
||||||
dstfactor, params.blend_equation_a)
|
dstfactor, params.blend_equation_a)
|
||||||
.a();
|
.a();
|
||||||
} else {
|
} else {
|
||||||
static auto LogicOp = [](u8 src, u8 dest, Regs::LogicOp op) -> u8 {
|
static auto LogicOp = [](u8 src, u8 dest, FramebufferRegs::LogicOp op) -> u8 {
|
||||||
switch (op) {
|
switch (op) {
|
||||||
case Regs::LogicOp::Clear:
|
case FramebufferRegs::LogicOp::Clear:
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
case Regs::LogicOp::And:
|
case FramebufferRegs::LogicOp::And:
|
||||||
return src & dest;
|
return src & dest;
|
||||||
|
|
||||||
case Regs::LogicOp::AndReverse:
|
case FramebufferRegs::LogicOp::AndReverse:
|
||||||
return src & ~dest;
|
return src & ~dest;
|
||||||
|
|
||||||
case Regs::LogicOp::Copy:
|
case FramebufferRegs::LogicOp::Copy:
|
||||||
return src;
|
return src;
|
||||||
|
|
||||||
case Regs::LogicOp::Set:
|
case FramebufferRegs::LogicOp::Set:
|
||||||
return 255;
|
return 255;
|
||||||
|
|
||||||
case Regs::LogicOp::CopyInverted:
|
case FramebufferRegs::LogicOp::CopyInverted:
|
||||||
return ~src;
|
return ~src;
|
||||||
|
|
||||||
case Regs::LogicOp::NoOp:
|
case FramebufferRegs::LogicOp::NoOp:
|
||||||
return dest;
|
return dest;
|
||||||
|
|
||||||
case Regs::LogicOp::Invert:
|
case FramebufferRegs::LogicOp::Invert:
|
||||||
return ~dest;
|
return ~dest;
|
||||||
|
|
||||||
case Regs::LogicOp::Nand:
|
case FramebufferRegs::LogicOp::Nand:
|
||||||
return ~(src & dest);
|
return ~(src & dest);
|
||||||
|
|
||||||
case Regs::LogicOp::Or:
|
case FramebufferRegs::LogicOp::Or:
|
||||||
return src | dest;
|
return src | dest;
|
||||||
|
|
||||||
case Regs::LogicOp::Nor:
|
case FramebufferRegs::LogicOp::Nor:
|
||||||
return ~(src | dest);
|
return ~(src | dest);
|
||||||
|
|
||||||
case Regs::LogicOp::Xor:
|
case FramebufferRegs::LogicOp::Xor:
|
||||||
return src ^ dest;
|
return src ^ dest;
|
||||||
|
|
||||||
case Regs::LogicOp::Equiv:
|
case FramebufferRegs::LogicOp::Equiv:
|
||||||
return ~(src ^ dest);
|
return ~(src ^ dest);
|
||||||
|
|
||||||
case Regs::LogicOp::AndInverted:
|
case FramebufferRegs::LogicOp::AndInverted:
|
||||||
return ~src & dest;
|
return ~src & dest;
|
||||||
|
|
||||||
case Regs::LogicOp::OrReverse:
|
case FramebufferRegs::LogicOp::OrReverse:
|
||||||
return src | ~dest;
|
return src | ~dest;
|
||||||
|
|
||||||
case Regs::LogicOp::OrInverted:
|
case FramebufferRegs::LogicOp::OrInverted:
|
||||||
return ~src | dest;
|
return ~src | dest;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -1275,7 +1282,7 @@ static void ProcessTriangleInternal(const Vertex& v0, const Vertex& v1, const Ve
|
||||||
output_merger.alpha_enable ? blend_output.a() : dest.a(),
|
output_merger.alpha_enable ? blend_output.a() : dest.a(),
|
||||||
};
|
};
|
||||||
|
|
||||||
if (regs.framebuffer.allow_color_write != 0)
|
if (regs.framebuffer.framebuffer.allow_color_write != 0)
|
||||||
DrawPixel(x >> 4, y >> 4, result);
|
DrawPixel(x >> 4, y >> 4, result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
282
src/video_core/regs_framebuffer.h
Normal file
282
src/video_core/regs_framebuffer.h
Normal file
|
@ -0,0 +1,282 @@
|
||||||
|
// Copyright 2017 Citra Emulator Project
|
||||||
|
// Licensed under GPLv2 or any later version
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
|
||||||
|
#include "common/bit_field.h"
|
||||||
|
#include "common/common_funcs.h"
|
||||||
|
#include "common/common_types.h"
|
||||||
|
|
||||||
|
namespace Pica {
|
||||||
|
|
||||||
|
struct FramebufferRegs {
|
||||||
|
enum class LogicOp : u32 {
|
||||||
|
Clear = 0,
|
||||||
|
And = 1,
|
||||||
|
AndReverse = 2,
|
||||||
|
Copy = 3,
|
||||||
|
Set = 4,
|
||||||
|
CopyInverted = 5,
|
||||||
|
NoOp = 6,
|
||||||
|
Invert = 7,
|
||||||
|
Nand = 8,
|
||||||
|
Or = 9,
|
||||||
|
Nor = 10,
|
||||||
|
Xor = 11,
|
||||||
|
Equiv = 12,
|
||||||
|
AndInverted = 13,
|
||||||
|
OrReverse = 14,
|
||||||
|
OrInverted = 15,
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class BlendEquation : u32 {
|
||||||
|
Add = 0,
|
||||||
|
Subtract = 1,
|
||||||
|
ReverseSubtract = 2,
|
||||||
|
Min = 3,
|
||||||
|
Max = 4,
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class BlendFactor : u32 {
|
||||||
|
Zero = 0,
|
||||||
|
One = 1,
|
||||||
|
SourceColor = 2,
|
||||||
|
OneMinusSourceColor = 3,
|
||||||
|
DestColor = 4,
|
||||||
|
OneMinusDestColor = 5,
|
||||||
|
SourceAlpha = 6,
|
||||||
|
OneMinusSourceAlpha = 7,
|
||||||
|
DestAlpha = 8,
|
||||||
|
OneMinusDestAlpha = 9,
|
||||||
|
ConstantColor = 10,
|
||||||
|
OneMinusConstantColor = 11,
|
||||||
|
ConstantAlpha = 12,
|
||||||
|
OneMinusConstantAlpha = 13,
|
||||||
|
SourceAlphaSaturate = 14,
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class CompareFunc : u32 {
|
||||||
|
Never = 0,
|
||||||
|
Always = 1,
|
||||||
|
Equal = 2,
|
||||||
|
NotEqual = 3,
|
||||||
|
LessThan = 4,
|
||||||
|
LessThanOrEqual = 5,
|
||||||
|
GreaterThan = 6,
|
||||||
|
GreaterThanOrEqual = 7,
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class StencilAction : u32 {
|
||||||
|
Keep = 0,
|
||||||
|
Zero = 1,
|
||||||
|
Replace = 2,
|
||||||
|
Increment = 3,
|
||||||
|
Decrement = 4,
|
||||||
|
Invert = 5,
|
||||||
|
IncrementWrap = 6,
|
||||||
|
DecrementWrap = 7,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct {
|
||||||
|
union {
|
||||||
|
// If false, logic blending is used
|
||||||
|
BitField<8, 1, u32> alphablend_enable;
|
||||||
|
};
|
||||||
|
|
||||||
|
union {
|
||||||
|
BitField<0, 8, BlendEquation> blend_equation_rgb;
|
||||||
|
BitField<8, 8, BlendEquation> blend_equation_a;
|
||||||
|
|
||||||
|
BitField<16, 4, BlendFactor> factor_source_rgb;
|
||||||
|
BitField<20, 4, BlendFactor> factor_dest_rgb;
|
||||||
|
|
||||||
|
BitField<24, 4, BlendFactor> factor_source_a;
|
||||||
|
BitField<28, 4, BlendFactor> factor_dest_a;
|
||||||
|
} alpha_blending;
|
||||||
|
|
||||||
|
union {
|
||||||
|
BitField<0, 4, LogicOp> logic_op;
|
||||||
|
};
|
||||||
|
|
||||||
|
union {
|
||||||
|
u32 raw;
|
||||||
|
BitField<0, 8, u32> r;
|
||||||
|
BitField<8, 8, u32> g;
|
||||||
|
BitField<16, 8, u32> b;
|
||||||
|
BitField<24, 8, u32> a;
|
||||||
|
} blend_const;
|
||||||
|
|
||||||
|
union {
|
||||||
|
BitField<0, 1, u32> enable;
|
||||||
|
BitField<4, 3, CompareFunc> func;
|
||||||
|
BitField<8, 8, u32> ref;
|
||||||
|
} alpha_test;
|
||||||
|
|
||||||
|
struct {
|
||||||
|
union {
|
||||||
|
// Raw value of this register
|
||||||
|
u32 raw_func;
|
||||||
|
|
||||||
|
// If true, enable stencil testing
|
||||||
|
BitField<0, 1, u32> enable;
|
||||||
|
|
||||||
|
// Comparison operation for stencil testing
|
||||||
|
BitField<4, 3, CompareFunc> func;
|
||||||
|
|
||||||
|
// Mask used to control writing to the stencil buffer
|
||||||
|
BitField<8, 8, u32> write_mask;
|
||||||
|
|
||||||
|
// Value to compare against for stencil testing
|
||||||
|
BitField<16, 8, u32> reference_value;
|
||||||
|
|
||||||
|
// Mask to apply on stencil test inputs
|
||||||
|
BitField<24, 8, u32> input_mask;
|
||||||
|
};
|
||||||
|
|
||||||
|
union {
|
||||||
|
// Raw value of this register
|
||||||
|
u32 raw_op;
|
||||||
|
|
||||||
|
// Action to perform when the stencil test fails
|
||||||
|
BitField<0, 3, StencilAction> action_stencil_fail;
|
||||||
|
|
||||||
|
// Action to perform when stencil testing passed but depth testing fails
|
||||||
|
BitField<4, 3, StencilAction> action_depth_fail;
|
||||||
|
|
||||||
|
// Action to perform when both stencil and depth testing pass
|
||||||
|
BitField<8, 3, StencilAction> action_depth_pass;
|
||||||
|
};
|
||||||
|
} stencil_test;
|
||||||
|
|
||||||
|
union {
|
||||||
|
BitField<0, 1, u32> depth_test_enable;
|
||||||
|
BitField<4, 3, CompareFunc> depth_test_func;
|
||||||
|
BitField<8, 1, u32> red_enable;
|
||||||
|
BitField<9, 1, u32> green_enable;
|
||||||
|
BitField<10, 1, u32> blue_enable;
|
||||||
|
BitField<11, 1, u32> alpha_enable;
|
||||||
|
BitField<12, 1, u32> depth_write_enable;
|
||||||
|
};
|
||||||
|
|
||||||
|
INSERT_PADDING_WORDS(0x8);
|
||||||
|
} output_merger;
|
||||||
|
|
||||||
|
// Components are laid out in reverse byte order, most significant bits first.
|
||||||
|
enum class ColorFormat : u32 {
|
||||||
|
RGBA8 = 0,
|
||||||
|
RGB8 = 1,
|
||||||
|
RGB5A1 = 2,
|
||||||
|
RGB565 = 3,
|
||||||
|
RGBA4 = 4,
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class DepthFormat : u32 {
|
||||||
|
D16 = 0,
|
||||||
|
D24 = 2,
|
||||||
|
D24S8 = 3,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Returns the number of bytes in the specified color format
|
||||||
|
static unsigned BytesPerColorPixel(ColorFormat format) {
|
||||||
|
switch (format) {
|
||||||
|
case ColorFormat::RGBA8:
|
||||||
|
return 4;
|
||||||
|
case ColorFormat::RGB8:
|
||||||
|
return 3;
|
||||||
|
case ColorFormat::RGB5A1:
|
||||||
|
case ColorFormat::RGB565:
|
||||||
|
case ColorFormat::RGBA4:
|
||||||
|
return 2;
|
||||||
|
default:
|
||||||
|
LOG_CRITICAL(HW_GPU, "Unknown color format %u", format);
|
||||||
|
UNIMPLEMENTED();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct FramebufferConfig {
|
||||||
|
INSERT_PADDING_WORDS(0x3);
|
||||||
|
|
||||||
|
union {
|
||||||
|
BitField<0, 4, u32> allow_color_write; // 0 = disable, else enable
|
||||||
|
};
|
||||||
|
|
||||||
|
INSERT_PADDING_WORDS(0x1);
|
||||||
|
|
||||||
|
union {
|
||||||
|
BitField<0, 2, u32> allow_depth_stencil_write; // 0 = disable, else enable
|
||||||
|
};
|
||||||
|
|
||||||
|
DepthFormat depth_format; // TODO: Should be a BitField!
|
||||||
|
BitField<16, 3, ColorFormat> color_format;
|
||||||
|
|
||||||
|
INSERT_PADDING_WORDS(0x4);
|
||||||
|
|
||||||
|
u32 depth_buffer_address;
|
||||||
|
u32 color_buffer_address;
|
||||||
|
|
||||||
|
union {
|
||||||
|
// Apparently, the framebuffer width is stored as expected,
|
||||||
|
// while the height is stored as the actual height minus one.
|
||||||
|
// Hence, don't access these fields directly but use the accessors
|
||||||
|
// GetWidth() and GetHeight() instead.
|
||||||
|
BitField<0, 11, u32> width;
|
||||||
|
BitField<12, 10, u32> height;
|
||||||
|
};
|
||||||
|
|
||||||
|
INSERT_PADDING_WORDS(0x1);
|
||||||
|
|
||||||
|
inline PAddr GetColorBufferPhysicalAddress() const {
|
||||||
|
return color_buffer_address * 8;
|
||||||
|
}
|
||||||
|
inline PAddr GetDepthBufferPhysicalAddress() const {
|
||||||
|
return depth_buffer_address * 8;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline u32 GetWidth() const {
|
||||||
|
return width;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline u32 GetHeight() const {
|
||||||
|
return height + 1;
|
||||||
|
}
|
||||||
|
} framebuffer;
|
||||||
|
|
||||||
|
// 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns the number of bits per depth component of the specified depth format
|
||||||
|
static u32 DepthBitsPerPixel(DepthFormat format) {
|
||||||
|
switch (format) {
|
||||||
|
case DepthFormat::D16:
|
||||||
|
return 16;
|
||||||
|
case DepthFormat::D24:
|
||||||
|
case DepthFormat::D24S8:
|
||||||
|
return 24;
|
||||||
|
default:
|
||||||
|
LOG_CRITICAL(HW_GPU, "Unknown depth format %u", format);
|
||||||
|
UNIMPLEMENTED();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
INSERT_PADDING_WORDS(0x20);
|
||||||
|
};
|
||||||
|
|
||||||
|
static_assert(sizeof(FramebufferRegs) == 0x40 * sizeof(u32),
|
||||||
|
"FramebufferRegs struct has incorrect size");
|
||||||
|
|
||||||
|
} // namespace Pica
|
|
@ -183,7 +183,7 @@ void RasterizerOpenGL::DrawTriangles() {
|
||||||
CachedSurface* depth_surface;
|
CachedSurface* depth_surface;
|
||||||
MathUtil::Rectangle<int> rect;
|
MathUtil::Rectangle<int> rect;
|
||||||
std::tie(color_surface, depth_surface, rect) =
|
std::tie(color_surface, depth_surface, rect) =
|
||||||
res_cache.GetFramebufferSurfaces(regs.framebuffer);
|
res_cache.GetFramebufferSurfaces(regs.framebuffer.framebuffer);
|
||||||
|
|
||||||
state.draw.draw_framebuffer = framebuffer.handle;
|
state.draw.draw_framebuffer = framebuffer.handle;
|
||||||
state.Apply();
|
state.Apply();
|
||||||
|
@ -192,7 +192,8 @@ void RasterizerOpenGL::DrawTriangles() {
|
||||||
color_surface != nullptr ? color_surface->texture.handle : 0, 0);
|
color_surface != nullptr ? color_surface->texture.handle : 0, 0);
|
||||||
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D,
|
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D,
|
||||||
depth_surface != nullptr ? depth_surface->texture.handle : 0, 0);
|
depth_surface != nullptr ? depth_surface->texture.handle : 0, 0);
|
||||||
bool has_stencil = regs.framebuffer.depth_format == Pica::Regs::DepthFormat::D24S8;
|
bool has_stencil =
|
||||||
|
regs.framebuffer.framebuffer.depth_format == Pica::FramebufferRegs::DepthFormat::D24S8;
|
||||||
glFramebufferTexture2D(
|
glFramebufferTexture2D(
|
||||||
GL_DRAW_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_TEXTURE_2D,
|
GL_DRAW_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_TEXTURE_2D,
|
||||||
(has_stencil && depth_surface != nullptr) ? depth_surface->texture.handle : 0, 0);
|
(has_stencil && depth_surface != nullptr) ? depth_surface->texture.handle : 0, 0);
|
||||||
|
@ -339,13 +340,13 @@ void RasterizerOpenGL::NotifyPicaRegisterChanged(u32 id) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Blending
|
// Blending
|
||||||
case PICA_REG_INDEX(output_merger.alphablend_enable):
|
case PICA_REG_INDEX(framebuffer.output_merger.alphablend_enable):
|
||||||
SyncBlendEnabled();
|
SyncBlendEnabled();
|
||||||
break;
|
break;
|
||||||
case PICA_REG_INDEX(output_merger.alpha_blending):
|
case PICA_REG_INDEX(framebuffer.output_merger.alpha_blending):
|
||||||
SyncBlendFuncs();
|
SyncBlendFuncs();
|
||||||
break;
|
break;
|
||||||
case PICA_REG_INDEX(output_merger.blend_const):
|
case PICA_REG_INDEX(framebuffer.output_merger.blend_const):
|
||||||
SyncBlendColor();
|
SyncBlendColor();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -365,25 +366,25 @@ void RasterizerOpenGL::NotifyPicaRegisterChanged(u32 id) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Alpha test
|
// Alpha test
|
||||||
case PICA_REG_INDEX(output_merger.alpha_test):
|
case PICA_REG_INDEX(framebuffer.output_merger.alpha_test):
|
||||||
SyncAlphaTest();
|
SyncAlphaTest();
|
||||||
shader_dirty = true;
|
shader_dirty = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Sync GL stencil test + stencil write mask
|
// Sync GL stencil test + stencil write mask
|
||||||
// (Pica stencil test function register also contains a stencil write mask)
|
// (Pica stencil test function register also contains a stencil write mask)
|
||||||
case PICA_REG_INDEX(output_merger.stencil_test.raw_func):
|
case PICA_REG_INDEX(framebuffer.output_merger.stencil_test.raw_func):
|
||||||
SyncStencilTest();
|
SyncStencilTest();
|
||||||
SyncStencilWriteMask();
|
SyncStencilWriteMask();
|
||||||
break;
|
break;
|
||||||
case PICA_REG_INDEX(output_merger.stencil_test.raw_op):
|
case PICA_REG_INDEX(framebuffer.output_merger.stencil_test.raw_op):
|
||||||
case PICA_REG_INDEX(framebuffer.depth_format):
|
case PICA_REG_INDEX(framebuffer.framebuffer.depth_format):
|
||||||
SyncStencilTest();
|
SyncStencilTest();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Sync GL depth test + depth and color write mask
|
// Sync GL depth test + depth and color write mask
|
||||||
// (Pica depth test function register also contains a depth and color write mask)
|
// (Pica depth test function register also contains a depth and color write mask)
|
||||||
case PICA_REG_INDEX(output_merger.depth_test_enable):
|
case PICA_REG_INDEX(framebuffer.output_merger.depth_test_enable):
|
||||||
SyncDepthTest();
|
SyncDepthTest();
|
||||||
SyncDepthWriteMask();
|
SyncDepthWriteMask();
|
||||||
SyncColorWriteMask();
|
SyncColorWriteMask();
|
||||||
|
@ -391,14 +392,14 @@ void RasterizerOpenGL::NotifyPicaRegisterChanged(u32 id) {
|
||||||
|
|
||||||
// Sync GL depth and stencil write mask
|
// Sync GL depth and stencil write mask
|
||||||
// (This is a dedicated combined depth / stencil write-enable register)
|
// (This is a dedicated combined depth / stencil write-enable register)
|
||||||
case PICA_REG_INDEX(framebuffer.allow_depth_stencil_write):
|
case PICA_REG_INDEX(framebuffer.framebuffer.allow_depth_stencil_write):
|
||||||
SyncDepthWriteMask();
|
SyncDepthWriteMask();
|
||||||
SyncStencilWriteMask();
|
SyncStencilWriteMask();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Sync GL color write mask
|
// Sync GL color write mask
|
||||||
// (This is a dedicated color write-enable register)
|
// (This is a dedicated color write-enable register)
|
||||||
case PICA_REG_INDEX(framebuffer.allow_color_write):
|
case PICA_REG_INDEX(framebuffer.framebuffer.allow_color_write):
|
||||||
SyncColorWriteMask();
|
SyncColorWriteMask();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -408,7 +409,7 @@ void RasterizerOpenGL::NotifyPicaRegisterChanged(u32 id) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Logic op
|
// Logic op
|
||||||
case PICA_REG_INDEX(output_merger.logic_op):
|
case PICA_REG_INDEX(framebuffer.output_merger.logic_op):
|
||||||
SyncLogicOp();
|
SyncLogicOp();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -1158,25 +1159,28 @@ void RasterizerOpenGL::SyncDepthOffset() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void RasterizerOpenGL::SyncBlendEnabled() {
|
void RasterizerOpenGL::SyncBlendEnabled() {
|
||||||
state.blend.enabled = (Pica::g_state.regs.output_merger.alphablend_enable == 1);
|
state.blend.enabled = (Pica::g_state.regs.framebuffer.output_merger.alphablend_enable == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RasterizerOpenGL::SyncBlendFuncs() {
|
void RasterizerOpenGL::SyncBlendFuncs() {
|
||||||
const auto& regs = Pica::g_state.regs;
|
const auto& regs = Pica::g_state.regs;
|
||||||
state.blend.rgb_equation =
|
state.blend.rgb_equation =
|
||||||
PicaToGL::BlendEquation(regs.output_merger.alpha_blending.blend_equation_rgb);
|
PicaToGL::BlendEquation(regs.framebuffer.output_merger.alpha_blending.blend_equation_rgb);
|
||||||
state.blend.a_equation =
|
state.blend.a_equation =
|
||||||
PicaToGL::BlendEquation(regs.output_merger.alpha_blending.blend_equation_a);
|
PicaToGL::BlendEquation(regs.framebuffer.output_merger.alpha_blending.blend_equation_a);
|
||||||
state.blend.src_rgb_func =
|
state.blend.src_rgb_func =
|
||||||
PicaToGL::BlendFunc(regs.output_merger.alpha_blending.factor_source_rgb);
|
PicaToGL::BlendFunc(regs.framebuffer.output_merger.alpha_blending.factor_source_rgb);
|
||||||
state.blend.dst_rgb_func =
|
state.blend.dst_rgb_func =
|
||||||
PicaToGL::BlendFunc(regs.output_merger.alpha_blending.factor_dest_rgb);
|
PicaToGL::BlendFunc(regs.framebuffer.output_merger.alpha_blending.factor_dest_rgb);
|
||||||
state.blend.src_a_func = PicaToGL::BlendFunc(regs.output_merger.alpha_blending.factor_source_a);
|
state.blend.src_a_func =
|
||||||
state.blend.dst_a_func = PicaToGL::BlendFunc(regs.output_merger.alpha_blending.factor_dest_a);
|
PicaToGL::BlendFunc(regs.framebuffer.output_merger.alpha_blending.factor_source_a);
|
||||||
|
state.blend.dst_a_func =
|
||||||
|
PicaToGL::BlendFunc(regs.framebuffer.output_merger.alpha_blending.factor_dest_a);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RasterizerOpenGL::SyncBlendColor() {
|
void RasterizerOpenGL::SyncBlendColor() {
|
||||||
auto blend_color = PicaToGL::ColorRGBA8(Pica::g_state.regs.output_merger.blend_const.raw);
|
auto blend_color =
|
||||||
|
PicaToGL::ColorRGBA8(Pica::g_state.regs.framebuffer.output_merger.blend_const.raw);
|
||||||
state.blend.color.red = blend_color[0];
|
state.blend.color.red = blend_color[0];
|
||||||
state.blend.color.green = blend_color[1];
|
state.blend.color.green = blend_color[1];
|
||||||
state.blend.color.blue = blend_color[2];
|
state.blend.color.blue = blend_color[2];
|
||||||
|
@ -1208,66 +1212,73 @@ void RasterizerOpenGL::SyncFogLUT() {
|
||||||
|
|
||||||
void RasterizerOpenGL::SyncAlphaTest() {
|
void RasterizerOpenGL::SyncAlphaTest() {
|
||||||
const auto& regs = Pica::g_state.regs;
|
const auto& regs = Pica::g_state.regs;
|
||||||
if (regs.output_merger.alpha_test.ref != uniform_block_data.data.alphatest_ref) {
|
if (regs.framebuffer.output_merger.alpha_test.ref != uniform_block_data.data.alphatest_ref) {
|
||||||
uniform_block_data.data.alphatest_ref = regs.output_merger.alpha_test.ref;
|
uniform_block_data.data.alphatest_ref = regs.framebuffer.output_merger.alpha_test.ref;
|
||||||
uniform_block_data.dirty = true;
|
uniform_block_data.dirty = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RasterizerOpenGL::SyncLogicOp() {
|
void RasterizerOpenGL::SyncLogicOp() {
|
||||||
state.logic_op = PicaToGL::LogicOp(Pica::g_state.regs.output_merger.logic_op);
|
state.logic_op = PicaToGL::LogicOp(Pica::g_state.regs.framebuffer.output_merger.logic_op);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RasterizerOpenGL::SyncColorWriteMask() {
|
void RasterizerOpenGL::SyncColorWriteMask() {
|
||||||
const auto& regs = Pica::g_state.regs;
|
const auto& regs = Pica::g_state.regs;
|
||||||
|
|
||||||
auto IsColorWriteEnabled = [&](u32 value) {
|
auto IsColorWriteEnabled = [&](u32 value) {
|
||||||
return (regs.framebuffer.allow_color_write != 0 && value != 0) ? GL_TRUE : GL_FALSE;
|
return (regs.framebuffer.framebuffer.allow_color_write != 0 && value != 0) ? GL_TRUE
|
||||||
|
: GL_FALSE;
|
||||||
};
|
};
|
||||||
|
|
||||||
state.color_mask.red_enabled = IsColorWriteEnabled(regs.output_merger.red_enable);
|
state.color_mask.red_enabled = IsColorWriteEnabled(regs.framebuffer.output_merger.red_enable);
|
||||||
state.color_mask.green_enabled = IsColorWriteEnabled(regs.output_merger.green_enable);
|
state.color_mask.green_enabled =
|
||||||
state.color_mask.blue_enabled = IsColorWriteEnabled(regs.output_merger.blue_enable);
|
IsColorWriteEnabled(regs.framebuffer.output_merger.green_enable);
|
||||||
state.color_mask.alpha_enabled = IsColorWriteEnabled(regs.output_merger.alpha_enable);
|
state.color_mask.blue_enabled = IsColorWriteEnabled(regs.framebuffer.output_merger.blue_enable);
|
||||||
|
state.color_mask.alpha_enabled =
|
||||||
|
IsColorWriteEnabled(regs.framebuffer.output_merger.alpha_enable);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RasterizerOpenGL::SyncStencilWriteMask() {
|
void RasterizerOpenGL::SyncStencilWriteMask() {
|
||||||
const auto& regs = Pica::g_state.regs;
|
const auto& regs = Pica::g_state.regs;
|
||||||
state.stencil.write_mask = (regs.framebuffer.allow_depth_stencil_write != 0)
|
state.stencil.write_mask =
|
||||||
? static_cast<GLuint>(regs.output_merger.stencil_test.write_mask)
|
(regs.framebuffer.framebuffer.allow_depth_stencil_write != 0)
|
||||||
: 0;
|
? static_cast<GLuint>(regs.framebuffer.output_merger.stencil_test.write_mask)
|
||||||
|
: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RasterizerOpenGL::SyncDepthWriteMask() {
|
void RasterizerOpenGL::SyncDepthWriteMask() {
|
||||||
const auto& regs = Pica::g_state.regs;
|
const auto& regs = Pica::g_state.regs;
|
||||||
state.depth.write_mask =
|
state.depth.write_mask = (regs.framebuffer.framebuffer.allow_depth_stencil_write != 0 &&
|
||||||
(regs.framebuffer.allow_depth_stencil_write != 0 && regs.output_merger.depth_write_enable)
|
regs.framebuffer.output_merger.depth_write_enable)
|
||||||
? GL_TRUE
|
? GL_TRUE
|
||||||
: GL_FALSE;
|
: GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RasterizerOpenGL::SyncStencilTest() {
|
void RasterizerOpenGL::SyncStencilTest() {
|
||||||
const auto& regs = Pica::g_state.regs;
|
const auto& regs = Pica::g_state.regs;
|
||||||
state.stencil.test_enabled = regs.output_merger.stencil_test.enable &&
|
state.stencil.test_enabled =
|
||||||
regs.framebuffer.depth_format == Pica::Regs::DepthFormat::D24S8;
|
regs.framebuffer.output_merger.stencil_test.enable &&
|
||||||
state.stencil.test_func = PicaToGL::CompareFunc(regs.output_merger.stencil_test.func);
|
regs.framebuffer.framebuffer.depth_format == Pica::FramebufferRegs::DepthFormat::D24S8;
|
||||||
state.stencil.test_ref = regs.output_merger.stencil_test.reference_value;
|
state.stencil.test_func =
|
||||||
state.stencil.test_mask = regs.output_merger.stencil_test.input_mask;
|
PicaToGL::CompareFunc(regs.framebuffer.output_merger.stencil_test.func);
|
||||||
|
state.stencil.test_ref = regs.framebuffer.output_merger.stencil_test.reference_value;
|
||||||
|
state.stencil.test_mask = regs.framebuffer.output_merger.stencil_test.input_mask;
|
||||||
state.stencil.action_stencil_fail =
|
state.stencil.action_stencil_fail =
|
||||||
PicaToGL::StencilOp(regs.output_merger.stencil_test.action_stencil_fail);
|
PicaToGL::StencilOp(regs.framebuffer.output_merger.stencil_test.action_stencil_fail);
|
||||||
state.stencil.action_depth_fail =
|
state.stencil.action_depth_fail =
|
||||||
PicaToGL::StencilOp(regs.output_merger.stencil_test.action_depth_fail);
|
PicaToGL::StencilOp(regs.framebuffer.output_merger.stencil_test.action_depth_fail);
|
||||||
state.stencil.action_depth_pass =
|
state.stencil.action_depth_pass =
|
||||||
PicaToGL::StencilOp(regs.output_merger.stencil_test.action_depth_pass);
|
PicaToGL::StencilOp(regs.framebuffer.output_merger.stencil_test.action_depth_pass);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RasterizerOpenGL::SyncDepthTest() {
|
void RasterizerOpenGL::SyncDepthTest() {
|
||||||
const auto& regs = Pica::g_state.regs;
|
const auto& regs = Pica::g_state.regs;
|
||||||
state.depth.test_enabled =
|
state.depth.test_enabled = regs.framebuffer.output_merger.depth_test_enable == 1 ||
|
||||||
regs.output_merger.depth_test_enable == 1 || regs.output_merger.depth_write_enable == 1;
|
regs.framebuffer.output_merger.depth_write_enable == 1;
|
||||||
state.depth.test_func = regs.output_merger.depth_test_enable == 1
|
state.depth.test_func =
|
||||||
? PicaToGL::CompareFunc(regs.output_merger.depth_test_func)
|
regs.framebuffer.output_merger.depth_test_enable == 1
|
||||||
: GL_ALWAYS;
|
? PicaToGL::CompareFunc(regs.framebuffer.output_merger.depth_test_func)
|
||||||
|
: GL_ALWAYS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RasterizerOpenGL::SyncCombinerColor() {
|
void RasterizerOpenGL::SyncCombinerColor() {
|
||||||
|
|
|
@ -56,9 +56,9 @@ union PicaShaderConfig {
|
||||||
|
|
||||||
state.depthmap_enable = regs.rasterizer.depthmap_enable;
|
state.depthmap_enable = regs.rasterizer.depthmap_enable;
|
||||||
|
|
||||||
state.alpha_test_func = regs.output_merger.alpha_test.enable
|
state.alpha_test_func = regs.framebuffer.output_merger.alpha_test.enable
|
||||||
? regs.output_merger.alpha_test.func.Value()
|
? regs.framebuffer.output_merger.alpha_test.func.Value()
|
||||||
: Pica::Regs::CompareFunc::Always;
|
: Pica::FramebufferRegs::CompareFunc::Always;
|
||||||
|
|
||||||
state.texture0_type = regs.texturing.texture0.type;
|
state.texture0_type = regs.texturing.texture0.type;
|
||||||
|
|
||||||
|
@ -172,7 +172,7 @@ union PicaShaderConfig {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct State {
|
struct State {
|
||||||
Pica::Regs::CompareFunc alpha_test_func;
|
Pica::FramebufferRegs::CompareFunc alpha_test_func;
|
||||||
Pica::RasterizerRegs::ScissorMode scissor_test_mode;
|
Pica::RasterizerRegs::ScissorMode scissor_test_mode;
|
||||||
Pica::TexturingRegs::TextureConfig::TextureType texture0_type;
|
Pica::TexturingRegs::TextureConfig::TextureType texture0_type;
|
||||||
std::array<TevStageConfigRaw, 6> tev_stages;
|
std::array<TevStageConfigRaw, 6> tev_stages;
|
||||||
|
|
|
@ -525,7 +525,9 @@ CachedSurface* RasterizerCacheOpenGL::GetTextureSurface(
|
||||||
}
|
}
|
||||||
|
|
||||||
std::tuple<CachedSurface*, CachedSurface*, MathUtil::Rectangle<int>>
|
std::tuple<CachedSurface*, CachedSurface*, MathUtil::Rectangle<int>>
|
||||||
RasterizerCacheOpenGL::GetFramebufferSurfaces(const Pica::Regs::FramebufferConfig& config) {
|
RasterizerCacheOpenGL::GetFramebufferSurfaces(
|
||||||
|
const Pica::FramebufferRegs::FramebufferConfig& config) {
|
||||||
|
|
||||||
const auto& regs = Pica::g_state.regs;
|
const auto& regs = Pica::g_state.regs;
|
||||||
|
|
||||||
// Make sur that framebuffers don't overlap if both color and depth are being used
|
// Make sur that framebuffers don't overlap if both color and depth are being used
|
||||||
|
@ -537,11 +539,12 @@ RasterizerCacheOpenGL::GetFramebufferSurfaces(const Pica::Regs::FramebufferConfi
|
||||||
config.GetColorBufferPhysicalAddress(),
|
config.GetColorBufferPhysicalAddress(),
|
||||||
fb_area * GPU::Regs::BytesPerPixel(GPU::Regs::PixelFormat(config.color_format.Value())),
|
fb_area * GPU::Regs::BytesPerPixel(GPU::Regs::PixelFormat(config.color_format.Value())),
|
||||||
config.GetDepthBufferPhysicalAddress(),
|
config.GetDepthBufferPhysicalAddress(),
|
||||||
fb_area * Pica::Regs::BytesPerDepthPixel(config.depth_format));
|
fb_area * Pica::FramebufferRegs::BytesPerDepthPixel(config.depth_format));
|
||||||
bool using_color_fb = config.GetColorBufferPhysicalAddress() != 0;
|
bool using_color_fb = config.GetColorBufferPhysicalAddress() != 0;
|
||||||
bool using_depth_fb = config.GetDepthBufferPhysicalAddress() != 0 &&
|
bool using_depth_fb =
|
||||||
(regs.output_merger.depth_test_enable ||
|
config.GetDepthBufferPhysicalAddress() != 0 &&
|
||||||
regs.output_merger.depth_write_enable || !framebuffers_overlap);
|
(regs.framebuffer.output_merger.depth_test_enable ||
|
||||||
|
regs.framebuffer.output_merger.depth_write_enable || !framebuffers_overlap);
|
||||||
|
|
||||||
if (framebuffers_overlap && using_color_fb && using_depth_fb) {
|
if (framebuffers_overlap && using_color_fb && using_depth_fb) {
|
||||||
LOG_CRITICAL(Render_OpenGL, "Color and depth framebuffer memory regions overlap; "
|
LOG_CRITICAL(Render_OpenGL, "Color and depth framebuffer memory regions overlap; "
|
||||||
|
|
|
@ -100,11 +100,11 @@ struct CachedSurface {
|
||||||
return ((unsigned int)format < 14) ? (PixelFormat)format : PixelFormat::Invalid;
|
return ((unsigned int)format < 14) ? (PixelFormat)format : PixelFormat::Invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PixelFormat PixelFormatFromColorFormat(Pica::Regs::ColorFormat format) {
|
static PixelFormat PixelFormatFromColorFormat(Pica::FramebufferRegs::ColorFormat format) {
|
||||||
return ((unsigned int)format < 5) ? (PixelFormat)format : PixelFormat::Invalid;
|
return ((unsigned int)format < 5) ? (PixelFormat)format : PixelFormat::Invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PixelFormat PixelFormatFromDepthFormat(Pica::Regs::DepthFormat format) {
|
static PixelFormat PixelFormatFromDepthFormat(Pica::FramebufferRegs::DepthFormat format) {
|
||||||
return ((unsigned int)format < 4) ? (PixelFormat)((unsigned int)format + 14)
|
return ((unsigned int)format < 4) ? (PixelFormat)((unsigned int)format + 14)
|
||||||
: PixelFormat::Invalid;
|
: PixelFormat::Invalid;
|
||||||
}
|
}
|
||||||
|
@ -217,7 +217,7 @@ public:
|
||||||
/// Gets the color and depth surfaces and rect (resolution scaled) based on the framebuffer
|
/// Gets the color and depth surfaces and rect (resolution scaled) based on the framebuffer
|
||||||
/// configuration
|
/// configuration
|
||||||
std::tuple<CachedSurface*, CachedSurface*, MathUtil::Rectangle<int>> GetFramebufferSurfaces(
|
std::tuple<CachedSurface*, CachedSurface*, MathUtil::Rectangle<int>> GetFramebufferSurfaces(
|
||||||
const Pica::Regs::FramebufferConfig& config);
|
const Pica::FramebufferRegs::FramebufferConfig& config);
|
||||||
|
|
||||||
/// Attempt to get a surface that exactly matches the fill region and format
|
/// Attempt to get a surface that exactly matches the fill region and format
|
||||||
CachedSurface* TryGetFillSurface(const GPU::Regs::MemoryFillConfig& config);
|
CachedSurface* TryGetFillSurface(const GPU::Regs::MemoryFillConfig& config);
|
||||||
|
|
|
@ -277,8 +277,8 @@ static void AppendAlphaCombiner(std::string& out, TevStageConfig::Operation oper
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Writes the if-statement condition used to evaluate alpha testing
|
/// Writes the if-statement condition used to evaluate alpha testing
|
||||||
static void AppendAlphaTestCondition(std::string& out, Regs::CompareFunc func) {
|
static void AppendAlphaTestCondition(std::string& out, Pica::FramebufferRegs::CompareFunc func) {
|
||||||
using CompareFunc = Regs::CompareFunc;
|
using CompareFunc = Pica::FramebufferRegs::CompareFunc;
|
||||||
switch (func) {
|
switch (func) {
|
||||||
case CompareFunc::Never:
|
case CompareFunc::Never:
|
||||||
out += "true";
|
out += "true";
|
||||||
|
@ -634,7 +634,7 @@ vec4 secondary_fragment_color = vec4(0.0);
|
||||||
)";
|
)";
|
||||||
|
|
||||||
// Do not do any sort of processing if it's obvious we're not going to pass the alpha test
|
// Do not do any sort of processing if it's obvious we're not going to pass the alpha test
|
||||||
if (state.alpha_test_func == Regs::CompareFunc::Never) {
|
if (state.alpha_test_func == Pica::FramebufferRegs::CompareFunc::Never) {
|
||||||
out += "discard; }";
|
out += "discard; }";
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
@ -667,7 +667,7 @@ vec4 secondary_fragment_color = vec4(0.0);
|
||||||
for (size_t index = 0; index < state.tev_stages.size(); ++index)
|
for (size_t index = 0; index < state.tev_stages.size(); ++index)
|
||||||
WriteTevStage(out, config, (unsigned)index);
|
WriteTevStage(out, config, (unsigned)index);
|
||||||
|
|
||||||
if (state.alpha_test_func != Regs::CompareFunc::Always) {
|
if (state.alpha_test_func != Pica::FramebufferRegs::CompareFunc::Always) {
|
||||||
out += "if (";
|
out += "if (";
|
||||||
AppendAlphaTestCondition(out, state.alpha_test_func);
|
AppendAlphaTestCondition(out, state.alpha_test_func);
|
||||||
out += ") discard;\n";
|
out += ") discard;\n";
|
||||||
|
|
|
@ -76,7 +76,7 @@ inline GLenum WrapMode(Pica::TexturingRegs::TextureConfig::WrapMode mode) {
|
||||||
return gl_mode;
|
return gl_mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline GLenum BlendEquation(Pica::Regs::BlendEquation equation) {
|
inline GLenum BlendEquation(Pica::FramebufferRegs::BlendEquation equation) {
|
||||||
static const GLenum blend_equation_table[] = {
|
static const GLenum blend_equation_table[] = {
|
||||||
GL_FUNC_ADD, // BlendEquation::Add
|
GL_FUNC_ADD, // BlendEquation::Add
|
||||||
GL_FUNC_SUBTRACT, // BlendEquation::Subtract
|
GL_FUNC_SUBTRACT, // BlendEquation::Subtract
|
||||||
|
@ -96,7 +96,7 @@ inline GLenum BlendEquation(Pica::Regs::BlendEquation equation) {
|
||||||
return blend_equation_table[(unsigned)equation];
|
return blend_equation_table[(unsigned)equation];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline GLenum BlendFunc(Pica::Regs::BlendFactor factor) {
|
inline GLenum BlendFunc(Pica::FramebufferRegs::BlendFactor factor) {
|
||||||
static const GLenum blend_func_table[] = {
|
static const GLenum blend_func_table[] = {
|
||||||
GL_ZERO, // BlendFactor::Zero
|
GL_ZERO, // BlendFactor::Zero
|
||||||
GL_ONE, // BlendFactor::One
|
GL_ONE, // BlendFactor::One
|
||||||
|
@ -126,7 +126,7 @@ inline GLenum BlendFunc(Pica::Regs::BlendFactor factor) {
|
||||||
return blend_func_table[(unsigned)factor];
|
return blend_func_table[(unsigned)factor];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline GLenum LogicOp(Pica::Regs::LogicOp op) {
|
inline GLenum LogicOp(Pica::FramebufferRegs::LogicOp op) {
|
||||||
static const GLenum logic_op_table[] = {
|
static const GLenum logic_op_table[] = {
|
||||||
GL_CLEAR, // Clear
|
GL_CLEAR, // Clear
|
||||||
GL_AND, // And
|
GL_AND, // And
|
||||||
|
@ -157,7 +157,7 @@ inline GLenum LogicOp(Pica::Regs::LogicOp op) {
|
||||||
return logic_op_table[(unsigned)op];
|
return logic_op_table[(unsigned)op];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline GLenum CompareFunc(Pica::Regs::CompareFunc func) {
|
inline GLenum CompareFunc(Pica::FramebufferRegs::CompareFunc func) {
|
||||||
static const GLenum compare_func_table[] = {
|
static const GLenum compare_func_table[] = {
|
||||||
GL_NEVER, // CompareFunc::Never
|
GL_NEVER, // CompareFunc::Never
|
||||||
GL_ALWAYS, // CompareFunc::Always
|
GL_ALWAYS, // CompareFunc::Always
|
||||||
|
@ -180,7 +180,7 @@ inline GLenum CompareFunc(Pica::Regs::CompareFunc func) {
|
||||||
return compare_func_table[(unsigned)func];
|
return compare_func_table[(unsigned)func];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline GLenum StencilOp(Pica::Regs::StencilAction action) {
|
inline GLenum StencilOp(Pica::FramebufferRegs::StencilAction action) {
|
||||||
static const GLenum stencil_op_table[] = {
|
static const GLenum stencil_op_table[] = {
|
||||||
GL_KEEP, // StencilAction::Keep
|
GL_KEEP, // StencilAction::Keep
|
||||||
GL_ZERO, // StencilAction::Zero
|
GL_ZERO, // StencilAction::Zero
|
||||||
|
|
Loading…
Reference in a new issue