mirror of
https://git.eden-emu.dev/eden-emu/eden
synced 2026-06-29 20:25:40 +02:00
[android] MediaTek specific opts
Signed-off-by: lizzie <lizzie@eden-emu.dev>
This commit is contained in:
parent
0c2894eabf
commit
bb56e8fed4
2 changed files with 37 additions and 42 deletions
|
|
@ -25,9 +25,9 @@ namespace FFmpeg {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
constexpr AVPixelFormat PreferredGpuFormat = AV_PIX_FMT_NV12;
|
constexpr AVPixelFormat PREFERRED_GPU_FORMAT = AV_PIX_FMT_NV12;
|
||||||
constexpr AVPixelFormat PreferredCpuFormat = AV_PIX_FMT_YUV420P;
|
constexpr AVPixelFormat PREFERRED_CPU_FORMAT = AV_PIX_FMT_YUV420P;
|
||||||
constexpr std::array PreferredGpuDecoders = {
|
constexpr std::array PREFERRED_GPU_DECODERS = {
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
AV_HWDEVICE_TYPE_CUDA,
|
AV_HWDEVICE_TYPE_CUDA,
|
||||||
AV_HWDEVICE_TYPE_D3D11VA,
|
AV_HWDEVICE_TYPE_D3D11VA,
|
||||||
|
|
@ -54,15 +54,14 @@ AVPixelFormat GetGpuFormat(AVCodecContext* codec_context, const AVPixelFormat* p
|
||||||
if (desc && !(desc->flags & AV_PIX_FMT_FLAG_HWACCEL)) {
|
if (desc && !(desc->flags & AV_PIX_FMT_FLAG_HWACCEL)) {
|
||||||
for (int i = 0;; i++) {
|
for (int i = 0;; i++) {
|
||||||
const AVCodecHWConfig* config = avcodec_get_hw_config(codec_context->codec, i);
|
const AVCodecHWConfig* config = avcodec_get_hw_config(codec_context->codec, i);
|
||||||
if (!config) {
|
if (config) {
|
||||||
|
for (const auto type : PREFERRED_GPU_DECODERS)
|
||||||
|
if (config->methods & AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX && config->device_type == type) {
|
||||||
|
codec_context->pix_fmt = config->pix_fmt;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const auto type : PreferredGpuDecoders) {
|
|
||||||
if (config->methods & AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX && config->device_type == type) {
|
|
||||||
codec_context->pix_fmt = config->pix_fmt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -74,7 +73,7 @@ AVPixelFormat GetGpuFormat(AVCodecContext* codec_context, const AVPixelFormat* p
|
||||||
|
|
||||||
LOG_INFO(HW_GPU, "Could not find supported GPU pixel format, falling back to CPU decoder");
|
LOG_INFO(HW_GPU, "Could not find supported GPU pixel format, falling back to CPU decoder");
|
||||||
av_buffer_unref(&codec_context->hw_device_ctx);
|
av_buffer_unref(&codec_context->hw_device_ctx);
|
||||||
codec_context->pix_fmt = PreferredCpuFormat;
|
codec_context->pix_fmt = PREFERRED_CPU_FORMAT;
|
||||||
return codec_context->pix_fmt;
|
return codec_context->pix_fmt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -142,13 +141,10 @@ bool Decoder::SupportsDecodingOnDevice(AVPixelFormat* out_pix_fmt, AVHWDeviceTyp
|
||||||
std::vector<AVHWDeviceType> HardwareContext::GetSupportedDeviceTypes() {
|
std::vector<AVHWDeviceType> HardwareContext::GetSupportedDeviceTypes() {
|
||||||
std::vector<AVHWDeviceType> types;
|
std::vector<AVHWDeviceType> types;
|
||||||
AVHWDeviceType current_device_type = AV_HWDEVICE_TYPE_NONE;
|
AVHWDeviceType current_device_type = AV_HWDEVICE_TYPE_NONE;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
current_device_type = av_hwdevice_iterate_types(current_device_type);
|
current_device_type = av_hwdevice_iterate_types(current_device_type);
|
||||||
if (current_device_type == AV_HWDEVICE_TYPE_NONE) {
|
if (current_device_type == AV_HWDEVICE_TYPE_NONE)
|
||||||
return types;
|
return types;
|
||||||
}
|
|
||||||
|
|
||||||
types.push_back(current_device_type);
|
types.push_back(current_device_type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -158,25 +154,20 @@ HardwareContext::~HardwareContext() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HardwareContext::InitializeForDecoder(DecoderContext& decoder_context, const Decoder& decoder) {
|
bool HardwareContext::InitializeForDecoder(DecoderContext& decoder_context, const Decoder& decoder) {
|
||||||
const auto supported_types = GetSupportedDeviceTypes();
|
auto const supported_types = GetSupportedDeviceTypes();
|
||||||
for (const auto type : PreferredGpuDecoders) {
|
for (auto const type : PREFERRED_GPU_DECODERS) {
|
||||||
AVPixelFormat hw_pix_fmt;
|
|
||||||
|
|
||||||
if (std::ranges::find(supported_types, type) == supported_types.end()) {
|
if (std::ranges::find(supported_types, type) == supported_types.end()) {
|
||||||
LOG_DEBUG(HW_GPU, "{} explicitly unsupported", av_hwdevice_get_type_name(type));
|
LOG_DEBUG(HW_GPU, "{} explicitly unsupported", av_hwdevice_get_type_name(type));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (InitializeWithType(type)) {
|
||||||
if (!this->InitializeWithType(type)) {
|
AVPixelFormat hw_pix_fmt{};
|
||||||
continue;
|
if (decoder.SupportsDecodingOnDevice(&hw_pix_fmt, type)) {
|
||||||
}
|
decoder_context.InitializeHardwareDecoder(*this, hw_pix_fmt);
|
||||||
|
return true;
|
||||||
if (decoder.SupportsDecodingOnDevice(&hw_pix_fmt, type)) {
|
}
|
||||||
decoder_context.InitializeHardwareDecoder(*this, hw_pix_fmt);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -184,7 +175,7 @@ bool HardwareContext::InitializeWithType(AVHWDeviceType type) {
|
||||||
av_buffer_unref(&m_gpu_decoder);
|
av_buffer_unref(&m_gpu_decoder);
|
||||||
|
|
||||||
if (const int ret = av_hwdevice_ctx_create(&m_gpu_decoder, type, nullptr, nullptr, 0); ret < 0) {
|
if (const int ret = av_hwdevice_ctx_create(&m_gpu_decoder, type, nullptr, nullptr, 0); ret < 0) {
|
||||||
LOG_DEBUG(HW_GPU, "av_hwdevice_ctx_create({}) failed: {}", av_hwdevice_get_type_name(type), AVError(ret));
|
LOG_INFO(HW_GPU, "av_hwdevice_ctx_create({}) failed: {}", av_hwdevice_get_type_name(type), AVError(ret));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -265,11 +256,17 @@ std::shared_ptr<Frame> DecoderContext::ReceiveFrame() {
|
||||||
|
|
||||||
m_final_frame = std::make_shared<Frame>();
|
m_final_frame = std::make_shared<Frame>();
|
||||||
if (m_codec_context->hw_device_ctx) {
|
if (m_codec_context->hw_device_ctx) {
|
||||||
m_final_frame->SetFormat(PreferredGpuFormat);
|
#ifdef __ANDROID__
|
||||||
|
// c2.mtk.vp9.decoder, c2.mtk.vp89.decoder will be fine if we don't
|
||||||
|
// re-encode stuff twice :>
|
||||||
|
m_final_frame = std::move(intermediate_frame);
|
||||||
|
#else
|
||||||
|
m_final_frame->SetFormat(PREFERRED_GPU_FORMAT);
|
||||||
if (const int ret = av_hwframe_transfer_data(m_final_frame->GetFrame(), intermediate_frame->GetFrame(), 0); ret < 0) {
|
if (const int ret = av_hwframe_transfer_data(m_final_frame->GetFrame(), intermediate_frame->GetFrame(), 0); ret < 0) {
|
||||||
LOG_ERROR(HW_GPU, "av_hwframe_transfer_data error: {}", AVError(ret));
|
LOG_ERROR(HW_GPU, "av_hwframe_transfer_data error: {}", AVError(ret));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
} else {
|
} else {
|
||||||
m_final_frame = std::move(intermediate_frame);
|
m_final_frame = std::move(intermediate_frame);
|
||||||
}
|
}
|
||||||
|
|
@ -284,6 +281,8 @@ void DecodeApi::Reset() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DecodeApi::Initialize(Tegra::Host1x::NvdecCommon::VideoCodec codec) {
|
bool DecodeApi::Initialize(Tegra::Host1x::NvdecCommon::VideoCodec codec) {
|
||||||
|
av_log_set_level(AV_LOG_DEBUG);
|
||||||
|
|
||||||
this->Reset();
|
this->Reset();
|
||||||
m_decoder.emplace(codec);
|
m_decoder.emplace(codec);
|
||||||
m_decoder_context.emplace(*m_decoder);
|
m_decoder_context.emplace(*m_decoder);
|
||||||
|
|
|
||||||
|
|
@ -37,8 +37,6 @@
|
||||||
|
|
||||||
namespace Vulkan {
|
namespace Vulkan {
|
||||||
namespace {
|
namespace {
|
||||||
using boost::container::small_vector;
|
|
||||||
using boost::container::static_vector;
|
|
||||||
using Shader::ImageBufferDescriptor;
|
using Shader::ImageBufferDescriptor;
|
||||||
using Shader::Backend::SPIRV::RENDERAREA_LAYOUT_OFFSET;
|
using Shader::Backend::SPIRV::RENDERAREA_LAYOUT_OFFSET;
|
||||||
using Shader::Backend::SPIRV::RESCALING_LAYOUT_DOWN_FACTOR_OFFSET;
|
using Shader::Backend::SPIRV::RESCALING_LAYOUT_DOWN_FACTOR_OFFSET;
|
||||||
|
|
@ -584,9 +582,9 @@ void GraphicsPipeline::MakePipeline(VkRenderPass render_pass) {
|
||||||
} else {
|
} else {
|
||||||
dynamic.raw1 = key.state.dynamic_state.raw1;
|
dynamic.raw1 = key.state.dynamic_state.raw1;
|
||||||
}
|
}
|
||||||
static_vector<VkVertexInputBindingDescription, 32> vertex_bindings;
|
boost::container::static_vector<VkVertexInputBindingDescription, 32> vertex_bindings;
|
||||||
static_vector<VkVertexInputBindingDivisorDescriptionEXT, 32> vertex_binding_divisors;
|
boost::container::static_vector<VkVertexInputBindingDivisorDescriptionEXT, 32> vertex_binding_divisors;
|
||||||
static_vector<VkVertexInputAttributeDescription, 32> vertex_attributes;
|
boost::container::static_vector<VkVertexInputAttributeDescription, 32> vertex_attributes;
|
||||||
if (!key.state.dynamic_vertex_input) {
|
if (!key.state.dynamic_vertex_input) {
|
||||||
const size_t num_vertex_arrays = (std::min)(
|
const size_t num_vertex_arrays = (std::min)(
|
||||||
Maxwell::NumVertexArrays, static_cast<size_t>(device.GetMaxVertexInputBindings()));
|
Maxwell::NumVertexArrays, static_cast<size_t>(device.GetMaxVertexInputBindings()));
|
||||||
|
|
@ -811,7 +809,7 @@ void GraphicsPipeline::MakePipeline(VkRenderPass render_pass) {
|
||||||
if (dynamic.depth_bounds_enable && !device.IsDepthBoundsSupported()) {
|
if (dynamic.depth_bounds_enable && !device.IsDepthBoundsSupported()) {
|
||||||
LOG_WARNING(Render_Vulkan, "Depth bounds is enabled but not supported");
|
LOG_WARNING(Render_Vulkan, "Depth bounds is enabled but not supported");
|
||||||
}
|
}
|
||||||
static_vector<VkPipelineColorBlendAttachmentState, Maxwell::NumRenderTargets> cb_attachments;
|
boost::container::static_vector<VkPipelineColorBlendAttachmentState, Maxwell::NumRenderTargets> cb_attachments;
|
||||||
const size_t num_attachments{NumAttachments(key.state)};
|
const size_t num_attachments{NumAttachments(key.state)};
|
||||||
for (size_t index = 0; index < num_attachments; ++index) {
|
for (size_t index = 0; index < num_attachments; ++index) {
|
||||||
static constexpr std::array mask_table{
|
static constexpr std::array mask_table{
|
||||||
|
|
@ -847,7 +845,7 @@ void GraphicsPipeline::MakePipeline(VkRenderPass render_pass) {
|
||||||
.pAttachments = cb_attachments.data(),
|
.pAttachments = cb_attachments.data(),
|
||||||
.blendConstants = {}
|
.blendConstants = {}
|
||||||
};
|
};
|
||||||
static_vector<VkDynamicState, 34> dynamic_states{
|
boost::container::static_vector<VkDynamicState, 34> dynamic_states{
|
||||||
VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR,
|
VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR,
|
||||||
VK_DYNAMIC_STATE_DEPTH_BIAS, VK_DYNAMIC_STATE_BLEND_CONSTANTS,
|
VK_DYNAMIC_STATE_DEPTH_BIAS, VK_DYNAMIC_STATE_BLEND_CONSTANTS,
|
||||||
VK_DYNAMIC_STATE_DEPTH_BOUNDS, VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK,
|
VK_DYNAMIC_STATE_DEPTH_BOUNDS, VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK,
|
||||||
|
|
@ -942,12 +940,9 @@ void GraphicsPipeline::MakePipeline(VkRenderPass render_pass) {
|
||||||
.pNext = nullptr,
|
.pNext = nullptr,
|
||||||
.requiredSubgroupSize = GuestWarpSize,
|
.requiredSubgroupSize = GuestWarpSize,
|
||||||
};
|
};
|
||||||
static_vector<VkPipelineShaderStageCreateInfo, 5> shader_stages;
|
boost::container::static_vector<VkPipelineShaderStageCreateInfo, 5> shader_stages;
|
||||||
for (size_t stage = 0; stage < Maxwell::MaxShaderStage; ++stage) {
|
for (size_t stage = 0; stage < Maxwell::MaxShaderStage; ++stage) {
|
||||||
if (!spv_modules[stage]) {
|
if (spv_modules[stage]) {
|
||||||
continue;
|
|
||||||
}
|
|
||||||
[[maybe_unused]] auto& stage_ci =
|
|
||||||
shader_stages.emplace_back(VkPipelineShaderStageCreateInfo{
|
shader_stages.emplace_back(VkPipelineShaderStageCreateInfo{
|
||||||
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
|
||||||
.pNext = nullptr,
|
.pNext = nullptr,
|
||||||
|
|
@ -957,6 +952,7 @@ void GraphicsPipeline::MakePipeline(VkRenderPass render_pass) {
|
||||||
.pName = "main",
|
.pName = "main",
|
||||||
.pSpecializationInfo = nullptr,
|
.pSpecializationInfo = nullptr,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
VkPipelineCreateFlags flags{};
|
VkPipelineCreateFlags flags{};
|
||||||
if (device.IsKhrPipelineExecutablePropertiesEnabled() && Settings::values.renderer_debug.GetValue()) {
|
if (device.IsKhrPipelineExecutablePropertiesEnabled() && Settings::values.renderer_debug.GetValue()) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue