# SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
# SPDX-License-Identifier: GPL-3.0-or-later

# SPDX-License-Identifier: GPL-2.0-or-later

add_subdirectory(host_shaders)
add_subdirectory(gpu_logging)

if(LIBVA_FOUND)
    set_source_files_properties(host1x/ffmpeg.cpp
        PROPERTIES COMPILE_DEFINITIONS LIBVA_FOUND=1)
    list(APPEND FFmpeg_LIBRARIES ${LIBVA_LIBRARIES})
endif()

add_library(video_core STATIC
    async_translate.h
    back_read_audit.cpp
    back_read_audit.h
    buffer_cache/buffer_base.h
    buffer_cache/buffer_cache_base.h
    buffer_cache/buffer_cache.cpp
    buffer_cache/buffer_cache.h
    buffer_cache/cache_inputs.h
    buffer_cache/mem_read_log.h
    buffer_cache/memory_tracker_base.h
    buffer_cache/nx2_bytes_equal.h
    buffer_cache/usage_tracker.h
    buffer_cache/virtual_range_cache.h
    buffer_cache/word_manager.h
    buffer_churn_stats.h
    cache_types.h
    capture.h
    cdma_pusher.cpp
    cdma_pusher.h
    churn_counters.h
    compatible_formats.cpp
    compatible_formats.h
    compute_skip_hook.h
    control/channel_state.cpp
    control/channel_state.h
    control/channel_state_cache.cpp
    control/channel_state_cache.h
    control/scheduler.cpp
    control/scheduler.h
    delayed_destruction_ring.h
    dirty_flags.cpp
    dirty_flags.h
    dma_pusher.cpp
    dma_pusher.h
    early_compute.h
    engines/sw_blitter/blitter.cpp
    engines/sw_blitter/blitter.h
    engines/sw_blitter/converter.cpp
    engines/sw_blitter/converter.h
    engines/const_buffer_info.h
    engines/draw_manager.cpp
    engines/engine_interface.h
    engines/engine_upload.cpp
    engines/engine_upload.h
    engines/fermi_2d.cpp
    engines/fermi_2d.h
    engines/kepler_compute.cpp
    engines/kepler_compute.h
    engines/kepler_memory.cpp
    engines/kepler_memory.h
    engines/maxwell_3d.cpp
    engines/maxwell_3d.h
    engines/maxwell_dma.cpp
    engines/maxwell_dma.h
    engines/puller.cpp
    engines/puller.h
    framebuffer_config.cpp
    framebuffer_config.h
    fritchii_delta_path.h
    fritchii_draw_kinds.h
    fritchii_report_runs.h
    render_trace.h
    fsr.cpp
    fsr.h
    fsr4_support.h
    game_dlss_status.cpp
    game_dlss_status.h
    host1x/codecs/decoder.cpp
    host1x/codecs/decoder.h
    host1x/codecs/h264.cpp
    host1x/codecs/h264.h
    host1x/codecs/vp8.cpp
    host1x/codecs/vp8.h
    host1x/codecs/vp9.cpp
    host1x/codecs/vp9.h
    host1x/codec_types.h
    host1x/ffmpeg.cpp
    host1x/ffmpeg.h
    host1x/control.cpp
    host1x/control.h
    host1x/gpu_device_memory_manager.cpp
    host1x/gpu_device_memory_manager.h
    host1x/h264_packet.h
    host1x/host1x.cpp
    host1x/host1x.h
    host1x/nvdec.cpp
    host1x/nvdec.h
    host1x/nvdec_common.h
    host1x/nx2_video_decoder.cpp
    host1x/nx2_video_decoder.h
    host1x/syncpoint_manager.cpp
    host1x/syncpoint_manager.h
    host1x/vic.cpp
    host1x/vic.h
    macro.cpp
    macro.h
    macro_hle_oot.cpp
    macro_hle_oot.h
    macro_ops_oot.h
    macro_memo.h
    macro_turing.h
    fence_manager.h
    fritchii_e_split.cpp
    fritchii_e_split.h
    fritchii_e_split_thread.cpp
    fritchii_e_split_thread.h
    fritchii_fill_cuts.h
    fritchii_occl_lean.h
    fritchii_front_split.cpp
    fritchii_front_split.h
    fritchii_focus.h
    fritchii_occlusion.h
    fritchii_price.cpp
    fritchii_price.h
    fritchii_s4_count.cpp
    fritchii_s4_count.h
    gpu.cpp
    gpu.h
    gpu_timestamp.h
    gpu_split.cpp
    gpu_split.h
    gpu_thread.cpp
    gpu_thread.h
    guest_memory.h
    invalidation_accumulator.h
    memory_manager.cpp
    memory_manager.h
    memstage_shadow.cpp
    memstage_shadow.h
    memstage_shadow_engine.h
    memory_stage_link.cpp
    memory_stage_link.h
    page_filter.h
    pipeline_cache_files.cpp
    pipeline_cache_files.h
    pipeline_cache_policy.h
    native_qmd.h
    native_query_trace.h
    nx2.h
    nx2_cb_path.h
    nx2_cmdpage_diag.h
    nx2_debug_control.cpp
    nx2_fastdraw_count.h
    nx2_ghost_pools.h
    nx2_precompile.cpp
    nx2_precompile.h
    nx2_recipe.cpp
    nx2_recipe.h
    nx2_report_census.h
    nx2_debug_control.h
    nx2_frame_fence.h
    nx2_list_verify.h
    nx2_profile.h
    nx2_qmd_prediction.cpp
    nx2_qmd_prediction.h
    nx2_runahead.cpp
    nx2_runahead.h
    nx2_write_track.cpp
    nx2_write_track.h
    nx2_perf.h
    nx2_download_trace.h
    nx2_async_readback.h
    one_follower.cpp
    one_follower.h
    one_follower_draw.cpp
    one_follower_hooks.h
    one_follower_view.cpp
    one_follower_stats.cpp
    one_follower_stats.h
    pending_maps.h
    present.h
    pte_kind.h
    query_cache/bank_base.h
    query_cache/query_base.h
    query_cache/query_cache_base.h
    query_cache/query_cache.h
    query_cache/query_stream.h
    query_cache/types.h
    query_cache.h
    query_dma.h
    rasterizer_interface.h
    renderer_base.cpp
    renderer_base.h

    # Null
    renderer_null/null_rasterizer.cpp
    renderer_null/null_rasterizer.h
    renderer_null/renderer_null.cpp
    renderer_null/renderer_null.h

    # Vulkan
    renderer_vulkan/present/anti_alias_pass.h
    renderer_vulkan/present/filters.cpp
    renderer_vulkan/present/filters.h
    renderer_vulkan/present/fsr.cpp
    renderer_vulkan/present/fsr.h
    renderer_vulkan/present/fsr3.cpp
    renderer_vulkan/present/fsr3.h
    renderer_vulkan/present/fxaa.cpp
    renderer_vulkan/present/fxaa.h
    renderer_vulkan/present/layer.cpp
    renderer_vulkan/present/layer.h
    renderer_vulkan/present/present_push_constants.h
    renderer_vulkan/present/smaa.cpp
    renderer_vulkan/present/smaa.h
    renderer_vulkan/present/sgsr.cpp
    renderer_vulkan/present/sgsr.h
    renderer_vulkan/present/util.cpp
    renderer_vulkan/present/util.h
    renderer_vulkan/present/window_adapt_pass.cpp
    renderer_vulkan/present/window_adapt_pass.h
    renderer_vulkan/blit_image.cpp
    renderer_vulkan/blit_image.h
    renderer_vulkan/fixed_pipeline_state.cpp
    renderer_vulkan/fixed_pipeline_state.h
    renderer_vulkan/framebuffer_clear_layers.h
    renderer_vulkan/framebuffer_limits.h
    renderer_vulkan/maxwell_to_vk.cpp
    renderer_vulkan/maxwell_to_vk.h
    renderer_vulkan/pipeline_build.h
    renderer_vulkan/pipeline_helper.h
    renderer_vulkan/pipeline_optimization.h
    renderer_vulkan/pipeline_shader_emission.h
    renderer_vulkan/pipeline_statistics.cpp
    renderer_vulkan/pipeline_statistics.h
    renderer_vulkan/renderer_vulkan.h
    renderer_vulkan/renderer_vulkan.cpp
    renderer_vulkan/vk_blit_screen.cpp
    renderer_vulkan/vk_blit_screen.h
    renderer_vulkan/vk_buffer_cache_base.cpp
    renderer_vulkan/vk_buffer_cache.cpp
    renderer_vulkan/vk_buffer_cache.h
    renderer_vulkan/vk_buffer_recycler.h
    renderer_vulkan/vk_command_pool.cpp
    renderer_vulkan/vk_command_pool.h
    renderer_vulkan/vk_compute_pass.cpp
    renderer_vulkan/vk_compute_pass.h
    renderer_vulkan/vk_fsr3_upscaler.cpp
    renderer_vulkan/vk_fsr3_upscaler.h
    renderer_vulkan/vk_fsr4_upscaler.cpp
    renderer_vulkan/vk_fsr4_upscaler.h
    vulkan_common/ffx_files.h
    vulkan_common/ffx_runtime.cpp
    vulkan_common/ffx_runtime.h
    renderer_vulkan/vk_dlss_network_probe.cpp
    renderer_vulkan/vk_dlss_network_probe.h
    renderer_vulkan/vk_ocarina_camera_motion.cpp
    renderer_vulkan/vk_ocarina_camera_motion.h
    renderer_vulkan/vk_async_compute_skip.h
    renderer_vulkan/vk_compute_pipeline.cpp
    renderer_vulkan/vk_compute_pipeline.h
    renderer_vulkan/vk_cooperative_hmma_test.cpp
    renderer_vulkan/vk_cooperative_hmma_test.h
    renderer_vulkan/vk_descriptor_buffer.cpp
    renderer_vulkan/vk_descriptor_buffer.h
    renderer_vulkan/vk_descriptor_pool.cpp
    renderer_vulkan/vk_descriptor_pool.h
    renderer_vulkan/vk_fence_manager.cpp
    renderer_vulkan/vk_fence_manager.h
    renderer_vulkan/vk_flash_watch.cpp
    renderer_vulkan/vk_flash_watch.h
    renderer_vulkan/vk_frame_dump.cpp
    renderer_vulkan/vk_frame_dump.h
    renderer_vulkan/vk_graphics_pipeline.cpp
    renderer_vulkan/vk_graphics_pipeline.h
    renderer_vulkan/vk_pipeline_library.cpp
    renderer_vulkan/vk_pipeline_library.h
    renderer_vulkan/vk_multi_range_buffer.cpp
    renderer_vulkan/vk_multi_range_buffer.h
    renderer_vulkan/vk_master_semaphore.cpp
    renderer_vulkan/vk_master_semaphore.h
    renderer_vulkan/vk_mem_stage.cpp
    renderer_vulkan/vk_mem_stage.h
    renderer_vulkan/vk_mem_stage_hook.h
    renderer_vulkan/vk_mem_stage_shadow.h
    renderer_vulkan/vk_one_follower_draw.cpp
    renderer_vulkan/vk_one_follower_draw.h
    renderer_vulkan/vk_pipeline_binary.cpp
    renderer_vulkan/vk_pipeline_binary.h
    renderer_vulkan/vk_pipeline_cache.cpp
    renderer_vulkan/vk_pipeline_cache.h
    renderer_vulkan/vk_pipeline_translate_queue.cpp
    renderer_vulkan/vk_pipeline_translate_queue.h
    renderer_vulkan/vk_precompiled_kept.cpp
    renderer_vulkan/vk_precompiled_kept.h
    renderer_vulkan/vk_present_manager.cpp
    renderer_vulkan/vk_present_manager.h
    renderer_vulkan/vk_host_pacer.cpp
    renderer_vulkan/vk_host_pacer.h
    renderer_vulkan/vk_query_cache.cpp
    renderer_vulkan/vk_query_cache.h
    renderer_vulkan/vk_rasterizer.cpp
    renderer_vulkan/vk_rasterizer.h
    renderer_vulkan/submission_policy.h
    renderer_vulkan/upload_batch.h
    renderer_vulkan/vk_render_pass_cache.cpp
    renderer_vulkan/vk_render_pass_cache.h
    renderer_vulkan/vk_resource_pool.cpp
    renderer_vulkan/vk_resource_pool.h
    renderer_vulkan/vk_scheduler.cpp
    renderer_vulkan/vk_scheduler.h
    renderer_vulkan/vk_seam_clock.h
    renderer_vulkan/fragment_barrier_state.h
    renderer_vulkan/vk_shader_util.cpp
    renderer_vulkan/vk_shader_util.h
    renderer_vulkan/vk_staging_buffer_pool.cpp
    renderer_vulkan/vk_staging_buffer_pool.h
    renderer_vulkan/vk_side_queue.cpp
    renderer_vulkan/vk_side_queue.h
    renderer_vulkan/vk_state_tracker.cpp
    renderer_vulkan/vk_state_tracker.h
    renderer_vulkan/vk_pcie_link.cpp
    renderer_vulkan/vk_pcie_link.h
    renderer_vulkan/vk_sim_gpu_slow.cpp
    renderer_vulkan/vk_sim_gpu_slow.h
    renderer_vulkan/vk_sim_link_hog.cpp
    renderer_vulkan/vk_sim_link_hog.h
    renderer_vulkan/vk_submit_times.cpp
    renderer_vulkan/vk_submit_times.h
    renderer_vulkan/vk_swapchain.cpp
    renderer_vulkan/vk_swapchain.h
    renderer_vulkan/vk_texture_cache.cpp
    renderer_vulkan/vk_texture_cache.h
    renderer_vulkan/vk_texture_cache_base.cpp
    renderer_vulkan/vk_turbo_mode.cpp
    renderer_vulkan/vk_turbo_mode.h
    renderer_vulkan/vk_update_descriptor.cpp
    renderer_vulkan/vk_update_descriptor.h
    renderer_vulkan/descriptor_payload_growth.h
    vulkan_common/vulkan_cmd_stats.h
    vulkan_common/vulkan_debug_callback.cpp
    vulkan_common/vulkan_debug_callback.h
    vulkan_common/vulkan_device.cpp
    vulkan_common/vulkan_device.h
    vulkan_common/vulkan_instance.cpp
    vulkan_common/vulkan_instance.h
    vulkan_common/vulkan_library.cpp
    vulkan_common/vulkan_library.h
    vulkan_common/vulkan_overlay_filter.h
    vulkan_common/unbacked_fallback.h
    vulkan_common/vulkan_memory_allocator.cpp
    vulkan_common/vulkan_memory_allocator.h
    vulkan_common/vulkan_kept_blocks.cpp
    vulkan_common/vulkan_kept_blocks.h
    vulkan_common/vulkan_surface.cpp
    vulkan_common/vulkan_surface.h
    vulkan_common/vulkan_wrapper.cpp
    vulkan_common/vulkan_wrapper.h
    vulkan_common/nsight_aftermath_tracker.cpp
    vulkan_common/aftermath_dump.h
    vulkan_common/nsight_aftermath_tracker.h
    vulkan_common/vma.h
    vulkan_common/vulkan.h

    shader_cache.cpp
    shader_cache.h
    shader_environment.cpp
    shader_environment.h
    evicted_pointer_slots.h
    shader_handle_program.h
    texture_handle_values.h
    shader_notify.cpp
    shader_notify.h
    shader_warm/shader_archives.cpp
    shader_warm/shader_archives.h
    shader_warm/shader_warm_builder.cpp
    shader_warm/shader_warm_builder.h
    shader_warm/warm_defaults.cpp
    shader_warm/warm_records.cpp
    shader_warm/warm_records.h
    smaa_area_tex.h
    smaa_search_tex.h
    surface.cpp
    surface.h
    texture_cache/accelerated_swizzle.cpp
    texture_cache/accelerated_swizzle.h
    texture_cache/decode_bc.cpp
    texture_cache/decode_bc.h
    texture_cache/descriptor_table.h
    texture_cache/host_memory_limit.h
    texture_cache/formatter.cpp
    texture_cache/formatter.h
    texture_cache/format_lookup_table.cpp
    texture_cache/format_lookup_table.h
    texture_cache/image_base.cpp
    texture_cache/image_base.h
    texture_cache/image_info.cpp
    texture_cache/image_info.h
    texture_cache/image_view_base.cpp
    texture_cache/image_view_base.h
    texture_cache/image_view_info.cpp
    texture_cache/image_view_info.h
    texture_cache/relocation_memory.cpp
    texture_cache/relocation_memory.h
    texture_cache/render_targets.h
    texture_cache/samples_helper.h
    texture_cache/texture_cache.cpp
    texture_cache/texture_cache.h
    test_watermark.cpp
    test_watermark.h
    texture_cache/texture_cache_base.h
    texture_cache/types.h
    texture_cache/util.cpp
    texture_cache/util.h
    textures/astc.h
    textures/astc.cpp
    textures/bcn.cpp
    textures/bcn.h
    textures/decoders.cpp
    textures/decoders.h
    textures/texture.cpp
    textures/texture.h
    textures/unswizzle_worker.cpp
    textures/unswizzle_worker.h
    textures/workers.cpp
    textures/workers.h
    transform_feedback.cpp
    transform_feedback.h
    video_core.cpp
    video_core.h
)

if (ENABLE_RESHADE)
    set(BUNDLED_FX_DIR ${CMAKE_SOURCE_DIR}/dist/post_shaders)
    set(BUNDLED_FX_HEADER ${CMAKE_CURRENT_BINARY_DIR}/bundled_fx_effects.h)
    file(GLOB BUNDLED_FX_FILES ${BUNDLED_FX_DIR}/*.fx)

    add_custom_command(
        OUTPUT ${BUNDLED_FX_HEADER}
        COMMAND ${CMAKE_COMMAND} -P
            ${CMAKE_CURRENT_SOURCE_DIR}/post_processing/GenerateBundledEffects.cmake
            ${BUNDLED_FX_DIR} ${BUNDLED_FX_HEADER}
        DEPENDS ${BUNDLED_FX_FILES}
    )

    set(BUNDLED_PRESET_DIR ${CMAKE_SOURCE_DIR}/dist/post_presets)
    set(BUNDLED_PRESET_HEADER ${CMAKE_CURRENT_BINARY_DIR}/bundled_fx_presets.h)
    file(GLOB BUNDLED_PRESET_FILES ${BUNDLED_PRESET_DIR}/*.fxp)

    add_custom_command(
        OUTPUT ${BUNDLED_PRESET_HEADER}
        COMMAND ${CMAKE_COMMAND} -P
            ${CMAKE_CURRENT_SOURCE_DIR}/post_processing/GenerateBundledPresets.cmake
            ${BUNDLED_PRESET_DIR} ${BUNDLED_PRESET_HEADER}
        DEPENDS ${BUNDLED_PRESET_FILES}
    )

    target_sources(video_core PRIVATE
        post_processing/fx_chain.cpp
        post_processing/fx_chain.h
        post_processing/fx_compile.cpp
        post_processing/fx_compile.h
        post_processing/fx_effect.cpp
        post_processing/fx_effect.h
        post_processing/fx_preset.cpp
        post_processing/fx_preset.h
        renderer_vulkan/present/post_process.cpp
        renderer_vulkan/present/post_process.h
        ${BUNDLED_FX_HEADER}
        ${BUNDLED_PRESET_HEADER}
    )
    target_include_directories(video_core PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
    target_link_libraries(video_core PRIVATE reshadefx::reshadefx)
    target_compile_definitions(video_core PUBLIC HAS_RESHADE)
endif()

# "Preparing shaders" is stamped with a hash of what decides the driver's compiled pipelines (the
# shader recompiler, pipeline creation, the precompile step), not the release version
# (CMakeModules/Nx2ShaderStamp.cmake): releases that change no shader skip the step. A change to
# any of these files, even a comment, makes every player prepare again: read that script first.
file(GLOB_RECURSE NX2_SHADER_STAMP_INPUTS CONFIGURE_DEPENDS
    "${PROJECT_SOURCE_DIR}/src/shader_recompiler/*.cpp"
    "${PROJECT_SOURCE_DIR}/src/shader_recompiler/*.h"
    "${CMAKE_CURRENT_SOURCE_DIR}/renderer_vulkan/fixed_pipeline_state.*"
    "${CMAKE_CURRENT_SOURCE_DIR}/renderer_vulkan/vk_graphics_pipeline.*"
    "${CMAKE_CURRENT_SOURCE_DIR}/renderer_vulkan/vk_compute_pipeline.*"
    "${CMAKE_CURRENT_SOURCE_DIR}/nx2_precompile.*")
string(REPLACE ";" "\n" NX2_SHADER_STAMP_LIST "${NX2_SHADER_STAMP_INPUTS}")
file(CONFIGURE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/nx2_shader_stamp_inputs.txt"
     CONTENT "${NX2_SHADER_STAMP_LIST}\n")
add_custom_command(
    OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/nx2_shader_stamp.h"
    COMMAND ${CMAKE_COMMAND} "-DINPUT_LIST=${CMAKE_CURRENT_BINARY_DIR}/nx2_shader_stamp_inputs.txt"
            "-DOUT=${CMAKE_CURRENT_BINARY_DIR}/nx2_shader_stamp.h"
            -P "${PROJECT_SOURCE_DIR}/CMakeModules/Nx2ShaderStamp.cmake"
    DEPENDS ${NX2_SHADER_STAMP_INPUTS} "${PROJECT_SOURCE_DIR}/CMakeModules/Nx2ShaderStamp.cmake"
            "${CMAKE_CURRENT_BINARY_DIR}/nx2_shader_stamp_inputs.txt"
    COMMENT "Hashing the shader translator for the Preparing shaders stamp"
    VERBATIM)
target_sources(video_core PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/nx2_shader_stamp.h")
target_include_directories(video_core PRIVATE ${CMAKE_CURRENT_BINARY_DIR})

if (ENABLE_OPENGL)
    target_sources(video_core PRIVATE
        renderer_opengl/present/filters.cpp
        renderer_opengl/present/filters.h
        renderer_opengl/present/fsr.cpp
        renderer_opengl/present/fsr.h
        renderer_opengl/present/fxaa.cpp
        renderer_opengl/present/fxaa.h
        renderer_opengl/present/layer.cpp
        renderer_opengl/present/layer.h
        renderer_opengl/present/present_uniforms.h
        renderer_opengl/present/smaa.cpp
        renderer_opengl/present/smaa.h
        renderer_opengl/present/util.h
        renderer_opengl/present/window_adapt_pass.cpp
        renderer_opengl/present/window_adapt_pass.h
        renderer_opengl/blit_image.cpp
        renderer_opengl/blit_image.h
        renderer_opengl/gl_blit_screen.cpp
        renderer_opengl/gl_blit_screen.h
        renderer_opengl/gl_buffer_cache_base.cpp
        renderer_opengl/gl_buffer_cache.cpp
        renderer_opengl/gl_buffer_cache.h
        renderer_opengl/gl_compute_pipeline.cpp
        renderer_opengl/gl_compute_pipeline.h
        renderer_opengl/gl_device.cpp
        renderer_opengl/gl_device.h
        renderer_opengl/gl_fence_manager.cpp
        renderer_opengl/gl_fence_manager.h
        renderer_opengl/gl_graphics_pipeline.cpp
        renderer_opengl/gl_graphics_pipeline.h
        renderer_opengl/gl_rasterizer.cpp
        renderer_opengl/gl_rasterizer.h
        renderer_opengl/gl_resource_manager.cpp
        renderer_opengl/gl_resource_manager.h
        renderer_opengl/gl_shader_cache.cpp
        renderer_opengl/gl_shader_cache.h
        renderer_opengl/gl_shader_manager.cpp
        renderer_opengl/gl_shader_manager.h
        renderer_opengl/gl_shader_context.h
        renderer_opengl/gl_shader_util.cpp
        renderer_opengl/gl_shader_util.h
        renderer_opengl/gl_state_tracker.cpp
        renderer_opengl/gl_state_tracker.h
        renderer_opengl/gl_staging_buffer_pool.cpp
        renderer_opengl/gl_staging_buffer_pool.h
        renderer_opengl/gl_texture_cache.cpp
        renderer_opengl/gl_texture_cache.h
        renderer_opengl/gl_texture_cache_base.cpp
        renderer_opengl/gl_query_cache.cpp
        renderer_opengl/gl_query_cache.h
        renderer_opengl/maxwell_to_gl.h
        renderer_opengl/renderer_opengl.cpp
        renderer_opengl/renderer_opengl.h
        renderer_opengl/util_shaders.cpp
        renderer_opengl/util_shaders.h
    )
endif()

target_link_libraries(video_core PUBLIC common core)
if(WIN32)
    target_link_libraries(video_core PRIVATE advapi32)
endif()

# Shader warm-up builder: game archives use zstd (also with dictionaries) and zlib.
target_link_libraries(video_core PRIVATE zstd::zstd ZLIB::ZLIB)
target_link_libraries(video_core PUBLIC shader_recompiler stb bc_decoder gpu_logging)
if (ENABLE_OPENGL)
    target_link_libraries(video_core PUBLIC glad)
endif()

if (YUZU_USE_EXTERNAL_FFMPEG)
    add_dependencies(video_core ffmpeg-build)
endif()

target_include_directories(video_core PUBLIC ${FFmpeg_INCLUDE_DIR})

target_link_libraries(video_core PRIVATE ${FFmpeg_LIBRARIES})
target_link_options(video_core PRIVATE ${FFmpeg_LDFLAGS})

add_dependencies(video_core host_shaders)
target_include_directories(video_core PRIVATE ${HOST_SHADERS_INCLUDE})
# AMD's FFX API headers (MIT), for calling AMD's FSR 4 runtime (vk_fsr4_upscaler.cpp).
target_include_directories(video_core PRIVATE ${CMAKE_SOURCE_DIR}/externals/ffx-api)
if (WIN32)
    # Checks AMD's downloaded FSR 4 runtime (vulkan_common/ffx_runtime.cpp).
    target_link_libraries(video_core PRIVATE bcrypt wintrust crypt32)
endif()

target_link_libraries(video_core PRIVATE sirit::sirit)

# Header-only stuff needed by all dependent targets
target_link_libraries(video_core PUBLIC Vulkan::Headers Vulkan::UtilityHeaders GPUOpen::VulkanMemoryAllocator)

if (ENABLE_NSIGHT_AFTERMATH)
    if (NOT DEFINED ENV{NSIGHT_AFTERMATH_SDK})
        message(FATAL_ERROR "Environment variable NSIGHT_AFTERMATH_SDK has to be provided")
    endif()
    if (NOT WIN32)
        message(FATAL_ERROR "Nsight Aftermath doesn't support non-Windows platforms")
    endif()
    target_compile_definitions(video_core PRIVATE HAS_NSIGHT_AFTERMATH)
    target_include_directories(video_core PRIVATE "$ENV{NSIGHT_AFTERMATH_SDK}/include")
endif()

if (NOT MSVC)
    if (APPLE)
        # error: declaration shadows a typedef in 'interval_base_set<SubType, DomainT, Compare, Interval, Alloc>'
        # error: implicit conversion loses integer precision: 'int' to 'boost::icl::bound_type' (aka 'unsigned char')
        target_compile_options(video_core PRIVATE
            $<$<COMPILE_LANGUAGE:C,CXX>:-Wno-shadow>
            $<$<COMPILE_LANGUAGE:C,CXX>:-Wno-unused-local-typedef>)
    else()
        target_compile_options(video_core PRIVATE $<$<COMPILE_LANGUAGE:C,CXX>:-Wconversion>)
    endif()

    target_compile_options(video_core PRIVATE $<$<COMPILE_LANGUAGE:C,CXX>:-Wno-sign-conversion>)

    # xbyak
    set_source_files_properties(macro/macro_jit_x64.cpp PROPERTIES COMPILE_OPTIONS "-Wno-conversion;-Wno-shadow")

    # Get around GCC failing with intrinsics in Debug
    if (CXX_GCC AND CMAKE_BUILD_TYPE MATCHES "Debug")
        set_source_files_properties(host1x/vic.cpp PROPERTIES COMPILE_OPTIONS "-O2")
    endif()
endif()

if (ENABLE_OPENGL)
    target_compile_definitions(video_core PUBLIC HAS_OPENGL)
endif()

if (ARCHITECTURE_x86_64)
    target_link_libraries(video_core PUBLIC xbyak::xbyak)
endif()

if (ARCHITECTURE_x86_64 OR ARCHITECTURE_arm64)
    target_link_libraries(video_core PRIVATE dynarmic::dynarmic)
endif()

if (ANDROID AND ARCHITECTURE_arm64)
    target_link_libraries(video_core PRIVATE adrenotools)
endif()

# NVIDIA DLSS through NVIDIA Streamline, in place of a game's DLSS (before FSR 3.1) when the
# setting is on. Only Streamline's MIT-licensed headers are compiled in and nothing of NVIDIA's is
# linked or copied: sl.interposer.dll and the DLSS plugins are loaded at run time from the user's PC.
cmake_dependent_option(ENABLE_NVIDIA_DLSS "Enable NVIDIA DLSS through NVIDIA Streamline" ON
                       "MSVC AND ARCHITECTURE_x86_64" OFF)
set(EGLANTINE_STREAMLINE_SDK "" CACHE PATH
    "NVIDIA Streamline SDK directory for its headers (empty: download them)")
if (ENABLE_NVIDIA_DLSS)
    if (EGLANTINE_STREAMLINE_SDK)
        set(STREAMLINE_INCLUDE_DIR "${EGLANTINE_STREAMLINE_SDK}/include")
    else()
        AddJsonPackage(NAME streamline DOWNLOAD_ONLY)
        set(STREAMLINE_INCLUDE_DIR "${streamline_SOURCE_DIR}/include")
    endif()
    target_sources(video_core PRIVATE
        renderer_vulkan/vk_streamline_dlss.cpp
        renderer_vulkan/vk_streamline_dlss.h
        vulkan_common/streamline.cpp
        vulkan_common/streamline.h
        vulkan_common/streamline_api.h
    )
    target_include_directories(video_core PRIVATE "${STREAMLINE_INCLUDE_DIR}")
    target_link_libraries(video_core PRIVATE version wintrust crypt32)
    target_compile_definitions(video_core PUBLIC EGLANTINE_STREAMLINE)
    message(STATUS "NVIDIA DLSS through Streamline: ${STREAMLINE_INCLUDE_DIR}")
endif()

create_target_directory_groups(video_core)
