├── .clang-format ├── .gitattributes ├── .github └── workflows │ └── CI.yml ├── .gitignore ├── .gitmodules ├── BinaryData └── DefaultSkybox.zip ├── BoolkaCommon ├── Algorithms │ ├── Hashing.cpp │ └── Hashing.h ├── BoolkaCommon.vcxproj ├── BoolkaCommon.vcxproj.filters ├── DebugHelpers │ ├── DebugClipboardManager.cpp │ ├── DebugClipboardManager.h │ ├── DebugFileReader.cpp │ ├── DebugFileReader.h │ ├── DebugFileWriter.cpp │ ├── DebugFileWriter.h │ ├── DebugOutputStream.cpp │ ├── DebugOutputStream.h │ ├── DebugProfileTimer.cpp │ ├── DebugProfileTimer.h │ ├── DebugTimer.cpp │ └── DebugTimer.h ├── SolutionConfig.h ├── SolutionHelpers.h ├── Structures │ ├── AABB.cpp │ ├── AABB.h │ ├── Frustum.cpp │ ├── Frustum.h │ ├── Matrix.cpp │ ├── Matrix.h │ ├── MemoryBlock.h │ ├── Sphere.cpp │ ├── Sphere.h │ ├── Vector.h │ ├── VectorSSE.cpp │ └── VectorSSE.h ├── stdafx.cpp └── stdafx.h ├── BoolkaCommonUnitTests ├── BoolkaCommonUnitTests.vcxproj ├── BoolkaCommonUnitTests.vcxproj.filters ├── CommonMathHelpers.h ├── Hashing.cpp ├── Matrix.cpp ├── Vector.cpp ├── pch.cpp └── pch.h ├── BoolkaEngine.sln ├── Bootstrap ├── Application.manifest ├── Bootstrap.vcxproj ├── Bootstrap.vcxproj.filters ├── Main.cpp └── packages.config ├── D3D12Backend ├── APIWrappers │ ├── CommandAllocator │ │ ├── CommandAllocator.cpp │ │ ├── CommandAllocator.h │ │ ├── ComputeCommandAllocator.cpp │ │ ├── ComputeCommandAllocator.h │ │ ├── CopyCommandAllocator.cpp │ │ ├── CopyCommandAllocator.h │ │ ├── GraphicCommandAllocator.cpp │ │ └── GraphicCommandAllocator.h │ ├── CommandList │ │ ├── CommandList.cpp │ │ ├── CommandList.h │ │ ├── ComputeCommandList.cpp │ │ ├── ComputeCommandList.h │ │ ├── ComputeCommandListImpl.cpp │ │ ├── ComputeCommandListImpl.h │ │ ├── CopyCommandList.cpp │ │ ├── CopyCommandList.h │ │ ├── CopyCommandListImpl.cpp │ │ ├── CopyCommandListImpl.h │ │ ├── GraphicCommandList.cpp │ │ ├── GraphicCommandList.h │ │ ├── GraphicCommandListImpl.cpp │ │ └── GraphicCommandListImpl.h │ ├── CommandQueue │ │ ├── CommandQueue.cpp │ │ ├── CommandQueue.h │ │ ├── ComputeQueue.cpp │ │ ├── ComputeQueue.h │ │ ├── CopyQueue.cpp │ │ ├── CopyQueue.h │ │ ├── GraphicQueue.cpp │ │ └── GraphicQueue.h │ ├── DescriptorHeap.cpp │ ├── DescriptorHeap.h │ ├── Device.cpp │ ├── Device.h │ ├── DirectStorage │ │ ├── DStorageFactory.cpp │ │ ├── DStorageFactory.h │ │ ├── DStorageFile.cpp │ │ ├── DStorageFile.h │ │ ├── DStorageQueue.cpp │ │ └── DStorageQueue.h │ ├── Factory.cpp │ ├── Factory.h │ ├── Fence.cpp │ ├── Fence.h │ ├── InputLayout.cpp │ ├── InputLayout.h │ ├── PipelineState │ │ ├── ComputePipelineState.cpp │ │ ├── ComputePipelineState.h │ │ ├── GraphicPipelineState.cpp │ │ ├── GraphicPipelineState.h │ │ ├── PipelineState.cpp │ │ ├── PipelineState.h │ │ ├── PipelineStateParameters.h │ │ ├── StateObject.cpp │ │ ├── StateObject.h │ │ └── StateObjectParameters.h │ ├── Queries │ │ ├── QueryHeap.cpp │ │ └── QueryHeap.h │ ├── Raytracing │ │ └── AccelerationStructure │ │ │ ├── BottomLevelAS.cpp │ │ │ ├── BottomLevelAS.h │ │ │ ├── TopLevelAS.cpp │ │ │ └── TopLevelAS.h │ ├── RenderDebug.cpp │ ├── RenderDebug.h │ ├── ResourceHeap.cpp │ ├── ResourceHeap.h │ ├── Resources │ │ ├── Buffers │ │ │ ├── Buffer.cpp │ │ │ ├── Buffer.h │ │ │ ├── CommandSignature.cpp │ │ │ ├── CommandSignature.h │ │ │ ├── ReadbackBuffer.cpp │ │ │ ├── ReadbackBuffer.h │ │ │ ├── UploadBuffer.cpp │ │ │ ├── UploadBuffer.h │ │ │ └── Views │ │ │ │ ├── ConstantBufferView.cpp │ │ │ │ ├── ConstantBufferView.h │ │ │ │ ├── IndexBufferView.cpp │ │ │ │ ├── IndexBufferView.h │ │ │ │ ├── VertexBufferView.cpp │ │ │ │ └── VertexBufferView.h │ │ ├── Resource.cpp │ │ ├── Resource.h │ │ ├── ResourceTransition.cpp │ │ ├── ResourceTransition.h │ │ ├── Textures │ │ │ ├── Texture.cpp │ │ │ ├── Texture.h │ │ │ ├── Texture2D.cpp │ │ │ ├── Texture2D.h │ │ │ └── Views │ │ │ │ ├── DepthStencilView.cpp │ │ │ │ ├── DepthStencilView.h │ │ │ │ ├── RenderTargetView.cpp │ │ │ │ ├── RenderTargetView.h │ │ │ │ ├── ShaderResourceView.cpp │ │ │ │ ├── ShaderResourceView.h │ │ │ │ ├── UnorderedAccessView.cpp │ │ │ │ └── UnorderedAccessView.h │ │ ├── UAVBarrier.cpp │ │ └── UAVBarrier.h │ ├── RootSignature.cpp │ ├── RootSignature.h │ ├── Swapchain.cpp │ └── Swapchain.h ├── BatchManager.cpp ├── BatchManager.h ├── Camera.cpp ├── Camera.h ├── Containers │ ├── LightContainer.cpp │ ├── LightContainer.h │ ├── PSOContainer.cpp │ ├── PSOContainer.h │ ├── RTASContainer.cpp │ ├── RTASContainer.h │ ├── ResourceContainer.cpp │ ├── ResourceContainer.h │ ├── Scene.cpp │ ├── Scene.h │ ├── ShaderTable.cpp │ ├── ShaderTable.h │ ├── Streaming │ │ ├── SceneData.cpp │ │ ├── SceneData.h │ │ ├── SceneDataReader.cpp │ │ └── SceneDataReader.h │ ├── TimestampContainer.cpp │ └── TimestampContainer.h ├── Contexts │ ├── FrameStats.cpp │ ├── FrameStats.h │ ├── RenderContext.cpp │ ├── RenderContext.h │ ├── RenderEngineContext.cpp │ ├── RenderEngineContext.h │ ├── RenderFrameContext.cpp │ ├── RenderFrameContext.h │ ├── RenderThreadContext.cpp │ └── RenderThreadContext.h ├── D3D12Backend.vcxproj ├── D3D12Backend.vcxproj.filters ├── DebugHelpers │ ├── DebugCPUScope.cpp │ ├── DebugCPUScope.h │ ├── DebugRenderScope.cpp │ ├── DebugRenderScope.h │ ├── ImguiGraphHelper.cpp │ └── ImguiGraphHelper.h ├── FeatureSupportHelper.cpp ├── FeatureSupportHelper.h ├── HLSLShared.h ├── ProjectConfig.h ├── ProjectHelpers.h ├── RenderBackend.cpp ├── RenderBackend.h ├── RenderBackendImpl.cpp ├── RenderBackendImpl.h ├── RenderPass.h ├── RenderPasses │ ├── DebugOverlayPass.cpp │ ├── DebugOverlayPass.h │ ├── DeferredLightingPass.cpp │ ├── DeferredLightingPass.h │ ├── GBufferRenderPass.cpp │ ├── GBufferRenderPass.h │ ├── GPUCullingRenderPass.cpp │ ├── GPUCullingRenderPass.h │ ├── PresentPass.cpp │ ├── PresentPass.h │ ├── RaytraceRenderPass.cpp │ ├── RaytraceRenderPass.h │ ├── ReferenceRenderPass.cpp │ ├── ReferenceRenderPass.h │ ├── ShadowMapRenderPass.cpp │ ├── ShadowMapRenderPass.h │ ├── SkyBoxRenderPass.cpp │ ├── SkyBoxRenderPass.h │ ├── ToneMappingPass.cpp │ ├── ToneMappingPass.h │ ├── TransparentRenderPass.cpp │ ├── TransparentRenderPass.h │ ├── UpdateRenderPass.cpp │ ├── UpdateRenderPass.h │ ├── ZRenderPass.cpp │ └── ZRenderPass.h ├── RenderSchedule │ ├── RenderSchedule.cpp │ ├── RenderSchedule.h │ ├── ResourceTracker.cpp │ └── ResourceTracker.h ├── Shaders │ ├── Color.hlsli │ ├── Common.hlsli │ ├── CppShared.hlsli │ ├── CullingPass │ │ └── GPUCullingComputeShader.hlsl │ ├── Debug3DPass │ │ ├── Debug3DPassPixelShader.hlsl │ │ ├── Debug3DPassShadersCommon.hlsli │ │ └── Debug3DPassVertexShader.hlsl │ ├── DebugMeshPass │ │ ├── DebugMeshPassMeshShader.hlsl │ │ ├── DebugMeshPassPixelShader.hlsl │ │ └── DebugMeshPassShadersCommon.hlsli │ ├── DebugPass │ │ ├── DebugPassPixelShader.hlsl │ │ ├── DebugPassShadersCommon.hlsli │ │ └── DebugPassVertexShader.hlsl │ ├── DeferredLightingPass │ │ └── DeferredLightingPassPS.hlsl │ ├── FullScreen │ │ ├── FullScreenCommon.hlsli │ │ └── FullScreenVS.hlsl │ ├── GBufferPass │ │ └── GBufferPassPixelShader.hlsl │ ├── LightingLibrary │ │ └── Lighting.hlsli │ ├── MeshCommon.hlsli │ ├── MeshShaders │ │ ├── AmplificationShader.hlsl │ │ └── MeshShader.hlsl │ ├── RaytracePass │ │ └── RaytracePassLib.hlsl │ ├── ResourceBindings.hlsli │ ├── RootSig.hlsl │ ├── ShadowMapPass │ │ ├── ShadowMapAmplificationShader.hlsl │ │ └── ShadowMapPassMeshShader.hlsl │ ├── SkyBoxPass │ │ └── SkyBoxPassPixelShader.hlsl │ ├── ToneMappingPass │ │ └── ToneMappingPassPS.hlsl │ ├── TransformCommon.hlsli │ └── TransparentPass │ │ └── TransparentPassPixelShader.hlsl ├── WindowManagement │ ├── DisplayController.cpp │ ├── DisplayController.h │ ├── WindowManager.cpp │ ├── WindowManager.h │ ├── WindowState.cpp │ └── WindowState.h ├── packages.config ├── stdafx.cpp └── stdafx.h ├── HelperScripts ├── BuildAllAndRunTests.bat ├── BuildAndStartReleaseEngine.bat ├── FormatAll.ps1 ├── Internal │ ├── BuildSolution.bat │ ├── FindVisualStudioInstallation.bat │ └── RunTests.bat ├── PrepareScene.bat └── QuickStart.bat ├── LICENSE ├── OBJConverter ├── OBJConverter.cpp ├── OBJConverter.h ├── OBJConverter.vcxproj ├── OBJConverter.vcxproj.filters ├── main.cpp ├── stdafx.cpp └── stdafx.h ├── Props ├── Common.props ├── Debug.props ├── Development.props └── ThirdParty.props ├── README.md ├── Screenshot.png ├── ThirdParty ├── imgui │ ├── .editorconfig │ ├── .gitattributes │ ├── .gitignore │ ├── LICENSE.txt │ ├── backends │ │ ├── imgui_impl_allegro5.cpp │ │ ├── imgui_impl_allegro5.h │ │ ├── imgui_impl_dx10.cpp │ │ ├── imgui_impl_dx10.h │ │ ├── imgui_impl_dx11.cpp │ │ ├── imgui_impl_dx11.h │ │ ├── imgui_impl_dx12.cpp │ │ ├── imgui_impl_dx12.h │ │ ├── imgui_impl_dx9.cpp │ │ ├── imgui_impl_dx9.h │ │ ├── imgui_impl_glfw.cpp │ │ ├── imgui_impl_glfw.h │ │ ├── imgui_impl_glut.cpp │ │ ├── imgui_impl_glut.h │ │ ├── imgui_impl_marmalade.cpp │ │ ├── imgui_impl_marmalade.h │ │ ├── imgui_impl_metal.h │ │ ├── imgui_impl_metal.mm │ │ ├── imgui_impl_opengl2.cpp │ │ ├── imgui_impl_opengl2.h │ │ ├── imgui_impl_opengl3.cpp │ │ ├── imgui_impl_opengl3.h │ │ ├── imgui_impl_osx.h │ │ ├── imgui_impl_osx.mm │ │ ├── imgui_impl_sdl.cpp │ │ ├── imgui_impl_sdl.h │ │ ├── imgui_impl_vulkan.cpp │ │ ├── imgui_impl_vulkan.h │ │ ├── imgui_impl_win32.cpp │ │ ├── imgui_impl_win32.h │ │ └── vulkan │ │ │ ├── generate_spv.sh │ │ │ ├── glsl_shader.frag │ │ │ └── glsl_shader.vert │ ├── imconfig.h │ ├── imgui.cpp │ ├── imgui.h │ ├── imgui.vcxproj │ ├── imgui.vcxproj.filters │ ├── imgui_demo.cpp │ ├── imgui_draw.cpp │ ├── imgui_helper.cpp │ ├── imgui_helper.h │ ├── imgui_internal.h │ ├── imgui_tables.cpp │ ├── imgui_widgets.cpp │ ├── imstb_rectpack.h │ ├── imstb_textedit.h │ ├── imstb_truetype.h │ └── misc │ │ ├── README.txt │ │ ├── cpp │ │ ├── README.txt │ │ ├── imgui_stdlib.cpp │ │ └── imgui_stdlib.h │ │ ├── fonts │ │ ├── Cousine-Regular.ttf │ │ ├── DroidSans.ttf │ │ ├── Karla-Regular.ttf │ │ ├── ProggyClean.ttf │ │ ├── ProggyTiny.ttf │ │ ├── Roboto-Medium.ttf │ │ └── binary_to_compressed_c.cpp │ │ ├── freetype │ │ ├── README.md │ │ ├── imgui_freetype.cpp │ │ └── imgui_freetype.h │ │ ├── natvis │ │ ├── README.txt │ │ └── imgui.natvis │ │ └── single_file │ │ └── imgui_single_file.h ├── stb │ ├── stb_image.cpp │ └── stb_image.h └── tinyobjloader │ ├── LICENSE │ ├── tiny_obj_loader.cpp │ └── tiny_obj_loader.h └── vs-chromium-project.txt /.github/workflows/CI.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | 3 | on: [push] 4 | 5 | jobs: 6 | build_and_run_tests: 7 | name: Build and run tests 8 | runs-on: windows-2022 9 | steps: 10 | - name: Sync 11 | uses: actions/checkout@v2 12 | with: 13 | submodules: 'recursive' 14 | 15 | - name: Build Debug configuration 16 | working-directory: ${{env.GITHUB_WORKSPACE}} 17 | shell: cmd 18 | run: .\HelperScripts\Internal\BuildSolution.bat Debug 19 | 20 | - name: Run tests on Debug configuration 21 | working-directory: ${{env.GITHUB_WORKSPACE}} 22 | shell: cmd 23 | run: .\HelperScripts\Internal\RunTests.bat Debug 24 | 25 | - name: Build Development configuration 26 | working-directory: ${{env.GITHUB_WORKSPACE}} 27 | shell: cmd 28 | run: .\HelperScripts\Internal\BuildSolution.bat Development 29 | 30 | - name: Run tests on Development configuration 31 | working-directory: ${{env.GITHUB_WORKSPACE}} 32 | shell: cmd 33 | run: .\HelperScripts\Internal\RunTests.bat Development 34 | 35 | - name: Build Release configuration 36 | working-directory: ${{env.GITHUB_WORKSPACE}} 37 | shell: cmd 38 | run: .\HelperScripts\Internal\BuildSolution.bat Release 39 | 40 | - name: Run tests on Release configuration 41 | working-directory: ${{env.GITHUB_WORKSPACE}} 42 | shell: cmd 43 | run: .\HelperScripts\Internal\RunTests.bat Release 44 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "ThirdParty/DirectXMesh"] 2 | path = ThirdParty/DirectXMesh 3 | url = https://github.com/microsoft/DirectXMesh.git 4 | -------------------------------------------------------------------------------- /BinaryData/DefaultSkybox.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Devaniti/BoolkaEngine/338c87eebb221f3ffd5915f8e1e10d5bb2689e97/BinaryData/DefaultSkybox.zip -------------------------------------------------------------------------------- /BoolkaCommon/Algorithms/Hashing.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #include "Hashing.h" 4 | 5 | #include "Structures/MemoryBlock.h" 6 | 7 | #define BLK_CRC32_POLYNOMIAL 0xEDB88320 8 | 9 | namespace Boolka 10 | { 11 | 12 | uint32_t Hashing::CRC32(const MemoryBlock& memory) 13 | { 14 | // Can be significantly optimized 15 | const char* start = reinterpret_cast(memory.m_Data); 16 | const char* end = start + memory.m_Size; 17 | uint32_t result = 0xFFFFFFFF; 18 | 19 | for (const char* i = start; i < end; ++i) 20 | { 21 | char currentByte = *i; 22 | for (size_t j = 0; j < 8; ++j) 23 | { 24 | uint32_t bit = (currentByte ^ result) & 1; 25 | result >>= 1; 26 | result = result ^ (bit * BLK_CRC32_POLYNOMIAL); 27 | currentByte >>= 1; 28 | } 29 | } 30 | 31 | return ~result; 32 | } 33 | 34 | } // namespace Boolka 35 | -------------------------------------------------------------------------------- /BoolkaCommon/Algorithms/Hashing.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Boolka 4 | { 5 | 6 | struct MemoryBlock; 7 | 8 | class Hashing 9 | { 10 | public: 11 | [[nodiscard]] static uint32_t CRC32(const MemoryBlock& memory); 12 | }; 13 | 14 | } // namespace Boolka 15 | -------------------------------------------------------------------------------- /BoolkaCommon/DebugHelpers/DebugClipboardManager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "BoolkaCommon/Structures/MemoryBlock.h" 3 | 4 | namespace Boolka 5 | { 6 | 7 | class DebugClipboardManager 8 | { 9 | public: 10 | static void SetClipboard(const wchar_t* string); 11 | static void GetClipboard(std::wstring& string); 12 | 13 | static void SerializeToClipboard(const wchar_t* format, ...); 14 | static void DeserializeFromClipboard(const wchar_t* format, ...); 15 | 16 | private: 17 | class [[nodiscard]] ClipboardWrapper 18 | { 19 | public: 20 | ClipboardWrapper(); 21 | ~ClipboardWrapper(); 22 | 23 | void Set(const wchar_t* string); 24 | void Get(std::wstring& string); 25 | }; 26 | }; 27 | 28 | } // namespace Boolka 29 | -------------------------------------------------------------------------------- /BoolkaCommon/DebugHelpers/DebugFileReader.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #include "DebugFileReader.h" 4 | 5 | namespace Boolka 6 | { 7 | 8 | MemoryBlock DebugFileReader::ReadFile(const char* filename) 9 | { 10 | std::ifstream file(filename, std::ios::binary | std::ios::ate); 11 | if (!file) 12 | return MemoryBlock{}; 13 | return ReadFile(file); 14 | } 15 | 16 | MemoryBlock DebugFileReader::ReadFile(const wchar_t* filename) 17 | { 18 | std::ifstream file(filename, std::ios::binary | std::ios::ate); 19 | if (!file) 20 | return MemoryBlock{}; 21 | return ReadFile(file); 22 | } 23 | 24 | MemoryBlock DebugFileReader::ReadFile(std::ifstream& file) 25 | { 26 | BLK_ASSERT(file); 27 | std::streamsize size = file.tellg(); 28 | BLK_ASSERT(size >= 0); 29 | file.seekg(0, std::ios::beg); 30 | BLK_ASSERT(file); 31 | 32 | MemoryBlock blob{(void*)new char[size], static_cast(size)}; 33 | file.read((char*)blob.m_Data, size); 34 | BLK_ASSERT(file); 35 | return blob; 36 | } 37 | 38 | void DebugFileReader::FreeMemory(MemoryBlock& data) 39 | { 40 | delete[] static_cast(data.m_Data); 41 | data = {}; 42 | } 43 | 44 | } // namespace Boolka -------------------------------------------------------------------------------- /BoolkaCommon/DebugHelpers/DebugFileReader.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "BoolkaCommon/Structures/MemoryBlock.h" 3 | 4 | namespace Boolka 5 | { 6 | 7 | class DebugFileReader 8 | { 9 | public: 10 | [[nodiscard]] static MemoryBlock ReadFile(const char* filename); 11 | [[nodiscard]] static MemoryBlock ReadFile(const wchar_t* filename); 12 | [[nodiscard]] static MemoryBlock ReadFile(std::ifstream& file); 13 | static void FreeMemory(MemoryBlock& blob); 14 | }; 15 | 16 | } // namespace Boolka 17 | -------------------------------------------------------------------------------- /BoolkaCommon/DebugHelpers/DebugFileWriter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "BoolkaCommon/Structures/MemoryBlock.h" 3 | 4 | namespace Boolka 5 | { 6 | 7 | class [[nodiscard]] DebugFileWriter 8 | { 9 | public: 10 | DebugFileWriter(); 11 | ~DebugFileWriter(); 12 | 13 | bool OpenFile(const char* filename); 14 | bool OpenFile(const wchar_t* filename); 15 | bool Write(MemoryBlock memoryBlock); 16 | bool Write(const void* data, size_t size); 17 | bool AddPadding(size_t size); 18 | bool Close(size_t alignment = 0); 19 | 20 | // Compact way of writing file from single MemoryBlock 21 | static bool WriteFile(const char* filename, MemoryBlock data, size_t alignment = 0); 22 | static bool WriteFile(const wchar_t* filename, MemoryBlock data, size_t alignment = 0); 23 | 24 | private: 25 | static bool WriteFile(DebugFileWriter& fileWriter, MemoryBlock data, size_t alignment); 26 | 27 | std::ofstream m_File; 28 | size_t m_BytesWritten; 29 | }; 30 | 31 | } // namespace Boolka 32 | -------------------------------------------------------------------------------- /BoolkaCommon/DebugHelpers/DebugOutputStream.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Boolka 4 | { 5 | 6 | extern std::ostream g_DebugOutput; 7 | extern std::wostream g_WDebugOutput; 8 | 9 | } // namespace Boolka 10 | -------------------------------------------------------------------------------- /BoolkaCommon/DebugHelpers/DebugProfileTimer.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #include "DebugProfileTimer.h" 4 | 5 | #include "DebugHelpers/DebugOutputStream.h" 6 | 7 | namespace Boolka 8 | { 9 | 10 | void DebugProfileTimer::Start() 11 | { 12 | bool res = m_Timer.Start(); 13 | BLK_ASSERT_VAR(res); 14 | } 15 | 16 | void DebugProfileTimer::Stop(const wchar_t* name) 17 | { 18 | // time in ms 19 | float time = m_Timer.Stop() * 1000.0f; 20 | 21 | g_WDebugOutput << name << L" time:" << time << L"ms" << std::endl; 22 | } 23 | 24 | } // namespace Boolka 25 | -------------------------------------------------------------------------------- /BoolkaCommon/DebugHelpers/DebugProfileTimer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "BoolkaCommon/DebugHelpers/DebugTimer.h" 3 | 4 | namespace Boolka 5 | { 6 | 7 | class [[nodiscard]] DebugProfileTimer 8 | { 9 | public: 10 | void Start(); 11 | void Stop(const wchar_t* name); 12 | 13 | private: 14 | DebugTimer m_Timer; 15 | }; 16 | 17 | } // namespace Boolka 18 | -------------------------------------------------------------------------------- /BoolkaCommon/DebugHelpers/DebugTimer.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #include "DebugTimer.h" 4 | 5 | namespace Boolka 6 | { 7 | 8 | DebugTimer::DebugTimer() 9 | : m_LastTimestamp{} 10 | , m_Frequency{} 11 | { 12 | BOOL res = ::QueryPerformanceFrequency(&m_Frequency); 13 | BLK_CRITICAL_ASSERT(res); 14 | } 15 | 16 | DebugTimer::~DebugTimer() 17 | { 18 | } 19 | 20 | bool DebugTimer::Start() 21 | { 22 | BOOL res = ::QueryPerformanceCounter(&m_LastTimestamp); 23 | BLK_CRITICAL_ASSERT(res); 24 | return true; 25 | } 26 | 27 | float DebugTimer::Stop() 28 | { 29 | LARGE_INTEGER currentTimestamp; 30 | BOOL res = ::QueryPerformanceCounter(¤tTimestamp); 31 | BLK_CRITICAL_ASSERT(res); 32 | 33 | LARGE_INTEGER timestampDifference = currentTimestamp - m_LastTimestamp; 34 | 35 | return timestampDifference / m_Frequency; 36 | } 37 | 38 | } // namespace Boolka 39 | -------------------------------------------------------------------------------- /BoolkaCommon/DebugHelpers/DebugTimer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Boolka 4 | { 5 | 6 | class [[nodiscard]] DebugTimer 7 | { 8 | public: 9 | DebugTimer(); 10 | ~DebugTimer(); 11 | 12 | bool Start(); 13 | // return time in seconds 14 | float Stop(); 15 | 16 | private: 17 | LARGE_INTEGER m_LastTimestamp; 18 | LARGE_INTEGER m_Frequency; 19 | }; 20 | 21 | } // namespace Boolka 22 | -------------------------------------------------------------------------------- /BoolkaCommon/SolutionConfig.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Only defines to change different stuff in the project allowed here 4 | // Included first in ALL files 5 | 6 | #if defined(BLK_CONFIGURATION_DEBUG) || defined(BLK_CONFIGURATION_DEVELOPMENT) 7 | #define BLK_DEBUG 8 | #else 9 | #define BLK_DEBUG 10 | // No debug 11 | #endif 12 | 13 | #define BLK_ENABLE_STATS 14 | 15 | #define BLK_GAME_NAME L"Test Game" 16 | #define BLK_ENGINE_NAME L"Boolka Engine" 17 | #define BLK_IN_FLIGHT_FRAMES 2 18 | 19 | #define BLK_FILE_BLOCK_SIZE 4096 20 | 21 | // 126 is not a typo, it's reccomendation by nvidia 22 | // https://developer.nvidia.com/blog/introduction-turing-mesh-shaders/ 23 | #define BLK_MESHLET_MAX_VERTS 64 24 | #define BLK_MESHLET_MAX_PRIMS 126 25 | 26 | // Enables usage of SSE intrinsics 27 | #define BLK_USE_SSE 28 | -------------------------------------------------------------------------------- /BoolkaCommon/Structures/AABB.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #include "AABB.h" 4 | 5 | namespace Boolka 6 | { 7 | 8 | AABB::AABB(Vector4 min, Vector4 max) 9 | : m_min(min) 10 | , m_max(max) 11 | { 12 | } 13 | 14 | const Vector4& AABB::GetMin() const 15 | { 16 | return m_min; 17 | } 18 | 19 | Vector4& AABB::GetMin() 20 | { 21 | return m_min; 22 | } 23 | 24 | const Vector4& AABB::GetMax() const 25 | { 26 | return m_max; 27 | } 28 | 29 | Vector4& AABB::GetMax() 30 | { 31 | return m_max; 32 | } 33 | 34 | } // namespace Boolka 35 | -------------------------------------------------------------------------------- /BoolkaCommon/Structures/AABB.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Vector.h" 3 | 4 | namespace Boolka 5 | { 6 | 7 | class [[nodiscard]] AABB 8 | { 9 | public: 10 | AABB() = default; 11 | ~AABB() = default; 12 | 13 | AABB(Vector4 min, Vector4 max); 14 | 15 | [[nodiscard]] Vector4& GetMin(); 16 | [[nodiscard]] const Vector4& GetMin() const; 17 | [[nodiscard]] Vector4& GetMax(); 18 | [[nodiscard]] const Vector4& GetMax() const; 19 | 20 | private: 21 | Vector4 m_min; 22 | Vector4 m_max; 23 | }; 24 | 25 | } // namespace Boolka 26 | -------------------------------------------------------------------------------- /BoolkaCommon/Structures/Frustum.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Matrix.h" 3 | #include "Vector.h" 4 | 5 | namespace Boolka 6 | { 7 | 8 | class AABB; 9 | 10 | class [[nodiscard]] Frustum 11 | { 12 | public: 13 | enum TestResult 14 | { 15 | Outside = 0, 16 | Intersects = 1, 17 | Inside = 2, 18 | }; 19 | 20 | Frustum() = default; 21 | ~Frustum() = default; 22 | 23 | Frustum(const Matrix4x4& viewProj); 24 | 25 | [[nodiscard]] bool CheckPoint(const Vector4& point) const; 26 | [[nodiscard]] TestResult CheckSphere(const Vector4& center, float radius) const; 27 | [[nodiscard]] TestResult CheckAABB(const AABB& boundingBox) const; 28 | [[nodiscard]] TestResult CheckFrustum(const Matrix4x4& invViewMatrix, 29 | const Matrix4x4 invProjMatrix) const; 30 | 31 | // Fast variants return false if tested geometry is completely outside frustum, and true 32 | // otherwise 33 | // Faster since we don't need to distinguish between fully inside and intersection cases 34 | 35 | [[nodiscard]] bool CheckAABBFast(const AABB& boundingBox) const; 36 | [[nodiscard]] bool CheckSphereFast(const Vector4& center, float radius) const; 37 | [[nodiscard]] bool CheckFrustumFast(const Matrix4x4& invViewMatrix, 38 | const Matrix4x4 invProjMatrix) const; 39 | 40 | [[nodiscard]] float* GetBuffer(); 41 | [[nodiscard]] const float* GetBuffer() const; 42 | 43 | private: 44 | // 6 Planes of frustum in next order 45 | // 0 - Near 46 | // 1 - Far 47 | // 2 - Left 48 | // 3 - Right 49 | // 4 - Top 50 | // 5 - Bottom 51 | Vector4 m_planes[6]; 52 | }; 53 | 54 | } // namespace Boolka 55 | -------------------------------------------------------------------------------- /BoolkaCommon/Structures/MemoryBlock.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Boolka 4 | { 5 | 6 | struct [[nodiscard]] MemoryBlock 7 | { 8 | void* m_Data; 9 | size_t m_Size; 10 | }; 11 | 12 | } // namespace Boolka 13 | -------------------------------------------------------------------------------- /BoolkaCommon/Structures/Sphere.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Vector.h" 3 | 4 | namespace Boolka 5 | { 6 | 7 | class AABB; 8 | 9 | class [[nodiscard]] Sphere 10 | { 11 | public: 12 | Sphere() = default; 13 | ~Sphere() = default; 14 | 15 | Sphere(const Vector3& center, float radiusSqr); 16 | Sphere(const Vector4& sphere); 17 | 18 | [[nodiscard]] static Sphere BuildBoundingSphere(const Vector4* verticies, 19 | size_t vertexCount); 20 | 21 | [[nodiscard]] const Vector4& GetData(); 22 | 23 | private: 24 | // xyz - center, w - radius squared 25 | Vector4 m_Sphere; 26 | }; 27 | 28 | } // namespace Boolka 29 | -------------------------------------------------------------------------------- /BoolkaCommon/stdafx.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | -------------------------------------------------------------------------------- /BoolkaCommon/stdafx.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Careful, this header will be included in all projects precompiled headers 4 | 5 | // Solution configuration 6 | // only defines here 7 | #include "BoolkaCommon/SolutionConfig.h" 8 | 9 | // STL 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | // Windows 27 | #define WIN32_LEAN_AND_MEAN 28 | #define NOMINMAX 29 | #define NODRAWTEXT 30 | #define NOGDI 31 | #define NOMCX 32 | #define NOSERVICE 33 | #define NOHELP 34 | #include 35 | #include 36 | #include 37 | 38 | // Intrinsics 39 | #ifdef BLK_USE_SSE 40 | #include 41 | #include 42 | #endif 43 | 44 | // Own common code 45 | #include "BoolkaCommon/SolutionHelpers.h" 46 | #include "Structures/AABB.h" 47 | #include "Structures/Frustum.h" 48 | #include "Structures/Matrix.h" 49 | #include "Structures/Vector.h" 50 | 51 | #ifdef BLK_DEBUG 52 | #include "DebugHelpers/DebugOutputStream.h" 53 | #endif 54 | -------------------------------------------------------------------------------- /BoolkaCommonUnitTests/BoolkaCommonUnitTests.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /BoolkaCommonUnitTests/CommonMathHelpers.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define BLK_TEST_EPSILON (1e-5f) 4 | 5 | namespace Boolka 6 | { 7 | inline bool ApproxEqual(float a, float b, float epsilon = BLK_TEST_EPSILON) 8 | { 9 | return abs(a - b) <= epsilon; 10 | } 11 | 12 | template 13 | bool ApproxEqual(const Vector& a, const Vector& b, 14 | float epsilon = BLK_TEST_EPSILON) 15 | { 16 | for (size_t i = 0; i < componentCount; i++) 17 | { 18 | if (!ApproxEqual(a[i], b[i], epsilon)) 19 | return false; 20 | } 21 | return true; 22 | } 23 | 24 | inline bool ApproxEqual(const Matrix4x4 a, const Matrix4x4 b, float epsilon = BLK_TEST_EPSILON) 25 | { 26 | for (size_t i = 0; i < 4; i++) 27 | { 28 | if (!ApproxEqual(a[i], b[i], epsilon)) 29 | return false; 30 | } 31 | return true; 32 | } 33 | 34 | } // namespace Boolka -------------------------------------------------------------------------------- /BoolkaCommonUnitTests/pch.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | -------------------------------------------------------------------------------- /BoolkaCommonUnitTests/pch.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "BoolkaCommon/stdafx.h" 4 | 5 | #include "CommonMathHelpers.h" 6 | #include "CppUnitTest.h" 7 | 8 | using namespace Microsoft::VisualStudio::CppUnitTestFramework; 9 | -------------------------------------------------------------------------------- /Bootstrap/Application.manifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | true/pm 6 | permonitorv2,permonitor 7 | 8 | 9 | -------------------------------------------------------------------------------- /Bootstrap/Bootstrap.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Bootstrap/Main.cpp: -------------------------------------------------------------------------------- 1 | #include "BoolkaCommon/stdafx.h" 2 | 3 | #include 4 | #include 5 | 6 | #include "BoolkaCommon/DebugHelpers/DebugProfileTimer.h" 7 | #include "D3D12Backend/Containers/Streaming/SceneData.h" 8 | #include "D3D12Backend/ProjectConfig.h" 9 | #include "D3D12Backend/RenderBackend.h" 10 | 11 | int RealMain(int argc, wchar_t* argv[]) 12 | { 13 | BLK_CRITICAL_ASSERT(argc == 1); 14 | 15 | if (!SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS)) 16 | { 17 | BLK_ASSERT(0); 18 | } 19 | 20 | Boolka::DebugProfileTimer loadTimer; 21 | loadTimer.Start(); 22 | 23 | Boolka::RenderBackend* renderer = Boolka::RenderBackend::CreateRenderBackend(); 24 | bool res = renderer->Initialize(argv[0]); 25 | BLK_CRITICAL_ASSERT(res); 26 | 27 | loadTimer.Stop(L"Load"); 28 | 29 | ::GetAsyncKeyState(VK_ESCAPE); 30 | while (true) 31 | { 32 | renderer->RenderFrame(); 33 | renderer->Present(); 34 | 35 | if (::GetAsyncKeyState(VK_ESCAPE)) 36 | break; 37 | } 38 | renderer->UnloadScene(); 39 | renderer->Unload(); 40 | 41 | Boolka::RenderBackend::DeleteRenderBackend(renderer); 42 | 43 | return 0; 44 | } 45 | 46 | int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR pCmdLine, int nCmdShow) 47 | { 48 | int argc; 49 | LPWSTR* argv = ::CommandLineToArgvW(pCmdLine, &argc); 50 | return RealMain(argc, argv); 51 | } 52 | 53 | int wmain(int argc, wchar_t* argv[]) 54 | { 55 | return RealMain(argc, argv); 56 | } 57 | -------------------------------------------------------------------------------- /Bootstrap/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/CommandAllocator/CommandAllocator.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #include "CommandAllocator.h" 4 | 5 | namespace Boolka 6 | { 7 | 8 | CommandAllocator::CommandAllocator() 9 | : m_CommandAllocator(nullptr) 10 | { 11 | } 12 | 13 | CommandAllocator::~CommandAllocator() 14 | { 15 | BLK_ASSERT(m_CommandAllocator == nullptr); 16 | } 17 | 18 | bool CommandAllocator::Reset() 19 | { 20 | HRESULT hr = m_CommandAllocator->Reset(); 21 | return SUCCEEDED(hr); 22 | } 23 | 24 | ID3D12CommandAllocator* CommandAllocator::Get() 25 | { 26 | BLK_ASSERT(m_CommandAllocator != nullptr); 27 | return m_CommandAllocator; 28 | } 29 | 30 | ID3D12CommandAllocator* CommandAllocator::operator->() 31 | { 32 | return Get(); 33 | } 34 | 35 | bool CommandAllocator::Initialize(ID3D12CommandAllocator* commandAllocator) 36 | { 37 | BLK_ASSERT(m_CommandAllocator == nullptr); 38 | 39 | m_CommandAllocator = commandAllocator; 40 | return true; 41 | } 42 | 43 | void CommandAllocator::Unload() 44 | { 45 | BLK_ASSERT(m_CommandAllocator != nullptr); 46 | 47 | m_CommandAllocator->Release(); 48 | m_CommandAllocator = nullptr; 49 | } 50 | 51 | } // namespace Boolka 52 | -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/CommandAllocator/CommandAllocator.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Boolka 4 | { 5 | 6 | class [[nodiscard]] CommandAllocator 7 | { 8 | public: 9 | bool Reset(); 10 | 11 | [[nodiscard]] ID3D12CommandAllocator* Get(); 12 | [[nodiscard]] ID3D12CommandAllocator* operator->(); 13 | 14 | protected: 15 | CommandAllocator(); 16 | ~CommandAllocator(); 17 | 18 | CommandAllocator(const CommandAllocator&) = delete; 19 | CommandAllocator(CommandAllocator&&) = delete; 20 | CommandAllocator& operator=(const CommandAllocator&) = delete; 21 | CommandAllocator& operator=(CommandAllocator&&) = delete; 22 | 23 | bool Initialize(ID3D12CommandAllocator* commandAllocator); 24 | void Unload(); 25 | 26 | ID3D12CommandAllocator* m_CommandAllocator; 27 | }; 28 | 29 | } // namespace Boolka 30 | -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/CommandAllocator/ComputeCommandAllocator.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #include "ComputeCommandAllocator.h" 4 | 5 | #include "APIWrappers/Device.h" 6 | 7 | namespace Boolka 8 | { 9 | 10 | bool ComputeCommandAllocator::Initialize(Device& device) 11 | { 12 | ID3D12CommandAllocator* commandAllocator = nullptr; 13 | device->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_COMPUTE, 14 | IID_PPV_ARGS(&commandAllocator)); 15 | 16 | return CommandAllocator::Initialize(commandAllocator); 17 | } 18 | 19 | bool ComputeCommandAllocator::InitializeCommandList(ComputeCommandListImpl& commandList, 20 | Device& device, ID3D12PipelineState* PSO) 21 | { 22 | return commandList.Initialize(device, m_CommandAllocator, PSO); 23 | } 24 | 25 | bool ComputeCommandAllocator::ResetCommandList(ComputeCommandListImpl& commandList, 26 | ID3D12PipelineState* PSO) 27 | { 28 | return commandList.Reset(m_CommandAllocator, PSO); 29 | } 30 | 31 | void ComputeCommandAllocator::Unload() 32 | { 33 | CommandAllocator::Unload(); 34 | } 35 | 36 | } // namespace Boolka -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/CommandAllocator/ComputeCommandAllocator.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "APIWrappers/CommandList/ComputeCommandListImpl.h" 3 | #include "CommandAllocator.h" 4 | 5 | namespace Boolka 6 | { 7 | 8 | class [[nodiscard]] ComputeCommandAllocator : public CommandAllocator 9 | { 10 | public: 11 | ComputeCommandAllocator() = default; 12 | ~ComputeCommandAllocator() = default; 13 | 14 | bool Initialize(Device& device); 15 | void Unload(); 16 | 17 | bool InitializeCommandList(ComputeCommandListImpl& commandList, Device& device, 18 | ID3D12PipelineState* PSO); 19 | bool ResetCommandList(ComputeCommandListImpl& commandList, ID3D12PipelineState* PSO); 20 | }; 21 | 22 | } // namespace Boolka 23 | -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/CommandAllocator/CopyCommandAllocator.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #include "CopyCommandAllocator.h" 4 | 5 | #include "APIWrappers/Device.h" 6 | 7 | namespace Boolka 8 | { 9 | 10 | bool CopyCommandAllocator::Initialize(Device& device) 11 | { 12 | ID3D12CommandAllocator* commandAllocator = nullptr; 13 | device->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_COPY, 14 | IID_PPV_ARGS(&commandAllocator)); 15 | 16 | return CommandAllocator::Initialize(commandAllocator); 17 | } 18 | 19 | bool CopyCommandAllocator::InitializeCommandList(CopyCommandListImpl& commandList, 20 | Device& device, ID3D12PipelineState* PSO) 21 | { 22 | return commandList.Initialize(device, m_CommandAllocator, PSO); 23 | } 24 | 25 | bool CopyCommandAllocator::ResetCommandList(CopyCommandListImpl& commandList, 26 | ID3D12PipelineState* PSO) 27 | { 28 | return commandList.Reset(m_CommandAllocator, PSO); 29 | } 30 | 31 | void CopyCommandAllocator::Unload() 32 | { 33 | CommandAllocator::Unload(); 34 | } 35 | 36 | } // namespace Boolka -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/CommandAllocator/CopyCommandAllocator.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "APIWrappers/CommandList/CopyCommandListImpl.h" 3 | #include "CommandAllocator.h" 4 | 5 | namespace Boolka 6 | { 7 | class Device; 8 | 9 | class [[nodiscard]] CopyCommandAllocator : public CommandAllocator 10 | { 11 | public: 12 | CopyCommandAllocator() = default; 13 | ~CopyCommandAllocator() = default; 14 | 15 | bool Initialize(Device& device); 16 | void Unload(); 17 | 18 | bool InitializeCommandList(CopyCommandListImpl& commandList, Device& device, 19 | ID3D12PipelineState* PSO); 20 | bool ResetCommandList(CopyCommandListImpl& commandList, ID3D12PipelineState* PSO); 21 | }; 22 | 23 | } // namespace Boolka 24 | -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/CommandAllocator/GraphicCommandAllocator.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #include "GraphicCommandAllocator.h" 4 | 5 | #include "APIWrappers/Device.h" 6 | 7 | namespace Boolka 8 | { 9 | 10 | bool GraphicCommandAllocator::Initialize(Device& device) 11 | { 12 | ID3D12CommandAllocator* commandAllocator = nullptr; 13 | device->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, 14 | IID_PPV_ARGS(&commandAllocator)); 15 | 16 | return CommandAllocator::Initialize(commandAllocator); 17 | } 18 | 19 | bool GraphicCommandAllocator::InitializeCommandList(GraphicCommandListImpl& commandList, 20 | Device& device, ID3D12PipelineState* PSO) 21 | { 22 | return commandList.Initialize(device, m_CommandAllocator, PSO); 23 | } 24 | 25 | bool GraphicCommandAllocator::ResetCommandList(GraphicCommandListImpl& commandList, 26 | ID3D12PipelineState* PSO) 27 | { 28 | return commandList.Reset(m_CommandAllocator, PSO); 29 | } 30 | 31 | void GraphicCommandAllocator::Unload() 32 | { 33 | CommandAllocator::Unload(); 34 | } 35 | 36 | } // namespace Boolka -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/CommandAllocator/GraphicCommandAllocator.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "APIWrappers/CommandList/GraphicCommandListImpl.h" 3 | #include "CommandAllocator.h" 4 | 5 | namespace Boolka 6 | { 7 | class Device; 8 | 9 | class [[nodiscard]] GraphicCommandAllocator : public CommandAllocator 10 | { 11 | public: 12 | GraphicCommandAllocator() = default; 13 | ~GraphicCommandAllocator() = default; 14 | 15 | bool Initialize(Device& device); 16 | void Unload(); 17 | 18 | bool InitializeCommandList(GraphicCommandListImpl& commandList, Device& device, 19 | ID3D12PipelineState* PSO); 20 | bool ResetCommandList(GraphicCommandListImpl& commandList, ID3D12PipelineState* PSO); 21 | }; 22 | 23 | } // namespace Boolka 24 | -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/CommandList/CommandList.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #include "CommandList.h" 4 | 5 | namespace Boolka 6 | { 7 | 8 | CommandList::CommandList() 9 | : m_CommandList(nullptr) 10 | { 11 | } 12 | 13 | CommandList::~CommandList() 14 | { 15 | BLK_ASSERT(m_CommandList == nullptr); 16 | } 17 | 18 | bool CommandList::Initialize(ID3D12GraphicsCommandList6* commandList) 19 | { 20 | BLK_ASSERT(m_CommandList == nullptr); 21 | 22 | m_CommandList = commandList; 23 | return true; 24 | } 25 | 26 | ID3D12GraphicsCommandList6* CommandList::Get() 27 | { 28 | BLK_ASSERT(m_CommandList != nullptr); 29 | return m_CommandList; 30 | } 31 | 32 | ID3D12GraphicsCommandList6* CommandList::operator->() 33 | { 34 | return Get(); 35 | } 36 | 37 | void CommandList::Unload() 38 | { 39 | BLK_ASSERT(m_CommandList != nullptr); 40 | 41 | m_CommandList->Release(); 42 | m_CommandList = nullptr; 43 | } 44 | 45 | } // namespace Boolka -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/CommandList/CommandList.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Boolka 4 | { 5 | 6 | class [[nodiscard]] CommandList 7 | { 8 | protected: 9 | CommandList(); 10 | ~CommandList(); 11 | 12 | CommandList(const CommandList&) = delete; 13 | CommandList(CommandList&&) = delete; 14 | CommandList& operator=(const CommandList&) = delete; 15 | CommandList& operator=(CommandList&&) = delete; 16 | 17 | public: 18 | [[nodiscard]] ID3D12GraphicsCommandList6* Get(); 19 | [[nodiscard]] ID3D12GraphicsCommandList6* operator->(); 20 | 21 | void Unload(); 22 | 23 | protected: 24 | bool Initialize(ID3D12GraphicsCommandList6* commandList); 25 | 26 | ID3D12GraphicsCommandList6* m_CommandList; 27 | }; 28 | 29 | } // namespace Boolka 30 | -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/CommandList/ComputeCommandList.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #include "ComputeCommandList.h" 4 | 5 | namespace Boolka 6 | { 7 | 8 | } -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/CommandList/ComputeCommandList.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "CopyCommandList.h" 3 | 4 | namespace Boolka 5 | { 6 | 7 | class [[nodiscard]] ComputeCommandList : public CopyCommandList 8 | { 9 | protected: 10 | ComputeCommandList() = default; 11 | ~ComputeCommandList() = default; 12 | }; 13 | 14 | } // namespace Boolka 15 | -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/CommandList/ComputeCommandListImpl.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #include "ComputeCommandListImpl.h" 4 | 5 | #include "APIWrappers/Device.h" 6 | 7 | namespace Boolka 8 | { 9 | 10 | bool ComputeCommandListImpl::Initialize(Device& device, ID3D12CommandAllocator* allocator, 11 | ID3D12PipelineState* PSO) 12 | { 13 | ID3D12GraphicsCommandList6* commandList = nullptr; 14 | HRESULT hr = device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_COMPUTE, allocator, PSO, 15 | IID_PPV_ARGS(&commandList)); 16 | if (FAILED(hr)) 17 | return false; 18 | 19 | return CommandList::Initialize(commandList); 20 | } 21 | 22 | bool ComputeCommandListImpl::Reset(ID3D12CommandAllocator* allocator, ID3D12PipelineState* PSO) 23 | { 24 | HRESULT hr = m_CommandList->Reset(allocator, PSO); 25 | return SUCCEEDED(hr); 26 | } 27 | 28 | } // namespace Boolka -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/CommandList/ComputeCommandListImpl.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ComputeCommandList.h" 3 | 4 | namespace Boolka 5 | { 6 | 7 | class Device; 8 | 9 | class [[nodiscard]] ComputeCommandListImpl : public ComputeCommandList 10 | { 11 | public: 12 | ComputeCommandListImpl() = default; 13 | ~ComputeCommandListImpl() = default; 14 | 15 | bool Initialize(Device& device, ID3D12CommandAllocator* allocator, 16 | ID3D12PipelineState* PSO); 17 | bool Reset(ID3D12CommandAllocator* allocator, ID3D12PipelineState* PSO); 18 | }; 19 | 20 | } // namespace Boolka 21 | -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/CommandList/CopyCommandList.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #include "CopyCommandList.h" 4 | 5 | namespace Boolka 6 | { 7 | 8 | } -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/CommandList/CopyCommandList.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "CommandList.h" 3 | 4 | namespace Boolka 5 | { 6 | 7 | class [[nodiscard]] CopyCommandList : public CommandList 8 | { 9 | protected: 10 | CopyCommandList() = default; 11 | ~CopyCommandList() = default; 12 | }; 13 | 14 | } // namespace Boolka 15 | -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/CommandList/CopyCommandListImpl.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #include "CopyCommandListImpl.h" 4 | 5 | #include "APIWrappers/Device.h" 6 | 7 | namespace Boolka 8 | { 9 | 10 | bool CopyCommandListImpl::Initialize(Device& device, ID3D12CommandAllocator* allocator, 11 | ID3D12PipelineState* PSO) 12 | { 13 | ID3D12GraphicsCommandList6* commandList = nullptr; 14 | HRESULT hr = device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_COPY, allocator, PSO, 15 | IID_PPV_ARGS(&commandList)); 16 | if (FAILED(hr)) 17 | return false; 18 | 19 | return CommandList::Initialize(commandList); 20 | } 21 | 22 | bool CopyCommandListImpl::Reset(ID3D12CommandAllocator* allocator, ID3D12PipelineState* PSO) 23 | { 24 | HRESULT hr = m_CommandList->Reset(allocator, PSO); 25 | return SUCCEEDED(hr); 26 | } 27 | 28 | } // namespace Boolka 29 | -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/CommandList/CopyCommandListImpl.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "CopyCommandList.h" 3 | 4 | namespace Boolka 5 | { 6 | 7 | class Device; 8 | class [[nodiscard]] CopyCommandListImpl : public CopyCommandList 9 | { 10 | public: 11 | CopyCommandListImpl() = default; 12 | ~CopyCommandListImpl() = default; 13 | 14 | bool Initialize(Device& device, ID3D12CommandAllocator* allocator, 15 | ID3D12PipelineState* PSO); 16 | bool Reset(ID3D12CommandAllocator* allocator, ID3D12PipelineState* PSO); 17 | }; 18 | 19 | } // namespace Boolka 20 | -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/CommandList/GraphicCommandList.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #include "GraphicCommandList.h" 4 | 5 | namespace Boolka 6 | { 7 | 8 | } -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/CommandList/GraphicCommandList.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ComputeCommandList.h" 3 | 4 | namespace Boolka 5 | { 6 | 7 | class [[nodiscard]] GraphicCommandList : public ComputeCommandList 8 | { 9 | protected: 10 | GraphicCommandList() = default; 11 | ~GraphicCommandList() = default; 12 | }; 13 | 14 | } // namespace Boolka 15 | -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/CommandList/GraphicCommandListImpl.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #include "GraphicCommandListImpl.h" 4 | 5 | #include "APIWrappers/Device.h" 6 | 7 | namespace Boolka 8 | { 9 | 10 | bool GraphicCommandListImpl::Initialize(Device& device, ID3D12CommandAllocator* allocator, 11 | ID3D12PipelineState* PSO) 12 | { 13 | ID3D12GraphicsCommandList6* commandList = nullptr; 14 | HRESULT hr = device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, allocator, PSO, 15 | IID_PPV_ARGS(&commandList)); 16 | if (FAILED(hr)) 17 | return false; 18 | 19 | return CommandList::Initialize(commandList); 20 | } 21 | 22 | bool GraphicCommandListImpl::Reset(ID3D12CommandAllocator* allocator, ID3D12PipelineState* PSO) 23 | { 24 | HRESULT hr = m_CommandList->Reset(allocator, PSO); 25 | return SUCCEEDED(hr); 26 | } 27 | 28 | } // namespace Boolka -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/CommandList/GraphicCommandListImpl.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "GraphicCommandList.h" 3 | 4 | namespace Boolka 5 | { 6 | class Device; 7 | 8 | class [[nodiscard]] GraphicCommandListImpl : public GraphicCommandList 9 | { 10 | public: 11 | GraphicCommandListImpl() = default; 12 | ~GraphicCommandListImpl() = default; 13 | 14 | bool Initialize(Device& device, ID3D12CommandAllocator* allocator, 15 | ID3D12PipelineState* PSO); 16 | bool Reset(ID3D12CommandAllocator* allocator, ID3D12PipelineState* PSO); 17 | }; 18 | 19 | } // namespace Boolka 20 | -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/CommandQueue/CommandQueue.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #include "CommandQueue.h" 4 | 5 | #include "APIWrappers/Device.h" 6 | 7 | namespace Boolka 8 | { 9 | 10 | CommandQueue::CommandQueue() 11 | : m_Queue(nullptr) 12 | { 13 | } 14 | 15 | CommandQueue::~CommandQueue() 16 | { 17 | BLK_ASSERT(m_Queue == nullptr); 18 | } 19 | 20 | bool CommandQueue::Initialize(Device& device, ID3D12CommandQueue* queue) 21 | { 22 | BLK_ASSERT(m_Queue == nullptr); 23 | 24 | m_Queue = queue; 25 | 26 | m_Fence.Initialize(device); 27 | 28 | return true; 29 | } 30 | 31 | ID3D12CommandQueue* CommandQueue::Get() 32 | { 33 | BLK_ASSERT(m_Queue != nullptr); 34 | return m_Queue; 35 | } 36 | 37 | ID3D12CommandQueue* CommandQueue::operator->() 38 | { 39 | return Get(); 40 | } 41 | 42 | void CommandQueue::Unload() 43 | { 44 | BLK_ASSERT(m_Queue != nullptr); 45 | 46 | m_Fence.Unload(); 47 | 48 | m_Queue->Release(); 49 | m_Queue = nullptr; 50 | } 51 | 52 | UINT64 CommandQueue::SignalCPU() 53 | { 54 | return m_Fence.SignalCPU(); 55 | } 56 | 57 | UINT64 CommandQueue::SignalGPU() 58 | { 59 | return m_Fence.SignalGPU(*this); 60 | } 61 | 62 | void CommandQueue::WaitCPU(UINT64 value) 63 | { 64 | m_Fence.WaitCPU(value); 65 | } 66 | 67 | void CommandQueue::WaitGPU(UINT64 value) 68 | { 69 | m_Fence.WaitGPU(value, *this); 70 | } 71 | 72 | void CommandQueue::Flush() 73 | { 74 | UINT64 value = SignalGPU(); 75 | WaitCPU(value); 76 | } 77 | 78 | Fence& CommandQueue::GetFence() 79 | { 80 | return m_Fence; 81 | } 82 | 83 | } // namespace Boolka 84 | -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/CommandQueue/CommandQueue.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "APIWrappers/Fence.h" 4 | 5 | namespace Boolka 6 | { 7 | 8 | class Device; 9 | 10 | class [[nodiscard]] CommandQueue 11 | { 12 | public: 13 | [[nodiscard]] ID3D12CommandQueue* Get(); 14 | [[nodiscard]] ID3D12CommandQueue* operator->(); 15 | 16 | void Unload(); 17 | 18 | [[nodiscard]] UINT64 SignalCPU(); 19 | [[nodiscard]] UINT64 SignalGPU(); 20 | void WaitCPU(UINT64 value); 21 | void WaitGPU(UINT64 value); 22 | 23 | void Flush(); 24 | 25 | [[nodiscard]] Fence& GetFence(); 26 | 27 | protected: 28 | CommandQueue(); 29 | ~CommandQueue(); 30 | 31 | CommandQueue(const CommandQueue&) = delete; 32 | CommandQueue(CommandQueue&&) = delete; 33 | CommandQueue& operator=(const CommandQueue&) = delete; 34 | CommandQueue& operator=(CommandQueue&&) = delete; 35 | 36 | bool Initialize(Device& device, ID3D12CommandQueue* queue); 37 | 38 | ID3D12CommandQueue* m_Queue; 39 | Fence m_Fence; 40 | }; 41 | 42 | } // namespace Boolka 43 | -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/CommandQueue/ComputeQueue.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #include "ComputeQueue.h" 4 | 5 | #include "APIWrappers/CommandList/ComputeCommandListImpl.h" 6 | #include "APIWrappers/Device.h" 7 | 8 | namespace Boolka 9 | { 10 | 11 | bool ComputeQueue::Initialize(Device& device) 12 | { 13 | ID3D12CommandQueue* commandQueue = nullptr; 14 | D3D12_COMMAND_QUEUE_DESC desc = {}; 15 | desc.Type = D3D12_COMMAND_LIST_TYPE_COMPUTE; 16 | desc.Priority = D3D12_COMMAND_QUEUE_PRIORITY_NORMAL; 17 | desc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE; 18 | desc.NodeMask = 0; 19 | HRESULT hr = device->CreateCommandQueue(&desc, IID_PPV_ARGS(&commandQueue)); 20 | if (FAILED(hr)) 21 | return false; 22 | 23 | return CommandQueue::Initialize(device, commandQueue); 24 | } 25 | 26 | void ComputeQueue::ExecuteCommandList(ComputeCommandListImpl& commandList) 27 | { 28 | ID3D12CommandList* nativeCommandList = commandList.Get(); 29 | m_Queue->ExecuteCommandLists(1, &nativeCommandList); 30 | } 31 | 32 | } // namespace Boolka 33 | -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/CommandQueue/ComputeQueue.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "CommandQueue.h" 3 | 4 | namespace Boolka 5 | { 6 | 7 | class Device; 8 | class ComputeCommandListImpl; 9 | 10 | class [[nodiscard]] ComputeQueue : public CommandQueue 11 | { 12 | public: 13 | ComputeQueue() = default; 14 | ~ComputeQueue() = default; 15 | 16 | bool Initialize(Device& device); 17 | 18 | void ExecuteCommandList(ComputeCommandListImpl& commandList); 19 | 20 | private: 21 | }; 22 | 23 | } // namespace Boolka 24 | -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/CommandQueue/CopyQueue.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #include "CopyQueue.h" 4 | 5 | #include "APIWrappers/CommandList/CopyCommandListImpl.h" 6 | #include "APIWrappers/Device.h" 7 | 8 | namespace Boolka 9 | { 10 | 11 | bool CopyQueue::Initialize(Device& device) 12 | { 13 | ID3D12CommandQueue* commandQueue = nullptr; 14 | D3D12_COMMAND_QUEUE_DESC desc = {}; 15 | desc.Type = D3D12_COMMAND_LIST_TYPE_COPY; 16 | desc.Priority = D3D12_COMMAND_QUEUE_PRIORITY_NORMAL; 17 | desc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE; 18 | desc.NodeMask = 0; 19 | HRESULT hr = device->CreateCommandQueue(&desc, IID_PPV_ARGS(&commandQueue)); 20 | if (FAILED(hr)) 21 | return false; 22 | 23 | return CommandQueue::Initialize(device, commandQueue); 24 | } 25 | 26 | void CopyQueue::ExecuteCommandList(CopyCommandListImpl& commandList) 27 | { 28 | ID3D12CommandList* nativeCommandList = commandList.Get(); 29 | m_Queue->ExecuteCommandLists(1, &nativeCommandList); 30 | } 31 | 32 | } // namespace Boolka 33 | -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/CommandQueue/CopyQueue.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "CommandQueue.h" 3 | 4 | namespace Boolka 5 | { 6 | 7 | class Device; 8 | class CopyCommandListImpl; 9 | 10 | class [[nodiscard]] CopyQueue : public CommandQueue 11 | { 12 | public: 13 | CopyQueue() = default; 14 | ~CopyQueue() = default; 15 | 16 | bool Initialize(Device& device); 17 | 18 | void ExecuteCommandList(CopyCommandListImpl& commandList); 19 | 20 | private: 21 | }; 22 | 23 | } // namespace Boolka 24 | -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/CommandQueue/GraphicQueue.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #include "GraphicQueue.h" 4 | 5 | #include "APIWrappers/CommandList/GraphicCommandListImpl.h" 6 | #include "APIWrappers/Device.h" 7 | 8 | namespace Boolka 9 | { 10 | 11 | bool GraphicQueue::Initialize(Device& device) 12 | { 13 | ID3D12CommandQueue* commandQueue = nullptr; 14 | D3D12_COMMAND_QUEUE_DESC desc = {}; 15 | desc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT; 16 | desc.Priority = D3D12_COMMAND_QUEUE_PRIORITY_NORMAL; 17 | desc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE; 18 | desc.NodeMask = 0; 19 | HRESULT hr = device->CreateCommandQueue(&desc, IID_PPV_ARGS(&commandQueue)); 20 | if (FAILED(hr)) 21 | return false; 22 | 23 | return CommandQueue::Initialize(device, commandQueue); 24 | } 25 | 26 | void GraphicQueue::ExecuteCommandList(GraphicCommandListImpl& commandList) 27 | { 28 | ID3D12CommandList* nativeCommandList = commandList.Get(); 29 | m_Queue->ExecuteCommandLists(1, &nativeCommandList); 30 | } 31 | 32 | } // namespace Boolka 33 | -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/CommandQueue/GraphicQueue.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "CommandQueue.h" 3 | 4 | namespace Boolka 5 | { 6 | 7 | class Device; 8 | class GraphicCommandListImpl; 9 | 10 | class [[nodiscard]] GraphicQueue : public CommandQueue 11 | { 12 | public: 13 | GraphicQueue() = default; 14 | ~GraphicQueue() = default; 15 | 16 | bool Initialize(Device& device); 17 | 18 | void ExecuteCommandList(GraphicCommandListImpl& commandList); 19 | 20 | private: 21 | }; 22 | 23 | } // namespace Boolka 24 | -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/DescriptorHeap.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Boolka 4 | { 5 | 6 | class Device; 7 | 8 | class [[nodiscard]] DescriptorHeap 9 | { 10 | public: 11 | DescriptorHeap(); 12 | ~DescriptorHeap(); 13 | 14 | [[nodiscard]] ID3D12DescriptorHeap* Get(); 15 | [[nodiscard]] ID3D12DescriptorHeap* operator->(); 16 | [[nodiscard]] D3D12_CPU_DESCRIPTOR_HANDLE GetCPUHandle(UINT index) const; 17 | [[nodiscard]] D3D12_GPU_DESCRIPTOR_HANDLE GetGPUHandle(UINT index) const; 18 | 19 | bool Initialize(Device& device, UINT elementCount, D3D12_DESCRIPTOR_HEAP_TYPE heapType, 20 | D3D12_DESCRIPTOR_HEAP_FLAGS heapFlags); 21 | void Unload(); 22 | 23 | private: 24 | ID3D12DescriptorHeap* m_DescriptorHeap; 25 | UINT m_DescriptorHandleIncrementSize; 26 | D3D12_CPU_DESCRIPTOR_HANDLE m_CPUStartHandle; 27 | D3D12_GPU_DESCRIPTOR_HANDLE m_GPUStartHandle; 28 | 29 | #ifdef BLK_DEBUG 30 | UINT m_ElementCount; 31 | #endif 32 | }; 33 | 34 | } // namespace Boolka 35 | -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/DirectStorage/DStorageFactory.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #include "DStorageFactory.h" 4 | 5 | #include "Containers/Streaming/SceneData.h" 6 | 7 | namespace Boolka 8 | { 9 | 10 | DStorageFactory::DStorageFactory() 11 | : m_Factory(nullptr) 12 | { 13 | } 14 | 15 | DStorageFactory::~DStorageFactory() 16 | { 17 | BLK_ASSERT(m_Factory == nullptr); 18 | } 19 | 20 | IDStorageFactory* DStorageFactory::Get() 21 | { 22 | BLK_ASSERT(m_Factory != nullptr); 23 | return m_Factory; 24 | } 25 | 26 | IDStorageFactory* DStorageFactory::operator->() 27 | { 28 | return Get(); 29 | } 30 | 31 | bool DStorageFactory::Initialize() 32 | { 33 | BLK_ASSERT(m_Factory == nullptr); 34 | HRESULT hr = DStorageGetFactory(IID_PPV_ARGS(&m_Factory)); 35 | BLK_ASSERT(SUCCEEDED(hr)); 36 | if (FAILED(hr)) 37 | return false; 38 | 39 | #ifdef BLK_DEBUG 40 | // m_Factory->SetDebugFlags(DSTORAGE_DEBUG_SHOW_ERRORS | DSTORAGE_DEBUG_BREAK_ON_ERROR | 41 | // DSTORAGE_DEBUG_RECORD_OBJECT_NAMES); 42 | #endif 43 | 44 | m_Factory->SetStagingBufferSize(BLK_SCENE_MAX_ALLOWED_BUFFER_SIZE); 45 | return true; 46 | } 47 | 48 | void DStorageFactory::Unload() 49 | { 50 | BLK_ASSERT(m_Factory != nullptr); 51 | m_Factory->Release(); 52 | m_Factory = nullptr; 53 | } 54 | 55 | } // namespace Boolka -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/DirectStorage/DStorageFactory.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Boolka 4 | { 5 | 6 | class [[nodiscard]] DStorageFactory 7 | { 8 | public: 9 | DStorageFactory(); 10 | ~DStorageFactory(); 11 | 12 | [[nodiscard]] IDStorageFactory* Get(); 13 | [[nodiscard]] IDStorageFactory* operator->(); 14 | 15 | bool Initialize(); 16 | void Unload(); 17 | 18 | private: 19 | IDStorageFactory* m_Factory; 20 | }; 21 | 22 | } // namespace Boolka 23 | -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/DirectStorage/DStorageFile.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #include "DStorageFile.h" 4 | 5 | #include "DStorageFactory.h" 6 | 7 | namespace Boolka 8 | { 9 | 10 | DStorageFile::DStorageFile() 11 | : m_File(nullptr) 12 | { 13 | } 14 | 15 | DStorageFile::~DStorageFile() 16 | { 17 | BLK_ASSERT(m_File == nullptr); 18 | } 19 | 20 | IDStorageFile* DStorageFile::Get() 21 | { 22 | BLK_ASSERT(m_File != nullptr); 23 | return m_File; 24 | } 25 | 26 | IDStorageFile* DStorageFile::operator->() 27 | { 28 | return Get(); 29 | } 30 | 31 | bool DStorageFile::OpenFile(DStorageFactory& factory, const wchar_t* filename) 32 | { 33 | BLK_ASSERT(m_File == nullptr); 34 | HRESULT hr = factory->OpenFile(filename, IID_PPV_ARGS(&m_File)); 35 | return SUCCEEDED(hr); 36 | } 37 | 38 | void DStorageFile::CloseFile() 39 | { 40 | BLK_ASSERT(m_File != nullptr); 41 | m_File->Release(); 42 | m_File = nullptr; 43 | } 44 | 45 | } // namespace Boolka 46 | -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/DirectStorage/DStorageFile.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Boolka 4 | { 5 | 6 | class DStorageFactory; 7 | 8 | class [[nodiscard]] DStorageFile 9 | { 10 | public: 11 | DStorageFile(); 12 | ~DStorageFile(); 13 | 14 | [[nodiscard]] IDStorageFile* Get(); 15 | [[nodiscard]] IDStorageFile* operator->(); 16 | 17 | bool OpenFile(DStorageFactory& factory, const wchar_t* filename); 18 | void CloseFile(); 19 | 20 | private: 21 | IDStorageFile* m_File; 22 | }; 23 | 24 | } // namespace Boolka 25 | -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/DirectStorage/DStorageQueue.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Boolka 4 | { 5 | 6 | class Buffer; 7 | class CommandQueue; 8 | class DStorageFile; 9 | class Texture2D; 10 | struct MemoryBlock; 11 | 12 | class [[nodiscard]] DStorageQueue 13 | { 14 | public: 15 | DStorageQueue(); 16 | ~DStorageQueue(); 17 | 18 | [[nodiscard]] IDStorageQueue* Get(); 19 | [[nodiscard]] IDStorageQueue* operator->(); 20 | 21 | bool Initialize(Device& device); 22 | void Unload(); 23 | 24 | [[nodiscard]] UINT64 SignalCPU(); 25 | [[nodiscard]] UINT64 SignalDStorage(); 26 | void WaitCPU(UINT64 value); 27 | 28 | void SyncGPU(CommandQueue& commandQueue); 29 | 30 | void Flush(); 31 | 32 | [[nodiscard]] Fence& GetFence(); 33 | void EnququeRead(const MemoryBlock& memory, Buffer& buffer, size_t dstOffset = 0); 34 | void EnququeRead(DStorageFile& file, size_t srcOffset, size_t srcSize, Buffer& buffer, 35 | size_t dstOffset); 36 | void EnququeRead(DStorageFile& file, size_t srcOffset, size_t srcSize, Texture2D& texture, 37 | UINT subresourceIndex, UINT right, UINT bottom, UINT left = 0, 38 | UINT top = 0); 39 | void SubmitCommands(); 40 | 41 | private: 42 | IDStorageQueue* m_Queue; 43 | Fence m_Fence; 44 | }; 45 | 46 | } // namespace Boolka 47 | -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/Factory.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #include "Factory.h" 4 | 5 | namespace Boolka 6 | { 7 | 8 | Factory::Factory() 9 | : m_Factory(nullptr) 10 | { 11 | } 12 | 13 | Factory::~Factory() 14 | { 15 | BLK_ASSERT(m_Factory == nullptr); 16 | } 17 | 18 | IDXGIFactory7* Factory::Get() 19 | { 20 | BLK_ASSERT(m_Factory != nullptr); 21 | return m_Factory; 22 | } 23 | 24 | IDXGIFactory7* Factory::operator->() 25 | { 26 | return Get(); 27 | } 28 | 29 | bool Factory::Initialize() 30 | { 31 | BLK_ASSERT(m_Factory == nullptr); 32 | 33 | UINT flags = 0; 34 | #ifdef BLK_RENDER_DEBUG 35 | flags |= DXGI_CREATE_FACTORY_DEBUG; 36 | #endif 37 | HRESULT hr = ::CreateDXGIFactory2(flags, IID_PPV_ARGS(&m_Factory)); 38 | 39 | return SUCCEEDED(hr); 40 | } 41 | 42 | void Factory::Unload() 43 | { 44 | BLK_ASSERT(m_Factory != nullptr); 45 | 46 | m_Factory->Release(); 47 | m_Factory = nullptr; 48 | } 49 | 50 | } // namespace Boolka -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/Factory.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Boolka 4 | { 5 | 6 | class [[nodiscard]] Factory 7 | { 8 | public: 9 | Factory(); 10 | ~Factory(); 11 | 12 | [[nodiscard]] IDXGIFactory7* Get(); 13 | [[nodiscard]] IDXGIFactory7* operator->(); 14 | 15 | bool Initialize(); 16 | void Unload(); 17 | 18 | private: 19 | IDXGIFactory7* m_Factory; 20 | }; 21 | 22 | } // namespace Boolka 23 | -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/Fence.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Boolka 4 | { 5 | 6 | class Device; 7 | class CommandQueue; 8 | class DStorageQueue; 9 | 10 | class [[nodiscard]] Fence 11 | { 12 | public: 13 | Fence(); 14 | ~Fence(); 15 | 16 | bool Initialize(Device& device); 17 | void Unload(); 18 | 19 | [[nodiscard]] ID3D12Fence1* Get(); 20 | [[nodiscard]] ID3D12Fence1* operator->(); 21 | 22 | [[nodiscard]] UINT64 SignalCPU(); 23 | [[nodiscard]] UINT64 SignalGPU(CommandQueue& commandQueue); 24 | [[nodiscard]] UINT64 SignalDStorage(DStorageQueue& dstorageQueue); 25 | 26 | void SignalCPUWithValue(UINT64 value); 27 | void SignalGPUWithValue(UINT64 value, CommandQueue& commandQueue); 28 | void SignalDStorageWithValue(UINT64 value, DStorageQueue& dstorageQueue); 29 | 30 | void WaitCPU(UINT64 value); 31 | void WaitGPU(UINT64 value, CommandQueue& commandQueue); 32 | 33 | static void WaitCPUMultiple(size_t count, Fence** fences, UINT64* values); 34 | 35 | private: 36 | ID3D12Fence1* m_Fence; 37 | UINT64 m_ExpactedValue; 38 | HANDLE m_CPUEvent; 39 | }; 40 | 41 | } // namespace Boolka 42 | -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/InputLayout.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #include "InputLayout.h" 4 | 5 | namespace Boolka 6 | { 7 | 8 | InputLayout::InputLayout() 9 | : m_Header{0} 10 | , m_Entries(nullptr) 11 | , m_NativeEntries(nullptr) 12 | { 13 | } 14 | 15 | InputLayout::~InputLayout() 16 | { 17 | BLK_ASSERT(m_Header.m_NumEntries == 0); 18 | BLK_ASSERT(m_Entries == nullptr); 19 | BLK_ASSERT(m_NativeEntries == nullptr); 20 | } 21 | 22 | void InputLayout::Initialize(UINT numEntries) 23 | { 24 | BLK_ASSERT(m_Entries == nullptr); 25 | BLK_ASSERT(m_Header.m_NumEntries == 0); 26 | m_Header.m_NumEntries = numEntries; 27 | 28 | size_t size = numEntries * (sizeof(InputLayoutEntry) + sizeof(D3D12_INPUT_ELEMENT_DESC)); 29 | unsigned char* memoryBlock = new unsigned char[size]; 30 | 31 | m_Entries = reinterpret_cast(memoryBlock); 32 | m_NativeEntries = reinterpret_cast( 33 | memoryBlock + numEntries * sizeof(InputLayoutEntry)); 34 | } 35 | 36 | void InputLayout::Unload() 37 | { 38 | delete[] m_Entries; 39 | m_Entries = nullptr; 40 | m_NativeEntries = nullptr; 41 | m_Header.m_NumEntries = 0; 42 | } 43 | 44 | void InputLayout::SetEntry(size_t index, const D3D12_INPUT_ELEMENT_DESC& desc) 45 | { 46 | m_NativeEntries[index] = desc; 47 | BLK_ASSERT(strlen(desc.SemanticName) < ARRAYSIZE(m_Entries[index].SemanticName)); 48 | strcpy_s(m_Entries[index].SemanticName, desc.SemanticName); 49 | } 50 | 51 | void InputLayout::FillInputLayoutDesc(D3D12_INPUT_LAYOUT_DESC& desc) const 52 | { 53 | desc.NumElements = m_Header.m_NumEntries; 54 | desc.pInputElementDescs = m_NativeEntries; 55 | } 56 | 57 | } // namespace Boolka 58 | -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/InputLayout.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Boolka 4 | { 5 | 6 | class [[nodiscard]] InputLayout 7 | { 8 | public: 9 | InputLayout(); 10 | ~InputLayout(); 11 | 12 | void Initialize(UINT numEntries); 13 | void Unload(); 14 | 15 | void SetEntry(size_t index, const D3D12_INPUT_ELEMENT_DESC& desc); 16 | 17 | struct [[nodiscard]] InputLayoutHeader 18 | { 19 | UINT m_NumEntries; 20 | }; 21 | 22 | struct [[nodiscard]] InputLayoutEntry 23 | { 24 | char SemanticName[BLK_D3D12_SEMANTIC_MAX_LENGTH]; 25 | }; 26 | 27 | BLK_IS_PLAIN_DATA_ASSERT(InputLayoutHeader); 28 | BLK_IS_PLAIN_DATA_ASSERT(InputLayoutEntry); 29 | BLK_IS_PLAIN_DATA_ASSERT(D3D12_INPUT_ELEMENT_DESC); 30 | 31 | void FillInputLayoutDesc(D3D12_INPUT_LAYOUT_DESC& desc) const; 32 | 33 | private: 34 | InputLayoutHeader m_Header; 35 | InputLayoutEntry* m_Entries; 36 | D3D12_INPUT_ELEMENT_DESC* m_NativeEntries; 37 | }; 38 | 39 | } // namespace Boolka 40 | -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/PipelineState/ComputePipelineState.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #include "ComputePipelineState.h" 4 | 5 | #include "APIWrappers/Device.h" 6 | #include "APIWrappers/RootSignature.h" 7 | 8 | namespace Boolka 9 | { 10 | 11 | bool ComputePipelineState::Initialize(Device& device, const wchar_t* name, 12 | RootSignature& rootSig, 13 | const MemoryBlock& computeShaderBytecode) 14 | { 15 | ID3D12PipelineState* state = nullptr; 16 | D3D12_COMPUTE_PIPELINE_STATE_DESC desc = {}; 17 | 18 | desc.pRootSignature = rootSig.Get(); 19 | desc.CS = D3D12_SHADER_BYTECODE{computeShaderBytecode.m_Data, computeShaderBytecode.m_Size}; 20 | 21 | HRESULT hr; 22 | 23 | hr = device->CreateComputePipelineState(&desc, IID_PPV_ARGS(&state)); 24 | if (FAILED(hr)) 25 | return false; 26 | 27 | RenderDebug::SetDebugName(state, L"%ls", name); 28 | PipelineState::Initialize(state); 29 | 30 | return true; 31 | } 32 | 33 | } // namespace Boolka 34 | -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/PipelineState/ComputePipelineState.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "BoolkaCommon/Structures/MemoryBlock.h" 3 | #include "PipelineState.h" 4 | 5 | namespace Boolka 6 | { 7 | class Device; 8 | class RootSignature; 9 | 10 | class [[nodiscard]] ComputePipelineState : public PipelineState 11 | { 12 | public: 13 | ComputePipelineState() = default; 14 | ~ComputePipelineState() = default; 15 | 16 | bool Initialize(Device& device, const wchar_t* name, RootSignature& rootSig, 17 | const MemoryBlock& computeShaderBytecode); 18 | }; 19 | 20 | } // namespace Boolka 21 | -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/PipelineState/GraphicPipelineState.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #include "GraphicPipelineState.h" 4 | 5 | #include "APIWrappers/Device.h" 6 | #include "APIWrappers/InputLayout.h" 7 | #include "APIWrappers/RootSignature.h" 8 | 9 | namespace Boolka 10 | { 11 | 12 | bool GraphicPipelineState::InitializeInternal( 13 | Device& device, const wchar_t* name, const D3D12_PIPELINE_STATE_STREAM_DESC& streamDesc) 14 | { 15 | ID3D12PipelineState* state = nullptr; 16 | HRESULT hr; 17 | 18 | hr = device->CreatePipelineState(&streamDesc, IID_PPV_ARGS(&state)); 19 | BLK_ASSERT(SUCCEEDED(hr)); 20 | if (FAILED(hr)) 21 | return false; 22 | 23 | RenderDebug::SetDebugName(state, L"%ls", name); 24 | PipelineState::Initialize(state); 25 | 26 | return true; 27 | } 28 | 29 | } // namespace Boolka -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/PipelineState/PipelineState.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #include "PipelineState.h" 4 | 5 | namespace Boolka 6 | { 7 | 8 | PipelineState::PipelineState() 9 | : m_PipelineState(nullptr) 10 | { 11 | } 12 | 13 | PipelineState::~PipelineState() 14 | { 15 | BLK_ASSERT(m_PipelineState == nullptr); 16 | } 17 | 18 | void PipelineState::Initialize(ID3D12PipelineState* pipelineState) 19 | { 20 | BLK_ASSERT(m_PipelineState == nullptr); 21 | m_PipelineState = pipelineState; 22 | } 23 | 24 | ID3D12PipelineState* PipelineState::Get() 25 | { 26 | BLK_ASSERT(m_PipelineState != nullptr); 27 | return m_PipelineState; 28 | } 29 | 30 | ID3D12PipelineState* PipelineState::operator->() 31 | { 32 | return Get(); 33 | } 34 | 35 | void PipelineState::Unload() 36 | { 37 | BLK_ASSERT(m_PipelineState != nullptr); 38 | 39 | m_PipelineState->Release(); 40 | m_PipelineState = nullptr; 41 | } 42 | 43 | } // namespace Boolka -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/PipelineState/PipelineState.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Boolka 4 | { 5 | 6 | class [[nodiscard]] PipelineState 7 | { 8 | protected: 9 | PipelineState(); 10 | ~PipelineState(); 11 | 12 | void Initialize(ID3D12PipelineState* pipelineState); 13 | 14 | public: 15 | [[nodiscard]] ID3D12PipelineState* Get(); 16 | [[nodiscard]] ID3D12PipelineState* operator->(); 17 | 18 | void Unload(); 19 | 20 | private: 21 | ID3D12PipelineState* m_PipelineState; 22 | }; 23 | 24 | } // namespace Boolka 25 | -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/PipelineState/StateObject.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #include "StateObject.h" 4 | 5 | #include "APIWrappers/Device.h" 6 | #include "BoolkaCommon/DebugHelpers/DebugProfileTimer.h" 7 | 8 | namespace Boolka 9 | { 10 | 11 | StateObject::StateObject() 12 | : m_StateObject(nullptr) 13 | { 14 | } 15 | 16 | StateObject::~StateObject() 17 | { 18 | BLK_ASSERT(m_StateObject == nullptr); 19 | } 20 | 21 | ID3D12StateObject* StateObject::Get() 22 | { 23 | BLK_ASSERT(m_StateObject != nullptr); 24 | return m_StateObject; 25 | } 26 | 27 | ID3D12StateObject* StateObject::operator->() 28 | { 29 | return Get(); 30 | } 31 | 32 | void StateObject::Unload() 33 | { 34 | BLK_ASSERT(m_StateObject != nullptr); 35 | 36 | m_StateObject->Release(); 37 | m_StateObject = nullptr; 38 | } 39 | 40 | void StateObject::SafeUnload() 41 | { 42 | BLK_SAFE_RELEASE(m_StateObject); 43 | } 44 | 45 | bool StateObject::InitializeInternal(Device& device, const wchar_t* name, 46 | const D3D12_STATE_OBJECT_DESC& desc) 47 | { 48 | BLK_CPU_SCOPE("StateObject::InitializeInternal"); 49 | 50 | HRESULT hr = device->CreateStateObject(&desc, IID_PPV_ARGS(&m_StateObject)); 51 | BLK_ASSERT(SUCCEEDED(hr)); 52 | if (FAILED(hr)) 53 | return false; 54 | 55 | RenderDebug::SetDebugName(m_StateObject, L"%ls", name); 56 | 57 | return true; 58 | } 59 | 60 | } // namespace Boolka -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/PipelineState/StateObject.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "APIWrappers/PipelineState/StateObjectParameters.h" 3 | 4 | namespace Boolka 5 | { 6 | class Device; 7 | class RootSignature; 8 | 9 | class [[nodiscard]] StateObject 10 | { 11 | public: 12 | StateObject(); 13 | ~StateObject(); 14 | 15 | ID3D12StateObject* Get(); 16 | ID3D12StateObject* operator->(); 17 | 18 | template 19 | bool Initialize(Device& device, const wchar_t* name, const Args&... args) 20 | { 21 | D3D12_STATE_SUBOBJECT subobjects[sizeof...(Args)]; 22 | 23 | StateObjectStream stateObjectStream(subobjects, args...); 24 | 25 | D3D12_STATE_OBJECT_DESC desc; 26 | desc.Type = D3D12_STATE_OBJECT_TYPE_RAYTRACING_PIPELINE; 27 | desc.NumSubobjects = sizeof...(Args); 28 | desc.pSubobjects = subobjects; 29 | return InitializeInternal(device, name, desc); 30 | }; 31 | 32 | void Unload(); 33 | void SafeUnload(); 34 | 35 | private: 36 | bool InitializeInternal(Device& device, const wchar_t* name, 37 | const D3D12_STATE_OBJECT_DESC& desc); 38 | 39 | ID3D12StateObject* m_StateObject; 40 | }; 41 | 42 | } // namespace Boolka 43 | -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/Queries/QueryHeap.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #include "QueryHeap.h" 4 | 5 | #include "APIWrappers/Device.h" 6 | 7 | namespace Boolka 8 | { 9 | 10 | QueryHeap::QueryHeap() 11 | : m_Heap(nullptr) 12 | { 13 | } 14 | 15 | QueryHeap::~QueryHeap() 16 | { 17 | BLK_ASSERT(m_Heap == nullptr); 18 | } 19 | 20 | ID3D12QueryHeap* QueryHeap::Get() 21 | { 22 | BLK_ASSERT(m_Heap != nullptr); 23 | return m_Heap; 24 | } 25 | 26 | ID3D12QueryHeap* QueryHeap::operator->() 27 | { 28 | return Get(); 29 | } 30 | 31 | bool QueryHeap::Initialize(Device& device, D3D12_QUERY_HEAP_TYPE heapType, UINT elementCount) 32 | { 33 | BLK_ASSERT(m_Heap == nullptr); 34 | 35 | D3D12_QUERY_HEAP_DESC desc{}; 36 | desc.Type = heapType; 37 | desc.Count = elementCount; 38 | HRESULT hr = device->CreateQueryHeap(&desc, IID_PPV_ARGS(&m_Heap)); 39 | BLK_ASSERT(SUCCEEDED(hr)); 40 | return SUCCEEDED(hr); 41 | } 42 | 43 | void QueryHeap::Unload() 44 | { 45 | BLK_ASSERT(m_Heap != nullptr) 46 | 47 | m_Heap->Release(); 48 | m_Heap = nullptr; 49 | } 50 | 51 | } // namespace Boolka 52 | -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/Queries/QueryHeap.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Boolka 4 | { 5 | 6 | class [[nodiscard]] QueryHeap 7 | { 8 | public: 9 | QueryHeap(); 10 | ~QueryHeap(); 11 | 12 | [[nodiscard]] ID3D12QueryHeap* Get(); 13 | [[nodiscard]] ID3D12QueryHeap* operator->(); 14 | 15 | bool Initialize(Device& device, D3D12_QUERY_HEAP_TYPE heapType, UINT elementCount); 16 | void Unload(); 17 | 18 | private: 19 | ID3D12QueryHeap* m_Heap; 20 | }; 21 | 22 | } // namespace Boolka 23 | -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/Raytracing/AccelerationStructure/BottomLevelAS.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Boolka 4 | { 5 | 6 | class Device; 7 | 8 | class BottomLevelAS 9 | { 10 | public: 11 | static void GetSizes(Device& device, UINT vertexCount, UINT vertexStride, UINT indexCount, 12 | UINT64& outScratchSize, UINT64& outBLASSize); 13 | static void Initialize(ComputeCommandList& commandList, 14 | D3D12_GPU_VIRTUAL_ADDRESS destination, 15 | D3D12_GPU_VIRTUAL_ADDRESS scratchBuffer, 16 | D3D12_GPU_VIRTUAL_ADDRESS vertexBuffer, UINT vertexCount, 17 | UINT vertexStride, D3D12_GPU_VIRTUAL_ADDRESS indexBuffer, 18 | UINT indexCount, 19 | D3D12_GPU_VIRTUAL_ADDRESS postBuildDataBuffer = NULL); 20 | }; 21 | 22 | } // namespace Boolka 23 | -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/Raytracing/AccelerationStructure/TopLevelAS.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Boolka 4 | { 5 | 6 | class Device; 7 | 8 | class TopLevelAS 9 | { 10 | public: 11 | static void GetSizes(Device& device, UINT blasInstanceCount, UINT64& outScratchSize, 12 | UINT64& outTLASSize); 13 | static void Initialize(ComputeCommandList& commandList, 14 | D3D12_GPU_VIRTUAL_ADDRESS destination, 15 | D3D12_GPU_VIRTUAL_ADDRESS scratchBuffer, 16 | D3D12_GPU_VIRTUAL_ADDRESS blasInstances, UINT instanceCount); 17 | }; 18 | 19 | } // namespace Boolka 20 | -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/RenderDebug.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Boolka 4 | 5 | { 6 | 7 | class [[nodiscard]] RenderDebug 8 | { 9 | public: 10 | RenderDebug() = default; 11 | ~RenderDebug() = default; 12 | 13 | bool Initialize(); 14 | void Unload(); 15 | 16 | #ifdef BLK_RENDER_DEBUG 17 | static void SetDebugName(ID3D12DeviceChild* object, const wchar_t* format, ...); 18 | #else 19 | static void SetDebugName(ID3D12DeviceChild* object, const wchar_t* format, ...){}; 20 | #endif 21 | 22 | private: 23 | // Nothing yet 24 | }; 25 | 26 | } // namespace Boolka 27 | -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/ResourceHeap.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #include "ResourceHeap.h" 4 | 5 | #include "APIWrappers/Device.h" 6 | 7 | namespace Boolka 8 | { 9 | 10 | ResourceHeap::ResourceHeap() 11 | : m_Heap(nullptr) 12 | { 13 | } 14 | 15 | ResourceHeap::~ResourceHeap() 16 | { 17 | BLK_ASSERT(m_Heap == nullptr); 18 | } 19 | 20 | ID3D12Heap* ResourceHeap::Get() 21 | { 22 | BLK_ASSERT(m_Heap != nullptr); 23 | return m_Heap; 24 | } 25 | 26 | ID3D12Heap* ResourceHeap::operator->() 27 | { 28 | return Get(); 29 | } 30 | 31 | bool ResourceHeap::Initialize(Device& device, size_t size, D3D12_HEAP_TYPE heapType, 32 | D3D12_HEAP_FLAGS heapFlags) 33 | { 34 | BLK_ASSERT(m_Heap == nullptr); 35 | 36 | BLK_CPU_SCOPE("ResourceHeap::Initialize"); 37 | 38 | D3D12_HEAP_DESC desc = {}; 39 | desc.Alignment = D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT; 40 | desc.Flags = heapFlags; 41 | desc.SizeInBytes = size; 42 | desc.Properties.Type = heapType; 43 | desc.Properties.CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_UNKNOWN; 44 | desc.Properties.MemoryPoolPreference = D3D12_MEMORY_POOL_UNKNOWN; 45 | 46 | HRESULT hr = device->CreateHeap(&desc, IID_PPV_ARGS(&m_Heap)); 47 | BLK_ASSERT(SUCCEEDED(hr)); 48 | 49 | return SUCCEEDED(hr); 50 | } 51 | 52 | void ResourceHeap::Unload() 53 | { 54 | BLK_ASSERT(m_Heap != nullptr); 55 | 56 | m_Heap->Release(); 57 | m_Heap = nullptr; 58 | } 59 | 60 | } // namespace Boolka 61 | -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/ResourceHeap.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Boolka 4 | { 5 | 6 | class Device; 7 | 8 | class [[nodiscard]] ResourceHeap 9 | { 10 | public: 11 | ResourceHeap(); 12 | ~ResourceHeap(); 13 | 14 | [[nodiscard]] ID3D12Heap* Get(); 15 | [[nodiscard]] ID3D12Heap* operator->(); 16 | 17 | bool Initialize(Device& device, size_t size, D3D12_HEAP_TYPE heapType, 18 | D3D12_HEAP_FLAGS heapFlags); 19 | void Unload(); 20 | 21 | private: 22 | ID3D12Heap* m_Heap; 23 | }; 24 | 25 | } // namespace Boolka 26 | -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/Resources/Buffers/Buffer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "APIWrappers/Resources/Resource.h" 3 | 4 | namespace Boolka 5 | { 6 | 7 | class Device; 8 | 9 | class [[nodiscard]] Buffer : public Resource 10 | { 11 | public: 12 | Buffer() = default; 13 | ~Buffer() = default; 14 | 15 | bool Initialize(Device& device, UINT64 size, D3D12_HEAP_TYPE heapType, 16 | D3D12_RESOURCE_FLAGS resourceFlags, 17 | D3D12_RESOURCE_STATES initialState = D3D12_RESOURCE_STATE_COMMON); 18 | void SafeUnload(); 19 | void Unload(); 20 | }; 21 | 22 | } // namespace Boolka 23 | -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/Resources/Buffers/CommandSignature.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #include "CommandSignature.h" 4 | 5 | #include "APIWrappers/Device.h" 6 | #include "APIWrappers/RootSignature.h" 7 | 8 | namespace Boolka 9 | { 10 | 11 | CommandSignature::CommandSignature() 12 | : m_CommandSignature(nullptr) 13 | { 14 | } 15 | 16 | CommandSignature::~CommandSignature() 17 | { 18 | BLK_ASSERT(m_CommandSignature == nullptr); 19 | } 20 | 21 | ID3D12CommandSignature* CommandSignature::Get() 22 | { 23 | BLK_ASSERT(m_CommandSignature != nullptr); 24 | return m_CommandSignature; 25 | } 26 | 27 | ID3D12CommandSignature* CommandSignature::operator->() 28 | { 29 | return Get(); 30 | } 31 | 32 | bool CommandSignature::Initialize(Device& device, ID3D12RootSignature* rootSig, 33 | UINT commandStride, UINT argumentCount, 34 | const D3D12_INDIRECT_ARGUMENT_DESC* arguments) 35 | { 36 | BLK_ASSERT(m_CommandSignature == nullptr); 37 | 38 | D3D12_COMMAND_SIGNATURE_DESC desc = {}; 39 | desc.ByteStride = commandStride; 40 | desc.NumArgumentDescs = argumentCount; 41 | desc.pArgumentDescs = arguments; 42 | 43 | HRESULT hr = 44 | device->CreateCommandSignature(&desc, rootSig, IID_PPV_ARGS(&m_CommandSignature)); 45 | 46 | return SUCCEEDED(hr); 47 | } 48 | 49 | void CommandSignature::Unload() 50 | { 51 | BLK_ASSERT(m_CommandSignature != nullptr); 52 | m_CommandSignature->Release(); 53 | m_CommandSignature = nullptr; 54 | } 55 | 56 | } // namespace Boolka -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/Resources/Buffers/CommandSignature.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Boolka 4 | { 5 | 6 | class Device; 7 | class RootSignature; 8 | 9 | class [[nodiscard]] CommandSignature 10 | { 11 | public: 12 | CommandSignature(); 13 | ~CommandSignature(); 14 | 15 | [[nodiscard]] ID3D12CommandSignature* Get(); 16 | [[nodiscard]] ID3D12CommandSignature* operator->(); 17 | 18 | bool Initialize(Device& device, ID3D12RootSignature* rootSig, UINT commandStride, 19 | UINT argumentCount, const D3D12_INDIRECT_ARGUMENT_DESC* arguments); 20 | void Unload(); 21 | 22 | private: 23 | ID3D12CommandSignature* m_CommandSignature; 24 | }; 25 | 26 | } // namespace Boolka 27 | -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/Resources/Buffers/ReadbackBuffer.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #include "ReadbackBuffer.h" 4 | 5 | namespace Boolka 6 | { 7 | 8 | bool ReadbackBuffer::Initialize(Device& device, UINT64 size) 9 | { 10 | if (!Buffer::Initialize(device, size, D3D12_HEAP_TYPE_READBACK, D3D12_RESOURCE_FLAG_NONE)) 11 | return false; 12 | 13 | return true; 14 | } 15 | 16 | void ReadbackBuffer::Unload() 17 | { 18 | BLK_ASSERT(m_Resource != nullptr); 19 | m_Resource->Release(); 20 | m_Resource = nullptr; 21 | } 22 | 23 | void* ReadbackBuffer::Map(UINT64 readRangeBegin, UINT64 readRangeEnd) 24 | { 25 | D3D12_RANGE readRange = {readRangeBegin, readRangeEnd}; 26 | void* result = nullptr; 27 | HRESULT hr = m_Resource->Map(0, &readRange, &result); 28 | BLK_ASSERT_VAR(SUCCEEDED(hr)); 29 | return result; 30 | } 31 | 32 | void ReadbackBuffer::Unmap() 33 | { 34 | D3D12_RANGE writeRange = {}; // empty read range = no writing 35 | m_Resource->Unmap(0, &writeRange); 36 | } 37 | 38 | void ReadbackBuffer::Readback(void* data, UINT64 size, UINT64 offset /*= 0*/) 39 | { 40 | const char* result = static_cast(Map(0, size)); 41 | memcpy(data, result + offset, size); 42 | Unmap(); 43 | } 44 | 45 | } // namespace Boolka -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/Resources/Buffers/ReadbackBuffer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "APIWrappers/Resources/Buffers/Buffer.h" 3 | 4 | namespace Boolka 5 | { 6 | 7 | class Device; 8 | 9 | class [[nodiscard]] ReadbackBuffer : public Buffer 10 | { 11 | public: 12 | ReadbackBuffer() = default; 13 | ~ReadbackBuffer() = default; 14 | 15 | bool Initialize(Device& device, UINT64 size); 16 | void Unload(); 17 | 18 | [[nodiscard]] void* Map(UINT64 readRangeBegin, UINT64 readRangeEnd); 19 | void Unmap(); 20 | 21 | void Readback(void* data, UINT64 size, UINT64 offset = 0); 22 | }; 23 | 24 | } // namespace Boolka 25 | -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/Resources/Buffers/UploadBuffer.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #include "UploadBuffer.h" 4 | 5 | namespace Boolka 6 | { 7 | 8 | bool UploadBuffer::Initialize(Device& device, UINT64 size) 9 | { 10 | if (!Buffer::Initialize(device, size, D3D12_HEAP_TYPE_UPLOAD, D3D12_RESOURCE_FLAG_NONE)) 11 | return false; 12 | 13 | return true; 14 | } 15 | 16 | void UploadBuffer::Unload() 17 | { 18 | BLK_ASSERT(m_Resource != nullptr); 19 | m_Resource->Release(); 20 | m_Resource = nullptr; 21 | } 22 | 23 | void* UploadBuffer::Map() 24 | { 25 | D3D12_RANGE readRange = {}; // empty read range = no reading 26 | void* result = nullptr; 27 | HRESULT hr = m_Resource->Map(0, &readRange, &result); 28 | BLK_ASSERT_VAR(SUCCEEDED(hr)); 29 | return result; 30 | } 31 | 32 | void UploadBuffer::Unmap() 33 | { 34 | m_Resource->Unmap(0, nullptr); 35 | } 36 | 37 | void UploadBuffer::Upload(const void* data, UINT64 size) 38 | { 39 | void* dst = Map(); 40 | memcpy(dst, data, size); 41 | Unmap(); 42 | } 43 | 44 | } // namespace Boolka -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/Resources/Buffers/UploadBuffer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "APIWrappers/Resources/Buffers/Buffer.h" 3 | 4 | namespace Boolka 5 | { 6 | 7 | class Device; 8 | 9 | class [[nodiscard]] UploadBuffer : public Buffer 10 | { 11 | public: 12 | UploadBuffer() = default; 13 | ~UploadBuffer() = default; 14 | 15 | bool Initialize(Device& device, UINT64 size); 16 | void Unload(); 17 | 18 | [[nodiscard]] void* Map(); 19 | void Unmap(); 20 | 21 | void Upload(const void* data, UINT64 size); 22 | }; 23 | 24 | } // namespace Boolka 25 | -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/Resources/Buffers/Views/ConstantBufferView.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #include "ConstantBufferView.h" 4 | 5 | #include "APIWrappers/Device.h" 6 | 7 | namespace Boolka 8 | { 9 | 10 | bool ConstantBufferView::Initialize(Device& device, Buffer& constantBuffer, 11 | D3D12_CPU_DESCRIPTOR_HANDLE destinationDescriptorHandle, 12 | UINT size) 13 | { 14 | D3D12_CONSTANT_BUFFER_VIEW_DESC desc = {}; 15 | desc.BufferLocation = constantBuffer->GetGPUVirtualAddress(); 16 | desc.SizeInBytes = size; 17 | device->CreateConstantBufferView(&desc, destinationDescriptorHandle); 18 | 19 | return true; 20 | } 21 | 22 | } // namespace Boolka -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/Resources/Buffers/Views/ConstantBufferView.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "APIWrappers/Resources/Buffers/Buffer.h" 3 | 4 | namespace Boolka 5 | { 6 | 7 | class ConstantBufferView 8 | { 9 | public: 10 | static bool Initialize(Device& device, Buffer& constantBuffer, 11 | D3D12_CPU_DESCRIPTOR_HANDLE destinationDescriptorHandle, UINT size); 12 | }; 13 | 14 | } // namespace Boolka 15 | -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/Resources/Buffers/Views/IndexBufferView.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #include "IndexBufferView.h" 4 | 5 | namespace Boolka 6 | { 7 | 8 | IndexBufferView::IndexBufferView() 9 | : m_View{} 10 | { 11 | } 12 | 13 | IndexBufferView::~IndexBufferView() 14 | { 15 | BLK_ASSERT(m_View.BufferLocation == 0); 16 | } 17 | 18 | bool IndexBufferView::Initialize(Buffer& indexBuffer, UINT size, DXGI_FORMAT format, 19 | UINT64 bufferOffset /*= 0*/) 20 | { 21 | BLK_ASSERT(m_View.BufferLocation == 0); 22 | BLK_ASSERT(format == DXGI_FORMAT_R16_UINT || format == DXGI_FORMAT_R32_UINT); 23 | 24 | m_View.BufferLocation = indexBuffer->GetGPUVirtualAddress() + bufferOffset; 25 | m_View.SizeInBytes = size; 26 | m_View.Format = format; 27 | 28 | return true; 29 | } 30 | 31 | void IndexBufferView::Unload() 32 | { 33 | BLK_ASSERT(m_View.BufferLocation != 0); 34 | m_View = {}; 35 | } 36 | 37 | const D3D12_INDEX_BUFFER_VIEW* IndexBufferView::GetView() 38 | { 39 | BLK_ASSERT(m_View.BufferLocation != 0); 40 | return &m_View; 41 | } 42 | 43 | } // namespace Boolka -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/Resources/Buffers/Views/IndexBufferView.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "APIWrappers/Resources/Buffers/Buffer.h" 3 | 4 | namespace Boolka 5 | { 6 | 7 | class IndexBuffer; 8 | 9 | class [[nodiscard]] IndexBufferView 10 | { 11 | public: 12 | IndexBufferView(); 13 | ~IndexBufferView(); 14 | 15 | bool Initialize(Buffer& indexBuffer, UINT size, DXGI_FORMAT format, 16 | UINT64 bufferOffset = 0); 17 | void Unload(); 18 | 19 | [[nodiscard]] const D3D12_INDEX_BUFFER_VIEW* GetView(); 20 | 21 | private: 22 | D3D12_INDEX_BUFFER_VIEW m_View; 23 | }; 24 | 25 | } // namespace Boolka 26 | -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/Resources/Buffers/Views/VertexBufferView.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #include "VertexBufferView.h" 4 | 5 | namespace Boolka 6 | { 7 | 8 | VertexBufferView::VertexBufferView() 9 | : m_View{} 10 | { 11 | } 12 | 13 | VertexBufferView::~VertexBufferView() 14 | { 15 | BLK_ASSERT(m_View.BufferLocation == 0); 16 | } 17 | 18 | bool VertexBufferView::Initialize(Buffer& vertexBuffer, UINT size, UINT stride, 19 | UINT64 bufferOffset /*= 0*/) 20 | { 21 | BLK_ASSERT(m_View.BufferLocation == 0); 22 | 23 | m_View.BufferLocation = vertexBuffer->GetGPUVirtualAddress() + bufferOffset; 24 | m_View.SizeInBytes = size; 25 | m_View.StrideInBytes = stride; 26 | 27 | return true; 28 | } 29 | 30 | void VertexBufferView::Unload() 31 | { 32 | BLK_ASSERT(m_View.BufferLocation != 0); 33 | m_View = {}; 34 | } 35 | 36 | const D3D12_VERTEX_BUFFER_VIEW* VertexBufferView::GetView() 37 | { 38 | BLK_ASSERT(m_View.BufferLocation != 0); 39 | return &m_View; 40 | } 41 | 42 | } // namespace Boolka -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/Resources/Buffers/Views/VertexBufferView.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "APIWrappers/Resources/Buffers/Buffer.h" 3 | 4 | namespace Boolka 5 | { 6 | 7 | class VertexBuffer; 8 | 9 | class [[nodiscard]] VertexBufferView 10 | { 11 | public: 12 | VertexBufferView(); 13 | ~VertexBufferView(); 14 | 15 | bool Initialize(Buffer& vertexBuffer, UINT size, UINT stride, UINT64 bufferOffset = 0); 16 | void Unload(); 17 | 18 | [[nodiscard]] const D3D12_VERTEX_BUFFER_VIEW* GetView(); 19 | 20 | private: 21 | D3D12_VERTEX_BUFFER_VIEW m_View; 22 | }; 23 | 24 | } // namespace Boolka 25 | -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/Resources/Resource.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #include "Resource.h" 4 | 5 | namespace Boolka 6 | { 7 | 8 | ID3D12Resource* Resource::Get() 9 | { 10 | BLK_ASSERT(m_Resource != nullptr); 11 | return m_Resource; 12 | } 13 | 14 | ID3D12Resource* Resource::operator->() 15 | { 16 | return Get(); 17 | } 18 | 19 | Resource::Resource() 20 | : m_Resource(nullptr) 21 | { 22 | } 23 | 24 | Resource::~Resource() 25 | { 26 | BLK_ASSERT(m_Resource == nullptr); 27 | } 28 | 29 | } // namespace Boolka 30 | -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/Resources/Resource.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Boolka 4 | { 5 | 6 | class [[nodiscard]] Resource 7 | { 8 | public: 9 | [[nodiscard]] ID3D12Resource* Get(); 10 | [[nodiscard]] ID3D12Resource* operator->(); 11 | 12 | protected: 13 | Resource(); 14 | ~Resource(); 15 | 16 | ID3D12Resource* m_Resource; 17 | }; 18 | 19 | } // namespace Boolka 20 | -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/Resources/ResourceTransition.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Boolka 4 | { 5 | 6 | class Resource; 7 | class CommandList; 8 | 9 | class ResourceTransition 10 | { 11 | public: 12 | static void Transition(CommandList& commangList, Resource& resource, 13 | D3D12_RESOURCE_STATES srcState, D3D12_RESOURCE_STATES dstState); 14 | 15 | static void TransitionMany( 16 | CommandList& commangList, 17 | std::tuple* transitions, 18 | size_t transitionCount); 19 | 20 | static void TransitionMany(CommandList& commangList, Resource** resources, 21 | D3D12_RESOURCE_STATES sharedSrcState, 22 | D3D12_RESOURCE_STATES sharedDstState, size_t transitionCount); 23 | 24 | static bool NeedTransition(D3D12_RESOURCE_STATES srcState, D3D12_RESOURCE_STATES dstState); 25 | 26 | // Common state promotion/decay helpers 27 | static bool CanPromote(D3D12_RESOURCE_STATES srcState, D3D12_RESOURCE_STATES dstState); 28 | static bool CanDecay(D3D12_RESOURCE_STATES srcState); 29 | }; 30 | 31 | } // namespace Boolka 32 | -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/Resources/Textures/Texture.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #include "Texture.h" 4 | 5 | namespace Boolka 6 | { 7 | 8 | } -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/Resources/Textures/Texture.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "APIWrappers/Resources/Resource.h" 4 | 5 | namespace Boolka 6 | { 7 | 8 | class Texture : public Resource 9 | { 10 | protected: 11 | Texture() = default; 12 | ~Texture() = default; 13 | }; 14 | 15 | } // namespace Boolka 16 | -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/Resources/Textures/Views/DepthStencilView.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #include "DepthStencilView.h" 4 | 5 | #include "APIWrappers/Device.h" 6 | #include "APIWrappers/Resources/Textures/Texture2D.h" 7 | 8 | namespace Boolka 9 | { 10 | 11 | DepthStencilView::DepthStencilView() 12 | : m_CPUDescriptorHandle{} 13 | { 14 | } 15 | 16 | DepthStencilView::~DepthStencilView() 17 | { 18 | BLK_ASSERT(m_CPUDescriptorHandle.ptr == 0); 19 | } 20 | 21 | bool DepthStencilView::Initialize(Device& device, Texture2D& texture, DXGI_FORMAT format, 22 | D3D12_CPU_DESCRIPTOR_HANDLE destDescriptor, 23 | UINT16 arraySlice /*= 0*/) 24 | { 25 | BLK_ASSERT(m_CPUDescriptorHandle.ptr == 0); 26 | 27 | D3D12_DEPTH_STENCIL_VIEW_DESC desc = {}; 28 | desc.ViewDimension = D3D12_DSV_DIMENSION_TEXTURE2DARRAY; 29 | desc.Format = format; 30 | desc.Texture2DArray.ArraySize = 1; 31 | desc.Texture2DArray.FirstArraySlice = arraySlice; 32 | 33 | device->CreateDepthStencilView(texture.Get(), &desc, destDescriptor); 34 | m_CPUDescriptorHandle = destDescriptor; 35 | 36 | return true; 37 | } 38 | 39 | void DepthStencilView::Unload() 40 | { 41 | BLK_ASSERT(m_CPUDescriptorHandle.ptr != 0); 42 | m_CPUDescriptorHandle = {}; 43 | } 44 | 45 | D3D12_CPU_DESCRIPTOR_HANDLE* DepthStencilView::GetCPUDescriptor() 46 | { 47 | BLK_ASSERT(m_CPUDescriptorHandle.ptr != 0); 48 | return &m_CPUDescriptorHandle; 49 | } 50 | 51 | } // namespace Boolka -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/Resources/Textures/Views/DepthStencilView.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Boolka 4 | { 5 | class Device; 6 | class Texture2D; 7 | 8 | class [[nodiscard]] DepthStencilView 9 | { 10 | public: 11 | DepthStencilView(); 12 | ~DepthStencilView(); 13 | 14 | bool Initialize(Device& device, Texture2D& texture, DXGI_FORMAT format, 15 | D3D12_CPU_DESCRIPTOR_HANDLE destDescriptor, UINT16 arraySlice = 0); 16 | void Unload(); 17 | 18 | [[nodiscard]] D3D12_CPU_DESCRIPTOR_HANDLE* GetCPUDescriptor(); 19 | 20 | private: 21 | D3D12_CPU_DESCRIPTOR_HANDLE m_CPUDescriptorHandle; 22 | }; 23 | 24 | } // namespace Boolka 25 | -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/Resources/Textures/Views/RenderTargetView.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #include "RenderTargetView.h" 4 | 5 | #include "APIWrappers/Device.h" 6 | #include "APIWrappers/Resources/Textures/Texture2D.h" 7 | 8 | namespace Boolka 9 | { 10 | 11 | RenderTargetView::RenderTargetView() 12 | : m_CPUDescriptorHandle{} 13 | { 14 | } 15 | 16 | RenderTargetView::~RenderTargetView() 17 | { 18 | BLK_ASSERT(m_CPUDescriptorHandle.ptr == 0); 19 | } 20 | 21 | bool RenderTargetView::Initialize(Device& device, Texture2D& texture, DXGI_FORMAT format, 22 | D3D12_CPU_DESCRIPTOR_HANDLE destDescriptor) 23 | { 24 | BLK_ASSERT(m_CPUDescriptorHandle.ptr == 0); 25 | 26 | D3D12_RENDER_TARGET_VIEW_DESC desc = {}; 27 | desc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE2D; 28 | desc.Format = format; 29 | 30 | device->CreateRenderTargetView(texture.Get(), &desc, destDescriptor); 31 | m_CPUDescriptorHandle = destDescriptor; 32 | 33 | return true; 34 | } 35 | 36 | void RenderTargetView::Unload() 37 | { 38 | BLK_ASSERT(m_CPUDescriptorHandle.ptr != 0); 39 | m_CPUDescriptorHandle = {}; 40 | } 41 | 42 | D3D12_CPU_DESCRIPTOR_HANDLE* RenderTargetView::GetCPUDescriptor() 43 | { 44 | BLK_ASSERT(m_CPUDescriptorHandle.ptr != 0); 45 | return &m_CPUDescriptorHandle; 46 | } 47 | 48 | } // namespace Boolka -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/Resources/Textures/Views/RenderTargetView.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Boolka 4 | { 5 | class Device; 6 | class Texture2D; 7 | 8 | class [[nodiscard]] RenderTargetView 9 | { 10 | public: 11 | RenderTargetView(); 12 | ~RenderTargetView(); 13 | 14 | bool Initialize(Device& device, Texture2D& texture, DXGI_FORMAT format, 15 | D3D12_CPU_DESCRIPTOR_HANDLE destDescriptor); 16 | void Unload(); 17 | 18 | [[nodiscard]] D3D12_CPU_DESCRIPTOR_HANDLE* GetCPUDescriptor(); 19 | 20 | private: 21 | D3D12_CPU_DESCRIPTOR_HANDLE m_CPUDescriptorHandle; 22 | }; 23 | 24 | } // namespace Boolka 25 | -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/Resources/Textures/Views/ShaderResourceView.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Boolka 4 | { 5 | class Device; 6 | class Texture2D; 7 | class Buffer; 8 | 9 | class ShaderResourceView 10 | { 11 | public: 12 | static void Initialize(Device& device, Texture2D& texture, 13 | D3D12_CPU_DESCRIPTOR_HANDLE destDescriptor); 14 | static void Initialize(Device& device, Texture2D& texture, 15 | D3D12_CPU_DESCRIPTOR_HANDLE destDescriptor, DXGI_FORMAT format); 16 | static void Initialize(Device& device, Buffer& buffer, UINT elementCount, UINT stride, 17 | D3D12_CPU_DESCRIPTOR_HANDLE destDescriptor); 18 | static void Initialize(Device& device, Buffer& buffer, UINT elementCount, 19 | DXGI_FORMAT format, D3D12_CPU_DESCRIPTOR_HANDLE destDescriptor); 20 | static void InitializeCube(Device& device, Texture2D& texture, 21 | D3D12_CPU_DESCRIPTOR_HANDLE destDescriptor, DXGI_FORMAT format); 22 | static void InitializeAccelerationStructure(Device& device, 23 | D3D12_GPU_VIRTUAL_ADDRESS tlasAddress, 24 | D3D12_CPU_DESCRIPTOR_HANDLE destDescriptor); 25 | static void InitializeNullDescriptorTexture2D(Device& device, DXGI_FORMAT format, 26 | D3D12_CPU_DESCRIPTOR_HANDLE destDescriptor); 27 | 28 | private: 29 | static void Initialize(Device& device, Buffer& buffer, UINT elementCount, UINT stride, 30 | DXGI_FORMAT format, D3D12_CPU_DESCRIPTOR_HANDLE destDescriptor); 31 | }; 32 | 33 | } // namespace Boolka 34 | -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/Resources/Textures/Views/UnorderedAccessView.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Boolka 4 | { 5 | class Device; 6 | class Texture2D; 7 | class Buffer; 8 | 9 | class UnorderedAccessView 10 | { 11 | public: 12 | static void Initialize(Device& device, Texture2D& texture, DXGI_FORMAT format, 13 | D3D12_CPU_DESCRIPTOR_HANDLE destDescriptor); 14 | static void Initialize(Device& device, Buffer& buffer, UINT stride, UINT elementCount, 15 | D3D12_CPU_DESCRIPTOR_HANDLE destDescriptor); 16 | static void Initialize(Device& device, Buffer& buffer, DXGI_FORMAT format, 17 | UINT elementCount, D3D12_CPU_DESCRIPTOR_HANDLE destDescriptor); 18 | static void InitializeWithCounter(Device& device, Buffer& buffer, UINT stride, 19 | UINT elementCount, 20 | D3D12_CPU_DESCRIPTOR_HANDLE destDescriptor); 21 | static void InitializeWithCounter(Device& device, Buffer& buffer, DXGI_FORMAT format, 22 | UINT elementCount, 23 | D3D12_CPU_DESCRIPTOR_HANDLE destDescriptor); 24 | 25 | private: 26 | static void Initialize(Device& device, Buffer& buffer, DXGI_FORMAT format, UINT stride, 27 | UINT elementCount, D3D12_CPU_DESCRIPTOR_HANDLE destDescriptor); 28 | static void InitializeWithCounter(Device& device, Buffer& buffer, DXGI_FORMAT format, 29 | UINT stride, UINT elementCount, 30 | D3D12_CPU_DESCRIPTOR_HANDLE destDescriptor); 31 | }; 32 | 33 | } // namespace Boolka 34 | -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/Resources/UAVBarrier.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #include "UAVBarrier.h" 4 | 5 | #include "APIWrappers/CommandList/CommandList.h" 6 | #include "APIWrappers/Resources/Resource.h" 7 | 8 | namespace Boolka 9 | { 10 | 11 | void UAVBarrier::Barrier(CommandList& commangList, Resource& resource) 12 | { 13 | D3D12_RESOURCE_BARRIER uavBarrier{}; 14 | uavBarrier.Type = D3D12_RESOURCE_BARRIER_TYPE_UAV; 15 | uavBarrier.UAV.pResource = resource.Get(); 16 | commangList->ResourceBarrier(1, &uavBarrier); 17 | } 18 | 19 | void UAVBarrier::BarrierAll(CommandList& commangList) 20 | { 21 | D3D12_RESOURCE_BARRIER uavBarrier{}; 22 | uavBarrier.Type = D3D12_RESOURCE_BARRIER_TYPE_UAV; 23 | commangList->ResourceBarrier(1, &uavBarrier); 24 | } 25 | 26 | } // namespace Boolka 27 | -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/Resources/UAVBarrier.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Boolka 4 | { 5 | 6 | class Resource; 7 | class CommandList; 8 | 9 | class UAVBarrier 10 | { 11 | public: 12 | static void Barrier(CommandList& commangList, Resource& resource); 13 | static void BarrierAll(CommandList& commangList); 14 | }; 15 | 16 | } // namespace Boolka 17 | -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/RootSignature.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #include "RootSignature.h" 4 | 5 | #include "APIWrappers/Device.h" 6 | #include "BoolkaCommon/DebugHelpers/DebugFileReader.h" 7 | 8 | namespace Boolka 9 | { 10 | 11 | RootSignature::RootSignature() 12 | : m_RootSignature(nullptr) 13 | { 14 | } 15 | 16 | RootSignature::~RootSignature() 17 | { 18 | BLK_ASSERT(m_RootSignature == nullptr); 19 | } 20 | 21 | ID3D12RootSignature* RootSignature::Get() const 22 | { 23 | BLK_ASSERT(m_RootSignature != nullptr); 24 | return m_RootSignature; 25 | } 26 | 27 | ID3D12RootSignature* RootSignature::operator->() const 28 | { 29 | return Get(); 30 | } 31 | 32 | bool RootSignature::Initialize(Device& device, const char* filename) 33 | { 34 | BLK_ASSERT(m_RootSignature == nullptr); 35 | 36 | MemoryBlock compiledRootSignature = DebugFileReader::ReadFile(filename); 37 | HRESULT hr = device->CreateRootSignature(0, compiledRootSignature.m_Data, 38 | compiledRootSignature.m_Size, 39 | IID_PPV_ARGS(&m_RootSignature)); 40 | DebugFileReader::FreeMemory(compiledRootSignature); 41 | return SUCCEEDED(hr); 42 | } 43 | 44 | void RootSignature::Unload() 45 | { 46 | BLK_ASSERT(m_RootSignature != nullptr); 47 | m_RootSignature->Release(); 48 | m_RootSignature = nullptr; 49 | } 50 | 51 | } // namespace Boolka 52 | -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/RootSignature.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Boolka 4 | { 5 | 6 | class Device; 7 | 8 | class [[nodiscard]] RootSignature 9 | { 10 | public: 11 | RootSignature(); 12 | ~RootSignature(); 13 | 14 | [[nodiscard]] ID3D12RootSignature* Get() const; 15 | [[nodiscard]] ID3D12RootSignature* operator->() const; 16 | 17 | bool Initialize(Device& device, const char* filename); 18 | void Unload(); 19 | 20 | private: 21 | ID3D12RootSignature* m_RootSignature; 22 | }; 23 | 24 | } // namespace Boolka 25 | -------------------------------------------------------------------------------- /D3D12Backend/APIWrappers/Swapchain.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Boolka 4 | { 5 | 6 | class Device; 7 | class Factory; 8 | struct WindowState; 9 | 10 | class [[nodiscard]] Swapchain 11 | { 12 | public: 13 | Swapchain(); 14 | ~Swapchain(); 15 | 16 | [[nodiscard]] IDXGISwapChain4* Get(); 17 | [[nodiscard]] IDXGISwapChain4* operator->(); 18 | 19 | // Present CAN fail, have to check return code 20 | [[nodiscard]] bool Present(const WindowState& windowState); 21 | [[nodiscard]] ID3D12Resource* GetBuffer(UINT index); 22 | [[nodiscard]] UINT GetCurrentFrameIndex(); 23 | 24 | bool Initialize(Device& device, Factory& factory, HWND window, WindowState& windowState); 25 | void Unload(); 26 | 27 | bool Update(Device& device, WindowState windowState); 28 | 29 | private: 30 | IDXGISwapChain4* m_Swapchain; 31 | bool m_IsFullscreen; 32 | UINT m_PresentFlags; 33 | }; 34 | 35 | } // namespace Boolka 36 | -------------------------------------------------------------------------------- /D3D12Backend/BatchManager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Boolka 4 | { 5 | 6 | class CommandList; 7 | class Scene; 8 | class RenderFrameContext; 9 | 10 | class [[nodiscard]] BatchManager 11 | { 12 | public: 13 | enum class BatchType 14 | { 15 | Opaque, 16 | ShadowMapSun, 17 | ShadowMapLight0, 18 | Count = ShadowMapLight0 + BLK_MAX_LIGHT_COUNT * BLK_TEXCUBE_FACE_COUNT 19 | }; 20 | 21 | // TODO design good place to put it 22 | enum class ViewType 23 | { 24 | MainView, 25 | ShadowMapSun, 26 | ShadowMapLight0, 27 | Count = ShadowMapLight0 + BLK_MAX_LIGHT_COUNT * BLK_TEXCUBE_FACE_COUNT, 28 | }; 29 | 30 | BatchManager() = default; 31 | ~BatchManager() = default; 32 | 33 | bool Initialize(Device& device, const Scene& scene, RenderEngineContext& engineContext); 34 | void Unload(); 35 | 36 | bool PrepareBatches(const RenderFrameContext& frameContext, const Scene& scene); 37 | 38 | bool Render(CommandList& commandList, RenderContext& renderContext, BatchType batch); 39 | 40 | private: 41 | struct [[nodiscard]] DrawData 42 | { 43 | UINT objectOffset; 44 | UINT objectCount; 45 | }; 46 | 47 | // used to sort objects by distance 48 | struct [[nodiscard]] SortingData 49 | { 50 | UINT objectIndex; 51 | float distance; 52 | }; 53 | 54 | DrawData m_Batches[static_cast(BatchType::Count)]; 55 | CommandSignature m_CommandSignature; 56 | }; 57 | 58 | BLK_DECLARE_ENUM_OPERATORS(BatchManager::BatchType); 59 | BLK_DECLARE_ENUM_OPERATORS(BatchManager::ViewType); 60 | 61 | } // namespace Boolka 62 | -------------------------------------------------------------------------------- /D3D12Backend/Camera.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Boolka 4 | { 5 | 6 | class Camera 7 | { 8 | public: 9 | Camera(); 10 | ~Camera(); 11 | 12 | bool Initialize(float rotationYaw, float rotationPitch, float fieldOfView, 13 | const Vector4& cameraPos); 14 | void Unload(); 15 | 16 | bool Update(float deltaTime, float aspectRatio, Matrix4x4& outViewMatrix, 17 | Matrix4x4& outProjMatrix, Vector4& outCameraPos, Vector4* outEyeRayCoeficients); 18 | 19 | private: 20 | void UpdateInput(float deltaTime, const Vector4& right, const Vector4& up, 21 | const Vector4& forward); 22 | void UpdateMatrices(float aspectRatio, const Vector4& right, const Vector4& up, 23 | const Vector4& forward, Matrix4x4& outViewMatrix, 24 | Matrix4x4& outProjMatrix); 25 | float m_RotationYaw; 26 | float m_RotationPitch; 27 | float m_FieldOfView; 28 | Vector4 m_CameraPos; 29 | }; 30 | 31 | } // namespace Boolka 32 | -------------------------------------------------------------------------------- /D3D12Backend/Containers/LightContainer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Boolka 4 | { 5 | // Temp container for lights 6 | class [[nodiscard]] LightContainer 7 | { 8 | public: 9 | LightContainer(); 10 | 11 | struct [[nodiscard]] Light 12 | { 13 | Vector3 worldPos; 14 | float nearZ; 15 | Vector3 color; 16 | float farZ; 17 | }; 18 | 19 | struct [[nodiscard]] Sun 20 | { 21 | Vector4 lightDir; 22 | Vector4 worldPos; 23 | Vector4 color; 24 | }; 25 | 26 | [[nodiscard]] const std::vector& GetLights() const; 27 | [[nodiscard]] const std::vector>& 28 | GetViewProjMatrices() const; 29 | [[nodiscard]] const std::vector>& 30 | GetViewMatrices() const; 31 | [[nodiscard]] const std::vector>& 32 | GetProjMatrices() const; 33 | 34 | [[nodiscard]] const Sun& GetSun() const; 35 | [[nodiscard]] const Matrix4x4& GetSunView() const; 36 | [[nodiscard]] const Matrix4x4& GetSunProj() const; 37 | [[nodiscard]] const Matrix4x4& GetSunViewProj() const; 38 | 39 | void Update(float deltaTime); 40 | 41 | private: 42 | void UpdateLights(); 43 | void UpdateSun(); 44 | 45 | std::vector m_Lights; 46 | std::vector> m_ViewProjMatrices; 47 | std::vector> m_ViewMatrices; 48 | std::vector> m_ProjMatrices; 49 | Sun m_Sun; 50 | Matrix4x4 m_SunView; 51 | Matrix4x4 m_SunProj; 52 | Matrix4x4 m_SunViewProj; 53 | float m_CurrentRotation; 54 | }; 55 | 56 | } // namespace Boolka 57 | -------------------------------------------------------------------------------- /D3D12Backend/Containers/ShaderTable.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Boolka 4 | { 5 | 6 | class StateObject; 7 | 8 | class [[nodiscard]] ShaderTable 9 | { 10 | public: 11 | [[nodiscard]] static UINT64 CalculateRequiredBufferSize(UINT rayGenShaderCount, 12 | UINT missShaderCount, 13 | UINT closestHitShaderCount); 14 | void Build(D3D12_GPU_VIRTUAL_ADDRESS destGPUBufferAdress, void* uploadDest, 15 | StateObject& stateObject, UINT rayGenShaderCount, 16 | const wchar_t** rayGenShaderExports, UINT missShaderCount, 17 | const wchar_t** missShaderExports, UINT hitGroupCount, 18 | const wchar_t** hitGroupExports); 19 | 20 | [[nodiscard]] D3D12_GPU_VIRTUAL_ADDRESS GetRayGenShader() const; 21 | [[nodiscard]] D3D12_GPU_VIRTUAL_ADDRESS GetMissShaderTable() const; 22 | [[nodiscard]] D3D12_GPU_VIRTUAL_ADDRESS GetHitGroupTable() const; 23 | 24 | private: 25 | D3D12_GPU_VIRTUAL_ADDRESS m_RayGenShaderTable; 26 | D3D12_GPU_VIRTUAL_ADDRESS m_MissShaderTable; 27 | D3D12_GPU_VIRTUAL_ADDRESS m_HitGroupTable; 28 | }; 29 | 30 | } // namespace Boolka 31 | -------------------------------------------------------------------------------- /D3D12Backend/Containers/Streaming/SceneData.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | namespace Boolka 4 | { 5 | 6 | static_assert(sizeof(HLSLShared::VertexData1) % 16 == 0, 7 | "This struct is used in structured buffer, so for performance reasons its " 8 | "size should be multiple of float4"); 9 | 10 | static_assert(sizeof(HLSLShared::VertexData2) % 16 == 0, 11 | "This struct is used in structured buffer, so for performance reasons its " 12 | "size should be multiple of float4"); 13 | 14 | static_assert(sizeof(HLSLShared::ObjectData) % 16 == 0, 15 | "This struct is used in structured buffer, so for performance reasons its " 16 | "size should be multiple of float4"); 17 | 18 | static_assert(sizeof(HLSLShared::MeshletData) % 16 == 0, 19 | "This struct is used in structured buffer, so for performance reasons its " 20 | "size should be multiple of float4"); 21 | 22 | namespace SceneData 23 | { 24 | 25 | bool FormatHeader::IsValid() const 26 | { 27 | FormatHeader valid{}; 28 | return (memcmp(signature, valid.signature, sizeof(signature)) == 0) && 29 | (formatVersion == valid.formatVersion); 30 | } 31 | 32 | } // namespace SceneData 33 | } // namespace Boolka 34 | -------------------------------------------------------------------------------- /D3D12Backend/Containers/Streaming/SceneDataReader.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "APIWrappers/DirectStorage/DStorageFile.h" 3 | #include "BoolkaCommon/Structures/AABB.h" 4 | #include "BoolkaCommon/Structures/MemoryBlock.h" 5 | #include "SceneData.h" 6 | 7 | namespace Boolka 8 | { 9 | class FileReader; 10 | 11 | class [[nodiscard]] SceneDataReader 12 | { 13 | public: 14 | SceneDataReader(); 15 | ~SceneDataReader(); 16 | 17 | bool OpenScene(Device& device, const wchar_t* folderPath); 18 | void CloseReader(); 19 | 20 | struct [[nodiscard]] HeaderWrapper 21 | { 22 | const SceneData::SceneHeader* header; 23 | const SceneData::TextureHeader* textureHeaders; 24 | const SceneData::CPUObjectHeader* cpuObjectHeaders; 25 | }; 26 | 27 | HeaderWrapper GetHeaderWrapper(); 28 | DStorageFile& GetSceneDataFile(); 29 | 30 | private: 31 | struct [[nodiscard]] HeaderStart 32 | { 33 | SceneData::FormatHeader formatHeader; 34 | SceneData::SceneHeader sceneHeader; 35 | }; 36 | 37 | MemoryBlock m_Header; 38 | DStorageFile m_SceneDataFile; 39 | }; 40 | 41 | } // namespace Boolka 42 | -------------------------------------------------------------------------------- /D3D12Backend/Containers/TimestampContainer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../APIWrappers/Queries/QueryHeap.h" 3 | 4 | namespace Boolka 5 | { 6 | // Temp container for timestamps 7 | class [[nodiscard]] TimestampContainer 8 | { 9 | public: 10 | TimestampContainer(); 11 | ~TimestampContainer(); 12 | 13 | enum class Markers 14 | { 15 | UpdateRenderPass, 16 | BeginFrame = UpdateRenderPass, 17 | GPUCullingRenderPass, 18 | ZRenderPass, 19 | ShadowMapRenderPass, 20 | GBufferRenderPass, 21 | RaytraceRenderPass, 22 | DeferredLightingPass, 23 | SkyBoxRenderPass, 24 | TransparentRenderPass, 25 | ToneMappingPass, 26 | DebugOverlayPass, 27 | PresentPass, 28 | EndFrame, 29 | Count 30 | }; 31 | 32 | bool Initialize(Device& device, GraphicCommandListImpl& m_InitializationCommandList); 33 | void Unload(); 34 | 35 | void Mark(GraphicCommandListImpl& commandList, Markers marker); 36 | void FinishFrame(GraphicCommandListImpl& commandList, RenderContext& renderContext, 37 | UINT frameIndex); 38 | 39 | private: 40 | QueryHeap m_QueryHeap; 41 | ReadbackBuffer m_ReadbackBuffer[BLK_IN_FLIGHT_FRAMES]; 42 | UINT64 m_TimestampFrequency; 43 | }; 44 | 45 | } // namespace Boolka 46 | -------------------------------------------------------------------------------- /D3D12Backend/Contexts/FrameStats.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #include "FrameStats.h" 4 | 5 | namespace Boolka 6 | { 7 | 8 | FrameStats::GPUTimes FrameStats::GPUTimes::operator*(float factor) 9 | { 10 | GPUTimes result{}; 11 | 12 | for (size_t i = 0; i < ARRAYSIZE(result.Markers); ++i) 13 | { 14 | result.Markers[i] = Markers[i] * factor; 15 | } 16 | 17 | return result; 18 | } 19 | 20 | FrameStats::GPUTimes FrameStats::GPUTimes::operator+(const GPUTimes& other) 21 | { 22 | GPUTimes result{}; 23 | 24 | for (size_t i = 0; i < ARRAYSIZE(result.Markers); ++i) 25 | { 26 | result.Markers[i] = Markers[i] + other.Markers[i]; 27 | } 28 | 29 | return result; 30 | } 31 | 32 | } // namespace Boolka 33 | -------------------------------------------------------------------------------- /D3D12Backend/Contexts/FrameStats.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef BLK_ENABLE_STATS 4 | 5 | namespace Boolka 6 | { 7 | 8 | struct [[nodiscard]] FrameStats 9 | { 10 | float frameTime; 11 | float frameTimeStable; 12 | 13 | struct [[nodiscard]] GPUTimes 14 | { 15 | float Markers[static_cast(TimestampContainer::Markers::Count)]; 16 | 17 | GPUTimes operator*(float factor); 18 | GPUTimes operator+(const GPUTimes& other); 19 | }; 20 | 21 | GPUTimes gpuTimes; 22 | GPUTimes gpuTimesStable; 23 | 24 | struct 25 | { 26 | uint visibleObjectCount; 27 | uint visibleMeshletCount; 28 | } visiblePerFrustum[BLK_RENDER_VIEW_COUNT]; 29 | 30 | uint gpuDebugMarkers[BLK_DEBUG_DATA_ELEMENT_COUNT]; 31 | }; 32 | 33 | } // namespace Boolka 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /D3D12Backend/Contexts/RenderContext.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Boolka 4 | { 5 | 6 | class RenderEngineContext; 7 | class RenderFrameContext; 8 | class RenderThreadContext; 9 | 10 | class [[nodiscard]] RenderContext 11 | { 12 | public: 13 | RenderContext(); 14 | ~RenderContext(); 15 | 16 | bool Initialize(RenderEngineContext& engineContext, RenderFrameContext& frameContext, 17 | RenderThreadContext& threadContext); 18 | void Unload(); 19 | 20 | [[nodiscard]] RenderEngineContext& GetRenderEngineContext(); 21 | [[nodiscard]] RenderFrameContext& GetRenderFrameContext(); 22 | [[nodiscard]] RenderThreadContext& GetRenderThreadContext(); 23 | 24 | [[nodiscard]] const RenderEngineContext& GetRenderEngineContext() const; 25 | [[nodiscard]] const RenderFrameContext& GetRenderFrameContext() const; 26 | [[nodiscard]] const RenderThreadContext& GetRenderThreadContext() const; 27 | 28 | [[nodiscard]] std::tuple 29 | GetContexts(); 30 | [[nodiscard]] std::tuple 32 | GetContexts() const; 33 | 34 | private: 35 | RenderEngineContext* m_EngineContext; 36 | RenderFrameContext* m_FrameContext; 37 | RenderThreadContext* m_ThreadContext; 38 | }; 39 | 40 | } // namespace Boolka 41 | -------------------------------------------------------------------------------- /D3D12Backend/Contexts/RenderThreadContext.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "APIWrappers/CommandAllocator/GraphicCommandAllocator.h" 4 | 5 | namespace Boolka 6 | { 7 | 8 | class Device; 9 | 10 | class [[nodiscard]] RenderThreadContext 11 | { 12 | public: 13 | RenderThreadContext(); 14 | ~RenderThreadContext(); 15 | 16 | bool Initialize(Device& device); 17 | void Unload(); 18 | 19 | [[nodiscard]] GraphicCommandListImpl& GetGraphicCommandList(); 20 | 21 | void FlipFrame(UINT frameIndex); 22 | 23 | private: 24 | GraphicCommandAllocator* m_CurrentGraphicCommandAllocator; 25 | GraphicCommandListImpl* m_CurrentGraphicCommandList; 26 | GraphicCommandAllocator m_GraphicCommandAllocator[BLK_IN_FLIGHT_FRAMES]; 27 | GraphicCommandListImpl m_GraphicCommandList[BLK_IN_FLIGHT_FRAMES]; 28 | }; 29 | 30 | } // namespace Boolka 31 | -------------------------------------------------------------------------------- /D3D12Backend/DebugHelpers/DebugCPUScope.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #include "DebugCPUScope.h" 4 | 5 | namespace Boolka 6 | { 7 | 8 | DebugCPUScope::DebugCPUScope(const char* name) 9 | { 10 | StartEvent(name); 11 | } 12 | 13 | DebugCPUScope::~DebugCPUScope() 14 | { 15 | EndEvent(); 16 | } 17 | 18 | void DebugCPUScope::StartEvent(const char* name) 19 | { 20 | #ifdef BLK_USE_PIX_MARKERS 21 | PIXBeginEvent(BLK_PIX_SCOPE_COLOR, name); 22 | #endif 23 | } 24 | 25 | void DebugCPUScope::EndEvent() 26 | { 27 | #ifdef BLK_USE_PIX_MARKERS 28 | PIXEndEvent(); 29 | #endif 30 | } 31 | 32 | } // namespace Boolka 33 | -------------------------------------------------------------------------------- /D3D12Backend/DebugHelpers/DebugCPUScope.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Boolka 4 | { 5 | 6 | class [[nodiscard]] DebugCPUScope 7 | { 8 | public: 9 | DebugCPUScope(const char* name); 10 | ~DebugCPUScope(); 11 | 12 | private: 13 | void StartEvent(const char* name); 14 | void EndEvent(); 15 | }; 16 | 17 | } // namespace Boolka 18 | -------------------------------------------------------------------------------- /D3D12Backend/DebugHelpers/DebugRenderScope.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #include "DebugRenderScope.h" 4 | 5 | #ifdef BLK_USE_PIX_MARKERS 6 | 7 | namespace Boolka 8 | { 9 | 10 | DebugRenderScope::DebugRenderScope(CommandList& commandList, const char* name) 11 | : m_CommandList(commandList.Get()) 12 | { 13 | StartEvent(name); 14 | } 15 | 16 | DebugRenderScope::~DebugRenderScope() 17 | { 18 | EndEvent(); 19 | } 20 | 21 | void DebugRenderScope::StartEvent(const char* name) 22 | { 23 | PIXBeginEvent(m_CommandList, BLK_PIX_SCOPE_COLOR, name); 24 | } 25 | 26 | void DebugRenderScope::EndEvent() 27 | { 28 | PIXEndEvent(m_CommandList); 29 | } 30 | 31 | } // namespace Boolka 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /D3D12Backend/DebugHelpers/DebugRenderScope.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef BLK_USE_PIX_MARKERS 4 | 5 | namespace Boolka 6 | { 7 | 8 | class [[nodiscard]] DebugRenderScope 9 | { 10 | public: 11 | DebugRenderScope(CommandList& commandList, const char* name); 12 | ~DebugRenderScope(); 13 | 14 | private: 15 | void StartEvent(const char* name); 16 | void EndEvent(); 17 | 18 | ID3D12GraphicsCommandList* m_CommandList; 19 | }; 20 | 21 | } // namespace Boolka 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /D3D12Backend/DebugHelpers/ImguiGraphHelper.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef BLK_ENABLE_STATS 4 | 5 | namespace Boolka 6 | { 7 | 8 | class [[nodiscard]] ImguiGraphHelper 9 | { 10 | public: 11 | ImguiGraphHelper(); 12 | ~ImguiGraphHelper() = default; 13 | 14 | void PushValue(float value); 15 | void CalculateMinMaxAvg(float& minValue, float& maxValue, float& avgValue); 16 | void Render(float minValue, float maxValue, float width, float height); 17 | void PushValueAndRender(float value, const char* header, float width, float height); 18 | 19 | static const size_t ms_HistoryCount = 300; 20 | 21 | private: 22 | float m_HistoryBuffer[ms_HistoryCount]; 23 | }; 24 | 25 | } // namespace Boolka 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /D3D12Backend/FeatureSupportHelper.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Boolka 4 | { 5 | 6 | class Device; 7 | 8 | class FeatureSupportHelper 9 | { 10 | public: 11 | [[nodiscard]] static bool HasPreferredFeatures(ID3D12Device* device); 12 | [[nodiscard]] static bool IsSupported(ID3D12Device* device); 13 | [[nodiscard]] static bool SupportRaytracing(ID3D12Device* device); 14 | }; 15 | 16 | } // namespace Boolka 17 | -------------------------------------------------------------------------------- /D3D12Backend/HLSLShared.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Boolka 4 | { 5 | namespace HLSLShared 6 | { 7 | #include "D3D12Backend/Shaders/CppShared.hlsli" 8 | } 9 | } // namespace Boolka 10 | -------------------------------------------------------------------------------- /D3D12Backend/ProjectConfig.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if defined(BLK_CONFIGURATION_DEBUG) 4 | #define BLK_RENDER_DEBUG 5 | #define BLK_RENDER_DEVICE_LOST_DEBUG 6 | #define BLK_RENDER_PROFILING 7 | #define BLK_USE_GPU_VALIDATION 8 | #elif defined(BLK_CONFIGURATION_DEVELOPMENT) 9 | #define BLK_RENDER_DEVICE_LOST_DEBUG 10 | #define BLK_RENDER_PROFILING 11 | #else 12 | #define BLK_RENDER_DEVICE_LOST_DEBUG 13 | #endif 14 | 15 | #ifdef BLK_RENDER_PROFILING 16 | #define BLK_USE_PIX_MARKERS 17 | #endif 18 | 19 | #ifdef BLK_USE_PIX_MARKERS 20 | #define USE_PIX 21 | #endif 22 | 23 | #define BLK_ENABLE_RTAS_CACHE 24 | 25 | // Concatenates BLK_ENGINE_NAME which is a string with " Window Class" 26 | #define BLK_WINDOW_CLASS_NAME (BLK_ENGINE_NAME L" Window Class") 27 | 28 | #define BLK_D3D12_SEMANTIC_MAX_LENGTH 32 29 | 30 | #define BLK_MAX_LIGHT_COUNT 4 31 | #define BLK_SUN_SHADOWMAP_SIZE 8192 32 | #define BLK_LIGHT_SHADOWMAP_SIZE 1024 33 | 34 | #define BLK_USE_COMMON_STATE_PROMOTION 35 | -------------------------------------------------------------------------------- /D3D12Backend/RenderBackend.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #include "RenderBackend.h" 4 | 5 | #include "RenderBackendImpl.h" 6 | 7 | namespace Boolka 8 | { 9 | 10 | RenderBackend* RenderBackend::CreateRenderBackend() 11 | { 12 | return new RenderBackendImpl(); 13 | } 14 | 15 | void RenderBackend::DeleteRenderBackend(RenderBackend* object) 16 | { 17 | delete object; 18 | } 19 | 20 | } // namespace Boolka 21 | -------------------------------------------------------------------------------- /D3D12Backend/RenderBackend.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Boolka 4 | { 5 | 6 | class [[nodiscard]] RenderBackend 7 | { 8 | public: 9 | virtual ~RenderBackend() = default; 10 | 11 | virtual bool Initialize(const wchar_t* folderPath) = 0; 12 | virtual void Unload() = 0; 13 | virtual bool Present() = 0; 14 | virtual bool RenderFrame() = 0; 15 | 16 | [[nodiscard]] static RenderBackend* CreateRenderBackend(); 17 | static void DeleteRenderBackend(RenderBackend* object); 18 | virtual void UnloadScene() = 0; 19 | }; 20 | 21 | } // namespace Boolka 22 | -------------------------------------------------------------------------------- /D3D12Backend/RenderBackendImpl.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "APIWrappers/Device.h" 3 | #include "APIWrappers/DirectStorage/DStorageFactory.h" 4 | #include "APIWrappers/Factory.h" 5 | #include "APIWrappers/RenderDebug.h" 6 | #include "RenderBackend.h" 7 | #include "RenderSchedule/RenderSchedule.h" 8 | #include "WindowManagement/DisplayController.h" 9 | 10 | namespace Boolka 11 | { 12 | 13 | class [[nodiscard]] RenderBackendImpl : public RenderBackend 14 | { 15 | public: 16 | RenderBackendImpl(); 17 | ~RenderBackendImpl(); 18 | 19 | bool Initialize(const wchar_t* folderPath) final; 20 | void Unload() final; 21 | bool Present() final; 22 | bool RenderFrame() final; 23 | void UnloadScene() final; 24 | 25 | private: 26 | RenderDebug m_Debug; 27 | Factory m_Factory; 28 | Device m_Device; 29 | DisplayController m_DisplayController; 30 | RenderSchedule m_RenderSchedule; 31 | Fence m_FrameFence; 32 | UINT64 m_FrameID; 33 | 34 | #ifdef BLK_RENDER_DEBUG 35 | void ReportD3DObjectLeaks(); 36 | #endif 37 | }; 38 | 39 | } // namespace Boolka 40 | -------------------------------------------------------------------------------- /D3D12Backend/RenderPass.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Boolka 4 | { 5 | class Device; 6 | class RenderContext; 7 | class ResourceTracker; 8 | 9 | class RenderPass 10 | { 11 | public: 12 | RenderPass() = default; 13 | virtual ~RenderPass() = default; 14 | 15 | virtual bool PrepareRendering() = 0; 16 | virtual bool Render(RenderContext& renderContext, ResourceTracker& resourceTracker) = 0; 17 | 18 | virtual bool Initialize(Device& device, RenderContext& renderContext) = 0; 19 | virtual void Unload() = 0; 20 | }; 21 | 22 | } // namespace Boolka 23 | -------------------------------------------------------------------------------- /D3D12Backend/RenderPasses/DebugOverlayPass.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "APIWrappers/DescriptorHeap.h" 3 | #include "Contexts/FrameStats.h" 4 | #include "DebugHelpers/ImguiGraphHelper.h" 5 | #include "RenderPass.h" 6 | 7 | #ifdef BLK_ENABLE_STATS 8 | 9 | namespace Boolka 10 | { 11 | 12 | class [[nodiscard]] DebugOverlayPass : public RenderPass 13 | { 14 | public: 15 | DebugOverlayPass(); 16 | ~DebugOverlayPass(); 17 | 18 | bool Initialize(Device& device, RenderContext& renderContext) final; 19 | void Unload() final; 20 | 21 | bool Render(RenderContext& renderContext, ResourceTracker& resourceTracker) final; 22 | bool PrepareRendering() final; 23 | 24 | private: 25 | void ImguiFlipFrame(); 26 | void ImguiUIManagement(const RenderContext& renderContext); 27 | 28 | void ImguiHelpWindow(); 29 | void ImguiDebugWindow(const RenderContext& renderContext); 30 | void ImguiStatsWindow(const RenderContext& renderContext); 31 | void ImguiHardwareWindow(); 32 | 33 | void ImguiCullingTable(const RenderContext& renderContext); 34 | void ImguiGPUDebugMarkers(const RenderContext& renderContext); 35 | void ImguiUIGPUTimes(const RenderContext& renderContext); 36 | void ImguiGraphs(const RenderContext& renderContext); 37 | 38 | DescriptorHeap m_ImguiDescriptorHeap; 39 | 40 | float m_ScaleFactor; 41 | bool m_IsEnabled; 42 | 43 | bool m_GPUSupportsRaytracing; 44 | 45 | ImguiGraphHelper m_FPSGraph; 46 | ImguiGraphHelper m_FrameTimeGraph; 47 | ImguiGraphHelper m_GPUTime; 48 | 49 | ImguiGraphHelper m_GPUPassGraphs[ARRAYSIZE(FrameStats::GPUTimes::Markers)]; 50 | }; 51 | 52 | } // namespace Boolka 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /D3D12Backend/RenderPasses/DeferredLightingPass.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "APIWrappers/PipelineState/GraphicPipelineState.h" 3 | #include "RenderPass.h" 4 | 5 | namespace Boolka 6 | { 7 | 8 | class [[nodiscard]] DeferredLightingPass : public RenderPass 9 | { 10 | public: 11 | DeferredLightingPass() = default; 12 | ~DeferredLightingPass() = default; 13 | 14 | bool Initialize(Device& device, RenderContext& renderContext) final; 15 | void Unload() final; 16 | 17 | bool Render(RenderContext& renderContext, ResourceTracker& resourceTracker) final; 18 | bool PrepareRendering() final; 19 | 20 | private: 21 | }; 22 | 23 | } // namespace Boolka 24 | -------------------------------------------------------------------------------- /D3D12Backend/RenderPasses/GBufferRenderPass.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "APIWrappers/PipelineState/GraphicPipelineState.h" 3 | #include "Camera.h" 4 | #include "RenderPass.h" 5 | 6 | namespace Boolka 7 | { 8 | 9 | class [[nodiscard]] GBufferRenderPass : public RenderPass 10 | { 11 | public: 12 | GBufferRenderPass() = default; 13 | ~GBufferRenderPass() = default; 14 | 15 | bool Initialize(Device& device, RenderContext& renderContext) final; 16 | void Unload() final; 17 | 18 | bool Render(RenderContext& renderContext, ResourceTracker& resourceTracker) final; 19 | bool PrepareRendering() final; 20 | 21 | private: 22 | }; 23 | 24 | } // namespace Boolka 25 | -------------------------------------------------------------------------------- /D3D12Backend/RenderPasses/GPUCullingRenderPass.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "APIWrappers/PipelineState/ComputePipelineState.h" 3 | #include "RenderPass.h" 4 | 5 | namespace Boolka 6 | { 7 | 8 | class [[nodiscard]] GPUCullingRenderPass : public RenderPass 9 | { 10 | public: 11 | GPUCullingRenderPass() = default; 12 | ~GPUCullingRenderPass() = default; 13 | 14 | bool Initialize(Device& device, RenderContext& renderContext) final; 15 | void Unload() final; 16 | 17 | bool Render(RenderContext& renderContext, ResourceTracker& resourceTracker) final; 18 | bool PrepareRendering() final; 19 | 20 | private: 21 | #ifdef BLK_ENABLE_STATS 22 | ReadbackBuffer m_CulledCountBuffer[BLK_IN_FLIGHT_FRAMES]; 23 | #endif 24 | }; 25 | 26 | } // namespace Boolka 27 | -------------------------------------------------------------------------------- /D3D12Backend/RenderPasses/PresentPass.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #include "PresentPass.h" 4 | 5 | namespace Boolka 6 | { 7 | 8 | bool PresentPass::Initialize(Device& device, RenderContext& renderContext) 9 | { 10 | return true; 11 | } 12 | 13 | void PresentPass::Unload() 14 | { 15 | } 16 | 17 | bool PresentPass::Render(RenderContext& renderContext, ResourceTracker& resourceTracker) 18 | { 19 | BLK_RENDER_PASS_START(PresentPass); 20 | 21 | auto [engineContext, frameContext, threadContext] = renderContext.GetContexts(); 22 | auto& resourceContainer = engineContext.GetResourceContainer(); 23 | 24 | GraphicCommandListImpl& commandList = threadContext.GetGraphicCommandList(); 25 | 26 | UINT frameIndex = frameContext.GetFrameIndex(); 27 | resourceTracker.Transition(resourceContainer.GetBackBuffer(frameIndex), commandList, 28 | D3D12_RESOURCE_STATE_PRESENT); 29 | 30 | engineContext.GetTimestampContainer().Mark(commandList, 31 | TimestampContainer::Markers::EndFrame); 32 | engineContext.GetTimestampContainer().FinishFrame(commandList, renderContext, frameIndex); 33 | 34 | return true; 35 | } 36 | 37 | bool PresentPass::PrepareRendering() 38 | { 39 | return true; 40 | } 41 | 42 | } // namespace Boolka 43 | -------------------------------------------------------------------------------- /D3D12Backend/RenderPasses/PresentPass.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "RenderPass.h" 3 | 4 | namespace Boolka 5 | { 6 | 7 | class [[nodiscard]] PresentPass : public RenderPass 8 | { 9 | public: 10 | PresentPass() = default; 11 | ~PresentPass() = default; 12 | 13 | bool Initialize(Device& device, RenderContext& renderContext) final; 14 | void Unload() final; 15 | 16 | bool Render(RenderContext& renderContext, ResourceTracker& resourceTracker) final; 17 | bool PrepareRendering() final; 18 | 19 | private: 20 | }; 21 | 22 | } // namespace Boolka 23 | -------------------------------------------------------------------------------- /D3D12Backend/RenderPasses/RaytraceRenderPass.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "APIWrappers/PipelineState/StateObject.h" 3 | #include "Containers/ShaderTable.h" 4 | #include "RenderPass.h" 5 | 6 | namespace Boolka 7 | { 8 | 9 | // Used for Reflection and Refraction 10 | class [[nodiscard]] RaytraceRenderPass : public RenderPass 11 | { 12 | public: 13 | RaytraceRenderPass() = default; 14 | ~RaytraceRenderPass() = default; 15 | 16 | bool Initialize(Device& device, RenderContext& renderContext) final; 17 | void Unload() final; 18 | 19 | bool Render(RenderContext& renderContext, ResourceTracker& resourceTracker) final; 20 | bool PrepareRendering() final; 21 | 22 | private: 23 | bool m_Enabled; 24 | }; 25 | 26 | } // namespace Boolka 27 | -------------------------------------------------------------------------------- /D3D12Backend/RenderPasses/ReferenceRenderPass.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #include "ReferenceRenderPass.h" 4 | 5 | namespace Boolka 6 | { 7 | 8 | bool ReferenceRenderPass::Render(RenderContext& renderContext, ResourceTracker& resourceTracker) 9 | { 10 | // Uncomment and replace class name when creating new RenderPass 11 | // Also add new class to TimestampContainer::Markers 12 | // BLK_RENDER_PASS_START(ReferenceRenderPass); 13 | 14 | auto [engineContext, frameContext, threadContext] = renderContext.GetContexts(); 15 | auto& resourceContainer = engineContext.GetResourceContainer(); 16 | 17 | UINT frameIndex = frameContext.GetFrameIndex(); 18 | 19 | Buffer& frameConstantBuffer = resourceContainer.GetBuffer(ResourceContainer::Buf::Frame); 20 | BLK_UNUSED_VARIABLE(frameConstantBuffer); // Remove when creating new RenderPass 21 | 22 | GraphicCommandListImpl& commandList = threadContext.GetGraphicCommandList(); 23 | BLK_UNUSED_VARIABLE(commandList); // Remove when creating new RenderPass 24 | 25 | return true; 26 | } 27 | 28 | bool ReferenceRenderPass::PrepareRendering() 29 | { 30 | throw std::logic_error("The method or operation is not implemented."); 31 | } 32 | 33 | bool ReferenceRenderPass::Initialize(Device& device, RenderContext& renderContext) 34 | { 35 | auto [engineContext, frameContext, threadContext] = renderContext.GetContexts(); 36 | auto& resourceContainer = engineContext.GetResourceContainer(); 37 | auto& defaultRootSig = 38 | resourceContainer.GetRootSignature(ResourceContainer::RootSig::Default); 39 | BLK_UNUSED_VARIABLE(defaultRootSig); // Remove when creating new RenderPass 40 | 41 | return true; 42 | } 43 | 44 | void ReferenceRenderPass::Unload() 45 | { 46 | } 47 | 48 | } // namespace Boolka -------------------------------------------------------------------------------- /D3D12Backend/RenderPasses/ReferenceRenderPass.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "RenderPass.h" 3 | 4 | // Use this file as reference when creating new render passes 5 | 6 | namespace Boolka 7 | { 8 | 9 | class [[nodiscard]] ReferenceRenderPass : public RenderPass 10 | { 11 | public: 12 | ReferenceRenderPass() = default; 13 | ~ReferenceRenderPass() = default; 14 | 15 | bool Initialize(Device& device, RenderContext& renderContext) final; 16 | void Unload() final; 17 | 18 | bool Render(RenderContext& renderContext, ResourceTracker& resourceTracker) final; 19 | bool PrepareRendering() final; 20 | 21 | private: 22 | }; 23 | 24 | } // namespace Boolka 25 | -------------------------------------------------------------------------------- /D3D12Backend/RenderPasses/ShadowMapRenderPass.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "APIWrappers/PipelineState/GraphicPipelineState.h" 3 | #include "RenderPass.h" 4 | 5 | namespace Boolka 6 | { 7 | 8 | class [[nodiscard]] ShadowMapRenderPass : public RenderPass 9 | { 10 | public: 11 | ShadowMapRenderPass() = default; 12 | ~ShadowMapRenderPass() = default; 13 | 14 | bool Initialize(Device& device, RenderContext& renderContext) final; 15 | void Unload() final; 16 | 17 | bool Render(RenderContext& renderContext, ResourceTracker& resourceTracker) final; 18 | bool PrepareRendering() final; 19 | 20 | private: 21 | }; 22 | 23 | } // namespace Boolka 24 | -------------------------------------------------------------------------------- /D3D12Backend/RenderPasses/SkyBoxRenderPass.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "APIWrappers/PipelineState/GraphicPipelineState.h" 3 | #include "RenderPass.h" 4 | 5 | // Use this file as reference when creating new render passes 6 | 7 | namespace Boolka 8 | { 9 | 10 | class [[nodiscard]] SkyBoxRenderPass : public RenderPass 11 | { 12 | public: 13 | SkyBoxRenderPass() = default; 14 | ~SkyBoxRenderPass() = default; 15 | 16 | bool Initialize(Device& device, RenderContext& renderContext) final; 17 | void Unload() final; 18 | 19 | bool Render(RenderContext& renderContext, ResourceTracker& resourceTracker) final; 20 | bool PrepareRendering() final; 21 | 22 | private: 23 | }; 24 | 25 | } // namespace Boolka 26 | -------------------------------------------------------------------------------- /D3D12Backend/RenderPasses/ToneMappingPass.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "APIWrappers/PipelineState/GraphicPipelineState.h" 3 | #include "RenderPass.h" 4 | 5 | namespace Boolka 6 | { 7 | 8 | class [[nodiscard]] ToneMappingPass : public RenderPass 9 | { 10 | public: 11 | ToneMappingPass() = default; 12 | ~ToneMappingPass() = default; 13 | 14 | bool Initialize(Device& device, RenderContext& renderContext) final; 15 | void Unload() final; 16 | 17 | bool Render(RenderContext& renderContext, ResourceTracker& resourceTracker) final; 18 | bool PrepareRendering() final; 19 | 20 | private: 21 | }; 22 | 23 | } // namespace Boolka 24 | -------------------------------------------------------------------------------- /D3D12Backend/RenderPasses/TransparentRenderPass.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "APIWrappers/PipelineState/GraphicPipelineState.h" 3 | #include "RenderPass.h" 4 | 5 | namespace Boolka 6 | { 7 | 8 | class [[nodiscard]] TransparentRenderPass : public RenderPass 9 | { 10 | public: 11 | TransparentRenderPass() = default; 12 | ~TransparentRenderPass() = default; 13 | 14 | bool Initialize(Device& device, RenderContext& renderContext) final; 15 | void Unload() final; 16 | 17 | bool Render(RenderContext& renderContext, ResourceTracker& resourceTracker) final; 18 | bool PrepareRendering() final; 19 | 20 | private: 21 | }; 22 | 23 | } // namespace Boolka 24 | -------------------------------------------------------------------------------- /D3D12Backend/RenderPasses/UpdateRenderPass.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "RenderPass.h" 3 | 4 | namespace Boolka 5 | { 6 | 7 | class [[nodiscard]] UpdateRenderPass : public RenderPass 8 | { 9 | public: 10 | UpdateRenderPass() = default; 11 | ~UpdateRenderPass() = default; 12 | 13 | bool Initialize(Device& device, RenderContext& renderContext) final; 14 | void Unload() final; 15 | 16 | bool Render(RenderContext& renderContext, ResourceTracker& resourceTracker) final; 17 | bool PrepareRendering() final; 18 | 19 | private: 20 | void UploadFrameConstantBuffer(RenderContext& renderContext, 21 | ResourceTracker& resourceTracker); 22 | void UploadLightingConstantBuffer(RenderContext& renderContext, 23 | ResourceTracker& resourceTracker); 24 | void UploadCullingConstantBuffer(RenderContext& renderContext, 25 | ResourceTracker& resourceTracker); 26 | void ReadbackHelperBuffers(RenderContext& renderContext, ResourceTracker& resourceTracker); 27 | 28 | ReadbackBuffer m_ReadbackBuffers[BLK_IN_FLIGHT_FRAMES]; 29 | }; 30 | 31 | } // namespace Boolka 32 | -------------------------------------------------------------------------------- /D3D12Backend/RenderPasses/ZRenderPass.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "APIWrappers/PipelineState/GraphicPipelineState.h" 3 | #include "RenderPass.h" 4 | 5 | namespace Boolka 6 | { 7 | 8 | class [[nodiscard]] ZRenderPass : public RenderPass 9 | { 10 | public: 11 | ZRenderPass() = default; 12 | ~ZRenderPass() = default; 13 | 14 | bool Initialize(Device& device, RenderContext& renderContext) final; 15 | void Unload() final; 16 | 17 | bool Render(RenderContext& renderContext, ResourceTracker& resourceTracker) final; 18 | bool PrepareRendering() final; 19 | 20 | private: 21 | }; 22 | 23 | } // namespace Boolka 24 | -------------------------------------------------------------------------------- /D3D12Backend/RenderSchedule/ResourceTracker.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "APIWrappers/RootSignature.h" 3 | 4 | namespace Boolka 5 | { 6 | 7 | class Device; 8 | class Resource; 9 | class Texture2D; 10 | class CommandList; 11 | class RenderTargetView; 12 | 13 | class [[nodiscard]] ResourceTracker 14 | { 15 | public: 16 | ResourceTracker() = default; 17 | ~ResourceTracker(); 18 | 19 | bool Initialize(Device& device, size_t expectedResources); 20 | void Unload(); 21 | 22 | void RegisterResource(Resource& resource, D3D12_RESOURCE_STATES initialState); 23 | bool Transition(Resource& resource, CommandList& commandList, 24 | D3D12_RESOURCE_STATES targetState); 25 | 26 | #ifdef BLK_RENDER_DEBUG 27 | void ValidateStates(CommandList& commandList); 28 | #endif 29 | 30 | void Decay(); 31 | 32 | private: 33 | std::unordered_map m_TrackedResources; 34 | }; 35 | 36 | } // namespace Boolka 37 | -------------------------------------------------------------------------------- /D3D12Backend/Shaders/Color.hlsli: -------------------------------------------------------------------------------- 1 | #ifndef __COLOR_HLSLI__ 2 | #define __COLOR_HLSLI__ 3 | 4 | float LinearToSRGB(float linearColor) 5 | { 6 | return (linearColor < 0.0031308 ? linearColor * 12.92 7 | : 1.055 * pow(linearColor, 0.41666) - 0.055); 8 | } 9 | 10 | float SRGBToLinear(float srgbColor) 11 | { 12 | return (srgbColor <= 0.04045) ? srgbColor / 12.92 : pow((srgbColor + 0.055) / 1.055, 2.4); 13 | } 14 | 15 | float3 LinearToSRGB(float3 linearColor) 16 | { 17 | return float3(LinearToSRGB(linearColor.r), LinearToSRGB(linearColor.g), 18 | LinearToSRGB(linearColor.b)); 19 | } 20 | 21 | float3 SRGBToLinear(float3 srgbColor) 22 | { 23 | return float3(SRGBToLinear(srgbColor.r), SRGBToLinear(srgbColor.g), SRGBToLinear(srgbColor.b)); 24 | } 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /D3D12Backend/Shaders/Common.hlsli: -------------------------------------------------------------------------------- 1 | #ifndef __COMMON_HLSLI__ 2 | #define __COMMON_HLSLI__ 3 | 4 | #include "CppShared.hlsli" 5 | #include "ResourceBindings.hlsli" 6 | 7 | #define FLT_MAX 3.402823466e+38F 8 | 9 | bool IntersectionFrustumAABB(const in Frustum currentFrustum, const in AABB boundingBox) 10 | { 11 | [unroll(6)] for (int i = 0; i < 6; ++i) 12 | { 13 | float4 mask = (currentFrustum.planes[i] > float4(0, 0, 0, 0)); 14 | float4 min = lerp(boundingBox.min, boundingBox.max, mask); 15 | float dotMin = dot(currentFrustum.planes[i], min); 16 | 17 | if (dotMin < 0) 18 | return false; 19 | }; 20 | 21 | return true; 22 | } 23 | 24 | bool IntersectionFrustumSphere(const in Frustum currentFrustum, const in float4 sphere) 25 | { 26 | float4 center = float4(sphere.xyz, 1.0f); 27 | float radius = sphere.w; 28 | 29 | [unroll(6)] for (int i = 0; i < 6; ++i) 30 | { 31 | if (dot(currentFrustum.planes[i], center) < -radius) 32 | return false; 33 | }; 34 | 35 | return true; 36 | } 37 | 38 | // Only works for positive numbers, doesn't expect 0 39 | uint CeilToNextPowerOfTwo(uint value) 40 | { 41 | uint rounded = 1l << (firstbithigh(value - 1) + 1); 42 | return rounded; 43 | } 44 | 45 | void DebugIncrementCounter(uint marker) 46 | { 47 | uint dummy; 48 | InterlockedAdd(debugMarkers[marker], 1, dummy); 49 | } 50 | 51 | void DebugSetData(uint marker, uint data) 52 | { 53 | debugMarkers[marker] = data; 54 | } 55 | 56 | void DebugSetData(uint marker, float data) 57 | { 58 | debugMarkers[marker] = asuint(data); 59 | } 60 | 61 | void ProfileSetData(uint offset, uint data) 62 | { 63 | profileMetrics[offset] = data; 64 | } 65 | 66 | void ProfileSetData(uint offset, float data) 67 | { 68 | profileMetrics[offset] = asuint(data); 69 | } 70 | 71 | #include "ResourceBindings.hlsli" 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /D3D12Backend/Shaders/Debug3DPass/Debug3DPassPixelShader.hlsl: -------------------------------------------------------------------------------- 1 | #include "Debug3DPassShadersCommon.hlsli" 2 | 3 | PSOut main(VSOut In) 4 | { 5 | PSOut Out = (PSOut)0; 6 | Out.color = float4(In.color, 1.0f); 7 | return Out; 8 | } 9 | -------------------------------------------------------------------------------- /D3D12Backend/Shaders/Debug3DPass/Debug3DPassShadersCommon.hlsli: -------------------------------------------------------------------------------- 1 | struct VSIn 2 | { 3 | float3 position : POSITION; 4 | float3 color : COLOR; 5 | float4x4 worldMatrix : WORLD_MATRIX; 6 | }; 7 | 8 | struct VSOut 9 | { 10 | float4 position : SV_Position; 11 | float3 color : COLOR; 12 | }; 13 | 14 | struct PSOut 15 | { 16 | float4 color : SV_Target; 17 | }; 18 | 19 | cbuffer PerFrame : register(b0) 20 | { 21 | float4x4 viewProjectionMatrix; 22 | }; 23 | -------------------------------------------------------------------------------- /D3D12Backend/Shaders/Debug3DPass/Debug3DPassVertexShader.hlsl: -------------------------------------------------------------------------------- 1 | #include "Debug3DPassShadersCommon.hlsli" 2 | 3 | VSOut main(VSIn In) 4 | { 5 | VSOut Out = (VSOut)0; 6 | Out.position = mul(mul(float4(In.position, 1.0f), In.worldMatrix), viewProjectionMatrix); 7 | Out.color = In.color; 8 | return Out; 9 | } 10 | -------------------------------------------------------------------------------- /D3D12Backend/Shaders/DebugMeshPass/DebugMeshPassMeshShader.hlsl: -------------------------------------------------------------------------------- 1 | #include "DebugMeshPassShadersCommon.hlsli" 2 | 3 | [NumThreads(1, 1, 1)] 4 | [OutputTopology("triangle")] 5 | void main(out vertices VSOut vertices[3], 6 | out indices uint3 triangles[1]) 7 | { 8 | SetMeshOutputCounts(3, 1); 9 | 10 | static const float a = 0.8f; 11 | static const float2 positions[3] = 12 | { 13 | float2(-sqrt(3.0f) / 2.0f * a, -a / 2.0f), 14 | float2(sqrt(3.0f) / 2.0f * a, -a / 2.0f), 15 | float2(0.0f, a) 16 | }; 17 | 18 | vertices[0].position = float4(mul(positions[0], vertexToScreen), 1, 1); 19 | vertices[0].color = float4(1, 0, 0, 0); 20 | vertices[1].position = float4(mul(positions[1], vertexToScreen), 1, 1); 21 | vertices[1].color = float4(0, 1, 0, 0); 22 | vertices[2].position = float4(mul(positions[2], vertexToScreen), 1, 1); 23 | vertices[2].color = float4(0, 0, 1, 0); 24 | 25 | triangles[0] = uint3(0, 1, 2); 26 | } -------------------------------------------------------------------------------- /D3D12Backend/Shaders/DebugMeshPass/DebugMeshPassPixelShader.hlsl: -------------------------------------------------------------------------------- 1 | #include "DebugMeshPassShadersCommon.hlsli" 2 | 3 | PSOut main(VSOut In) 4 | { 5 | PSOut Out = (PSOut)0; 6 | Out.color = In.color; 7 | return Out; 8 | } 9 | -------------------------------------------------------------------------------- /D3D12Backend/Shaders/DebugMeshPass/DebugMeshPassShadersCommon.hlsli: -------------------------------------------------------------------------------- 1 | struct VSOut 2 | { 3 | float4 position : SV_Position; 4 | float4 color : COLOR; 5 | }; 6 | 7 | struct PSOut 8 | { 9 | float4 color : SV_Target; 10 | }; 11 | 12 | cbuffer PerFrame : register(b0) 13 | { 14 | float4 vertexToScreenPacked; 15 | }; 16 | 17 | static float2x2 vertexToScreen = {{vertexToScreenPacked[0], vertexToScreenPacked[1]}, 18 | {vertexToScreenPacked[2], vertexToScreenPacked[3]}}; 19 | -------------------------------------------------------------------------------- /D3D12Backend/Shaders/DebugPass/DebugPassPixelShader.hlsl: -------------------------------------------------------------------------------- 1 | #include "DebugPassShadersCommon.hlsli" 2 | 3 | PSOut main(VSOut In) 4 | { 5 | PSOut Out = (PSOut)0; 6 | Out.color = In.color; 7 | return Out; 8 | } 9 | -------------------------------------------------------------------------------- /D3D12Backend/Shaders/DebugPass/DebugPassShadersCommon.hlsli: -------------------------------------------------------------------------------- 1 | struct VSIn 2 | { 3 | float4 position : POSITION; 4 | float4 color : COLOR; 5 | }; 6 | 7 | struct VSOut 8 | { 9 | float4 position : SV_Position; 10 | float4 color : COLOR; 11 | }; 12 | 13 | struct PSOut 14 | { 15 | float4 color : SV_Target; 16 | }; 17 | 18 | cbuffer PerFrame : register(b0) 19 | { 20 | float4 vertexToScreenPacked; 21 | }; 22 | 23 | static float2x2 vertexToScreen = {{vertexToScreenPacked[0], vertexToScreenPacked[1]}, 24 | {vertexToScreenPacked[2], vertexToScreenPacked[3]}}; 25 | -------------------------------------------------------------------------------- /D3D12Backend/Shaders/DebugPass/DebugPassVertexShader.hlsl: -------------------------------------------------------------------------------- 1 | #include "DebugPassShadersCommon.hlsli" 2 | 3 | VSOut main(VSIn In) 4 | { 5 | VSOut Out = (VSOut)0; 6 | Out.position = float4(mul(In.position.xy, vertexToScreen), 1.0f, 1.0f); 7 | Out.color = In.color; 8 | return Out; 9 | } 10 | -------------------------------------------------------------------------------- /D3D12Backend/Shaders/DeferredLightingPass/DeferredLightingPassPS.hlsl: -------------------------------------------------------------------------------- 1 | #include "../Color.hlsli" 2 | #include "../TransformCommon.hlsli" 3 | #include "../FullScreen/FullScreenCommon.hlsli" 4 | #include "../LightingLibrary/Lighting.hlsli" 5 | 6 | struct PSOut 7 | { 8 | float4 light : SV_Target; 9 | }; 10 | 11 | PSOut main(VSOut In) 12 | { 13 | PSOut Out = (PSOut)0; 14 | 15 | float2 UV = In.texcoord; 16 | uint2 vpos = uint2(In.position.xy); 17 | float3 albedoVal = SRGBToLinear(albedo.Load(uint3(vpos, 0)).rgb); 18 | float4 normalVal = normal.Load(uint3(vpos, 0)); 19 | float3 rtVal = raytraceResults.Load(uint3(vpos, 0)).rgb; 20 | float depthVal = depth.Load(uint3(vpos, 0)); 21 | 22 | float3 normal = normalVal.xyz; 23 | uint materialID = uint(normalVal.w); 24 | 25 | if (depthVal == 1.0f) // Far plane 26 | discard; // Skip writting to RT, SkyBox will overwrite it 27 | 28 | float3 viewPos = CalculateViewPos(UV, depthVal); 29 | float3 viewDir = normalize(viewPos); 30 | 31 | MaterialData matData = materialsData[materialID]; 32 | Out.light = float4(CalculateLighting(matData, albedoVal, albedoVal, normal, viewPos, viewDir), 0.0f); 33 | if (matData.specularExp > 200.0f) 34 | Out.light += float4(rtVal, 0.0f); 35 | 36 | return Out; 37 | } 38 | -------------------------------------------------------------------------------- /D3D12Backend/Shaders/FullScreen/FullScreenCommon.hlsli: -------------------------------------------------------------------------------- 1 | #include "../Common.hlsli" 2 | 3 | struct VSIn 4 | { 5 | uint vertexID : SV_VertexID; 6 | }; 7 | 8 | struct VSOut 9 | { 10 | float4 position : SV_Position; 11 | float2 texcoord : TexCoord0; 12 | }; 13 | -------------------------------------------------------------------------------- /D3D12Backend/Shaders/FullScreen/FullScreenVS.hlsl: -------------------------------------------------------------------------------- 1 | 2 | #include "FullScreenCommon.hlsli" 3 | 4 | VSOut main(VSIn In) 5 | { 6 | VSOut Out = (VSOut)0; 7 | Out.texcoord = float2(In.vertexID & 2, (In.vertexID << 1) & 2); 8 | Out.position = float4(Out.texcoord * float2(2.0f, -2.0f) + float2(-1.0f, 1.0f), 1.0f, 1.0f); 9 | return Out; 10 | } 11 | -------------------------------------------------------------------------------- /D3D12Backend/Shaders/GBufferPass/GBufferPassPixelShader.hlsl: -------------------------------------------------------------------------------- 1 | #include "../MeshCommon.hlsli" 2 | 3 | struct PSOut 4 | { 5 | float4 color : SV_Target0; 6 | float4 normal : SV_Target1; 7 | }; 8 | 9 | PSOut main(Vertex In) 10 | { 11 | PSOut Out = (PSOut)0; 12 | Out.color = sceneTextures[In.materialID].Sample(anisoSampler, In.texcoord.xy); 13 | Out.normal = float4(In.normal, float(In.materialID)); 14 | return Out; 15 | } 16 | -------------------------------------------------------------------------------- /D3D12Backend/Shaders/MeshShaders/AmplificationShader.hlsl: -------------------------------------------------------------------------------- 1 | #include "../MeshCommon.hlsli" 2 | 3 | groupshared Payload payload; 4 | groupshared uint visibleCount; 5 | 6 | [numthreads(BLK_AS_GROUP_SIZE, 1, 1)] 7 | void main(uint GTiD : SV_GroupThreadID, uint GiD : SV_GroupID) 8 | { 9 | if (GTiD == 0) 10 | { 11 | visibleCount = 0; 12 | } 13 | GroupMemoryBarrierWithGroupSync(); 14 | 15 | uint mehsletIndex = gpuCullingMeshletIndices[GiD] + GTiD; 16 | bool isMeshletVisible = IsMeshletVisible(mehsletIndex, 0); 17 | uint waveVisibleIndex = WavePrefixCountBits(isMeshletVisible); 18 | uint waveVisibleCount = WaveActiveCountBits(isMeshletVisible); 19 | uint waveOffset; 20 | if (WaveIsFirstLane()) 21 | { 22 | InterlockedAdd(visibleCount, waveVisibleCount, waveOffset); 23 | } 24 | waveOffset = WaveReadLaneFirst(waveOffset); 25 | uint threadIndex = waveOffset + waveVisibleIndex; 26 | 27 | if (isMeshletVisible) 28 | { 29 | payload.meshletIndicies[threadIndex] = mehsletIndex; 30 | } 31 | 32 | GroupMemoryBarrierWithGroupSync(); 33 | DispatchMesh(visibleCount, 1, 1, payload); 34 | } 35 | -------------------------------------------------------------------------------- /D3D12Backend/Shaders/MeshShaders/MeshShader.hlsl: -------------------------------------------------------------------------------- 1 | #include "../MeshCommon.hlsli" 2 | 3 | [NumThreads(128, 1, 1)] 4 | [OutputTopology("triangle")] 5 | void main(uint gtid : SV_GroupThreadID, 6 | uint gid : SV_GroupID, 7 | in payload Payload payload, 8 | out vertices Vertex vertices[64], 9 | out indices uint3 triangles[126]) 10 | { 11 | MeshletData meshletData = GetMeshletData(payload, gid); 12 | 13 | SetMeshOutputCounts(meshletData.VertCount, meshletData.PrimCount); 14 | 15 | if (gtid < meshletData.VertCount) 16 | { 17 | vertices[gtid] = GetVertex(payload, meshletData, gtid); 18 | } 19 | 20 | if (gtid < meshletData.PrimCount) 21 | { 22 | triangles[gtid] = GetPrimitive(payload, meshletData, gtid); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /D3D12Backend/Shaders/ShadowMapPass/ShadowMapAmplificationShader.hlsl: -------------------------------------------------------------------------------- 1 | #include "../MeshCommon.hlsli" 2 | 3 | groupshared Payload payload; 4 | groupshared uint visibleCount; 5 | 6 | [numthreads(BLK_AS_GROUP_SIZE, 1, 1)] 7 | void main(uint GTiD : SV_GroupThreadID, uint GiD : SV_GroupID) 8 | { 9 | if (GTiD == 0) 10 | { 11 | visibleCount = 0; 12 | } 13 | GroupMemoryBarrierWithGroupSync(); 14 | uint viewIndex = viewIndexParam; 15 | 16 | uint mehsletIndex = gpuCullingMeshletIndicesUAV[BLM_MAX_AS_GROUPS * viewIndex + GiD] + GTiD; 17 | bool isMeshletVisible = IsMeshletVisible(mehsletIndex, viewIndex); 18 | uint waveVisibleIndex = WavePrefixCountBits(isMeshletVisible); 19 | uint waveVisibleCount = WaveActiveCountBits(isMeshletVisible); 20 | uint waveOffset; 21 | if (WaveIsFirstLane()) 22 | { 23 | InterlockedAdd(visibleCount, waveVisibleCount, waveOffset); 24 | } 25 | waveOffset = WaveReadLaneFirst(waveOffset); 26 | uint threadIndex = waveOffset + waveVisibleIndex; 27 | 28 | if (isMeshletVisible) 29 | { 30 | payload.meshletIndicies[threadIndex] = mehsletIndex; 31 | } 32 | 33 | GroupMemoryBarrierWithGroupSync(); 34 | DispatchMesh(visibleCount, 1, 1, payload); 35 | } 36 | -------------------------------------------------------------------------------- /D3D12Backend/Shaders/ShadowMapPass/ShadowMapPassMeshShader.hlsl: -------------------------------------------------------------------------------- 1 | #include "../MeshCommon.hlsli" 2 | 3 | Vertex GetVertexShadow(in const Payload payload, in const MeshletData meshletData, 4 | in uint vertexIndex) 5 | { 6 | Vertex Out = (Vertex)0; 7 | 8 | uint remappedVertexIndex = vertexIndirectionBuffer[meshletData.VertOffset + vertexIndex]; 9 | VertexData1 vertexData1 = vertexBuffer1[remappedVertexIndex]; 10 | 11 | uint viewIndex = viewIndexParam; 12 | Out.position = mul(float4(vertexData1.position, 1.0f), GPUCulling.viewProjMatrix[viewIndex]); 13 | 14 | return Out; 15 | } 16 | 17 | [NumThreads(128, 1, 1)] 18 | [OutputTopology("triangle")] 19 | void main(uint gtid : SV_GroupThreadID, 20 | uint gid : SV_GroupID, 21 | in payload Payload payload, 22 | out vertices Vertex vertices[64], 23 | out indices uint3 triangles[126]) 24 | { 25 | MeshletData meshletData = GetMeshletData(payload, gid); 26 | 27 | SetMeshOutputCounts(meshletData.VertCount, meshletData.PrimCount); 28 | 29 | if (gtid < meshletData.VertCount) 30 | { 31 | vertices[gtid] = GetVertexShadow(payload, meshletData, gtid); 32 | } 33 | 34 | if (gtid < meshletData.PrimCount) 35 | { 36 | triangles[gtid] = GetPrimitive(payload, meshletData, gtid); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /D3D12Backend/Shaders/SkyBoxPass/SkyBoxPassPixelShader.hlsl: -------------------------------------------------------------------------------- 1 | #include "../TransformCommon.hlsli" 2 | #include "../FullScreen/FullScreenCommon.hlsli" 3 | 4 | struct PSOut 5 | { 6 | float4 color : SV_Target0; 7 | }; 8 | 9 | PSOut main(VSOut In) 10 | { 11 | PSOut Out = (PSOut)0; 12 | 13 | float2 UV = In.texcoord; 14 | float3 viewPos = CalculateViewPos(UV, 1.0f); 15 | float3 viewDirWorld = mul(float4(viewPos, 0.0f), Frame.invViewMatrix).xyz; 16 | Out.color = skyBox.Sample(anisoSampler, viewDirWorld); 17 | return Out; 18 | } 19 | -------------------------------------------------------------------------------- /D3D12Backend/Shaders/ToneMappingPass/ToneMappingPassPS.hlsl: -------------------------------------------------------------------------------- 1 | #include "../Color.hlsli" 2 | #include "../FullScreen/FullScreenCommon.hlsli" 3 | 4 | struct PSOut 5 | { 6 | float4 color : SV_Target; 7 | }; 8 | 9 | // https://www.desmos.com/calculator/gslcdxvipg 10 | float GTTonemap(float x) 11 | { 12 | float P = 1.0f; 13 | float a = 1.0f; 14 | float m = 0.22f; 15 | float l = 0.4f; 16 | float c = 1.33f; 17 | float b = 0.0f; 18 | float l0 = (P - m) * l / a; 19 | float Lx = m + a * (x - m); 20 | float Tx = m * pow(x / m, c) + b; 21 | float S0 = m + l0; 22 | float S1 = m + a * l0; 23 | float C2 = a * P / (P - S1); 24 | float Sx = P - (P - S1) * exp(-C2 * (x - S0) / P); 25 | float w0 = 1.0f - smoothstep(0, m, x); 26 | float w2 = step(m + l0, x); 27 | float w1 = 1.0f - w0 - w2; 28 | return Tx * w0 + Lx * w1 + Sx * w2; 29 | } 30 | 31 | float3 GTTonemap(float3 c) 32 | { 33 | // Another option is to tonemap max from rgb components and scale others accordingly 34 | return float3(GTTonemap(c.r), GTTonemap(c.g), GTTonemap(c.b)); 35 | } 36 | 37 | float3 Tonemap(float3 c) 38 | { 39 | return LinearToSRGB(GTTonemap(c)); 40 | } 41 | 42 | PSOut main(VSOut In) 43 | { 44 | PSOut Out = (PSOut)0; 45 | 46 | uint2 vpos = uint2(In.position.xy); 47 | float4 light = lightBuffer.Load(uint3(vpos, 0)); 48 | Out.color = float4(Tonemap(light.rgb), 0.0f); 49 | return Out; 50 | } 51 | -------------------------------------------------------------------------------- /D3D12Backend/Shaders/TransformCommon.hlsli: -------------------------------------------------------------------------------- 1 | #ifndef __TRANSFORM_COMMON_HLSLI__ 2 | #define __TRANSFORM_COMMON_HLSLI__ 3 | 4 | #include "Common.hlsli" 5 | 6 | float3 CalculateViewPos(float2 UV, float depthVal) 7 | { 8 | float4 viewProjPos = float4(UV.x * 2.0f - 1.0f, UV.y * -2.0f + 1.0f, depthVal, 1.0f); 9 | float4 viewPos = mul(viewProjPos, Frame.invProjMatrix); 10 | return viewPos.xyz / viewPos.w; 11 | } 12 | 13 | float3 CalculateWorldPos(float3 viewPos) 14 | { 15 | return mul(float4(viewPos, 1.0f), Frame.invViewMatrix).xyz; 16 | } 17 | 18 | float3 CalculateWorldSpaceNormal(float3 vsNormal) 19 | { 20 | return normalize(mul(float4(vsNormal, 0.0f), Frame.invViewMatrix).xyz); 21 | } 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /D3D12Backend/Shaders/TransparentPass/TransparentPassPixelShader.hlsl: -------------------------------------------------------------------------------- 1 | #include "../Color.hlsli" 2 | #include "../MeshCommon.hlsli" 3 | 4 | struct PSOut 5 | { 6 | float4 color : SV_Target; 7 | }; 8 | 9 | PSOut main(Vertex In) 10 | { 11 | PSOut Out = (PSOut)0; 12 | Out.color = sceneTextures[In.materialID].Sample(anisoSampler, In.texcoord.xy); 13 | clip(Out.color.a == 0.0f ? -1 : 1); 14 | Out.color.rgb = SRGBToLinear(Out.color.rgb); 15 | return Out; 16 | } 17 | -------------------------------------------------------------------------------- /D3D12Backend/WindowManagement/DisplayController.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "APIWrappers/Resources/Textures/Texture2D.h" 3 | #include "APIWrappers/Swapchain.h" 4 | #include "WindowManager.h" 5 | 6 | namespace Boolka 7 | { 8 | 9 | class Factory; 10 | class Device; 11 | 12 | class [[nodiscard]] DisplayController 13 | { 14 | public: 15 | DisplayController(); 16 | ~DisplayController(); 17 | 18 | bool Initialize(Device& device, Factory& factory); 19 | void Unload(); 20 | 21 | [[nodiscard]] bool Present(); 22 | 23 | // returns true if something was updated, or false otherwise 24 | bool Update(Device& device); 25 | bool SetWindowState(const WindowState& newWindowState); 26 | 27 | [[nodiscard]] Texture2D& GetBuffer(UINT index); 28 | [[nodiscard]] UINT GetCurrentFrameIndex(); 29 | 30 | [[nodiscard]] const WindowState& GetWindowState(); 31 | [[nodiscard]] HWND GetHWND() const; 32 | 33 | private: 34 | WindowManager m_Window; 35 | Swapchain m_Swapchain; 36 | Texture2D m_BackBuffers[BLK_IN_FLIGHT_FRAMES]; 37 | WindowState m_WindowState; 38 | }; 39 | 40 | } // namespace Boolka 41 | -------------------------------------------------------------------------------- /D3D12Backend/WindowManagement/WindowManager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "WindowState.h" 3 | 4 | namespace Boolka 5 | { 6 | 7 | class [[nodiscard]] WindowManager 8 | { 9 | public: 10 | WindowManager(); 11 | ~WindowManager(); 12 | 13 | bool Initialize(const WindowState& windowState); 14 | void Unload(); 15 | 16 | bool Update(WindowState& stateToUpdate); 17 | 18 | [[nodiscard]] HWND GetHWND() const; 19 | 20 | void ShowWindow(bool show); 21 | 22 | private: 23 | // WindowThread only 24 | void WindowThreadEntryPoint(WindowState windowState); 25 | void InitializeThread(); 26 | void InitializeWindow(const WindowState& windowState); 27 | void MessageLoop(); 28 | [[nodiscard]] static LRESULT CALLBACK WindowProcDetour(HWND hwnd, UINT message, 29 | WPARAM wParam, LPARAM lParam); 30 | [[nodiscard]] LRESULT CALLBACK WindowProc(HWND hwnd, UINT message, WPARAM wParam, 31 | LPARAM lParam); 32 | 33 | // Helper functions 34 | [[nodiscard]] static DWORD CalculateWindowStyle(WindowState::WindowMode windowMode); 35 | 36 | HWND m_HWND; 37 | std::thread m_WindowThread; 38 | std::atomic m_IsUpdated; 39 | 40 | static HMODULE ms_CurrentInstance; 41 | static ATOM ms_WindowClass; 42 | }; 43 | 44 | } // namespace Boolka 45 | -------------------------------------------------------------------------------- /D3D12Backend/WindowManagement/WindowState.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #include "WindowState.h" 4 | 5 | namespace Boolka 6 | { 7 | 8 | WindowState WindowState::GetDefault() 9 | { 10 | WindowState result{}; 11 | result.x = result.y = 0; 12 | result.width = ::GetSystemMetrics(SM_CXSCREEN); 13 | result.height = ::GetSystemMetrics(SM_CYSCREEN); 14 | result.presentInterval = 0; 15 | result.windowMode = WindowMode::Borderless; 16 | return result; 17 | } 18 | 19 | } // namespace Boolka -------------------------------------------------------------------------------- /D3D12Backend/WindowManagement/WindowState.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Boolka 4 | { 5 | 6 | struct [[nodiscard]] WindowState 7 | { 8 | enum class WindowMode 9 | { 10 | Windowed, 11 | Borderless, 12 | Fullscreen 13 | }; 14 | 15 | int x; 16 | int y; 17 | int width; 18 | int height; 19 | int presentInterval; // aka VSYNC 20 | WindowMode windowMode; 21 | 22 | [[nodiscard]] static WindowState GetDefault(); 23 | }; 24 | 25 | BLK_IS_PLAIN_DATA_ASSERT(WindowState); 26 | 27 | } // namespace Boolka 28 | -------------------------------------------------------------------------------- /D3D12Backend/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /D3D12Backend/stdafx.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | -------------------------------------------------------------------------------- /D3D12Backend/stdafx.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "BoolkaCommon/stdafx.h" 4 | 5 | #include "ProjectConfig.h" 6 | #include "ProjectHelpers.h" 7 | 8 | // DirectX 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | // Own code 17 | 18 | #include "APIWrappers/CommandList/GraphicCommandListImpl.h" 19 | #include "APIWrappers/Device.h" 20 | #include "APIWrappers/InputLayout.h" 21 | #include "APIWrappers/RenderDebug.h" 22 | #include "APIWrappers/Resources/Buffers/Buffer.h" 23 | #include "APIWrappers/Resources/ResourceTransition.h" 24 | #include "APIWrappers/Resources/Textures/Texture2D.h" 25 | #include "APIWrappers/Resources/Textures/Views/DepthStencilView.h" 26 | #include "APIWrappers/Resources/Textures/Views/RenderTargetView.h" 27 | #include "BoolkaCommon/DebugHelpers/DebugFileReader.h" 28 | #include "Containers/ResourceContainer.h" 29 | #include "Contexts/RenderContext.h" 30 | #include "Contexts/RenderEngineContext.h" 31 | #include "Contexts/RenderFrameContext.h" 32 | #include "Contexts/RenderThreadContext.h" 33 | #include "DebugHelpers/DebugCPUScope.h" 34 | #include "DebugHelpers/DebugRenderScope.h" 35 | #include "HLSLShared.h" 36 | #include "RenderPass.h" 37 | #include "RenderSchedule/ResourceTracker.h" 38 | -------------------------------------------------------------------------------- /HelperScripts/BuildAllAndRunTests.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | pushd "%~dp0" 3 | 4 | echo Building solution 5 | call Internal\BuildSolution.bat Debug || goto error 6 | call Internal\BuildSolution.bat Development || goto error 7 | call Internal\BuildSolution.bat Release || goto error 8 | call Internal\RunTests.bat Debug || goto error 9 | call Internal\RunTests.bat Development || goto error 10 | call Internal\RunTests.bat Release || goto error 11 | 12 | popd 13 | exit /b 0 14 | 15 | :error 16 | popd 17 | exit /b 1 -------------------------------------------------------------------------------- /HelperScripts/BuildAndStartReleaseEngine.bat: -------------------------------------------------------------------------------- 1 | pushd "%~dp0" 2 | 3 | call Internal\BuildSolution.bat Release || goto error 4 | 5 | pushd ..\x64\Release 6 | echo %cd% 7 | start Bootstrap.exe ..\..\Scenes\Binarized\ 8 | popd 9 | popd 10 | exit /b 0 11 | 12 | :error 13 | popd 14 | exit /b 1 15 | -------------------------------------------------------------------------------- /HelperScripts/FormatAll.ps1: -------------------------------------------------------------------------------- 1 | $ScriptPath = $MyInvocation.MyCommand.Path 2 | $ScriptDir = Split-Path $ScriptPath 3 | Push-Location $ScriptDir\.. 4 | 5 | Get-ChildItem -Path ('BoolkaCommon', 'BoolkaCommonUnitTests', 'Bootstrap', 'D3D12Backend', 'OBJConverter') -include ('*.cpp', '*.h', '*.hpp') -Recurse | 6 | foreach { 7 | Write-Host "Formatting " $_ 8 | clang-format -i $_ 9 | } 10 | 11 | Pop-Location -------------------------------------------------------------------------------- /HelperScripts/Internal/BuildSolution.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | pushd "%~dp0" 3 | call FindVisualStudioInstallation.bat 4 | pushd ..\.. 5 | (%InstallDir%\MSBuild\Current\Bin\MSBuild.exe BoolkaEngine.sln -m -t:Restore -p:RestorePackagesConfig=true;Configuration=%1 && echo Successfully restored packages for %1 configuration) || echo Failed to restore Nuget packages on %1 configuration failed && goto error 6 | (%InstallDir%\MSBuild\Current\Bin\MSBuild.exe BoolkaEngine.sln -m -t:Build -p:Configuration=%1 && echo Successfully built %1 configuration) || echo Failed to build %1 configuration && goto error 7 | 8 | :success 9 | popd 10 | popd 11 | exit /b 0 12 | 13 | :error 14 | popd 15 | popd 16 | exit /b 1 -------------------------------------------------------------------------------- /HelperScripts/Internal/FindVisualStudioInstallation.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | if defined InstallDir ( 4 | goto success 5 | ) 6 | 7 | echo Searching for Visual Studio intallation 8 | set InstallDir= 9 | for /f "usebackq tokens=*" %%i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -latest -products * -property installationPath`) do ( 10 | set InstallDir="%%i" 11 | ) 12 | 13 | if %InstallDir%=="" ( 14 | echo Visual studio not found 15 | goto error 16 | ) 17 | 18 | echo Using Visual Studio from path: %InstallDir% 19 | 20 | :success 21 | exit /b 0 22 | 23 | :error 24 | exit /b 1 -------------------------------------------------------------------------------- /HelperScripts/Internal/RunTests.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | pushd "%~dp0" 3 | call FindVisualStudioInstallation.bat 4 | pushd ..\.. 5 | (%InstallDir%\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe x64\%1\BoolkaCommonUnitTests.dll && echo Tests passed on %1 configuration) || echo Tests failed on %1 configuration && goto error 6 | 7 | popd 8 | popd 9 | exit /b 0 10 | 11 | :error 12 | popd 13 | popd 14 | exit /b 1 15 | -------------------------------------------------------------------------------- /HelperScripts/PrepareScene.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | pushd "%~dp0" 3 | call Internal\FindVisualStudioInstallation.bat 4 | pushd .. 5 | echo building OBJConverter 6 | %InstallDir%\MSBuild\Current\Bin\MSBuild.exe BoolkaEngine.sln -m -target:ObjConverter -p:Configuration=Release || echo Error building ObjConverter && goto error 7 | 8 | if exist Scenes\SanMiguel\ echo SanMiguel scene already present, skip download && goto skybox 9 | 10 | echo Downloading SanMiguel scene 11 | echo Models downloaded from Morgan McGuire's Computer Graphics Archive https://casual-effects.com/data 12 | mkdir Scenes 13 | mkdir Scenes\SanMiguel 14 | powershell -command "Start-BitsTransfer -Source https://fileshare.boolka.dev/San_Miguel.zip -Destination Scenes/SanMiguel/San_Miguel.zip" 15 | echo Downloaded scene, unpacking 16 | powershell -command "Expand-Archive Scenes/SanMiguel/San_Miguel.zip Scenes/SanMiguel/" 17 | echo Scene unpacked, deleting archive 18 | del "Scenes\SanMiguel\San_Miguel.zip" 19 | 20 | :skybox 21 | if exist Scenes\SanMiguel\skybox echo Skybox already present, skip unpacking && goto binarize 22 | 23 | mkdir Scenes\SanMiguel\skybox 24 | powershell -command "Expand-Archive BinaryData/DefaultSkybox.zip Scenes/SanMiguel/skybox/" 25 | echo Skybox unpacked 26 | 27 | :binarize 28 | mkdir Scenes\Binarized 29 | echo Binarizing SanMiguel scene 30 | x64\Release\OBJConverter.exe Scenes\SanMiguel\ san-miguel-low-poly.obj ..\Binarized\ || echo Failed to binarize scene && goto error 31 | 32 | popd 33 | popd 34 | exit /b 0 35 | 36 | :error 37 | popd 38 | popd 39 | exit /b 1 40 | -------------------------------------------------------------------------------- /HelperScripts/QuickStart.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | pushd "%~dp0" 3 | call PrepareScene.bat || goto error 4 | call BuildAndStartReleaseEngine.bat || goto error 5 | popd 6 | exit /b 0 7 | 8 | :error 9 | popd 10 | exit /b 1 11 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020-2023 Dmytro Bulatov 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 | -------------------------------------------------------------------------------- /OBJConverter/OBJConverter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Boolka 4 | { 5 | 6 | class OBJConverter 7 | { 8 | public: 9 | static bool Convert(std::wstring inFile, std::wstring outFolder); 10 | }; 11 | 12 | } // namespace Boolka 13 | -------------------------------------------------------------------------------- /OBJConverter/OBJConverter.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | stb 9 | 10 | 11 | tinyobjloader 12 | 13 | 14 | 15 | 16 | 17 | 18 | stb 19 | 20 | 21 | tinyobjloader 22 | 23 | 24 | 25 | 26 | {aecf6d3b-777e-4f28-9672-c305c3777b0f} 27 | 28 | 29 | {5033d052-face-402f-81b0-848953849bb4} 30 | 31 | 32 | -------------------------------------------------------------------------------- /OBJConverter/main.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #include "BoolkaCommon/DebugHelpers/DebugTimer.h" 4 | #include "OBJConverter.h" 5 | 6 | void WinError() 7 | { 8 | LPVOID lpMsgBuf; 9 | DWORD dw = GetLastError(); 10 | 11 | DWORD formatResult = FormatMessageA( 12 | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 13 | NULL, dw, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&lpMsgBuf, 0, NULL); 14 | 15 | if (formatResult == 0) 16 | { 17 | std::cout << "Error generating error string\n"; 18 | return; 19 | } 20 | 21 | std::cout << "Error: " << (char*)lpMsgBuf; 22 | 23 | LocalFree(lpMsgBuf); 24 | } 25 | 26 | int wmain(int argc, wchar_t* argv[], wchar_t* envp[]) 27 | { 28 | if (argc != 4) 29 | { 30 | std::cerr << "Expected 3 command line argument, Got " << argc - 1 << "\n"; 31 | return -1; 32 | } 33 | 34 | wchar_t* directory = argv[1]; 35 | wchar_t* objFile = argv[2]; 36 | wchar_t* outFolder = argv[3]; 37 | 38 | BOOL winSuccess = ::SetCurrentDirectoryW(directory); 39 | if (!winSuccess) 40 | { 41 | WinError(); 42 | return -1; 43 | } 44 | 45 | Boolka::DebugTimer timer; 46 | timer.Start(); 47 | bool res = Boolka::OBJConverter::Convert(objFile, outFolder); 48 | float seconds = timer.Stop(); 49 | std::cout << "Conversion took " << seconds << "s" << std::endl; 50 | 51 | if (!res) 52 | { 53 | return -1; 54 | } 55 | 56 | return 0; 57 | } 58 | -------------------------------------------------------------------------------- /OBJConverter/stdafx.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | -------------------------------------------------------------------------------- /OBJConverter/stdafx.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "BoolkaCommon/stdafx.h" 4 | 5 | #include 6 | 7 | #define WIN32_LEAN_AND_MEAN 8 | #include 9 | #include 10 | 11 | // 3rd party libraries 12 | #include "ThirdParty/stb/stb_image.h" 13 | #include "ThirdParty/tinyobjloader/tiny_obj_loader.h" 14 | -------------------------------------------------------------------------------- /Props/Common.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %PATH%;C:\Projects\BoolkaEngine\ThirdParty\DXC 6 | 7 | 8 | false 9 | true 10 | 11 | 12 | 13 | $(ProjectDir);$(SolutionDir) 14 | 15 | 16 | 17 | 18 | stdcpplatest 19 | true 20 | true 21 | Level3 22 | Fast 23 | true 24 | true 25 | 26 | 27 | -HV 2018 -enable-16bit-types 28 | 6.5 29 | 30 | 31 | Pathcch.lib;%(AdditionalDependencies) 32 | 33 | 34 | 35 | 36 | $(PATH) 37 | true 38 | 39 | 40 | -------------------------------------------------------------------------------- /Props/Debug.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | BLK_CONFIGURATION_DEBUG;_DEBUG;_UNICODE;UNICODE;%(PreprocessorDefinitions) 9 | 10 | 11 | -Qembed_debug -HV 2018 -enable-16bit-types 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Props/Development.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | 7 | 8 | false 9 | 10 | 11 | 12 | ProgramDatabase 13 | MultiThreadedDLL 14 | BLK_CONFIGURATION_DEVELOPMENT;_ITERATOR_DEBUG_LEVEL=0;_UNICODE;UNICODE 15 | 16 | 17 | UseLinkTimeCodeGeneration 18 | 19 | 20 | false 21 | 22 | 23 | 24 | 25 | $(VcpkgConfiguration) 26 | 27 | 28 | -------------------------------------------------------------------------------- /Props/ThirdParty.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | false 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | BoolkaEngine 2 | ============ 3 | BoolkaEngine is DX12 rendering engine. 4 | 5 | ![Screenshot](https://raw.githubusercontent.com/Devaniti/BoolkaEngine/master/Screenshot.png) 6 | 7 | Features 8 | -------- 9 | * Perfect mirror RT reflections (multi bounce) with ray differentials LOD calculation 10 | * HDR Rendering + Tonemapping 11 | * Point lights with shadows 12 | * Sun light with shadows 13 | * GPU Frustum culling using mesh shaders 14 | * Fast loading via DirectStorage 15 | * Skybox 16 | * ImGui debug output 17 | 18 | Requirements 19 | -------- 20 | * Windows 10 version 2004 or newer 21 | * GPU with mesh shader (NVIDIA GTX 16xx or higher, AMD RX 6xxx or higher) 22 | * GPU with DXR 1.0 support recommended 23 | * SSD Recommended 24 | 25 | To build BoolkaEngine you'll also need: 26 | * Visual Studio 2022 27 | * Windows 10 SDK 19041 or later 28 | 29 | Quick Start 30 | -------- 31 | You can download and run BoolkaEngine with default scene using following command: 32 | 33 | `git clone --recurse-submodules -j8 https://github.com/Devaniti/BoolkaEngine.git && BoolkaEngine\HelperScripts\QuickStart.bat` 34 | 35 | Building 36 | -------- 37 | You can just build BoolkaEngine.sln solution, but you'll also need binarized scene to run it 38 | 39 | If you want to use default scene run HelperScripts\PrepareScene.bat, which will download and binarize San Miguel scene and default skybox 40 | 41 | If you want to use another scene: 42 | 1. Build OBJConverter project 43 | 2. Place your obj, mtl and texture files in one folder (which is going to be inObjFolder for OBJConverter) 44 | 3. Create "skybox" subfolder there and place skybox textures (see BinaryData\DefaultSkybox.zip for format reference) 45 | 4. Run OBJConverter 46 | 47 | Command line parameters 48 | -------- 49 | Bootstrap parameters:\ 50 | Bootstrap.exe binarizedSceneFolder 51 | 52 | OBJConverter parameters:\ 53 | OBJConverter.exe inObjFolder inObjFile outBinarizedSceneFolder -------------------------------------------------------------------------------- /Screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Devaniti/BoolkaEngine/338c87eebb221f3ffd5915f8e1e10d5bb2689e97/Screenshot.png -------------------------------------------------------------------------------- /ThirdParty/imgui/.editorconfig: -------------------------------------------------------------------------------- 1 | # See http://editorconfig.org to read about the EditorConfig format. 2 | # - Automatically supported by VS2017+ and most common IDE or text editors. 3 | # - For older VS2010 to VS2015, install https://marketplace.visualstudio.com/items?itemName=EditorConfigTeam.EditorConfig 4 | 5 | # top-most EditorConfig file 6 | root = true 7 | 8 | # Default settings: 9 | # Use 4 spaces as indentation 10 | [*] 11 | indent_style = space 12 | indent_size = 4 13 | insert_final_newline = true 14 | trim_trailing_whitespace = true 15 | 16 | [imstb_*] 17 | indent_size = 3 18 | trim_trailing_whitespace = false 19 | 20 | [Makefile] 21 | indent_style = tab 22 | indent_size = 4 23 | -------------------------------------------------------------------------------- /ThirdParty/imgui/.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | 3 | *.c text 4 | *.cpp text 5 | *.h text 6 | *.m text 7 | *.mm text 8 | *.md text 9 | *.txt text 10 | *.html text 11 | *.bat text 12 | *.frag text 13 | *.vert text 14 | *.mkb text 15 | *.icf text 16 | 17 | *.sln text eol=crlf 18 | *.vcxproj text eol=crlf 19 | *.vcxproj.filters text eol=crlf 20 | *.natvis text eol=crlf 21 | 22 | Makefile text eol=lf 23 | *.sh text eol=lf 24 | *.pbxproj text eol=lf 25 | *.storyboard text eol=lf 26 | *.plist text eol=lf 27 | 28 | *.png binary 29 | *.ttf binary 30 | *.lib binary 31 | -------------------------------------------------------------------------------- /ThirdParty/imgui/.gitignore: -------------------------------------------------------------------------------- 1 | ## OSX artifacts 2 | .DS_Store 3 | 4 | ## Dear ImGui artifacts 5 | imgui.ini 6 | 7 | ## General build artifacts 8 | *.o 9 | *.obj 10 | *.exe 11 | examples/build/* 12 | examples/*/Debug/* 13 | examples/*/Release/* 14 | examples/*/x64/* 15 | 16 | ## Visual Studio artifacts 17 | .vs 18 | ipch 19 | *.opensdf 20 | *.log 21 | *.pdb 22 | *.ilk 23 | *.user 24 | *.sdf 25 | *.suo 26 | *.VC.db 27 | *.VC.VC.opendb 28 | 29 | ## Xcode artifacts 30 | project.xcworkspace 31 | xcuserdata 32 | 33 | ## Emscripten artifacts 34 | examples/*.o.tmp 35 | examples/*.out.js 36 | examples/*.out.wasm 37 | examples/example_emscripten_opengl3/web/* 38 | 39 | ## JetBrains IDE artifacts 40 | .idea 41 | cmake-build-* 42 | 43 | ## Unix executables from our example Makefiles 44 | examples/example_glfw_opengl2/example_glfw_opengl2 45 | examples/example_glfw_opengl3/example_glfw_opengl3 46 | examples/example_glut_opengl2/example_glut_opengl2 47 | examples/example_null/example_null 48 | examples/example_sdl_opengl2/example_sdl_opengl2 49 | examples/example_sdl_opengl3/example_sdl_opengl3 50 | -------------------------------------------------------------------------------- /ThirdParty/imgui/LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014-2021 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 | -------------------------------------------------------------------------------- /ThirdParty/imgui/backends/imgui_impl_allegro5.h: -------------------------------------------------------------------------------- 1 | // dear imgui: Renderer + Platform Backend for Allegro 5 2 | // (Info: Allegro 5 is a cross-platform general purpose library for handling windows, inputs, graphics, etc.) 3 | 4 | // Implemented features: 5 | // [X] Renderer: User texture binding. Use 'ALLEGRO_BITMAP*' as ImTextureID. Read the FAQ about ImTextureID! 6 | // [X] Platform: Clipboard support (from Allegro 5.1.12) 7 | // [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'. 8 | // Issues: 9 | // [ ] Renderer: The renderer is suboptimal as we need to unindex our buffers and convert vertices manually. 10 | // [ ] Platform: Missing gamepad support. 11 | 12 | // You can copy and use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. 13 | // If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp. 14 | // Read online: https://github.com/ocornut/imgui/tree/master/docs 15 | 16 | #pragma once 17 | #include "imgui.h" // IMGUI_IMPL_API 18 | 19 | struct ALLEGRO_DISPLAY; 20 | union ALLEGRO_EVENT; 21 | 22 | IMGUI_IMPL_API bool ImGui_ImplAllegro5_Init(ALLEGRO_DISPLAY* display); 23 | IMGUI_IMPL_API void ImGui_ImplAllegro5_Shutdown(); 24 | IMGUI_IMPL_API void ImGui_ImplAllegro5_NewFrame(); 25 | IMGUI_IMPL_API void ImGui_ImplAllegro5_RenderDrawData(ImDrawData* draw_data); 26 | IMGUI_IMPL_API bool ImGui_ImplAllegro5_ProcessEvent(ALLEGRO_EVENT* event); 27 | 28 | // Use if you want to reset your rendering device without losing Dear ImGui state. 29 | IMGUI_IMPL_API bool ImGui_ImplAllegro5_CreateDeviceObjects(); 30 | IMGUI_IMPL_API void ImGui_ImplAllegro5_InvalidateDeviceObjects(); 31 | -------------------------------------------------------------------------------- /ThirdParty/imgui/backends/imgui_impl_dx10.h: -------------------------------------------------------------------------------- 1 | // dear imgui: Renderer Backend for DirectX10 2 | // This needs to be used along with a Platform Backend (e.g. Win32) 3 | 4 | // Implemented features: 5 | // [X] Renderer: User texture backend. Use 'ID3D10ShaderResourceView*' 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 | #pragma once 13 | #include "imgui.h" // IMGUI_IMPL_API 14 | 15 | struct ID3D10Device; 16 | 17 | IMGUI_IMPL_API bool ImGui_ImplDX10_Init(ID3D10Device* device); 18 | IMGUI_IMPL_API void ImGui_ImplDX10_Shutdown(); 19 | IMGUI_IMPL_API void ImGui_ImplDX10_NewFrame(); 20 | IMGUI_IMPL_API void ImGui_ImplDX10_RenderDrawData(ImDrawData* draw_data); 21 | 22 | // Use if you want to reset your rendering device without losing Dear ImGui state. 23 | IMGUI_IMPL_API void ImGui_ImplDX10_InvalidateDeviceObjects(); 24 | IMGUI_IMPL_API bool ImGui_ImplDX10_CreateDeviceObjects(); 25 | -------------------------------------------------------------------------------- /ThirdParty/imgui/backends/imgui_impl_dx11.h: -------------------------------------------------------------------------------- 1 | // dear imgui: Renderer Backend for DirectX11 2 | // This needs to be used along with a Platform Backend (e.g. Win32) 3 | 4 | // Implemented features: 5 | // [X] Renderer: User texture binding. Use 'ID3D11ShaderResourceView*' 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 | #pragma once 13 | #include "imgui.h" // IMGUI_IMPL_API 14 | 15 | struct ID3D11Device; 16 | struct ID3D11DeviceContext; 17 | 18 | IMGUI_IMPL_API bool ImGui_ImplDX11_Init(ID3D11Device* device, ID3D11DeviceContext* device_context); 19 | IMGUI_IMPL_API void ImGui_ImplDX11_Shutdown(); 20 | IMGUI_IMPL_API void ImGui_ImplDX11_NewFrame(); 21 | IMGUI_IMPL_API void ImGui_ImplDX11_RenderDrawData(ImDrawData* draw_data); 22 | 23 | // Use if you want to reset your rendering device without losing Dear ImGui state. 24 | IMGUI_IMPL_API void ImGui_ImplDX11_InvalidateDeviceObjects(); 25 | IMGUI_IMPL_API bool ImGui_ImplDX11_CreateDeviceObjects(); 26 | -------------------------------------------------------------------------------- /ThirdParty/imgui/backends/imgui_impl_dx9.h: -------------------------------------------------------------------------------- 1 | // dear imgui: Renderer Backend for DirectX9 2 | // This needs to be used along with a Platform Backend (e.g. Win32) 3 | 4 | // Implemented features: 5 | // [X] Renderer: User texture binding. Use 'LPDIRECT3DTEXTURE9' 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 | #pragma once 13 | #include "imgui.h" // IMGUI_IMPL_API 14 | 15 | struct IDirect3DDevice9; 16 | 17 | IMGUI_IMPL_API bool ImGui_ImplDX9_Init(IDirect3DDevice9* device); 18 | IMGUI_IMPL_API void ImGui_ImplDX9_Shutdown(); 19 | IMGUI_IMPL_API void ImGui_ImplDX9_NewFrame(); 20 | IMGUI_IMPL_API void ImGui_ImplDX9_RenderDrawData(ImDrawData* draw_data); 21 | 22 | // Use if you want to reset your rendering device without losing Dear ImGui state. 23 | IMGUI_IMPL_API bool ImGui_ImplDX9_CreateDeviceObjects(); 24 | IMGUI_IMPL_API void ImGui_ImplDX9_InvalidateDeviceObjects(); 25 | -------------------------------------------------------------------------------- /ThirdParty/imgui/backends/imgui_impl_marmalade.h: -------------------------------------------------------------------------------- 1 | // dear imgui: Renderer + Platform Backend for Marmalade + IwGx 2 | // Marmalade code: Copyright (C) 2015 by Giovanni Zito (this file is part of Dear ImGui) 3 | 4 | // Implemented features: 5 | // [X] Renderer: User texture binding. Use 'CIwTexture*' as ImTextureID. Read the FAQ about ImTextureID! 6 | 7 | // You can copy and use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. 8 | // If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp. 9 | // Read online: https://github.com/ocornut/imgui/tree/master/docs 10 | 11 | #pragma once 12 | #include "imgui.h" // IMGUI_IMPL_API 13 | 14 | IMGUI_IMPL_API bool ImGui_Marmalade_Init(bool install_callbacks); 15 | IMGUI_IMPL_API void ImGui_Marmalade_Shutdown(); 16 | IMGUI_IMPL_API void ImGui_Marmalade_NewFrame(); 17 | IMGUI_IMPL_API void ImGui_Marmalade_RenderDrawData(ImDrawData* draw_data); 18 | 19 | // Use if you want to reset your rendering device without losing Dear ImGui state. 20 | IMGUI_IMPL_API void ImGui_Marmalade_InvalidateDeviceObjects(); 21 | IMGUI_IMPL_API bool ImGui_Marmalade_CreateDeviceObjects(); 22 | 23 | // Callbacks (installed by default if you enable 'install_callbacks' during initialization) 24 | // You can also handle inputs yourself and use those as a reference. 25 | IMGUI_IMPL_API int32 ImGui_Marmalade_PointerButtonEventCallback(void* system_data, void* user_data); 26 | IMGUI_IMPL_API int32 ImGui_Marmalade_KeyCallback(void* system_data, void* user_data); 27 | IMGUI_IMPL_API int32 ImGui_Marmalade_CharCallback(void* system_data, void* user_data); 28 | -------------------------------------------------------------------------------- /ThirdParty/imgui/backends/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 | -------------------------------------------------------------------------------- /ThirdParty/imgui/backends/imgui_impl_osx.h: -------------------------------------------------------------------------------- 1 | // dear imgui: Platform Backend for OSX / Cocoa 2 | // This needs to be used along with a Renderer (e.g. OpenGL2, OpenGL3, Vulkan, Metal..) 3 | // [ALPHA] Early backend, not well tested. If you want a portable application, prefer using the GLFW or SDL platform Backends on Mac. 4 | 5 | // Implemented features: 6 | // [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'. 7 | // [X] Platform: OSX clipboard is supported within core Dear ImGui (no specific code in this backend). 8 | // Issues: 9 | // [ ] Platform: Keys are all generally very broken. Best using [event keycode] and not [event characters].. 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 | #include "imgui.h" // IMGUI_IMPL_API 16 | 17 | @class NSEvent; 18 | @class NSView; 19 | 20 | IMGUI_IMPL_API bool ImGui_ImplOSX_Init(); 21 | IMGUI_IMPL_API void ImGui_ImplOSX_Shutdown(); 22 | IMGUI_IMPL_API void ImGui_ImplOSX_NewFrame(NSView* _Nullable view); 23 | IMGUI_IMPL_API bool ImGui_ImplOSX_HandleEvent(NSEvent* _Nonnull event, NSView* _Nullable view); 24 | -------------------------------------------------------------------------------- /ThirdParty/imgui/backends/imgui_impl_sdl.h: -------------------------------------------------------------------------------- 1 | // dear imgui: Platform Backend for SDL2 2 | // This needs to be used along with a Renderer (e.g. DirectX11, OpenGL3, Vulkan..) 3 | // (Info: SDL2 is a cross-platform general purpose library for handling windows, inputs, graphics context creation, etc.) 4 | 5 | // Implemented features: 6 | // [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'. 7 | // [X] Platform: Clipboard support. 8 | // [X] Platform: Keyboard arrays indexed using SDL_SCANCODE_* codes, e.g. ImGui::IsKeyPressed(SDL_SCANCODE_SPACE). 9 | // [X] Platform: Gamepad support. Enabled with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'. 10 | // Missing features: 11 | // [ ] Platform: SDL2 handling of IME under Windows appears to be broken and it explicitly disable the regular Windows IME. You can restore Windows IME by compiling SDL with SDL_DISABLE_WINDOWS_IME. 12 | 13 | // You can copy and use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. 14 | // If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp. 15 | // Read online: https://github.com/ocornut/imgui/tree/master/docs 16 | 17 | #pragma once 18 | #include "imgui.h" // IMGUI_IMPL_API 19 | 20 | struct SDL_Window; 21 | typedef union SDL_Event SDL_Event; 22 | 23 | IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForOpenGL(SDL_Window* window, void* sdl_gl_context); 24 | IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForVulkan(SDL_Window* window); 25 | IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForD3D(SDL_Window* window); 26 | IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForMetal(SDL_Window* window); 27 | IMGUI_IMPL_API void ImGui_ImplSDL2_Shutdown(); 28 | IMGUI_IMPL_API void ImGui_ImplSDL2_NewFrame(SDL_Window* window); 29 | IMGUI_IMPL_API bool ImGui_ImplSDL2_ProcessEvent(const SDL_Event* event); 30 | -------------------------------------------------------------------------------- /ThirdParty/imgui/backends/vulkan/generate_spv.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ## -V: create SPIR-V binary 3 | ## -x: save binary output as text-based 32-bit hexadecimal numbers 4 | ## -o: output file 5 | glslangValidator -V -x -o glsl_shader.frag.u32 glsl_shader.frag 6 | glslangValidator -V -x -o glsl_shader.vert.u32 glsl_shader.vert 7 | -------------------------------------------------------------------------------- /ThirdParty/imgui/backends/vulkan/glsl_shader.frag: -------------------------------------------------------------------------------- 1 | #version 450 core 2 | layout(location = 0) out vec4 fColor; 3 | 4 | layout(set=0, binding=0) uniform sampler2D sTexture; 5 | 6 | layout(location = 0) in struct { 7 | vec4 Color; 8 | vec2 UV; 9 | } In; 10 | 11 | void main() 12 | { 13 | fColor = In.Color * texture(sTexture, In.UV.st); 14 | } 15 | -------------------------------------------------------------------------------- /ThirdParty/imgui/backends/vulkan/glsl_shader.vert: -------------------------------------------------------------------------------- 1 | #version 450 core 2 | layout(location = 0) in vec2 aPos; 3 | layout(location = 1) in vec2 aUV; 4 | layout(location = 2) in vec4 aColor; 5 | 6 | layout(push_constant) uniform uPushConstant { 7 | vec2 uScale; 8 | vec2 uTranslate; 9 | } pc; 10 | 11 | out gl_PerVertex { 12 | vec4 gl_Position; 13 | }; 14 | 15 | layout(location = 0) out struct { 16 | vec4 Color; 17 | vec2 UV; 18 | } Out; 19 | 20 | void main() 21 | { 22 | Out.Color = aColor; 23 | Out.UV = aUV; 24 | gl_Position = vec4(aPos * pc.uScale + pc.uTranslate, 0, 1); 25 | } 26 | -------------------------------------------------------------------------------- /ThirdParty/imgui/imgui.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | backends 12 | 13 | 14 | backends 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | backends 26 | 27 | 28 | backends 29 | 30 | 31 | 32 | 33 | 34 | {799972ba-6992-4ff9-912e-6efafc28f013} 35 | 36 | 37 | -------------------------------------------------------------------------------- /ThirdParty/imgui/imgui_helper.cpp: -------------------------------------------------------------------------------- 1 | #include "imgui_helper.h" 2 | 3 | std::recursive_mutex g_imguiMutex; 4 | -------------------------------------------------------------------------------- /ThirdParty/imgui/imgui_helper.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | extern std::recursive_mutex g_imguiMutex; 5 | -------------------------------------------------------------------------------- /ThirdParty/imgui/misc/README.txt: -------------------------------------------------------------------------------- 1 | 2 | misc/cpp/ 3 | InputText() wrappers for C++ standard library (STL) type: std::string. 4 | This is also an example of how you may wrap your own similar types. 5 | 6 | misc/fonts/ 7 | Fonts loading/merging instructions (e.g. How to handle glyph ranges, how to merge icons fonts). 8 | Command line tool "binary_to_compressed_c" to create compressed arrays to embed data in source code. 9 | Suggested fonts and links. 10 | 11 | misc/freetype/ 12 | Font atlas builder/rasterizer using FreeType instead of stb_truetype. 13 | Benefit from better FreeType rasterization, in particular for small fonts. 14 | 15 | misc/natvis/ 16 | Natvis file to describe dear imgui types in the Visual Studio debugger. 17 | With this, types like ImVector<> will be displayed nicely in the debugger. 18 | You can include this file a Visual Studio project file, or install it in Visual Studio folder. 19 | 20 | misc/single_file/ 21 | Single-file header stub. 22 | We use this to validate compiling all *.cpp files in a same compilation unit. 23 | Users of that technique (also called "Unity builds") can generally provide this themselves, 24 | so we don't really recommend you use this in your projects. 25 | -------------------------------------------------------------------------------- /ThirdParty/imgui/misc/cpp/README.txt: -------------------------------------------------------------------------------- 1 | 2 | imgui_stdlib.h + imgui_stdlib.cpp 3 | InputText() wrappers for C++ standard library (STL) type: std::string. 4 | This is also an example of how you may wrap your own similar types. 5 | 6 | imgui_scoped.h 7 | [Experimental, not currently in main repository] 8 | Additional header file with some RAII-style wrappers for common Dear ImGui functions. 9 | Try by merging: https://github.com/ocornut/imgui/pull/2197 10 | Discuss at: https://github.com/ocornut/imgui/issues/2096 11 | -------------------------------------------------------------------------------- /ThirdParty/imgui/misc/cpp/imgui_stdlib.h: -------------------------------------------------------------------------------- 1 | // dear imgui: wrappers for C++ standard library (STL) types (std::string, etc.) 2 | // This is also an example of how you may wrap your own similar types. 3 | 4 | // Compatibility: 5 | // - std::string support is only guaranteed to work from C++11. 6 | // If you try to use it pre-C++11, please share your findings (w/ info about compiler/architecture) 7 | 8 | // Changelog: 9 | // - v0.10: Initial version. Added InputText() / InputTextMultiline() calls with std::string 10 | 11 | #pragma once 12 | 13 | #include 14 | 15 | namespace ImGui 16 | { 17 | // ImGui::InputText() with std::string 18 | // Because text input needs dynamic resizing, we need to setup a callback to grow the capacity 19 | IMGUI_API bool InputText(const char* label, std::string* str, ImGuiInputTextFlags flags = 0, ImGuiInputTextCallback callback = NULL, void* user_data = NULL); 20 | IMGUI_API bool InputTextMultiline(const char* label, std::string* str, const ImVec2& size = ImVec2(0, 0), ImGuiInputTextFlags flags = 0, ImGuiInputTextCallback callback = NULL, void* user_data = NULL); 21 | IMGUI_API bool InputTextWithHint(const char* label, const char* hint, std::string* str, ImGuiInputTextFlags flags = 0, ImGuiInputTextCallback callback = NULL, void* user_data = NULL); 22 | } 23 | -------------------------------------------------------------------------------- /ThirdParty/imgui/misc/fonts/Cousine-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Devaniti/BoolkaEngine/338c87eebb221f3ffd5915f8e1e10d5bb2689e97/ThirdParty/imgui/misc/fonts/Cousine-Regular.ttf -------------------------------------------------------------------------------- /ThirdParty/imgui/misc/fonts/DroidSans.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Devaniti/BoolkaEngine/338c87eebb221f3ffd5915f8e1e10d5bb2689e97/ThirdParty/imgui/misc/fonts/DroidSans.ttf -------------------------------------------------------------------------------- /ThirdParty/imgui/misc/fonts/Karla-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Devaniti/BoolkaEngine/338c87eebb221f3ffd5915f8e1e10d5bb2689e97/ThirdParty/imgui/misc/fonts/Karla-Regular.ttf -------------------------------------------------------------------------------- /ThirdParty/imgui/misc/fonts/ProggyClean.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Devaniti/BoolkaEngine/338c87eebb221f3ffd5915f8e1e10d5bb2689e97/ThirdParty/imgui/misc/fonts/ProggyClean.ttf -------------------------------------------------------------------------------- /ThirdParty/imgui/misc/fonts/ProggyTiny.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Devaniti/BoolkaEngine/338c87eebb221f3ffd5915f8e1e10d5bb2689e97/ThirdParty/imgui/misc/fonts/ProggyTiny.ttf -------------------------------------------------------------------------------- /ThirdParty/imgui/misc/fonts/Roboto-Medium.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Devaniti/BoolkaEngine/338c87eebb221f3ffd5915f8e1e10d5bb2689e97/ThirdParty/imgui/misc/fonts/Roboto-Medium.ttf -------------------------------------------------------------------------------- /ThirdParty/imgui/misc/natvis/README.txt: -------------------------------------------------------------------------------- 1 | 2 | Natvis file to describe dear imgui types in the Visual Studio debugger. 3 | With this, types like ImVector<> will be displayed nicely in the debugger. 4 | You can include this file a Visual Studio project file, or install it in Visual Studio folder. 5 | -------------------------------------------------------------------------------- /ThirdParty/imgui/misc/natvis/imgui.natvis: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | {{Size={Size} Capacity={Capacity}}} 9 | 10 | 11 | Size 12 | Data 13 | 14 | 15 | 16 | 17 | 18 | {{Size={DataEnd-Data} }} 19 | 20 | 21 | DataEnd-Data 22 | Data 23 | 24 | 25 | 26 | 27 | 28 | {{x={x,g} y={y,g}}} 29 | 30 | 31 | 32 | {{x={x,g} y={y,g} z={z,g} w={w,g}}} 33 | 34 | 35 | 36 | {{Min=({Min.x,g} {Min.y,g}) Max=({Max.x,g} {Max.y,g}) Size=({Max.x-Min.x,g} {Max.y-Min.y,g})}} 37 | 38 | Min 39 | Max 40 | Max.x - Min.x 41 | Max.y - Min.y 42 | 43 | 44 | 45 | 46 | {{Name {Name,s} Active {(Active||WasActive)?1:0,d} Child {(Flags & 0x01000000)?1:0,d} Popup {(Flags & 0x04000000)?1:0,d} Hidden {(Hidden)?1:0,d}} 47 | 48 | 49 | -------------------------------------------------------------------------------- /ThirdParty/imgui/misc/single_file/imgui_single_file.h: -------------------------------------------------------------------------------- 1 | // dear imgui: single-file wrapper include 2 | // We use this to validate compiling all *.cpp files in a same compilation unit. 3 | // Users of that technique (also called "Unity builds") can generally provide this themselves, 4 | // so we don't really recommend you use this in your projects. 5 | 6 | // Do this: 7 | // #define IMGUI_IMPLEMENTATION 8 | // Before you include this file in *one* C++ file to create the implementation. 9 | // Using this in your project will leak the contents of imgui_internal.h and ImVec2 operators in this compilation unit. 10 | #include "../../imgui.h" 11 | 12 | #ifdef IMGUI_IMPLEMENTATION 13 | #include "../../imgui.cpp" 14 | #include "../../imgui_demo.cpp" 15 | #include "../../imgui_draw.cpp" 16 | #include "../../imgui_tables.cpp" 17 | #include "../../imgui_widgets.cpp" 18 | #endif 19 | -------------------------------------------------------------------------------- /ThirdParty/stb/stb_image.cpp: -------------------------------------------------------------------------------- 1 | #define STB_IMAGE_IMPLEMENTATION 2 | #include "stb_image.h" 3 | -------------------------------------------------------------------------------- /ThirdParty/tinyobjloader/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2012-2019 Syoyo Fujita and many contributors. 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 13 | all 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 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /ThirdParty/tinyobjloader/tiny_obj_loader.cpp: -------------------------------------------------------------------------------- 1 | #define TINYOBJLOADER_IMPLEMENTATION 2 | #include "tiny_obj_loader.h" 3 | --------------------------------------------------------------------------------