Skip to content

Commit

Permalink
Merge pull request #24 from Deamon87/development
Browse files Browse the repository at this point in the history
Enable Vulkan and expose Disable portal culling
  • Loading branch information
Deamon87 authored Jan 7, 2023
2 parents 2255316 + 70ef422 commit c10c7e7
Show file tree
Hide file tree
Showing 21 changed files with 20,341 additions and 15,072 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,14 @@ jobs:
- uses: actions/setup-python@v4
with:
python-version: '3.10'

- name: Prepare Vulkan SDK
# Disable Vulkan for MacOS for now, as it requires MoltenVK
if: ${{ !startsWith(matrix.config.name, 'emscripten') && !startsWith(matrix.config.name, 'macOS') }}
uses: humbletim/[email protected]
with:
vulkan-query-version: 1.3.204.0
vulkan-components: Vulkan-Headers, Vulkan-Loader, SPIRV-Tools
vulkan-use-cache: true
- name: Print env
run: |
echo github.event.action: ${{ github.event.action }}
Expand Down
7 changes: 6 additions & 1 deletion src/exporters/gltfExporter/GLTFExporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "../../screenshots/screenshotMaker.h"
#include "../../../wowViewerLib/src/engine/texture/DxtDecompress.h"
#include "../../../wowViewerLib/src/include/string_utils.h"
#include "../../../3rdparty/filesystem_impl/include/ghc/filesystem.hpp"

void GLTFExporter::addM2Object(std::shared_ptr<M2Object> &m2Object) {
m2sToExport.push_back(m2Object);
Expand Down Expand Up @@ -155,7 +156,7 @@ void GLTFExporter::createTextures(GLTFExporter::M2ModelData &m2ModelData, std::s
sampler.minFilter = TINYGLTF_TEXTURE_FILTER_LINEAR;
sampler.magFilter = TINYGLTF_TEXTURE_FILTER_LINEAR;
sampler.wrapS = wrapX ? TINYGLTF_TEXTURE_WRAP_REPEAT : TINYGLTF_TEXTURE_WRAP_CLAMP_TO_EDGE;
sampler.wrapT = wrapX ? TINYGLTF_TEXTURE_WRAP_REPEAT : TINYGLTF_TEXTURE_WRAP_CLAMP_TO_EDGE;
sampler.wrapT = wrapY ? TINYGLTF_TEXTURE_WRAP_REPEAT : TINYGLTF_TEXTURE_WRAP_CLAMP_TO_EDGE;

model.samplers.push_back(sampler);
}
Expand Down Expand Up @@ -632,6 +633,10 @@ void GLTFExporter::createAttributesForVBO(M2ModelData &m2ModelData, std::shared_

GLTFExporter::GLTFExporter(std::string folderPath) : m_folderPath(folderPath) {
model.asset.version = "2.0";

if (!ghc::filesystem::is_directory(m_folderPath) || !ghc::filesystem::exists(m_folderPath)) {
ghc::filesystem::create_directory(m_folderPath); // create src folder
}
}

void GLTFExporter::createVboAndIbo(M2ModelData &m2ModelData, std::shared_ptr<M2Object> &m2Object) {
Expand Down
6 changes: 3 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#ifdef LINK_VULKAN
#define GLFW_INCLUDE_VULKAN
#include "../wowViewerLib/src/include/vulkancontext.h"
#define VK_NO_PROTOTYPES
#else
#undef GLFW_INCLUDE_VULKAN
#endif
Expand Down Expand Up @@ -352,8 +352,8 @@ int main(){
#endif

// std::string rendererName = "ogl2";
std::string rendererName = "ogl3";
// std::string rendererName = "vulkan";
// std::string rendererName = "ogl3";
std::string rendererName = "vulkan";

//FOR OGL

Expand Down
6 changes: 6 additions & 0 deletions src/ui/FrontendUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1097,10 +1097,16 @@ void FrontendUI::showSettingsDialog() {
m_api->getConfig()->drawM2BB = drawM2BB;
}

bool disablePortalCulling = !m_api->getConfig()->usePortalCulling;
if (ImGui::Checkbox("Disable portal culling", &disablePortalCulling)) {
m_api->getConfig()->usePortalCulling = !disablePortalCulling;
}

bool renderPortals = m_api->getConfig()->renderPortals;
if (ImGui::Checkbox("Render portals", &renderPortals)) {
m_api->getConfig()->renderPortals = renderPortals;
}

if (renderPortals) {
bool renderPortalsIgnoreDepth = m_api->getConfig()->renderPortalsIgnoreDepth;
if (ImGui::Checkbox("Ignore depth test for rendering portals", &renderPortalsIgnoreDepth)) {
Expand Down
76 changes: 49 additions & 27 deletions wowViewerLib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -450,10 +450,8 @@ set(OPENGL4x_IMPLEMENTATION src/gapi/ogl4.x/textures/GBlpTextureGL4x.cpp
src/gapi/ogl4.x/GOcclusionQueryGL4x.h src/gapi/ogl4.x/syncronization/GPUFenceGL44.cpp src/gapi/ogl4.x/syncronization/GPUFenceGL44.h src/engine/persistance/header/skelFileHeader.h)
endif()

set(Vulkan_INCLUDE_DIR "")
if (LINK_VULKAN)
set(VULKAN_IMPLEMENTATION
src/include/vulkancontext.h
src/gapi/vulkan/GDeviceVulkan.cpp
src/gapi/vulkan/GDeviceVulkan.h
src/gapi/vulkan/vkAllocator.cpp
Expand Down Expand Up @@ -495,34 +493,55 @@ if (LINK_VULKAN)
src/gapi/vulkan/shaders/GDrawBoundingBoxVLK.h
src/gapi/vulkan/shaders/GWaterfallShaderVLK.cpp
src/gapi/vulkan/shaders/GWaterfallShaderVLK.h)
set(Vulkan_INCLUDE_DIR $ENV{VULKAN_SDK}/Include)
IF(WIN32)
IF (NOT Vulkan_FOUND)
find_library(Vulkan_LIBRARY NAMES vulkan-1 vulkan PATHS "$ENV{VULKAN_SDK}/lib")
IF (Vulkan_LIBRARY)
set(Vulkan_FOUND ON PARENT_SCOPE)
MESSAGE("Using bundled Vulkan library version win32, Vulkan_LIBRARY= ${Vulkan_LIBRARY}")
ELSE()
set(LINK_VULKAN OFF)
set(VULKAN_IMPLEMENTATION "")
ENDIF()
ENDIF()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DVK_USE_PLATFORM_WIN32_KHR")
ELSE(WIN32)
IF (NOT Vulkan_FOUND)
find_library(Vulkan_LIBRARY NAMES vulkan HINTS "$ENV{VULKAN_SDK}/lib" "${CMAKE_SOURCE_DIR}/libs/vulkan")
IF (Vulkan_LIBRARY)
set(Vulkan_FOUND ON PARENT_SCOPE)
MESSAGE("Using bundled Vulkan library version non-win32")
ELSE()
set(LINK_VULKAN OFF)
set(VULKAN_IMPLEMENTATION "")
ENDIF()
ENDIF()


find_package(Vulkan)
IF (Vulkan_LIBRARY)
set(Vulkan_FOUND ON PARENT_SCOPE)
MESSAGE("Using Vulkan library, Vulkan_LIBRARY= ${Vulkan_LIBRARY}")
ELSE()
MESSAGE("Vulkan Lib was not found. Disabling vulkan build")

set(LINK_VULKAN OFF)
set(VULKAN_IMPLEMENTATION "")
ENDIF()


if (Vulkan_LIBRARY)
message(Vulkan_INCLUDE_DIR = ${Vulkan_INCLUDE_DIR})
if (Vulkan_INCLUDE_DIR STREQUAL "")
message(FATAL_ERROR "Vulkan_INCLUDE_DIR is empty")
endif()

get_filename_component(Vulkan_LIBRARY_DIR ${Vulkan_LIBRARY} DIRECTORY)
message(Vulkan_LIBRARY_DIR = ${Vulkan_LIBRARY_DIR})

# IF(WIN32)
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DVK_USE_PLATFORM_WIN32_KHR")
# endif()

if(CMAKE_SYSTEM_NAME STREQUAL Windows)
set(VOLK_STATIC_DEFINES VK_USE_PLATFORM_WIN32_KHR)
elseif(CMAKE_SYSTEM_NAME STREQUAL Linux)
set(VOLK_STATIC_DEFINES VK_USE_PLATFORM_XLIB_KHR)
elseif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
set(VOLK_STATIC_DEFINES VK_USE_PLATFORM_MACOS_MVK)
#We need to bundle moltenVK and vulkan lib on macos
file(GLOB vulkanLibFiles RELATIVE ${srcDir} ${srcDir}/*.*)

install(FILES ${Vulkan_LIBRARY} DESTINATION ${CMAKE_INSTALL_BINDIR})
#TODO: The moltenVK needs to be built separately
# install(FILES ${Vulkan_LIBRARY_DIR}/libMoltenVK.dylib DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
#Add volk loader
set(VULKAN_IMPLEMENTATION ${VULKAN_IMPLEMENTATION} src/gapi/vulkan/volk.c)
endif()


if (LINK_VULKAN)
add_definitions(-DLINK_VULKAN)
else()
set(Vulkan_INCLUDE_DIR "")
endif()
endif()

Expand Down Expand Up @@ -566,6 +585,9 @@ add_library(WoWViewerLib STATIC ${SOURCE_FILES} ${OPENGL20_IMPLEMENTATION} ${OPE
if (NOT MSVC)
target_compile_options(WoWViewerLib PUBLIC -Werror=return-type)
endif()
if (LINK_VULKAN)
target_compile_definitions(WoWViewerLib PUBLIC ${VOLK_STATIC_DEFINES})
endif()

foreach(X IN LISTS My_Vectorize_Compile_Options)
target_compile_options(WoWViewerLib PRIVATE ${X})
Expand Down Expand Up @@ -608,7 +630,7 @@ if (LINK_VULKAN)
message("Include vulkan include dir ${Vulkan_INCLUDE_DIR}")
target_include_directories(WoWViewerLib PUBLIC ${Vulkan_INCLUDE_DIR})
target_compile_definitions(WoWViewerLib PUBLIC -DLINK_VULKAN)
target_link_libraries(WoWViewerLib ${Vulkan_LIBRARY})
# target_link_libraries(WoWViewerLib ${Vulkan_LIBRARY})
#Vulkan stuff end
else()
target_compile_definitions(WoWViewerLib PUBLIC -DSKIP_VULKAN)
Expand Down
3 changes: 2 additions & 1 deletion wowViewerLib/src/engine/shader/ShaderDefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ const std::unordered_map<std::string, shaderMetaData> shaderMetaInfo = {{ "wmoSh
}
},{ "m2ParticleShader.frag.spv", {
{
{0,4,32},
{0,4,48},
{0,0,368},
}
}
Expand Down Expand Up @@ -945,6 +945,7 @@ const std::unordered_map<std::string, std::unordered_map<int, std::vector<field
4, {
{"_277_uAlphaTestv", true, 0, 1, 4, 0},
{"_277_uPixelShaderBlendModev", false, 16, 1, 4, 0},
{"_277_uTextureTranslate", true, 32, 1, 4, 0},
}
},
}},
Expand Down
4 changes: 2 additions & 2 deletions wowViewerLib/src/engine/texture/BlpTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "../persistance/helper/ChunkFileReader.h"

TextureFormat getTextureType(BlpFile *blpFile) {
TextureFormat textureFormat = TextureFormat::None;
TextureFormat textureFormat = TextureFormat::Undetected;
switch (blpFile->preferredFormat) {
case BLPPixelFormat::PIXEL_DXT1:
if (blpFile->alphaChannelBitDepth > 0) {
Expand Down Expand Up @@ -158,7 +158,7 @@ void BlpTexture::process(HFileContent blpFile, const std::string &fileName) {
this->m_textureFormat = getTextureType(pBlpFile);

/* Load texture by mipmaps */
assert(this->m_textureFormat != TextureFormat::None);
assert(this->m_textureFormat != TextureFormat::Undetected);
m_mipmaps = parseMipmaps(pBlpFile, m_textureFormat);

// /* Load texture into GL memory */
Expand Down
5 changes: 3 additions & 2 deletions wowViewerLib/src/engine/texture/BlpTexture.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
#include "../../include/sharedFile.h"
#include "../persistance/PersistentFile.h"
#include <vector>

enum class TextureFormat {
None,
Undetected,
S3TC_RGBA_DXT1,
S3TC_RGB_DXT1,
S3TC_RGBA_DXT3,
Expand Down Expand Up @@ -47,7 +48,7 @@ class BlpTexture : public PersistentFile{
std::string m_textureName;

HMipmapsVector m_mipmaps;
TextureFormat m_textureFormat = TextureFormat::None;
TextureFormat m_textureFormat = TextureFormat::Undetected;
};


Expand Down
21 changes: 20 additions & 1 deletion wowViewerLib/src/gapi/interface/IDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,27 @@ class gMeshTemplate;
#include <functional>
#include <algorithm>
#include "syncronization/IGPUFence.h"

#ifdef LINK_VULKAN
#include <vulkan/vulkan_core.h>
#define VK_NO_PROTOTYPES
#include "../vulkan/volk.h"

//HACKS for stupid defines in X11
#undef None // Defined by X11/X.h to 0L
#undef Status // Defined by X11/Xlib.h to int
#undef True // Defined by X11/Xlib.h to 1
#undef False // Defined by X11/Xlib.h to 0
#undef Bool // Defined by X11/Xlib.h to int
#undef RootWindow // Defined by X11/Xlib.h
#undef CurrentTime // Defined by X11/X.h to 0L
#undef Success // Defined by X11/X.h to 0
#undef DestroyAll // Defined by X11/X.h to 0
#undef COUNT // Defined by X11/extensions/XI.h to 0
#undef CREATE // Defined by X11/extensions/XI.h to 1
#undef DeviceAdded // Defined by X11/extensions/XI.h to 0
#undef DeviceRemoved // Defined by X11/extensions/XI.h to 1

#include "../vulkan/vk_mem_alloc.h"
#endif

typedef std::shared_ptr<IVertexBufferDynamic> HGVertexBufferDynamic;
Expand Down
2 changes: 1 addition & 1 deletion wowViewerLib/src/gapi/ogl2.0/textures/GBlpTextureGL20.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ void GBlpTextureGL20::createGlTexture(TextureFormat textureFormat, const HMipmap
&mipmaps[k].texture[0]);
}
break;
case TextureFormat::None:
case TextureFormat::Undetected:
case TextureFormat::BGRA:
case TextureFormat::PalARGB1555DitherFloydSteinberg:
case TextureFormat::PalARGB4444DitherFloydSteinberg:
Expand Down
29 changes: 27 additions & 2 deletions wowViewerLib/src/gapi/vulkan/GDeviceVulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include <array>
#include <thread>
#include "GDeviceVulkan.h"
#include "../../include/vulkancontext.h"

#include "meshes/GM2MeshVLK.h"
#include "meshes/GMeshVLK.h"
Expand Down Expand Up @@ -183,6 +182,11 @@ void populateDebugMessengerCreateInfo(VkDebugUtilsMessengerCreateInfoEXT& create
GDeviceVLK::GDeviceVLK(vkCallInitCallback * callback) {
enableValidationLayers = false;

if (volkInitialize()) {
std::cerr << "Failed to initialize volk loader" << std::endl;
exit(1);
}

this->threadCount = std::max<int>((int)std::thread::hardware_concurrency() - 3, 1);

if (enableValidationLayers && !checkValidationLayerSupport()) {
Expand Down Expand Up @@ -234,6 +238,8 @@ GDeviceVLK::GDeviceVLK(vkCallInitCallback * callback) {
throw std::runtime_error("failed to create instance!");
}

volkLoadInstance(vkInstance);

//Create surface
vkSurface = callback->createSurface(vkInstance);

Expand All @@ -243,11 +249,30 @@ GDeviceVLK::GDeviceVLK(vkCallInitCallback * callback) {
createLogicalDevice();
//---------------
//Init AMD's VMA
VmaVulkanFunctions vma_vulkan_func{};
vma_vulkan_func.vkAllocateMemory = vkAllocateMemory;
vma_vulkan_func.vkBindBufferMemory = vkBindBufferMemory;
vma_vulkan_func.vkBindImageMemory = vkBindImageMemory;
vma_vulkan_func.vkCreateBuffer = vkCreateBuffer;
vma_vulkan_func.vkCreateImage = vkCreateImage;
vma_vulkan_func.vkDestroyBuffer = vkDestroyBuffer;
vma_vulkan_func.vkDestroyImage = vkDestroyImage;
vma_vulkan_func.vkFlushMappedMemoryRanges = vkFlushMappedMemoryRanges;
vma_vulkan_func.vkFreeMemory = vkFreeMemory;
vma_vulkan_func.vkGetBufferMemoryRequirements = vkGetBufferMemoryRequirements;
vma_vulkan_func.vkGetImageMemoryRequirements = vkGetImageMemoryRequirements;
vma_vulkan_func.vkGetPhysicalDeviceMemoryProperties = vkGetPhysicalDeviceMemoryProperties;
vma_vulkan_func.vkGetPhysicalDeviceProperties = vkGetPhysicalDeviceProperties;
vma_vulkan_func.vkInvalidateMappedMemoryRanges = vkInvalidateMappedMemoryRanges;
vma_vulkan_func.vkMapMemory = vkMapMemory;
vma_vulkan_func.vkUnmapMemory = vkUnmapMemory;
vma_vulkan_func.vkCmdCopyBuffer = vkCmdCopyBuffer;

VmaAllocatorCreateInfo allocatorInfo = {};
allocatorInfo.physicalDevice = physicalDevice;
allocatorInfo.device = device;
allocatorInfo.instance = vkInstance;

allocatorInfo.pVulkanFunctions = &vma_vulkan_func;

vmaCreateAllocator(&allocatorInfo, &vmaAllocator);
//---------------
Expand Down
3 changes: 1 addition & 2 deletions wowViewerLib/src/gapi/vulkan/GDeviceVulkan.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class gMeshTemplate;

#include <unordered_set>
#include <list>
#include "vk_mem_alloc.h"

#include "../interface/IDevice.h"
#include "descriptorSets/GDescriptorSet.h"
Expand Down Expand Up @@ -87,7 +86,7 @@ class GDeviceVLK : public IDevice, public std::enable_shared_from_this<GDeviceVL
return uploadQueue != graphicsQueue;
}

HGTexture getBlackPixelTexture() {
HGTexture getBlackTexturePixel() override {
return m_blackPixelTexture;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

class GDescriptorSets;

#include <vulkan/vulkan.h>
#include "../../interface/IDevice.h"
#include "../GDeviceVulkan.h"
#include "GDescriptorSet.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class GDeviceVLK;
class GDescriptorPoolVLK;

#include <vector>
#include <vulkan/vulkan.h>
#include "../../interface/IDevice.h"
#include "../GDeviceVulkan.h"

Expand Down
2 changes: 1 addition & 1 deletion wowViewerLib/src/gapi/vulkan/meshes/GMeshVLK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ void GMeshVLK::createDescriptorSets(GShaderPermutationVLK *shaderVLK) {
//Bind Black pixel texture
std::vector<VkDescriptorImageInfo> imageInfos(shaderVLK->getTextureCount());

auto blackTexture = m_device.getBlackPixelTexture();
auto blackTexture = m_device.getBlackTexturePixel();
GTextureVLK *blackTextureVlk = reinterpret_cast<GTextureVLK *>(blackTexture.get());

int bindIndex = 0;
Expand Down
2 changes: 0 additions & 2 deletions wowViewerLib/src/gapi/vulkan/shaders/GShaderPermutationVLK.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
#ifndef AWEBWOWVIEWERCPP_GSHADERPERMUTATION_H
#define AWEBWOWVIEWERCPP_GSHADERPERMUTATION_H

class GDeviceGL33;

#include <string>
#include <unordered_map>
#include "../GDeviceVulkan.h"
Expand Down
Loading

0 comments on commit c10c7e7

Please sign in to comment.