Skip to content

Commit

Permalink
Junk commit so that I don't lose my work
Browse files Browse the repository at this point in the history
  • Loading branch information
melvyn2 committed Sep 29, 2020
1 parent 202558e commit 9aafe2f
Show file tree
Hide file tree
Showing 15 changed files with 126 additions and 21 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,6 @@ ASALocalRun/

# BeatPulse healthcheck temp database
healthchecksdb
stdshader_dx9_tf2vulkan/src/Generated/
*.vcxproj.filters
stdshader_vulkan/src/shaders/Generated/
stdshader_vulkan/src/shaders/Generated/*
*.tlog
1 change: 1 addition & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[submodule "sdk2013"]
path = sdk2013
url = https://github.com/PazerOP/source-sdk-2013
branch = modified-correct
[submodule "spirv-cross"]
path = spirv-cross
url = https://github.com/PazerOP/SPIRV-Cross.git
Expand Down
44 changes: 44 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
project(tf2vulkan)
cmake_minimum_required(VERSION 3.13)

set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 11)

if(UNIX)
add_compile_definitions(PLATFORM_POSIX POSIX _POSIX)
add_compile_definitions(GNUC) # Not sure what this does, but is required
endif()
if(UNIX AND NOT APPLE AND NOT CYGWIN)
add_compile_definitions(PLATFORM_LINUX LINUX _LINUX)
endif()
if(APPLE)
add_compile_definitions(OSX _OSX)
endif()
if(WIN32)
add_compile_definitions(PLATFORM_WINDOWS_PC PLATFORM_WINDOWS WIN32 _WIN32)
endif()


if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
add_compile_definitions(COMPILER_GCC) # IDK why but clang == gcc
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
add_compile_definitions(COMPILER_GCC)
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
add_compile_definitions(COMPILER_MSVC)

endif()

set(CMAKE_POSITION_INDEPENDENT_CODE True)

set(CMAKE_C_FLAGS_DEBUG_INIT -DDEBUG -D_DEBUG -O0 -ggdb -g3)
set(CMAKE_CXX_FLAGS_DEBUG_INIT -DDEBUG -D_DEBUG -O0 -ggdb -g3)

set(CMAKE_C_FLAGS_RELEASE_INIT -DNDEBUG -O3 -ggdb -g1)
set(CMAKE_CXX_FLAGS_RELEASE_INIT -DNDEBUG -O3 -ggdb -g1)

set(CMAKE_C_FLAGS "-w -m32")
set(CMAKE_CXX_FLAGS "-w -m32")


add_subdirectory(TF2VulkanUtil)
add_subdirectory(stdshader_vulkan)
16 changes: 16 additions & 0 deletions TF2VulkanUtil/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
project(tf2vulkanutil)
set(CMAKE_CXX_STANDARD 20)

add_library(tf2vulkanutil STATIC)

target_sources(tf2vulkanutil PUBLIC
include/TF2Vulkan/Util/ImageManip.cpp
include/TF2Vulkan/Util/Threads.cpp
src/TF2Vulkan/Util/Macros.cpp
src/TF2Vulkan/Util/interface.cpp
src/TF2Vulkan/Util/KeyValues.cpp
src/TF2Vulkan/Util/std_string.cpp
src/TF2Vulkan/Util/std_utility.cpp
src/TF2Vulkan/Util/utlsymbol.cpp)

target_include_directories(tf2vulkanutil PUBLIC include ../sdk2013/mp/src/public/)
15 changes: 14 additions & 1 deletion TF2VulkanUtil/include/TF2Vulkan/Util/Macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@

#include <tier0/basetypes.h>

#ifdef COMPILER_MSVC
#define ENSURE(condition) { if (!(condition)) ::Util::EnsureConditionFailed(V_STRINGIFY(#condition), __FUNCSIG__, __FILE__, __LINE__); }

#else
#define ENSURE(condition) { if (!(condition)) ::Util::EnsureConditionFailed(V_STRINGIFY(#condition), __func__, __FILE__, __LINE__); }
#endif
#define ASSERT_MAIN_THREAD() ENSURE(::Util::IsMainThread())

namespace Util
Expand Down Expand Up @@ -71,6 +74,16 @@ namespace Util
#define PRINTF_SV(stringView) Util::SafeConvert<int>((stringView).size()), (stringView).data()
static constexpr const char* PRINTF_BOOL(bool val) { return val ? "true" : "false"; }

#if __has_builtin(__builtin_debugtrap)
#define DEBUG_BREAK __builtin_debugtrap();
#elif POSIX
#define DEBUG_BREAK std::raise(SIGTRAP);
#elif COMPILER_MSVC
#define DEBUG_BREAK __debugbreak();
#else
#define DEBUG_BREAK
#endif

#ifdef MATT_HAYNIE
#define NOT_IMPLEMENTED_FUNC() \
{ NOT_IMPLEMENTED_FUNC_NOBREAK(); __debugbreak(); throw 0; }
Expand Down
3 changes: 2 additions & 1 deletion TF2VulkanUtil/include/TF2Vulkan/Util/Misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

#include <cstddef>
#include <type_traits>
#include <tier0/platform.h>

namespace Util
{
template<typename T, typename TOffset, typename = std::enable_if_t<std::is_integral_v<TOffset>>>
__forceinline T* OffsetPtr(T* base, TOffset offset)
FORCEINLINE_TEMPLATE T* OffsetPtr(T* base, TOffset offset)
{
if (!base)
return base;
Expand Down
4 changes: 2 additions & 2 deletions TF2VulkanUtil/include/TF2Vulkan/Util/interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ namespace Util
if (!factory)
{
assert(factory);
Error("[TF2Vulkan] " __FUNCTION__ "(): Factory was null");
Error("[TF2Vulkan] " + __FUNCTION__ + "(): Factory was null");
}

if (!(interfacePtr = (T*)factory(interfaceName, nullptr)))
{
assert(interfacePtr);
Error("[TF2Vulkan] " __FUNCTION__ "(): Failed to connect to %s", interfaceName);
Error("[TF2Vulkan] " + __FUNCTION__ + "(): Failed to connect to %s", interfaceName);
}
}

Expand Down
2 changes: 1 addition & 1 deletion TF2VulkanUtil/include/TF2Vulkan/Util/std_compare.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace Util
else if constexpr (std::is_convertible_v<T, std::weak_equality>)
return std::weak_equality::equivalent;
else
static_assert(false, "Invalid type");
static_assert(true, "Invalid type");
}

template<typename T> constexpr bool is_ordering_impl()
Expand Down
14 changes: 8 additions & 6 deletions TF2VulkanUtil/include/TF2Vulkan/Util/std_utility.h
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
#pragma once

#include "Macros.h"

#include <initializer_list>
#include <utility>

namespace Util
{
using std::as_const;
template<typename T>
constexpr __forceinline std::add_const_t<T>* as_const(T* t) noexcept
constexpr FORCEINLINE_TEMPLATE std::add_const_t<T>* as_const(T* t) noexcept
{
return t;
}

template<typename T>
[[nodiscard]] __forceinline size_t hash_value(const T& value)
[[nodiscard]] FORCEINLINE_TEMPLATE size_t hash_value(const T& value)
{
return std::hash<T>{}(value);
}
Expand All @@ -31,7 +33,7 @@ namespace Util
return retVal;
}

[[nodiscard]] __forceinline size_t hash_combine(const std::initializer_list<size_t>& hashes)
[[nodiscard]] FORCEINLINE_TEMPLATE size_t hash_combine(const std::initializer_list<size_t>& hashes)
{
return ::Util::hash_combine_range(hashes.begin(), hashes.end());
}
Expand All @@ -48,18 +50,18 @@ namespace Util
}

template<typename T, size_t size>
[[nodiscard]] __forceinline size_t hash_value(const T(&value)[size])
[[nodiscard]] FORCEINLINE_TEMPLATE size_t hash_value(const T(&value)[size])
{
return ::Util::hash_range(std::begin(value), std::end(value));
}

template<typename TOnly>
[[nodiscard]] __forceinline size_t hash_multi(const TOnly& only)
[[nodiscard]] FORCEINLINE_TEMPLATE size_t hash_multi(const TOnly& only)
{
return ::Util::hash_value(only);
}
template<typename TFirst, typename... TExtra>
[[nodiscard]] __forceinline size_t hash_multi(const TFirst& first, const TExtra& ... args)
[[nodiscard]] FORCEINLINE_TEMPLATE size_t hash_multi(const TFirst& first, const TExtra& ... args)
{
return ::Util::hash_combine({ ::Util::hash_value(first), ::Util::hash_value(args)... });
}
Expand Down
12 changes: 10 additions & 2 deletions TF2VulkanUtil/src/TF2Vulkan/Util/Macros.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
#pragma push_macro("_PREFAST_")
#undef RTL_NUMBER_OF_V2
#undef _PREFAST_
#ifdef WIN32
#include <Windows.h>
#else
#include <iostream>
#endif
#pragma pop_macro("RTL_NUMBER_OF_V2")
#pragma pop_macro("_PREFAST_")

Expand Down Expand Up @@ -51,7 +55,7 @@ void Util::EnsureConditionFailed(const char* condition, const char* fnSig, const
Warning(fmtStr, condition, fnSig, file, line);

if (Plat_IsInDebugSession())
__debugbreak();
DEBUG_BREAK

Error(fmtStr, condition, fnSig, file, line);
}
Expand Down Expand Up @@ -89,9 +93,13 @@ void Util::LogFunctionCall(const std::string_view& fnSig, const std::string_view
const FnSigComponents comps(fnSig);

char buf[512];
sprintf_s(buf, "[TF2Vulkan] -> %.*s%.*s%s%.*s\n",
sprintf(buf, "[TF2Vulkan] -> %.*s%.*s%s%.*s\n",
s_LogFunctionCallIndentation, LOG_FN_INDENT_CHARS,
PRINTF_SV(fnSig), msg.empty() ? "" : ": ", PRINTF_SV(msg));

#ifdef COMPILER_MSVC
OutputDebugStringA(buf);
#else
std::cerr << buf;
#endif
}
12 changes: 10 additions & 2 deletions TF2VulkanUtil/src/TF2Vulkan/Util/interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
#undef _PREFAST_
#undef RTL_NUMBER_OF_V2

#ifdef WIN32
#include <Windows.h>
#else
#include <dlfcn.h>
#endif

CSysModule* Util::FindModule(const char* moduleName)
{
Expand All @@ -12,8 +16,12 @@ CSysModule* Util::FindModule(const char* moduleName)
assert(false);
return nullptr;
}

#ifdef WIN32
return (CSysModule*)GetModuleHandleA(moduleName);
#else
printf("Trying to dlopen %s", moduleName);
return (CSysModule*)dlopen(moduleName, RTLD_LAZY);
#endif
}

#ifdef CUSTOM_CREATEINTERFACE_FN
Expand Down Expand Up @@ -51,5 +59,5 @@ void* Util::FindProcAddressRaw(CSysModule* module, const char* symbolName)
if (!module)
return nullptr;

return GetProcAddress((HMODULE)module, symbolName);
return GetProcAddress((void *)module, symbolName);
}
1 change: 1 addition & 0 deletions TF2VulkanUtil/src/TF2Vulkan/Util/utlsymbol.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "TF2Vulkan/Util/utlsymbol.h"
#include <functional>

size_t std::hash<CUtlSymbol>::operator()(const CUtlSymbol& s) const
{
Expand Down
2 changes: 1 addition & 1 deletion sdk2013
12 changes: 12 additions & 0 deletions stdshader_vulkan/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
PROJECT(stdshader_vulkan)

file(GLOB SHADERS ${CMAKE_CURRENT_SOURCE_DIR}/src/shaders/HLSL/*.hlsl)
foreach(SHADER ${SHADERS})
get_filename_component(SHADER_NAME ${SHADER} NAME_WLE)
list(APPEND COMPILED_SHADERS ${CMAKE_CURRENT_SOURCE_DIR}/src/shaders/generated/${SHADER_NAME}.h)
endforeach()
add_custom_command( OUTPUT ${COMPILED_SHADERS}
COMMAND make
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/shaders/HLSL)
add_custom_target(shaders DEPENDS ${COMPILED_SHADERS})

6 changes: 3 additions & 3 deletions stdshader_vulkan/src/shaders/HLSL/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ TEXTURE_OFFSET:=0 #200
# COMPILER_ARGS_TARGET:= -o

# glslangValidator
SHADER_COMPILER:=glslangValidator.exe
SHADER_COMPILER:=glslangValidator
COMPILER_ARGS:= -fhlsl_functionality1 --shift-sampler-binding $(SAMPLER_OFFSET) --shift-texture-binding $(TEXTURE_OFFSET) --invert-y -V -e main
COMPILER_ARGS_VERT:=
COMPILER_ARGS_FRAG:=
COMPILER_ARGS_TARGET:= -o

SPIRV_VAL:=spirv-val.exe
SPIRV_DIS:=spirv-dis.exe
SPIRV_VAL:=spirv-val
SPIRV_DIS:=spirv-dis

SOURCE_DIR:=
TARGET_DIR:=../Generated/
Expand Down

0 comments on commit 9aafe2f

Please sign in to comment.