Skip to content

Commit

Permalink
Merge branch 'clshortfuse:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
marat569 authored Jan 11, 2025
2 parents 67a3a14 + ea42a65 commit d310f20
Show file tree
Hide file tree
Showing 225 changed files with 111,112 additions and 7,978 deletions.
29 changes: 11 additions & 18 deletions .github/workflows/cmake-ninja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@ name: CMake (Ninja)
on:
push:
branches: [main]
paths-ignore:
- "**/*.md"
- "**/*.json"
- "docs/**"
pull_request:
branches: [main]
paths-ignore:
- "**/*.md"
- "**/*.json"
- "docs/**"

jobs:
build:
Expand All @@ -26,9 +34,6 @@ jobs:
- name: Configure CMake (x64)
run: cmake --preset ninja-x64

- name: Build (x64)
run: cmake --build --preset ninja-x64-release --verbose

- name: Build RelWithDebInfo (x64)
run: cmake --build --preset ninja-x64-relwithdebinfo --verbose

Expand All @@ -40,32 +45,20 @@ jobs:
- name: Configure CMake (x86)
run: cmake --preset ninja-x86

- name: Build (x86)
run: cmake --build --preset ninja-x86-release --verbose

- name: Build RelWithDebInfo (x86)
run: cmake --build --preset ninja-x86-relwithdebinfo --verbose

- name: Prepare Web Listing
run: md www

- name: Copy Binaries (x64)
run: copy build\Release\*.addon64 www\
run: copy build\RelWithDebInfo\*.addon64 www\

- name: Copy Binaries (x86)
run: copy build32\Release\*.addon32 www\
run: copy build32\RelWithDebInfo\*.addon32 www\

- name: Copy Binaries (Tools)
run: copy build\Release\*.exe www\

- name: Prepare Debug Web Listing
run: md www\debug

- name: Copy RelWithDebInfo Binaries (x64)
run: copy build\RelWithDebInfo\*.addon64 www\debug\

- name: Copy RelWithDebInfo Binaries (x86)
run: copy build32\RelWithDebInfo\*.addon32 www\debug\
run: copy build\RelWithDebInfo\*.exe www\

- name: Upload artifact
uses: actions/upload-pages-artifact@v1
Expand Down
18 changes: 18 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "(msvc) Attach",
"type": "cppvsdbg",
"request": "attach",
"processId": "${command:pickProcess}"
},
],
"inputs": [
{
"type": "promptString",
"id": "launchExecutable",
"description": "Select executable to launch"
}
]
}
52 changes: 28 additions & 24 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ enable_testing()
add_executable(embedfile embedfile.cpp)
add_executable(decomp ./src/decompiler/cli.cpp)

function(inspect_hlsl_imports FILE VARIABLE)
function(inspect_hlsl_imports FILE VARIABLE REQUESTING_FILE)
unset(CACHE_ENTRY)
set(HLSL_CACHE_VAR HLSL_CACHE_${FILE})
get_property(CACHE_ENTRY GLOBAL PROPERTY ${HLSL_CACHE_VAR})
Expand All @@ -39,7 +39,7 @@ function(inspect_hlsl_imports FILE VARIABLE)
unset(CACHE_ENTRY)
if(EMPTY_CACHE_ENTRY)
# message(${FILE} " - Is zero dependency file")
else()
elseif(EXISTS ${FILE})
# message(${FILE} " - EMPTY_CACHE_ENTRY Result: " ${EMPTY_CACHE_ENTRY})
file(STRINGS ${FILE} HLSL_IMPORTS REGEX "^#include \"([^\"]+)\"")
foreach(IMPORT_LINE ${HLSL_IMPORTS})
Expand All @@ -52,7 +52,7 @@ function(inspect_hlsl_imports FILE VARIABLE)
#message(${FILE} " - Added: " ${HLSL_PATH})
# message(${FILE} " - List: " ${CACHE_ENTRY})
# recursive
inspect_hlsl_imports(${HLSL_PATH} CHILD_DEPENDENCIES)
inspect_hlsl_imports(${HLSL_PATH} CHILD_DEPENDENCIES ${FILE})
# message(${FILE} " - Adding children from " ${HLSL_PATH} ": " ${TEMP_CACHE_ENTRY})
list(APPEND CACHE_ENTRY ${CHILD_DEPENDENCIES})
# message(${FILE} " - Added children from " ${HLSL_PATH} ": " ${CACHE_ENTRY})
Expand All @@ -64,6 +64,8 @@ function(inspect_hlsl_imports FILE VARIABLE)
set_property(GLOBAL PROPERTY HLSL_CACHE_EMPTY_${FILE} "TRUE")
# message(${FILE} " -Marking zero dependency")
endif()
else()
message(FATAL_ERROR "Failed to parse " ${REQUESTING_FILE} " " ${FILE} " does not exist.")
endif()
endif()

Expand All @@ -76,7 +78,7 @@ function(build_shader_target ADDON ADDON_PATH)
set(EMBED_FOLDER ${CMAKE_CURRENT_BINARY_DIR}/${ADDON}.include/embed)
unset(SHADER_BINARIES)

file(GLOB SHADER_SOURCES ${ADDON_PATH}/*.hlsl)
file(GLOB_RECURSE SHADER_SOURCES ${ADDON_PATH}/*.hlsl)
foreach(FILE ${SHADER_SOURCES})
cmake_path(GET FILE FILENAME FILENAME)
cmake_path(GET FILE PARENT_PATH TARGET_PATH)
Expand All @@ -91,23 +93,29 @@ function(build_shader_target ADDON ADDON_PATH)

if(SHADER_TARGET AND (SHADER_HASH OR SHADER_NAME))
string(SUBSTRING ${SHADER_TARGET} 3 1 SHADER_TARGET_MAJOR)
string(SUBSTRING ${SHADER_TARGET} 5 1 SHADER_TARGET_MINOR)
set(SHADER_COMPILER ${FXC_BIN})
if(SHADER_TARGET_MAJOR EQUAL "6")
unset(SHADER_FLAGS)
if(SHADER_TARGET_MAJOR GREATER_EQUAL "6")
set(SHADER_COMPILER ${DXC_BIN})
set(SHADER_FLAGS "/HV 2021")
elseif(SHADER_TARGET_MAJOR EQUAL "5")
if(SHADER_TARGET_MINOR EQUAL "0")
set(SHADER_FLAGS "/Gec")
endif()
set(SHADER_FLAGS "/HV 2021") # Ovewrite flags
else()
set(SHADER_FLAGS "/Gec") # Compatibility mode
set(SHADER_FLAGS ${SHADER_FLAGS} /D __SHADER_TARGET_MAJOR=${SHADER_TARGET_MAJOR})
set(SHADER_FLAGS ${SHADER_FLAGS} /D __SHADER_TARGET_MINOR=${SHADER_TARGET_MINOR})
if(SHADER_TARGET_MAJOR EQUAL "5")
if(SHADER_TARGET_MINOR EQUAL "0")
set(SHADER_FLAGS ${SHADER_FLAGS} /Gec)
endif()
else()
set(SHADER_FLAGS ${SHADER_FLAGS} /Gec)
endif()
endif()

unset(HLSL_DEPENDENCIES)
unset(HLSL_CHILD_DEPENDENCIES)
list(APPEND HLSL_DEPENDENCIES ${FILE})
# message("Building HLSL dependencies for " ${FILE})
inspect_hlsl_imports(${FILE} HLSL_CHILD_DEPENDENCIES)
inspect_hlsl_imports(${FILE} HLSL_CHILD_DEPENDENCIES ".")
list(APPEND HLSL_DEPENDENCIES ${HLSL_CHILD_DEPENDENCIES})
if(SHADER_HASH)
# message("Registering: " ${FILE} " => " ${EMBED_FOLDER}/${SHADER_HASH}.cso)
Expand All @@ -129,7 +137,7 @@ function(build_shader_target ADDON ADDON_PATH)
endforeach()


file(GLOB SHADER_CSO_FILES ${ADDON_PATH}/*.cso)
file(GLOB_RECURSE SHADER_CSO_FILES ${ADDON_PATH}/*.cso)
foreach(FILE ${SHADER_CSO_FILES})
cmake_path(GET FILE FILENAME FILENAME)
cmake_path(GET FILE PARENT_PATH TARGET_PATH)
Expand All @@ -150,7 +158,7 @@ function(build_shader_target ADDON ADDON_PATH)
endif()
endforeach()

file(GLOB SHADER_SPV_FILES ${ADDON_PATH}/*.spv)
file(GLOB_RECURSE SHADER_SPV_FILES ${ADDON_PATH}/*.spv)
foreach(FILE ${SHADER_SPV_FILES})
cmake_path(GET FILE FILENAME FILENAME)
cmake_path(GET FILE PARENT_PATH TARGET_PATH)
Expand All @@ -171,6 +179,7 @@ function(build_shader_target ADDON ADDON_PATH)
endif()
endforeach()

unset(SHADERS_H_OUTPUT)
foreach(FILE ${SHADER_BINARIES})
cmake_path(GET FILE STEM LAST_ONLY FILENAME)
add_custom_command(
Expand All @@ -179,25 +188,21 @@ function(build_shader_target ADDON ADDON_PATH)
DEPENDS ${FILE}
)
list(APPEND SHADER_HEADER_FILES ${EMBED_FOLDER}/${FILENAME}.h)
string(APPEND SHADERS_H_OUTPUT "#include \"./${FILENAME}.h\"\n")
endforeach()


list(JOIN SHADER_HEADER_FILES " " SHADER_HEADER_FILE_ITEMS)
add_custom_target(${ADDON}-shaders DEPENDS ${SHADER_HEADER_FILES})

if(SHADER_HEADER_FILES)
add_custom_target(${ADDON}-shaders-packed DEPENDS ${EMBED_FOLDER}/shaders.h)
add_custom_command(
OUTPUT ${EMBED_FOLDER}/shaders.h
COMMAND ${CMAKE_COMMAND} -E cat ${SHADER_HEADER_FILES} > ${EMBED_FOLDER}/shaders.h
DEPENDS ${SHADER_HEADER_FILES}
)
else()
add_custom_target(${ADDON}-shaders-packed)

if(SHADERS_H_OUTPUT)
file(GENERATE OUTPUT ${EMBED_FOLDER}/shaders.h CONTENT "${SHADERS_H_OUTPUT}")
endif()
endfunction()

if(CMAKE_GENERATOR_PLATFORM STREQUAL "Win32" OR CMAKE_EXE_LINKER_FLAGS MATCHES "/machine:X86")
message("Building 32" ${CMAKE_GENERATOR_PLATFORM} ${CMAKE_EXE_LINKER_FLAGS})
set(TARGET_SUFFIX ".addon32")
else()
set(TARGET_SUFFIX ".addon64")
Expand All @@ -211,7 +216,6 @@ foreach(FILE ${ADDON_FILES})
add_library(${ADDON} MODULE ${FILE})
build_shader_target(${ADDON} ${CMAKE_CURRENT_SOURCE_DIR}/src/games/${ADDON})
add_dependencies(${ADDON} ${ADDON}-shaders)
add_dependencies(${ADDON} ${ADDON}-shaders-packed)
target_include_directories(${ADDON} SYSTEM PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/external/reshade)
target_include_directories(${ADDON} SYSTEM PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_include_directories(${ADDON} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/${ADDON}.include)
Expand Down
8 changes: 5 additions & 3 deletions embedfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ int main(int argc, char** argv) {

auto output_basename = output_path.stem().string();

stream << "#ifndef _" << output_basename << "_EMBED_FILE\n";
stream << "#define _" << output_basename << "_EMBED_FILE\n";
stream << "#pragma once\n";
stream << "#ifndef __" << output_basename << "_EMBED_FILE\n";
stream << "#define __" << output_basename << "_EMBED_FILE\n";
stream << "#include <cstdint>\n";
stream << "const std::uint8_t _" << output_basename << "[] = {\n";
stream << "#include <initializer_list>\n";
stream << "const std::initializer_list<uint8_t> __" << output_basename << " = {\n";
size_t current_line_bytes = 0;
for (uint8_t byte : binary_data) {
if (current_line_bytes == 0) {
Expand Down
Loading

0 comments on commit d310f20

Please sign in to comment.