mirror of
https://github.com/KytyPS5/KytyPS5.git
synced 2026-10-27 16:02:37 +00:00
Compare commits
45
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7907a50817 | ||
|
|
769edf470b | ||
|
|
68fffdfb66 | ||
|
|
26781e6fea | ||
|
|
d5c95bc3ee | ||
|
|
ace549ab21 | ||
|
|
0cbae39e41 | ||
|
|
e9f5da27f8 | ||
|
|
3052dac82e | ||
|
|
2bb0483473 | ||
|
|
389fd1e5be | ||
|
|
a76f3ac2fe | ||
|
|
2fc4855f29 | ||
|
|
869329ee68 | ||
|
|
b2963aa6e0 | ||
|
|
9859b3e1d6 | ||
|
|
cd19fa283f | ||
|
|
b6af7c73ec | ||
|
|
ac64d202af | ||
|
|
df44ad3fac | ||
|
|
0a2f4814ac | ||
|
|
e6b4707a5d | ||
|
|
9a3468e3a0 | ||
|
|
73da43a7be | ||
|
|
aa88d94755 | ||
|
|
51562cd8d2 | ||
|
|
822ca3c10b | ||
|
|
2b6fd699e7 | ||
|
|
b9aa0dc3b3 | ||
|
|
f380d69b9d | ||
|
|
f06d7e6084 | ||
|
|
00a5dd32c0 | ||
|
|
a9ddd44d73 | ||
|
|
2f9fcc63c3 | ||
|
|
0bbd0bdd99 | ||
|
|
6396dc9a85 | ||
|
|
a3a00464bc | ||
|
|
1da99a0671 | ||
|
|
9304921132 | ||
|
|
c13a1d752b | ||
|
|
51d0e02543 | ||
|
|
e8752aca7e | ||
|
|
7dd50ea127 | ||
|
|
d09c81d1c6 | ||
|
|
26f0c7b0bf |
No files matched your search
+98
-30
@@ -6,9 +6,27 @@ on:
|
||||
branches: [ main, master ]
|
||||
pull_request:
|
||||
|
||||
env:
|
||||
KYTY_BUILD_ORIGIN: ${{ github.repository != 'KytyPS5/KytyPS5' && 'Fork' || github.event_name == 'push' && 'Official' || 'Source' }}
|
||||
KYTY_BUILD_REPOSITORY: ${{ github.repository }}
|
||||
|
||||
jobs:
|
||||
metadata:
|
||||
name: Prepare build metadata
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
release_tag: ${{ steps.release_tag.outputs.value }}
|
||||
|
||||
steps:
|
||||
- name: Generate release tag
|
||||
id: release_tag
|
||||
shell: bash
|
||||
run: |
|
||||
echo "value=KytyPS5-$(date -u +'%Y-%m-%d')-${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT"
|
||||
|
||||
windows:
|
||||
name: Build KytyPS5 (Windows)
|
||||
needs: metadata
|
||||
runs-on: windows-2022
|
||||
|
||||
steps:
|
||||
@@ -76,6 +94,10 @@ jobs:
|
||||
cmake -S . -B _Build/windows ^
|
||||
-G Ninja ^
|
||||
-DCMAKE_BUILD_TYPE=Release ^
|
||||
-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON ^
|
||||
-DKYTY_BUILD_ORIGIN=%KYTY_BUILD_ORIGIN% ^
|
||||
-DKYTY_BUILD_REPOSITORY=%KYTY_BUILD_REPOSITORY% ^
|
||||
-DKYTY_RELEASE_TAG=${{ needs.metadata.outputs.release_tag }} ^
|
||||
-DCMAKE_C_COMPILER=clang-cl ^
|
||||
-DCMAKE_CXX_COMPILER=clang-cl ^
|
||||
-DCMAKE_PREFIX_PATH="%Qt6_DIR%"
|
||||
@@ -83,12 +105,12 @@ jobs:
|
||||
- name: Build
|
||||
shell: cmd
|
||||
run: |
|
||||
cmake --build _Build/windows --target launcher audio_out2_port_tests virtual_memory_allocation_tests --parallel
|
||||
cmake --build _Build/windows --target launcher audio_out2_port_tests ime_dialog_tests virtual_memory_allocation_tests --parallel
|
||||
|
||||
- name: Test
|
||||
shell: cmd
|
||||
run: |
|
||||
ctest --test-dir _Build/windows --output-on-failure -R "^(audio_out2_port|virtual_memory_allocation)$"
|
||||
ctest --test-dir _Build/windows --output-on-failure -R "^(audio_out2_port|ime_dialog|virtual_memory_allocation)$"
|
||||
|
||||
- name: Install
|
||||
shell: cmd
|
||||
@@ -104,6 +126,7 @@ jobs:
|
||||
|
||||
macos:
|
||||
name: Build KytyPS5 (macOS)
|
||||
needs: metadata
|
||||
runs-on: macos-15
|
||||
|
||||
steps:
|
||||
@@ -150,6 +173,10 @@ jobs:
|
||||
cmake -S . -B _Build/macos \
|
||||
-G Ninja \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON \
|
||||
-DKYTY_BUILD_ORIGIN="$KYTY_BUILD_ORIGIN" \
|
||||
-DKYTY_BUILD_REPOSITORY="$KYTY_BUILD_REPOSITORY" \
|
||||
-DKYTY_RELEASE_TAG="${{ needs.metadata.outputs.release_tag }}" \
|
||||
-DCMAKE_OSX_ARCHITECTURES=x86_64 \
|
||||
-DCMAKE_C_COMPILER=clang \
|
||||
-DCMAKE_CXX_COMPILER=clang++ \
|
||||
@@ -159,14 +186,14 @@ jobs:
|
||||
shell: bash
|
||||
run: |
|
||||
cmake --build _Build/macos \
|
||||
--target launcher audio_out2_port_tests virtual_memory_allocation_tests \
|
||||
--target launcher audio_out2_port_tests ime_dialog_tests virtual_memory_allocation_tests \
|
||||
--parallel
|
||||
|
||||
- name: Test
|
||||
shell: bash
|
||||
run: |
|
||||
ctest --test-dir _Build/macos --output-on-failure \
|
||||
-R '^(audio_out2_port|virtual_memory_allocation)$'
|
||||
-R '^(audio_out2_port|ime_dialog|virtual_memory_allocation)$'
|
||||
|
||||
- name: Install
|
||||
shell: bash
|
||||
@@ -213,6 +240,7 @@ jobs:
|
||||
|
||||
linux:
|
||||
name: Build KytyPS5 (Linux)
|
||||
needs: metadata
|
||||
runs-on: ubuntu-24.04
|
||||
|
||||
steps:
|
||||
@@ -273,6 +301,10 @@ jobs:
|
||||
cmake -S . -B _Build/linux \
|
||||
-G Ninja \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON \
|
||||
-DKYTY_BUILD_ORIGIN="$KYTY_BUILD_ORIGIN" \
|
||||
-DKYTY_BUILD_REPOSITORY="$KYTY_BUILD_REPOSITORY" \
|
||||
-DKYTY_RELEASE_TAG="${{ needs.metadata.outputs.release_tag }}" \
|
||||
-DCMAKE_C_COMPILER=clang \
|
||||
-DCMAKE_CXX_COMPILER=clang++ \
|
||||
-DCMAKE_PREFIX_PATH="$Qt6_DIR" 2>&1 | tee _Build/configure.log
|
||||
@@ -297,14 +329,14 @@ jobs:
|
||||
run: |
|
||||
cmake --build _Build/linux \
|
||||
--target launcher page_manager_tests memory_tracker_tests \
|
||||
audio_out2_port_tests virtual_memory_allocation_tests \
|
||||
audio_out2_port_tests ime_dialog_tests virtual_memory_allocation_tests \
|
||||
--parallel
|
||||
|
||||
- name: Test
|
||||
shell: bash
|
||||
run: |
|
||||
ctest --test-dir _Build/linux --output-on-failure \
|
||||
-R '^(audio_out2_port|page_manager|memory_tracker|virtual_memory_allocation)$'
|
||||
-R '^(audio_out2_port|ime_dialog|page_manager|memory_tracker|virtual_memory_allocation)$'
|
||||
|
||||
- name: Install
|
||||
shell: bash
|
||||
@@ -341,46 +373,77 @@ jobs:
|
||||
|
||||
release:
|
||||
name: Release KytyPS5
|
||||
if: github.event_name == 'push' && github.repository == 'KytyPS5/KytyPS5'
|
||||
needs: [windows, macos, linux]
|
||||
if: >-
|
||||
always() &&
|
||||
github.event_name == 'push' &&
|
||||
github.repository == 'KytyPS5/KytyPS5' &&
|
||||
(needs.windows.result == 'success' ||
|
||||
needs.macos.result == 'success' ||
|
||||
needs.linux.result == 'success')
|
||||
needs: [metadata, windows, macos, linux]
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: write
|
||||
env:
|
||||
RELEASE_NAME: ${{ needs.metadata.outputs.release_tag }}
|
||||
|
||||
steps:
|
||||
- name: Download builds
|
||||
- name: Download Windows build
|
||||
if: needs.windows.result == 'success'
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
path: artifacts
|
||||
name: KytyPS5-Windows-x64
|
||||
path: artifacts/KytyPS5-Windows-x64
|
||||
|
||||
- name: Set release name
|
||||
shell: bash
|
||||
run: |
|
||||
echo "RELEASE_NAME=KytyPS5-$(date -u +'%Y-%m-%d')-${GITHUB_SHA::7}" >> "$GITHUB_ENV"
|
||||
- name: Download macOS build
|
||||
if: needs.macos.result == 'success'
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: KytyPS5-macOS-x86_64
|
||||
path: artifacts/KytyPS5-macOS-x86_64
|
||||
|
||||
- name: Package builds
|
||||
- name: Download Linux build
|
||||
if: needs.linux.result == 'success'
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: KytyPS5-Linux-x86_64
|
||||
path: artifacts/KytyPS5-Linux-x86_64
|
||||
|
||||
- name: Package Windows build
|
||||
if: needs.windows.result == 'success'
|
||||
shell: bash
|
||||
run: |
|
||||
windows_dir="artifacts/KytyPS5-Windows-x64"
|
||||
macos_dir="artifacts/KytyPS5-macOS-x86_64"
|
||||
linux_dir="artifacts/KytyPS5-Linux-x86_64"
|
||||
test -d "$windows_dir"
|
||||
test -d "$macos_dir"
|
||||
test -d "$linux_dir"
|
||||
chmod a+x \
|
||||
"$macos_dir/launcher" \
|
||||
"$macos_dir/kyty_emulator" \
|
||||
"$macos_dir/libMoltenVK.dylib" \
|
||||
"$linux_dir/launcher" \
|
||||
"$linux_dir/kyty_emulator"
|
||||
(
|
||||
cd "$windows_dir"
|
||||
zip -r "$GITHUB_WORKSPACE/$RELEASE_NAME-Windows-x64.zip" .
|
||||
)
|
||||
|
||||
- name: Package macOS build
|
||||
if: needs.macos.result == 'success'
|
||||
shell: bash
|
||||
run: |
|
||||
macos_dir="artifacts/KytyPS5-macOS-x86_64"
|
||||
test -d "$macos_dir"
|
||||
chmod a+x \
|
||||
"$macos_dir/launcher" \
|
||||
"$macos_dir/kyty_emulator" \
|
||||
"$macos_dir/libMoltenVK.dylib"
|
||||
(
|
||||
cd "$macos_dir"
|
||||
zip -r "$GITHUB_WORKSPACE/$RELEASE_NAME-macOS-x86_64.zip" .
|
||||
)
|
||||
|
||||
- name: Package Linux build
|
||||
if: needs.linux.result == 'success'
|
||||
shell: bash
|
||||
run: |
|
||||
linux_dir="artifacts/KytyPS5-Linux-x86_64"
|
||||
test -d "$linux_dir"
|
||||
chmod a+x \
|
||||
"$linux_dir/launcher" \
|
||||
"$linux_dir/kyty_emulator"
|
||||
tar -C "$linux_dir" -czf \
|
||||
"$GITHUB_WORKSPACE/$RELEASE_NAME-Linux-x86_64.tar.gz" .
|
||||
|
||||
@@ -389,11 +452,16 @@ jobs:
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
run: |
|
||||
assets=(
|
||||
"$RELEASE_NAME-Windows-x64.zip"
|
||||
"$RELEASE_NAME-macOS-x86_64.zip"
|
||||
"$RELEASE_NAME-Linux-x86_64.tar.gz"
|
||||
)
|
||||
assets=()
|
||||
for artifact in \
|
||||
"$RELEASE_NAME-Windows-x64.zip" \
|
||||
"$RELEASE_NAME-macOS-x86_64.zip" \
|
||||
"$RELEASE_NAME-Linux-x86_64.tar.gz"; do
|
||||
if [[ -f "$artifact" ]]; then
|
||||
assets+=("$artifact")
|
||||
fi
|
||||
done
|
||||
test "${#assets[@]}" -gt 0
|
||||
if gh release view "$RELEASE_NAME" --repo "$GITHUB_REPOSITORY" > /dev/null 2>&1; then
|
||||
gh release upload "$RELEASE_NAME" "${assets[@]}" \
|
||||
--clobber \
|
||||
|
||||
@@ -39,3 +39,6 @@
|
||||
[submodule "3rdparty/nlohmann_json"]
|
||||
path = 3rdparty/nlohmann_json
|
||||
url = https://github.com/nlohmann/json.git
|
||||
[submodule "3rdparty/imgui"]
|
||||
path = 3rdparty/imgui
|
||||
url = https://github.com/ocornut/imgui.git
|
||||
Vendored
+45
@@ -2,6 +2,32 @@ set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
|
||||
|
||||
add_subdirectory(cpuinfo)
|
||||
|
||||
# The Windows guest red-zone patcher needs a decoder/encoder and a small
|
||||
# trampoline assembler. Pin the same revisions used by shadPS4's implementation.
|
||||
include(FetchContent)
|
||||
|
||||
set(XBYAK_BUILD_TESTS OFF CACHE BOOL "" FORCE)
|
||||
FetchContent_Declare(
|
||||
xbyak
|
||||
GIT_REPOSITORY https://github.com/herumi/xbyak.git
|
||||
GIT_TAG 44a72f369268f7d552650891b296693e91db86bb
|
||||
GIT_SHALLOW FALSE
|
||||
)
|
||||
|
||||
set(ZYDIS_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
|
||||
set(ZYDIS_BUILD_TOOLS OFF CACHE BOOL "" FORCE)
|
||||
set(ZYDIS_BUILD_TESTS OFF CACHE BOOL "" FORCE)
|
||||
set(ZYDIS_BUILD_DOXYGEN OFF CACHE BOOL "" FORCE)
|
||||
FetchContent_Declare(
|
||||
zydis
|
||||
GIT_REPOSITORY https://github.com/zyantific/zydis.git
|
||||
GIT_TAG 120e0e705f8e3b507dc49377ac2879979f0d545c
|
||||
GIT_SUBMODULES_RECURSE TRUE
|
||||
GIT_SHALLOW FALSE
|
||||
)
|
||||
|
||||
FetchContent_MakeAvailable(xbyak zydis)
|
||||
|
||||
set(SDL_SHARED OFF CACHE BOOL "" FORCE)
|
||||
add_subdirectory(SDL2)
|
||||
|
||||
@@ -11,6 +37,25 @@ target_include_directories(Vulkan-Headers INTERFACE
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/Vulkan-Headers/include"
|
||||
)
|
||||
|
||||
add_library(imgui STATIC
|
||||
imgui/imgui.cpp
|
||||
imgui/imgui_draw.cpp
|
||||
imgui/imgui_tables.cpp
|
||||
imgui/imgui_widgets.cpp
|
||||
imgui/backends/imgui_impl_vulkan.cpp
|
||||
)
|
||||
target_include_directories(imgui PUBLIC
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/imgui"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/imgui/backends"
|
||||
)
|
||||
target_compile_definitions(imgui PRIVATE IMGUI_IMPL_VULKAN_NO_PROTOTYPES)
|
||||
target_link_libraries(imgui PUBLIC Vulkan::Headers)
|
||||
if(MSVC)
|
||||
target_compile_options(imgui PRIVATE /W0)
|
||||
else()
|
||||
target_compile_options(imgui PRIVATE -w)
|
||||
endif()
|
||||
|
||||
set(SPIRV_SKIP_TESTS ON CACHE BOOL "" FORCE)
|
||||
set(SPIRV_SKIP_EXECUTABLES ON CACHE BOOL "" FORCE)
|
||||
set(SKIP_SPIRV_TOOLS_INSTALL ON CACHE BOOL "" FORCE)
|
||||
|
||||
+1
Submodule 3rdparty/imgui added at f1cc2ae15e.
Vendored
+1
-1
Submodule 3rdparty/tracy updated: 00c079cec9...05cceee0df.
+62
-19
@@ -4,6 +4,12 @@ if(CMAKE_VERSION VERSION_GREATER_EQUAL 4.0)
|
||||
set(CMAKE_POLICY_VERSION_MINIMUM 3.5 CACHE STRING "Minimum policy version for bundled dependencies")
|
||||
endif()
|
||||
|
||||
get_property(KYTY_GENERATOR_IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
|
||||
if(NOT KYTY_GENERATOR_IS_MULTI_CONFIG AND NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build" FORCE)
|
||||
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS Debug Release RelWithDebInfo MinSizeRel)
|
||||
endif()
|
||||
|
||||
project(Kyty)
|
||||
|
||||
set(KYTY_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src")
|
||||
@@ -28,6 +34,29 @@ include(CTest)
|
||||
|
||||
option(KYTY_ENABLE_CLANG_TIDY "Run clang-tidy checks during builds" OFF)
|
||||
|
||||
set(KYTY_BUILD_ORIGIN "Source" CACHE STRING "Build provenance shown in diagnostics")
|
||||
set_property(CACHE KYTY_BUILD_ORIGIN PROPERTY STRINGS Source Official Fork)
|
||||
if(NOT KYTY_BUILD_ORIGIN STREQUAL "Source" AND NOT KYTY_BUILD_ORIGIN STREQUAL "Official" AND
|
||||
NOT KYTY_BUILD_ORIGIN STREQUAL "Fork")
|
||||
message(FATAL_ERROR "KYTY_BUILD_ORIGIN must be Source, Official, or Fork")
|
||||
endif()
|
||||
|
||||
set(KYTY_RELEASE_TAG "" CACHE STRING "Release tag embedded in official builds")
|
||||
set(KYTY_BUILD_REPOSITORY "" CACHE STRING "GitHub repository embedded in fork builds")
|
||||
set(KYTY_OFFICIAL_BUILD OFF)
|
||||
set(KYTY_FORK_BUILD OFF)
|
||||
if(KYTY_BUILD_ORIGIN STREQUAL "Official")
|
||||
if(KYTY_RELEASE_TAG STREQUAL "")
|
||||
message(FATAL_ERROR "Official builds require KYTY_RELEASE_TAG")
|
||||
endif()
|
||||
set(KYTY_OFFICIAL_BUILD ON)
|
||||
elseif(KYTY_BUILD_ORIGIN STREQUAL "Fork")
|
||||
if(KYTY_BUILD_REPOSITORY STREQUAL "")
|
||||
message(FATAL_ERROR "Fork builds require KYTY_BUILD_REPOSITORY")
|
||||
endif()
|
||||
set(KYTY_FORK_BUILD ON)
|
||||
endif()
|
||||
|
||||
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
|
||||
|
||||
include(TestBigEndian)
|
||||
@@ -117,16 +146,20 @@ configure_file(
|
||||
|
||||
find_package(Git)
|
||||
|
||||
add_custom_target( KytyGitVersion
|
||||
COMMAND ${CMAKE_COMMAND}
|
||||
-D INPUT_FILE=${KYTY_SOURCE_DIR}/kytyGitVersion.h.in
|
||||
-D OUTPUT_FILE=${PROJECT_BINARY_DIR}/kytyGitVersion.h
|
||||
-D GIT_EXECUTABLE=${GIT_EXECUTABLE}
|
||||
-D GIT_WORKING_DIRECTORY=${CMAKE_CURRENT_SOURCE_DIR}
|
||||
-P ${KYTY_SOURCE_DIR}/generate_version.cmake
|
||||
add_custom_target(KytyGitVersion
|
||||
COMMAND ${CMAKE_COMMAND}
|
||||
-D INPUT_FILE=${KYTY_SOURCE_DIR}/kytyGitVersion.h.in
|
||||
-D OUTPUT_FILE=${PROJECT_BINARY_DIR}/kytyGitVersion.h
|
||||
-D GIT_EXECUTABLE=${GIT_EXECUTABLE}
|
||||
-D GIT_WORKING_DIRECTORY=${CMAKE_CURRENT_SOURCE_DIR}
|
||||
-P ${KYTY_SOURCE_DIR}/generate_version.cmake
|
||||
BYPRODUCTS ${PROJECT_BINARY_DIR}/kytyGitVersion.h
|
||||
COMMENT "Generate kytyGitVersion.h"
|
||||
)
|
||||
|
||||
add_library(kyty_git_version INTERFACE)
|
||||
add_dependencies(kyty_git_version KytyGitVersion)
|
||||
|
||||
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 12.0.0)
|
||||
list(APPEND KYTY_IWYU
|
||||
kyty_emulator
|
||||
@@ -259,7 +292,7 @@ if (KYTY_CLANG_CL)
|
||||
set_source_files_properties(${kyty_emulator_src} PROPERTIES COMPILE_FLAGS "-Wno-pragma-pack -Wno-deprecated-declarations -D_TIMESPEC_DEFINED")
|
||||
endif()
|
||||
|
||||
set(kyty_emulator_link_libraries common Vulkan::Headers spirv-tools-opt spirv-tools SDL2-static xxhash FFmpeg::ffmpeg fmt::fmt nlohmann_json::nlohmann_json LibAtrac9)
|
||||
set(kyty_emulator_link_libraries common Vulkan::Headers spirv-tools-opt spirv-tools SDL2-static imgui xxhash FFmpeg::ffmpeg fmt::fmt nlohmann_json::nlohmann_json LibAtrac9 kyty_git_version Zydis::Zydis xbyak::xbyak)
|
||||
|
||||
# Linux system libraries required by the static FFmpeg archive.
|
||||
if(LINUX)
|
||||
@@ -352,6 +385,12 @@ add_executable(bit_array_tests EXCLUDE_FROM_ALL
|
||||
)
|
||||
target_include_directories(bit_array_tests PRIVATE ${inc_headers})
|
||||
|
||||
add_executable(ime_dialog_tests EXCLUDE_FROM_ALL
|
||||
"${KYTY_TESTS_DIR}/ImeDialogTests.cpp"
|
||||
"${KYTY_SOURCE_DIR}/libs/imeDialog.cpp"
|
||||
)
|
||||
target_include_directories(ime_dialog_tests PRIVATE ${inc_headers})
|
||||
|
||||
add_executable(memory_tracker_tests EXCLUDE_FROM_ALL
|
||||
"${KYTY_TESTS_DIR}/MemoryTrackerTests.cpp"
|
||||
"${KYTY_SOURCE_DIR}/graphics/host_gpu/pageManager.cpp"
|
||||
@@ -394,13 +433,6 @@ add_executable(resource_tracking_tests EXCLUDE_FROM_ALL
|
||||
target_link_libraries(resource_tracking_tests fmt::fmt)
|
||||
target_include_directories(resource_tracking_tests PRIVATE ${inc_headers})
|
||||
|
||||
add_executable(resource_mutex_tests EXCLUDE_FROM_ALL
|
||||
"${KYTY_TESTS_DIR}/ResourceMutexTests.cpp"
|
||||
"${KYTY_SOURCE_DIR}/graphics/host_gpu/renderer/cache/resourceMutex.cpp"
|
||||
)
|
||||
target_link_libraries(resource_mutex_tests common)
|
||||
target_include_directories(resource_mutex_tests PRIVATE ${inc_headers})
|
||||
|
||||
add_executable(audio_out2_port_tests EXCLUDE_FROM_ALL
|
||||
"${KYTY_TESTS_DIR}/AudioOut2PortTests.cpp"
|
||||
"${KYTY_SOURCE_DIR}/libs/libAudio2.cpp"
|
||||
@@ -417,6 +449,13 @@ add_executable(event_queue_lifetime_tests EXCLUDE_FROM_ALL
|
||||
target_link_libraries(event_queue_lifetime_tests common fmt::fmt)
|
||||
target_include_directories(event_queue_lifetime_tests PRIVATE ${inc_headers})
|
||||
|
||||
add_executable(sync_on_address_tests EXCLUDE_FROM_ALL
|
||||
"${KYTY_TESTS_DIR}/SyncOnAddressTests.cpp"
|
||||
"${KYTY_SOURCE_DIR}/kernel/syncOnAddress.cpp"
|
||||
)
|
||||
target_link_libraries(sync_on_address_tests common)
|
||||
target_include_directories(sync_on_address_tests PRIVATE ${inc_headers})
|
||||
|
||||
add_executable(image_page_table_tests EXCLUDE_FROM_ALL
|
||||
"${KYTY_TESTS_DIR}/ImagePageTableTests.cpp"
|
||||
)
|
||||
@@ -459,6 +498,7 @@ if(NOT KYTY_CLANG_CL)
|
||||
endif()
|
||||
|
||||
if(BUILD_TESTING)
|
||||
add_test(NAME ime_dialog COMMAND $<TARGET_FILE:ime_dialog_tests>)
|
||||
add_test(NAME shader_cfg COMMAND $<TARGET_FILE:shader_cfg_tests>)
|
||||
add_test(NAME scalar_provenance COMMAND $<TARGET_FILE:scalar_provenance_tests>)
|
||||
add_test(NAME image_page_table COMMAND $<TARGET_FILE:image_page_table_tests>)
|
||||
@@ -468,18 +508,22 @@ if(BUILD_TESTING)
|
||||
add_test(NAME shader_vertex_metadata COMMAND $<TARGET_FILE:shader_vertex_metadata_tests>)
|
||||
add_test(NAME shader_stage_runtime COMMAND $<TARGET_FILE:shader_stage_runtime_tests>)
|
||||
add_test(NAME resource_tracking COMMAND $<TARGET_FILE:resource_tracking_tests>)
|
||||
add_test(NAME resource_mutex COMMAND $<TARGET_FILE:resource_mutex_tests>)
|
||||
add_test(NAME event_queue_lifetime COMMAND $<TARGET_FILE:event_queue_lifetime_tests>)
|
||||
add_test(NAME sync_on_address COMMAND $<TARGET_FILE:sync_on_address_tests>)
|
||||
add_test(NAME audio_out2_port COMMAND $<TARGET_FILE:audio_out2_port_tests>)
|
||||
add_test(NAME shader_recompiler_compute COMMAND $<TARGET_FILE:shader_recompiler_compute_tests>)
|
||||
add_test(NAME virtual_memory_allocation
|
||||
COMMAND $<TARGET_FILE:virtual_memory_allocation_tests>)
|
||||
add_test(NAME guest_red_zone_patcher
|
||||
COMMAND $<TARGET_FILE:virtual_memory_allocation_tests> --red-zone-patcher-only)
|
||||
add_test(NAME command_scheduler_timeline
|
||||
COMMAND $<TARGET_FILE:shader_recompiler_compute_tests> --scheduler-only)
|
||||
add_test(NAME stream_buffer_ring
|
||||
COMMAND $<TARGET_FILE:shader_recompiler_compute_tests> --stream-buffer-only)
|
||||
add_test(NAME gpu_command_lane
|
||||
COMMAND $<TARGET_FILE:shader_recompiler_compute_tests> --gpu-command-lane-only)
|
||||
add_test(NAME pm4_context_state
|
||||
COMMAND $<TARGET_FILE:shader_recompiler_compute_tests> --context-state-only)
|
||||
add_test(NAME gpu_tiler
|
||||
COMMAND $<TARGET_FILE:shader_recompiler_compute_tests> --gpu-tiler-only)
|
||||
|
||||
@@ -505,6 +549,7 @@ if(BUILD_TESTING)
|
||||
endif()
|
||||
|
||||
add_custom_target(kyty_tests DEPENDS
|
||||
ime_dialog_tests
|
||||
shader_cfg_tests
|
||||
scalar_provenance_tests
|
||||
image_page_table_tests
|
||||
@@ -514,8 +559,8 @@ if(BUILD_TESTING)
|
||||
shader_vertex_metadata_tests
|
||||
shader_stage_runtime_tests
|
||||
resource_tracking_tests
|
||||
resource_mutex_tests
|
||||
event_queue_lifetime_tests
|
||||
sync_on_address_tests
|
||||
shader_recompiler_compute_tests
|
||||
virtual_memory_allocation_tests
|
||||
)
|
||||
@@ -563,8 +608,6 @@ elseif(WIN32 OR LINUX)
|
||||
set_target_properties(kyty_emulator PROPERTIES LINK_FLAGS "${KYTY_LD_OPTIONS} -Wl,-Map=${KYTY_EMULATOR_MAP_LINK_PATH}")
|
||||
endif()
|
||||
|
||||
add_dependencies(kyty_emulator KytyGitVersion)
|
||||
|
||||
if(APPLE)
|
||||
# The emulator writes x86-64 trampolines/PLT stubs into memory and executes them, and
|
||||
# runs guest code under Rosetta. That requires the JIT / unsigned-executable-memory
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
#define KYTY_VERSION "@KYTY_VERSION@"
|
||||
#define KYTY_BUILD_REPOSITORY "@KYTY_BUILD_REPOSITORY@"
|
||||
#define KYTY_RELEASE_TAG "@KYTY_RELEASE_TAG@"
|
||||
#cmakedefine KYTY_OFFICIAL_BUILD
|
||||
#cmakedefine KYTY_FORK_BUILD
|
||||
#define KYTY_ENDIAN @KYTY_ENDIAN@
|
||||
#define KYTY_PLATFORM @KYTY_PLATFORM@
|
||||
#define KYTY_COMPILER KYTY_COMPILER_@KYTY_COMPILER@
|
||||
|
||||
@@ -33,6 +33,10 @@ uint32_t GetScreenHeight() {
|
||||
return g_config->screen_height;
|
||||
}
|
||||
|
||||
bool FullscreenEnabled() {
|
||||
return g_config->fullscreen_enabled;
|
||||
}
|
||||
|
||||
uint32_t GetVblankFrequency() {
|
||||
return std::clamp(g_config->vblank_frequency, 30u, 360u);
|
||||
}
|
||||
@@ -97,4 +101,14 @@ bool ReadbackLinearImagesEnabled() {
|
||||
return g_config->readback_linear_images;
|
||||
}
|
||||
|
||||
#if KYTY_PLATFORM == KYTY_PLATFORM_WINDOWS
|
||||
bool RedZoneProtectionEnabled() {
|
||||
return g_config->red_zone_protection_enabled;
|
||||
}
|
||||
#endif
|
||||
|
||||
const Keymap& GetKeymap() {
|
||||
return g_config->keymap;
|
||||
}
|
||||
|
||||
} // namespace Config
|
||||
@@ -5,6 +5,8 @@
|
||||
#include "common/subsystems.h"
|
||||
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace Config {
|
||||
|
||||
@@ -18,12 +20,15 @@ enum class ProfilerDirection { None, Network };
|
||||
|
||||
enum class OutputDirection { Silent, Console, File };
|
||||
|
||||
using Keymap = std::vector<std::string>;
|
||||
|
||||
constexpr uint32_t DEFAULT_CONSOLE_LANGUAGE = 1;
|
||||
constexpr uint32_t MAX_CONSOLE_LANGUAGE = 29;
|
||||
|
||||
struct ConfigOptions {
|
||||
uint32_t screen_width = 1280;
|
||||
uint32_t screen_height = 720;
|
||||
bool fullscreen_enabled = false;
|
||||
uint32_t vblank_frequency = 60;
|
||||
uint32_t console_language = DEFAULT_CONSOLE_LANGUAGE;
|
||||
bool vulkan_validation_enabled = false;
|
||||
@@ -40,12 +45,17 @@ struct ConfigOptions {
|
||||
bool spirv_debug_printf_enabled = false;
|
||||
bool renderdoc_enabled = false;
|
||||
bool readback_linear_images = false;
|
||||
#if KYTY_PLATFORM == KYTY_PLATFORM_WINDOWS
|
||||
bool red_zone_protection_enabled = false;
|
||||
#endif
|
||||
Keymap keymap;
|
||||
};
|
||||
|
||||
void Load(const ConfigOptions& cfg);
|
||||
|
||||
uint32_t GetScreenWidth();
|
||||
uint32_t GetScreenHeight();
|
||||
bool FullscreenEnabled();
|
||||
uint32_t GetVblankFrequency();
|
||||
uint32_t GetConsoleLanguage();
|
||||
bool VulkanValidationEnabled();
|
||||
@@ -69,6 +79,11 @@ bool SpirvDebugPrintfEnabled();
|
||||
|
||||
bool RenderDocEnabled();
|
||||
bool ReadbackLinearImagesEnabled();
|
||||
#if KYTY_PLATFORM == KYTY_PLATFORM_WINDOWS
|
||||
bool RedZoneProtectionEnabled();
|
||||
#endif
|
||||
|
||||
const Keymap& GetKeymap();
|
||||
|
||||
} // namespace Config
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
set(KYTY_GIT_VERSION "unknown")
|
||||
set(KYTY_GIT_HASH "unknown")
|
||||
if(GIT_EXECUTABLE)
|
||||
execute_process(
|
||||
COMMAND "${GIT_EXECUTABLE}" describe --tags --always
|
||||
COMMAND "${GIT_EXECUTABLE}" describe --tags --always --dirty
|
||||
WORKING_DIRECTORY "${GIT_WORKING_DIRECTORY}"
|
||||
OUTPUT_VARIABLE KYTY_GIT_VERSION
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
@@ -11,5 +12,27 @@ if(GIT_EXECUTABLE)
|
||||
if(NOT GIT_RESULT EQUAL 0)
|
||||
set(KYTY_GIT_VERSION "unknown")
|
||||
endif()
|
||||
|
||||
execute_process(
|
||||
COMMAND "${GIT_EXECUTABLE}" rev-parse --short=7 HEAD
|
||||
WORKING_DIRECTORY "${GIT_WORKING_DIRECTORY}"
|
||||
OUTPUT_VARIABLE KYTY_GIT_HASH
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
RESULT_VARIABLE GIT_HASH_RESULT
|
||||
ERROR_QUIET
|
||||
)
|
||||
if(NOT GIT_HASH_RESULT EQUAL 0)
|
||||
set(KYTY_GIT_HASH "unknown")
|
||||
else()
|
||||
execute_process(
|
||||
COMMAND "${GIT_EXECUTABLE}" diff-index --quiet HEAD --
|
||||
WORKING_DIRECTORY "${GIT_WORKING_DIRECTORY}"
|
||||
RESULT_VARIABLE GIT_DIRTY_RESULT
|
||||
ERROR_QUIET
|
||||
)
|
||||
if(NOT GIT_DIRTY_RESULT EQUAL 0)
|
||||
string(APPEND KYTY_GIT_HASH "-dirty")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
configure_file("${INPUT_FILE}" "${OUTPUT_FILE}")
|
||||
@@ -15,6 +15,13 @@ bool TestWaitRegMemValue(uint64_t value, uint64_t ref, uint64_t mask, uint32_t f
|
||||
|
||||
enum class Pm4ProcessResult { Complete, Blocked };
|
||||
|
||||
enum class ContextStateOperation : uint32_t {
|
||||
Clear = 0,
|
||||
Push = 1,
|
||||
Pop = 2,
|
||||
PushClear = 3,
|
||||
};
|
||||
|
||||
class Pm4Execution {
|
||||
public:
|
||||
[[nodiscard]] bool MadeProgress() const noexcept { return m_made_progress; }
|
||||
@@ -49,24 +56,12 @@ public:
|
||||
KYTY_CLASS_NO_COPY(CommandProcessor);
|
||||
|
||||
void Reset();
|
||||
void ApplyContextStateOperation(ContextStateOperation operation);
|
||||
|
||||
void BufferInit();
|
||||
void BufferFlush();
|
||||
void BufferFlushAndWait();
|
||||
void BufferWait();
|
||||
void BeginReadbackTransaction() {
|
||||
if (m_readback_active) {
|
||||
EXIT("nested command-processor readback transaction\n");
|
||||
}
|
||||
m_readback_active = true;
|
||||
}
|
||||
void EndReadbackTransaction() {
|
||||
if (!m_readback_active) {
|
||||
EXIT("command-processor readback transaction is not active\n");
|
||||
}
|
||||
m_readback_active = false;
|
||||
}
|
||||
|
||||
void BufferInit();
|
||||
void BufferFlush();
|
||||
void BufferFlushAndWait();
|
||||
void BufferWait();
|
||||
HW::Context& GetCtx() { return m_ctx; }
|
||||
HW::UserConfig& GetUcfg() { return m_ucfg; }
|
||||
HW::Shader& GetShCtx() { return m_sh_ctx; }
|
||||
@@ -162,6 +157,8 @@ private:
|
||||
|
||||
RenderContext& m_renderer;
|
||||
HW::Context m_ctx;
|
||||
HW::Context m_saved_ctx;
|
||||
bool m_context_state_pushed = false;
|
||||
HW::UserConfig m_ucfg;
|
||||
HW::Shader m_sh_ctx;
|
||||
HW::UserSgprType m_user_data_marker = HW::UserSgprType::Unknown;
|
||||
@@ -173,10 +170,9 @@ private:
|
||||
// Persistent draw state: indirect draws update it for subsequent draws.
|
||||
uint32_t m_num_instances = 1;
|
||||
|
||||
uint32_t m_de_count = 0;
|
||||
uint32_t m_ce_count = 0;
|
||||
bool m_ce_complete = false;
|
||||
bool m_readback_active = false;
|
||||
uint32_t m_de_count = 0;
|
||||
uint32_t m_ce_count = 0;
|
||||
bool m_ce_complete = false;
|
||||
|
||||
uint32_t m_const_ram[0x3000] = {0};
|
||||
|
||||
|
||||
@@ -254,6 +254,7 @@ constexpr auto MakeCustomOpcodeDispatchTable() {
|
||||
g_cp_op_custom_func[Pm4::R_WAIT_MEM_64] = CpOpWaitRegMem64;
|
||||
g_cp_op_custom_func[Pm4::R_FLIP] = CpOpFlip;
|
||||
g_cp_op_custom_func[Pm4::R_RELEASE_MEM] = CpOpReleaseMem;
|
||||
g_cp_op_custom_func[Pm4::R_CONTEXT_STATE] = CpOpContextState;
|
||||
|
||||
return g_cp_op_custom_func;
|
||||
}
|
||||
|
||||
@@ -121,6 +121,7 @@ uint32_t HwUcSetGeIndexOffset(CommandProcessor&, uint32_t, uint32_t, const uint3
|
||||
uint32_t HwUcSetGdsOaRegisters(CommandProcessor&, uint32_t, uint32_t, const uint32_t*, uint32_t);
|
||||
|
||||
uint32_t CpOpNop(CommandProcessor&, uint32_t, const uint32_t*, uint32_t, uint32_t);
|
||||
uint32_t CpOpContextState(CommandProcessor&, uint32_t, const uint32_t*, uint32_t, uint32_t);
|
||||
uint32_t CpOpSetBase(CommandProcessor&, uint32_t, const uint32_t*, uint32_t, uint32_t);
|
||||
uint32_t CpOpClearState(CommandProcessor&, uint32_t, const uint32_t*, uint32_t, uint32_t);
|
||||
uint32_t CpOpIndexBase(CommandProcessor&, uint32_t, const uint32_t*, uint32_t, uint32_t);
|
||||
|
||||
@@ -18,7 +18,9 @@
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <atomic>
|
||||
#include <bit>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
|
||||
#define KYTY_HW_CTX_PARSER_ARGS \
|
||||
@@ -895,23 +897,44 @@ KYTY_HW_CTX_PARSER(HwCtxSetModeControl) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void HwCtxIgnorePolyOffsetRegister(uint32_t cmd_offset, uint32_t value) {
|
||||
static std::atomic<uint32_t> log_count = 0;
|
||||
static void HwCtxSetPolyOffsetRegister(CommandProcessor& cp, uint32_t cmd_offset, uint32_t value) {
|
||||
HW::PolyOffset offset = cp.GetCtx().GetPolyOffset();
|
||||
|
||||
auto count = log_count.fetch_add(1);
|
||||
if (count < 8) {
|
||||
LOGF_COLOR(Log::Color::Red,
|
||||
"\t temporary: ignoring polygon offset context register 0x%03" PRIx32
|
||||
" = 0x%08" PRIx32 " (depth bias not implemented)\n",
|
||||
cmd_offset, value);
|
||||
switch (cmd_offset) {
|
||||
case Pm4::PA_SU_POLY_OFFSET_DB_FMT_CNTL: {
|
||||
const auto neg_bits =
|
||||
KYTY_PM4_GET(value, PA_SU_POLY_OFFSET_DB_FMT_CNTL, NEG_NUM_DB_BITS);
|
||||
offset.neg_num_db_bits = std::bit_cast<int8_t>(static_cast<uint8_t>(neg_bits));
|
||||
offset.db_is_float_fmt =
|
||||
KYTY_PM4_GET(value, PA_SU_POLY_OFFSET_DB_FMT_CNTL, DB_IS_FLOAT_FMT) != 0;
|
||||
break;
|
||||
}
|
||||
case Pm4::PA_SU_POLY_OFFSET_CLAMP: offset.clamp = std::bit_cast<float>(value); break;
|
||||
case Pm4::PA_SU_POLY_OFFSET_FRONT_SCALE:
|
||||
offset.front_scale = std::bit_cast<float>(value);
|
||||
break;
|
||||
case Pm4::PA_SU_POLY_OFFSET_FRONT_OFFSET:
|
||||
offset.front_offset = std::bit_cast<float>(value);
|
||||
break;
|
||||
case Pm4::PA_SU_POLY_OFFSET_BACK_SCALE:
|
||||
offset.back_scale = std::bit_cast<float>(value);
|
||||
break;
|
||||
case Pm4::PA_SU_POLY_OFFSET_BACK_OFFSET:
|
||||
offset.back_offset = std::bit_cast<float>(value);
|
||||
break;
|
||||
default:
|
||||
EXIT("unknown polygon offset context register 0x%03" PRIx32 " = 0x%08" PRIx32 "\n",
|
||||
cmd_offset, value);
|
||||
}
|
||||
|
||||
cp.GetCtx().SetPolyOffset(offset);
|
||||
}
|
||||
|
||||
KYTY_HW_CTX_PARSER(HwCtxSetPolyOffsetRegisters) {
|
||||
auto num_values = KYTY_PM4_LEN(cmd_id) - 2u;
|
||||
|
||||
for (uint32_t i = 0; i < num_values; i++) {
|
||||
HwCtxIgnorePolyOffsetRegister(cmd_offset + i, buffer[i]);
|
||||
HwCtxSetPolyOffsetRegister(cp, cmd_offset + i, buffer[i]);
|
||||
}
|
||||
|
||||
return num_values;
|
||||
@@ -1312,26 +1335,36 @@ static void HwShSetCsRegister(CommandProcessor& cp, uint32_t cmd_offset, uint32_
|
||||
(value >> Pm4::COMPUTE_PGM_RSRC1_VGPRS_SHIFT) & Pm4::COMPUTE_PGM_RSRC1_VGPRS_MASK;
|
||||
cs_regs.sgprs =
|
||||
(value >> Pm4::COMPUTE_PGM_RSRC1_SGPRS_SHIFT) & Pm4::COMPUTE_PGM_RSRC1_SGPRS_MASK;
|
||||
cs_regs.bulky =
|
||||
(value >> Pm4::COMPUTE_PGM_RSRC1_BULKY_SHIFT) & Pm4::COMPUTE_PGM_RSRC1_BULKY_MASK;
|
||||
cs_regs.wave_size = (((value >> Pm4::COMPUTE_PGM_RSRC1_W32_EN_SHIFT) &
|
||||
Pm4::COMPUTE_PGM_RSRC1_W32_EN_MASK) != 0u)
|
||||
? 32u
|
||||
: 64u;
|
||||
cs_regs.float_mode = (value >> Pm4::COMPUTE_PGM_RSRC1_FLOAT_MODE_SHIFT) &
|
||||
Pm4::COMPUTE_PGM_RSRC1_FLOAT_MODE_MASK;
|
||||
cs_regs.dx10_clamp = ((value >> Pm4::COMPUTE_PGM_RSRC1_DX10_CLAMP_SHIFT) &
|
||||
Pm4::COMPUTE_PGM_RSRC1_DX10_CLAMP_MASK) != 0u;
|
||||
cs_regs.ieee_mode = ((value >> Pm4::COMPUTE_PGM_RSRC1_IEEE_MODE_SHIFT) &
|
||||
Pm4::COMPUTE_PGM_RSRC1_IEEE_MODE_MASK) != 0u;
|
||||
cs_regs.fp16_overflow = ((value >> Pm4::COMPUTE_PGM_RSRC1_FP16_OVFL_SHIFT) &
|
||||
Pm4::COMPUTE_PGM_RSRC1_FP16_OVFL_MASK) != 0u;
|
||||
cs_regs.bulky = ((value >> Pm4::COMPUTE_PGM_RSRC1_BULKY_SHIFT) &
|
||||
Pm4::COMPUTE_PGM_RSRC1_BULKY_MASK) != 0u;
|
||||
cs_regs.threadgroup_configuration = ((value >> Pm4::COMPUTE_PGM_RSRC1_WGP_MODE_SHIFT) &
|
||||
Pm4::COMPUTE_PGM_RSRC1_WGP_MODE_MASK) != 0u;
|
||||
cs_regs.wave_size = (((value >> Pm4::COMPUTE_PGM_RSRC1_W32_EN_SHIFT) &
|
||||
Pm4::COMPUTE_PGM_RSRC1_W32_EN_MASK) != 0u)
|
||||
? 32u
|
||||
: 64u;
|
||||
break;
|
||||
case Pm4::COMPUTE_PGM_RSRC2:
|
||||
cs_regs.scratch_en = (value >> Pm4::COMPUTE_PGM_RSRC2_SCRATCH_EN_SHIFT) &
|
||||
Pm4::COMPUTE_PGM_RSRC2_SCRATCH_EN_MASK;
|
||||
cs_regs.scratch_en = ((value >> Pm4::COMPUTE_PGM_RSRC2_SCRATCH_EN_SHIFT) &
|
||||
Pm4::COMPUTE_PGM_RSRC2_SCRATCH_EN_MASK) != 0u;
|
||||
cs_regs.user_sgpr = (value >> Pm4::COMPUTE_PGM_RSRC2_USER_SGPR_SHIFT) &
|
||||
Pm4::COMPUTE_PGM_RSRC2_USER_SGPR_MASK;
|
||||
cs_regs.tgid_x_en = (value >> Pm4::COMPUTE_PGM_RSRC2_TGID_X_EN_SHIFT) &
|
||||
Pm4::COMPUTE_PGM_RSRC2_TGID_X_EN_MASK;
|
||||
cs_regs.tgid_y_en = (value >> Pm4::COMPUTE_PGM_RSRC2_TGID_Y_EN_SHIFT) &
|
||||
Pm4::COMPUTE_PGM_RSRC2_TGID_Y_EN_MASK;
|
||||
cs_regs.tgid_z_en = (value >> Pm4::COMPUTE_PGM_RSRC2_TGID_Z_EN_SHIFT) &
|
||||
Pm4::COMPUTE_PGM_RSRC2_TGID_Z_EN_MASK;
|
||||
cs_regs.tg_size_en = (value >> Pm4::COMPUTE_PGM_RSRC2_TG_SIZE_EN_SHIFT) &
|
||||
Pm4::COMPUTE_PGM_RSRC2_TG_SIZE_EN_MASK;
|
||||
cs_regs.tgid_x_en = ((value >> Pm4::COMPUTE_PGM_RSRC2_TGID_X_EN_SHIFT) &
|
||||
Pm4::COMPUTE_PGM_RSRC2_TGID_X_EN_MASK) != 0u;
|
||||
cs_regs.tgid_y_en = ((value >> Pm4::COMPUTE_PGM_RSRC2_TGID_Y_EN_SHIFT) &
|
||||
Pm4::COMPUTE_PGM_RSRC2_TGID_Y_EN_MASK) != 0u;
|
||||
cs_regs.tgid_z_en = ((value >> Pm4::COMPUTE_PGM_RSRC2_TGID_Z_EN_SHIFT) &
|
||||
Pm4::COMPUTE_PGM_RSRC2_TGID_Z_EN_MASK) != 0u;
|
||||
cs_regs.tg_size_en = ((value >> Pm4::COMPUTE_PGM_RSRC2_TG_SIZE_EN_SHIFT) &
|
||||
Pm4::COMPUTE_PGM_RSRC2_TG_SIZE_EN_MASK) != 0u;
|
||||
cs_regs.tidig_comp_cnt = (value >> Pm4::COMPUTE_PGM_RSRC2_TIDIG_COMP_CNT_SHIFT) &
|
||||
Pm4::COMPUTE_PGM_RSRC2_TIDIG_COMP_CNT_MASK;
|
||||
cs_regs.lds_size = (value >> Pm4::COMPUTE_PGM_RSRC2_LDS_SIZE_SHIFT) &
|
||||
@@ -2102,11 +2135,24 @@ KYTY_CP_OP_PARSER(CpOpClearState) {
|
||||
EXIT_NOT_IMPLEMENTED(cmd_id != 0xc0001200);
|
||||
EXIT_NOT_IMPLEMENTED((buffer[0] & ~0xfu) != 0);
|
||||
|
||||
cp.Reset();
|
||||
cp.ApplyContextStateOperation(ContextStateOperation::Clear);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
KYTY_CP_OP_PARSER(CpOpContextState) {
|
||||
KYTY_PROFILER_FUNCTION();
|
||||
|
||||
const auto packet_size_dw = KYTY_PM4_LEN(cmd_id);
|
||||
EXIT_NOT_IMPLEMENTED(KYTY_PM4_R(cmd_id) != Pm4::R_CONTEXT_STATE);
|
||||
EXIT_NOT_IMPLEMENTED(packet_size_dw != 3u && packet_size_dw != 5u);
|
||||
EXIT_NOT_IMPLEMENTED(buffer[0] > static_cast<uint32_t>(ContextStateOperation::PushClear));
|
||||
|
||||
cp.ApplyContextStateOperation(static_cast<ContextStateOperation>(buffer[0]));
|
||||
|
||||
return packet_size_dw - 1u;
|
||||
}
|
||||
|
||||
KYTY_CP_OP_PARSER(CpOpDumpConstRam) {
|
||||
KYTY_PROFILER_FUNCTION();
|
||||
|
||||
@@ -3682,22 +3728,22 @@ void GraphicsInitJmpTablesCxIndirect() {
|
||||
};
|
||||
|
||||
g_hw_ctx_indirect_func[Pm4::PA_SU_POLY_OFFSET_DB_FMT_CNTL] = [](KYTY_HW_CTX_INDIRECT_ARGS) {
|
||||
HwCtxIgnorePolyOffsetRegister(cmd_offset, value);
|
||||
HwCtxSetPolyOffsetRegister(cp, cmd_offset, value);
|
||||
};
|
||||
g_hw_ctx_indirect_func[Pm4::PA_SU_POLY_OFFSET_CLAMP] = [](KYTY_HW_CTX_INDIRECT_ARGS) {
|
||||
HwCtxIgnorePolyOffsetRegister(cmd_offset, value);
|
||||
HwCtxSetPolyOffsetRegister(cp, cmd_offset, value);
|
||||
};
|
||||
g_hw_ctx_indirect_func[Pm4::PA_SU_POLY_OFFSET_FRONT_SCALE] = [](KYTY_HW_CTX_INDIRECT_ARGS) {
|
||||
HwCtxIgnorePolyOffsetRegister(cmd_offset, value);
|
||||
HwCtxSetPolyOffsetRegister(cp, cmd_offset, value);
|
||||
};
|
||||
g_hw_ctx_indirect_func[Pm4::PA_SU_POLY_OFFSET_FRONT_OFFSET] = [](KYTY_HW_CTX_INDIRECT_ARGS) {
|
||||
HwCtxIgnorePolyOffsetRegister(cmd_offset, value);
|
||||
HwCtxSetPolyOffsetRegister(cp, cmd_offset, value);
|
||||
};
|
||||
g_hw_ctx_indirect_func[Pm4::PA_SU_POLY_OFFSET_BACK_SCALE] = [](KYTY_HW_CTX_INDIRECT_ARGS) {
|
||||
HwCtxIgnorePolyOffsetRegister(cmd_offset, value);
|
||||
HwCtxSetPolyOffsetRegister(cp, cmd_offset, value);
|
||||
};
|
||||
g_hw_ctx_indirect_func[Pm4::PA_SU_POLY_OFFSET_BACK_OFFSET] = [](KYTY_HW_CTX_INDIRECT_ARGS) {
|
||||
HwCtxIgnorePolyOffsetRegister(cmd_offset, value);
|
||||
HwCtxSetPolyOffsetRegister(cp, cmd_offset, value);
|
||||
};
|
||||
|
||||
g_hw_ctx_indirect_func[Pm4::DB_Z_INFO] = [](KYTY_HW_CTX_INDIRECT_ARGS) {
|
||||
@@ -4220,29 +4266,28 @@ void GraphicsInitJmpTablesShIndirect() {
|
||||
};
|
||||
|
||||
g_hw_sh_indirect_func[Pm4::SPI_SHADER_PGM_RSRC1_HS] = [](KYTY_HW_SH_INDIRECT_ARGS) {
|
||||
HW::VsShaderResource1 r1;
|
||||
r1.vgprs = KYTY_PM4_GET(value, SPI_SHADER_PGM_RSRC1_VS, VGPRS);
|
||||
r1.sgprs = KYTY_PM4_GET(value, SPI_SHADER_PGM_RSRC1_VS, SGPRS);
|
||||
r1.priority = KYTY_PM4_GET(value, SPI_SHADER_PGM_RSRC1_VS, PRIORITY);
|
||||
r1.float_mode = KYTY_PM4_GET(value, SPI_SHADER_PGM_RSRC1_VS, FLOAT_MODE);
|
||||
r1.dx10_clamp = KYTY_PM4_GET(value, SPI_SHADER_PGM_RSRC1_VS, DX10_CLAMP) != 0;
|
||||
r1.ieee_mode = KYTY_PM4_GET(value, SPI_SHADER_PGM_RSRC1_VS, IEEE_MODE) != 0;
|
||||
r1.vgpr_component_count = KYTY_PM4_GET(value, SPI_SHADER_PGM_RSRC1_VS, VGPR_COMP_CNT);
|
||||
r1.cu_group_enable = KYTY_PM4_GET(value, SPI_SHADER_PGM_RSRC1_VS, CU_GROUP_ENABLE) != 0;
|
||||
HW::HsShaderResource1 r1;
|
||||
r1.vgprs = KYTY_PM4_GET(value, SPI_SHADER_PGM_RSRC1_HS, VGPRS);
|
||||
r1.priority = KYTY_PM4_GET(value, SPI_SHADER_PGM_RSRC1_HS, PRIORITY);
|
||||
r1.float_mode = KYTY_PM4_GET(value, SPI_SHADER_PGM_RSRC1_HS, FLOAT_MODE);
|
||||
r1.dx10_clamp = KYTY_PM4_GET(value, SPI_SHADER_PGM_RSRC1_HS, DX10_CLAMP) != 0;
|
||||
r1.debug_mode = KYTY_PM4_GET(value, SPI_SHADER_PGM_RSRC1_HS, DEBUG_MODE) != 0;
|
||||
r1.ieee_mode = KYTY_PM4_GET(value, SPI_SHADER_PGM_RSRC1_HS, IEEE_MODE) != 0;
|
||||
r1.require_forward_progress =
|
||||
KYTY_PM4_GET(value, SPI_SHADER_PGM_RSRC1_VS, FWD_PROGRESS) != 0;
|
||||
r1.fp16_overflow = KYTY_PM4_GET(value, SPI_SHADER_PGM_RSRC1_VS, FP16_OVFL) != 0;
|
||||
KYTY_PM4_GET(value, SPI_SHADER_PGM_RSRC1_HS, FWD_PROGRESS) != 0;
|
||||
r1.threadgroup_configuration = KYTY_PM4_GET(value, SPI_SHADER_PGM_RSRC1_HS, WGP_MODE) != 0;
|
||||
r1.ls_vgpr_component_count = KYTY_PM4_GET(value, SPI_SHADER_PGM_RSRC1_HS, LS_VGPR_COMP_CNT);
|
||||
r1.fp16_overflow = KYTY_PM4_GET(value, SPI_SHADER_PGM_RSRC1_HS, FP16_OVFL) != 0;
|
||||
cp.GetShCtx().SetHsShaderResource1(r1);
|
||||
};
|
||||
|
||||
g_hw_sh_indirect_func[Pm4::SPI_SHADER_PGM_RSRC2_HS] = [](KYTY_HW_SH_INDIRECT_ARGS) {
|
||||
HW::VsShaderResource2 r2;
|
||||
r2.scratch_en = KYTY_PM4_GET(value, SPI_SHADER_PGM_RSRC2_VS, SCRATCH_EN) != 0;
|
||||
r2.user_sgpr = KYTY_PM4_GET(value, SPI_SHADER_PGM_RSRC2_VS, USER_SGPR) +
|
||||
(KYTY_PM4_GET(value, SPI_SHADER_PGM_RSRC2_VS, USER_SGPR_MSB) << 5u);
|
||||
r2.offchip_lds = KYTY_PM4_GET(value, SPI_SHADER_PGM_RSRC2_VS, OC_LDS_EN) != 0;
|
||||
r2.streamout_enabled = KYTY_PM4_GET(value, SPI_SHADER_PGM_RSRC2_VS, SO_EN) != 0;
|
||||
r2.shared_vgprs = KYTY_PM4_GET(value, SPI_SHADER_PGM_RSRC2_VS, SHARED_VGPR_CNT);
|
||||
HW::HsShaderResource2 r2;
|
||||
r2.scratch_en = KYTY_PM4_GET(value, SPI_SHADER_PGM_RSRC2_HS, SCRATCH_EN) != 0;
|
||||
r2.user_sgpr = KYTY_PM4_GET(value, SPI_SHADER_PGM_RSRC2_HS, USER_SGPR) +
|
||||
(KYTY_PM4_GET(value, SPI_SHADER_PGM_RSRC2_HS, USER_SGPR_MSB) << 5u);
|
||||
r2.lds_size = KYTY_PM4_GET(value, SPI_SHADER_PGM_RSRC2_HS, LDS_SIZE);
|
||||
r2.shared_vgprs = KYTY_PM4_GET(value, SPI_SHADER_PGM_RSRC2_HS, SHARED_VGPR_CNT);
|
||||
cp.GetShCtx().SetHsShaderResource2(r2);
|
||||
};
|
||||
|
||||
@@ -4330,7 +4375,7 @@ void GraphicsInitJmpTablesShIndirect() {
|
||||
r1.cu_group_enable = KYTY_PM4_GET(value, SPI_SHADER_PGM_RSRC1_GS, CU_GROUP_ENABLE) != 0;
|
||||
r1.require_forward_progress =
|
||||
KYTY_PM4_GET(value, SPI_SHADER_PGM_RSRC1_GS, FWD_PROGRESS) != 0;
|
||||
r1.lds_configuration = KYTY_PM4_GET(value, SPI_SHADER_PGM_RSRC1_GS, WGP_MODE) != 0;
|
||||
r1.threadgroup_configuration = KYTY_PM4_GET(value, SPI_SHADER_PGM_RSRC1_GS, WGP_MODE) != 0;
|
||||
r1.gs_vgpr_component_count = KYTY_PM4_GET(value, SPI_SHADER_PGM_RSRC1_GS, GS_VGPR_COMP_CNT);
|
||||
r1.fp16_overflow = KYTY_PM4_GET(value, SPI_SHADER_PGM_RSRC1_GS, FP16_OVFL) != 0;
|
||||
cp.GetShCtx().SetGsShaderResource1(r1);
|
||||
@@ -4390,7 +4435,7 @@ void GraphicsInitJmpTablesShIndirect() {
|
||||
r2.wave_cnt_en = KYTY_PM4_GET(value, SPI_SHADER_PGM_RSRC2_PS, WAVE_CNT_EN);
|
||||
r2.extra_lds_size = KYTY_PM4_GET(value, SPI_SHADER_PGM_RSRC2_PS, EXTRA_LDS_SIZE);
|
||||
r2.raster_ordered_shading =
|
||||
KYTY_PM4_GET(value, SPI_SHADER_PGM_RSRC2_PS, LOAD_INTRAWAVE_COLLISION);
|
||||
KYTY_PM4_GET(value, SPI_SHADER_PGM_RSRC2_PS, RASTER_ORDERED_SHADING);
|
||||
r2.shared_vgprs = KYTY_PM4_GET(value, SPI_SHADER_PGM_RSRC2_PS, SHARED_VGPR_CNT);
|
||||
cp.GetShCtx().SetPsShaderResource2(r2);
|
||||
};
|
||||
|
||||
@@ -60,24 +60,34 @@ enum class GsOutputPrimitiveType : uint32_t {
|
||||
};
|
||||
|
||||
enum class ChannelLayout : uint32_t {
|
||||
kInvalid = 0,
|
||||
k8 = 1,
|
||||
k16 = 2,
|
||||
k8_8 = 3,
|
||||
k32 = 4,
|
||||
k16_16 = 5,
|
||||
k11_11_10 = 6,
|
||||
k10_10_10_2 = 9,
|
||||
k8_8_8_8 = 10,
|
||||
k32_32 = 11,
|
||||
k16_16_16_16 = 12,
|
||||
k32_32_32_32 = 14,
|
||||
k5_6_5 = 16,
|
||||
k5_5_5_1 = 17,
|
||||
k4_4_4_4 = 19,
|
||||
kBc1 = 35,
|
||||
kBc2 = 36,
|
||||
kBc3 = 37,
|
||||
kInvalid = 0,
|
||||
k8 = 1,
|
||||
k16 = 2,
|
||||
k8_8 = 3,
|
||||
k32 = 4,
|
||||
k16_16 = 5,
|
||||
k11_11_10 = 6,
|
||||
k10_11_11 = 7,
|
||||
k2_10_10_10 = 8,
|
||||
k10_10_10_2 = 9,
|
||||
k8_8_8_8 = 10,
|
||||
k32_32 = 11,
|
||||
k16_16_16_16 = 12,
|
||||
k32_32_32 = 13,
|
||||
k32_32_32_32 = 14,
|
||||
k5_6_5 = 16,
|
||||
k5_5_5_1 = 17,
|
||||
k1_5_5_5 = 18,
|
||||
k4_4_4_4 = 19,
|
||||
k10_10_10_2Float = 31,
|
||||
k9_9_9_5 = 34,
|
||||
kBc1 = 35,
|
||||
kBc2 = 36,
|
||||
kBc3 = 37,
|
||||
kBc4 = 38,
|
||||
kBc5 = 39,
|
||||
kBc6 = 40,
|
||||
kBc7 = 41,
|
||||
};
|
||||
|
||||
enum class ChannelType : uint32_t {
|
||||
|
||||
@@ -36,6 +36,7 @@ static thread_local CommandProcessor* g_current_processor = nullptr;
|
||||
static thread_local Pm4Execution* g_current_execution = nullptr;
|
||||
static thread_local bool g_gpu_mutex_owned = false;
|
||||
static thread_local bool g_gpu_thread = false;
|
||||
static thread_local GpuState* g_gpu_state = nullptr;
|
||||
|
||||
class GpuMutexLock final {
|
||||
public:
|
||||
@@ -98,11 +99,10 @@ public:
|
||||
void SubmitFlipPreparation(uint64_t request_id);
|
||||
void Done();
|
||||
void Shutdown();
|
||||
[[nodiscard]] bool IsStopping();
|
||||
void SendCommand(Common::UniqueFunction<void>&& command);
|
||||
void SendCommandSync(Common::UniqueFunction<void>&& command);
|
||||
void SendCommandSyncWithProcessor(Common::UniqueFunction<void, CommandProcessor&>&& command);
|
||||
int GetFrameNum();
|
||||
[[nodiscard]] bool IsStopping();
|
||||
void SendCommand(Common::UniqueFunction<void>&& command);
|
||||
void SendCommandSync(Common::UniqueFunction<void>&& command);
|
||||
int GetFrameNum();
|
||||
[[nodiscard]] static bool IsGpuThread() noexcept { return g_gpu_thread; }
|
||||
|
||||
private:
|
||||
@@ -127,6 +127,7 @@ private:
|
||||
void WaitLocked();
|
||||
void Enqueue(Submission submission);
|
||||
void WaitForIdle();
|
||||
void ProcessCommands();
|
||||
bool Process(Submission& submission);
|
||||
static void ThreadRun(void* data);
|
||||
CommandProcessor& GetProcessor(uint32_t queue_id);
|
||||
@@ -139,6 +140,7 @@ private:
|
||||
Common::CondVar m_idle;
|
||||
std::array<std::deque<Submission>, QueueCount> m_queues;
|
||||
std::deque<Common::UniqueFunction<void>> m_commands;
|
||||
std::atomic_uint32_t m_pending_commands {0};
|
||||
uint32_t m_next_queue = 0;
|
||||
uint32_t m_submission_count = 0;
|
||||
bool m_processing = false;
|
||||
@@ -153,6 +155,8 @@ private:
|
||||
uint64_t m_submit_id = 0;
|
||||
std::atomic_int m_done_num = 0;
|
||||
std::jthread m_thread;
|
||||
|
||||
friend class CommandProcessor;
|
||||
};
|
||||
|
||||
static bool GraphicsRunDebugDumpEnabled() {
|
||||
@@ -195,9 +199,25 @@ void GpuState::SendCommand(Common::UniqueFunction<void>&& command) {
|
||||
Common::LockGuard lock(m_queue_mutex);
|
||||
EXIT_IF(!m_accepting);
|
||||
m_commands.push_back(std::move(command));
|
||||
m_pending_commands.fetch_add(1, std::memory_order_release);
|
||||
m_work_available.Signal();
|
||||
}
|
||||
|
||||
void GpuState::ProcessCommands() {
|
||||
EXIT_IF(!IsGpuThread());
|
||||
while (m_pending_commands.load(std::memory_order_acquire) != 0) {
|
||||
Common::UniqueFunction<void> command;
|
||||
{
|
||||
Common::LockGuard lock(m_queue_mutex);
|
||||
EXIT_IF(m_commands.empty());
|
||||
command = std::move(m_commands.front());
|
||||
m_commands.pop_front();
|
||||
EXIT_IF(m_pending_commands.fetch_sub(1, std::memory_order_acq_rel) == 0);
|
||||
}
|
||||
command();
|
||||
}
|
||||
}
|
||||
|
||||
void GpuState::SendCommandSync(Common::UniqueFunction<void>&& command) {
|
||||
EXIT_IF(!command);
|
||||
if (IsGpuThread()) {
|
||||
@@ -212,17 +232,6 @@ void GpuState::SendCommandSync(Common::UniqueFunction<void>&& command) {
|
||||
done.acquire();
|
||||
}
|
||||
|
||||
void GpuState::SendCommandSyncWithProcessor(
|
||||
Common::UniqueFunction<void, CommandProcessor&>&& command) {
|
||||
EXIT_IF(!command);
|
||||
SendCommandSync([this, operation = std::move(command)]() mutable {
|
||||
EXIT_IF(g_current_processor != nullptr);
|
||||
g_current_processor = m_gfx_cp.get();
|
||||
operation(*m_gfx_cp);
|
||||
g_current_processor = nullptr;
|
||||
});
|
||||
}
|
||||
|
||||
void GpuState::Submit(uint32_t* cmd_draw_buffer, uint32_t num_draw_dw, uint32_t* cmd_const_buffer,
|
||||
uint32_t num_const_dw, bool trigger_agc_interrupt_on_done) {
|
||||
GpuMutexLock lock(m_submission_mutex);
|
||||
@@ -303,6 +312,8 @@ void CommandProcessor::Reset() {
|
||||
m_sh_ctx.Reset();
|
||||
m_ucfg.Reset();
|
||||
m_ctx.Reset();
|
||||
m_saved_ctx.Reset();
|
||||
m_context_state_pushed = false;
|
||||
m_index_type_and_size = 0;
|
||||
m_index_buffer_size = 0;
|
||||
m_user_data_marker = HW::UserSgprType::Unknown;
|
||||
@@ -312,6 +323,30 @@ void CommandProcessor::Reset() {
|
||||
std::memset(m_const_ram, 0, sizeof(m_const_ram));
|
||||
}
|
||||
|
||||
void CommandProcessor::ApplyContextStateOperation(ContextStateOperation operation) {
|
||||
switch (operation) {
|
||||
case ContextStateOperation::Clear: m_ctx.Reset(); break;
|
||||
case ContextStateOperation::Push:
|
||||
EXIT_IF(m_context_state_pushed);
|
||||
m_saved_ctx = m_ctx;
|
||||
m_context_state_pushed = true;
|
||||
break;
|
||||
case ContextStateOperation::Pop:
|
||||
EXIT_IF(!m_context_state_pushed);
|
||||
m_ctx = m_saved_ctx;
|
||||
m_saved_ctx = {};
|
||||
m_context_state_pushed = false;
|
||||
break;
|
||||
case ContextStateOperation::PushClear:
|
||||
EXIT_IF(m_context_state_pushed);
|
||||
m_saved_ctx = m_ctx;
|
||||
m_context_state_pushed = true;
|
||||
m_ctx.Reset();
|
||||
break;
|
||||
default: EXIT("unknown context state operation: %u\n", static_cast<uint32_t>(operation));
|
||||
}
|
||||
}
|
||||
|
||||
void CommandProcessor::BufferInit() {
|
||||
GetScheduler().Begin(m_ctx, m_ucfg, m_sh_ctx);
|
||||
}
|
||||
@@ -509,6 +544,7 @@ void GpuState::ThreadRun(void* data) {
|
||||
EXIT_IF(gpu == nullptr);
|
||||
KYTY_PROFILER_THREAD("Thread_Gpu");
|
||||
g_gpu_thread = true;
|
||||
g_gpu_state = gpu;
|
||||
|
||||
for (;;) {
|
||||
Submission submission;
|
||||
@@ -529,6 +565,7 @@ void GpuState::ThreadRun(void* data) {
|
||||
} else if (!gpu->m_commands.empty()) {
|
||||
command = std::move(gpu->m_commands.front());
|
||||
gpu->m_commands.pop_front();
|
||||
EXIT_IF(gpu->m_pending_commands.fetch_sub(1, std::memory_order_acq_rel) == 0);
|
||||
gpu->m_processing = true;
|
||||
} else {
|
||||
int selected_queue = -1;
|
||||
@@ -560,6 +597,7 @@ void GpuState::ThreadRun(void* data) {
|
||||
}
|
||||
if (should_stop) {
|
||||
gpu->m_gfx_cp->BufferWait();
|
||||
g_gpu_state = nullptr;
|
||||
g_gpu_thread = false;
|
||||
return;
|
||||
}
|
||||
@@ -741,6 +779,9 @@ void CommandProcessor::SuspendPm4() {
|
||||
|
||||
void CommandProcessor::ProcessPm4(Pm4Execution& execution, size_t stop_depth) {
|
||||
while (execution.m_buffer_stack.size() > stop_depth) {
|
||||
if (g_gpu_state != nullptr) {
|
||||
g_gpu_state->ProcessCommands();
|
||||
}
|
||||
const auto buffer_index = execution.m_buffer_stack.size() - 1;
|
||||
auto& cursor = execution.m_buffer_stack[buffer_index];
|
||||
if (cursor.deferred_advance_dw != 0) {
|
||||
@@ -1135,9 +1176,9 @@ void CommandProcessor::DrawIndirectMulti(uint32_t data_offset, uint32_t max_coun
|
||||
void CommandProcessor::DispatchDirect(uint32_t thread_group_x, uint32_t thread_group_y,
|
||||
uint32_t thread_group_z, uint32_t mode) {
|
||||
uint32_t frame_num = 0;
|
||||
uint32_t local_x = 1;
|
||||
uint32_t local_y = 1;
|
||||
uint32_t local_z = 1;
|
||||
// uint32_t local_x = 1;
|
||||
// uint32_t local_y = 1;
|
||||
// uint32_t local_z = 1;
|
||||
|
||||
{
|
||||
CheckBuffer();
|
||||
@@ -1161,9 +1202,9 @@ void CommandProcessor::DispatchDirect(uint32_t thread_group_x, uint32_t thread_g
|
||||
}
|
||||
|
||||
const auto& cs = m_sh_ctx.GetCs().cs_regs;
|
||||
local_x = std::max(cs.num_thread_x, 1u);
|
||||
local_y = std::max(cs.num_thread_y, 1u);
|
||||
local_z = std::max(cs.num_thread_z, 1u);
|
||||
// local_x = std::max(cs.num_thread_x, 1u);
|
||||
// local_y = std::max(cs.num_thread_y, 1u);
|
||||
// local_z = std::max(cs.num_thread_z, 1u);
|
||||
if (cs.wave_size == 64u) {
|
||||
static std::atomic_bool logged_wave64_shader {false};
|
||||
if (!logged_wave64_shader.exchange(true, std::memory_order_relaxed)) {
|
||||
@@ -1179,27 +1220,27 @@ void CommandProcessor::DispatchDirect(uint32_t thread_group_x, uint32_t thread_g
|
||||
thread_group_y, thread_group_z, mode);
|
||||
}
|
||||
|
||||
constexpr uint32_t DispatchInitiatorUseThreadDimensions = 1u << 5u;
|
||||
/*constexpr uint32_t DispatchInitiatorUseThreadDimensions = 1u << 5u;
|
||||
auto group_count = [](uint32_t threads, uint32_t group_size) {
|
||||
return (threads == 0
|
||||
? 0u
|
||||
: (threads + std::max(group_size, 1u) - 1u) / std::max(group_size, 1u));
|
||||
return (threads == 0
|
||||
? 0u
|
||||
: (threads + std::max(group_size, 1u) - 1u) / std::max(group_size, 1u));
|
||||
};
|
||||
|
||||
auto groups_x = thread_group_x;
|
||||
auto groups_y = thread_group_y;
|
||||
auto groups_z = thread_group_z;
|
||||
if ((mode & DispatchInitiatorUseThreadDimensions) != 0) {
|
||||
groups_x = group_count(thread_group_x, local_x);
|
||||
groups_y = group_count(thread_group_y, local_y);
|
||||
groups_z = group_count(thread_group_z, local_z);
|
||||
groups_x = group_count(thread_group_x, local_x);
|
||||
groups_y = group_count(thread_group_y, local_y);
|
||||
groups_z = group_count(thread_group_z, local_z);
|
||||
}
|
||||
|
||||
const uint64_t invocations =
|
||||
static_cast<uint64_t>(groups_x) * groups_y * groups_z * local_x * local_y * local_z;
|
||||
if (invocations != 0) {
|
||||
BufferFlushAndWait();
|
||||
}
|
||||
BufferFlushAndWait();
|
||||
}*/
|
||||
}
|
||||
|
||||
void CommandProcessor::DispatchIndirect(uint32_t data_offset, uint32_t mode) {
|
||||
@@ -1650,10 +1691,6 @@ void Gpu::SendCommandSync(Common::UniqueFunction<void>&& command) {
|
||||
m_state->SendCommandSync(std::move(command));
|
||||
}
|
||||
|
||||
void Gpu::SendCommandSyncWithProcessor(Common::UniqueFunction<void, CommandProcessor&>&& command) {
|
||||
m_state->SendCommandSyncWithProcessor(std::move(command));
|
||||
}
|
||||
|
||||
void Gpu::Submit(uint32_t* draw_commands, uint32_t draw_size_dw, uint32_t* constant_commands,
|
||||
uint32_t constant_size_dw, bool trigger_agc_interrupt_on_done) {
|
||||
EXIT_IF(draw_commands == nullptr || draw_size_dw == 0);
|
||||
@@ -1679,12 +1716,8 @@ int Gpu::GetFrameNum() const {
|
||||
return m_state->GetFrameNum();
|
||||
}
|
||||
|
||||
bool Gpu::IsCommandProcessorThread() noexcept {
|
||||
return g_current_processor != nullptr;
|
||||
}
|
||||
|
||||
CommandProcessor* Gpu::CurrentCommandProcessor() noexcept {
|
||||
return g_current_processor;
|
||||
bool Gpu::IsGpuThread() noexcept {
|
||||
return GpuState::IsGpuThread();
|
||||
}
|
||||
|
||||
} // namespace Libs::Graphics
|
||||
@@ -9,7 +9,6 @@
|
||||
|
||||
namespace Libs::Graphics {
|
||||
|
||||
class CommandProcessor;
|
||||
class GpuState;
|
||||
class RenderContext;
|
||||
|
||||
@@ -23,7 +22,6 @@ public:
|
||||
[[nodiscard]] bool IsStopping();
|
||||
void SendCommand(Common::UniqueFunction<void>&& command);
|
||||
void SendCommandSync(Common::UniqueFunction<void>&& command);
|
||||
void SendCommandSyncWithProcessor(Common::UniqueFunction<void, CommandProcessor&>&& command);
|
||||
|
||||
void Submit(uint32_t* draw_commands, uint32_t draw_size_dw, uint32_t* constant_commands,
|
||||
uint32_t constant_size_dw, bool trigger_agc_interrupt_on_done = false);
|
||||
@@ -33,8 +31,7 @@ public:
|
||||
void Done();
|
||||
[[nodiscard]] int GetFrameNum() const;
|
||||
|
||||
[[nodiscard]] static bool IsCommandProcessorThread() noexcept;
|
||||
[[nodiscard]] static CommandProcessor* CurrentCommandProcessor() noexcept;
|
||||
[[nodiscard]] static bool IsGpuThread() noexcept;
|
||||
|
||||
private:
|
||||
std::unique_ptr<GpuState> m_state;
|
||||
|
||||
@@ -348,6 +348,16 @@ struct ModeControl {
|
||||
bool persp_corr_dis = false;
|
||||
};
|
||||
|
||||
struct PolyOffset {
|
||||
int8_t neg_num_db_bits = -23;
|
||||
bool db_is_float_fmt = true;
|
||||
float clamp = 0.0f;
|
||||
float front_scale = 0.0f;
|
||||
float front_offset = 0.0f;
|
||||
float back_scale = 0.0f;
|
||||
float back_offset = 0.0f;
|
||||
};
|
||||
|
||||
struct BlendControl {
|
||||
uint8_t color_srcblend = 1;
|
||||
uint8_t color_comb_fcn = 0;
|
||||
@@ -482,6 +492,26 @@ struct VsShaderResource2 {
|
||||
uint8_t shared_vgprs = 0;
|
||||
};
|
||||
|
||||
struct HsShaderResource1 {
|
||||
uint8_t vgprs = 0;
|
||||
uint8_t priority = 0;
|
||||
uint8_t float_mode = 0;
|
||||
bool dx10_clamp = false;
|
||||
bool debug_mode = false;
|
||||
bool ieee_mode = false;
|
||||
bool require_forward_progress = false;
|
||||
bool threadgroup_configuration = false;
|
||||
uint8_t ls_vgpr_component_count = 0;
|
||||
bool fp16_overflow = false;
|
||||
};
|
||||
|
||||
struct HsShaderResource2 {
|
||||
bool scratch_en = false;
|
||||
uint8_t user_sgpr = 0;
|
||||
uint16_t lds_size = 0;
|
||||
uint8_t shared_vgprs = 0;
|
||||
};
|
||||
|
||||
struct PsShaderResource1 {
|
||||
uint8_t vgprs = 0;
|
||||
uint8_t sgprs = 0;
|
||||
@@ -500,7 +530,7 @@ struct PsShaderResource2 {
|
||||
uint8_t user_sgpr = 0;
|
||||
bool wave_cnt_en = false;
|
||||
uint8_t extra_lds_size = 0;
|
||||
bool raster_ordered_shading = false;
|
||||
uint8_t raster_ordered_shading = 0;
|
||||
uint8_t shared_vgprs = 0;
|
||||
};
|
||||
|
||||
@@ -513,22 +543,27 @@ struct PsStageRegisters {
|
||||
|
||||
struct CsStageRegisters {
|
||||
|
||||
uint64_t data_addr = 0;
|
||||
uint32_t num_thread_x = 0;
|
||||
uint32_t num_thread_y = 0;
|
||||
uint32_t num_thread_z = 0;
|
||||
uint8_t vgprs = 0;
|
||||
uint8_t sgprs = 0;
|
||||
uint8_t bulky = 0;
|
||||
uint8_t wave_size = 64;
|
||||
uint8_t scratch_en = 0;
|
||||
uint8_t user_sgpr = 0;
|
||||
uint8_t tgid_x_en = 0;
|
||||
uint8_t tgid_y_en = 0;
|
||||
uint8_t tgid_z_en = 0;
|
||||
uint8_t tg_size_en = 0;
|
||||
uint8_t tidig_comp_cnt = 0;
|
||||
uint8_t lds_size = 0;
|
||||
uint64_t data_addr = 0;
|
||||
uint32_t num_thread_x = 0;
|
||||
uint32_t num_thread_y = 0;
|
||||
uint32_t num_thread_z = 0;
|
||||
uint8_t vgprs = 0;
|
||||
uint8_t sgprs = 0;
|
||||
uint8_t float_mode = 0;
|
||||
bool dx10_clamp = false;
|
||||
bool ieee_mode = false;
|
||||
bool fp16_overflow = false;
|
||||
bool bulky = false;
|
||||
bool threadgroup_configuration = false;
|
||||
uint8_t wave_size = 64;
|
||||
bool scratch_en = false;
|
||||
uint8_t user_sgpr = 0;
|
||||
bool tgid_x_en = false;
|
||||
bool tgid_y_en = false;
|
||||
bool tgid_z_en = false;
|
||||
bool tg_size_en = false;
|
||||
uint8_t tidig_comp_cnt = 0;
|
||||
uint16_t lds_size = 0;
|
||||
};
|
||||
|
||||
struct EsStageRegisters {
|
||||
@@ -543,24 +578,24 @@ struct LsStageRegisters {
|
||||
|
||||
struct HsStageRegisters {
|
||||
uint64_t data_addr = 0;
|
||||
VsShaderResource1 rsrc1;
|
||||
VsShaderResource2 rsrc2;
|
||||
HsShaderResource1 rsrc1;
|
||||
HsShaderResource2 rsrc2;
|
||||
uint64_t chksum = 0;
|
||||
};
|
||||
|
||||
struct GsShaderResource1 {
|
||||
uint8_t vgprs = 0;
|
||||
uint8_t sgprs = 0;
|
||||
uint8_t priority = 0;
|
||||
uint8_t float_mode = 0;
|
||||
bool dx10_clamp = false;
|
||||
bool debug_mode = false;
|
||||
bool ieee_mode = false;
|
||||
bool cu_group_enable = false;
|
||||
bool require_forward_progress = false;
|
||||
bool lds_configuration = false;
|
||||
uint8_t gs_vgpr_component_count = 0;
|
||||
bool fp16_overflow = false;
|
||||
uint8_t vgprs = 0;
|
||||
uint8_t sgprs = 0;
|
||||
uint8_t priority = 0;
|
||||
uint8_t float_mode = 0;
|
||||
bool dx10_clamp = false;
|
||||
bool debug_mode = false;
|
||||
bool ieee_mode = false;
|
||||
bool cu_group_enable = false;
|
||||
bool require_forward_progress = false;
|
||||
bool threadgroup_configuration = false;
|
||||
uint8_t gs_vgpr_component_count = 0;
|
||||
bool fp16_overflow = false;
|
||||
};
|
||||
|
||||
struct GsShaderResource2 {
|
||||
@@ -880,6 +915,8 @@ public:
|
||||
void SetDepthControl(const DepthControl& control) { m_depth_control = control; }
|
||||
[[nodiscard]] const ModeControl& GetModeControl() const { return m_mode_control; }
|
||||
void SetModeControl(const ModeControl& control) { m_mode_control = control; }
|
||||
[[nodiscard]] const PolyOffset& GetPolyOffset() const { return m_poly_offset; }
|
||||
void SetPolyOffset(const PolyOffset& offset) { m_poly_offset = offset; }
|
||||
[[nodiscard]] const EqaaControl& GetEqaaControl() const { return m_eqaa_control; }
|
||||
void SetEqaaControl(const EqaaControl& control) { m_eqaa_control = control; }
|
||||
[[nodiscard]] const StencilControl& GetStencilControl() const { return m_stencil_control; }
|
||||
@@ -977,6 +1014,7 @@ private:
|
||||
uint8_t m_stencil_clear_value = 0;
|
||||
|
||||
ModeControl m_mode_control;
|
||||
PolyOffset m_poly_offset;
|
||||
EqaaControl m_eqaa_control;
|
||||
|
||||
ShaderRegisters m_sh_regs;
|
||||
@@ -1034,8 +1072,8 @@ public:
|
||||
void SetLsShaderResource1(const VsShaderResource1& rsrc1) { m_vs.ls_regs.rsrc1 = rsrc1; }
|
||||
void SetLsShaderResource2(const VsShaderResource2& rsrc2) { m_vs.ls_regs.rsrc2 = rsrc2; }
|
||||
void SetHsShaderBase(uint64_t addr) { m_vs.hs_regs.data_addr = addr; }
|
||||
void SetHsShaderResource1(const VsShaderResource1& rsrc1) { m_vs.hs_regs.rsrc1 = rsrc1; }
|
||||
void SetHsShaderResource2(const VsShaderResource2& rsrc2) { m_vs.hs_regs.rsrc2 = rsrc2; }
|
||||
void SetHsShaderResource1(const HsShaderResource1& rsrc1) { m_vs.hs_regs.rsrc1 = rsrc1; }
|
||||
void SetHsShaderResource2(const HsShaderResource2& rsrc2) { m_vs.hs_regs.rsrc2 = rsrc2; }
|
||||
void SetHsShaderChksum(uint32_t value) { m_vs.hs_regs.chksum = value; }
|
||||
void SetGsShaderBase(uint64_t addr) { m_vs.gs_regs.data_addr = addr; }
|
||||
void SetGsShaderResource1(const GsShaderResource1& rsrc1) { m_vs.gs_regs.rsrc1 = rsrc1; }
|
||||
|
||||
@@ -30,6 +30,7 @@ constexpr auto MakeRegisterNames() {
|
||||
names[R_FLIP] = "R_FLIP";
|
||||
names[R_RELEASE_MEM] = "R_RELEASE_MEM";
|
||||
names[R_DMA_DATA] = "R_DMA_DATA";
|
||||
names[R_CONTEXT_STATE] = "R_CONTEXT_STATE";
|
||||
return names;
|
||||
}
|
||||
|
||||
|
||||
+132
-87
@@ -87,6 +87,7 @@ constexpr uint32_t R_WAIT_MEM_64 = 0x16;
|
||||
constexpr uint32_t R_FLIP = 0x17;
|
||||
constexpr uint32_t R_RELEASE_MEM = 0x18;
|
||||
constexpr uint32_t R_DMA_DATA = 0x19;
|
||||
constexpr uint32_t R_CONTEXT_STATE = 0x1A;
|
||||
|
||||
constexpr uint32_t R_NUM = 0x3F + 1;
|
||||
|
||||
@@ -577,24 +578,28 @@ constexpr uint32_t DB_HTILE_SURFACE_PREFETCH_HEIGHT_MASK = 0x3F;
|
||||
constexpr uint32_t DB_HTILE_SURFACE_DST_OUTSIDE_ZERO_TO_ONE_SHIFT = 16;
|
||||
constexpr uint32_t DB_HTILE_SURFACE_DST_OUTSIDE_ZERO_TO_ONE_MASK = 0x1;
|
||||
|
||||
constexpr uint32_t DB_SRESULTS_COMPARE_STATE0 = 0x2B0;
|
||||
constexpr uint32_t DB_SRESULTS_COMPARE_STATE1 = 0x2B1;
|
||||
constexpr uint32_t VGT_GS_MAX_VERT_OUT = 0x2CE;
|
||||
constexpr uint32_t GE_NGG_SUBGRP_CNTL = 0x2D3;
|
||||
constexpr uint32_t VGT_TESS_DISTRIBUTION = 0x2D4;
|
||||
constexpr uint32_t VGT_SHADER_STAGES_EN = 0x2D5;
|
||||
constexpr uint32_t VGT_LS_HS_CONFIG = 0x2D6;
|
||||
constexpr uint32_t VGT_TF_PARAM = 0x2DB;
|
||||
constexpr uint32_t DB_ALPHA_TO_MASK = 0x2DC;
|
||||
constexpr uint32_t PA_SU_POLY_OFFSET_DB_FMT_CNTL = 0x2DE;
|
||||
constexpr uint32_t PA_SU_POLY_OFFSET_CLAMP = 0x2DF;
|
||||
constexpr uint32_t PA_SU_POLY_OFFSET_FRONT_SCALE = 0x2E0;
|
||||
constexpr uint32_t PA_SU_POLY_OFFSET_FRONT_OFFSET = 0x2E1;
|
||||
constexpr uint32_t PA_SU_POLY_OFFSET_BACK_SCALE = 0x2E2;
|
||||
constexpr uint32_t PA_SU_POLY_OFFSET_BACK_OFFSET = 0x2E3;
|
||||
constexpr uint32_t VGT_GS_INSTANCE_CNT = 0x2E4;
|
||||
constexpr uint32_t PA_SC_CENTROID_PRIORITY_0 = 0x2F5;
|
||||
constexpr uint32_t PA_SC_CENTROID_PRIORITY_1 = 0x2F6;
|
||||
constexpr uint32_t DB_SRESULTS_COMPARE_STATE0 = 0x2B0;
|
||||
constexpr uint32_t DB_SRESULTS_COMPARE_STATE1 = 0x2B1;
|
||||
constexpr uint32_t VGT_GS_MAX_VERT_OUT = 0x2CE;
|
||||
constexpr uint32_t GE_NGG_SUBGRP_CNTL = 0x2D3;
|
||||
constexpr uint32_t VGT_TESS_DISTRIBUTION = 0x2D4;
|
||||
constexpr uint32_t VGT_SHADER_STAGES_EN = 0x2D5;
|
||||
constexpr uint32_t VGT_LS_HS_CONFIG = 0x2D6;
|
||||
constexpr uint32_t VGT_TF_PARAM = 0x2DB;
|
||||
constexpr uint32_t DB_ALPHA_TO_MASK = 0x2DC;
|
||||
constexpr uint32_t PA_SU_POLY_OFFSET_DB_FMT_CNTL = 0x2DE;
|
||||
constexpr uint32_t PA_SU_POLY_OFFSET_DB_FMT_CNTL_NEG_NUM_DB_BITS_SHIFT = 0;
|
||||
constexpr uint32_t PA_SU_POLY_OFFSET_DB_FMT_CNTL_NEG_NUM_DB_BITS_MASK = 0xFF;
|
||||
constexpr uint32_t PA_SU_POLY_OFFSET_DB_FMT_CNTL_DB_IS_FLOAT_FMT_SHIFT = 8;
|
||||
constexpr uint32_t PA_SU_POLY_OFFSET_DB_FMT_CNTL_DB_IS_FLOAT_FMT_MASK = 0x1;
|
||||
constexpr uint32_t PA_SU_POLY_OFFSET_CLAMP = 0x2DF;
|
||||
constexpr uint32_t PA_SU_POLY_OFFSET_FRONT_SCALE = 0x2E0;
|
||||
constexpr uint32_t PA_SU_POLY_OFFSET_FRONT_OFFSET = 0x2E1;
|
||||
constexpr uint32_t PA_SU_POLY_OFFSET_BACK_SCALE = 0x2E2;
|
||||
constexpr uint32_t PA_SU_POLY_OFFSET_BACK_OFFSET = 0x2E3;
|
||||
constexpr uint32_t VGT_GS_INSTANCE_CNT = 0x2E4;
|
||||
constexpr uint32_t PA_SC_CENTROID_PRIORITY_0 = 0x2F5;
|
||||
constexpr uint32_t PA_SC_CENTROID_PRIORITY_1 = 0x2F6;
|
||||
|
||||
constexpr uint32_t PA_SC_AA_CONFIG = 0x2F8;
|
||||
constexpr uint32_t PA_SC_AA_CONFIG_MSAA_NUM_SAMPLES_SHIFT = 0;
|
||||
@@ -778,21 +783,21 @@ constexpr uint32_t SPI_SHADER_PGM_RSRC1_PS_FWD_PROGRESS_MASK = 0x1;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC1_PS_FP16_OVFL_SHIFT = 29;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC1_PS_FP16_OVFL_MASK = 0x1;
|
||||
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC2_PS = 0xB;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC2_PS_SCRATCH_EN_SHIFT = 0;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC2_PS_SCRATCH_EN_MASK = 0x1;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC2_PS_USER_SGPR_SHIFT = 1;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC2_PS_USER_SGPR_MASK = 0x1F;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC2_PS_WAVE_CNT_EN_SHIFT = 7;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC2_PS_WAVE_CNT_EN_MASK = 0x1;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC2_PS_EXTRA_LDS_SIZE_SHIFT = 8;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC2_PS_EXTRA_LDS_SIZE_MASK = 0xFF;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC2_PS_LOAD_INTRAWAVE_COLLISION_SHIFT = 26;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC2_PS_LOAD_INTRAWAVE_COLLISION_MASK = 0x1;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC2_PS_USER_SGPR_MSB_SHIFT = 27;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC2_PS_USER_SGPR_MSB_MASK = 0x1;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC2_PS_SHARED_VGPR_CNT_SHIFT = 28;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC2_PS_SHARED_VGPR_CNT_MASK = 0xF;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC2_PS = 0xB;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC2_PS_SCRATCH_EN_SHIFT = 0;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC2_PS_SCRATCH_EN_MASK = 0x1;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC2_PS_USER_SGPR_SHIFT = 1;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC2_PS_USER_SGPR_MASK = 0x1F;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC2_PS_WAVE_CNT_EN_SHIFT = 7;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC2_PS_WAVE_CNT_EN_MASK = 0x1;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC2_PS_EXTRA_LDS_SIZE_SHIFT = 8;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC2_PS_EXTRA_LDS_SIZE_MASK = 0xFF;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC2_PS_RASTER_ORDERED_SHADING_SHIFT = 25;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC2_PS_RASTER_ORDERED_SHADING_MASK = 0x3;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC2_PS_USER_SGPR_MSB_SHIFT = 27;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC2_PS_USER_SGPR_MSB_MASK = 0x1;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC2_PS_SHARED_VGPR_CNT_SHIFT = 28;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC2_PS_SHARED_VGPR_CNT_MASK = 0xF;
|
||||
|
||||
constexpr uint32_t SPI_SHADER_USER_DATA_PS_0 = 0xC;
|
||||
constexpr uint32_t SPI_SHADER_USER_DATA_PS_15 = 0x1B;
|
||||
@@ -885,61 +890,101 @@ constexpr uint32_t SPI_SHADER_PGM_RSRC2_GS_USER_SGPR_MSB_MASK = 0x1;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC2_GS_SHARED_VGPR_CNT_SHIFT = 28;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC2_GS_SHARED_VGPR_CNT_MASK = 0xF;
|
||||
|
||||
constexpr uint32_t SPI_SHADER_USER_DATA_GS_0 = 0x8C;
|
||||
constexpr uint32_t SPI_SHADER_USER_DATA_GS_15 = 0x9B;
|
||||
constexpr uint32_t SPI_SHADER_USER_DATA_GS_31 = 0xAB;
|
||||
constexpr uint32_t SPI_SHADER_REQ_CTRL_ESGS = 0xB0;
|
||||
constexpr uint32_t SPI_SHADER_USER_ACCUM_ESGS_0 = 0xB2;
|
||||
constexpr uint32_t SPI_SHADER_USER_ACCUM_ESGS_3 = 0xB5;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC2_ES_GS = 0xBC;
|
||||
constexpr uint32_t SPI_SHADER_PGM_LO_ES = 0xC8;
|
||||
constexpr uint32_t SPI_SHADER_PGM_HI_ES = 0xC9;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC1_ES = 0xCA;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC2_ES = 0xCB;
|
||||
constexpr uint32_t SPI_SHADER_USER_DATA_ES_0 = 0xCC;
|
||||
constexpr uint32_t SPI_SHADER_USER_DATA_ES_15 = 0xDB;
|
||||
constexpr uint32_t SPI_SHADER_USER_DATA_ES_31 = 0xEB;
|
||||
constexpr uint32_t SPI_SHADER_PGM_CHKSUM_HS = 0x100;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC4_HS = 0x101;
|
||||
constexpr uint32_t SPI_SHADER_USER_DATA_ADDR_LO_HS = 0x102;
|
||||
constexpr uint32_t SPI_SHADER_USER_DATA_ADDR_HI_HS = 0x103;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC3_HS = 0x107;
|
||||
constexpr uint32_t SPI_SHADER_PGM_LO_HS = 0x108;
|
||||
constexpr uint32_t SPI_SHADER_PGM_HI_HS = 0x109;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC1_HS = 0x10A;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC2_HS = 0x10B;
|
||||
constexpr uint32_t SPI_SHADER_USER_DATA_HS_0 = 0x10C;
|
||||
constexpr uint32_t SPI_SHADER_USER_DATA_HS_15 = 0x11B;
|
||||
constexpr uint32_t SPI_SHADER_USER_DATA_HS_31 = 0x12B;
|
||||
constexpr uint32_t SPI_SHADER_REQ_CTRL_LSHS = 0x130;
|
||||
constexpr uint32_t SPI_SHADER_USER_ACCUM_LSHS_0 = 0x132;
|
||||
constexpr uint32_t SPI_SHADER_USER_ACCUM_LSHS_3 = 0x135;
|
||||
constexpr uint32_t SPI_SHADER_PGM_LO_LS = 0x148;
|
||||
constexpr uint32_t SPI_SHADER_PGM_HI_LS = 0x149;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC1_LS = 0x14A;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC2_LS = 0x14B;
|
||||
constexpr uint32_t COMPUTE_START_X = 0x204;
|
||||
constexpr uint32_t COMPUTE_START_Y = 0x205;
|
||||
constexpr uint32_t COMPUTE_START_Z = 0x206;
|
||||
constexpr uint32_t COMPUTE_NUM_THREAD_X = 0x207;
|
||||
constexpr uint32_t COMPUTE_NUM_THREAD_Y = 0x208;
|
||||
constexpr uint32_t COMPUTE_NUM_THREAD_Z = 0x209;
|
||||
constexpr uint32_t COMPUTE_PGM_LO = 0x20C;
|
||||
constexpr uint32_t COMPUTE_PGM_HI = 0x20D;
|
||||
constexpr uint32_t COMPUTE_TBA_LO = 0x20E;
|
||||
constexpr uint32_t COMPUTE_TBA_HI = 0x20F;
|
||||
constexpr uint32_t COMPUTE_TMA_LO = 0x210;
|
||||
constexpr uint32_t COMPUTE_TMA_HI = 0x211;
|
||||
constexpr uint32_t SPI_SHADER_USER_DATA_GS_0 = 0x8C;
|
||||
constexpr uint32_t SPI_SHADER_USER_DATA_GS_15 = 0x9B;
|
||||
constexpr uint32_t SPI_SHADER_USER_DATA_GS_31 = 0xAB;
|
||||
constexpr uint32_t SPI_SHADER_REQ_CTRL_ESGS = 0xB0;
|
||||
constexpr uint32_t SPI_SHADER_USER_ACCUM_ESGS_0 = 0xB2;
|
||||
constexpr uint32_t SPI_SHADER_USER_ACCUM_ESGS_3 = 0xB5;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC2_ES_GS = 0xBC;
|
||||
constexpr uint32_t SPI_SHADER_PGM_LO_ES = 0xC8;
|
||||
constexpr uint32_t SPI_SHADER_PGM_HI_ES = 0xC9;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC1_ES = 0xCA;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC2_ES = 0xCB;
|
||||
constexpr uint32_t SPI_SHADER_USER_DATA_ES_0 = 0xCC;
|
||||
constexpr uint32_t SPI_SHADER_USER_DATA_ES_15 = 0xDB;
|
||||
constexpr uint32_t SPI_SHADER_USER_DATA_ES_31 = 0xEB;
|
||||
constexpr uint32_t SPI_SHADER_PGM_CHKSUM_HS = 0x100;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC4_HS = 0x101;
|
||||
constexpr uint32_t SPI_SHADER_USER_DATA_ADDR_LO_HS = 0x102;
|
||||
constexpr uint32_t SPI_SHADER_USER_DATA_ADDR_HI_HS = 0x103;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC3_HS = 0x107;
|
||||
constexpr uint32_t SPI_SHADER_PGM_LO_HS = 0x108;
|
||||
constexpr uint32_t SPI_SHADER_PGM_HI_HS = 0x109;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC1_HS = 0x10A;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC2_HS = 0x10B;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC1_HS_VGPRS_SHIFT = 0;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC1_HS_VGPRS_MASK = 0x3F;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC1_HS_PRIORITY_SHIFT = 10;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC1_HS_PRIORITY_MASK = 0x3;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC1_HS_FLOAT_MODE_SHIFT = 12;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC1_HS_FLOAT_MODE_MASK = 0xFF;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC1_HS_DX10_CLAMP_SHIFT = 21;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC1_HS_DX10_CLAMP_MASK = 0x1;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC1_HS_DEBUG_MODE_SHIFT = 22;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC1_HS_DEBUG_MODE_MASK = 0x1;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC1_HS_IEEE_MODE_SHIFT = 23;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC1_HS_IEEE_MODE_MASK = 0x1;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC1_HS_FWD_PROGRESS_SHIFT = 25;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC1_HS_FWD_PROGRESS_MASK = 0x1;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC1_HS_WGP_MODE_SHIFT = 26;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC1_HS_WGP_MODE_MASK = 0x1;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC1_HS_LS_VGPR_COMP_CNT_SHIFT = 28;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC1_HS_LS_VGPR_COMP_CNT_MASK = 0x3;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC1_HS_FP16_OVFL_SHIFT = 30;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC1_HS_FP16_OVFL_MASK = 0x1;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC2_HS_SCRATCH_EN_SHIFT = 0;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC2_HS_SCRATCH_EN_MASK = 0x1;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC2_HS_USER_SGPR_SHIFT = 1;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC2_HS_USER_SGPR_MASK = 0x1F;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC2_HS_LDS_SIZE_SHIFT = 18;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC2_HS_LDS_SIZE_MASK = 0x1FF;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC2_HS_USER_SGPR_MSB_SHIFT = 27;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC2_HS_USER_SGPR_MSB_MASK = 0x1;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC2_HS_SHARED_VGPR_CNT_SHIFT = 28;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC2_HS_SHARED_VGPR_CNT_MASK = 0xF;
|
||||
constexpr uint32_t SPI_SHADER_USER_DATA_HS_0 = 0x10C;
|
||||
constexpr uint32_t SPI_SHADER_USER_DATA_HS_15 = 0x11B;
|
||||
constexpr uint32_t SPI_SHADER_USER_DATA_HS_31 = 0x12B;
|
||||
constexpr uint32_t SPI_SHADER_REQ_CTRL_LSHS = 0x130;
|
||||
constexpr uint32_t SPI_SHADER_USER_ACCUM_LSHS_0 = 0x132;
|
||||
constexpr uint32_t SPI_SHADER_USER_ACCUM_LSHS_3 = 0x135;
|
||||
constexpr uint32_t SPI_SHADER_PGM_LO_LS = 0x148;
|
||||
constexpr uint32_t SPI_SHADER_PGM_HI_LS = 0x149;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC1_LS = 0x14A;
|
||||
constexpr uint32_t SPI_SHADER_PGM_RSRC2_LS = 0x14B;
|
||||
constexpr uint32_t COMPUTE_START_X = 0x204;
|
||||
constexpr uint32_t COMPUTE_START_Y = 0x205;
|
||||
constexpr uint32_t COMPUTE_START_Z = 0x206;
|
||||
constexpr uint32_t COMPUTE_NUM_THREAD_X = 0x207;
|
||||
constexpr uint32_t COMPUTE_NUM_THREAD_Y = 0x208;
|
||||
constexpr uint32_t COMPUTE_NUM_THREAD_Z = 0x209;
|
||||
constexpr uint32_t COMPUTE_PGM_LO = 0x20C;
|
||||
constexpr uint32_t COMPUTE_PGM_HI = 0x20D;
|
||||
constexpr uint32_t COMPUTE_TBA_LO = 0x20E;
|
||||
constexpr uint32_t COMPUTE_TBA_HI = 0x20F;
|
||||
constexpr uint32_t COMPUTE_TMA_LO = 0x210;
|
||||
constexpr uint32_t COMPUTE_TMA_HI = 0x211;
|
||||
|
||||
constexpr uint32_t COMPUTE_PGM_RSRC1 = 0x212;
|
||||
constexpr uint32_t COMPUTE_PGM_RSRC1_VGPRS_SHIFT = 0;
|
||||
constexpr uint32_t COMPUTE_PGM_RSRC1_VGPRS_MASK = 0x3F;
|
||||
constexpr uint32_t COMPUTE_PGM_RSRC1_SGPRS_SHIFT = 6;
|
||||
constexpr uint32_t COMPUTE_PGM_RSRC1_SGPRS_MASK = 0xF;
|
||||
constexpr uint32_t COMPUTE_PGM_RSRC1_BULKY_SHIFT = 24;
|
||||
constexpr uint32_t COMPUTE_PGM_RSRC1_BULKY_MASK = 0x1;
|
||||
constexpr uint32_t COMPUTE_PGM_RSRC1_W32_EN_SHIFT = 30;
|
||||
constexpr uint32_t COMPUTE_PGM_RSRC1_W32_EN_MASK = 0x1;
|
||||
constexpr uint32_t COMPUTE_PGM_RSRC1 = 0x212;
|
||||
constexpr uint32_t COMPUTE_PGM_RSRC1_VGPRS_SHIFT = 0;
|
||||
constexpr uint32_t COMPUTE_PGM_RSRC1_VGPRS_MASK = 0x3F;
|
||||
constexpr uint32_t COMPUTE_PGM_RSRC1_SGPRS_SHIFT = 6;
|
||||
constexpr uint32_t COMPUTE_PGM_RSRC1_SGPRS_MASK = 0xF;
|
||||
constexpr uint32_t COMPUTE_PGM_RSRC1_FLOAT_MODE_SHIFT = 12;
|
||||
constexpr uint32_t COMPUTE_PGM_RSRC1_FLOAT_MODE_MASK = 0xFF;
|
||||
constexpr uint32_t COMPUTE_PGM_RSRC1_DX10_CLAMP_SHIFT = 21;
|
||||
constexpr uint32_t COMPUTE_PGM_RSRC1_DX10_CLAMP_MASK = 0x1;
|
||||
constexpr uint32_t COMPUTE_PGM_RSRC1_IEEE_MODE_SHIFT = 23;
|
||||
constexpr uint32_t COMPUTE_PGM_RSRC1_IEEE_MODE_MASK = 0x1;
|
||||
constexpr uint32_t COMPUTE_PGM_RSRC1_BULKY_SHIFT = 24;
|
||||
constexpr uint32_t COMPUTE_PGM_RSRC1_BULKY_MASK = 0x1;
|
||||
constexpr uint32_t COMPUTE_PGM_RSRC1_FP16_OVFL_SHIFT = 26;
|
||||
constexpr uint32_t COMPUTE_PGM_RSRC1_FP16_OVFL_MASK = 0x1;
|
||||
constexpr uint32_t COMPUTE_PGM_RSRC1_WGP_MODE_SHIFT = 29;
|
||||
constexpr uint32_t COMPUTE_PGM_RSRC1_WGP_MODE_MASK = 0x1;
|
||||
constexpr uint32_t COMPUTE_PGM_RSRC1_W32_EN_SHIFT = 30;
|
||||
constexpr uint32_t COMPUTE_PGM_RSRC1_W32_EN_MASK = 0x1;
|
||||
|
||||
constexpr uint32_t COMPUTE_PGM_RSRC2 = 0x213;
|
||||
constexpr uint32_t COMPUTE_PGM_RSRC2_SCRATCH_EN_SHIFT = 0;
|
||||
|
||||
+310
-609
File diff suppressed because it is too large.
Load diff
@@ -39,7 +39,7 @@ enum class TileBlockFamily : uint32_t {
|
||||
};
|
||||
|
||||
struct TileBlockLayout {
|
||||
TileBlockFamily family = TileBlockFamily::Standard256B;
|
||||
TileBlockFamily family = TileBlockFamily::Count;
|
||||
uint32_t bytes_per_element = 0;
|
||||
uint32_t block_size = 0;
|
||||
uint32_t block_width = 0;
|
||||
@@ -47,38 +47,69 @@ struct TileBlockLayout {
|
||||
uint32_t block_depth = 0;
|
||||
};
|
||||
|
||||
struct TileVolumeLayout {
|
||||
TileBlockFamily family = TileBlockFamily::Count;
|
||||
uint32_t bytes_per_element = 0;
|
||||
uint32_t texel_width = 1;
|
||||
uint32_t texel_height = 1;
|
||||
uint32_t first_tail_level = 0;
|
||||
uint32_t block_depth = 1;
|
||||
uint64_t block_slice_size = 0;
|
||||
uint64_t total_size = 0;
|
||||
uint64_t level_offsets[16] = {};
|
||||
uint64_t level_sizes[16] = {};
|
||||
uint32_t tail_x[16] = {};
|
||||
uint32_t tail_y[16] = {};
|
||||
uint32_t level_widths[16] = {};
|
||||
uint32_t level_heights[16] = {};
|
||||
struct TileTextureElementLayout {
|
||||
uint32_t bytes = 0;
|
||||
uint32_t texel_width = 1;
|
||||
uint32_t texel_height = 1;
|
||||
};
|
||||
|
||||
struct TileTextureBlockLayout {
|
||||
TileBlockLayout block;
|
||||
uint32_t texel_width = 1;
|
||||
uint32_t texel_height = 1;
|
||||
};
|
||||
|
||||
enum class TileSurfaceDimension : uint32_t {
|
||||
Dim2D,
|
||||
Dim3D,
|
||||
};
|
||||
|
||||
struct TileSurfaceDescription {
|
||||
uint32_t format = 0;
|
||||
uint32_t tile_mode = 0;
|
||||
TileSurfaceDimension dimension = TileSurfaceDimension::Dim2D;
|
||||
uint32_t width = 0;
|
||||
uint32_t height = 0;
|
||||
uint32_t depth = 1;
|
||||
uint32_t levels = 1;
|
||||
uint32_t layers = 1;
|
||||
};
|
||||
|
||||
// Width/height fields are measured in addressable elements, not texture texels.
|
||||
struct TileMipLayout {
|
||||
uint64_t offset = 0;
|
||||
uint64_t size = 0;
|
||||
uint32_t width = 0;
|
||||
uint32_t height = 0;
|
||||
uint32_t padded_width = 0;
|
||||
uint32_t padded_height = 0;
|
||||
uint32_t tail_x = 0;
|
||||
uint32_t tail_y = 0;
|
||||
};
|
||||
|
||||
struct TileSurfaceLayout {
|
||||
TileSurfaceDescription description;
|
||||
TileTextureBlockLayout texture;
|
||||
uint32_t first_tail_level = 0;
|
||||
uint64_t block_slice_size = 0;
|
||||
uint64_t total_size = 0;
|
||||
TileMipLayout mips[16] = {};
|
||||
};
|
||||
|
||||
bool TileGetBlockLayout(TileBlockFamily family, uint32_t bytes_per_element,
|
||||
TileBlockLayout& layout);
|
||||
bool TileGetTextureElementLayout(uint32_t format, TileTextureElementLayout& layout);
|
||||
bool TileGetTextureBlockLayout(uint32_t format, uint32_t tile, bool volume,
|
||||
TileTextureBlockLayout& layout);
|
||||
bool TileGetTiledTextureLayout(const TileSurfaceDescription& description,
|
||||
TileSurfaceLayout& layout);
|
||||
bool TileGetBlockOffset(const TileBlockLayout& layout, uint32_t x, uint32_t y, uint32_t z,
|
||||
uint32_t& byte_offset);
|
||||
bool TileGetBlockXor(const TileBlockLayout& layout, uint32_t block_x, uint32_t block_y,
|
||||
uint32_t& byte_offset);
|
||||
bool TileGetBlockXor(const TileBlockLayout& layout, uint32_t block_x, uint32_t block_y,
|
||||
uint32_t block_z, uint32_t& byte_offset);
|
||||
bool TileIsStandard256BTextureSupported(uint32_t format);
|
||||
bool TileIsStandard4KBTextureSupported(uint32_t format);
|
||||
bool TileIsStandard64KBTextureSupported(uint32_t format);
|
||||
bool TileGetTextureVolumeLayout(uint32_t format, uint32_t width, uint32_t height, uint32_t depth,
|
||||
uint32_t levels, uint32_t tile, TileVolumeLayout& layout);
|
||||
|
||||
bool TileGetHtileSize(uint32_t width, uint32_t height, TileSizeAlign& htile_size);
|
||||
bool TileGetDepthSize(uint32_t width, uint32_t height, uint32_t pitch, uint32_t z_format,
|
||||
uint32_t stencil_format, bool htile, TileSizeAlign& stencil_size,
|
||||
TileSizeAlign& htile_size, TileSizeAlign& depth_size,
|
||||
@@ -94,13 +125,13 @@ bool TileGetRenderTargetMipLayout(uint32_t width, uint32_t height, uint32_t
|
||||
uint32_t bytes_per_element, uint32_t levels,
|
||||
TileSizeAlign& total_size, TileSizeOffset* level_sizes,
|
||||
TilePaddedSize* padded_size);
|
||||
void TileGetTextureSize(uint32_t format, uint32_t width, uint32_t height, uint32_t pitch,
|
||||
uint32_t levels, uint32_t tile, TileSizeAlign* total_size,
|
||||
TileSizeOffset* level_sizes, TilePaddedSize* padded_size);
|
||||
void TileGetTextureTotalSize(uint32_t format, uint32_t width, uint32_t height, uint32_t depth,
|
||||
uint32_t pitch, uint32_t levels, uint32_t tile, bool volume_texture,
|
||||
TileSizeAlign& total_size);
|
||||
uint32_t TileGetTexturePitch(uint32_t format, uint32_t width, uint32_t levels, uint32_t tile);
|
||||
void TileGetTextureSize(uint32_t format, uint32_t width, uint32_t height, uint32_t levels,
|
||||
uint32_t tile, TileSizeAlign* total_size, TileSizeOffset* level_sizes,
|
||||
TilePaddedSize* padded_size);
|
||||
void TileGetTextureTotalSize(uint32_t format, uint32_t width, uint32_t height, uint32_t depth,
|
||||
uint32_t levels, uint32_t tile, bool volume_texture,
|
||||
TileSizeAlign& total_size);
|
||||
uint32_t TileGetTexturePitch(uint32_t format, uint32_t width, uint32_t tile);
|
||||
|
||||
} // namespace Libs::Graphics
|
||||
|
||||
|
||||
@@ -79,7 +79,6 @@ RegionManager* MemoryTracker::GetOrCreateRegion(uint64_t index) {
|
||||
|
||||
bool MemoryTracker::IsRegionCpuModified(uint64_t vaddr, uint64_t size) {
|
||||
CheckNotInUploadCallback();
|
||||
std::lock_guard access(m_access_mutex);
|
||||
return Iterate<true>(vaddr, size, [](RegionManager* manager, uint64_t offset, uint64_t bytes) {
|
||||
std::scoped_lock lock(manager->lock);
|
||||
return manager->IsModified<DirtySource::Cpu>(offset, bytes);
|
||||
@@ -88,7 +87,6 @@ bool MemoryTracker::IsRegionCpuModified(uint64_t vaddr, uint64_t size) {
|
||||
|
||||
bool MemoryTracker::IsRegionGpuModified(uint64_t vaddr, uint64_t size) {
|
||||
CheckNotInUploadCallback();
|
||||
std::lock_guard access(m_access_mutex);
|
||||
return Iterate<false>(vaddr, size, [](RegionManager* manager, uint64_t offset, uint64_t bytes) {
|
||||
std::scoped_lock lock(manager->lock);
|
||||
return manager->IsModified<DirtySource::Gpu>(offset, bytes);
|
||||
@@ -97,7 +95,6 @@ bool MemoryTracker::IsRegionGpuModified(uint64_t vaddr, uint64_t size) {
|
||||
|
||||
void MemoryTracker::MarkRegionAsCpuModified(uint64_t vaddr, uint64_t size) {
|
||||
CheckNotInUploadCallback();
|
||||
std::lock_guard access(m_access_mutex);
|
||||
Iterate<true>(vaddr, size, [](RegionManager* manager, uint64_t offset, uint64_t bytes) {
|
||||
std::scoped_lock lock(manager->lock);
|
||||
manager->ChangeState<DirtySource::Cpu, true>(manager->GetCpuAddr() + offset, bytes);
|
||||
@@ -106,7 +103,6 @@ void MemoryTracker::MarkRegionAsCpuModified(uint64_t vaddr, uint64_t size) {
|
||||
|
||||
void MemoryTracker::MarkRegionAsGpuModified(uint64_t vaddr, uint64_t size) {
|
||||
CheckNotInUploadCallback();
|
||||
std::lock_guard access(m_access_mutex);
|
||||
Iterate<true>(vaddr, size, [](RegionManager* manager, uint64_t offset, uint64_t bytes) {
|
||||
std::scoped_lock lock(manager->lock);
|
||||
manager->ChangeState<DirtySource::Gpu, true>(manager->GetCpuAddr() + offset, bytes);
|
||||
@@ -115,14 +111,13 @@ void MemoryTracker::MarkRegionAsGpuModified(uint64_t vaddr, uint64_t size) {
|
||||
|
||||
void MemoryTracker::UnmarkRegionAsGpuModified(uint64_t vaddr, uint64_t size) {
|
||||
CheckNotInUploadCallback();
|
||||
std::lock_guard access(m_access_mutex);
|
||||
Iterate<false>(vaddr, size, [](RegionManager* manager, uint64_t offset, uint64_t bytes) {
|
||||
std::scoped_lock lock(manager->lock);
|
||||
manager->ChangeState<DirtySource::Gpu, false>(manager->GetCpuAddr() + offset, bytes);
|
||||
});
|
||||
}
|
||||
|
||||
void MemoryTracker::UntrackMemoryLocked(uint64_t vaddr, uint64_t size) {
|
||||
void MemoryTracker::UntrackMemoryImpl(uint64_t vaddr, uint64_t size) {
|
||||
std::vector<RegionManager*> managers;
|
||||
managers.reserve((vaddr % TRACKER_REGION_SIZE + size + TRACKER_REGION_SIZE - 1) /
|
||||
TRACKER_REGION_SIZE);
|
||||
@@ -148,8 +143,7 @@ void MemoryTracker::UntrackMemoryLocked(uint64_t vaddr, uint64_t size) {
|
||||
|
||||
void MemoryTracker::UntrackMemory(uint64_t vaddr, uint64_t size) {
|
||||
CheckNotInUploadCallback();
|
||||
std::lock_guard access(m_access_mutex);
|
||||
UntrackMemoryLocked(vaddr, size);
|
||||
UntrackMemoryImpl(vaddr, size);
|
||||
}
|
||||
|
||||
} // namespace Libs::Graphics
|
||||
@@ -29,45 +29,29 @@ public:
|
||||
void MarkRegionAsGpuModified(uint64_t vaddr, uint64_t size);
|
||||
void UnmarkRegionAsGpuModified(uint64_t vaddr, uint64_t size);
|
||||
void UntrackMemory(uint64_t vaddr, uint64_t size);
|
||||
// Removes protection from a range and flushes GPU-owned data when required.
|
||||
template <typename Flush>
|
||||
void InvalidateRegion(uint64_t vaddr, uint64_t size, Flush&& on_flush) {
|
||||
void InvalidateRegion(uint64_t vaddr, uint64_t size, Flush&& on_flush) noexcept {
|
||||
static_assert(std::is_invocable_v<Flush&>);
|
||||
CheckNotInUploadCallback();
|
||||
ValidateRange(vaddr, size);
|
||||
|
||||
const auto update_cpu_state = [this, vaddr, size] {
|
||||
std::lock_guard access(m_access_mutex);
|
||||
std::vector<RegionManager*> managers;
|
||||
Iterate<false>(vaddr, size, [&](RegionManager* manager, uint64_t, uint64_t) {
|
||||
managers.push_back(manager);
|
||||
});
|
||||
std::vector<std::unique_lock<TrackingSpinLock>> locks;
|
||||
locks.reserve(managers.size());
|
||||
for (auto* manager: managers) {
|
||||
locks.emplace_back(manager->lock);
|
||||
Iterate<false>(vaddr, size, [&](RegionManager* manager, uint64_t offset, uint64_t bytes) {
|
||||
const bool should_flush = [&] {
|
||||
// Perform both the GPU modification check and CPU state change with the lock in
|
||||
// case the GPU thread is racing to mark the page modified. If a flush is needed,
|
||||
// on_flush performs the CPU state change.
|
||||
std::scoped_lock lock(manager->lock);
|
||||
if (manager->IsModified<DirtySource::Gpu>(offset, bytes)) {
|
||||
return true;
|
||||
}
|
||||
manager->ChangeState<DirtySource::Cpu, true>(manager->GetCpuAddr() + offset, bytes);
|
||||
return false;
|
||||
}();
|
||||
if (should_flush) {
|
||||
on_flush();
|
||||
}
|
||||
const bool gpu_modified = Iterate<false>(
|
||||
vaddr, size, [](RegionManager* manager, uint64_t offset, uint64_t bytes) {
|
||||
return manager->IsModified<DirtySource::Gpu>(offset, bytes);
|
||||
});
|
||||
if (gpu_modified) {
|
||||
return true;
|
||||
}
|
||||
Iterate<false>(vaddr, size,
|
||||
[](RegionManager* manager, uint64_t offset, uint64_t bytes) {
|
||||
manager->ChangeState<DirtySource::Cpu, true>(
|
||||
manager->GetCpuAddr() + offset, bytes);
|
||||
});
|
||||
return false;
|
||||
};
|
||||
|
||||
if (!update_cpu_state()) {
|
||||
return;
|
||||
}
|
||||
std::forward<Flush>(on_flush)();
|
||||
if (update_cpu_state()) {
|
||||
EXIT("memory invalidation retained GPU-owned pages\n");
|
||||
}
|
||||
});
|
||||
}
|
||||
#if KYTY_BUILD == KYTY_BUILD_DEBUG
|
||||
void ValidateGpuDirtyPages(const RangeSet& dirty, uint64_t vaddr, uint64_t size,
|
||||
@@ -84,7 +68,6 @@ public:
|
||||
static_assert(std::is_nothrow_invocable_v<Preflight&, uint64_t, uint64_t>);
|
||||
static_assert(std::is_nothrow_invocable_v<Func&, uint64_t, uint64_t>);
|
||||
CheckNotInUploadCallback();
|
||||
std::lock_guard access(m_access_mutex);
|
||||
std::vector<RegionManager*> managers;
|
||||
Iterate<false>(vaddr, size, [&](RegionManager* manager, uint64_t, uint64_t) {
|
||||
managers.push_back(manager);
|
||||
@@ -125,7 +108,6 @@ public:
|
||||
static_assert(std::is_nothrow_invocable_v<RangeFunc&, uint64_t, uint64_t>);
|
||||
static_assert(std::is_nothrow_invocable_v<UploadFunc&>);
|
||||
CheckNotInUploadCallback();
|
||||
std::unique_lock access(m_access_mutex);
|
||||
Iterate<true>(vaddr, size, [](RegionManager*, uint64_t, uint64_t) {});
|
||||
const auto* previous_upload_owner = std::exchange(s_upload_owner, this);
|
||||
Iterate<false>(vaddr, size, [&](RegionManager* manager, uint64_t offset, uint64_t bytes) {
|
||||
@@ -189,13 +171,12 @@ private:
|
||||
}
|
||||
|
||||
static void ValidateRange(uint64_t vaddr, uint64_t size);
|
||||
void UntrackMemoryLocked(uint64_t vaddr, uint64_t size);
|
||||
void UntrackMemoryImpl(uint64_t vaddr, uint64_t size);
|
||||
RegionManager* GetOrCreateRegion(uint64_t index);
|
||||
|
||||
std::unique_ptr<std::atomic<RegionManager*>[]> m_regions;
|
||||
std::vector<std::unique_ptr<RegionManager>> m_region_storage;
|
||||
std::mutex m_region_mutex;
|
||||
std::mutex m_access_mutex;
|
||||
PageManager& m_page_manager;
|
||||
};
|
||||
|
||||
|
||||
+71
-49
@@ -3,15 +3,17 @@
|
||||
#include "common/assert.h"
|
||||
#include "common/logging/log.h"
|
||||
#include "common/profiler.h"
|
||||
#include "graphics/guest_gpu/graphicsRun.h"
|
||||
#include "graphics/host_gpu/graphicContext.h"
|
||||
#include "graphics/host_gpu/renderer/cache/resourceMutex.h"
|
||||
#include "graphics/host_gpu/renderer/cache/textureCache.h"
|
||||
#include "graphics/host_gpu/renderer/commandScheduler.h"
|
||||
#include "graphics/host_gpu/renderer/render.h"
|
||||
#include "graphics/host_gpu/renderer/renderContext.h"
|
||||
#include "kernel/memory.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
@@ -57,15 +59,6 @@ uint64_t BufferCache::AlignUp(uint64_t value) {
|
||||
return (value + CACHING_PAGE_SIZE - 1) & ~(CACHING_PAGE_SIZE - 1);
|
||||
}
|
||||
|
||||
bool BufferCache::PageOverlaps(uint64_t left, uint64_t left_size, uint64_t right,
|
||||
uint64_t right_size) noexcept {
|
||||
const auto left_begin = left & ~(TRACKER_PAGE_SIZE - 1);
|
||||
const auto left_end = (left + left_size + TRACKER_PAGE_SIZE - 1) & ~(TRACKER_PAGE_SIZE - 1);
|
||||
const auto right_begin = right & ~(TRACKER_PAGE_SIZE - 1);
|
||||
const auto right_end = (right + right_size + TRACKER_PAGE_SIZE - 1) & ~(TRACKER_PAGE_SIZE - 1);
|
||||
return left_begin < right_end && right_begin < left_end;
|
||||
}
|
||||
|
||||
void BufferCache::Upload(CommandBuffer& command, Buffer& destination, uint64_t destination_offset,
|
||||
const void* source, uint64_t size) {
|
||||
auto* bytes = static_cast<const uint8_t*>(source);
|
||||
@@ -217,8 +210,7 @@ void BufferCache::QueueGarbageDownload(std::span<const DownloadCopy> copies, Ret
|
||||
}
|
||||
|
||||
BufferCache::BufferCache(GraphicContext& graphics, CommandScheduler& scheduler,
|
||||
PageManager& page_manager, TextureCache& texture_cache,
|
||||
ResourceMutex& resource_mutex)
|
||||
PageManager& page_manager, TextureCache& texture_cache)
|
||||
: m_graphics(graphics), m_scheduler(scheduler),
|
||||
m_gds_buffer(graphics, scheduler, MemoryUsage::Stream, 0, AllFlags, GdsBufferSize),
|
||||
m_memory_tracker(page_manager),
|
||||
@@ -226,7 +218,7 @@ BufferCache::BufferCache(GraphicContext& graphics, CommandScheduler& scheduler,
|
||||
m_stream_buffer(graphics, scheduler, MemoryUsage::Stream, 64 * MiB),
|
||||
m_download_buffer(graphics, scheduler, MemoryUsage::Download, 32 * MiB),
|
||||
m_device_buffer(graphics, scheduler, MemoryUsage::DeviceLocal, 128 * MiB),
|
||||
m_texture_cache(texture_cache), m_resource_mutex(resource_mutex) {
|
||||
m_texture_cache(texture_cache) {
|
||||
std::memset(m_gds_buffer.Mapped().data(), 0, static_cast<size_t>(m_gds_buffer.Size()));
|
||||
m_gds_buffer.Flush(0, m_gds_buffer.Size());
|
||||
if (!m_graphics.CanReportMemoryUsage()) {
|
||||
@@ -284,14 +276,28 @@ void BufferCache::InvalidateMemory(uint64_t vaddr, uint64_t size) {
|
||||
size > TRACKER_ADDRESS_SIZE - vaddr) {
|
||||
EXIT("BufferCache: invalid memory-invalidation range\n");
|
||||
}
|
||||
if (!HasPageOverlap(vaddr, size)) {
|
||||
if (!IsRegionRegistered(vaddr, size)) {
|
||||
return;
|
||||
}
|
||||
m_memory_tracker.InvalidateRegion(vaddr, size,
|
||||
[this, vaddr, size] { ReadMemory(vaddr, size); });
|
||||
[this, vaddr, size] { ReadMemory(vaddr, size, true); });
|
||||
}
|
||||
|
||||
void BufferCache::ReadMemory(uint64_t vaddr, uint64_t size) {
|
||||
void BufferCache::ReadMemory(uint64_t vaddr, uint64_t size, bool is_write) {
|
||||
if (Gpu::IsGpuThread()) {
|
||||
ReadMemoryOnGpu(vaddr, size, is_write);
|
||||
return;
|
||||
}
|
||||
if (CommandScheduler::InDeferredOperation()) {
|
||||
EXIT("unsupported buffer readback from an asynchronous GPU completion, "
|
||||
"addr=0x%016" PRIx64 " size=0x%016" PRIx64 "\n",
|
||||
vaddr, size);
|
||||
}
|
||||
m_scheduler.Context().GetGpu().SendCommandSync(
|
||||
[this, vaddr, size, is_write] { ReadMemoryOnGpu(vaddr, size, is_write); });
|
||||
}
|
||||
|
||||
void BufferCache::ReadMemoryOnGpu(uint64_t vaddr, uint64_t size, bool is_write) {
|
||||
std::vector<DownloadCopy> copies;
|
||||
{
|
||||
FaultSafeCacheLock lock(this, m_mutex);
|
||||
@@ -322,9 +328,16 @@ void BufferCache::ReadMemory(uint64_t vaddr, uint64_t size) {
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
if (copies.empty()) {
|
||||
return;
|
||||
if (copies.empty()) {
|
||||
if (!is_write) {
|
||||
return;
|
||||
}
|
||||
// A preceding read fault can consume the last GPU-owned copy after this write
|
||||
// invalidation has already chosen to flush. Complete the CPU ownership handoff even
|
||||
// though this callback no longer has bytes to download.
|
||||
m_memory_tracker.MarkRegionAsCpuModified(vaddr, size);
|
||||
return;
|
||||
}
|
||||
}
|
||||
auto downloads = RecordDownloads(copies);
|
||||
m_scheduler.FinishCurrent();
|
||||
@@ -336,6 +349,9 @@ void BufferCache::ReadMemory(uint64_t vaddr, uint64_t size) {
|
||||
}
|
||||
// The enumeration above covered whole dirty pages and every exact interval on them.
|
||||
m_memory_tracker.UnmarkRegionAsGpuModified(vaddr, size);
|
||||
if (is_write) {
|
||||
m_memory_tracker.MarkRegionAsCpuModified(vaddr, size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -497,7 +513,6 @@ BufferBinding BufferCache::ObtainBuffer(CommandBuffer& command, uint64_t vaddr,
|
||||
if (command.IsInvalid() || command.IsExecute()) {
|
||||
EXIT("BufferCache: buffer request requires a recording command buffer\n");
|
||||
}
|
||||
std::lock_guard transaction(m_resource_mutex);
|
||||
|
||||
if (is_read && !is_written && size <= CACHING_PAGE_SIZE &&
|
||||
!m_memory_tracker.IsRegionGpuModified(vaddr, size) &&
|
||||
@@ -524,25 +539,33 @@ BufferBinding BufferCache::ObtainBuffer(CommandBuffer& command, uint64_t vaddr,
|
||||
(void)m_texture_cache.InvalidateMemoryFromGPU(vaddr, size, true);
|
||||
}
|
||||
|
||||
FaultSafeCacheLock lock(this, m_mutex);
|
||||
auto& cached = GetOrCreateBuffer(command, vaddr, size);
|
||||
std::vector<std::pair<uint64_t, uint64_t>> uploads;
|
||||
m_memory_tracker.ForEachUploadRange(
|
||||
vaddr, size, is_written,
|
||||
[&](uint64_t address, uint64_t bytes) noexcept { uploads.emplace_back(address, bytes); },
|
||||
[&]() noexcept {
|
||||
for (const auto& [address, bytes]: uploads) {
|
||||
Upload(command, *cached.buffer, cached.buffer->Offset(address),
|
||||
reinterpret_cast<const void*>(address), bytes);
|
||||
}
|
||||
});
|
||||
if (is_written) {
|
||||
m_gpu_modified_ranges.Add(vaddr, size);
|
||||
std::shared_ptr<Buffer> owner;
|
||||
uint64_t offset = 0;
|
||||
{
|
||||
FaultSafeCacheLock lock(this, m_mutex);
|
||||
auto& cached = GetOrCreateBuffer(command, vaddr, size);
|
||||
std::vector<std::pair<uint64_t, uint64_t>> uploads;
|
||||
m_memory_tracker.ForEachUploadRange(
|
||||
vaddr, size, is_written,
|
||||
[&](uint64_t address, uint64_t bytes) noexcept {
|
||||
uploads.emplace_back(address, bytes);
|
||||
},
|
||||
[&]() noexcept {
|
||||
for (const auto& [address, bytes]: uploads) {
|
||||
Upload(command, *cached.buffer, cached.buffer->Offset(address),
|
||||
reinterpret_cast<const void*>(address), bytes);
|
||||
}
|
||||
});
|
||||
if (is_written) {
|
||||
m_gpu_modified_ranges.Add(vaddr, size);
|
||||
}
|
||||
owner = cached.buffer;
|
||||
offset = cached.buffer->Offset(vaddr);
|
||||
}
|
||||
if (is_formatted && is_read && !is_written) {
|
||||
(void)SynchronizeBufferFromImage(*cached.buffer, vaddr, size);
|
||||
(void)SynchronizeBufferFromImage(*owner, vaddr, size);
|
||||
}
|
||||
return {cached.buffer, cached.buffer->Handle(), cached.buffer->Offset(vaddr)};
|
||||
return {owner, owner->Handle(), offset};
|
||||
}
|
||||
|
||||
std::shared_ptr<Buffer> BufferCache::ObtainNullBuffer() {
|
||||
@@ -718,8 +741,7 @@ void BufferCache::FillBuffer(uint64_t vaddr, uint64_t size, uint32_t value, bool
|
||||
}
|
||||
(void)m_texture_cache.ClearMeta(vaddr);
|
||||
{
|
||||
std::lock_guard transaction(m_resource_mutex);
|
||||
const auto region = m_texture_cache.QueryRegion(vaddr, size);
|
||||
const auto region = m_texture_cache.QueryRegion(vaddr, size);
|
||||
if (!HasGpuDirtyBytes(vaddr, size) && !region.gpu_image_bytes) {
|
||||
if (region.image_bytes) {
|
||||
m_texture_cache.InvalidateMemory(vaddr, size);
|
||||
@@ -758,8 +780,7 @@ void BufferCache::CopyBuffer(uint64_t dst_vaddr, uint64_t src_vaddr, uint64_t si
|
||||
EXIT("BufferCache: invalid or overlapping copy range\n");
|
||||
}
|
||||
if (src_memory || dst_memory) {
|
||||
std::lock_guard transaction(m_resource_mutex);
|
||||
const auto src_region =
|
||||
const auto src_region =
|
||||
src_memory ? m_texture_cache.QueryRegion(src_vaddr, size) : TextureCache::RegionInfo {};
|
||||
const auto dst_region =
|
||||
dst_memory ? m_texture_cache.QueryRegion(dst_vaddr, size) : TextureCache::RegionInfo {};
|
||||
@@ -810,18 +831,20 @@ void BufferCache::CopyBuffer(uint64_t dst_vaddr, uint64_t src_vaddr, uint64_t si
|
||||
destination.CopyFrom(command, source, src.offset, dst.offset, size);
|
||||
}
|
||||
|
||||
bool BufferCache::HasPageOverlap(uint64_t vaddr, uint64_t size) {
|
||||
bool BufferCache::IsRegionRegistered(uint64_t vaddr, uint64_t size) {
|
||||
if (vaddr == 0 || size == 0 || vaddr >= TRACKER_ADDRESS_SIZE ||
|
||||
size > TRACKER_ADDRESS_SIZE - vaddr) {
|
||||
EXIT("BufferCache: invalid page-overlap query\n");
|
||||
EXIT("BufferCache: invalid registered-region query\n");
|
||||
}
|
||||
FaultSafeCacheLock lock(this, m_mutex);
|
||||
for (const auto& [address, cached]: m_buffers) {
|
||||
if (PageOverlaps(vaddr, size, address, cached->size)) {
|
||||
return true;
|
||||
}
|
||||
// Cached buffers are ordered and non-overlapping. The last buffer beginning before the query
|
||||
// end is therefore the only possible intersection.
|
||||
const auto candidate = m_buffers.lower_bound(vaddr + size);
|
||||
if (candidate == m_buffers.begin()) {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
const auto& [address, cached] = *std::prev(candidate);
|
||||
return address + cached->size > vaddr;
|
||||
}
|
||||
|
||||
bool BufferCache::IsRegionGpuModified(uint64_t vaddr, uint64_t size) {
|
||||
@@ -838,8 +861,7 @@ bool BufferCache::IsRegionCpuModified(uint64_t vaddr, uint64_t size) {
|
||||
}
|
||||
|
||||
void BufferCache::RunGarbageCollector() {
|
||||
std::lock_guard transaction(m_resource_mutex);
|
||||
const auto tick = m_gc_tick++;
|
||||
const auto tick = m_gc_tick++;
|
||||
if (m_graphics.CanReportMemoryUsage()) {
|
||||
m_total_used_memory = m_graphics.GetDeviceMemoryUsage();
|
||||
}
|
||||
|
||||
+4
-7
@@ -20,7 +20,6 @@ struct GraphicContext;
|
||||
class CommandBuffer;
|
||||
class CommandScheduler;
|
||||
class TextureCache;
|
||||
class ResourceMutex;
|
||||
|
||||
struct BufferBinding {
|
||||
std::shared_ptr<void> owner;
|
||||
@@ -41,12 +40,12 @@ public:
|
||||
}
|
||||
|
||||
BufferCache(GraphicContext& graphics, CommandScheduler& scheduler, PageManager& page_manager,
|
||||
TextureCache& texture_cache, ResourceMutex& resource_mutex);
|
||||
TextureCache& texture_cache);
|
||||
~BufferCache();
|
||||
KYTY_CLASS_NO_COPY(BufferCache);
|
||||
|
||||
void InvalidateMemory(uint64_t vaddr, uint64_t size);
|
||||
void ReadMemory(uint64_t vaddr, uint64_t size);
|
||||
void ReadMemory(uint64_t vaddr, uint64_t size, bool is_write = false);
|
||||
void UnmapMemory(uint64_t vaddr, uint64_t size);
|
||||
[[nodiscard]] BufferBinding ObtainBuffer(CommandBuffer& command, uint64_t vaddr, uint64_t size,
|
||||
bool is_written = false, bool is_read = true,
|
||||
@@ -61,7 +60,7 @@ public:
|
||||
void FillBuffer(uint64_t vaddr, uint64_t size, uint32_t value, bool is_gds = false);
|
||||
void CopyBuffer(uint64_t dst_vaddr, uint64_t src_vaddr, uint64_t size, bool dst_gds = false,
|
||||
bool src_gds = false);
|
||||
[[nodiscard]] bool HasPageOverlap(uint64_t vaddr, uint64_t size);
|
||||
[[nodiscard]] bool IsRegionRegistered(uint64_t vaddr, uint64_t size);
|
||||
[[nodiscard]] bool HasGpuDirtyBytes(uint64_t vaddr, uint64_t size);
|
||||
[[nodiscard]] bool IsRegionCpuModified(uint64_t vaddr, uint64_t size);
|
||||
[[nodiscard]] bool IsRegionGpuModified(uint64_t vaddr, uint64_t size);
|
||||
@@ -84,8 +83,6 @@ private:
|
||||
[[nodiscard]] static constexpr uint64_t AlignDownload(uint64_t size) noexcept {
|
||||
return (size + DOWNLOAD_ALIGNMENT - 1) & ~(DOWNLOAD_ALIGNMENT - 1);
|
||||
}
|
||||
[[nodiscard]] static bool PageOverlaps(uint64_t left, uint64_t left_size, uint64_t right,
|
||||
uint64_t right_size) noexcept;
|
||||
[[nodiscard]] static std::pair<uint64_t, uint64_t> DownloadEnvelope(const DownloadCopy& copy);
|
||||
[[nodiscard]] static bool ResolveOverlap(CacheRange& merged, CacheRange candidate) noexcept;
|
||||
void Upload(CommandBuffer& command, Buffer& destination, uint64_t destination_offset,
|
||||
@@ -97,6 +94,7 @@ private:
|
||||
void PublishDownloads(std::span<const DownloadRange> downloads);
|
||||
void QueueGarbageDownload(std::span<const DownloadCopy> copies, RetiredBuffer retire);
|
||||
void WriteHostMemory(uint64_t vaddr, std::span<const uint8_t> data);
|
||||
void ReadMemoryOnGpu(uint64_t vaddr, uint64_t size, bool is_write);
|
||||
|
||||
GraphicContext& m_graphics;
|
||||
CommandScheduler& m_scheduler;
|
||||
@@ -111,7 +109,6 @@ private:
|
||||
StreamBuffer m_download_buffer;
|
||||
StreamBuffer m_device_buffer;
|
||||
TextureCache& m_texture_cache;
|
||||
ResourceMutex& m_resource_mutex;
|
||||
uint64_t m_total_used_memory = 0;
|
||||
uint64_t m_trigger_gc_memory = 1ull * 1024 * 1024 * 1024;
|
||||
uint64_t m_critical_gc_memory = 2ull * 1024 * 1024 * 1024;
|
||||
|
||||
+10
-65
@@ -1,15 +1,13 @@
|
||||
#include "graphics/host_gpu/renderer/cache/gpuResourceManager.h"
|
||||
|
||||
#include "common/assert.h"
|
||||
#include "graphics/guest_gpu/command_processor/commandProcessor.h"
|
||||
#include "graphics/guest_gpu/graphicsRun.h"
|
||||
#include "graphics/host_gpu/renderer/commandScheduler.h"
|
||||
namespace Libs::Graphics {
|
||||
|
||||
GpuResourceManager::GpuResourceManager(GraphicContext& graphics, CommandScheduler& scheduler)
|
||||
: m_scheduler(scheduler),
|
||||
m_buffer_cache(graphics, scheduler, m_page_manager, m_texture_cache, m_resource_mutex),
|
||||
m_texture_cache(graphics, scheduler, m_page_manager, m_buffer_cache, m_resource_mutex) {}
|
||||
: m_scheduler(scheduler), m_buffer_cache(graphics, scheduler, m_page_manager, m_texture_cache),
|
||||
m_texture_cache(graphics, scheduler, m_page_manager, m_buffer_cache) {}
|
||||
|
||||
GpuResourceManager::~GpuResourceManager() = default;
|
||||
|
||||
@@ -18,69 +16,21 @@ bool GpuResourceManager::HandleFault(PageFaultAccess access, uint64_t fault_vadd
|
||||
if (!IsMapped(fault_vaddr, fault_size)) {
|
||||
return false;
|
||||
}
|
||||
if (CommandScheduler::InDeferredOperation()) {
|
||||
EXIT("unsupported guest-memory fault from an asynchronous GPU completion, "
|
||||
"addr=0x%016" PRIx64 " access=%u\n",
|
||||
fault_vaddr, static_cast<uint32_t>(access));
|
||||
if (access == PageFaultAccess::Write) {
|
||||
m_buffer_cache.InvalidateMemory(fault_vaddr, fault_size);
|
||||
m_texture_cache.InvalidateMemory(fault_vaddr, fault_size);
|
||||
} else {
|
||||
m_buffer_cache.ReadMemory(fault_vaddr, fault_size);
|
||||
}
|
||||
bool handled = false;
|
||||
const auto resolve = [this, access, fault_vaddr, &handled](CommandProcessor& cp) {
|
||||
cp.BeginReadbackTransaction();
|
||||
{
|
||||
ResourceMutex::FaultScope fault(m_resource_mutex);
|
||||
if (access == PageFaultAccess::Write) {
|
||||
m_buffer_cache.InvalidateMemory(fault_vaddr, fault_size);
|
||||
m_texture_cache.InvalidateMemory(fault_vaddr, fault_size);
|
||||
} else {
|
||||
m_buffer_cache.ReadMemory(fault_vaddr, fault_size);
|
||||
}
|
||||
handled = true;
|
||||
}
|
||||
cp.EndReadbackTransaction();
|
||||
};
|
||||
if (auto* cp = Gpu::CurrentCommandProcessor(); cp != nullptr) {
|
||||
resolve(*cp);
|
||||
return handled;
|
||||
}
|
||||
if (m_resource_mutex.IsOwnedByCurrentThread()) {
|
||||
EXIT("unsupported page fault from a pre-owned resource transaction, addr=0x%016" PRIx64
|
||||
" access=%u\n",
|
||||
fault_vaddr, static_cast<uint32_t>(access));
|
||||
}
|
||||
EXIT_IF(m_gpu == nullptr);
|
||||
m_gpu->SendCommandSyncWithProcessor(resolve);
|
||||
return handled;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GpuResourceManager::InvalidateMemory(uint64_t vaddr, uint64_t size) {
|
||||
if (!IsMapped(vaddr, size)) {
|
||||
return false;
|
||||
}
|
||||
if (CommandScheduler::InDeferredOperation()) {
|
||||
EXIT("unsupported memory invalidation from an asynchronous GPU completion, "
|
||||
"addr=0x%016" PRIx64 " size=0x%016" PRIx64 "\n",
|
||||
vaddr, size);
|
||||
}
|
||||
const auto resolve = [this, vaddr, size](CommandProcessor& cp) {
|
||||
cp.BeginReadbackTransaction();
|
||||
{
|
||||
ResourceMutex::FaultScope fault(m_resource_mutex);
|
||||
m_buffer_cache.InvalidateMemory(vaddr, size);
|
||||
m_texture_cache.InvalidateMemory(vaddr, size);
|
||||
}
|
||||
cp.EndReadbackTransaction();
|
||||
};
|
||||
if (auto* cp = Gpu::CurrentCommandProcessor(); cp != nullptr) {
|
||||
resolve(*cp);
|
||||
return true;
|
||||
}
|
||||
if (m_resource_mutex.IsOwnedByCurrentThread()) {
|
||||
EXIT("unsupported memory invalidation from a pre-owned resource transaction, "
|
||||
"addr=0x%016" PRIx64 " size=0x%016" PRIx64 "\n",
|
||||
vaddr, size);
|
||||
}
|
||||
EXIT_IF(m_gpu == nullptr);
|
||||
m_gpu->SendCommandSyncWithProcessor(resolve);
|
||||
m_buffer_cache.InvalidateMemory(vaddr, size);
|
||||
m_texture_cache.InvalidateMemory(vaddr, size);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -107,11 +57,6 @@ void GpuResourceManager::UnmapMemory(uint64_t vaddr, uint64_t size) {
|
||||
"addr=0x%016" PRIx64 " size=0x%016" PRIx64 "\n",
|
||||
vaddr, size);
|
||||
}
|
||||
if (m_resource_mutex.IsOwnedByCurrentThread()) {
|
||||
EXIT("unsupported memory unmap from a pre-owned resource transaction, "
|
||||
"addr=0x%016" PRIx64 " size=0x%016" PRIx64 "\n",
|
||||
vaddr, size);
|
||||
}
|
||||
const auto unmap = [this, vaddr, size] {
|
||||
if (m_scheduler.Active()) {
|
||||
const auto tick = m_scheduler.CurrentTick();
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
#include "common/common.h"
|
||||
#include "graphics/host_gpu/pageManager.h"
|
||||
#include "graphics/host_gpu/renderer/cache/bufferCache.h"
|
||||
#include "graphics/host_gpu/renderer/cache/resourceMutex.h"
|
||||
#include "graphics/host_gpu/renderer/cache/textureCache.h"
|
||||
|
||||
#include <cstdint>
|
||||
@@ -35,7 +34,6 @@ public:
|
||||
|
||||
private:
|
||||
PageManager m_page_manager;
|
||||
ResourceMutex m_resource_mutex;
|
||||
CommandScheduler& m_scheduler;
|
||||
BufferCache m_buffer_cache;
|
||||
TextureCache m_texture_cache;
|
||||
|
||||
+154
-242
@@ -7,8 +7,9 @@
|
||||
#include <array>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <list>
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
@@ -103,6 +104,158 @@ private:
|
||||
size_t m_allocated_buckets = 0;
|
||||
};
|
||||
|
||||
// Inline owner storage for page-table entries. Texture pages normally have only a
|
||||
// handful of owners, so avoid a heap allocation on the first 16 registrations.
|
||||
//
|
||||
// Owners are packed into live uint64_t objects instead of being constructed in
|
||||
// raw storage. This keeps sparse bucket construction cheap without relying on
|
||||
// subtle implicit-lifetime or pointer-provenance rules.
|
||||
template <typename OwnerT, size_t InlineCapacity = 16>
|
||||
class InlinePageOwnerList final {
|
||||
public:
|
||||
using value_type = OwnerT;
|
||||
using size_type = size_t;
|
||||
|
||||
class const_iterator final {
|
||||
public:
|
||||
[[nodiscard]] OwnerT operator*() const noexcept { return m_owners->At(m_index); }
|
||||
const_iterator& operator++() noexcept {
|
||||
++m_index;
|
||||
return *this;
|
||||
}
|
||||
bool operator==(const const_iterator&) const = default;
|
||||
|
||||
private:
|
||||
friend class InlinePageOwnerList;
|
||||
const_iterator(const InlinePageOwnerList* owners, size_type index) noexcept
|
||||
: m_owners(owners), m_index(index) {}
|
||||
|
||||
const InlinePageOwnerList* m_owners = nullptr;
|
||||
size_type m_index = 0;
|
||||
};
|
||||
|
||||
static_assert(InlineCapacity > 0);
|
||||
static_assert(std::is_default_constructible_v<OwnerT>);
|
||||
static_assert(std::is_trivially_copyable_v<OwnerT>);
|
||||
static_assert(std::has_unique_object_representations_v<OwnerT>);
|
||||
static_assert(sizeof(OwnerT) <= sizeof(uint64_t));
|
||||
|
||||
InlinePageOwnerList() noexcept {}
|
||||
InlinePageOwnerList(const InlinePageOwnerList&) = delete;
|
||||
InlinePageOwnerList& operator=(const InlinePageOwnerList&) = delete;
|
||||
InlinePageOwnerList(InlinePageOwnerList&& other) noexcept
|
||||
: m_overflow(std::move(other.m_overflow)),
|
||||
m_inline_size(std::exchange(other.m_inline_size, 0)) {
|
||||
if (m_overflow == nullptr) {
|
||||
std::copy_n(other.m_inline.begin(), m_inline_size, m_inline.begin());
|
||||
}
|
||||
}
|
||||
InlinePageOwnerList& operator=(InlinePageOwnerList&& other) noexcept {
|
||||
if (this != &other) {
|
||||
m_overflow = std::move(other.m_overflow);
|
||||
m_inline_size = std::exchange(other.m_inline_size, 0);
|
||||
if (m_overflow == nullptr) {
|
||||
std::copy_n(other.m_inline.begin(), m_inline_size, m_inline.begin());
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
[[nodiscard]] const_iterator begin() const noexcept { return {this, 0}; }
|
||||
[[nodiscard]] const_iterator end() const noexcept { return {this, size()}; }
|
||||
|
||||
[[nodiscard]] bool empty() const noexcept { return size() == 0; }
|
||||
[[nodiscard]] size_type size() const noexcept {
|
||||
return m_overflow == nullptr ? m_inline_size : m_overflow->size();
|
||||
}
|
||||
[[nodiscard]] OwnerT front() const noexcept { return At(0); }
|
||||
[[nodiscard]] OwnerT operator[](size_type index) const noexcept { return At(index); }
|
||||
|
||||
void push_back(const OwnerT& owner) {
|
||||
const uint64_t packed = Pack(owner);
|
||||
if (m_overflow != nullptr) {
|
||||
m_overflow->push_back(packed);
|
||||
return;
|
||||
}
|
||||
if (m_inline_size < InlineCapacity) {
|
||||
m_inline[m_inline_size] = packed;
|
||||
++m_inline_size;
|
||||
return;
|
||||
}
|
||||
auto overflow = std::make_unique<std::vector<uint64_t>>();
|
||||
overflow->reserve(InlineCapacity * 2);
|
||||
overflow->assign(m_inline.begin(), m_inline.end());
|
||||
overflow->push_back(packed);
|
||||
m_overflow = std::move(overflow);
|
||||
}
|
||||
|
||||
[[nodiscard]] bool Contains(const OwnerT& owner) const noexcept {
|
||||
const uint64_t packed = Pack(owner);
|
||||
if (m_overflow != nullptr) {
|
||||
return std::find(m_overflow->begin(), m_overflow->end(), packed) != m_overflow->end();
|
||||
}
|
||||
return std::find(m_inline.begin(), m_inline.begin() + static_cast<ptrdiff_t>(m_inline_size),
|
||||
packed) != m_inline.begin() + static_cast<ptrdiff_t>(m_inline_size);
|
||||
}
|
||||
|
||||
[[nodiscard]] bool Erase(const OwnerT& owner) noexcept {
|
||||
const uint64_t packed = Pack(owner);
|
||||
if (m_overflow != nullptr) {
|
||||
const auto found = std::find(m_overflow->begin(), m_overflow->end(), packed);
|
||||
if (found == m_overflow->end()) {
|
||||
return false;
|
||||
}
|
||||
m_overflow->erase(found);
|
||||
if (m_overflow->size() == InlineCapacity) {
|
||||
std::copy(m_overflow->begin(), m_overflow->end(), m_inline.begin());
|
||||
m_inline_size = InlineCapacity;
|
||||
m_overflow.reset();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
const auto end = m_inline.begin() + static_cast<ptrdiff_t>(m_inline_size);
|
||||
const auto found = std::find(m_inline.begin(), end, packed);
|
||||
if (found == end) {
|
||||
return false;
|
||||
}
|
||||
std::move(found + 1, end, found);
|
||||
--m_inline_size;
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename Func>
|
||||
void ForEach(Func&& func) const {
|
||||
if (m_overflow != nullptr) {
|
||||
for (const uint64_t owner: *m_overflow) {
|
||||
func(Unpack(owner));
|
||||
}
|
||||
return;
|
||||
}
|
||||
for (size_type index = 0; index < m_inline_size; ++index) {
|
||||
func(Unpack(m_inline[index]));
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
[[nodiscard]] OwnerT At(size_type index) const noexcept {
|
||||
return Unpack(m_overflow == nullptr ? m_inline[index] : (*m_overflow)[index]);
|
||||
}
|
||||
[[nodiscard]] static uint64_t Pack(const OwnerT& owner) noexcept {
|
||||
uint64_t packed = 0;
|
||||
std::memcpy(&packed, &owner, sizeof(owner));
|
||||
return packed;
|
||||
}
|
||||
[[nodiscard]] static OwnerT Unpack(uint64_t packed) noexcept {
|
||||
OwnerT owner {};
|
||||
std::memcpy(&owner, &packed, sizeof(owner));
|
||||
return owner;
|
||||
}
|
||||
|
||||
std::array<uint64_t, InlineCapacity> m_inline;
|
||||
std::unique_ptr<std::vector<uint64_t>> m_overflow;
|
||||
size_type m_inline_size = 0;
|
||||
};
|
||||
|
||||
// Removes only the requested owner. Other owners in the same page entry remain intact.
|
||||
template <typename Container, typename Value>
|
||||
[[nodiscard]] bool EraseExact(Container& owners, const Value& owner) {
|
||||
@@ -114,247 +267,6 @@ template <typename Container, typename Value>
|
||||
return true;
|
||||
}
|
||||
|
||||
// Multi-range ownership with 1 MiB candidate buckets and precise 4 KiB
|
||||
// lifetime accounting. OwnerT only needs equality.
|
||||
template <typename OwnerT>
|
||||
class MultiRangePageOwnerIndex final {
|
||||
private:
|
||||
struct Registration;
|
||||
using MembershipList = std::vector<const Registration*>;
|
||||
|
||||
public:
|
||||
struct ByteRange final {
|
||||
uint64_t address = 0;
|
||||
uint64_t size = 0;
|
||||
};
|
||||
|
||||
using CoarseTable = MultiLevelPageTable<MembershipList, 20, 40, 10>;
|
||||
using TrackingTable = MultiLevelPageTable<MembershipList, 12, 40, 18>;
|
||||
|
||||
[[nodiscard]] bool Register(const OwnerT& owner, const std::vector<ByteRange>& ranges) {
|
||||
if (FindRegistration(owner) != m_registrations.end()) {
|
||||
return false;
|
||||
}
|
||||
auto normalized = Normalize(ranges);
|
||||
if (normalized.empty()) {
|
||||
return false;
|
||||
}
|
||||
m_registrations.push_back({owner, std::move(normalized)});
|
||||
const Registration* registration = &m_registrations.back();
|
||||
for (const size_t page: CollectPages<20>(registration->ranges)) {
|
||||
m_coarse_pages[page].push_back(registration);
|
||||
}
|
||||
for (const size_t page: CollectPages<12>(registration->ranges)) {
|
||||
m_tracking_pages[page].push_back(registration);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// No state changes if an expected membership is absent. Final releases are
|
||||
// sorted and coalesced 4 KiB spans whose final owner disappeared.
|
||||
[[nodiscard]] bool Unregister(const OwnerT& owner, std::vector<ByteRange>& final_releases) {
|
||||
final_releases.clear();
|
||||
auto registration = FindRegistration(owner);
|
||||
if (registration == m_registrations.end()) {
|
||||
return false;
|
||||
}
|
||||
const auto coarse_pages = CollectPages<20>(registration->ranges);
|
||||
const auto tracking_pages = CollectPages<12>(registration->ranges);
|
||||
const Registration* registration_ptr = &*registration;
|
||||
if (!HasAllMemberships(m_coarse_pages, coarse_pages, registration_ptr) ||
|
||||
!HasAllMemberships(m_tracking_pages, tracking_pages, registration_ptr)) {
|
||||
return false;
|
||||
}
|
||||
std::vector<size_t> final_pages;
|
||||
for (const size_t page: coarse_pages) {
|
||||
(void)EraseExact(*m_coarse_pages.Find(page), registration_ptr);
|
||||
}
|
||||
for (const size_t page: tracking_pages) {
|
||||
auto& owners = *m_tracking_pages.Find(page);
|
||||
if (owners.size() == 1) {
|
||||
final_pages.push_back(page);
|
||||
}
|
||||
(void)EraseExact(owners, registration_ptr);
|
||||
}
|
||||
m_registrations.erase(registration);
|
||||
final_releases = CoalesceTrackingPages(final_pages);
|
||||
return true;
|
||||
}
|
||||
|
||||
[[nodiscard]] std::vector<OwnerT> Query(uint64_t address, uint64_t size) const {
|
||||
return Query(address, size, [](const OwnerT&) { return true; });
|
||||
}
|
||||
|
||||
template <typename Predicate>
|
||||
[[nodiscard]] std::vector<OwnerT> Query(uint64_t address, uint64_t size,
|
||||
Predicate&& predicate) const {
|
||||
return QueryImpl(address, size, true, std::forward<Predicate>(predicate));
|
||||
}
|
||||
|
||||
// Fault paths use page candidates: exact byte-disjoint owners sharing a
|
||||
// touched 4 KiB page are intentionally retained.
|
||||
[[nodiscard]] std::vector<OwnerT> QueryCandidates(uint64_t address, uint64_t size) const {
|
||||
return QueryCandidates(address, size, [](const OwnerT&) { return true; });
|
||||
}
|
||||
|
||||
template <typename Predicate>
|
||||
[[nodiscard]] std::vector<OwnerT> QueryCandidates(uint64_t address, uint64_t size,
|
||||
Predicate&& predicate) const {
|
||||
return QueryImpl(address, size, false, std::forward<Predicate>(predicate));
|
||||
}
|
||||
|
||||
[[nodiscard]] size_t CoarseMembershipCount(size_t page) const {
|
||||
const auto* owners = m_coarse_pages.Find(page);
|
||||
return owners == nullptr ? 0 : owners->size();
|
||||
}
|
||||
[[nodiscard]] size_t TrackingMembershipCount(size_t page) const {
|
||||
const auto* owners = m_tracking_pages.Find(page);
|
||||
return owners == nullptr ? 0 : owners->size();
|
||||
}
|
||||
|
||||
private:
|
||||
template <typename Predicate>
|
||||
[[nodiscard]] std::vector<OwnerT> QueryImpl(uint64_t address, uint64_t size, bool strict_bytes,
|
||||
Predicate&& predicate) const {
|
||||
typename CoarseTable::PageRange coarse_range {};
|
||||
typename TrackingTable::PageRange tracking_range {};
|
||||
if (!CoarseTable::TryGetPageRange(address, size, coarse_range) ||
|
||||
(!strict_bytes && !TrackingTable::TryGetPageRange(address, size, tracking_range))) {
|
||||
return {};
|
||||
}
|
||||
MembershipList candidates;
|
||||
for (size_t page = coarse_range.first; page < coarse_range.last_exclusive; ++page) {
|
||||
if (const auto* owners = m_coarse_pages.Find(page); owners != nullptr) {
|
||||
AppendUnique(candidates, *owners);
|
||||
}
|
||||
}
|
||||
std::vector<OwnerT> result;
|
||||
for (const Registration* registration: candidates) {
|
||||
if ((strict_bytes ? Overlaps(registration->ranges, address, size)
|
||||
: HasTrackingMembership(registration, tracking_range)) &&
|
||||
predicate(registration->owner)) {
|
||||
result.push_back(registration->owner);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
struct Registration final {
|
||||
OwnerT owner;
|
||||
std::vector<ByteRange> ranges;
|
||||
};
|
||||
using RegistrationIterator = typename std::list<Registration>::iterator;
|
||||
using ConstRegistrationIterator = typename std::list<Registration>::const_iterator;
|
||||
|
||||
[[nodiscard]] RegistrationIterator FindRegistration(const OwnerT& owner) {
|
||||
return std::find_if(m_registrations.begin(), m_registrations.end(),
|
||||
[&](const Registration& item) { return item.owner == owner; });
|
||||
}
|
||||
[[nodiscard]] ConstRegistrationIterator FindRegistration(const OwnerT& owner) const {
|
||||
return std::find_if(m_registrations.begin(), m_registrations.end(),
|
||||
[&](const Registration& item) { return item.owner == owner; });
|
||||
}
|
||||
|
||||
[[nodiscard]] static std::vector<ByteRange> Normalize(const std::vector<ByteRange>& ranges) {
|
||||
std::vector<ByteRange> sorted;
|
||||
for (const auto& range: ranges) {
|
||||
typename CoarseTable::PageRange ignored {};
|
||||
if (!CoarseTable::TryGetPageRange(range.address, range.size, ignored)) {
|
||||
return {};
|
||||
}
|
||||
sorted.push_back(range);
|
||||
}
|
||||
std::sort(sorted.begin(), sorted.end(), [](const ByteRange& lhs, const ByteRange& rhs) {
|
||||
return lhs.address < rhs.address;
|
||||
});
|
||||
std::vector<ByteRange> merged;
|
||||
for (const auto& range: sorted) {
|
||||
if (merged.empty() || range.address > merged.back().address + merged.back().size) {
|
||||
merged.push_back(range);
|
||||
} else {
|
||||
const uint64_t end = std::max(merged.back().address + merged.back().size,
|
||||
range.address + range.size);
|
||||
merged.back().size = end - merged.back().address;
|
||||
}
|
||||
}
|
||||
return merged;
|
||||
}
|
||||
|
||||
template <size_t Bits>
|
||||
[[nodiscard]] static std::vector<size_t> CollectPages(const std::vector<ByteRange>& ranges) {
|
||||
std::vector<size_t> pages;
|
||||
for (const auto& range: ranges) {
|
||||
const size_t first = static_cast<size_t>(range.address >> Bits);
|
||||
const size_t last = static_cast<size_t>((range.address + range.size - 1) >> Bits);
|
||||
for (size_t page = first; page <= last; ++page) {
|
||||
pages.push_back(page);
|
||||
}
|
||||
}
|
||||
std::sort(pages.begin(), pages.end());
|
||||
pages.erase(std::unique(pages.begin(), pages.end()), pages.end());
|
||||
return pages;
|
||||
}
|
||||
|
||||
template <typename Table>
|
||||
[[nodiscard]] static bool HasAllMemberships(const Table& table,
|
||||
const std::vector<size_t>& pages,
|
||||
const Registration* registration) {
|
||||
for (const size_t page: pages) {
|
||||
const auto* owners = table.Find(page);
|
||||
if (owners == nullptr ||
|
||||
std::find(owners->begin(), owners->end(), registration) == owners->end()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
[[nodiscard]] bool HasTrackingMembership(const Registration* registration,
|
||||
const typename TrackingTable::PageRange& range) const {
|
||||
for (size_t page = range.first; page < range.last_exclusive; ++page) {
|
||||
const auto* owners = m_tracking_pages.Find(page);
|
||||
if (owners != nullptr &&
|
||||
std::find(owners->begin(), owners->end(), registration) != owners->end()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
[[nodiscard]] static bool Overlaps(const std::vector<ByteRange>& ranges, uint64_t address,
|
||||
uint64_t size) {
|
||||
const uint64_t end = address + size;
|
||||
return std::any_of(ranges.begin(), ranges.end(), [&](const ByteRange& range) {
|
||||
return range.address < end && address < range.address + range.size;
|
||||
});
|
||||
}
|
||||
static void AppendUnique(MembershipList& destination, const MembershipList& source) {
|
||||
for (const Registration* registration: source) {
|
||||
if (std::find(destination.begin(), destination.end(), registration) ==
|
||||
destination.end()) {
|
||||
destination.push_back(registration);
|
||||
}
|
||||
}
|
||||
}
|
||||
[[nodiscard]] static std::vector<ByteRange>
|
||||
CoalesceTrackingPages(const std::vector<size_t>& pages) {
|
||||
std::vector<ByteRange> result;
|
||||
for (const size_t page: pages) {
|
||||
const uint64_t address = static_cast<uint64_t>(page) << 12;
|
||||
if (!result.empty() && result.back().address + result.back().size == address) {
|
||||
result.back().size += uint64_t {1} << 12;
|
||||
} else {
|
||||
result.push_back({address, uint64_t {1} << 12});
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
CoarseTable m_coarse_pages;
|
||||
TrackingTable m_tracking_pages;
|
||||
std::list<Registration> m_registrations;
|
||||
};
|
||||
|
||||
} // namespace Libs::Graphics
|
||||
|
||||
#endif // EMULATOR_SRC_GRAPHICS_HOST_GPU_RENDERER_MULTILEVELPAGETABLE_H_
|
||||
@@ -1,93 +0,0 @@
|
||||
#include "graphics/host_gpu/renderer/cache/resourceMutex.h"
|
||||
|
||||
#include "common/assert.h"
|
||||
|
||||
namespace Libs::Graphics {
|
||||
|
||||
ResourceMutex::FaultScope::FaultScope(ResourceMutex& mutex): m_mutex(mutex) {
|
||||
m_resource_preowned = m_mutex.BeginFault();
|
||||
}
|
||||
|
||||
ResourceMutex::FaultScope::~FaultScope() {
|
||||
m_mutex.EndFault(m_resource_preowned);
|
||||
}
|
||||
|
||||
ResourceMutex::~ResourceMutex() {
|
||||
std::lock_guard state(m_state);
|
||||
if (m_resource_owner != std::thread::id {} || m_fault_owner != std::thread::id {}) {
|
||||
EXIT("ResourceMutex destroyed with an active owner or fault transaction\n");
|
||||
}
|
||||
}
|
||||
|
||||
void ResourceMutex::lock() {
|
||||
const auto current = std::this_thread::get_id();
|
||||
{
|
||||
std::lock_guard state(m_state);
|
||||
if (m_resource_owner == current) {
|
||||
EXIT("recursive resource transaction\n");
|
||||
}
|
||||
if (m_fault_owner == current) {
|
||||
EXIT("resource transaction re-entered from a page-fault callback\n");
|
||||
}
|
||||
}
|
||||
m_resource.lock();
|
||||
std::lock_guard state(m_state);
|
||||
if (m_resource_owner != std::thread::id {}) {
|
||||
EXIT("resource mutex acquired with a stale owner\n");
|
||||
}
|
||||
m_resource_owner = current;
|
||||
}
|
||||
|
||||
void ResourceMutex::unlock() {
|
||||
const auto current = std::this_thread::get_id();
|
||||
{
|
||||
std::lock_guard state(m_state);
|
||||
if (m_resource_owner != current) {
|
||||
EXIT("resource transaction released without ownership\n");
|
||||
}
|
||||
m_resource_owner = {};
|
||||
}
|
||||
m_resource.unlock();
|
||||
}
|
||||
|
||||
bool ResourceMutex::IsOwnedByCurrentThread() {
|
||||
std::lock_guard state(m_state);
|
||||
return m_resource_owner == std::this_thread::get_id();
|
||||
}
|
||||
|
||||
bool ResourceMutex::BeginFault() {
|
||||
const auto current = std::this_thread::get_id();
|
||||
{
|
||||
std::lock_guard state(m_state);
|
||||
if (m_fault_owner == current) {
|
||||
EXIT("nested resource page-fault transaction\n");
|
||||
}
|
||||
if (m_resource_owner == current) {
|
||||
m_fault_owner = current;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
lock();
|
||||
std::lock_guard state(m_state);
|
||||
if (m_resource_owner != current || m_fault_owner != std::thread::id {}) {
|
||||
EXIT("resource fault transaction acquired inconsistent ownership\n");
|
||||
}
|
||||
m_fault_owner = current;
|
||||
return false;
|
||||
}
|
||||
|
||||
void ResourceMutex::EndFault(bool resource_preowned) {
|
||||
const auto current = std::this_thread::get_id();
|
||||
{
|
||||
std::lock_guard state(m_state);
|
||||
if (m_fault_owner != current || m_resource_owner != current) {
|
||||
EXIT("resource page-fault transaction ended with inconsistent ownership\n");
|
||||
}
|
||||
m_fault_owner = {};
|
||||
}
|
||||
if (!resource_preowned) {
|
||||
unlock();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Libs::Graphics
|
||||
@@ -1,48 +0,0 @@
|
||||
#ifndef EMULATOR_SRC_GRAPHICS_HOST_GPU_RENDERER_RESOURCEMUTEX_H_
|
||||
#define EMULATOR_SRC_GRAPHICS_HOST_GPU_RENDERER_RESOURCEMUTEX_H_
|
||||
|
||||
#include "common/common.h"
|
||||
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
|
||||
namespace Libs::Graphics {
|
||||
|
||||
// Owner-tracked shared buffer/image transaction. External faults pause GPU submissions first;
|
||||
// command-processor faults drain pending guest processors before entering this transaction.
|
||||
class ResourceMutex final {
|
||||
public:
|
||||
class FaultScope final {
|
||||
public:
|
||||
explicit FaultScope(ResourceMutex& mutex);
|
||||
~FaultScope();
|
||||
KYTY_CLASS_NO_COPY(FaultScope);
|
||||
|
||||
private:
|
||||
ResourceMutex& m_mutex;
|
||||
bool m_resource_preowned = false;
|
||||
};
|
||||
|
||||
ResourceMutex() = default;
|
||||
~ResourceMutex();
|
||||
KYTY_CLASS_NO_COPY(ResourceMutex);
|
||||
|
||||
void lock();
|
||||
void unlock();
|
||||
[[nodiscard]] bool IsOwnedByCurrentThread();
|
||||
|
||||
private:
|
||||
friend class FaultScope;
|
||||
|
||||
[[nodiscard]] bool BeginFault();
|
||||
void EndFault(bool resource_preowned);
|
||||
|
||||
std::mutex m_resource;
|
||||
std::mutex m_state;
|
||||
std::thread::id m_resource_owner;
|
||||
std::thread::id m_fault_owner;
|
||||
};
|
||||
|
||||
} // namespace Libs::Graphics
|
||||
|
||||
#endif // EMULATOR_SRC_GRAPHICS_HOST_GPU_RENDERER_RESOURCEMUTEX_H_
|
||||
+109
-84
@@ -8,7 +8,6 @@
|
||||
#include "graphics/guest_gpu/tile.h"
|
||||
#include "graphics/host_gpu/graphicContext.h"
|
||||
#include "graphics/host_gpu/renderer/cache/bufferCache.h"
|
||||
#include "graphics/host_gpu/renderer/cache/resourceMutex.h"
|
||||
#include "graphics/host_gpu/renderer/commandScheduler.h"
|
||||
#include "graphics/host_gpu/renderer/image/imageView.h"
|
||||
#include "graphics/host_gpu/renderer/image/textureCommon.h"
|
||||
@@ -56,13 +55,12 @@ private:
|
||||
} // namespace
|
||||
|
||||
TextureCache::TextureCache(GraphicContext& graphics, CommandScheduler& scheduler,
|
||||
PageManager& page_manager, BufferCache& buffer_cache,
|
||||
ResourceMutex& resource_mutex)
|
||||
PageManager& page_manager, BufferCache& buffer_cache)
|
||||
: m_graphics(graphics), m_scheduler(scheduler), m_page_manager(page_manager),
|
||||
m_blit_helper(graphics, scheduler),
|
||||
m_tiler(std::make_unique<TileManager>(graphics, scheduler,
|
||||
buffer_cache.GetUtilityBuffer(MemoryUsage::Stream))),
|
||||
m_buffer_cache(buffer_cache), m_resource_mutex(resource_mutex),
|
||||
m_buffer_cache(buffer_cache),
|
||||
m_readback_linear_images(Config::ReadbackLinearImagesEnabled()) {
|
||||
if (m_graphics.CanReportMemoryUsage()) {
|
||||
constexpr int64_t GiB = 1024ll * 1024 * 1024;
|
||||
@@ -195,10 +193,12 @@ void TextureCache::RegisterImage(ImageId id) {
|
||||
if (image.registered || image.info.data.Empty()) {
|
||||
EXIT("TextureCache: invalid image registration\n");
|
||||
}
|
||||
std::vector<ImageOwnerIndex::ByteRange> ranges;
|
||||
ranges.push_back({image.info.data.address, image.info.data.size});
|
||||
if (!m_image_owner_index.Register(id, ranges)) {
|
||||
EXIT("TextureCache: duplicate or invalid image registration\n");
|
||||
ImagePageTable::PageRange pages {};
|
||||
if (!ImagePageTable::TryGetPageRange(image.info.data.address, image.info.data.size, pages)) {
|
||||
EXIT("TextureCache: image registration is outside the guest address space\n");
|
||||
}
|
||||
for (size_t page = pages.first; page < pages.last_exclusive; ++page) {
|
||||
m_image_page_table[page].push_back(id);
|
||||
}
|
||||
image.registered = true;
|
||||
image.lru_id = m_lru_cache.Insert(id, m_gc_tick);
|
||||
@@ -211,9 +211,15 @@ void TextureCache::UnregisterImage(ImageId id) {
|
||||
return;
|
||||
}
|
||||
UntrackImage(id);
|
||||
std::vector<ImageOwnerIndex::ByteRange> releases;
|
||||
if (!m_image_owner_index.Unregister(id, releases)) {
|
||||
EXIT("TextureCache: image missing from owner index\n");
|
||||
ImagePageTable::PageRange pages {};
|
||||
if (!ImagePageTable::TryGetPageRange(image.info.data.address, image.info.data.size, pages)) {
|
||||
EXIT("TextureCache: registered image is outside the guest address space\n");
|
||||
}
|
||||
for (size_t page = pages.first; page < pages.last_exclusive; ++page) {
|
||||
auto* owners = m_image_page_table.Find(page);
|
||||
if (owners == nullptr || !owners->Erase(id)) {
|
||||
EXIT("TextureCache: image missing from page owner index\n");
|
||||
}
|
||||
}
|
||||
m_lru_cache.Free(image.lru_id);
|
||||
const auto accounted = image.AccountedSize();
|
||||
@@ -426,9 +432,8 @@ void TextureCache::UntrackImageTail(ImageId id) {
|
||||
}
|
||||
|
||||
void TextureCache::TrackImageDownload(ImageId id) {
|
||||
std::lock_guard transaction(m_resource_mutex);
|
||||
CacheLock lock(*this, m_lock);
|
||||
auto& image = ResolveImage(id);
|
||||
CacheLock lock(*this, m_lock);
|
||||
auto& image = ResolveImage(id);
|
||||
TrackImageDownloadLocked(id, image);
|
||||
}
|
||||
|
||||
@@ -451,10 +456,48 @@ const Image& TextureCache::GetImage(ImageId id) const {
|
||||
return ResolveImage(id);
|
||||
}
|
||||
|
||||
std::vector<ImageId> TextureCache::FindImagesInRegion(uint64_t address, uint64_t size,
|
||||
bool page_overlap) const {
|
||||
return page_overlap ? m_image_owner_index.QueryCandidates(address, size)
|
||||
: m_image_owner_index.Query(address, size);
|
||||
TextureCache::ImageIds TextureCache::FindImagesInRegion(uint64_t address, uint64_t size,
|
||||
bool page_overlap) const {
|
||||
ImagePageTable::PageRange pages {};
|
||||
if (!ImagePageTable::TryGetPageRange(address, size, pages)) {
|
||||
return {};
|
||||
}
|
||||
|
||||
uint32_t query_epoch = ++m_image_query_epoch;
|
||||
if (query_epoch == 0) {
|
||||
for (const auto& slot: m_slots) {
|
||||
if (slot.image != nullptr) {
|
||||
slot.image->query_epoch = 0;
|
||||
}
|
||||
}
|
||||
query_epoch = ++m_image_query_epoch;
|
||||
}
|
||||
|
||||
ImageIds result;
|
||||
for (size_t page = pages.first; page < pages.last_exclusive; ++page) {
|
||||
const auto* owners = m_image_page_table.Find(page);
|
||||
if (owners == nullptr) {
|
||||
continue;
|
||||
}
|
||||
owners->ForEach([&](ImageId id) {
|
||||
if (!id || id.index >= m_slots.size()) {
|
||||
return;
|
||||
}
|
||||
const auto& slot = m_slots[id.index];
|
||||
if (slot.generation != id.generation || slot.image == nullptr) {
|
||||
return;
|
||||
}
|
||||
auto& image = *slot.image;
|
||||
if (image.query_epoch == query_epoch) {
|
||||
return;
|
||||
}
|
||||
image.query_epoch = query_epoch;
|
||||
if (image.Overlaps(address, size, page_overlap)) {
|
||||
result.push_back(id);
|
||||
}
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
ImageId TextureCache::GetNullImage(const ImageDesc& desc) {
|
||||
@@ -865,7 +908,6 @@ TextureCache::BuildColorTransfer(const Image& image, BindingType binding,
|
||||
uint32_t format = info.guest_format;
|
||||
uint32_t layers = info.TransferLayers();
|
||||
bool volume = info.IsVolume();
|
||||
bool layered = info.IsLayered();
|
||||
bool allow_depth_tile = direction == TransferDirection::Upload;
|
||||
const char* owner =
|
||||
direction == TransferDirection::Upload ? "TextureCache" : "TextureCache readback";
|
||||
@@ -894,7 +936,6 @@ TextureCache::BuildColorTransfer(const Image& image, BindingType binding,
|
||||
format = info.guest_format;
|
||||
layers = info.resources.layers;
|
||||
volume = false;
|
||||
layered = layers > 1;
|
||||
allow_depth_tile = false;
|
||||
plan.swap_bgra16 = info.bgra16;
|
||||
owner = "VideoOut";
|
||||
@@ -912,19 +953,14 @@ TextureCache::BuildColorTransfer(const Image& image, BindingType binding,
|
||||
plan.swap_bgra16 = info.bgra16;
|
||||
}
|
||||
|
||||
plan.layout = TextureCalcUploadLayout(format, info.extent.width, info.extent.height,
|
||||
info.resources.levels, layers, info.pitch, info.tile_mode,
|
||||
info.data.size, allow_depth_tile, volume, owner);
|
||||
plan.regions = TextureBuildImageCopies(plan.layout, info.extent.width, info.extent.height,
|
||||
layers, info.resources.levels, layered, volume);
|
||||
plan.tiled = static_cast<Prospero::TileMode>(plan.layout.tile) != Prospero::TileMode::kLinear;
|
||||
plan.layout = TextureCalcUploadLayout(format, info.extent.width, info.extent.height,
|
||||
info.resources.levels, layers, info.tile_mode,
|
||||
info.data.size, allow_depth_tile, volume, owner);
|
||||
plan.regions = TextureBuildImageCopies(plan.layout);
|
||||
plan.tiled = static_cast<Prospero::TileMode>(plan.layout.surface.description.tile_mode) !=
|
||||
Prospero::TileMode::kLinear;
|
||||
if (plan.tiled) {
|
||||
// CMASK/FMASK decoding is intentionally deferred.
|
||||
if (plan.layout.tile_family == TileBlockFamily::Depth64KB &&
|
||||
Prospero::IsFmaskTextureFormat(format)) {
|
||||
return plan;
|
||||
}
|
||||
if (!TextureBuildGpuTileInfos(info.data.size, plan.regions, plan.layout, format, layers,
|
||||
if (!TextureBuildGpuTileInfos(info.data.size, plan.regions, plan.layout,
|
||||
info.resources.levels, plan.tiles)) {
|
||||
return plan;
|
||||
}
|
||||
@@ -971,9 +1007,10 @@ void TextureCache::UploadImage(Image& image, const ImageDesc& desc, Buffer& sour
|
||||
" size=0x%016" PRIx64 " format=%u tile=%u family=%u extent=%ux%ux%u "
|
||||
"pitch=%u levels=%u layers=%u samples=%u\n",
|
||||
static_cast<uint32_t>(desc.type), info.data.address, info.data.size,
|
||||
info.guest_format, info.tile_mode, static_cast<uint32_t>(plan.layout.tile_family),
|
||||
info.extent.width, info.extent.height, info.extent.depth, info.pitch,
|
||||
info.resources.levels, info.resources.layers, info.samples);
|
||||
info.guest_format, info.tile_mode,
|
||||
static_cast<uint32_t>(plan.layout.surface.texture.block.family), info.extent.width,
|
||||
info.extent.height, info.extent.depth, info.pitch, info.resources.levels,
|
||||
info.resources.layers, info.samples);
|
||||
}
|
||||
TileManager::Result linear {source.Handle(), source_offset, info.data.size};
|
||||
if (plan.tiled) {
|
||||
@@ -1106,8 +1143,7 @@ void TextureCache::RefreshImage(ImageId id, const ImageDesc& desc) {
|
||||
}
|
||||
|
||||
void TextureCache::AssociateStencil(ImageId depth_id, GuestRange stencil) {
|
||||
std::lock_guard transaction(m_resource_mutex);
|
||||
CacheLock lock(*this, m_lock);
|
||||
CacheLock lock(*this, m_lock);
|
||||
AssociateStencilLocked(depth_id, stencil);
|
||||
}
|
||||
|
||||
@@ -1150,11 +1186,9 @@ ImageId TextureCache::FindImage(ImageDesc& desc, bool exact_format) {
|
||||
}
|
||||
|
||||
ImageId result {};
|
||||
bool inserted_new = false;
|
||||
{
|
||||
std::lock_guard transaction(m_resource_mutex);
|
||||
CacheLock lock(*this, m_lock);
|
||||
const std::vector<ImageId> candidates =
|
||||
CacheLock lock(*this, m_lock);
|
||||
const auto candidates =
|
||||
FindImagesInRegion(desc.info.data.address, desc.info.data.size, false);
|
||||
|
||||
for (const auto id: candidates) {
|
||||
@@ -1197,19 +1231,12 @@ ImageId TextureCache::FindImage(ImageDesc& desc, bool exact_format) {
|
||||
}
|
||||
if (!result) {
|
||||
result = InsertImage(desc.info);
|
||||
inserted_new = true;
|
||||
auto& inserted = ResolveImage(result);
|
||||
if (m_buffer_cache.HasGpuDirtyBytes(inserted.info.data.address,
|
||||
inserted.info.data.size)) {
|
||||
inserted.MarkBufferModified();
|
||||
}
|
||||
}
|
||||
if (inserted_new) {
|
||||
InitializeImage(result, desc);
|
||||
} else {
|
||||
RefreshImage(result, desc);
|
||||
}
|
||||
|
||||
auto& image = ResolveImage(result);
|
||||
if (desc.type == BindingType::VideoOut &&
|
||||
desc.info.metadata.compression != VideoOutCompression::Uncompressed) {
|
||||
@@ -1234,6 +1261,13 @@ ImageId TextureCache::FindImage(ImageDesc& desc, bool exact_format) {
|
||||
return result;
|
||||
}
|
||||
|
||||
void TextureCache::UpdateImage(ImageId id) {
|
||||
CacheLock lock(*this, m_lock);
|
||||
auto& image = ResolveImage(id);
|
||||
TouchImage(image);
|
||||
RefreshImage(id, ImageDesc {.info = image.info, .type = UploadBinding(image)});
|
||||
}
|
||||
|
||||
ImageId TextureCache::FindImageFromRange(uint64_t address, uint64_t size, bool ensure_valid) {
|
||||
if (!GuestRange {address, size}.Valid()) {
|
||||
return {};
|
||||
@@ -1278,22 +1312,24 @@ ImageId TextureCache::FindImageFromRange(uint64_t address, uint64_t size, bool e
|
||||
}
|
||||
|
||||
vk::ImageView TextureCache::FindTexture(ImageId id, const ImageDesc& desc) {
|
||||
std::lock_guard transaction(m_resource_mutex);
|
||||
CacheLock lock(*this, m_lock);
|
||||
auto& image = ResolveImage(id);
|
||||
CacheLock lock(*this, m_lock);
|
||||
auto& image = ResolveImage(id);
|
||||
TouchImage(image);
|
||||
if (!image.info.data.Empty()) {
|
||||
if (!image.registered || image.depth_id || image.binding.needs_rebind) {
|
||||
EXIT("TextureCache: texture requires rediscovery before final acquisition\n");
|
||||
}
|
||||
}
|
||||
if (desc.type == BindingType::Storage) {
|
||||
image.MarkGpuModified();
|
||||
}
|
||||
if (!image.info.data.Empty()) {
|
||||
RefreshImage(id, desc);
|
||||
}
|
||||
switch (desc.type) {
|
||||
case BindingType::Texture: break;
|
||||
case BindingType::Storage:
|
||||
if (image.info.data.Empty()) {
|
||||
image.MarkGpuModified();
|
||||
} else {
|
||||
if (!image.info.data.Empty()) {
|
||||
if (!image.registered || image.depth_id) {
|
||||
EXIT("TextureCache: cannot acquire an unavailable storage image\n");
|
||||
}
|
||||
@@ -1312,16 +1348,16 @@ vk::ImageView TextureCache::FindRenderTarget(ImageId id, const ImageDesc& desc)
|
||||
if (desc.type != BindingType::RenderTarget) {
|
||||
EXIT("TextureCache: invalid color-target binding\n");
|
||||
}
|
||||
std::lock_guard transaction(m_resource_mutex);
|
||||
CacheLock lock(*this, m_lock);
|
||||
auto& image = ResolveImage(id);
|
||||
CacheLock lock(*this, m_lock);
|
||||
auto& image = ResolveImage(id);
|
||||
if (!image.registered || image.depth_id || image.binding.needs_rebind) {
|
||||
EXIT("TextureCache: color target requires rediscovery before final acquisition\n");
|
||||
}
|
||||
TouchImage(image);
|
||||
image.MarkGpuModified();
|
||||
image.usage.render_target = true;
|
||||
RefreshImage(id, desc);
|
||||
CommitGpuWrite(image);
|
||||
image.usage.render_target = true;
|
||||
TrackImageDownloadLocked(id, image);
|
||||
const auto view = image.FindView(desc.view_info);
|
||||
RetainImage(m_scheduler.Current(), id);
|
||||
@@ -1332,13 +1368,14 @@ vk::ImageView TextureCache::FindDepthTarget(ImageId id, const ImageDesc& desc) {
|
||||
if (desc.type != BindingType::DepthTarget) {
|
||||
EXIT("TextureCache: invalid depth-target binding\n");
|
||||
}
|
||||
std::lock_guard transaction(m_resource_mutex);
|
||||
CacheLock lock(*this, m_lock);
|
||||
auto& image = ResolveImage(id);
|
||||
CacheLock lock(*this, m_lock);
|
||||
auto& image = ResolveImage(id);
|
||||
if (!image.registered || image.depth_id || image.binding.needs_rebind) {
|
||||
EXIT("TextureCache: depth target requires rediscovery before final acquisition\n");
|
||||
}
|
||||
TouchImage(image);
|
||||
image.MarkGpuModified();
|
||||
image.usage.depth_target = true;
|
||||
RefreshImage(id, desc);
|
||||
if (desc.info.HasMetadata()) {
|
||||
image.info.metadata = desc.info.metadata;
|
||||
@@ -1346,7 +1383,6 @@ vk::ImageView TextureCache::FindDepthTarget(ImageId id, const ImageDesc& desc) {
|
||||
MetaDataInfo {.clear_mask = image.info.htile_clear_mask});
|
||||
}
|
||||
CommitGpuWrite(image);
|
||||
image.usage.depth_target = true;
|
||||
if (desc.info.HasStencil()) {
|
||||
AssociateStencilLocked(id, desc.info.stencil);
|
||||
}
|
||||
@@ -1356,9 +1392,8 @@ vk::ImageView TextureCache::FindDepthTarget(ImageId id, const ImageDesc& desc) {
|
||||
}
|
||||
|
||||
void TextureCache::MarkGpuWritten(ImageId id) {
|
||||
std::lock_guard transaction(m_resource_mutex);
|
||||
CacheLock lock(*this, m_lock);
|
||||
auto& image = ResolveImage(id);
|
||||
CacheLock lock(*this, m_lock);
|
||||
auto& image = ResolveImage(id);
|
||||
if (!image.registered || image.depth_id) {
|
||||
EXIT("TextureCache: cannot mark an unavailable image GPU-written\n");
|
||||
}
|
||||
@@ -1382,7 +1417,6 @@ bool TextureCache::ClearImageFromBuffer(CommandBuffer& command, uint64_t address
|
||||
if (command.IsInvalid() || !GuestRange {address, size}.Valid()) {
|
||||
EXIT("TextureCache: invalid image clear\n");
|
||||
}
|
||||
std::lock_guard transaction(m_resource_mutex);
|
||||
CacheLock lock(*this, m_lock);
|
||||
ImageId selected {};
|
||||
vk::ImageAspectFlags aspect {};
|
||||
@@ -1667,14 +1701,9 @@ bool BufferCache::SynchronizeBufferFromImage(Buffer& buffer, uint64_t vaddr, uin
|
||||
return false;
|
||||
}
|
||||
if (color.tiled) {
|
||||
const auto binding = m_texture_cache.UploadBinding(image);
|
||||
const auto format =
|
||||
binding == TextureCache::BindingType::RenderTarget
|
||||
? ImageOps::RenderTargetTransferFormat(image.info.bytes_per_block)
|
||||
: image.info.guest_format;
|
||||
color.tiles.clear();
|
||||
if (!TextureBuildGpuTileInfos(copy_size, color.regions, color.layout, format,
|
||||
image.info.TransferLayers(), levels, color.tiles)) {
|
||||
if (!TextureBuildGpuTileInfos(copy_size, color.regions, color.layout, levels,
|
||||
color.tiles)) {
|
||||
return false;
|
||||
}
|
||||
color.linear_size = GetLinearSize(color.tiles);
|
||||
@@ -1845,9 +1874,8 @@ bool TextureCache::IsMetaCleared(uint64_t address, uint32_t slice) {
|
||||
}
|
||||
|
||||
bool TextureCache::ClearMeta(uint64_t address) {
|
||||
std::lock_guard transaction(m_resource_mutex);
|
||||
CacheLock lock(*this, m_lock);
|
||||
const auto found = m_surface_metas.find(address);
|
||||
CacheLock lock(*this, m_lock);
|
||||
const auto found = m_surface_metas.find(address);
|
||||
if (found == m_surface_metas.end()) {
|
||||
return false;
|
||||
}
|
||||
@@ -1873,9 +1901,8 @@ void TextureCache::UnmapMemory(uint64_t address, uint64_t size) {
|
||||
if (!GuestRange {address, size}.Valid()) {
|
||||
EXIT("TextureCache: invalid unmap range\n");
|
||||
}
|
||||
std::lock_guard transaction(m_resource_mutex);
|
||||
CacheLock lock(*this, m_lock);
|
||||
auto images = FindImagesInRegion(address, size, false);
|
||||
CacheLock lock(*this, m_lock);
|
||||
auto images = FindImagesInRegion(address, size, false);
|
||||
if (!images.empty()) {
|
||||
m_scheduler.Finish();
|
||||
}
|
||||
@@ -1892,9 +1919,8 @@ void TextureCache::UnmapMemory(uint64_t address, uint64_t size) {
|
||||
}
|
||||
|
||||
void TextureCache::RunGarbageCollector() {
|
||||
std::lock_guard transaction(m_resource_mutex);
|
||||
CacheLock lock(*this, m_lock);
|
||||
const uint64_t tick = m_gc_tick++;
|
||||
CacheLock lock(*this, m_lock);
|
||||
const uint64_t tick = m_gc_tick++;
|
||||
if (m_graphics.CanReportMemoryUsage()) {
|
||||
m_total_used_memory = m_graphics.GetDeviceMemoryUsage();
|
||||
}
|
||||
@@ -1954,8 +1980,7 @@ void TextureCache::RunGarbageCollector() {
|
||||
}
|
||||
|
||||
void TextureCache::ProcessDownloadImages() {
|
||||
std::lock_guard transaction(m_resource_mutex);
|
||||
CacheLock lock(*this, m_lock);
|
||||
CacheLock lock(*this, m_lock);
|
||||
for (const auto id: m_download_images) {
|
||||
const auto owner = ResolveOwner(id);
|
||||
if (owner != nullptr && owner->registered && owner->IsGpuModified()) {
|
||||
|
||||
+12
-10
@@ -26,7 +26,6 @@ class Buffer;
|
||||
class BufferCache;
|
||||
class CommandBuffer;
|
||||
class CommandScheduler;
|
||||
class ResourceMutex;
|
||||
class RenderExecutor;
|
||||
class StreamBuffer;
|
||||
class TileManager;
|
||||
@@ -49,11 +48,12 @@ public:
|
||||
};
|
||||
|
||||
TextureCache(GraphicContext& graphics, CommandScheduler& scheduler, PageManager& page_manager,
|
||||
BufferCache& buffer_cache, ResourceMutex& resource_mutex);
|
||||
BufferCache& buffer_cache);
|
||||
~TextureCache();
|
||||
KYTY_CLASS_NO_COPY(TextureCache);
|
||||
|
||||
[[nodiscard]] ImageId FindImage(ImageDesc& desc, bool exact_format = false);
|
||||
void UpdateImage(ImageId id);
|
||||
[[nodiscard]] ImageId FindImageFromRange(uint64_t address, uint64_t size,
|
||||
bool ensure_valid = true);
|
||||
[[nodiscard]] vk::ImageView FindTexture(ImageId id, const ImageDesc& desc);
|
||||
@@ -99,7 +99,8 @@ private:
|
||||
int32_t layer = -1;
|
||||
};
|
||||
|
||||
using ImageOwnerIndex = MultiRangePageOwnerIndex<ImageId>;
|
||||
using ImageIds = InlinePageOwnerList<ImageId, 16>;
|
||||
using ImagePageTable = MultiLevelPageTable<ImageIds, 20, 40, 10>;
|
||||
|
||||
[[nodiscard]] Image& ResolveImage(ImageId id);
|
||||
[[nodiscard]] const Image& ResolveImage(ImageId id) const;
|
||||
@@ -125,8 +126,9 @@ private:
|
||||
[[nodiscard]] static BindingType UploadBinding(const Image& image);
|
||||
[[nodiscard]] bool SafeToDownload(const Image& image);
|
||||
|
||||
[[nodiscard]] std::vector<ImageId> FindImagesInRegion(uint64_t address, uint64_t size,
|
||||
bool page_overlap) const;
|
||||
// Caller holds m_lock; it also serializes the per-image query epoch.
|
||||
[[nodiscard]] ImageIds FindImagesInRegion(uint64_t address, uint64_t size,
|
||||
bool page_overlap) const;
|
||||
[[nodiscard]] OverlapResult ResolveOverlap(const ImageInfo& requested, BindingType binding,
|
||||
ImageId cached, ImageId merged);
|
||||
[[nodiscard]] ImageId ResolveDepthOverlap(const ImageInfo& requested, BindingType binding,
|
||||
@@ -166,10 +168,9 @@ private:
|
||||
BlitHelper m_blit_helper;
|
||||
std::unique_ptr<TileManager> m_tiler;
|
||||
BufferCache& m_buffer_cache;
|
||||
ResourceMutex& m_resource_mutex;
|
||||
std::vector<Slot> m_slots;
|
||||
std::vector<uint32_t> m_free_slots;
|
||||
ImageOwnerIndex m_image_owner_index;
|
||||
ImagePageTable m_image_page_table;
|
||||
std::map<vk::Format, ImageId> m_null_images;
|
||||
Common::LeastRecentlyUsedCache<ImageId, uint64_t> m_lru_cache;
|
||||
std::set<ImageId> m_download_images;
|
||||
@@ -177,9 +178,10 @@ private:
|
||||
uint64_t m_total_used_memory = 0;
|
||||
uint64_t m_trigger_gc_memory = 0;
|
||||
uint64_t m_pressure_gc_memory = 1536ull * 1024 * 1024;
|
||||
uint64_t m_critical_gc_memory = 3ull * 1024 * 1024 * 1024;
|
||||
uint64_t m_gc_tick = 0;
|
||||
bool m_readback_linear_images = false;
|
||||
uint64_t m_critical_gc_memory = 3ull * 1024 * 1024 * 1024;
|
||||
uint64_t m_gc_tick = 0;
|
||||
mutable uint32_t m_image_query_epoch = 0;
|
||||
bool m_readback_linear_images = false;
|
||||
|
||||
friend struct TextureCacheTestAccess;
|
||||
friend class BufferCache;
|
||||
|
||||
@@ -178,10 +178,10 @@ void RenderExecutor::ResolveRenderColorTarget(uint64_t submit_id, RenderCommandB
|
||||
pitch = (rt.pitch.pitch_div8_minus1 + 1u) << 3u;
|
||||
} else if (tile) {
|
||||
if (volume) {
|
||||
pitch = TileGetTexturePitch(transfer_format, width, levels, rt.attrib3.tile_mode);
|
||||
pitch = TileGetTexturePitch(transfer_format, width, rt.attrib3.tile_mode);
|
||||
} else if (standard64) {
|
||||
pitch = TileGetTexturePitch(Prospero::GpuEnumValue(Prospero::BufferFormat::k32Float),
|
||||
width, levels, rt.attrib3.tile_mode);
|
||||
width, rt.attrib3.tile_mode);
|
||||
} else {
|
||||
pitch = TileGetRenderTargetPitch(width, bytes_per_element, rt.attrib.num_fragments);
|
||||
}
|
||||
@@ -192,13 +192,20 @@ void RenderExecutor::ResolveRenderColorTarget(uint64_t submit_id, RenderCommandB
|
||||
pitch = width;
|
||||
}
|
||||
|
||||
TileSizeOffset mip_sizes[16] {};
|
||||
TilePaddedSize mip_padded[16] {};
|
||||
TileVolumeLayout volume_layout {};
|
||||
uint64_t backing_size = 0;
|
||||
TileSizeOffset mip_sizes[16] {};
|
||||
TilePaddedSize mip_padded[16] {};
|
||||
TileSurfaceLayout volume_layout {};
|
||||
uint64_t backing_size = 0;
|
||||
if (volume) {
|
||||
if (!tile || !TileGetTextureVolumeLayout(transfer_format, width, height, depth, levels,
|
||||
rt.attrib3.tile_mode, volume_layout)) {
|
||||
const TileSurfaceDescription description {transfer_format,
|
||||
rt.attrib3.tile_mode,
|
||||
TileSurfaceDimension::Dim3D,
|
||||
width,
|
||||
height,
|
||||
depth,
|
||||
levels,
|
||||
1};
|
||||
if (!tile || !TileGetTiledTextureLayout(description, volume_layout)) {
|
||||
EXIT("unsupported 3D render-target layout: %ux%ux%u levels=%u tile=%u\n", width, height,
|
||||
depth, levels, rt.attrib3.tile_mode);
|
||||
}
|
||||
@@ -209,7 +216,7 @@ void RenderExecutor::ResolveRenderColorTarget(uint64_t submit_id, RenderCommandB
|
||||
bool valid_layout = false;
|
||||
if (standard64) {
|
||||
TileGetTextureSize(Prospero::GpuEnumValue(Prospero::BufferFormat::k32Float), width,
|
||||
height, pitch, levels, rt.attrib3.tile_mode, &layout, mip_sizes,
|
||||
height, levels, rt.attrib3.tile_mode, &layout, mip_sizes,
|
||||
mip_padded);
|
||||
valid_layout = layout.size != 0 && layout.align == 65536;
|
||||
} else {
|
||||
@@ -289,11 +296,12 @@ void RenderExecutor::ResolveRenderColorTarget(uint64_t submit_id, RenderCommandB
|
||||
desc.info.tile_mode = rt.attrib3.tile_mode;
|
||||
for (uint32_t level = 0; level < levels; level++) {
|
||||
if (volume) {
|
||||
const auto& mip = volume_layout.mips[level];
|
||||
desc.info.mip_layout[level] = {
|
||||
volume_layout.level_offsets[level],
|
||||
volume_layout.level_sizes[level],
|
||||
volume_layout.level_widths[level],
|
||||
volume_layout.level_heights[level],
|
||||
mip.offset,
|
||||
mip.size,
|
||||
mip.padded_width,
|
||||
mip.padded_height,
|
||||
};
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -686,14 +686,6 @@ static void McCheck(const HW::ModeControl& c) {
|
||||
}
|
||||
EXIT_NOT_IMPLEMENTED(c.polymode_front_ptype != 0 && c.polymode_front_ptype != 2);
|
||||
EXIT_NOT_IMPLEMENTED(c.polymode_back_ptype != 0 && c.polymode_back_ptype != 2);
|
||||
if (c.poly_offset_front_enable || c.poly_offset_back_enable) {
|
||||
static bool logged = false;
|
||||
if (!logged) {
|
||||
LOGF("\t temporary: PA_SU_SC_MODE_CNTL.POLY_OFFSET_*_ENABLE is not implemented; "
|
||||
"continuing without depth bias\n");
|
||||
logged = true;
|
||||
}
|
||||
}
|
||||
if (c.vtx_window_offset_enable) {
|
||||
static bool logged = false;
|
||||
if (!logged) {
|
||||
|
||||
@@ -663,7 +663,8 @@ Image::Image(GraphicContext& graphics, CommandScheduler& scheduler, const ImageI
|
||||
: info(image_info), m_graphics(&graphics), m_scheduler(&scheduler) {
|
||||
KYTY_PROFILER_FUNCTION();
|
||||
ImageOps::Validate(info);
|
||||
m_cpu_dirty = !info.data.Empty();
|
||||
m_cpu_dirty =
|
||||
!info.data.Empty() && info.metadata.compression == VideoOutCompression::Uncompressed;
|
||||
if (info.pixel_format == vk::Format::eUndefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -154,17 +154,18 @@ public:
|
||||
}
|
||||
[[nodiscard]] uint64_t HashGuestEdges() const;
|
||||
|
||||
ImageInfo info;
|
||||
VulkanImage backing;
|
||||
ImageViewCache views;
|
||||
ImageUsage usage;
|
||||
ImageBinding binding;
|
||||
bool registered = false;
|
||||
uint64_t track_addr = 0;
|
||||
uint64_t track_addr_end = 0;
|
||||
ImageId depth_id {};
|
||||
uint64_t tick_accessed_last = 0;
|
||||
size_t lru_id = 0;
|
||||
ImageInfo info;
|
||||
VulkanImage backing;
|
||||
ImageViewCache views;
|
||||
ImageUsage usage;
|
||||
ImageBinding binding;
|
||||
bool registered = false;
|
||||
mutable uint32_t query_epoch = 0;
|
||||
uint64_t track_addr = 0;
|
||||
uint64_t track_addr_end = 0;
|
||||
ImageId depth_id {};
|
||||
uint64_t tick_accessed_last = 0;
|
||||
size_t lru_id = 0;
|
||||
|
||||
private:
|
||||
friend struct ImageTestAccess;
|
||||
|
||||
@@ -22,6 +22,10 @@ struct RenderTargetFormatMapping {
|
||||
};
|
||||
|
||||
constexpr RenderTargetFormatMapping kRenderTargetFormats[] = {
|
||||
{Prospero::ChannelLayout::k8,
|
||||
Prospero::ChannelType::kUInt,
|
||||
Prospero::ChannelOrder::kStandard,
|
||||
{vk::Format::eR8Uint, 1}},
|
||||
{Prospero::ChannelLayout::k8_8,
|
||||
Prospero::ChannelType::kUNorm,
|
||||
Prospero::ChannelOrder::kStandard,
|
||||
@@ -164,14 +168,6 @@ RenderTargetFormatInfo TextureGetRenderTargetFormat(uint32_t raw_layout, uint32_
|
||||
|
||||
namespace {
|
||||
|
||||
static uint64_t GetLevelSrcOffset(const TileSizeOffset& level_size) {
|
||||
return (level_size.src_size != 0 ? level_size.src_offset : level_size.offset);
|
||||
}
|
||||
|
||||
static uint64_t GetLevelSrcSize(const TileSizeOffset& level_size) {
|
||||
return (level_size.src_size != 0 ? level_size.src_size : level_size.size);
|
||||
}
|
||||
|
||||
static uint32_t GetTextureLevelDepth(uint32_t depth, uint32_t level, bool volume_texture) {
|
||||
return volume_texture ? std::max(depth >> level, 1u) : depth;
|
||||
}
|
||||
@@ -184,20 +180,6 @@ static size_t GetTextureRegionCount(uint32_t depth, uint64_t levels, bool volume
|
||||
return count;
|
||||
}
|
||||
|
||||
uint64_t TextureUploadSliceSourceOffset(const TextureUploadLayout& layout, uint32_t level,
|
||||
uint32_t slice) {
|
||||
if (level >= 16 || layout.level_sizes[level].size == 0) {
|
||||
EXIT("invalid texture upload slice source, level=%u slice=%u\n", level, slice);
|
||||
}
|
||||
const auto level_offset = GetLevelSrcOffset(layout.level_sizes[level]);
|
||||
const auto slice_stride =
|
||||
layout.source_slice_stride != 0 ? layout.source_slice_stride : layout.slice_stride;
|
||||
if (slice_stride != 0 && slice > (UINT64_MAX - level_offset) / slice_stride) {
|
||||
EXIT("texture upload slice source offset overflow, level=%u slice=%u\n", level, slice);
|
||||
}
|
||||
return level_offset + static_cast<uint64_t>(slice) * slice_stride;
|
||||
}
|
||||
|
||||
vk::ComponentSwizzle TextureGetComponentSwizzle(uint8_t s) {
|
||||
switch (static_cast<Prospero::CompSwizzle>(s)) {
|
||||
case Prospero::CompSwizzle::kZero: return vk::ComponentSwizzle::eZero;
|
||||
@@ -237,12 +219,11 @@ vk::Format TextureGetFormat(uint32_t fmt) {
|
||||
|
||||
namespace {
|
||||
|
||||
uint64_t CalcTextureSliceStride(const TileSizeOffset* level_sizes, uint64_t levels,
|
||||
uint64_t CalcTextureSliceStride(const TextureUploadMipLayout* mips, uint64_t levels,
|
||||
uint64_t total_size, uint32_t depth) {
|
||||
uint64_t stride = 0;
|
||||
for (uint32_t i = 0; i < levels; i++) {
|
||||
stride =
|
||||
std::max(stride, static_cast<uint64_t>(level_sizes[i].offset) + level_sizes[i].size);
|
||||
stride = std::max(stride, mips[i].offset + mips[i].size);
|
||||
}
|
||||
|
||||
if (depth > 1 && total_size != 0 && total_size % depth == 0) {
|
||||
@@ -255,39 +236,26 @@ uint64_t CalcTextureSliceStride(const TileSizeOffset* level_sizes, uint64_t leve
|
||||
return stride;
|
||||
}
|
||||
|
||||
uint64_t CalcLinearUploadLevelSize(uint32_t fmt, uint32_t pitch, uint32_t height) {
|
||||
if (const uint32_t bytes_per_element = Prospero::NumBytesPerElement(fmt);
|
||||
bytes_per_element != 0) {
|
||||
return static_cast<uint64_t>(pitch) * height * bytes_per_element;
|
||||
}
|
||||
|
||||
if (const uint32_t bytes_per_block = Prospero::BlockCompressedBytesPerBlock(fmt);
|
||||
bytes_per_block != 0) {
|
||||
const uint32_t blocks_w = std::max((pitch + 3u) / 4u, 1u);
|
||||
const uint32_t blocks_h = std::max((height + 3u) / 4u, 1u);
|
||||
return static_cast<uint64_t>(blocks_w) * blocks_h * bytes_per_block;
|
||||
}
|
||||
|
||||
return 0;
|
||||
uint64_t CalcLinearUploadLevelSize(const TileTextureElementLayout& element, uint32_t pitch,
|
||||
uint32_t height) {
|
||||
const uint32_t elements_w =
|
||||
std::max((pitch + element.texel_width - 1u) / element.texel_width, 1u);
|
||||
const uint32_t elements_h =
|
||||
std::max((height + element.texel_height - 1u) / element.texel_height, 1u);
|
||||
return static_cast<uint64_t>(elements_w) * elements_h * element.bytes;
|
||||
}
|
||||
|
||||
uint64_t SetLinearUploadLevels(TileSizeOffset* level_sizes, uint32_t fmt, uint64_t height,
|
||||
uint64_t SetLinearUploadLevels(TextureUploadMipLayout* mips,
|
||||
const TileTextureElementLayout& element, uint64_t height,
|
||||
uint64_t levels, uint32_t base_pitch) {
|
||||
uint64_t offset = 0;
|
||||
auto pitch = base_pitch;
|
||||
auto h = static_cast<uint32_t>(height);
|
||||
|
||||
for (uint32_t i = 0; i < levels; i++) {
|
||||
const auto size = CalcLinearUploadLevelSize(fmt, pitch, h);
|
||||
EXIT_NOT_IMPLEMENTED(size > 0xffffffffull);
|
||||
EXIT_NOT_IMPLEMENTED(offset > 0xffffffffull);
|
||||
|
||||
level_sizes[i].size = static_cast<uint32_t>(size);
|
||||
level_sizes[i].offset = static_cast<uint32_t>(offset);
|
||||
level_sizes[i].src_size = 0;
|
||||
level_sizes[i].src_offset = 0;
|
||||
level_sizes[i].x = 0;
|
||||
level_sizes[i].y = 0;
|
||||
const auto size = CalcLinearUploadLevelSize(element, pitch, h);
|
||||
mips[i].size = size;
|
||||
mips[i].offset = offset;
|
||||
|
||||
offset += size;
|
||||
if (pitch > 1) {
|
||||
@@ -303,141 +271,123 @@ uint64_t SetLinearUploadLevels(TileSizeOffset* level_sizes, uint32_t fmt, uint64
|
||||
|
||||
} // namespace
|
||||
|
||||
TextureUploadLayout TextureCalcUploadLayout(uint32_t fmt, uint64_t width, uint64_t height,
|
||||
uint64_t levels, uint32_t depth, uint64_t pitch,
|
||||
uint64_t tile, uint64_t upload_size,
|
||||
bool allow_depth_tile, bool volume_texture,
|
||||
const char* owner) {
|
||||
TextureUploadLayout TextureCalcUploadLayout(uint32_t fmt, uint32_t width, uint32_t height,
|
||||
uint32_t levels, uint32_t depth, uint32_t tile,
|
||||
uint64_t upload_size, bool allow_depth_tile,
|
||||
bool volume_texture, const char* owner) {
|
||||
TextureUploadLayout layout {};
|
||||
layout.tile = static_cast<uint32_t>(tile);
|
||||
layout.pitch = static_cast<uint32_t>(pitch);
|
||||
layout.texel_block = Prospero::BlockCompressedBytesPerBlock(fmt) != 0 ? 4u : 1u;
|
||||
layout.volume_texture = volume_texture;
|
||||
layout.surface.description = {
|
||||
fmt,
|
||||
tile,
|
||||
volume_texture ? TileSurfaceDimension::Dim3D : TileSurfaceDimension::Dim2D,
|
||||
width,
|
||||
height,
|
||||
volume_texture ? depth : 1u,
|
||||
levels,
|
||||
volume_texture ? 1u : depth,
|
||||
};
|
||||
const auto& description = layout.surface.description;
|
||||
const auto tile_mode = static_cast<Prospero::TileMode>(description.tile_mode);
|
||||
TileTextureElementLayout element {};
|
||||
|
||||
if (fmt != 0) {
|
||||
if (layout.tile != 0) {
|
||||
const auto tile_mode = static_cast<Prospero::TileMode>(layout.tile);
|
||||
switch (tile_mode) {
|
||||
case Prospero::TileMode::kStandard256B:
|
||||
if (TileIsStandard256BTextureSupported(fmt)) {
|
||||
layout.tile_family = TileBlockFamily::Standard256B;
|
||||
}
|
||||
break;
|
||||
case Prospero::TileMode::kStandard4KB:
|
||||
if (TileIsStandard4KBTextureSupported(fmt)) {
|
||||
layout.tile_family = TileBlockFamily::Standard4KB;
|
||||
}
|
||||
break;
|
||||
case Prospero::TileMode::kStandard64KB:
|
||||
if (TileIsStandard64KBTextureSupported(fmt)) {
|
||||
layout.tile_family = TileBlockFamily::Standard64KB;
|
||||
}
|
||||
break;
|
||||
case Prospero::TileMode::kPrt:
|
||||
if (TileIsStandard64KBTextureSupported(fmt)) {
|
||||
layout.tile_family = TileBlockFamily::Prt64KB;
|
||||
}
|
||||
break;
|
||||
case Prospero::TileMode::kRenderTarget:
|
||||
if (Prospero::RenderTargetBytesPerElement(fmt) != 0) {
|
||||
layout.tile_family = TileBlockFamily::RenderTarget64KB;
|
||||
}
|
||||
break;
|
||||
case Prospero::TileMode::kDepth:
|
||||
if (allow_depth_tile && Prospero::RenderTargetBytesPerElement(fmt) != 0) {
|
||||
layout.tile_family = TileBlockFamily::Depth64KB;
|
||||
}
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
if (layout.tile_family == TileBlockFamily::Count) {
|
||||
EXIT("%s: unsupported typed tiled upload: fmt=%u tile=%u "
|
||||
"size=%" PRIu64 " extent=%" PRIu64 "x%" PRIu64 " pitch=%" PRIu64
|
||||
" levels=%" PRIu64 "\n",
|
||||
owner, static_cast<uint32_t>(fmt), layout.tile, upload_size, width, height,
|
||||
pitch, levels);
|
||||
}
|
||||
}
|
||||
|
||||
layout.pitch = TileGetTexturePitch(fmt, width, levels, layout.tile);
|
||||
|
||||
TileGetTextureSize(fmt, width, height, layout.pitch, levels, layout.tile, nullptr,
|
||||
layout.level_sizes, layout.padded_sizes);
|
||||
|
||||
if (static_cast<Prospero::TileMode>(layout.tile) != Prospero::TileMode::kLinear) {
|
||||
if (layout.volume_texture) {
|
||||
layout.slice_stride = SetLinearUploadLevels(layout.level_sizes, fmt, height, levels,
|
||||
static_cast<uint32_t>(width));
|
||||
} else {
|
||||
TileSizeOffset tiled_levels[16] {};
|
||||
std::copy_n(layout.level_sizes, levels, tiled_levels);
|
||||
layout.source_slice_stride =
|
||||
CalcTextureSliceStride(tiled_levels, levels, upload_size, depth);
|
||||
SetLinearUploadLevels(layout.level_sizes, fmt, height, levels, layout.pitch);
|
||||
for (uint32_t i = 0; i < levels; ++i) {
|
||||
if (tiled_levels[i].src_size > tiled_levels[i].size) {
|
||||
layout.first_tail_level = std::min(layout.first_tail_level, i);
|
||||
}
|
||||
layout.level_sizes[i].src_offset = GetLevelSrcOffset(tiled_levels[i]);
|
||||
layout.level_sizes[i].src_size = GetLevelSrcSize(tiled_levels[i]);
|
||||
layout.level_sizes[i].x = tiled_levels[i].x;
|
||||
layout.level_sizes[i].y = tiled_levels[i].y;
|
||||
}
|
||||
}
|
||||
} else if (layout.volume_texture) {
|
||||
layout.slice_stride =
|
||||
CalcTextureSliceStride(layout.level_sizes, levels, upload_size, depth);
|
||||
}
|
||||
} else {
|
||||
if (fmt == 0) {
|
||||
EXIT("%s: legacy texture upload format unsupported: fmt=0 tile=%u size=%" PRIu64
|
||||
" extent=%" PRIu64 "x%" PRIu64 " pitch=%" PRIu64 " levels=%" PRIu64 "\n",
|
||||
owner, layout.tile, upload_size, width, height, pitch, levels);
|
||||
" extent=%ux%u levels=%u\n",
|
||||
owner, description.tile_mode, upload_size, width, height, levels);
|
||||
}
|
||||
|
||||
if (!layout.volume_texture) {
|
||||
layout.slice_stride =
|
||||
CalcTextureSliceStride(layout.level_sizes, levels, upload_size, depth);
|
||||
switch (tile_mode) {
|
||||
case Prospero::TileMode::kLinear:
|
||||
if (!TileGetTextureElementLayout(fmt, element)) {
|
||||
EXIT("%s: unsupported linear texture format: fmt=%u\n", owner, fmt);
|
||||
}
|
||||
break;
|
||||
case Prospero::TileMode::kDepth:
|
||||
if (!allow_depth_tile || !TileGetTiledTextureLayout(description, layout.surface)) {
|
||||
EXIT("%s: unsupported typed tiled upload: fmt=%u tile=%u "
|
||||
"size=%" PRIu64 " extent=%ux%u levels=%u\n",
|
||||
owner, static_cast<uint32_t>(fmt), description.tile_mode, upload_size, width,
|
||||
height, levels);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (!TileGetTiledTextureLayout(description, layout.surface)) {
|
||||
EXIT("%s: unsupported typed tiled upload: fmt=%u tile=%u "
|
||||
"size=%" PRIu64 " extent=%ux%u levels=%u\n",
|
||||
owner, static_cast<uint32_t>(fmt), description.tile_mode, upload_size, width,
|
||||
height, levels);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (tile_mode != Prospero::TileMode::kLinear) {
|
||||
element = {layout.surface.texture.block.bytes_per_element,
|
||||
layout.surface.texture.texel_width, layout.surface.texture.texel_height};
|
||||
}
|
||||
layout.pitch = TileGetTexturePitch(fmt, width, description.tile_mode);
|
||||
if (tile_mode == Prospero::TileMode::kLinear) {
|
||||
TileSizeOffset level_sizes[16] {};
|
||||
TilePaddedSize padded_sizes[16] {};
|
||||
TileGetTextureSize(fmt, width, height, levels, description.tile_mode, nullptr, level_sizes,
|
||||
padded_sizes);
|
||||
for (uint32_t level = 0; level < levels; ++level) {
|
||||
layout.mips[level] = {level_sizes[level].offset, level_sizes[level].size,
|
||||
padded_sizes[level].width, padded_sizes[level].height};
|
||||
}
|
||||
} else if (volume_texture) {
|
||||
layout.slice_stride = SetLinearUploadLevels(layout.mips, element, height, levels, width);
|
||||
} else {
|
||||
layout.source_slice_stride = layout.surface.block_slice_size;
|
||||
if (depth > 1 && upload_size != 0 && upload_size % depth == 0) {
|
||||
layout.source_slice_stride = std::max(layout.source_slice_stride, upload_size / depth);
|
||||
}
|
||||
SetLinearUploadLevels(layout.mips, element, height, levels, layout.pitch);
|
||||
}
|
||||
|
||||
if (!volume_texture || tile_mode == Prospero::TileMode::kLinear) {
|
||||
layout.slice_stride = CalcTextureSliceStride(layout.mips, levels, upload_size, depth);
|
||||
}
|
||||
return layout;
|
||||
}
|
||||
|
||||
std::vector<vk::BufferImageCopy> TextureBuildImageCopies(const TextureUploadLayout& layout,
|
||||
uint32_t width, uint32_t height,
|
||||
uint32_t depth, uint64_t levels,
|
||||
bool array_texture, bool volume_texture) {
|
||||
uint32_t mip_width = width;
|
||||
uint32_t mip_height = height;
|
||||
uint32_t mip_pitch = volume_texture && static_cast<Prospero::TileMode>(layout.tile) !=
|
||||
Prospero::TileMode::kLinear
|
||||
? width
|
||||
: layout.pitch;
|
||||
std::vector<vk::BufferImageCopy> TextureBuildImageCopies(const TextureUploadLayout& layout) {
|
||||
const auto& description = layout.surface.description;
|
||||
const bool volume_texture = description.dimension == TileSurfaceDimension::Dim3D;
|
||||
const auto depth = volume_texture ? description.depth : description.layers;
|
||||
uint32_t mip_width = description.width;
|
||||
uint32_t mip_height = description.height;
|
||||
uint32_t mip_pitch = volume_texture && static_cast<Prospero::TileMode>(description.tile_mode) !=
|
||||
Prospero::TileMode::kLinear
|
||||
? description.width
|
||||
: layout.pitch;
|
||||
|
||||
std::vector<vk::BufferImageCopy> regions;
|
||||
regions.reserve(GetTextureRegionCount(depth, levels, volume_texture));
|
||||
for (uint32_t i = 0; i < levels; i++) {
|
||||
EXIT_NOT_IMPLEMENTED(layout.level_sizes[i].size == 0);
|
||||
regions.reserve(GetTextureRegionCount(depth, description.levels, volume_texture));
|
||||
for (uint32_t i = 0; i < description.levels; i++) {
|
||||
EXIT_NOT_IMPLEMENTED(layout.mips[i].size == 0);
|
||||
|
||||
const auto mip_depth = GetTextureLevelDepth(depth, i, volume_texture);
|
||||
|
||||
for (uint32_t z = 0; z < mip_depth; z++) {
|
||||
const auto slice_offset = z * layout.slice_stride;
|
||||
vk::BufferImageCopy region {};
|
||||
region.bufferOffset = layout.level_sizes[i].offset + slice_offset;
|
||||
region.imageSubresource = {vk::ImageAspectFlagBits::eColor, i, array_texture ? z : 0,
|
||||
region.bufferOffset = layout.mips[i].offset + slice_offset;
|
||||
region.imageSubresource = {vk::ImageAspectFlagBits::eColor, i, volume_texture ? 0u : z,
|
||||
1};
|
||||
region.imageOffset.z = volume_texture ? static_cast<int>(z) : 0;
|
||||
region.imageExtent = {mip_width, mip_height, 1};
|
||||
const bool linear =
|
||||
static_cast<Prospero::TileMode>(layout.tile) == Prospero::TileMode::kLinear;
|
||||
const bool linear = static_cast<Prospero::TileMode>(description.tile_mode) ==
|
||||
Prospero::TileMode::kLinear;
|
||||
if (linear) {
|
||||
region.bufferRowLength = layout.padded_sizes[i].width;
|
||||
region.bufferImageHeight = layout.padded_sizes[i].height;
|
||||
region.bufferRowLength = layout.mips[i].row_length;
|
||||
region.bufferImageHeight = layout.mips[i].image_height;
|
||||
} else {
|
||||
const auto align = [](uint32_t value, uint32_t block) {
|
||||
const auto texel_width = layout.surface.texture.texel_width;
|
||||
const auto align = [](uint32_t value, uint32_t block) {
|
||||
return ((value + block - 1u) / block) * block;
|
||||
};
|
||||
const auto pitch = align(mip_pitch, layout.texel_block);
|
||||
region.bufferRowLength = pitch > align(mip_width, layout.texel_block) ? pitch : 0;
|
||||
const auto pitch = align(mip_pitch, texel_width);
|
||||
region.bufferRowLength = pitch > align(mip_width, texel_width) ? pitch : 0;
|
||||
}
|
||||
regions.push_back(region);
|
||||
}
|
||||
@@ -456,24 +406,6 @@ std::vector<vk::BufferImageCopy> TextureBuildImageCopies(const TextureUploadLayo
|
||||
return regions;
|
||||
}
|
||||
|
||||
struct GpuTileElementLayout {
|
||||
uint32_t bytes = 0;
|
||||
uint32_t wide = 1;
|
||||
uint32_t tall = 1;
|
||||
};
|
||||
|
||||
static bool GetGpuTileElementLayout(uint32_t fmt, GpuTileElementLayout& out) {
|
||||
if (const auto bytes = Prospero::NumBytesPerElement(fmt); bytes != 0) {
|
||||
out = {bytes, 1, 1};
|
||||
return true;
|
||||
}
|
||||
if (const auto bytes = Prospero::BlockCompressedBytesPerBlock(fmt); bytes != 0) {
|
||||
out = {bytes, 4, 4};
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool SetGpuTileSize(uint64_t offset, uint64_t length, uint64_t capacity, uint64_t& size) {
|
||||
if (offset > capacity || length > capacity - offset) {
|
||||
return false;
|
||||
@@ -483,42 +415,32 @@ static bool SetGpuTileSize(uint64_t offset, uint64_t length, uint64_t capacity,
|
||||
}
|
||||
|
||||
bool TextureBuildGpuTileInfos(uint64_t tiled_size, const std::vector<vk::BufferImageCopy>& regions,
|
||||
const TextureUploadLayout& layout, uint32_t fmt, uint32_t depth,
|
||||
uint64_t levels, std::vector<GpuTileInfo>& out_infos) {
|
||||
const TextureUploadLayout& layout, uint32_t levels,
|
||||
std::vector<GpuTileInfo>& out_infos) {
|
||||
const auto& description = layout.surface.description;
|
||||
const bool volume_texture = description.dimension == TileSurfaceDimension::Dim3D;
|
||||
const auto depth = volume_texture ? description.depth : description.layers;
|
||||
if (tiled_size == 0 || levels == 0 || levels > 16 || depth == 0 ||
|
||||
regions.size() != GetTextureRegionCount(depth, levels, layout.volume_texture) ||
|
||||
Prospero::IsFmaskTextureFormat(fmt)) {
|
||||
regions.size() != GetTextureRegionCount(depth, levels, volume_texture) ||
|
||||
Prospero::IsFmaskTextureFormat(description.format)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
GpuTileElementLayout element {};
|
||||
if (layout.tile_family == TileBlockFamily::RenderTarget64KB ||
|
||||
layout.tile_family == TileBlockFamily::Depth64KB) {
|
||||
element.bytes = Prospero::RenderTargetBytesPerElement(fmt);
|
||||
} else if (!GetGpuTileElementLayout(fmt, element)) {
|
||||
return false;
|
||||
}
|
||||
if (element.bytes == 0) {
|
||||
const auto& surface = layout.surface;
|
||||
const auto& texture = surface.texture;
|
||||
const auto& block = texture.block;
|
||||
if (surface.description.levels < levels || block.bytes_per_element == 0 ||
|
||||
block.family == TileBlockFamily::Count) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<GpuTileInfo> infos;
|
||||
infos.reserve(regions.size());
|
||||
if (layout.volume_texture) {
|
||||
TileVolumeLayout volume {};
|
||||
if (!TileGetTextureVolumeLayout(fmt, regions[0].imageExtent.width,
|
||||
regions[0].imageExtent.height, depth,
|
||||
static_cast<uint32_t>(levels), layout.tile, volume)) {
|
||||
return false;
|
||||
}
|
||||
element = {volume.bytes_per_element, volume.texel_width, volume.texel_height};
|
||||
TileBlockLayout block {};
|
||||
if (!TileGetBlockLayout(volume.family, element.bytes, block)) return false;
|
||||
|
||||
if (volume_texture) {
|
||||
size_t region_base = 0;
|
||||
for (uint32_t level = 0; level < levels; ++level) {
|
||||
const uint32_t mip_depth = GetTextureLevelDepth(depth, level, true);
|
||||
const bool tail = level >= volume.first_tail_level;
|
||||
const bool tail = level >= surface.first_tail_level;
|
||||
const uint64_t linear_stride = layout.slice_stride;
|
||||
for (uint32_t z = 0; z < mip_depth; z += block.block_depth) {
|
||||
const uint32_t copy_depth = std::min(block.block_depth, mip_depth - z);
|
||||
@@ -533,50 +455,43 @@ bool TextureBuildGpuTileInfos(uint64_t tiled_size, const std::vector<vk::BufferI
|
||||
info.bytes_per_element = block.bytes_per_element;
|
||||
info.linear_offset = region.bufferOffset;
|
||||
info.tiled_offset =
|
||||
static_cast<uint64_t>(z / block.block_depth) * volume.block_slice_size +
|
||||
volume.level_offsets[level];
|
||||
static_cast<uint64_t>(z / block.block_depth) * surface.block_slice_size +
|
||||
surface.mips[level].offset;
|
||||
const uint64_t linear_span =
|
||||
static_cast<uint64_t>(copy_depth - 1u) * linear_stride +
|
||||
layout.level_sizes[level].size;
|
||||
layout.mips[level].size;
|
||||
if (!SetGpuTileSize(info.linear_offset, linear_span, UINT64_MAX,
|
||||
info.linear_size) ||
|
||||
!SetGpuTileSize(info.tiled_offset, volume.level_sizes[level], tiled_size,
|
||||
!SetGpuTileSize(info.tiled_offset, surface.mips[level].size, tiled_size,
|
||||
info.tiled_size)) {
|
||||
return false;
|
||||
}
|
||||
info.linear_slice_stride = linear_stride;
|
||||
info.width =
|
||||
std::max((region.imageExtent.width + element.wide - 1u) / element.wide, 1u);
|
||||
info.height = std::max((logical_height + element.tall - 1u) / element.tall, 1u);
|
||||
info.depth = copy_depth;
|
||||
info.width = std::max((region.imageExtent.width + texture.texel_width - 1u) /
|
||||
texture.texel_width,
|
||||
1u);
|
||||
info.height = std::max(
|
||||
(logical_height + texture.texel_height - 1u) / texture.texel_height, 1u);
|
||||
info.depth = copy_depth;
|
||||
info.surface_z =
|
||||
block.block_depth == 1 ? static_cast<uint32_t>(region.imageOffset.z) : 0;
|
||||
info.pitch = std::max((pitch + element.wide - 1u) / element.wide, 1u);
|
||||
info.tail_x = tail ? volume.tail_x[level] : 0;
|
||||
info.tail_y = tail ? volume.tail_y[level] : 0;
|
||||
info.pitch = std::max((pitch + texture.texel_width - 1u) / texture.texel_width, 1u);
|
||||
info.tail_x = tail ? surface.mips[level].tail_x : 0;
|
||||
info.tail_y = tail ? surface.mips[level].tail_y : 0;
|
||||
info.tail = tail;
|
||||
info.tiled_width = volume.level_widths[level];
|
||||
info.tiled_height = volume.level_heights[level];
|
||||
info.tiled_width = surface.mips[level].padded_width;
|
||||
info.tiled_height = surface.mips[level].padded_height;
|
||||
infos.push_back(info);
|
||||
}
|
||||
region_base += mip_depth;
|
||||
}
|
||||
} else {
|
||||
const auto base_family = layout.tile_family;
|
||||
if (base_family == TileBlockFamily::Count) {
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t region_index = 0;
|
||||
for (uint32_t level = 0; level < levels; level++) {
|
||||
const auto& level_size = layout.level_sizes[level];
|
||||
const bool tail = level >= layout.first_tail_level;
|
||||
const auto family = base_family;
|
||||
TileBlockLayout block {};
|
||||
if (!TileGetBlockLayout(family, element.bytes, block)) {
|
||||
return false;
|
||||
}
|
||||
const auto level_depth = GetTextureLevelDepth(depth, level, layout.volume_texture);
|
||||
const auto& level_size = layout.mips[level];
|
||||
const auto& mip = surface.mips[level];
|
||||
const bool tail = level >= surface.first_tail_level;
|
||||
const auto level_depth = GetTextureLevelDepth(depth, level, false);
|
||||
for (uint32_t z = 0; z < level_depth; z++) {
|
||||
const auto& region = regions[region_index++];
|
||||
const auto pitch =
|
||||
@@ -585,39 +500,36 @@ bool TextureBuildGpuTileInfos(uint64_t tiled_size, const std::vector<vk::BufferI
|
||||
? region.bufferImageHeight
|
||||
: region.imageExtent.height;
|
||||
GpuTileInfo info {};
|
||||
info.family = block.family;
|
||||
info.bytes_per_element = block.bytes_per_element;
|
||||
info.linear_offset = region.bufferOffset;
|
||||
info.tiled_offset = TextureUploadSliceSourceOffset(layout, level, z);
|
||||
if (!SetGpuTileSize(info.linear_offset, level_size.size, UINT64_MAX,
|
||||
info.linear_size) ||
|
||||
!SetGpuTileSize(info.tiled_offset, GetLevelSrcSize(level_size), tiled_size,
|
||||
info.tiled_size)) {
|
||||
info.family = block.family;
|
||||
info.bytes_per_element = block.bytes_per_element;
|
||||
info.linear_offset = region.bufferOffset;
|
||||
const auto source_stride = layout.source_slice_stride != 0
|
||||
? layout.source_slice_stride
|
||||
: surface.block_slice_size;
|
||||
if (z > (UINT64_MAX - mip.offset) / source_stride) {
|
||||
return false;
|
||||
}
|
||||
info.width =
|
||||
std::max((region.imageExtent.width + element.wide - 1u) / element.wide, 1u);
|
||||
info.height = std::max((logical_height + element.tall - 1u) / element.tall, 1u);
|
||||
info.surface_z = base_family == TileBlockFamily::RenderTarget64KB ||
|
||||
base_family == TileBlockFamily::Depth64KB
|
||||
info.tiled_offset = mip.offset + static_cast<uint64_t>(z) * source_stride;
|
||||
if (!SetGpuTileSize(info.linear_offset, level_size.size, UINT64_MAX,
|
||||
info.linear_size) ||
|
||||
!SetGpuTileSize(info.tiled_offset, mip.size, tiled_size, info.tiled_size)) {
|
||||
return false;
|
||||
}
|
||||
info.width = std::max((region.imageExtent.width + texture.texel_width - 1u) /
|
||||
texture.texel_width,
|
||||
1u);
|
||||
info.height = std::max(
|
||||
(logical_height + texture.texel_height - 1u) / texture.texel_height, 1u);
|
||||
info.surface_z = block.family == TileBlockFamily::RenderTarget64KB ||
|
||||
block.family == TileBlockFamily::Depth64KB
|
||||
? region.imageSubresource.baseArrayLayer
|
||||
: 0;
|
||||
info.pitch = std::max((pitch + element.wide - 1u) / element.wide, 1u);
|
||||
info.tail = tail;
|
||||
info.tail_x = tail ? level_size.x : 0;
|
||||
info.tail_y = tail ? level_size.y : 0;
|
||||
info.tiled_width =
|
||||
layout.padded_sizes[level].width != 0
|
||||
? std::max((layout.padded_sizes[level].width + element.wide - 1u) /
|
||||
element.wide,
|
||||
1u)
|
||||
: info.pitch;
|
||||
info.tiled_height =
|
||||
layout.padded_sizes[level].height != 0
|
||||
? std::max((layout.padded_sizes[level].height + element.tall - 1u) /
|
||||
element.tall,
|
||||
1u)
|
||||
: info.height;
|
||||
info.pitch = std::max((pitch + texture.texel_width - 1u) / texture.texel_width, 1u);
|
||||
info.tail = tail;
|
||||
info.tail_x = tail ? mip.tail_x : 0;
|
||||
info.tail_y = tail ? mip.tail_y : 0;
|
||||
info.tiled_width = mip.padded_width;
|
||||
info.tiled_height = mip.padded_height;
|
||||
infos.push_back(info);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,34 +19,32 @@ struct RenderTargetFormatInfo {
|
||||
Prospero::ColorComponentMapping export_mapping;
|
||||
};
|
||||
|
||||
struct TextureUploadMipLayout {
|
||||
uint64_t offset = 0;
|
||||
uint64_t size = 0;
|
||||
uint32_t row_length = 0;
|
||||
uint32_t image_height = 0;
|
||||
};
|
||||
|
||||
struct TextureUploadLayout {
|
||||
uint32_t tile = 0;
|
||||
uint32_t pitch = 0;
|
||||
uint32_t texel_block = 1;
|
||||
uint64_t slice_stride = 0;
|
||||
uint64_t source_slice_stride = 0;
|
||||
uint32_t first_tail_level = 16;
|
||||
TileBlockFamily tile_family = TileBlockFamily::Count;
|
||||
bool volume_texture = false;
|
||||
TileSizeOffset level_sizes[16] = {};
|
||||
TilePaddedSize padded_sizes[16] = {};
|
||||
uint32_t pitch = 0;
|
||||
uint64_t slice_stride = 0;
|
||||
uint64_t source_slice_stride = 0;
|
||||
TileSurfaceLayout surface;
|
||||
TextureUploadMipLayout mips[16] = {};
|
||||
};
|
||||
|
||||
vk::ComponentMapping TextureGetComponentMapping(uint32_t swizzle);
|
||||
vk::Format TextureGetFormat(uint32_t fmt);
|
||||
RenderTargetFormatInfo TextureGetRenderTargetFormat(uint32_t layout, uint32_t type, uint32_t order);
|
||||
TextureUploadLayout TextureCalcUploadLayout(uint32_t fmt, uint64_t width, uint64_t height,
|
||||
uint64_t levels, uint32_t depth, uint64_t pitch,
|
||||
uint64_t tile, uint64_t upload_size,
|
||||
bool allow_depth_tile, bool volume_texture,
|
||||
const char* owner);
|
||||
std::vector<vk::BufferImageCopy> TextureBuildImageCopies(const TextureUploadLayout& layout,
|
||||
uint32_t width, uint32_t height,
|
||||
uint32_t depth, uint64_t levels,
|
||||
bool array_texture, bool volume_texture);
|
||||
TextureUploadLayout TextureCalcUploadLayout(uint32_t fmt, uint32_t width, uint32_t height,
|
||||
uint32_t levels, uint32_t depth, uint32_t tile,
|
||||
uint64_t upload_size, bool allow_depth_tile,
|
||||
bool volume_texture, const char* owner);
|
||||
std::vector<vk::BufferImageCopy> TextureBuildImageCopies(const TextureUploadLayout& layout);
|
||||
bool TextureBuildGpuTileInfos(uint64_t tiled_size, const std::vector<vk::BufferImageCopy>& regions,
|
||||
const TextureUploadLayout& layout, uint32_t fmt, uint32_t depth,
|
||||
uint64_t levels, std::vector<GpuTileInfo>& infos);
|
||||
const TextureUploadLayout& layout, uint32_t levels,
|
||||
std::vector<GpuTileInfo>& infos);
|
||||
|
||||
} // namespace Libs::Graphics
|
||||
|
||||
|
||||
@@ -239,7 +239,7 @@ bool IsSupportedDepthTargetDescriptor(const ShaderTextureResource& descriptor, c
|
||||
const auto samples = multisampled ? 1u << descriptor.LastLevel() : 1u;
|
||||
const auto pitch =
|
||||
multisampled ? TileGetDepthPitch(width, image.info.bytes_per_block, descriptor.LastLevel())
|
||||
: TileGetTexturePitch(descriptor.Format(), width, 1, descriptor.TileMode());
|
||||
: TileGetTexturePitch(descriptor.Format(), width, descriptor.TileMode());
|
||||
const bool supported_2d = type == Prospero::ImageType::kColor2D &&
|
||||
image.info.resources.layers == 1 && descriptor.Depth() == 0 &&
|
||||
descriptor.BaseArray5() == 0;
|
||||
@@ -321,7 +321,7 @@ static void ValidateDepthTargetBinding(const ShaderRecompiler::IR::ImageResource
|
||||
return;
|
||||
}
|
||||
const auto descriptor_pitch =
|
||||
TileGetTexturePitch(descriptor.Format(), static_cast<uint32_t>(descriptor.Width5()) + 1u, 1,
|
||||
TileGetTexturePitch(descriptor.Format(), static_cast<uint32_t>(descriptor.Width5()) + 1u,
|
||||
descriptor.TileMode());
|
||||
EXIT("unsupported sampled depth target: resource=%d descriptor=%d encoding=%d format=%d "
|
||||
"kind=%u dimension=%u mip_mode=%u read=%d written=%d atomic=%d compare=%d "
|
||||
@@ -373,21 +373,33 @@ static bool IsSupportedStorageTextureDescriptor(const ShaderRecompiler::IR::Imag
|
||||
const bool is_3d = resource.dimension == ShaderRecompiler::Decoder::ImageDimension::Dim3D &&
|
||||
descriptor.Type() == Prospero::GpuEnumValue(Prospero::ImageType::kColor3D) &&
|
||||
descriptor.BaseArray5() == 0;
|
||||
TileBlockLayout depth_block {};
|
||||
const auto depth_bpe = Prospero::RenderTargetBytesPerElement(descriptor.Format());
|
||||
const bool supported_depth_tile =
|
||||
tile == Prospero::GpuEnumValue(Prospero::TileMode::kDepth) && !resource.read &&
|
||||
!Prospero::IsFmaskTextureFormat(descriptor.Format()) && (is_2d || is_2d_array) &&
|
||||
TileGetBlockLayout(TileBlockFamily::Depth64KB, depth_bpe, depth_block);
|
||||
const bool supported_standard_tile =
|
||||
(tile == Prospero::GpuEnumValue(Prospero::TileMode::kStandard4KB) &&
|
||||
TileIsStandard4KBTextureSupported(descriptor.Format())) ||
|
||||
(tile == Prospero::GpuEnumValue(Prospero::TileMode::kStandard64KB) &&
|
||||
TileIsStandard64KBTextureSupported(descriptor.Format()));
|
||||
const bool supported_tile = tile == Prospero::GpuEnumValue(Prospero::TileMode::kLinear) ||
|
||||
tile == Prospero::GpuEnumValue(Prospero::TileMode::kRenderTarget) ||
|
||||
supported_depth_tile || supported_standard_tile;
|
||||
const auto swizzle = descriptor.DstSelXYZW();
|
||||
TileTextureBlockLayout tile_layout {};
|
||||
bool supported_tile = false;
|
||||
switch (static_cast<Prospero::TileMode>(tile)) {
|
||||
case Prospero::TileMode::kLinear: supported_tile = true; break;
|
||||
case Prospero::TileMode::kDepth:
|
||||
supported_tile =
|
||||
!resource.read && !Prospero::IsFmaskTextureFormat(descriptor.Format()) &&
|
||||
(is_2d || is_2d_array) &&
|
||||
TileGetTextureBlockLayout(descriptor.Format(), tile, false, tile_layout);
|
||||
break;
|
||||
case Prospero::TileMode::kStandard256B:
|
||||
supported_tile =
|
||||
(is_2d || is_2d_array) &&
|
||||
TileGetTextureBlockLayout(descriptor.Format(), tile, false, tile_layout);
|
||||
break;
|
||||
case Prospero::TileMode::kStandard4KB:
|
||||
case Prospero::TileMode::kStandard64KB:
|
||||
supported_tile =
|
||||
TileGetTextureBlockLayout(descriptor.Format(), tile, is_3d, tile_layout);
|
||||
break;
|
||||
case Prospero::TileMode::kRenderTarget:
|
||||
supported_tile =
|
||||
TileGetTextureBlockLayout(descriptor.Format(), tile, false, tile_layout);
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
const auto swizzle = descriptor.DstSelXYZW();
|
||||
const bool supported_swizzle =
|
||||
IsValidImageSwizzle(swizzle) &&
|
||||
(swizzle == DstSel(4, 5, 6, 7) || !resource.read || resource.atomic);
|
||||
@@ -493,18 +505,20 @@ static TextureCache::ImageDesc NullTextureDesc(const ShaderRecompiler::IR::Image
|
||||
|
||||
static void PopulateTextureMipLayout(ImageInfo& info) {
|
||||
if (info.IsVolume() && info.tile_mode != Prospero::GpuEnumValue(Prospero::TileMode::kLinear)) {
|
||||
TileVolumeLayout volume {};
|
||||
if (!TileGetTextureVolumeLayout(info.guest_format, info.extent.width, info.extent.height,
|
||||
info.extent.depth, info.resources.levels, info.tile_mode,
|
||||
volume)) {
|
||||
TileSurfaceLayout surface {};
|
||||
const TileSurfaceDescription description {
|
||||
info.guest_format, info.tile_mode, TileSurfaceDimension::Dim3D, info.extent.width,
|
||||
info.extent.height, info.extent.depth, info.resources.levels, 1};
|
||||
if (!TileGetTiledTextureLayout(description, surface)) {
|
||||
EXIT("unsupported normalized volume texture layout\n");
|
||||
}
|
||||
for (uint32_t level = 0; level < info.resources.levels; level++) {
|
||||
const auto& mip = surface.mips[level];
|
||||
info.mip_layout[level] = {
|
||||
volume.level_offsets[level],
|
||||
volume.level_sizes[level],
|
||||
volume.level_widths[level],
|
||||
volume.level_heights[level],
|
||||
mip.offset,
|
||||
mip.size,
|
||||
mip.padded_width,
|
||||
mip.padded_height,
|
||||
};
|
||||
}
|
||||
return;
|
||||
@@ -512,7 +526,7 @@ static void PopulateTextureMipLayout(ImageInfo& info) {
|
||||
|
||||
TileSizeOffset levels[16] {};
|
||||
TilePaddedSize padded[16] {};
|
||||
TileGetTextureSize(info.guest_format, info.extent.width, info.extent.height, info.pitch,
|
||||
TileGetTextureSize(info.guest_format, info.extent.width, info.extent.height,
|
||||
info.resources.levels, info.tile_mode, nullptr, levels, padded);
|
||||
for (uint32_t level = 0; level < info.resources.levels; level++) {
|
||||
const auto offset =
|
||||
@@ -670,9 +684,9 @@ RenderExecutor::ResolveTexture(const ShaderRecompiler::IR::ImageResource& reso
|
||||
}
|
||||
size.size *= image_layers;
|
||||
} else {
|
||||
pitch = TileGetTexturePitch(format, width, levels, tile);
|
||||
TileGetTextureTotalSize(format, width, height, volume ? depth : image_layers, pitch, levels,
|
||||
tile, volume, size);
|
||||
pitch = TileGetTexturePitch(format, width, tile);
|
||||
TileGetTextureTotalSize(format, width, height, volume ? depth : image_layers, levels, tile,
|
||||
volume, size);
|
||||
}
|
||||
EXIT_NOT_IMPLEMENTED(size.size == 0 || size.align == 0 ||
|
||||
(address & (static_cast<uint64_t>(size.align) - 1u)) != 0);
|
||||
@@ -919,22 +933,21 @@ RenderExecutor::PrepareGraphicsBindings(CommandBuffer& buffer, const ShaderStage
|
||||
return bindings;
|
||||
}
|
||||
|
||||
static void RetainBindings(CommandBuffer& buffer,
|
||||
const DescriptorCache::NativeDescriptors& resources) {
|
||||
static void RetainBindings(CommandBuffer& buffer, DescriptorCache::NativeDescriptors& resources) {
|
||||
if (resources.flattened_srt.owner != nullptr) {
|
||||
buffer.RetainResourceUntilFence(resources.flattened_srt.owner);
|
||||
buffer.RetainResourceUntilFence(std::move(resources.flattened_srt.owner));
|
||||
}
|
||||
if (resources.user_data.owner != nullptr) {
|
||||
buffer.RetainResourceUntilFence(resources.user_data.owner);
|
||||
buffer.RetainResourceUntilFence(std::move(resources.user_data.owner));
|
||||
}
|
||||
for (const auto& view: resources.buffers) {
|
||||
for (auto& view: resources.buffers) {
|
||||
if (view.owner != nullptr) {
|
||||
buffer.RetainResourceUntilFence(view.owner);
|
||||
buffer.RetainResourceUntilFence(std::move(view.owner));
|
||||
}
|
||||
}
|
||||
for (const auto& view: resources.addresses) {
|
||||
for (auto& view: resources.addresses) {
|
||||
if (view.owner != nullptr) {
|
||||
buffer.RetainResourceUntilFence(view.owner);
|
||||
buffer.RetainResourceUntilFence(std::move(view.owner));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,22 @@ VulkanMemoryBarrier MakeShaderWriteDependency() {
|
||||
return barrier;
|
||||
}
|
||||
|
||||
VulkanMemoryBarrier MakeShaderAccessDependency() {
|
||||
VulkanMemoryBarrier barrier {};
|
||||
barrier.sType = vk::StructureType::eMemoryBarrier;
|
||||
barrier.srcAccessMask = vk::AccessFlagBits::eShaderRead | vk::AccessFlagBits::eShaderWrite;
|
||||
barrier.dstAccessMask = vk::AccessFlagBits::eMemoryRead | vk::AccessFlagBits::eMemoryWrite;
|
||||
return barrier;
|
||||
}
|
||||
|
||||
VulkanMemoryBarrier MakeShaderWriteHazardDependency() {
|
||||
VulkanMemoryBarrier barrier {};
|
||||
barrier.sType = vk::StructureType::eMemoryBarrier;
|
||||
barrier.srcAccessMask = vk::AccessFlagBits::eMemoryRead | vk::AccessFlagBits::eMemoryWrite;
|
||||
barrier.dstAccessMask = vk::AccessFlagBits::eShaderRead | vk::AccessFlagBits::eShaderWrite;
|
||||
return barrier;
|
||||
}
|
||||
|
||||
vk::BufferMemoryBarrier MakeGdsDependency(vk::Buffer buffer) {
|
||||
EXIT_IF(buffer == nullptr);
|
||||
|
||||
@@ -84,6 +100,21 @@ bool HasShaderBufferWrites(const ShaderStageRuntime& runtime) {
|
||||
return !CollectShaderBufferWrites(*runtime.program, *runtime.resources).empty();
|
||||
}
|
||||
|
||||
void ShaderAccessBarrier(vk::CommandBuffer vk_buffer, vk::PipelineStageFlags source_stages) {
|
||||
EXIT_IF(vk_buffer == nullptr || !source_stages);
|
||||
const auto barrier = MakeShaderAccessDependency();
|
||||
vk_buffer.pipelineBarrier(source_stages, vk::PipelineStageFlagBits::eAllCommands,
|
||||
vk::DependencyFlags {}, 1, &barrier, 0, nullptr, 0, nullptr);
|
||||
}
|
||||
|
||||
void ShaderWriteHazardBarrier(vk::CommandBuffer vk_buffer,
|
||||
vk::PipelineStageFlags destination_stages) {
|
||||
EXIT_IF(vk_buffer == nullptr || !destination_stages);
|
||||
const auto barrier = MakeShaderWriteHazardDependency();
|
||||
vk_buffer.pipelineBarrier(vk::PipelineStageFlagBits::eAllCommands, destination_stages,
|
||||
vk::DependencyFlags {}, 1, &barrier, 0, nullptr, 0, nullptr);
|
||||
}
|
||||
|
||||
void ShaderWriteBarrier(vk::CommandBuffer vk_buffer, vk::PipelineStageFlags source_stages) {
|
||||
EXIT_IF(vk_buffer == nullptr || !source_stages);
|
||||
const auto barrier = MakeShaderWriteDependency();
|
||||
|
||||
@@ -18,12 +18,17 @@ struct ShaderBufferWriteRange {
|
||||
};
|
||||
|
||||
vk::PipelineStageFlags ShaderPipelineStages(vk::ShaderStageFlags stages);
|
||||
VulkanMemoryBarrier MakeShaderAccessDependency();
|
||||
VulkanMemoryBarrier MakeShaderWriteHazardDependency();
|
||||
VulkanMemoryBarrier MakeShaderWriteDependency();
|
||||
vk::BufferMemoryBarrier MakeGdsDependency(vk::Buffer buffer);
|
||||
std::vector<ShaderBufferWriteRange>
|
||||
CollectShaderBufferWrites(const ShaderRecompiler::IR::Program& program,
|
||||
const ShaderRecompiler::IR::ResourceSnapshot& resources);
|
||||
bool HasShaderBufferWrites(const ShaderStageRuntime& runtime);
|
||||
void ShaderAccessBarrier(vk::CommandBuffer vk_buffer, vk::PipelineStageFlags source_stages);
|
||||
void ShaderWriteHazardBarrier(vk::CommandBuffer vk_buffer,
|
||||
vk::PipelineStageFlags destination_stages);
|
||||
void ShaderWriteBarrier(vk::CommandBuffer vk_buffer, vk::PipelineStageFlags source_stages);
|
||||
|
||||
} // namespace Libs::Graphics
|
||||
|
||||
@@ -947,6 +947,8 @@ void CreatePipelineInternal(
|
||||
vk::DynamicState::eViewport,
|
||||
vk::DynamicState::eScissor,
|
||||
vk::DynamicState::eLineWidth,
|
||||
vk::DynamicState::eDepthBiasEnable,
|
||||
vk::DynamicState::eDepthBias,
|
||||
vk::DynamicState::eStencilCompareMask,
|
||||
vk::DynamicState::eStencilReference,
|
||||
vk::DynamicState::eStencilWriteMask,
|
||||
|
||||
@@ -325,9 +325,6 @@ void RenderExecutor::DispatchDirect(uint64_t submit_id, RenderCommandBuffer& buf
|
||||
|
||||
auto vk_buffer = buffer.Handle();
|
||||
CommitBindings(buffer, vk::PipelineBindPoint::eCompute, pipeline.pipeline_layout, bindings);
|
||||
vk_buffer.bindPipeline(vk::PipelineBindPoint::eCompute, pipeline.pipeline);
|
||||
vk_buffer.dispatch(thread_group_x, thread_group_y, thread_group_z);
|
||||
|
||||
bool has_storage_writes = HasShaderBufferWrites(input_info.stage);
|
||||
has_storage_writes =
|
||||
std::any_of(program.info.images.begin(), program.info.images.end(),
|
||||
@@ -338,8 +335,15 @@ void RenderExecutor::DispatchDirect(uint64_t submit_id, RenderCommandBuffer& buf
|
||||
}) ||
|
||||
has_storage_writes;
|
||||
if (has_storage_writes) {
|
||||
ShaderWriteBarrier(vk_buffer, vk::PipelineStageFlagBits::eComputeShader);
|
||||
// A host fence used to serialize every dispatch. Preserve its read-before-write ordering
|
||||
// while allowing the queue to execute asynchronously.
|
||||
ShaderWriteHazardBarrier(vk_buffer, vk::PipelineStageFlagBits::eComputeShader);
|
||||
}
|
||||
vk_buffer.bindPipeline(vk::PipelineBindPoint::eCompute, pipeline.pipeline);
|
||||
vk_buffer.dispatch(thread_group_x, thread_group_y, thread_group_z);
|
||||
|
||||
// The removed host fence also ordered read-only dispatches before later writers.
|
||||
ShaderAccessBarrier(vk_buffer, vk::PipelineStageFlagBits::eComputeShader);
|
||||
ResetBindings();
|
||||
}
|
||||
|
||||
|
||||
@@ -64,12 +64,32 @@ int32_t ResolveVertexOffset(uint32_t index_offset, const ShaderVertexInputInfo&
|
||||
return 0;
|
||||
}
|
||||
|
||||
static std::atomic<uint32_t> g_draw_state_log_count = 0;
|
||||
static std::atomic<uint32_t> g_draw_input_log_count = 0;
|
||||
static std::atomic<uint32_t> g_mrt_state_log_count = 0;
|
||||
static std::atomic<uint32_t> g_shader_stage_log_count = 0;
|
||||
static std::atomic<uint32_t> g_draw_state_log_count = 0;
|
||||
static std::atomic<uint32_t> g_draw_input_log_count = 0;
|
||||
static std::atomic<uint32_t> g_mrt_state_log_count = 0;
|
||||
static std::atomic<uint32_t> g_shader_stage_log_count = 0;
|
||||
|
||||
static std::atomic<uint32_t> g_framebuffer_skip_log_count = 0;
|
||||
|
||||
static float ConvertPolygonOffsetConstantFactor(float guest_factor, const HW::PolyOffset& offset,
|
||||
vk::Format host_depth_format) {
|
||||
if (offset.db_is_float_fmt) {
|
||||
return guest_factor;
|
||||
}
|
||||
|
||||
int host_depth_bits = 0;
|
||||
switch (host_depth_format) {
|
||||
case vk::Format::eD16Unorm:
|
||||
case vk::Format::eD16UnormS8Uint: host_depth_bits = 16; break;
|
||||
case vk::Format::eD24UnormS8Uint: host_depth_bits = 24; break;
|
||||
default:
|
||||
// A fixed-point guest bias cannot be represented exactly by a floating-point host
|
||||
// attachment without VK_EXT_depth_bias_control.
|
||||
return guest_factor;
|
||||
}
|
||||
return std::ldexp(guest_factor, host_depth_bits + offset.neg_num_db_bits);
|
||||
}
|
||||
|
||||
static const char* RenderColorTypeName(RenderColorType type) {
|
||||
switch (type) {
|
||||
case RenderColorType::NoColorOutput: return "NoColorOutput";
|
||||
@@ -335,6 +355,22 @@ static PipelineDynamicParameters BuildGraphicsDynamicParams(const RenderCommandB
|
||||
ret.stencil_front = depth.stencil_dynamic_front;
|
||||
ret.stencil_back = depth.stencil_dynamic_back;
|
||||
|
||||
const auto& mode = ctx.GetModeControl();
|
||||
const auto& poly_offset = ctx.GetPolyOffset();
|
||||
const bool use_front = mode.poly_offset_front_enable && !mode.cull_front;
|
||||
const bool use_back = mode.poly_offset_back_enable && !mode.cull_back;
|
||||
ret.depth_bias_enable = use_front || use_back;
|
||||
if (ret.depth_bias_enable) {
|
||||
// Vulkan has one bias for both faces. Prefer a visible front face when both are enabled.
|
||||
const float guest_constant_factor =
|
||||
use_front ? poly_offset.front_offset : poly_offset.back_offset;
|
||||
ret.depth_bias_constant_factor =
|
||||
ConvertPolygonOffsetConstantFactor(guest_constant_factor, poly_offset, depth.format);
|
||||
ret.depth_bias_clamp = poly_offset.clamp;
|
||||
ret.depth_bias_slope_factor =
|
||||
(use_front ? poly_offset.front_scale : poly_offset.back_scale) / 16.0f;
|
||||
}
|
||||
|
||||
// CB_COLOR_CONTROL.operation controls special CB operations, not the normal color component
|
||||
// write mask. Use CB_TARGET_MASK here so scanout passes with mode=Disable do not go black.
|
||||
for (uint32_t i = 0; i < RENDER_COLOR_ATTACHMENTS_MAX; i++) {
|
||||
@@ -379,6 +415,13 @@ static void SetDynamicParams(const RenderCommandBuffer& buffer, vk::CommandBuffe
|
||||
}
|
||||
vk_buffer.setLineWidth(line_width);
|
||||
|
||||
vk_buffer.setDepthBiasEnable(dynamic_params.depth_bias_enable ? VK_TRUE : VK_FALSE);
|
||||
if (dynamic_params.depth_bias_enable) {
|
||||
vk_buffer.setDepthBias(dynamic_params.depth_bias_constant_factor,
|
||||
dynamic_params.depth_bias_clamp,
|
||||
dynamic_params.depth_bias_slope_factor);
|
||||
}
|
||||
|
||||
if (dynamic_params.stencil_test_enable) {
|
||||
vk_buffer.setStencilCompareMask(vk::StencilFaceFlagBits::eFront,
|
||||
dynamic_params.stencil_front.compareMask);
|
||||
@@ -664,12 +707,10 @@ struct DrawIndexBufferSource {
|
||||
|
||||
struct PreparedIndexBuffer {
|
||||
std::shared_ptr<void> owner;
|
||||
vk::Buffer buffer = nullptr;
|
||||
uint64_t address = 0;
|
||||
uint64_t size = 0;
|
||||
vk::DeviceSize offset = 0;
|
||||
vk::IndexType type = vk::IndexType::eUint16;
|
||||
bool streamed = false;
|
||||
vk::Buffer buffer = nullptr;
|
||||
uint64_t size = 0;
|
||||
vk::DeviceSize offset = 0;
|
||||
vk::IndexType type = vk::IndexType::eUint16;
|
||||
};
|
||||
|
||||
static uint64_t VertexBufferDescriptorSize(const ShaderVertexInputBuffer& buffer) {
|
||||
@@ -686,11 +727,24 @@ struct VertexBufferRange {
|
||||
[[nodiscard]] uint64_t RequestedSize() const { return requested_end - base_address; }
|
||||
};
|
||||
|
||||
static std::vector<BufferBinding> AcquireVertexBuffers(RenderCommandBuffer& buffer,
|
||||
const ShaderVertexInputInfo& vs_input_info) {
|
||||
struct PreparedVertexBuffers {
|
||||
static constexpr uint32_t MaxBuffers = ShaderVertexInputInfo::RES_MAX;
|
||||
|
||||
std::array<vk::Buffer, MaxBuffers> buffers {};
|
||||
std::array<vk::DeviceSize, MaxBuffers> offsets {};
|
||||
std::array<std::shared_ptr<void>, MaxBuffers> owners {};
|
||||
uint32_t count = 0;
|
||||
uint32_t owner_count = 0;
|
||||
};
|
||||
|
||||
static PreparedVertexBuffers AcquireVertexBuffers(RenderCommandBuffer& buffer,
|
||||
const ShaderVertexInputInfo& vs_input_info) {
|
||||
EXIT_IF(vs_input_info.buffers_num < 0 ||
|
||||
vs_input_info.buffers_num > ShaderVertexInputInfo::RES_MAX);
|
||||
|
||||
// Collect the non-empty guest vertex ranges.
|
||||
std::vector<VertexBufferRange> ranges;
|
||||
ranges.reserve(vs_input_info.buffers_num);
|
||||
std::array<VertexBufferRange, ShaderVertexInputInfo::RES_MAX> ranges {};
|
||||
uint32_t range_count = 0;
|
||||
for (int i = 0; i < vs_input_info.buffers_num; i++) {
|
||||
const auto& vertex = vs_input_info.buffers[i];
|
||||
const auto size = VertexBufferDescriptorSize(vertex);
|
||||
@@ -701,27 +755,31 @@ static std::vector<BufferBinding> AcquireVertexBuffers(RenderCommandBuffer&
|
||||
EXIT("invalid vertex buffer range: addr=0x%016" PRIx64 " size=0x%016" PRIx64 "\n",
|
||||
vertex.addr, size);
|
||||
}
|
||||
ranges.push_back({vertex.addr, vertex.addr + size});
|
||||
ranges[range_count++] = {vertex.addr, vertex.addr + size};
|
||||
}
|
||||
|
||||
std::ranges::sort(ranges, [](const VertexBufferRange& left, const VertexBufferRange& right) {
|
||||
return left.base_address < right.base_address;
|
||||
});
|
||||
std::sort(ranges.begin(), ranges.begin() + range_count,
|
||||
[](const VertexBufferRange& left, const VertexBufferRange& right) {
|
||||
return left.base_address < right.base_address;
|
||||
});
|
||||
|
||||
// Merge overlapping or touching ranges before acquiring host buffers.
|
||||
std::vector<VertexBufferRange> merged_ranges;
|
||||
merged_ranges.reserve(ranges.size());
|
||||
for (const auto& range: ranges) {
|
||||
if (!merged_ranges.empty() && merged_ranges.back().requested_end >= range.base_address) {
|
||||
merged_ranges.back().requested_end =
|
||||
std::max(merged_ranges.back().requested_end, range.requested_end);
|
||||
std::array<VertexBufferRange, ShaderVertexInputInfo::RES_MAX> merged_ranges {};
|
||||
uint32_t merged_count = 0;
|
||||
for (uint32_t i = 0; i < range_count; i++) {
|
||||
const auto& range = ranges[i];
|
||||
if (merged_count != 0 &&
|
||||
merged_ranges[merged_count - 1].requested_end >= range.base_address) {
|
||||
merged_ranges[merged_count - 1].requested_end =
|
||||
std::max(merged_ranges[merged_count - 1].requested_end, range.requested_end);
|
||||
continue;
|
||||
}
|
||||
merged_ranges.push_back(range);
|
||||
merged_ranges[merged_count++] = {range.base_address, range.requested_end};
|
||||
}
|
||||
|
||||
auto& cache = buffer.GetContext().GetBufferCache();
|
||||
for (auto& range: merged_ranges) {
|
||||
for (uint32_t i = 0; i < merged_count; i++) {
|
||||
auto& range = merged_ranges[i];
|
||||
// PPSA20298
|
||||
const auto size =
|
||||
Libs::LibKernel::Memory::ClampRangeSize(range.base_address, range.RequestedSize());
|
||||
@@ -730,30 +788,47 @@ static std::vector<BufferBinding> AcquireVertexBuffers(RenderCommandBuffer&
|
||||
}
|
||||
|
||||
// Rebuild slot bindings, offsetting non-empty slots into their acquired merged range.
|
||||
std::vector<BufferBinding> bindings;
|
||||
bindings.reserve(vs_input_info.buffers_num);
|
||||
PreparedVertexBuffers prepared;
|
||||
prepared.count = static_cast<uint32_t>(vs_input_info.buffers_num);
|
||||
std::shared_ptr<Buffer> null_owner;
|
||||
vk::Buffer null_buffer = nullptr;
|
||||
for (int i = 0; i < vs_input_info.buffers_num; i++) {
|
||||
const auto& vertex = vs_input_info.buffers[i];
|
||||
const auto size = VertexBufferDescriptorSize(vertex);
|
||||
if (size == 0) {
|
||||
auto owner = cache.ObtainNullBuffer();
|
||||
bindings.push_back({owner, owner->Handle(), 0});
|
||||
if (null_owner == nullptr) {
|
||||
null_owner = cache.ObtainNullBuffer();
|
||||
null_buffer = null_owner->Handle();
|
||||
}
|
||||
prepared.buffers[i] = null_buffer;
|
||||
prepared.offsets[i] = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto range = std::ranges::find_if(merged_ranges, [&](const VertexBufferRange& value) {
|
||||
return vertex.addr >= value.base_address && vertex.addr < value.acquired_end;
|
||||
});
|
||||
if (range == merged_ranges.end()) {
|
||||
const auto range = std::find_if(merged_ranges.begin(), merged_ranges.begin() + merged_count,
|
||||
[&](const VertexBufferRange& value) {
|
||||
return vertex.addr >= value.base_address &&
|
||||
vertex.addr < value.acquired_end;
|
||||
});
|
||||
if (range == merged_ranges.begin() + merged_count) {
|
||||
EXIT("vertex buffer address is outside the acquired range: addr=0x%016" PRIx64 "\n",
|
||||
vertex.addr);
|
||||
}
|
||||
|
||||
auto binding = range->binding;
|
||||
binding.offset += vertex.addr - range->base_address;
|
||||
bindings.push_back(std::move(binding));
|
||||
prepared.buffers[i] = range->binding.buffer;
|
||||
prepared.offsets[i] = range->binding.offset + vertex.addr - range->base_address;
|
||||
}
|
||||
return bindings;
|
||||
|
||||
if (null_owner != nullptr) {
|
||||
prepared.owners[prepared.owner_count++] = std::move(null_owner);
|
||||
}
|
||||
for (uint32_t i = 0; i < merged_count; i++) {
|
||||
if (merged_ranges[i].binding.owner != nullptr) {
|
||||
EXIT_IF(prepared.owner_count >= PreparedVertexBuffers::MaxBuffers);
|
||||
prepared.owners[prepared.owner_count++] = std::move(merged_ranges[i].binding.owner);
|
||||
}
|
||||
}
|
||||
return prepared;
|
||||
}
|
||||
|
||||
static void SetDrawDebugPhase(RenderCommandBuffer& buffer, uint64_t submit_id,
|
||||
@@ -885,10 +960,9 @@ static void RefreshShaders(RenderCommandBuffer& buffer, const DrawCallInfo& draw
|
||||
}
|
||||
}
|
||||
|
||||
static std::vector<BufferBinding> PrepareVertexBuffers(uint64_t submit_id,
|
||||
RenderCommandBuffer& buffer,
|
||||
const DrawCallInfo& draw,
|
||||
const ShaderVertexInputInfo& vs_input_info) {
|
||||
static PreparedVertexBuffers PrepareVertexBuffers(uint64_t submit_id, RenderCommandBuffer& buffer,
|
||||
const DrawCallInfo& draw,
|
||||
const ShaderVertexInputInfo& vs_input_info) {
|
||||
EXIT_IF(draw.name == nullptr);
|
||||
(void)submit_id;
|
||||
|
||||
@@ -896,12 +970,6 @@ static std::vector<BufferBinding> PrepareVertexBuffers(uint64_t
|
||||
return AcquireVertexBuffers(buffer, vs_input_info);
|
||||
}
|
||||
|
||||
static void RebindVertexBuffers(RenderCommandBuffer& buffer,
|
||||
const ShaderVertexInputInfo& vs_input_info,
|
||||
std::vector<BufferBinding>& bindings) {
|
||||
bindings = AcquireVertexBuffers(buffer, vs_input_info);
|
||||
}
|
||||
|
||||
static PreparedIndexBuffer PrepareIndexBuffer(RenderCommandBuffer& buffer,
|
||||
const DrawIndexBufferSource& source) {
|
||||
PreparedIndexBuffer prepared;
|
||||
@@ -909,16 +977,14 @@ static PreparedIndexBuffer PrepareIndexBuffer(RenderCommandBuffer& buffe
|
||||
return prepared;
|
||||
}
|
||||
EXIT_IF(source.size == 0);
|
||||
prepared.address = source.address;
|
||||
prepared.size = source.size;
|
||||
prepared.type = source.type;
|
||||
prepared.size = source.size;
|
||||
prepared.type = source.type;
|
||||
if (source.host_data != nullptr) {
|
||||
auto binding =
|
||||
buffer.GetContext().GetBufferCache().UploadTransient(source.host_data, source.size, 16);
|
||||
prepared.owner = std::move(binding.owner);
|
||||
prepared.buffer = binding.buffer;
|
||||
prepared.offset = binding.offset;
|
||||
prepared.streamed = true;
|
||||
prepared.owner = std::move(binding.owner);
|
||||
prepared.buffer = binding.buffer;
|
||||
prepared.offset = binding.offset;
|
||||
} else {
|
||||
auto binding =
|
||||
buffer.GetContext().GetBufferCache().ObtainBuffer(buffer, source.address, source.size);
|
||||
@@ -929,36 +995,29 @@ static PreparedIndexBuffer PrepareIndexBuffer(RenderCommandBuffer& buffe
|
||||
return prepared;
|
||||
}
|
||||
|
||||
static void RebindIndexBuffer(RenderCommandBuffer& buffer, PreparedIndexBuffer& prepared) {
|
||||
if (prepared.size == 0 || prepared.streamed) {
|
||||
return;
|
||||
}
|
||||
auto binding =
|
||||
buffer.GetContext().GetBufferCache().ObtainBuffer(buffer, prepared.address, prepared.size);
|
||||
prepared.owner = std::move(binding.owner);
|
||||
prepared.buffer = binding.buffer;
|
||||
prepared.offset = binding.offset;
|
||||
}
|
||||
|
||||
static void CommitVertexBuffers(RenderCommandBuffer& buffer, vk::CommandBuffer vk_buffer,
|
||||
std::vector<BufferBinding>& bindings) {
|
||||
for (uint32_t slot = 0; slot < bindings.size(); slot++) {
|
||||
auto& binding = bindings[slot];
|
||||
if (binding.owner != nullptr) {
|
||||
buffer.RetainResourceUntilFence(binding.owner);
|
||||
PreparedVertexBuffers& prepared) {
|
||||
for (uint32_t i = 0; i < prepared.owner_count; i++) {
|
||||
if (prepared.owners[i] != nullptr) {
|
||||
buffer.RetainResourceUntilFence(std::move(prepared.owners[i]));
|
||||
}
|
||||
EXIT_IF(binding.buffer == nullptr);
|
||||
vk_buffer.bindVertexBuffers(slot, 1, &binding.buffer, &binding.offset);
|
||||
}
|
||||
for (uint32_t i = 0; i < prepared.count; i++) {
|
||||
EXIT_IF(prepared.buffers[i] == nullptr);
|
||||
}
|
||||
if (prepared.count != 0) {
|
||||
vk_buffer.bindVertexBuffers(0, prepared.count, prepared.buffers.data(),
|
||||
prepared.offsets.data());
|
||||
}
|
||||
}
|
||||
|
||||
static void CommitIndexBuffer(RenderCommandBuffer& buffer, vk::CommandBuffer vk_buffer,
|
||||
const PreparedIndexBuffer& prepared) {
|
||||
PreparedIndexBuffer& prepared) {
|
||||
if (prepared.size == 0) {
|
||||
return;
|
||||
}
|
||||
if (prepared.owner != nullptr) {
|
||||
buffer.RetainResourceUntilFence(prepared.owner);
|
||||
buffer.RetainResourceUntilFence(std::move(prepared.owner));
|
||||
}
|
||||
EXIT_IF(prepared.buffer == nullptr);
|
||||
vk_buffer.bindIndexBuffer(prepared.buffer, prepared.offset, prepared.type);
|
||||
@@ -1046,8 +1105,6 @@ void RenderExecutor::ExecutePreparedDraw(uint64_t submit_id, RenderCommandBuffer
|
||||
state.ps_input_info.stage, state.ps_active);
|
||||
auto vertex_bindings = PrepareVertexBuffers(submit_id, buffer, draw, state.vs_input_info);
|
||||
auto index_binding = PrepareIndexBuffer(buffer, index_source);
|
||||
RebindVertexBuffers(buffer, state.vs_input_info, vertex_bindings);
|
||||
RebindIndexBuffer(buffer, index_binding);
|
||||
state.rendering =
|
||||
AcquireRenderTargets(buffer, state.color_info, state.color_count, state.depth_info);
|
||||
|
||||
|
||||
@@ -15,12 +15,16 @@ struct ShaderVertexInputInfo;
|
||||
|
||||
struct PipelineDynamicParameters {
|
||||
bool stencil_test_enable = false;
|
||||
bool depth_bias_enable = false;
|
||||
|
||||
float viewport_scale[3] = {};
|
||||
float viewport_offset[3] = {};
|
||||
int scissor_ltrb[4] = {0};
|
||||
|
||||
float line_width = 1.0f;
|
||||
float depth_bias_constant_factor = 0.0f;
|
||||
float depth_bias_clamp = 0.0f;
|
||||
float depth_bias_slope_factor = 0.0f;
|
||||
uint32_t color_write_count = 1;
|
||||
bool color_write_enable[RENDER_COLOR_ATTACHMENTS_MAX] = {true, true};
|
||||
|
||||
@@ -33,10 +37,6 @@ struct PipelineDynamicParameters {
|
||||
static_assert(std::is_trivially_copyable_v<PipelineDynamicParameters>);
|
||||
static_assert(std::is_standard_layout_v<PipelineDynamicParameters>);
|
||||
static_assert(alignof(PipelineDynamicParameters) == 1);
|
||||
static_assert(sizeof(PipelineDynamicParameters) ==
|
||||
sizeof(bool) + sizeof(float[3]) + sizeof(float[3]) + sizeof(int[4]) + sizeof(float) +
|
||||
sizeof(uint32_t) + sizeof(bool[RENDER_COLOR_ATTACHMENTS_MAX]) +
|
||||
sizeof(PipelineStencilDynamicState) * 2);
|
||||
|
||||
[[nodiscard]] int32_t ResolveVertexOffset(uint32_t index_offset,
|
||||
const ShaderVertexInputInfo& vs_input_info);
|
||||
|
||||
@@ -0,0 +1,876 @@
|
||||
#include "graphics/presentation/imeDialogOverlay.h"
|
||||
|
||||
#include "SDL.h"
|
||||
#include "common/assert.h"
|
||||
#include "common/stringUtils.h"
|
||||
#include "graphics/host_gpu/graphicContext.h"
|
||||
#include "imgui.h"
|
||||
#include "imgui_impl_vulkan.h"
|
||||
#include "libs/controller.h"
|
||||
#include "libs/imeDialog.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <deque>
|
||||
#include <mutex>
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
|
||||
namespace Libs::Graphics {
|
||||
|
||||
namespace {
|
||||
|
||||
namespace Ime = Libs::Dialog::ImeDialog;
|
||||
|
||||
constexpr size_t INPUT_QUEUE_CAPACITY = 128;
|
||||
|
||||
enum class InputKind : uint8_t {
|
||||
Button,
|
||||
Axis,
|
||||
MousePosition,
|
||||
MouseButton,
|
||||
MouseWheel,
|
||||
ResetController
|
||||
};
|
||||
|
||||
struct InputEvent {
|
||||
InputKind kind;
|
||||
uint64_t generation;
|
||||
int id;
|
||||
float x;
|
||||
float y;
|
||||
};
|
||||
|
||||
struct VisibilityUpdate {
|
||||
uint64_t generation;
|
||||
bool visible;
|
||||
bool capture_controller;
|
||||
bool capture_keyboard;
|
||||
bool multiline;
|
||||
};
|
||||
|
||||
std::atomic<Uint32> g_visibility_event {static_cast<Uint32>(-1)};
|
||||
std::mutex g_visibility_mutex;
|
||||
std::mutex g_input_mutex;
|
||||
std::deque<InputEvent> g_input_events;
|
||||
std::deque<VisibilityUpdate> g_visibility_updates;
|
||||
size_t g_missing_visibility_wakeups = 0;
|
||||
bool g_input_reset_requested = false;
|
||||
uint16_t g_last_external_keycode = 0;
|
||||
uint32_t g_last_external_status = 0;
|
||||
uint64_t g_input_generation = 0;
|
||||
bool g_input_active = false;
|
||||
bool g_input_controller = false;
|
||||
bool g_input_keyboard = false;
|
||||
bool g_input_multiline = false;
|
||||
bool g_input_lifecycle_active = false;
|
||||
bool g_active = false;
|
||||
bool g_controller_captured = false;
|
||||
uint64_t g_generation = 0;
|
||||
|
||||
void ClearInputEvents() {
|
||||
std::scoped_lock lock(g_input_mutex);
|
||||
g_input_events.clear();
|
||||
g_input_reset_requested = false;
|
||||
}
|
||||
|
||||
void QueueInput(InputEvent event) {
|
||||
std::scoped_lock lock(g_input_mutex);
|
||||
const bool replaceable =
|
||||
event.kind == InputKind::Axis || event.kind == InputKind::MousePosition;
|
||||
if (replaceable && !g_input_events.empty()) {
|
||||
auto& last = g_input_events.back();
|
||||
if (last.generation == event.generation && last.kind == event.kind && last.id == event.id) {
|
||||
last = event;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (g_input_events.size() == INPUT_QUEUE_CAPACITY) {
|
||||
g_input_events.clear();
|
||||
g_input_reset_requested = true;
|
||||
}
|
||||
g_input_events.push_back(event);
|
||||
}
|
||||
|
||||
void RetryVisibilityWakeup() {
|
||||
const Uint32 type = g_visibility_event.load(std::memory_order_acquire);
|
||||
if (type == static_cast<Uint32>(-1)) {
|
||||
return;
|
||||
}
|
||||
std::scoped_lock lock(g_input_mutex);
|
||||
if (g_missing_visibility_wakeups == 0) {
|
||||
return;
|
||||
}
|
||||
SDL_Event event {};
|
||||
event.type = type;
|
||||
if (SDL_PushEvent(&event) > 0) {
|
||||
g_missing_visibility_wakeups--;
|
||||
}
|
||||
}
|
||||
|
||||
void OnVisibilityChanged(bool visible, uint64_t generation) {
|
||||
std::scoped_lock visibility_lock(g_visibility_mutex);
|
||||
if (!g_input_lifecycle_active) {
|
||||
return;
|
||||
}
|
||||
if (generation < g_generation || (generation == g_generation && visible == g_active)) {
|
||||
return;
|
||||
}
|
||||
|
||||
g_generation = generation;
|
||||
bool capture_controller = false;
|
||||
bool capture_keyboard = false;
|
||||
bool multiline = false;
|
||||
if (visible) {
|
||||
Ime::HostSnapshot snapshot;
|
||||
if (Ime::GetHostSnapshot(&snapshot) && snapshot.generation == generation) {
|
||||
capture_controller = (snapshot.disable_device & Ime::DISABLE_DEVICE_CONTROLLER) == 0;
|
||||
capture_keyboard = (snapshot.disable_device & Ime::DISABLE_DEVICE_EXT_KEYBOARD) == 0;
|
||||
multiline = (snapshot.option & Ime::OPTION_MULTILINE) != 0;
|
||||
} else {
|
||||
visible = false;
|
||||
}
|
||||
}
|
||||
const bool was_controller = std::exchange(g_controller_captured, capture_controller);
|
||||
if (capture_controller || was_controller) {
|
||||
Controller::ControllerResetInputState();
|
||||
}
|
||||
g_active = visible;
|
||||
|
||||
const Uint32 type = g_visibility_event.load(std::memory_order_acquire);
|
||||
if (type != static_cast<Uint32>(-1)) {
|
||||
SDL_Event event {};
|
||||
event.type = type;
|
||||
std::scoped_lock input_lock(g_input_mutex);
|
||||
g_visibility_updates.push_back(
|
||||
{generation, visible, capture_controller, capture_keyboard, multiline});
|
||||
if (g_missing_visibility_wakeups != 0 || SDL_PushEvent(&event) <= 0) {
|
||||
g_missing_visibility_wakeups++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t ExternalKeyStatus(SDL_Keymod modifiers, bool character_valid) {
|
||||
uint32_t status = 0x00000001 | (character_valid ? 0x00000002 : 0);
|
||||
if ((modifiers & KMOD_LCTRL) != 0) status |= 0x00000100;
|
||||
if ((modifiers & KMOD_LSHIFT) != 0) status |= 0x00000200;
|
||||
if ((modifiers & KMOD_LALT) != 0) status |= 0x00000400;
|
||||
if ((modifiers & KMOD_LGUI) != 0) status |= 0x00000800;
|
||||
if ((modifiers & KMOD_RCTRL) != 0) status |= 0x00001000;
|
||||
if ((modifiers & KMOD_RSHIFT) != 0) status |= 0x00002000;
|
||||
if ((modifiers & KMOD_RALT) != 0) status |= 0x00004000;
|
||||
if ((modifiers & KMOD_RGUI) != 0) status |= 0x00008000;
|
||||
if ((modifiers & KMOD_NUM) != 0) status |= 0x00010000;
|
||||
if ((modifiers & KMOD_CAPS) != 0) status |= 0x00020000;
|
||||
return status;
|
||||
}
|
||||
|
||||
Ime::ExternalInput MakeExternalInput(Ime::ExternalAction action, uint16_t keycode,
|
||||
uint32_t status) {
|
||||
Ime::ExternalInput input {};
|
||||
input.key.keycode = keycode;
|
||||
input.key.status = status;
|
||||
input.key.type = 4;
|
||||
input.action = action;
|
||||
return input;
|
||||
}
|
||||
|
||||
std::u16string Utf8ToUtf16(std::string_view text) {
|
||||
std::u16string result;
|
||||
result.reserve(text.size());
|
||||
for (size_t i = 0; i < text.size();) {
|
||||
const auto first = static_cast<uint8_t>(text[i++]);
|
||||
uint32_t codepoint = 0;
|
||||
uint32_t remaining = 0;
|
||||
if (first < 0x80) {
|
||||
codepoint = first;
|
||||
} else if ((first & 0xe0) == 0xc0) {
|
||||
codepoint = first & 0x1f;
|
||||
remaining = 1;
|
||||
} else if ((first & 0xf0) == 0xe0) {
|
||||
codepoint = first & 0x0f;
|
||||
remaining = 2;
|
||||
} else if ((first & 0xf8) == 0xf0) {
|
||||
codepoint = first & 0x07;
|
||||
remaining = 3;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
if (i + remaining > text.size()) {
|
||||
break;
|
||||
}
|
||||
bool valid = true;
|
||||
for (uint32_t j = 0; j < remaining; j++) {
|
||||
const auto next = static_cast<uint8_t>(text[i++]);
|
||||
if ((next & 0xc0) != 0x80) {
|
||||
valid = false;
|
||||
break;
|
||||
}
|
||||
codepoint = (codepoint << 6) | (next & 0x3f);
|
||||
}
|
||||
if (!valid || codepoint > 0x10ffff || (codepoint >= 0xd800 && codepoint <= 0xdfff)) {
|
||||
continue;
|
||||
}
|
||||
if (codepoint <= 0xffff) {
|
||||
result.push_back(static_cast<char16_t>(codepoint));
|
||||
} else {
|
||||
codepoint -= 0x10000;
|
||||
result.push_back(static_cast<char16_t>(0xd800 + (codepoint >> 10)));
|
||||
result.push_back(static_cast<char16_t>(0xdc00 + (codepoint & 0x3ff)));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string VisibleText(const Ime::HostSnapshot& snapshot, size_t max_units) {
|
||||
const size_t cursor = std::min<size_t>(snapshot.cursor, snapshot.text.size());
|
||||
const size_t payload_units = max_units > 4 ? max_units - 4 : 1;
|
||||
size_t begin = cursor > payload_units / 2 ? cursor - payload_units / 2 : 0;
|
||||
size_t end = std::min(snapshot.text.size(), begin + payload_units);
|
||||
if (end == snapshot.text.size() && end - begin < payload_units) {
|
||||
begin = end > payload_units ? end - payload_units : 0;
|
||||
}
|
||||
if (begin > 0 && snapshot.text[begin] >= 0xdc00 && snapshot.text[begin] <= 0xdfff) {
|
||||
begin--;
|
||||
}
|
||||
if (end < snapshot.text.size() && end > begin && snapshot.text[end - 1] >= 0xd800 &&
|
||||
snapshot.text[end - 1] <= 0xdbff) {
|
||||
end--;
|
||||
}
|
||||
|
||||
std::u16string visible;
|
||||
if (begin != 0) {
|
||||
visible.push_back(u'\u2026');
|
||||
}
|
||||
const size_t caret = visible.size() + cursor - begin;
|
||||
if ((snapshot.option & Ime::OPTION_PASSWORD) != 0) {
|
||||
visible.append(end - begin, u'*');
|
||||
} else {
|
||||
visible.append(snapshot.text, begin, end - begin);
|
||||
std::replace(visible.begin(), visible.end(), u'\n', u'\u21b5');
|
||||
std::replace(visible.begin(), visible.end(), u'\r', u'\u21b5');
|
||||
}
|
||||
visible.insert(std::min(caret, visible.size()), 1, u'|');
|
||||
if (end != snapshot.text.size()) {
|
||||
visible.push_back(u'\u2026');
|
||||
}
|
||||
return Common::Utf16ToUtf8(visible.c_str());
|
||||
}
|
||||
|
||||
const char* EnterLabel(Ime::EnterLabel label) {
|
||||
switch (label) {
|
||||
case Ime::EnterLabel::Send: return "Send";
|
||||
case Ime::EnterLabel::Search: return "Search";
|
||||
case Ime::EnterLabel::Go: return "Go";
|
||||
default: return "Done";
|
||||
}
|
||||
}
|
||||
|
||||
float AlignmentPivot(Ime::Alignment alignment) {
|
||||
switch (alignment) {
|
||||
case Ime::Alignment::Start: return 0.0f;
|
||||
case Ime::Alignment::End: return 1.0f;
|
||||
default: return 0.5f;
|
||||
}
|
||||
}
|
||||
|
||||
ImGuiKey ControllerButtonToKey(int button) {
|
||||
switch (button) {
|
||||
case SDL_CONTROLLER_BUTTON_A: return ImGuiKey_GamepadFaceDown;
|
||||
case SDL_CONTROLLER_BUTTON_B: return ImGuiKey_GamepadFaceRight;
|
||||
case SDL_CONTROLLER_BUTTON_X: return ImGuiKey_GamepadFaceLeft;
|
||||
case SDL_CONTROLLER_BUTTON_Y: return ImGuiKey_GamepadFaceUp;
|
||||
case SDL_CONTROLLER_BUTTON_DPAD_LEFT: return ImGuiKey_GamepadDpadLeft;
|
||||
case SDL_CONTROLLER_BUTTON_DPAD_RIGHT: return ImGuiKey_GamepadDpadRight;
|
||||
case SDL_CONTROLLER_BUTTON_DPAD_UP: return ImGuiKey_GamepadDpadUp;
|
||||
case SDL_CONTROLLER_BUTTON_DPAD_DOWN: return ImGuiKey_GamepadDpadDown;
|
||||
default: return ImGuiKey_None;
|
||||
}
|
||||
}
|
||||
|
||||
PFN_vkVoidFunction LoadVulkanFunction(const char* name, void* user_data) {
|
||||
auto& graphics = *static_cast<GraphicContext*>(user_data);
|
||||
return graphics.instance.getProcAddr(name);
|
||||
}
|
||||
|
||||
void CheckVulkanResult(VkResult result) {
|
||||
EXIT_IF(result != VK_SUCCESS);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void InitializeImeDialogInput() {
|
||||
const Uint32 type = SDL_RegisterEvents(1);
|
||||
EXIT_IF(type == static_cast<Uint32>(-1));
|
||||
{
|
||||
std::scoped_lock lock(g_visibility_mutex);
|
||||
g_input_lifecycle_active = true;
|
||||
g_visibility_event.store(type, std::memory_order_release);
|
||||
}
|
||||
Ime::SetVisibilityCallback(OnVisibilityChanged);
|
||||
Ime::HostSnapshot snapshot;
|
||||
if (Ime::GetHostSnapshot(&snapshot)) {
|
||||
OnVisibilityChanged(true, snapshot.generation);
|
||||
}
|
||||
}
|
||||
|
||||
void ShutdownImeDialogInput() {
|
||||
Ime::SetVisibilityCallback(nullptr);
|
||||
{
|
||||
std::scoped_lock lock(g_visibility_mutex);
|
||||
g_input_lifecycle_active = false;
|
||||
g_active = false;
|
||||
if (std::exchange(g_controller_captured, false)) {
|
||||
Controller::ControllerResetInputState();
|
||||
}
|
||||
g_visibility_event.store(static_cast<Uint32>(-1), std::memory_order_release);
|
||||
}
|
||||
ClearInputEvents();
|
||||
{
|
||||
std::scoped_lock lock(g_input_mutex);
|
||||
g_visibility_updates.clear();
|
||||
g_missing_visibility_wakeups = 0;
|
||||
}
|
||||
g_input_active = false;
|
||||
g_input_controller = false;
|
||||
g_input_keyboard = false;
|
||||
g_input_multiline = false;
|
||||
if (SDL_IsTextInputActive() == SDL_TRUE) {
|
||||
SDL_StopTextInput();
|
||||
}
|
||||
}
|
||||
|
||||
bool ProcessImeDialogInput(const SDL_Event& event) {
|
||||
RetryVisibilityWakeup();
|
||||
if (event.type == g_visibility_event.load(std::memory_order_acquire)) {
|
||||
VisibilityUpdate update {};
|
||||
{
|
||||
std::scoped_lock lock(g_input_mutex);
|
||||
if (g_visibility_updates.empty()) {
|
||||
return true;
|
||||
}
|
||||
update = g_visibility_updates.front();
|
||||
g_visibility_updates.pop_front();
|
||||
}
|
||||
ClearInputEvents();
|
||||
g_last_external_keycode = 0;
|
||||
g_last_external_status = 0;
|
||||
g_input_generation = update.generation;
|
||||
g_input_active = update.visible;
|
||||
g_input_controller = update.capture_controller;
|
||||
g_input_keyboard = update.capture_keyboard;
|
||||
g_input_multiline = update.multiline;
|
||||
if (g_input_keyboard) {
|
||||
SDL_StartTextInput();
|
||||
} else if (SDL_IsTextInputActive() == SDL_TRUE) {
|
||||
SDL_StopTextInput();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (event.type == SDL_CONTROLLERDEVICEREMOVED) {
|
||||
if (g_input_active && g_input_controller) {
|
||||
QueueInput({InputKind::ResetController, g_input_generation, 0, 0.0f, 0.0f});
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (!g_input_active) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const uint64_t generation = g_input_generation;
|
||||
const bool controller_event = event.type == SDL_CONTROLLERBUTTONDOWN ||
|
||||
event.type == SDL_CONTROLLERBUTTONUP ||
|
||||
event.type == SDL_CONTROLLERAXISMOTION;
|
||||
if (controller_event && !g_input_controller) {
|
||||
return false;
|
||||
}
|
||||
const bool keyboard_event = event.type == SDL_TEXTINPUT || event.type == SDL_TEXTEDITING ||
|
||||
event.type == SDL_KEYDOWN || event.type == SDL_KEYUP;
|
||||
if (keyboard_event && !g_input_keyboard) {
|
||||
return false;
|
||||
}
|
||||
switch (event.type) {
|
||||
case SDL_TEXTINPUT: {
|
||||
const auto text = Utf8ToUtf16(event.text.text);
|
||||
if (!text.empty()) {
|
||||
auto input = MakeExternalInput(Ime::ExternalAction::Text, g_last_external_keycode,
|
||||
g_last_external_status | 0x00000002);
|
||||
input.key.character = text.front();
|
||||
input.text = text;
|
||||
Ime::HostQueueExternalInput(generation, std::move(input));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case SDL_TEXTEDITING: return true;
|
||||
case SDL_KEYDOWN: {
|
||||
g_last_external_keycode = static_cast<uint16_t>(event.key.keysym.scancode);
|
||||
g_last_external_status =
|
||||
ExternalKeyStatus(static_cast<SDL_Keymod>(event.key.keysym.mod), false);
|
||||
auto action = Ime::ExternalAction::Text;
|
||||
bool queue = true;
|
||||
if (event.key.keysym.sym == SDLK_BACKSPACE) {
|
||||
action = Ime::ExternalAction::Backspace;
|
||||
} else if (event.key.keysym.sym == SDLK_LEFT) {
|
||||
action = Ime::ExternalAction::MoveLeft;
|
||||
} else if (event.key.keysym.sym == SDLK_RIGHT) {
|
||||
action = Ime::ExternalAction::MoveRight;
|
||||
} else if (event.key.keysym.sym == SDLK_ESCAPE) {
|
||||
action = Ime::ExternalAction::Cancel;
|
||||
} else if (event.key.keysym.sym == SDLK_RETURN ||
|
||||
event.key.keysym.sym == SDLK_KP_ENTER) {
|
||||
action =
|
||||
g_input_multiline ? Ime::ExternalAction::Newline : Ime::ExternalAction::Accept;
|
||||
} else if (event.key.keysym.sym == SDLK_TAB) {
|
||||
action = Ime::ExternalAction::None;
|
||||
} else {
|
||||
queue = false;
|
||||
}
|
||||
if (queue) {
|
||||
Ime::HostQueueExternalInput(
|
||||
generation,
|
||||
MakeExternalInput(action, g_last_external_keycode, g_last_external_status));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case SDL_KEYUP: return true;
|
||||
case SDL_CONTROLLERBUTTONDOWN:
|
||||
case SDL_CONTROLLERBUTTONUP:
|
||||
QueueInput({InputKind::Button, generation, event.cbutton.button,
|
||||
event.type == SDL_CONTROLLERBUTTONDOWN ? 1.0f : 0.0f, 0.0f});
|
||||
return true;
|
||||
case SDL_CONTROLLERAXISMOTION:
|
||||
QueueInput({InputKind::Axis, generation, event.caxis.axis,
|
||||
static_cast<float>(event.caxis.value), 0.0f});
|
||||
return true;
|
||||
case SDL_MOUSEMOTION:
|
||||
QueueInput({InputKind::MousePosition, generation, 0, static_cast<float>(event.motion.x),
|
||||
static_cast<float>(event.motion.y)});
|
||||
return true;
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
QueueInput({InputKind::MouseButton, generation, event.button.button,
|
||||
event.type == SDL_MOUSEBUTTONDOWN ? 1.0f : 0.0f, 0.0f});
|
||||
return true;
|
||||
case SDL_MOUSEWHEEL:
|
||||
QueueInput({InputKind::MouseWheel, generation, 0, static_cast<float>(event.wheel.x),
|
||||
static_cast<float>(event.wheel.y)});
|
||||
return true;
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
|
||||
struct ImeDialogOverlay::Impl {
|
||||
explicit Impl(GraphicContext& context): graphics(context) {}
|
||||
|
||||
~Impl() {
|
||||
ReleaseVulkan();
|
||||
if (imgui_context != nullptr) {
|
||||
ImGui::DestroyContext(imgui_context);
|
||||
}
|
||||
}
|
||||
|
||||
void EnsureContext() {
|
||||
if (imgui_context != nullptr) {
|
||||
ImGui::SetCurrentContext(imgui_context);
|
||||
return;
|
||||
}
|
||||
IMGUI_CHECKVERSION();
|
||||
imgui_context = ImGui::CreateContext();
|
||||
ImGui::SetCurrentContext(imgui_context);
|
||||
auto& io = ImGui::GetIO();
|
||||
io.IniFilename = nullptr;
|
||||
io.LogFilename = nullptr;
|
||||
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad;
|
||||
io.BackendFlags |= ImGuiBackendFlags_HasGamepad;
|
||||
io.BackendPlatformName = "Kyty ImeDialog input";
|
||||
ImGui::StyleColorsDark();
|
||||
auto& style = ImGui::GetStyle();
|
||||
style.WindowRounding = 10.0f;
|
||||
style.FrameRounding = 6.0f;
|
||||
style.ItemSpacing = {8.0f, 8.0f};
|
||||
}
|
||||
|
||||
void EnsureVulkan(vk::Format format, uint32_t image_count) {
|
||||
EnsureContext();
|
||||
if (vulkan_initialized) {
|
||||
return;
|
||||
}
|
||||
EXIT_IF(image_count < 2);
|
||||
EXIT_IF(!ImGui_ImplVulkan_LoadFunctions(VK_API_VERSION_1_3, LoadVulkanFunction, &graphics));
|
||||
|
||||
const VkFormat color_format = static_cast<VkFormat>(format);
|
||||
ImGui_ImplVulkan_InitInfo info {};
|
||||
info.ApiVersion = VK_API_VERSION_1_3;
|
||||
info.Instance = static_cast<VkInstance>(graphics.instance);
|
||||
info.PhysicalDevice = static_cast<VkPhysicalDevice>(graphics.physical_device);
|
||||
info.Device = static_cast<VkDevice>(graphics.device);
|
||||
info.QueueFamily = graphics.queue_family;
|
||||
info.Queue = static_cast<VkQueue>(graphics.queue);
|
||||
info.DescriptorPoolSize = IMGUI_IMPL_VULKAN_MINIMUM_SAMPLED_IMAGE_POOL_SIZE;
|
||||
info.MinImageCount = image_count;
|
||||
info.ImageCount = image_count;
|
||||
info.UseDynamicRendering = true;
|
||||
info.PipelineInfoMain.MSAASamples = VK_SAMPLE_COUNT_1_BIT;
|
||||
info.PipelineInfoMain.PipelineRenderingCreateInfo.sType =
|
||||
VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO;
|
||||
info.PipelineInfoMain.PipelineRenderingCreateInfo.colorAttachmentCount = 1;
|
||||
info.PipelineInfoMain.PipelineRenderingCreateInfo.pColorAttachmentFormats = &color_format;
|
||||
info.CheckVkResultFn = CheckVulkanResult;
|
||||
EXIT_IF(!ImGui_ImplVulkan_Init(&info));
|
||||
vulkan_initialized = true;
|
||||
}
|
||||
|
||||
void DrainInput(uint64_t generation) {
|
||||
std::deque<InputEvent> events;
|
||||
bool reset = false;
|
||||
{
|
||||
std::scoped_lock lock(g_input_mutex);
|
||||
events.swap(g_input_events);
|
||||
reset = g_input_reset_requested;
|
||||
g_input_reset_requested = false;
|
||||
}
|
||||
auto& io = ImGui::GetIO();
|
||||
if (reset) {
|
||||
io.ClearEventsQueue();
|
||||
io.ClearInputKeys();
|
||||
io.ClearInputMouse();
|
||||
right_stick = {};
|
||||
}
|
||||
for (const auto& event: events) {
|
||||
if (event.generation != generation) {
|
||||
continue;
|
||||
}
|
||||
switch (event.kind) {
|
||||
case InputKind::Button: {
|
||||
const bool down = event.x != 0.0f;
|
||||
if (down && event.id == SDL_CONTROLLER_BUTTON_B) {
|
||||
Ime::HostCancel(generation);
|
||||
} else if (down && event.id == SDL_CONTROLLER_BUTTON_Y) {
|
||||
Ime::HostBackspace(generation);
|
||||
}
|
||||
const ImGuiKey key = ControllerButtonToKey(event.id);
|
||||
if (key != ImGuiKey_None) {
|
||||
io.AddKeyEvent(key, down);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case InputKind::Axis: {
|
||||
const float value = event.x / (event.x < 0.0f ? 32768.0f : 32767.0f);
|
||||
if (event.id == SDL_CONTROLLER_AXIS_LEFTX) {
|
||||
io.AddKeyAnalogEvent(ImGuiKey_GamepadLStickLeft, value < -0.25f,
|
||||
std::max(-value, 0.0f));
|
||||
io.AddKeyAnalogEvent(ImGuiKey_GamepadLStickRight, value > 0.25f,
|
||||
std::max(value, 0.0f));
|
||||
} else if (event.id == SDL_CONTROLLER_AXIS_LEFTY) {
|
||||
io.AddKeyAnalogEvent(ImGuiKey_GamepadLStickUp, value < -0.25f,
|
||||
std::max(-value, 0.0f));
|
||||
io.AddKeyAnalogEvent(ImGuiKey_GamepadLStickDown, value > 0.25f,
|
||||
std::max(value, 0.0f));
|
||||
} else if (event.id == SDL_CONTROLLER_AXIS_RIGHTX) {
|
||||
right_stick.x = std::abs(value) > 0.2f ? value : 0.0f;
|
||||
} else if (event.id == SDL_CONTROLLER_AXIS_RIGHTY) {
|
||||
right_stick.y = std::abs(value) > 0.2f ? value : 0.0f;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case InputKind::MousePosition: io.AddMousePosEvent(event.x, event.y); break;
|
||||
case InputKind::MouseButton: {
|
||||
int button = -1;
|
||||
if (event.id == SDL_BUTTON_LEFT) button = 0;
|
||||
if (event.id == SDL_BUTTON_RIGHT) button = 1;
|
||||
if (event.id == SDL_BUTTON_MIDDLE) button = 2;
|
||||
if (button >= 0) io.AddMouseButtonEvent(button, event.x != 0.0f);
|
||||
break;
|
||||
}
|
||||
case InputKind::MouseWheel: io.AddMouseWheelEvent(event.x, event.y); break;
|
||||
case InputKind::ResetController:
|
||||
io.ClearEventsQueue();
|
||||
io.ClearInputKeys();
|
||||
right_stick = {};
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void KeyButton(std::string_view label, char16_t value, uint64_t generation, float width,
|
||||
bool default_focus) {
|
||||
const bool pressed = ImGui::Button(label.data(), {width, button_height});
|
||||
if (default_focus) {
|
||||
ImGui::SetItemDefaultFocus();
|
||||
}
|
||||
if (pressed) {
|
||||
Ime::HostInsertText(generation, std::u16string_view(&value, 1));
|
||||
}
|
||||
}
|
||||
|
||||
void DrawKeyRows(const Ime::HostSnapshot& snapshot, float width) {
|
||||
static constexpr std::array<std::string_view, 4> lower = {"1234567890", "qwertyuiop",
|
||||
"asdfghjkl", "zxcvbnm"};
|
||||
static constexpr std::array<std::string_view, 4> upper = {"1234567890", "QWERTYUIOP",
|
||||
"ASDFGHJKL", "ZXCVBNM"};
|
||||
static constexpr std::array<std::string_view, 3> symbols = {"1234567890", "!@#$%^&*()",
|
||||
"-_=+/:?."};
|
||||
static constexpr std::array<std::string_view, 4> number = {"123", "456", "789", "-0."};
|
||||
|
||||
std::span<const std::string_view> rows;
|
||||
if (snapshot.type == Ime::Type::Number) {
|
||||
rows = number;
|
||||
} else if (symbol_mode) {
|
||||
rows = symbols;
|
||||
} else {
|
||||
rows = shift ? std::span<const std::string_view>(upper)
|
||||
: std::span<const std::string_view>(lower);
|
||||
}
|
||||
bool first = focus_pending;
|
||||
size_t row_index = 0;
|
||||
for (const auto row: rows) {
|
||||
const float key_width =
|
||||
std::min(56.0f * ui_scale, (width - 8.0f * (row.size() - 1)) / row.size());
|
||||
const float row_width = key_width * row.size() + 8.0f * (row.size() - 1);
|
||||
ImGui::SetCursorPosX((width - row_width) * 0.5f);
|
||||
ImGui::PushID(static_cast<int>(row_index++));
|
||||
for (size_t i = 0; i < row.size(); i++) {
|
||||
ImGui::PushID(static_cast<int>(i));
|
||||
const char label[2] = {row[i], '\0'};
|
||||
KeyButton(label, static_cast<char16_t>(row[i]), snapshot.generation, key_width,
|
||||
first);
|
||||
first = false;
|
||||
ImGui::PopID();
|
||||
if (i + 1 < row.size()) ImGui::SameLine();
|
||||
}
|
||||
ImGui::PopID();
|
||||
}
|
||||
focus_pending = false;
|
||||
}
|
||||
|
||||
void DrawDialog(const Ime::HostSnapshot& snapshot, vk::Extent2D extent) {
|
||||
const ImVec2 display(static_cast<float>(extent.width), static_cast<float>(extent.height));
|
||||
const bool over_2k = (snapshot.option & Ime::OPTION_USE_OVER_2K) != 0;
|
||||
const float reference_width = over_2k ? 3840.0f : 1920.0f;
|
||||
const float reference_height = over_2k ? 2160.0f : 1080.0f;
|
||||
const float scale_x = display.x / reference_width;
|
||||
const float scale_y = display.y / reference_height;
|
||||
const float width = static_cast<float>(snapshot.panel_width) * scale_x;
|
||||
const float height = static_cast<float>(snapshot.panel_height) * scale_y;
|
||||
ui_scale = std::min(scale_x, scale_y) * (over_2k ? 2.0f : 1.0f);
|
||||
button_height = std::max(28.0f, 42.0f * ui_scale);
|
||||
|
||||
const ImVec2 pivot {AlignmentPivot(snapshot.horizontal_alignment),
|
||||
AlignmentPivot(snapshot.vertical_alignment)};
|
||||
if ((snapshot.option & Ime::OPTION_FIXED_POSITION) == 0) {
|
||||
const float movement = 600.0f * ImGui::GetIO().DeltaTime;
|
||||
panel_offset.x += right_stick.x * movement;
|
||||
panel_offset.y += right_stick.y * movement;
|
||||
}
|
||||
const ImVec2 base_position {snapshot.posx * scale_x - pivot.x * width,
|
||||
snapshot.posy * scale_y - pivot.y * height};
|
||||
ImVec2 position {base_position.x + panel_offset.x, base_position.y + panel_offset.y};
|
||||
if ((snapshot.option & Ime::OPTION_DISABLE_POSITION_ADJ) == 0) {
|
||||
position.x = std::clamp(position.x, 0.0f, std::max(display.x - width, 0.0f));
|
||||
position.y = std::clamp(position.y, 0.0f, std::max(display.y - height, 0.0f));
|
||||
panel_offset = {position.x - base_position.x, position.y - base_position.y};
|
||||
}
|
||||
ImGui::SetNextWindowPos(position, ImGuiCond_Always);
|
||||
ImGui::SetNextWindowSize({width, height}, ImGuiCond_Always);
|
||||
constexpr ImGuiWindowFlags flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove |
|
||||
ImGuiWindowFlags_NoSavedSettings;
|
||||
ImGui::Begin("##ImeDialog", nullptr, flags);
|
||||
|
||||
const std::u16string title = snapshot.title.empty() ? u"Enter text" : snapshot.title;
|
||||
if (!snapshot.key_panel_visible) {
|
||||
std::string compact = Common::Utf16ToUtf8(title.c_str()) + ": ";
|
||||
const float glyph_width = std::max(ImGui::CalcTextSize("M").x, 1.0f);
|
||||
const float text_width =
|
||||
std::max(ImGui::GetContentRegionAvail().x - ImGui::CalcTextSize(compact.c_str()).x,
|
||||
glyph_width);
|
||||
const size_t visible_units =
|
||||
std::max<size_t>(6, static_cast<size_t>(text_width / glyph_width));
|
||||
compact += snapshot.text.empty() && !snapshot.placeholder.empty()
|
||||
? Common::Utf16ToUtf8(snapshot.placeholder.c_str())
|
||||
: VisibleText(snapshot, visible_units);
|
||||
ImGui::TextUnformatted(compact.c_str());
|
||||
const float compact_height = std::min(button_height, 28.0f * ui_scale);
|
||||
if (ImGui::Button("Cancel", {90.0f * ui_scale, compact_height})) {
|
||||
Ime::HostCancel(snapshot.generation);
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button(EnterLabel(snapshot.enter_label),
|
||||
{90.0f * ui_scale, compact_height})) {
|
||||
Ime::HostAccept(snapshot.generation);
|
||||
}
|
||||
ImGui::End();
|
||||
return;
|
||||
}
|
||||
|
||||
ImGui::TextUnformatted(Common::Utf16ToUtf8(title.c_str()).c_str());
|
||||
ImGui::Separator();
|
||||
const float text_height = std::max(
|
||||
32.0f, ((snapshot.option & Ime::OPTION_MULTILINE) != 0 ? 80.0f : 48.0f) * ui_scale);
|
||||
ImGui::BeginChild("##ImeText", {0.0f, text_height}, true);
|
||||
if (snapshot.text.empty() && !snapshot.placeholder.empty()) {
|
||||
ImGui::TextDisabled("%s", Common::Utf16ToUtf8(snapshot.placeholder.c_str()).c_str());
|
||||
} else {
|
||||
const float glyph_width = std::max(ImGui::CalcTextSize("M").x, 1.0f);
|
||||
const size_t columns = std::max<size_t>(
|
||||
8, static_cast<size_t>(ImGui::GetContentRegionAvail().x / glyph_width));
|
||||
const size_t lines =
|
||||
std::max<size_t>(1, static_cast<size_t>(ImGui::GetContentRegionAvail().y /
|
||||
ImGui::GetTextLineHeightWithSpacing()));
|
||||
const auto text = VisibleText(snapshot, columns * lines);
|
||||
ImGui::TextWrapped("%s", text.c_str());
|
||||
}
|
||||
ImGui::EndChild();
|
||||
ImGui::TextDisabled("%zu / %u", snapshot.text.size(), snapshot.max_text_length);
|
||||
ImGui::Separator();
|
||||
|
||||
const float content_width = ImGui::GetContentRegionAvail().x;
|
||||
DrawKeyRows(snapshot, content_width);
|
||||
if (snapshot.type != Ime::Type::Number) {
|
||||
if (ImGui::Button(shift ? "Lower" : "Shift", {84.0f * ui_scale, button_height})) {
|
||||
shift = !shift;
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button(symbol_mode ? "ABC" : "Symbols", {84.0f * ui_scale, button_height})) {
|
||||
symbol_mode = !symbol_mode;
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Space", {120.0f * ui_scale, button_height})) {
|
||||
Ime::HostInsertText(snapshot.generation, u" ");
|
||||
}
|
||||
ImGui::SameLine();
|
||||
}
|
||||
const float action_width = snapshot.type == Ime::Type::Number
|
||||
? std::max((content_width - 16.0f) / 3.0f, 48.0f)
|
||||
: 100.0f * ui_scale;
|
||||
if (ImGui::Button("Backspace", {action_width, button_height})) {
|
||||
Ime::HostBackspace(snapshot.generation);
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if ((snapshot.option & Ime::OPTION_MULTILINE) != 0) {
|
||||
if (ImGui::Button("Newline", {action_width, button_height})) {
|
||||
Ime::HostInsertText(snapshot.generation, u"\n");
|
||||
}
|
||||
ImGui::SameLine();
|
||||
}
|
||||
if (ImGui::Button("Cancel", {action_width, button_height})) {
|
||||
Ime::HostCancel(snapshot.generation);
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button(EnterLabel(snapshot.enter_label), {action_width, button_height})) {
|
||||
Ime::HostAccept(snapshot.generation);
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
bool PrepareFrame(vk::Extent2D frame_extent, vk::Format format, uint32_t image_count) {
|
||||
Ime::HostSnapshot snapshot;
|
||||
if (!Ime::GetHostSnapshot(&snapshot)) {
|
||||
return false;
|
||||
}
|
||||
const uint64_t prepared_generation = snapshot.generation;
|
||||
EnsureVulkan(format, image_count);
|
||||
if (generation != snapshot.generation) {
|
||||
generation = snapshot.generation;
|
||||
focus_pending = true;
|
||||
shift = (snapshot.option & Ime::OPTION_NO_AUTO_CAPITALIZE) == 0;
|
||||
symbol_mode = false;
|
||||
panel_offset = {};
|
||||
right_stick = {};
|
||||
auto& io = ImGui::GetIO();
|
||||
io.ClearEventsQueue();
|
||||
io.ClearInputKeys();
|
||||
io.ClearInputMouse();
|
||||
}
|
||||
DrainInput(snapshot.generation);
|
||||
|
||||
auto& io = ImGui::GetIO();
|
||||
io.DisplaySize = {static_cast<float>(frame_extent.width),
|
||||
static_cast<float>(frame_extent.height)};
|
||||
const auto now = std::chrono::steady_clock::now();
|
||||
io.DeltaTime = last_frame == std::chrono::steady_clock::time_point {}
|
||||
? 1.0f / 60.0f
|
||||
: std::clamp(std::chrono::duration<float>(now - last_frame).count(),
|
||||
1.0f / 1000.0f, 0.1f);
|
||||
last_frame = now;
|
||||
ImGui_ImplVulkan_NewFrame();
|
||||
ImGui::NewFrame();
|
||||
if (!Ime::GetHostSnapshot(&snapshot) || snapshot.generation != prepared_generation) {
|
||||
ImGui::EndFrame();
|
||||
return false;
|
||||
}
|
||||
DrawDialog(snapshot, frame_extent);
|
||||
ImGui::Render();
|
||||
extent = frame_extent;
|
||||
return true;
|
||||
}
|
||||
|
||||
void Record(vk::CommandBuffer command, vk::ImageView target) {
|
||||
vk::RenderingAttachmentInfo color {};
|
||||
color.sType = vk::StructureType::eRenderingAttachmentInfo;
|
||||
color.imageView = target;
|
||||
color.imageLayout = vk::ImageLayout::eColorAttachmentOptimal;
|
||||
color.loadOp = vk::AttachmentLoadOp::eLoad;
|
||||
color.storeOp = vk::AttachmentStoreOp::eStore;
|
||||
vk::RenderingInfo rendering {};
|
||||
rendering.sType = vk::StructureType::eRenderingInfo;
|
||||
rendering.renderArea.extent = extent;
|
||||
rendering.layerCount = 1;
|
||||
rendering.colorAttachmentCount = 1;
|
||||
rendering.pColorAttachments = &color;
|
||||
command.beginRendering(rendering);
|
||||
{
|
||||
Common::LockGuard queue_lock(graphics.queue_mutex);
|
||||
ImGui_ImplVulkan_RenderDrawData(ImGui::GetDrawData(),
|
||||
static_cast<VkCommandBuffer>(command));
|
||||
}
|
||||
command.endRendering();
|
||||
}
|
||||
|
||||
void ReleaseVulkan() {
|
||||
if (!vulkan_initialized) {
|
||||
return;
|
||||
}
|
||||
ImGui::SetCurrentContext(imgui_context);
|
||||
ImGui_ImplVulkan_Shutdown();
|
||||
vulkan_initialized = false;
|
||||
}
|
||||
|
||||
GraphicContext& graphics;
|
||||
ImGuiContext* imgui_context = nullptr;
|
||||
bool vulkan_initialized = false;
|
||||
bool shift = false;
|
||||
bool symbol_mode = false;
|
||||
bool focus_pending = true;
|
||||
float ui_scale = 1.0f;
|
||||
float button_height = 42.0f;
|
||||
ImVec2 panel_offset {};
|
||||
ImVec2 right_stick {};
|
||||
uint64_t generation = 0;
|
||||
vk::Extent2D extent {};
|
||||
std::chrono::steady_clock::time_point last_frame;
|
||||
};
|
||||
|
||||
ImeDialogOverlay::ImeDialogOverlay(GraphicContext& graphics)
|
||||
: m_impl(std::make_unique<Impl>(graphics)) {}
|
||||
|
||||
ImeDialogOverlay::~ImeDialogOverlay() = default;
|
||||
|
||||
bool ImeDialogOverlay::PrepareFrame(vk::Extent2D extent, vk::Format format, uint32_t image_count) {
|
||||
return m_impl->PrepareFrame(extent, format, image_count);
|
||||
}
|
||||
|
||||
void ImeDialogOverlay::Record(vk::CommandBuffer command, vk::ImageView target) {
|
||||
m_impl->Record(command, target);
|
||||
}
|
||||
|
||||
void ImeDialogOverlay::ReleaseVulkan() {
|
||||
m_impl->ReleaseVulkan();
|
||||
}
|
||||
|
||||
} // namespace Libs::Graphics
|
||||
@@ -0,0 +1,36 @@
|
||||
#ifndef EMULATOR_SRC_GRAPHICS_PRESENTATION_IMEDIALOGOVERLAY_H_
|
||||
#define EMULATOR_SRC_GRAPHICS_PRESENTATION_IMEDIALOGOVERLAY_H_
|
||||
|
||||
#include "common/common.h"
|
||||
#include "graphics/host_gpu/vulkanCommon.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
union SDL_Event;
|
||||
|
||||
namespace Libs::Graphics {
|
||||
|
||||
struct GraphicContext;
|
||||
|
||||
void InitializeImeDialogInput();
|
||||
void ShutdownImeDialogInput();
|
||||
bool ProcessImeDialogInput(const SDL_Event& event);
|
||||
|
||||
class ImeDialogOverlay final {
|
||||
public:
|
||||
explicit ImeDialogOverlay(GraphicContext& graphics);
|
||||
~ImeDialogOverlay();
|
||||
KYTY_CLASS_NO_COPY(ImeDialogOverlay);
|
||||
|
||||
[[nodiscard]] bool PrepareFrame(vk::Extent2D extent, vk::Format format, uint32_t image_count);
|
||||
void Record(vk::CommandBuffer command, vk::ImageView target);
|
||||
void ReleaseVulkan();
|
||||
|
||||
private:
|
||||
struct Impl;
|
||||
std::unique_ptr<Impl> m_impl;
|
||||
};
|
||||
|
||||
} // namespace Libs::Graphics
|
||||
|
||||
#endif // EMULATOR_SRC_GRAPHICS_PRESENTATION_IMEDIALOGOVERLAY_H_
|
||||
@@ -25,6 +25,7 @@ public:
|
||||
CommandBuffer* producer = nullptr);
|
||||
[[nodiscard]] Frame* PrepareLastFrame();
|
||||
[[nodiscard]] bool IsGuestPaused() const noexcept;
|
||||
[[nodiscard]] bool NeedsImeRefresh() const noexcept;
|
||||
[[nodiscard]] RenderContext& Renderer() const noexcept;
|
||||
void Present(Frame& frame, bool reuse = false);
|
||||
void Discard(Frame& frame);
|
||||
|
||||
@@ -128,8 +128,7 @@ static bool BindRenderDocApi(HMODULE module) {
|
||||
g_api = static_cast<RenderDocApi*>(api);
|
||||
|
||||
g_api->SetCaptureFilePathTemplate("_RenderDoc/kyty");
|
||||
static RenderDocInputButton capture_keys[] = {eRENDERDOC_Key_F1};
|
||||
g_api->SetCaptureKeys(capture_keys, 1);
|
||||
g_api->SetCaptureKeys(nullptr, 0);
|
||||
g_api->UnloadCrashHandler();
|
||||
|
||||
char module_path[MAX_PATH] = {};
|
||||
@@ -170,8 +169,7 @@ static bool BindRenderDocApi(HMODULE module) {
|
||||
g_api = static_cast<RenderDocApi*>(api);
|
||||
|
||||
g_api->SetCaptureFilePathTemplate("_RenderDoc/kyty");
|
||||
static RenderDocInputButton capture_keys[] = {eRENDERDOC_Key_F1};
|
||||
g_api->SetCaptureKeys(capture_keys, 1);
|
||||
g_api->SetCaptureKeys(nullptr, 0);
|
||||
g_api->UnloadCrashHandler();
|
||||
|
||||
Dl_info info {};
|
||||
|
||||
@@ -537,10 +537,10 @@ Graphics::ImageInfo BufferAttributeGroup::ImageInfo(const VideoOutBuffer& buffer
|
||||
const auto tile_mode =
|
||||
Graphics::Prospero::GpuEnumValue(Graphics::Prospero::TileMode::kRenderTarget);
|
||||
const auto pitch =
|
||||
Graphics::TileGetTexturePitch(pixel_format.guest_format, attribute.width, 1, tile_mode);
|
||||
Graphics::TileGetTexturePitch(pixel_format.guest_format, attribute.width, tile_mode);
|
||||
Graphics::TileSizeAlign total {};
|
||||
Graphics::TileGetTextureTotalSize(pixel_format.guest_format, attribute.width, attribute.height,
|
||||
1, pitch, 1, tile_mode, false, total);
|
||||
1, 1, tile_mode, false, total);
|
||||
if (total.size == 0 || total.align != 65536 ||
|
||||
(buffer.data_address & (total.align - 1u)) != 0) {
|
||||
EXIT("invalid video-out surface footprint or alignment\n");
|
||||
@@ -817,7 +817,24 @@ void VideoOutDriver::Impl::PresentThread(std::stop_token token) {
|
||||
}
|
||||
|
||||
VblankBegin();
|
||||
const bool presented = m_flip_queue.Flip(0);
|
||||
bool presented = m_flip_queue.Flip(0);
|
||||
if (!presented && m_presenter.NeedsImeRefresh()) {
|
||||
if (auto* frame = m_presenter.PrepareLastFrame(); frame != nullptr) {
|
||||
m_presenter.Present(*frame, true);
|
||||
presented = true;
|
||||
} else {
|
||||
uint32_t width = 0;
|
||||
uint32_t height = 0;
|
||||
{
|
||||
Common::LockGuard lock(m_mutex);
|
||||
width = m_video_out_ctx[0].width;
|
||||
height = m_video_out_ctx[0].height;
|
||||
}
|
||||
auto& blank = m_presenter.PrepareBlankFrame(width, height, true);
|
||||
m_presenter.Present(blank);
|
||||
presented = true;
|
||||
}
|
||||
}
|
||||
if (!presented && total_wait < 0) {
|
||||
bool any_open = false;
|
||||
uint32_t width = 0;
|
||||
|
||||
@@ -0,0 +1,256 @@
|
||||
#include "graphics/presentation/window/hostInput.h"
|
||||
|
||||
#include "SDL_keyboard.h"
|
||||
#include "SDL_keycode.h"
|
||||
#include "SDL_mouse.h"
|
||||
#include "common/assert.h"
|
||||
#include "common/emulatorConfig.h"
|
||||
#include "libs/controller.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
|
||||
namespace Libs::Graphics {
|
||||
|
||||
namespace {
|
||||
|
||||
struct Binding {
|
||||
SDL_Keycode key = SDLK_UNKNOWN;
|
||||
uint8_t mouse_button = 0;
|
||||
uint32_t pad_button = 0;
|
||||
};
|
||||
|
||||
static constexpr std::array PAD_BUTTONS = {
|
||||
std::pair {std::string_view("L3"), Controller::PAD_BUTTON_L3},
|
||||
std::pair {std::string_view("R3"), Controller::PAD_BUTTON_R3},
|
||||
std::pair {std::string_view("Options"), Controller::PAD_BUTTON_OPTIONS},
|
||||
std::pair {std::string_view("Up"), Controller::PAD_BUTTON_UP},
|
||||
std::pair {std::string_view("Right"), Controller::PAD_BUTTON_RIGHT},
|
||||
std::pair {std::string_view("Down"), Controller::PAD_BUTTON_DOWN},
|
||||
std::pair {std::string_view("Left"), Controller::PAD_BUTTON_LEFT},
|
||||
std::pair {std::string_view("L2"), Controller::PAD_BUTTON_L2},
|
||||
std::pair {std::string_view("R2"), Controller::PAD_BUTTON_R2},
|
||||
std::pair {std::string_view("L1"), Controller::PAD_BUTTON_L1},
|
||||
std::pair {std::string_view("R1"), Controller::PAD_BUTTON_R1},
|
||||
std::pair {std::string_view("Triangle"), Controller::PAD_BUTTON_TRIANGLE},
|
||||
std::pair {std::string_view("Circle"), Controller::PAD_BUTTON_CIRCLE},
|
||||
std::pair {std::string_view("Cross"), Controller::PAD_BUTTON_CROSS},
|
||||
std::pair {std::string_view("Square"), Controller::PAD_BUTTON_SQUARE},
|
||||
std::pair {std::string_view("TouchPad"), Controller::PAD_BUTTON_TOUCH_PAD},
|
||||
};
|
||||
|
||||
uint32_t PadButtonFromName(std::string_view name) {
|
||||
const auto button = std::find_if(PAD_BUTTONS.begin(), PAD_BUTTONS.end(),
|
||||
[name](const auto& item) { return item.first == name; });
|
||||
return button != PAD_BUTTONS.end() ? button->second : 0;
|
||||
}
|
||||
|
||||
SDL_Keycode NormalizeKey(SDL_Keycode key) {
|
||||
switch (key) {
|
||||
case SDLK_RSHIFT: return SDLK_LSHIFT;
|
||||
case SDLK_RCTRL: return SDLK_LCTRL;
|
||||
case SDLK_RALT: return SDLK_LALT;
|
||||
case SDLK_RGUI: return SDLK_LGUI;
|
||||
default: return key;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t MouseButtonFromName(std::string_view name) {
|
||||
static constexpr std::array buttons = {
|
||||
std::pair {std::string_view("Mouse:Left"), uint8_t {SDL_BUTTON_LEFT}},
|
||||
std::pair {std::string_view("Mouse:Middle"), uint8_t {SDL_BUTTON_MIDDLE}},
|
||||
std::pair {std::string_view("Mouse:Right"), uint8_t {SDL_BUTTON_RIGHT}},
|
||||
std::pair {std::string_view("Mouse:X1"), uint8_t {SDL_BUTTON_X1}},
|
||||
std::pair {std::string_view("Mouse:X2"), uint8_t {SDL_BUTTON_X2}},
|
||||
};
|
||||
|
||||
const auto button = std::find_if(buttons.begin(), buttons.end(),
|
||||
[name](const auto& item) { return item.first == name; });
|
||||
return button != buttons.end() ? button->second : 0;
|
||||
}
|
||||
|
||||
bool Conflicts(const Binding& first, const Binding& second) {
|
||||
return first.pad_button == second.pad_button ||
|
||||
(first.key != SDLK_UNKNOWN && first.key == second.key) ||
|
||||
(first.mouse_button != 0 && first.mouse_button == second.mouse_button);
|
||||
}
|
||||
|
||||
class InputMap {
|
||||
public:
|
||||
InputMap(): m_custom(!Config::GetKeymap().empty()) {
|
||||
for (const auto& value: Config::GetKeymap()) {
|
||||
const std::string_view entry = value;
|
||||
const auto split = entry.find('=');
|
||||
|
||||
Binding binding;
|
||||
if (split != std::string_view::npos) {
|
||||
binding.pad_button = PadButtonFromName(entry.substr(0, split));
|
||||
const auto host_input = entry.substr(split + 1);
|
||||
binding.mouse_button = MouseButtonFromName(host_input);
|
||||
if (binding.mouse_button == 0) {
|
||||
binding.key = NormalizeKey(SDL_GetKeyFromName(std::string(host_input).c_str()));
|
||||
}
|
||||
}
|
||||
|
||||
const bool reserved =
|
||||
binding.key == SDLK_ESCAPE || binding.key == SDLK_SPACE || binding.key == SDLK_F1;
|
||||
if (binding.pad_button == 0 || reserved ||
|
||||
(binding.key == SDLK_UNKNOWN && binding.mouse_button == 0)) {
|
||||
EXIT("Invalid input mapping: %s\n", value.c_str());
|
||||
}
|
||||
Add(binding);
|
||||
}
|
||||
}
|
||||
[[nodiscard]] bool Custom() const { return m_custom; }
|
||||
|
||||
[[nodiscard]] uint32_t FindKey(int key_code) const {
|
||||
key_code = NormalizeKey(static_cast<SDL_Keycode>(key_code));
|
||||
const auto binding =
|
||||
std::find_if(m_bindings.begin(), m_bindings.begin() + m_size,
|
||||
[key_code](const auto& item) { return item.key == key_code; });
|
||||
return binding != m_bindings.begin() + m_size ? binding->pad_button : 0;
|
||||
}
|
||||
|
||||
[[nodiscard]] uint32_t FindMouseButton(uint8_t mouse_button) const {
|
||||
const auto binding = std::find_if(
|
||||
m_bindings.begin(), m_bindings.begin() + m_size,
|
||||
[mouse_button](const auto& item) { return item.mouse_button == mouse_button; });
|
||||
return binding != m_bindings.begin() + m_size ? binding->pad_button : 0;
|
||||
}
|
||||
|
||||
private:
|
||||
void Add(const Binding& binding) {
|
||||
for (std::size_t index = 0; index < m_size;) {
|
||||
if (Conflicts(m_bindings[index], binding)) {
|
||||
m_bindings[index] = m_bindings[--m_size];
|
||||
} else {
|
||||
index++;
|
||||
}
|
||||
}
|
||||
EXIT_IF(m_size >= m_bindings.size());
|
||||
m_bindings[m_size++] = binding;
|
||||
}
|
||||
|
||||
std::array<Binding, PAD_BUTTONS.size()> m_bindings {};
|
||||
std::size_t m_size = 0;
|
||||
bool m_custom;
|
||||
};
|
||||
|
||||
const InputMap& GetInputMap() {
|
||||
static const InputMap map;
|
||||
return map;
|
||||
}
|
||||
|
||||
void SetButton(uint32_t button, bool down) {
|
||||
if (button == Controller::PAD_BUTTON_L2) {
|
||||
Controller::ControllerAxis(Controller::HOST_INPUT_CONTROLLER_ID,
|
||||
Controller::Axis::TriggerLeft, down ? 255 : 0);
|
||||
} else if (button == Controller::PAD_BUTTON_R2) {
|
||||
Controller::ControllerAxis(Controller::HOST_INPUT_CONTROLLER_ID,
|
||||
Controller::Axis::TriggerRight, down ? 255 : 0);
|
||||
} else if (button != 0) {
|
||||
Controller::ControllerButton(Controller::HOST_INPUT_CONTROLLER_ID, button, down);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t DefaultKeyboardButton(int key_code) {
|
||||
switch (NormalizeKey(static_cast<SDL_Keycode>(key_code))) {
|
||||
case SDLK_UP: return Controller::PAD_BUTTON_UP;
|
||||
case SDLK_LEFT: return Controller::PAD_BUTTON_LEFT;
|
||||
case SDLK_DOWN: return Controller::PAD_BUTTON_DOWN;
|
||||
case SDLK_RIGHT: return Controller::PAD_BUTTON_RIGHT;
|
||||
case SDLK_j: return Controller::PAD_BUTTON_CROSS;
|
||||
case SDLK_i: return Controller::PAD_BUTTON_TRIANGLE;
|
||||
case SDLK_k: return Controller::PAD_BUTTON_SQUARE;
|
||||
case SDLK_l: return Controller::PAD_BUTTON_CIRCLE;
|
||||
case SDLK_q: return Controller::PAD_BUTTON_L1;
|
||||
case SDLK_e: return Controller::PAD_BUTTON_R1;
|
||||
case SDLK_LSHIFT: return Controller::PAD_BUTTON_L3;
|
||||
case SDLK_LCTRL: return Controller::PAD_BUTTON_R3;
|
||||
case SDLK_RETURN:
|
||||
case SDLK_RETURN2: return Controller::PAD_BUTTON_OPTIONS;
|
||||
case SDLK_BACKSPACE:
|
||||
case SDLK_TAB: return Controller::PAD_BUTTON_TOUCH_PAD;
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
|
||||
struct StickKeys {
|
||||
bool left = false;
|
||||
bool right = false;
|
||||
bool up = false;
|
||||
bool down = false;
|
||||
};
|
||||
|
||||
void SetStickAxis(Controller::Axis axis, bool negative, bool positive) {
|
||||
const int value = negative == positive ? 128 : negative ? 0 : 255;
|
||||
Controller::ControllerAxis(Controller::HOST_INPUT_CONTROLLER_ID, axis, value);
|
||||
}
|
||||
|
||||
void DefaultKeyboardInput(int key_code, bool down) {
|
||||
static StickKeys left;
|
||||
static StickKeys right;
|
||||
|
||||
switch (NormalizeKey(static_cast<SDL_Keycode>(key_code))) {
|
||||
case SDLK_a:
|
||||
left.left = down;
|
||||
SetStickAxis(Controller::Axis::LeftX, left.left, left.right);
|
||||
return;
|
||||
case SDLK_d:
|
||||
left.right = down;
|
||||
SetStickAxis(Controller::Axis::LeftX, left.left, left.right);
|
||||
return;
|
||||
case SDLK_w:
|
||||
left.up = down;
|
||||
SetStickAxis(Controller::Axis::LeftY, left.up, left.down);
|
||||
return;
|
||||
case SDLK_s:
|
||||
left.down = down;
|
||||
SetStickAxis(Controller::Axis::LeftY, left.up, left.down);
|
||||
return;
|
||||
case SDLK_f:
|
||||
right.left = down;
|
||||
SetStickAxis(Controller::Axis::RightX, right.left, right.right);
|
||||
return;
|
||||
case SDLK_h:
|
||||
right.right = down;
|
||||
SetStickAxis(Controller::Axis::RightX, right.left, right.right);
|
||||
return;
|
||||
case SDLK_t:
|
||||
right.up = down;
|
||||
SetStickAxis(Controller::Axis::RightY, right.up, right.down);
|
||||
return;
|
||||
case SDLK_g:
|
||||
right.down = down;
|
||||
SetStickAxis(Controller::Axis::RightY, right.up, right.down);
|
||||
return;
|
||||
default: SetButton(DefaultKeyboardButton(key_code), down); return;
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void HostInputInit() {
|
||||
GetInputMap();
|
||||
}
|
||||
|
||||
void HostInputKey(int key_code, bool down) {
|
||||
const auto& map = GetInputMap();
|
||||
if (map.Custom()) {
|
||||
SetButton(map.FindKey(key_code), down);
|
||||
} else {
|
||||
DefaultKeyboardInput(key_code, down);
|
||||
}
|
||||
}
|
||||
|
||||
void HostInputMouseButton(uint8_t mouse_button, bool down) {
|
||||
const auto& map = GetInputMap();
|
||||
if (map.Custom() && mouse_button != 0) {
|
||||
SetButton(map.FindMouseButton(mouse_button), down);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Libs::Graphics
|
||||
@@ -0,0 +1,14 @@
|
||||
#ifndef KYTY_GRAPHICS_PRESENTATION_WINDOW_HOST_INPUT_H_
|
||||
#define KYTY_GRAPHICS_PRESENTATION_WINDOW_HOST_INPUT_H_
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace Libs::Graphics {
|
||||
|
||||
void HostInputInit();
|
||||
void HostInputKey(int key_code, bool down);
|
||||
void HostInputMouseButton(uint8_t mouse_button, bool down);
|
||||
|
||||
} // namespace Libs::Graphics
|
||||
|
||||
#endif /* KYTY_GRAPHICS_PRESENTATION_WINDOW_HOST_INPUT_H_ */
|
||||
@@ -31,11 +31,13 @@
|
||||
#include "graphics/host_gpu/renderer/renderContext.h"
|
||||
#include "graphics/host_gpu/vma.h"
|
||||
#include "graphics/host_gpu/vulkanCommon.h"
|
||||
#include "graphics/presentation/imeDialogOverlay.h"
|
||||
#include "graphics/presentation/presenter.h"
|
||||
#include "graphics/presentation/renderDoc.h"
|
||||
#include "graphics/presentation/videoOut.h"
|
||||
#include "graphics/presentation/window/windowInternal.h"
|
||||
#include "libs/controller.h"
|
||||
#include "libs/imeDialog.h"
|
||||
#include "loader/systemContent.h"
|
||||
|
||||
#include <algorithm>
|
||||
@@ -329,8 +331,9 @@ public:
|
||||
void Create();
|
||||
void Recreate(bool surface_lost = false);
|
||||
[[nodiscard]] Status AcquireNextImage();
|
||||
void RecordPresentCommands(CommandBuffer& command, VulkanImage& source);
|
||||
void Submit(CommandBuffer& command);
|
||||
[[nodiscard]] bool PrepareImeOverlay();
|
||||
void RecordPresentCommands(CommandBuffer& command, VulkanImage& source, bool draw_ime_overlay);
|
||||
void Submit(CommandBuffer& command);
|
||||
[[nodiscard]] Status Present();
|
||||
|
||||
[[nodiscard]] uint32_t ImageCount() const noexcept {
|
||||
@@ -342,16 +345,17 @@ private:
|
||||
void Destroy();
|
||||
void RefreshSurfaceSize();
|
||||
|
||||
WindowContext& m_window;
|
||||
vk::SwapchainKHR m_handle = nullptr;
|
||||
vk::Format m_format = vk::Format::eUndefined;
|
||||
vk::Extent2D m_extent {};
|
||||
std::vector<vk::Image> m_images;
|
||||
std::vector<vk::ImageView> m_image_views;
|
||||
std::vector<vk::Semaphore> m_image_acquired;
|
||||
std::vector<vk::Semaphore> m_render_complete;
|
||||
uint32_t m_image_index = static_cast<uint32_t>(-1);
|
||||
uint32_t m_frame_index = 0;
|
||||
WindowContext& m_window;
|
||||
vk::SwapchainKHR m_handle = nullptr;
|
||||
vk::Format m_format = vk::Format::eUndefined;
|
||||
vk::Extent2D m_extent {};
|
||||
std::vector<vk::Image> m_images;
|
||||
std::vector<vk::ImageView> m_image_views;
|
||||
std::vector<vk::Semaphore> m_image_acquired;
|
||||
std::vector<vk::Semaphore> m_render_complete;
|
||||
std::unique_ptr<ImeDialogOverlay> m_ime_overlay;
|
||||
uint32_t m_image_index = static_cast<uint32_t>(-1);
|
||||
uint32_t m_frame_index = 0;
|
||||
};
|
||||
|
||||
struct Presenter::Impl {
|
||||
@@ -383,17 +387,20 @@ struct Presenter::Impl {
|
||||
desc.view_info.usage = vk::ImageUsageFlagBits::eTransferSrc;
|
||||
desc.type = TextureCache::BindingType::VideoOut;
|
||||
|
||||
auto& cache = renderer.GetTextureCache();
|
||||
auto& image = cache.GetImage(cache.FindImage(desc));
|
||||
auto& cache = renderer.GetTextureCache();
|
||||
const auto image_id = cache.FindImage(desc);
|
||||
auto& image = cache.GetImage(image_id);
|
||||
image.usage.video_out = true;
|
||||
cache.UpdateImage(image_id);
|
||||
return image;
|
||||
}
|
||||
|
||||
RenderContext& renderer;
|
||||
WindowContext& window;
|
||||
Swapchain swapchain;
|
||||
CommandScheduler present_scheduler;
|
||||
FramePool frames;
|
||||
RenderContext& renderer;
|
||||
WindowContext& window;
|
||||
Swapchain swapchain;
|
||||
CommandScheduler present_scheduler;
|
||||
FramePool frames;
|
||||
std::atomic<uint64_t> presented_ime_revision {0};
|
||||
};
|
||||
|
||||
void Swapchain::Create() {
|
||||
@@ -522,6 +529,9 @@ void Swapchain::Destroy() {
|
||||
Common::LockGuard queue_lock(graphics.queue_mutex);
|
||||
RequireVulkanSuccess(graphics.queue.waitIdle(), "wait for swapchain queue");
|
||||
}
|
||||
if (m_ime_overlay != nullptr) {
|
||||
m_ime_overlay->ReleaseVulkan();
|
||||
}
|
||||
|
||||
for (const auto semaphore: m_image_acquired) {
|
||||
if (semaphore != nullptr) {
|
||||
@@ -606,7 +616,15 @@ Swapchain::Status Swapchain::AcquireNextImage() {
|
||||
return Status::Success;
|
||||
}
|
||||
|
||||
void Swapchain::RecordPresentCommands(CommandBuffer& command, VulkanImage& source) {
|
||||
bool Swapchain::PrepareImeOverlay() {
|
||||
if (m_ime_overlay == nullptr) {
|
||||
m_ime_overlay = std::make_unique<ImeDialogOverlay>(m_window.graphic_ctx);
|
||||
}
|
||||
return m_ime_overlay->PrepareFrame(m_extent, m_format, ImageCount());
|
||||
}
|
||||
|
||||
void Swapchain::RecordPresentCommands(CommandBuffer& command, VulkanImage& source,
|
||||
bool draw_ime_overlay) {
|
||||
if (source.state.layout != vk::ImageLayout::eTransferSrcOptimal) {
|
||||
EXIT("invalid prepared presentation image, vk_image=%p layout=%d\n",
|
||||
static_cast<void*>(source.image), static_cast<int>(source.state.layout));
|
||||
@@ -652,11 +670,14 @@ void Swapchain::RecordPresentCommands(CommandBuffer& command, VulkanImage& sourc
|
||||
vk::Filter::eLinear);
|
||||
|
||||
vk::ImageMemoryBarrier to_present {};
|
||||
to_present.sType = vk::StructureType::eImageMemoryBarrier;
|
||||
to_present.srcAccessMask = vk::AccessFlagBits::eTransferWrite;
|
||||
to_present.dstAccessMask = vk::AccessFlagBits::eMemoryRead;
|
||||
to_present.oldLayout = vk::ImageLayout::eTransferDstOptimal;
|
||||
to_present.newLayout = vk::ImageLayout::ePresentSrcKHR;
|
||||
to_present.sType = vk::StructureType::eImageMemoryBarrier;
|
||||
to_present.srcAccessMask = vk::AccessFlagBits::eTransferWrite;
|
||||
to_present.dstAccessMask = draw_ime_overlay ? vk::AccessFlagBits::eColorAttachmentRead |
|
||||
vk::AccessFlagBits::eColorAttachmentWrite
|
||||
: vk::AccessFlagBits::eMemoryRead;
|
||||
to_present.oldLayout = vk::ImageLayout::eTransferDstOptimal;
|
||||
to_present.newLayout = draw_ime_overlay ? vk::ImageLayout::eColorAttachmentOptimal
|
||||
: vk::ImageLayout::ePresentSrcKHR;
|
||||
to_present.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||
to_present.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||
to_present.image = m_images[m_image_index];
|
||||
@@ -665,9 +686,22 @@ void Swapchain::RecordPresentCommands(CommandBuffer& command, VulkanImage& sourc
|
||||
to_present.subresourceRange.levelCount = 1;
|
||||
to_present.subresourceRange.baseArrayLayer = 0;
|
||||
to_present.subresourceRange.layerCount = 1;
|
||||
vk_command.pipelineBarrier(
|
||||
vk::PipelineStageFlagBits::eAllCommands, vk::PipelineStageFlagBits::eAllCommands,
|
||||
vk::DependencyFlagBits::eByRegion, 0, nullptr, 0, nullptr, 1, &to_present);
|
||||
vk_command.pipelineBarrier(vk::PipelineStageFlagBits::eTransfer,
|
||||
draw_ime_overlay ? vk::PipelineStageFlagBits::eColorAttachmentOutput
|
||||
: vk::PipelineStageFlagBits::eAllCommands,
|
||||
vk::DependencyFlagBits::eByRegion, 0, nullptr, 0, nullptr, 1,
|
||||
&to_present);
|
||||
if (draw_ime_overlay) {
|
||||
m_ime_overlay->Record(vk_command, m_image_views[m_image_index]);
|
||||
to_present.srcAccessMask = vk::AccessFlagBits::eColorAttachmentWrite;
|
||||
to_present.dstAccessMask = vk::AccessFlagBits::eMemoryRead;
|
||||
to_present.oldLayout = vk::ImageLayout::eColorAttachmentOptimal;
|
||||
to_present.newLayout = vk::ImageLayout::ePresentSrcKHR;
|
||||
vk_command.pipelineBarrier(vk::PipelineStageFlagBits::eColorAttachmentOutput,
|
||||
vk::PipelineStageFlagBits::eAllCommands,
|
||||
vk::DependencyFlagBits::eByRegion, 0, nullptr, 0, nullptr, 1,
|
||||
&to_present);
|
||||
}
|
||||
command.End();
|
||||
}
|
||||
|
||||
@@ -772,6 +806,12 @@ bool Presenter::IsGuestPaused() const noexcept {
|
||||
return m_impl->window.loop.paused.load(std::memory_order_acquire);
|
||||
}
|
||||
|
||||
bool Presenter::NeedsImeRefresh() const noexcept {
|
||||
const auto visual = Dialog::ImeDialog::GetVisualState();
|
||||
return visual.active ||
|
||||
visual.revision != m_impl->presented_ime_revision.load(std::memory_order_acquire);
|
||||
}
|
||||
|
||||
RenderContext& Presenter::Renderer() const noexcept {
|
||||
return m_impl->renderer;
|
||||
}
|
||||
@@ -789,19 +829,22 @@ void Presenter::Present(Frame& frame, bool reuse) {
|
||||
[&window] {
|
||||
window.UpdateIcon();
|
||||
SDL_ShowWindow(window.window);
|
||||
SDL_RaiseWindow(window.window);
|
||||
},
|
||||
true);
|
||||
#else
|
||||
window.UpdateIcon();
|
||||
|
||||
SDL_ShowWindow(window.window);
|
||||
SDL_RaiseWindow(window.window);
|
||||
#endif
|
||||
|
||||
window.window_hidden = false;
|
||||
m_impl->RecoverSwapchain(Swapchain::Status::Recreate);
|
||||
}
|
||||
|
||||
auto& swapchain = m_impl->swapchain;
|
||||
const auto ime_visual = Dialog::ImeDialog::GetVisualState();
|
||||
auto& swapchain = m_impl->swapchain;
|
||||
for (uint32_t attempt = 0; attempt < 2; attempt++) {
|
||||
auto status = swapchain.AcquireNextImage();
|
||||
if (status != Swapchain::Status::Success) {
|
||||
@@ -814,8 +857,9 @@ void Presenter::Present(Frame& frame, bool reuse) {
|
||||
{
|
||||
Common::LockGuard render_lock(m_impl->renderer.GetMutex());
|
||||
frame.present_commands->WaitForFenceAndReset();
|
||||
auto& command = *frame.present_commands;
|
||||
swapchain.RecordPresentCommands(command, frame.image);
|
||||
auto& command = *frame.present_commands;
|
||||
const bool draw_ime_overlay = ime_visual.active && swapchain.PrepareImeOverlay();
|
||||
swapchain.RecordPresentCommands(command, frame.image, draw_ime_overlay);
|
||||
swapchain.Submit(command);
|
||||
}
|
||||
status = swapchain.Present();
|
||||
@@ -825,6 +869,7 @@ void Presenter::Present(Frame& frame, bool reuse) {
|
||||
}
|
||||
|
||||
RenderDocOnPresent();
|
||||
m_impl->presented_ime_revision.store(ime_visual.revision, std::memory_order_release);
|
||||
window.UpdateTitle();
|
||||
m_impl->frames.Release(&frame, true);
|
||||
return;
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include "graphics/host_gpu/renderer/renderContext.h"
|
||||
#include "graphics/host_gpu/vma.h"
|
||||
#include "graphics/host_gpu/vulkanCommon.h"
|
||||
#include "graphics/presentation/imeDialogOverlay.h"
|
||||
#include "graphics/presentation/presenter.h"
|
||||
#include "graphics/presentation/renderDoc.h"
|
||||
#include "graphics/presentation/videoOut.h"
|
||||
@@ -259,6 +260,10 @@ static void VulkanFindPhysicalDevice(vk::Instance instance, vk::SurfaceKHR surfa
|
||||
LOGF("sampleRateShading is not supported\n");
|
||||
skip_device = true;
|
||||
}
|
||||
if (device_features2.features.depthBiasClamp != VK_TRUE) {
|
||||
LOGF("depthBiasClamp is not supported\n");
|
||||
skip_device = true;
|
||||
}
|
||||
|
||||
if (device_features2.features.fragmentStoresAndAtomics != VK_TRUE) {
|
||||
LOGF("fragmentStoresAndAtomics is not supported\n");
|
||||
@@ -548,6 +553,7 @@ static vk::Device VulkanCreateDevice(vk::PhysicalDevice physical_device, const V
|
||||
EXIT_NOT_IMPLEMENTED(required_features13.synchronization2 == VK_TRUE &&
|
||||
supported_features13.synchronization2 != VK_TRUE);
|
||||
EXIT_NOT_IMPLEMENTED(supported_features2.features.sampleRateShading != VK_TRUE);
|
||||
EXIT_NOT_IMPLEMENTED(supported_features2.features.depthBiasClamp != VK_TRUE);
|
||||
features12.timelineSemaphore = VK_TRUE;
|
||||
|
||||
vk::PhysicalDeviceFeatures device_features {};
|
||||
@@ -563,6 +569,7 @@ static vk::Device VulkanCreateDevice(vk::PhysicalDevice physical_device, const V
|
||||
device_features.independentBlend = VK_TRUE;
|
||||
device_features.tessellationShader = VK_TRUE;
|
||||
device_features.sampleRateShading = VK_TRUE;
|
||||
device_features.depthBiasClamp = VK_TRUE;
|
||||
graphics.sample_rate_shading_enabled = true;
|
||||
device_features.vertexPipelineStoresAndAtomics =
|
||||
supported_features2.features.vertexPipelineStoresAndAtomics;
|
||||
@@ -1008,6 +1015,7 @@ void WindowContext::RecreateSurface() {
|
||||
}
|
||||
|
||||
WindowContext::~WindowContext() {
|
||||
ShutdownImeDialogInput();
|
||||
presenter.reset();
|
||||
LibKernel::Memory::InstallGpuResources(nullptr);
|
||||
render_context.reset();
|
||||
|
||||
@@ -31,8 +31,11 @@
|
||||
#include "graphics/host_gpu/renderer/render.h"
|
||||
#include "graphics/host_gpu/vma.h"
|
||||
#include "graphics/host_gpu/vulkanCommon.h"
|
||||
#include "graphics/presentation/imeDialogOverlay.h"
|
||||
#include "graphics/presentation/renderDoc.h"
|
||||
#include "graphics/presentation/window/hostInput.h"
|
||||
#include "graphics/presentation/window/windowInternal.h"
|
||||
#include "kytyGitVersion.h"
|
||||
#include "libs/controller.h"
|
||||
#include "loader/systemContent.h"
|
||||
|
||||
@@ -58,8 +61,6 @@
|
||||
|
||||
namespace Libs::Graphics {
|
||||
|
||||
constexpr int KEYBOARD_CONTROLLER_ID = -1000;
|
||||
|
||||
struct EventKeyboard {
|
||||
bool down;
|
||||
bool up;
|
||||
@@ -72,26 +73,6 @@ struct EventKeyboard {
|
||||
double timestamp_seconds;
|
||||
};
|
||||
|
||||
static uint32_t KeyboardKeyToPadButton(int key_code) {
|
||||
switch (key_code) {
|
||||
case SDLK_w: return Controller::PAD_BUTTON_UP;
|
||||
case SDLK_a: return Controller::PAD_BUTTON_LEFT;
|
||||
case SDLK_s: return Controller::PAD_BUTTON_DOWN;
|
||||
case SDLK_d: return Controller::PAD_BUTTON_RIGHT;
|
||||
case SDLK_j: return Controller::PAD_BUTTON_CROSS;
|
||||
case SDLK_i: return Controller::PAD_BUTTON_TRIANGLE;
|
||||
case SDLK_k: return Controller::PAD_BUTTON_SQUARE;
|
||||
case SDLK_l: return Controller::PAD_BUTTON_CIRCLE;
|
||||
case SDLK_q: return Controller::PAD_BUTTON_L1;
|
||||
case SDLK_e: return Controller::PAD_BUTTON_R1;
|
||||
case SDLK_RETURN:
|
||||
case SDLK_RETURN2: return Controller::PAD_BUTTON_OPTIONS;
|
||||
case SDLK_BACKSPACE:
|
||||
case SDLK_TAB: return Controller::PAD_BUTTON_TOUCH_PAD;
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static uint32_t ControllerButtonToPadButton(int button) {
|
||||
switch (button) {
|
||||
case SDL_CONTROLLER_BUTTON_A: return Controller::PAD_BUTTON_CROSS;
|
||||
@@ -260,16 +241,11 @@ static void GameEventKeyboard(WindowLoopState& game, const EventKeyboard& key) {
|
||||
}
|
||||
}
|
||||
|
||||
const auto button = KeyboardKeyToPadButton(key.key_code);
|
||||
if (button != 0 && (key.down || key.up) && !key.repeat) {
|
||||
static bool keyboard_connected = false;
|
||||
if (!keyboard_connected) {
|
||||
Controller::ControllerConnect(KEYBOARD_CONTROLLER_ID);
|
||||
keyboard_connected = true;
|
||||
}
|
||||
Controller::ControllerButton(KEYBOARD_CONTROLLER_ID, button, key.down);
|
||||
}
|
||||
#endif
|
||||
|
||||
if ((key.down || key.up) && !key.repeat) {
|
||||
HostInputKey(key.key_code, key.down);
|
||||
}
|
||||
}
|
||||
|
||||
static void GameEventMouse([[maybe_unused]] const EventMouse& mb) {
|
||||
@@ -291,6 +267,23 @@ static void GameEventMouse([[maybe_unused]] const EventMouse& mb) {
|
||||
mb.x, mb.y);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (mb.down || mb.up) {
|
||||
uint8_t mouse_button = 0;
|
||||
if (mb.left) {
|
||||
mouse_button = SDL_BUTTON_LEFT;
|
||||
} else if (mb.middle) {
|
||||
mouse_button = SDL_BUTTON_MIDDLE;
|
||||
} else if (mb.right) {
|
||||
mouse_button = SDL_BUTTON_RIGHT;
|
||||
} else if (mb.x1) {
|
||||
mouse_button = SDL_BUTTON_X1;
|
||||
} else if (mb.x2) {
|
||||
mouse_button = SDL_BUTTON_X2;
|
||||
}
|
||||
|
||||
HostInputMouseButton(mouse_button, mb.down);
|
||||
}
|
||||
}
|
||||
|
||||
static void GameEventFinger([[maybe_unused]] const EventFinger& f) {
|
||||
@@ -484,6 +477,9 @@ void WindowContext::ProcessEvent(double time_s) {
|
||||
auto& game = loop;
|
||||
auto* event = &game.event;
|
||||
EXIT_IF(SDL_GetEventState(SDL_DISPLAYEVENT) != SDL_ENABLE);
|
||||
if (ProcessImeDialogInput(*event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (event->type) {
|
||||
case SDL_QUIT: GameEventQuit(game); break;
|
||||
@@ -794,10 +790,15 @@ static void WindowCreate(WindowContext& context) {
|
||||
if (SDL_InitSubSystem(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER) < 0) {
|
||||
EXIT("%s\n", SDL_GetError());
|
||||
}
|
||||
HostInputInit();
|
||||
InitializeImeDialogInput();
|
||||
|
||||
LOGF("WindowCreate(): width = %d, height = %d\n", width, height);
|
||||
|
||||
uint32_t window_flags = KYTY_SDL_WINDOW_FLAGS;
|
||||
if (Config::FullscreenEnabled()) {
|
||||
window_flags |= static_cast<uint32_t>(SDL_WINDOW_FULLSCREEN_DESKTOP);
|
||||
}
|
||||
#if defined(__APPLE__)
|
||||
// macOS 26 window chrome (CoreUI asset decode, SwiftUI titlebar) has been observed
|
||||
// throwing NSExceptions under Rosetta during the first CATransaction commit. A
|
||||
@@ -937,6 +938,22 @@ void WindowContext::UpdateTitle() {
|
||||
static uint64_t fps_frames = 0;
|
||||
static double current_fps = 0.0;
|
||||
|
||||
#if KYTY_BUILD == KYTY_BUILD_DEBUG
|
||||
static constexpr auto build_type = "Debug";
|
||||
#elif KYTY_BUILD == KYTY_BUILD_RELEASE
|
||||
static constexpr auto build_type = "Release";
|
||||
#else
|
||||
static constexpr auto build_type = "Unknown";
|
||||
#endif
|
||||
|
||||
#if defined(KYTY_OFFICIAL_BUILD)
|
||||
static constexpr auto build_label = "Official build " KYTY_RELEASE_TAG;
|
||||
#elif defined(KYTY_FORK_BUILD)
|
||||
static constexpr auto build_label = "Fork build " KYTY_BUILD_REPOSITORY " " KYTY_GIT_HASH;
|
||||
#else
|
||||
static constexpr auto build_label = "Source build " KYTY_GIT_HASH;
|
||||
#endif
|
||||
|
||||
const auto now = Common::Timer::QueryPerformanceCounter();
|
||||
const auto frequency = Common::Timer::QueryPerformanceFrequency();
|
||||
frame_num++;
|
||||
@@ -948,11 +965,11 @@ void WindowContext::UpdateTitle() {
|
||||
fps_frames = 0;
|
||||
}
|
||||
|
||||
auto fps =
|
||||
fmt::format("{}{}{}{}{}{}[{}] [{}], frame: {}, fps: {:f}", (has_title ? title : ""),
|
||||
(has_title ? ", " : ""), (has_title_id ? title_id : ""),
|
||||
(has_title_id ? ", " : ""), (has_app_ver ? app_ver : ""),
|
||||
(has_app_ver ? " " : ""), device_name, processor_name, frame_num, current_fps);
|
||||
auto fps = fmt::format("[{} | {}] {}{}{}{}{}{}[{}] [{}], frame: {}, fps: {:f}", build_label,
|
||||
build_type, (has_title ? title : ""), (has_title ? ", " : ""),
|
||||
(has_title_id ? title_id : ""), (has_title_id ? ", " : ""),
|
||||
(has_app_ver ? app_ver : ""), (has_app_ver ? " " : ""), device_name,
|
||||
processor_name, frame_num, current_fps);
|
||||
|
||||
#if defined(__APPLE__)
|
||||
// AppKit traps on title changes off the main thread; fire-and-forget keeps present pacing.
|
||||
|
||||
@@ -84,6 +84,8 @@ bool InstructionMaySplitSpirvBlock(const IR::Instruction& inst) {
|
||||
case IR::Opcode::AtomicAndU32:
|
||||
case IR::Opcode::AtomicOrU32:
|
||||
case IR::Opcode::AtomicXorU32:
|
||||
case IR::Opcode::AtomicFMinF32:
|
||||
case IR::Opcode::AtomicFMaxF32:
|
||||
case IR::Opcode::FlatLoadUbyte:
|
||||
case IR::Opcode::FlatLoadSbyte:
|
||||
case IR::Opcode::FlatLoadUshort:
|
||||
|
||||
@@ -57,6 +57,8 @@ constexpr MemoryOpcodeInfo MUBUF_OPS[] = {
|
||||
{0x39u, Opcode::BufferAtomicAnd, 1, 32},
|
||||
{0x3au, Opcode::BufferAtomicOr, 1, 32},
|
||||
{0x3bu, Opcode::BufferAtomicXor, 1, 32},
|
||||
{0x3fu, Opcode::BufferAtomicFMin, 1, 32},
|
||||
{0x40u, Opcode::BufferAtomicFMax, 1, 32},
|
||||
};
|
||||
|
||||
constexpr MemoryOpcodeInfo MTBUF_OPS[] = {
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
#ifndef EMULATOR_INCLUDE_EMULATOR_GRAPHICS_SHADER_RECOMPILER_DECOMPILER_OPCODETABLE_H_
|
||||
#define EMULATOR_INCLUDE_EMULATOR_GRAPHICS_SHADER_RECOMPILER_DECOMPILER_OPCODETABLE_H_
|
||||
|
||||
#include "graphics/shader/recompiler/decompiler/ShaderDecoder.h"
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
namespace Libs::Graphics::ShaderRecompiler::Decoder::Detail {
|
||||
|
||||
struct OpcodeMap {
|
||||
uint32_t encoding = 0;
|
||||
Opcode decoded = Opcode::Unknown;
|
||||
};
|
||||
|
||||
template <typename Entry, size_t N>
|
||||
constexpr const Entry* FindOpcode(const Entry (&table)[N], uint32_t encoding) {
|
||||
for (const auto& entry: table) {
|
||||
if (entry.encoding == encoding) {
|
||||
return &entry;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
template <typename Entry, size_t N>
|
||||
constexpr Opcode LookupOpcode(const Entry (&table)[N], uint32_t encoding) {
|
||||
const auto* entry = FindOpcode(table, encoding);
|
||||
return entry != nullptr ? entry->decoded : Opcode::Unsupported;
|
||||
}
|
||||
|
||||
template <typename Entry, size_t N>
|
||||
constexpr bool HasUniqueEncodings(const Entry (&table)[N]) {
|
||||
for (size_t i = 0; i < N; i++) {
|
||||
for (size_t j = i + 1; j < N; j++) {
|
||||
if (table[i].encoding == table[j].encoding) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace Libs::Graphics::ShaderRecompiler::Decoder::Detail
|
||||
|
||||
#endif // EMULATOR_INCLUDE_EMULATOR_GRAPHICS_SHADER_RECOMPILER_DECOMPILER_OPCODETABLE_H_
|
||||
@@ -1,14 +1,11 @@
|
||||
#include "graphics/shader/recompiler/decompiler/ScalarAluOps.h"
|
||||
|
||||
#include <iterator>
|
||||
#include "graphics/shader/recompiler/decompiler/OpcodeTable.h"
|
||||
|
||||
namespace Libs::Graphics::ShaderRecompiler::Decoder {
|
||||
namespace {
|
||||
|
||||
struct OpcodeMap {
|
||||
uint32_t opcode = 0;
|
||||
Opcode ir = Opcode::Unknown;
|
||||
};
|
||||
using Detail::OpcodeMap;
|
||||
|
||||
constexpr OpcodeMap SOP2_OPS[] = {
|
||||
{0x00u, Opcode::SAddU32}, {0x01u, Opcode::SSubU32}, {0x02u, Opcode::SAddI32},
|
||||
@@ -58,7 +55,8 @@ constexpr OpcodeMap SOPC_OPS[] = {
|
||||
{0x03u, Opcode::SCmpGeI32}, {0x04u, Opcode::SCmpLtI32}, {0x05u, Opcode::SCmpLeI32},
|
||||
{0x06u, Opcode::SCmpEqU32}, {0x07u, Opcode::SCmpLgU32}, {0x08u, Opcode::SCmpGtU32},
|
||||
{0x09u, Opcode::SCmpGeU32}, {0x0au, Opcode::SCmpLtU32}, {0x0bu, Opcode::SCmpLeU32},
|
||||
{0x0cu, Opcode::SBitcmp0B32}, {0x0du, Opcode::SBitcmp1B32}, {0x13u, Opcode::SCmpLgU64},
|
||||
{0x0cu, Opcode::SBitcmp0B32}, {0x0du, Opcode::SBitcmp1B32}, {0x12u, Opcode::SCmpEqU64},
|
||||
{0x13u, Opcode::SCmpLgU64},
|
||||
};
|
||||
|
||||
constexpr OpcodeMap SOPK_OPS[] = {
|
||||
@@ -78,15 +76,11 @@ constexpr OpcodeMap SOPP_OPS[] = {
|
||||
{0x0au, Opcode::SBarrier}, {0x0cu, Opcode::SWaitcnt}, {0x0eu, Opcode::SSleep},
|
||||
{0x10u, Opcode::SSendmsg}, {0x16u, Opcode::STtraceData}, {0x20u, Opcode::SInstPrefetch},
|
||||
};
|
||||
|
||||
Opcode Lookup(const OpcodeMap* ops, uint32_t count, uint32_t opcode) {
|
||||
for (uint32_t i = 0; i < count; i++) {
|
||||
if (ops[i].opcode == opcode) {
|
||||
return ops[i].ir;
|
||||
}
|
||||
}
|
||||
return Opcode::Unsupported;
|
||||
}
|
||||
static_assert(Detail::HasUniqueEncodings(SOP1_OPS));
|
||||
static_assert(Detail::HasUniqueEncodings(SOP2_OPS));
|
||||
static_assert(Detail::HasUniqueEncodings(SOPK_OPS));
|
||||
static_assert(Detail::HasUniqueEncodings(SOPC_OPS));
|
||||
static_assert(Detail::HasUniqueEncodings(SOPP_OPS));
|
||||
|
||||
bool DecodeBinarySources(uint32_t pc, std::span<const uint32_t> code, uint32_t word_index,
|
||||
Instruction& inst, uint32_t ssrc0, uint32_t ssrc1, std::string* error) {
|
||||
@@ -111,7 +105,7 @@ bool DecodeSop1(uint32_t pc, std::span<const uint32_t> code, uint32_t word_index
|
||||
inst.word = word;
|
||||
inst.family = Family::SOP1;
|
||||
inst.opcode_id = opcode;
|
||||
inst.opcode = Lookup(SOP1_OPS, static_cast<uint32_t>(std::size(SOP1_OPS)), opcode);
|
||||
inst.opcode = Detail::LookupOpcode(SOP1_OPS, opcode);
|
||||
SetRawWords(inst, code, word_index, 1);
|
||||
|
||||
if (inst.opcode == Opcode::Unsupported) {
|
||||
@@ -153,7 +147,7 @@ bool DecodeSop2(uint32_t pc, std::span<const uint32_t> code, uint32_t word_index
|
||||
inst.word = word;
|
||||
inst.family = Family::SOP2;
|
||||
inst.opcode_id = opcode;
|
||||
inst.opcode = Lookup(SOP2_OPS, static_cast<uint32_t>(std::size(SOP2_OPS)), opcode);
|
||||
inst.opcode = Detail::LookupOpcode(SOP2_OPS, opcode);
|
||||
SetRawWords(inst, code, word_index, 1);
|
||||
|
||||
if (inst.opcode == Opcode::Unsupported) {
|
||||
@@ -180,7 +174,7 @@ bool DecodeSopk(uint32_t pc, std::span<const uint32_t> code, uint32_t word_index
|
||||
inst.word = word;
|
||||
inst.family = Family::SOPK;
|
||||
inst.opcode_id = opcode;
|
||||
inst.opcode = Lookup(SOPK_OPS, static_cast<uint32_t>(std::size(SOPK_OPS)), opcode);
|
||||
inst.opcode = Detail::LookupOpcode(SOPK_OPS, opcode);
|
||||
inst.src0.kind = OperandKind::IntegerInlineConstant;
|
||||
inst.src0.signed_val = imm;
|
||||
inst.src0.value = static_cast<uint32_t>(imm);
|
||||
@@ -237,7 +231,7 @@ bool DecodeSopc(uint32_t pc, std::span<const uint32_t> code, uint32_t word_index
|
||||
inst.word = word;
|
||||
inst.family = Family::SOPC;
|
||||
inst.opcode_id = opcode;
|
||||
inst.opcode = Lookup(SOPC_OPS, static_cast<uint32_t>(std::size(SOPC_OPS)), opcode);
|
||||
inst.opcode = Detail::LookupOpcode(SOPC_OPS, opcode);
|
||||
inst.dst.kind = OperandKind::Scc;
|
||||
SetRawWords(inst, code, word_index, 1);
|
||||
|
||||
@@ -261,7 +255,7 @@ bool DecodeSopp(uint32_t pc, std::span<const uint32_t> code, uint32_t word_index
|
||||
inst.word = word;
|
||||
inst.family = Family::SOPP;
|
||||
inst.opcode_id = opcode;
|
||||
inst.opcode = Lookup(SOPP_OPS, static_cast<uint32_t>(std::size(SOPP_OPS)), opcode);
|
||||
inst.opcode = Detail::LookupOpcode(SOPP_OPS, opcode);
|
||||
inst.src0.kind = OperandKind::LiteralConstant;
|
||||
inst.src0.value = simm;
|
||||
inst.src0.signed_val = static_cast<int16_t>(simm);
|
||||
|
||||
@@ -77,6 +77,16 @@ std::string FormatBinary(const Instruction& inst) {
|
||||
return text;
|
||||
}
|
||||
|
||||
std::string FormatSources(const Instruction& inst) {
|
||||
std::string text = fmt::format("0x{:08x}: {}", inst.pc, OpcodeToString(inst.opcode));
|
||||
const Operand* sources[] = {&inst.src0, &inst.src1, &inst.src2, &inst.src3};
|
||||
for (uint32_t i = 0; i < inst.src_count && i < 4u; i++) {
|
||||
text += i == 0 ? " " : ", ";
|
||||
text += OperandToString(*sources[i]);
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
std::string FormatMemory(const Instruction& inst) {
|
||||
std::string text = fmt::format("0x{:08x}: {} {}", inst.pc, OpcodeToString(inst.opcode).c_str(),
|
||||
OperandToString(inst.dst).c_str());
|
||||
@@ -511,6 +521,7 @@ std::string OpcodeToString(Opcode opcode) {
|
||||
case Opcode::SCmpGeU32: return "s_cmp_ge_u32";
|
||||
case Opcode::SCmpLtU32: return "s_cmp_lt_u32";
|
||||
case Opcode::SCmpLeU32: return "s_cmp_le_u32";
|
||||
case Opcode::SCmpEqU64: return "s_cmp_eq_u64";
|
||||
case Opcode::SCmpLgU64: return "s_cmp_lg_u64";
|
||||
case Opcode::VNop: return "v_nop";
|
||||
case Opcode::VMovB32: return "v_mov_b32";
|
||||
@@ -766,6 +777,7 @@ std::string OpcodeToString(Opcode opcode) {
|
||||
case Opcode::VCmpNeU32: return "v_cmp_ne_u32";
|
||||
case Opcode::VCmpGeU32: return "v_cmp_ge_u32";
|
||||
case Opcode::VCmpTU32: return "v_cmp_t_u32";
|
||||
case Opcode::VCmpEqI64: return "v_cmp_eq_i64";
|
||||
case Opcode::VCmpNeU64: return "v_cmp_ne_u64";
|
||||
case Opcode::VCmpxLtU32: return "v_cmpx_lt_u32";
|
||||
case Opcode::VCmpxEqU32: return "v_cmpx_eq_u32";
|
||||
@@ -823,6 +835,8 @@ std::string OpcodeToString(Opcode opcode) {
|
||||
case Opcode::BufferAtomicAnd: return "buffer_atomic_and";
|
||||
case Opcode::BufferAtomicOr: return "buffer_atomic_or";
|
||||
case Opcode::BufferAtomicXor: return "buffer_atomic_xor";
|
||||
case Opcode::BufferAtomicFMin: return "buffer_atomic_fmin";
|
||||
case Opcode::BufferAtomicFMax: return "buffer_atomic_fmax";
|
||||
case Opcode::FlatLoadUbyte: return "flat_load_ubyte";
|
||||
case Opcode::FlatLoadSbyte: return "flat_load_sbyte";
|
||||
case Opcode::FlatLoadUshort: return "flat_load_ushort";
|
||||
@@ -983,6 +997,9 @@ std::string InstructionToString(const Instruction& inst) {
|
||||
inst.pc, FamilyToString(inst.family).c_str(), inst.opcode_id,
|
||||
RawWordsToString(inst).c_str(), inst.unsupported_reason.c_str());
|
||||
}
|
||||
if (inst.family == Family::SOPC) {
|
||||
return WithUnsupportedReason(inst, FormatSources(inst));
|
||||
}
|
||||
|
||||
switch (inst.opcode) {
|
||||
case Opcode::SMovB32:
|
||||
@@ -1110,6 +1127,8 @@ std::string InstructionToString(const Instruction& inst) {
|
||||
case Opcode::BufferAtomicAnd:
|
||||
case Opcode::BufferAtomicOr:
|
||||
case Opcode::BufferAtomicXor:
|
||||
case Opcode::BufferAtomicFMin:
|
||||
case Opcode::BufferAtomicFMax:
|
||||
case Opcode::BufferLoadSbyte:
|
||||
case Opcode::BufferLoadSshort:
|
||||
case Opcode::FlatLoadUbyte:
|
||||
@@ -1171,25 +1190,6 @@ std::string InstructionToString(const Instruction& inst) {
|
||||
case Opcode::DsWriteB128:
|
||||
case Opcode::DsWriteAddtidB32:
|
||||
case Opcode::DsReadAddtidB32: return WithUnsupportedReason(inst, FormatMemory(inst));
|
||||
case Opcode::SCmpEqU32:
|
||||
case Opcode::SCmpEqI32:
|
||||
case Opcode::SCmpLgU32:
|
||||
case Opcode::SCmpLgI32:
|
||||
case Opcode::SCmpGtU32:
|
||||
case Opcode::SCmpGtI32:
|
||||
case Opcode::SCmpGeU32:
|
||||
case Opcode::SCmpGeI32:
|
||||
case Opcode::SCmpLtU32:
|
||||
case Opcode::SCmpLtI32:
|
||||
case Opcode::SCmpLeU32:
|
||||
case Opcode::SCmpLeI32:
|
||||
case Opcode::SBitcmp0B32:
|
||||
case Opcode::SBitcmp1B32:
|
||||
case Opcode::SCmpLgU64:
|
||||
return WithUnsupportedReason(inst, fmt::format("0x{:08x}: {} {}, {}", inst.pc,
|
||||
OpcodeToString(inst.opcode).c_str(),
|
||||
OperandToString(inst.src0).c_str(),
|
||||
OperandToString(inst.src1).c_str()));
|
||||
default: return WithUnsupportedReason(inst, FormatBinary(inst));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,6 +118,7 @@ enum class Opcode {
|
||||
SCmpGeU32,
|
||||
SCmpLtU32,
|
||||
SCmpLeU32,
|
||||
SCmpEqU64,
|
||||
SCmpLgU64,
|
||||
|
||||
VNop,
|
||||
@@ -374,6 +375,7 @@ enum class Opcode {
|
||||
VCmpNeU32,
|
||||
VCmpGeU32,
|
||||
VCmpTU32,
|
||||
VCmpEqI64,
|
||||
VCmpNeU64,
|
||||
VCmpxLtU32,
|
||||
VCmpxEqU32,
|
||||
@@ -432,6 +434,8 @@ enum class Opcode {
|
||||
BufferAtomicAnd,
|
||||
BufferAtomicOr,
|
||||
BufferAtomicXor,
|
||||
BufferAtomicFMin,
|
||||
BufferAtomicFMax,
|
||||
FlatLoadUbyte,
|
||||
FlatLoadSbyte,
|
||||
FlatLoadUshort,
|
||||
|
||||
@@ -1,43 +1,91 @@
|
||||
#include "graphics/shader/recompiler/decompiler/VectorAluOps.h"
|
||||
|
||||
#include "graphics/shader/recompiler/decompiler/OpcodeTable.h"
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include <iterator>
|
||||
|
||||
namespace Libs::Graphics::ShaderRecompiler::Decoder {
|
||||
namespace {
|
||||
|
||||
struct OpcodeMap {
|
||||
uint32_t opcode = 0;
|
||||
Opcode ir = Opcode::Unknown;
|
||||
using Detail::OpcodeMap;
|
||||
|
||||
// These profiles describe the selectors that the current lowering implements. They are not
|
||||
// architectural SDWA legality classes.
|
||||
enum class Vop2SdwaProfile {
|
||||
None,
|
||||
Cndmask,
|
||||
Float32,
|
||||
Float16,
|
||||
IntegerFullDestination,
|
||||
IntegerPartialDestination,
|
||||
ReverseLogicalRight,
|
||||
ReverseLogicalLeft,
|
||||
Bitwise,
|
||||
Count,
|
||||
};
|
||||
|
||||
constexpr OpcodeMap VOP2_OPS[] = {
|
||||
{0x01u, Opcode::VCndmaskB32}, {0x02u, Opcode::VDot2cF32F16},
|
||||
{0x03u, Opcode::VAddF32}, {0x04u, Opcode::VSubF32},
|
||||
{0x05u, Opcode::VSubrevF32}, {0x08u, Opcode::VMulF32},
|
||||
{0x09u, Opcode::VMulI32I24}, {0x0bu, Opcode::VMulU32U24},
|
||||
{0x0fu, Opcode::VMinF32}, {0x10u, Opcode::VMaxF32},
|
||||
{0x11u, Opcode::VMinI32}, {0x12u, Opcode::VMaxI32},
|
||||
{0x13u, Opcode::VMinU32}, {0x14u, Opcode::VMaxU32},
|
||||
{0x15u, Opcode::VLshrB32}, {0x16u, Opcode::VLshrrevB32},
|
||||
{0x17u, Opcode::VAshrI32}, {0x18u, Opcode::VAshrrevI32},
|
||||
{0x19u, Opcode::VLshlB32}, {0x1au, Opcode::VLshlrevB32},
|
||||
{0x1bu, Opcode::VAndB32}, {0x1cu, Opcode::VOrB32},
|
||||
{0x1du, Opcode::VXorB32}, {0x1eu, Opcode::VXnorB32},
|
||||
{0x1fu, Opcode::VMacF32}, {0x20u, Opcode::VMadmkF32},
|
||||
{0x21u, Opcode::VMadakF32}, {0x22u, Opcode::VBcntU32B32},
|
||||
{0x23u, Opcode::VMbcntLoU32B32}, {0x24u, Opcode::VMbcntHiU32B32},
|
||||
{0x25u, Opcode::VAddNcU32}, {0x28u, Opcode::VAddcU32},
|
||||
{0x26u, Opcode::VSubNcU32}, {0x27u, Opcode::VSubrevNcU32},
|
||||
{0x2bu, Opcode::VMacF32}, {0x2cu, Opcode::VMadmkF32},
|
||||
{0x2du, Opcode::VMadakF32}, {0x2fu, Opcode::VCvtPkrtzF16F32},
|
||||
{0x32u, Opcode::VAddF16}, {0x33u, Opcode::VSubF16},
|
||||
{0x34u, Opcode::VSubrevF16}, {0x35u, Opcode::VMulF16},
|
||||
{0x36u, Opcode::VFmacF16}, {0x37u, Opcode::VFmamkF16},
|
||||
{0x38u, Opcode::VFmaakF16}, {0x39u, Opcode::VMaxF16},
|
||||
{0x3au, Opcode::VMinF16}, {0x3cu, Opcode::VPkFmacF16},
|
||||
struct Vop2OpcodeInfo {
|
||||
uint32_t encoding = 0;
|
||||
Opcode decoded = Opcode::Unknown;
|
||||
Vop2SdwaProfile sdwa_profile = Vop2SdwaProfile::None;
|
||||
};
|
||||
|
||||
constexpr Vop2OpcodeInfo VOP2_OPS[] = {
|
||||
{0x01u, Opcode::VCndmaskB32, Vop2SdwaProfile::Cndmask},
|
||||
{0x02u, Opcode::VDot2cF32F16},
|
||||
{0x03u, Opcode::VAddF32, Vop2SdwaProfile::Float32},
|
||||
{0x04u, Opcode::VSubF32, Vop2SdwaProfile::Float32},
|
||||
{0x05u, Opcode::VSubrevF32},
|
||||
{0x08u, Opcode::VMulF32, Vop2SdwaProfile::Float32},
|
||||
{0x09u, Opcode::VMulI32I24, Vop2SdwaProfile::IntegerFullDestination},
|
||||
{0x0bu, Opcode::VMulU32U24, Vop2SdwaProfile::IntegerFullDestination},
|
||||
{0x0fu, Opcode::VMinF32},
|
||||
{0x10u, Opcode::VMaxF32},
|
||||
{0x11u, Opcode::VMinI32},
|
||||
{0x12u, Opcode::VMaxI32},
|
||||
{0x13u, Opcode::VMinU32, Vop2SdwaProfile::IntegerPartialDestination},
|
||||
{0x14u, Opcode::VMaxU32, Vop2SdwaProfile::IntegerFullDestination},
|
||||
{0x15u, Opcode::VLshrB32},
|
||||
{0x16u, Opcode::VLshrrevB32, Vop2SdwaProfile::ReverseLogicalRight},
|
||||
{0x17u, Opcode::VAshrI32},
|
||||
{0x18u, Opcode::VAshrrevI32},
|
||||
{0x19u, Opcode::VLshlB32},
|
||||
{0x1au, Opcode::VLshlrevB32, Vop2SdwaProfile::ReverseLogicalLeft},
|
||||
{0x1bu, Opcode::VAndB32, Vop2SdwaProfile::Bitwise},
|
||||
{0x1cu, Opcode::VOrB32, Vop2SdwaProfile::Bitwise},
|
||||
{0x1du, Opcode::VXorB32, Vop2SdwaProfile::Bitwise},
|
||||
{0x1eu, Opcode::VXnorB32, Vop2SdwaProfile::Bitwise},
|
||||
{0x1fu, Opcode::VMacF32},
|
||||
{0x20u, Opcode::VMadmkF32},
|
||||
{0x21u, Opcode::VMadakF32},
|
||||
{0x22u, Opcode::VBcntU32B32},
|
||||
{0x23u, Opcode::VMbcntLoU32B32},
|
||||
{0x24u, Opcode::VMbcntHiU32B32},
|
||||
{0x25u, Opcode::VAddNcU32, Vop2SdwaProfile::IntegerFullDestination},
|
||||
{0x28u, Opcode::VAddcU32},
|
||||
{0x26u, Opcode::VSubNcU32, Vop2SdwaProfile::IntegerPartialDestination},
|
||||
{0x27u, Opcode::VSubrevNcU32, Vop2SdwaProfile::IntegerFullDestination},
|
||||
{0x2bu, Opcode::VMacF32},
|
||||
{0x2cu, Opcode::VMadmkF32},
|
||||
{0x2du, Opcode::VMadakF32},
|
||||
{0x2fu, Opcode::VCvtPkrtzF16F32},
|
||||
{0x32u, Opcode::VAddF16, Vop2SdwaProfile::Float16},
|
||||
{0x33u, Opcode::VSubF16, Vop2SdwaProfile::Float16},
|
||||
{0x34u, Opcode::VSubrevF16, Vop2SdwaProfile::Float16},
|
||||
{0x35u, Opcode::VMulF16, Vop2SdwaProfile::Float16},
|
||||
{0x36u, Opcode::VFmacF16},
|
||||
{0x37u, Opcode::VFmamkF16},
|
||||
{0x38u, Opcode::VFmaakF16},
|
||||
{0x39u, Opcode::VMaxF16, Vop2SdwaProfile::Float16},
|
||||
{0x3au, Opcode::VMinF16, Vop2SdwaProfile::Float16},
|
||||
{0x3cu, Opcode::VPkFmacF16},
|
||||
};
|
||||
static_assert(Detail::HasUniqueEncodings(VOP2_OPS));
|
||||
|
||||
constexpr Opcode LookupVop2Opcode(uint32_t encoding) {
|
||||
return Detail::LookupOpcode(VOP2_OPS, encoding);
|
||||
}
|
||||
|
||||
constexpr OpcodeMap VOP1_OPS[] = {
|
||||
{0x00u, Opcode::VNop},
|
||||
{0x01u, Opcode::VMovB32},
|
||||
@@ -135,37 +183,59 @@ constexpr OpcodeMap VOP3_ENCODED_VOP1_OPS[] = {
|
||||
{0x5eu, Opcode::VRndneF16},
|
||||
};
|
||||
|
||||
constexpr OpcodeMap VOPC_OPS[] = {
|
||||
{0x00u, Opcode::VCmpFF32}, {0x01u, Opcode::VCmpLtF32}, {0x02u, Opcode::VCmpEqF32},
|
||||
{0x03u, Opcode::VCmpLeF32}, {0x04u, Opcode::VCmpGtF32}, {0x05u, Opcode::VCmpLgF32},
|
||||
{0x06u, Opcode::VCmpGeF32}, {0x07u, Opcode::VCmpOF32}, {0x08u, Opcode::VCmpUF32},
|
||||
{0x09u, Opcode::VCmpNgeF32}, {0x0au, Opcode::VCmpNlgF32}, {0x0bu, Opcode::VCmpNgtF32},
|
||||
{0x0cu, Opcode::VCmpNleF32}, {0x0du, Opcode::VCmpNeqF32}, {0x0eu, Opcode::VCmpNltF32},
|
||||
{0x0fu, Opcode::VCmpTruF32}, {0x11u, Opcode::VCmpxLtF32}, {0x12u, Opcode::VCmpxEqF32},
|
||||
{0x13u, Opcode::VCmpxLeF32}, {0x14u, Opcode::VCmpxGtF32}, {0x15u, Opcode::VCmpxLgF32},
|
||||
{0x16u, Opcode::VCmpxGeF32}, {0x19u, Opcode::VCmpxNgeF32}, {0x1au, Opcode::VCmpxNlgF32},
|
||||
{0x1bu, Opcode::VCmpxNgtF32}, {0x1cu, Opcode::VCmpxNleF32}, {0x1du, Opcode::VCmpxNeqF32},
|
||||
{0x1eu, Opcode::VCmpxNltF32}, {0x80u, Opcode::VCmpFI32}, {0x81u, Opcode::VCmpLtI32},
|
||||
{0x82u, Opcode::VCmpEqI32}, {0x83u, Opcode::VCmpLeI32}, {0x84u, Opcode::VCmpGtI32},
|
||||
{0x85u, Opcode::VCmpNeI32}, {0x86u, Opcode::VCmpGeI32}, {0x87u, Opcode::VCmpTI32},
|
||||
{0x88u, Opcode::VCmpClassF32}, {0x89u, Opcode::VCmpLtI16}, {0x8au, Opcode::VCmpEqI16},
|
||||
{0x8bu, Opcode::VCmpLeI16}, {0x8cu, Opcode::VCmpGtI16}, {0x8du, Opcode::VCmpNeI16},
|
||||
{0x8eu, Opcode::VCmpGeI16}, {0x91u, Opcode::VCmpxLtI32}, {0x92u, Opcode::VCmpxEqI32},
|
||||
{0x93u, Opcode::VCmpxLeI32}, {0x94u, Opcode::VCmpxGtI32}, {0x95u, Opcode::VCmpxNeI32},
|
||||
{0x96u, Opcode::VCmpxGeI32}, {0xa9u, Opcode::VCmpLtU16}, {0xaau, Opcode::VCmpEqU16},
|
||||
{0xabu, Opcode::VCmpLeU16}, {0xacu, Opcode::VCmpGtU16}, {0xadu, Opcode::VCmpNeU16},
|
||||
{0xaeu, Opcode::VCmpGeU16}, {0xc0u, Opcode::VCmpFU32}, {0xc1u, Opcode::VCmpLtU32},
|
||||
{0xc2u, Opcode::VCmpEqU32}, {0xc3u, Opcode::VCmpLeU32}, {0xc4u, Opcode::VCmpGtU32},
|
||||
{0xc5u, Opcode::VCmpNeU32}, {0xc6u, Opcode::VCmpGeU32}, {0xc7u, Opcode::VCmpTU32},
|
||||
{0xd1u, Opcode::VCmpxLtU32}, {0xd2u, Opcode::VCmpxEqU32}, {0xd3u, Opcode::VCmpxLeU32},
|
||||
{0xd4u, Opcode::VCmpxGtU32}, {0xd5u, Opcode::VCmpxNeU32}, {0xd6u, Opcode::VCmpxGeU32},
|
||||
{0xe5u, Opcode::VCmpNeU64}, {0xc9u, Opcode::VCmpLtF16}, {0xcau, Opcode::VCmpEqF16},
|
||||
{0xcbu, Opcode::VCmpLeF16}, {0xccu, Opcode::VCmpGtF16}, {0xcdu, Opcode::VCmpLgF16},
|
||||
{0xceu, Opcode::VCmpGeF16}, {0xedu, Opcode::VCmpNeqF16}, {0xd9u, Opcode::VCmpxLtF16},
|
||||
{0xdau, Opcode::VCmpxEqF16}, {0xdbu, Opcode::VCmpxLeF16}, {0xdcu, Opcode::VCmpxGtF16},
|
||||
{0xdeu, Opcode::VCmpxGeF16}, {0xfdu, Opcode::VCmpxNeqF16}, {0xfeu, Opcode::VCmpxNltF16},
|
||||
struct VopcOpcodeInfo {
|
||||
uint32_t encoding = 0;
|
||||
Opcode decoded = Opcode::Unknown;
|
||||
bool supports_dpp = true;
|
||||
};
|
||||
|
||||
constexpr VopcOpcodeInfo VOPC_OPS[] = {
|
||||
{0x00u, Opcode::VCmpFF32}, {0x01u, Opcode::VCmpLtF32},
|
||||
{0x02u, Opcode::VCmpEqF32}, {0x03u, Opcode::VCmpLeF32},
|
||||
{0x04u, Opcode::VCmpGtF32}, {0x05u, Opcode::VCmpLgF32},
|
||||
{0x06u, Opcode::VCmpGeF32}, {0x07u, Opcode::VCmpOF32},
|
||||
{0x08u, Opcode::VCmpUF32}, {0x09u, Opcode::VCmpNgeF32},
|
||||
{0x0au, Opcode::VCmpNlgF32}, {0x0bu, Opcode::VCmpNgtF32},
|
||||
{0x0cu, Opcode::VCmpNleF32}, {0x0du, Opcode::VCmpNeqF32},
|
||||
{0x0eu, Opcode::VCmpNltF32}, {0x0fu, Opcode::VCmpTruF32},
|
||||
{0x11u, Opcode::VCmpxLtF32}, {0x12u, Opcode::VCmpxEqF32},
|
||||
{0x13u, Opcode::VCmpxLeF32}, {0x14u, Opcode::VCmpxGtF32},
|
||||
{0x15u, Opcode::VCmpxLgF32}, {0x16u, Opcode::VCmpxGeF32},
|
||||
{0x19u, Opcode::VCmpxNgeF32}, {0x1au, Opcode::VCmpxNlgF32},
|
||||
{0x1bu, Opcode::VCmpxNgtF32}, {0x1cu, Opcode::VCmpxNleF32},
|
||||
{0x1du, Opcode::VCmpxNeqF32}, {0x1eu, Opcode::VCmpxNltF32},
|
||||
{0x80u, Opcode::VCmpFI32}, {0x81u, Opcode::VCmpLtI32},
|
||||
{0x82u, Opcode::VCmpEqI32}, {0x83u, Opcode::VCmpLeI32},
|
||||
{0x84u, Opcode::VCmpGtI32}, {0x85u, Opcode::VCmpNeI32},
|
||||
{0x86u, Opcode::VCmpGeI32}, {0x87u, Opcode::VCmpTI32},
|
||||
{0x88u, Opcode::VCmpClassF32}, {0x89u, Opcode::VCmpLtI16},
|
||||
{0x8au, Opcode::VCmpEqI16}, {0x8bu, Opcode::VCmpLeI16},
|
||||
{0x8cu, Opcode::VCmpGtI16}, {0x8du, Opcode::VCmpNeI16},
|
||||
{0x8eu, Opcode::VCmpGeI16}, {0x91u, Opcode::VCmpxLtI32},
|
||||
{0x92u, Opcode::VCmpxEqI32}, {0x93u, Opcode::VCmpxLeI32},
|
||||
{0x94u, Opcode::VCmpxGtI32}, {0x95u, Opcode::VCmpxNeI32},
|
||||
{0x96u, Opcode::VCmpxGeI32}, {0xa9u, Opcode::VCmpLtU16},
|
||||
{0xaau, Opcode::VCmpEqU16}, {0xabu, Opcode::VCmpLeU16},
|
||||
{0xacu, Opcode::VCmpGtU16}, {0xadu, Opcode::VCmpNeU16},
|
||||
{0xaeu, Opcode::VCmpGeU16}, {0xc0u, Opcode::VCmpFU32},
|
||||
{0xc1u, Opcode::VCmpLtU32}, {0xc2u, Opcode::VCmpEqU32},
|
||||
{0xc3u, Opcode::VCmpLeU32}, {0xc4u, Opcode::VCmpGtU32},
|
||||
{0xc5u, Opcode::VCmpNeU32}, {0xc6u, Opcode::VCmpGeU32},
|
||||
{0xc7u, Opcode::VCmpTU32}, {0xa2u, Opcode::VCmpEqI64, false},
|
||||
{0xd1u, Opcode::VCmpxLtU32}, {0xd2u, Opcode::VCmpxEqU32},
|
||||
{0xd3u, Opcode::VCmpxLeU32}, {0xd4u, Opcode::VCmpxGtU32},
|
||||
{0xd5u, Opcode::VCmpxNeU32}, {0xd6u, Opcode::VCmpxGeU32},
|
||||
{0xe5u, Opcode::VCmpNeU64, false}, {0xc9u, Opcode::VCmpLtF16},
|
||||
{0xcau, Opcode::VCmpEqF16}, {0xcbu, Opcode::VCmpLeF16},
|
||||
{0xccu, Opcode::VCmpGtF16}, {0xcdu, Opcode::VCmpLgF16},
|
||||
{0xceu, Opcode::VCmpGeF16}, {0xedu, Opcode::VCmpNeqF16},
|
||||
{0xd9u, Opcode::VCmpxLtF16}, {0xdau, Opcode::VCmpxEqF16},
|
||||
{0xdbu, Opcode::VCmpxLeF16}, {0xdcu, Opcode::VCmpxGtF16},
|
||||
{0xdeu, Opcode::VCmpxGeF16}, {0xfdu, Opcode::VCmpxNeqF16},
|
||||
{0xfeu, Opcode::VCmpxNltF16},
|
||||
};
|
||||
static_assert(Detail::HasUniqueEncodings(VOPC_OPS));
|
||||
|
||||
constexpr OpcodeMap VOP3_OPS[] = {
|
||||
{0x141u, Opcode::VMadF32}, {0x142u, Opcode::VMadI32I24},
|
||||
{0x143u, Opcode::VMadU32U24}, {0x176u, Opcode::VMadU64U32},
|
||||
@@ -214,16 +284,6 @@ constexpr OpcodeMap VOP3P_OPS[] = {
|
||||
{0x22u, Opcode::VMadMixhiF16},
|
||||
};
|
||||
|
||||
Opcode Lookup(const OpcodeMap* ops, uint32_t count, uint32_t opcode) {
|
||||
for (uint32_t i = 0; i < count; i++) {
|
||||
const auto& op = ops[i];
|
||||
if (op.opcode == opcode) {
|
||||
return op.ir;
|
||||
}
|
||||
}
|
||||
return Opcode::Unsupported;
|
||||
}
|
||||
|
||||
bool IsVop2LiteralMadOpcode(uint32_t opcode) {
|
||||
return opcode == 0x20u || opcode == 0x21u || opcode == 0x2cu || opcode == 0x2du;
|
||||
}
|
||||
@@ -234,24 +294,23 @@ bool IsUnsupportedVop3EncodedVop2Alias(uint32_t opcode) {
|
||||
}
|
||||
|
||||
Opcode LookupVop3Opcode(uint32_t opcode) {
|
||||
const auto direct = Lookup(VOP3_OPS, static_cast<uint32_t>(std::size(VOP3_OPS)), opcode);
|
||||
const auto direct = Detail::LookupOpcode(VOP3_OPS, opcode);
|
||||
if (direct != Opcode::Unsupported) {
|
||||
return direct;
|
||||
}
|
||||
if (opcode <= 0xffu) {
|
||||
return Lookup(VOPC_OPS, static_cast<uint32_t>(std::size(VOPC_OPS)), opcode);
|
||||
return Detail::LookupOpcode(VOPC_OPS, opcode);
|
||||
}
|
||||
if (opcode >= 0x100u && opcode <= 0x13fu) {
|
||||
if (IsUnsupportedVop3EncodedVop2Alias(opcode - 0x100u)) {
|
||||
return Opcode::Unsupported;
|
||||
}
|
||||
return Lookup(VOP2_OPS, static_cast<uint32_t>(std::size(VOP2_OPS)), opcode - 0x100u);
|
||||
return LookupVop2Opcode(opcode - 0x100u);
|
||||
}
|
||||
if (opcode >= 0x180u && opcode <= 0x1ffu) {
|
||||
return Lookup(VOP3_ENCODED_VOP1_OPS,
|
||||
static_cast<uint32_t>(std::size(VOP3_ENCODED_VOP1_OPS)), opcode - 0x180u);
|
||||
return Detail::LookupOpcode(VOP3_ENCODED_VOP1_OPS, opcode - 0x180u);
|
||||
}
|
||||
return Lookup(VOP3_OPS, static_cast<uint32_t>(std::size(VOP3_OPS)), opcode);
|
||||
return Detail::LookupOpcode(VOP3_OPS, opcode);
|
||||
}
|
||||
|
||||
bool IsVop3EncodedVopc(uint32_t opcode) {
|
||||
@@ -791,7 +850,6 @@ Vop2SdwaFields DecodeVop2SdwaFields(uint32_t modifier) {
|
||||
}
|
||||
|
||||
struct Vop2SdwaRule {
|
||||
Opcode opcode = Opcode::Unknown;
|
||||
uint32_t dst_selectors = SdwaSelFull();
|
||||
uint32_t src0_selectors = SdwaSelFull();
|
||||
uint32_t src1_selectors = SdwaSelFull();
|
||||
@@ -804,46 +862,27 @@ constexpr uint32_t SdwaSelAll() {
|
||||
}
|
||||
|
||||
constexpr Vop2SdwaRule VOP2_SDWA_RULES[] = {
|
||||
{Opcode::VCndmaskB32, SdwaSelWords(), SdwaSelWords() | SdwaSelFull(),
|
||||
SdwaSelWords() | SdwaSelFull(), true, false},
|
||||
{Opcode::VAddF32, SdwaSelFull(), SdwaSelFull(), SdwaSelFull(), false, true},
|
||||
{Opcode::VSubF32, SdwaSelFull(), SdwaSelFull(), SdwaSelFull(), false, true},
|
||||
{Opcode::VMulF32, SdwaSelFull(), SdwaSelFull(), SdwaSelFull(), false, true},
|
||||
{Opcode::VAddF16, SdwaSelWords() | SdwaSelFull(), SdwaSelWords() | SdwaSelFull(),
|
||||
SdwaSelWords() | SdwaSelFull(), true, true},
|
||||
{Opcode::VSubF16, SdwaSelWords() | SdwaSelFull(), SdwaSelWords() | SdwaSelFull(),
|
||||
SdwaSelWords() | SdwaSelFull(), true, true},
|
||||
{Opcode::VSubrevF16, SdwaSelWords() | SdwaSelFull(), SdwaSelWords() | SdwaSelFull(),
|
||||
SdwaSelWords() | SdwaSelFull(), true, true},
|
||||
{Opcode::VMulF16, SdwaSelWords() | SdwaSelFull(), SdwaSelWords() | SdwaSelFull(),
|
||||
SdwaSelWords() | SdwaSelFull(), true, true},
|
||||
{Opcode::VMaxF16, SdwaSelWords() | SdwaSelFull(), SdwaSelWords() | SdwaSelFull(),
|
||||
SdwaSelWords() | SdwaSelFull(), true, true},
|
||||
{Opcode::VMinF16, SdwaSelWords() | SdwaSelFull(), SdwaSelWords() | SdwaSelFull(),
|
||||
SdwaSelWords() | SdwaSelFull(), true, true},
|
||||
{Opcode::VMulI32I24, SdwaSelFull(), SdwaSelAll(), SdwaSelAll(), false, false},
|
||||
{Opcode::VMulU32U24, SdwaSelFull(), SdwaSelAll(), SdwaSelAll(), false, false},
|
||||
{Opcode::VMinU32, SdwaSelFull(), SdwaSelAll(), SdwaSelAll(), false, false},
|
||||
{Opcode::VMaxU32, SdwaSelFull(), SdwaSelAll(), SdwaSelAll(), false, false},
|
||||
{Opcode::VLshrrevB32, SdwaSelFull(), SdwaSelFull(), SdwaSelWords() | SdwaSelFull(), false,
|
||||
false},
|
||||
{Opcode::VLshlrevB32, SdwaSelFull(), SdwaSelFull(), SdwaSelAll(), false, false},
|
||||
{Opcode::VAndB32, SdwaSelWords() | SdwaSelFull(), SdwaSelAll(), SdwaSelAll(), true, false},
|
||||
{Opcode::VOrB32, SdwaSelWords() | SdwaSelFull(), SdwaSelAll(), SdwaSelAll(), true, false},
|
||||
{Opcode::VXorB32, SdwaSelWords() | SdwaSelFull(), SdwaSelAll(), SdwaSelAll(), true, false},
|
||||
{Opcode::VXnorB32, SdwaSelWords() | SdwaSelFull(), SdwaSelAll(), SdwaSelAll(), true, false},
|
||||
{Opcode::VAddNcU32, SdwaSelFull(), SdwaSelAll(), SdwaSelAll(), false, false},
|
||||
{Opcode::VSubNcU32, SdwaSelFull(), SdwaSelAll(), SdwaSelAll(), false, false},
|
||||
{Opcode::VSubrevNcU32, SdwaSelFull(), SdwaSelAll(), SdwaSelAll(), false, false},
|
||||
{},
|
||||
{SdwaSelWords() | SdwaSelFull(), SdwaSelWords() | SdwaSelFull(), SdwaSelWords() | SdwaSelFull(),
|
||||
true, false},
|
||||
{SdwaSelFull(), SdwaSelFull(), SdwaSelFull(), false, true},
|
||||
{SdwaSelWords() | SdwaSelFull(), SdwaSelWords() | SdwaSelFull(), SdwaSelWords() | SdwaSelFull(),
|
||||
true, true},
|
||||
{SdwaSelFull(), SdwaSelAll(), SdwaSelAll(), false, false},
|
||||
{SdwaSelAll(), SdwaSelAll(), SdwaSelAll(), true, false},
|
||||
{SdwaSelFull(), SdwaSelFull(), SdwaSelWords() | SdwaSelFull(), false, false},
|
||||
{SdwaSelFull(), SdwaSelFull(), SdwaSelAll(), false, false},
|
||||
{SdwaSelWords() | SdwaSelFull(), SdwaSelAll(), SdwaSelAll(), true, false},
|
||||
};
|
||||
static_assert(sizeof(VOP2_SDWA_RULES) / sizeof(VOP2_SDWA_RULES[0]) ==
|
||||
static_cast<size_t>(Vop2SdwaProfile::Count));
|
||||
|
||||
const Vop2SdwaRule* FindVop2SdwaRule(Opcode opcode) {
|
||||
for (const auto& rule: VOP2_SDWA_RULES) {
|
||||
if (rule.opcode == opcode) {
|
||||
return &rule;
|
||||
}
|
||||
const Vop2SdwaRule* FindVop2SdwaRule(uint32_t encoding) {
|
||||
const auto* info = Detail::FindOpcode(VOP2_OPS, encoding);
|
||||
if (info == nullptr || info->sdwa_profile == Vop2SdwaProfile::None) {
|
||||
return nullptr;
|
||||
}
|
||||
return nullptr;
|
||||
return &VOP2_SDWA_RULES[static_cast<size_t>(info->sdwa_profile)];
|
||||
}
|
||||
|
||||
bool IsVop2SdwaDestinationSupported(const Vop2SdwaRule& rule, const Vop2SdwaFields& fields) {
|
||||
@@ -881,7 +920,7 @@ bool ValidateVop2Sdwa(Instruction& inst, uint32_t opcode, const Vop2SdwaFields&
|
||||
return true;
|
||||
}
|
||||
|
||||
const auto* rule = FindVop2SdwaRule(inst.opcode);
|
||||
const auto* rule = FindVop2SdwaRule(opcode);
|
||||
if (rule == nullptr) {
|
||||
SetUnsupported(inst, Family::VOP2, opcode,
|
||||
"VOP2 SDWA modifier is not supported for opcode");
|
||||
@@ -1135,6 +1174,11 @@ bool DecodeVopcDpp(uint32_t pc, std::span<const uint32_t> code, uint32_t word_in
|
||||
SetUnsupported(inst, Family::VOPC, opcode, "VOPC opcode is not implemented");
|
||||
return true;
|
||||
}
|
||||
const auto* info = Detail::FindOpcode(VOPC_OPS, opcode);
|
||||
if (info == nullptr || !info->supports_dpp) {
|
||||
SetUnsupported(inst, Family::VOPC, opcode, "VOPC DPP modifier is not supported for opcode");
|
||||
return true;
|
||||
}
|
||||
if (!DecodeScalarSource(src0 + 256u, pc, inst.src0, error) ||
|
||||
!DecodeVectorGpr(vsrc1, inst.src1, error)) {
|
||||
return false;
|
||||
@@ -1427,7 +1471,7 @@ bool DecodeVop2(uint32_t pc, std::span<const uint32_t> code, uint32_t word_index
|
||||
inst.word = word;
|
||||
inst.family = Family::VOP2;
|
||||
inst.opcode_id = opcode;
|
||||
inst.opcode = Lookup(VOP2_OPS, static_cast<uint32_t>(std::size(VOP2_OPS)), opcode);
|
||||
inst.opcode = LookupVop2Opcode(opcode);
|
||||
SetRawWords(inst, code, word_index, 1);
|
||||
|
||||
switch (opcode) {
|
||||
@@ -1468,7 +1512,7 @@ bool DecodeVop1(uint32_t pc, std::span<const uint32_t> code, uint32_t word_index
|
||||
inst.word = word;
|
||||
inst.family = Family::VOP1;
|
||||
inst.opcode_id = opcode;
|
||||
inst.opcode = Lookup(VOP1_OPS, static_cast<uint32_t>(std::size(VOP1_OPS)), opcode);
|
||||
inst.opcode = Detail::LookupOpcode(VOP1_OPS, opcode);
|
||||
SetRawWords(inst, code, word_index, 1);
|
||||
|
||||
if (inst.opcode == Opcode::Unsupported) {
|
||||
@@ -1509,7 +1553,7 @@ bool DecodeVopc(uint32_t pc, std::span<const uint32_t> code, uint32_t word_index
|
||||
inst.word = word;
|
||||
inst.family = Family::VOPC;
|
||||
inst.opcode_id = opcode;
|
||||
inst.opcode = Lookup(VOPC_OPS, static_cast<uint32_t>(std::size(VOPC_OPS)), opcode);
|
||||
inst.opcode = Detail::LookupOpcode(VOPC_OPS, opcode);
|
||||
inst.dst.kind = IsVopcCompareExec(inst.opcode) ? OperandKind::ExecLo : OperandKind::VccLo;
|
||||
SetRawWords(inst, code, word_index, 1);
|
||||
|
||||
@@ -1723,7 +1767,7 @@ bool DecodeVop3p(uint32_t pc, std::span<const uint32_t> code, uint32_t word_inde
|
||||
inst.word = word0;
|
||||
inst.family = Family::VOP3P;
|
||||
inst.opcode_id = opcode;
|
||||
inst.opcode = Lookup(VOP3P_OPS, static_cast<uint32_t>(std::size(VOP3P_OPS)), opcode);
|
||||
inst.opcode = Detail::LookupOpcode(VOP3P_OPS, opcode);
|
||||
SetRawWords(inst, code, word_index, 2);
|
||||
|
||||
if (inst.opcode == Opcode::Unsupported) {
|
||||
|
||||
@@ -131,7 +131,9 @@ bool IsAtomic(IR::Opcode op) {
|
||||
case IR::Opcode::AtomicUMaxU32:
|
||||
case IR::Opcode::AtomicAndU32:
|
||||
case IR::Opcode::AtomicOrU32:
|
||||
case IR::Opcode::AtomicXorU32: return true;
|
||||
case IR::Opcode::AtomicXorU32:
|
||||
case IR::Opcode::AtomicFMinF32:
|
||||
case IR::Opcode::AtomicFMaxF32: return true;
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
@@ -141,6 +143,9 @@ uint32_t BufferAddressOperandCount(const IR::Instruction& inst) {
|
||||
}
|
||||
|
||||
bool ValidateInstructionContract(const IR::Instruction& inst, std::string* error) {
|
||||
if (static_cast<size_t>(inst.op) >= static_cast<size_t>(IR::Opcode::Count)) {
|
||||
return Fail(error, "IR instruction opcode is out of range");
|
||||
}
|
||||
if (inst.src_count > std::size(inst.src)) {
|
||||
return Fail(error, "instruction source count exceeds fixed IR storage");
|
||||
}
|
||||
@@ -200,6 +205,12 @@ bool ValidateInstructionContract(const IR::Instruction& inst, std::string* error
|
||||
inst.src_count != 2)) {
|
||||
return Fail(error, "storage image instruction has an invalid resource class");
|
||||
}
|
||||
const auto float_atomic =
|
||||
inst.op == IR::Opcode::AtomicFMinF32 || inst.op == IR::Opcode::AtomicFMaxF32;
|
||||
if (float_atomic &&
|
||||
(kind != IR::ResourceKind::Buffer || inst.src_count != buffer_address_count + 1u)) {
|
||||
return Fail(error, "floating-point atomic instruction must target a buffer");
|
||||
}
|
||||
if (IsAtomic(inst.op) &&
|
||||
!((kind == IR::ResourceKind::Buffer && inst.src_count == buffer_address_count + 1u) ||
|
||||
((kind == IR::ResourceKind::Lds || kind == IR::ResourceKind::Gds) &&
|
||||
@@ -389,7 +400,7 @@ bool ProgramRequiresExactSubgroupSize(const IR::Program& program) {
|
||||
if (Emitter::InstructionHasDppSource(inst)) {
|
||||
return true;
|
||||
}
|
||||
if (Emitter::IsCompareOpcode(inst.op) && !Emitter::IsSccOperand(inst.dst)) {
|
||||
if (IR::IsCompareOpcode(inst.op) && !Emitter::IsSccOperand(inst.dst)) {
|
||||
return true;
|
||||
}
|
||||
if ((IsExecDestination(inst.dst) || IsExecDestination(inst.dst2)) &&
|
||||
@@ -488,6 +499,13 @@ bool EmitProgram(const IR::Program& program, const IR::ResourceSnapshot& resourc
|
||||
AllocateBlockLabels(state, program);
|
||||
AllocateDispatcherState(state, program);
|
||||
EmitFunction(state, program);
|
||||
if (state.unsupported_ir_instruction) {
|
||||
char pc[9] {};
|
||||
std::snprintf(pc, sizeof(pc), "%08x", state.unsupported_ir_pc);
|
||||
return Fail(error, "SPIR-V emitter has no handler for IR opcode " +
|
||||
std::string(IR::OpcodeName(state.unsupported_ir_opcode)) +
|
||||
" at pc 0x" + pc);
|
||||
}
|
||||
|
||||
ReportReserveExceeded(program, "registers", state.registers.size());
|
||||
ReportReserveExceeded(program, "inputs", state.inputs.size());
|
||||
|
||||
@@ -1486,17 +1486,20 @@ void EmitBitCompareB32(EmitterState& state, const IR::Instruction& inst, bool bi
|
||||
EmitStoreU32(state, inst.dst, ret);
|
||||
}
|
||||
|
||||
void EmitCompareNeU64(EmitterState& state, const IR::Instruction& inst) {
|
||||
const auto lhs_low = EmitSequentialValueLoad(state, inst.src[0], 0);
|
||||
const auto lhs_high = EmitSequentialValueLoad(state, inst.src[0], 1);
|
||||
const auto rhs_low = EmitSequentialValueLoad(state, inst.src[1], 0);
|
||||
const auto rhs_high = EmitSequentialValueLoad(state, inst.src[1], 1);
|
||||
const auto ne_low = state.builder.AllocateId();
|
||||
const auto ne_high = state.builder.AllocateId();
|
||||
const auto cond = state.builder.AllocateId();
|
||||
state.builder.AddFunction({OpINotEqual, state.bool_type, ne_low, lhs_low, rhs_low});
|
||||
state.builder.AddFunction({OpINotEqual, state.bool_type, ne_high, lhs_high, rhs_high});
|
||||
state.builder.AddFunction({OpLogicalOr, state.bool_type, cond, ne_low, ne_high});
|
||||
void EmitCompareU64(EmitterState& state, const IR::Instruction& inst) {
|
||||
const bool equal = inst.op == IR::Opcode::CompareEqU64;
|
||||
const auto lhs_low = EmitSequentialValueLoad(state, inst.src[0], 0);
|
||||
const auto lhs_high = EmitSequentialValueLoad(state, inst.src[0], 1);
|
||||
const auto rhs_low = EmitSequentialValueLoad(state, inst.src[1], 0);
|
||||
const auto rhs_high = EmitSequentialValueLoad(state, inst.src[1], 1);
|
||||
const auto low = state.builder.AllocateId();
|
||||
const auto high = state.builder.AllocateId();
|
||||
const auto cond = state.builder.AllocateId();
|
||||
const auto compare_op = equal ? OpIEqual : OpINotEqual;
|
||||
state.builder.AddFunction({compare_op, state.bool_type, low, lhs_low, rhs_low});
|
||||
state.builder.AddFunction({compare_op, state.bool_type, high, lhs_high, rhs_high});
|
||||
state.builder.AddFunction(
|
||||
{equal ? OpLogicalAnd : OpLogicalOr, state.bool_type, cond, low, high});
|
||||
EmitCompareResult(state, inst.dst, cond);
|
||||
}
|
||||
|
||||
|
||||
@@ -75,8 +75,6 @@ bool IsSccOperand(const IR::Operand& operand) {
|
||||
return operand.kind == IR::OperandKind::Register && operand.reg.file == IR::RegisterFile::Scc;
|
||||
}
|
||||
|
||||
bool IsCompareOpcode(IR::Opcode op);
|
||||
|
||||
void CollectMaskStateRegisters(std::vector<RegisterBinding>& registers) {
|
||||
CollectRegister(registers, {IR::RegisterFile::Exec, 0});
|
||||
CollectRegister(registers, {IR::RegisterFile::Exec, 1});
|
||||
@@ -189,11 +187,11 @@ void CollectRegisters(const IR::Program& program, std::vector<RegisterBinding>&
|
||||
if (inst.op == IR::Opcode::BitCountU64 || inst.op == IR::Opcode::FindMsbFromHighU64) {
|
||||
CollectSequentialRegisters(registers, inst.src[0], 2);
|
||||
}
|
||||
if (inst.op == IR::Opcode::CompareNeU64) {
|
||||
if (IR::IsCompare64Opcode(inst.op)) {
|
||||
CollectSequentialRegisters(registers, inst.src[0], 2);
|
||||
CollectSequentialRegisters(registers, inst.src[1], 2);
|
||||
}
|
||||
if (IsCompareOpcode(inst.op) && inst.dst.kind == IR::OperandKind::Register &&
|
||||
if (IR::IsCompareOpcode(inst.op) && inst.dst.kind == IR::OperandKind::Register &&
|
||||
inst.dst.reg.file != IR::RegisterFile::Scc) {
|
||||
CollectSequentialRegisters(registers, inst.dst, 2);
|
||||
}
|
||||
@@ -384,93 +382,6 @@ bool ProgramNeedsSubgroupShuffle(const IR::Program& program) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IsCompareOpcode(IR::Opcode op) {
|
||||
switch (op) {
|
||||
case IR::Opcode::CompareFalse:
|
||||
case IR::Opcode::CompareTrue:
|
||||
case IR::Opcode::CompareEqU32:
|
||||
case IR::Opcode::CompareNeU32:
|
||||
case IR::Opcode::CompareGtU32:
|
||||
case IR::Opcode::CompareGeU32:
|
||||
case IR::Opcode::CompareLtU32:
|
||||
case IR::Opcode::CompareLeU32:
|
||||
case IR::Opcode::CompareNeU64:
|
||||
case IR::Opcode::CompareMaskEqU32:
|
||||
case IR::Opcode::CompareMaskNeU32:
|
||||
case IR::Opcode::CompareMaskGtU32:
|
||||
case IR::Opcode::CompareMaskGeU32:
|
||||
case IR::Opcode::CompareMaskLtU32:
|
||||
case IR::Opcode::CompareMaskLeU32:
|
||||
case IR::Opcode::CompareEqI32:
|
||||
case IR::Opcode::CompareNeI32:
|
||||
case IR::Opcode::CompareGtI32:
|
||||
case IR::Opcode::CompareGeI32:
|
||||
case IR::Opcode::CompareLtI32:
|
||||
case IR::Opcode::CompareLeI32:
|
||||
case IR::Opcode::CompareEqI16:
|
||||
case IR::Opcode::CompareNeI16:
|
||||
case IR::Opcode::CompareGtI16:
|
||||
case IR::Opcode::CompareGeI16:
|
||||
case IR::Opcode::CompareLtI16:
|
||||
case IR::Opcode::CompareLeI16:
|
||||
case IR::Opcode::CompareMaskEqI32:
|
||||
case IR::Opcode::CompareMaskNeI32:
|
||||
case IR::Opcode::CompareMaskGtI32:
|
||||
case IR::Opcode::CompareMaskGeI32:
|
||||
case IR::Opcode::CompareMaskLtI32:
|
||||
case IR::Opcode::CompareMaskLeI32:
|
||||
case IR::Opcode::CompareEqU16:
|
||||
case IR::Opcode::CompareNeU16:
|
||||
case IR::Opcode::CompareGtU16:
|
||||
case IR::Opcode::CompareGeU16:
|
||||
case IR::Opcode::CompareLtU16:
|
||||
case IR::Opcode::CompareLeU16:
|
||||
case IR::Opcode::CompareEqF32:
|
||||
case IR::Opcode::CompareNeF32:
|
||||
case IR::Opcode::CompareGtF32:
|
||||
case IR::Opcode::CompareGeF32:
|
||||
case IR::Opcode::CompareLtF32:
|
||||
case IR::Opcode::CompareLeF32:
|
||||
case IR::Opcode::CompareOrderedF32:
|
||||
case IR::Opcode::CompareUnorderedF32:
|
||||
case IR::Opcode::CompareUnordEqF32:
|
||||
case IR::Opcode::CompareUnordNeF32:
|
||||
case IR::Opcode::CompareUnordGtF32:
|
||||
case IR::Opcode::CompareUnordGeF32:
|
||||
case IR::Opcode::CompareUnordLtF32:
|
||||
case IR::Opcode::CompareUnordLeF32:
|
||||
case IR::Opcode::CompareClassF32:
|
||||
case IR::Opcode::CompareEqF16:
|
||||
case IR::Opcode::CompareNeF16:
|
||||
case IR::Opcode::CompareGtF16:
|
||||
case IR::Opcode::CompareGeF16:
|
||||
case IR::Opcode::CompareLtF16:
|
||||
case IR::Opcode::CompareLeF16:
|
||||
case IR::Opcode::CompareUnordNeF16:
|
||||
case IR::Opcode::CompareMaskEqF16:
|
||||
case IR::Opcode::CompareMaskNeF16:
|
||||
case IR::Opcode::CompareMaskGtF16:
|
||||
case IR::Opcode::CompareMaskGeF16:
|
||||
case IR::Opcode::CompareMaskLtF16:
|
||||
case IR::Opcode::CompareMaskLeF16:
|
||||
case IR::Opcode::CompareMaskUnordNeF16:
|
||||
case IR::Opcode::CompareMaskUnordGeF16:
|
||||
case IR::Opcode::CompareMaskEqF32:
|
||||
case IR::Opcode::CompareMaskNeF32:
|
||||
case IR::Opcode::CompareMaskGtF32:
|
||||
case IR::Opcode::CompareMaskGeF32:
|
||||
case IR::Opcode::CompareMaskLtF32:
|
||||
case IR::Opcode::CompareMaskLeF32:
|
||||
case IR::Opcode::CompareMaskUnordEqF32:
|
||||
case IR::Opcode::CompareMaskUnordNeF32:
|
||||
case IR::Opcode::CompareMaskUnordGtF32:
|
||||
case IR::Opcode::CompareMaskUnordGeF32:
|
||||
case IR::Opcode::CompareMaskUnordLtF32:
|
||||
case IR::Opcode::CompareMaskUnordLeF32: return true;
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool ProgramNeedsSubgroupLocalInvocationId(const IR::Program& program) {
|
||||
for (const auto& block: program.blocks) {
|
||||
for (const auto& inst: block.instructions) {
|
||||
@@ -481,7 +392,7 @@ bool ProgramNeedsSubgroupLocalInvocationId(const IR::Program& program) {
|
||||
InstructionHasDppSource(inst)) {
|
||||
return true;
|
||||
}
|
||||
if (IsCompareOpcode(inst.op)) {
|
||||
if (IR::IsCompareOpcode(inst.op)) {
|
||||
return true;
|
||||
}
|
||||
if (inst.dst.kind == IR::OperandKind::Register &&
|
||||
|
||||
@@ -516,7 +516,8 @@ void EmitInstruction(EmitterState& state, const IR::Instruction& inst) {
|
||||
case IR::Opcode::CompareGeU32: EmitCompareU32(state, inst, OpUGreaterThanEqual); break;
|
||||
case IR::Opcode::CompareLtU32: EmitCompareU32(state, inst, OpULessThan); break;
|
||||
case IR::Opcode::CompareLeU32: EmitCompareU32(state, inst, OpULessThanEqual); break;
|
||||
case IR::Opcode::CompareNeU64: EmitCompareNeU64(state, inst); break;
|
||||
case IR::Opcode::CompareEqU64:
|
||||
case IR::Opcode::CompareNeU64: EmitCompareU64(state, inst); break;
|
||||
case IR::Opcode::CompareMaskEqU32: EmitCompareMaskU32(state, inst, OpIEqual); break;
|
||||
case IR::Opcode::CompareMaskNeU32: EmitCompareMaskU32(state, inst, OpINotEqual); break;
|
||||
case IR::Opcode::CompareMaskGtU32: EmitCompareMaskU32(state, inst, OpUGreaterThan); break;
|
||||
@@ -774,6 +775,12 @@ void EmitInstruction(EmitterState& state, const IR::Instruction& inst) {
|
||||
case IR::Opcode::AtomicXorU32:
|
||||
EmitGuardedByExec(state, [&]() { EmitAtomicU32(state, inst, OpAtomicXor); });
|
||||
break;
|
||||
case IR::Opcode::AtomicFMinF32:
|
||||
EmitGuardedByExec(state, [&]() { EmitAtomicFMinF32(state, inst); });
|
||||
break;
|
||||
case IR::Opcode::AtomicFMaxF32:
|
||||
EmitGuardedByExec(state, [&]() { EmitAtomicFMaxF32(state, inst); });
|
||||
break;
|
||||
case IR::Opcode::FlatLoadUbyte: EmitFlatLoadUbyte(state, inst); break;
|
||||
case IR::Opcode::FlatLoadSbyte: EmitFlatLoadSbyte(state, inst); break;
|
||||
case IR::Opcode::FlatLoadUshort: EmitFlatLoadUshort(state, inst); break;
|
||||
@@ -850,7 +857,13 @@ void EmitInstruction(EmitterState& state, const IR::Instruction& inst) {
|
||||
}
|
||||
EmitGuardedByExec(state, [&]() { EmitExport(state, inst); });
|
||||
break;
|
||||
default: break;
|
||||
default:
|
||||
if (!state.unsupported_ir_instruction) {
|
||||
state.unsupported_ir_instruction = true;
|
||||
state.unsupported_ir_opcode = inst.op;
|
||||
state.unsupported_ir_pc = inst.pc;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -414,6 +414,9 @@ struct EmitterState {
|
||||
bool needs_image_gather_extended = false;
|
||||
bool needs_function_lds = false;
|
||||
bool needs_pixel_valid_mask = false;
|
||||
bool unsupported_ir_instruction = false;
|
||||
IR::Opcode unsupported_ir_opcode = IR::Opcode::Count;
|
||||
uint32_t unsupported_ir_pc = 0;
|
||||
std::vector<RegisterBinding> registers;
|
||||
std::vector<InputBinding> inputs;
|
||||
std::vector<OutputBinding> outputs;
|
||||
@@ -611,8 +614,6 @@ bool IsMaskRegisterFile(IR::RegisterFile file);
|
||||
|
||||
bool IsSccOperand(const IR::Operand& operand);
|
||||
|
||||
bool IsCompareOpcode(IR::Opcode op);
|
||||
|
||||
void CollectMaskStateRegisters(std::vector<RegisterBinding>& registers);
|
||||
|
||||
void CollectSequentialRegisters(std::vector<RegisterBinding>& registers, const IR::Operand& base,
|
||||
@@ -651,8 +652,6 @@ bool ProgramNeedsSubgroupBallot(const IR::Program& program);
|
||||
|
||||
bool ProgramNeedsSubgroupShuffle(const IR::Program& program);
|
||||
|
||||
bool IsCompareOpcode(IR::Opcode op);
|
||||
|
||||
bool ProgramNeedsSubgroupLocalInvocationId(const IR::Program& program);
|
||||
|
||||
uint32_t PointerForRegister(const EmitterState& state, IR::Register reg);
|
||||
@@ -1015,6 +1014,9 @@ void EmitDeviceAtomicMemoryBarrier(EmitterState& state);
|
||||
|
||||
void EmitAtomicU32(EmitterState& state, const IR::Instruction& inst, uint32_t opcode);
|
||||
|
||||
void EmitAtomicFMinF32(EmitterState& state, const IR::Instruction& inst);
|
||||
void EmitAtomicFMaxF32(EmitterState& state, const IR::Instruction& inst);
|
||||
|
||||
void EmitSLoadDword(EmitterState& state, const IR::Instruction& inst);
|
||||
|
||||
void EmitLoadSrtDword(EmitterState& state, const IR::Instruction& inst);
|
||||
@@ -1345,7 +1347,7 @@ void EmitCompareI16(EmitterState& state, const IR::Instruction& inst, uint32_t o
|
||||
|
||||
void EmitBitCompareB32(EmitterState& state, const IR::Instruction& inst, bool bit_set);
|
||||
|
||||
void EmitCompareNeU64(EmitterState& state, const IR::Instruction& inst);
|
||||
void EmitCompareU64(EmitterState& state, const IR::Instruction& inst);
|
||||
|
||||
void EmitCompareConstant(EmitterState& state, const IR::Instruction& inst, bool value);
|
||||
|
||||
@@ -1577,19 +1579,22 @@ uint32_t EmitValueOrZeroIfCondition(EmitterState& state, uint32_t condition, Fn&
|
||||
}
|
||||
|
||||
const auto then_label = state.builder.AllocateId();
|
||||
const auto then_exit = state.builder.AllocateId();
|
||||
const auto else_label = state.builder.AllocateId();
|
||||
const auto merge_label = state.builder.AllocateId();
|
||||
state.builder.AddFunction({OpSelectionMerge, merge_label, SelectionControlNone});
|
||||
state.builder.AddFunction({OpBranchConditional, condition, then_label, else_label});
|
||||
state.builder.AddFunction({OpLabel, then_label});
|
||||
const auto then_value = fn();
|
||||
state.builder.AddFunction({OpBranch, then_exit});
|
||||
state.builder.AddFunction({OpLabel, then_exit});
|
||||
state.builder.AddFunction({OpBranch, merge_label});
|
||||
state.builder.AddFunction({OpLabel, else_label});
|
||||
state.builder.AddFunction({OpBranch, merge_label});
|
||||
state.builder.AddFunction({OpLabel, merge_label});
|
||||
const auto value = state.builder.AllocateId();
|
||||
state.builder.AddFunction(
|
||||
{OpPhi, state.uint_type, value, then_value, then_label, ConstantU32(state, 0), else_label});
|
||||
{OpPhi, state.uint_type, value, then_value, then_exit, ConstantU32(state, 0), else_label});
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
@@ -640,8 +640,8 @@ void EmitMemoryStoreU32(EmitterState& state, const IR::Instruction& inst, IR::Re
|
||||
}
|
||||
|
||||
template <typename Fn>
|
||||
void EmitAtomicUpdateU32(EmitterState& state, uint32_t pointer, IR::ResourceKind kind,
|
||||
Fn&& desired_value) {
|
||||
uint32_t EmitAtomicUpdateU32(EmitterState& state, uint32_t pointer, IR::ResourceKind kind,
|
||||
Fn&& desired_value) {
|
||||
const auto scope = kind == IR::ResourceKind::Lds ? ScopeWorkgroup : ScopeDevice;
|
||||
const auto memory = kind == IR::ResourceKind::Lds ? MemorySemanticsWorkgroupMemory
|
||||
: MemorySemanticsUniformMemory;
|
||||
@@ -675,6 +675,7 @@ void EmitAtomicUpdateU32(EmitterState& state, uint32_t pointer, IR::ResourceKind
|
||||
const auto semantics = MemorySemanticsAcquireRelease | memory;
|
||||
state.builder.AddFunction(
|
||||
{OpMemoryBarrier, ConstantU32(state, scope), ConstantU32(state, semantics)});
|
||||
return observed;
|
||||
}
|
||||
|
||||
void EmitMemoryStoreSubDwordU32(EmitterState& state, const IR::Instruction& inst,
|
||||
@@ -1181,6 +1182,79 @@ void EmitAtomicU32(EmitterState& state, const IR::Instruction& inst, uint32_t op
|
||||
EmitStoreU32(state, inst.dst, old);
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
uint32_t EmitF32BitsOrderedCompare(EmitterState& state, uint32_t lhs_bits, uint32_t rhs_bits,
|
||||
uint32_t comparison_opcode) {
|
||||
struct ClassifiedBits {
|
||||
uint32_t nan = 0;
|
||||
uint32_t zero = 0;
|
||||
uint32_t key = 0;
|
||||
};
|
||||
const auto Classify = [&](uint32_t bits) {
|
||||
ClassifiedBits cls;
|
||||
const auto abs_bits = EmitAndConstant(state, bits, 0x7fffffffu);
|
||||
const auto exponent_bits = EmitAndConstant(state, abs_bits, 0x7f800000u);
|
||||
const auto mantissa_bits = EmitAndConstant(state, abs_bits, 0x007fffffu);
|
||||
const auto exponent_max =
|
||||
EmitCompareU32Constant(state, OpIEqual, exponent_bits, 0x7f800000u);
|
||||
const auto mantissa_nonzero = EmitCompareU32Constant(state, OpINotEqual, mantissa_bits, 0);
|
||||
const auto negative = EmitCompareU32Constant(state, OpINotEqual,
|
||||
EmitAndConstant(state, bits, 0x80000000u), 0);
|
||||
const auto negative_key = state.builder.AllocateId();
|
||||
const auto positive_key = state.builder.AllocateId();
|
||||
// Map all non-NaN IEEE-754 encodings to monotonically increasing unsigned keys.
|
||||
state.builder.AddFunction({OpNot, state.uint_type, negative_key, bits});
|
||||
state.builder.AddFunction(
|
||||
{OpBitwiseXor, state.uint_type, positive_key, bits, ConstantU32(state, 0x80000000u)});
|
||||
cls.nan = EmitLogicalAndBool(state, exponent_max, mantissa_nonzero);
|
||||
cls.zero = EmitCompareU32Constant(state, OpIEqual, abs_bits, 0);
|
||||
cls.key = EmitSelectValueU32(state, negative, negative_key, positive_key);
|
||||
return cls;
|
||||
};
|
||||
|
||||
const auto lhs = Classify(lhs_bits);
|
||||
const auto rhs = Classify(rhs_bits);
|
||||
const auto any_nan = EmitLogicalOrBool(state, lhs.nan, rhs.nan);
|
||||
// The key transform orders -0 below +0, while the floating comparison treats them as equal.
|
||||
const auto both_zero = EmitLogicalAndBool(state, lhs.zero, rhs.zero);
|
||||
const auto ordered_nonzero =
|
||||
EmitLogicalNotBool(state, EmitLogicalOrBool(state, any_nan, both_zero));
|
||||
const auto comparison = state.builder.AllocateId();
|
||||
state.builder.AddFunction({comparison_opcode, state.bool_type, comparison, lhs.key, rhs.key});
|
||||
return EmitLogicalAndBool(state, ordered_nonzero, comparison);
|
||||
}
|
||||
|
||||
void EmitAtomicFMinMaxF32(EmitterState& state, const IR::Instruction& inst,
|
||||
uint32_t comparison_opcode) {
|
||||
const auto index =
|
||||
EmitMemoryDwordIndex(state, inst, inst.memory, 1, AddressSourceCount(inst, 1));
|
||||
const auto in_bounds = EmitStorageBufferElementInBounds(state, inst.memory, index, inst.pc);
|
||||
const auto src_u32 = EmitValueLoad(state, inst.src[0]);
|
||||
const auto old = EmitValueOrZeroIfCondition(state, in_bounds, [&]() {
|
||||
const auto pointer = EmitStorageBufferElementPointer(state, inst.memory, index, inst.pc);
|
||||
return EmitAtomicUpdateU32(state, pointer, inst.memory.kind, [&](uint32_t old_u32) {
|
||||
const auto replace_old = state.builder.AllocateId();
|
||||
const auto replace =
|
||||
EmitF32BitsOrderedCompare(state, src_u32, old_u32, comparison_opcode);
|
||||
state.builder.AddFunction(
|
||||
{OpSelect, state.uint_type, replace_old, replace, src_u32, old_u32});
|
||||
return replace_old;
|
||||
});
|
||||
});
|
||||
EmitStoreU32(state, inst.dst, old);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void EmitAtomicFMinF32(EmitterState& state, const IR::Instruction& inst) {
|
||||
EmitAtomicFMinMaxF32(state, inst, OpULessThan);
|
||||
}
|
||||
|
||||
void EmitAtomicFMaxF32(EmitterState& state, const IR::Instruction& inst) {
|
||||
EmitAtomicFMinMaxF32(state, inst, OpUGreaterThan);
|
||||
}
|
||||
|
||||
void EmitSLoadDword(EmitterState& state, const IR::Instruction& inst) {
|
||||
if (state.address_memory_variable == 0) {
|
||||
ExitDescriptorBindingFailure(state, IR::DescriptorBindingKind::AddressMemory,
|
||||
|
||||
@@ -30,7 +30,9 @@ bool IsAtomic(Opcode op) {
|
||||
case Opcode::AtomicUMaxU32:
|
||||
case Opcode::AtomicAndU32:
|
||||
case Opcode::AtomicOrU32:
|
||||
case Opcode::AtomicXorU32: return true;
|
||||
case Opcode::AtomicXorU32:
|
||||
case Opcode::AtomicFMinF32:
|
||||
case Opcode::AtomicFMaxF32: return true;
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -490,13 +490,26 @@ bool IsScalarMinMaxOpcode(Decoder::Opcode opcode) {
|
||||
}
|
||||
}
|
||||
|
||||
bool ResolveIrOpcode(Decoder::Opcode decoded, Opcode& lowered, std::string* error) {
|
||||
const auto opcode = LookupIrOpcode(decoded);
|
||||
if (!opcode.has_value()) {
|
||||
if (error != nullptr) {
|
||||
*error = fmt::format("decoded opcode has no IR lowering: {}",
|
||||
Decoder::OpcodeToString(decoded));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
lowered = *opcode;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LowerScalarMinMaxWithScc(const Decoder::Instruction& decoded, BasicBlock& block,
|
||||
std::string* error) {
|
||||
Instruction result;
|
||||
result.pc = decoded.pc;
|
||||
result.op = LookupIrOpcode(decoded.opcode);
|
||||
result.src_count = 2;
|
||||
if (!LowerRegisterOperand(decoded.dst, result.dst, error) ||
|
||||
if (!ResolveIrOpcode(decoded.opcode, result.op, error) ||
|
||||
!LowerRegisterOperand(decoded.dst, result.dst, error) ||
|
||||
!LowerSourceOperand(decoded.src0, result.src[0], error) ||
|
||||
!LowerSourceOperand(decoded.src1, result.src[1], error)) {
|
||||
return false;
|
||||
@@ -962,7 +975,12 @@ bool LowerControlInstruction(const Decoder::Instruction& decoded, BasicBlock& bl
|
||||
return LowerControlMarker(decoded, block, Opcode::TtraceData, true, error);
|
||||
case Decoder::Opcode::SInstPrefetch:
|
||||
return LowerControlMarker(decoded, block, Opcode::InstPrefetch, true, error);
|
||||
default: return false;
|
||||
default:
|
||||
if (error != nullptr) {
|
||||
*error = fmt::format("control opcode has no specialized IR lowering: {}",
|
||||
Decoder::OpcodeToString(decoded.opcode));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1051,6 +1069,18 @@ bool IsTerminatorOpcode(Decoder::Opcode opcode) {
|
||||
|
||||
bool LowerImplemented(const Decoder::Instruction& decoded, BasicBlock& block, std::string* error);
|
||||
|
||||
bool IsMemoryFamily(Decoder::Family family) {
|
||||
switch (family) {
|
||||
case Decoder::Family::SMEM:
|
||||
case Decoder::Family::MUBUF:
|
||||
case Decoder::Family::MTBUF:
|
||||
case Decoder::Family::FLAT:
|
||||
case Decoder::Family::DS:
|
||||
case Decoder::Family::MIMG: return true;
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool LowerDecodedInstruction(const Decoder::Instruction& inst, BasicBlock& block,
|
||||
std::string* error) {
|
||||
switch (inst.opcode) {
|
||||
@@ -1104,6 +1134,15 @@ bool LowerDecodedInstruction(const Decoder::Instruction& inst, BasicBlock& block
|
||||
if (IsMemoryOpcode(inst.opcode)) {
|
||||
return LowerMemoryInstruction(inst, block, error);
|
||||
}
|
||||
// Memory instructions require specialized lowering to populate MemoryInfo. Never let a
|
||||
// newly decoded memory-family opcode fall through to generic register-only IR.
|
||||
if (IsMemoryFamily(inst.family)) {
|
||||
if (error != nullptr) {
|
||||
*error = fmt::format("decoded memory-family opcode has no specialized IR lowering: {}",
|
||||
Decoder::OpcodeToString(inst.opcode));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (ScalarShiftLeftAddAmount(inst.opcode) != 0) {
|
||||
return LowerScalarShiftLeftAdd(inst, block, error);
|
||||
}
|
||||
@@ -1116,23 +1155,16 @@ bool LowerDecodedInstruction(const Decoder::Instruction& inst, BasicBlock& block
|
||||
if (VectorByteConvertIndex(inst.opcode) <= 3u) {
|
||||
return LowerVectorByteConvert(inst, block, error);
|
||||
}
|
||||
if (!IsImplemented(inst.opcode)) {
|
||||
if (error != nullptr) {
|
||||
*error = fmt::format("decoded opcode has no IR lowering yet: {}",
|
||||
Decoder::InstructionToString(inst).c_str());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return LowerImplemented(inst, block, error);
|
||||
}
|
||||
|
||||
bool LowerImplemented(const Decoder::Instruction& decoded, BasicBlock& block, std::string* error) {
|
||||
Instruction inst;
|
||||
inst.pc = decoded.pc;
|
||||
inst.op = LookupIrOpcode(decoded.opcode);
|
||||
inst.src_count = decoded.src_count;
|
||||
|
||||
if (!LowerRegisterOperand(decoded.dst, inst.dst, error)) {
|
||||
if (!ResolveIrOpcode(decoded.opcode, inst.op, error) ||
|
||||
!LowerRegisterOperand(decoded.dst, inst.dst, error)) {
|
||||
return false;
|
||||
}
|
||||
ApplyDppDestinationMask(decoded, inst.dst);
|
||||
|
||||
@@ -8,350 +8,48 @@
|
||||
#include "graphics/shader/shader.h"
|
||||
|
||||
#include <array>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
namespace Libs::Graphics::ShaderRecompiler::IR {
|
||||
|
||||
enum class Opcode {
|
||||
ControlNop,
|
||||
Waitcnt,
|
||||
Barrier,
|
||||
Sendmsg,
|
||||
TtraceData,
|
||||
InstPrefetch,
|
||||
MoveU32,
|
||||
MoveF32Bits,
|
||||
MoveRelDestU32,
|
||||
MoveRelSourceU32,
|
||||
MoveU64,
|
||||
WqmB64,
|
||||
SaveexecB32,
|
||||
SaveexecB64,
|
||||
ReadFirstLaneU32,
|
||||
ReadLaneU32,
|
||||
WriteLaneU32,
|
||||
Permlane16B32,
|
||||
Permlanex16B32,
|
||||
AbsI32,
|
||||
IAddU32,
|
||||
IAddCarryU32,
|
||||
ISubBorrowU32,
|
||||
ScalarAddCarryU32,
|
||||
ScalarSubBorrowU32,
|
||||
ScalarSubBorrowCarryU32,
|
||||
ScalarSignedAddOverflowI32,
|
||||
ScalarSignedSubOverflowI32,
|
||||
ScalarShiftLeftAddCarryU32,
|
||||
ISubU32,
|
||||
IMulU32,
|
||||
UMulHighU32,
|
||||
SMulHighI32,
|
||||
IMadI24U32,
|
||||
UMadU24U32,
|
||||
UMadU64U32,
|
||||
SadU32,
|
||||
IAdd3U32,
|
||||
IMulI24U32,
|
||||
UMulU24U32,
|
||||
IMinI32,
|
||||
IMaxI32,
|
||||
IMin3I32,
|
||||
IMax3I32,
|
||||
IMed3I32,
|
||||
UMinU32,
|
||||
UMaxU32,
|
||||
UMin3U32,
|
||||
UMax3U32,
|
||||
UMed3U32,
|
||||
BitwiseAndU32,
|
||||
BitwiseAndU64,
|
||||
BitwiseAndNotU32,
|
||||
BitwiseAndNotU64,
|
||||
BitwiseOrU32,
|
||||
BitwiseOrU64,
|
||||
BitwiseOrNotU32,
|
||||
BitwiseOrNotU64,
|
||||
BitwiseAndOrU32,
|
||||
BitwiseOr3U32,
|
||||
BitwiseXorU32,
|
||||
BitwiseXorU64,
|
||||
BitwiseXor3U32,
|
||||
BitwiseNandU32,
|
||||
BitwiseNandU64,
|
||||
BitwiseNorU32,
|
||||
BitwiseNorU64,
|
||||
BitwiseXnorU32,
|
||||
BitwiseXnorU64,
|
||||
BitwiseNotU32,
|
||||
BitwiseNotU64,
|
||||
BitClearU32,
|
||||
BitSetU32,
|
||||
BitReverseU32,
|
||||
BitCountU32,
|
||||
BitCountU64,
|
||||
BitReplicateB64B32,
|
||||
BitCountAddU32,
|
||||
MaskedBitCountLowU32,
|
||||
MaskedBitCountHighU32,
|
||||
FindLsbU32,
|
||||
FindMsbFromHighU32,
|
||||
FindMsbFromHighU64,
|
||||
BitFieldMaskU32,
|
||||
BitFieldMaskU64,
|
||||
BitFieldExtractU32,
|
||||
BitFieldExtractU64,
|
||||
BitFieldExtract3U32,
|
||||
BitFieldExtract3I32,
|
||||
BitFieldInsertSelectU32,
|
||||
BitCompare0B32,
|
||||
BitCompare1B32,
|
||||
AlignBitU32,
|
||||
ShiftLeftAddU32,
|
||||
AddShiftLeftU32,
|
||||
XorAddU32,
|
||||
ShiftLeftOrU32,
|
||||
ShiftLeftLogicalU32,
|
||||
ShiftLeftLogicalU64,
|
||||
ShiftLeftLogicalU16,
|
||||
ShiftRightLogicalU32,
|
||||
ShiftRightLogicalU64,
|
||||
ShiftRightLogicalU16,
|
||||
ShiftRightArithmeticI32,
|
||||
ShiftRightArithmeticI16,
|
||||
SelectU32,
|
||||
SelectMaskU32,
|
||||
SelectF32Bits,
|
||||
SelectMaskF32Bits,
|
||||
SelectU64,
|
||||
PackLowLowU16,
|
||||
PackLowHighU16,
|
||||
PackHighHighU16,
|
||||
CompareFalse,
|
||||
CompareTrue,
|
||||
CompareEqU32,
|
||||
CompareNeU32,
|
||||
CompareGtU32,
|
||||
CompareGeU32,
|
||||
CompareLtU32,
|
||||
CompareLeU32,
|
||||
CompareNeU64,
|
||||
CompareMaskEqU32,
|
||||
CompareMaskNeU32,
|
||||
CompareMaskGtU32,
|
||||
CompareMaskGeU32,
|
||||
CompareMaskLtU32,
|
||||
CompareMaskLeU32,
|
||||
CompareEqI32,
|
||||
CompareNeI32,
|
||||
CompareGtI32,
|
||||
CompareGeI32,
|
||||
CompareLtI32,
|
||||
CompareLeI32,
|
||||
CompareEqI16,
|
||||
CompareNeI16,
|
||||
CompareGtI16,
|
||||
CompareGeI16,
|
||||
CompareLtI16,
|
||||
CompareLeI16,
|
||||
CompareMaskEqI32,
|
||||
CompareMaskNeI32,
|
||||
CompareMaskGtI32,
|
||||
CompareMaskGeI32,
|
||||
CompareMaskLtI32,
|
||||
CompareMaskLeI32,
|
||||
CompareEqU16,
|
||||
CompareNeU16,
|
||||
CompareGtU16,
|
||||
CompareGeU16,
|
||||
CompareLtU16,
|
||||
CompareLeU16,
|
||||
CompareEqF32,
|
||||
CompareNeF32,
|
||||
CompareGtF32,
|
||||
CompareGeF32,
|
||||
CompareLtF32,
|
||||
CompareLeF32,
|
||||
CompareOrderedF32,
|
||||
CompareUnorderedF32,
|
||||
CompareUnordEqF32,
|
||||
CompareUnordNeF32,
|
||||
CompareUnordGtF32,
|
||||
CompareUnordGeF32,
|
||||
CompareUnordLtF32,
|
||||
CompareUnordLeF32,
|
||||
CompareClassF32,
|
||||
CompareEqF16,
|
||||
CompareNeF16,
|
||||
CompareGtF16,
|
||||
CompareGeF16,
|
||||
CompareLtF16,
|
||||
CompareLeF16,
|
||||
CompareUnordNeF16,
|
||||
CompareMaskEqF16,
|
||||
CompareMaskNeF16,
|
||||
CompareMaskGtF16,
|
||||
CompareMaskGeF16,
|
||||
CompareMaskLtF16,
|
||||
CompareMaskLeF16,
|
||||
CompareMaskUnordNeF16,
|
||||
CompareMaskUnordGeF16,
|
||||
CompareMaskEqF32,
|
||||
CompareMaskNeF32,
|
||||
CompareMaskGtF32,
|
||||
CompareMaskGeF32,
|
||||
CompareMaskLtF32,
|
||||
CompareMaskLeF32,
|
||||
CompareMaskUnordEqF32,
|
||||
CompareMaskUnordNeF32,
|
||||
CompareMaskUnordGtF32,
|
||||
CompareMaskUnordGeF32,
|
||||
CompareMaskUnordLtF32,
|
||||
CompareMaskUnordLeF32,
|
||||
ConvertByteU32ToF32,
|
||||
ConvertU32ToF32,
|
||||
ConvertI32ToF32,
|
||||
ConvertF32ToU32,
|
||||
ConvertF32ToI32,
|
||||
ConvertF32ToF16,
|
||||
ConvertF16ToF32,
|
||||
ConvertU16ToF16,
|
||||
ConvertF16ToU16,
|
||||
ConvertI16ToF16,
|
||||
ConvertF16ToI16,
|
||||
ConvertRoundPlusInfF32ToI32,
|
||||
ConvertFloorF32ToI32,
|
||||
ConvertI4ToOffsetF32,
|
||||
LdexpF32,
|
||||
PackF32ToF16Rtz,
|
||||
PackSnorm2x16F32,
|
||||
PackUnorm2x16F32,
|
||||
PackU16U32,
|
||||
PackU8F32,
|
||||
PackB32F16,
|
||||
PackedMadI16,
|
||||
PackedMulLoU16,
|
||||
PackedAddI16,
|
||||
PackedSubI16,
|
||||
PackedLshlrevB16,
|
||||
PackedLshrrevB16,
|
||||
PackedAshrrevI16,
|
||||
PackedMaxI16,
|
||||
PackedMinI16,
|
||||
PackedMadU16,
|
||||
PackedAddU16,
|
||||
PackedSubU16,
|
||||
PackedMaxU16,
|
||||
PackedMinU16,
|
||||
PackedAddF16,
|
||||
PackedMulF16,
|
||||
PackedMinF16,
|
||||
PackedMaxF16,
|
||||
PackedFmaF16,
|
||||
AddF16,
|
||||
SubF16,
|
||||
MulF16,
|
||||
MinF16,
|
||||
MaxF16,
|
||||
FmaF16,
|
||||
MadMixF16,
|
||||
IAddU16,
|
||||
ISubI16,
|
||||
IMinI16,
|
||||
IMaxI16,
|
||||
UMinU16,
|
||||
UMaxU16,
|
||||
RcpF32,
|
||||
FractF32,
|
||||
TruncF32,
|
||||
CeilF32,
|
||||
RoundEvenF32,
|
||||
FloorF32,
|
||||
Exp2F32,
|
||||
Log2F32,
|
||||
InverseSqrtF32,
|
||||
SqrtF32,
|
||||
RcpF16,
|
||||
SqrtF16,
|
||||
InverseSqrtF16,
|
||||
Log2F16,
|
||||
Exp2F16,
|
||||
FloorF16,
|
||||
CeilF16,
|
||||
TruncF16,
|
||||
RoundEvenF16,
|
||||
SinF32,
|
||||
CosF32,
|
||||
CubeIdF32,
|
||||
CubeScF32,
|
||||
CubeTcF32,
|
||||
CubeMaF32,
|
||||
FAddF32,
|
||||
FSubF32,
|
||||
FMulF32,
|
||||
FMinF32,
|
||||
FMaxF32,
|
||||
FMadF32,
|
||||
Dot2AccF32F16,
|
||||
FMin3F32,
|
||||
FMax3F32,
|
||||
FMed3F32,
|
||||
Min3F16,
|
||||
Max3F16,
|
||||
Med3F16,
|
||||
LoadSrtDword,
|
||||
SLoadDword,
|
||||
SBufferLoadDword,
|
||||
BufferLoadUbyte,
|
||||
BufferLoadSbyte,
|
||||
BufferLoadUshort,
|
||||
BufferLoadSshort,
|
||||
BufferLoadDword,
|
||||
BufferStoreByte,
|
||||
BufferStoreShort,
|
||||
BufferStoreDword,
|
||||
AtomicSwapU32,
|
||||
AtomicAddU32,
|
||||
AtomicSubU32,
|
||||
AtomicSMinI32,
|
||||
AtomicUMinU32,
|
||||
AtomicSMaxI32,
|
||||
AtomicUMaxU32,
|
||||
AtomicAndU32,
|
||||
AtomicOrU32,
|
||||
AtomicXorU32,
|
||||
FlatLoadUbyte,
|
||||
FlatLoadSbyte,
|
||||
FlatLoadUshort,
|
||||
FlatLoadSshort,
|
||||
FlatLoadDword,
|
||||
FlatStoreByte,
|
||||
FlatStoreShort,
|
||||
FlatStoreDword,
|
||||
DsReadUbyte,
|
||||
DsReadSbyte,
|
||||
DsReadUshort,
|
||||
DsReadSshort,
|
||||
DsReadB32,
|
||||
DsWriteByte,
|
||||
DsWriteShort,
|
||||
DsWriteB32,
|
||||
DsMinF32,
|
||||
DsMaxF32,
|
||||
DsSwizzleB32,
|
||||
DsConsume,
|
||||
DsAppend,
|
||||
DsWriteAddtidB32,
|
||||
DsReadAddtidB32,
|
||||
ImageGetResinfo,
|
||||
ImageGetLod,
|
||||
ImageLoad,
|
||||
ImageStore,
|
||||
ImageSample,
|
||||
ImageGather4,
|
||||
LoadInputF32,
|
||||
Export,
|
||||
#define IR_OPCODE(name, category) name,
|
||||
#include "graphics/shader/recompiler/ir/ShaderIROpcodes.inc"
|
||||
#undef IR_OPCODE
|
||||
Count,
|
||||
};
|
||||
|
||||
enum class OpcodeClass { General, Compare, Compare64 };
|
||||
|
||||
struct OpcodeInfo {
|
||||
std::string_view name;
|
||||
OpcodeClass opcode_class = OpcodeClass::General;
|
||||
};
|
||||
|
||||
inline constexpr OpcodeInfo OPCODE_INFO[] = {
|
||||
#define IR_OPCODE(name, category) {#name, OpcodeClass::category},
|
||||
#include "graphics/shader/recompiler/ir/ShaderIROpcodes.inc"
|
||||
#undef IR_OPCODE
|
||||
};
|
||||
static_assert(sizeof(OPCODE_INFO) / sizeof(OPCODE_INFO[0]) == static_cast<size_t>(Opcode::Count));
|
||||
|
||||
constexpr const OpcodeInfo& GetOpcodeInfo(Opcode opcode) {
|
||||
return OPCODE_INFO[static_cast<size_t>(opcode)];
|
||||
}
|
||||
|
||||
constexpr std::string_view OpcodeName(Opcode opcode) {
|
||||
return GetOpcodeInfo(opcode).name;
|
||||
}
|
||||
|
||||
constexpr bool IsCompareOpcode(Opcode opcode) {
|
||||
return GetOpcodeInfo(opcode).opcode_class != OpcodeClass::General;
|
||||
}
|
||||
|
||||
constexpr bool IsCompare64Opcode(Opcode opcode) {
|
||||
return GetOpcodeInfo(opcode).opcode_class == OpcodeClass::Compare64;
|
||||
}
|
||||
|
||||
enum class RegisterFile { Scalar, Vector, Vcc, Exec, Scc, M0 };
|
||||
|
||||
struct Register {
|
||||
|
||||
@@ -3,16 +3,17 @@
|
||||
|
||||
#include "graphics/shader/recompiler/ir/ShaderIR.h"
|
||||
|
||||
#include <optional>
|
||||
|
||||
namespace Libs::Graphics::ShaderRecompiler::IR {
|
||||
|
||||
void SetError(std::string* error, const char* message);
|
||||
|
||||
Opcode LookupIrOpcode(Decoder::Opcode opcode);
|
||||
bool IsImplemented(Decoder::Opcode opcode);
|
||||
bool IsReversedBinary(Decoder::Opcode opcode);
|
||||
bool IsVectorCarryOutOpcode(Decoder::Opcode opcode);
|
||||
bool ScalarResultWritesSccNonZero(Decoder::Opcode opcode);
|
||||
bool ScalarResultIs64Bit(Decoder::Opcode opcode);
|
||||
std::optional<Opcode> LookupIrOpcode(Decoder::Opcode opcode);
|
||||
bool IsReversedBinary(Decoder::Opcode opcode);
|
||||
bool IsVectorCarryOutOpcode(Decoder::Opcode opcode);
|
||||
bool ScalarResultWritesSccNonZero(Decoder::Opcode opcode);
|
||||
bool ScalarResultIs64Bit(Decoder::Opcode opcode);
|
||||
|
||||
Operand MakeSccOperand();
|
||||
Operand MakeImmediateU32(uint32_t value);
|
||||
|
||||
@@ -157,345 +157,7 @@ std::string InstructionToString(const Instruction& inst) {
|
||||
text += ExportInfoToString(inst.export_info);
|
||||
return text;
|
||||
}
|
||||
switch (inst.op) {
|
||||
case Opcode::ControlNop: text += "ControlNop"; break;
|
||||
case Opcode::Waitcnt: text += "Waitcnt"; break;
|
||||
case Opcode::Barrier: text += "Barrier"; break;
|
||||
case Opcode::Sendmsg: text += "Sendmsg"; break;
|
||||
case Opcode::TtraceData: text += "TtraceData"; break;
|
||||
case Opcode::InstPrefetch: text += "InstPrefetch"; break;
|
||||
case Opcode::MoveU32: text += "MoveU32"; break;
|
||||
case Opcode::MoveF32Bits: text += "MoveF32Bits"; break;
|
||||
case Opcode::MoveRelDestU32: text += "MoveRelDestU32"; break;
|
||||
case Opcode::MoveRelSourceU32: text += "MoveRelSourceU32"; break;
|
||||
case Opcode::MoveU64: text += "MoveU64"; break;
|
||||
case Opcode::WqmB64: text += "WqmB64"; break;
|
||||
case Opcode::SaveexecB32: text += "SaveexecB32"; break;
|
||||
case Opcode::SaveexecB64: text += "SaveexecB64"; break;
|
||||
case Opcode::ReadFirstLaneU32: text += "ReadFirstLaneU32"; break;
|
||||
case Opcode::ReadLaneU32: text += "ReadLaneU32"; break;
|
||||
case Opcode::WriteLaneU32: text += "WriteLaneU32"; break;
|
||||
case Opcode::Permlane16B32: text += "Permlane16B32"; break;
|
||||
case Opcode::Permlanex16B32: text += "Permlanex16B32"; break;
|
||||
case Opcode::AbsI32: text += "AbsI32"; break;
|
||||
case Opcode::IAddU32: text += "IAddU32"; break;
|
||||
case Opcode::IAddCarryU32: text += "IAddCarryU32"; break;
|
||||
case Opcode::ISubBorrowU32: text += "ISubBorrowU32"; break;
|
||||
case Opcode::ScalarAddCarryU32: text += "ScalarAddCarryU32"; break;
|
||||
case Opcode::ScalarSubBorrowU32: text += "ScalarSubBorrowU32"; break;
|
||||
case Opcode::ScalarSubBorrowCarryU32: text += "ScalarSubBorrowCarryU32"; break;
|
||||
case Opcode::ScalarSignedAddOverflowI32: text += "ScalarSignedAddOverflowI32"; break;
|
||||
case Opcode::ScalarSignedSubOverflowI32: text += "ScalarSignedSubOverflowI32"; break;
|
||||
case Opcode::ScalarShiftLeftAddCarryU32: text += "ScalarShiftLeftAddCarryU32"; break;
|
||||
case Opcode::ISubU32: text += "ISubU32"; break;
|
||||
case Opcode::IMulU32: text += "IMulU32"; break;
|
||||
case Opcode::UMulHighU32: text += "UMulHighU32"; break;
|
||||
case Opcode::SMulHighI32: text += "SMulHighI32"; break;
|
||||
case Opcode::IMadI24U32: text += "IMadI24U32"; break;
|
||||
case Opcode::UMadU24U32: text += "UMadU24U32"; break;
|
||||
case Opcode::UMadU64U32: text += "UMadU64U32"; break;
|
||||
case Opcode::SadU32: text += "SadU32"; break;
|
||||
case Opcode::IAdd3U32: text += "IAdd3U32"; break;
|
||||
case Opcode::IMulI24U32: text += "IMulI24U32"; break;
|
||||
case Opcode::UMulU24U32: text += "UMulU24U32"; break;
|
||||
case Opcode::IMinI32: text += "IMinI32"; break;
|
||||
case Opcode::IMaxI32: text += "IMaxI32"; break;
|
||||
case Opcode::IMin3I32: text += "IMin3I32"; break;
|
||||
case Opcode::IMax3I32: text += "IMax3I32"; break;
|
||||
case Opcode::IMed3I32: text += "IMed3I32"; break;
|
||||
case Opcode::UMinU32: text += "UMinU32"; break;
|
||||
case Opcode::UMaxU32: text += "UMaxU32"; break;
|
||||
case Opcode::UMin3U32: text += "UMin3U32"; break;
|
||||
case Opcode::UMax3U32: text += "UMax3U32"; break;
|
||||
case Opcode::UMed3U32: text += "UMed3U32"; break;
|
||||
case Opcode::BitwiseAndU32: text += "BitwiseAndU32"; break;
|
||||
case Opcode::BitwiseAndU64: text += "BitwiseAndU64"; break;
|
||||
case Opcode::BitwiseAndNotU32: text += "BitwiseAndNotU32"; break;
|
||||
case Opcode::BitwiseAndNotU64: text += "BitwiseAndNotU64"; break;
|
||||
case Opcode::BitwiseOrU32: text += "BitwiseOrU32"; break;
|
||||
case Opcode::BitwiseOrU64: text += "BitwiseOrU64"; break;
|
||||
case Opcode::BitwiseOrNotU32: text += "BitwiseOrNotU32"; break;
|
||||
case Opcode::BitwiseOrNotU64: text += "BitwiseOrNotU64"; break;
|
||||
case Opcode::BitwiseAndOrU32: text += "BitwiseAndOrU32"; break;
|
||||
case Opcode::BitwiseOr3U32: text += "BitwiseOr3U32"; break;
|
||||
case Opcode::BitwiseXorU32: text += "BitwiseXorU32"; break;
|
||||
case Opcode::BitwiseXorU64: text += "BitwiseXorU64"; break;
|
||||
case Opcode::BitwiseXor3U32: text += "BitwiseXor3U32"; break;
|
||||
case Opcode::BitwiseNandU32: text += "BitwiseNandU32"; break;
|
||||
case Opcode::BitwiseNandU64: text += "BitwiseNandU64"; break;
|
||||
case Opcode::BitwiseNorU32: text += "BitwiseNorU32"; break;
|
||||
case Opcode::BitwiseNorU64: text += "BitwiseNorU64"; break;
|
||||
case Opcode::BitwiseXnorU32: text += "BitwiseXnorU32"; break;
|
||||
case Opcode::BitwiseXnorU64: text += "BitwiseXnorU64"; break;
|
||||
case Opcode::BitwiseNotU32: text += "BitwiseNotU32"; break;
|
||||
case Opcode::BitwiseNotU64: text += "BitwiseNotU64"; break;
|
||||
case Opcode::BitClearU32: text += "BitClearU32"; break;
|
||||
case Opcode::BitSetU32: text += "BitSetU32"; break;
|
||||
case Opcode::BitReverseU32: text += "BitReverseU32"; break;
|
||||
case Opcode::BitCountU32: text += "BitCountU32"; break;
|
||||
case Opcode::BitCountU64: text += "BitCountU64"; break;
|
||||
case Opcode::BitReplicateB64B32: text += "BitReplicateB64B32"; break;
|
||||
case Opcode::BitCountAddU32: text += "BitCountAddU32"; break;
|
||||
case Opcode::MaskedBitCountLowU32: text += "MaskedBitCountLowU32"; break;
|
||||
case Opcode::MaskedBitCountHighU32: text += "MaskedBitCountHighU32"; break;
|
||||
case Opcode::FindLsbU32: text += "FindLsbU32"; break;
|
||||
case Opcode::FindMsbFromHighU32: text += "FindMsbFromHighU32"; break;
|
||||
case Opcode::FindMsbFromHighU64: text += "FindMsbFromHighU64"; break;
|
||||
case Opcode::BitFieldMaskU32: text += "BitFieldMaskU32"; break;
|
||||
case Opcode::BitFieldMaskU64: text += "BitFieldMaskU64"; break;
|
||||
case Opcode::BitFieldExtractU32: text += "BitFieldExtractU32"; break;
|
||||
case Opcode::BitFieldExtractU64: text += "BitFieldExtractU64"; break;
|
||||
case Opcode::BitFieldExtract3U32: text += "BitFieldExtract3U32"; break;
|
||||
case Opcode::BitFieldExtract3I32: text += "BitFieldExtract3I32"; break;
|
||||
case Opcode::BitFieldInsertSelectU32: text += "BitFieldInsertSelectU32"; break;
|
||||
case Opcode::BitCompare0B32: text += "BitCompare0B32"; break;
|
||||
case Opcode::BitCompare1B32: text += "BitCompare1B32"; break;
|
||||
case Opcode::AlignBitU32: text += "AlignBitU32"; break;
|
||||
case Opcode::ShiftLeftAddU32: text += "ShiftLeftAddU32"; break;
|
||||
case Opcode::AddShiftLeftU32: text += "AddShiftLeftU32"; break;
|
||||
case Opcode::XorAddU32: text += "XorAddU32"; break;
|
||||
case Opcode::ShiftLeftOrU32: text += "ShiftLeftOrU32"; break;
|
||||
case Opcode::ShiftLeftLogicalU32: text += "ShiftLeftLogicalU32"; break;
|
||||
case Opcode::ShiftLeftLogicalU64: text += "ShiftLeftLogicalU64"; break;
|
||||
case Opcode::ShiftLeftLogicalU16: text += "ShiftLeftLogicalU16"; break;
|
||||
case Opcode::ShiftRightLogicalU32: text += "ShiftRightLogicalU32"; break;
|
||||
case Opcode::ShiftRightLogicalU64: text += "ShiftRightLogicalU64"; break;
|
||||
case Opcode::ShiftRightLogicalU16: text += "ShiftRightLogicalU16"; break;
|
||||
case Opcode::ShiftRightArithmeticI32: text += "ShiftRightArithmeticI32"; break;
|
||||
case Opcode::ShiftRightArithmeticI16: text += "ShiftRightArithmeticI16"; break;
|
||||
case Opcode::SelectU32: text += "SelectU32"; break;
|
||||
case Opcode::SelectMaskU32: text += "SelectMaskU32"; break;
|
||||
case Opcode::SelectF32Bits: text += "SelectF32Bits"; break;
|
||||
case Opcode::SelectMaskF32Bits: text += "SelectMaskF32Bits"; break;
|
||||
case Opcode::SelectU64: text += "SelectU64"; break;
|
||||
case Opcode::PackLowLowU16: text += "PackLowLowU16"; break;
|
||||
case Opcode::PackLowHighU16: text += "PackLowHighU16"; break;
|
||||
case Opcode::PackHighHighU16: text += "PackHighHighU16"; break;
|
||||
case Opcode::CompareFalse: text += "CompareFalse"; break;
|
||||
case Opcode::CompareTrue: text += "CompareTrue"; break;
|
||||
case Opcode::CompareEqU32: text += "CompareEqU32"; break;
|
||||
case Opcode::CompareNeU32: text += "CompareNeU32"; break;
|
||||
case Opcode::CompareGtU32: text += "CompareGtU32"; break;
|
||||
case Opcode::CompareGeU32: text += "CompareGeU32"; break;
|
||||
case Opcode::CompareLtU32: text += "CompareLtU32"; break;
|
||||
case Opcode::CompareLeU32: text += "CompareLeU32"; break;
|
||||
case Opcode::CompareNeU64: text += "CompareNeU64"; break;
|
||||
case Opcode::CompareMaskEqU32: text += "CompareMaskEqU32"; break;
|
||||
case Opcode::CompareMaskNeU32: text += "CompareMaskNeU32"; break;
|
||||
case Opcode::CompareMaskGtU32: text += "CompareMaskGtU32"; break;
|
||||
case Opcode::CompareMaskGeU32: text += "CompareMaskGeU32"; break;
|
||||
case Opcode::CompareMaskLtU32: text += "CompareMaskLtU32"; break;
|
||||
case Opcode::CompareMaskLeU32: text += "CompareMaskLeU32"; break;
|
||||
case Opcode::CompareEqI32: text += "CompareEqI32"; break;
|
||||
case Opcode::CompareNeI32: text += "CompareNeI32"; break;
|
||||
case Opcode::CompareGtI32: text += "CompareGtI32"; break;
|
||||
case Opcode::CompareGeI32: text += "CompareGeI32"; break;
|
||||
case Opcode::CompareLtI32: text += "CompareLtI32"; break;
|
||||
case Opcode::CompareLeI32: text += "CompareLeI32"; break;
|
||||
case Opcode::CompareEqI16: text += "CompareEqI16"; break;
|
||||
case Opcode::CompareNeI16: text += "CompareNeI16"; break;
|
||||
case Opcode::CompareGtI16: text += "CompareGtI16"; break;
|
||||
case Opcode::CompareGeI16: text += "CompareGeI16"; break;
|
||||
case Opcode::CompareLtI16: text += "CompareLtI16"; break;
|
||||
case Opcode::CompareLeI16: text += "CompareLeI16"; break;
|
||||
case Opcode::CompareMaskEqI32: text += "CompareMaskEqI32"; break;
|
||||
case Opcode::CompareMaskNeI32: text += "CompareMaskNeI32"; break;
|
||||
case Opcode::CompareMaskGtI32: text += "CompareMaskGtI32"; break;
|
||||
case Opcode::CompareMaskGeI32: text += "CompareMaskGeI32"; break;
|
||||
case Opcode::CompareMaskLtI32: text += "CompareMaskLtI32"; break;
|
||||
case Opcode::CompareMaskLeI32: text += "CompareMaskLeI32"; break;
|
||||
case Opcode::CompareEqU16: text += "CompareEqU16"; break;
|
||||
case Opcode::CompareNeU16: text += "CompareNeU16"; break;
|
||||
case Opcode::CompareGtU16: text += "CompareGtU16"; break;
|
||||
case Opcode::CompareGeU16: text += "CompareGeU16"; break;
|
||||
case Opcode::CompareLtU16: text += "CompareLtU16"; break;
|
||||
case Opcode::CompareLeU16: text += "CompareLeU16"; break;
|
||||
case Opcode::CompareEqF32: text += "CompareEqF32"; break;
|
||||
case Opcode::CompareNeF32: text += "CompareNeF32"; break;
|
||||
case Opcode::CompareGtF32: text += "CompareGtF32"; break;
|
||||
case Opcode::CompareGeF32: text += "CompareGeF32"; break;
|
||||
case Opcode::CompareLtF32: text += "CompareLtF32"; break;
|
||||
case Opcode::CompareLeF32: text += "CompareLeF32"; break;
|
||||
case Opcode::CompareOrderedF32: text += "CompareOrderedF32"; break;
|
||||
case Opcode::CompareUnorderedF32: text += "CompareUnorderedF32"; break;
|
||||
case Opcode::CompareUnordEqF32: text += "CompareUnordEqF32"; break;
|
||||
case Opcode::CompareUnordNeF32: text += "CompareUnordNeF32"; break;
|
||||
case Opcode::CompareUnordGtF32: text += "CompareUnordGtF32"; break;
|
||||
case Opcode::CompareUnordGeF32: text += "CompareUnordGeF32"; break;
|
||||
case Opcode::CompareUnordLtF32: text += "CompareUnordLtF32"; break;
|
||||
case Opcode::CompareUnordLeF32: text += "CompareUnordLeF32"; break;
|
||||
case Opcode::CompareClassF32: text += "CompareClassF32"; break;
|
||||
case Opcode::CompareEqF16: text += "CompareEqF16"; break;
|
||||
case Opcode::CompareNeF16: text += "CompareNeF16"; break;
|
||||
case Opcode::CompareGtF16: text += "CompareGtF16"; break;
|
||||
case Opcode::CompareGeF16: text += "CompareGeF16"; break;
|
||||
case Opcode::CompareLtF16: text += "CompareLtF16"; break;
|
||||
case Opcode::CompareLeF16: text += "CompareLeF16"; break;
|
||||
case Opcode::CompareUnordNeF16: text += "CompareUnordNeF16"; break;
|
||||
case Opcode::CompareMaskEqF16: text += "CompareMaskEqF16"; break;
|
||||
case Opcode::CompareMaskNeF16: text += "CompareMaskNeF16"; break;
|
||||
case Opcode::CompareMaskGtF16: text += "CompareMaskGtF16"; break;
|
||||
case Opcode::CompareMaskGeF16: text += "CompareMaskGeF16"; break;
|
||||
case Opcode::CompareMaskLtF16: text += "CompareMaskLtF16"; break;
|
||||
case Opcode::CompareMaskLeF16: text += "CompareMaskLeF16"; break;
|
||||
case Opcode::CompareMaskUnordNeF16: text += "CompareMaskUnordNeF16"; break;
|
||||
case Opcode::CompareMaskUnordGeF16: text += "CompareMaskUnordGeF16"; break;
|
||||
case Opcode::CompareMaskEqF32: text += "CompareMaskEqF32"; break;
|
||||
case Opcode::CompareMaskNeF32: text += "CompareMaskNeF32"; break;
|
||||
case Opcode::CompareMaskGtF32: text += "CompareMaskGtF32"; break;
|
||||
case Opcode::CompareMaskGeF32: text += "CompareMaskGeF32"; break;
|
||||
case Opcode::CompareMaskLtF32: text += "CompareMaskLtF32"; break;
|
||||
case Opcode::CompareMaskLeF32: text += "CompareMaskLeF32"; break;
|
||||
case Opcode::CompareMaskUnordEqF32: text += "CompareMaskUnordEqF32"; break;
|
||||
case Opcode::CompareMaskUnordNeF32: text += "CompareMaskUnordNeF32"; break;
|
||||
case Opcode::CompareMaskUnordGtF32: text += "CompareMaskUnordGtF32"; break;
|
||||
case Opcode::CompareMaskUnordGeF32: text += "CompareMaskUnordGeF32"; break;
|
||||
case Opcode::CompareMaskUnordLtF32: text += "CompareMaskUnordLtF32"; break;
|
||||
case Opcode::CompareMaskUnordLeF32: text += "CompareMaskUnordLeF32"; break;
|
||||
case Opcode::ConvertByteU32ToF32: text += "ConvertByteU32ToF32"; break;
|
||||
case Opcode::ConvertU32ToF32: text += "ConvertU32ToF32"; break;
|
||||
case Opcode::ConvertI32ToF32: text += "ConvertI32ToF32"; break;
|
||||
case Opcode::ConvertF32ToU32: text += "ConvertF32ToU32"; break;
|
||||
case Opcode::ConvertF32ToI32: text += "ConvertF32ToI32"; break;
|
||||
case Opcode::ConvertF32ToF16: text += "ConvertF32ToF16"; break;
|
||||
case Opcode::ConvertF16ToF32: text += "ConvertF16ToF32"; break;
|
||||
case Opcode::ConvertU16ToF16: text += "ConvertU16ToF16"; break;
|
||||
case Opcode::ConvertF16ToU16: text += "ConvertF16ToU16"; break;
|
||||
case Opcode::ConvertI16ToF16: text += "ConvertI16ToF16"; break;
|
||||
case Opcode::ConvertF16ToI16: text += "ConvertF16ToI16"; break;
|
||||
case Opcode::ConvertRoundPlusInfF32ToI32: text += "ConvertRoundPlusInfF32ToI32"; break;
|
||||
case Opcode::ConvertFloorF32ToI32: text += "ConvertFloorF32ToI32"; break;
|
||||
case Opcode::ConvertI4ToOffsetF32: text += "ConvertI4ToOffsetF32"; break;
|
||||
case Opcode::LdexpF32: text += "LdexpF32"; break;
|
||||
case Opcode::PackF32ToF16Rtz: text += "PackF32ToF16Rtz"; break;
|
||||
case Opcode::PackSnorm2x16F32: text += "PackSnorm2x16F32"; break;
|
||||
case Opcode::PackUnorm2x16F32: text += "PackUnorm2x16F32"; break;
|
||||
case Opcode::PackU16U32: text += "PackU16U32"; break;
|
||||
case Opcode::PackU8F32: text += "PackU8F32"; break;
|
||||
case Opcode::PackB32F16: text += "PackB32F16"; break;
|
||||
case Opcode::PackedMadI16: text += "PackedMadI16"; break;
|
||||
case Opcode::PackedMulLoU16: text += "PackedMulLoU16"; break;
|
||||
case Opcode::PackedAddI16: text += "PackedAddI16"; break;
|
||||
case Opcode::PackedSubI16: text += "PackedSubI16"; break;
|
||||
case Opcode::PackedLshlrevB16: text += "PackedLshlrevB16"; break;
|
||||
case Opcode::PackedLshrrevB16: text += "PackedLshrrevB16"; break;
|
||||
case Opcode::PackedAshrrevI16: text += "PackedAshrrevI16"; break;
|
||||
case Opcode::PackedMaxI16: text += "PackedMaxI16"; break;
|
||||
case Opcode::PackedMinI16: text += "PackedMinI16"; break;
|
||||
case Opcode::PackedMadU16: text += "PackedMadU16"; break;
|
||||
case Opcode::PackedAddU16: text += "PackedAddU16"; break;
|
||||
case Opcode::PackedSubU16: text += "PackedSubU16"; break;
|
||||
case Opcode::PackedMaxU16: text += "PackedMaxU16"; break;
|
||||
case Opcode::PackedMinU16: text += "PackedMinU16"; break;
|
||||
case Opcode::PackedAddF16: text += "PackedAddF16"; break;
|
||||
case Opcode::PackedMulF16: text += "PackedMulF16"; break;
|
||||
case Opcode::PackedMinF16: text += "PackedMinF16"; break;
|
||||
case Opcode::PackedMaxF16: text += "PackedMaxF16"; break;
|
||||
case Opcode::PackedFmaF16: text += "PackedFmaF16"; break;
|
||||
case Opcode::AddF16: text += "AddF16"; break;
|
||||
case Opcode::SubF16: text += "SubF16"; break;
|
||||
case Opcode::MulF16: text += "MulF16"; break;
|
||||
case Opcode::MinF16: text += "MinF16"; break;
|
||||
case Opcode::MaxF16: text += "MaxF16"; break;
|
||||
case Opcode::FmaF16: text += "FmaF16"; break;
|
||||
case Opcode::MadMixF16: text += "MadMixF16"; break;
|
||||
case Opcode::IAddU16: text += "IAddU16"; break;
|
||||
case Opcode::ISubI16: text += "ISubI16"; break;
|
||||
case Opcode::IMinI16: text += "IMinI16"; break;
|
||||
case Opcode::IMaxI16: text += "IMaxI16"; break;
|
||||
case Opcode::UMinU16: text += "UMinU16"; break;
|
||||
case Opcode::UMaxU16: text += "UMaxU16"; break;
|
||||
case Opcode::RcpF32: text += "RcpF32"; break;
|
||||
case Opcode::FractF32: text += "FractF32"; break;
|
||||
case Opcode::TruncF32: text += "TruncF32"; break;
|
||||
case Opcode::CeilF32: text += "CeilF32"; break;
|
||||
case Opcode::RoundEvenF32: text += "RoundEvenF32"; break;
|
||||
case Opcode::FloorF32: text += "FloorF32"; break;
|
||||
case Opcode::Exp2F32: text += "Exp2F32"; break;
|
||||
case Opcode::Log2F32: text += "Log2F32"; break;
|
||||
case Opcode::InverseSqrtF32: text += "InverseSqrtF32"; break;
|
||||
case Opcode::SqrtF32: text += "SqrtF32"; break;
|
||||
case Opcode::RcpF16: text += "RcpF16"; break;
|
||||
case Opcode::SqrtF16: text += "SqrtF16"; break;
|
||||
case Opcode::InverseSqrtF16: text += "InverseSqrtF16"; break;
|
||||
case Opcode::Log2F16: text += "Log2F16"; break;
|
||||
case Opcode::Exp2F16: text += "Exp2F16"; break;
|
||||
case Opcode::FloorF16: text += "FloorF16"; break;
|
||||
case Opcode::CeilF16: text += "CeilF16"; break;
|
||||
case Opcode::TruncF16: text += "TruncF16"; break;
|
||||
case Opcode::RoundEvenF16: text += "RoundEvenF16"; break;
|
||||
case Opcode::SinF32: text += "SinF32"; break;
|
||||
case Opcode::CosF32: text += "CosF32"; break;
|
||||
case Opcode::CubeIdF32: text += "CubeIdF32"; break;
|
||||
case Opcode::CubeScF32: text += "CubeScF32"; break;
|
||||
case Opcode::CubeTcF32: text += "CubeTcF32"; break;
|
||||
case Opcode::CubeMaF32: text += "CubeMaF32"; break;
|
||||
case Opcode::FAddF32: text += "FAddF32"; break;
|
||||
case Opcode::FSubF32: text += "FSubF32"; break;
|
||||
case Opcode::FMulF32: text += "FMulF32"; break;
|
||||
case Opcode::FMinF32: text += "FMinF32"; break;
|
||||
case Opcode::FMaxF32: text += "FMaxF32"; break;
|
||||
case Opcode::FMadF32: text += "FMadF32"; break;
|
||||
case Opcode::Dot2AccF32F16: text += "Dot2AccF32F16"; break;
|
||||
case Opcode::FMin3F32: text += "FMin3F32"; break;
|
||||
case Opcode::FMax3F32: text += "FMax3F32"; break;
|
||||
case Opcode::FMed3F32: text += "FMed3F32"; break;
|
||||
case Opcode::Min3F16: text += "Min3F16"; break;
|
||||
case Opcode::Max3F16: text += "Max3F16"; break;
|
||||
case Opcode::Med3F16: text += "Med3F16"; break;
|
||||
case Opcode::LoadSrtDword: text += "LoadSrtDword"; break;
|
||||
case Opcode::SLoadDword: text += "SLoadDword"; break;
|
||||
case Opcode::SBufferLoadDword: text += "SBufferLoadDword"; break;
|
||||
case Opcode::BufferLoadUbyte: text += "BufferLoadUbyte"; break;
|
||||
case Opcode::BufferLoadSbyte: text += "BufferLoadSbyte"; break;
|
||||
case Opcode::BufferLoadUshort: text += "BufferLoadUshort"; break;
|
||||
case Opcode::BufferLoadSshort: text += "BufferLoadSshort"; break;
|
||||
case Opcode::BufferLoadDword: text += "BufferLoadDword"; break;
|
||||
case Opcode::BufferStoreByte: text += "BufferStoreByte"; break;
|
||||
case Opcode::BufferStoreShort: text += "BufferStoreShort"; break;
|
||||
case Opcode::BufferStoreDword: text += "BufferStoreDword"; break;
|
||||
case Opcode::AtomicSwapU32: text += "AtomicSwapU32"; break;
|
||||
case Opcode::AtomicAddU32: text += "AtomicAddU32"; break;
|
||||
case Opcode::AtomicSubU32: text += "AtomicSubU32"; break;
|
||||
case Opcode::AtomicSMinI32: text += "AtomicSMinI32"; break;
|
||||
case Opcode::AtomicUMinU32: text += "AtomicUMinU32"; break;
|
||||
case Opcode::AtomicSMaxI32: text += "AtomicSMaxI32"; break;
|
||||
case Opcode::AtomicUMaxU32: text += "AtomicUMaxU32"; break;
|
||||
case Opcode::AtomicAndU32: text += "AtomicAndU32"; break;
|
||||
case Opcode::AtomicOrU32: text += "AtomicOrU32"; break;
|
||||
case Opcode::AtomicXorU32: text += "AtomicXorU32"; break;
|
||||
case Opcode::FlatLoadUbyte: text += "FlatLoadUbyte"; break;
|
||||
case Opcode::FlatLoadSbyte: text += "FlatLoadSbyte"; break;
|
||||
case Opcode::FlatLoadUshort: text += "FlatLoadUshort"; break;
|
||||
case Opcode::FlatLoadSshort: text += "FlatLoadSshort"; break;
|
||||
case Opcode::FlatLoadDword: text += "FlatLoadDword"; break;
|
||||
case Opcode::FlatStoreByte: text += "FlatStoreByte"; break;
|
||||
case Opcode::FlatStoreShort: text += "FlatStoreShort"; break;
|
||||
case Opcode::FlatStoreDword: text += "FlatStoreDword"; break;
|
||||
case Opcode::DsReadUbyte: text += "DsReadUbyte"; break;
|
||||
case Opcode::DsReadSbyte: text += "DsReadSbyte"; break;
|
||||
case Opcode::DsReadUshort: text += "DsReadUshort"; break;
|
||||
case Opcode::DsReadSshort: text += "DsReadSshort"; break;
|
||||
case Opcode::DsReadB32: text += "DsReadB32"; break;
|
||||
case Opcode::DsWriteByte: text += "DsWriteByte"; break;
|
||||
case Opcode::DsWriteShort: text += "DsWriteShort"; break;
|
||||
case Opcode::DsWriteB32: text += "DsWriteB32"; break;
|
||||
case Opcode::DsMinF32: text += "DsMinF32"; break;
|
||||
case Opcode::DsMaxF32: text += "DsMaxF32"; break;
|
||||
case Opcode::DsSwizzleB32: text += "DsSwizzleB32"; break;
|
||||
case Opcode::DsConsume: text += "DsConsume"; break;
|
||||
case Opcode::DsAppend: text += "DsAppend"; break;
|
||||
case Opcode::DsWriteAddtidB32: text += "DsWriteAddtidB32"; break;
|
||||
case Opcode::DsReadAddtidB32: text += "DsReadAddtidB32"; break;
|
||||
case Opcode::ImageGetResinfo: text += "ImageGetResinfo"; break;
|
||||
case Opcode::ImageGetLod: text += "ImageGetLod"; break;
|
||||
case Opcode::ImageLoad: text += "ImageLoad"; break;
|
||||
case Opcode::ImageStore: text += "ImageStore"; break;
|
||||
case Opcode::ImageSample: text += "ImageSample"; break;
|
||||
case Opcode::ImageGather4: text += "ImageGather4"; break;
|
||||
case Opcode::LoadInputF32: text += "LoadInputF32"; break;
|
||||
case Opcode::Export: text += "Export"; break;
|
||||
}
|
||||
text += OpcodeName(inst.op);
|
||||
text += " ";
|
||||
text += OperandToString(inst.dst);
|
||||
if (inst.dst2.kind != OperandKind::Null) {
|
||||
|
||||
@@ -569,6 +569,10 @@ bool LowerMemoryInstruction(const Decoder::Instruction& decoded, BasicBlock& blo
|
||||
return LowerBufferAtomicDword(decoded, block, Opcode::AtomicOrU32, error);
|
||||
case Decoder::Opcode::BufferAtomicXor:
|
||||
return LowerBufferAtomicDword(decoded, block, Opcode::AtomicXorU32, error);
|
||||
case Decoder::Opcode::BufferAtomicFMin:
|
||||
return LowerBufferAtomicDword(decoded, block, Opcode::AtomicFMinF32, error);
|
||||
case Decoder::Opcode::BufferAtomicFMax:
|
||||
return LowerBufferAtomicDword(decoded, block, Opcode::AtomicFMaxF32, error);
|
||||
case Decoder::Opcode::FlatLoadUbyte:
|
||||
case Decoder::Opcode::FlatLoadSbyte:
|
||||
case Decoder::Opcode::FlatLoadUshort:
|
||||
@@ -673,7 +677,12 @@ bool LowerMemoryInstruction(const Decoder::Instruction& decoded, BasicBlock& blo
|
||||
case Decoder::Opcode::ImageAtomicAnd:
|
||||
case Decoder::Opcode::ImageAtomicOr:
|
||||
case Decoder::Opcode::ImageAtomicXor: return LowerImageAtomicU32(decoded, block, error);
|
||||
default: return false;
|
||||
default:
|
||||
if (error != nullptr) {
|
||||
*error = fmt::format("memory opcode has no specialized IR lowering: {}",
|
||||
Decoder::OpcodeToString(decoded.opcode));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -729,6 +738,8 @@ bool IsMemoryOpcode(Decoder::Opcode opcode) {
|
||||
case Decoder::Opcode::BufferAtomicAnd:
|
||||
case Decoder::Opcode::BufferAtomicOr:
|
||||
case Decoder::Opcode::BufferAtomicXor:
|
||||
case Decoder::Opcode::BufferAtomicFMin:
|
||||
case Decoder::Opcode::BufferAtomicFMax:
|
||||
case Decoder::Opcode::FlatLoadUbyte:
|
||||
case Decoder::Opcode::FlatLoadSbyte:
|
||||
case Decoder::Opcode::FlatLoadUshort:
|
||||
|
||||
@@ -82,6 +82,7 @@ constexpr LowerMap LOWER_OPS[] = {
|
||||
{Decoder::Opcode::SCmpGeU32, Opcode::CompareGeU32},
|
||||
{Decoder::Opcode::SCmpLtU32, Opcode::CompareLtU32},
|
||||
{Decoder::Opcode::SCmpLeU32, Opcode::CompareLeU32},
|
||||
{Decoder::Opcode::SCmpEqU64, Opcode::CompareEqU64},
|
||||
{Decoder::Opcode::SCmpLgU64, Opcode::CompareNeU64},
|
||||
{Decoder::Opcode::VReadfirstlaneB32, Opcode::ReadFirstLaneU32},
|
||||
{Decoder::Opcode::VReadlaneB32, Opcode::ReadLaneU32},
|
||||
@@ -325,6 +326,7 @@ constexpr LowerMap LOWER_OPS[] = {
|
||||
{Decoder::Opcode::VCmpNeU32, Opcode::CompareNeU32},
|
||||
{Decoder::Opcode::VCmpGeU32, Opcode::CompareGeU32},
|
||||
{Decoder::Opcode::VCmpTU32, Opcode::CompareTrue},
|
||||
{Decoder::Opcode::VCmpEqI64, Opcode::CompareEqU64},
|
||||
{Decoder::Opcode::VCmpNeU64, Opcode::CompareNeU64},
|
||||
{Decoder::Opcode::VCmpxLtU32, Opcode::CompareMaskLtU32},
|
||||
{Decoder::Opcode::VCmpxEqU32, Opcode::CompareMaskEqU32},
|
||||
@@ -350,6 +352,8 @@ constexpr LowerMap LOWER_OPS[] = {
|
||||
{Decoder::Opcode::BufferAtomicAnd, Opcode::AtomicAndU32},
|
||||
{Decoder::Opcode::BufferAtomicOr, Opcode::AtomicOrU32},
|
||||
{Decoder::Opcode::BufferAtomicXor, Opcode::AtomicXorU32},
|
||||
{Decoder::Opcode::BufferAtomicFMin, Opcode::AtomicFMinF32},
|
||||
{Decoder::Opcode::BufferAtomicFMax, Opcode::AtomicFMaxF32},
|
||||
{Decoder::Opcode::FlatLoadUbyte, Opcode::FlatLoadUbyte},
|
||||
{Decoder::Opcode::FlatLoadSbyte, Opcode::FlatLoadSbyte},
|
||||
{Decoder::Opcode::FlatLoadSshort, Opcode::FlatLoadSshort},
|
||||
@@ -432,22 +436,13 @@ void SetError(std::string* error, const char* message) {
|
||||
}
|
||||
}
|
||||
|
||||
Opcode LookupIrOpcode(Decoder::Opcode opcode) {
|
||||
std::optional<Opcode> LookupIrOpcode(Decoder::Opcode opcode) {
|
||||
for (const auto& op: LOWER_OPS) {
|
||||
if (op.decoded == opcode) {
|
||||
return op.ir;
|
||||
}
|
||||
}
|
||||
return Opcode::MoveU32;
|
||||
}
|
||||
|
||||
bool IsImplemented(Decoder::Opcode opcode) {
|
||||
for (const auto& op: LOWER_OPS) {
|
||||
if (op.decoded == opcode) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
bool IsReversedBinary(Decoder::Opcode opcode) {
|
||||
|
||||
@@ -0,0 +1,342 @@
|
||||
// Central IR opcode catalog. Keep semantic categories here so enum identity, logging,
|
||||
// and generic analysis cannot drift apart.
|
||||
IR_OPCODE(ControlNop, General)
|
||||
IR_OPCODE(Waitcnt, General)
|
||||
IR_OPCODE(Barrier, General)
|
||||
IR_OPCODE(Sendmsg, General)
|
||||
IR_OPCODE(TtraceData, General)
|
||||
IR_OPCODE(InstPrefetch, General)
|
||||
IR_OPCODE(MoveU32, General)
|
||||
IR_OPCODE(MoveF32Bits, General)
|
||||
IR_OPCODE(MoveRelDestU32, General)
|
||||
IR_OPCODE(MoveRelSourceU32, General)
|
||||
IR_OPCODE(MoveU64, General)
|
||||
IR_OPCODE(WqmB64, General)
|
||||
IR_OPCODE(SaveexecB32, General)
|
||||
IR_OPCODE(SaveexecB64, General)
|
||||
IR_OPCODE(ReadFirstLaneU32, General)
|
||||
IR_OPCODE(ReadLaneU32, General)
|
||||
IR_OPCODE(WriteLaneU32, General)
|
||||
IR_OPCODE(Permlane16B32, General)
|
||||
IR_OPCODE(Permlanex16B32, General)
|
||||
IR_OPCODE(AbsI32, General)
|
||||
IR_OPCODE(IAddU32, General)
|
||||
IR_OPCODE(IAddCarryU32, General)
|
||||
IR_OPCODE(ISubBorrowU32, General)
|
||||
IR_OPCODE(ScalarAddCarryU32, General)
|
||||
IR_OPCODE(ScalarSubBorrowU32, General)
|
||||
IR_OPCODE(ScalarSubBorrowCarryU32, General)
|
||||
IR_OPCODE(ScalarSignedAddOverflowI32, General)
|
||||
IR_OPCODE(ScalarSignedSubOverflowI32, General)
|
||||
IR_OPCODE(ScalarShiftLeftAddCarryU32, General)
|
||||
IR_OPCODE(ISubU32, General)
|
||||
IR_OPCODE(IMulU32, General)
|
||||
IR_OPCODE(UMulHighU32, General)
|
||||
IR_OPCODE(SMulHighI32, General)
|
||||
IR_OPCODE(IMadI24U32, General)
|
||||
IR_OPCODE(UMadU24U32, General)
|
||||
IR_OPCODE(UMadU64U32, General)
|
||||
IR_OPCODE(SadU32, General)
|
||||
IR_OPCODE(IAdd3U32, General)
|
||||
IR_OPCODE(IMulI24U32, General)
|
||||
IR_OPCODE(UMulU24U32, General)
|
||||
IR_OPCODE(IMinI32, General)
|
||||
IR_OPCODE(IMaxI32, General)
|
||||
IR_OPCODE(IMin3I32, General)
|
||||
IR_OPCODE(IMax3I32, General)
|
||||
IR_OPCODE(IMed3I32, General)
|
||||
IR_OPCODE(UMinU32, General)
|
||||
IR_OPCODE(UMaxU32, General)
|
||||
IR_OPCODE(UMin3U32, General)
|
||||
IR_OPCODE(UMax3U32, General)
|
||||
IR_OPCODE(UMed3U32, General)
|
||||
IR_OPCODE(BitwiseAndU32, General)
|
||||
IR_OPCODE(BitwiseAndU64, General)
|
||||
IR_OPCODE(BitwiseAndNotU32, General)
|
||||
IR_OPCODE(BitwiseAndNotU64, General)
|
||||
IR_OPCODE(BitwiseOrU32, General)
|
||||
IR_OPCODE(BitwiseOrU64, General)
|
||||
IR_OPCODE(BitwiseOrNotU32, General)
|
||||
IR_OPCODE(BitwiseOrNotU64, General)
|
||||
IR_OPCODE(BitwiseAndOrU32, General)
|
||||
IR_OPCODE(BitwiseOr3U32, General)
|
||||
IR_OPCODE(BitwiseXorU32, General)
|
||||
IR_OPCODE(BitwiseXorU64, General)
|
||||
IR_OPCODE(BitwiseXor3U32, General)
|
||||
IR_OPCODE(BitwiseNandU32, General)
|
||||
IR_OPCODE(BitwiseNandU64, General)
|
||||
IR_OPCODE(BitwiseNorU32, General)
|
||||
IR_OPCODE(BitwiseNorU64, General)
|
||||
IR_OPCODE(BitwiseXnorU32, General)
|
||||
IR_OPCODE(BitwiseXnorU64, General)
|
||||
IR_OPCODE(BitwiseNotU32, General)
|
||||
IR_OPCODE(BitwiseNotU64, General)
|
||||
IR_OPCODE(BitClearU32, General)
|
||||
IR_OPCODE(BitSetU32, General)
|
||||
IR_OPCODE(BitReverseU32, General)
|
||||
IR_OPCODE(BitCountU32, General)
|
||||
IR_OPCODE(BitCountU64, General)
|
||||
IR_OPCODE(BitReplicateB64B32, General)
|
||||
IR_OPCODE(BitCountAddU32, General)
|
||||
IR_OPCODE(MaskedBitCountLowU32, General)
|
||||
IR_OPCODE(MaskedBitCountHighU32, General)
|
||||
IR_OPCODE(FindLsbU32, General)
|
||||
IR_OPCODE(FindMsbFromHighU32, General)
|
||||
IR_OPCODE(FindMsbFromHighU64, General)
|
||||
IR_OPCODE(BitFieldMaskU32, General)
|
||||
IR_OPCODE(BitFieldMaskU64, General)
|
||||
IR_OPCODE(BitFieldExtractU32, General)
|
||||
IR_OPCODE(BitFieldExtractU64, General)
|
||||
IR_OPCODE(BitFieldExtract3U32, General)
|
||||
IR_OPCODE(BitFieldExtract3I32, General)
|
||||
IR_OPCODE(BitFieldInsertSelectU32, General)
|
||||
IR_OPCODE(BitCompare0B32, General)
|
||||
IR_OPCODE(BitCompare1B32, General)
|
||||
IR_OPCODE(AlignBitU32, General)
|
||||
IR_OPCODE(ShiftLeftAddU32, General)
|
||||
IR_OPCODE(AddShiftLeftU32, General)
|
||||
IR_OPCODE(XorAddU32, General)
|
||||
IR_OPCODE(ShiftLeftOrU32, General)
|
||||
IR_OPCODE(ShiftLeftLogicalU32, General)
|
||||
IR_OPCODE(ShiftLeftLogicalU64, General)
|
||||
IR_OPCODE(ShiftLeftLogicalU16, General)
|
||||
IR_OPCODE(ShiftRightLogicalU32, General)
|
||||
IR_OPCODE(ShiftRightLogicalU64, General)
|
||||
IR_OPCODE(ShiftRightLogicalU16, General)
|
||||
IR_OPCODE(ShiftRightArithmeticI32, General)
|
||||
IR_OPCODE(ShiftRightArithmeticI16, General)
|
||||
IR_OPCODE(SelectU32, General)
|
||||
IR_OPCODE(SelectMaskU32, General)
|
||||
IR_OPCODE(SelectF32Bits, General)
|
||||
IR_OPCODE(SelectMaskF32Bits, General)
|
||||
IR_OPCODE(SelectU64, General)
|
||||
IR_OPCODE(PackLowLowU16, General)
|
||||
IR_OPCODE(PackLowHighU16, General)
|
||||
IR_OPCODE(PackHighHighU16, General)
|
||||
IR_OPCODE(CompareFalse, Compare)
|
||||
IR_OPCODE(CompareTrue, Compare)
|
||||
IR_OPCODE(CompareEqU32, Compare)
|
||||
IR_OPCODE(CompareNeU32, Compare)
|
||||
IR_OPCODE(CompareGtU32, Compare)
|
||||
IR_OPCODE(CompareGeU32, Compare)
|
||||
IR_OPCODE(CompareLtU32, Compare)
|
||||
IR_OPCODE(CompareLeU32, Compare)
|
||||
IR_OPCODE(CompareEqU64, Compare64)
|
||||
IR_OPCODE(CompareNeU64, Compare64)
|
||||
IR_OPCODE(CompareMaskEqU32, Compare)
|
||||
IR_OPCODE(CompareMaskNeU32, Compare)
|
||||
IR_OPCODE(CompareMaskGtU32, Compare)
|
||||
IR_OPCODE(CompareMaskGeU32, Compare)
|
||||
IR_OPCODE(CompareMaskLtU32, Compare)
|
||||
IR_OPCODE(CompareMaskLeU32, Compare)
|
||||
IR_OPCODE(CompareEqI32, Compare)
|
||||
IR_OPCODE(CompareNeI32, Compare)
|
||||
IR_OPCODE(CompareGtI32, Compare)
|
||||
IR_OPCODE(CompareGeI32, Compare)
|
||||
IR_OPCODE(CompareLtI32, Compare)
|
||||
IR_OPCODE(CompareLeI32, Compare)
|
||||
IR_OPCODE(CompareEqI16, Compare)
|
||||
IR_OPCODE(CompareNeI16, Compare)
|
||||
IR_OPCODE(CompareGtI16, Compare)
|
||||
IR_OPCODE(CompareGeI16, Compare)
|
||||
IR_OPCODE(CompareLtI16, Compare)
|
||||
IR_OPCODE(CompareLeI16, Compare)
|
||||
IR_OPCODE(CompareMaskEqI32, Compare)
|
||||
IR_OPCODE(CompareMaskNeI32, Compare)
|
||||
IR_OPCODE(CompareMaskGtI32, Compare)
|
||||
IR_OPCODE(CompareMaskGeI32, Compare)
|
||||
IR_OPCODE(CompareMaskLtI32, Compare)
|
||||
IR_OPCODE(CompareMaskLeI32, Compare)
|
||||
IR_OPCODE(CompareEqU16, Compare)
|
||||
IR_OPCODE(CompareNeU16, Compare)
|
||||
IR_OPCODE(CompareGtU16, Compare)
|
||||
IR_OPCODE(CompareGeU16, Compare)
|
||||
IR_OPCODE(CompareLtU16, Compare)
|
||||
IR_OPCODE(CompareLeU16, Compare)
|
||||
IR_OPCODE(CompareEqF32, Compare)
|
||||
IR_OPCODE(CompareNeF32, Compare)
|
||||
IR_OPCODE(CompareGtF32, Compare)
|
||||
IR_OPCODE(CompareGeF32, Compare)
|
||||
IR_OPCODE(CompareLtF32, Compare)
|
||||
IR_OPCODE(CompareLeF32, Compare)
|
||||
IR_OPCODE(CompareOrderedF32, Compare)
|
||||
IR_OPCODE(CompareUnorderedF32, Compare)
|
||||
IR_OPCODE(CompareUnordEqF32, Compare)
|
||||
IR_OPCODE(CompareUnordNeF32, Compare)
|
||||
IR_OPCODE(CompareUnordGtF32, Compare)
|
||||
IR_OPCODE(CompareUnordGeF32, Compare)
|
||||
IR_OPCODE(CompareUnordLtF32, Compare)
|
||||
IR_OPCODE(CompareUnordLeF32, Compare)
|
||||
IR_OPCODE(CompareClassF32, Compare)
|
||||
IR_OPCODE(CompareEqF16, Compare)
|
||||
IR_OPCODE(CompareNeF16, Compare)
|
||||
IR_OPCODE(CompareGtF16, Compare)
|
||||
IR_OPCODE(CompareGeF16, Compare)
|
||||
IR_OPCODE(CompareLtF16, Compare)
|
||||
IR_OPCODE(CompareLeF16, Compare)
|
||||
IR_OPCODE(CompareUnordNeF16, Compare)
|
||||
IR_OPCODE(CompareMaskEqF16, Compare)
|
||||
IR_OPCODE(CompareMaskNeF16, Compare)
|
||||
IR_OPCODE(CompareMaskGtF16, Compare)
|
||||
IR_OPCODE(CompareMaskGeF16, Compare)
|
||||
IR_OPCODE(CompareMaskLtF16, Compare)
|
||||
IR_OPCODE(CompareMaskLeF16, Compare)
|
||||
IR_OPCODE(CompareMaskUnordNeF16, Compare)
|
||||
IR_OPCODE(CompareMaskUnordGeF16, Compare)
|
||||
IR_OPCODE(CompareMaskEqF32, Compare)
|
||||
IR_OPCODE(CompareMaskNeF32, Compare)
|
||||
IR_OPCODE(CompareMaskGtF32, Compare)
|
||||
IR_OPCODE(CompareMaskGeF32, Compare)
|
||||
IR_OPCODE(CompareMaskLtF32, Compare)
|
||||
IR_OPCODE(CompareMaskLeF32, Compare)
|
||||
IR_OPCODE(CompareMaskUnordEqF32, Compare)
|
||||
IR_OPCODE(CompareMaskUnordNeF32, Compare)
|
||||
IR_OPCODE(CompareMaskUnordGtF32, Compare)
|
||||
IR_OPCODE(CompareMaskUnordGeF32, Compare)
|
||||
IR_OPCODE(CompareMaskUnordLtF32, Compare)
|
||||
IR_OPCODE(CompareMaskUnordLeF32, Compare)
|
||||
IR_OPCODE(ConvertByteU32ToF32, General)
|
||||
IR_OPCODE(ConvertU32ToF32, General)
|
||||
IR_OPCODE(ConvertI32ToF32, General)
|
||||
IR_OPCODE(ConvertF32ToU32, General)
|
||||
IR_OPCODE(ConvertF32ToI32, General)
|
||||
IR_OPCODE(ConvertF32ToF16, General)
|
||||
IR_OPCODE(ConvertF16ToF32, General)
|
||||
IR_OPCODE(ConvertU16ToF16, General)
|
||||
IR_OPCODE(ConvertF16ToU16, General)
|
||||
IR_OPCODE(ConvertI16ToF16, General)
|
||||
IR_OPCODE(ConvertF16ToI16, General)
|
||||
IR_OPCODE(ConvertRoundPlusInfF32ToI32, General)
|
||||
IR_OPCODE(ConvertFloorF32ToI32, General)
|
||||
IR_OPCODE(ConvertI4ToOffsetF32, General)
|
||||
IR_OPCODE(LdexpF32, General)
|
||||
IR_OPCODE(PackF32ToF16Rtz, General)
|
||||
IR_OPCODE(PackSnorm2x16F32, General)
|
||||
IR_OPCODE(PackUnorm2x16F32, General)
|
||||
IR_OPCODE(PackU16U32, General)
|
||||
IR_OPCODE(PackU8F32, General)
|
||||
IR_OPCODE(PackB32F16, General)
|
||||
IR_OPCODE(PackedMadI16, General)
|
||||
IR_OPCODE(PackedMulLoU16, General)
|
||||
IR_OPCODE(PackedAddI16, General)
|
||||
IR_OPCODE(PackedSubI16, General)
|
||||
IR_OPCODE(PackedLshlrevB16, General)
|
||||
IR_OPCODE(PackedLshrrevB16, General)
|
||||
IR_OPCODE(PackedAshrrevI16, General)
|
||||
IR_OPCODE(PackedMaxI16, General)
|
||||
IR_OPCODE(PackedMinI16, General)
|
||||
IR_OPCODE(PackedMadU16, General)
|
||||
IR_OPCODE(PackedAddU16, General)
|
||||
IR_OPCODE(PackedSubU16, General)
|
||||
IR_OPCODE(PackedMaxU16, General)
|
||||
IR_OPCODE(PackedMinU16, General)
|
||||
IR_OPCODE(PackedAddF16, General)
|
||||
IR_OPCODE(PackedMulF16, General)
|
||||
IR_OPCODE(PackedMinF16, General)
|
||||
IR_OPCODE(PackedMaxF16, General)
|
||||
IR_OPCODE(PackedFmaF16, General)
|
||||
IR_OPCODE(AddF16, General)
|
||||
IR_OPCODE(SubF16, General)
|
||||
IR_OPCODE(MulF16, General)
|
||||
IR_OPCODE(MinF16, General)
|
||||
IR_OPCODE(MaxF16, General)
|
||||
IR_OPCODE(FmaF16, General)
|
||||
IR_OPCODE(MadMixF16, General)
|
||||
IR_OPCODE(IAddU16, General)
|
||||
IR_OPCODE(ISubI16, General)
|
||||
IR_OPCODE(IMinI16, General)
|
||||
IR_OPCODE(IMaxI16, General)
|
||||
IR_OPCODE(UMinU16, General)
|
||||
IR_OPCODE(UMaxU16, General)
|
||||
IR_OPCODE(RcpF32, General)
|
||||
IR_OPCODE(FractF32, General)
|
||||
IR_OPCODE(TruncF32, General)
|
||||
IR_OPCODE(CeilF32, General)
|
||||
IR_OPCODE(RoundEvenF32, General)
|
||||
IR_OPCODE(FloorF32, General)
|
||||
IR_OPCODE(Exp2F32, General)
|
||||
IR_OPCODE(Log2F32, General)
|
||||
IR_OPCODE(InverseSqrtF32, General)
|
||||
IR_OPCODE(SqrtF32, General)
|
||||
IR_OPCODE(RcpF16, General)
|
||||
IR_OPCODE(SqrtF16, General)
|
||||
IR_OPCODE(InverseSqrtF16, General)
|
||||
IR_OPCODE(Log2F16, General)
|
||||
IR_OPCODE(Exp2F16, General)
|
||||
IR_OPCODE(FloorF16, General)
|
||||
IR_OPCODE(CeilF16, General)
|
||||
IR_OPCODE(TruncF16, General)
|
||||
IR_OPCODE(RoundEvenF16, General)
|
||||
IR_OPCODE(SinF32, General)
|
||||
IR_OPCODE(CosF32, General)
|
||||
IR_OPCODE(CubeIdF32, General)
|
||||
IR_OPCODE(CubeScF32, General)
|
||||
IR_OPCODE(CubeTcF32, General)
|
||||
IR_OPCODE(CubeMaF32, General)
|
||||
IR_OPCODE(FAddF32, General)
|
||||
IR_OPCODE(FSubF32, General)
|
||||
IR_OPCODE(FMulF32, General)
|
||||
IR_OPCODE(FMinF32, General)
|
||||
IR_OPCODE(FMaxF32, General)
|
||||
IR_OPCODE(FMadF32, General)
|
||||
IR_OPCODE(Dot2AccF32F16, General)
|
||||
IR_OPCODE(FMin3F32, General)
|
||||
IR_OPCODE(FMax3F32, General)
|
||||
IR_OPCODE(FMed3F32, General)
|
||||
IR_OPCODE(Min3F16, General)
|
||||
IR_OPCODE(Max3F16, General)
|
||||
IR_OPCODE(Med3F16, General)
|
||||
IR_OPCODE(LoadSrtDword, General)
|
||||
IR_OPCODE(SLoadDword, General)
|
||||
IR_OPCODE(SBufferLoadDword, General)
|
||||
IR_OPCODE(BufferLoadUbyte, General)
|
||||
IR_OPCODE(BufferLoadSbyte, General)
|
||||
IR_OPCODE(BufferLoadUshort, General)
|
||||
IR_OPCODE(BufferLoadSshort, General)
|
||||
IR_OPCODE(BufferLoadDword, General)
|
||||
IR_OPCODE(BufferStoreByte, General)
|
||||
IR_OPCODE(BufferStoreShort, General)
|
||||
IR_OPCODE(BufferStoreDword, General)
|
||||
IR_OPCODE(AtomicSwapU32, General)
|
||||
IR_OPCODE(AtomicAddU32, General)
|
||||
IR_OPCODE(AtomicSubU32, General)
|
||||
IR_OPCODE(AtomicSMinI32, General)
|
||||
IR_OPCODE(AtomicUMinU32, General)
|
||||
IR_OPCODE(AtomicSMaxI32, General)
|
||||
IR_OPCODE(AtomicUMaxU32, General)
|
||||
IR_OPCODE(AtomicAndU32, General)
|
||||
IR_OPCODE(AtomicOrU32, General)
|
||||
IR_OPCODE(AtomicXorU32, General)
|
||||
IR_OPCODE(AtomicFMinF32, General)
|
||||
IR_OPCODE(AtomicFMaxF32, General)
|
||||
IR_OPCODE(FlatLoadUbyte, General)
|
||||
IR_OPCODE(FlatLoadSbyte, General)
|
||||
IR_OPCODE(FlatLoadUshort, General)
|
||||
IR_OPCODE(FlatLoadSshort, General)
|
||||
IR_OPCODE(FlatLoadDword, General)
|
||||
IR_OPCODE(FlatStoreByte, General)
|
||||
IR_OPCODE(FlatStoreShort, General)
|
||||
IR_OPCODE(FlatStoreDword, General)
|
||||
IR_OPCODE(DsReadUbyte, General)
|
||||
IR_OPCODE(DsReadSbyte, General)
|
||||
IR_OPCODE(DsReadUshort, General)
|
||||
IR_OPCODE(DsReadSshort, General)
|
||||
IR_OPCODE(DsReadB32, General)
|
||||
IR_OPCODE(DsWriteByte, General)
|
||||
IR_OPCODE(DsWriteShort, General)
|
||||
IR_OPCODE(DsWriteB32, General)
|
||||
IR_OPCODE(DsMinF32, General)
|
||||
IR_OPCODE(DsMaxF32, General)
|
||||
IR_OPCODE(DsSwizzleB32, General)
|
||||
IR_OPCODE(DsConsume, General)
|
||||
IR_OPCODE(DsAppend, General)
|
||||
IR_OPCODE(DsWriteAddtidB32, General)
|
||||
IR_OPCODE(DsReadAddtidB32, General)
|
||||
IR_OPCODE(ImageGetResinfo, General)
|
||||
IR_OPCODE(ImageGetLod, General)
|
||||
IR_OPCODE(ImageLoad, General)
|
||||
IR_OPCODE(ImageStore, General)
|
||||
IR_OPCODE(ImageSample, General)
|
||||
IR_OPCODE(ImageGather4, General)
|
||||
IR_OPCODE(LoadInputF32, General)
|
||||
IR_OPCODE(Export, General)
|
||||
@@ -302,7 +302,7 @@ static void vs_check(const HW::VertexShaderInfo& vs, const HW::ShaderRegisters&
|
||||
EXIT_NOT_IMPLEMENTED(vs.gs_regs.rsrc1.ieee_mode != false);
|
||||
EXIT_NOT_IMPLEMENTED(vs.gs_regs.rsrc1.cu_group_enable != false);
|
||||
EXIT_NOT_IMPLEMENTED(vs.gs_regs.rsrc1.require_forward_progress != false);
|
||||
EXIT_NOT_IMPLEMENTED(vs.gs_regs.rsrc1.lds_configuration != false);
|
||||
EXIT_NOT_IMPLEMENTED(vs.gs_regs.rsrc1.threadgroup_configuration != false);
|
||||
EXIT_NOT_IMPLEMENTED(vs.gs_regs.rsrc1.gs_vgpr_component_count != 3);
|
||||
EXIT_NOT_IMPLEMENTED(vs.gs_regs.rsrc1.fp16_overflow != false);
|
||||
EXIT_NOT_IMPLEMENTED(vs.gs_regs.rsrc2.scratch_en != false);
|
||||
@@ -374,7 +374,7 @@ static void ps_check(const HW::PsStageRegisters& ps, const HW::ShaderRegisters&
|
||||
ps.rsrc2.extra_lds_size);
|
||||
}
|
||||
}
|
||||
EXIT_NOT_IMPLEMENTED(ps.rsrc2.raster_ordered_shading != false);
|
||||
EXIT_NOT_IMPLEMENTED(ps.rsrc2.raster_ordered_shading != 0);
|
||||
EXIT_NOT_IMPLEMENTED(ps.rsrc2.shared_vgprs != 0);
|
||||
|
||||
if (sh.shader_z_format != 0x00000000 && sh.shader_z_format != 0x00000001 &&
|
||||
|
||||
@@ -64,6 +64,7 @@ struct File {
|
||||
std::filesystem::path real_name;
|
||||
std::atomic_bool opened;
|
||||
std::atomic_bool directory;
|
||||
std::atomic_bool writable;
|
||||
std::atomic_bool append;
|
||||
std::atomic_bool sync_writes;
|
||||
SpecialFile special;
|
||||
@@ -129,6 +130,7 @@ int FileDescriptors::CreateDescriptor() {
|
||||
auto* file = new File {};
|
||||
file->opened = false;
|
||||
file->directory = false;
|
||||
file->writable = false;
|
||||
file->append = false;
|
||||
file->sync_writes = false;
|
||||
file->special = SpecialFile::None;
|
||||
@@ -274,6 +276,10 @@ static std::filesystem::path ResolvePathIgnoringCase(const std::filesystem::path
|
||||
|
||||
return resolved;
|
||||
}
|
||||
#else
|
||||
static bool HasWindowsForbiddenFilenameCharacter(const std::string& relative_path) {
|
||||
return relative_path.find_first_of("<>:\"|?*") != std::string::npos;
|
||||
}
|
||||
#endif
|
||||
|
||||
std::filesystem::path MountPoints::GetRealFilename(const std::string& mounted_file_name) {
|
||||
@@ -293,6 +299,10 @@ std::filesystem::path MountPoints::GetRealFilename(const std::string& mounted_fi
|
||||
rel_path = Common::RemoveFirst(rel_path, 1);
|
||||
}
|
||||
#if KYTY_PLATFORM == KYTY_PLATFORM_WINDOWS
|
||||
if (HasWindowsForbiddenFilenameCharacter(rel_path)) {
|
||||
::printf("FileSystem: Windows-incompatible guest filename: %s\n",
|
||||
mounted_file_name.c_str());
|
||||
}
|
||||
return p.dir / rel_path;
|
||||
#else
|
||||
return ResolvePathIgnoringCase(p.dir / rel_path);
|
||||
@@ -408,6 +418,7 @@ int KYTY_SYSV_ABI KernelOpen(const char* path, int flags, uint16_t mode) {
|
||||
EXIT_IF(file == nullptr || file->opened || file->directory);
|
||||
|
||||
file->name = path;
|
||||
file->writable = rw_mode != Common::File::Mode::Read;
|
||||
file->append = append;
|
||||
file->sync_writes = fsync || sync || dsync;
|
||||
|
||||
@@ -792,7 +803,7 @@ int64_t KYTY_SYSV_ABI KernelLseek(int d, int64_t offset, int whence) {
|
||||
return KERNEL_ERROR_ESPIPE;
|
||||
}
|
||||
|
||||
file->mutex.Lock();
|
||||
Common::LockGuard lock(file->mutex);
|
||||
|
||||
bool is_invalid = file->f.IsInvalid();
|
||||
|
||||
@@ -817,8 +828,6 @@ int64_t KYTY_SYSV_ABI KernelLseek(int d, int64_t offset, int whence) {
|
||||
|
||||
EXIT_IF(pos != offset);
|
||||
|
||||
file->mutex.Unlock();
|
||||
|
||||
if (is_invalid) {
|
||||
LOGF("\tfile is invalid\n");
|
||||
return KERNEL_ERROR_EIO;
|
||||
@@ -953,6 +962,47 @@ int KYTY_SYSV_ABI KernelFstat(int d, FileStat* sb) {
|
||||
return OK;
|
||||
}
|
||||
|
||||
int KYTY_SYSV_ABI KernelFtruncate(int d, int64_t length) {
|
||||
PRINT_NAME();
|
||||
|
||||
if (d < DESCRIPTOR_MIN) {
|
||||
return KERNEL_ERROR_EBADF;
|
||||
}
|
||||
|
||||
if (length < 0) {
|
||||
return KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
if (::Libs::Network::Net::IsSocket(d)) {
|
||||
return KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
auto* file = g_files->GetFile(d);
|
||||
|
||||
if (file == nullptr || !file->opened) {
|
||||
return KERNEL_ERROR_EBADF;
|
||||
}
|
||||
|
||||
if (!file->writable) {
|
||||
return KERNEL_ERROR_EBADF;
|
||||
}
|
||||
|
||||
if (file->directory || file->special != SpecialFile::None) {
|
||||
return KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
Common::LockGuard lock(file->mutex);
|
||||
|
||||
if (file->f.IsInvalid() || !file->f.Truncate(static_cast<uint64_t>(length))) {
|
||||
return KERNEL_ERROR_EIO;
|
||||
}
|
||||
|
||||
LOGF("\tFtruncate (size = %" PRId64 ") file: %s\n", length,
|
||||
Common::PathToString(file->real_name).c_str());
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
int KYTY_SYSV_ABI KernelUnlink(const char* path) {
|
||||
PRINT_NAME();
|
||||
|
||||
|
||||
@@ -48,6 +48,7 @@ int64_t KYTY_SYSV_ABI KernelPwrite(int d, const void* buf, size_t nbytes, int64_
|
||||
int64_t KYTY_SYSV_ABI KernelLseek(int d, int64_t offset, int whence);
|
||||
int KYTY_SYSV_ABI KernelStat(const char* path, FileStat* sb);
|
||||
int KYTY_SYSV_ABI KernelFstat(int d, FileStat* sb);
|
||||
int KYTY_SYSV_ABI KernelFtruncate(int d, int64_t length);
|
||||
int KYTY_SYSV_ABI KernelUnlink(const char* path);
|
||||
int KYTY_SYSV_ABI KernelRename(const char* from, const char* to);
|
||||
int KYTY_SYSV_ABI KernelGetdirentries(int fd, char* buf, int nbytes, int64_t* basep);
|
||||
|
||||
@@ -65,7 +65,7 @@ constexpr uint64_t PAGE_TABLE_POOL_SIZE = 4ull * 1024ull * 1024ull * 1024ull;
|
||||
constexpr uint64_t PAGE_TABLE_GRANULARITY = 2ull * 1024ull * 1024ull;
|
||||
constexpr int PAGE_TABLE_POOL_ENTRIES =
|
||||
static_cast<int>(PAGE_TABLE_POOL_SIZE / PAGE_TABLE_GRANULARITY);
|
||||
constexpr uint64_t DEFAULT_FLEXIBLE_MEMORY_SIZE = 4ull * 1024ull * 1024ull * 1024ull;
|
||||
constexpr uint64_t DEFAULT_FLEXIBLE_MEMORY_SIZE = 1ull * 1024ull * 1024ull * 1024ull;
|
||||
|
||||
static uint64_t g_flexible_memory_size = DEFAULT_FLEXIBLE_MEMORY_SIZE;
|
||||
static bool g_flexible_memory_size_frozen = false;
|
||||
|
||||
@@ -22,6 +22,13 @@ static bool GuestFreeRangeContains(uint64_t base, uint64_t range_size, uint64_t
|
||||
return candidate <= range_end && size <= range_end - candidate;
|
||||
}
|
||||
|
||||
#if KYTY_PLATFORM == KYTY_PLATFORM_WINDOWS
|
||||
static bool CoalescePlaceholders(uint64_t vaddr, uint64_t size) {
|
||||
return size != 0 && VirtualFree(reinterpret_cast<void*>(vaddr), size,
|
||||
MEM_RELEASE | MEM_COALESCE_PLACEHOLDERS) != 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
class GuestBackingStore {
|
||||
public:
|
||||
enum class FailureReason {
|
||||
@@ -264,6 +271,19 @@ public:
|
||||
removed.push_back(entry);
|
||||
}
|
||||
|
||||
#if KYTY_PLATFORM == KYTY_PLATFORM_WINDOWS
|
||||
// Each unmapped file view becomes a separate Windows placeholder. The address-space owner
|
||||
// records this contiguous guest span as one free range, so normalize fragmented backing
|
||||
// views into one placeholder before publishing it there.
|
||||
if (removed.size() > 1 && !CoalescePlaceholders(vaddr, size)) {
|
||||
for (auto it = removed.rbegin(); it != removed.rend(); ++it) {
|
||||
EXIT_IF(!MapExistingPlaceholderFixed(it->vaddr, it->size, it->backing_offset,
|
||||
it->mode));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (placeholder_preserved != nullptr) {
|
||||
*placeholder_preserved = true;
|
||||
}
|
||||
@@ -832,6 +852,8 @@ public:
|
||||
EXIT_IF(VirtualFree(reinterpret_cast<void*>(region_vaddr), region_size,
|
||||
MEM_RELEASE | MEM_PRESERVE_PLACEHOLDER) == 0);
|
||||
}
|
||||
// ReleaseCommitted also publishes the aggregate span as one logical free range.
|
||||
EXIT_IF(regions.size() > 1 && !CoalescePlaceholders(vaddr, size));
|
||||
#else
|
||||
for (const auto& [region_vaddr, region_size]: regions) {
|
||||
RestorePlaceholder(region_vaddr, region_size);
|
||||
@@ -1252,8 +1274,7 @@ private:
|
||||
|
||||
if (base != it->first || end != it->first + it->second) {
|
||||
#if KYTY_PLATFORM == KYTY_PLATFORM_WINDOWS
|
||||
if (VirtualFree(reinterpret_cast<void*>(base), end - base,
|
||||
MEM_RELEASE | MEM_COALESCE_PLACEHOLDERS) != 0) {
|
||||
if (CoalescePlaceholders(base, end - base)) {
|
||||
m_free.erase(first, last);
|
||||
m_free.emplace(base, end - base);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,287 @@
|
||||
#include "kernel/syncOnAddress.h"
|
||||
|
||||
#include "common/threads.h"
|
||||
#include "libs/errno.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <climits>
|
||||
#include <cstdint>
|
||||
#include <list>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <unordered_map>
|
||||
|
||||
#if KYTY_PLATFORM == KYTY_PLATFORM_LINUX && !defined(__APPLE__)
|
||||
#include <cerrno>
|
||||
#include <linux/futex.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
namespace Libs::LibKernel::SyncOnAddress {
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr uint32_t SIGNAL_POLL_MICROS = 10000;
|
||||
|
||||
using Clock = std::chrono::steady_clock;
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] bool IsValidWaitAddress(const volatile T* address) {
|
||||
return address != nullptr && (reinterpret_cast<uintptr_t>(address) & (alignof(T) - 1u)) == 0;
|
||||
}
|
||||
|
||||
[[nodiscard]] bool IsValidWakeAddress(const volatile void* address) {
|
||||
return address != nullptr &&
|
||||
(reinterpret_cast<uintptr_t>(address) & (alignof(uint32_t) - 1u)) == 0;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] T ReadWord(const volatile T* address) {
|
||||
return __atomic_load_n(address, __ATOMIC_ACQUIRE);
|
||||
}
|
||||
|
||||
struct WaitDeadline {
|
||||
bool finite = false;
|
||||
Clock::time_point end {};
|
||||
};
|
||||
|
||||
[[nodiscard]] WaitDeadline MakeDeadline(const uint32_t* timeout_micros) {
|
||||
if (timeout_micros == nullptr) {
|
||||
return {};
|
||||
}
|
||||
return {true, Clock::now() + std::chrono::microseconds(*timeout_micros)};
|
||||
}
|
||||
|
||||
[[nodiscard]] uint32_t GetWaitSliceMicros(const WaitDeadline& deadline, bool first_wait) {
|
||||
if (!deadline.finite) {
|
||||
return SIGNAL_POLL_MICROS;
|
||||
}
|
||||
|
||||
const auto now = Clock::now();
|
||||
if (now >= deadline.end) {
|
||||
return first_wait ? 0u : UINT32_MAX;
|
||||
}
|
||||
|
||||
const auto remaining =
|
||||
std::chrono::duration_cast<std::chrono::microseconds>(deadline.end - now).count();
|
||||
return static_cast<uint32_t>(std::min<int64_t>(remaining, SIGNAL_POLL_MICROS));
|
||||
}
|
||||
|
||||
void PollSignals(signal_poll_func_t signal_poll) {
|
||||
if (signal_poll != nullptr) {
|
||||
signal_poll();
|
||||
}
|
||||
}
|
||||
|
||||
#if KYTY_PLATFORM == KYTY_PLATFORM_LINUX && !defined(__APPLE__)
|
||||
|
||||
template <typename T>
|
||||
int WaitLinux(volatile T* address, T expected, const uint32_t* timeout_micros,
|
||||
signal_poll_func_t signal_poll) {
|
||||
const auto deadline = MakeDeadline(timeout_micros);
|
||||
bool first_wait = true;
|
||||
|
||||
for (;;) {
|
||||
if (ReadWord(address) != expected) {
|
||||
return OK;
|
||||
}
|
||||
const auto slice_micros = GetWaitSliceMicros(deadline, first_wait);
|
||||
if (slice_micros == UINT32_MAX) {
|
||||
return ReadWord(address) == expected ? KERNEL_ERROR_ETIMEDOUT : OK;
|
||||
}
|
||||
const timespec timeout = {
|
||||
.tv_sec = static_cast<time_t>(slice_micros / 1000000u),
|
||||
.tv_nsec = static_cast<long>(slice_micros % 1000000u) * 1000L,
|
||||
};
|
||||
|
||||
long result = 0;
|
||||
int wait_error = 0;
|
||||
result = syscall(SYS_futex, const_cast<T*>(address), FUTEX_WAIT_PRIVATE,
|
||||
static_cast<uint32_t>(expected), &timeout, nullptr, 0);
|
||||
if (result != 0) {
|
||||
wait_error = errno;
|
||||
}
|
||||
if (result == 0 || wait_error == EAGAIN) {
|
||||
return OK;
|
||||
}
|
||||
if (wait_error != ETIMEDOUT && wait_error != EINTR) {
|
||||
return KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
PollSignals(signal_poll);
|
||||
if (deadline.finite && Clock::now() >= deadline.end) {
|
||||
return ReadWord(address) == expected ? KERNEL_ERROR_ETIMEDOUT : OK;
|
||||
}
|
||||
first_wait = false;
|
||||
}
|
||||
}
|
||||
|
||||
int WakeLinux(volatile void* address, int32_t count) {
|
||||
const auto result = syscall(SYS_futex, const_cast<void*>(address), FUTEX_WAKE_PRIVATE, count,
|
||||
nullptr, nullptr, 0);
|
||||
return result < 0 ? KERNEL_ERROR_EINVAL : OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
struct PortableWaiter {
|
||||
Common::CondVar condition;
|
||||
bool wake_requested = false;
|
||||
};
|
||||
|
||||
struct PortableAddressEntry {
|
||||
Common::Mutex mutex;
|
||||
std::list<PortableWaiter*> waiters;
|
||||
};
|
||||
|
||||
struct PortableAddressRegistry {
|
||||
std::mutex mutex;
|
||||
std::unordered_map<uintptr_t, std::shared_ptr<PortableAddressEntry>> entries;
|
||||
};
|
||||
|
||||
PortableAddressRegistry& GetPortableRegistry() {
|
||||
static PortableAddressRegistry registry;
|
||||
return registry;
|
||||
}
|
||||
|
||||
std::shared_ptr<PortableAddressEntry> RegisterPortableWaiter(volatile void* address,
|
||||
PortableWaiter* waiter) {
|
||||
auto& registry = GetPortableRegistry();
|
||||
std::lock_guard registry_lock(registry.mutex);
|
||||
auto& entry = registry.entries[reinterpret_cast<uintptr_t>(address)];
|
||||
if (!entry) {
|
||||
entry = std::make_shared<PortableAddressEntry>();
|
||||
}
|
||||
entry->mutex.Lock();
|
||||
entry->waiters.push_back(waiter);
|
||||
return entry;
|
||||
}
|
||||
|
||||
void UnregisterPortableWaiter(volatile void* address,
|
||||
const std::shared_ptr<PortableAddressEntry>& entry,
|
||||
PortableWaiter* waiter) {
|
||||
entry->waiters.remove(waiter);
|
||||
const bool empty = entry->waiters.empty();
|
||||
entry->mutex.Unlock();
|
||||
if (!empty) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto& registry = GetPortableRegistry();
|
||||
std::lock_guard registry_lock(registry.mutex);
|
||||
entry->mutex.Lock();
|
||||
const auto it = registry.entries.find(reinterpret_cast<uintptr_t>(address));
|
||||
if (it != registry.entries.end() && it->second == entry && entry->waiters.empty()) {
|
||||
registry.entries.erase(it);
|
||||
}
|
||||
entry->mutex.Unlock();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
int WaitPortable(volatile T* address, T expected, const uint32_t* timeout_micros,
|
||||
signal_poll_func_t signal_poll) {
|
||||
PortableWaiter waiter;
|
||||
auto entry = RegisterPortableWaiter(address, &waiter);
|
||||
const auto deadline = MakeDeadline(timeout_micros);
|
||||
bool first_wait = true;
|
||||
int result = OK;
|
||||
|
||||
while (ReadWord(address) == expected && !waiter.wake_requested) {
|
||||
const auto slice_micros = GetWaitSliceMicros(deadline, first_wait);
|
||||
if (slice_micros == UINT32_MAX) {
|
||||
result = KERNEL_ERROR_ETIMEDOUT;
|
||||
break;
|
||||
}
|
||||
if (slice_micros == 0) {
|
||||
result = KERNEL_ERROR_ETIMEDOUT;
|
||||
break;
|
||||
}
|
||||
|
||||
(void)waiter.condition.WaitFor(&entry->mutex, slice_micros);
|
||||
entry->mutex.Unlock();
|
||||
PollSignals(signal_poll);
|
||||
entry->mutex.Lock();
|
||||
|
||||
if (deadline.finite && Clock::now() >= deadline.end && ReadWord(address) == expected &&
|
||||
!waiter.wake_requested) {
|
||||
result = KERNEL_ERROR_ETIMEDOUT;
|
||||
break;
|
||||
}
|
||||
first_wait = false;
|
||||
}
|
||||
|
||||
UnregisterPortableWaiter(address, entry, &waiter);
|
||||
return result;
|
||||
}
|
||||
|
||||
int WakePortable(volatile void* address, int32_t count) {
|
||||
if (count == 0) {
|
||||
return OK;
|
||||
}
|
||||
auto& registry = GetPortableRegistry();
|
||||
std::unique_lock registry_lock(registry.mutex);
|
||||
const auto it = registry.entries.find(reinterpret_cast<uintptr_t>(address));
|
||||
if (it == registry.entries.end()) {
|
||||
return OK;
|
||||
}
|
||||
auto entry = it->second;
|
||||
entry->mutex.Lock();
|
||||
registry_lock.unlock();
|
||||
|
||||
int32_t remaining = count;
|
||||
for (auto* waiter: entry->waiters) {
|
||||
if (!waiter->wake_requested) {
|
||||
waiter->wake_requested = true;
|
||||
waiter->condition.Signal();
|
||||
if (remaining != INT_MAX && --remaining == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
entry->mutex.Unlock();
|
||||
return OK;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
int WaitImpl(volatile T* address, T expected, const uint32_t* timeout_micros,
|
||||
signal_poll_func_t signal_poll) {
|
||||
if (!IsValidWaitAddress(address)) {
|
||||
return KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
int result = OK;
|
||||
#if KYTY_PLATFORM == KYTY_PLATFORM_LINUX && !defined(__APPLE__)
|
||||
result = WaitLinux(address, expected, timeout_micros, signal_poll);
|
||||
#else
|
||||
result = WaitPortable(address, expected, timeout_micros, signal_poll);
|
||||
#endif
|
||||
PollSignals(signal_poll);
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int Wait32(volatile uint32_t* address, uint32_t expected, const uint32_t* timeout_micros,
|
||||
signal_poll_func_t signal_poll) {
|
||||
return WaitImpl(address, expected, timeout_micros, signal_poll);
|
||||
}
|
||||
|
||||
int Wait64(volatile uint64_t* address, uint64_t expected, const uint32_t* timeout_micros,
|
||||
signal_poll_func_t signal_poll) {
|
||||
return WaitImpl(address, expected, timeout_micros, signal_poll);
|
||||
}
|
||||
|
||||
int Wake(volatile void* address, int32_t count) {
|
||||
if (!IsValidWakeAddress(address) || count < 0) {
|
||||
return KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
#if KYTY_PLATFORM == KYTY_PLATFORM_LINUX && !defined(__APPLE__)
|
||||
return WakeLinux(address, count);
|
||||
#endif
|
||||
return WakePortable(address, count);
|
||||
}
|
||||
|
||||
} // namespace Libs::LibKernel::SyncOnAddress
|
||||
@@ -0,0 +1,19 @@
|
||||
#ifndef EMULATOR_INCLUDE_EMULATOR_KERNEL_SYNC_ON_ADDRESS_H_
|
||||
#define EMULATOR_INCLUDE_EMULATOR_KERNEL_SYNC_ON_ADDRESS_H_
|
||||
|
||||
#include "common/abi.h"
|
||||
#include "common/common.h"
|
||||
|
||||
namespace Libs::LibKernel::SyncOnAddress {
|
||||
|
||||
using signal_poll_func_t = void (*)();
|
||||
|
||||
int Wait32(volatile uint32_t* address, uint32_t expected, const uint32_t* timeout_micros,
|
||||
signal_poll_func_t signal_poll = nullptr);
|
||||
int Wait64(volatile uint64_t* address, uint64_t expected, const uint32_t* timeout_micros,
|
||||
signal_poll_func_t signal_poll = nullptr);
|
||||
int Wake(volatile void* address, int32_t count);
|
||||
|
||||
} // namespace Libs::LibKernel::SyncOnAddress
|
||||
|
||||
#endif /* EMULATOR_INCLUDE_EMULATOR_KERNEL_SYNC_ON_ADDRESS_H_ */
|
||||
@@ -1 +1,2 @@
|
||||
#define KYTY_GIT_VERSION "@KYTY_GIT_VERSION@"
|
||||
#define KYTY_GIT_VERSION "@KYTY_GIT_VERSION@"
|
||||
#define KYTY_GIT_HASH "@KYTY_GIT_HASH@"
|
||||
@@ -16,6 +16,7 @@ file(GLOB launcher_forms
|
||||
add_executable(launcher WIN32
|
||||
${launcher_src}
|
||||
${launcher_forms}
|
||||
resources.qrc
|
||||
)
|
||||
|
||||
|
||||
@@ -37,7 +38,6 @@ elseif(LINUX)
|
||||
set_target_properties(launcher PROPERTIES LINK_FLAGS "${KYTY_LD_OPTIONS}")
|
||||
endif()
|
||||
|
||||
add_dependencies(launcher KytyGitVersion)
|
||||
add_dependencies(launcher kyty_emulator)
|
||||
|
||||
if(KYTY_CLANG_CL)
|
||||
|
||||
@@ -78,6 +78,26 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QCheckBox" name="checkBox_fullscreen">
|
||||
<property name="toolTip">
|
||||
<string>Run in borderless desktop fullscreen</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Fullscreen</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QCheckBox" name="checkBox_red_zone_protection">
|
||||
<property name="toolTip">
|
||||
<string>Helps prevent crashes in some games on Windows</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Windows SysV red zone crash protection (Experimental)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
@@ -69,6 +69,31 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="input_mapping_button">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>36</width>
|
||||
<height>36</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Edit input mapping</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>32</width>
|
||||
<height>32</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="autoRaise">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="edit_button">
|
||||
<property name="minimumSize">
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">
|
||||
<g fill="none" stroke="#e8f1ff" stroke-linecap="round" stroke-linejoin="round" stroke-width="2">
|
||||
<path d="M8 4h11l5 5v7M24 9h-5V4M16 27H8a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2"/>
|
||||
<path d="m15 24 1-4 8-8 4 4-8 8-4 1Z"/>
|
||||
<path d="m22 14 4 4" opacity=".8"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 336 B |
@@ -0,0 +1,8 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">
|
||||
<g fill="none" stroke="#e8f1ff" stroke-linecap="round" stroke-linejoin="round" stroke-width="2">
|
||||
<path d="M5 8h3M14 8h13M5 16h13M24 16h3M5 24h6M17 24h10"/>
|
||||
<circle cx="11" cy="8" r="3"/>
|
||||
<circle cx="21" cy="16" r="3"/>
|
||||
<circle cx="14" cy="24" r="3"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 344 B |
@@ -0,0 +1,9 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">
|
||||
<g fill="none" stroke="#e8f1ff" stroke-linecap="round" stroke-linejoin="round" stroke-width="2">
|
||||
<path d="M10 10h12c3.6 0 5.8 2.3 6.6 6.8l.9 5.1c.4 2.4-.8 4.1-2.8 4.1-1.4 0-2.5-.7-3.6-2.3L21.3 21H10.7l-1.8 2.7C7.8 25.3 6.7 26 5.3 26c-2 0-3.2-1.7-2.8-4.1l.9-5.1C4.2 12.3 6.4 10 10 10Z"/>
|
||||
<path d="M8 16h6M11 13v6"/>
|
||||
<circle cx="22" cy="15" r="1" fill="#e8f1ff" stroke="none"/>
|
||||
<circle cx="25" cy="18" r="1" fill="#e8f1ff" stroke="none"/>
|
||||
<path d="M13 7h6M16 4v6" opacity=".8"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 574 B |
@@ -0,0 +1,6 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">
|
||||
<g fill="none" stroke="#e8f1ff" stroke-linecap="round" stroke-linejoin="round" stroke-width="2">
|
||||
<path d="M6 9h20M12 9V5h8v4M9 9l1 18h12l1-18"/>
|
||||
<path d="M14 14v8M18 14v8" opacity=".8"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 272 B |
@@ -85,9 +85,10 @@ public:
|
||||
QString game_comment;
|
||||
|
||||
Resolution screen_resolution = Resolution::R1280X720;
|
||||
bool fullscreen_enabled = false;
|
||||
int vblank_frequency = 60;
|
||||
int console_language = DEFAULT_CONSOLE_LANGUAGE;
|
||||
bool vulkan_validation_enabled = true;
|
||||
bool vulkan_validation_enabled = false;
|
||||
bool shader_validation_enabled = true;
|
||||
ShaderOptimizationType shader_optimization_type = ShaderOptimizationType::Performance;
|
||||
ShaderLogDirection shader_log_direction = ShaderLogDirection::Silent;
|
||||
@@ -98,11 +99,16 @@ public:
|
||||
QString printf_output_file = "_kyty.txt";
|
||||
ProfilerDirection profiler_direction = ProfilerDirection::None;
|
||||
bool renderdoc_enabled = false;
|
||||
#if defined(_WIN32)
|
||||
bool red_zone_protection_enabled = false;
|
||||
#endif
|
||||
QStringList host_input_mapping;
|
||||
|
||||
QString elf = QStringLiteral("eboot.bin");
|
||||
|
||||
void CopyEmulatorSettingsFrom(const Configuration& other) {
|
||||
screen_resolution = other.screen_resolution;
|
||||
fullscreen_enabled = other.fullscreen_enabled;
|
||||
vblank_frequency = other.vblank_frequency;
|
||||
console_language = other.console_language;
|
||||
vulkan_validation_enabled = other.vulkan_validation_enabled;
|
||||
@@ -116,6 +122,10 @@ public:
|
||||
printf_output_file = other.printf_output_file;
|
||||
profiler_direction = other.profiler_direction;
|
||||
renderdoc_enabled = other.renderdoc_enabled;
|
||||
#if defined(_WIN32)
|
||||
red_zone_protection_enabled = other.red_zone_protection_enabled;
|
||||
#endif
|
||||
host_input_mapping = other.host_input_mapping;
|
||||
}
|
||||
|
||||
void CopyFrom(const Configuration& other) {
|
||||
@@ -138,6 +148,7 @@ public:
|
||||
KYTY_CFG_SET(game_path);
|
||||
KYTY_CFG_SET(custom_settings);
|
||||
KYTY_CFG_SET(screen_resolution);
|
||||
KYTY_CFG_SET(fullscreen_enabled);
|
||||
KYTY_CFG_SET(vblank_frequency);
|
||||
KYTY_CFG_SET(console_language);
|
||||
KYTY_CFG_SET(vulkan_validation_enabled);
|
||||
@@ -151,6 +162,10 @@ public:
|
||||
KYTY_CFG_SET(printf_output_file);
|
||||
KYTY_CFG_SET(profiler_direction);
|
||||
KYTY_CFG_SET(renderdoc_enabled);
|
||||
#if defined(_WIN32)
|
||||
KYTY_CFG_SET(red_zone_protection_enabled);
|
||||
#endif
|
||||
s->setValue("host_input_mapping", host_input_mapping);
|
||||
KYTY_CFG_SET(elf);
|
||||
}
|
||||
|
||||
@@ -160,6 +175,7 @@ public:
|
||||
KYTY_CFG_GET(game_path);
|
||||
KYTY_CFG_GET(custom_settings);
|
||||
KYTY_CFG_GET(screen_resolution);
|
||||
KYTY_CFG_GET(fullscreen_enabled);
|
||||
vblank_frequency = s->value("vblank_frequency", vblank_frequency).toInt();
|
||||
console_language = s->value("console_language", console_language).toInt();
|
||||
if (console_language < 0 || console_language > MAX_CONSOLE_LANGUAGE) {
|
||||
@@ -176,7 +192,12 @@ public:
|
||||
KYTY_CFG_GET(printf_output_file);
|
||||
KYTY_CFG_GET(profiler_direction);
|
||||
KYTY_CFG_GET(renderdoc_enabled);
|
||||
elf = s->value("elf", elf).toString();
|
||||
#if defined(_WIN32)
|
||||
red_zone_protection_enabled =
|
||||
s->value("red_zone_protection_enabled", red_zone_protection_enabled).toBool();
|
||||
#endif
|
||||
host_input_mapping = s->value("host_input_mapping", host_input_mapping).toStringList();
|
||||
elf = s->value("elf", elf).toString();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -38,7 +38,10 @@ public:
|
||||
|
||||
[[nodiscard]] const QString& GetSettingsFile() const { return m_settings_file; }
|
||||
[[nodiscard]] const QStringList& GetGameDirectories() const { return m_game_dirs; }
|
||||
[[nodiscard]] bool CanViewSelectedTrophies() const;
|
||||
[[nodiscard]] const QStringList& GetHostInputMapping() const {
|
||||
return m_global_info.host_input_mapping;
|
||||
}
|
||||
[[nodiscard]] bool CanViewSelectedTrophies() const;
|
||||
|
||||
bool EnsureGameDirectory();
|
||||
void ScanGameDirectory();
|
||||
@@ -58,6 +61,7 @@ protected slots:
|
||||
void edit_configuration();
|
||||
void delete_configuartion();
|
||||
void edit_global_settings();
|
||||
void edit_input_mapping();
|
||||
void run_configuration();
|
||||
void list_currentItemChanged(QTreeWidgetItem* current, QTreeWidgetItem* previous);
|
||||
void list_itemDoubleClicked(QTreeWidgetItem* witem, int column);
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
#ifndef LAUNCHER_INCLUDE_INPUT_MAPPING_DIALOG_H_
|
||||
#define LAUNCHER_INCLUDE_INPUT_MAPPING_DIALOG_H_
|
||||
|
||||
#include <QDialog>
|
||||
#include <QStringList>
|
||||
|
||||
class QPushButton;
|
||||
class QTreeWidget;
|
||||
class QTreeWidgetItem;
|
||||
class QWidget;
|
||||
|
||||
class InputMappingDialog final: public QDialog {
|
||||
public:
|
||||
explicit InputMappingDialog(const QStringList& mapping, QWidget* parent = nullptr);
|
||||
|
||||
[[nodiscard]] QStringList Mapping() const;
|
||||
|
||||
private:
|
||||
void ChangeBinding();
|
||||
void ClearBinding();
|
||||
void RestoreDefaults();
|
||||
void SetBinding(QTreeWidgetItem* item, const QString& binding);
|
||||
void UpdateButtons();
|
||||
|
||||
QTreeWidget* m_bindings = nullptr;
|
||||
QPushButton* m_change_button = nullptr;
|
||||
QPushButton* m_clear_button = nullptr;
|
||||
bool m_customized = false;
|
||||
};
|
||||
|
||||
#endif /* LAUNCHER_INCLUDE_INPUT_MAPPING_DIALOG_H_ */
|
||||
@@ -0,0 +1,8 @@
|
||||
<RCC>
|
||||
<qresource prefix="/icons">
|
||||
<file alias="edit-configuration.svg">icons/edit-configuration.svg</file>
|
||||
<file alias="global-settings.svg">icons/global-settings.svg</file>
|
||||
<file alias="input-mapping.svg">icons/input-mapping.svg</file>
|
||||
<file alias="remove-configuration.svg">icons/remove-configuration.svg</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
@@ -153,6 +153,7 @@ static void ListInit(QComboBox* combo, T value) {
|
||||
|
||||
void ConfigurationEditDialog::Init(const Configuration& info) {
|
||||
ListInit(m_ui->comboBox_screen_resolution, info.screen_resolution);
|
||||
m_ui->checkBox_fullscreen->setChecked(info.fullscreen_enabled);
|
||||
m_ui->spinBox_vblank_frequency->setValue(info.vblank_frequency);
|
||||
m_ui->comboBox_console_language->clear();
|
||||
m_ui->comboBox_console_language->addItems(CONSOLE_LANGUAGE_NAMES);
|
||||
@@ -163,6 +164,11 @@ void ConfigurationEditDialog::Init(const Configuration& info) {
|
||||
m_ui->checkBox_shader_validation->setChecked(info.shader_validation_enabled);
|
||||
m_ui->checkBox_vulkan_validation->setChecked(info.vulkan_validation_enabled);
|
||||
m_ui->checkBox_renderdoc_capture->setChecked(info.renderdoc_enabled);
|
||||
#if defined(_WIN32)
|
||||
m_ui->checkBox_red_zone_protection->setChecked(info.red_zone_protection_enabled);
|
||||
#else
|
||||
m_ui->checkBox_red_zone_protection->setVisible(false);
|
||||
#endif
|
||||
ListInit(m_ui->comboBox_shader_optimization_type, info.shader_optimization_type);
|
||||
ListInit(m_ui->comboBox_shader_log_direction, info.shader_log_direction);
|
||||
m_ui->lineEdit_shader_log_folder->setText(info.shader_log_folder);
|
||||
@@ -279,12 +285,16 @@ void ConfigurationEditDialog::moveEvent(QMoveEvent* event) {
|
||||
static void UpdateInfo(Configuration& info, Ui::ConfigurationEditDialog& ui) {
|
||||
info.screen_resolution =
|
||||
TextToEnum<Configuration::Resolution>(ui.comboBox_screen_resolution->currentText());
|
||||
info.fullscreen_enabled = ui.checkBox_fullscreen->isChecked();
|
||||
info.vblank_frequency = ui.spinBox_vblank_frequency->value();
|
||||
info.console_language = ui.comboBox_console_language->currentIndex();
|
||||
info.vulkan_validation_enabled = ui.checkBox_vulkan_validation->isChecked();
|
||||
info.shader_validation_enabled = ui.checkBox_shader_validation->isChecked();
|
||||
info.renderdoc_enabled = ui.checkBox_renderdoc_capture->isChecked();
|
||||
info.shader_optimization_type = TextToEnum<Configuration::ShaderOptimizationType>(
|
||||
#if defined(_WIN32)
|
||||
info.red_zone_protection_enabled = ui.checkBox_red_zone_protection->isChecked();
|
||||
#endif
|
||||
info.shader_optimization_type = TextToEnum<Configuration::ShaderOptimizationType>(
|
||||
ui.comboBox_shader_optimization_type->currentText());
|
||||
info.shader_log_direction = TextToEnum<Configuration::ShaderLogDirection>(
|
||||
ui.comboBox_shader_log_direction->currentText());
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "configurationEditDialog.h"
|
||||
#include "configurationItem.h"
|
||||
#include "gameListTreeWidget.h"
|
||||
#include "inputMappingDialog.h"
|
||||
#include "mainDialog.h"
|
||||
#include "patchesDialog.h"
|
||||
#include "trophyViewerDialog.h"
|
||||
@@ -169,6 +170,7 @@ static void ApplyGameListStyle(Ui::ConfigurationListWidget* ui) {
|
||||
"QToolButton:disabled { background: transparent; }"));
|
||||
ui->edit_button->setStyleSheet(ui->global_settings_button->styleSheet());
|
||||
ui->delete_button->setStyleSheet(ui->global_settings_button->styleSheet());
|
||||
ui->input_mapping_button->setStyleSheet(ui->global_settings_button->styleSheet());
|
||||
}
|
||||
|
||||
static void AddSaveDataDir(QStringList* dirs, QSet<QString>* seen, const QString& root,
|
||||
@@ -226,10 +228,12 @@ ConfigurationListWidget::ConfigurationListWidget(QWidget* parent)
|
||||
m_ui->setupUi(this);
|
||||
ApplyGameListStyle(m_ui);
|
||||
|
||||
m_ui->global_settings_button->setIcon(style()->standardIcon(QStyle::SP_FileDialogDetailedView));
|
||||
m_ui->global_settings_button->setIcon(QIcon(QStringLiteral(":/icons/global-settings.svg")));
|
||||
m_ui->global_settings_button->setToolTip(tr("Edit global settings and game folders"));
|
||||
m_ui->edit_button->setIcon(style()->standardIcon(QStyle::SP_FileIcon));
|
||||
m_ui->delete_button->setIcon(style()->standardIcon(QStyle::SP_DialogDiscardButton));
|
||||
m_ui->input_mapping_button->setIcon(QIcon(QStringLiteral(":/icons/input-mapping.svg")));
|
||||
m_ui->input_mapping_button->setToolTip(tr("Edit global input mapping"));
|
||||
m_ui->edit_button->setIcon(QIcon(QStringLiteral(":/icons/edit-configuration.svg")));
|
||||
m_ui->delete_button->setIcon(QIcon(QStringLiteral(":/icons/remove-configuration.svg")));
|
||||
|
||||
m_ui->delete_button->setEnabled(false);
|
||||
m_ui->edit_button->setEnabled(false);
|
||||
@@ -249,6 +253,8 @@ ConfigurationListWidget::ConfigurationListWidget(QWidget* parent)
|
||||
|
||||
connect(m_ui->global_settings_button, &QToolButton::clicked, this,
|
||||
&ConfigurationListWidget::edit_global_settings);
|
||||
connect(m_ui->input_mapping_button, &QToolButton::clicked, this,
|
||||
&ConfigurationListWidget::edit_input_mapping);
|
||||
connect(m_ui->edit_button, &QToolButton::clicked, this,
|
||||
&ConfigurationListWidget::edit_configuration);
|
||||
connect(m_ui->delete_button, &QToolButton::clicked, this,
|
||||
@@ -717,6 +723,14 @@ void ConfigurationListWidget::edit_global_settings() {
|
||||
}
|
||||
}
|
||||
|
||||
void ConfigurationListWidget::edit_input_mapping() {
|
||||
InputMappingDialog dialog(m_global_info.host_input_mapping, this);
|
||||
if (dialog.exec() == QDialog::Accepted) {
|
||||
m_global_info.host_input_mapping = dialog.Mapping();
|
||||
WriteSettings();
|
||||
}
|
||||
}
|
||||
|
||||
void ConfigurationListWidget::ClearCustomSettings(ConfigurationItem* item) {
|
||||
delete m_custom_infos.take(item->GetInfo().game_path);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,311 @@
|
||||
#include "inputMappingDialog.h"
|
||||
|
||||
#include <QAbstractItemView>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QHBoxLayout>
|
||||
#include <QHash>
|
||||
#include <QHeaderView>
|
||||
#include <QKeyEvent>
|
||||
#include <QKeySequence>
|
||||
#include <QLabel>
|
||||
#include <QMouseEvent>
|
||||
#include <QPushButton>
|
||||
#include <QStringList>
|
||||
#include <QTreeWidget>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr int BINDING_COLUMN = 1;
|
||||
|
||||
struct PadButton {
|
||||
const char* id;
|
||||
const char* label;
|
||||
const char* default_binding;
|
||||
};
|
||||
|
||||
constexpr PadButton PAD_BUTTONS[] = {
|
||||
{"Up", "D-pad Up", "Up"},
|
||||
{"Down", "D-pad Down", "Down"},
|
||||
{"Left", "D-pad Left", "Left"},
|
||||
{"Right", "D-pad Right", "Right"},
|
||||
{"Triangle", "Triangle", "I"},
|
||||
{"Circle", "Circle", "L"},
|
||||
{"Cross", "Cross", "J"},
|
||||
{"Square", "Square", "K"},
|
||||
{"L1", "L1", "Q"},
|
||||
{"R1", "R1", "E"},
|
||||
{"L2", "L2", ""},
|
||||
{"R2", "R2", ""},
|
||||
{"L3", "L3", "Left Shift"},
|
||||
{"R3", "R3", "Left Ctrl"},
|
||||
{"Options", "Options", "Return"},
|
||||
{"TouchPad", "Touch pad", "Backspace"},
|
||||
};
|
||||
|
||||
QString KeypadName(int key) {
|
||||
if (key >= Qt::Key_0 && key <= Qt::Key_9) {
|
||||
return QStringLiteral("Keypad %1").arg(key - Qt::Key_0);
|
||||
}
|
||||
|
||||
switch (key) {
|
||||
case Qt::Key_Return:
|
||||
case Qt::Key_Enter: return QStringLiteral("Keypad Enter");
|
||||
case Qt::Key_Slash: return QStringLiteral("Keypad /");
|
||||
case Qt::Key_Asterisk: return QStringLiteral("Keypad *");
|
||||
case Qt::Key_Minus: return QStringLiteral("Keypad -");
|
||||
case Qt::Key_Plus: return QStringLiteral("Keypad +");
|
||||
case Qt::Key_Period: return QStringLiteral("Keypad .");
|
||||
case Qt::Key_Equal: return QStringLiteral("Keypad =");
|
||||
case Qt::Key_Comma: return QStringLiteral("Keypad ,");
|
||||
default: return {};
|
||||
}
|
||||
}
|
||||
|
||||
QString KeyName(const QKeyEvent& event) {
|
||||
const int key = event.key();
|
||||
if (event.modifiers().testFlag(Qt::KeypadModifier)) {
|
||||
return KeypadName(key);
|
||||
}
|
||||
if (key >= Qt::Key_A && key <= Qt::Key_Z) {
|
||||
return QChar(key);
|
||||
}
|
||||
if (key >= Qt::Key_0 && key <= Qt::Key_9) {
|
||||
return QChar(key);
|
||||
}
|
||||
if (key >= Qt::Key_F1 && key <= Qt::Key_F24) {
|
||||
return QStringLiteral("F%1").arg(key - Qt::Key_F1 + 1);
|
||||
}
|
||||
|
||||
switch (key) {
|
||||
case Qt::Key_Return:
|
||||
case Qt::Key_Enter: return QStringLiteral("Return");
|
||||
case Qt::Key_Backspace: return QStringLiteral("Backspace");
|
||||
case Qt::Key_Tab: return QStringLiteral("Tab");
|
||||
case Qt::Key_Shift: return QStringLiteral("Left Shift");
|
||||
case Qt::Key_Control: return QStringLiteral("Left Ctrl");
|
||||
case Qt::Key_Alt: return QStringLiteral("Left Alt");
|
||||
case Qt::Key_Meta: return QStringLiteral("Left GUI");
|
||||
case Qt::Key_Insert: return QStringLiteral("Insert");
|
||||
case Qt::Key_Delete: return QStringLiteral("Delete");
|
||||
case Qt::Key_Home: return QStringLiteral("Home");
|
||||
case Qt::Key_End: return QStringLiteral("End");
|
||||
case Qt::Key_PageUp: return QStringLiteral("PageUp");
|
||||
case Qt::Key_PageDown: return QStringLiteral("PageDown");
|
||||
case Qt::Key_Left: return QStringLiteral("Left");
|
||||
case Qt::Key_Right: return QStringLiteral("Right");
|
||||
case Qt::Key_Up: return QStringLiteral("Up");
|
||||
case Qt::Key_Down: return QStringLiteral("Down");
|
||||
case Qt::Key_CapsLock: return QStringLiteral("CapsLock");
|
||||
case Qt::Key_NumLock: return QStringLiteral("Numlock");
|
||||
case Qt::Key_ScrollLock: return QStringLiteral("ScrollLock");
|
||||
case Qt::Key_Pause: return QStringLiteral("Pause");
|
||||
case Qt::Key_Print: return QStringLiteral("PrintScreen");
|
||||
default: break;
|
||||
}
|
||||
|
||||
if (event.modifiers() != Qt::NoModifier) {
|
||||
return {};
|
||||
}
|
||||
const auto name = QKeySequence(key).toString(QKeySequence::PortableText);
|
||||
return name.size() == 1 ? name : QString();
|
||||
}
|
||||
|
||||
class InputCaptureDialog final: public QDialog {
|
||||
public:
|
||||
explicit InputCaptureDialog(QWidget* parent): QDialog(parent) {
|
||||
setWindowTitle(tr("Set Binding"));
|
||||
setModal(true);
|
||||
setMinimumWidth(360);
|
||||
|
||||
auto* layout = new QVBoxLayout(this);
|
||||
m_label = new QLabel(
|
||||
tr("Press a key or mouse button.\nSpace and F1 are reserved; Esc cancels."), this);
|
||||
m_label->setAlignment(Qt::AlignCenter);
|
||||
layout->addWidget(m_label);
|
||||
}
|
||||
|
||||
[[nodiscard]] const QString& Binding() const { return m_binding; }
|
||||
|
||||
protected:
|
||||
void keyPressEvent(QKeyEvent* event) override {
|
||||
if (event->isAutoRepeat()) {
|
||||
return;
|
||||
}
|
||||
if (event->key() == Qt::Key_Escape) {
|
||||
reject();
|
||||
return;
|
||||
}
|
||||
if (event->key() == Qt::Key_Space || event->key() == Qt::Key_F1) {
|
||||
m_label->setText(tr("That key is reserved by the emulator."));
|
||||
return;
|
||||
}
|
||||
|
||||
m_binding = KeyName(*event);
|
||||
if (!m_binding.isEmpty()) {
|
||||
accept();
|
||||
} else {
|
||||
m_label->setText(tr("That key is not supported."));
|
||||
}
|
||||
}
|
||||
|
||||
void mousePressEvent(QMouseEvent* event) override {
|
||||
switch (event->button()) {
|
||||
case Qt::LeftButton: m_binding = QStringLiteral("Mouse:Left"); break;
|
||||
case Qt::RightButton: m_binding = QStringLiteral("Mouse:Right"); break;
|
||||
case Qt::MiddleButton: m_binding = QStringLiteral("Mouse:Middle"); break;
|
||||
case Qt::BackButton: m_binding = QStringLiteral("Mouse:X1"); break;
|
||||
case Qt::ForwardButton: m_binding = QStringLiteral("Mouse:X2"); break;
|
||||
default: return;
|
||||
}
|
||||
accept();
|
||||
}
|
||||
|
||||
private:
|
||||
QLabel* m_label = nullptr;
|
||||
QString m_binding;
|
||||
};
|
||||
|
||||
QHash<QString, QString> ParseMapping(const QStringList& mapping) {
|
||||
QHash<QString, QString> result;
|
||||
for (const auto& entry: mapping) {
|
||||
const auto separator = entry.indexOf(QLatin1Char('='));
|
||||
if (separator > 0 && separator + 1 < entry.size()) {
|
||||
const auto binding = entry.mid(separator + 1);
|
||||
for (auto item = result.begin(); item != result.end();) {
|
||||
if (item.value().compare(binding, Qt::CaseInsensitive) == 0) {
|
||||
item = result.erase(item);
|
||||
} else {
|
||||
++item;
|
||||
}
|
||||
}
|
||||
result.insert(entry.left(separator), binding);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
InputMappingDialog::InputMappingDialog(const QStringList& mapping, QWidget* parent)
|
||||
: QDialog(parent), m_customized(!mapping.isEmpty()) {
|
||||
setWindowTitle(tr("Input Mapping"));
|
||||
resize(440, 520);
|
||||
|
||||
auto* layout = new QVBoxLayout(this);
|
||||
layout->addWidget(new QLabel(tr("Map keyboard or mouse input to DualSense buttons.\n"
|
||||
"Defaults: left stick W/A/S/D, right stick T/F/G/H."),
|
||||
this));
|
||||
|
||||
m_bindings = new QTreeWidget(this);
|
||||
m_bindings->setColumnCount(2);
|
||||
m_bindings->setHeaderLabels({tr("DualSense button"), tr("Host input")});
|
||||
m_bindings->setRootIsDecorated(false);
|
||||
m_bindings->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
m_bindings->header()->setSectionResizeMode(0, QHeaderView::Stretch);
|
||||
m_bindings->header()->setSectionResizeMode(1, QHeaderView::Stretch);
|
||||
layout->addWidget(m_bindings);
|
||||
|
||||
const auto parsed = ParseMapping(mapping);
|
||||
for (const auto& button: PAD_BUTTONS) {
|
||||
auto* item = new QTreeWidgetItem(m_bindings);
|
||||
item->setText(0, tr(button.label));
|
||||
item->setData(0, Qt::UserRole, QString::fromLatin1(button.id));
|
||||
SetBinding(item, m_customized ? parsed.value(QString::fromLatin1(button.id))
|
||||
: QString::fromLatin1(button.default_binding));
|
||||
}
|
||||
m_bindings->setCurrentItem(m_bindings->topLevelItem(0));
|
||||
|
||||
auto* controls = new QHBoxLayout;
|
||||
m_change_button = new QPushButton(tr("Change..."), this);
|
||||
m_clear_button = new QPushButton(tr("Clear"), this);
|
||||
auto* defaults = new QPushButton(tr("Defaults"), this);
|
||||
controls->addWidget(m_change_button);
|
||||
controls->addWidget(m_clear_button);
|
||||
controls->addWidget(defaults);
|
||||
controls->addStretch();
|
||||
layout->addLayout(controls);
|
||||
|
||||
auto* buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
|
||||
layout->addWidget(buttons);
|
||||
|
||||
connect(m_bindings, &QTreeWidget::itemDoubleClicked, this,
|
||||
[this](QTreeWidgetItem*, int) { ChangeBinding(); });
|
||||
connect(m_bindings, &QTreeWidget::itemSelectionChanged, this, [this]() { UpdateButtons(); });
|
||||
connect(m_change_button, &QPushButton::clicked, this, [this]() { ChangeBinding(); });
|
||||
connect(m_clear_button, &QPushButton::clicked, this, [this]() { ClearBinding(); });
|
||||
connect(defaults, &QPushButton::clicked, this, [this]() { RestoreDefaults(); });
|
||||
connect(buttons, &QDialogButtonBox::accepted, this, &QDialog::accept);
|
||||
connect(buttons, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
||||
UpdateButtons();
|
||||
}
|
||||
|
||||
QStringList InputMappingDialog::Mapping() const {
|
||||
QStringList result;
|
||||
if (!m_customized) {
|
||||
return result;
|
||||
}
|
||||
for (int index = 0; index < m_bindings->topLevelItemCount(); index++) {
|
||||
const auto* item = m_bindings->topLevelItem(index);
|
||||
const auto binding = item->data(BINDING_COLUMN, Qt::UserRole).toString();
|
||||
if (!binding.isEmpty()) {
|
||||
result.append(item->data(0, Qt::UserRole).toString() + QLatin1Char('=') + binding);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void InputMappingDialog::ChangeBinding() {
|
||||
auto* item = m_bindings->currentItem();
|
||||
if (item == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
InputCaptureDialog dialog(this);
|
||||
if (dialog.exec() != QDialog::Accepted) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int index = 0; index < m_bindings->topLevelItemCount(); index++) {
|
||||
auto* other = m_bindings->topLevelItem(index);
|
||||
if (other != item && other->data(BINDING_COLUMN, Qt::UserRole)
|
||||
.toString()
|
||||
.compare(dialog.Binding(), Qt::CaseInsensitive) == 0) {
|
||||
SetBinding(other, {});
|
||||
}
|
||||
}
|
||||
SetBinding(item, dialog.Binding());
|
||||
m_customized = true;
|
||||
}
|
||||
|
||||
void InputMappingDialog::ClearBinding() {
|
||||
SetBinding(m_bindings->currentItem(), {});
|
||||
m_customized = true;
|
||||
}
|
||||
|
||||
void InputMappingDialog::RestoreDefaults() {
|
||||
for (int index = 0; index < m_bindings->topLevelItemCount(); index++) {
|
||||
SetBinding(m_bindings->topLevelItem(index),
|
||||
QString::fromLatin1(PAD_BUTTONS[index].default_binding));
|
||||
}
|
||||
m_customized = false;
|
||||
}
|
||||
|
||||
void InputMappingDialog::SetBinding(QTreeWidgetItem* item, const QString& binding) {
|
||||
if (item == nullptr) {
|
||||
return;
|
||||
}
|
||||
item->setData(BINDING_COLUMN, Qt::UserRole, binding);
|
||||
item->setText(BINDING_COLUMN, binding.isEmpty() ? tr("None") : binding);
|
||||
UpdateButtons();
|
||||
}
|
||||
|
||||
void InputMappingDialog::UpdateButtons() {
|
||||
if (m_change_button == nullptr) {
|
||||
return;
|
||||
}
|
||||
const auto* item = m_bindings->currentItem();
|
||||
m_change_button->setEnabled(item != nullptr);
|
||||
m_clear_button->setEnabled(item != nullptr &&
|
||||
!item->data(BINDING_COLUMN, Qt::UserRole).toString().isEmpty());
|
||||
}
|
||||
@@ -204,6 +204,9 @@ static QStringList CreateEmulatorArgs(const Configuration& info) {
|
||||
|
||||
args << "--screen-width" << r.at(0);
|
||||
args << "--screen-height" << r.at(1);
|
||||
if (info.fullscreen_enabled) {
|
||||
args << "--fullscreen";
|
||||
}
|
||||
args << "--vblank-frequency" << QString::number(info.vblank_frequency);
|
||||
args << "--console-language" << QString::number(info.console_language);
|
||||
args << "--vulkan-validation" << BoolArg(info.vulkan_validation_enabled);
|
||||
@@ -217,6 +220,14 @@ static QStringList CreateEmulatorArgs(const Configuration& info) {
|
||||
args << "--printf-output-file" << info.printf_output_file;
|
||||
args << "--profiler-direction" << EnumToText(info.profiler_direction);
|
||||
args << "--spirv-debug-printf" << "false";
|
||||
#if defined(_WIN32)
|
||||
if (info.red_zone_protection_enabled) {
|
||||
args << "--redzone";
|
||||
}
|
||||
#endif
|
||||
for (const auto& binding: info.host_input_mapping) {
|
||||
args << "--keymap" << binding;
|
||||
}
|
||||
if (info.renderdoc_enabled) {
|
||||
args << "--rd";
|
||||
}
|
||||
@@ -435,7 +446,10 @@ void MainDialogPrivate::Run() {
|
||||
|
||||
m_running_item->SetRunning(true);
|
||||
|
||||
m_main_dialog->RunInterpreter(&m_process, m_running_item->GetInfo());
|
||||
Configuration info;
|
||||
info.CopyFrom(m_running_item->GetInfo());
|
||||
info.host_input_mapping = m_ui->widget->GetHostInputMapping();
|
||||
m_main_dialog->RunInterpreter(&m_process, info);
|
||||
|
||||
Update();
|
||||
}
|
||||
|
||||
Loaded 100 of 130 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user