├── .clang-format ├── .cmake-format.py ├── .editorconfig ├── .gitattributes ├── .github └── workflows │ └── build.yml ├── .gitignore ├── .gitmodules ├── CMakeLists.txt ├── LICENSE ├── README.md ├── cmake ├── CFlagOverrides.cmake └── ClangFormat.cmake ├── examples ├── CMakeLists.txt ├── GPUParticle │ ├── CMakeLists.txt │ ├── GPUParticle.cpp │ ├── GPUParticle.h │ ├── Main.cpp │ ├── Shaders │ │ ├── GLSL_GL │ │ │ ├── perticle-emit.frag │ │ │ ├── perticle-emit.vert │ │ │ ├── perticle-render.frag │ │ │ ├── perticle-render.vert │ │ │ ├── perticle-update.frag │ │ │ └── perticle-update.vert │ │ ├── GLSL_VULKAN │ │ │ ├── perticle-emit.frag │ │ │ ├── perticle-emit.vert │ │ │ ├── perticle-render.frag │ │ │ ├── perticle-render.vert │ │ │ ├── perticle-update.frag │ │ │ └── perticle-update.vert │ │ ├── HLSL_DX12 │ │ │ ├── perticle-emit.frag │ │ │ ├── perticle-emit.vert │ │ │ ├── perticle-render.frag │ │ │ ├── perticle-render.vert │ │ │ ├── perticle-update.frag │ │ │ └── perticle-update.vert │ │ ├── Metal │ │ │ ├── perticle-emit.frag │ │ │ ├── perticle-emit.vert │ │ │ ├── perticle-render.frag │ │ │ ├── perticle-render.vert │ │ │ ├── perticle-update.frag │ │ │ └── perticle-update.vert │ │ └── SPIRV │ │ │ ├── perticle-emit.frag.spv │ │ │ ├── perticle-emit.vert.spv │ │ │ ├── perticle-render.frag.spv │ │ │ ├── perticle-render.vert.spv │ │ │ ├── perticle-update.frag.spv │ │ │ └── perticle-update.vert.spv │ └── Textures │ │ └── Particle01.png ├── ImGuiPlatform │ ├── CMakeLists.txt │ ├── ImGuiPlatform.h │ ├── ImGuiPlatformDX12.cpp │ ├── ImGuiPlatformDX12.h │ ├── ImGuiPlatformMetal.h │ ├── ImGuiPlatformMetal.mm │ ├── ImGuiPlatformVulkan.cpp │ └── ImGuiPlatformVulkan.h ├── glfw │ ├── CMakeLists.txt │ └── main.cpp ├── imgui │ ├── CMakeLists.txt │ └── main.cpp └── thirdparty │ └── imgui │ ├── CMakeLists.txt │ ├── LICENSE.txt │ ├── imconfig.h │ ├── imgui.cpp │ ├── imgui.h │ ├── imgui_draw.cpp │ ├── imgui_impl_dx12.cpp │ ├── imgui_impl_dx12.h │ ├── imgui_impl_glfw.cpp │ ├── imgui_impl_glfw.h │ ├── imgui_impl_metal.h │ ├── imgui_impl_metal.mm │ ├── imgui_impl_vulkan.cpp │ ├── imgui_impl_vulkan.h │ ├── imgui_internal.h │ ├── imgui_tables.cpp │ ├── imgui_widgets.cpp │ ├── imstb_rectpack.h │ ├── imstb_textedit.h │ └── imstb_truetype.h ├── scripts ├── GenerateProjects.bat ├── GenerateProjects_ClangFormat.bat ├── GenerateProjects_ClangFormat.sh ├── GenerateProjects_Mac.sh ├── GenerateProjects_Vulkan.bat └── transpile.py ├── src ├── CMakeLists.txt ├── DX12 │ ├── LLGI.BaseDX12.cpp │ ├── LLGI.BaseDX12.h │ ├── LLGI.BufferDX12.cpp │ ├── LLGI.BufferDX12.h │ ├── LLGI.CommandListDX12.cpp │ ├── LLGI.CommandListDX12.h │ ├── LLGI.CompilerDX12.cpp │ ├── LLGI.CompilerDX12.h │ ├── LLGI.DescriptorHeapDX12.cpp │ ├── LLGI.DescriptorHeapDX12.h │ ├── LLGI.GraphicsDX12.cpp │ ├── LLGI.GraphicsDX12.h │ ├── LLGI.PipelineStateDX12.cpp │ ├── LLGI.PipelineStateDX12.h │ ├── LLGI.PlatformDX12.cpp │ ├── LLGI.PlatformDX12.h │ ├── LLGI.QueryDX12.cpp │ ├── LLGI.QueryDX12.h │ ├── LLGI.RenderPassDX12.cpp │ ├── LLGI.RenderPassDX12.h │ ├── LLGI.RenderPassPipelineStateDX12.cpp │ ├── LLGI.RenderPassPipelineStateDX12.h │ ├── LLGI.ShaderDX12.cpp │ ├── LLGI.ShaderDX12.h │ ├── LLGI.SingleFrameMemoryPoolDX12.cpp │ ├── LLGI.SingleFrameMemoryPoolDX12.h │ ├── LLGI.TextureDX12.cpp │ └── LLGI.TextureDX12.h ├── LLGI.Base.h ├── LLGI.Buffer.cpp ├── LLGI.Buffer.h ├── LLGI.CommandList.cpp ├── LLGI.CommandList.h ├── LLGI.Compiler.cpp ├── LLGI.Compiler.h ├── LLGI.Graphics.cpp ├── LLGI.Graphics.h ├── LLGI.PipelineState.cpp ├── LLGI.PipelineState.h ├── LLGI.Platform.cpp ├── LLGI.Platform.h ├── LLGI.Query.cpp ├── LLGI.Query.h ├── LLGI.Shader.h ├── LLGI.Texture.cpp ├── LLGI.Texture.h ├── Linux │ ├── LLGI.WindowLinux.cpp │ └── LLGI.WindowLinux.h ├── Mac │ ├── LLGI.WindowMac.h │ └── LLGI.WindowMac.mm ├── Metal │ ├── LLGI.BufferMetal.h │ ├── LLGI.BufferMetal.mm │ ├── LLGI.CommandListMetal.h │ ├── LLGI.CommandListMetal.mm │ ├── LLGI.CompilerMetal.h │ ├── LLGI.CompilerMetal.mm │ ├── LLGI.GraphicsMetal.h │ ├── LLGI.GraphicsMetal.mm │ ├── LLGI.Metal_Impl.h │ ├── LLGI.Metal_Impl.mm │ ├── LLGI.PipelineStateMetal.h │ ├── LLGI.PipelineStateMetal.mm │ ├── LLGI.PlatformMetal.h │ ├── LLGI.PlatformMetal.mm │ ├── LLGI.QueryMetal.h │ ├── LLGI.QueryMetal.mm │ ├── LLGI.RenderPassMetal.h │ ├── LLGI.RenderPassMetal.mm │ ├── LLGI.ShaderMetal.h │ ├── LLGI.ShaderMetal.mm │ ├── LLGI.SingleFrameMemoryPoolMetal.h │ ├── LLGI.SingleFrameMemoryPoolMetal.mm │ ├── LLGI.TextureMetal.h │ └── LLGI.TextureMetal.mm ├── PC │ └── LLGI.CreatePC.cpp ├── Utils │ ├── LLGI.CommandListPool.h │ └── LLGI.FixedSizeVector.h ├── Vulkan │ ├── LLGI.BaseVulkan.cpp │ ├── LLGI.BaseVulkan.h │ ├── LLGI.BufferVulkan.cpp │ ├── LLGI.BufferVulkan.h │ ├── LLGI.CommandListVulkan.cpp │ ├── LLGI.CommandListVulkan.h │ ├── LLGI.CompilerVulkan.cpp │ ├── LLGI.CompilerVulkan.h │ ├── LLGI.GraphicsVulkan.cpp │ ├── LLGI.GraphicsVulkan.h │ ├── LLGI.PipelineStateVulkan.cpp │ ├── LLGI.PipelineStateVulkan.h │ ├── LLGI.PlatformVulkan.cpp │ ├── LLGI.PlatformVulkan.h │ ├── LLGI.QueryVulkan.cpp │ ├── LLGI.QueryVulkan.h │ ├── LLGI.RenderPassPipelineStateCacheVulkan.cpp │ ├── LLGI.RenderPassPipelineStateCacheVulkan.h │ ├── LLGI.RenderPassVulkan.cpp │ ├── LLGI.RenderPassVulkan.h │ ├── LLGI.ShaderVulkan.cpp │ ├── LLGI.ShaderVulkan.h │ ├── LLGI.SingleFrameMemoryPoolVulkan.cpp │ ├── LLGI.SingleFrameMemoryPoolVulkan.h │ ├── LLGI.TextureVulkan.cpp │ └── LLGI.TextureVulkan.h └── Win │ ├── LLGI.WindowWin.cpp │ └── LLGI.WindowWin.h ├── src_test ├── CMakeLists.txt ├── Shaders │ ├── GLSL_GL │ │ ├── basic.comp │ │ ├── instancing.vert │ │ ├── readwrite.comp │ │ ├── readwrite_texture.comp │ │ ├── simple_compute_rectangle.frag │ │ ├── simple_compute_rectangle.vert │ │ ├── simple_constant_rectangle.frag │ │ ├── simple_constant_rectangle.vert │ │ ├── simple_mrt_texture_rectangle.frag │ │ ├── simple_rectangle.frag │ │ ├── simple_rectangle.vert │ │ ├── simple_texture_rectangle.frag │ │ ├── simple_texture_rectangle.vert │ │ ├── textures.frag │ │ ├── vertex_structured.vert │ │ └── vtf.vert │ ├── GLSL_VULKAN │ │ ├── basic.comp │ │ ├── instancing.vert │ │ ├── readwrite.comp │ │ ├── readwrite_texture.comp │ │ ├── simple_compute_rectangle.frag │ │ ├── simple_compute_rectangle.vert │ │ ├── simple_constant_rectangle.frag │ │ ├── simple_constant_rectangle.vert │ │ ├── simple_mrt_texture_rectangle.frag │ │ ├── simple_rectangle.frag │ │ ├── simple_rectangle.vert │ │ ├── simple_texture_rectangle.frag │ │ ├── simple_texture_rectangle.vert │ │ ├── textures.frag │ │ ├── vertex_structured.vert │ │ └── vtf.vert │ ├── HLSL_DX12 │ │ ├── basic.comp │ │ ├── instancing.vert │ │ ├── readwrite.comp │ │ ├── readwrite_texture.comp │ │ ├── simple_compute_rectangle.frag │ │ ├── simple_compute_rectangle.vert │ │ ├── simple_constant_rectangle.frag │ │ ├── simple_constant_rectangle.vert │ │ ├── simple_mrt_texture_rectangle.frag │ │ ├── simple_rectangle.frag │ │ ├── simple_rectangle.vert │ │ ├── simple_texture_rectangle.frag │ │ ├── simple_texture_rectangle.vert │ │ ├── textures.frag │ │ ├── vertex_structured.vert │ │ └── vtf.vert │ ├── Metal │ │ ├── basic.comp │ │ ├── instancing.vert │ │ ├── readwrite.comp │ │ ├── readwrite_texture.comp │ │ ├── simple_compute_rectangle.frag │ │ ├── simple_compute_rectangle.vert │ │ ├── simple_constant_rectangle.frag │ │ ├── simple_constant_rectangle.vert │ │ ├── simple_mrt_texture_rectangle.frag │ │ ├── simple_rectangle.frag │ │ ├── simple_rectangle.vert │ │ ├── simple_texture_rectangle.frag │ │ ├── simple_texture_rectangle.vert │ │ ├── textures.frag │ │ ├── vertex_structured.vert │ │ └── vtf.vert │ └── SPIRV │ │ ├── basic.comp.spv │ │ ├── instancing.vert.spv │ │ ├── readwrite.comp.spv │ │ ├── readwrite_texture.comp.spv │ │ ├── simple_compute_rectangle.frag.spv │ │ ├── simple_compute_rectangle.vert.spv │ │ ├── simple_constant_rectangle.frag.spv │ │ ├── simple_constant_rectangle.vert.spv │ │ ├── simple_mrt_texture_rectangle.frag.spv │ │ ├── simple_rectangle.frag.spv │ │ ├── simple_rectangle.vert.spv │ │ ├── simple_texture_rectangle.frag.spv │ │ ├── simple_texture_rectangle.vert.spv │ │ ├── textures.frag.spv │ │ ├── vertex_structured.vert.spv │ │ └── vtf.vert.spv ├── TestHelper.cpp ├── TestHelper.h ├── capture.cpp ├── main.cpp ├── test.h ├── test_clear.cpp ├── test_compile.cpp ├── test_compute_shader.cpp ├── test_depth_stencil.cpp ├── test_empty.cpp ├── test_mipmap.cpp ├── test_renderPass.cpp ├── test_simple_render.cpp ├── test_textures.cpp └── thirdparty │ └── stb │ ├── stb_image.h │ └── stb_image_write.h └── tools ├── CMakeLists.txt ├── README.md ├── ShaderTranspiler ├── CMakeLists.txt └── main.cpp └── ShaderTranspilerCore ├── CMakeLists.txt ├── ShaderTranspilerCore.cpp └── ShaderTranspilerCore.h /.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: LLVM 2 | IndentWidth: 4 3 | TabWidth: 4 4 | AccessModifierOffset: -4 5 | UseTab: Always 6 | BreakBeforeBraces: Allman 7 | ColumnLimit: 140 8 | 9 | DerivePointerAlignment: false 10 | PointerAlignment: Left 11 | 12 | BinPackArguments: false 13 | BinPackParameters: false 14 | 15 | ConstructorInitializerAllOnOneLineOrOnePerLine : true 16 | BreakConstructorInitializersBeforeComma : true 17 | -------------------------------------------------------------------------------- /.cmake-format.py: -------------------------------------------------------------------------------- 1 | # ----------------------------- 2 | # Options effecting formatting. 3 | # ----------------------------- 4 | with section("format"): 5 | 6 | # How wide to allow formatted cmake files 7 | line_width = 80 8 | 9 | # How many spaces to tab for indent 10 | tab_size = 2 11 | 12 | # If true, separate flow control names from their parentheses with a space 13 | separate_ctrl_name_with_space = False 14 | 15 | # If true, separate function names from parentheses with a space 16 | separate_fn_name_with_space = False 17 | 18 | # If a statement is wrapped to more than one line, than dangle the closing 19 | # parenthesis on its own line. 20 | dangle_parens = False 21 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | end_of_line = lf 5 | insert_final_newline = true 6 | charset = utf-8 7 | indent_style = tab 8 | trim_trailing_whitespace = true 9 | indent_size = 4 10 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | 3 | *.bat text eol=crlf 4 | 5 | *.cpp text eol=lf 6 | *.h text eol=lf 7 | *.sh text eol=lf 8 | 9 | *.py text eol=lf 10 | *.md text eol=lf 11 | CMakeLists.txt text eol=lf 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | .vs 34 | /msvc/*.user 35 | **/Debug 36 | /build 37 | /build_clangformat 38 | 39 | .DS_Store 40 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "examples/thirdparty/glfw"] 2 | path = examples/thirdparty/glfw 3 | url = https://github.com/glfw/glfw.git 4 | [submodule "thirdparty/glslang"] 5 | path = thirdparty/glslang 6 | url = https://github.com/KhronosGroup/glslang.git 7 | [submodule "thirdparty/SPIRV-Cross"] 8 | path = thirdparty/SPIRV-Cross 9 | url = https://github.com/KhronosGroup/SPIRV-Cross.git 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2019 Altseed 2 | 3 | This software is provided 'as-is', without any express or implied 4 | warranty. In no event will the authors be held liable for any damages 5 | arising from the use of this software. 6 | 7 | Permission is granted to anyone to use this software for any purpose, 8 | including commercial applications, and to alter it and redistribute it 9 | freely, subject to the following restrictions: 10 | 11 | 1. The origin of this software must not be misrepresented; you must not 12 | claim that you wrote the original software. If you use this software 13 | in a product, an acknowledgment in the product documentation would be 14 | appreciated but is not required. 15 | 16 | 2. Altered source versions must be plainly marked as such, and must not be 17 | misrepresented as being the original software. 18 | 19 | 3. This notice may not be removed or altered from any source 20 | distribution. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # LLGI 2 | 3 | How to build 4 | ---------- 5 | 6 | ### Windows 7 | 8 | ``` 9 | $ git clone https://github.com/altseed/LLGI.git 10 | $ cd LLGI 11 | $ git submodule update --init 12 | $ cmake -S . -B build -DBUILD_TEST=ON 13 | $ cmake --build build 14 | ``` 15 | 16 | ### macOS 17 | 18 | ``` 19 | $ git clone https://github.com/altseed/LLGI.git 20 | $ cd LLGI 21 | $ git submodule update --init 22 | $ cmake -S . -B build -G "Xcode" -DBUILD_TEST=ON 23 | $ cmake --build build 24 | ``` 25 | 26 | ### Vulkan(Window, Linux) 27 | 28 | ``` 29 | $ git clone https://github.com/altseed/LLGI.git 30 | $ cd LLGI 31 | $ git submodule update --init 32 | $ cmake -S . -B build -DBUILD_VULKAN=ON -DBUILD_TEST=ON 33 | $ cmake --build build 34 | ``` 35 | 36 | Test 37 | ---------- 38 | 39 | Run with Vulkan 40 | ``` 41 | ./LLGI_Test --vulkan 42 | ``` 43 | 44 | Run with single test 45 | 46 | ``` 47 | ./LLGI_Test --filter= 48 | ``` 49 | -------------------------------------------------------------------------------- /cmake/CFlagOverrides.cmake: -------------------------------------------------------------------------------- 1 | if(MSVC AND NOT USE_MSVC_RUNTIME_LIBRARY_DLL) 2 | foreach(flag CMAKE_C_FLAGS_DEBUG_INIT CMAKE_C_FLAGS_MINSIZEREL_INIT CMAKE_C_FLAGS_RELEASE_INIT CMAKE_C_FLAGS_RELWITHDEBINFO_INIT CMAKE_CXX_FLAGS_DEBUG_INIT CMAKE_CXX_FLAGS_MINSIZEREL_INIT CMAKE_CXX_FLAGS_RELEASE_INIT CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT) 3 | if(${flag} MATCHES "/MD") 4 | string(REGEX REPLACE "/MD" "/MT" ${flag} "${${flag}}") 5 | endif() 6 | if(${flag} MATCHES "/MDd") 7 | string(REGEX REPLACE "/MDd" "/MTd" ${flag} "${${flag}}") 8 | endif() 9 | endforeach() 10 | foreach(flag CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE) 11 | if(${flag} MATCHES "/MD") 12 | string(REGEX REPLACE "/MD" "/MT" ${flag} "${${flag}}") 13 | endif() 14 | if(${flag} MATCHES "/MDd") 15 | string(REGEX REPLACE "/MDd" "/MTd" ${flag} "${${flag}}") 16 | endif() 17 | endforeach() 18 | elseif(MSVC AND USE_MSVC_RUNTIME_LIBRARY_DLL) 19 | foreach(flag CMAKE_C_FLAGS_DEBUG_INIT CMAKE_C_FLAGS_MINSIZEREL_INIT CMAKE_C_FLAGS_RELEASE_INIT CMAKE_C_FLAGS_RELWITHDEBINFO_INIT CMAKE_CXX_FLAGS_DEBUG_INIT CMAKE_CXX_FLAGS_MINSIZEREL_INIT CMAKE_CXX_FLAGS_RELEASE_INIT CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT) 20 | if(${flag} MATCHES "/MT") 21 | string(REGEX REPLACE "/MT" "/MD" ${flag} "${${flag}}") 22 | endif() 23 | if(${flag} MATCHES "/MTd") 24 | string(REGEX REPLACE "/MTd" "/MDd" ${flag} "${${flag}}") 25 | endif() 26 | endforeach() 27 | foreach(flag CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE) 28 | if(${flag} MATCHES "/MT") 29 | string(REGEX REPLACE "/MT" "/MD" ${flag} "${${flag}}") 30 | endif() 31 | if(${flag} MATCHES "/MTd") 32 | string(REGEX REPLACE "/MTd" "/MDd" ${flag} "${${flag}}") 33 | endif() 34 | endforeach() 35 | endif() 36 | -------------------------------------------------------------------------------- /cmake/ClangFormat.cmake: -------------------------------------------------------------------------------- 1 | # Based on https://qiita.com/tenmyo/items/f8548ee9bab78f18cd25 2 | 3 | option(CLANG_FORMAT_ENABLED "Specifies whether clang-format is automatically applied." OFF) 4 | find_program(CLANG_FORMAT_EXE clang-format) 5 | 6 | function(clang_format target) 7 | if(CLANG_FORMAT_EXE AND CLANG_FORMAT_ENABLED) 8 | message(STATUS "Enable Clang-Format ${target}") 9 | get_target_property(MY_SOURCES ${target} SOURCES) 10 | add_custom_target( 11 | "${target}_format-with-clang-format" 12 | COMMAND "${CLANG_FORMAT_EXE}" -i -style=file ${MY_SOURCES} 13 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} 14 | ) 15 | add_dependencies(${target} "${target}_format-with-clang-format") 16 | endif() 17 | endfunction() 18 | -------------------------------------------------------------------------------- /examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory("thirdparty/glfw/") 2 | add_subdirectory("thirdparty/imgui/") 3 | add_subdirectory("ImGuiPlatform") 4 | add_subdirectory("glfw") 5 | add_subdirectory("imgui") 6 | add_subdirectory("GPUParticle") 7 | -------------------------------------------------------------------------------- /examples/GPUParticle/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable( 2 | example_GPUParticle 3 | GPUParticle.h 4 | GPUParticle.cpp 5 | Main.cpp 6 | ) 7 | 8 | target_include_directories( 9 | example_GPUParticle 10 | PRIVATE 11 | ../../src/ 12 | ) 13 | 14 | target_link_libraries( 15 | example_GPUParticle 16 | PRIVATE 17 | LLGI 18 | glfw 19 | ) 20 | 21 | target_link_directories(example_GPUParticle PRIVATE ${THIRDPARTY_LIBRARY_DIRECTORIES}) 22 | target_link_libraries(example_GPUParticle PRIVATE ${THIRDPARTY_LIBRARIES}) 23 | target_compile_definitions(example_GPUParticle PRIVATE EXAMPLE_ASSET_DIR="${CMAKE_CURRENT_LIST_DIR}") 24 | 25 | if(WIN32) 26 | # None 27 | elseif(APPLE) 28 | 29 | find_library(COCOA_LIBRARY Cocoa) 30 | find_library(METAL_LIBRARY Metal) 31 | find_library(APPKIT_LIBRARY AppKit) 32 | find_library(METALKIT_LIBRARY MetalKit) 33 | find_library(QUARTZ_CORE_LIBRARY QuartzCore) 34 | 35 | set(EXTRA_LIBS ${COCOA_LIBRARY} ${APPKIT_LIBRARY} ${METAL_LIBRARY} ${METALKIT_LIBRARY} ${QUARTZ_CORE_LIBRARY}) 36 | target_link_libraries(example_GPUParticle PRIVATE ${EXTRA_LIBS}) 37 | 38 | else() 39 | 40 | find_package(Threads REQUIRED) 41 | target_link_libraries( 42 | example_GPUParticle 43 | PRIVATE 44 | ${CMAKE_THREAD_LIBS_INIT} 45 | pthread 46 | X11 47 | X11-xcb 48 | ) 49 | 50 | endif() 51 | 52 | 53 | if(BUILD_VULKAN) 54 | find_package(Vulkan REQUIRED) 55 | target_include_directories(example_GPUParticle PRIVATE ${Vulkan_INCLUDE_DIRS}) 56 | target_link_libraries(example_GPUParticle PRIVATE ${Vulkan_LIBRARIES}) 57 | 58 | target_include_directories(example_GPUParticle PRIVATE ${LLGI_THIRDPARTY_INCLUDES}) 59 | target_link_libraries(example_GPUParticle PRIVATE ${LLGI_THIRDPARTY_LIBRARIES}) 60 | target_link_directories(example_GPUParticle PRIVATE ${LLGI_THIRDPARTY_LIBRARY_DIRECTORIES}) 61 | endif() 62 | -------------------------------------------------------------------------------- /examples/GPUParticle/Shaders/GLSL_GL/perticle-emit.frag: -------------------------------------------------------------------------------- 1 | #version 430 2 | 3 | struct PS_INPUT 4 | { 5 | vec4 PositionData; 6 | vec4 VelocityAndLifeTimeData; 7 | }; 8 | 9 | struct VS_OUTPUT 10 | { 11 | vec4 Position; 12 | vec4 VelocityAndLifeTime; 13 | }; 14 | 15 | layout(location = 0) in vec4 input_PositionData; 16 | layout(location = 1) in vec4 input_VelocityAndLifeTimeData; 17 | layout(location = 0) out vec4 _entryPointOutput_Position; 18 | layout(location = 1) out vec4 _entryPointOutput_VelocityAndLifeTime; 19 | 20 | VS_OUTPUT _main(PS_INPUT _input) 21 | { 22 | VS_OUTPUT _output; 23 | _output.Position = _input.PositionData; 24 | _output.VelocityAndLifeTime = _input.VelocityAndLifeTimeData; 25 | return _output; 26 | } 27 | 28 | void main() 29 | { 30 | PS_INPUT _input; 31 | _input.PositionData = input_PositionData; 32 | _input.VelocityAndLifeTimeData = input_VelocityAndLifeTimeData; 33 | PS_INPUT param = _input; 34 | VS_OUTPUT flattenTemp = _main(param); 35 | _entryPointOutput_Position = flattenTemp.Position; 36 | _entryPointOutput_VelocityAndLifeTime = flattenTemp.VelocityAndLifeTime; 37 | } 38 | 39 | -------------------------------------------------------------------------------- /examples/GPUParticle/Shaders/GLSL_GL/perticle-emit.vert: -------------------------------------------------------------------------------- 1 | #version 430 2 | 3 | out gl_PerVertex 4 | { 5 | vec4 gl_Position; 6 | }; 7 | 8 | struct VS_INPUT 9 | { 10 | vec2 ParticleIDAndLifeTime; 11 | vec3 Position; 12 | vec3 Velocity; 13 | }; 14 | 15 | struct VS_OUTPUT 16 | { 17 | vec4 PositionData; 18 | vec4 VelocityAndLifeTimeData; 19 | vec4 Position; 20 | }; 21 | 22 | layout(binding = 0, std140) uniform GPUParticleTextureInfo 23 | { 24 | vec4 TextureSize; 25 | layout(row_major) mat4 ViewProjMatrix; 26 | } CBVS0; 27 | 28 | layout(location = 0) in vec2 input_ParticleIDAndLifeTime; 29 | layout(location = 1) in vec3 input_Position; 30 | layout(location = 2) in vec3 input_Velocity; 31 | layout(location = 0) out vec4 _entryPointOutput_PositionData; 32 | layout(location = 1) out vec4 _entryPointOutput_VelocityAndLifeTimeData; 33 | 34 | VS_OUTPUT _main(VS_INPUT _input) 35 | { 36 | vec2 HalfPixelOffsetInClipSpace = vec2(1.0 / CBVS0.TextureSize.x, (-1.0) / CBVS0.TextureSize.y); 37 | float particleID = _input.ParticleIDAndLifeTime.x; 38 | float lifeTime = _input.ParticleIDAndLifeTime.y; 39 | vec2 texelPos = vec2(mod(particleID, CBVS0.TextureSize.x), particleID / CBVS0.TextureSize.x); 40 | vec2 svPos = (texelPos / vec2(CBVS0.TextureSize.xy)) * 2.0; 41 | svPos += vec2(-1.0); 42 | svPos.y *= (-1.0); 43 | svPos += HalfPixelOffsetInClipSpace; 44 | VS_OUTPUT _output; 45 | _output.Position = vec4(svPos, 0.0, 1.0); 46 | _output.PositionData = vec4(_input.Position, 0.0); 47 | _output.VelocityAndLifeTimeData = vec4(_input.Velocity, lifeTime); 48 | return _output; 49 | } 50 | 51 | void main() 52 | { 53 | VS_INPUT _input; 54 | _input.ParticleIDAndLifeTime = input_ParticleIDAndLifeTime; 55 | _input.Position = input_Position; 56 | _input.Velocity = input_Velocity; 57 | VS_INPUT param = _input; 58 | VS_OUTPUT flattenTemp = _main(param); 59 | _entryPointOutput_PositionData = flattenTemp.PositionData; 60 | _entryPointOutput_VelocityAndLifeTimeData = flattenTemp.VelocityAndLifeTimeData; 61 | gl_Position = flattenTemp.Position; 62 | } 63 | 64 | -------------------------------------------------------------------------------- /examples/GPUParticle/Shaders/GLSL_GL/perticle-render.frag: -------------------------------------------------------------------------------- 1 | #version 430 2 | 3 | struct PS_INPUT 4 | { 5 | vec2 UV; 6 | vec4 Color; 7 | }; 8 | 9 | layout(binding = 0) uniform sampler2D _66; 10 | 11 | layout(location = 0) in vec2 input_UV; 12 | layout(location = 1) in vec4 input_Color; 13 | layout(location = 0) out vec4 _entryPointOutput; 14 | 15 | vec4 _main(PS_INPUT _input) 16 | { 17 | if (_input.Color.w <= 0.0) 18 | { 19 | discard; 20 | } 21 | vec4 color = texture(_66, _input.UV); 22 | return color * _input.Color; 23 | } 24 | 25 | void main() 26 | { 27 | PS_INPUT _input; 28 | _input.UV = input_UV; 29 | _input.Color = input_Color; 30 | PS_INPUT param = _input; 31 | vec4 _64 = _main(param); 32 | _entryPointOutput = _64; 33 | } 34 | 35 | -------------------------------------------------------------------------------- /examples/GPUParticle/Shaders/GLSL_GL/perticle-render.vert: -------------------------------------------------------------------------------- 1 | #version 430 2 | #ifdef GL_ARB_shader_draw_parameters 3 | #extension GL_ARB_shader_draw_parameters : enable 4 | #endif 5 | 6 | out gl_PerVertex 7 | { 8 | vec4 gl_Position; 9 | }; 10 | 11 | struct VS_INPUT 12 | { 13 | vec3 Position; 14 | vec2 UV; 15 | uint InstanceId; 16 | }; 17 | 18 | struct VS_OUTPUT 19 | { 20 | vec2 UV; 21 | vec4 Color; 22 | vec4 Position; 23 | }; 24 | 25 | layout(binding = 0, std140) uniform GPUParticleTextureInfo 26 | { 27 | vec4 TextureResolution; 28 | layout(row_major) mat4 ViewProjMatrix; 29 | } CBVS0; 30 | 31 | layout(binding = 0) uniform sampler2D _143; 32 | layout(binding = 0) uniform sampler2D _145; 33 | 34 | layout(location = 0) in vec3 input_Position; 35 | layout(location = 1) in vec2 input_UV; 36 | #ifdef GL_ARB_shader_draw_parameters 37 | #define SPIRV_Cross_BaseInstance gl_BaseInstanceARB 38 | #else 39 | uniform int SPIRV_Cross_BaseInstance; 40 | #endif 41 | layout(location = 0) out vec2 _entryPointOutput_UV; 42 | layout(location = 1) out vec4 _entryPointOutput_Color; 43 | 44 | mat4 spvWorkaroundRowMajor(mat4 wrap) { return wrap; } 45 | 46 | VS_OUTPUT _main(VS_INPUT _input) 47 | { 48 | vec2 texelPos = vec2(mod(float(_input.InstanceId), CBVS0.TextureResolution.x), float(_input.InstanceId) / CBVS0.TextureResolution.x); 49 | vec2 fetchUV = texelPos * CBVS0.TextureResolution.zw; 50 | vec4 positionAndLocalTime = textureLod(_143, fetchUV, 0.0); 51 | vec4 velocityAndLifeTime = textureLod(_145, fetchUV, 0.0); 52 | vec3 posOffset = positionAndLocalTime.xyz; 53 | vec3 worldPos = _input.Position + posOffset; 54 | VS_OUTPUT _output; 55 | _output.Position = vec4(worldPos, 1.0) * spvWorkaroundRowMajor(CBVS0.ViewProjMatrix); 56 | _output.UV = _input.UV; 57 | _output.Color = vec4(1.0, 1.0, 1.0, 1.0 - (positionAndLocalTime.w / (velocityAndLifeTime.w + 9.9999997473787516355514526367188e-06))); 58 | return _output; 59 | } 60 | 61 | void main() 62 | { 63 | VS_INPUT _input; 64 | _input.Position = input_Position; 65 | _input.UV = input_UV; 66 | _input.InstanceId = uint((gl_InstanceID + SPIRV_Cross_BaseInstance)); 67 | VS_INPUT param = _input; 68 | VS_OUTPUT flattenTemp = _main(param); 69 | _entryPointOutput_UV = flattenTemp.UV; 70 | _entryPointOutput_Color = flattenTemp.Color; 71 | gl_Position = flattenTemp.Position; 72 | } 73 | 74 | -------------------------------------------------------------------------------- /examples/GPUParticle/Shaders/GLSL_GL/perticle-update.frag: -------------------------------------------------------------------------------- 1 | #version 430 2 | 3 | struct PS_INPUT 4 | { 5 | vec2 UV; 6 | }; 7 | 8 | struct PS_OUTPUT 9 | { 10 | vec4 PositionAndLocalTime; 11 | vec4 VelocityAndLifeTime; 12 | }; 13 | 14 | layout(binding = 0) uniform sampler2D _91; 15 | layout(binding = 0) uniform sampler2D _93; 16 | 17 | layout(location = 0) in vec2 input_UV; 18 | layout(location = 0) out vec4 _entryPointOutput_PositionAndLocalTime; 19 | layout(location = 1) out vec4 _entryPointOutput_VelocityAndLifeTime; 20 | 21 | PS_OUTPUT _main(PS_INPUT _input) 22 | { 23 | vec4 positionAndLocalTime = texture(_91, _input.UV); 24 | vec4 velocityAndLifeTime = texture(_93, _input.UV); 25 | vec3 position = positionAndLocalTime.xyz + velocityAndLifeTime.xyz; 26 | float localTime = positionAndLocalTime.w + 0.01600000075995922088623046875; 27 | PS_OUTPUT _output; 28 | _output.PositionAndLocalTime = vec4(position, localTime); 29 | _output.VelocityAndLifeTime = velocityAndLifeTime; 30 | return _output; 31 | } 32 | 33 | void main() 34 | { 35 | PS_INPUT _input; 36 | _input.UV = input_UV; 37 | PS_INPUT param = _input; 38 | PS_OUTPUT flattenTemp = _main(param); 39 | _entryPointOutput_PositionAndLocalTime = flattenTemp.PositionAndLocalTime; 40 | _entryPointOutput_VelocityAndLifeTime = flattenTemp.VelocityAndLifeTime; 41 | } 42 | 43 | -------------------------------------------------------------------------------- /examples/GPUParticle/Shaders/GLSL_GL/perticle-update.vert: -------------------------------------------------------------------------------- 1 | #version 430 2 | 3 | out gl_PerVertex 4 | { 5 | vec4 gl_Position; 6 | }; 7 | 8 | struct VS_INPUT 9 | { 10 | vec3 Position; 11 | vec2 UV; 12 | }; 13 | 14 | struct VS_OUTPUT 15 | { 16 | vec2 UV; 17 | vec4 Position; 18 | }; 19 | 20 | layout(location = 0) in vec3 input_Position; 21 | layout(location = 1) in vec2 input_UV; 22 | layout(location = 0) out vec2 _entryPointOutput_UV; 23 | 24 | VS_OUTPUT _main(VS_INPUT _input) 25 | { 26 | VS_OUTPUT _output; 27 | _output.Position = vec4(_input.Position, 1.0); 28 | _output.UV = _input.UV; 29 | return _output; 30 | } 31 | 32 | void main() 33 | { 34 | VS_INPUT _input; 35 | _input.Position = input_Position; 36 | _input.UV = input_UV; 37 | VS_INPUT param = _input; 38 | VS_OUTPUT flattenTemp = _main(param); 39 | _entryPointOutput_UV = flattenTemp.UV; 40 | gl_Position = flattenTemp.Position; 41 | } 42 | 43 | -------------------------------------------------------------------------------- /examples/GPUParticle/Shaders/GLSL_VULKAN/perticle-emit.frag: -------------------------------------------------------------------------------- 1 | #version 430 2 | 3 | struct PS_INPUT 4 | { 5 | vec4 PositionData; 6 | vec4 VelocityAndLifeTimeData; 7 | }; 8 | 9 | struct VS_OUTPUT 10 | { 11 | vec4 Position; 12 | vec4 VelocityAndLifeTime; 13 | }; 14 | 15 | layout(location = 0) in vec4 input_PositionData; 16 | layout(location = 1) in vec4 input_VelocityAndLifeTimeData; 17 | layout(location = 0) out vec4 _entryPointOutput_Position; 18 | layout(location = 1) out vec4 _entryPointOutput_VelocityAndLifeTime; 19 | 20 | VS_OUTPUT _main(PS_INPUT _input) 21 | { 22 | VS_OUTPUT _output; 23 | _output.Position = _input.PositionData; 24 | _output.VelocityAndLifeTime = _input.VelocityAndLifeTimeData; 25 | return _output; 26 | } 27 | 28 | void main() 29 | { 30 | PS_INPUT _input; 31 | _input.PositionData = input_PositionData; 32 | _input.VelocityAndLifeTimeData = input_VelocityAndLifeTimeData; 33 | PS_INPUT param = _input; 34 | VS_OUTPUT flattenTemp = _main(param); 35 | _entryPointOutput_Position = flattenTemp.Position; 36 | _entryPointOutput_VelocityAndLifeTime = flattenTemp.VelocityAndLifeTime; 37 | } 38 | 39 | -------------------------------------------------------------------------------- /examples/GPUParticle/Shaders/GLSL_VULKAN/perticle-emit.vert: -------------------------------------------------------------------------------- 1 | #version 430 2 | 3 | struct VS_INPUT 4 | { 5 | vec2 ParticleIDAndLifeTime; 6 | vec3 Position; 7 | vec3 Velocity; 8 | }; 9 | 10 | struct VS_OUTPUT 11 | { 12 | vec4 PositionData; 13 | vec4 VelocityAndLifeTimeData; 14 | vec4 Position; 15 | }; 16 | 17 | layout(set = 0, binding = 0, std140) uniform GPUParticleTextureInfo 18 | { 19 | vec4 TextureSize; 20 | layout(row_major) mat4 ViewProjMatrix; 21 | } _23; 22 | 23 | layout(location = 0) in vec2 input_ParticleIDAndLifeTime; 24 | layout(location = 1) in vec3 input_Position; 25 | layout(location = 2) in vec3 input_Velocity; 26 | layout(location = 0) out vec4 _entryPointOutput_PositionData; 27 | layout(location = 1) out vec4 _entryPointOutput_VelocityAndLifeTimeData; 28 | 29 | VS_OUTPUT _main(VS_INPUT _input) 30 | { 31 | vec2 HalfPixelOffsetInClipSpace = vec2(1.0 / _23.TextureSize.x, (-1.0) / _23.TextureSize.y); 32 | float particleID = _input.ParticleIDAndLifeTime.x; 33 | float lifeTime = _input.ParticleIDAndLifeTime.y; 34 | vec2 texelPos = vec2(mod(particleID, _23.TextureSize.x), particleID / _23.TextureSize.x); 35 | vec2 svPos = (texelPos / vec2(_23.TextureSize.xy)) * 2.0; 36 | svPos += vec2(-1.0); 37 | svPos.y *= (-1.0); 38 | svPos += HalfPixelOffsetInClipSpace; 39 | VS_OUTPUT _output; 40 | _output.Position = vec4(svPos, 0.0, 1.0); 41 | _output.PositionData = vec4(_input.Position, 0.0); 42 | _output.VelocityAndLifeTimeData = vec4(_input.Velocity, lifeTime); 43 | return _output; 44 | } 45 | 46 | void main() 47 | { 48 | VS_INPUT _input; 49 | _input.ParticleIDAndLifeTime = input_ParticleIDAndLifeTime; 50 | _input.Position = input_Position; 51 | _input.Velocity = input_Velocity; 52 | VS_INPUT param = _input; 53 | VS_OUTPUT flattenTemp = _main(param); 54 | _entryPointOutput_PositionData = flattenTemp.PositionData; 55 | _entryPointOutput_VelocityAndLifeTimeData = flattenTemp.VelocityAndLifeTimeData; 56 | vec4 _position = flattenTemp.Position; 57 | _position.y = -_position.y; 58 | gl_Position = _position; 59 | } 60 | 61 | -------------------------------------------------------------------------------- /examples/GPUParticle/Shaders/GLSL_VULKAN/perticle-render.frag: -------------------------------------------------------------------------------- 1 | #version 430 2 | 3 | struct PS_INPUT 4 | { 5 | vec2 UV; 6 | vec4 Color; 7 | }; 8 | 9 | layout(location = 2, set = 1, binding = 3) uniform sampler2D Sampler_ParticleSamplerState_; 10 | 11 | layout(location = 0) in vec2 input_UV; 12 | layout(location = 1) in vec4 input_Color; 13 | layout(location = 0) out vec4 _entryPointOutput; 14 | 15 | vec4 _main(PS_INPUT _input) 16 | { 17 | if (_input.Color.w <= 0.0) 18 | { 19 | discard; 20 | } 21 | vec4 color = texture(Sampler_ParticleSamplerState_, _input.UV); 22 | return color * _input.Color; 23 | } 24 | 25 | void main() 26 | { 27 | PS_INPUT _input; 28 | _input.UV = input_UV; 29 | _input.Color = input_Color; 30 | PS_INPUT param = _input; 31 | vec4 _64 = _main(param); 32 | _entryPointOutput = _64; 33 | } 34 | 35 | -------------------------------------------------------------------------------- /examples/GPUParticle/Shaders/GLSL_VULKAN/perticle-render.vert: -------------------------------------------------------------------------------- 1 | #version 430 2 | 3 | struct VS_INPUT 4 | { 5 | vec3 Position; 6 | vec2 UV; 7 | uint InstanceId; 8 | }; 9 | 10 | struct VS_OUTPUT 11 | { 12 | vec2 UV; 13 | vec4 Color; 14 | vec4 Position; 15 | }; 16 | 17 | layout(set = 0, binding = 0, std140) uniform GPUParticleTextureInfo 18 | { 19 | vec4 TextureResolution; 20 | layout(row_major) mat4 ViewProjMatrix; 21 | } _29; 22 | 23 | layout(location = 0, set = 0, binding = 1) uniform sampler2D Sampler_PositionSamplerState_; 24 | layout(location = 1, set = 0, binding = 2) uniform sampler2D Sampler_VelocitySamplerState_; 25 | 26 | layout(location = 0) in vec3 input_Position; 27 | layout(location = 1) in vec2 input_UV; 28 | layout(location = 0) out vec2 _entryPointOutput_UV; 29 | layout(location = 1) out vec4 _entryPointOutput_Color; 30 | 31 | VS_OUTPUT _main(VS_INPUT _input) 32 | { 33 | vec2 texelPos = vec2(mod(float(_input.InstanceId), _29.TextureResolution.x), float(_input.InstanceId) / _29.TextureResolution.x); 34 | vec2 fetchUV = texelPos * _29.TextureResolution.zw; 35 | vec4 positionAndLocalTime = textureLod(Sampler_PositionSamplerState_, fetchUV, 0.0); 36 | vec4 velocityAndLifeTime = textureLod(Sampler_VelocitySamplerState_, fetchUV, 0.0); 37 | vec3 posOffset = positionAndLocalTime.xyz; 38 | vec3 worldPos = _input.Position + posOffset; 39 | VS_OUTPUT _output; 40 | _output.Position = vec4(worldPos, 1.0) * _29.ViewProjMatrix; 41 | _output.UV = _input.UV; 42 | _output.Color = vec4(1.0, 1.0, 1.0, 1.0 - (positionAndLocalTime.w / (velocityAndLifeTime.w + 9.9999997473787516355514526367188e-06))); 43 | return _output; 44 | } 45 | 46 | void main() 47 | { 48 | VS_INPUT _input; 49 | _input.Position = input_Position; 50 | _input.UV = input_UV; 51 | _input.InstanceId = uint(gl_InstanceIndex); 52 | VS_INPUT param = _input; 53 | VS_OUTPUT flattenTemp = _main(param); 54 | _entryPointOutput_UV = flattenTemp.UV; 55 | _entryPointOutput_Color = flattenTemp.Color; 56 | vec4 _position = flattenTemp.Position; 57 | _position.y = -_position.y; 58 | gl_Position = _position; 59 | } 60 | 61 | -------------------------------------------------------------------------------- /examples/GPUParticle/Shaders/GLSL_VULKAN/perticle-update.frag: -------------------------------------------------------------------------------- 1 | #version 430 2 | 3 | struct PS_INPUT 4 | { 5 | vec2 UV; 6 | }; 7 | 8 | struct PS_OUTPUT 9 | { 10 | vec4 PositionAndLocalTime; 11 | vec4 VelocityAndLifeTime; 12 | }; 13 | 14 | layout(location = 0, set = 1, binding = 1) uniform sampler2D Sampler_PositionSamplerState_; 15 | layout(location = 1, set = 1, binding = 2) uniform sampler2D Sampler_VelocitySamplerState_; 16 | 17 | layout(location = 0) in vec2 input_UV; 18 | layout(location = 0) out vec4 _entryPointOutput_PositionAndLocalTime; 19 | layout(location = 1) out vec4 _entryPointOutput_VelocityAndLifeTime; 20 | 21 | PS_OUTPUT _main(PS_INPUT _input) 22 | { 23 | vec4 positionAndLocalTime = texture(Sampler_PositionSamplerState_, _input.UV); 24 | vec4 velocityAndLifeTime = texture(Sampler_VelocitySamplerState_, _input.UV); 25 | vec3 position = positionAndLocalTime.xyz + velocityAndLifeTime.xyz; 26 | float localTime = positionAndLocalTime.w + 0.01600000075995922088623046875; 27 | PS_OUTPUT _output; 28 | _output.PositionAndLocalTime = vec4(position, localTime); 29 | _output.VelocityAndLifeTime = velocityAndLifeTime; 30 | return _output; 31 | } 32 | 33 | void main() 34 | { 35 | PS_INPUT _input; 36 | _input.UV = input_UV; 37 | PS_INPUT param = _input; 38 | PS_OUTPUT flattenTemp = _main(param); 39 | _entryPointOutput_PositionAndLocalTime = flattenTemp.PositionAndLocalTime; 40 | _entryPointOutput_VelocityAndLifeTime = flattenTemp.VelocityAndLifeTime; 41 | } 42 | 43 | -------------------------------------------------------------------------------- /examples/GPUParticle/Shaders/GLSL_VULKAN/perticle-update.vert: -------------------------------------------------------------------------------- 1 | #version 430 2 | 3 | struct VS_INPUT 4 | { 5 | vec3 Position; 6 | vec2 UV; 7 | }; 8 | 9 | struct VS_OUTPUT 10 | { 11 | vec2 UV; 12 | vec4 Position; 13 | }; 14 | 15 | layout(location = 0) in vec3 input_Position; 16 | layout(location = 1) in vec2 input_UV; 17 | layout(location = 0) out vec2 _entryPointOutput_UV; 18 | 19 | VS_OUTPUT _main(VS_INPUT _input) 20 | { 21 | VS_OUTPUT _output; 22 | _output.Position = vec4(_input.Position, 1.0); 23 | _output.UV = _input.UV; 24 | return _output; 25 | } 26 | 27 | void main() 28 | { 29 | VS_INPUT _input; 30 | _input.Position = input_Position; 31 | _input.UV = input_UV; 32 | VS_INPUT param = _input; 33 | VS_OUTPUT flattenTemp = _main(param); 34 | _entryPointOutput_UV = flattenTemp.UV; 35 | vec4 _position = flattenTemp.Position; 36 | _position.y = -_position.y; 37 | gl_Position = _position; 38 | } 39 | 40 | -------------------------------------------------------------------------------- /examples/GPUParticle/Shaders/HLSL_DX12/perticle-emit.frag: -------------------------------------------------------------------------------- 1 | 2 | struct PS_INPUT 3 | { 4 | float4 PositionData : UV0; 5 | float4 VelocityAndLifeTimeData : COLOR0; 6 | }; 7 | 8 | struct VS_OUTPUT 9 | { 10 | float4 Position : SV_TARGET0; 11 | float4 VelocityAndLifeTime : SV_TARGET1; 12 | }; 13 | 14 | VS_OUTPUT main(PS_INPUT input) 15 | { 16 | VS_OUTPUT output; 17 | output.Position = input.PositionData; 18 | output.VelocityAndLifeTime = input.VelocityAndLifeTimeData; 19 | 20 | // Debug 21 | //output.Position = float4(1, 0, 0, 0); 22 | //output.VelocityAndLifeTime = float4(0, 1, 0, 1); 23 | //output.Position.a = 1.0; 24 | 25 | return output; 26 | } 27 | -------------------------------------------------------------------------------- /examples/GPUParticle/Shaders/HLSL_DX12/perticle-emit.vert: -------------------------------------------------------------------------------- 1 | struct VS_INPUT 2 | { 3 | float2 ParticleIDAndLifeTime: UV0; 4 | float3 Position: POSITION0; 5 | float3 Velocity: COLOR0; 6 | }; 7 | 8 | struct VS_OUTPUT 9 | { 10 | float4 PositionData : UV0; 11 | float4 VelocityAndLifeTimeData : COLOR0; 12 | float4 Position : SV_POSITION; 13 | }; 14 | 15 | cbuffer GPUParticleTextureInfo : register(b0) 16 | { 17 | float4 TextureSize; 18 | float4x4 ViewProjMatrix; 19 | }; 20 | 21 | 22 | VS_OUTPUT main(VS_INPUT input) 23 | { 24 | //const float2 TextureSize2 = float2(512, 512); 25 | const float2 HalfPixelOffsetInClipSpace = float2(1.0 / TextureSize.x, -1.0 / TextureSize.y); 26 | 27 | VS_OUTPUT output; 28 | float particleID = input.ParticleIDAndLifeTime.x; 29 | float lifeTime = input.ParticleIDAndLifeTime.y; 30 | 31 | //float2 svPos = float2(particleID & ID2TPos.x, particleID >> ID2TPos.y) * TPos2VPos.x + TPos2VPos.y; 32 | float2 texelPos = float2(fmod(particleID, TextureSize.x), particleID / TextureSize.x); 33 | float2 svPos = (texelPos / TextureSize) * 2.0; 34 | svPos += float2(-1.0, -1.0); 35 | svPos.y *= -1.0; 36 | 37 | // "GeForce RTX 2080 SUPER" + DX12 にて、(-1.0, 1.0) のように境界の位置にレンダリングしようとしたとき、描画されなくなることがあった。 38 | // そのため、確実に Pixel 内にレンダリングされるようにオフセットをつけている。 39 | svPos += HalfPixelOffsetInClipSpace; 40 | 41 | //svPos = float2(particleID / 10.0, 0); 42 | 43 | output.Position = float4(svPos, 0.0, 1.0); 44 | output.PositionData = float4(input.Position, 0.0); 45 | output.VelocityAndLifeTimeData = float4(input.Velocity, lifeTime); 46 | 47 | return output; 48 | } 49 | -------------------------------------------------------------------------------- /examples/GPUParticle/Shaders/HLSL_DX12/perticle-render.frag: -------------------------------------------------------------------------------- 1 | 2 | Texture2D ParticleTexture_ : register(t2); 3 | SamplerState ParticleSamplerState_ : register(s2); 4 | 5 | struct PS_INPUT 6 | { 7 | float2 UV : UV0; 8 | float4 Color: COLOR0; 9 | }; 10 | 11 | float4 main(PS_INPUT input) : SV_TARGET 12 | { 13 | if (input.Color.a <= 0.0) discard; 14 | 15 | float4 color = ParticleTexture_.Sample(ParticleSamplerState_, input.UV); 16 | 17 | 18 | return color * input.Color; 19 | } 20 | -------------------------------------------------------------------------------- /examples/GPUParticle/Shaders/HLSL_DX12/perticle-render.vert: -------------------------------------------------------------------------------- 1 | 2 | Texture2D PositionTexture_ : register(t0); 3 | SamplerState PositionSamplerState_ : register(s0); 4 | 5 | Texture2D VelocityTexture_ : register(t1); 6 | SamplerState VelocitySamplerState_ : register(s1); 7 | 8 | struct VS_INPUT 9 | { 10 | float3 Position : POSITION0; 11 | float2 UV : UV0; 12 | uint InstanceId : SV_InstanceID; // = ParticleId 13 | }; 14 | 15 | struct VS_OUTPUT 16 | { 17 | float2 UV : UV0; 18 | float4 Color: COLOR0; 19 | float4 Position : SV_POSITION; 20 | }; 21 | 22 | cbuffer GPUParticleTextureInfo : register(b0) 23 | { 24 | float4 TextureResolution; 25 | float4x4 ViewProjMatrix; 26 | }; 27 | 28 | VS_OUTPUT main(VS_INPUT input) 29 | { 30 | float2 texelPos = float2(fmod(input.InstanceId, TextureResolution.x), input.InstanceId / TextureResolution.x); 31 | float2 fetchUV = texelPos * TextureResolution.zw; 32 | float4 positionAndLocalTime = PositionTexture_.SampleLevel(PositionSamplerState_, fetchUV, 0); 33 | float4 velocityAndLifeTime = VelocityTexture_.SampleLevel(VelocitySamplerState_, fetchUV, 0); 34 | 35 | float3 posOffset = positionAndLocalTime.xyz; 36 | 37 | float3 worldPos = input.Position + posOffset; 38 | 39 | VS_OUTPUT output; 40 | output.Position = mul(ViewProjMatrix, float4(worldPos, 1.0f)); 41 | output.UV = input.UV; 42 | output.Color = float4(1, 1, 1, 1.0f - (positionAndLocalTime.w / (velocityAndLifeTime.w + 0.00001))); 43 | 44 | return output; 45 | } 46 | -------------------------------------------------------------------------------- /examples/GPUParticle/Shaders/HLSL_DX12/perticle-update.frag: -------------------------------------------------------------------------------- 1 | 2 | Texture2D PositionTexture_ : register(t0); 3 | SamplerState PositionSamplerState_ : register(s0); 4 | 5 | Texture2D VelocityTexture_ : register(t1); 6 | SamplerState VelocitySamplerState_ : register(s1); 7 | 8 | struct PS_INPUT 9 | { 10 | float2 UV : UV0; 11 | }; 12 | 13 | struct PS_OUTPUT 14 | { 15 | float4 PositionAndLocalTime : SV_TARGET0; 16 | float4 VelocityAndLifeTime : SV_TARGET1; 17 | }; 18 | 19 | PS_OUTPUT main(PS_INPUT input) : SV_TARGET 20 | { 21 | float4 positionAndLocalTime = PositionTexture_.Sample(PositionSamplerState_, input.UV); 22 | float4 velocityAndLifeTime = VelocityTexture_.Sample(VelocitySamplerState_, input.UV); 23 | 24 | float3 position = positionAndLocalTime.xyz + velocityAndLifeTime.xyz; 25 | float localTime = positionAndLocalTime.w + 0.016; 26 | 27 | PS_OUTPUT output; 28 | output.PositionAndLocalTime = float4(position, localTime); 29 | output.VelocityAndLifeTime = velocityAndLifeTime; 30 | return output; 31 | } 32 | -------------------------------------------------------------------------------- /examples/GPUParticle/Shaders/HLSL_DX12/perticle-update.vert: -------------------------------------------------------------------------------- 1 | 2 | // Note: Copy screen only. 3 | 4 | struct VS_INPUT 5 | { 6 | float3 Position : POSITION0; 7 | float2 UV : UV0; 8 | }; 9 | 10 | struct VS_OUTPUT 11 | { 12 | float2 UV : UV0; 13 | float4 Position : SV_POSITION; 14 | }; 15 | 16 | VS_OUTPUT main(VS_INPUT input) 17 | { 18 | VS_OUTPUT output; 19 | output.Position = float4(input.Position, 1.0f); 20 | output.UV = input.UV; 21 | return output; 22 | } 23 | -------------------------------------------------------------------------------- /examples/GPUParticle/Shaders/Metal/perticle-emit.frag: -------------------------------------------------------------------------------- 1 | #pragma clang diagnostic ignored "-Wmissing-prototypes" 2 | 3 | #include 4 | #include 5 | 6 | using namespace metal; 7 | 8 | struct PS_INPUT 9 | { 10 | float4 PositionData; 11 | float4 VelocityAndLifeTimeData; 12 | }; 13 | 14 | struct VS_OUTPUT 15 | { 16 | float4 Position; 17 | float4 VelocityAndLifeTime; 18 | }; 19 | 20 | struct main0_out 21 | { 22 | float4 _entryPointOutput_Position [[color(0)]]; 23 | float4 _entryPointOutput_VelocityAndLifeTime [[color(1)]]; 24 | }; 25 | 26 | struct main0_in 27 | { 28 | float4 input_PositionData [[user(locn0)]]; 29 | float4 input_VelocityAndLifeTimeData [[user(locn1)]]; 30 | }; 31 | 32 | static inline __attribute__((always_inline)) 33 | VS_OUTPUT _main(thread const PS_INPUT& _input) 34 | { 35 | VS_OUTPUT _output; 36 | _output.Position = _input.PositionData; 37 | _output.VelocityAndLifeTime = _input.VelocityAndLifeTimeData; 38 | return _output; 39 | } 40 | 41 | fragment main0_out main0(main0_in in [[stage_in]]) 42 | { 43 | main0_out out = {}; 44 | PS_INPUT _input; 45 | _input.PositionData = in.input_PositionData; 46 | _input.VelocityAndLifeTimeData = in.input_VelocityAndLifeTimeData; 47 | PS_INPUT param = _input; 48 | VS_OUTPUT flattenTemp = _main(param); 49 | out._entryPointOutput_Position = flattenTemp.Position; 50 | out._entryPointOutput_VelocityAndLifeTime = flattenTemp.VelocityAndLifeTime; 51 | return out; 52 | } 53 | 54 | -------------------------------------------------------------------------------- /examples/GPUParticle/Shaders/Metal/perticle-render.frag: -------------------------------------------------------------------------------- 1 | #pragma clang diagnostic ignored "-Wmissing-prototypes" 2 | 3 | #include 4 | #include 5 | 6 | using namespace metal; 7 | 8 | struct PS_INPUT 9 | { 10 | float2 UV; 11 | float4 Color; 12 | }; 13 | 14 | struct main0_out 15 | { 16 | float4 _entryPointOutput [[color(0)]]; 17 | }; 18 | 19 | struct main0_in 20 | { 21 | float2 input_UV [[user(locn0)]]; 22 | float4 input_Color [[user(locn1)]]; 23 | }; 24 | 25 | static inline __attribute__((always_inline)) 26 | float4 _main(thread const PS_INPUT& _input, texture2d ParticleTexture_, sampler ParticleSamplerState_) 27 | { 28 | if (_input.Color.w <= 0.0) 29 | { 30 | discard_fragment(); 31 | } 32 | float4 color = ParticleTexture_.sample(ParticleSamplerState_, _input.UV); 33 | return color * _input.Color; 34 | } 35 | 36 | fragment main0_out main0(main0_in in [[stage_in]], texture2d ParticleTexture_ [[texture(2)]], sampler ParticleSamplerState_ [[sampler(2)]]) 37 | { 38 | main0_out out = {}; 39 | PS_INPUT _input; 40 | _input.UV = in.input_UV; 41 | _input.Color = in.input_Color; 42 | PS_INPUT param = _input; 43 | float4 _64 = _main(param, ParticleTexture_, ParticleSamplerState_); 44 | out._entryPointOutput = _64; 45 | return out; 46 | } 47 | 48 | -------------------------------------------------------------------------------- /examples/GPUParticle/Shaders/Metal/perticle-update.frag: -------------------------------------------------------------------------------- 1 | #pragma clang diagnostic ignored "-Wmissing-prototypes" 2 | 3 | #include 4 | #include 5 | 6 | using namespace metal; 7 | 8 | struct PS_INPUT 9 | { 10 | float2 UV; 11 | }; 12 | 13 | struct PS_OUTPUT 14 | { 15 | float4 PositionAndLocalTime; 16 | float4 VelocityAndLifeTime; 17 | }; 18 | 19 | struct main0_out 20 | { 21 | float4 _entryPointOutput_PositionAndLocalTime [[color(0)]]; 22 | float4 _entryPointOutput_VelocityAndLifeTime [[color(1)]]; 23 | }; 24 | 25 | struct main0_in 26 | { 27 | float2 input_UV [[user(locn0)]]; 28 | }; 29 | 30 | static inline __attribute__((always_inline)) 31 | PS_OUTPUT _main(thread const PS_INPUT& _input, texture2d PositionTexture_, sampler PositionSamplerState_, texture2d VelocityTexture_, sampler VelocitySamplerState_) 32 | { 33 | float4 positionAndLocalTime = PositionTexture_.sample(PositionSamplerState_, _input.UV); 34 | float4 velocityAndLifeTime = VelocityTexture_.sample(VelocitySamplerState_, _input.UV); 35 | float3 position = positionAndLocalTime.xyz + velocityAndLifeTime.xyz; 36 | float localTime = positionAndLocalTime.w + 0.01600000075995922088623046875; 37 | PS_OUTPUT _output; 38 | _output.PositionAndLocalTime = float4(position, localTime); 39 | _output.VelocityAndLifeTime = velocityAndLifeTime; 40 | return _output; 41 | } 42 | 43 | fragment main0_out main0(main0_in in [[stage_in]], texture2d PositionTexture_ [[texture(0)]], texture2d VelocityTexture_ [[texture(1)]], sampler PositionSamplerState_ [[sampler(0)]], sampler VelocitySamplerState_ [[sampler(1)]]) 44 | { 45 | main0_out out = {}; 46 | PS_INPUT _input; 47 | _input.UV = in.input_UV; 48 | PS_INPUT param = _input; 49 | PS_OUTPUT flattenTemp = _main(param, PositionTexture_, PositionSamplerState_, VelocityTexture_, VelocitySamplerState_); 50 | out._entryPointOutput_PositionAndLocalTime = flattenTemp.PositionAndLocalTime; 51 | out._entryPointOutput_VelocityAndLifeTime = flattenTemp.VelocityAndLifeTime; 52 | return out; 53 | } 54 | 55 | -------------------------------------------------------------------------------- /examples/GPUParticle/Shaders/Metal/perticle-update.vert: -------------------------------------------------------------------------------- 1 | #pragma clang diagnostic ignored "-Wmissing-prototypes" 2 | 3 | #include 4 | #include 5 | 6 | using namespace metal; 7 | 8 | struct VS_INPUT 9 | { 10 | float3 Position; 11 | float2 UV; 12 | }; 13 | 14 | struct VS_OUTPUT 15 | { 16 | float2 UV; 17 | float4 Position; 18 | }; 19 | 20 | struct main0_out 21 | { 22 | float2 _entryPointOutput_UV [[user(locn0)]]; 23 | float4 gl_Position [[position]]; 24 | }; 25 | 26 | struct main0_in 27 | { 28 | float3 input_Position [[attribute(0)]]; 29 | float2 input_UV [[attribute(1)]]; 30 | }; 31 | 32 | static inline __attribute__((always_inline)) 33 | VS_OUTPUT _main(thread const VS_INPUT& _input) 34 | { 35 | VS_OUTPUT _output; 36 | _output.Position = float4(_input.Position, 1.0); 37 | _output.UV = _input.UV; 38 | return _output; 39 | } 40 | 41 | vertex main0_out main0(main0_in in [[stage_in]]) 42 | { 43 | main0_out out = {}; 44 | VS_INPUT _input; 45 | _input.Position = in.input_Position; 46 | _input.UV = in.input_UV; 47 | VS_INPUT param = _input; 48 | VS_OUTPUT flattenTemp = _main(param); 49 | out._entryPointOutput_UV = flattenTemp.UV; 50 | out.gl_Position = flattenTemp.Position; 51 | return out; 52 | } 53 | 54 | -------------------------------------------------------------------------------- /examples/GPUParticle/Shaders/SPIRV/perticle-emit.frag.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/altseed/LLGI/c3f1775b66d507d8b0b15e52cc41f13815ef45c7/examples/GPUParticle/Shaders/SPIRV/perticle-emit.frag.spv -------------------------------------------------------------------------------- /examples/GPUParticle/Shaders/SPIRV/perticle-emit.vert.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/altseed/LLGI/c3f1775b66d507d8b0b15e52cc41f13815ef45c7/examples/GPUParticle/Shaders/SPIRV/perticle-emit.vert.spv -------------------------------------------------------------------------------- /examples/GPUParticle/Shaders/SPIRV/perticle-render.frag.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/altseed/LLGI/c3f1775b66d507d8b0b15e52cc41f13815ef45c7/examples/GPUParticle/Shaders/SPIRV/perticle-render.frag.spv -------------------------------------------------------------------------------- /examples/GPUParticle/Shaders/SPIRV/perticle-render.vert.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/altseed/LLGI/c3f1775b66d507d8b0b15e52cc41f13815ef45c7/examples/GPUParticle/Shaders/SPIRV/perticle-render.vert.spv -------------------------------------------------------------------------------- /examples/GPUParticle/Shaders/SPIRV/perticle-update.frag.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/altseed/LLGI/c3f1775b66d507d8b0b15e52cc41f13815ef45c7/examples/GPUParticle/Shaders/SPIRV/perticle-update.frag.spv -------------------------------------------------------------------------------- /examples/GPUParticle/Shaders/SPIRV/perticle-update.vert.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/altseed/LLGI/c3f1775b66d507d8b0b15e52cc41f13815ef45c7/examples/GPUParticle/Shaders/SPIRV/perticle-update.vert.spv -------------------------------------------------------------------------------- /examples/GPUParticle/Textures/Particle01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/altseed/LLGI/c3f1775b66d507d8b0b15e52cc41f13815ef45c7/examples/GPUParticle/Textures/Particle01.png -------------------------------------------------------------------------------- /examples/ImGuiPlatform/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set( 2 | srcs 3 | ImGuiPlatform.h 4 | ) 5 | 6 | if(WIN32) 7 | list( 8 | APPEND 9 | srcs 10 | ImGuiPlatformDX12.cpp 11 | ) 12 | endif() 13 | 14 | if(APPLE) 15 | list( 16 | APPEND 17 | srcs 18 | ImGuiPlatformMetal.mm 19 | ) 20 | endif() 21 | 22 | if(BUILD_VULKAN) 23 | list( 24 | APPEND 25 | srcs 26 | ImGuiPlatformVulkan.cpp 27 | ) 28 | endif() 29 | 30 | add_library( 31 | ImGuiPlatform 32 | STATIC 33 | ${srcs} 34 | ) 35 | 36 | target_compile_features(ImGuiPlatform PUBLIC cxx_std_14) 37 | 38 | target_include_directories( 39 | ImGuiPlatform 40 | PRIVATE 41 | ../../src/ 42 | ../thirdparty/imgui/ 43 | ) 44 | 45 | target_include_directories( 46 | ImGuiPlatform 47 | PUBLIC 48 | ./ 49 | ) 50 | 51 | target_link_libraries( 52 | ImGuiPlatform 53 | PRIVATE 54 | LLGI 55 | imgui 56 | ) 57 | 58 | if(BUILD_VULKAN) 59 | find_package(Vulkan REQUIRED) 60 | target_include_directories(ImGuiPlatform PRIVATE ${Vulkan_INCLUDE_DIRS}) 61 | endif() 62 | -------------------------------------------------------------------------------- /examples/ImGuiPlatform/ImGuiPlatform.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "../thirdparty/imgui/imgui.h" 8 | 9 | #if defined(_WIN32) 10 | #undef CreateFont 11 | #endif 12 | 13 | class ImguiPlatform 14 | { 15 | public: 16 | ImguiPlatform() = default; 17 | virtual ~ImguiPlatform() = default; 18 | 19 | virtual void NewFrame(LLGI::RenderPass* renderPass) = 0; 20 | 21 | virtual void RenderDrawData(ImDrawData* draw_data, LLGI::CommandList* commandList) = 0; 22 | 23 | virtual ImTextureID GetTextureIDToRender(LLGI::Texture* texture, LLGI::CommandList* commandList) { return nullptr; } 24 | 25 | virtual void CreateFont() {} 26 | 27 | virtual void DisposeFont() {} 28 | }; 29 | -------------------------------------------------------------------------------- /examples/ImGuiPlatform/ImGuiPlatformDX12.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "../thirdparty/imgui/imgui.h" 5 | #include "../thirdparty/imgui/imgui_impl_dx12.h" 6 | #include "ImGuiPlatform.h" 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #if defined(_WIN32) 13 | #undef CreateFont 14 | #endif 15 | 16 | class ImguiPlatformDX12 : public ImguiPlatform 17 | { 18 | const int32_t DescriptorMax = 512; 19 | LLGI::GraphicsDX12* g_ = nullptr; 20 | ID3D12DescriptorHeap* srvDescHeap_ = nullptr; 21 | int32_t handleOffset_ = 0; 22 | int32_t handleSize_ = 0; 23 | 24 | std::unordered_map, ImTextureID> textures_; 25 | 26 | public: 27 | ImguiPlatformDX12(LLGI::Graphics* g); 28 | 29 | virtual ~ImguiPlatformDX12(); 30 | 31 | void NewFrame(LLGI::RenderPass* renderPass) override; 32 | 33 | ImTextureID GetTextureIDToRender(LLGI::Texture* texture, LLGI::CommandList* commandList) override; 34 | 35 | void RenderDrawData(ImDrawData* draw_data, LLGI::CommandList* commandList) override; 36 | 37 | void CreateFont() override; 38 | 39 | void DisposeFont() override; 40 | }; 41 | -------------------------------------------------------------------------------- /examples/ImGuiPlatform/ImGuiPlatformMetal.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "ImGuiPlatform.h" 5 | #include 6 | 7 | class ImguiPlatformMetal_Impl; 8 | 9 | class ImguiPlatformMetal : public ImguiPlatform 10 | { 11 | ImguiPlatformMetal_Impl* impl = nullptr; 12 | std::unordered_set> textures_; 13 | 14 | public: 15 | ImguiPlatformMetal(LLGI::Graphics* g); 16 | 17 | ~ImguiPlatformMetal() override; 18 | 19 | void NewFrame(LLGI::RenderPass* renderPass) override; 20 | 21 | void RenderDrawData(ImDrawData* draw_data, LLGI::CommandList* commandList) override; 22 | 23 | ImTextureID GetTextureIDToRender(LLGI::Texture* texture, LLGI::CommandList* commandList) override; 24 | 25 | void CreateFont() override; 26 | 27 | void DisposeFont() override; 28 | }; 29 | -------------------------------------------------------------------------------- /examples/ImGuiPlatform/ImGuiPlatformMetal.mm: -------------------------------------------------------------------------------- 1 | #include "ImGuiPlatformMetal.h" 2 | 3 | #include "../thirdparty/imgui/imgui.h" 4 | #include "../thirdparty/imgui/imgui_impl_metal.h" 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | class ImguiPlatformMetal_Impl 12 | { 13 | public: 14 | LLGI::GraphicsMetal* g_ = nullptr; 15 | 16 | ImguiPlatformMetal_Impl(LLGI::Graphics* g) : g_(static_cast(g)) { ImGui_ImplMetal_Init(g_->GetDevice()); } 17 | 18 | virtual ~ImguiPlatformMetal_Impl() { ImGui_ImplMetal_Shutdown(); } 19 | 20 | void NewFrame(LLGI::RenderPass* renderPass) 21 | { 22 | auto rp = static_cast(renderPass); 23 | ImGui_ImplMetal_NewFrame(rp->GetRenderPassDescriptor()); 24 | } 25 | 26 | void RenderDrawData(ImDrawData* draw_data, LLGI::CommandList* commandList) 27 | { 28 | auto cl = static_cast(commandList); 29 | ImGui_ImplMetal_RenderDrawData(ImGui::GetDrawData(), cl->GetCommandBuffer(), cl->GetRenderCommandEncorder()); 30 | } 31 | }; 32 | 33 | ImguiPlatformMetal::ImguiPlatformMetal(LLGI::Graphics* g) { impl = new ImguiPlatformMetal_Impl(g); } 34 | 35 | ImguiPlatformMetal::~ImguiPlatformMetal() { delete impl; } 36 | 37 | void ImguiPlatformMetal::NewFrame(LLGI::RenderPass* renderPass) 38 | { 39 | @autoreleasepool 40 | { 41 | textures_.clear(); 42 | impl->NewFrame(renderPass); 43 | } 44 | } 45 | 46 | void ImguiPlatformMetal::RenderDrawData(ImDrawData* draw_data, LLGI::CommandList* commandList) 47 | { 48 | @autoreleasepool 49 | { 50 | impl->RenderDrawData(draw_data, commandList); 51 | } 52 | } 53 | 54 | ImTextureID ImguiPlatformMetal::GetTextureIDToRender(LLGI::Texture* texture, LLGI::CommandList* commandList) 55 | { 56 | @autoreleasepool 57 | { 58 | LLGI::SafeAddRef(texture); 59 | auto texturePtr = LLGI::CreateSharedPtr(texture); 60 | textures_.insert(texturePtr); 61 | 62 | auto t = static_cast(texture); 63 | return (__bridge void*)(t->GetTexture()); 64 | } 65 | } 66 | 67 | void ImguiPlatformMetal::CreateFont() { 68 | ImGui_ImplMetal_CreateFontsTexture(impl->g_->GetDevice()); } 69 | 70 | void ImguiPlatformMetal::DisposeFont() { ImGui_ImplMetal_DestroyFontsTexture(); } 71 | -------------------------------------------------------------------------------- /examples/ImGuiPlatform/ImGuiPlatformVulkan.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #ifdef _WIN32 5 | #define VK_PROTOTYPES 6 | #define VK_USE_PLATFORM_WIN32_KHR 7 | #else 8 | #define VK_PROTOTYPES 9 | #define VK_USE_PLATFORM_XCB_KHR 10 | #endif 11 | 12 | #include "../thirdparty/imgui/imgui.h" 13 | #include "../thirdparty/imgui/imgui_impl_vulkan.h" 14 | #include "ImGuiPlatform.h" 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | #if defined(_WIN32) 22 | #undef CreateFont 23 | #endif 24 | 25 | class ImguiPlatformVulkan : public ImguiPlatform 26 | { 27 | private: 28 | struct TextureHolder 29 | { 30 | std::shared_ptr texture; 31 | int32_t life; 32 | ImTextureID id; 33 | }; 34 | 35 | LLGI::GraphicsVulkan* g_ = nullptr; 36 | LLGI::PlatformVulkan* p_ = nullptr; 37 | LLGI::RenderPassPipelineStateVulkan* ps_ = nullptr; 38 | 39 | VkDescriptorPool descriptorPool_ = VK_NULL_HANDLE; 40 | 41 | std::unordered_map textures_; 42 | vk::Sampler defaultSampler_ = nullptr; 43 | 44 | public: 45 | ImguiPlatformVulkan(LLGI::Graphics* g, LLGI::Platform* p); 46 | 47 | ~ImguiPlatformVulkan() override; 48 | 49 | void NewFrame(LLGI::RenderPass* renderPass) override; 50 | 51 | void RenderDrawData(ImDrawData* draw_data, LLGI::CommandList* commandList) override 52 | { 53 | auto cl = static_cast(commandList); 54 | ImGui_ImplVulkan_RenderDrawData(ImGui::GetDrawData(), static_cast(cl->GetCommandBuffer())); 55 | } 56 | 57 | ImTextureID GetTextureIDToRender(LLGI::Texture* texture, LLGI::CommandList* commandList) override; 58 | 59 | void CreateFont() override; 60 | 61 | void DisposeFont() override; 62 | }; 63 | -------------------------------------------------------------------------------- /examples/glfw/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable( 2 | example_glfw 3 | main.cpp 4 | ) 5 | 6 | target_include_directories( 7 | example_glfw 8 | PRIVATE 9 | ../../src/ 10 | ) 11 | 12 | target_link_libraries( 13 | example_glfw 14 | PRIVATE 15 | LLGI 16 | glfw 17 | ) 18 | 19 | target_link_directories(example_glfw PRIVATE ${THIRDPARTY_LIBRARY_DIRECTORIES}) 20 | target_link_libraries(example_glfw PRIVATE ${THIRDPARTY_LIBRARIES}) 21 | 22 | if(WIN32) 23 | # None 24 | elseif(APPLE) 25 | 26 | find_library(COCOA_LIBRARY Cocoa) 27 | find_library(METAL_LIBRARY Metal) 28 | find_library(APPKIT_LIBRARY AppKit) 29 | find_library(METALKIT_LIBRARY MetalKit) 30 | find_library(QUARTZ_CORE_LIBRARY QuartzCore) 31 | 32 | set(EXTRA_LIBS ${COCOA_LIBRARY} ${APPKIT_LIBRARY} ${METAL_LIBRARY} ${METALKIT_LIBRARY} ${QUARTZ_CORE_LIBRARY}) 33 | target_link_libraries(example_glfw PRIVATE ${EXTRA_LIBS}) 34 | 35 | else() 36 | 37 | find_package(Threads REQUIRED) 38 | target_link_libraries( 39 | example_glfw 40 | PRIVATE 41 | ${CMAKE_THREAD_LIBS_INIT} 42 | pthread 43 | X11 44 | X11-xcb 45 | ) 46 | 47 | endif() 48 | 49 | 50 | 51 | if(BUILD_VULKAN) 52 | find_package(Vulkan REQUIRED) 53 | target_include_directories(example_glfw PRIVATE ${Vulkan_INCLUDE_DIRS}) 54 | target_link_libraries(example_glfw PRIVATE ${Vulkan_LIBRARIES}) 55 | 56 | target_include_directories(example_glfw PRIVATE ${LLGI_THIRDPARTY_INCLUDES}) 57 | target_link_libraries(example_glfw PRIVATE ${LLGI_THIRDPARTY_LIBRARIES}) 58 | target_link_directories(example_glfw PRIVATE ${LLGI_THIRDPARTY_LIBRARY_DIRECTORIES}) 59 | endif() 60 | -------------------------------------------------------------------------------- /examples/imgui/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable( 2 | example_imgui 3 | main.cpp 4 | ) 5 | 6 | target_include_directories( 7 | example_imgui 8 | PRIVATE 9 | ../../src/ 10 | ../thirdparty/imgui/ 11 | ) 12 | 13 | target_link_libraries( 14 | example_imgui 15 | PRIVATE 16 | LLGI 17 | glfw 18 | imgui 19 | ImGuiPlatform 20 | ) 21 | 22 | target_link_directories(example_imgui PRIVATE ${THIRDPARTY_LIBRARY_DIRECTORIES}) 23 | target_link_libraries(example_imgui PRIVATE ${THIRDPARTY_LIBRARIES}) 24 | 25 | if(WIN32) 26 | # None 27 | elseif(APPLE) 28 | 29 | find_library(COCOA_LIBRARY Cocoa) 30 | find_library(METAL_LIBRARY Metal) 31 | find_library(APPKIT_LIBRARY AppKit) 32 | find_library(METALKIT_LIBRARY MetalKit) 33 | find_library(QUARTZ_CORE_LIBRARY QuartzCore) 34 | 35 | set(EXTRA_LIBS ${COCOA_LIBRARY} ${APPKIT_LIBRARY} ${METAL_LIBRARY} ${METALKIT_LIBRARY} ${QUARTZ_CORE_LIBRARY}) 36 | target_link_libraries(example_imgui PRIVATE ${EXTRA_LIBS}) 37 | 38 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fobjc-arc") 39 | set_target_properties(example_imgui PROPERTIES XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC "YES") 40 | else() 41 | 42 | find_package(Threads REQUIRED) 43 | target_link_libraries( 44 | example_imgui 45 | PRIVATE 46 | ${CMAKE_THREAD_LIBS_INIT} 47 | pthread 48 | X11 49 | X11-xcb 50 | ) 51 | 52 | endif() 53 | 54 | if(BUILD_VULKAN) 55 | find_package(Vulkan REQUIRED) 56 | target_include_directories(example_imgui PRIVATE ${Vulkan_INCLUDE_DIRS}) 57 | target_link_libraries(example_imgui PRIVATE ${Vulkan_LIBRARIES}) 58 | 59 | target_include_directories(example_imgui PRIVATE ${LLGI_THIRDPARTY_INCLUDES}) 60 | target_link_libraries(example_imgui PRIVATE ${LLGI_THIRDPARTY_LIBRARIES}) 61 | target_link_directories(example_imgui PRIVATE ${LLGI_THIRDPARTY_LIBRARY_DIRECTORIES}) 62 | 63 | endif() 64 | -------------------------------------------------------------------------------- /examples/thirdparty/imgui/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | enable_language(CXX) 2 | 3 | # imgui 4 | list( 5 | APPEND srcs 6 | imgui.h 7 | imgui_impl_glfw.h 8 | imgui.cpp 9 | imgui_draw.cpp 10 | imgui_widgets.cpp 11 | imgui_tables.cpp 12 | imgui_impl_glfw.cpp 13 | ) 14 | 15 | if(WIN32) 16 | list( 17 | APPEND 18 | srcs 19 | imgui_impl_dx12.cpp 20 | ) 21 | 22 | elseif(APPLE) 23 | list( 24 | APPEND 25 | srcs 26 | imgui_impl_metal.mm 27 | ) 28 | endif() 29 | 30 | if(BUILD_VULKAN) 31 | list( 32 | APPEND 33 | srcs 34 | imgui_impl_vulkan.cpp 35 | ) 36 | endif() 37 | 38 | add_library(imgui STATIC ${srcs}) 39 | 40 | target_include_directories( 41 | imgui 42 | PRIVATE 43 | ../glfw/include 44 | ) 45 | 46 | set_property(TARGET imgui PROPERTY POSITION_INDEPENDENT_CODE ON) 47 | 48 | if(APPLE) 49 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fobjc-arc") 50 | set_target_properties(imgui PROPERTIES XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC "YES") 51 | endif() 52 | 53 | if(BUILD_VULKAN) 54 | find_package(Vulkan REQUIRED) 55 | target_include_directories(imgui PRIVATE ${Vulkan_INCLUDE_DIRS}) 56 | endif() 57 | -------------------------------------------------------------------------------- /examples/thirdparty/imgui/LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014-2020 Omar Cornut 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /examples/thirdparty/imgui/imgui_impl_glfw.h: -------------------------------------------------------------------------------- 1 | // dear imgui: Platform Backend for GLFW 2 | // This needs to be used along with a Renderer (e.g. OpenGL3, Vulkan, WebGPU..) 3 | // (Info: GLFW is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.) 4 | 5 | // Implemented features: 6 | // [X] Platform: Clipboard support. 7 | // [X] Platform: Gamepad support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'. 8 | // [x] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'. FIXME: 3 cursors types are missing from GLFW. 9 | // [X] Platform: Keyboard arrays indexed using GLFW_KEY_* codes, e.g. ImGui::IsKeyPressed(GLFW_KEY_SPACE). 10 | 11 | // You can copy and use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. 12 | // If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp. 13 | // Read online: https://github.com/ocornut/imgui/tree/master/docs 14 | 15 | // About GLSL version: 16 | // The 'glsl_version' initialization parameter defaults to "#version 150" if NULL. 17 | // Only override if your GL version doesn't handle this GLSL version. Keep NULL if unsure! 18 | 19 | #pragma once 20 | #include "imgui.h" // IMGUI_IMPL_API 21 | 22 | struct GLFWwindow; 23 | 24 | IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForOpenGL(GLFWwindow* window, bool install_callbacks); 25 | IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForVulkan(GLFWwindow* window, bool install_callbacks); 26 | IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForOther(GLFWwindow* window, bool install_callbacks); 27 | IMGUI_IMPL_API void ImGui_ImplGlfw_Shutdown(); 28 | IMGUI_IMPL_API void ImGui_ImplGlfw_NewFrame(); 29 | 30 | // GLFW callbacks 31 | // - When calling Init with 'install_callbacks=true': GLFW callbacks will be installed for you. They will call user's previously installed callbacks, if any. 32 | // - When calling Init with 'install_callbacks=false': GLFW callbacks won't be installed. You will need to call those function yourself from your own GLFW callbacks. 33 | IMGUI_IMPL_API void ImGui_ImplGlfw_MouseButtonCallback(GLFWwindow* window, int button, int action, int mods); 34 | IMGUI_IMPL_API void ImGui_ImplGlfw_ScrollCallback(GLFWwindow* window, double xoffset, double yoffset); 35 | IMGUI_IMPL_API void ImGui_ImplGlfw_KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods); 36 | IMGUI_IMPL_API void ImGui_ImplGlfw_CharCallback(GLFWwindow* window, unsigned int c); 37 | -------------------------------------------------------------------------------- /examples/thirdparty/imgui/imgui_impl_metal.h: -------------------------------------------------------------------------------- 1 | // dear imgui: Renderer Backend for Metal 2 | // This needs to be used along with a Platform Backend (e.g. OSX) 3 | 4 | // Implemented features: 5 | // [X] Renderer: User texture binding. Use 'MTLTexture' as ImTextureID. Read the FAQ about ImTextureID! 6 | // [X] Renderer: Support for large meshes (64k+ vertices) with 16-bit indices. 7 | 8 | // You can copy and use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. 9 | // If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp. 10 | // Read online: https://github.com/ocornut/imgui/tree/master/docs 11 | 12 | #include "imgui.h" // IMGUI_IMPL_API 13 | 14 | @class MTLRenderPassDescriptor; 15 | @protocol MTLDevice, MTLCommandBuffer, MTLRenderCommandEncoder; 16 | 17 | IMGUI_IMPL_API bool ImGui_ImplMetal_Init(id device); 18 | IMGUI_IMPL_API void ImGui_ImplMetal_Shutdown(); 19 | IMGUI_IMPL_API void ImGui_ImplMetal_NewFrame(MTLRenderPassDescriptor* renderPassDescriptor); 20 | IMGUI_IMPL_API void ImGui_ImplMetal_RenderDrawData(ImDrawData* draw_data, 21 | id commandBuffer, 22 | id commandEncoder); 23 | 24 | // Called by Init/NewFrame/Shutdown 25 | IMGUI_IMPL_API bool ImGui_ImplMetal_CreateFontsTexture(id device); 26 | IMGUI_IMPL_API void ImGui_ImplMetal_DestroyFontsTexture(); 27 | IMGUI_IMPL_API bool ImGui_ImplMetal_CreateDeviceObjects(id device); 28 | IMGUI_IMPL_API void ImGui_ImplMetal_DestroyDeviceObjects(); 29 | -------------------------------------------------------------------------------- /scripts/GenerateProjects.bat: -------------------------------------------------------------------------------- 1 | echo set current directory 2 | cd /d %~dp0 3 | 4 | mkdir ..\build 5 | 6 | cd /d ..\build 7 | 8 | cmake -A x64 -D BUILD_TEST=ON -D BUILD_EXAMPLE=ON -D BUILD_TOOL=ON ../ 9 | 10 | pause 11 | -------------------------------------------------------------------------------- /scripts/GenerateProjects_ClangFormat.bat: -------------------------------------------------------------------------------- 1 | echo set current directory 2 | cd /d %~dp0 3 | 4 | mkdir ..\build_clangformat 5 | 6 | cd /d ..\build_clangformat 7 | 8 | cmake -A x64 -D BUILD_TEST=ON -D BUILD_EXAMPLE=ON -D BUILD_TOOL=ON -DCLANG_FORMAT_ENABLED=ON ../ 9 | 10 | pause 11 | -------------------------------------------------------------------------------- /scripts/GenerateProjects_ClangFormat.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo set current directory 4 | cd `dirname $0` 5 | 6 | mkdir ../build_clangformat 7 | 8 | cd ../build_clangformat 9 | 10 | cmake -D BUILD_TEST=ON -D BUILD_EXAMPLE=ON -DCLANG_FORMAT_ENABLED=ON ../ 11 | -------------------------------------------------------------------------------- /scripts/GenerateProjects_Mac.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo set current directory 4 | cd `dirname $0` 5 | 6 | mkdir ../build 7 | 8 | cd ../build 9 | 10 | cmake -D BUILD_TEST=ON -D BUILD_EXAMPLE=ON -G "Xcode" ../ 11 | -------------------------------------------------------------------------------- /scripts/GenerateProjects_Vulkan.bat: -------------------------------------------------------------------------------- 1 | echo set current directory 2 | cd /d %~dp0 3 | 4 | mkdir ..\build 5 | 6 | cd /d ..\build 7 | 8 | cmake -D BUILD_TEST=ON -D BUILD_VULKAN=ON -D BUILD_VULKAN_COMPILER=ON -D BUILD_EXAMPLE=ON -D BUILD_TOOL=ON ../ 9 | 10 | pause 11 | -------------------------------------------------------------------------------- /scripts/transpile.py: -------------------------------------------------------------------------------- 1 | # Usage: python scripts/transpile.py {target} 2 | # e.g. python scripts/transpile.py src_test/Shaders/ 3 | # python scripts/transpile.py examples/GPUParticle/Shaders/ 4 | 5 | import os, subprocess, shutil, glob, platform, argparse 6 | 7 | aparser = argparse.ArgumentParser() 8 | aparser.add_argument('target', help='target directory') 9 | 10 | args = aparser.parse_args() 11 | 12 | target_directory=os.path.join(os.getcwd(), args.target) 13 | os.chdir(os.path.dirname(__file__)) 14 | 15 | transpiler_filename = "ShaderTranspiler" 16 | if platform.system() == 'Windows': 17 | transpiler_filename += ".exe" 18 | 19 | transpiler_path = os.path.join("../build/tools/ShaderTranspiler/Debug", transpiler_filename) 20 | transpiler_path_make = os.path.join("../build/tools/ShaderTranspiler", transpiler_filename) 21 | if os.path.isfile(transpiler_path): 22 | shutil.copy(transpiler_path, ".") 23 | elif os.path.isfile(transpiler_path_make): 24 | shutil.copy(transpiler_path_make, "./") 25 | 26 | transpiler_call = 'ShaderTranspiler' 27 | if platform.system() == 'Linux': 28 | transpiler_call = './ShaderTranspiler' 29 | 30 | verts = glob.glob(os.path.join(target_directory, 'HLSL_DX12/*.vert'), recursive=True) 31 | frags = glob.glob(os.path.join(target_directory, 'HLSL_DX12/*.frag'), recursive=True) 32 | comps = glob.glob(os.path.join(target_directory, 'HLSL_DX12/*.comp'), recursive=True) 33 | 34 | for target,directory in [ 35 | ('-M', 'Metal'), 36 | ('-V', 'GLSL_VULKAN'), 37 | ('-G', 'GLSL_GL')]: 38 | for kind,paths in [ 39 | ('--vert', verts), 40 | ('--frag', frags), 41 | ('--comp', comps) ]: 42 | for f in paths: 43 | subprocess.call([transpiler_call, kind, target, '--input', f, '--output', os.path.join(target_directory, directory, os.path.basename(f))]) 44 | 45 | verts = glob.glob(os.path.join(target_directory, 'GLSL_VULKAN/*.vert'), recursive=True) 46 | frags = glob.glob(os.path.join(target_directory, 'GLSL_VULKAN/*.frag'), recursive=True) 47 | comps = glob.glob(os.path.join(target_directory, 'GLSL_VULKAN/*.comp'), recursive=True) 48 | 49 | if platform.system() != 'Linux': 50 | for f in (verts + frags + comps): 51 | subprocess.call(['glslangValidator', f, '-e', 'main', '-V', '-o', os.path.join(target_directory, 'SPIRV', os.path.basename(f)) + '.spv']) 52 | -------------------------------------------------------------------------------- /src/DX12/LLGI.BaseDX12.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "../LLGI.Base.h" 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #pragma comment(lib, "d3d12.lib") 12 | #pragma comment(lib, "dxgi.lib") 13 | 14 | namespace LLGI 15 | { 16 | 17 | bool GetIsGPUDebugEnabled(); 18 | 19 | void SetIsGPUDebugEnabled(bool value); 20 | 21 | void DumpDX12_DRED(ID3D12Device* device); 22 | 23 | #if defined(_DEBUG) 24 | void StartDX12_DRED_Debug(); 25 | 26 | void EndDX12_DRED_Debug(); 27 | #endif 28 | 29 | #define SHOW_DX12_ERROR(x, device) \ 30 | if (FAILED(x)) \ 31 | { \ 32 | auto msg = (std::string("Error : ") + std::string(__FILE__) + " : " + std::to_string(__LINE__) + std::string(" : ") + \ 33 | std::system_category().message(hr)); \ 34 | ::LLGI::Log(::LLGI::LogType::Error, msg.c_str()); \ 35 | DumpDX12_DRED(device); \ 36 | } 37 | 38 | class BufferDX12; 39 | class GraphicsDX12; 40 | class RenderPassDX12; 41 | class SingleFrameMemoryPoolDX12; 42 | 43 | ID3D12Resource* CreateResourceBuffer(ID3D12Device* device, 44 | D3D12_HEAP_TYPE heapType, 45 | DXGI_FORMAT format, 46 | D3D12_RESOURCE_DIMENSION resourceDimention, 47 | D3D12_RESOURCE_STATES resourceState, 48 | D3D12_RESOURCE_FLAGS flags, 49 | Vec3I size, 50 | int32_t samplingCount); 51 | 52 | DXGI_FORMAT ConvertFormat(TextureFormatType format); 53 | 54 | TextureFormatType ConvertFormat(DXGI_FORMAT format); 55 | 56 | namespace DirectX12 57 | { 58 | 59 | DXGI_FORMAT GetGeneratedFormat(DXGI_FORMAT format); 60 | 61 | DXGI_FORMAT GetShaderResourceViewFormat(DXGI_FORMAT format); 62 | 63 | int32_t GetNodeMask(); 64 | 65 | void SetNodeMask(int nodeMask); 66 | 67 | } // namespace DirectX12 68 | 69 | } // namespace LLGI 70 | -------------------------------------------------------------------------------- /src/DX12/LLGI.BufferDX12.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../LLGI.Buffer.h" 4 | #include "LLGI.BaseDX12.h" 5 | #include "LLGI.GraphicsDX12.h" 6 | 7 | namespace LLGI 8 | { 9 | class BufferDX12 : public Buffer 10 | { 11 | private: 12 | ID3D12Resource* buffer_ = nullptr; 13 | uint8_t* mapped_ = nullptr; 14 | int32_t offset_ = 0; 15 | int32_t size_ = 0; 16 | int32_t actualSize_ = 0; 17 | D3D12_RESOURCE_STATES state_; 18 | 19 | public: 20 | bool Initialize(GraphicsDX12* graphics, const BufferUsageType usage, const int32_t size); 21 | bool InitializeAsShortTime(SingleFrameMemoryPoolDX12* memoryPool, int32_t size); 22 | 23 | BufferDX12(); 24 | ~BufferDX12() override; 25 | 26 | void* Lock() override; 27 | void* Lock(int32_t offset, int32_t size) override; 28 | void Unlock() override; 29 | 30 | int32_t GetSize() override; 31 | 32 | int32_t GetActualSize() const; 33 | int32_t GetOffset() const; 34 | 35 | ID3D12Resource* Get() { return buffer_; } 36 | 37 | D3D12_RESOURCE_STATES GetResourceState() { return state_; } 38 | }; 39 | 40 | } // namespace LLGI 41 | -------------------------------------------------------------------------------- /src/DX12/LLGI.CompilerDX12.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "../LLGI.Compiler.h" 5 | #include "LLGI.BaseDX12.h" 6 | 7 | namespace LLGI 8 | { 9 | 10 | enum class CompilerDX12Option : int32_t 11 | { 12 | None = 0, 13 | RowMajor = (1 << 0), 14 | ColumnMajor = (2 << 0), 15 | }; 16 | 17 | class CompilerDX12 : public Compiler 18 | { 19 | private: 20 | struct CompileShaderResultDX12 21 | { 22 | ID3DBlob* shader = nullptr; 23 | std::string error; 24 | }; 25 | 26 | CompileShaderResultDX12 CompileShader(const char* text, 27 | const char* fileName, 28 | const char* target, 29 | const std::vector& macro, 30 | const CompilerDX12Option& option = LLGI::CompilerDX12Option::ColumnMajor); 31 | 32 | CompilerDX12Option option_; 33 | 34 | public: 35 | CompilerDX12(const CompilerDX12Option& option = LLGI::CompilerDX12Option::ColumnMajor); 36 | ~CompilerDX12() override = default; 37 | 38 | void Initialize() override; 39 | void Compile(CompilerResult& result, const char* code, ShaderStageType shaderStage) override; 40 | 41 | DeviceType GetDeviceType() const override { return DeviceType::DirectX12; } 42 | }; 43 | 44 | } // namespace LLGI 45 | -------------------------------------------------------------------------------- /src/DX12/LLGI.DescriptorHeapDX12.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "LLGI.BaseDX12.h" 4 | #include "LLGI.GraphicsDX12.h" 5 | 6 | namespace LLGI 7 | { 8 | 9 | namespace DX12 10 | { 11 | class DescriptorHeapBlock 12 | { 13 | ID3D12DescriptorHeap* descriptorHeap_ = nullptr; 14 | int size_ = 0; 15 | D3D12_DESCRIPTOR_HEAP_TYPE type_; 16 | int offset_ = 0; 17 | int handleSize_ = 0; 18 | 19 | public: 20 | static std::shared_ptr Create(std::shared_ptr graphics, D3D12_DESCRIPTOR_HEAP_TYPE type, int size); 21 | 22 | DescriptorHeapBlock(ID3D12Device* device, ID3D12DescriptorHeap* descriptorHeap, D3D12_DESCRIPTOR_HEAP_TYPE type, int32_t size); 23 | ~DescriptorHeapBlock(); 24 | 25 | bool Allocate(std::array& cpuDescriptorHandle, 26 | std::array& gpuDescriptorHandle, 27 | int32_t requiredHandle); 28 | 29 | ID3D12DescriptorHeap* GetHeap() const; 30 | 31 | void Reset(); 32 | }; 33 | 34 | class DescriptorHeapAllocator 35 | { 36 | private: 37 | static const int DescriptorPerBlock = 128; 38 | std::shared_ptr graphics_; 39 | D3D12_DESCRIPTOR_HEAP_TYPE type_; 40 | std::vector> blocks_; 41 | int32_t offset_ = 0; 42 | 43 | public: 44 | DescriptorHeapAllocator(std::shared_ptr graphics, D3D12_DESCRIPTOR_HEAP_TYPE type); 45 | virtual ~DescriptorHeapAllocator(); 46 | 47 | bool Allocate(ID3D12DescriptorHeap*& heap, 48 | std::array& cpuDescriptorHandle, 49 | std::array& gpuDescriptorHandle, 50 | int32_t requiredHandle); 51 | 52 | void Reset(); 53 | }; 54 | 55 | } // namespace DX12 56 | 57 | } // namespace LLGI 58 | -------------------------------------------------------------------------------- /src/DX12/LLGI.PipelineStateDX12.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "../LLGI.PipelineState.h" 5 | #include "../LLGI.Shader.h" 6 | #include "LLGI.BaseDX12.h" 7 | #include "LLGI.GraphicsDX12.h" 8 | 9 | using namespace DirectX; 10 | 11 | namespace LLGI 12 | { 13 | 14 | class PipelineStateDX12 : public PipelineState 15 | { 16 | private: 17 | std::shared_ptr graphics_; 18 | 19 | std::array(ShaderStageType::Max)> shaders_; 20 | 21 | ID3D12PipelineState* pipelineState_ = nullptr; 22 | ID3D12PipelineState* computePipelineState_ = nullptr; 23 | 24 | ID3DBlob* signature_ = nullptr; 25 | ID3DBlob* computeSignature_ = nullptr; 26 | ID3D12RootSignature* rootSignature_ = nullptr; 27 | ID3D12RootSignature* computeRootSignature_ = nullptr; 28 | 29 | bool CreateRootSignature(); 30 | bool CreateComputeRootSignature(); 31 | 32 | bool CreatePipelineState(); 33 | bool CreateComputePipelineState(); 34 | 35 | public: 36 | PipelineStateDX12() = default; 37 | PipelineStateDX12(GraphicsDX12* graphics); 38 | ~PipelineStateDX12() override; 39 | 40 | void SetShader(ShaderStageType stage, Shader* shader) override; 41 | bool Compile() override; 42 | 43 | ID3D12PipelineState* GetPipelineState() { return pipelineState_; } 44 | ID3D12RootSignature* GetRootSignature() { return rootSignature_; } 45 | 46 | ID3D12PipelineState* GetComputePipelineState() { return computePipelineState_; } 47 | ID3D12RootSignature* GetComputeRootSignature() { return computeRootSignature_; } 48 | }; 49 | 50 | } // namespace LLGI 51 | -------------------------------------------------------------------------------- /src/DX12/LLGI.PlatformDX12.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "../LLGI.Platform.h" 5 | #include "LLGI.BaseDX12.h" 6 | #include "LLGI.TextureDX12.h" 7 | 8 | #ifdef _WIN32 9 | #include "../Win/LLGI.WindowWin.h" 10 | #endif 11 | 12 | namespace LLGI 13 | { 14 | 15 | class PlatformDX12 : public Platform 16 | { 17 | private: 18 | static const int SwapBufferCount = 2; 19 | Window* window_ = nullptr; 20 | 21 | Vec2I windowSize_; 22 | 23 | ID3D12Device* device = nullptr; 24 | IDXGIFactory4* dxgiFactory = nullptr; 25 | ID3D12CommandQueue* commandQueue = nullptr; 26 | ID3D12Fence* fence = nullptr; 27 | HANDLE fenceEvent = nullptr; 28 | IDXGISwapChain3* swapChain = nullptr; 29 | 30 | ID3D12DescriptorHeap* descriptorHeapRTV = nullptr; 31 | std::array handleRTV; 32 | std::array renderResources_; 33 | std::array renderTargets_; 34 | std::array renderPasses_; 35 | 36 | std::array commandAllocators; 37 | ID3D12GraphicsCommandList* commandListStart = nullptr; 38 | ID3D12GraphicsCommandList* commandListPresent = nullptr; 39 | UINT64 fenceValue = 1; 40 | 41 | int32_t frameIndex = 0; 42 | 43 | bool inFrame_ = false; 44 | 45 | void Wait(); 46 | 47 | void ResetSwapBuffer(); 48 | bool GenerateSwapBuffer(); 49 | 50 | public: 51 | PlatformDX12(); 52 | ~PlatformDX12() override; 53 | 54 | bool Initialize(Window* window, bool waitVSync); 55 | 56 | int GetCurrentFrameIndex() const override; 57 | int GetMaxFrameCount() const override; 58 | 59 | bool NewFrame() override; 60 | void Present() override; 61 | Graphics* CreateGraphics() override; 62 | 63 | ID3D12Device* GetDevice(); 64 | 65 | void SetWindowSize(const Vec2I& windowSize) override; 66 | 67 | RenderPass* GetCurrentScreen(const Color8& clearColor, bool isColorCleared, bool isDepthCleared) override; 68 | 69 | DeviceType GetDeviceType() const override { return DeviceType::DirectX12; } 70 | }; 71 | 72 | } // namespace LLGI 73 | -------------------------------------------------------------------------------- /src/DX12/LLGI.QueryDX12.cpp: -------------------------------------------------------------------------------- 1 | #include "LLGI.QueryDX12.h" 2 | #include "LLGI.SingleFrameMemoryPoolDX12.h" 3 | 4 | namespace LLGI 5 | { 6 | 7 | QueryDX12::QueryDX12() {} 8 | 9 | QueryDX12::~QueryDX12() 10 | { 11 | SafeRelease(buffer_); 12 | SafeRelease(queryHeap_); 13 | } 14 | 15 | bool QueryDX12::Initialize(GraphicsDX12* graphics, QueryType queryType, uint32_t queryCount) 16 | { 17 | queryType_ = queryType; 18 | queryCount_ = queryCount; 19 | 20 | { 21 | D3D12_QUERY_HEAP_DESC heapDesc = {}; 22 | heapDesc.Count = static_cast(queryCount); 23 | 24 | switch (queryType) 25 | { 26 | case QueryType::Timestamp: 27 | heapDesc.Type = D3D12_QUERY_HEAP_TYPE_TIMESTAMP; 28 | queryTypeDX12_ = D3D12_QUERY_TYPE_TIMESTAMP; 29 | break; 30 | case QueryType::Occulusion: 31 | heapDesc.Type = D3D12_QUERY_HEAP_TYPE_OCCLUSION; 32 | queryTypeDX12_ = D3D12_QUERY_TYPE_OCCLUSION; 33 | break; 34 | default: 35 | return false; 36 | } 37 | 38 | graphics->GetDevice()->CreateQueryHeap(&heapDesc, IID_PPV_ARGS(&queryHeap_)); 39 | } 40 | 41 | { 42 | D3D12_RESOURCE_DESC resDesc{}; 43 | resDesc.SampleDesc.Count = 1; 44 | resDesc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER; 45 | resDesc.Width = sizeof(uint64_t) * queryCount; 46 | resDesc.Height = 1; 47 | resDesc.MipLevels = 1; 48 | resDesc.DepthOrArraySize = 1; 49 | resDesc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR; 50 | 51 | D3D12_HEAP_PROPERTIES heapProp{}; 52 | heapProp.Type = D3D12_HEAP_TYPE_READBACK; 53 | 54 | graphics->GetDevice()->CreateCommittedResource(&heapProp, D3D12_HEAP_FLAG_NONE, &resDesc, 55 | D3D12_RESOURCE_STATE_COPY_DEST, nullptr, IID_PPV_ARGS(&buffer_)); 56 | } 57 | 58 | return true; 59 | } 60 | 61 | uint64_t QueryDX12::GetQueryResult(uint32_t queryIndex) 62 | { 63 | D3D12_RANGE range{queryIndex * sizeof(uint64_t), (queryIndex + 1) * sizeof(uint64_t)}; 64 | void* ptr = nullptr; 65 | buffer_->Map(0, &range, &ptr); 66 | auto data = reinterpret_cast(ptr); 67 | uint64_t result = data[queryIndex]; 68 | buffer_->Unmap(0, nullptr); 69 | 70 | return result; 71 | } 72 | 73 | } // namespace LLGI 74 | -------------------------------------------------------------------------------- /src/DX12/LLGI.QueryDX12.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "../LLGI.Query.h" 5 | #include "LLGI.BaseDX12.h" 6 | #include "LLGI.GraphicsDX12.h" 7 | 8 | namespace LLGI 9 | { 10 | 11 | class QueryDX12 : public Query 12 | { 13 | private: 14 | ID3D12QueryHeap* queryHeap_ = nullptr; 15 | ID3D12Resource* buffer_ = nullptr; 16 | D3D12_QUERY_TYPE queryTypeDX12_{}; 17 | QueryType queryType_{}; 18 | uint32_t queryCount_{}; 19 | 20 | public: 21 | bool Initialize(GraphicsDX12* graphics, QueryType queryType, uint32_t queryCount); 22 | 23 | QueryDX12(); 24 | ~QueryDX12() override; 25 | 26 | ID3D12QueryHeap* GetQueryHeap() { return queryHeap_; } 27 | 28 | ID3D12Resource* GetBuffer() { return buffer_; } 29 | 30 | D3D12_QUERY_TYPE GetQueryTypeDX12() const { return queryTypeDX12_; } 31 | 32 | uint32_t GetQueryCount() const { return queryCount_; } 33 | 34 | uint64_t GetQueryResult(uint32_t queryIndex) override; 35 | }; 36 | 37 | } // namespace LLGI 38 | -------------------------------------------------------------------------------- /src/DX12/LLGI.RenderPassDX12.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../LLGI.Graphics.h" 4 | #include "LLGI.BaseDX12.h" 5 | 6 | namespace LLGI 7 | { 8 | 9 | namespace DX12 10 | { 11 | class DescriptorHeapAllocator; 12 | } 13 | 14 | class GraphicsDX12; 15 | class TextureDX12; 16 | class RenderPassPipelineStateDX12; 17 | class RenderTargetDX12; 18 | class CommandListDX12; 19 | 20 | class RenderPassDX12 : public RenderPass 21 | { 22 | private: 23 | ID3D12Device* device_ = nullptr; 24 | 25 | std::vector renderTargets_; 26 | std::vector handleRTV_; 27 | D3D12_CPU_DESCRIPTOR_HANDLE handleDSV_; 28 | 29 | int32_t numRenderTarget_ = 0; 30 | 31 | std::shared_ptr renderPassPipelineState_; 32 | 33 | public: 34 | RenderPassDX12(ID3D12Device* device); 35 | ~RenderPassDX12() override; 36 | 37 | bool Initialize(TextureDX12** textures, 38 | int numTextures, 39 | TextureDX12* depthTexture, 40 | TextureDX12* resolvedRenderTexture, 41 | TextureDX12* resolvedDepthTexture); 42 | 43 | const D3D12_CPU_DESCRIPTOR_HANDLE* GetHandleRTV() const { return handleRTV_.data(); } 44 | const RenderTargetDX12* GetRenderTarget(int idx) const { return &renderTargets_[idx]; } 45 | int32_t GetCount() const { return numRenderTarget_; } 46 | 47 | bool ReinitializeRenderTargetViews(CommandListDX12* commandList, 48 | std::shared_ptr rtDescriptorHeap, 49 | std::shared_ptr dtDescriptorHeap); 50 | 51 | const D3D12_CPU_DESCRIPTOR_HANDLE* GetHandleDSV() const 52 | { 53 | if (GetHasDepthTexture()) 54 | { 55 | return &handleDSV_; 56 | } 57 | 58 | return nullptr; 59 | } 60 | }; 61 | 62 | class RenderTargetDX12 63 | { 64 | public: 65 | TextureDX12* texture_ = nullptr; 66 | ID3D12Resource* renderPass_ = nullptr; 67 | 68 | RenderTargetDX12() {} 69 | }; 70 | } // namespace LLGI 71 | -------------------------------------------------------------------------------- /src/DX12/LLGI.RenderPassPipelineStateDX12.cpp: -------------------------------------------------------------------------------- 1 | #include "LLGI.RenderPassPipelineStateDX12.h" 2 | 3 | namespace LLGI 4 | { 5 | } // namespace LLGI 6 | -------------------------------------------------------------------------------- /src/DX12/LLGI.RenderPassPipelineStateDX12.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../LLGI.Graphics.h" 4 | #include "LLGI.BaseDX12.h" 5 | #include 6 | #include 7 | 8 | namespace LLGI 9 | { 10 | 11 | class GraphicsDX12; 12 | class RenderPassDX12; 13 | 14 | class RenderPassPipelineStateDX12 : public RenderPassPipelineState 15 | { 16 | private: 17 | public: 18 | RenderPassPipelineStateDX12() = default; 19 | ~RenderPassPipelineStateDX12() override = default; 20 | }; 21 | 22 | } // namespace LLGI 23 | -------------------------------------------------------------------------------- /src/DX12/LLGI.ShaderDX12.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "LLGI.ShaderDX12.h" 3 | #include "../LLGI.Shader.h" 4 | #include "LLGI.CompilerDX12.h" 5 | 6 | namespace LLGI 7 | { 8 | 9 | bool ShaderDX12::Initialize(DataStructure* data, int32_t count) 10 | { 11 | if (data == nullptr || count == 0) 12 | { 13 | return false; 14 | } 15 | 16 | auto p = static_cast(data->Data); 17 | data_.resize(data->Size); 18 | memcpy(data_.data(), p, data_.size()); 19 | return true; 20 | } 21 | 22 | } // namespace LLGI 23 | -------------------------------------------------------------------------------- /src/DX12/LLGI.ShaderDX12.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "../LLGI.Shader.h" 5 | #include "LLGI.BaseDX12.h" 6 | #include "LLGI.GraphicsDX12.h" 7 | 8 | using namespace DirectX; 9 | 10 | namespace LLGI 11 | { 12 | 13 | class ShaderDX12 : public Shader 14 | { 15 | private: 16 | std::vector data_; 17 | 18 | public: 19 | ShaderDX12() = default; 20 | ~ShaderDX12() override = default; 21 | 22 | bool Initialize(DataStructure* data, int32_t count); 23 | 24 | const std::vector& GetData() { return data_; } 25 | }; 26 | 27 | } // namespace LLGI 28 | -------------------------------------------------------------------------------- /src/DX12/LLGI.SingleFrameMemoryPoolDX12.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "LLGI.BaseDX12.h" 5 | #include "LLGI.DescriptorHeapDX12.h" 6 | #include "LLGI.GraphicsDX12.h" 7 | 8 | namespace LLGI 9 | { 10 | 11 | class InternalSingleFrameMemoryPoolDX12 12 | { 13 | private: 14 | BufferDX12* buffer_ = nullptr; 15 | int32_t constantBufferSize_ = 0; 16 | int32_t constantBufferOffset_ = 0; 17 | 18 | public: 19 | InternalSingleFrameMemoryPoolDX12(GraphicsDX12* graphics, int32_t constantBufferPoolSize, int32_t drawingCount); 20 | virtual ~InternalSingleFrameMemoryPoolDX12(); 21 | bool GetConstantBuffer(int32_t size, BufferDX12*& buffer, int32_t& offset); 22 | void Reset(); 23 | }; 24 | 25 | class SingleFrameMemoryPoolDX12 : public SingleFrameMemoryPool 26 | { 27 | private: 28 | GraphicsDX12* graphics_ = nullptr; 29 | bool isStrongRef_ = false; 30 | std::vector> memoryPools; 31 | int32_t currentSwap_ = 0; 32 | int32_t drawingCount_ = 0; 33 | 34 | Buffer* CreateBufferInternal(int32_t size) override; 35 | 36 | Buffer* ReinitializeBuffer(Buffer* cb, int32_t size) override; 37 | 38 | public: 39 | SingleFrameMemoryPoolDX12( 40 | GraphicsDX12* graphics, bool isStrongRef, int32_t swapBufferCount, int32_t constantBufferPoolSize, int32_t drawingCount); 41 | ~SingleFrameMemoryPoolDX12() override; 42 | 43 | bool GetConstantBuffer(int32_t size, BufferDX12*& buffer, int32_t& offset); 44 | 45 | InternalSingleFrameMemoryPoolDX12* GetInternal(); 46 | 47 | int32_t GetDrawingCount() const; 48 | 49 | void NewFrame() override; 50 | }; 51 | 52 | } // namespace LLGI 53 | -------------------------------------------------------------------------------- /src/DX12/LLGI.TextureDX12.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "../LLGI.Texture.h" 5 | #include "LLGI.BaseDX12.h" 6 | #include "LLGI.GraphicsDX12.h" 7 | 8 | namespace LLGI 9 | { 10 | 11 | class TextureDX12 : public Texture 12 | { 13 | private: 14 | GraphicsDX12* graphics_ = nullptr; 15 | bool hasStrongRef_ = false; 16 | ID3D12Device* device_ = nullptr; 17 | ID3D12CommandQueue* commandQueue_ = nullptr; 18 | 19 | ID3D12Resource* texture_ = nullptr; 20 | ID3D12Resource* buffer_for_upload_ = nullptr; 21 | ID3D12Resource* buffer_for_readback_ = nullptr; 22 | 23 | D3D12_PLACED_SUBRESOURCE_FOOTPRINT footprint_; 24 | D3D12_RESOURCE_STATES state_ = D3D12_RESOURCE_STATES::D3D12_RESOURCE_STATE_COMMON; 25 | DXGI_FORMAT dxgiFormat_; 26 | 27 | //! DX12 doesn't have packed buffer 28 | std::vector locked_buffer_; 29 | 30 | Vec3I texture_size_; 31 | int32_t cpu_memory_size_; 32 | TextureParameter parameter_; 33 | 34 | void CreateUploadReadbackBuffer(); 35 | 36 | public: 37 | TextureDX12(GraphicsDX12* graphics, bool hasStrongRef); 38 | 39 | //! init as screen texture 40 | TextureDX12(ID3D12Resource* textureResource, ID3D12Device* device, ID3D12CommandQueue* commandQueue); 41 | 42 | ~TextureDX12() override; 43 | 44 | bool Initialize(const TextureParameter& parameter); 45 | 46 | //! init as external texture 47 | bool Initialize(ID3D12Resource* textureResource); 48 | 49 | void* Lock() override; 50 | 51 | void Unlock() override; 52 | 53 | bool GetData(std::vector& data) override; 54 | 55 | const TextureParameter& GetParameter() const { return parameter_; } 56 | 57 | Vec3I GetSize() const { return texture_size_; } 58 | 59 | Vec2I GetSizeAs2D() const override; 60 | ID3D12Resource* Get() const { return texture_; } 61 | 62 | TextureFormatType GetFormat() const override { return format_; } 63 | 64 | DXGI_FORMAT GetDXGIFormat() const { return dxgiFormat_; } 65 | 66 | const D3D12_PLACED_SUBRESOURCE_FOOTPRINT& GetFootprint() const { return footprint_; } 67 | 68 | D3D12_RESOURCE_STATES GetState() const { return state_; } 69 | 70 | //! set a resource barrier and change a state 71 | void ResourceBarrier(ID3D12GraphicsCommandList* commandList, D3D12_RESOURCE_STATES state); 72 | }; 73 | } // namespace LLGI 74 | -------------------------------------------------------------------------------- /src/LLGI.Buffer.cpp: -------------------------------------------------------------------------------- 1 | #include "LLGI.Buffer.h" 2 | 3 | namespace LLGI 4 | { 5 | 6 | bool Buffer::VerifyUsage(BufferUsageType usage) 7 | { 8 | if (BitwiseContains(usage, BufferUsageType::MapWrite) && BitwiseContains(usage, BufferUsageType::MapRead)) 9 | { 10 | Log(LogType::Error, "It cannot specify MapWrite and MapRead simultaniously."); 11 | return false; 12 | } 13 | 14 | if ((BitwiseContains(usage, BufferUsageType::MapWrite) || BitwiseContains(usage, BufferUsageType::MapRead)) && 15 | BitwiseContains(usage, BufferUsageType::ComputeWrite)) 16 | { 17 | Log(LogType::Error, "It cannot specify Map(Read/Write) and Compute simultaniously."); 18 | return false; 19 | } 20 | 21 | return true; 22 | } 23 | 24 | void* Buffer::Lock() { return nullptr; } 25 | 26 | void* Buffer::Lock(int32_t offset, int32_t size) { return nullptr; } 27 | 28 | void Buffer::Unlock() {} 29 | 30 | // void* const Buffer::Read() { return nullptr; } 31 | 32 | int32_t Buffer::GetSize() { return int32_t(); } 33 | 34 | } // namespace LLGI 35 | -------------------------------------------------------------------------------- /src/LLGI.Buffer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "LLGI.Base.h" 4 | 5 | namespace LLGI 6 | { 7 | 8 | class Buffer : public ReferenceObject 9 | { 10 | protected: 11 | BufferUsageType usage_ = BufferUsageType::Index; 12 | 13 | static bool VerifyUsage(BufferUsageType usage); 14 | 15 | public: 16 | Buffer() = default; 17 | ~Buffer() override = default; 18 | 19 | virtual void* Lock(); 20 | virtual void* Lock(int32_t offset, int32_t size); 21 | virtual void Unlock(); 22 | 23 | virtual int32_t GetSize(); 24 | 25 | BufferUsageType GetBufferUsage() { return usage_; } 26 | }; 27 | 28 | } // namespace LLGI 29 | -------------------------------------------------------------------------------- /src/LLGI.Compiler.cpp: -------------------------------------------------------------------------------- 1 | #include "LLGI.Compiler.h" 2 | 3 | namespace LLGI 4 | { 5 | 6 | void Compiler::Initialize() {} 7 | 8 | void Compiler::Compile(CompilerResult& result, const char* code, ShaderStageType shaderStage) {} 9 | 10 | } // namespace LLGI 11 | -------------------------------------------------------------------------------- /src/LLGI.Compiler.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "LLGI.Base.h" 4 | 5 | namespace LLGI 6 | { 7 | 8 | Compiler* CreateCompiler(DeviceType device); 9 | 10 | struct CompilerResult 11 | { 12 | std::string Message; 13 | std::vector> Binary; 14 | }; 15 | 16 | class Compiler : public ReferenceObject 17 | { 18 | private: 19 | public: 20 | Compiler() = default; 21 | ~Compiler() override = default; 22 | 23 | virtual void Initialize(); 24 | virtual void Compile(CompilerResult& result, const char* code, ShaderStageType shaderStage); 25 | 26 | virtual DeviceType GetDeviceType() const { return DeviceType::Default; } 27 | }; 28 | 29 | } // namespace LLGI 30 | -------------------------------------------------------------------------------- /src/LLGI.PipelineState.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "LLGI.PipelineState.h" 3 | #include "LLGI.Graphics.h" 4 | 5 | namespace LLGI 6 | { 7 | 8 | PipelineState::PipelineState() { VertexLayoutSemantics.fill(0); } 9 | 10 | void PipelineState::SetShader(ShaderStageType stage, Shader* shader) {} 11 | 12 | RenderPassPipelineState* PipelineState::GetRenderPassPipelineState() const { return renderPassPipelineState_.get(); } 13 | 14 | void PipelineState::SetRenderPassPipelineState(RenderPassPipelineState* renderPassPipelineState) 15 | { 16 | SafeAddRef(renderPassPipelineState); 17 | renderPassPipelineState_ = CreateSharedPtr(renderPassPipelineState); 18 | } 19 | 20 | bool PipelineState::Compile() { return false; } 21 | 22 | } // namespace LLGI 23 | -------------------------------------------------------------------------------- /src/LLGI.PipelineState.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "LLGI.Base.h" 5 | 6 | namespace LLGI 7 | { 8 | 9 | class PipelineState : public ReferenceObject 10 | { 11 | protected: 12 | std::shared_ptr renderPassPipelineState_ = nullptr; 13 | 14 | public: 15 | PipelineState(); 16 | ~PipelineState() override = default; 17 | 18 | CullingMode Culling = CullingMode::Clockwise; 19 | TopologyType Topology = TopologyType::Triangle; 20 | 21 | bool IsBlendEnabled = true; 22 | 23 | BlendFuncType BlendSrcFunc = BlendFuncType::SrcAlpha; 24 | BlendFuncType BlendDstFunc = BlendFuncType::OneMinusSrcAlpha; 25 | BlendFuncType BlendSrcFuncAlpha = BlendFuncType::SrcAlpha; 26 | BlendFuncType BlendDstFuncAlpha = BlendFuncType::OneMinusSrcAlpha; 27 | 28 | BlendEquationType BlendEquationRGB = BlendEquationType::Add; 29 | BlendEquationType BlendEquationAlpha = BlendEquationType::Add; 30 | 31 | bool IsDepthTestEnabled = false; 32 | bool IsDepthWriteEnabled = false; 33 | DepthFuncType DepthFunc = DepthFuncType::Less; 34 | 35 | uint8_t StencilRef = 0xff; 36 | uint8_t StencilReadMask = 0xff; 37 | uint8_t StencilWriteMask = 0xff; 38 | 39 | StencilOperatorType StencilDepthFailOp = StencilOperatorType::Keep; 40 | StencilOperatorType StencilFailOp = StencilOperatorType::Keep; 41 | StencilOperatorType StencilPassOp = StencilOperatorType::Keep; 42 | 43 | CompareFuncType StencilCompareFunc = CompareFuncType::Always; 44 | 45 | bool IsStencilTestEnabled = false; 46 | 47 | std::array VertexLayoutNames; 48 | std::array VertexLayouts; 49 | 50 | //! only for DirectX12 51 | std::array VertexLayoutSemantics; 52 | int32_t VertexLayoutCount = 0; 53 | 54 | virtual void SetShader(ShaderStageType stage, Shader* shader); 55 | 56 | virtual RenderPassPipelineState* GetRenderPassPipelineState() const; 57 | 58 | virtual void SetRenderPassPipelineState(RenderPassPipelineState* renderPassPipelineState); 59 | 60 | virtual bool Compile(); 61 | }; 62 | 63 | } // namespace LLGI 64 | -------------------------------------------------------------------------------- /src/LLGI.Platform.cpp: -------------------------------------------------------------------------------- 1 | #include "LLGI.Platform.h" 2 | 3 | namespace LLGI 4 | { 5 | 6 | bool Platform::NewFrame() { return false; } 7 | 8 | void Platform::Present() {} 9 | 10 | Graphics* Platform::CreateGraphics() { return nullptr; } 11 | 12 | int Platform::GetCurrentFrameIndex() const 13 | { 14 | assert(0); // TODO: Not implemented. 15 | return 0; 16 | } 17 | 18 | int Platform::GetMaxFrameCount() const 19 | { 20 | assert(0); // TODO: Not implemented. 21 | return 0; 22 | } 23 | 24 | void Platform::SetWindowSize(const Vec2I& windowSize) 25 | { 26 | assert(0); // TODO: Not implemented. 27 | } 28 | 29 | RenderPass* Platform::GetCurrentScreen(const Color8& clearColor, bool isColorCleared, bool isDepthCleared) 30 | { 31 | Log(LogType::Warning, "GetCurrentScreen is not implemented."); 32 | return nullptr; 33 | } 34 | 35 | } // namespace LLGI 36 | -------------------------------------------------------------------------------- /src/LLGI.Platform.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "LLGI.Base.h" 5 | 6 | #ifdef _WIN32 7 | #undef CreateWindow 8 | #endif 9 | 10 | namespace LLGI 11 | { 12 | 13 | struct PlatformParameter 14 | { 15 | DeviceType Device = DeviceType::Default; 16 | bool WaitVSync = true; 17 | }; 18 | 19 | Window* CreateWindow(const char* title, Vec2I windowSize); 20 | 21 | Platform* CreatePlatform(const PlatformParameter& parameter, Window* window); 22 | 23 | class Platform : public ReferenceObject 24 | { 25 | private: 26 | protected: 27 | bool waitVSync_ = false; 28 | 29 | public: 30 | Platform() = default; 31 | ~Platform() override = default; 32 | 33 | virtual bool NewFrame(); 34 | virtual void Present(); 35 | virtual Graphics* CreateGraphics(); 36 | virtual DeviceType GetDeviceType() const { return DeviceType::Default; } 37 | virtual int GetCurrentFrameIndex() const; 38 | virtual int GetMaxFrameCount() const; 39 | 40 | /* 41 | @brief change this window size 42 | @note 43 | the argument is ignored on Mac. This function notify that an window size is changed. 44 | **/ 45 | virtual void SetWindowSize(const Vec2I& windowSize); 46 | 47 | bool GetWaitVSync() const { return waitVSync_; } 48 | 49 | /** 50 | @brief get render pass of screen to show on a display. 51 | @note 52 | Don't release and addref it. 53 | Don't use it for the many purposes, please input Clear or SetRenderPass immediately. 54 | */ 55 | virtual RenderPass* GetCurrentScreen(const Color8& clearColor = Color8(), bool isColorCleared = false, bool isDepthCleared = false); 56 | }; 57 | 58 | } // namespace LLGI 59 | -------------------------------------------------------------------------------- /src/LLGI.Query.cpp: -------------------------------------------------------------------------------- 1 | #include "LLGI.Query.h" 2 | 3 | namespace LLGI 4 | { 5 | 6 | } // namespace LLGI 7 | -------------------------------------------------------------------------------- /src/LLGI.Query.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "LLGI.Base.h" 4 | 5 | namespace LLGI 6 | { 7 | 8 | class Query : public ReferenceObject 9 | { 10 | protected: 11 | QueryType queryType_ = QueryType::Timestamp; 12 | 13 | public: 14 | Query() = default; 15 | ~Query() override = default; 16 | 17 | QueryType GetQueryType() const { return queryType_; } 18 | 19 | virtual uint64_t GetQueryResult(uint32_t queryIndex) { return 0; } 20 | }; 21 | 22 | } // namespace LLGI 23 | -------------------------------------------------------------------------------- /src/LLGI.Shader.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "LLGI.Base.h" 5 | 6 | namespace LLGI 7 | { 8 | 9 | class Shader : public ReferenceObject 10 | { 11 | private: 12 | public: 13 | Shader() = default; 14 | ~Shader() override = default; 15 | }; 16 | 17 | } // namespace LLGI 18 | -------------------------------------------------------------------------------- /src/LLGI.Texture.cpp: -------------------------------------------------------------------------------- 1 | #include "LLGI.Texture.h" 2 | 3 | namespace LLGI 4 | { 5 | 6 | void* Texture::Lock() { return nullptr; } 7 | 8 | void Texture::Unlock() {} 9 | 10 | Vec2I Texture::GetSizeAs2D() const { return Vec2I(); } 11 | 12 | bool Texture::IsRenderTexture() const { return false; } 13 | 14 | bool Texture::IsDepthTexture() const { return false; } 15 | 16 | TextureFormatType Texture::GetFormat() const { return format_; } 17 | 18 | TextureUsageType Texture::GetUsage() const { return usage_; } 19 | 20 | } // namespace LLGI 21 | -------------------------------------------------------------------------------- /src/LLGI.Texture.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "LLGI.Base.h" 5 | 6 | namespace LLGI 7 | { 8 | 9 | class Texture : public ReferenceObject 10 | { 11 | private: 12 | protected: 13 | TextureType type_ = TextureType::Unknown; 14 | TextureFormatType format_ = TextureFormatType::Unknown; 15 | TextureUsageType usage_ = TextureUsageType::NoneFlag; 16 | 17 | int32_t samplingCount_ = 1; 18 | int32_t mipmapCount_ = 1; 19 | 20 | public: 21 | Texture() = default; 22 | ~Texture() override = default; 23 | 24 | /*[[deprecated("use CommandList::SetImageData2D.")]]*/ virtual void* Lock(); 25 | 26 | /*[[deprecated("use CommandList::SetImageData2D.")]]*/ virtual void Unlock(); 27 | 28 | /** 29 | @brief Lock an image on mipmap 30 | */ 31 | virtual void* Lock(int32_t mipmapLevel) { return nullptr; } 32 | 33 | virtual bool GetData(std::vector& data) { return false; } 34 | 35 | /** 36 | @brief Generate mipmaps based on level zero. 37 | */ 38 | virtual void GenerateMipMaps() {} 39 | 40 | virtual Vec2I GetSizeAs2D() const; 41 | [[deprecated("use GetType.")]] virtual bool IsRenderTexture() const; 42 | [[deprecated("use GetType.")]] virtual bool IsDepthTexture() const; 43 | 44 | TextureType GetType() const { return type_; } 45 | 46 | virtual TextureFormatType GetFormat() const; 47 | 48 | TextureUsageType GetUsage() const; 49 | 50 | int32_t GetSamplingCount() const { return samplingCount_; } 51 | 52 | int32_t GetMipmapCount() const { return mipmapCount_; } 53 | }; 54 | 55 | } // namespace LLGI 56 | -------------------------------------------------------------------------------- /src/Linux/LLGI.WindowLinux.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../LLGI.Base.h" 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | namespace LLGI 11 | { 12 | 13 | class WindowLinux : public Window 14 | { 15 | private: 16 | Display* display_ = nullptr; 17 | ::Window window_; 18 | GC gc_; 19 | bool closed_ = false; 20 | Atom wm_delete_window_; 21 | std::string title_; 22 | Vec2I windowSize_; 23 | 24 | public: 25 | WindowLinux() = default; 26 | 27 | ~WindowLinux() override; 28 | 29 | bool Initialize(const char* title, const Vec2I& windowSize); 30 | 31 | bool DoEvent(); 32 | 33 | void Terminate(); 34 | 35 | Display*& GetDisplay() { return display_; } 36 | ::Window& GetWindow() { return window_; } 37 | 38 | bool OnNewFrame() override; 39 | 40 | void* GetNativePtr(int32_t index) override; 41 | 42 | Vec2I GetWindowSize() const override; 43 | }; 44 | 45 | } // namespace LLGI 46 | -------------------------------------------------------------------------------- /src/Mac/LLGI.WindowMac.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../LLGI.Base.h" 4 | #include 5 | 6 | namespace LLGI 7 | { 8 | 9 | struct WindowMac_Impl; 10 | 11 | class WindowMac : public Window 12 | { 13 | private: 14 | std::shared_ptr impl_ = nullptr; 15 | Vec2I windowSize_; 16 | 17 | public: 18 | WindowMac() = default; 19 | 20 | ~WindowMac() override = default; 21 | 22 | bool Initialize(const char* title, const Vec2I& windowSize); 23 | 24 | bool DoEvent(); 25 | 26 | void Terminate(); 27 | 28 | void* GetNSWindowAsVoidPtr(); 29 | 30 | bool OnNewFrame() override; 31 | 32 | void* GetNativePtr(int32_t index) override; 33 | 34 | Vec2I GetWindowSize() const override; 35 | 36 | Vec2I GetFrameBufferSize() const override; 37 | }; 38 | 39 | } // namespace LLGI 40 | -------------------------------------------------------------------------------- /src/Metal/LLGI.BufferMetal.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../LLGI.Graphics.h" 4 | #include "../LLGI.Buffer.h" 5 | #import 6 | #include 7 | #include 8 | #include 9 | 10 | namespace LLGI 11 | { 12 | 13 | class BufferMetal : public Buffer 14 | { 15 | private: 16 | id buffer_ = nullptr; 17 | int32_t size_ = 0; 18 | int32_t offset_ = 0; 19 | bool isExternalResource_ = false; 20 | 21 | public: 22 | BufferMetal(); 23 | ~BufferMetal() override; 24 | 25 | bool Initialize(Graphics* graphics, BufferUsageType usage, int32_t size); 26 | bool InitializeAsShortTime(BufferMetal* buffer, int32_t offset, int32_t size); 27 | 28 | void* Lock() override; 29 | 30 | void* Lock(int32_t offset, int32_t size) override; 31 | 32 | void Unlock() override; 33 | 34 | int32_t GetSize() override; 35 | 36 | int32_t GetBufferSize() const { return static_cast(buffer_.length); } 37 | 38 | int32_t GetOffset() const { return offset_; } 39 | 40 | id& GetBuffer() { return buffer_; } 41 | }; 42 | 43 | } // namespace LLGI 44 | -------------------------------------------------------------------------------- /src/Metal/LLGI.BufferMetal.mm: -------------------------------------------------------------------------------- 1 | #include "LLGI.BufferMetal.h" 2 | #include "LLGI.CommandListMetal.h" 3 | #include "LLGI.GraphicsMetal.h" 4 | #include "LLGI.Metal_Impl.h" 5 | #include "LLGI.PipelineStateMetal.h" 6 | #include "LLGI.RenderPassMetal.h" 7 | #include "LLGI.ShaderMetal.h" 8 | #include "LLGI.SingleFrameMemoryPoolMetal.h" 9 | #include "LLGI.TextureMetal.h" 10 | 11 | #import 12 | 13 | namespace LLGI 14 | { 15 | 16 | BufferMetal::BufferMetal() 17 | { 18 | 19 | } 20 | 21 | BufferMetal::~BufferMetal() 22 | { 23 | if (isExternalResource_) 24 | return; 25 | 26 | if (buffer_ != nullptr) 27 | { 28 | [buffer_ release]; 29 | buffer_ = nullptr; 30 | } 31 | } 32 | 33 | bool BufferMetal::Initialize(Graphics* graphics, BufferUsageType usage, int32_t size) 34 | { 35 | if (!VerifyUsage(usage)) 36 | { 37 | return false; 38 | } 39 | 40 | auto g = static_cast(graphics); 41 | 42 | if(BitwiseContains(usage, BufferUsageType::MapWrite) || BitwiseContains(usage, BufferUsageType::MapRead)) 43 | { 44 | buffer_ = [g->GetDevice() newBufferWithLength:size options:MTLResourceStorageModeShared]; 45 | } 46 | else 47 | { 48 | buffer_ = [g->GetDevice() newBufferWithLength:size options:MTLResourceStorageModePrivate]; 49 | } 50 | 51 | size_ = size; 52 | 53 | return true; 54 | } 55 | 56 | bool BufferMetal::InitializeAsShortTime(BufferMetal* buffer, int32_t offset, int32_t size) 57 | { 58 | buffer_ = buffer->GetBuffer(); 59 | size_ = size; 60 | offset_ = offset; 61 | isExternalResource_ = true; 62 | return true; 63 | } 64 | 65 | void* BufferMetal::Lock() 66 | { 67 | auto buffer = static_cast(buffer_.contents); 68 | buffer += offset_; 69 | return buffer; 70 | } 71 | 72 | void* BufferMetal::Lock(int32_t offset, int32_t size) 73 | { 74 | NSCAssert(0 <= offset && offset + offset_ + size <= GetBufferSize(), @"Run off the buffer"); 75 | 76 | auto buffer = static_cast(buffer_.contents); 77 | buffer += offset + offset_; 78 | return buffer; 79 | } 80 | 81 | void BufferMetal::Unlock() {} 82 | 83 | int32_t BufferMetal::GetSize() { return size_; } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /src/Metal/LLGI.CompilerMetal.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "../LLGI.Compiler.h" 5 | 6 | namespace LLGI 7 | { 8 | 9 | class CompilerMetal : public Compiler 10 | { 11 | private: 12 | public: 13 | void Initialize() override; 14 | void Compile(CompilerResult& result, const char* code, ShaderStageType shaderStage) override; 15 | 16 | DeviceType GetDeviceType() const override { return DeviceType::Metal; } 17 | }; 18 | 19 | } // namespace LLGI 20 | -------------------------------------------------------------------------------- /src/Metal/LLGI.CompilerMetal.mm: -------------------------------------------------------------------------------- 1 | #include "LLGI.CompilerMetal.h" 2 | 3 | #import 4 | 5 | namespace LLGI 6 | { 7 | 8 | void CompilerMetal::Initialize() {} 9 | 10 | void CompilerMetal::Compile(CompilerResult& result, const char* code, ShaderStageType shaderStage) 11 | { 12 | @autoreleasepool 13 | { 14 | // Metal doesn't support to save a library as binary file (with external tool, it can) 15 | NSString* codeStr = [[[NSString alloc] initWithUTF8String:code] autorelease]; 16 | 17 | id device = MTLCreateSystemDefaultDevice(); 18 | 19 | NSError* libraryError = nil; 20 | id lib = [[device newLibraryWithSource:codeStr options:NULL error:&libraryError] autorelease]; 21 | if (libraryError) 22 | { 23 | result.Message = libraryError.localizedDescription.UTF8String; 24 | } 25 | 26 | if (lib == NULL) 27 | { 28 | return; 29 | } 30 | 31 | std::vector buffer; 32 | 33 | // header 34 | buffer.push_back('m'); 35 | buffer.push_back('t'); 36 | buffer.push_back('l'); 37 | buffer.push_back('c'); 38 | buffer.push_back('o'); 39 | buffer.push_back('d'); 40 | buffer.push_back('e'); 41 | 42 | auto len = strlen(code) + 1; 43 | for (int i = 0; i < len; i++) 44 | { 45 | buffer.push_back(code[i]); 46 | } 47 | 48 | result.Binary.resize(1); 49 | result.Binary[0].resize(buffer.size()); 50 | memcpy(result.Binary[0].data(), buffer.data(), buffer.size()); 51 | } 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/Metal/LLGI.Metal_Impl.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../LLGI.Graphics.h" 4 | #include "../LLGI.PipelineState.h" 5 | 6 | #import 7 | 8 | namespace LLGI 9 | { 10 | 11 | //! which buffer is used as vertex buffer 12 | const int VertexBufferIndex = 4; 13 | 14 | MTLPixelFormat ConvertFormat(TextureFormatType format); 15 | 16 | TextureFormatType ConvertFormat(MTLPixelFormat format); 17 | 18 | } // namespace LLGI 19 | -------------------------------------------------------------------------------- /src/Metal/LLGI.PipelineStateMetal.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../LLGI.PipelineState.h" 4 | #import 5 | #include 6 | 7 | namespace LLGI 8 | { 9 | 10 | class GraphicsMetal; 11 | 12 | class PipelineStateMetal : public PipelineState 13 | { 14 | private: 15 | GraphicsMetal* graphics_ = nullptr; 16 | std::array(ShaderStageType::Max)> shaders; 17 | 18 | id pipelineState_ = nullptr; 19 | id depthStencilState_ = nullptr; 20 | id computePipelineState_ = nullptr; 21 | 22 | bool Compile(PipelineState* self, Graphics* graphics); 23 | bool CreateRenderPipelineState(PipelineState* self, Graphics* graphics); 24 | bool CreateComputePipelineState(PipelineState* self, Graphics* graphics); 25 | 26 | public: 27 | PipelineStateMetal(); 28 | ~PipelineStateMetal() override; 29 | 30 | bool Initialize(GraphicsMetal* graphics); 31 | void SetShader(ShaderStageType stage, Shader* shader) override; 32 | bool Compile() override; 33 | 34 | std::array(ShaderStageType::Max)> GetShaders() const { return shaders; } 35 | 36 | id& GetRenderPipelineState() { return pipelineState_; } 37 | 38 | id& GetDepthStencilState() { return depthStencilState_; } 39 | 40 | id& GetComputePipelineState() { return computePipelineState_; } 41 | }; 42 | 43 | } // namespace LLGI 44 | -------------------------------------------------------------------------------- /src/Metal/LLGI.PlatformMetal.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "../LLGI.Platform.h" 5 | 6 | namespace LLGI 7 | { 8 | 9 | struct PlatformMetal_Impl; 10 | 11 | class TextureMetal; 12 | class RenderPassMetal; 13 | class WindowMac; 14 | 15 | class PlatformMetal : public Platform 16 | { 17 | PlatformMetal_Impl* impl = nullptr; 18 | 19 | Vec2I windowSize_; 20 | 21 | struct RingBuffer 22 | { 23 | std::shared_ptr renderTexture = nullptr; 24 | std::shared_ptr renderPass = nullptr; 25 | }; 26 | 27 | int32_t ringIndex_ = 0; 28 | std::vector ringBuffers_; 29 | 30 | public: 31 | PlatformMetal(Window* window, bool waitVSync); 32 | ~PlatformMetal() override; 33 | bool NewFrame() override; 34 | void Present() override; 35 | Graphics* CreateGraphics() override; 36 | 37 | void SetWindowSize(const Vec2I& windowSize) override; 38 | 39 | RenderPass* GetCurrentScreen(const Color8& clearColor, bool isColorCleared, bool isDepthCleared) override; 40 | 41 | DeviceType GetDeviceType() const override { return DeviceType::Metal; } 42 | }; 43 | 44 | } // namespace LLGI 45 | -------------------------------------------------------------------------------- /src/Metal/LLGI.QueryMetal.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../LLGI.Graphics.h" 4 | #include "../LLGI.Query.h" 5 | #import 6 | #include 7 | #include 8 | #include 9 | 10 | namespace LLGI 11 | { 12 | 13 | class QueryMetal : public Query 14 | { 15 | private: 16 | id timestampBuffer_; 17 | uint32_t queryCount_ = 0; 18 | 19 | public: 20 | QueryMetal(); 21 | ~QueryMetal() override; 22 | 23 | bool Initialize(Graphics* graphics, QueryType queryType, uint32_t queryCount); 24 | 25 | uint32_t GetQueryCount() const { return queryCount_; } 26 | 27 | uint64_t GetQueryResult(uint32_t queryIndex) override; 28 | 29 | id GetTimestampBuffer() { return timestampBuffer_; } 30 | }; 31 | 32 | } // namespace LLGI 33 | -------------------------------------------------------------------------------- /src/Metal/LLGI.QueryMetal.mm: -------------------------------------------------------------------------------- 1 | #include "LLGI.QueryMetal.h" 2 | #include "LLGI.CommandListMetal.h" 3 | #include "LLGI.GraphicsMetal.h" 4 | #include "LLGI.Metal_Impl.h" 5 | #include "LLGI.PipelineStateMetal.h" 6 | #include "LLGI.RenderPassMetal.h" 7 | #include "LLGI.ShaderMetal.h" 8 | #include "LLGI.SingleFrameMemoryPoolMetal.h" 9 | #include "LLGI.TextureMetal.h" 10 | 11 | #import 12 | 13 | namespace LLGI 14 | { 15 | 16 | QueryMetal::QueryMetal() 17 | { 18 | } 19 | 20 | QueryMetal::~QueryMetal() 21 | { 22 | } 23 | 24 | bool QueryMetal::Initialize(Graphics* graphics, QueryType queryType, uint32_t queryCount) 25 | { 26 | queryCount_ = queryCount; 27 | 28 | auto device = static_cast(graphics)->GetDevice(); 29 | 30 | if (queryType == QueryType::Timestamp) 31 | { 32 | MTLCounterSampleBufferDescriptor *descriptor = [[MTLCounterSampleBufferDescriptor alloc] init]; 33 | descriptor.label = @"Timestamps"; 34 | descriptor.storageMode = MTLStorageModeShared; 35 | descriptor.sampleCount = queryCount; 36 | for (id counterSet in device.counterSets) 37 | { 38 | if ([counterSet.name isEqualToString:MTLCommonCounterSetTimestamp]) 39 | { 40 | descriptor.counterSet = counterSet; 41 | } 42 | } 43 | if (descriptor.counterSet != nil) 44 | { 45 | timestampBuffer_ = [device newCounterSampleBufferWithDescriptor:descriptor error:nil]; 46 | return (timestampBuffer_ != nil); 47 | } 48 | } 49 | return false; 50 | } 51 | 52 | uint64_t QueryMetal::GetQueryResult(uint32_t queryIndex) 53 | { 54 | uint64_t result = 0; 55 | NSRange range = { queryIndex, 1 }; 56 | NSData * counterData = [timestampBuffer_ resolveCounterRange:range]; 57 | if (counterData) 58 | { 59 | memcpy(&result, [counterData bytes], sizeof(uint64_t)); 60 | } 61 | return result; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/Metal/LLGI.RenderPassMetal.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../LLGI.Graphics.h" 4 | #import 5 | #include 6 | #include 7 | 8 | namespace LLGI 9 | { 10 | 11 | struct Graphics_Impl; 12 | struct RenderPass_Impl; 13 | struct RenderPassPipelineState_Impl; 14 | 15 | class GraphicsMetal; 16 | class RenderPassMetal; 17 | class RenderPassPipelineStateMetal; 18 | class TextureMetal; 19 | 20 | class RenderPassMetal : public RenderPass 21 | { 22 | MTLRenderPassDescriptor* renderPassDescriptor_; 23 | 24 | bool Initialize(); 25 | 26 | void UpdateTarget(TextureMetal** textures, 27 | int32_t textureCount, 28 | TextureMetal* depthTexture, 29 | TextureMetal* resolvedTexture, 30 | TextureMetal* resolvedDepthTexture); 31 | 32 | public: 33 | RenderPassMetal(); 34 | 35 | ~RenderPassMetal() override; 36 | 37 | bool UpdateRenderTarget( 38 | Texture** textures, int32_t textureCount, Texture* depthTexture, Texture* resolvedTexture, Texture* resolvedDepthTexture); 39 | 40 | void SetIsColorCleared(bool isColorCleared) override; 41 | 42 | void SetIsDepthCleared(bool isDepthCleared) override; 43 | 44 | void SetClearColor(const Color8& color) override; 45 | 46 | MTLRenderPassDescriptor* GetRenderPassDescriptor() { return renderPassDescriptor_; } 47 | 48 | Color8 clearColor; 49 | bool isColorCleared; 50 | bool isDepthCleared; 51 | FixedSizeVector pixelFormats; 52 | MTLPixelFormat depthStencilFormat = MTLPixelFormatInvalid; 53 | }; 54 | 55 | class RenderPassPipelineStateMetal : public RenderPassPipelineState 56 | { 57 | private: 58 | FixedSizeVector pixelFormats_; 59 | MTLPixelFormat depthStencilFormat_ = MTLPixelFormatInvalid; 60 | 61 | public: 62 | RenderPassPipelineStateMetal(); 63 | ~RenderPassPipelineStateMetal() override = default; 64 | 65 | void SetKey(const RenderPassPipelineStateKey& key); 66 | 67 | const FixedSizeVector& GetPixelFormats() const { return pixelFormats_; } 68 | const MTLPixelFormat& GetDepthStencilFormat() const { return depthStencilFormat_; } 69 | }; 70 | 71 | } // namespace LLGI 72 | -------------------------------------------------------------------------------- /src/Metal/LLGI.ShaderMetal.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "../LLGI.Shader.h" 5 | #import 6 | 7 | namespace LLGI 8 | { 9 | 10 | class GraphicsMetal; 11 | 12 | class ShaderMetal : public Shader 13 | { 14 | private: 15 | GraphicsMetal* graphics_ = nullptr; 16 | id library_ = nullptr; 17 | 18 | public: 19 | ShaderMetal(); 20 | ~ShaderMetal() override; 21 | bool Initialize(GraphicsMetal* graphics, DataStructure* data, int32_t count); 22 | 23 | id& GetLibrary() { return library_; } 24 | }; 25 | 26 | } // namespace LLGI 27 | -------------------------------------------------------------------------------- /src/Metal/LLGI.ShaderMetal.mm: -------------------------------------------------------------------------------- 1 | #include "LLGI.ShaderMetal.h" 2 | #include "LLGI.GraphicsMetal.h" 3 | #include "LLGI.Metal_Impl.h" 4 | #import 5 | 6 | #define SUPPRESS_COMPILE_WARNINGS 7 | 8 | namespace LLGI 9 | { 10 | 11 | ShaderMetal::ShaderMetal() {} 12 | 13 | ShaderMetal::~ShaderMetal() 14 | { 15 | if (library_ != nullptr) 16 | { 17 | [library_ release]; 18 | library_ = nullptr; 19 | } 20 | SafeRelease(graphics_); 21 | } 22 | 23 | bool ShaderMetal::Initialize(GraphicsMetal* graphics, DataStructure* data, int32_t count) 24 | { 25 | @autoreleasepool 26 | { 27 | SafeAddRef(graphics); 28 | SafeRelease(graphics_); 29 | graphics_ = graphics; 30 | auto g = static_cast(graphics); 31 | 32 | auto device = g->GetDevice(); 33 | 34 | if (data[0].Size < 7) 35 | return false; 36 | 37 | // check whether binary or code 38 | bool isCode = false; 39 | const char* code = static_cast(data[0].Data); 40 | 41 | if (code[0] == 'm' || code[1] == 't' || code[2] == 'l' || code[3] == 'c' || code[4] == 'o' || code[5] == 'd' || code[6] == 'e') 42 | { 43 | isCode = true; 44 | } 45 | 46 | if (isCode) 47 | { 48 | code += 7; 49 | NSString* codeStr = [[[NSString alloc] initWithUTF8String:code] autorelease]; 50 | 51 | id device = MTLCreateSystemDefaultDevice(); 52 | 53 | NSError* libraryError = nil; 54 | id lib = [device newLibraryWithSource:codeStr options:NULL error:&libraryError]; 55 | if (libraryError 56 | #ifdef SUPPRESS_COMPILE_WARNINGS 57 | && [libraryError.localizedDescription rangeOfString:@"succeeded"].location == NSNotFound 58 | #endif 59 | ) 60 | { 61 | Log(LogType::Error, libraryError.localizedDescription.UTF8String); 62 | return false; 63 | } 64 | 65 | this->library_ = lib; 66 | } 67 | else 68 | { 69 | NSError* libraryError = nil; 70 | id lib = [device newLibraryWithData:(dispatch_data_t)data error:&libraryError]; 71 | 72 | if (libraryError 73 | #ifdef SUPPRESS_COMPILE_WARNINGS 74 | && [libraryError.localizedDescription rangeOfString:@"succeeded"].location == NSNotFound 75 | #endif 76 | ) 77 | { 78 | Log(LogType::Error, libraryError.localizedDescription.UTF8String); 79 | return false; 80 | } 81 | 82 | this->library_ = lib; 83 | } 84 | 85 | return true; 86 | } 87 | } 88 | 89 | } 90 | -------------------------------------------------------------------------------- /src/Metal/LLGI.SingleFrameMemoryPoolMetal.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../LLGI.Graphics.h" 4 | #include "LLGI.BufferMetal.h" 5 | #import 6 | #include 7 | #include 8 | 9 | namespace LLGI 10 | { 11 | 12 | struct SingleFrameMemoryPoolMetal_Impl; 13 | struct Buffer_Impl; 14 | 15 | class GraphicsMetal; 16 | class RenderPassMetal; 17 | class RenderPassPipelineStateMetal; 18 | class TextureMetal; 19 | 20 | class InternalSingleFrameMemoryPoolMetal 21 | { 22 | private: 23 | BufferMetal* buffer_ = nullptr; 24 | int32_t constantBufferSize_ = 0; 25 | int32_t constantBufferOffset_ = 0; 26 | 27 | public: 28 | InternalSingleFrameMemoryPoolMetal(GraphicsMetal* graphics, int32_t constantBufferPoolSize, int32_t drawingCount); 29 | virtual ~InternalSingleFrameMemoryPoolMetal(); 30 | bool GetConstantBuffer(int32_t size, BufferMetal*& buffer, int32_t& offset); 31 | void Reset(); 32 | }; 33 | 34 | class SingleFrameMemoryPoolMetal : public SingleFrameMemoryPool 35 | { 36 | private: 37 | GraphicsMetal* graphics_ = nullptr; 38 | bool isStrongRef_ = false; 39 | std::vector> memoryPools; 40 | int32_t currentSwap_ = 0; 41 | 42 | Buffer* CreateBufferInternal(int32_t size) override; 43 | 44 | Buffer* ReinitializeBuffer(Buffer* cb, int32_t size) override; 45 | 46 | public: 47 | SingleFrameMemoryPoolMetal(GraphicsMetal* graphics, bool isStrongRef, int32_t constantBufferPoolSize, int32_t drawingCount); 48 | ~SingleFrameMemoryPoolMetal() override; 49 | virtual void NewFrame() override; 50 | }; 51 | 52 | } // namespace LLGI 53 | -------------------------------------------------------------------------------- /src/Metal/LLGI.TextureMetal.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "../LLGI.Texture.h" 5 | #include "LLGI.GraphicsMetal.h" 6 | 7 | namespace LLGI 8 | { 9 | 10 | class TextureMetal : public Texture 11 | { 12 | private: 13 | ReferenceObject* owner_ = nullptr; 14 | std::vector data_; 15 | 16 | id texture_ = nullptr; 17 | Vec3I size_; 18 | bool fromExternal_ = false; 19 | 20 | TextureParameter parameter_; 21 | 22 | bool Initialize(id device, const TextureParameter& parameter); 23 | void Write(const uint8_t* data); 24 | 25 | public: 26 | TextureMetal(); 27 | ~TextureMetal() override; 28 | 29 | bool Initialize(GraphicsMetal* owner, const TextureParameter& parameter); 30 | bool Initialize(GraphicsMetal* owner, id externalTexture); 31 | void Reset(id nativeTexture); 32 | void* Lock() override; 33 | void Unlock() override; 34 | bool GetData(std::vector& data) override; 35 | Vec2I GetSizeAs2D() const override; 36 | 37 | const TextureParameter& GetParameter() const { return parameter_; } 38 | 39 | id& GetTexture() { return texture_; } 40 | }; 41 | 42 | } // namespace LLGI 43 | -------------------------------------------------------------------------------- /src/Utils/LLGI.CommandListPool.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "../LLGI.CommandList.h" 5 | #include "../LLGI.Graphics.h" 6 | 7 | namespace LLGI 8 | { 9 | 10 | class CommandListPool 11 | { 12 | private: 13 | Graphics* graphics_ = nullptr; 14 | 15 | int32_t current_ = 0; 16 | std::vector commandLists_; 17 | 18 | public: 19 | CommandListPool(Graphics* graphics, SingleFrameMemoryPool* memoryPool, int32_t count) 20 | { 21 | SafeAssign(graphics_, graphics); 22 | 23 | commandLists_.reserve(count); 24 | 25 | for (int32_t i = 0; i < count; i++) 26 | { 27 | auto commandList = graphics_->CreateCommandList(memoryPool); 28 | commandLists_.push_back(commandList); 29 | } 30 | } 31 | 32 | ~CommandListPool() 33 | { 34 | for (auto o : commandLists_) 35 | { 36 | o->Release(); 37 | } 38 | 39 | SafeRelease(graphics_); 40 | } 41 | 42 | CommandList* Get(bool addRef = false) 43 | { 44 | CommandList* commandList = nullptr; 45 | 46 | commandLists_[current_]->WaitUntilCompleted(); 47 | 48 | commandList = commandLists_[current_]; 49 | 50 | if (addRef) 51 | { 52 | SafeAddRef(commandList); 53 | } 54 | 55 | current_++; 56 | current_ %= commandLists_.size(); 57 | 58 | return commandList; 59 | } 60 | }; 61 | 62 | } // namespace LLGI 63 | -------------------------------------------------------------------------------- /src/Utils/LLGI.FixedSizeVector.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | namespace LLGI 10 | { 11 | 12 | template struct FixedSizeVector 13 | { 14 | private: 15 | std::array internal_; 16 | size_t size_ = 0; 17 | 18 | public: 19 | T& at(size_t n) 20 | { 21 | assert(n < size_); 22 | return internal_.at(n); 23 | } 24 | 25 | const T& at(size_t n) const 26 | { 27 | assert(n < size_); 28 | 29 | return internal_.at(n); 30 | } 31 | 32 | const T* data() const { return internal_.data(); } 33 | 34 | void resize(size_t nsize) 35 | { 36 | assert(nsize <= internal_.size()); 37 | size_ = nsize; 38 | } 39 | 40 | bool operator==(FixedSizeVector const& rhs) const 41 | { 42 | if (size_ != rhs.size_) 43 | return false; 44 | 45 | for (size_t i = 0; i < size_; i++) 46 | { 47 | if (internal_[i] != rhs.internal_[i]) 48 | return false; 49 | } 50 | 51 | return true; 52 | } 53 | 54 | bool operator!=(FixedSizeVector const& rhs) const { return !(*this == rhs); } 55 | 56 | size_t size() const { return size_; } 57 | 58 | size_t get_hash() const 59 | { 60 | auto h = std::hash()(size()); 61 | for (size_t i = 0; i < size(); i++) 62 | { 63 | h += std::hash()(at(i)); 64 | } 65 | return h; 66 | } 67 | }; 68 | 69 | } // namespace LLGI 70 | -------------------------------------------------------------------------------- /src/Vulkan/LLGI.BufferVulkan.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "../LLGI.Buffer.h" 5 | #include "LLGI.BaseVulkan.h" 6 | #include "LLGI.GraphicsVulkan.h" 7 | 8 | namespace LLGI 9 | { 10 | class SingleFrameMemoryPoolVulkan; 11 | 12 | class BufferVulkan : public Buffer 13 | { 14 | private: 15 | std::shared_ptr graphics_; 16 | std::unique_ptr buffer_; 17 | void* data = nullptr; 18 | int32_t size_ = 0; 19 | int32_t actualSize_ = 0; 20 | int32_t offset_ = 0; 21 | 22 | // Should specify None for the first time. 23 | vk::AccessFlagBits accessFlag_ = vk::AccessFlagBits::eHostRead; 24 | 25 | public: 26 | bool Initialize(GraphicsVulkan* graphics, BufferUsageType usage, int32_t size); 27 | bool InitializeAsShortTime(GraphicsVulkan* graphics, SingleFrameMemoryPoolVulkan* memoryPool, int32_t size); 28 | 29 | BufferVulkan(); 30 | ~BufferVulkan() override; 31 | 32 | void* Lock() override; 33 | void* Lock(int32_t offset, int32_t size) override; 34 | void Unlock() override; 35 | 36 | int32_t GetSize() override; 37 | int32_t GetActualSize() const { return actualSize_; } 38 | int32_t GetOffset() const { return offset_; } 39 | 40 | vk::Buffer GetBuffer() { return buffer_->buffer(); } 41 | 42 | void ResourceBarrier(vk::CommandBuffer& commandBuffer, const vk::AccessFlagBits& accessFlag); 43 | }; 44 | 45 | } // namespace LLGI 46 | -------------------------------------------------------------------------------- /src/Vulkan/LLGI.CompilerVulkan.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "../LLGI.Compiler.h" 5 | #include "LLGI.BaseVulkan.h" 6 | 7 | namespace LLGI 8 | { 9 | 10 | class CompilerVulkan : public Compiler 11 | { 12 | private: 13 | public: 14 | CompilerVulkan(); 15 | ~CompilerVulkan() override; 16 | 17 | void Initialize() override; 18 | void Compile(CompilerResult& result, const char* code, ShaderStageType shaderStage) override; 19 | 20 | DeviceType GetDeviceType() const override { return DeviceType::Vulkan; } 21 | }; 22 | 23 | } // namespace LLGI 24 | -------------------------------------------------------------------------------- /src/Vulkan/LLGI.PipelineStateVulkan.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "../LLGI.PipelineState.h" 5 | #include "LLGI.BaseVulkan.h" 6 | #include "LLGI.GraphicsVulkan.h" 7 | 8 | namespace LLGI 9 | { 10 | 11 | class PipelineStateVulkan : public PipelineState 12 | { 13 | private: 14 | GraphicsVulkan* graphics_ = nullptr; 15 | std::array(ShaderStageType::Max)> shaders; 16 | 17 | vk::Pipeline pipeline_ = nullptr; 18 | vk::PipelineLayout pipelineLayout_ = nullptr; 19 | std::array descriptorSetLayouts_; 20 | 21 | vk::Pipeline computePipeline_ = nullptr; 22 | vk::PipelineLayout computePipelineLayout_ = nullptr; 23 | std::array computeDescriptorSetLayouts_; 24 | 25 | bool CreateGraphicsPipeline(); 26 | bool CreateComputePipeline(); 27 | 28 | public: 29 | PipelineStateVulkan(); 30 | ~PipelineStateVulkan() override; 31 | 32 | bool Initialize(GraphicsVulkan* graphics); 33 | 34 | void SetShader(ShaderStageType stage, Shader* shader) override; 35 | 36 | bool Compile() override; 37 | 38 | vk::Pipeline GetPipeline() const { return pipeline_; } 39 | 40 | vk::PipelineLayout GetPipelineLayout() const { return pipelineLayout_; } 41 | 42 | const std::array& GetDescriptorSetLayout() const { return descriptorSetLayouts_; } 43 | 44 | vk::Pipeline GetComputePipeline() const { return computePipeline_; } 45 | 46 | vk::PipelineLayout GetComputePipelineLayout() const { return computePipelineLayout_; } 47 | 48 | const std::array& GetComputeDescriptorSetLayout() const { return computeDescriptorSetLayouts_; } 49 | }; 50 | 51 | } // namespace LLGI 52 | -------------------------------------------------------------------------------- /src/Vulkan/LLGI.QueryVulkan.cpp: -------------------------------------------------------------------------------- 1 | #include "LLGI.QueryVulkan.h" 2 | #include "LLGI.SingleFrameMemoryPoolVulkan.h" 3 | 4 | namespace LLGI 5 | { 6 | 7 | QueryVulkan::QueryVulkan() {} 8 | 9 | QueryVulkan::~QueryVulkan() 10 | { 11 | if (queryPool_) 12 | { 13 | graphics_->GetDevice().destroyQueryPool(queryPool_); 14 | queryPool_ = nullptr; 15 | } 16 | } 17 | 18 | bool QueryVulkan::Initialize(GraphicsVulkan* graphics, QueryType queryType, uint32_t queryCount) 19 | { 20 | graphics_ = CreateSharedPtr(graphics); 21 | queryType_ = queryType; 22 | queryCount_ = queryCount; 23 | 24 | vk::QueryPoolCreateInfo queryInfo; 25 | queryInfo.setQueryCount(queryCount); 26 | 27 | switch (queryType) 28 | { 29 | case QueryType::Timestamp: 30 | queryInfo.setQueryType(vk::QueryType::eTimestamp); 31 | break; 32 | case QueryType::Occulusion: 33 | queryInfo.setQueryType(vk::QueryType::eOcclusion); 34 | break; 35 | default: 36 | return false; 37 | } 38 | 39 | queryPool_ = graphics->GetDevice().createQueryPool(queryInfo); 40 | 41 | return true; 42 | } 43 | 44 | uint64_t QueryVulkan::GetQueryResult(uint32_t queryIndex) 45 | { 46 | uint64_t value = 0; 47 | vk::Result result = graphics_->GetDevice().getQueryPoolResults( 48 | queryPool_, queryIndex, 1, sizeof(uint64_t), &value, sizeof(uint64_t), 49 | vk::QueryResultFlagBits::e64 | vk::QueryResultFlagBits::eWait); 50 | 51 | if (result == vk::Result::eSuccess) 52 | { 53 | return value; 54 | } 55 | 56 | return 0; 57 | } 58 | 59 | } // namespace LLGI 60 | -------------------------------------------------------------------------------- /src/Vulkan/LLGI.QueryVulkan.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "../LLGI.Query.h" 5 | #include "LLGI.BaseVulkan.h" 6 | #include "LLGI.GraphicsVulkan.h" 7 | 8 | namespace LLGI 9 | { 10 | 11 | class QueryVulkan : public Query 12 | { 13 | private: 14 | std::shared_ptr graphics_; 15 | vk::QueryPool queryPool_; 16 | QueryType queryType_{}; 17 | uint32_t queryCount_{}; 18 | 19 | public: 20 | bool Initialize(GraphicsVulkan* graphics, QueryType queryType, uint32_t queryCount); 21 | 22 | QueryVulkan(); 23 | ~QueryVulkan() override; 24 | 25 | vk::QueryPool& GetQueryPool() { return queryPool_; } 26 | 27 | uint32_t GetQueryCount() const { return queryCount_; } 28 | 29 | uint64_t GetQueryResult(uint32_t queryIndex) override; 30 | }; 31 | 32 | } // namespace LLGI 33 | -------------------------------------------------------------------------------- /src/Vulkan/LLGI.RenderPassPipelineStateCacheVulkan.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../LLGI.Graphics.h" 4 | #include "../Utils/LLGI.FixedSizeVector.h" 5 | #include "LLGI.BaseVulkan.h" 6 | #include "LLGI.RenderPassVulkan.h" 7 | #include 8 | #include 9 | 10 | namespace LLGI 11 | { 12 | 13 | class RenderPassPipelineStateCacheVulkan : public ReferenceObject 14 | { 15 | private: 16 | std::unordered_map, RenderPassPipelineStateKey::Hash> 17 | renderPassPipelineStates_; 18 | 19 | vk::Device device_; 20 | ReferenceObject* owner_ = nullptr; 21 | 22 | public: 23 | RenderPassPipelineStateCacheVulkan(vk::Device device, ReferenceObject* owner); 24 | ~RenderPassPipelineStateCacheVulkan() override; 25 | 26 | RenderPassPipelineStateVulkan* Create(const RenderPassPipelineStateKey key); 27 | }; 28 | 29 | } // namespace LLGI 30 | -------------------------------------------------------------------------------- /src/Vulkan/LLGI.RenderPassVulkan.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../LLGI.Graphics.h" 4 | #include "../Utils/LLGI.FixedSizeVector.h" 5 | #include "LLGI.BaseVulkan.h" 6 | #include 7 | #include 8 | 9 | namespace LLGI 10 | { 11 | 12 | class RenderPassVulkan; 13 | class RenderPassPipelineStateVulkan; 14 | class RenderPassPipelineStateCacheVulkan; 15 | class TextureVulkan; 16 | 17 | class RenderPassVulkan : public RenderPass 18 | { 19 | private: 20 | RenderPassPipelineStateCacheVulkan* renderPassPipelineStateCache_ = nullptr; 21 | vk::Device device_; 22 | ReferenceObject* owner_ = nullptr; 23 | 24 | std::shared_ptr depthBufferPtr; 25 | bool isValid_ = false; 26 | 27 | public: 28 | struct RenderTargetProperty 29 | { 30 | vk::Format format; 31 | vk::Image colorBuffer; 32 | std::shared_ptr colorBufferPtr; 33 | }; 34 | 35 | RenderPassPipelineStateVulkan* renderPassPipelineState = nullptr; 36 | 37 | vk::Framebuffer frameBuffer_; 38 | 39 | FixedSizeVector renderTargetProperties; 40 | 41 | vk::Image depthBuffer; 42 | 43 | RenderPassVulkan(RenderPassPipelineStateCacheVulkan* renderPassPipelineStateCache, vk::Device device, ReferenceObject* owner); 44 | ~RenderPassVulkan() override; 45 | 46 | bool Initialize(const TextureVulkan** textures, 47 | int32_t textureCount, 48 | TextureVulkan* depthTexture, 49 | TextureVulkan* resolvedTexture, 50 | TextureVulkan* resolvedDepthTexture); 51 | 52 | Vec2I GetImageSize() const; 53 | 54 | virtual void SetIsColorCleared(bool isColorCleared) override; 55 | 56 | virtual void SetIsDepthCleared(bool isDepthCleared) override; 57 | 58 | bool GetIsValid() const { return isValid_; } 59 | 60 | private: 61 | void ResetRenderPassPipelineState(); 62 | }; 63 | 64 | class RenderPassPipelineStateVulkan : public RenderPassPipelineState 65 | { 66 | private: 67 | vk::Device device_; 68 | ReferenceObject* owner_ = nullptr; 69 | 70 | public: 71 | RenderPassPipelineStateVulkan(vk::Device device, ReferenceObject* owner); 72 | 73 | ~RenderPassPipelineStateVulkan() override; 74 | 75 | vk::RenderPass renderPass_ = nullptr; 76 | int32_t RenderTargetCount = 0; 77 | FixedSizeVector finalLayouts_; 78 | 79 | vk::RenderPass GetRenderPass() const; 80 | }; 81 | 82 | } // namespace LLGI 83 | -------------------------------------------------------------------------------- /src/Vulkan/LLGI.ShaderVulkan.cpp: -------------------------------------------------------------------------------- 1 | #include "LLGI.ShaderVulkan.h" 2 | 3 | namespace LLGI 4 | { 5 | 6 | ShaderVulkan::ShaderVulkan() {} 7 | 8 | ShaderVulkan::~ShaderVulkan() 9 | { 10 | if (shaderModule_) 11 | { 12 | graphics_->GetDevice().destroyShaderModule(shaderModule_); 13 | shaderModule_ = nullptr; 14 | } 15 | 16 | SafeRelease(graphics_); 17 | } 18 | 19 | bool ShaderVulkan::Initialize(GraphicsVulkan* graphics, DataStructure* data, int count) 20 | { 21 | if (count != 1) 22 | return false; 23 | if (data[0].Size == 0) 24 | return false; 25 | 26 | buffer.resize(data[0].Size); 27 | memcpy(buffer.data(), data[0].Data, data[0].Size); 28 | 29 | SafeAddRef(graphics); 30 | SafeRelease(graphics_); 31 | graphics_ = graphics; 32 | 33 | vk::ShaderModuleCreateInfo info; 34 | info.pCode = reinterpret_cast(buffer.data()); 35 | info.codeSize = buffer.size(); 36 | 37 | shaderModule_ = graphics_->GetDevice().createShaderModule(info); 38 | 39 | return true; 40 | } 41 | 42 | vk::ShaderModule ShaderVulkan::GetShaderModule() const { return shaderModule_; } 43 | 44 | } // namespace LLGI 45 | -------------------------------------------------------------------------------- /src/Vulkan/LLGI.ShaderVulkan.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "../LLGI.Shader.h" 5 | #include "LLGI.BaseVulkan.h" 6 | #include "LLGI.GraphicsVulkan.h" 7 | 8 | namespace LLGI 9 | { 10 | 11 | class ShaderVulkan : public Shader 12 | { 13 | private: 14 | GraphicsVulkan* graphics_ = nullptr; 15 | std::vector buffer; 16 | vk::ShaderModule shaderModule_; 17 | 18 | public: 19 | ShaderVulkan(); 20 | ~ShaderVulkan() override; 21 | 22 | bool Initialize(GraphicsVulkan* graphics, DataStructure* data, int count); 23 | 24 | vk::ShaderModule GetShaderModule() const; 25 | }; 26 | 27 | } // namespace LLGI 28 | -------------------------------------------------------------------------------- /src/Vulkan/LLGI.SingleFrameMemoryPoolVulkan.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "LLGI.BaseVulkan.h" 5 | #include "LLGI.GraphicsVulkan.h" 6 | #include "LLGI.BufferVulkan.h" 7 | 8 | namespace LLGI 9 | { 10 | class GraphicsVulkan; 11 | 12 | class InternalSingleFrameMemoryPoolVulkan 13 | { 14 | private: 15 | int32_t constantBufferSize_ = 0; 16 | int32_t constantBufferOffset_ = 0; 17 | std::unique_ptr buffer_ = nullptr; 18 | 19 | public: 20 | InternalSingleFrameMemoryPoolVulkan(); 21 | virtual ~InternalSingleFrameMemoryPoolVulkan(); 22 | bool Initialize(GraphicsVulkan* graphics, int32_t constantBufferPoolSize, int32_t drawingCount); 23 | void Dispose(); 24 | bool GetConstantBuffer(int32_t size, BufferVulkan*& buffer, int32_t& outOffset); 25 | void Reset(); 26 | }; 27 | 28 | class SingleFrameMemoryPoolVulkan : public SingleFrameMemoryPool 29 | { 30 | private: 31 | GraphicsVulkan* graphics_ = nullptr; 32 | bool isStrongRef_ = false; 33 | std::vector> memoryPools; 34 | int32_t currentSwap_ = 0; 35 | int32_t drawingCount_ = 0; 36 | 37 | protected: 38 | Buffer* CreateBufferInternal(int32_t size) override; 39 | 40 | Buffer* ReinitializeBuffer(Buffer* cb, int32_t size) override; 41 | 42 | public: 43 | SingleFrameMemoryPoolVulkan( 44 | GraphicsVulkan* graphics, bool isStrongRef, int32_t swapBufferCount, int32_t constantBufferPoolSize, int32_t drawingCount); 45 | ~SingleFrameMemoryPoolVulkan() override; 46 | 47 | bool GetConstantBuffer(int32_t size, BufferVulkan*& buffer, int32_t& outOffset); 48 | 49 | InternalSingleFrameMemoryPoolVulkan* GetInternal(); 50 | 51 | int32_t GetDrawingCount() const; 52 | 53 | void NewFrame() override; 54 | }; 55 | 56 | } // namespace LLGI 57 | -------------------------------------------------------------------------------- /src/Win/LLGI.WindowWin.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../LLGI.Base.h" 4 | #include 5 | #include 6 | 7 | namespace LLGI 8 | { 9 | 10 | class WindowWin : public Window 11 | { 12 | private: 13 | HWND hwnd_ = nullptr; 14 | HINSTANCE hInstance_ = nullptr; 15 | std::string title_; 16 | Vec2I windowSize_; 17 | 18 | public: 19 | WindowWin() = default; 20 | 21 | ~WindowWin() override; 22 | 23 | bool Initialize(const char* title, const Vec2I& windowSize); 24 | 25 | bool DoEvent(); 26 | 27 | void Terminate(); 28 | 29 | bool OnNewFrame() override; 30 | 31 | void* GetNativePtr(int32_t index) override; 32 | 33 | Vec2I GetWindowSize() const; 34 | 35 | HWND GetHandle() const { return hwnd_; } 36 | 37 | HINSTANCE GetInstance() const { return hInstance_; } 38 | }; 39 | 40 | } // namespace LLGI 41 | -------------------------------------------------------------------------------- /src_test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file(GLOB files *.h *.cpp) 2 | 3 | add_executable(LLGI_Test ${files}) 4 | 5 | if(APPLE) 6 | 7 | find_library(COCOA_LIBRARY Cocoa) 8 | find_library(METAL_LIBRARY Metal) 9 | find_library(APPKIT_LIBRARY AppKit) 10 | find_library(METALKIT_LIBRARY MetalKit) 11 | find_library(QUARTZ_CORE_LIBRARY QuartzCore) 12 | 13 | set(EXTRA_LIBS ${COCOA_LIBRARY} ${APPKIT_LIBRARY} ${METAL_LIBRARY} 14 | ${METALKIT_LIBRARY} ${QUARTZ_CORE_LIBRARY}) 15 | target_link_libraries(LLGI_Test PRIVATE ${EXTRA_LIBS}) 16 | 17 | endif() 18 | 19 | target_include_directories(LLGI_Test PUBLIC ../src/) 20 | 21 | target_link_libraries(LLGI_Test PRIVATE LLGI) 22 | target_compile_features(LLGI_Test PUBLIC cxx_std_14) 23 | 24 | if(BUILD_VULKAN_COMPILER AND USE_THIRDPARTY_DIRECTORY) 25 | 26 | target_link_directories(LLGI_Test PRIVATE 27 | ${LLGI_THIRDPARTY_LIBRARY_DIRECTORIES}) 28 | target_link_libraries(LLGI_Test PRIVATE ${LLGI_THIRDPARTY_LIBRARIES}) 29 | add_dependencies(LLGI_Test EP_glslang EP_SPIRV-Cross) 30 | endif() 31 | 32 | if(MSVC) 33 | target_link_libraries(LLGI_Test PRIVATE) 34 | elseif(APPLE) 35 | target_link_libraries(LLGI_Test PRIVATE) 36 | else() 37 | find_package(Threads REQUIRED) 38 | target_link_libraries(LLGI_Test PRIVATE ${CMAKE_THREAD_LIBS_INIT} pthread X11 39 | X11-xcb) 40 | endif() 41 | 42 | file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/Shaders 43 | DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/) 44 | 45 | clang_format(LLGI_Test) 46 | 47 | if(MSVC) 48 | target_compile_options(LLGI_Test PRIVATE /W4 /WX /wd4100) 49 | else() 50 | target_compile_options(LLGI_Test PRIVATE -Wall -Werror) 51 | endif() 52 | -------------------------------------------------------------------------------- /src_test/Shaders/GLSL_GL/basic.comp: -------------------------------------------------------------------------------- 1 | #version 430 2 | layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in; 3 | 4 | struct CS_OUTPUT 5 | { 6 | float value; 7 | }; 8 | 9 | struct CS_INPUT 10 | { 11 | float value1; 12 | float value2; 13 | }; 14 | 15 | layout(binding = 1, std430) buffer write 16 | { 17 | CS_OUTPUT _data[]; 18 | } write_1; 19 | 20 | layout(binding = 0, std430) buffer read 21 | { 22 | CS_INPUT _data[]; 23 | } read_1; 24 | 25 | layout(binding = 0, std140) uniform CB 26 | { 27 | float offset; 28 | } CBCS0; 29 | 30 | void _main(uvec3 dtid) 31 | { 32 | write_1._data[dtid.x].value = (read_1._data[dtid.x].value1 * read_1._data[dtid.x].value2) + CBCS0.offset; 33 | } 34 | 35 | void main() 36 | { 37 | uvec3 dtid = gl_GlobalInvocationID; 38 | uvec3 param = dtid; 39 | _main(param); 40 | } 41 | 42 | -------------------------------------------------------------------------------- /src_test/Shaders/GLSL_GL/instancing.vert: -------------------------------------------------------------------------------- 1 | #version 430 2 | #ifdef GL_ARB_shader_draw_parameters 3 | #extension GL_ARB_shader_draw_parameters : enable 4 | #endif 5 | 6 | out gl_PerVertex 7 | { 8 | vec4 gl_Position; 9 | }; 10 | 11 | struct VS_INPUT 12 | { 13 | vec3 g_position; 14 | vec2 g_uv; 15 | vec4 g_color; 16 | uint InstanceId; 17 | }; 18 | 19 | struct VS_OUTPUT 20 | { 21 | vec4 g_position; 22 | vec4 g_color; 23 | }; 24 | 25 | layout(binding = 0, std140) uniform CB 26 | { 27 | vec4 offsets[10]; 28 | } CBVS0; 29 | 30 | layout(location = 0) in vec3 input_g_position; 31 | layout(location = 1) in vec2 input_g_uv; 32 | layout(location = 2) in vec4 input_g_color; 33 | #ifdef GL_ARB_shader_draw_parameters 34 | #define SPIRV_Cross_BaseInstance gl_BaseInstanceARB 35 | #else 36 | uniform int SPIRV_Cross_BaseInstance; 37 | #endif 38 | layout(location = 0) out vec4 _entryPointOutput_g_color; 39 | 40 | VS_OUTPUT _main(VS_INPUT _input) 41 | { 42 | VS_OUTPUT _output; 43 | _output.g_position = vec4(_input.g_position, 1.0); 44 | _output.g_position.x += CBVS0.offsets[_input.InstanceId].x; 45 | _output.g_position.y += CBVS0.offsets[_input.InstanceId].y; 46 | _output.g_color = _input.g_color; 47 | return _output; 48 | } 49 | 50 | void main() 51 | { 52 | VS_INPUT _input; 53 | _input.g_position = input_g_position; 54 | _input.g_uv = input_g_uv; 55 | _input.g_color = input_g_color; 56 | _input.InstanceId = uint((gl_InstanceID + SPIRV_Cross_BaseInstance)); 57 | VS_INPUT param = _input; 58 | VS_OUTPUT flattenTemp = _main(param); 59 | gl_Position = flattenTemp.g_position; 60 | _entryPointOutput_g_color = flattenTemp.g_color; 61 | } 62 | 63 | -------------------------------------------------------------------------------- /src_test/Shaders/GLSL_GL/readwrite.comp: -------------------------------------------------------------------------------- 1 | #version 430 2 | layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in; 3 | 4 | struct CS_OUTPUT 5 | { 6 | float value; 7 | }; 8 | 9 | struct CS_INPUT 10 | { 11 | float value1; 12 | float value2; 13 | }; 14 | 15 | layout(binding = 1, std430) buffer write 16 | { 17 | CS_OUTPUT _data[]; 18 | } write_1; 19 | 20 | layout(binding = 0, std430) readonly buffer read 21 | { 22 | CS_INPUT _data[]; 23 | } read_1; 24 | 25 | layout(binding = 0, std140) uniform CB 26 | { 27 | float offset; 28 | } CBCS0; 29 | 30 | void _main(uvec3 dtid) 31 | { 32 | write_1._data[dtid.x].value = (read_1._data[dtid.x].value1 * read_1._data[dtid.x].value2) + CBCS0.offset; 33 | } 34 | 35 | void main() 36 | { 37 | uvec3 dtid = gl_GlobalInvocationID; 38 | uvec3 param = dtid; 39 | _main(param); 40 | } 41 | 42 | -------------------------------------------------------------------------------- /src_test/Shaders/GLSL_GL/readwrite_texture.comp: -------------------------------------------------------------------------------- 1 | #version 430 2 | layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in; 3 | 4 | layout(binding = 1, rgba32f) uniform readonly image2D read1; 5 | layout(binding = 0, rgba32f) uniform writeonly image2D write; 6 | layout(binding = 2) uniform sampler2D _55; 7 | 8 | void _main(uvec3 dtid) 9 | { 10 | uvec2 index = dtid.xy; 11 | vec4 storeTemp = imageLoad(read1, ivec2(index)) + textureLod(_55, vec2(0.0), 0.0); 12 | imageStore(write, ivec2(index), storeTemp); 13 | } 14 | 15 | void main() 16 | { 17 | uvec3 dtid = gl_GlobalInvocationID; 18 | uvec3 param = dtid; 19 | _main(param); 20 | } 21 | 22 | -------------------------------------------------------------------------------- /src_test/Shaders/GLSL_GL/simple_compute_rectangle.frag: -------------------------------------------------------------------------------- 1 | #version 430 2 | 3 | struct PS_INPUT 4 | { 5 | vec4 Position; 6 | vec2 UV; 7 | vec4 Color; 8 | }; 9 | 10 | layout(binding = 0, std430) readonly buffer compute 11 | { 12 | float _data[]; 13 | } compute_1; 14 | 15 | layout(binding = 1, std140) uniform CB 16 | { 17 | vec4 offset; 18 | } CBPS0; 19 | 20 | layout(location = 0) in vec2 input_UV; 21 | layout(location = 1) in vec4 input_Color; 22 | layout(location = 0) out vec4 _entryPointOutput; 23 | 24 | vec4 _main(PS_INPUT _input) 25 | { 26 | vec4 c = _input.Color + vec4(compute_1._data[0]); 27 | c.w = 1.0; 28 | return c; 29 | } 30 | 31 | void main() 32 | { 33 | PS_INPUT _input; 34 | _input.Position = gl_FragCoord; 35 | _input.UV = input_UV; 36 | _input.Color = input_Color; 37 | PS_INPUT param = _input; 38 | _entryPointOutput = _main(param); 39 | } 40 | 41 | -------------------------------------------------------------------------------- /src_test/Shaders/GLSL_GL/simple_compute_rectangle.vert: -------------------------------------------------------------------------------- 1 | #version 430 2 | 3 | out gl_PerVertex 4 | { 5 | vec4 gl_Position; 6 | }; 7 | 8 | struct VS_INPUT 9 | { 10 | vec3 Position; 11 | vec2 UV; 12 | vec4 Color; 13 | }; 14 | 15 | struct VS_OUTPUT 16 | { 17 | vec4 Position; 18 | vec2 UV; 19 | vec4 Color; 20 | }; 21 | 22 | layout(binding = 0, std430) readonly buffer compute 23 | { 24 | float _data[]; 25 | } compute_1; 26 | 27 | layout(location = 0) in vec3 input_Position; 28 | layout(location = 1) in vec2 input_UV; 29 | layout(location = 2) in vec4 input_Color; 30 | layout(location = 0) out vec2 _entryPointOutput_UV; 31 | layout(location = 1) out vec4 _entryPointOutput_Color; 32 | 33 | VS_OUTPUT _main(VS_INPUT _input) 34 | { 35 | VS_OUTPUT _output; 36 | _output.Position = vec4(_input.Position, 1.0) + vec4(compute_1._data[0]); 37 | _output.UV = _input.UV; 38 | _output.Color = _input.Color; 39 | return _output; 40 | } 41 | 42 | void main() 43 | { 44 | VS_INPUT _input; 45 | _input.Position = input_Position; 46 | _input.UV = input_UV; 47 | _input.Color = input_Color; 48 | VS_INPUT param = _input; 49 | VS_OUTPUT flattenTemp = _main(param); 50 | gl_Position = flattenTemp.Position; 51 | _entryPointOutput_UV = flattenTemp.UV; 52 | _entryPointOutput_Color = flattenTemp.Color; 53 | } 54 | 55 | -------------------------------------------------------------------------------- /src_test/Shaders/GLSL_GL/simple_constant_rectangle.frag: -------------------------------------------------------------------------------- 1 | #version 430 2 | 3 | struct PS_INPUT 4 | { 5 | vec4 Position; 6 | vec2 UV; 7 | vec4 Color; 8 | }; 9 | 10 | layout(binding = 1, std140) uniform CB 11 | { 12 | vec4 offset; 13 | } CBPS0; 14 | 15 | layout(location = 0) in vec2 input_UV; 16 | layout(location = 1) in vec4 input_Color; 17 | layout(location = 0) out vec4 _entryPointOutput; 18 | 19 | vec4 _main(PS_INPUT _input) 20 | { 21 | vec4 c = _input.Color + CBPS0.offset; 22 | c.w = 1.0; 23 | return c; 24 | } 25 | 26 | void main() 27 | { 28 | PS_INPUT _input; 29 | _input.Position = gl_FragCoord; 30 | _input.UV = input_UV; 31 | _input.Color = input_Color; 32 | PS_INPUT param = _input; 33 | _entryPointOutput = _main(param); 34 | } 35 | 36 | -------------------------------------------------------------------------------- /src_test/Shaders/GLSL_GL/simple_constant_rectangle.vert: -------------------------------------------------------------------------------- 1 | #version 430 2 | 3 | out gl_PerVertex 4 | { 5 | vec4 gl_Position; 6 | }; 7 | 8 | struct VS_INPUT 9 | { 10 | vec3 Position; 11 | vec2 UV; 12 | vec4 Color; 13 | }; 14 | 15 | struct VS_OUTPUT 16 | { 17 | vec4 Position; 18 | vec2 UV; 19 | vec4 Color; 20 | }; 21 | 22 | layout(binding = 0, std140) uniform CB 23 | { 24 | vec4 offset; 25 | } CBVS0; 26 | 27 | layout(location = 0) in vec3 input_Position; 28 | layout(location = 1) in vec2 input_UV; 29 | layout(location = 2) in vec4 input_Color; 30 | layout(location = 0) out vec2 _entryPointOutput_UV; 31 | layout(location = 1) out vec4 _entryPointOutput_Color; 32 | 33 | VS_OUTPUT _main(VS_INPUT _input) 34 | { 35 | VS_OUTPUT _output; 36 | _output.Position = vec4(_input.Position, 1.0) + CBVS0.offset; 37 | _output.UV = _input.UV; 38 | _output.Color = _input.Color; 39 | return _output; 40 | } 41 | 42 | void main() 43 | { 44 | VS_INPUT _input; 45 | _input.Position = input_Position; 46 | _input.UV = input_UV; 47 | _input.Color = input_Color; 48 | VS_INPUT param = _input; 49 | VS_OUTPUT flattenTemp = _main(param); 50 | gl_Position = flattenTemp.Position; 51 | _entryPointOutput_UV = flattenTemp.UV; 52 | _entryPointOutput_Color = flattenTemp.Color; 53 | } 54 | 55 | -------------------------------------------------------------------------------- /src_test/Shaders/GLSL_GL/simple_mrt_texture_rectangle.frag: -------------------------------------------------------------------------------- 1 | #version 430 2 | 3 | struct PS_INPUT 4 | { 5 | vec4 Position; 6 | vec2 UV; 7 | vec4 Color; 8 | }; 9 | 10 | struct PS_OUTPUT 11 | { 12 | vec4 Color0; 13 | vec4 Color1; 14 | }; 15 | 16 | layout(binding = 0) uniform sampler2D _90; 17 | 18 | layout(location = 0) in vec2 input_UV; 19 | layout(location = 1) in vec4 input_Color; 20 | layout(location = 0) out vec4 _entryPointOutput_Color0; 21 | layout(location = 1) out vec4 _entryPointOutput_Color1; 22 | 23 | PS_OUTPUT _main(PS_INPUT _input) 24 | { 25 | vec4 c = texture(_90, _input.UV); 26 | c.w = 255.0; 27 | PS_OUTPUT _output; 28 | _output.Color0 = c; 29 | c.x = 1.0 - c.x; 30 | c.y = 1.0 - c.y; 31 | c.z = 1.0 - c.z; 32 | _output.Color1 = c; 33 | return _output; 34 | } 35 | 36 | void main() 37 | { 38 | PS_INPUT _input; 39 | _input.Position = gl_FragCoord; 40 | _input.UV = input_UV; 41 | _input.Color = input_Color; 42 | PS_INPUT param = _input; 43 | PS_OUTPUT flattenTemp = _main(param); 44 | _entryPointOutput_Color0 = flattenTemp.Color0; 45 | _entryPointOutput_Color1 = flattenTemp.Color1; 46 | } 47 | 48 | -------------------------------------------------------------------------------- /src_test/Shaders/GLSL_GL/simple_rectangle.frag: -------------------------------------------------------------------------------- 1 | #version 430 2 | 3 | struct PS_INPUT 4 | { 5 | vec4 g_position; 6 | vec4 g_color; 7 | }; 8 | 9 | layout(location = 0) in vec4 input_g_color; 10 | layout(location = 0) out vec4 _entryPointOutput; 11 | 12 | vec4 _main(PS_INPUT _input) 13 | { 14 | return _input.g_color; 15 | } 16 | 17 | void main() 18 | { 19 | PS_INPUT _input; 20 | _input.g_position = gl_FragCoord; 21 | _input.g_color = input_g_color; 22 | PS_INPUT param = _input; 23 | _entryPointOutput = _main(param); 24 | } 25 | 26 | -------------------------------------------------------------------------------- /src_test/Shaders/GLSL_GL/simple_rectangle.vert: -------------------------------------------------------------------------------- 1 | #version 430 2 | 3 | out gl_PerVertex 4 | { 5 | vec4 gl_Position; 6 | }; 7 | 8 | struct VS_INPUT 9 | { 10 | vec3 g_position; 11 | vec2 g_uv; 12 | vec4 g_color; 13 | }; 14 | 15 | struct VS_OUTPUT 16 | { 17 | vec4 g_position; 18 | vec4 g_color; 19 | }; 20 | 21 | layout(location = 0) in vec3 input_g_position; 22 | layout(location = 1) in vec2 input_g_uv; 23 | layout(location = 2) in vec4 input_g_color; 24 | layout(location = 0) out vec4 _entryPointOutput_g_color; 25 | 26 | VS_OUTPUT _main(VS_INPUT _input) 27 | { 28 | VS_OUTPUT _output; 29 | _output.g_position = vec4(_input.g_position, 1.0); 30 | _output.g_color = _input.g_color; 31 | return _output; 32 | } 33 | 34 | void main() 35 | { 36 | VS_INPUT _input; 37 | _input.g_position = input_g_position; 38 | _input.g_uv = input_g_uv; 39 | _input.g_color = input_g_color; 40 | VS_INPUT param = _input; 41 | VS_OUTPUT flattenTemp = _main(param); 42 | gl_Position = flattenTemp.g_position; 43 | _entryPointOutput_g_color = flattenTemp.g_color; 44 | } 45 | 46 | -------------------------------------------------------------------------------- /src_test/Shaders/GLSL_GL/simple_texture_rectangle.frag: -------------------------------------------------------------------------------- 1 | #version 430 2 | 3 | struct PS_INPUT 4 | { 5 | vec4 Position; 6 | vec2 UV; 7 | vec4 Color; 8 | }; 9 | 10 | layout(binding = 0) uniform sampler2D _61; 11 | 12 | layout(location = 0) in vec2 input_UV; 13 | layout(location = 1) in vec4 input_Color; 14 | layout(location = 0) out vec4 _entryPointOutput; 15 | 16 | vec4 _main(PS_INPUT _input) 17 | { 18 | vec4 c = texture(_61, _input.UV); 19 | c.w = 255.0; 20 | return c; 21 | } 22 | 23 | void main() 24 | { 25 | PS_INPUT _input; 26 | _input.Position = gl_FragCoord; 27 | _input.UV = input_UV; 28 | _input.Color = input_Color; 29 | PS_INPUT param = _input; 30 | _entryPointOutput = _main(param); 31 | } 32 | 33 | -------------------------------------------------------------------------------- /src_test/Shaders/GLSL_GL/simple_texture_rectangle.vert: -------------------------------------------------------------------------------- 1 | #version 430 2 | 3 | out gl_PerVertex 4 | { 5 | vec4 gl_Position; 6 | }; 7 | 8 | struct VS_INPUT 9 | { 10 | vec3 Position; 11 | vec2 UV; 12 | vec4 Color; 13 | }; 14 | 15 | struct VS_OUTPUT 16 | { 17 | vec4 Position; 18 | vec2 UV; 19 | vec4 Color; 20 | }; 21 | 22 | layout(location = 0) in vec3 input_Position; 23 | layout(location = 1) in vec2 input_UV; 24 | layout(location = 2) in vec4 input_Color; 25 | layout(location = 0) out vec2 _entryPointOutput_UV; 26 | layout(location = 1) out vec4 _entryPointOutput_Color; 27 | 28 | VS_OUTPUT _main(VS_INPUT _input) 29 | { 30 | VS_OUTPUT _output; 31 | _output.Position = vec4(_input.Position, 1.0); 32 | _output.UV = _input.UV; 33 | _output.Color = _input.Color; 34 | return _output; 35 | } 36 | 37 | void main() 38 | { 39 | VS_INPUT _input; 40 | _input.Position = input_Position; 41 | _input.UV = input_UV; 42 | _input.Color = input_Color; 43 | VS_INPUT param = _input; 44 | VS_OUTPUT flattenTemp = _main(param); 45 | gl_Position = flattenTemp.Position; 46 | _entryPointOutput_UV = flattenTemp.UV; 47 | _entryPointOutput_Color = flattenTemp.Color; 48 | } 49 | 50 | -------------------------------------------------------------------------------- /src_test/Shaders/GLSL_GL/textures.frag: -------------------------------------------------------------------------------- 1 | #version 430 2 | 3 | struct PS_Input 4 | { 5 | vec4 Pos; 6 | vec2 UV; 7 | vec4 Color; 8 | }; 9 | 10 | layout(binding = 0) uniform sampler2D _97; 11 | layout(binding = 1) uniform sampler2DArray _99; 12 | layout(binding = 2) uniform sampler3D _101; 13 | 14 | layout(location = 0) in vec2 Input_UV; 15 | layout(location = 1) in vec4 Input_Color; 16 | layout(location = 0) out vec4 _entryPointOutput; 17 | 18 | vec4 _main(PS_Input Input) 19 | { 20 | if (Input.UV.x < 0.300000011920928955078125) 21 | { 22 | return texture(_97, Input.UV); 23 | } 24 | else 25 | { 26 | if (Input.UV.x < 0.60000002384185791015625) 27 | { 28 | return texture(_99, vec3(Input.UV, 1.0)); 29 | } 30 | } 31 | return texture(_101, vec3(Input.UV, 0.5)); 32 | } 33 | 34 | void main() 35 | { 36 | PS_Input Input; 37 | Input.Pos = gl_FragCoord; 38 | Input.UV = Input_UV; 39 | Input.Color = Input_Color; 40 | _entryPointOutput = _main(Input); 41 | } 42 | 43 | -------------------------------------------------------------------------------- /src_test/Shaders/GLSL_GL/vertex_structured.vert: -------------------------------------------------------------------------------- 1 | #version 430 2 | #ifdef GL_ARB_shader_draw_parameters 3 | #extension GL_ARB_shader_draw_parameters : enable 4 | #endif 5 | 6 | out gl_PerVertex 7 | { 8 | vec4 gl_Position; 9 | }; 10 | 11 | struct VS_INPUT 12 | { 13 | vec3 g_position; 14 | vec2 g_uv; 15 | vec4 g_color; 16 | uint InstanceId; 17 | }; 18 | 19 | struct VS_OUTPUT 20 | { 21 | vec4 g_position; 22 | vec4 g_color; 23 | }; 24 | 25 | struct CS_INPUT 26 | { 27 | float value1; 28 | float value2; 29 | }; 30 | 31 | layout(binding = 0, std430) readonly buffer read 32 | { 33 | CS_INPUT _data[]; 34 | } read_1; 35 | 36 | layout(location = 0) in vec3 input_g_position; 37 | layout(location = 1) in vec2 input_g_uv; 38 | layout(location = 2) in vec4 input_g_color; 39 | #ifdef GL_ARB_shader_draw_parameters 40 | #define SPIRV_Cross_BaseInstance gl_BaseInstanceARB 41 | #else 42 | uniform int SPIRV_Cross_BaseInstance; 43 | #endif 44 | layout(location = 0) out vec4 _entryPointOutput_g_color; 45 | 46 | VS_OUTPUT _main(VS_INPUT _input) 47 | { 48 | VS_OUTPUT _output; 49 | _output.g_position = vec4(_input.g_position, 1.0); 50 | _output.g_position.x += read_1._data[_input.InstanceId].value1; 51 | _output.g_position.y += read_1._data[_input.InstanceId].value2; 52 | _output.g_color = _input.g_color; 53 | return _output; 54 | } 55 | 56 | void main() 57 | { 58 | VS_INPUT _input; 59 | _input.g_position = input_g_position; 60 | _input.g_uv = input_g_uv; 61 | _input.g_color = input_g_color; 62 | _input.InstanceId = uint((gl_InstanceID + SPIRV_Cross_BaseInstance)); 63 | VS_INPUT param = _input; 64 | VS_OUTPUT flattenTemp = _main(param); 65 | gl_Position = flattenTemp.g_position; 66 | _entryPointOutput_g_color = flattenTemp.g_color; 67 | } 68 | 69 | -------------------------------------------------------------------------------- /src_test/Shaders/GLSL_GL/vtf.vert: -------------------------------------------------------------------------------- 1 | #version 430 2 | 3 | out gl_PerVertex 4 | { 5 | vec4 gl_Position; 6 | }; 7 | 8 | struct VS_INPUT 9 | { 10 | vec3 g_position; 11 | vec2 g_uv; 12 | vec4 g_color; 13 | }; 14 | 15 | struct VS_OUTPUT 16 | { 17 | vec4 g_position; 18 | vec4 g_color; 19 | }; 20 | 21 | layout(binding = 0) uniform sampler2D _94; 22 | 23 | layout(location = 0) in vec3 input_g_position; 24 | layout(location = 1) in vec2 input_g_uv; 25 | layout(location = 2) in vec4 input_g_color; 26 | layout(location = 0) out vec4 _entryPointOutput_g_color; 27 | 28 | VS_OUTPUT _main(VS_INPUT _input) 29 | { 30 | vec4 c = textureLod(_94, _input.g_uv, 0.0); 31 | VS_OUTPUT _output; 32 | _output.g_position = vec4(_input.g_position, 1.0); 33 | vec4 _51 = _output.g_position; 34 | vec2 _53 = _51.xy + c.xy; 35 | _output.g_position.x = _53.x; 36 | _output.g_position.y = _53.y; 37 | _output.g_color = _input.g_color; 38 | return _output; 39 | } 40 | 41 | void main() 42 | { 43 | VS_INPUT _input; 44 | _input.g_position = input_g_position; 45 | _input.g_uv = input_g_uv; 46 | _input.g_color = input_g_color; 47 | VS_INPUT param = _input; 48 | VS_OUTPUT flattenTemp = _main(param); 49 | gl_Position = flattenTemp.g_position; 50 | _entryPointOutput_g_color = flattenTemp.g_color; 51 | } 52 | 53 | -------------------------------------------------------------------------------- /src_test/Shaders/GLSL_VULKAN/basic.comp: -------------------------------------------------------------------------------- 1 | #version 430 2 | layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in; 3 | 4 | struct CS_OUTPUT 5 | { 6 | float value; 7 | }; 8 | 9 | struct CS_INPUT 10 | { 11 | float value1; 12 | float value2; 13 | }; 14 | 15 | layout(set = 2, binding = 1, std430) buffer write 16 | { 17 | CS_OUTPUT _data[]; 18 | } write_1; 19 | 20 | layout(set = 2, binding = 0, std430) buffer read 21 | { 22 | CS_INPUT _data[]; 23 | } read_1; 24 | 25 | layout(set = 0, binding = 0, std140) uniform CB 26 | { 27 | float offset; 28 | } _43; 29 | 30 | void _main(uvec3 dtid) 31 | { 32 | write_1._data[dtid.x].value = (read_1._data[dtid.x].value1 * read_1._data[dtid.x].value2) + _43.offset; 33 | } 34 | 35 | void main() 36 | { 37 | uvec3 dtid = gl_GlobalInvocationID; 38 | uvec3 param = dtid; 39 | _main(param); 40 | } 41 | 42 | -------------------------------------------------------------------------------- /src_test/Shaders/GLSL_VULKAN/instancing.vert: -------------------------------------------------------------------------------- 1 | #version 430 2 | 3 | struct VS_INPUT 4 | { 5 | vec3 g_position; 6 | vec2 g_uv; 7 | vec4 g_color; 8 | uint InstanceId; 9 | }; 10 | 11 | struct VS_OUTPUT 12 | { 13 | vec4 g_position; 14 | vec4 g_color; 15 | }; 16 | 17 | layout(set = 0, binding = 0, std140) uniform CB 18 | { 19 | vec4 offsets[10]; 20 | } _36; 21 | 22 | layout(location = 0) in vec3 input_g_position; 23 | layout(location = 1) in vec2 input_g_uv; 24 | layout(location = 2) in vec4 input_g_color; 25 | layout(location = 0) out vec4 _entryPointOutput_g_color; 26 | 27 | VS_OUTPUT _main(VS_INPUT _input) 28 | { 29 | VS_OUTPUT _output; 30 | _output.g_position = vec4(_input.g_position, 1.0); 31 | _output.g_position.x += _36.offsets[_input.InstanceId].x; 32 | _output.g_position.y += _36.offsets[_input.InstanceId].y; 33 | _output.g_color = _input.g_color; 34 | return _output; 35 | } 36 | 37 | void main() 38 | { 39 | VS_INPUT _input; 40 | _input.g_position = input_g_position; 41 | _input.g_uv = input_g_uv; 42 | _input.g_color = input_g_color; 43 | _input.InstanceId = uint(gl_InstanceIndex); 44 | VS_INPUT param = _input; 45 | VS_OUTPUT flattenTemp = _main(param); 46 | vec4 _position = flattenTemp.g_position; 47 | _position.y = -_position.y; 48 | gl_Position = _position; 49 | _entryPointOutput_g_color = flattenTemp.g_color; 50 | } 51 | 52 | -------------------------------------------------------------------------------- /src_test/Shaders/GLSL_VULKAN/readwrite.comp: -------------------------------------------------------------------------------- 1 | #version 430 2 | layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in; 3 | 4 | struct CS_OUTPUT 5 | { 6 | float value; 7 | }; 8 | 9 | struct CS_INPUT 10 | { 11 | float value1; 12 | float value2; 13 | }; 14 | 15 | layout(set = 2, binding = 1, std430) buffer write 16 | { 17 | CS_OUTPUT _data[]; 18 | } write_1; 19 | 20 | layout(set = 2, binding = 0, std430) readonly buffer read 21 | { 22 | CS_INPUT _data[]; 23 | } read_1; 24 | 25 | layout(set = 0, binding = 0, std140) uniform CB 26 | { 27 | float offset; 28 | } _43; 29 | 30 | void _main(uvec3 dtid) 31 | { 32 | write_1._data[dtid.x].value = (read_1._data[dtid.x].value1 * read_1._data[dtid.x].value2) + _43.offset; 33 | } 34 | 35 | void main() 36 | { 37 | uvec3 dtid = gl_GlobalInvocationID; 38 | uvec3 param = dtid; 39 | _main(param); 40 | } 41 | 42 | -------------------------------------------------------------------------------- /src_test/Shaders/GLSL_VULKAN/readwrite_texture.comp: -------------------------------------------------------------------------------- 1 | #version 430 2 | layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in; 3 | 4 | layout(set = 3, binding = 1, rgba32f) uniform readonly image2D read1; 5 | layout(set = 3, binding = 0, rgba32f) uniform writeonly image2D write; 6 | layout(set = 1, binding = 2) uniform sampler2D Sampler_read2_sampler; 7 | 8 | void _main(uvec3 dtid) 9 | { 10 | uvec2 index = dtid.xy; 11 | vec4 storeTemp = imageLoad(read1, ivec2(index)) + textureLod(Sampler_read2_sampler, vec2(0.0), 0.0); 12 | imageStore(write, ivec2(index), storeTemp); 13 | } 14 | 15 | void main() 16 | { 17 | uvec3 dtid = gl_GlobalInvocationID; 18 | uvec3 param = dtid; 19 | _main(param); 20 | } 21 | 22 | -------------------------------------------------------------------------------- /src_test/Shaders/GLSL_VULKAN/simple_compute_rectangle.frag: -------------------------------------------------------------------------------- 1 | #version 430 2 | 3 | struct PS_INPUT 4 | { 5 | vec4 Position; 6 | vec2 UV; 7 | vec4 Color; 8 | }; 9 | 10 | layout(set = 2, binding = 0, std430) readonly buffer compute 11 | { 12 | float _data[]; 13 | } compute_1; 14 | 15 | layout(set = 0, binding = 1, std140) uniform CB 16 | { 17 | vec4 offset; 18 | } _60; 19 | 20 | layout(location = 0) in vec2 input_UV; 21 | layout(location = 1) in vec4 input_Color; 22 | layout(location = 0) out vec4 _entryPointOutput; 23 | 24 | vec4 _main(PS_INPUT _input) 25 | { 26 | vec4 c = _input.Color + vec4(compute_1._data[0]); 27 | c.w = 1.0; 28 | return c; 29 | } 30 | 31 | void main() 32 | { 33 | PS_INPUT _input; 34 | _input.Position = gl_FragCoord; 35 | _input.UV = input_UV; 36 | _input.Color = input_Color; 37 | PS_INPUT param = _input; 38 | _entryPointOutput = _main(param); 39 | } 40 | 41 | -------------------------------------------------------------------------------- /src_test/Shaders/GLSL_VULKAN/simple_compute_rectangle.vert: -------------------------------------------------------------------------------- 1 | #version 430 2 | 3 | struct VS_INPUT 4 | { 5 | vec3 Position; 6 | vec2 UV; 7 | vec4 Color; 8 | }; 9 | 10 | struct VS_OUTPUT 11 | { 12 | vec4 Position; 13 | vec2 UV; 14 | vec4 Color; 15 | }; 16 | 17 | layout(set = 2, binding = 0, std430) readonly buffer compute 18 | { 19 | float _data[]; 20 | } compute_1; 21 | 22 | layout(location = 0) in vec3 input_Position; 23 | layout(location = 1) in vec2 input_UV; 24 | layout(location = 2) in vec4 input_Color; 25 | layout(location = 0) out vec2 _entryPointOutput_UV; 26 | layout(location = 1) out vec4 _entryPointOutput_Color; 27 | 28 | VS_OUTPUT _main(VS_INPUT _input) 29 | { 30 | VS_OUTPUT _output; 31 | _output.Position = vec4(_input.Position, 1.0) + vec4(compute_1._data[0]); 32 | _output.UV = _input.UV; 33 | _output.Color = _input.Color; 34 | return _output; 35 | } 36 | 37 | void main() 38 | { 39 | VS_INPUT _input; 40 | _input.Position = input_Position; 41 | _input.UV = input_UV; 42 | _input.Color = input_Color; 43 | VS_INPUT param = _input; 44 | VS_OUTPUT flattenTemp = _main(param); 45 | vec4 _position = flattenTemp.Position; 46 | _position.y = -_position.y; 47 | gl_Position = _position; 48 | _entryPointOutput_UV = flattenTemp.UV; 49 | _entryPointOutput_Color = flattenTemp.Color; 50 | } 51 | 52 | -------------------------------------------------------------------------------- /src_test/Shaders/GLSL_VULKAN/simple_constant_rectangle.frag: -------------------------------------------------------------------------------- 1 | #version 430 2 | 3 | struct PS_INPUT 4 | { 5 | vec4 Position; 6 | vec2 UV; 7 | vec4 Color; 8 | }; 9 | 10 | layout(set = 0, binding = 1, std140) uniform CB 11 | { 12 | vec4 offset; 13 | } _23; 14 | 15 | layout(location = 0) in vec2 input_UV; 16 | layout(location = 1) in vec4 input_Color; 17 | layout(location = 0) out vec4 _entryPointOutput; 18 | 19 | vec4 _main(PS_INPUT _input) 20 | { 21 | vec4 c = _input.Color + _23.offset; 22 | c.w = 1.0; 23 | return c; 24 | } 25 | 26 | void main() 27 | { 28 | PS_INPUT _input; 29 | _input.Position = gl_FragCoord; 30 | _input.UV = input_UV; 31 | _input.Color = input_Color; 32 | PS_INPUT param = _input; 33 | _entryPointOutput = _main(param); 34 | } 35 | 36 | -------------------------------------------------------------------------------- /src_test/Shaders/GLSL_VULKAN/simple_constant_rectangle.vert: -------------------------------------------------------------------------------- 1 | #version 430 2 | 3 | struct VS_INPUT 4 | { 5 | vec3 Position; 6 | vec2 UV; 7 | vec4 Color; 8 | }; 9 | 10 | struct VS_OUTPUT 11 | { 12 | vec4 Position; 13 | vec2 UV; 14 | vec4 Color; 15 | }; 16 | 17 | layout(set = 0, binding = 0, std140) uniform CB 18 | { 19 | vec4 offset; 20 | } _31; 21 | 22 | layout(location = 0) in vec3 input_Position; 23 | layout(location = 1) in vec2 input_UV; 24 | layout(location = 2) in vec4 input_Color; 25 | layout(location = 0) out vec2 _entryPointOutput_UV; 26 | layout(location = 1) out vec4 _entryPointOutput_Color; 27 | 28 | VS_OUTPUT _main(VS_INPUT _input) 29 | { 30 | VS_OUTPUT _output; 31 | _output.Position = vec4(_input.Position, 1.0) + _31.offset; 32 | _output.UV = _input.UV; 33 | _output.Color = _input.Color; 34 | return _output; 35 | } 36 | 37 | void main() 38 | { 39 | VS_INPUT _input; 40 | _input.Position = input_Position; 41 | _input.UV = input_UV; 42 | _input.Color = input_Color; 43 | VS_INPUT param = _input; 44 | VS_OUTPUT flattenTemp = _main(param); 45 | vec4 _position = flattenTemp.Position; 46 | _position.y = -_position.y; 47 | gl_Position = _position; 48 | _entryPointOutput_UV = flattenTemp.UV; 49 | _entryPointOutput_Color = flattenTemp.Color; 50 | } 51 | 52 | -------------------------------------------------------------------------------- /src_test/Shaders/GLSL_VULKAN/simple_mrt_texture_rectangle.frag: -------------------------------------------------------------------------------- 1 | #version 430 2 | 3 | struct PS_INPUT 4 | { 5 | vec4 Position; 6 | vec2 UV; 7 | vec4 Color; 8 | }; 9 | 10 | struct PS_OUTPUT 11 | { 12 | vec4 Color0; 13 | vec4 Color1; 14 | }; 15 | 16 | layout(set = 1, binding = 0) uniform sampler2D Sampler_smp; 17 | 18 | layout(location = 0) in vec2 input_UV; 19 | layout(location = 1) in vec4 input_Color; 20 | layout(location = 0) out vec4 _entryPointOutput_Color0; 21 | layout(location = 1) out vec4 _entryPointOutput_Color1; 22 | 23 | PS_OUTPUT _main(PS_INPUT _input) 24 | { 25 | vec4 c = texture(Sampler_smp, _input.UV); 26 | c.w = 255.0; 27 | PS_OUTPUT _output; 28 | _output.Color0 = c; 29 | c.x = 1.0 - c.x; 30 | c.y = 1.0 - c.y; 31 | c.z = 1.0 - c.z; 32 | _output.Color1 = c; 33 | return _output; 34 | } 35 | 36 | void main() 37 | { 38 | PS_INPUT _input; 39 | _input.Position = gl_FragCoord; 40 | _input.UV = input_UV; 41 | _input.Color = input_Color; 42 | PS_INPUT param = _input; 43 | PS_OUTPUT flattenTemp = _main(param); 44 | _entryPointOutput_Color0 = flattenTemp.Color0; 45 | _entryPointOutput_Color1 = flattenTemp.Color1; 46 | } 47 | 48 | -------------------------------------------------------------------------------- /src_test/Shaders/GLSL_VULKAN/simple_rectangle.frag: -------------------------------------------------------------------------------- 1 | #version 430 2 | 3 | struct PS_INPUT 4 | { 5 | vec4 g_position; 6 | vec4 g_color; 7 | }; 8 | 9 | layout(location = 0) in vec4 input_g_color; 10 | layout(location = 0) out vec4 _entryPointOutput; 11 | 12 | vec4 _main(PS_INPUT _input) 13 | { 14 | return _input.g_color; 15 | } 16 | 17 | void main() 18 | { 19 | PS_INPUT _input; 20 | _input.g_position = gl_FragCoord; 21 | _input.g_color = input_g_color; 22 | PS_INPUT param = _input; 23 | _entryPointOutput = _main(param); 24 | } 25 | 26 | -------------------------------------------------------------------------------- /src_test/Shaders/GLSL_VULKAN/simple_rectangle.vert: -------------------------------------------------------------------------------- 1 | #version 430 2 | 3 | struct VS_INPUT 4 | { 5 | vec3 g_position; 6 | vec2 g_uv; 7 | vec4 g_color; 8 | }; 9 | 10 | struct VS_OUTPUT 11 | { 12 | vec4 g_position; 13 | vec4 g_color; 14 | }; 15 | 16 | layout(location = 0) in vec3 input_g_position; 17 | layout(location = 1) in vec2 input_g_uv; 18 | layout(location = 2) in vec4 input_g_color; 19 | layout(location = 0) out vec4 _entryPointOutput_g_color; 20 | 21 | VS_OUTPUT _main(VS_INPUT _input) 22 | { 23 | VS_OUTPUT _output; 24 | _output.g_position = vec4(_input.g_position, 1.0); 25 | _output.g_color = _input.g_color; 26 | return _output; 27 | } 28 | 29 | void main() 30 | { 31 | VS_INPUT _input; 32 | _input.g_position = input_g_position; 33 | _input.g_uv = input_g_uv; 34 | _input.g_color = input_g_color; 35 | VS_INPUT param = _input; 36 | VS_OUTPUT flattenTemp = _main(param); 37 | vec4 _position = flattenTemp.g_position; 38 | _position.y = -_position.y; 39 | gl_Position = _position; 40 | _entryPointOutput_g_color = flattenTemp.g_color; 41 | } 42 | 43 | -------------------------------------------------------------------------------- /src_test/Shaders/GLSL_VULKAN/simple_texture_rectangle.frag: -------------------------------------------------------------------------------- 1 | #version 430 2 | 3 | struct PS_INPUT 4 | { 5 | vec4 Position; 6 | vec2 UV; 7 | vec4 Color; 8 | }; 9 | 10 | layout(set = 1, binding = 0) uniform sampler2D Sampler_smp; 11 | 12 | layout(location = 0) in vec2 input_UV; 13 | layout(location = 1) in vec4 input_Color; 14 | layout(location = 0) out vec4 _entryPointOutput; 15 | 16 | vec4 _main(PS_INPUT _input) 17 | { 18 | vec4 c = texture(Sampler_smp, _input.UV); 19 | c.w = 255.0; 20 | return c; 21 | } 22 | 23 | void main() 24 | { 25 | PS_INPUT _input; 26 | _input.Position = gl_FragCoord; 27 | _input.UV = input_UV; 28 | _input.Color = input_Color; 29 | PS_INPUT param = _input; 30 | _entryPointOutput = _main(param); 31 | } 32 | 33 | -------------------------------------------------------------------------------- /src_test/Shaders/GLSL_VULKAN/simple_texture_rectangle.vert: -------------------------------------------------------------------------------- 1 | #version 430 2 | 3 | struct VS_INPUT 4 | { 5 | vec3 Position; 6 | vec2 UV; 7 | vec4 Color; 8 | }; 9 | 10 | struct VS_OUTPUT 11 | { 12 | vec4 Position; 13 | vec2 UV; 14 | vec4 Color; 15 | }; 16 | 17 | layout(location = 0) in vec3 input_Position; 18 | layout(location = 1) in vec2 input_UV; 19 | layout(location = 2) in vec4 input_Color; 20 | layout(location = 0) out vec2 _entryPointOutput_UV; 21 | layout(location = 1) out vec4 _entryPointOutput_Color; 22 | 23 | VS_OUTPUT _main(VS_INPUT _input) 24 | { 25 | VS_OUTPUT _output; 26 | _output.Position = vec4(_input.Position, 1.0); 27 | _output.UV = _input.UV; 28 | _output.Color = _input.Color; 29 | return _output; 30 | } 31 | 32 | void main() 33 | { 34 | VS_INPUT _input; 35 | _input.Position = input_Position; 36 | _input.UV = input_UV; 37 | _input.Color = input_Color; 38 | VS_INPUT param = _input; 39 | VS_OUTPUT flattenTemp = _main(param); 40 | vec4 _position = flattenTemp.Position; 41 | _position.y = -_position.y; 42 | gl_Position = _position; 43 | _entryPointOutput_UV = flattenTemp.UV; 44 | _entryPointOutput_Color = flattenTemp.Color; 45 | } 46 | 47 | -------------------------------------------------------------------------------- /src_test/Shaders/GLSL_VULKAN/textures.frag: -------------------------------------------------------------------------------- 1 | #version 430 2 | 3 | struct PS_Input 4 | { 5 | vec4 Pos; 6 | vec2 UV; 7 | vec4 Color; 8 | }; 9 | 10 | layout(set = 1, binding = 0) uniform sampler2D Sampler_g_sampler1; 11 | layout(set = 1, binding = 1) uniform sampler2DArray Sampler_g_sampler2; 12 | layout(set = 1, binding = 2) uniform sampler3D Sampler_g_sampler3; 13 | 14 | layout(location = 0) in vec2 Input_UV; 15 | layout(location = 1) in vec4 Input_Color; 16 | layout(location = 0) out vec4 _entryPointOutput; 17 | 18 | vec4 _main(PS_Input Input) 19 | { 20 | if (Input.UV.x < 0.300000011920928955078125) 21 | { 22 | return texture(Sampler_g_sampler1, Input.UV); 23 | } 24 | else 25 | { 26 | if (Input.UV.x < 0.60000002384185791015625) 27 | { 28 | return texture(Sampler_g_sampler2, vec3(Input.UV, 1.0)); 29 | } 30 | } 31 | return texture(Sampler_g_sampler3, vec3(Input.UV, 0.5)); 32 | } 33 | 34 | void main() 35 | { 36 | PS_Input Input; 37 | Input.Pos = gl_FragCoord; 38 | Input.UV = Input_UV; 39 | Input.Color = Input_Color; 40 | _entryPointOutput = _main(Input); 41 | } 42 | 43 | -------------------------------------------------------------------------------- /src_test/Shaders/GLSL_VULKAN/vertex_structured.vert: -------------------------------------------------------------------------------- 1 | #version 430 2 | 3 | struct VS_INPUT 4 | { 5 | vec3 g_position; 6 | vec2 g_uv; 7 | vec4 g_color; 8 | uint InstanceId; 9 | }; 10 | 11 | struct VS_OUTPUT 12 | { 13 | vec4 g_position; 14 | vec4 g_color; 15 | }; 16 | 17 | struct CS_INPUT 18 | { 19 | float value1; 20 | float value2; 21 | }; 22 | 23 | layout(set = 2, binding = 0, std430) readonly buffer read 24 | { 25 | CS_INPUT _data[]; 26 | } read_1; 27 | 28 | layout(location = 0) in vec3 input_g_position; 29 | layout(location = 1) in vec2 input_g_uv; 30 | layout(location = 2) in vec4 input_g_color; 31 | layout(location = 0) out vec4 _entryPointOutput_g_color; 32 | 33 | VS_OUTPUT _main(VS_INPUT _input) 34 | { 35 | VS_OUTPUT _output; 36 | _output.g_position = vec4(_input.g_position, 1.0); 37 | _output.g_position.x += read_1._data[_input.InstanceId].value1; 38 | _output.g_position.y += read_1._data[_input.InstanceId].value2; 39 | _output.g_color = _input.g_color; 40 | return _output; 41 | } 42 | 43 | void main() 44 | { 45 | VS_INPUT _input; 46 | _input.g_position = input_g_position; 47 | _input.g_uv = input_g_uv; 48 | _input.g_color = input_g_color; 49 | _input.InstanceId = uint(gl_InstanceIndex); 50 | VS_INPUT param = _input; 51 | VS_OUTPUT flattenTemp = _main(param); 52 | vec4 _position = flattenTemp.g_position; 53 | _position.y = -_position.y; 54 | gl_Position = _position; 55 | _entryPointOutput_g_color = flattenTemp.g_color; 56 | } 57 | 58 | -------------------------------------------------------------------------------- /src_test/Shaders/GLSL_VULKAN/vtf.vert: -------------------------------------------------------------------------------- 1 | #version 430 2 | 3 | struct VS_INPUT 4 | { 5 | vec3 g_position; 6 | vec2 g_uv; 7 | vec4 g_color; 8 | }; 9 | 10 | struct VS_OUTPUT 11 | { 12 | vec4 g_position; 13 | vec4 g_color; 14 | }; 15 | 16 | layout(set = 1, binding = 0) uniform sampler2D Sampler_smp; 17 | 18 | layout(location = 0) in vec3 input_g_position; 19 | layout(location = 1) in vec2 input_g_uv; 20 | layout(location = 2) in vec4 input_g_color; 21 | layout(location = 0) out vec4 _entryPointOutput_g_color; 22 | 23 | VS_OUTPUT _main(VS_INPUT _input) 24 | { 25 | vec4 c = textureLod(Sampler_smp, _input.g_uv, 0.0); 26 | VS_OUTPUT _output; 27 | _output.g_position = vec4(_input.g_position, 1.0); 28 | vec4 _51 = _output.g_position; 29 | vec2 _53 = _51.xy + c.xy; 30 | _output.g_position.x = _53.x; 31 | _output.g_position.y = _53.y; 32 | _output.g_color = _input.g_color; 33 | return _output; 34 | } 35 | 36 | void main() 37 | { 38 | VS_INPUT _input; 39 | _input.g_position = input_g_position; 40 | _input.g_uv = input_g_uv; 41 | _input.g_color = input_g_color; 42 | VS_INPUT param = _input; 43 | VS_OUTPUT flattenTemp = _main(param); 44 | vec4 _position = flattenTemp.g_position; 45 | _position.y = -_position.y; 46 | gl_Position = _position; 47 | _entryPointOutput_g_color = flattenTemp.g_color; 48 | } 49 | 50 | -------------------------------------------------------------------------------- /src_test/Shaders/HLSL_DX12/basic.comp: -------------------------------------------------------------------------------- 1 | struct CS_INPUT{ 2 | float value1; 3 | float value2; 4 | }; 5 | 6 | struct CS_OUTPUT{ 7 | float value; 8 | }; 9 | 10 | cbuffer CB : register(b0) 11 | { 12 | float offset; 13 | }; 14 | 15 | RWStructuredBuffer read : register(u0); 16 | RWStructuredBuffer write : register(u1); 17 | 18 | [numthreads(1, 1, 1)] 19 | void main(uint3 dtid : SV_DispatchThreadID) 20 | { 21 | write[dtid.x].value = read[dtid.x].value1 * read[dtid.x].value2 + offset; 22 | } -------------------------------------------------------------------------------- /src_test/Shaders/HLSL_DX12/instancing.vert: -------------------------------------------------------------------------------- 1 | struct VS_INPUT{ 2 | float3 g_position : POSITION0; 3 | float2 g_uv : UV0; 4 | float4 g_color : COLOR0; 5 | uint InstanceId : SV_InstanceID; 6 | }; 7 | struct VS_OUTPUT{ 8 | float4 g_position : SV_POSITION; 9 | float4 g_color : COLOR0; 10 | }; 11 | 12 | cbuffer CB : register(b0) 13 | { 14 | float4 offsets[10]; 15 | }; 16 | 17 | VS_OUTPUT main(VS_INPUT input){ 18 | VS_OUTPUT output; 19 | 20 | output.g_position = float4(input.g_position, 1.0f); 21 | output.g_position.x += offsets[input.InstanceId].x; 22 | output.g_position.y += offsets[input.InstanceId].y; 23 | output.g_color = input.g_color; 24 | 25 | return output; 26 | } 27 | -------------------------------------------------------------------------------- /src_test/Shaders/HLSL_DX12/readwrite.comp: -------------------------------------------------------------------------------- 1 | struct CS_INPUT{ 2 | float value1; 3 | float value2; 4 | }; 5 | 6 | struct CS_OUTPUT{ 7 | float value; 8 | }; 9 | 10 | cbuffer CB : register(b0) 11 | { 12 | float offset; 13 | }; 14 | 15 | StructuredBuffer read : register(t0); 16 | RWStructuredBuffer write : register(u1); 17 | 18 | [numthreads(1, 1, 1)] 19 | void main(uint3 dtid : SV_DispatchThreadID) 20 | { 21 | write[dtid.x].value = read[dtid.x].value1 * read[dtid.x].value2 + offset; 22 | } -------------------------------------------------------------------------------- /src_test/Shaders/HLSL_DX12/readwrite_texture.comp: -------------------------------------------------------------------------------- 1 | 2 | RWTexture2D write : register(u0); 3 | 4 | RWTexture2D read1 : register(u1); 5 | //SamplerState read_sampler : register(s1); 6 | 7 | Texture2D read2 : register(t2); 8 | SamplerState read2_sampler : register(s2); 9 | 10 | [numthreads(1, 1, 1)] 11 | void main(uint3 dtid : SV_DispatchThreadID) 12 | { 13 | uint2 index = uint2(dtid.xy); 14 | write[index] = read1[index] + read2.SampleLevel(read2_sampler, float2(0.0f, 0.0f), 0); 15 | } 16 | -------------------------------------------------------------------------------- /src_test/Shaders/HLSL_DX12/simple_compute_rectangle.frag: -------------------------------------------------------------------------------- 1 | cbuffer CB : register(b1) 2 | { 3 | float4 offset; 4 | }; 5 | 6 | StructuredBuffer compute : register(u0); 7 | 8 | struct PS_INPUT 9 | { 10 | float4 Position : SV_POSITION; 11 | float2 UV : UV0; 12 | float4 Color : COLOR0; 13 | }; 14 | 15 | float4 main(PS_INPUT input) : SV_TARGET 16 | { 17 | float4 c; 18 | c = input.Color + compute[0]; 19 | c.a = 1.0f; 20 | return c; 21 | } 22 | -------------------------------------------------------------------------------- /src_test/Shaders/HLSL_DX12/simple_compute_rectangle.vert: -------------------------------------------------------------------------------- 1 | struct VS_INPUT{ 2 | float3 Position : POSITION0; 3 | float2 UV : UV0; 4 | float4 Color : COLOR0; 5 | }; 6 | struct VS_OUTPUT{ 7 | float4 Position : SV_POSITION; 8 | float2 UV : UV0; 9 | float4 Color : COLOR0; 10 | }; 11 | 12 | StructuredBuffer compute : register(u0); 13 | 14 | VS_OUTPUT main(VS_INPUT input){ 15 | VS_OUTPUT output; 16 | 17 | output.Position = float4(input.Position, 1.0f) + compute[0]; 18 | output.UV = input.UV; 19 | output.Color = input.Color; 20 | 21 | return output; 22 | } 23 | -------------------------------------------------------------------------------- /src_test/Shaders/HLSL_DX12/simple_constant_rectangle.frag: -------------------------------------------------------------------------------- 1 | cbuffer CB : register(b1) 2 | { 3 | float4 offset; 4 | }; 5 | 6 | struct PS_INPUT 7 | { 8 | float4 Position : SV_POSITION; 9 | float2 UV : UV0; 10 | float4 Color : COLOR0; 11 | }; 12 | 13 | float4 main(PS_INPUT input) : SV_TARGET 14 | { 15 | float4 c; 16 | c = input.Color + offset; 17 | c.a = 1.0f; 18 | return c; 19 | } 20 | -------------------------------------------------------------------------------- /src_test/Shaders/HLSL_DX12/simple_constant_rectangle.vert: -------------------------------------------------------------------------------- 1 | struct VS_INPUT{ 2 | float3 Position : POSITION0; 3 | float2 UV : UV0; 4 | float4 Color : COLOR0; 5 | }; 6 | struct VS_OUTPUT{ 7 | float4 Position : SV_POSITION; 8 | float2 UV : UV0; 9 | float4 Color : COLOR0; 10 | }; 11 | 12 | 13 | cbuffer CB : register(b0) 14 | { 15 | float4 offset; 16 | }; 17 | 18 | VS_OUTPUT main(VS_INPUT input){ 19 | VS_OUTPUT output; 20 | 21 | output.Position = float4(input.Position, 1.0f) + offset; 22 | output.UV = input.UV; 23 | output.Color = input.Color; 24 | 25 | return output; 26 | } 27 | -------------------------------------------------------------------------------- /src_test/Shaders/HLSL_DX12/simple_mrt_texture_rectangle.frag: -------------------------------------------------------------------------------- 1 | Texture2D txt : register(t0); 2 | SamplerState smp : register(s0); 3 | 4 | struct PS_INPUT 5 | { 6 | float4 Position : SV_POSITION; 7 | float2 UV : UV0; 8 | float4 Color : COLOR0; 9 | }; 10 | 11 | struct PS_OUTPUT 12 | { 13 | float4 Color0 : SV_TARGET0; 14 | float4 Color1 : SV_TARGET1; 15 | }; 16 | 17 | 18 | PS_OUTPUT main(PS_INPUT input) 19 | { 20 | PS_OUTPUT output; 21 | 22 | float4 c; 23 | c = txt.Sample(smp, input.UV); 24 | c.a = 255; 25 | output.Color0 = c; 26 | 27 | c.r = 1.0f - c.r; 28 | c.g = 1.0f - c.g; 29 | c.b = 1.0f - c.b; 30 | output.Color1 = c; 31 | 32 | return output; 33 | } 34 | -------------------------------------------------------------------------------- /src_test/Shaders/HLSL_DX12/simple_rectangle.frag: -------------------------------------------------------------------------------- 1 | struct PS_INPUT{ 2 | float4 g_position : SV_POSITION; 3 | float4 g_color : COLOR0; 4 | }; 5 | 6 | float4 main(PS_INPUT input) : SV_TARGET{ 7 | return input.g_color; 8 | } 9 | -------------------------------------------------------------------------------- /src_test/Shaders/HLSL_DX12/simple_rectangle.vert: -------------------------------------------------------------------------------- 1 | struct VS_INPUT{ 2 | float3 g_position : POSITION0; 3 | float2 g_uv : UV0; 4 | float4 g_color : COLOR0; 5 | }; 6 | struct VS_OUTPUT{ 7 | float4 g_position : SV_POSITION; 8 | float4 g_color : COLOR0; 9 | }; 10 | 11 | VS_OUTPUT main(VS_INPUT input){ 12 | VS_OUTPUT output; 13 | 14 | output.g_position = float4(input.g_position, 1.0f); 15 | output.g_color = input.g_color; 16 | 17 | return output; 18 | } 19 | -------------------------------------------------------------------------------- /src_test/Shaders/HLSL_DX12/simple_texture_rectangle.frag: -------------------------------------------------------------------------------- 1 | Texture2D txt : register(t0); 2 | SamplerState smp : register(s0); 3 | 4 | struct PS_INPUT 5 | { 6 | float4 Position : SV_POSITION; 7 | float2 UV : UV0; 8 | float4 Color : COLOR0; 9 | }; 10 | 11 | float4 main(PS_INPUT input) : SV_TARGET 12 | { 13 | float4 c; 14 | c = txt.Sample(smp, input.UV); 15 | c.a = 255; 16 | return c; 17 | } 18 | -------------------------------------------------------------------------------- /src_test/Shaders/HLSL_DX12/simple_texture_rectangle.vert: -------------------------------------------------------------------------------- 1 | struct VS_INPUT{ 2 | float3 Position : POSITION0; 3 | float2 UV : UV0; 4 | float4 Color : COLOR0; 5 | }; 6 | struct VS_OUTPUT{ 7 | float4 Position : SV_POSITION; 8 | float2 UV : UV0; 9 | float4 Color : COLOR0; 10 | }; 11 | 12 | VS_OUTPUT main(VS_INPUT input){ 13 | VS_OUTPUT output; 14 | 15 | output.Position = float4(input.Position, 1.0f); 16 | output.UV = input.UV; 17 | output.Color = input.Color; 18 | 19 | return output; 20 | } 21 | -------------------------------------------------------------------------------- /src_test/Shaders/HLSL_DX12/textures.frag: -------------------------------------------------------------------------------- 1 | 2 | Texture2D g_texture1 : register(t0); 3 | SamplerState g_sampler1 : register(s0); 4 | 5 | Texture2DArray g_texture2 : register(t1); 6 | SamplerState g_sampler2 : register(s1); 7 | 8 | Texture3D g_texture3 : register(t2); 9 | SamplerState g_sampler3 : register(s2); 10 | 11 | struct PS_Input 12 | { 13 | float4 Pos : SV_POSITION; 14 | float2 UV : UV0; 15 | float4 Color : COLOR0; 16 | }; 17 | 18 | float4 main(const PS_Input Input): SV_Target 19 | { 20 | if(Input.UV.x < 0.3) 21 | { 22 | return g_texture1.Sample(g_sampler1, Input.UV); 23 | } 24 | else if(Input.UV.x < 0.6) 25 | { 26 | return g_texture2.Sample(g_sampler2, float3(Input.UV, 1)); 27 | } 28 | return g_texture3.Sample(g_sampler3, float3(Input.UV, 0.5f)); 29 | } -------------------------------------------------------------------------------- /src_test/Shaders/HLSL_DX12/vertex_structured.vert: -------------------------------------------------------------------------------- 1 | struct VS_INPUT{ 2 | float3 g_position : POSITION0; 3 | float2 g_uv : UV0; 4 | float4 g_color : COLOR0; 5 | uint InstanceId : SV_InstanceID; 6 | }; 7 | struct VS_OUTPUT{ 8 | float4 g_position : SV_POSITION; 9 | float4 g_color : COLOR0; 10 | }; 11 | 12 | struct CS_INPUT{ 13 | float value1; 14 | float value2; 15 | }; 16 | 17 | StructuredBuffer read : register(t0); 18 | 19 | VS_OUTPUT main(VS_INPUT input){ 20 | VS_OUTPUT output; 21 | 22 | output.g_position = float4(input.g_position, 1.0f); 23 | output.g_position.x += read[input.InstanceId].value1; 24 | output.g_position.y += read[input.InstanceId].value2; 25 | output.g_color = input.g_color; 26 | 27 | return output; 28 | } 29 | -------------------------------------------------------------------------------- /src_test/Shaders/HLSL_DX12/vtf.vert: -------------------------------------------------------------------------------- 1 | struct VS_INPUT{ 2 | float3 g_position : POSITION0; 3 | float2 g_uv : UV0; 4 | float4 g_color : COLOR0; 5 | }; 6 | struct VS_OUTPUT{ 7 | float4 g_position : SV_POSITION; 8 | float4 g_color : COLOR0; 9 | }; 10 | 11 | Texture2D txt : register(t0); 12 | SamplerState smp : register(s0); 13 | 14 | VS_OUTPUT main(VS_INPUT input){ 15 | VS_OUTPUT output; 16 | float4 c = txt.SampleLevel(smp, input.g_uv, 0); 17 | 18 | output.g_position = float4(input.g_position, 1.0f); 19 | output.g_position.xy += c.xy; 20 | output.g_color = input.g_color; 21 | 22 | return output; 23 | } 24 | -------------------------------------------------------------------------------- /src_test/Shaders/Metal/basic.comp: -------------------------------------------------------------------------------- 1 | #pragma clang diagnostic ignored "-Wmissing-prototypes" 2 | 3 | #include 4 | #include 5 | 6 | using namespace metal; 7 | 8 | struct CS_OUTPUT 9 | { 10 | float value; 11 | }; 12 | 13 | struct write 14 | { 15 | CS_OUTPUT _data[1]; 16 | }; 17 | 18 | struct CS_INPUT 19 | { 20 | float value1; 21 | float value2; 22 | }; 23 | 24 | struct read 25 | { 26 | CS_INPUT _data[1]; 27 | }; 28 | 29 | struct CB 30 | { 31 | float offset; 32 | }; 33 | 34 | static inline __attribute__((always_inline)) 35 | void _main(thread const uint3& dtid, device write& write_1, device read& read_1, constant CB& _43) 36 | { 37 | write_1._data[dtid.x].value = (read_1._data[dtid.x].value1 * read_1._data[dtid.x].value2) + _43.offset; 38 | } 39 | 40 | kernel void main0(constant CB& _43 [[buffer(0)]], device read& read_1 [[buffer(10)]], device write& write_1 [[buffer(11)]], uint3 gl_GlobalInvocationID [[thread_position_in_grid]]) 41 | { 42 | uint3 dtid = gl_GlobalInvocationID; 43 | uint3 param = dtid; 44 | _main(param, write_1, read_1, _43); 45 | } 46 | 47 | -------------------------------------------------------------------------------- /src_test/Shaders/Metal/instancing.vert: -------------------------------------------------------------------------------- 1 | #pragma clang diagnostic ignored "-Wmissing-prototypes" 2 | 3 | #include 4 | #include 5 | 6 | using namespace metal; 7 | 8 | struct VS_INPUT 9 | { 10 | float3 g_position; 11 | float2 g_uv; 12 | float4 g_color; 13 | uint InstanceId; 14 | }; 15 | 16 | struct VS_OUTPUT 17 | { 18 | float4 g_position; 19 | float4 g_color; 20 | }; 21 | 22 | struct CB 23 | { 24 | float4 offsets[10]; 25 | }; 26 | 27 | struct main0_out 28 | { 29 | float4 _entryPointOutput_g_color [[user(locn0)]]; 30 | float4 gl_Position [[position]]; 31 | }; 32 | 33 | struct main0_in 34 | { 35 | float3 input_g_position [[attribute(0)]]; 36 | float2 input_g_uv [[attribute(1)]]; 37 | float4 input_g_color [[attribute(2)]]; 38 | }; 39 | 40 | static inline __attribute__((always_inline)) 41 | VS_OUTPUT _main(thread const VS_INPUT& _input, constant CB& _36) 42 | { 43 | VS_OUTPUT _output; 44 | _output.g_position = float4(_input.g_position, 1.0); 45 | _output.g_position.x += _36.offsets[_input.InstanceId].x; 46 | _output.g_position.y += _36.offsets[_input.InstanceId].y; 47 | _output.g_color = _input.g_color; 48 | return _output; 49 | } 50 | 51 | vertex main0_out main0(main0_in in [[stage_in]], constant CB& _36 [[buffer(0)]], uint gl_InstanceIndex [[instance_id]]) 52 | { 53 | main0_out out = {}; 54 | VS_INPUT _input; 55 | _input.g_position = in.input_g_position; 56 | _input.g_uv = in.input_g_uv; 57 | _input.g_color = in.input_g_color; 58 | _input.InstanceId = gl_InstanceIndex; 59 | VS_INPUT param = _input; 60 | VS_OUTPUT flattenTemp = _main(param, _36); 61 | out.gl_Position = flattenTemp.g_position; 62 | out._entryPointOutput_g_color = flattenTemp.g_color; 63 | return out; 64 | } 65 | 66 | -------------------------------------------------------------------------------- /src_test/Shaders/Metal/readwrite.comp: -------------------------------------------------------------------------------- 1 | #pragma clang diagnostic ignored "-Wmissing-prototypes" 2 | 3 | #include 4 | #include 5 | 6 | using namespace metal; 7 | 8 | struct CS_OUTPUT 9 | { 10 | float value; 11 | }; 12 | 13 | struct write 14 | { 15 | CS_OUTPUT _data[1]; 16 | }; 17 | 18 | struct CS_INPUT 19 | { 20 | float value1; 21 | float value2; 22 | }; 23 | 24 | struct read 25 | { 26 | CS_INPUT _data[1]; 27 | }; 28 | 29 | struct CB 30 | { 31 | float offset; 32 | }; 33 | 34 | static inline __attribute__((always_inline)) 35 | void _main(thread const uint3& dtid, device write& write_1, const device read& read_1, constant CB& _43) 36 | { 37 | write_1._data[dtid.x].value = (read_1._data[dtid.x].value1 * read_1._data[dtid.x].value2) + _43.offset; 38 | } 39 | 40 | kernel void main0(constant CB& _43 [[buffer(0)]], const device read& read_1 [[buffer(10)]], device write& write_1 [[buffer(11)]], uint3 gl_GlobalInvocationID [[thread_position_in_grid]]) 41 | { 42 | uint3 dtid = gl_GlobalInvocationID; 43 | uint3 param = dtid; 44 | _main(param, write_1, read_1, _43); 45 | } 46 | 47 | -------------------------------------------------------------------------------- /src_test/Shaders/Metal/readwrite_texture.comp: -------------------------------------------------------------------------------- 1 | #pragma clang diagnostic ignored "-Wmissing-prototypes" 2 | 3 | #include 4 | #include 5 | 6 | using namespace metal; 7 | 8 | static inline __attribute__((always_inline)) 9 | void _main(thread const uint3& dtid, texture2d read1, texture2d read2, sampler read2_sampler, texture2d write) 10 | { 11 | uint2 index = dtid.xy; 12 | float4 storeTemp = read1.read(uint2(index)) + read2.sample(read2_sampler, float2(0.0), level(0.0)); 13 | write.write(storeTemp, uint2(index)); 14 | } 15 | 16 | kernel void main0(texture2d write [[texture(0)]], texture2d read1 [[texture(1)]], texture2d read2 [[texture(2)]], sampler read2_sampler [[sampler(2)]], uint3 gl_GlobalInvocationID [[thread_position_in_grid]]) 17 | { 18 | uint3 dtid = gl_GlobalInvocationID; 19 | uint3 param = dtid; 20 | _main(param, read1, read2, read2_sampler, write); 21 | } 22 | 23 | -------------------------------------------------------------------------------- /src_test/Shaders/Metal/simple_compute_rectangle.frag: -------------------------------------------------------------------------------- 1 | #pragma clang diagnostic ignored "-Wmissing-prototypes" 2 | 3 | #include 4 | #include 5 | 6 | using namespace metal; 7 | 8 | struct PS_INPUT 9 | { 10 | float4 Position; 11 | float2 UV; 12 | float4 Color; 13 | }; 14 | 15 | struct compute 16 | { 17 | float _data[1]; 18 | }; 19 | 20 | struct CB 21 | { 22 | float4 offset; 23 | }; 24 | 25 | struct main0_out 26 | { 27 | float4 _entryPointOutput [[color(0)]]; 28 | }; 29 | 30 | struct main0_in 31 | { 32 | float2 input_UV [[user(locn0)]]; 33 | float4 input_Color [[user(locn1)]]; 34 | }; 35 | 36 | static inline __attribute__((always_inline)) 37 | float4 _main(thread const PS_INPUT& _input, const device compute& compute0) 38 | { 39 | float4 c = _input.Color + float4(compute0._data[0]); 40 | c.w = 1.0; 41 | return c; 42 | } 43 | 44 | fragment main0_out main0(main0_in in [[stage_in]], const device compute& compute0 [[buffer(10)]], float4 gl_FragCoord [[position]]) 45 | { 46 | main0_out out = {}; 47 | PS_INPUT _input; 48 | _input.Position = gl_FragCoord; 49 | _input.UV = in.input_UV; 50 | _input.Color = in.input_Color; 51 | PS_INPUT param = _input; 52 | out._entryPointOutput = _main(param, compute0); 53 | return out; 54 | } 55 | 56 | -------------------------------------------------------------------------------- /src_test/Shaders/Metal/simple_compute_rectangle.vert: -------------------------------------------------------------------------------- 1 | #pragma clang diagnostic ignored "-Wmissing-prototypes" 2 | 3 | #include 4 | #include 5 | 6 | using namespace metal; 7 | 8 | struct VS_INPUT 9 | { 10 | float3 Position; 11 | float2 UV; 12 | float4 Color; 13 | }; 14 | 15 | struct VS_OUTPUT 16 | { 17 | float4 Position; 18 | float2 UV; 19 | float4 Color; 20 | }; 21 | 22 | struct compute 23 | { 24 | float _data[1]; 25 | }; 26 | 27 | struct main0_out 28 | { 29 | float2 _entryPointOutput_UV [[user(locn0)]]; 30 | float4 _entryPointOutput_Color [[user(locn1)]]; 31 | float4 gl_Position [[position]]; 32 | }; 33 | 34 | struct main0_in 35 | { 36 | float3 input_Position [[attribute(0)]]; 37 | float2 input_UV [[attribute(1)]]; 38 | float4 input_Color [[attribute(2)]]; 39 | }; 40 | 41 | static inline __attribute__((always_inline)) 42 | VS_OUTPUT _main(thread const VS_INPUT& _input, const device compute& compute0) 43 | { 44 | VS_OUTPUT _output; 45 | _output.Position = float4(_input.Position, 1.0) + float4(compute0._data[0]); 46 | _output.UV = _input.UV; 47 | _output.Color = _input.Color; 48 | return _output; 49 | } 50 | 51 | vertex main0_out main0(main0_in in [[stage_in]], const device compute& compute0 [[buffer(10)]]) 52 | { 53 | main0_out out = {}; 54 | VS_INPUT _input; 55 | _input.Position = in.input_Position; 56 | _input.UV = in.input_UV; 57 | _input.Color = in.input_Color; 58 | VS_INPUT param = _input; 59 | VS_OUTPUT flattenTemp = _main(param, compute0); 60 | out.gl_Position = flattenTemp.Position; 61 | out._entryPointOutput_UV = flattenTemp.UV; 62 | out._entryPointOutput_Color = flattenTemp.Color; 63 | return out; 64 | } 65 | 66 | -------------------------------------------------------------------------------- /src_test/Shaders/Metal/simple_constant_rectangle.frag: -------------------------------------------------------------------------------- 1 | #pragma clang diagnostic ignored "-Wmissing-prototypes" 2 | 3 | #include 4 | #include 5 | 6 | using namespace metal; 7 | 8 | struct PS_INPUT 9 | { 10 | float4 Position; 11 | float2 UV; 12 | float4 Color; 13 | }; 14 | 15 | struct CB 16 | { 17 | float4 offset; 18 | }; 19 | 20 | struct main0_out 21 | { 22 | float4 _entryPointOutput [[color(0)]]; 23 | }; 24 | 25 | struct main0_in 26 | { 27 | float2 input_UV [[user(locn0)]]; 28 | float4 input_Color [[user(locn1)]]; 29 | }; 30 | 31 | static inline __attribute__((always_inline)) 32 | float4 _main(thread const PS_INPUT& _input, constant CB& _23) 33 | { 34 | float4 c = _input.Color + _23.offset; 35 | c.w = 1.0; 36 | return c; 37 | } 38 | 39 | fragment main0_out main0(main0_in in [[stage_in]], constant CB& _23 [[buffer(1)]], float4 gl_FragCoord [[position]]) 40 | { 41 | main0_out out = {}; 42 | PS_INPUT _input; 43 | _input.Position = gl_FragCoord; 44 | _input.UV = in.input_UV; 45 | _input.Color = in.input_Color; 46 | PS_INPUT param = _input; 47 | out._entryPointOutput = _main(param, _23); 48 | return out; 49 | } 50 | 51 | -------------------------------------------------------------------------------- /src_test/Shaders/Metal/simple_constant_rectangle.vert: -------------------------------------------------------------------------------- 1 | #pragma clang diagnostic ignored "-Wmissing-prototypes" 2 | 3 | #include 4 | #include 5 | 6 | using namespace metal; 7 | 8 | struct VS_INPUT 9 | { 10 | float3 Position; 11 | float2 UV; 12 | float4 Color; 13 | }; 14 | 15 | struct VS_OUTPUT 16 | { 17 | float4 Position; 18 | float2 UV; 19 | float4 Color; 20 | }; 21 | 22 | struct CB 23 | { 24 | float4 offset; 25 | }; 26 | 27 | struct main0_out 28 | { 29 | float2 _entryPointOutput_UV [[user(locn0)]]; 30 | float4 _entryPointOutput_Color [[user(locn1)]]; 31 | float4 gl_Position [[position]]; 32 | }; 33 | 34 | struct main0_in 35 | { 36 | float3 input_Position [[attribute(0)]]; 37 | float2 input_UV [[attribute(1)]]; 38 | float4 input_Color [[attribute(2)]]; 39 | }; 40 | 41 | static inline __attribute__((always_inline)) 42 | VS_OUTPUT _main(thread const VS_INPUT& _input, constant CB& _31) 43 | { 44 | VS_OUTPUT _output; 45 | _output.Position = float4(_input.Position, 1.0) + _31.offset; 46 | _output.UV = _input.UV; 47 | _output.Color = _input.Color; 48 | return _output; 49 | } 50 | 51 | vertex main0_out main0(main0_in in [[stage_in]], constant CB& _31 [[buffer(0)]]) 52 | { 53 | main0_out out = {}; 54 | VS_INPUT _input; 55 | _input.Position = in.input_Position; 56 | _input.UV = in.input_UV; 57 | _input.Color = in.input_Color; 58 | VS_INPUT param = _input; 59 | VS_OUTPUT flattenTemp = _main(param, _31); 60 | out.gl_Position = flattenTemp.Position; 61 | out._entryPointOutput_UV = flattenTemp.UV; 62 | out._entryPointOutput_Color = flattenTemp.Color; 63 | return out; 64 | } 65 | 66 | -------------------------------------------------------------------------------- /src_test/Shaders/Metal/simple_mrt_texture_rectangle.frag: -------------------------------------------------------------------------------- 1 | #pragma clang diagnostic ignored "-Wmissing-prototypes" 2 | 3 | #include 4 | #include 5 | 6 | using namespace metal; 7 | 8 | struct PS_INPUT 9 | { 10 | float4 Position; 11 | float2 UV; 12 | float4 Color; 13 | }; 14 | 15 | struct PS_OUTPUT 16 | { 17 | float4 Color0; 18 | float4 Color1; 19 | }; 20 | 21 | struct main0_out 22 | { 23 | float4 _entryPointOutput_Color0 [[color(0)]]; 24 | float4 _entryPointOutput_Color1 [[color(1)]]; 25 | }; 26 | 27 | struct main0_in 28 | { 29 | float2 input_UV [[user(locn0)]]; 30 | float4 input_Color [[user(locn1)]]; 31 | }; 32 | 33 | static inline __attribute__((always_inline)) 34 | PS_OUTPUT _main(thread const PS_INPUT& _input, texture2d txt, sampler smp) 35 | { 36 | float4 c = txt.sample(smp, _input.UV); 37 | c.w = 255.0; 38 | PS_OUTPUT _output; 39 | _output.Color0 = c; 40 | c.x = 1.0 - c.x; 41 | c.y = 1.0 - c.y; 42 | c.z = 1.0 - c.z; 43 | _output.Color1 = c; 44 | return _output; 45 | } 46 | 47 | fragment main0_out main0(main0_in in [[stage_in]], texture2d txt [[texture(0)]], sampler smp [[sampler(0)]], float4 gl_FragCoord [[position]]) 48 | { 49 | main0_out out = {}; 50 | PS_INPUT _input; 51 | _input.Position = gl_FragCoord; 52 | _input.UV = in.input_UV; 53 | _input.Color = in.input_Color; 54 | PS_INPUT param = _input; 55 | PS_OUTPUT flattenTemp = _main(param, txt, smp); 56 | out._entryPointOutput_Color0 = flattenTemp.Color0; 57 | out._entryPointOutput_Color1 = flattenTemp.Color1; 58 | return out; 59 | } 60 | 61 | -------------------------------------------------------------------------------- /src_test/Shaders/Metal/simple_rectangle.frag: -------------------------------------------------------------------------------- 1 | #pragma clang diagnostic ignored "-Wmissing-prototypes" 2 | 3 | #include 4 | #include 5 | 6 | using namespace metal; 7 | 8 | struct PS_INPUT 9 | { 10 | float4 g_position; 11 | float4 g_color; 12 | }; 13 | 14 | struct main0_out 15 | { 16 | float4 _entryPointOutput [[color(0)]]; 17 | }; 18 | 19 | struct main0_in 20 | { 21 | float4 input_g_color [[user(locn0)]]; 22 | }; 23 | 24 | static inline __attribute__((always_inline)) 25 | float4 _main(thread const PS_INPUT& _input) 26 | { 27 | return _input.g_color; 28 | } 29 | 30 | fragment main0_out main0(main0_in in [[stage_in]], float4 gl_FragCoord [[position]]) 31 | { 32 | main0_out out = {}; 33 | PS_INPUT _input; 34 | _input.g_position = gl_FragCoord; 35 | _input.g_color = in.input_g_color; 36 | PS_INPUT param = _input; 37 | out._entryPointOutput = _main(param); 38 | return out; 39 | } 40 | 41 | -------------------------------------------------------------------------------- /src_test/Shaders/Metal/simple_rectangle.vert: -------------------------------------------------------------------------------- 1 | #pragma clang diagnostic ignored "-Wmissing-prototypes" 2 | 3 | #include 4 | #include 5 | 6 | using namespace metal; 7 | 8 | struct VS_INPUT 9 | { 10 | float3 g_position; 11 | float2 g_uv; 12 | float4 g_color; 13 | }; 14 | 15 | struct VS_OUTPUT 16 | { 17 | float4 g_position; 18 | float4 g_color; 19 | }; 20 | 21 | struct main0_out 22 | { 23 | float4 _entryPointOutput_g_color [[user(locn0)]]; 24 | float4 gl_Position [[position]]; 25 | }; 26 | 27 | struct main0_in 28 | { 29 | float3 input_g_position [[attribute(0)]]; 30 | float2 input_g_uv [[attribute(1)]]; 31 | float4 input_g_color [[attribute(2)]]; 32 | }; 33 | 34 | static inline __attribute__((always_inline)) 35 | VS_OUTPUT _main(thread const VS_INPUT& _input) 36 | { 37 | VS_OUTPUT _output; 38 | _output.g_position = float4(_input.g_position, 1.0); 39 | _output.g_color = _input.g_color; 40 | return _output; 41 | } 42 | 43 | vertex main0_out main0(main0_in in [[stage_in]]) 44 | { 45 | main0_out out = {}; 46 | VS_INPUT _input; 47 | _input.g_position = in.input_g_position; 48 | _input.g_uv = in.input_g_uv; 49 | _input.g_color = in.input_g_color; 50 | VS_INPUT param = _input; 51 | VS_OUTPUT flattenTemp = _main(param); 52 | out.gl_Position = flattenTemp.g_position; 53 | out._entryPointOutput_g_color = flattenTemp.g_color; 54 | return out; 55 | } 56 | 57 | -------------------------------------------------------------------------------- /src_test/Shaders/Metal/simple_texture_rectangle.frag: -------------------------------------------------------------------------------- 1 | #pragma clang diagnostic ignored "-Wmissing-prototypes" 2 | 3 | #include 4 | #include 5 | 6 | using namespace metal; 7 | 8 | struct PS_INPUT 9 | { 10 | float4 Position; 11 | float2 UV; 12 | float4 Color; 13 | }; 14 | 15 | struct main0_out 16 | { 17 | float4 _entryPointOutput [[color(0)]]; 18 | }; 19 | 20 | struct main0_in 21 | { 22 | float2 input_UV [[user(locn0)]]; 23 | float4 input_Color [[user(locn1)]]; 24 | }; 25 | 26 | static inline __attribute__((always_inline)) 27 | float4 _main(thread const PS_INPUT& _input, texture2d txt, sampler smp) 28 | { 29 | float4 c = txt.sample(smp, _input.UV); 30 | c.w = 255.0; 31 | return c; 32 | } 33 | 34 | fragment main0_out main0(main0_in in [[stage_in]], texture2d txt [[texture(0)]], sampler smp [[sampler(0)]], float4 gl_FragCoord [[position]]) 35 | { 36 | main0_out out = {}; 37 | PS_INPUT _input; 38 | _input.Position = gl_FragCoord; 39 | _input.UV = in.input_UV; 40 | _input.Color = in.input_Color; 41 | PS_INPUT param = _input; 42 | out._entryPointOutput = _main(param, txt, smp); 43 | return out; 44 | } 45 | 46 | -------------------------------------------------------------------------------- /src_test/Shaders/Metal/simple_texture_rectangle.vert: -------------------------------------------------------------------------------- 1 | #pragma clang diagnostic ignored "-Wmissing-prototypes" 2 | 3 | #include 4 | #include 5 | 6 | using namespace metal; 7 | 8 | struct VS_INPUT 9 | { 10 | float3 Position; 11 | float2 UV; 12 | float4 Color; 13 | }; 14 | 15 | struct VS_OUTPUT 16 | { 17 | float4 Position; 18 | float2 UV; 19 | float4 Color; 20 | }; 21 | 22 | struct main0_out 23 | { 24 | float2 _entryPointOutput_UV [[user(locn0)]]; 25 | float4 _entryPointOutput_Color [[user(locn1)]]; 26 | float4 gl_Position [[position]]; 27 | }; 28 | 29 | struct main0_in 30 | { 31 | float3 input_Position [[attribute(0)]]; 32 | float2 input_UV [[attribute(1)]]; 33 | float4 input_Color [[attribute(2)]]; 34 | }; 35 | 36 | static inline __attribute__((always_inline)) 37 | VS_OUTPUT _main(thread const VS_INPUT& _input) 38 | { 39 | VS_OUTPUT _output; 40 | _output.Position = float4(_input.Position, 1.0); 41 | _output.UV = _input.UV; 42 | _output.Color = _input.Color; 43 | return _output; 44 | } 45 | 46 | vertex main0_out main0(main0_in in [[stage_in]]) 47 | { 48 | main0_out out = {}; 49 | VS_INPUT _input; 50 | _input.Position = in.input_Position; 51 | _input.UV = in.input_UV; 52 | _input.Color = in.input_Color; 53 | VS_INPUT param = _input; 54 | VS_OUTPUT flattenTemp = _main(param); 55 | out.gl_Position = flattenTemp.Position; 56 | out._entryPointOutput_UV = flattenTemp.UV; 57 | out._entryPointOutput_Color = flattenTemp.Color; 58 | return out; 59 | } 60 | 61 | -------------------------------------------------------------------------------- /src_test/Shaders/Metal/textures.frag: -------------------------------------------------------------------------------- 1 | #pragma clang diagnostic ignored "-Wmissing-prototypes" 2 | 3 | #include 4 | #include 5 | 6 | using namespace metal; 7 | 8 | struct PS_Input 9 | { 10 | float4 Pos; 11 | float2 UV; 12 | float4 Color; 13 | }; 14 | 15 | struct main0_out 16 | { 17 | float4 _entryPointOutput [[color(0)]]; 18 | }; 19 | 20 | struct main0_in 21 | { 22 | float2 Input_UV [[user(locn0)]]; 23 | float4 Input_Color [[user(locn1)]]; 24 | }; 25 | 26 | static inline __attribute__((always_inline)) 27 | float4 _main(PS_Input Input, texture2d g_texture1, sampler g_sampler1, texture2d_array g_texture2, sampler g_sampler2, texture3d g_texture3, sampler g_sampler3) 28 | { 29 | if (Input.UV.x < 0.300000011920928955078125) 30 | { 31 | return g_texture1.sample(g_sampler1, Input.UV); 32 | } 33 | else 34 | { 35 | if (Input.UV.x < 0.60000002384185791015625) 36 | { 37 | float3 _56 = float3(Input.UV, 1.0); 38 | return g_texture2.sample(g_sampler2, _56.xy, uint(rint(_56.z))); 39 | } 40 | } 41 | return g_texture3.sample(g_sampler3, float3(Input.UV, 0.5)); 42 | } 43 | 44 | fragment main0_out main0(main0_in in [[stage_in]], texture2d g_texture1 [[texture(0)]], texture2d_array g_texture2 [[texture(1)]], texture3d g_texture3 [[texture(2)]], sampler g_sampler1 [[sampler(0)]], sampler g_sampler2 [[sampler(1)]], sampler g_sampler3 [[sampler(2)]], float4 gl_FragCoord [[position]]) 45 | { 46 | main0_out out = {}; 47 | PS_Input Input; 48 | Input.Pos = gl_FragCoord; 49 | Input.UV = in.Input_UV; 50 | Input.Color = in.Input_Color; 51 | out._entryPointOutput = _main(Input, g_texture1, g_sampler1, g_texture2, g_sampler2, g_texture3, g_sampler3); 52 | return out; 53 | } 54 | 55 | -------------------------------------------------------------------------------- /src_test/Shaders/Metal/vertex_structured.vert: -------------------------------------------------------------------------------- 1 | #pragma clang diagnostic ignored "-Wmissing-prototypes" 2 | 3 | #include 4 | #include 5 | 6 | using namespace metal; 7 | 8 | struct VS_INPUT 9 | { 10 | float3 g_position; 11 | float2 g_uv; 12 | float4 g_color; 13 | uint InstanceId; 14 | }; 15 | 16 | struct VS_OUTPUT 17 | { 18 | float4 g_position; 19 | float4 g_color; 20 | }; 21 | 22 | struct CS_INPUT 23 | { 24 | float value1; 25 | float value2; 26 | }; 27 | 28 | struct read 29 | { 30 | CS_INPUT _data[1]; 31 | }; 32 | 33 | struct main0_out 34 | { 35 | float4 _entryPointOutput_g_color [[user(locn0)]]; 36 | float4 gl_Position [[position]]; 37 | }; 38 | 39 | struct main0_in 40 | { 41 | float3 input_g_position [[attribute(0)]]; 42 | float2 input_g_uv [[attribute(1)]]; 43 | float4 input_g_color [[attribute(2)]]; 44 | }; 45 | 46 | static inline __attribute__((always_inline)) 47 | VS_OUTPUT _main(thread const VS_INPUT& _input, const device read& read_1) 48 | { 49 | VS_OUTPUT _output; 50 | _output.g_position = float4(_input.g_position, 1.0); 51 | _output.g_position.x += read_1._data[_input.InstanceId].value1; 52 | _output.g_position.y += read_1._data[_input.InstanceId].value2; 53 | _output.g_color = _input.g_color; 54 | return _output; 55 | } 56 | 57 | vertex main0_out main0(main0_in in [[stage_in]], const device read& read_1 [[buffer(10)]], uint gl_InstanceIndex [[instance_id]]) 58 | { 59 | main0_out out = {}; 60 | VS_INPUT _input; 61 | _input.g_position = in.input_g_position; 62 | _input.g_uv = in.input_g_uv; 63 | _input.g_color = in.input_g_color; 64 | _input.InstanceId = gl_InstanceIndex; 65 | VS_INPUT param = _input; 66 | VS_OUTPUT flattenTemp = _main(param, read_1); 67 | out.gl_Position = flattenTemp.g_position; 68 | out._entryPointOutput_g_color = flattenTemp.g_color; 69 | return out; 70 | } 71 | 72 | -------------------------------------------------------------------------------- /src_test/Shaders/Metal/vtf.vert: -------------------------------------------------------------------------------- 1 | #pragma clang diagnostic ignored "-Wmissing-prototypes" 2 | 3 | #include 4 | #include 5 | 6 | using namespace metal; 7 | 8 | struct VS_INPUT 9 | { 10 | float3 g_position; 11 | float2 g_uv; 12 | float4 g_color; 13 | }; 14 | 15 | struct VS_OUTPUT 16 | { 17 | float4 g_position; 18 | float4 g_color; 19 | }; 20 | 21 | struct main0_out 22 | { 23 | float4 _entryPointOutput_g_color [[user(locn0)]]; 24 | float4 gl_Position [[position]]; 25 | }; 26 | 27 | struct main0_in 28 | { 29 | float3 input_g_position [[attribute(0)]]; 30 | float2 input_g_uv [[attribute(1)]]; 31 | float4 input_g_color [[attribute(2)]]; 32 | }; 33 | 34 | static inline __attribute__((always_inline)) 35 | VS_OUTPUT _main(thread const VS_INPUT& _input, texture2d txt, sampler smp) 36 | { 37 | float4 c = txt.sample(smp, _input.g_uv, level(0.0)); 38 | VS_OUTPUT _output; 39 | _output.g_position = float4(_input.g_position, 1.0); 40 | float4 _51 = _output.g_position; 41 | float2 _53 = _51.xy + c.xy; 42 | _output.g_position.x = _53.x; 43 | _output.g_position.y = _53.y; 44 | _output.g_color = _input.g_color; 45 | return _output; 46 | } 47 | 48 | vertex main0_out main0(main0_in in [[stage_in]], texture2d txt [[texture(0)]], sampler smp [[sampler(0)]]) 49 | { 50 | main0_out out = {}; 51 | VS_INPUT _input; 52 | _input.g_position = in.input_g_position; 53 | _input.g_uv = in.input_g_uv; 54 | _input.g_color = in.input_g_color; 55 | VS_INPUT param = _input; 56 | VS_OUTPUT flattenTemp = _main(param, txt, smp); 57 | out.gl_Position = flattenTemp.g_position; 58 | out._entryPointOutput_g_color = flattenTemp.g_color; 59 | return out; 60 | } 61 | 62 | -------------------------------------------------------------------------------- /src_test/Shaders/SPIRV/basic.comp.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/altseed/LLGI/c3f1775b66d507d8b0b15e52cc41f13815ef45c7/src_test/Shaders/SPIRV/basic.comp.spv -------------------------------------------------------------------------------- /src_test/Shaders/SPIRV/instancing.vert.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/altseed/LLGI/c3f1775b66d507d8b0b15e52cc41f13815ef45c7/src_test/Shaders/SPIRV/instancing.vert.spv -------------------------------------------------------------------------------- /src_test/Shaders/SPIRV/readwrite.comp.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/altseed/LLGI/c3f1775b66d507d8b0b15e52cc41f13815ef45c7/src_test/Shaders/SPIRV/readwrite.comp.spv -------------------------------------------------------------------------------- /src_test/Shaders/SPIRV/readwrite_texture.comp.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/altseed/LLGI/c3f1775b66d507d8b0b15e52cc41f13815ef45c7/src_test/Shaders/SPIRV/readwrite_texture.comp.spv -------------------------------------------------------------------------------- /src_test/Shaders/SPIRV/simple_compute_rectangle.frag.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/altseed/LLGI/c3f1775b66d507d8b0b15e52cc41f13815ef45c7/src_test/Shaders/SPIRV/simple_compute_rectangle.frag.spv -------------------------------------------------------------------------------- /src_test/Shaders/SPIRV/simple_compute_rectangle.vert.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/altseed/LLGI/c3f1775b66d507d8b0b15e52cc41f13815ef45c7/src_test/Shaders/SPIRV/simple_compute_rectangle.vert.spv -------------------------------------------------------------------------------- /src_test/Shaders/SPIRV/simple_constant_rectangle.frag.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/altseed/LLGI/c3f1775b66d507d8b0b15e52cc41f13815ef45c7/src_test/Shaders/SPIRV/simple_constant_rectangle.frag.spv -------------------------------------------------------------------------------- /src_test/Shaders/SPIRV/simple_constant_rectangle.vert.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/altseed/LLGI/c3f1775b66d507d8b0b15e52cc41f13815ef45c7/src_test/Shaders/SPIRV/simple_constant_rectangle.vert.spv -------------------------------------------------------------------------------- /src_test/Shaders/SPIRV/simple_mrt_texture_rectangle.frag.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/altseed/LLGI/c3f1775b66d507d8b0b15e52cc41f13815ef45c7/src_test/Shaders/SPIRV/simple_mrt_texture_rectangle.frag.spv -------------------------------------------------------------------------------- /src_test/Shaders/SPIRV/simple_rectangle.frag.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/altseed/LLGI/c3f1775b66d507d8b0b15e52cc41f13815ef45c7/src_test/Shaders/SPIRV/simple_rectangle.frag.spv -------------------------------------------------------------------------------- /src_test/Shaders/SPIRV/simple_rectangle.vert.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/altseed/LLGI/c3f1775b66d507d8b0b15e52cc41f13815ef45c7/src_test/Shaders/SPIRV/simple_rectangle.vert.spv -------------------------------------------------------------------------------- /src_test/Shaders/SPIRV/simple_texture_rectangle.frag.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/altseed/LLGI/c3f1775b66d507d8b0b15e52cc41f13815ef45c7/src_test/Shaders/SPIRV/simple_texture_rectangle.frag.spv -------------------------------------------------------------------------------- /src_test/Shaders/SPIRV/simple_texture_rectangle.vert.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/altseed/LLGI/c3f1775b66d507d8b0b15e52cc41f13815ef45c7/src_test/Shaders/SPIRV/simple_texture_rectangle.vert.spv -------------------------------------------------------------------------------- /src_test/Shaders/SPIRV/textures.frag.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/altseed/LLGI/c3f1775b66d507d8b0b15e52cc41f13815ef45c7/src_test/Shaders/SPIRV/textures.frag.spv -------------------------------------------------------------------------------- /src_test/Shaders/SPIRV/vertex_structured.vert.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/altseed/LLGI/c3f1775b66d507d8b0b15e52cc41f13815ef45c7/src_test/Shaders/SPIRV/vertex_structured.vert.spv -------------------------------------------------------------------------------- /src_test/Shaders/SPIRV/vtf.vert.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/altseed/LLGI/c3f1775b66d507d8b0b15e52cc41f13815ef45c7/src_test/Shaders/SPIRV/vtf.vert.spv -------------------------------------------------------------------------------- /src_test/main.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "TestHelper.h" 3 | #include "test.h" 4 | #include 5 | #include 6 | 7 | #ifdef _WIN32 8 | #pragma comment(lib, "d3dcompiler.lib") 9 | 10 | #define _CRTDBG_MAP_ALLOC 11 | #include 12 | #include 13 | 14 | #endif 15 | 16 | #if defined(__linux__) || defined(__APPLE__) || defined(WIN32) 17 | 18 | int main(int argc, char* argv[]) 19 | { 20 | 21 | #if _WIN32 22 | _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); 23 | #endif 24 | 25 | auto args = TestHelper::ParseArg(argc, argv); 26 | 27 | // make shaders folder path from __FILE__ 28 | { 29 | 30 | auto path = std::string(__FILE__); 31 | #if defined(WIN32) 32 | auto pos = path.find_last_of("\\"); 33 | #else 34 | auto pos = path.find_last_of("/"); 35 | #endif 36 | 37 | path = path.substr(0, pos); 38 | 39 | if (args.Device == LLGI::DeviceType::DirectX12) 40 | { 41 | TestHelper::SetRoot((path + "/Shaders/HLSL_DX12/").c_str()); 42 | } 43 | else if (args.Device == LLGI::DeviceType::Metal) 44 | { 45 | TestHelper::SetRoot((path + "/Shaders/Metal/").c_str()); 46 | } 47 | else if (args.Device == LLGI::DeviceType::Vulkan) 48 | { 49 | #ifdef ENABLE_VULKAN_COMPILER 50 | TestHelper::SetRoot((path + "/Shaders/GLSL_VULKAN/").c_str()); 51 | #else 52 | TestHelper::SetRoot((path + "/Shaders/SPIRV/").c_str()); 53 | #endif 54 | } 55 | } 56 | 57 | LLGI::SetLogger([](LLGI::LogType logType, const std::string& message) { std::cerr << message << std::endl; }); 58 | 59 | TestHelper::SetIsCaptureRequired(true); 60 | 61 | TestHelper::Run(args); 62 | 63 | LLGI::SetLogger(nullptr); 64 | 65 | TestHelper::Dispose(); 66 | 67 | return 0; 68 | } 69 | #endif 70 | -------------------------------------------------------------------------------- /src_test/test.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | struct SimpleVertex 16 | { 17 | LLGI::Vec3F Pos; 18 | LLGI::Vec2F UV; 19 | LLGI::Color8 Color; 20 | }; 21 | 22 | struct SimpleVertexF 23 | { 24 | LLGI::Vec3F Pos; 25 | LLGI::Vec2F UV; 26 | LLGI::ColorF Color; 27 | }; 28 | -------------------------------------------------------------------------------- /src_test/test_empty.cpp: -------------------------------------------------------------------------------- 1 | #include "TestHelper.h" 2 | #include "test.h" 3 | 4 | void test_empty(LLGI::DeviceType deviceType) 5 | { 6 | int count = 0; 7 | 8 | LLGI::PlatformParameter pp; 9 | pp.Device = deviceType; 10 | pp.WaitVSync = true; 11 | auto window = std::unique_ptr(LLGI::CreateWindow("Empty", LLGI::Vec2I(1280, 720))); 12 | auto platform = LLGI::CreatePlatform(pp, window.get()); 13 | 14 | auto graphics = platform->CreateGraphics(); 15 | 16 | while (count < 60) 17 | { 18 | if (!platform->NewFrame()) 19 | break; 20 | 21 | platform->Present(); 22 | count++; 23 | } 24 | 25 | LLGI::SafeRelease(graphics); 26 | LLGI::SafeRelease(platform); 27 | } 28 | 29 | TestRegister Empty_Basic("Empty.Basic", [](LLGI::DeviceType device) -> void { test_empty(device); }); 30 | -------------------------------------------------------------------------------- /tools/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(ShaderTranspilerCore) 2 | add_subdirectory(ShaderTranspiler) 3 | install(TARGETS ShaderTranspiler DESTINATION ${CMAKE_INSTALL_BINDIR}) 4 | -------------------------------------------------------------------------------- /tools/README.md: -------------------------------------------------------------------------------- 1 | 2 | ## Debug 3 | 4 | ./ShaderTranspler --input /path/to/input --output /path/to/output (--vert/--frag/--comp) -S 5 | 6 | https://www.khronos.org/spir/visualizer/ 7 | -------------------------------------------------------------------------------- /tools/ShaderTranspiler/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0.0) 2 | project(ShaderTranspiler) 3 | 4 | add_executable(ShaderTranspiler main.cpp) 5 | 6 | target_compile_features(ShaderTranspiler PUBLIC cxx_std_17) 7 | 8 | target_include_directories(ShaderTranspiler PUBLIC ../ShaderTranspilerCore) 9 | 10 | target_link_libraries(ShaderTranspiler PUBLIC ShaderTranspilerCore) 11 | 12 | if(MSVC) 13 | target_compile_options(ShaderTranspiler PRIVATE /W4 /WX /wd4100) 14 | else() 15 | target_compile_options(ShaderTranspiler PRIVATE -Wall -Werror) 16 | endif() 17 | -------------------------------------------------------------------------------- /tools/ShaderTranspilerCore/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0.0) 2 | project(ShaderTranspilerCore) 3 | 4 | add_library( 5 | ShaderTranspilerCore STATIC ShaderTranspilerCore.cpp ShaderTranspilerCore.h) 6 | 7 | target_compile_features(ShaderTranspilerCore PUBLIC cxx_std_17) 8 | target_include_directories(ShaderTranspilerCore 9 | PUBLIC ${LLGI_THIRDPARTY_INCLUDES}) 10 | 11 | if(USE_THIRDPARTY_DIRECTORY) 12 | target_link_libraries(ShaderTranspilerCore 13 | PUBLIC ${LLGI_THIRDPARTY_LIBRARIES}) 14 | target_link_directories(ShaderTranspilerCore PUBLIC 15 | ${LLGI_THIRDPARTY_LIBRARY_DIRECTORIES}) 16 | endif() 17 | 18 | if(WIN32) 19 | # None 20 | else() 21 | find_package(Threads REQUIRED) 22 | target_link_libraries(ShaderTranspilerCore PUBLIC ${CMAKE_THREAD_LIBS_INIT} 23 | pthread) 24 | 25 | endif() 26 | 27 | if(USE_THIRDPARTY_DIRECTORY) 28 | add_dependencies(ShaderTranspilerCore EP_glslang EP_SPIRV-Cross) 29 | endif() 30 | 31 | if(MSVC) 32 | target_compile_options(ShaderTranspilerCore PRIVATE /W4 /WX /wd4100) 33 | else() 34 | target_compile_options(ShaderTranspilerCore PRIVATE -Wall -Werror) 35 | endif() 36 | 37 | if(GLSLANG_WITHOUT_INSTALL) 38 | target_compile_definitions(ShaderTranspilerCore PRIVATE ENABLE_GLSLANG_WITHOUT_INSTALL) 39 | endif() 40 | 41 | if(SPIRVCROSS_WITHOUT_INSTALL) 42 | target_compile_definitions(ShaderTranspilerCore PRIVATE ENABLE_SPIRVCROSS_WITHOUT_INSTALL) 43 | endif() 44 | --------------------------------------------------------------------------------