Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/shader pipe line creation #10

Merged
merged 11 commits into from
Oct 19, 2024
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "Ifnity/Ifnity/vendor/SPIRV-Cross"]
path = Ifnity/Ifnity/vendor/SPIRV-Cross
url = https://github.com/KhronosGroup/SPIRV-Cross.git
3 changes: 2 additions & 1 deletion Ifnity/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.8)
project(IFNITYPROYECT)

# Define la opción y propágala a los subdirectorios
option(BUILD_SHARED_IFNITY "Build Ifnity as a shared library dll " OFF)
option(BUILD_SHARED_IFNITY "Build Ifnity as a shared library dll " ON)
# Asegurar modulos cmake
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")

Expand All @@ -12,6 +12,7 @@ add_subdirectory(Ifnity)
# Añade el subdirectorio que contiene el proyecto Sandbox Y EJEMPLOS
add_subdirectory(Sandbox)
add_subdirectory(GPU_MONITOR)
add_subdirectory(ShadersPipeLine)

# El dll que genera Ifnity se copiará automáticamente a la carpeta de salida de Sandbox

15 changes: 15 additions & 0 deletions Ifnity/CMakeSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"configurations": [
{
"name": "x64-Debug",
"generator": "Ninja",
"configurationType": "Debug",
"inheritEnvironments": [ "msvc_x64_x64" ],
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": ""
}
]
}
14 changes: 14 additions & 0 deletions Ifnity/Ifnity/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DIST ${CMAKE_BINARY_DIR}/Dist)






# Buscar nvml.dll en el sistema
find_file(NVML_LIBRARY
NAMES nvml.dll
Expand Down Expand Up @@ -47,6 +50,11 @@ add_subdirectory(${PROJECT_SOURCE_DIR}/vendor)
add_subdirectory(${PROJECT_SOURCE_DIR}/vendor/D3D12MemoryAllocator)
# add vulkan bootstrap
add_subdirectory(${PROJECT_SOURCE_DIR}/vendor/vk-bootstrap)
#add glslang
add_subdirectory(${PROJECT_SOURCE_DIR}/vendor/SPIRV-Cross)





# Include directories
Expand All @@ -73,6 +81,7 @@ include_directories(${Vulkan_INCLUDE_DIRS})
include_directories(${PROJECT_SOURCE_DIR}/vendor/vk-bootstrap)



message("Ruta del directorio de origen del proyecto: ${PROJECT_SOURCE_DIR}")
# Source files
file(GLOB_RECURSE SOURCE_FILES
Expand Down Expand Up @@ -108,6 +117,8 @@ if(NOT SOURCE_FILES)
message(FATAL_ERROR "No source files given to target: ${PROJECT_NAME}")
endif()



# Link libraries
target_link_libraries(${PROJECT_NAME} PUBLIC glfw)
target_link_libraries(${PROJECT_NAME} PUBLIC opengl32)
Expand All @@ -120,6 +131,7 @@ target_link_libraries(${PROJECT_NAME} PUBLIC D3D12MemoryAllocator)
target_link_libraries(${PROJECT_NAME} PUBLIC ${Vulkan_LIBRARIES})
# Link VK-Bootstrap
target_link_libraries(${PROJECT_NAME} PUBLIC vk-bootstrap::vk-bootstrap)
target_link_libraries(${PROJECT_NAME} PUBLIC spirv-cross-core spirv-cross-c)

# Include Target Directories
target_include_directories(${PROJECT_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/src/vma)
Expand All @@ -144,6 +156,8 @@ set(CMAKE_CONFIGURATION_TYPES "Debug;Release;Dist")
# Antes de definir las propiedades del target, establece las banderas del enlazador para la configuración Dist
set(CMAKE_SHARED_LINKER_FLAGS_DIST "-O2" CACHE STRING "Flags used by the linker during Dist builds.")



# Flags for different configurations
set_target_properties(${PROJECT_NAME} PROPERTIES
COMPILE_FLAGS_DEBUG "-D IFNITY_DEBUG"
Expand Down
4 changes: 3 additions & 1 deletion Ifnity/Ifnity/src/Ifnity.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

//IFNITY ENGINE USES

#include "Ifnity/Utils/VFS.hpp"
#include "Ifnity/App.h"
#include "Ifnity/Layer.hpp"
#include "Ifnity/Layers/ImguiLayer.h"
#include "Ifnity/Layers/NVML_Layer.hpp"
#include "Ifnity/Layers/ExampleLayer.h"

#include "../ShaderBuilding/ShaderBuilder.hpp"
#include "Ifnity/Graphics/IShader.hpp"

//wOMDPW
//Entry Point this include have put at the end of the file.
Expand Down
48 changes: 48 additions & 0 deletions Ifnity/Ifnity/src/Ifnity/Graphics/IShader.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@


#include "IShader.hpp"








IFNITY_NAMESPACE

std::vector<const wchar_t*> IShader::CreateCompileArgs(const ShaderCreateDescription& shaderDescription) const
{
//Reserve only the space for the arguments that are going to be used
std::vector<const wchar_t*> args;
args.reserve(10);

// Argumentos obligatorios
args = { L"-E", shaderDescription.EntryPoint.c_str(), L"-T", shaderDescription.Profile.c_str() };

ShaderCompileFlagType flags = shaderDescription.Flags;

// Flags.
if(flags & OPTIMIZE_SIZE) args.push_back(L"-Osize");
if(flags & ENABLE_DEBUG_INFO) args.push_back(L"-Zi");
if(flags & ENABLE_SPIRV) args.push_back(L"-spirv");
if(flags & PACK_MATRIX_ROW_MAJOR) args.push_back(L"-Zpr");

return args;
}

std::vector<const wchar_t*> IShader::GetCompileArgs(const ShaderCreateDescription& shaderDescription) const
{
return CreateCompileArgs(shaderDescription);

}

void IShader::AddShaderDescription(rhi::GraphicsAPI api, const ShaderCreateDescription& description)
{
shaderMap[ api ] = (description);
}



IFNITY_END_NAMESPACE

109 changes: 109 additions & 0 deletions Ifnity/Ifnity/src/Ifnity/Graphics/IShader.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@

#pragma once


#include "pch.h"
#include <set>

IFNITY_NAMESPACE


enum IFNITY_API ShaderType: uint8_t
{
VERTEX_SHADER = 0x00,
PIXEL_SHADER = 0x01,
GEOMETRY_SHADER = 0x02,
COMPUTE_SHADER = 0x03,
HULL_SHADER = 0x04,
DOMAIN_SHADER = 0x05,
UNKNOWN_SHADER = 0x06
};


enum IFNITY_API ShaderCompileFlagType: uint32_t
{
OPTIMIZE_SIZE = 0x1,
ENABLE_DEBUG_INFO = 0x2,
ENABLE_SPIRV = 0x4,
PACK_MATRIX_ROW_MAJOR = 0x8,

DEFAULT_FLAG = 0x0C
// Agrega más flags según sea necesario
};



struct IFNITY_API ShaderCreateDescription
{
ShaderType Type;
std::wstring ShaderSource;
std::wstring EntryPoint;
std::wstring Profile;
ShaderCompileFlagType Flags;
bool SaveFile{ true };
std::string FileName;
std::string Filepath{};

// Operator to compare two ShaderCreateDescription and uses in std::set
bool operator<(const ShaderCreateDescription& other) const
{
return std::tie(FileName, Type) != std::tie(other.FileName, other.Type);
}
};


/// <summary>
/// Shader Interface to be implemented by the graphics API Inside
/// </summary>
class IFNITY_API IShader
{
public:
//Constructor
IShader() = default;
//Destructor
virtual ~IShader() = default;

void SetShaderDescription(const ShaderCreateDescription& description) { m_Description = description; }

ShaderCreateDescription GetShaderDescription() const { return m_Description; }
void AddShaderDescription(rhi::GraphicsAPI api, const ShaderCreateDescription& description);



std::vector<const wchar_t*> GetCompileArgs(const ShaderCreateDescription& shaderDescription) const;


private:
std::vector<const wchar_t*> CreateCompileArgs(const ShaderCreateDescription& shaderDescription) const;

std::map<rhi::GraphicsAPI, ShaderCreateDescription> shaderMap;

ShaderCreateDescription m_Description;

};

























IFNITY_END_NAMESPACE
Loading
Loading