diff --git a/CMakeLists.txt b/CMakeLists.txt index 8a52dd7e1..d48667a77 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,6 +28,7 @@ if(MSVC) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MP") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP") endif() +set(DIVE_REPO_DIR "${CMAKE_CURRENT_SOURCE_DIR}") set(THIRDPARTY_DIRECTORY "${CMAKE_SOURCE_DIR}/third_party") # TODO: b/462767957 - remove set(CMAKE_INSTALL_PREFIX ...) once we fix search path and mac build. set(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/install") @@ -110,10 +111,6 @@ if(ANDROID) message(CHECK_PASS "done") endif() -# ------------------------------------------------------------------------------ -# For generated headers -include_directories(${CMAKE_CURRENT_BINARY_DIR}/dive_core) - # ------------------------------------------------------------------------------ # Determine if third-party libraries should be built for the current target diff --git a/cli/CMakeLists.txt b/cli/CMakeLists.txt index 6fc098c21..694ac6542 100644 --- a/cli/CMakeLists.txt +++ b/cli/CMakeLists.txt @@ -58,7 +58,10 @@ target_link_libraries( ) add_executable(${PROJECT_NAME} "main.cpp") -target_link_libraries(${PROJECT_NAME} PRIVATE ${PROJECT_NAME}_lib) +target_link_libraries( + ${PROJECT_NAME} + PRIVATE ${PROJECT_NAME}_lib dive_src_includes +) if(MSVC) # 4100: unreferenced formal parameter diff --git a/cli/main.cpp b/cli/main.cpp index 521183c4b..367b7cfc7 100644 --- a/cli/main.cpp +++ b/cli/main.cpp @@ -16,14 +16,14 @@ #include #include "commands.h" -#include "pm4_info.h" +#include "dive/isa/isa.h" using namespace Dive::cli; // NOLINT int main(int argc, char** argv) { Dive::cli::Init(); - Pm4InfoInit(); + Dive::InitPm4(); std::map commands; std::vector commandlist = { diff --git a/dive_core/CMakeLists.txt b/dive_core/CMakeLists.txt index b7159e839..268063796 100644 --- a/dive_core/CMakeLists.txt +++ b/dive_core/CMakeLists.txt @@ -33,106 +33,11 @@ endif() # MSVC set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) -set(DIVE_CORE_GENERATED_FILE_DIR "${CMAKE_CURRENT_BINARY_DIR}") -set(PM4_INFO_FILE "${DIVE_CORE_GENERATED_FILE_DIR}/pm4_info") -set(PM4_GENERATED_SRC_FILE "${DIVE_CORE_GENERATED_FILE_DIR}/pm4_info.cpp") -set(PM4_GENERATED_HDR_FILE "${DIVE_CORE_GENERATED_FILE_DIR}/pm4_info.h") -set(ADRENO_HDR_FILE "${DIVE_CORE_GENERATED_FILE_DIR}/adreno.h") -set(A6XX_PY_FILE "${DIVE_CORE_GENERATED_FILE_DIR}/a6xx.py") -set(FREEDRENO_ISA_DIRECTORY "${DIVE_CORE_GENERATED_FILE_DIR}/freedreno/isa") -set(FREEDRENO_DEVICES_HDR_FILE "${FREEDRENO_ISA_DIRECTORY}/freedreno_devices.h") -set(FREEDRENO_IR3_ISA_SRC_FILE "${FREEDRENO_ISA_DIRECTORY}/ir3-isa.c") -set(FREEDRENO_IR3_ISA_HDR_FILE "${FREEDRENO_ISA_DIRECTORY}/ir3-isa.h") - -if(WIN32) - set(Python3_FIND_REGISTRY "NEVER") -endif() # WIN32 -find_package(Python3 COMPONENTS Interpreter) - -if(NOT Python3_EXECUTABLE) - message(FATAL_ERROR "python3 not found") -endif() # NOT Python3_EXECUTABLE - -add_custom_command( - OUTPUT ${PM4_GENERATED_HDR_FILE} ${PM4_GENERATED_SRC_FILE} - COMMAND - ${Python3_EXECUTABLE} - ${CMAKE_CURRENT_SOURCE_DIR}/generatePm4Info_adreno.py - "${THIRDPARTY_DIRECTORY}/mesa/src/freedreno/registers" "adreno/a6xx.xml" - ${PM4_INFO_FILE} - DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/generatePm4Info_adreno.py" - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - VERBATIM -) -add_custom_target( - pm4_info - ALL - DEPENDS ${PM4_GENERATED_HDR_FILE} ${PM4_GENERATED_SRC_FILE} -) - -add_custom_command( - OUTPUT ${ADRENO_HDR_FILE} - COMMAND - ${Python3_EXECUTABLE} - ${CMAKE_CURRENT_SOURCE_DIR}/generateAdrenoHeader.py - "${THIRDPARTY_DIRECTORY}/mesa/src/freedreno/registers" "adreno/a6xx.xml" - ${ADRENO_HDR_FILE} - DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/generateAdrenoHeader.py" - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - VERBATIM -) -add_custom_target(adreno_header ALL DEPENDS ${ADRENO_HDR_FILE}) - -add_custom_command( - OUTPUT ${A6XX_PY_FILE} - COMMAND - ${Python3_EXECUTABLE} - ${THIRDPARTY_DIRECTORY}/mesa/src/freedreno/registers/gen_header.py - "--rnn" "${THIRDPARTY_DIRECTORY}/mesa/src/freedreno/registers" "--xml" - "${THIRDPARTY_DIRECTORY}/mesa/src/freedreno/registers/adreno/a6xx.xml" - "py-defines" > ${A6XX_PY_FILE} - DEPENDS "${THIRDPARTY_DIRECTORY}/mesa/src/freedreno/registers/gen_header.py" - WORKING_DIRECTORY ${THIRDPARTY_DIRECTORY}/mesa/src/freedreno/registers - VERBATIM -) -add_custom_target(a6xx_py ALL DEPENDS ${A6XX_PY_FILE}) - -add_custom_command( - OUTPUT ${FREEDRENO_DEVICES_HDR_FILE} - COMMAND - ${Python3_EXECUTABLE} - ${THIRDPARTY_DIRECTORY}/mesa/src/freedreno/common/freedreno_devices.py - "-p" "${DIVE_CORE_GENERATED_FILE_DIR}" > ${FREEDRENO_DEVICES_HDR_FILE} - DEPENDS - "${THIRDPARTY_DIRECTORY}/mesa/src/freedreno/common/freedreno_devices.py" - "${A6XX_PY_FILE}" - VERBATIM -) -add_custom_target( - freedreno_devices_header - ALL - DEPENDS ${FREEDRENO_DEVICES_HDR_FILE} -) - -if(MSVC) - set_target_properties( - freedreno_devices_header - PROPERTIES FOLDER "freedreno" - ) -endif() # MSVC - -set(FREEDRENO_SRC_FILES - "${THIRDPARTY_DIRECTORY}/mesa/src/freedreno/common/freedreno_dev_info.c" -) - add_library(dive_core_includes INTERFACE) target_include_directories( dive_core_includes INTERFACE - ${CMAKE_SOURCE_DIR} - ${DIVE_CORE_GENERATED_FILE_DIR} - ${FREEDRENO_ISA_DIRECTORY} ${THIRDPARTY_DIRECTORY}/Vulkan-Headers/include ${THIRDPARTY_DIRECTORY}/mesa/src/freedreno/common ${THIRDPARTY_DIRECTORY}/mesa/src/ @@ -149,9 +54,6 @@ add_library( STATIC # Platform specific: $<$:event_state.natvis> - # Generated - ${PM4_GENERATED_SRC_FILE} - ${FREEDRENO_SRC_FILES} # Common common/common.h common/dive_capture_format.h @@ -207,7 +109,6 @@ add_library( shader_disassembly.h sqtt_ids.cpp sqtt_ids.h - stl_replacement.h struct_of_arrays.h ) @@ -216,110 +117,18 @@ add_dependencies(${PROJECT_NAME} adreno_header) add_dependencies(${PROJECT_NAME} a6xx_py) add_dependencies(${PROJECT_NAME} freedreno_devices_header) -target_link_libraries( - ${PROJECT_NAME} - PUBLIC dive_core_includes absl::no_destructor absl::strings -) - -make_directory("${FREEDRENO_ISA_DIRECTORY}") - -add_custom_command( - OUTPUT ${FREEDRENO_IR3_ISA_SRC_FILE} ${FREEDRENO_IR3_ISA_HDR_FILE} - COMMAND - ${Python3_EXECUTABLE} - ${THIRDPARTY_DIRECTORY}/mesa/src/compiler/isaspec/decode.py "--xml" - "${THIRDPARTY_DIRECTORY}/mesa/src/freedreno/isa/ir3.xml" "--out-c" - ${FREEDRENO_IR3_ISA_SRC_FILE} "--out-h" ${FREEDRENO_IR3_ISA_HDR_FILE} - DEPENDS - "${THIRDPARTY_DIRECTORY}/mesa/src/compiler/isaspec/decode.py" - "${THIRDPARTY_DIRECTORY}/mesa/src/freedreno/isa/ir3.xml" - VERBATIM -) - -add_library( - freedreno_ir3 - STATIC - ${FREEDRENO_IR3_ISA_SRC_FILE} - "${THIRDPARTY_DIRECTORY}/mesa/src/freedreno/ir3/disasm-a3xx.c" - "${THIRDPARTY_DIRECTORY}/mesa/src/compiler/isaspec/isaspec.c" - "${THIRDPARTY_DIRECTORY}/mesa/src/util/blob.c" - "${THIRDPARTY_DIRECTORY}/mesa/src/util/half_float.c" - "${THIRDPARTY_DIRECTORY}/mesa/src/util/hash_table.c" - "${THIRDPARTY_DIRECTORY}/mesa/src/util/log.c" - "${THIRDPARTY_DIRECTORY}/mesa/src/util/os_file.c" - "${THIRDPARTY_DIRECTORY}/mesa/src/util/os_misc.c" - "${THIRDPARTY_DIRECTORY}/mesa/src/util/ralloc.c" - "${THIRDPARTY_DIRECTORY}/mesa/src/util/simple_mtx.c" - "${THIRDPARTY_DIRECTORY}/mesa/src/util/softfloat.c" - "${THIRDPARTY_DIRECTORY}/mesa/src/util/u_call_once.c" - "${THIRDPARTY_DIRECTORY}/mesa/src/util/u_cpu_detect.c" - "${THIRDPARTY_DIRECTORY}/mesa/src/util/u_debug.c" - "${THIRDPARTY_DIRECTORY}/mesa/src/util/u_printf.c" - "${THIRDPARTY_DIRECTORY}/mesa/src/util/u_process.c" - "${THIRDPARTY_DIRECTORY}/mesa/src/util/u_thread.c" -) - -target_include_directories( - freedreno_ir3 - PRIVATE - "${THIRDPARTY_DIRECTORY}/mesa/include" - "${THIRDPARTY_DIRECTORY}/mesa/src" - "${THIRDPARTY_DIRECTORY}/mesa/src/compiler" - "${THIRDPARTY_DIRECTORY}/mesa/src/compiler/isaspec" - "${THIRDPARTY_DIRECTORY}/mesa/src/freedreno" - "${THIRDPARTY_DIRECTORY}/mesa/src/freedreno/common" - "${THIRDPARTY_DIRECTORY}/mesa/src/freedreno/isa" -) - -if(MSVC) - target_compile_definitions(freedreno_ir3 PRIVATE -DHAVE_STRUCT_TIMESPEC) - set_property(TARGET freedreno_ir3 PROPERTY C_STANDARD 11) # To support alignas - target_sources( - freedreno_ir3 - PRIVATE "${THIRDPARTY_DIRECTORY}/mesa/src/util/google_dive_ext.c" - ) - set_target_properties(freedreno_ir3 PROPERTIES FOLDER "freedreno") -elseif(UNIX AND NOT APPLE) - #set_source_files_properties(PROPERTIES LANGUAGE CXX - target_compile_definitions( - freedreno_ir3 - PRIVATE - -DHAVE_ENDIAN_H - -DHAVE_FUNC_ATTRIBUTE_PACKED - -DHAVE_STRUCT_TIMESPEC - -DHAVE_PTHREAD - -DHAVE_SYSCONF - -D_GNU_SOURCE - -DHAVE_SECURE_GETENV - ) -elseif(APPLE) - target_compile_definitions( - freedreno_ir3 - PRIVATE - -DHAVE_FUNC_ATTRIBUTE_PACKED - -DHAVE_STRUCT_TIMESPEC - -DHAVE_PTHREAD - -DHAVE_SYSCONF - -D_GNU_SOURCE - ) - target_sources( - freedreno_ir3 - PRIVATE - "${THIRDPARTY_DIRECTORY}/mesa/src/c11/impl/threads_posix.c" - "${THIRDPARTY_DIRECTORY}/mesa/src/c11/impl/time.c" - ) -endif() # MSVC +target_link_libraries(${PROJECT_NAME} PUBLIC absl::no_destructor absl::strings) -target_compile_options(freedreno_ir3 PRIVATE -fPIC) -add_dependencies(${PROJECT_NAME} freedreno_ir3) -target_link_libraries(${PROJECT_NAME} PRIVATE freedreno_ir3) +target_link_libraries(${PROJECT_NAME} PUBLIC dive_freedreno dive_lib_isa) # This is linked privately because gfxr contains X11 headers that contain preprocessor macros which cause collisions # gfxr_decode_ext_lib itself can't link gfxrecon_decode privately because it's a dependency of a target (gfxrecon-replay) that doesn't specify PRIVATE/PUBLIC target_link_libraries(${PROJECT_NAME} PRIVATE gfxr_decode_ext_lib) target_include_directories( ${PROJECT_NAME} - PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../third_party/gfxreconstruct/framework + PUBLIC + "${DIVE_REPO_DIR}" + ${CMAKE_CURRENT_SOURCE_DIR}/../third_party/gfxreconstruct/framework ) target_link_libraries(${PROJECT_NAME} PRIVATE string_utils) diff --git a/dive_core/capture_event_info.cpp b/dive_core/capture_event_info.cpp index fee93c609..3a37fd5d2 100644 --- a/dive_core/capture_event_info.cpp +++ b/dive_core/capture_event_info.cpp @@ -19,7 +19,7 @@ #include "capture_event_info.h" #include "dive_core/common/memory_manager_base.h" #include "dive_core/common/pm4_packets/me_pm4_packets.h" -#include "pm4_info.h" +#include "dive/isa/pm4_info.h" namespace Dive { @@ -538,4 +538,4 @@ std::optional Util::GetTopology(const IMemoryManager &mem_m }; } -} // namespace Dive \ No newline at end of file +} // namespace Dive diff --git a/dive_core/command_hierarchy.cpp b/dive_core/command_hierarchy.cpp index eeb62bb08..ec2e29e3a 100644 --- a/dive_core/command_hierarchy.cpp +++ b/dive_core/command_hierarchy.cpp @@ -29,7 +29,7 @@ #include "pm4_capture_data.h" #include "dive_strings.h" -#include "pm4_info.h" +#include "dive/isa/pm4_info.h" namespace Dive { diff --git a/dive_core/command_hierarchy.h b/dive_core/command_hierarchy.h index 8bcb6da64..364c979ba 100644 --- a/dive_core/command_hierarchy.h +++ b/dive_core/command_hierarchy.h @@ -32,7 +32,7 @@ #include "dive_core/common/dive_capture_format.h" #include "dive_core/common/emulate_pm4.h" #include "dive_core/common/pm4_packets/pfp_pm4_packets.h" -#include "dive_core/stl_replacement.h" +#include "dive/container/stl_replacement.h" // Forward declarations struct PacketInfo; diff --git a/dive_core/common/emulate_pm4.cpp b/dive_core/common/emulate_pm4.cpp index d49168120..2b967695d 100644 --- a/dive_core/common/emulate_pm4.cpp +++ b/dive_core/common/emulate_pm4.cpp @@ -19,14 +19,14 @@ #include // memcpy -#include "adreno.h" +#include "dive/isa/adreno.h" #include "common.h" #include "dive_capture_format.h" #include "dive_core/pm4_capture_data.h" -#include "dive_core/stl_replacement.h" +#include "dive/container/stl_replacement.h" #include "emulate_pm4.h" #include "memory_manager_base.h" -#include "pm4_info.h" +#include "dive/isa/pm4_info.h" #include #include diff --git a/dive_core/common/emulate_pm4.h b/dive_core/common/emulate_pm4.h index f7e324a09..99dd4e3d9 100644 --- a/dive_core/common/emulate_pm4.h +++ b/dive_core/common/emulate_pm4.h @@ -28,9 +28,9 @@ #pragma once #include #include -#include "adreno.h" +#include "dive/isa/adreno.h" #include "dive_core/common/pm4_packets/pfp_pm4_packets.h" -#include "dive_core/stl_replacement.h" +#include "dive/container/stl_replacement.h" #include "gpudefs.h" namespace Dive diff --git a/dive_core/data_core.cpp b/dive_core/data_core.cpp index 680bb3573..f7a4891ae 100644 --- a/dive_core/data_core.cpp +++ b/dive_core/data_core.cpp @@ -19,7 +19,7 @@ #include #include "dive_core/command_hierarchy.h" #include "dive_core/gfxr_vulkan_command_hierarchy.h" -#include "pm4_info.h" +#include "dive/isa/pm4_info.h" namespace Dive { diff --git a/dive_core/event_state.h b/dive_core/event_state.h index 8281c0311..71c10988d 100644 --- a/dive_core/event_state.h +++ b/dive_core/event_state.h @@ -25,7 +25,7 @@ #pragma once -#include "adreno.h" +#include "dive/isa/adreno.h" #include "common.h" #include "dive_core/common/gpudefs.h" #include "info_id.h" diff --git a/dive_core/pm4_capture_data.cpp b/dive_core/pm4_capture_data.cpp index 8292de2cb..77f6fc4e5 100644 --- a/dive_core/pm4_capture_data.cpp +++ b/dive_core/pm4_capture_data.cpp @@ -25,8 +25,8 @@ #include "archive.h" #include "dive_core/command_hierarchy.h" #include "dive_core/common/common.h" -#include "freedreno_dev_info.h" -#include "pm4_info.h" +#include "dive/isa/freedreno/dev_info.h" +#include "dive/isa/pm4_info.h" #include "gfxr_ext/decode/dive_file_processor.h" #include "third_party/gfxreconstruct/framework/generated/generated_vulkan_dive_consumer.h" #include "third_party/gfxreconstruct/framework/generated/generated_vulkan_decoder.h" diff --git a/dive_core/shader_disassembly.cpp b/dive_core/shader_disassembly.cpp index eeafb4f23..dc81c3fd1 100644 --- a/dive_core/shader_disassembly.cpp +++ b/dive_core/shader_disassembly.cpp @@ -20,7 +20,7 @@ #include #include "dive_core/common/memory_manager_base.h" -#include "pm4_info.h" +#include "dive/isa/pm4_info.h" #ifdef _MSC_VER # include diff --git a/lrz_validator/CMakeLists.txt b/lrz_validator/CMakeLists.txt index effc447d3..03de5fe29 100644 --- a/lrz_validator/CMakeLists.txt +++ b/lrz_validator/CMakeLists.txt @@ -41,7 +41,7 @@ include_directories( ) add_executable(${PROJECT_NAME} "main.cpp") -target_link_libraries(${PROJECT_NAME} PRIVATE dive_core) +target_link_libraries(${PROJECT_NAME} PRIVATE dive_core dive_src_includes) target_include_directories( ${PROJECT_NAME} PRIVATE ${THIRDPARTY_DIRECTORY}/gfxreconstruct/framework diff --git a/lrz_validator/main.cpp b/lrz_validator/main.cpp index 45b09de8b..e03992bfb 100644 --- a/lrz_validator/main.cpp +++ b/lrz_validator/main.cpp @@ -18,7 +18,7 @@ #include #include "dive_core/data_core.h" -#include "pm4_info.h" +#include "dive/isa/isa.h" bool ValidateLRZ(const Dive::CaptureMetadata &meta_data, const std::string &output_file_name) { @@ -143,7 +143,7 @@ bool ValidateLRZ(const Dive::CaptureMetadata &meta_data, const std::string &outp int main(int argc, char **argv) { - Pm4InfoInit(); + Dive::InitPm4(); // Handle args if ((argc != 2) && (argc != 3)) diff --git a/src/dive/CMakeLists.txt b/src/dive/CMakeLists.txt index aa058563a..7a2181a09 100644 --- a/src/dive/CMakeLists.txt +++ b/src/dive/CMakeLists.txt @@ -19,3 +19,4 @@ add_subdirectory(os) add_subdirectory(plugin) add_subdirectory(utils) add_subdirectory(common) +add_subdirectory(isa) diff --git a/dive_core/stl_replacement.h b/src/dive/container/stl_replacement.h similarity index 94% rename from dive_core/stl_replacement.h rename to src/dive/container/stl_replacement.h index 8ba1b70ed..8faee6513 100644 --- a/dive_core/stl_replacement.h +++ b/src/dive/container/stl_replacement.h @@ -15,6 +15,8 @@ */ #pragma once + +#include #include // Provides a replacement of some STL containers. The reason for this is that Windows DEBUG versions @@ -69,8 +71,8 @@ template class Vector } // namespace Dive -#include "stl_replacement.hpp" +#include "dive/container/stl_replacement_impl.h" // IWYU pragma: export template // using DiveVector = std::vector; -using DiveVector = Dive::Vector; \ No newline at end of file +using DiveVector = Dive::Vector; diff --git a/dive_core/stl_replacement.hpp b/src/dive/container/stl_replacement_impl.h similarity index 98% rename from dive_core/stl_replacement.hpp rename to src/dive/container/stl_replacement_impl.h index ef4697b2c..e1d5ef856 100644 --- a/dive_core/stl_replacement.hpp +++ b/src/dive/container/stl_replacement_impl.h @@ -13,8 +13,13 @@ See the License for the specific language governing permissions and limitations under the License. */ + +#pragma once + #include -#include "common/common.h" +#include + +#include "dive/container/stl_replacement.h" namespace Dive { @@ -89,7 +94,7 @@ template Vector::~Vector() //-------------------------------------------------------------------------------------------------- template Type &Vector::operator[](uint64_t i) const { - DIVE_ASSERT(i < m_size); + assert(i < m_size); return m_buffer[i]; } diff --git a/src/dive/isa/CMakeLists.txt b/src/dive/isa/CMakeLists.txt new file mode 100644 index 000000000..fa0f778d4 --- /dev/null +++ b/src/dive/isa/CMakeLists.txt @@ -0,0 +1,20 @@ +# +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +add_subdirectory(freedreno) + +add_library(dive_lib_isa isa.cpp isa.h pm4_info.h) +target_link_libraries(dive_lib_isa PUBLIC dive_src_includes) diff --git a/src/dive/isa/adreno.h b/src/dive/isa/adreno.h new file mode 100644 index 000000000..50be77ba4 --- /dev/null +++ b/src/dive/isa/adreno.h @@ -0,0 +1,19 @@ +/* +Copyright 2025 Google Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +#pragma once + +#include "dive/isa/freedreno/adreno.h" // IWYU pragma: export diff --git a/src/dive/isa/freedreno/CMakeLists.txt b/src/dive/isa/freedreno/CMakeLists.txt new file mode 100644 index 000000000..20e22eb7b --- /dev/null +++ b/src/dive/isa/freedreno/CMakeLists.txt @@ -0,0 +1,252 @@ +# +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +message(CHECK_START "Generate build files for src/freedreno") +if(ANDROID) + message(CHECK_FAIL "detected Android platform, skipping") + return() +endif() +list(APPEND CMAKE_MESSAGE_INDENT " ") + +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) + +set(DIVE_FREEDRENO_GENFILE_INCLUDE_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated") +set(DIVE_FREEDRENO_GENFILE_DIR + "${CMAKE_CURRENT_BINARY_DIR}/generated/dive/isa/freedreno" +) +set(PM4_INFO_FILE "${DIVE_FREEDRENO_GENFILE_DIR}/pm4_info") +set(PM4_GENERATED_SRC_FILE "${DIVE_FREEDRENO_GENFILE_DIR}/pm4_info.cpp") +set(PM4_GENERATED_HDR_FILE "${DIVE_FREEDRENO_GENFILE_DIR}/pm4_info.h") +set(ADRENO_HDR_FILE "${DIVE_FREEDRENO_GENFILE_DIR}/adreno.h") +set(A6XX_PY_FILE "${DIVE_FREEDRENO_GENFILE_DIR}/a6xx.py") +set(FREEDRENO_ISA_DIRECTORY "${DIVE_FREEDRENO_GENFILE_DIR}/freedreno/isa") +set(FREEDRENO_DEVICES_HDR_FILE "${FREEDRENO_ISA_DIRECTORY}/freedreno_devices.h") +set(FREEDRENO_IR3_ISA_SRC_FILE "${FREEDRENO_ISA_DIRECTORY}/ir3-isa.c") +set(FREEDRENO_IR3_ISA_HDR_FILE "${FREEDRENO_ISA_DIRECTORY}/ir3-isa.h") + +if(WIN32) + set(Python3_FIND_REGISTRY "NEVER") +endif() # WIN32 +find_package(Python3 COMPONENTS Interpreter) + +if(NOT Python3_EXECUTABLE) + message(FATAL_ERROR "python3 not found") +endif() # NOT Python3_EXECUTABLE + +add_custom_command( + OUTPUT ${PM4_GENERATED_HDR_FILE} ${PM4_GENERATED_SRC_FILE} + COMMAND + ${Python3_EXECUTABLE} + ${CMAKE_CURRENT_SOURCE_DIR}/generatePm4Info_adreno.py + "${THIRDPARTY_DIRECTORY}/mesa/src/freedreno/registers" "adreno/a6xx.xml" + ${PM4_INFO_FILE} + DEPENDS a6xx_py "${CMAKE_CURRENT_SOURCE_DIR}/generatePm4Info_adreno.py" + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + VERBATIM +) +add_custom_target( + pm4_info + ALL + DEPENDS ${PM4_GENERATED_HDR_FILE} ${PM4_GENERATED_SRC_FILE} +) + +add_custom_command( + OUTPUT ${ADRENO_HDR_FILE} + COMMAND + ${Python3_EXECUTABLE} + ${CMAKE_CURRENT_SOURCE_DIR}/generateAdrenoHeader.py + "${THIRDPARTY_DIRECTORY}/mesa/src/freedreno/registers" "adreno/a6xx.xml" + ${ADRENO_HDR_FILE} + DEPENDS a6xx_py "${CMAKE_CURRENT_SOURCE_DIR}/generateAdrenoHeader.py" + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + VERBATIM +) +add_custom_target(adreno_header ALL DEPENDS ${ADRENO_HDR_FILE}) + +add_custom_command( + OUTPUT ${A6XX_PY_FILE} + COMMAND + ${Python3_EXECUTABLE} + ${THIRDPARTY_DIRECTORY}/mesa/src/freedreno/registers/gen_header.py + "--rnn" "${THIRDPARTY_DIRECTORY}/mesa/src/freedreno/registers" "--xml" + "${THIRDPARTY_DIRECTORY}/mesa/src/freedreno/registers/adreno/a6xx.xml" + "py-defines" > ${A6XX_PY_FILE} + DEPENDS "${THIRDPARTY_DIRECTORY}/mesa/src/freedreno/registers/gen_header.py" + WORKING_DIRECTORY ${THIRDPARTY_DIRECTORY}/mesa/src/freedreno/registers + VERBATIM +) +add_custom_target(a6xx_py ALL DEPENDS ${A6XX_PY_FILE}) + +add_custom_command( + OUTPUT ${FREEDRENO_DEVICES_HDR_FILE} + COMMAND + ${Python3_EXECUTABLE} + ${THIRDPARTY_DIRECTORY}/mesa/src/freedreno/common/freedreno_devices.py + "-p" "${DIVE_CORE_GENERATED_FILE_DIR}" > ${FREEDRENO_DEVICES_HDR_FILE} + DEPENDS + "${THIRDPARTY_DIRECTORY}/mesa/src/freedreno/common/freedreno_devices.py" + "${A6XX_PY_FILE}" + WORKING_DIRECTORY "${DIVE_FREEDRENO_GENFILE_DIR}" + VERBATIM +) +add_custom_target( + freedreno_devices_header + ALL + DEPENDS ${FREEDRENO_DEVICES_HDR_FILE} +) + +if(MSVC) + set_target_properties( + freedreno_devices_header + PROPERTIES FOLDER "freedreno" + ) +endif() # MSVC + +set(FREEDRENO_SRC_FILES + "${THIRDPARTY_DIRECTORY}/mesa/src/freedreno/common/freedreno_dev_info.c" +) + +if(NOT MSVC AND NOT APPLE) + add_definitions(-DHAVE_ENDIAN_H) # Required for freedreno_dev_info.c on Linux +endif() # NOT MSVC AND NOT APPLE + +make_directory("${FREEDRENO_ISA_DIRECTORY}") + +add_custom_command( + OUTPUT ${FREEDRENO_IR3_ISA_SRC_FILE} ${FREEDRENO_IR3_ISA_HDR_FILE} + COMMAND + ${Python3_EXECUTABLE} + ${THIRDPARTY_DIRECTORY}/mesa/src/compiler/isaspec/decode.py "--xml" + "${THIRDPARTY_DIRECTORY}/mesa/src/freedreno/isa/ir3.xml" "--out-c" + ${FREEDRENO_IR3_ISA_SRC_FILE} "--out-h" ${FREEDRENO_IR3_ISA_HDR_FILE} + DEPENDS + "${THIRDPARTY_DIRECTORY}/mesa/src/compiler/isaspec/decode.py" + "${THIRDPARTY_DIRECTORY}/mesa/src/freedreno/isa/ir3.xml" + VERBATIM +) + +add_library( + freedreno_ir3 + STATIC + ${FREEDRENO_IR3_ISA_SRC_FILE} + ${FREEDRENO_IR3_ISA_HDR_FILE} + "${THIRDPARTY_DIRECTORY}/mesa/src/freedreno/ir3/disasm-a3xx.c" + "${THIRDPARTY_DIRECTORY}/mesa/src/compiler/isaspec/isaspec.c" + "${THIRDPARTY_DIRECTORY}/mesa/src/util/blob.c" + "${THIRDPARTY_DIRECTORY}/mesa/src/util/half_float.c" + "${THIRDPARTY_DIRECTORY}/mesa/src/util/hash_table.c" + "${THIRDPARTY_DIRECTORY}/mesa/src/util/log.c" + "${THIRDPARTY_DIRECTORY}/mesa/src/util/os_file.c" + "${THIRDPARTY_DIRECTORY}/mesa/src/util/os_misc.c" + "${THIRDPARTY_DIRECTORY}/mesa/src/util/ralloc.c" + "${THIRDPARTY_DIRECTORY}/mesa/src/util/simple_mtx.c" + "${THIRDPARTY_DIRECTORY}/mesa/src/util/softfloat.c" + "${THIRDPARTY_DIRECTORY}/mesa/src/util/u_call_once.c" + "${THIRDPARTY_DIRECTORY}/mesa/src/util/u_cpu_detect.c" + "${THIRDPARTY_DIRECTORY}/mesa/src/util/u_debug.c" + "${THIRDPARTY_DIRECTORY}/mesa/src/util/u_printf.c" + "${THIRDPARTY_DIRECTORY}/mesa/src/util/u_process.c" + "${THIRDPARTY_DIRECTORY}/mesa/src/util/u_thread.c" +) +add_dependencies(freedreno_ir3 freedreno_devices_header) + +target_compile_options(freedreno_ir3 PRIVATE -Wno-initializer-overrides) + +target_include_directories( + freedreno_ir3 + PRIVATE + "${DIVE_FREEDRENO_GENFILE_DIR}" + "${THIRDPARTY_DIRECTORY}/mesa/include" + "${THIRDPARTY_DIRECTORY}/mesa/src" + "${THIRDPARTY_DIRECTORY}/mesa/src/compiler" + "${THIRDPARTY_DIRECTORY}/mesa/src/compiler/isaspec" + "${THIRDPARTY_DIRECTORY}/mesa/src/freedreno" + "${THIRDPARTY_DIRECTORY}/mesa/src/freedreno/common" + "${THIRDPARTY_DIRECTORY}/mesa/src/freedreno/isa" +) + +if(MSVC) + target_compile_definitions(freedreno_ir3 PRIVATE -DHAVE_STRUCT_TIMESPEC) + set_property(TARGET freedreno_ir3 PROPERTY C_STANDARD 11) # To support alignas + target_sources( + freedreno_ir3 + PRIVATE "${THIRDPARTY_DIRECTORY}/mesa/src/util/google_dive_ext.c" + ) + set_target_properties(freedreno_ir3 PROPERTIES FOLDER "freedreno") +elseif(UNIX AND NOT APPLE) + #set_source_files_properties(PROPERTIES LANGUAGE CXX + target_compile_definitions( + freedreno_ir3 + PRIVATE + -DHAVE_ENDIAN_H + -DHAVE_FUNC_ATTRIBUTE_PACKED + -DHAVE_STRUCT_TIMESPEC + -DHAVE_PTHREAD + -DHAVE_SYSCONF + -D_GNU_SOURCE + -DHAVE_SECURE_GETENV + -DHAVE_PROGRAM_INVOCATION_NAME + ) +elseif(APPLE) + target_compile_definitions( + freedreno_ir3 + PRIVATE + -DHAVE_FUNC_ATTRIBUTE_PACKED + -DHAVE_STRUCT_TIMESPEC + -DHAVE_PTHREAD + -DHAVE_SYSCONF + -D_GNU_SOURCE + -DHAVE_PROGRAM_INVOCATION_NAME + ) + target_sources( + freedreno_ir3 + PRIVATE + "${THIRDPARTY_DIRECTORY}/mesa/src/c11/impl/threads_posix.c" + "${THIRDPARTY_DIRECTORY}/mesa/src/c11/impl/time.c" + ) +endif() # MSVC + +target_compile_options(freedreno_ir3 PRIVATE -fPIC) + +add_library( + dive_freedreno + STATIC + ${PM4_GENERATED_SRC_FILE} + ${FREEDRENO_SRC_FILES} +) + +target_link_libraries(dive_freedreno PUBLIC freedreno_ir3 dive_legacy_includes) + +target_include_directories( + dive_freedreno + PRIVATE + "${DIVE_FREEDRENO_GENFILE_DIR}" + "${FREEDRENO_ISA_DIRECTORY}" + "${THIRDPARTY_DIRECTORY}/Vulkan-Headers/include" + "${THIRDPARTY_DIRECTORY}/mesa/src/freedreno/common" + "${THIRDPARTY_DIRECTORY}/libarchive/libarchive/" + PUBLIC + "${DIVE_FREEDRENO_GENFILE_INCLUDE_DIR}" + "${THIRDPARTY_DIRECTORY}" + "${THIRDPARTY_DIRECTORY}/mesa/src/" + "${THIRDPARTY_DIRECTORY}/mesa/include/" +) + +target_compile_options(dive_freedreno PRIVATE -Wno-initializer-overrides) + +list(POP_BACK CMAKE_MESSAGE_INDENT) +message(CHECK_PASS "done") diff --git a/dive_core/common.py b/src/dive/isa/freedreno/common.py similarity index 100% rename from dive_core/common.py rename to src/dive/isa/freedreno/common.py diff --git a/src/dive/isa/freedreno/dev_info.h b/src/dive/isa/freedreno/dev_info.h new file mode 100644 index 000000000..54fc742e4 --- /dev/null +++ b/src/dive/isa/freedreno/dev_info.h @@ -0,0 +1,20 @@ +/* +Copyright 2025 Google Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +#pragma once + +// third_party/mesa/src/freedreno/common/freedreno_dev_info.h +#include "mesa/src/freedreno/common/freedreno_dev_info.h" // IWYU pragma: export diff --git a/dive_core/generateAdrenoHeader.py b/src/dive/isa/freedreno/generateAdrenoHeader.py similarity index 100% rename from dive_core/generateAdrenoHeader.py rename to src/dive/isa/freedreno/generateAdrenoHeader.py diff --git a/dive_core/generatePm4Info_adreno.py b/src/dive/isa/freedreno/generatePm4Info_adreno.py similarity index 99% rename from dive_core/generatePm4Info_adreno.py rename to src/dive/isa/freedreno/generatePm4Info_adreno.py index 6edaf3c2c..5003d24d0 100644 --- a/dive_core/generatePm4Info_adreno.py +++ b/src/dive/isa/freedreno/generatePm4Info_adreno.py @@ -45,7 +45,7 @@ def outputH(pm4_info_file): #include #include -#include "dive_core/stl_replacement.h" +#include "dive/container/stl_replacement.h" enum ValueType { @@ -158,7 +158,6 @@ def outputHeaderCpp(pm4_info_header_file_name, pm4_info_file): #include #include #include -#include "dive_core/common/common.h" static DiveVector g_sOpCodeToString; static std::unordered_map g_sRegInfoVariant; @@ -171,6 +170,8 @@ def outputHeaderCpp(pm4_info_header_file_name, pm4_info_file): static GPUVariantType g_sGPU_variant = kGPUVariantNone; static uint32_t g_sGPU_id = 0; +#define FREEDRENO_DIVE_ASSERT(x) assert(x) + std::string GetGPUStr(GPUVariantType variant) { std::string s; @@ -185,7 +186,7 @@ def outputHeaderCpp(pm4_info_header_file_name, pm4_info_file): case kA8XX: s = "A8XX"; break; case kGPUVariantNone: default: - DIVE_ASSERT(false); + FREEDRENO_DIVE_ASSERT(false); break; } return s; @@ -982,7 +983,7 @@ def outputFunctionsCpp(pm4_info_file): uint32_t GetRegOffsetByName(const char *name) { - DIVE_ASSERT(g_sGPU_variant != kGPUVariantNone); + FREEDRENO_DIVE_ASSERT(g_sGPU_variant != kGPUVariantNone); std::string str = std::string(name); auto i = g_sRegNameToIndex.find(str); if (i == g_sRegNameToIndex.end()) @@ -1064,7 +1065,7 @@ def outputFunctionsCpp(pm4_info_file): bool IsFieldEnabled(const RegField* field) { - DIVE_ASSERT(g_sGPU_variant != kGPUVariantNone); + FREEDRENO_DIVE_ASSERT(g_sGPU_variant != kGPUVariantNone); return (g_sGPU_variant & field->m_gpu_variants) != 0; } ''' diff --git a/src/dive/isa/isa.cpp b/src/dive/isa/isa.cpp new file mode 100644 index 000000000..890786c9e --- /dev/null +++ b/src/dive/isa/isa.cpp @@ -0,0 +1,33 @@ +/* +Copyright 2025 Google Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +#include "dive/isa/isa.h" + +extern void Pm4InfoInit(); + +namespace Dive +{ + +void InitPm4() +{ + static const int once = []() { + Pm4InfoInit(); + return 0; + }(); + (void)once; +} + +} // namespace Dive diff --git a/src/dive/isa/isa.h b/src/dive/isa/isa.h new file mode 100644 index 000000000..bf8a7887f --- /dev/null +++ b/src/dive/isa/isa.h @@ -0,0 +1,24 @@ +/* +Copyright 2025 Google Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +#pragma once + +namespace Dive +{ + +void InitPm4(); + +} // namespace Dive diff --git a/src/dive/isa/pm4_info.h b/src/dive/isa/pm4_info.h new file mode 100644 index 000000000..3a938357a --- /dev/null +++ b/src/dive/isa/pm4_info.h @@ -0,0 +1,19 @@ +/* +Copyright 2025 Google Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +#pragma once + +#include "dive/isa/freedreno/pm4_info.h" // IWYU pragma: export diff --git a/trace_stats/main.cpp b/trace_stats/main.cpp index fb279d191..40c7c7e07 100644 --- a/trace_stats/main.cpp +++ b/trace_stats/main.cpp @@ -24,11 +24,11 @@ #include "dive_core/context.h" #include "dive_core/data_core.h" #include "trace_stats.h" -#include "pm4_info.h" +#include "dive/isa/isa.h" int main(int argc, char **argv) { - Pm4InfoInit(); + Dive::InitPm4(); // Handle args if ((argc != 2) && (argc != 3)) diff --git a/ui/main.cpp b/ui/main.cpp index 4220e2ab7..49537551e 100644 --- a/ui/main.cpp +++ b/ui/main.cpp @@ -28,7 +28,6 @@ #include #include #include "dive_core/common.h" -#include "dive_core/pm4_info.h" #include "application_controller.h" #include "main_window.h" #include "utils/version_info.h" @@ -39,6 +38,7 @@ #include "absl/flags/parse.h" #include "absl/flags/usage.h" #include "absl/flags/usage_config.h" +#include "dive/isa/isa.h" #include "dive/os/terminal.h" #ifdef __linux__ # include @@ -350,7 +350,7 @@ int main(int argc, char *argv[]) splash_screen->show(); // Initialize packet info query data structures needed for parsing - Pm4InfoInit(); + Dive::InitPm4(); ApplicationController controller; MainWindow *main_window = new MainWindow(controller);