From 63d9eb10819fe818461f45f1ceeee3f56188c7e9 Mon Sep 17 00:00:00 2001 From: Jimmy Tremblay-Bernier Date: Tue, 26 Nov 2024 21:19:50 -0500 Subject: [PATCH] CONGE-2 ADDED THE SHADER COMPILATION FROM GLSL TO SPIRV --- ConjureEngine/docs/RenderingPipelineSteps.mmd | 41 ++++++++++++++++++ ConjureEngine/docs/renderingPipeline.mmd | 28 ++++++++++++ Demo1/.gitignore | 4 +- Demo1/CMakeLists.txt | 10 +++++ Demo1/CompileShaders.py | 43 +++++++++++++++++++ Demo1/src/Demo1.cpp | 8 ++-- Demo1/src/Shaders/Test.frag | 7 +++ Demo1/src/Shaders/Test.vert | 5 +++ Demo1/src/main.cpp | 4 +- 9 files changed, 142 insertions(+), 8 deletions(-) create mode 100644 ConjureEngine/docs/RenderingPipelineSteps.mmd create mode 100644 ConjureEngine/docs/renderingPipeline.mmd create mode 100644 Demo1/CompileShaders.py create mode 100644 Demo1/src/Shaders/Test.frag create mode 100644 Demo1/src/Shaders/Test.vert diff --git a/ConjureEngine/docs/RenderingPipelineSteps.mmd b/ConjureEngine/docs/RenderingPipelineSteps.mmd new file mode 100644 index 0000000..b5a2ff5 --- /dev/null +++ b/ConjureEngine/docs/RenderingPipelineSteps.mmd @@ -0,0 +1,41 @@ +--- +title: Rendering Pipeline Steps +--- +stateDiagram-v2 + direction LR + state "Data" as Data1 + state "Vertex Shader" as VertexShader1 + state "Tesselation Shader" as TesselationShader1 + state "Rasterization" as Rasterization1 + state "Fragment Shader" as FragmentShader1 + state "Blending" as Blending1 + state "Texture" as Texture1 + + state "Texture" as Texture2 + state "Vertex Shader" as VertexShader2 + state "Tesselation Shader" as TesselationShader2 + state "Rasterization" as Rasterization2 + state "Fragment Shader" as FragmentShader2 + state "Blending" as Blending2 + state "Frame Buffer" as FrameBuffer2 + + Data1 --> VertexShader1 + state "Pass 1" as Pass1{ + direction LR + VertexShader1 --> TesselationShader1 + TesselationShader1 --> Rasterization1 + Rasterization1 --> FragmentShader1 + FragmentShader1 --> Blending1 + } + Blending1 --> Texture1 + + + Texture2 --> VertexShader2 + state "Pass 2" as Pass2{ + direction LR + VertexShader2 --> TesselationShader2 + TesselationShader2 --> Rasterization2 + Rasterization2 --> FragmentShader2 + FragmentShader2 --> Blending2 + } + Blending2 --> FrameBuffer2 \ No newline at end of file diff --git a/ConjureEngine/docs/renderingPipeline.mmd b/ConjureEngine/docs/renderingPipeline.mmd new file mode 100644 index 0000000..6a9a952 --- /dev/null +++ b/ConjureEngine/docs/renderingPipeline.mmd @@ -0,0 +1,28 @@ +--- +title: Rendering Pipeline +--- +classDiagram + class VAO + class VBO + class Shader + class Pipeline0 + class Pipeline1 + class Pipeline2 + + class Entity0 + class Entity1 + class Entity2 + + Entity0 -- Pipeline0 + Entity0 -- Pipeline1 + Entity0 -- Pipeline2 + + Entity1 -- Pipeline0 + Entity1 -- Pipeline1 + + Entity2 -- Pipeline1 + Entity2 -- Pipeline2 + + Pipeline0 -- Shader + Pipeline1 -- Shader + Pipeline2 -- Shader \ No newline at end of file diff --git a/Demo1/.gitignore b/Demo1/.gitignore index e210f52..bc5d3a8 100644 --- a/Demo1/.gitignore +++ b/Demo1/.gitignore @@ -1,3 +1,5 @@ CMakeFiles/ cmake_install.cmake -CMakeUserPresets.json \ No newline at end of file +CMakeUserPresets.json +CompileShaders.log +**/*.spv \ No newline at end of file diff --git a/Demo1/CMakeLists.txt b/Demo1/CMakeLists.txt index 870ccb1..d39fedd 100644 --- a/Demo1/CMakeLists.txt +++ b/Demo1/CMakeLists.txt @@ -3,11 +3,21 @@ project(Demo1) set(CMAKE_CXX_STANDARD 20) +find_package(Python3 REQUIRED COMPONENTS Interpreter) + + add_executable(${PROJECT_NAME} src/main.cpp src/Demo1.cpp src/Demo1.h ) +# SHADERS +add_custom_command( + TARGET ${PROJECT_NAME} + COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/CompileShaders.py ${CMAKE_CURRENT_SOURCE_DIR}/src/Shaders + COMMENT "Compiling shaders" +) + target_link_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/ConjureEngine) find_package(SDL2 REQUIRED) diff --git a/Demo1/CompileShaders.py b/Demo1/CompileShaders.py new file mode 100644 index 0000000..d5c49bc --- /dev/null +++ b/Demo1/CompileShaders.py @@ -0,0 +1,43 @@ +import os +import sys +import subprocess +import logging + +os.chdir(sys.argv[1]) + +# Configure logging +logging.basicConfig( + filename=os.path.join("D:/Dev/ETS/CONJURE/conjure-engine/Demo1", "CompileShaders.log"), # Log file name + filemode="w", # Append mode (use "w" for overwrite) + format="%(asctime)s - %(levelname)s - %(message)s", # Log format + level=logging.INFO # Logging level +) + + +SHADERS_PATH = os.path.join(os.getcwd()) +GLSLC_PATH = os.path.join(os.environ.get("VULKAN_SDK"), "bin", "glslc") + +def filterFunc(fileName): + logging.info(fileName) + name, ext = fileName.split(".") + return ext != "spv" + +def __main__(): + logging.info("SHADER PATH: " + SHADERS_PATH) + logging.info("GLSLC PATH:" + GLSLC_PATH) + + shaders = filter(filterFunc, os.listdir(SHADERS_PATH)) + for shader in shaders: + name, ext = shader.split(".") + + command = GLSLC_PATH + args = [ + os.path.join(SHADERS_PATH, shader), + "-o", + os.path.join(SHADERS_PATH, name + "." + ext + ".spv") + ] + + logging.info(command + " " + str.join(" ", args)) + subprocess.run(command + " " + str.join(" ", args)) +if __name__ == "__main__": + __main__() \ No newline at end of file diff --git a/Demo1/src/Demo1.cpp b/Demo1/src/Demo1.cpp index 9425f1a..5d7705f 100644 --- a/Demo1/src/Demo1.cpp +++ b/Demo1/src/Demo1.cpp @@ -21,22 +21,22 @@ namespace Demo1 { void Demo1::Awake() { - SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,"AWAKING"); + SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION,"AWAKING"); } void Demo1::Start() { - SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,"STARTING"); + SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION,"STARTING"); } void Demo1::Tick(double deltaTime) { - SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "TICKING %f", deltaTime); + SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "TICKING %f", deltaTime); } void Demo1::Destroy() { - SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,"DESTROYING"); + SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION,"DESTROYING"); } } // Demo1 diff --git a/Demo1/src/Shaders/Test.frag b/Demo1/src/Shaders/Test.frag new file mode 100644 index 0000000..2801bac --- /dev/null +++ b/Demo1/src/Shaders/Test.frag @@ -0,0 +1,7 @@ +#version 460 core + +layout (location = 0) out vec4 oColor; + +void main() { + oColor = vec4(1); +} \ No newline at end of file diff --git a/Demo1/src/Shaders/Test.vert b/Demo1/src/Shaders/Test.vert new file mode 100644 index 0000000..4a76a79 --- /dev/null +++ b/Demo1/src/Shaders/Test.vert @@ -0,0 +1,5 @@ +#version 460 core + +void main() { + gl_Position = vec4(0); +} \ No newline at end of file diff --git a/Demo1/src/main.cpp b/Demo1/src/main.cpp index 004ff01..106453e 100644 --- a/Demo1/src/main.cpp +++ b/Demo1/src/main.cpp @@ -88,7 +88,5 @@ int main ( int argc, char* argv[] ) Demo1::Demo1 app; // AND THEN START IT - int status = app.Run(); - - return status; + return app.Run(); } \ No newline at end of file