Skip to content

Commit

Permalink
Merge branch 'PabloMK7:master' into wayland
Browse files Browse the repository at this point in the history
  • Loading branch information
Miguel-hrvs authored Apr 29, 2024
2 parents 516013c + b5126f9 commit 9de84a0
Show file tree
Hide file tree
Showing 44 changed files with 906 additions and 860 deletions.
9 changes: 8 additions & 1 deletion src/citra_qt/debugger/console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@ void ToggleConsole() {
#ifdef _WIN32
FILE* temp;
if (UISettings::values.show_console) {
if (AllocConsole()) {
BOOL alloc_console_res = AllocConsole();
DWORD last_error = 0;
if (!alloc_console_res) {
last_error = GetLastError();
}
// If the windows debugger already opened a console, calling AllocConsole again
// will cause ERROR_ACCESS_DENIED. If that's the case assume a console is open.
if (alloc_console_res || last_error == ERROR_ACCESS_DENIED) {
// The first parameter for freopen_s is a out parameter, so we can just ignore it
freopen_s(&temp, "CONIN$", "r", stdin);
freopen_s(&temp, "CONOUT$", "w", stdout);
Expand Down
17 changes: 16 additions & 1 deletion src/core/file_sys/ncch_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,11 +577,26 @@ Loader::ResultStatus NCCHContainer::ApplyCodePatch(std::vector<u8>& code) const
const auto mods_path =
fmt::format("{}mods/{:016X}/", FileUtil::GetUserPath(FileUtil::UserPath::LoadDir),
GetModId(ncch_header.program_id));
const std::array<PatchLocation, 6> patch_paths{{

constexpr u32 system_module_tid_high = 0x00040130;

std::string luma_ips_location;
if ((static_cast<u32>(ncch_header.program_id >> 32) & system_module_tid_high) ==
system_module_tid_high) {
luma_ips_location =
fmt::format("{}luma/sysmodules/{:016X}.ips",
FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir), ncch_header.program_id);
} else {
luma_ips_location =
fmt::format("{}luma/titles/{:016X}/code.ips",
FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir), ncch_header.program_id);
}
const std::array<PatchLocation, 7> patch_paths{{
{mods_path + "exefs/code.ips", Patch::ApplyIpsPatch},
{mods_path + "exefs/code.bps", Patch::ApplyBpsPatch},
{mods_path + "code.ips", Patch::ApplyIpsPatch},
{mods_path + "code.bps", Patch::ApplyBpsPatch},
{luma_ips_location, Patch::ApplyIpsPatch},
{filepath + ".exefsdir/code.ips", Patch::ApplyIpsPatch},
{filepath + ".exefsdir/code.bps", Patch::ApplyBpsPatch},
}};
Expand Down
4 changes: 2 additions & 2 deletions src/core/hle/kernel/resource_limit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ bool ResourceLimit::Reserve(ResourceLimitType type, s32 amount) {
const auto index = static_cast<std::size_t>(type);
const s32 limit = m_limit_values[index];
const s32 new_value = m_current_values[index] + amount;
// TODO(PabloMK7): Fix all resource limit bugs and return an error, instead of ignoring it.
if (new_value > limit) {
LOG_ERROR(Kernel, "New value {} exceeds limit {} for resource type {}", new_value, limit,
type);
return false;
}
m_current_values[index] = new_value;
return true;
Expand All @@ -57,10 +57,10 @@ bool ResourceLimit::Reserve(ResourceLimitType type, s32 amount) {
bool ResourceLimit::Release(ResourceLimitType type, s32 amount) {
const auto index = static_cast<std::size_t>(type);
const s32 value = m_current_values[index];
// TODO(PabloMK7): Fix all resource limit bugs and return an error, instead of ignoring it.
if (amount > value) {
LOG_ERROR(Kernel, "Amount {} exceeds current value {} for resource type {}", amount, value,
type);
return false;
}
m_current_values[index] = value - amount;
return true;
Expand Down
8 changes: 4 additions & 4 deletions src/video_core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ if (ENABLE_VULKAN)
renderer_vulkan/vk_blit_helper.h
renderer_vulkan/vk_common.cpp
renderer_vulkan/vk_common.h
renderer_vulkan/vk_descriptor_pool.cpp
renderer_vulkan/vk_descriptor_pool.h
renderer_vulkan/vk_descriptor_update_queue.cpp
renderer_vulkan/vk_descriptor_update_queue.h
renderer_vulkan/vk_graphics_pipeline.cpp
renderer_vulkan/vk_graphics_pipeline.h
renderer_vulkan/vk_master_semaphore.cpp
Expand All @@ -183,8 +183,8 @@ if (ENABLE_VULKAN)
renderer_vulkan/vk_platform.h
renderer_vulkan/vk_present_window.cpp
renderer_vulkan/vk_present_window.h
renderer_vulkan/vk_renderpass_cache.cpp
renderer_vulkan/vk_renderpass_cache.h
renderer_vulkan/vk_render_manager.cpp
renderer_vulkan/vk_render_manager.h
renderer_vulkan/vk_shader_util.cpp
renderer_vulkan/vk_shader_util.h
renderer_vulkan/vk_stream_buffer.cpp
Expand Down
2 changes: 1 addition & 1 deletion src/video_core/custom_textures/custom_tex_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ std::vector<FileUtil::FSTEntry> CustomTexManager::GetTextures(u64 title_id) {
}

void CustomTexManager::CreateWorkers() {
const std::size_t num_workers = std::max(std::thread::hardware_concurrency(), 2U) - 1;
const std::size_t num_workers = std::max(std::thread::hardware_concurrency(), 2U) >> 1;
workers = std::make_unique<Common::ThreadWorker>(num_workers, "Custom textures");
}

Expand Down
8 changes: 4 additions & 4 deletions src/video_core/pica/regs_texturing.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,15 @@ struct TexturingRegs {
INSERT_PADDING_WORDS(0x9);

struct FullTextureConfig {
const bool enabled;
const u32 enabled;
const TextureConfig config;
const TextureFormat format;
};
const std::array<FullTextureConfig, 3> GetTextures() const {
return {{
{static_cast<bool>(main_config.texture0_enable), texture0, texture0_format},
{static_cast<bool>(main_config.texture1_enable), texture1, texture1_format},
{static_cast<bool>(main_config.texture2_enable), texture2, texture2_format},
{main_config.texture0_enable, texture0, texture0_format},
{main_config.texture1_enable, texture1, texture1_format},
{main_config.texture2_enable, texture2, texture2_format},
}};
}

Expand Down
63 changes: 37 additions & 26 deletions src/video_core/rasterizer_cache/rasterizer_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -600,14 +600,43 @@ typename T::Surface& RasterizerCache<T>::GetTextureCube(const TextureCubeConfig&
auto [it, new_surface] = texture_cube_cache.try_emplace(config);
TextureCube& cube = it->second;

const std::array addresses = {config.px, config.nx, config.py, config.ny, config.pz, config.nz};

if (new_surface) {
Pica::Texture::TextureInfo info = {
.width = config.width,
.height = config.width,
.format = config.format,
};
info.SetDefaultStride();

u32 res_scale = 1;
for (u32 i = 0; i < addresses.size(); i++) {
if (!addresses[i]) {
continue;
}

SurfaceId& face_id = cube.face_ids[i];
if (!face_id) {
info.physical_address = addresses[i];
face_id = GetTextureSurface(info, config.levels - 1);
Surface& surface = slot_surfaces[face_id];
ASSERT_MSG(
surface.levels >= config.levels,
"Texture cube face levels are not enough to validate the levels requested");
surface.flags |= SurfaceFlagBits::Tracked;
}
Surface& surface = slot_surfaces[face_id];
res_scale = std::max(surface.res_scale, res_scale);
}

SurfaceParams cube_params = {
.addr = config.px,
.width = config.width,
.height = config.width,
.stride = config.width,
.levels = config.levels,
.res_scale = filter != Settings::TextureFilter::None ? resolution_scale_factor : 1,
.res_scale = res_scale,
.texture_type = TextureType::CubeMap,
.pixel_format = PixelFormatFromTextureFormat(config.format),
.type = SurfaceType::Texture,
Expand All @@ -616,48 +645,30 @@ typename T::Surface& RasterizerCache<T>::GetTextureCube(const TextureCubeConfig&
cube.surface_id = CreateSurface(cube_params);
}

const u32 scaled_size = slot_surfaces[cube.surface_id].GetScaledWidth();
const std::array addresses = {config.px, config.nx, config.py, config.ny, config.pz, config.nz};

Pica::Texture::TextureInfo info = {
.width = config.width,
.height = config.width,
.format = config.format,
};
info.SetDefaultStride();

Surface& cube_surface = slot_surfaces[cube.surface_id];
for (u32 i = 0; i < addresses.size(); i++) {
if (!addresses[i]) {
continue;
}

SurfaceId& face_id = cube.face_ids[i];
if (!face_id) {
info.physical_address = addresses[i];
face_id = GetTextureSurface(info, config.levels - 1);
ASSERT_MSG(slot_surfaces[face_id].levels >= config.levels,
"Texture cube face levels are not enough to validate the levels requested");
}
Surface& surface = slot_surfaces[face_id];
surface.flags |= SurfaceFlagBits::Tracked;
Surface& surface = slot_surfaces[cube.face_ids[i]];
if (cube.ticks[i] == surface.modification_tick) {
continue;
}
cube.ticks[i] = surface.modification_tick;
Surface& cube_surface = slot_surfaces[cube.surface_id];
boost::container::small_vector<TextureCopy, 8> upload_copies;
for (u32 level = 0; level < config.levels; level++) {
const u32 width_lod = scaled_size >> level;
const TextureCopy texture_copy = {
const u32 width_lod = surface.GetScaledWidth() >> level;
upload_copies.push_back({
.src_level = level,
.dst_level = level,
.src_layer = 0,
.dst_layer = i,
.src_offset = {0, 0},
.dst_offset = {0, 0},
.extent = {width_lod, width_lod},
};
runtime.CopyTextures(surface, cube_surface, texture_copy);
});
}
runtime.CopyTextures(surface, cube_surface, upload_copies);
}

return slot_surfaces[cube.surface_id];
Expand Down
13 changes: 8 additions & 5 deletions src/video_core/renderer_opengl/gl_texture_runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,16 +260,19 @@ void TextureRuntime::ClearTexture(Surface& surface, const VideoCore::TextureClea
}

bool TextureRuntime::CopyTextures(Surface& source, Surface& dest,
const VideoCore::TextureCopy& copy) {
std::span<const VideoCore::TextureCopy> copies) {
const GLenum src_textarget = source.texture_type == VideoCore::TextureType::CubeMap
? GL_TEXTURE_CUBE_MAP
: GL_TEXTURE_2D;
const GLenum dest_textarget =
dest.texture_type == VideoCore::TextureType::CubeMap ? GL_TEXTURE_CUBE_MAP : GL_TEXTURE_2D;
glCopyImageSubData(source.Handle(), src_textarget, copy.src_level, copy.src_offset.x,
copy.src_offset.y, copy.src_layer, dest.Handle(), dest_textarget,
copy.dst_level, copy.dst_offset.x, copy.dst_offset.y, copy.dst_layer,
copy.extent.width, copy.extent.height, 1);

for (const auto& copy : copies) {
glCopyImageSubData(source.Handle(), src_textarget, copy.src_level, copy.src_offset.x,
copy.src_offset.y, copy.src_layer, dest.Handle(), dest_textarget,
copy.dst_level, copy.dst_offset.x, copy.dst_offset.y, copy.dst_layer,
copy.extent.width, copy.extent.height, 1);
}
return true;
}

Expand Down
7 changes: 6 additions & 1 deletion src/video_core/renderer_opengl/gl_texture_runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,12 @@ class TextureRuntime {
void ClearTexture(Surface& surface, const VideoCore::TextureClear& clear);

/// Copies a rectangle of source to another rectange of dest
bool CopyTextures(Surface& source, Surface& dest, const VideoCore::TextureCopy& copy);
bool CopyTextures(Surface& source, Surface& dest,
std::span<const VideoCore::TextureCopy> copies);

bool CopyTextures(Surface& source, Surface& dest, const VideoCore::TextureCopy& copy) {
return CopyTextures(source, dest, std::array{copy});
}

/// Blits a rectangle of source to another rectange of dest
bool BlitTextures(Surface& source, Surface& dest, const VideoCore::TextureBlit& blit);
Expand Down
62 changes: 16 additions & 46 deletions src/video_core/renderer_vulkan/renderer_vulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,14 @@ RendererVulkan::RendererVulkan(Core::System& system, Pica::PicaCore& pica_,
Frontend::EmuWindow& window, Frontend::EmuWindow* secondary_window)
: RendererBase{system, window, secondary_window}, memory{system.Memory()}, pica{pica_},
instance{window, Settings::values.physical_device.GetValue()}, scheduler{instance},
renderpass_cache{instance, scheduler}, pool{instance}, main_window{window, instance,
scheduler},
renderpass_cache{instance, scheduler}, main_window{window, instance, scheduler},
vertex_buffer{instance, scheduler, vk::BufferUsageFlagBits::eVertexBuffer,
VERTEX_BUFFER_SIZE},
rasterizer{memory,
pica,
system.CustomTexManager(),
*this,
render_window,
instance,
scheduler,
pool,
renderpass_cache,
main_window.ImageCount()},
present_set_provider{instance, pool, PRESENT_BINDINGS} {
update_queue{instance},
rasterizer{
memory, pica, system.CustomTexManager(), *this, render_window,
instance, scheduler, renderpass_cache, update_queue, main_window.ImageCount()},
present_heap{instance, scheduler.GetMasterSemaphore(), PRESENT_BINDINGS, 32} {
CompileShaders();
BuildLayouts();
BuildPipelines();
Expand Down Expand Up @@ -112,6 +105,7 @@ void RendererVulkan::PrepareRendertarget() {

const auto color_fill = fb_id == 0 ? regs_lcd.color_fill_top : regs_lcd.color_fill_bottom;
if (color_fill.is_enabled) {
screen_infos[i].image_view = texture.image_view;
FillScreen(color_fill.AsVector(), texture);
continue;
}
Expand All @@ -127,16 +121,14 @@ void RendererVulkan::PrepareRendertarget() {

void RendererVulkan::PrepareDraw(Frame* frame, const Layout::FramebufferLayout& layout) {
const auto sampler = present_samplers[!Settings::values.filter_mode.GetValue()];
std::transform(screen_infos.begin(), screen_infos.end(), present_textures.begin(),
[&](auto& info) {
return DescriptorData{vk::DescriptorImageInfo{sampler, info.image_view,
vk::ImageLayout::eGeneral}};
});

const auto descriptor_set = present_set_provider.Acquire(present_textures);
const auto present_set = present_heap.Commit();
for (u32 index = 0; index < screen_infos.size(); index++) {
update_queue.AddImageSampler(present_set, 0, index, screen_infos[index].image_view,
sampler);
}

renderpass_cache.EndRendering();
scheduler.Record([this, layout, frame, descriptor_set, renderpass = main_window.Renderpass(),
scheduler.Record([this, layout, frame, present_set, renderpass = main_window.Renderpass(),
index = current_pipeline](vk::CommandBuffer cmdbuf) {
const vk::Viewport viewport = {
.x = 0.0f,
Expand Down Expand Up @@ -171,7 +163,7 @@ void RendererVulkan::PrepareDraw(Frame* frame, const Layout::FramebufferLayout&

cmdbuf.beginRenderPass(renderpass_begin_info, vk::SubpassContents::eInline);
cmdbuf.bindPipeline(vk::PipelineBindPoint::eGraphics, present_pipelines[index]);
cmdbuf.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, layout, 0, descriptor_set, {});
cmdbuf.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, layout, 0, present_set, {});
});
}

Expand Down Expand Up @@ -264,7 +256,7 @@ void RendererVulkan::BuildLayouts() {
.size = sizeof(PresentUniformData),
};

const auto descriptor_set_layout = present_set_provider.Layout();
const auto descriptor_set_layout = present_heap.Layout();
const vk::PipelineLayoutCreateInfo layout_info = {
.setLayoutCount = 1,
.pSetLayouts = &descriptor_set_layout,
Expand Down Expand Up @@ -809,29 +801,7 @@ void RendererVulkan::DrawScreens(Frame* frame, const Layout::FramebufferLayout&
}
}

scheduler.Record([image = frame->image](vk::CommandBuffer cmdbuf) {
const vk::ImageMemoryBarrier render_barrier = {
.srcAccessMask = vk::AccessFlagBits::eColorAttachmentWrite,
.dstAccessMask = vk::AccessFlagBits::eTransferRead,
.oldLayout = vk::ImageLayout::eTransferSrcOptimal,
.newLayout = vk::ImageLayout::eTransferSrcOptimal,
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.image = image,
.subresourceRange{
.aspectMask = vk::ImageAspectFlagBits::eColor,
.baseMipLevel = 0,
.levelCount = 1,
.baseArrayLayer = 0,
.layerCount = VK_REMAINING_ARRAY_LAYERS,
},
};

cmdbuf.endRenderPass();
cmdbuf.pipelineBarrier(vk::PipelineStageFlagBits::eColorAttachmentOutput,
vk::PipelineStageFlagBits::eTransfer,
vk::DependencyFlagBits::eByRegion, {}, {}, render_barrier);
});
scheduler.Record([](vk::CommandBuffer cmdbuf) { cmdbuf.endRenderPass(); });
}

void RendererVulkan::SwapBuffers() {
Expand Down
Loading

0 comments on commit 9de84a0

Please sign in to comment.