mirror of
				https://github.com/PabloMK7/citra.git
				synced 2025-11-04 07:38:47 +00:00 
			
		
		
		
	Y2R: Rework conversion process, enabling support for all formats
This commit is contained in:
		
							parent
							
								
									29d2b70ea4
								
							
						
					
					
						commit
						3e6663da43
					
				
					 5 changed files with 701 additions and 169 deletions
				
			
		| 
						 | 
				
			
			@ -9,8 +9,8 @@
 | 
			
		|||
#include "core/hle/hle.h"
 | 
			
		||||
#include "core/hle/kernel/event.h"
 | 
			
		||||
#include "core/hle/service/y2r_u.h"
 | 
			
		||||
#include "core/hw/y2r.h"
 | 
			
		||||
#include "core/mem_map.h"
 | 
			
		||||
#include "core/memory.h"
 | 
			
		||||
 | 
			
		||||
#include "video_core/utils.h"
 | 
			
		||||
#include "video_core/video_core.h"
 | 
			
		||||
| 
						 | 
				
			
			@ -20,47 +20,6 @@
 | 
			
		|||
 | 
			
		||||
namespace Y2R_U {
 | 
			
		||||
 | 
			
		||||
enum class InputFormat : u8 {
 | 
			
		||||
    /// 8-bit input, with YUV components in separate planes and using 4:2:2 subsampling.
 | 
			
		||||
    YUV422_Indiv8 = 0,
 | 
			
		||||
    /// 8-bit input, with YUV components in separate planes and using 4:2:0 subsampling.
 | 
			
		||||
    YUV420_Indiv8 = 1,
 | 
			
		||||
 | 
			
		||||
    YUV422_INDIV_16 = 2,
 | 
			
		||||
    YUV420_INDIV_16 = 3,
 | 
			
		||||
    YUV422_BATCH = 4,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
enum class OutputFormat : u8 {
 | 
			
		||||
    Rgb32 = 0,
 | 
			
		||||
    Rgb24 = 1,
 | 
			
		||||
    Rgb16_555 = 2,
 | 
			
		||||
    Rgb16_565 = 3,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
enum class Rotation : u8 {
 | 
			
		||||
    None = 0,
 | 
			
		||||
    Clockwise_90 = 1,
 | 
			
		||||
    Clockwise_180 = 2,
 | 
			
		||||
    Clockwise_270 = 3,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
enum class BlockAlignment : u8 {
 | 
			
		||||
    /// Image is output in linear format suitable for use as a framebuffer.
 | 
			
		||||
    Linear = 0,
 | 
			
		||||
    /// Image is output in tiled PICA format, suitable for use as a texture.
 | 
			
		||||
    Block8x8 = 1,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
enum class StandardCoefficient : u8 {
 | 
			
		||||
    ITU_Rec601 = 0,
 | 
			
		||||
    ITU_Rec709 = 1,
 | 
			
		||||
    ITU_Rec601_Scaling = 2,
 | 
			
		||||
    ITU_Rec709_Scaling = 3,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static Kernel::SharedPtr<Kernel::Event> completion_event;
 | 
			
		||||
 | 
			
		||||
struct ConversionParameters {
 | 
			
		||||
    InputFormat input_format;
 | 
			
		||||
    OutputFormat output_format;
 | 
			
		||||
| 
						 | 
				
			
			@ -74,28 +33,60 @@ struct ConversionParameters {
 | 
			
		|||
};
 | 
			
		||||
static_assert(sizeof(ConversionParameters) == 12, "ConversionParameters struct has incorrect size");
 | 
			
		||||
 | 
			
		||||
struct ConversionBuffer {
 | 
			
		||||
    VAddr address;
 | 
			
		||||
    u32 image_size;
 | 
			
		||||
    u16 transfer_unit;
 | 
			
		||||
    u16 stride;
 | 
			
		||||
static Kernel::SharedPtr<Kernel::Event> completion_event;
 | 
			
		||||
static ConversionConfiguration conversion;
 | 
			
		||||
 | 
			
		||||
static const CoefficientSet standard_coefficients[4] = {
 | 
			
		||||
    {{ 0x100, 0x166, 0xB6, 0x58, 0x1C5, -0x166F, 0x10EE, -0x1C5B }}, // ITU_Rec601
 | 
			
		||||
    {{ 0x100, 0x193, 0x77, 0x2F, 0x1DB, -0x1933,  0xA7C, -0x1D51 }}, // ITU_Rec709
 | 
			
		||||
    {{ 0x12A, 0x198, 0xD0, 0x64, 0x204, -0x1BDE, 0x10F2, -0x229B }}, // ITU_Rec601_Scaling
 | 
			
		||||
    {{ 0x12A, 0x1CA, 0x88, 0x36, 0x21C, -0x1F04,  0x99C, -0x2421 }}, // ITU_Rec709_Scaling
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct ConversionData {
 | 
			
		||||
    ConversionParameters params;
 | 
			
		||||
    /// Input parameters for the Y (luma) plane
 | 
			
		||||
    ConversionBuffer src_Y;
 | 
			
		||||
    /// Output parameters for the conversion results
 | 
			
		||||
    ConversionBuffer dst;
 | 
			
		||||
};
 | 
			
		||||
ResultCode ConversionConfiguration::SetInputLineWidth(u16 width) {
 | 
			
		||||
    if (width == 0 || width > 1024 || width % 8 != 0) {
 | 
			
		||||
        return ResultCode(ErrorDescription::OutOfRange, ErrorModule::CAM,
 | 
			
		||||
            ErrorSummary::InvalidArgument, ErrorLevel::Usage); // 0xE0E053FD
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
static ConversionData conversion;
 | 
			
		||||
    // Note: The hardware uses the register value 0 to represent a width of 1024, so for a width of
 | 
			
		||||
    // 1024 the `camera` module would set the value 0 here, but we don't need to emulate this
 | 
			
		||||
    // internal detail.
 | 
			
		||||
    this->input_line_width = width;
 | 
			
		||||
    return RESULT_SUCCESS;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ResultCode ConversionConfiguration::SetInputLines(u16 lines) {
 | 
			
		||||
    if (lines == 0 || lines > 1024) {
 | 
			
		||||
        return ResultCode(ErrorDescription::OutOfRange, ErrorModule::CAM,
 | 
			
		||||
            ErrorSummary::InvalidArgument, ErrorLevel::Usage); // 0xE0E053FD
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Note: In what appears to be a bug, the `camera` module does not set the hardware register at
 | 
			
		||||
    // all if `lines` is 1024, so the conversion uses the last value that was set. The intention
 | 
			
		||||
    // was probably to set it to 0 like in SetInputLineWidth.
 | 
			
		||||
    if (lines != 1024) {
 | 
			
		||||
        this->input_lines = lines;
 | 
			
		||||
    }
 | 
			
		||||
    return RESULT_SUCCESS;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ResultCode ConversionConfiguration::SetStandardCoefficient(StandardCoefficient standard_coefficient) {
 | 
			
		||||
    size_t index = static_cast<size_t>(standard_coefficient);
 | 
			
		||||
    if (index >= 4) {
 | 
			
		||||
        return ResultCode(ErrorDescription::InvalidEnumValue, ErrorModule::CAM,
 | 
			
		||||
            ErrorSummary::InvalidArgument, ErrorLevel::Usage); // 0xE0E053ED
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    std::memcpy(coefficients.data(), standard_coefficients[index].data(), sizeof(coefficients));
 | 
			
		||||
    return RESULT_SUCCESS;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void SetInputFormat(Service::Interface* self) {
 | 
			
		||||
    u32* cmd_buff = Kernel::GetCommandBuffer();
 | 
			
		||||
 | 
			
		||||
    conversion.params.input_format = static_cast<InputFormat>(cmd_buff[1]);
 | 
			
		||||
    LOG_DEBUG(Service_Y2R, "called input_format=%u", conversion.params.input_format);
 | 
			
		||||
    conversion.input_format = static_cast<InputFormat>(cmd_buff[1]);
 | 
			
		||||
    LOG_DEBUG(Service_Y2R, "called input_format=%hhu", conversion.input_format);
 | 
			
		||||
 | 
			
		||||
    cmd_buff[1] = RESULT_SUCCESS.raw;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -103,8 +94,8 @@ static void SetInputFormat(Service::Interface* self) {
 | 
			
		|||
static void SetOutputFormat(Service::Interface* self) {
 | 
			
		||||
    u32* cmd_buff = Kernel::GetCommandBuffer();
 | 
			
		||||
 | 
			
		||||
    conversion.params.output_format = static_cast<OutputFormat>(cmd_buff[1]);
 | 
			
		||||
    LOG_DEBUG(Service_Y2R, "called output_format=%u", conversion.params.output_format);
 | 
			
		||||
    conversion.output_format = static_cast<OutputFormat>(cmd_buff[1]);
 | 
			
		||||
    LOG_DEBUG(Service_Y2R, "called output_format=%hhu", conversion.output_format);
 | 
			
		||||
 | 
			
		||||
    cmd_buff[1] = RESULT_SUCCESS.raw;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -112,8 +103,8 @@ static void SetOutputFormat(Service::Interface* self) {
 | 
			
		|||
static void SetRotation(Service::Interface* self) {
 | 
			
		||||
    u32* cmd_buff = Kernel::GetCommandBuffer();
 | 
			
		||||
 | 
			
		||||
    conversion.params.rotation = static_cast<Rotation>(cmd_buff[1]);
 | 
			
		||||
    LOG_DEBUG(Service_Y2R, "called rotation=%u", conversion.params.rotation);
 | 
			
		||||
    conversion.rotation = static_cast<Rotation>(cmd_buff[1]);
 | 
			
		||||
    LOG_DEBUG(Service_Y2R, "called rotation=%hhu", conversion.rotation);
 | 
			
		||||
 | 
			
		||||
    cmd_buff[1] = RESULT_SUCCESS.raw;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -121,12 +112,20 @@ static void SetRotation(Service::Interface* self) {
 | 
			
		|||
static void SetBlockAlignment(Service::Interface* self) {
 | 
			
		||||
    u32* cmd_buff = Kernel::GetCommandBuffer();
 | 
			
		||||
 | 
			
		||||
    conversion.params.block_alignment = static_cast<BlockAlignment>(cmd_buff[1]);
 | 
			
		||||
    LOG_DEBUG(Service_Y2R, "called alignment=%u", conversion.params.block_alignment);
 | 
			
		||||
    conversion.block_alignment = static_cast<BlockAlignment>(cmd_buff[1]);
 | 
			
		||||
    LOG_DEBUG(Service_Y2R, "called alignment=%hhu", conversion.block_alignment);
 | 
			
		||||
 | 
			
		||||
    cmd_buff[1] = RESULT_SUCCESS.raw;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void SetTransferEndInterrupt(Service::Interface* self) {
 | 
			
		||||
    u32* cmd_buff = Kernel::GetCommandBuffer();
 | 
			
		||||
 | 
			
		||||
    cmd_buff[0] = 0x000D0040;
 | 
			
		||||
    cmd_buff[1] = RESULT_SUCCESS.raw;
 | 
			
		||||
    LOG_DEBUG(Service_Y2R, "(STUBBED) called");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Y2R_U::GetTransferEndEvent service function
 | 
			
		||||
 *  Outputs:
 | 
			
		||||
| 
						 | 
				
			
			@ -147,11 +146,56 @@ static void SetSendingY(Service::Interface* self) {
 | 
			
		|||
    conversion.src_Y.address = cmd_buff[1];
 | 
			
		||||
    conversion.src_Y.image_size = cmd_buff[2];
 | 
			
		||||
    conversion.src_Y.transfer_unit = cmd_buff[3];
 | 
			
		||||
    conversion.src_Y.stride = cmd_buff[4];
 | 
			
		||||
    conversion.src_Y.gap = cmd_buff[4];
 | 
			
		||||
    u32 src_process_handle = cmd_buff[6];
 | 
			
		||||
    LOG_DEBUG(Service_Y2R, "called image_size=0x%08X, transfer_unit=%hu, transfer_stride=%hu, "
 | 
			
		||||
        "src_process_handle=0x%08X", conversion.src_Y.image_size,
 | 
			
		||||
        conversion.src_Y.transfer_unit, conversion.src_Y.stride, src_process_handle);
 | 
			
		||||
        conversion.src_Y.transfer_unit, conversion.src_Y.gap, src_process_handle);
 | 
			
		||||
 | 
			
		||||
    cmd_buff[1] = RESULT_SUCCESS.raw;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void SetSendingU(Service::Interface* self) {
 | 
			
		||||
    u32* cmd_buff = Kernel::GetCommandBuffer();
 | 
			
		||||
 | 
			
		||||
    conversion.src_U.address = cmd_buff[1];
 | 
			
		||||
    conversion.src_U.image_size = cmd_buff[2];
 | 
			
		||||
    conversion.src_U.transfer_unit = cmd_buff[3];
 | 
			
		||||
    conversion.src_U.gap = cmd_buff[4];
 | 
			
		||||
    u32 src_process_handle = cmd_buff[6];
 | 
			
		||||
    LOG_DEBUG(Service_Y2R, "called image_size=0x%08X, transfer_unit=%hu, transfer_stride=%hu, "
 | 
			
		||||
        "src_process_handle=0x%08X", conversion.src_U.image_size,
 | 
			
		||||
        conversion.src_U.transfer_unit, conversion.src_U.gap, src_process_handle);
 | 
			
		||||
 | 
			
		||||
    cmd_buff[1] = RESULT_SUCCESS.raw;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void SetSendingV(Service::Interface* self) {
 | 
			
		||||
    u32* cmd_buff = Kernel::GetCommandBuffer();
 | 
			
		||||
 | 
			
		||||
    conversion.src_V.address = cmd_buff[1];
 | 
			
		||||
    conversion.src_V.image_size = cmd_buff[2];
 | 
			
		||||
    conversion.src_V.transfer_unit = cmd_buff[3];
 | 
			
		||||
    conversion.src_V.gap = cmd_buff[4];
 | 
			
		||||
    u32 src_process_handle = cmd_buff[6];
 | 
			
		||||
    LOG_DEBUG(Service_Y2R, "called image_size=0x%08X, transfer_unit=%hu, transfer_stride=%hu, "
 | 
			
		||||
        "src_process_handle=0x%08X", conversion.src_V.image_size,
 | 
			
		||||
        conversion.src_V.transfer_unit, conversion.src_V.gap, src_process_handle);
 | 
			
		||||
 | 
			
		||||
    cmd_buff[1] = RESULT_SUCCESS.raw;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void SetSendingYUYV(Service::Interface* self) {
 | 
			
		||||
    u32* cmd_buff = Kernel::GetCommandBuffer();
 | 
			
		||||
 | 
			
		||||
    conversion.src_YUYV.address = cmd_buff[1];
 | 
			
		||||
    conversion.src_YUYV.image_size = cmd_buff[2];
 | 
			
		||||
    conversion.src_YUYV.transfer_unit = cmd_buff[3];
 | 
			
		||||
    conversion.src_YUYV.gap = cmd_buff[4];
 | 
			
		||||
    u32 src_process_handle = cmd_buff[6];
 | 
			
		||||
    LOG_DEBUG(Service_Y2R, "called image_size=0x%08X, transfer_unit=%hu, transfer_stride=%hu, "
 | 
			
		||||
        "src_process_handle=0x%08X", conversion.src_YUYV.image_size,
 | 
			
		||||
        conversion.src_YUYV.transfer_unit, conversion.src_YUYV.gap, src_process_handle);
 | 
			
		||||
 | 
			
		||||
    cmd_buff[1] = RESULT_SUCCESS.raw;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -162,11 +206,11 @@ static void SetReceiving(Service::Interface* self) {
 | 
			
		|||
    conversion.dst.address = cmd_buff[1];
 | 
			
		||||
    conversion.dst.image_size = cmd_buff[2];
 | 
			
		||||
    conversion.dst.transfer_unit = cmd_buff[3];
 | 
			
		||||
    conversion.dst.stride = cmd_buff[4];
 | 
			
		||||
    conversion.dst.gap = cmd_buff[4];
 | 
			
		||||
    u32 dst_process_handle = cmd_buff[6];
 | 
			
		||||
    LOG_DEBUG(Service_Y2R, "called image_size=0x%08X, transfer_unit=%hu, transfer_stride=%hu, "
 | 
			
		||||
        "dst_process_handle=0x%08X", conversion.dst.image_size,
 | 
			
		||||
        conversion.dst.transfer_unit, conversion.dst.stride,
 | 
			
		||||
        conversion.dst.transfer_unit, conversion.dst.gap,
 | 
			
		||||
        dst_process_handle);
 | 
			
		||||
 | 
			
		||||
    cmd_buff[1] = RESULT_SUCCESS.raw;
 | 
			
		||||
| 
						 | 
				
			
			@ -175,17 +219,42 @@ static void SetReceiving(Service::Interface* self) {
 | 
			
		|||
static void SetInputLineWidth(Service::Interface* self) {
 | 
			
		||||
    u32* cmd_buff = Kernel::GetCommandBuffer();
 | 
			
		||||
 | 
			
		||||
    conversion.params.input_line_width = cmd_buff[1];
 | 
			
		||||
    LOG_DEBUG(Service_Y2R, "input_line_width=%u", conversion.params.input_line_width);
 | 
			
		||||
 | 
			
		||||
    cmd_buff[1] = RESULT_SUCCESS.raw;
 | 
			
		||||
    LOG_DEBUG(Service_Y2R, "called input_line_width=%u", cmd_buff[1]);
 | 
			
		||||
    cmd_buff[1] = conversion.SetInputLineWidth(cmd_buff[1]).raw;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void SetInputLines(Service::Interface* self) {
 | 
			
		||||
    u32* cmd_buff = Kernel::GetCommandBuffer();
 | 
			
		||||
 | 
			
		||||
    conversion.params.input_lines = cmd_buff[1];
 | 
			
		||||
    LOG_DEBUG(Service_Y2R, "input_line_number=%u", conversion.params.input_lines);
 | 
			
		||||
    LOG_DEBUG(Service_Y2R, "called input_line_number=%u", cmd_buff[1]);
 | 
			
		||||
    cmd_buff[1] = conversion.SetInputLines(cmd_buff[1]).raw;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void SetCoefficient(Service::Interface* self) {
 | 
			
		||||
    u32* cmd_buff = Kernel::GetCommandBuffer();
 | 
			
		||||
 | 
			
		||||
    const u16* coefficients = reinterpret_cast<const u16*>(&cmd_buff[1]);
 | 
			
		||||
    std::memcpy(conversion.coefficients.data(), coefficients, sizeof(CoefficientSet));
 | 
			
		||||
    LOG_DEBUG(Service_Y2R, "called coefficients=[%hX, %hX, %hX, %hX, %hX, %hX, %hX, %hX]",
 | 
			
		||||
            coefficients[0], coefficients[1], coefficients[2], coefficients[3],
 | 
			
		||||
            coefficients[4], coefficients[5], coefficients[6], coefficients[7]);
 | 
			
		||||
 | 
			
		||||
    cmd_buff[1] = RESULT_SUCCESS.raw;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void SetStandardCoefficient(Service::Interface* self) {
 | 
			
		||||
    u32* cmd_buff = Kernel::GetCommandBuffer();
 | 
			
		||||
 | 
			
		||||
    LOG_DEBUG(Service_Y2R, "called standard_coefficient=%u", cmd_buff[1]);
 | 
			
		||||
 | 
			
		||||
    cmd_buff[1] = conversion.SetStandardCoefficient((StandardCoefficient)cmd_buff[1]).raw;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void SetAlpha(Service::Interface* self) {
 | 
			
		||||
    u32* cmd_buff = Kernel::GetCommandBuffer();
 | 
			
		||||
 | 
			
		||||
    conversion.alpha = cmd_buff[1];
 | 
			
		||||
    LOG_DEBUG(Service_Y2R, "called alpha=%hu", conversion.alpha);
 | 
			
		||||
 | 
			
		||||
    cmd_buff[1] = RESULT_SUCCESS.raw;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -193,89 +262,11 @@ static void SetInputLines(Service::Interface* self) {
 | 
			
		|||
static void StartConversion(Service::Interface* self) {
 | 
			
		||||
    u32* cmd_buff = Kernel::GetCommandBuffer();
 | 
			
		||||
 | 
			
		||||
    const ConversionParameters& params = conversion.params;
 | 
			
		||||
    HW::Y2R::PerformConversion(conversion);
 | 
			
		||||
 | 
			
		||||
    const u8* srcY_buffer = Memory::GetPointer(conversion.src_Y.address);
 | 
			
		||||
    u8* dst_buffer = Memory::GetPointer(conversion.dst.address);
 | 
			
		||||
 | 
			
		||||
    // TODO: support color and other kinds of conversions
 | 
			
		||||
    ASSERT(params.input_format == InputFormat::YUV422_Indiv8
 | 
			
		||||
        || params.input_format == InputFormat::YUV420_Indiv8);
 | 
			
		||||
    ASSERT(params.output_format == OutputFormat::Rgb24);
 | 
			
		||||
    ASSERT(params.rotation == Rotation::None);
 | 
			
		||||
    const int bpp = 3;
 | 
			
		||||
 | 
			
		||||
    switch (params.block_alignment) {
 | 
			
		||||
    case BlockAlignment::Linear:
 | 
			
		||||
    {
 | 
			
		||||
        const size_t input_lines = params.input_lines;
 | 
			
		||||
        const size_t input_line_width = params.input_line_width;
 | 
			
		||||
        const size_t srcY_stride = conversion.src_Y.stride;
 | 
			
		||||
        const size_t dst_stride = conversion.dst.stride;
 | 
			
		||||
 | 
			
		||||
        size_t srcY_offset = 0;
 | 
			
		||||
        size_t dst_offset = 0;
 | 
			
		||||
 | 
			
		||||
        for (size_t line = 0; line < input_lines; ++line) {
 | 
			
		||||
            for (size_t i = 0; i < input_line_width; ++i) {
 | 
			
		||||
                u8 Y = srcY_buffer[srcY_offset];
 | 
			
		||||
                dst_buffer[dst_offset + 0] = Y;
 | 
			
		||||
                dst_buffer[dst_offset + 1] = Y;
 | 
			
		||||
                dst_buffer[dst_offset + 2] = Y;
 | 
			
		||||
 | 
			
		||||
                srcY_offset += 1;
 | 
			
		||||
                dst_offset += bpp;
 | 
			
		||||
            }
 | 
			
		||||
            srcY_offset += srcY_stride;
 | 
			
		||||
            dst_offset += dst_stride;
 | 
			
		||||
        }
 | 
			
		||||
        break;
 | 
			
		||||
    }
 | 
			
		||||
    case BlockAlignment::Block8x8:
 | 
			
		||||
    {
 | 
			
		||||
        const size_t input_lines = params.input_lines;
 | 
			
		||||
        const size_t input_line_width = params.input_line_width;
 | 
			
		||||
        const size_t srcY_stride = conversion.src_Y.stride;
 | 
			
		||||
        const size_t dst_transfer_unit = conversion.dst.transfer_unit;
 | 
			
		||||
        const size_t dst_stride = conversion.dst.stride;
 | 
			
		||||
 | 
			
		||||
        size_t srcY_offset = 0;
 | 
			
		||||
        size_t dst_tile_line_offs = 0;
 | 
			
		||||
 | 
			
		||||
        const size_t tile_size = 8 * 8 * bpp;
 | 
			
		||||
 | 
			
		||||
        for (size_t line = 0; line < input_lines;) {
 | 
			
		||||
            size_t max_line = line + 8;
 | 
			
		||||
 | 
			
		||||
            for (; line < max_line; ++line) {
 | 
			
		||||
                for (size_t x = 0; x < input_line_width; ++x) {
 | 
			
		||||
                    size_t tile_x = x / 8;
 | 
			
		||||
 | 
			
		||||
                    size_t dst_tile_offs = dst_tile_line_offs + tile_x * tile_size;
 | 
			
		||||
                    size_t tile_i = VideoCore::MortonInterleave((u32)x, (u32)line);
 | 
			
		||||
 | 
			
		||||
                    size_t dst_offset = dst_tile_offs + tile_i * bpp;
 | 
			
		||||
 | 
			
		||||
                    u8 Y = srcY_buffer[srcY_offset];
 | 
			
		||||
                    dst_buffer[dst_offset + 0] = Y;
 | 
			
		||||
                    dst_buffer[dst_offset + 1] = Y;
 | 
			
		||||
                    dst_buffer[dst_offset + 2] = Y;
 | 
			
		||||
 | 
			
		||||
                    srcY_offset += 1;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                srcY_offset += srcY_stride;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            dst_tile_line_offs += dst_transfer_unit + dst_stride;
 | 
			
		||||
        }
 | 
			
		||||
        break;
 | 
			
		||||
    }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // dst_image_size would seem to be perfect for this, but it doesn't include the stride :(
 | 
			
		||||
    u32 total_output_size = params.input_lines *
 | 
			
		||||
        (conversion.dst.transfer_unit + conversion.dst.stride);
 | 
			
		||||
    // dst_image_size would seem to be perfect for this, but it doesn't include the gap :(
 | 
			
		||||
    u32 total_output_size = conversion.input_lines *
 | 
			
		||||
        (conversion.dst.transfer_unit + conversion.dst.gap);
 | 
			
		||||
    VideoCore::g_renderer->hw_rasterizer->NotifyFlush(
 | 
			
		||||
        Memory::VirtualToPhysicalAddress(conversion.dst.address), total_output_size);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -285,6 +276,14 @@ static void StartConversion(Service::Interface* self) {
 | 
			
		|||
    cmd_buff[1] = RESULT_SUCCESS.raw;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void StopConversion(Service::Interface* self) {
 | 
			
		||||
    u32* cmd_buff = Kernel::GetCommandBuffer();
 | 
			
		||||
 | 
			
		||||
    cmd_buff[0] = 0x00270040;
 | 
			
		||||
    cmd_buff[1] = RESULT_SUCCESS.raw;
 | 
			
		||||
    LOG_DEBUG(Service_Y2R, "called");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Y2R_U::IsBusyConversion service function
 | 
			
		||||
 *  Outputs:
 | 
			
		||||
| 
						 | 
				
			
			@ -306,15 +305,31 @@ static void SetConversionParams(Service::Interface* self) {
 | 
			
		|||
    u32* cmd_buff = Kernel::GetCommandBuffer();
 | 
			
		||||
 | 
			
		||||
    auto params = reinterpret_cast<const ConversionParameters*>(&cmd_buff[1]);
 | 
			
		||||
    conversion.params = *params;
 | 
			
		||||
 | 
			
		||||
    cmd_buff[0] = 0x00290000; // TODO verify
 | 
			
		||||
    cmd_buff[1] = RESULT_SUCCESS.raw;
 | 
			
		||||
    LOG_DEBUG(Service_Y2R,
 | 
			
		||||
        "called input_format=%hhu output_format=%hhu rotation=%hhu block_alignment=%hhu "
 | 
			
		||||
        "input_line_width=%hX input_lines=%hu standard_coefficient=%hhu reserved=%hhu alpha=%hX",
 | 
			
		||||
        "input_line_width=%hu input_lines=%hu standard_coefficient=%hhu "
 | 
			
		||||
        "reserved=%hhu alpha=%hX",
 | 
			
		||||
        params->input_format, params->output_format, params->rotation, params->block_alignment,
 | 
			
		||||
        params->input_line_width, params->input_lines, params->standard_coefficient);
 | 
			
		||||
        params->input_line_width, params->input_lines, params->standard_coefficient,
 | 
			
		||||
        params->reserved, params->alpha);
 | 
			
		||||
 | 
			
		||||
    ResultCode result = RESULT_SUCCESS;
 | 
			
		||||
 | 
			
		||||
    conversion.input_format = params->input_format;
 | 
			
		||||
    conversion.output_format = params->output_format;
 | 
			
		||||
    conversion.rotation = params->rotation;
 | 
			
		||||
    conversion.block_alignment = params->block_alignment;
 | 
			
		||||
    result = conversion.SetInputLineWidth(params->input_line_width);
 | 
			
		||||
    if (result.IsError()) goto cleanup;
 | 
			
		||||
    result = conversion.SetInputLines(params->input_lines);
 | 
			
		||||
    if (result.IsError()) goto cleanup;
 | 
			
		||||
    result = conversion.SetStandardCoefficient(params->standard_coefficient);
 | 
			
		||||
    if (result.IsError()) goto cleanup;
 | 
			
		||||
    conversion.alpha = params->alpha;
 | 
			
		||||
 | 
			
		||||
cleanup:
 | 
			
		||||
    cmd_buff[0] = 0x00290040; // TODO verify
 | 
			
		||||
    cmd_buff[1] = result.raw;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void PingProcess(Service::Interface* self) {
 | 
			
		||||
| 
						 | 
				
			
			@ -325,28 +340,63 @@ static void PingProcess(Service::Interface* self) {
 | 
			
		|||
    LOG_WARNING(Service_Y2R, "(STUBBED) called");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void DriverInitialize(Service::Interface* self) {
 | 
			
		||||
    u32* cmd_buff = Kernel::GetCommandBuffer();
 | 
			
		||||
 | 
			
		||||
    conversion.input_format = InputFormat::YUV422_Indiv8;
 | 
			
		||||
    conversion.output_format = OutputFormat::RGBA8;
 | 
			
		||||
    conversion.rotation = Rotation::None;
 | 
			
		||||
    conversion.block_alignment = BlockAlignment::Linear;
 | 
			
		||||
    conversion.coefficients.fill(0);
 | 
			
		||||
    conversion.SetInputLineWidth(1024);
 | 
			
		||||
    conversion.SetInputLines(1024);
 | 
			
		||||
    conversion.alpha = 0;
 | 
			
		||||
 | 
			
		||||
    ConversionBuffer zero_buffer = {};
 | 
			
		||||
    conversion.src_Y = zero_buffer;
 | 
			
		||||
    conversion.src_U = zero_buffer;
 | 
			
		||||
    conversion.src_V = zero_buffer;
 | 
			
		||||
    conversion.dst = zero_buffer;
 | 
			
		||||
 | 
			
		||||
    completion_event->Clear();
 | 
			
		||||
 | 
			
		||||
    cmd_buff[0] = 0x002B0040;
 | 
			
		||||
    cmd_buff[1] = RESULT_SUCCESS.raw;
 | 
			
		||||
    LOG_DEBUG(Service_Y2R, "called");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void DriverFinalize(Service::Interface* self) {
 | 
			
		||||
    u32* cmd_buff = Kernel::GetCommandBuffer();
 | 
			
		||||
 | 
			
		||||
    cmd_buff[0] = 0x002C0040;
 | 
			
		||||
    cmd_buff[1] = RESULT_SUCCESS.raw;
 | 
			
		||||
    LOG_DEBUG(Service_Y2R, "called");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const Interface::FunctionInfo FunctionTable[] = {
 | 
			
		||||
    {0x00010040, SetInputFormat,          "SetInputFormat"},
 | 
			
		||||
    {0x00030040, SetOutputFormat,         "SetOutputFormat"},
 | 
			
		||||
    {0x00050040, SetRotation,             "SetRotation"},
 | 
			
		||||
    {0x00070040, SetBlockAlignment,       "SetBlockAlignment"},
 | 
			
		||||
    {0x000D0040, nullptr,                 "SetTransferEndInterrupt"},
 | 
			
		||||
    {0x000D0040, SetTransferEndInterrupt, "SetTransferEndInterrupt"},
 | 
			
		||||
    {0x000F0000, GetTransferEndEvent,     "GetTransferEndEvent"},
 | 
			
		||||
    {0x00100102, SetSendingY,             "SetSendingY"},
 | 
			
		||||
    {0x00110102, nullptr,                 "SetSendingU"},
 | 
			
		||||
    {0x00120102, nullptr,                 "SetSendingV"},
 | 
			
		||||
    {0x00110102, SetSendingU,             "SetSendingU"},
 | 
			
		||||
    {0x00120102, SetSendingV,             "SetSendingV"},
 | 
			
		||||
    {0x00130102, SetSendingYUYV,          "SetSendingYUYV"},
 | 
			
		||||
    {0x00180102, SetReceiving,            "SetReceiving"},
 | 
			
		||||
    {0x001A0040, SetInputLineWidth,       "SetInputLineWidth"},
 | 
			
		||||
    {0x001C0040, SetInputLines,           "SetInputLines"},
 | 
			
		||||
    {0x00200040, nullptr,                 "SetStandardCoefficient"},
 | 
			
		||||
    {0x00220040, nullptr,                 "SetAlpha"},
 | 
			
		||||
    {0x001E0100, SetCoefficient,          "SetCoefficient"},
 | 
			
		||||
    {0x00200040, SetStandardCoefficient,  "SetStandardCoefficient"},
 | 
			
		||||
    {0x00220040, SetAlpha,                "SetAlpha"},
 | 
			
		||||
    {0x00260000, StartConversion,         "StartConversion"},
 | 
			
		||||
    {0x00270000, nullptr,                 "StopConversion"},
 | 
			
		||||
    {0x00270000, StopConversion,          "StopConversion"},
 | 
			
		||||
    {0x00280000, IsBusyConversion,        "IsBusyConversion"},
 | 
			
		||||
    {0x002901C0, SetConversionParams,     "SetConversionParams"},
 | 
			
		||||
    {0x002A0000, PingProcess,             "PingProcess"},
 | 
			
		||||
    {0x002B0000, nullptr,                 "DriverInitialize"},
 | 
			
		||||
    {0x002C0000, nullptr,                 "DriverFinalize"},
 | 
			
		||||
    {0x002B0000, DriverInitialize,        "DriverInitialize"},
 | 
			
		||||
    {0x002C0000, DriverFinalize,          "DriverFinalize"},
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
////////////////////////////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,6 +4,10 @@
 | 
			
		|||
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include <array>
 | 
			
		||||
 | 
			
		||||
#include "common/common_types.h"
 | 
			
		||||
 | 
			
		||||
#include "core/hle/service/service.h"
 | 
			
		||||
 | 
			
		||||
////////////////////////////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
| 
						 | 
				
			
			@ -11,6 +15,98 @@
 | 
			
		|||
 | 
			
		||||
namespace Y2R_U {
 | 
			
		||||
 | 
			
		||||
enum class InputFormat : u8 {
 | 
			
		||||
    /// 8-bit input, with YUV components in separate planes and 4:2:2 subsampling.
 | 
			
		||||
    YUV422_Indiv8 = 0,
 | 
			
		||||
    /// 8-bit input, with YUV components in separate planes and 4:2:0 subsampling.
 | 
			
		||||
    YUV420_Indiv8 = 1,
 | 
			
		||||
 | 
			
		||||
    /// 16-bit input (only LSB used), with YUV components in separate planes and 4:2:2 subsampling.
 | 
			
		||||
    YUV422_Indiv16 = 2,
 | 
			
		||||
    /// 16-bit input (only LSB used), with YUV components in separate planes and 4:2:0 subsampling.
 | 
			
		||||
    YUV420_Indiv16 = 3,
 | 
			
		||||
 | 
			
		||||
    /// 8-bit input, with a single interleaved stream in YUYV format and 4:2:2 subsampling.
 | 
			
		||||
    YUYV422_Interleaved = 4,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
enum class OutputFormat : u8 {
 | 
			
		||||
    RGBA8 = 0,
 | 
			
		||||
    RGB8 = 1,
 | 
			
		||||
    RGB5A1 = 2,
 | 
			
		||||
    RGB565 = 3,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
enum class Rotation : u8 {
 | 
			
		||||
    None = 0,
 | 
			
		||||
    Clockwise_90 = 1,
 | 
			
		||||
    Clockwise_180 = 2,
 | 
			
		||||
    Clockwise_270 = 3,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
enum class BlockAlignment : u8 {
 | 
			
		||||
    /// Image is output in linear format suitable for use as a framebuffer.
 | 
			
		||||
    Linear = 0,
 | 
			
		||||
    /// Image is output in tiled PICA format, suitable for use as a texture.
 | 
			
		||||
    Block8x8 = 1,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
enum class StandardCoefficient : u8 {
 | 
			
		||||
    /// ITU Rec. BT.601 primaries, with PC ranges.
 | 
			
		||||
    ITU_Rec601 = 0,
 | 
			
		||||
    /// ITU Rec. BT.709 primaries, with PC ranges.
 | 
			
		||||
    ITU_Rec709 = 1,
 | 
			
		||||
    /// ITU Rec. BT.601 primaries, with TV ranges.
 | 
			
		||||
    ITU_Rec601_Scaling = 2,
 | 
			
		||||
    /// ITU Rec. BT.709 primaries, with TV ranges.
 | 
			
		||||
    ITU_Rec709_Scaling = 3,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * A set of coefficients configuring the RGB to YUV conversion. Coefficients 0-4 are unsigned 2.8
 | 
			
		||||
 * fixed pointer numbers representing entries on the conversion matrix, while coefficient 5-7 are
 | 
			
		||||
 * signed 11.5 fixed point numbers added as offsets to the RGB result.
 | 
			
		||||
 *
 | 
			
		||||
 * The overall conversion process formula is:
 | 
			
		||||
 * ```
 | 
			
		||||
 * R = trunc((c_0 * Y           + c_1 * V) + c_5 + 0.75)
 | 
			
		||||
 * G = trunc((c_0 * Y - c_3 * U - c_2 * V) + c_6 + 0.75)
 | 
			
		||||
 * B = trunc((c_0 * Y + c_4 * U          ) + c_7 + 0.75)
 | 
			
		||||
 * ```
 | 
			
		||||
 */
 | 
			
		||||
using CoefficientSet = std::array<s16, 8>;
 | 
			
		||||
 | 
			
		||||
struct ConversionBuffer {
 | 
			
		||||
    /// Current reading/writing address of this buffer.
 | 
			
		||||
    VAddr address;
 | 
			
		||||
    /// Remaining amount of bytes to be DMAed, does not include the inter-trasfer gap.
 | 
			
		||||
    u32 image_size;
 | 
			
		||||
    /// Size of a single DMA transfer.
 | 
			
		||||
    u16 transfer_unit;
 | 
			
		||||
    /// Amount of bytes to be skipped between copying each `transfer_unit` bytes.
 | 
			
		||||
    u16 gap;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct ConversionConfiguration {
 | 
			
		||||
    InputFormat input_format;
 | 
			
		||||
    OutputFormat output_format;
 | 
			
		||||
    Rotation rotation;
 | 
			
		||||
    BlockAlignment block_alignment;
 | 
			
		||||
    u16 input_line_width;
 | 
			
		||||
    u16 input_lines;
 | 
			
		||||
    CoefficientSet coefficients;
 | 
			
		||||
    u16 alpha;
 | 
			
		||||
 | 
			
		||||
    /// Input parameters for the Y (luma) plane
 | 
			
		||||
    ConversionBuffer src_Y, src_U, src_V, src_YUYV;
 | 
			
		||||
    /// Output parameters for the conversion results
 | 
			
		||||
    ConversionBuffer dst;
 | 
			
		||||
 | 
			
		||||
    ResultCode SetInputLineWidth(u16 width);
 | 
			
		||||
    ResultCode SetInputLines(u16 lines);
 | 
			
		||||
    ResultCode SetStandardCoefficient(StandardCoefficient standard_coefficient);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class Interface : public Service::Interface {
 | 
			
		||||
public:
 | 
			
		||||
    Interface();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue