diff --git a/Assets/compiled/Triangle.vert.dxil b/Assets/compiled/Triangle.vert.dxil index 5711d79..df12025 100644 Binary files a/Assets/compiled/Triangle.vert.dxil and b/Assets/compiled/Triangle.vert.dxil differ diff --git a/Assets/source/Triangle.vert.hlsl b/Assets/source/Triangle.vert.hlsl index 56c2885..5d0a814 100644 --- a/Assets/source/Triangle.vert.hlsl +++ b/Assets/source/Triangle.vert.hlsl @@ -9,31 +9,31 @@ struct Output float4 Position : SV_Position; }; +// Bindless storage buffer access +// We assume DescriptorIndex 0 is our buffer for this example, or passed via push constant +// Since we don't have push constants hooked up in the C++ simplified example yet, +// we will assume the First descriptor in the heap is our buffer (Index 0). +// In a real app, 'bufferIndex' would be passed as a Root Constant. + Output main(Input input) { Output output; - float2 pos; - if (input.VertexIndex == 0) - { - pos = (-1.0f).xx; - output.Color = float4(1.0f, 0.0f, 0.0f, 1.0f); - } - else - { - if (input.VertexIndex == 1) - { - pos = float2(1.0f, -1.0f); - output.Color = float4(0.0f, 1.0f, 0.0f, 1.0f); - } - else - { - if (input.VertexIndex == 2) - { - pos = float2(0.0f, 1.0f); - output.Color = float4(0.0f, 0.0f, 1.0f, 1.0f); - } - } - } + + // Retrieve the buffer using SM6.6 bindless syntax + // heap index 0 is used for simplicity. + uint bufferIndex = 0; + ByteAddressBuffer buffer = ResourceDescriptorHeap[bufferIndex]; + + // Read position from buffer (Index * stride) + // Stride = 2 float (pos) + 4 float (color) = 6 * 4 = 24 bytes ? + // Let's assume just position 2D (8 bytes) + Color (16 bytes) + uint stride = 24; + uint offset = input.VertexIndex * stride; + + float2 pos = asfloat(buffer.Load2(offset)); + float4 col = asfloat(buffer.Load4(offset + 8)); + output.Position = float4(pos, 0.0f, 1.0f); + output.Color = col; return output; } diff --git a/Game/Game.vcxproj b/Game/Game.vcxproj index c3d9e1f..a1a4838 100644 --- a/Game/Game.vcxproj +++ b/Game/Game.vcxproj @@ -178,8 +178,8 @@ cd $(SolutionDir) & misc\fbuild -ide -dist -monitor -cache $(ProjectName)-$(Configuration) - cd $(SolutionDir) & mics\fbuild -ide -dist -monitor -cache -clean $(ProjectName)-$(Configuration) - WIN32_LEAN_AND_MEAN;WIN32;_WIN32;__WINDOWS__;_HAS_EXCEPTIONS=0;WIN64;DEBUG;PROFILING_ENABLED;JULIET_EXPORT;JULIET_WIN32; + cd $(SolutionDir) & misc\fbuild -ide -dist -monitor -cache -clean $(ProjectName)-$(Configuration) + _CRT_SECURE_NO_WARNINGS;_UNICODE;UNICODE;WIN32_LEAN_AND_MEAN;WIN32;_WIN32;__WINDOWS__;_HAS_EXCEPTIONS=0;WIN64;DEBUG;PROFILING_ENABLED;JULIET_EXPORT;JULIET_WIN32; ..\;..\Juliet\include;..\Juliet\src;C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\um;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\shared; /std:c++20 /wd5267 /wd4061 /wd4505 /wd4514 /wd4577 /wd4625 /wd4710 /wd4711 /wd4746 /wd4820 /wd5045 /wd5220 /wd5245 $(SolutionDir)\bin\$(Configuration)\ @@ -188,8 +188,8 @@ cd $(SolutionDir) & misc\fbuild -ide -dist -monitor -cache $(ProjectName)-$(Configuration) - cd $(SolutionDir) & mics\fbuild -ide -dist -monitor -cache -clean $(ProjectName)-$(Configuration) - WIN32_LEAN_AND_MEAN;WIN32;_WIN32;__WINDOWS__;_HAS_EXCEPTIONS=0;WIN64;RELEASE;PROFILING_ENABLED;JULIET_EXPORT;JULIET_WIN32; + cd $(SolutionDir) & misc\fbuild -ide -dist -monitor -cache -clean $(ProjectName)-$(Configuration) + _CRT_SECURE_NO_WARNINGS;_UNICODE;UNICODE;WIN32_LEAN_AND_MEAN;WIN32;_WIN32;__WINDOWS__;_HAS_EXCEPTIONS=0;WIN64;RELEASE;PROFILING_ENABLED;JULIET_EXPORT;JULIET_WIN32; ..\;..\Juliet\include;..\Juliet\src;C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\um;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\shared; /std:c++20 /wd5267 /wd4061 /wd4505 /wd4514 /wd4577 /wd4625 /wd4710 /wd4711 /wd4746 /wd4820 /wd5045 /wd5220 /wd5245 $(SolutionDir)\bin\$(Configuration)\ @@ -198,8 +198,8 @@ cd $(SolutionDir) & misc\fbuild -ide -dist -monitor -cache $(ProjectName)-$(Configuration) - cd $(SolutionDir) & mics\fbuild -ide -dist -monitor -cache -clean $(ProjectName)-$(Configuration) - WIN32_LEAN_AND_MEAN;WIN32;_WIN32;__WINDOWS__;_HAS_EXCEPTIONS=0;WIN64;RELEASE;JULIET_EXPORT;JULIET_WIN32; + cd $(SolutionDir) & misc\fbuild -ide -dist -monitor -cache -clean $(ProjectName)-$(Configuration) + _CRT_SECURE_NO_WARNINGS;_UNICODE;UNICODE;WIN32_LEAN_AND_MEAN;WIN32;_WIN32;__WINDOWS__;_HAS_EXCEPTIONS=0;WIN64;RELEASE;JULIET_EXPORT;JULIET_WIN32; ..\;..\Juliet\include;..\Juliet\src;C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\um;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\shared; /std:c++20 /wd5267 /wd4061 /wd4505 /wd4514 /wd4577 /wd4625 /wd4710 /wd4711 /wd4746 /wd4820 /wd5045 /wd5220 /wd5245 $(SolutionDir)\bin\$(Configuration)\ @@ -208,8 +208,8 @@ cd $(SolutionDir) & misc\fbuild -ide -dist -monitor -cache $(ProjectName)-$(Configuration) - cd $(SolutionDir) & mics\fbuild -ide -dist -monitor -cache -clean $(ProjectName)-$(Configuration) - WIN32_LEAN_AND_MEAN;WIN32;_WIN32;__WINDOWS__;_HAS_EXCEPTIONS=0;WIN64;DEBUG;PROFILING_ENABLED;JULIET_EXPORT;JULIET_WIN32; + cd $(SolutionDir) & misc\fbuild -ide -dist -monitor -cache -clean $(ProjectName)-$(Configuration) + _CRT_SECURE_NO_WARNINGS;_UNICODE;UNICODE;WIN32_LEAN_AND_MEAN;WIN32;_WIN32;__WINDOWS__;_HAS_EXCEPTIONS=0;WIN64;DEBUG;PROFILING_ENABLED;JULIET_EXPORT;JULIET_WIN32; ..\;..\Juliet\include;..\Juliet\src;C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\um;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\shared; /std:c++20 /wd5267 /wd4061 /wd4505 /wd4514 /wd4577 /wd4625 /wd4710 /wd4711 /wd4746 /wd4820 /wd5045 /wd5220 /wd5245 $(SolutionDir)\bin\$(Configuration)\ @@ -218,8 +218,8 @@ cd $(SolutionDir) & misc\fbuild -ide -dist -monitor -cache $(ProjectName)-$(Configuration) - cd $(SolutionDir) & mics\fbuild -ide -dist -monitor -cache -clean $(ProjectName)-$(Configuration) - WIN32_LEAN_AND_MEAN;WIN32;_WIN32;__WINDOWS__;_HAS_EXCEPTIONS=0;WIN64;RELEASE;PROFILING_ENABLED;JULIET_EXPORT;JULIET_WIN32; + cd $(SolutionDir) & misc\fbuild -ide -dist -monitor -cache -clean $(ProjectName)-$(Configuration) + _CRT_SECURE_NO_WARNINGS;_UNICODE;UNICODE;WIN32_LEAN_AND_MEAN;WIN32;_WIN32;__WINDOWS__;_HAS_EXCEPTIONS=0;WIN64;RELEASE;PROFILING_ENABLED;JULIET_EXPORT;JULIET_WIN32; ..\;..\Juliet\include;..\Juliet\src;C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\um;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\shared; /std:c++20 /wd5267 /wd4061 /wd4505 /wd4514 /wd4577 /wd4625 /wd4710 /wd4711 /wd4746 /wd4820 /wd5045 /wd5220 /wd5245 $(SolutionDir)\bin\$(Configuration)\ @@ -228,8 +228,8 @@ cd $(SolutionDir) & misc\fbuild -ide -dist -monitor -cache $(ProjectName)-$(Configuration) - cd $(SolutionDir) & mics\fbuild -ide -dist -monitor -cache -clean $(ProjectName)-$(Configuration) - WIN32_LEAN_AND_MEAN;WIN32;_WIN32;__WINDOWS__;_HAS_EXCEPTIONS=0;WIN64;RELEASE;JULIET_EXPORT;JULIET_WIN32; + cd $(SolutionDir) & misc\fbuild -ide -dist -monitor -cache -clean $(ProjectName)-$(Configuration) + _CRT_SECURE_NO_WARNINGS;_UNICODE;UNICODE;WIN32_LEAN_AND_MEAN;WIN32;_WIN32;__WINDOWS__;_HAS_EXCEPTIONS=0;WIN64;RELEASE;JULIET_EXPORT;JULIET_WIN32; ..\;..\Juliet\include;..\Juliet\src;C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\um;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\shared; /std:c++20 /wd5267 /wd4061 /wd4505 /wd4514 /wd4577 /wd4625 /wd4710 /wd4711 /wd4746 /wd4820 /wd5045 /wd5220 /wd5245 $(SolutionDir)\bin\$(Configuration)\ @@ -238,8 +238,8 @@ cd $(SolutionDir) & misc\fbuild -ide -dist -monitor -cache $(ProjectName)-$(Configuration) - cd $(SolutionDir) & mics\fbuild -ide -dist -monitor -cache -clean $(ProjectName)-$(Configuration) - WIN32_LEAN_AND_MEAN;WIN32;_WIN32;__WINDOWS__;_HAS_EXCEPTIONS=0;WIN64;DEBUG;PROFILING_ENABLED;JULIET_WIN32; + cd $(SolutionDir) & misc\fbuild -ide -dist -monitor -cache -clean $(ProjectName)-$(Configuration) + _CRT_SECURE_NO_WARNINGS;_UNICODE;UNICODE;WIN32_LEAN_AND_MEAN;WIN32;_WIN32;__WINDOWS__;_HAS_EXCEPTIONS=0;WIN64;DEBUG;PROFILING_ENABLED;JULIET_WIN32; ..\;..\Juliet\include;..\Game;C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\um;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\shared; /std:c++20 /wd5267 /wd4061 /wd4505 /wd4514 /wd4577 /wd4625 /wd4710 /wd4711 /wd4746 /wd4820 /wd5045 /wd5220 /wd5245 $(SolutionDir)\bin\$(Configuration)\ @@ -248,8 +248,8 @@ cd $(SolutionDir) & misc\fbuild -ide -dist -monitor -cache $(ProjectName)-$(Configuration) - cd $(SolutionDir) & mics\fbuild -ide -dist -monitor -cache -clean $(ProjectName)-$(Configuration) - WIN32_LEAN_AND_MEAN;WIN32;_WIN32;__WINDOWS__;_HAS_EXCEPTIONS=0;WIN64;RELEASE;PROFILING_ENABLED;JULIET_WIN32; + cd $(SolutionDir) & misc\fbuild -ide -dist -monitor -cache -clean $(ProjectName)-$(Configuration) + _CRT_SECURE_NO_WARNINGS;_UNICODE;UNICODE;WIN32_LEAN_AND_MEAN;WIN32;_WIN32;__WINDOWS__;_HAS_EXCEPTIONS=0;WIN64;RELEASE;PROFILING_ENABLED;JULIET_WIN32; ..\;..\Juliet\include;..\Game;C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\um;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\shared; /std:c++20 /wd5267 /wd4061 /wd4505 /wd4514 /wd4577 /wd4625 /wd4710 /wd4711 /wd4746 /wd4820 /wd5045 /wd5220 /wd5245 $(SolutionDir)\bin\$(Configuration)\ @@ -258,8 +258,8 @@ cd $(SolutionDir) & misc\fbuild -ide -dist -monitor -cache $(ProjectName)-$(Configuration) - cd $(SolutionDir) & mics\fbuild -ide -dist -monitor -cache -clean $(ProjectName)-$(Configuration) - WIN32_LEAN_AND_MEAN;WIN32;_WIN32;__WINDOWS__;_HAS_EXCEPTIONS=0;WIN64;RELEASE;JULIET_WIN32; + cd $(SolutionDir) & misc\fbuild -ide -dist -monitor -cache -clean $(ProjectName)-$(Configuration) + _CRT_SECURE_NO_WARNINGS;_UNICODE;UNICODE;WIN32_LEAN_AND_MEAN;WIN32;_WIN32;__WINDOWS__;_HAS_EXCEPTIONS=0;WIN64;RELEASE;JULIET_WIN32; ..\;..\Juliet\include;..\Game;C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\um;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\shared; /std:c++20 /wd5267 /wd4061 /wd4505 /wd4514 /wd4577 /wd4625 /wd4710 /wd4711 /wd4746 /wd4820 /wd5045 /wd5220 /wd5245 $(SolutionDir)\bin\$(Configuration)\ @@ -268,8 +268,8 @@ cd $(SolutionDir) & misc\fbuild -ide -dist -monitor -cache $(ProjectName)-$(Configuration) - cd $(SolutionDir) & mics\fbuild -ide -dist -monitor -cache -clean $(ProjectName)-$(Configuration) - WIN32_LEAN_AND_MEAN;WIN32;_WIN32;__WINDOWS__;_HAS_EXCEPTIONS=0;WIN64;DEBUG;PROFILING_ENABLED;JULIET_WIN32; + cd $(SolutionDir) & misc\fbuild -ide -dist -monitor -cache -clean $(ProjectName)-$(Configuration) + _CRT_SECURE_NO_WARNINGS;_UNICODE;UNICODE;WIN32_LEAN_AND_MEAN;WIN32;_WIN32;__WINDOWS__;_HAS_EXCEPTIONS=0;WIN64;DEBUG;PROFILING_ENABLED;JULIET_WIN32; ..\;..\Juliet\include;..\Game;C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\um;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\shared; /std:c++20 /wd5267 /wd4061 /wd4505 /wd4514 /wd4577 /wd4625 /wd4710 /wd4711 /wd4746 /wd4820 /wd5045 /wd5220 /wd5245 $(SolutionDir)\bin\$(Configuration)\ @@ -278,8 +278,8 @@ cd $(SolutionDir) & misc\fbuild -ide -dist -monitor -cache $(ProjectName)-$(Configuration) - cd $(SolutionDir) & mics\fbuild -ide -dist -monitor -cache -clean $(ProjectName)-$(Configuration) - WIN32_LEAN_AND_MEAN;WIN32;_WIN32;__WINDOWS__;_HAS_EXCEPTIONS=0;WIN64;RELEASE;PROFILING_ENABLED;JULIET_WIN32; + cd $(SolutionDir) & misc\fbuild -ide -dist -monitor -cache -clean $(ProjectName)-$(Configuration) + _CRT_SECURE_NO_WARNINGS;_UNICODE;UNICODE;WIN32_LEAN_AND_MEAN;WIN32;_WIN32;__WINDOWS__;_HAS_EXCEPTIONS=0;WIN64;RELEASE;PROFILING_ENABLED;JULIET_WIN32; ..\;..\Juliet\include;..\Game;C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\um;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\shared; /std:c++20 /wd5267 /wd4061 /wd4505 /wd4514 /wd4577 /wd4625 /wd4710 /wd4711 /wd4746 /wd4820 /wd5045 /wd5220 /wd5245 $(SolutionDir)\bin\$(Configuration)\ @@ -288,8 +288,8 @@ cd $(SolutionDir) & misc\fbuild -ide -dist -monitor -cache $(ProjectName)-$(Configuration) - cd $(SolutionDir) & mics\fbuild -ide -dist -monitor -cache -clean $(ProjectName)-$(Configuration) - WIN32_LEAN_AND_MEAN;WIN32;_WIN32;__WINDOWS__;_HAS_EXCEPTIONS=0;WIN64;RELEASE;JULIET_WIN32; + cd $(SolutionDir) & misc\fbuild -ide -dist -monitor -cache -clean $(ProjectName)-$(Configuration) + _CRT_SECURE_NO_WARNINGS;_UNICODE;UNICODE;WIN32_LEAN_AND_MEAN;WIN32;_WIN32;__WINDOWS__;_HAS_EXCEPTIONS=0;WIN64;RELEASE;JULIET_WIN32; ..\;..\Juliet\include;..\Game;C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\um;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\shared; /std:c++20 /wd5267 /wd4061 /wd4505 /wd4514 /wd4577 /wd4625 /wd4710 /wd4711 /wd4746 /wd4820 /wd5045 /wd5220 /wd5245 $(SolutionDir)\bin\$(Configuration)\ diff --git a/Juliet/include/Graphics/Graphics.h b/Juliet/include/Graphics/Graphics.h index 7cf877c..24e5078 100644 --- a/Juliet/include/Graphics/Graphics.h +++ b/Juliet/include/Graphics/Graphics.h @@ -120,9 +120,10 @@ namespace Juliet extern JULIET_API void SetStencilReference(NonNullPtr renderPass, uint8 reference); extern JULIET_API void BindGraphicsPipeline(NonNullPtr renderPass, NonNullPtr graphicsPipeline); - extern JULIET_API void DrawPrimitives(NonNullPtr renderPass, uint32 numVertices, uint32 numInstances, uint32 firstVertex, uint32 firstInstance); + extern JULIET_API void SetPushConstants(NonNullPtr commandList, ShaderStage stage, + uint32 rootParameterIndex, uint32 numConstants, const void* constants); // Fences extern JULIET_API bool WaitUntilGPUIsIdle(NonNullPtr device); @@ -142,9 +143,16 @@ namespace Juliet #endif // Buffers - extern GraphicsBuffer* CreateGraphicsBuffer(NonNullPtr device, const BufferCreateInfo& createInfo); - extern GraphicsTransferBuffer* CreateGraphicsTransferBuffer(NonNullPtr device, - const TransferBufferCreateInfo& createInfo); - extern void ReleaseGraphicsBuffer(NonNullPtr device, NonNullPtr buffer); - extern void ReleaseGraphicsTransferBuffer(NonNullPtr device, NonNullPtr buffer); + extern JULIET_API GraphicsBuffer* CreateGraphicsBuffer(NonNullPtr device, const BufferCreateInfo& createInfo); + extern JULIET_API GraphicsTransferBuffer* CreateGraphicsTransferBuffer(NonNullPtr device, + const TransferBufferCreateInfo& createInfo); + extern JULIET_API void* MapGraphicsTransferBuffer(NonNullPtr device, NonNullPtr buffer); + extern JULIET_API void UnmapGraphicsTransferBuffer(NonNullPtr device, NonNullPtr buffer); + extern JULIET_API void CopyBuffer(NonNullPtr commandList, NonNullPtr dst, + NonNullPtr src, size_t size, size_t dstOffset = 0, + size_t srcOffset = 0); + extern JULIET_API void TransitionBufferToReadable(NonNullPtr commandList, NonNullPtr buffer); + extern JULIET_API uint32 GetDescriptorIndex(NonNullPtr device, NonNullPtr buffer); + extern JULIET_API void DestroyGraphicsBuffer(NonNullPtr device, NonNullPtr buffer); + extern JULIET_API void DestroyGraphicsTransferBuffer(NonNullPtr device, NonNullPtr buffer); } // namespace Juliet diff --git a/Juliet/src/Graphics/D3D12/D3D12Buffer.cpp b/Juliet/src/Graphics/D3D12/D3D12Buffer.cpp index 6d9ab9b..f1e9968 100644 --- a/Juliet/src/Graphics/D3D12/D3D12Buffer.cpp +++ b/Juliet/src/Graphics/D3D12/D3D12Buffer.cpp @@ -1,5 +1,9 @@ #include #include + +#include +#include +#include #include #include #include @@ -10,12 +14,9 @@ namespace Juliet::D3D12 { struct D3D12Buffer { - ID3D12Resource* Handle; - int32 ReferenceCount; - - Internal::D3D12DescriptorHeap CBVDescriptorHeap; - Internal::D3D12DescriptorHeap SRVDescriptorHeap; - Internal::D3D12DescriptorHeap UAVDescriptorHeap; + Internal::D3D12Descriptor Descriptor; + ID3D12Resource* Handle; + D3D12_RESOURCE_STATES CurrentState; }; enum class D3D12BufferType : uint8 @@ -25,13 +26,18 @@ namespace Juliet::D3D12 TransferUpload, }; - void DestroyBuffer(NonNullPtr /*d3d12Driver*/, D3D12Buffer* buffer) + void DestroyBuffer(D3D12Buffer* buffer) { if (!buffer) { return; } + if (buffer->Descriptor.Index != UINT32_MAX) + { + Internal::ReleaseDescriptor(buffer->Descriptor); + } + if (buffer->Handle) { ID3D12Resource_Release(buffer->Handle); @@ -47,6 +53,12 @@ namespace Juliet::D3D12 return nullptr; } + // Align size for Constant Buffers + if (usage == BufferUsage::ConstantBuffer) + { + size = (size + 255U) & ~255U; + } + D3D12_RESOURCE_STATES initialState = D3D12_RESOURCE_STATE_COMMON; D3D12_HEAP_PROPERTIES heapProperties = {}; D3D12_HEAP_FLAGS heapFlags = D3D12_HEAP_FLAG_NONE; @@ -59,8 +71,8 @@ namespace Juliet::D3D12 { case BufferUsage::None: { - Assert(false , "Creating buffer with invalid usage"); - DestroyBuffer(d3d12Driver, buffer); + Assert(false, "Creating buffer with invalid usage"); + DestroyBuffer(buffer); return nullptr; } @@ -114,9 +126,7 @@ namespace Juliet::D3D12 } } - // D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc; - // D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc; - // D3D12_CONSTANT_BUFFER_VIEW_DESC cbvDesc; + D3D12_CONSTANT_BUFFER_VIEW_DESC cbvDesc = {}; D3D12_RESOURCE_DESC desc = {}; desc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER; @@ -138,14 +148,55 @@ namespace Juliet::D3D12 if (FAILED(result)) { LogError(d3d12Driver->D3D12Device, "Could not create buffer!", result); - DestroyBuffer(d3d12Driver, buffer); + DestroyBuffer(buffer); return nullptr; } - buffer->ReferenceCount = 0; - buffer->Handle = handle; + buffer->Handle = handle; + buffer->CurrentState = initialState; + buffer->Descriptor.Index = UINT32_MAX; - return nullptr; + if (usage == BufferUsage::ConstantBuffer || usage == BufferUsage::StructuredBuffer) + { + auto& heap = d3d12Driver->BindlessDescriptorHeap; + + Internal::D3D12Descriptor descriptor; + if (Internal::AssignDescriptor(heap, descriptor)) + { + buffer->Descriptor = descriptor; + + D3D12_CPU_DESCRIPTOR_HANDLE cpuHandle = descriptor.CpuHandle; + + if (usage == BufferUsage::ConstantBuffer) + { + cbvDesc.BufferLocation = ID3D12Resource_GetGPUVirtualAddress(handle); + cbvDesc.SizeInBytes = static_cast(size); + ID3D12Device_CreateConstantBufferView(d3d12Driver->D3D12Device, &cbvDesc, cpuHandle); + } + else if (usage == BufferUsage::StructuredBuffer) + { + D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc = {}; + srvDesc.ViewDimension = D3D12_SRV_DIMENSION_BUFFER; + srvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING; + srvDesc.Buffer.FirstElement = 0; + srvDesc.Buffer.NumElements = static_cast( + size / 4); // Assuming 4 bytes stride for raw access or similar. Ideally should be provided. + srvDesc.Buffer.StructureByteStride = 0; // Raw buffer for simplicity, or 4 if typed? + // If it's a Structured Buffer, we typically need stride. For now let's assume raw ByteAddressBuffer (R32_TYPELESS) or similar if stride is 0. + // Actually, let's treat it as a ByteAddressBuffer (Raw) for most flexibility in bindless. + srvDesc.Format = DXGI_FORMAT_R32_TYPELESS; + srvDesc.Buffer.Flags = D3D12_BUFFER_SRV_FLAG_RAW; + + ID3D12Device_CreateShaderResourceView(d3d12Driver->D3D12Device, handle, &srvDesc, cpuHandle); + } + } + else + { + LogError(LogCategory::Graphics, "Bindless Heap Full or Invalid!"); + } + } + + return buffer; } } // namespace @@ -155,6 +206,11 @@ namespace Juliet::D3D12 return reinterpret_cast(CreateBuffer(d3d12Driver, size, usage, D3D12BufferType::Base)); } + void DestroyGraphicsBuffer(NonNullPtr buffer) + { + DestroyBuffer(reinterpret_cast(buffer.Get())); + } + GraphicsTransferBuffer* CreateGraphicsTransferBuffer(NonNullPtr driver, size_t size, TransferBufferUsage usage) { auto d3d12Driver = static_cast(driver.Get()); @@ -163,4 +219,86 @@ namespace Juliet::D3D12 usage == TransferBufferUsage::Upload ? D3D12BufferType::TransferUpload : D3D12BufferType::TransferDownload)); } + void DestroyGraphicsTransferBuffer(NonNullPtr buffer) + { + DestroyBuffer(reinterpret_cast(buffer.Get())); + } + + void* MapBuffer(NonNullPtr /*driver*/, NonNullPtr buffer) + { + auto d3d12Buffer = reinterpret_cast(buffer.Get()); + void* ptr = nullptr; + // 0-0 range means we don't intend to read anything. + D3D12_RANGE readRange = { 0, 0 }; + if (FAILED(ID3D12Resource_Map(d3d12Buffer->Handle, 0, &readRange, &ptr))) + { + return nullptr; + } + return ptr; + } + + void UnmapBuffer(NonNullPtr /*driver*/, NonNullPtr buffer) + { + auto d3d12Buffer = reinterpret_cast(buffer.Get()); + ID3D12Resource_Unmap(d3d12Buffer->Handle, 0, nullptr); + } + + uint32 GetDescriptorIndex(NonNullPtr /*driver*/, NonNullPtr buffer) + { + auto d3d12Buffer = reinterpret_cast(buffer.Get()); + return d3d12Buffer->Descriptor.Index; + } + + void CopyBuffer(NonNullPtr commandList, NonNullPtr dst, + NonNullPtr src, size_t size, size_t dstOffset, size_t srcOffset) + { + auto d3d12CmdList = reinterpret_cast(commandList.Get()); + auto d3d12Dst = reinterpret_cast(dst.Get()); + auto d3d12Src = reinterpret_cast(src.Get()); + + // Transition DST to COPY_DEST if needed + if (d3d12Dst->CurrentState != D3D12_RESOURCE_STATE_COPY_DEST) + { + D3D12_RESOURCE_BARRIER barrier = {}; + barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION; + barrier.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE; + barrier.Transition.pResource = d3d12Dst->Handle; + barrier.Transition.StateBefore = d3d12Dst->CurrentState; + barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_COPY_DEST; + barrier.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES; + + ID3D12GraphicsCommandList_ResourceBarrier(d3d12CmdList->GraphicsCommandList.CommandList, 1, &barrier); + d3d12Dst->CurrentState = D3D12_RESOURCE_STATE_COPY_DEST; + } + + // Src is Upload Buffer, usually effectively GenericRead/Common but for Upload heaps it's simpler. + // We assume Upload buffers are always in state GENERIC_READ or similar suitable for CopySrc. + // D3D12 Upload heaps start in GENERIC_READ and cannot transition. + + ID3D12GraphicsCommandList_CopyBufferRegion(d3d12CmdList->GraphicsCommandList.CommandList, d3d12Dst->Handle, + dstOffset, d3d12Src->Handle, srcOffset, size); + } + + void TransitionBufferToReadable(NonNullPtr commandList, NonNullPtr buffer) + { + auto d3d12CmdList = reinterpret_cast(commandList.Get()); + auto d3d12Buffer = reinterpret_cast(buffer.Get()); + + D3D12_RESOURCE_STATES neededState = D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE | D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE; + + if (d3d12Buffer->CurrentState != neededState) + { + D3D12_RESOURCE_BARRIER barrier = {}; + barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION; + barrier.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE; + barrier.Transition.pResource = d3d12Buffer->Handle; + barrier.Transition.StateBefore = d3d12Buffer->CurrentState; + barrier.Transition.StateAfter = neededState; + barrier.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES; + + ID3D12GraphicsCommandList_ResourceBarrier(d3d12CmdList->GraphicsCommandList.CommandList, 1, &barrier); + d3d12Buffer->CurrentState = neededState; + } + } + } // namespace Juliet::D3D12 diff --git a/Juliet/src/Graphics/D3D12/D3D12Buffer.h b/Juliet/src/Graphics/D3D12/D3D12Buffer.h index 41466ae..8e01995 100644 --- a/Juliet/src/Graphics/D3D12/D3D12Buffer.h +++ b/Juliet/src/Graphics/D3D12/D3D12Buffer.h @@ -5,10 +5,21 @@ namespace Juliet { + struct CommandList; struct GPUDriver; -} +} // namespace Juliet namespace Juliet::D3D12 { extern GraphicsBuffer* CreateGraphicsBuffer(NonNullPtr driver, size_t size, BufferUsage usage); + extern void DestroyGraphicsBuffer(NonNullPtr buffer); + extern GraphicsTransferBuffer* CreateGraphicsTransferBuffer(NonNullPtr driver, size_t size, TransferBufferUsage usage); -} + extern void DestroyGraphicsTransferBuffer(NonNullPtr buffer); + + extern void* MapBuffer(NonNullPtr driver, NonNullPtr buffer); + extern void UnmapBuffer(NonNullPtr driver, NonNullPtr buffer); + extern uint32 GetDescriptorIndex(NonNullPtr driver, NonNullPtr buffer); + extern void CopyBuffer(NonNullPtr commandList, NonNullPtr dst, + NonNullPtr src, size_t size, size_t dstOffset, size_t srcOffset); + extern void TransitionBufferToReadable(NonNullPtr commandList, NonNullPtr buffer); +} // namespace Juliet::D3D12 diff --git a/Juliet/src/Graphics/D3D12/D3D12CommandList.cpp b/Juliet/src/Graphics/D3D12/D3D12CommandList.cpp index d4433ff..5718fc1 100644 --- a/Juliet/src/Graphics/D3D12/D3D12CommandList.cpp +++ b/Juliet/src/Graphics/D3D12/D3D12CommandList.cpp @@ -30,7 +30,7 @@ namespace Juliet::D3D12 reinterpret_cast(&baseData->Allocator)); if (FAILED(result)) { - Assert(false, "Error not implemented: cannot create ID3D12CommandAllocator"); + AssertHR(result, "Cannot create ID3D12CommandAllocator"); return false; } @@ -101,7 +101,7 @@ namespace Juliet::D3D12 if (FAILED(result)) { - AssertHR(result, "Error not implemented: cannot create ID3D12GraphicsCommandList (copy command list)"); + AssertHR(result, "cannot create ID3D12GraphicsCommandList (copy command list)"); return false; } commandList->CopyCommandList.CommandList = d3d12CopyCommandList; @@ -369,6 +369,15 @@ namespace Juliet::D3D12 ID3D12GraphicsCommandList_OMSetStencilRef(d3d12CommandList->GraphicsCommandList.CommandList, reference); } + void SetPushConstants(NonNullPtr commandList, ShaderStage /*stage*/, uint32 rootParameterIndex, + uint32 numConstants, const void* constants) + { + auto d3d12CommandList = reinterpret_cast(commandList.Get()); + // For now we assume Graphics Root Signature. Compute support would need a check or separate function. + ID3D12GraphicsCommandList_SetGraphicsRoot32BitConstants(d3d12CommandList->GraphicsCommandList.CommandList, + rootParameterIndex, numConstants, constants, 0); + } + namespace Internal { void SetDescriptorHeaps(NonNullPtr commandList) @@ -377,7 +386,8 @@ namespace Juliet::D3D12 D3D12DescriptorHeap* viewHeap = nullptr; D3D12DescriptorHeap* samplerHeap = nullptr; - viewHeap = AcquireDescriptorHeapFromPool(commandList->Driver, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV); + viewHeap = commandList->Driver->BindlessDescriptorHeap; + samplerHeap = AcquireDescriptorHeapFromPool(commandList->Driver, D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER); commandList->CRB_SRV_UAV_Heap = viewHeap; @@ -426,7 +436,7 @@ namespace Juliet::D3D12 } // Return heap descriptor to pool - ReturnDescriptorHeapToPool(driver, commandList->CRB_SRV_UAV_Heap); + // CRB_SRV_UAV_Heap is global bindless, do not return it. ReturnDescriptorHeapToPool(driver, commandList->RTV_Heap); commandList->CRB_SRV_UAV_Heap = nullptr; commandList->RTV_Heap = nullptr; diff --git a/Juliet/src/Graphics/D3D12/D3D12CommandList.h b/Juliet/src/Graphics/D3D12/D3D12CommandList.h index 08b278c..a6de01c 100644 --- a/Juliet/src/Graphics/D3D12/D3D12CommandList.h +++ b/Juliet/src/Graphics/D3D12/D3D12CommandList.h @@ -93,7 +93,9 @@ namespace Juliet::D3D12 extern void SetViewPort(NonNullPtr commandList, const GraphicsViewPort& viewPort); extern void SetScissorRect(NonNullPtr commandList, const Rectangle& rectangle); extern void SetBlendConstants(NonNullPtr commandList, FColor blendConstants); + extern void SetBlendConstants(NonNullPtr commandList, FColor blendConstants); extern void SetStencilReference(NonNullPtr commandList, uint8 reference); + extern void SetPushConstants(NonNullPtr commandList, ShaderStage stage, uint32 rootParameterIndex, uint32 numConstants, const void* constants); namespace Internal { diff --git a/Juliet/src/Graphics/D3D12/D3D12DescriptorHeap.cpp b/Juliet/src/Graphics/D3D12/D3D12DescriptorHeap.cpp index fcf1414..a03ff74 100644 --- a/Juliet/src/Graphics/D3D12/D3D12DescriptorHeap.cpp +++ b/Juliet/src/Graphics/D3D12/D3D12DescriptorHeap.cpp @@ -16,6 +16,9 @@ namespace Juliet::D3D12::Internal } heap->CurrentDescriptorIndex = 0; + heap->FreeIndicesCapacity = 16; + heap->FreeIndicesCount = 0; + heap->FreeIndices = static_cast(Calloc(heap->FreeIndicesCapacity, sizeof(uint32))); D3D12_DESCRIPTOR_HEAP_DESC heapDesc; heapDesc.NumDescriptors = count; @@ -52,9 +55,56 @@ namespace Juliet::D3D12::Internal { ID3D12DescriptorHeap_Release(heap->Handle); } + SafeFree(heap->FreeIndices); Free(heap.Get()); } + bool AssignDescriptor(D3D12DescriptorHeap* heap, D3D12Descriptor& outDescriptor) + { + uint32 index = UINT32_MAX; + + if (heap->FreeIndicesCount > 0) + { + heap->FreeIndicesCount -= 1; + index = heap->FreeIndices[heap->FreeIndicesCount]; + } + else if (heap->CurrentDescriptorIndex < heap->MaxDescriptors) + { + index = heap->CurrentDescriptorIndex; + heap->CurrentDescriptorIndex++; + } + else + { + Assert(false, "Descriptor Heap Full!"); + return false; + } + + outDescriptor.Heap = heap; + outDescriptor.Index = index; + outDescriptor.CpuHandle = heap->DescriptorHeapCPUStart; + outDescriptor.CpuHandle.ptr += heap->DescriptorSize * index; + outDescriptor.GpuHandle = heap->DescriptorHeapGPUStart; + outDescriptor.GpuHandle.ptr += heap->DescriptorSize * index; + + return true; + } + + void ReleaseDescriptor(const D3D12Descriptor& descriptor) + { + if (descriptor.Index == UINT32_MAX || descriptor.Heap == nullptr) return; + + D3D12DescriptorHeap* heap = descriptor.Heap; + + if (heap->FreeIndicesCount >= heap->FreeIndicesCapacity) + { + heap->FreeIndicesCapacity *= 2; + heap->FreeIndices = static_cast(Realloc(heap->FreeIndices, heap->FreeIndicesCapacity * sizeof(uint32))); + } + + heap->FreeIndices[heap->FreeIndicesCount] = descriptor.Index; + heap->FreeIndicesCount++; + } + D3D12DescriptorHeap* AcquireDescriptorHeapFromPool(NonNullPtr d3d12Driver, D3D12_DESCRIPTOR_HEAP_TYPE type) { D3D12DescriptorHeapPool* pool = nullptr; diff --git a/Juliet/src/Graphics/D3D12/D3D12DescriptorHeap.h b/Juliet/src/Graphics/D3D12/D3D12DescriptorHeap.h index c43b6c6..0d28c13 100644 --- a/Juliet/src/Graphics/D3D12/D3D12DescriptorHeap.h +++ b/Juliet/src/Graphics/D3D12/D3D12DescriptorHeap.h @@ -21,9 +21,22 @@ namespace Juliet::D3D12::Internal uint32 MaxDescriptors; uint32 DescriptorSize; uint32 CurrentDescriptorIndex; // only used by GPU heaps + + uint32* FreeIndices; + uint32 FreeIndicesCapacity; + uint32 FreeIndicesCount; + bool Staging : 1; }; + struct D3D12Descriptor + { + D3D12DescriptorHeap* Heap; + uint32 Index; + D3D12_CPU_DESCRIPTOR_HANDLE CpuHandle; + D3D12_GPU_DESCRIPTOR_HANDLE GpuHandle; + }; + struct D3D12DescriptorHeapPool { D3D12DescriptorHeap** Heaps; @@ -38,4 +51,7 @@ namespace Juliet::D3D12::Internal extern D3D12DescriptorHeap* AcquireDescriptorHeapFromPool(NonNullPtr commandList, D3D12_DESCRIPTOR_HEAP_TYPE type); extern void ReturnDescriptorHeapToPool(NonNullPtr d3d12Driver, D3D12DescriptorHeap* heap); + + extern bool AssignDescriptor(D3D12DescriptorHeap* heap, D3D12Descriptor& outDescriptor); + extern void ReleaseDescriptor(const D3D12Descriptor& descriptor); } // namespace Juliet::D3D12 diff --git a/Juliet/src/Graphics/D3D12/D3D12GraphicsDevice.cpp b/Juliet/src/Graphics/D3D12/D3D12GraphicsDevice.cpp index fa59d9e..9f8437d 100644 --- a/Juliet/src/Graphics/D3D12/D3D12GraphicsDevice.cpp +++ b/Juliet/src/Graphics/D3D12/D3D12GraphicsDevice.cpp @@ -461,7 +461,8 @@ namespace Juliet::D3D12 return; } - ID3D12InfoQueue1_RegisterMessageCallback(infoQueue, OnD3D12DebugInfoMsg, D3D12_MESSAGE_CALLBACK_FLAG_NONE, nullptr, nullptr); + ID3D12InfoQueue1_RegisterMessageCallback(infoQueue, OnD3D12DebugInfoMsg, D3D12_MESSAGE_CALLBACK_FLAG_NONE, + nullptr, nullptr); ID3D12InfoQueue1_Release(infoQueue); } #endif @@ -520,6 +521,8 @@ namespace Juliet::D3D12 DestroyGraphicsRootSignature(driver->BindlessRootSignature); + Internal::DestroyDescriptorHeap(driver->BindlessDescriptorHeap); + // Clean allocations SafeFree(driver->AvailableCommandLists); SafeFree(driver->SubmittedCommandLists); @@ -999,6 +1002,7 @@ namespace Juliet::D3D12 device->BindGraphicsPipeline = BindGraphicsPipeline; device->DrawPrimitives = DrawPrimitives; device->WaitUntilGPUIsIdle = WaitUntilGPUIsIdle; + device->SetPushConstants = SetPushConstants; device->QueryFence = QueryFence; device->ReleaseFence = ReleaseFence; device->CreateShader = CreateShader; @@ -1006,7 +1010,14 @@ namespace Juliet::D3D12 device->CreateGraphicsPipeline = CreateGraphicsPipeline; device->DestroyGraphicsPipeline = DestroyGraphicsPipeline; device->CreateGraphicsBuffer = CreateGraphicsBuffer; + device->DestroyGraphicsBuffer = DestroyGraphicsBuffer; device->CreateGraphicsTransferBuffer = CreateGraphicsTransferBuffer; + device->DestroyGraphicsTransferBuffer = DestroyGraphicsTransferBuffer; + device->MapGraphicsTransferBuffer = MapBuffer; + device->UnmapGraphicsTransferBuffer = UnmapBuffer; + device->CopyBuffer = CopyBuffer; + device->TransitionBufferToReadable = TransitionBufferToReadable; + device->GetDescriptorIndex = GetDescriptorIndex; #if ALLOW_SHADER_HOT_RELOAD device->UpdateGraphicsPipelineShaders = UpdateGraphicsPipelineShaders; @@ -1017,6 +1028,9 @@ namespace Juliet::D3D12 driver->GraphicsDevice = device; + // Create Global Bindless Heap that stays alive for the driver whole lifetime + driver->BindlessDescriptorHeap = Internal::AcquireDescriptorHeapFromPool(driver, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV); + return device; } } // namespace diff --git a/Juliet/src/Graphics/D3D12/D3D12GraphicsDevice.h b/Juliet/src/Graphics/D3D12/D3D12GraphicsDevice.h index 6b2be61..3f0f075 100644 --- a/Juliet/src/Graphics/D3D12/D3D12GraphicsDevice.h +++ b/Juliet/src/Graphics/D3D12/D3D12GraphicsDevice.h @@ -98,6 +98,7 @@ namespace Juliet::D3D12 D3D12GraphicsRootSignature* BindlessRootSignature; D3D12StagingDescriptorPool* StagingDescriptorPools[D3D12_DESCRIPTOR_HEAP_TYPE_NUM_TYPES]; + Internal::D3D12DescriptorHeap* BindlessDescriptorHeap; Internal::D3D12DescriptorHeapPool CRB_SRV_UAV_HeapPool; Internal::D3D12DescriptorHeapPool RTV_HeapPool; diff --git a/Juliet/src/Graphics/Graphics.cpp b/Juliet/src/Graphics/Graphics.cpp index 64e287f..c85d516 100644 --- a/Juliet/src/Graphics/Graphics.cpp +++ b/Juliet/src/Graphics/Graphics.cpp @@ -264,6 +264,13 @@ namespace Juliet commandListHeader->Device->DrawPrimitives(commandList, numVertices, numInstances, firstVertex, firstInstance); } + void SetPushConstants(NonNullPtr commandList, ShaderStage stage, uint32 rootParameterIndex, + uint32 numConstants, const void* constants) + { + auto* header = reinterpret_cast(commandList.Get()); + header->Device->SetPushConstants(commandList, stage, rootParameterIndex, numConstants, constants); + } + // Fences bool WaitUntilGPUIsIdle(NonNullPtr device) { @@ -335,15 +342,41 @@ namespace Juliet return device->CreateGraphicsTransferBuffer(device->Driver, createInfo.Size, createInfo.Usage); } - void ReleaseGraphicsBuffer(NonNullPtr device, NonNullPtr buffer) + void* MapGraphicsTransferBuffer(NonNullPtr device, NonNullPtr buffer) { - (void)device; - (void)buffer; + return device->MapGraphicsTransferBuffer(device->Driver, buffer); } - void ReleaseGraphicsTransferBuffer(NonNullPtr device, NonNullPtr buffer) + void UnmapGraphicsTransferBuffer(NonNullPtr device, NonNullPtr buffer) { - (void)device; - (void)buffer; + device->UnmapGraphicsTransferBuffer(device->Driver, buffer); + } + + void CopyBuffer(NonNullPtr commandList, NonNullPtr dst, + NonNullPtr src, size_t size, size_t dstOffset, size_t srcOffset) + { + auto* header = reinterpret_cast(commandList.Get()); + header->Device->CopyBuffer(commandList, dst, src, size, dstOffset, srcOffset); + } + + void TransitionBufferToReadable(NonNullPtr commandList, NonNullPtr buffer) + { + auto* header = reinterpret_cast(commandList.Get()); + header->Device->TransitionBufferToReadable(commandList, buffer); + } + + uint32 GetDescriptorIndex(NonNullPtr device, NonNullPtr buffer) + { + return device->GetDescriptorIndex(device->Driver, buffer); + } + + void DestroyGraphicsBuffer(NonNullPtr device, NonNullPtr buffer) + { + device->DestroyGraphicsBuffer(buffer); + } + + void DestroyGraphicsTransferBuffer(NonNullPtr device, NonNullPtr buffer) + { + device->DestroyGraphicsTransferBuffer(buffer); } } // namespace Juliet diff --git a/Juliet/src/Graphics/GraphicsDevice.h b/Juliet/src/Graphics/GraphicsDevice.h index 32af354..acdd256 100644 --- a/Juliet/src/Graphics/GraphicsDevice.h +++ b/Juliet/src/Graphics/GraphicsDevice.h @@ -71,6 +71,9 @@ namespace Juliet void (*DrawPrimitives)(NonNullPtr commandList, uint32 numVertices, uint32 numInstances, uint32 firstVertex, uint32 firstInstance); + void (*SetPushConstants)(NonNullPtr commandList, ShaderStage stage, uint32 rootParameterIndex, + uint32 numConstants, const void* constants); + // Fences bool (*WaitUntilGPUIsIdle)(NonNullPtr driver); bool (*QueryFence)(NonNullPtr driver, NonNullPtr fence); @@ -88,7 +91,17 @@ namespace Juliet // Buffers GraphicsBuffer* (*CreateGraphicsBuffer)(NonNullPtr driver, size_t size, BufferUsage usage); + void (*DestroyGraphicsBuffer)(NonNullPtr buffer); + GraphicsTransferBuffer* (*CreateGraphicsTransferBuffer)(NonNullPtr driver, size_t size, TransferBufferUsage usage); + void (*DestroyGraphicsTransferBuffer)(NonNullPtr buffer); + + void* (*MapGraphicsTransferBuffer)(NonNullPtr driver, NonNullPtr buffer); + void (*UnmapGraphicsTransferBuffer)(NonNullPtr driver, NonNullPtr buffer); + void (*CopyBuffer)(NonNullPtr commandList, NonNullPtr dst, + NonNullPtr src, size_t size, size_t dstOffset, size_t srcOffset); + void (*TransitionBufferToReadable)(NonNullPtr commandList, NonNullPtr buffer); + uint32 (*GetDescriptorIndex)(NonNullPtr driver, NonNullPtr buffer); const char* Name = "Unknown"; GPUDriver* Driver = nullptr; diff --git a/JulietApp/JulietApp.vcxproj b/JulietApp/JulietApp.vcxproj index 8cbfced..44f9063 100644 --- a/JulietApp/JulietApp.vcxproj +++ b/JulietApp/JulietApp.vcxproj @@ -254,8 +254,8 @@ cd $(SolutionDir) & misc\fbuild -ide -dist -monitor -cache $(ProjectName)-$(Configuration) - cd $(SolutionDir) & mics\fbuild -ide -dist -monitor -cache -clean $(ProjectName)-$(Configuration) - WIN32_LEAN_AND_MEAN;WIN32;_WIN32;__WINDOWS__;_HAS_EXCEPTIONS=0;WIN64;DEBUG;PROFILING_ENABLED;JULIET_EXPORT;JULIET_WIN32; + cd $(SolutionDir) & misc\fbuild -ide -dist -monitor -cache -clean $(ProjectName)-$(Configuration) + _CRT_SECURE_NO_WARNINGS;_UNICODE;UNICODE;WIN32_LEAN_AND_MEAN;WIN32;_WIN32;__WINDOWS__;_HAS_EXCEPTIONS=0;WIN64;DEBUG;PROFILING_ENABLED;JULIET_EXPORT;JULIET_WIN32; ..\;..\Juliet\include;..\Juliet\src;C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\um;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\shared; /std:c++20 /wd5267 /wd4061 /wd4505 /wd4514 /wd4577 /wd4625 /wd4710 /wd4711 /wd4746 /wd4820 /wd5045 /wd5220 /wd5245 $(SolutionDir)\bin\$(Configuration)\ @@ -264,8 +264,8 @@ cd $(SolutionDir) & misc\fbuild -ide -dist -monitor -cache $(ProjectName)-$(Configuration) - cd $(SolutionDir) & mics\fbuild -ide -dist -monitor -cache -clean $(ProjectName)-$(Configuration) - WIN32_LEAN_AND_MEAN;WIN32;_WIN32;__WINDOWS__;_HAS_EXCEPTIONS=0;WIN64;RELEASE;PROFILING_ENABLED;JULIET_EXPORT;JULIET_WIN32; + cd $(SolutionDir) & misc\fbuild -ide -dist -monitor -cache -clean $(ProjectName)-$(Configuration) + _CRT_SECURE_NO_WARNINGS;_UNICODE;UNICODE;WIN32_LEAN_AND_MEAN;WIN32;_WIN32;__WINDOWS__;_HAS_EXCEPTIONS=0;WIN64;RELEASE;PROFILING_ENABLED;JULIET_EXPORT;JULIET_WIN32; ..\;..\Juliet\include;..\Juliet\src;C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\um;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\shared; /std:c++20 /wd5267 /wd4061 /wd4505 /wd4514 /wd4577 /wd4625 /wd4710 /wd4711 /wd4746 /wd4820 /wd5045 /wd5220 /wd5245 $(SolutionDir)\bin\$(Configuration)\ @@ -274,8 +274,8 @@ cd $(SolutionDir) & misc\fbuild -ide -dist -monitor -cache $(ProjectName)-$(Configuration) - cd $(SolutionDir) & mics\fbuild -ide -dist -monitor -cache -clean $(ProjectName)-$(Configuration) - WIN32_LEAN_AND_MEAN;WIN32;_WIN32;__WINDOWS__;_HAS_EXCEPTIONS=0;WIN64;RELEASE;JULIET_EXPORT;JULIET_WIN32; + cd $(SolutionDir) & misc\fbuild -ide -dist -monitor -cache -clean $(ProjectName)-$(Configuration) + _CRT_SECURE_NO_WARNINGS;_UNICODE;UNICODE;WIN32_LEAN_AND_MEAN;WIN32;_WIN32;__WINDOWS__;_HAS_EXCEPTIONS=0;WIN64;RELEASE;JULIET_EXPORT;JULIET_WIN32; ..\;..\Juliet\include;..\Juliet\src;C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\um;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\shared; /std:c++20 /wd5267 /wd4061 /wd4505 /wd4514 /wd4577 /wd4625 /wd4710 /wd4711 /wd4746 /wd4820 /wd5045 /wd5220 /wd5245 $(SolutionDir)\bin\$(Configuration)\ @@ -284,8 +284,8 @@ cd $(SolutionDir) & misc\fbuild -ide -dist -monitor -cache $(ProjectName)-$(Configuration) - cd $(SolutionDir) & mics\fbuild -ide -dist -monitor -cache -clean $(ProjectName)-$(Configuration) - WIN32_LEAN_AND_MEAN;WIN32;_WIN32;__WINDOWS__;_HAS_EXCEPTIONS=0;WIN64;DEBUG;PROFILING_ENABLED;JULIET_EXPORT;JULIET_WIN32; + cd $(SolutionDir) & misc\fbuild -ide -dist -monitor -cache -clean $(ProjectName)-$(Configuration) + _CRT_SECURE_NO_WARNINGS;_UNICODE;UNICODE;WIN32_LEAN_AND_MEAN;WIN32;_WIN32;__WINDOWS__;_HAS_EXCEPTIONS=0;WIN64;DEBUG;PROFILING_ENABLED;JULIET_EXPORT;JULIET_WIN32; ..\;..\Juliet\include;..\Juliet\src;C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\um;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\shared; /std:c++20 /wd5267 /wd4061 /wd4505 /wd4514 /wd4577 /wd4625 /wd4710 /wd4711 /wd4746 /wd4820 /wd5045 /wd5220 /wd5245 $(SolutionDir)\bin\$(Configuration)\ @@ -294,8 +294,8 @@ cd $(SolutionDir) & misc\fbuild -ide -dist -monitor -cache $(ProjectName)-$(Configuration) - cd $(SolutionDir) & mics\fbuild -ide -dist -monitor -cache -clean $(ProjectName)-$(Configuration) - WIN32_LEAN_AND_MEAN;WIN32;_WIN32;__WINDOWS__;_HAS_EXCEPTIONS=0;WIN64;RELEASE;PROFILING_ENABLED;JULIET_EXPORT;JULIET_WIN32; + cd $(SolutionDir) & misc\fbuild -ide -dist -monitor -cache -clean $(ProjectName)-$(Configuration) + _CRT_SECURE_NO_WARNINGS;_UNICODE;UNICODE;WIN32_LEAN_AND_MEAN;WIN32;_WIN32;__WINDOWS__;_HAS_EXCEPTIONS=0;WIN64;RELEASE;PROFILING_ENABLED;JULIET_EXPORT;JULIET_WIN32; ..\;..\Juliet\include;..\Juliet\src;C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\um;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\shared; /std:c++20 /wd5267 /wd4061 /wd4505 /wd4514 /wd4577 /wd4625 /wd4710 /wd4711 /wd4746 /wd4820 /wd5045 /wd5220 /wd5245 $(SolutionDir)\bin\$(Configuration)\ @@ -304,8 +304,8 @@ cd $(SolutionDir) & misc\fbuild -ide -dist -monitor -cache $(ProjectName)-$(Configuration) - cd $(SolutionDir) & mics\fbuild -ide -dist -monitor -cache -clean $(ProjectName)-$(Configuration) - WIN32_LEAN_AND_MEAN;WIN32;_WIN32;__WINDOWS__;_HAS_EXCEPTIONS=0;WIN64;RELEASE;JULIET_EXPORT;JULIET_WIN32; + cd $(SolutionDir) & misc\fbuild -ide -dist -monitor -cache -clean $(ProjectName)-$(Configuration) + _CRT_SECURE_NO_WARNINGS;_UNICODE;UNICODE;WIN32_LEAN_AND_MEAN;WIN32;_WIN32;__WINDOWS__;_HAS_EXCEPTIONS=0;WIN64;RELEASE;JULIET_EXPORT;JULIET_WIN32; ..\;..\Juliet\include;..\Juliet\src;C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\um;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\shared; /std:c++20 /wd5267 /wd4061 /wd4505 /wd4514 /wd4577 /wd4625 /wd4710 /wd4711 /wd4746 /wd4820 /wd5045 /wd5220 /wd5245 $(SolutionDir)\bin\$(Configuration)\ @@ -314,8 +314,8 @@ cd $(SolutionDir) & misc\fbuild -ide -dist -monitor -cache $(ProjectName)-$(Configuration) - cd $(SolutionDir) & mics\fbuild -ide -dist -monitor -cache -clean $(ProjectName)-$(Configuration) - WIN32_LEAN_AND_MEAN;WIN32;_WIN32;__WINDOWS__;_HAS_EXCEPTIONS=0;WIN64;DEBUG;PROFILING_ENABLED;JULIET_WIN32; + cd $(SolutionDir) & misc\fbuild -ide -dist -monitor -cache -clean $(ProjectName)-$(Configuration) + _CRT_SECURE_NO_WARNINGS;_UNICODE;UNICODE;WIN32_LEAN_AND_MEAN;WIN32;_WIN32;__WINDOWS__;_HAS_EXCEPTIONS=0;WIN64;DEBUG;PROFILING_ENABLED;JULIET_WIN32; ..\;..\Juliet\include;..\Game;C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\um;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\shared; /std:c++20 /wd5267 /wd4061 /wd4505 /wd4514 /wd4577 /wd4625 /wd4710 /wd4711 /wd4746 /wd4820 /wd5045 /wd5220 /wd5245 $(SolutionDir)\bin\$(Configuration)\ @@ -324,8 +324,8 @@ cd $(SolutionDir) & misc\fbuild -ide -dist -monitor -cache $(ProjectName)-$(Configuration) - cd $(SolutionDir) & mics\fbuild -ide -dist -monitor -cache -clean $(ProjectName)-$(Configuration) - WIN32_LEAN_AND_MEAN;WIN32;_WIN32;__WINDOWS__;_HAS_EXCEPTIONS=0;WIN64;RELEASE;PROFILING_ENABLED;JULIET_WIN32; + cd $(SolutionDir) & misc\fbuild -ide -dist -monitor -cache -clean $(ProjectName)-$(Configuration) + _CRT_SECURE_NO_WARNINGS;_UNICODE;UNICODE;WIN32_LEAN_AND_MEAN;WIN32;_WIN32;__WINDOWS__;_HAS_EXCEPTIONS=0;WIN64;RELEASE;PROFILING_ENABLED;JULIET_WIN32; ..\;..\Juliet\include;..\Game;C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\um;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\shared; /std:c++20 /wd5267 /wd4061 /wd4505 /wd4514 /wd4577 /wd4625 /wd4710 /wd4711 /wd4746 /wd4820 /wd5045 /wd5220 /wd5245 $(SolutionDir)\bin\$(Configuration)\ @@ -334,8 +334,8 @@ cd $(SolutionDir) & misc\fbuild -ide -dist -monitor -cache $(ProjectName)-$(Configuration) - cd $(SolutionDir) & mics\fbuild -ide -dist -monitor -cache -clean $(ProjectName)-$(Configuration) - WIN32_LEAN_AND_MEAN;WIN32;_WIN32;__WINDOWS__;_HAS_EXCEPTIONS=0;WIN64;RELEASE;JULIET_WIN32; + cd $(SolutionDir) & misc\fbuild -ide -dist -monitor -cache -clean $(ProjectName)-$(Configuration) + _CRT_SECURE_NO_WARNINGS;_UNICODE;UNICODE;WIN32_LEAN_AND_MEAN;WIN32;_WIN32;__WINDOWS__;_HAS_EXCEPTIONS=0;WIN64;RELEASE;JULIET_WIN32; ..\;..\Juliet\include;..\Game;C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\um;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\shared; /std:c++20 /wd5267 /wd4061 /wd4505 /wd4514 /wd4577 /wd4625 /wd4710 /wd4711 /wd4746 /wd4820 /wd5045 /wd5220 /wd5245 $(SolutionDir)\bin\$(Configuration)\ @@ -344,8 +344,8 @@ cd $(SolutionDir) & misc\fbuild -ide -dist -monitor -cache $(ProjectName)-$(Configuration) - cd $(SolutionDir) & mics\fbuild -ide -dist -monitor -cache -clean $(ProjectName)-$(Configuration) - WIN32_LEAN_AND_MEAN;WIN32;_WIN32;__WINDOWS__;_HAS_EXCEPTIONS=0;WIN64;DEBUG;PROFILING_ENABLED;JULIET_WIN32; + cd $(SolutionDir) & misc\fbuild -ide -dist -monitor -cache -clean $(ProjectName)-$(Configuration) + _CRT_SECURE_NO_WARNINGS;_UNICODE;UNICODE;WIN32_LEAN_AND_MEAN;WIN32;_WIN32;__WINDOWS__;_HAS_EXCEPTIONS=0;WIN64;DEBUG;PROFILING_ENABLED;JULIET_WIN32; ..\;..\Juliet\include;..\Game;C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\um;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\shared; /std:c++20 /wd5267 /wd4061 /wd4505 /wd4514 /wd4577 /wd4625 /wd4710 /wd4711 /wd4746 /wd4820 /wd5045 /wd5220 /wd5245 $(SolutionDir)\bin\$(Configuration)\ @@ -354,8 +354,8 @@ cd $(SolutionDir) & misc\fbuild -ide -dist -monitor -cache $(ProjectName)-$(Configuration) - cd $(SolutionDir) & mics\fbuild -ide -dist -monitor -cache -clean $(ProjectName)-$(Configuration) - WIN32_LEAN_AND_MEAN;WIN32;_WIN32;__WINDOWS__;_HAS_EXCEPTIONS=0;WIN64;RELEASE;PROFILING_ENABLED;JULIET_WIN32; + cd $(SolutionDir) & misc\fbuild -ide -dist -monitor -cache -clean $(ProjectName)-$(Configuration) + _CRT_SECURE_NO_WARNINGS;_UNICODE;UNICODE;WIN32_LEAN_AND_MEAN;WIN32;_WIN32;__WINDOWS__;_HAS_EXCEPTIONS=0;WIN64;RELEASE;PROFILING_ENABLED;JULIET_WIN32; ..\;..\Juliet\include;..\Game;C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\um;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\shared; /std:c++20 /wd5267 /wd4061 /wd4505 /wd4514 /wd4577 /wd4625 /wd4710 /wd4711 /wd4746 /wd4820 /wd5045 /wd5220 /wd5245 $(SolutionDir)\bin\$(Configuration)\ @@ -364,8 +364,8 @@ cd $(SolutionDir) & misc\fbuild -ide -dist -monitor -cache $(ProjectName)-$(Configuration) - cd $(SolutionDir) & mics\fbuild -ide -dist -monitor -cache -clean $(ProjectName)-$(Configuration) - WIN32_LEAN_AND_MEAN;WIN32;_WIN32;__WINDOWS__;_HAS_EXCEPTIONS=0;WIN64;RELEASE;JULIET_WIN32; + cd $(SolutionDir) & misc\fbuild -ide -dist -monitor -cache -clean $(ProjectName)-$(Configuration) + _CRT_SECURE_NO_WARNINGS;_UNICODE;UNICODE;WIN32_LEAN_AND_MEAN;WIN32;_WIN32;__WINDOWS__;_HAS_EXCEPTIONS=0;WIN64;RELEASE;JULIET_WIN32; ..\;..\Juliet\include;..\Game;C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\um;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\shared; /std:c++20 /wd5267 /wd4061 /wd4505 /wd4514 /wd4577 /wd4625 /wd4710 /wd4711 /wd4746 /wd4820 /wd5045 /wd5220 /wd5245 $(SolutionDir)\bin\$(Configuration)\ @@ -374,8 +374,8 @@ cd $(SolutionDir) & misc\fbuild -ide -dist -monitor -cache $(ProjectName)-$(Configuration) - cd $(SolutionDir) & mics\fbuild -ide -dist -monitor -cache -clean $(ProjectName)-$(Configuration) - WIN32_LEAN_AND_MEAN;WIN32;_WIN32;__WINDOWS__;_HAS_EXCEPTIONS=0;WIN64;DEBUG;PROFILING_ENABLED;JULIET_WIN32; + cd $(SolutionDir) & misc\fbuild -ide -dist -monitor -cache -clean $(ProjectName)-$(Configuration) + _CRT_SECURE_NO_WARNINGS;_UNICODE;UNICODE;WIN32_LEAN_AND_MEAN;WIN32;_WIN32;__WINDOWS__;_HAS_EXCEPTIONS=0;WIN64;DEBUG;PROFILING_ENABLED;JULIET_WIN32; ..\;..\Juliet\include;C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\um;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\shared; /std:c++20 /wd5267 /wd4061 /wd4505 /wd4514 /wd4577 /wd4625 /wd4710 /wd4711 /wd4746 /wd4820 /wd5045 /wd5220 /wd5245 $(SolutionDir)\bin\$(Configuration)\ @@ -384,8 +384,8 @@ cd $(SolutionDir) & misc\fbuild -ide -dist -monitor -cache $(ProjectName)-$(Configuration) - cd $(SolutionDir) & mics\fbuild -ide -dist -monitor -cache -clean $(ProjectName)-$(Configuration) - WIN32_LEAN_AND_MEAN;WIN32;_WIN32;__WINDOWS__;_HAS_EXCEPTIONS=0;WIN64;RELEASE;PROFILING_ENABLED;JULIET_WIN32; + cd $(SolutionDir) & misc\fbuild -ide -dist -monitor -cache -clean $(ProjectName)-$(Configuration) + _CRT_SECURE_NO_WARNINGS;_UNICODE;UNICODE;WIN32_LEAN_AND_MEAN;WIN32;_WIN32;__WINDOWS__;_HAS_EXCEPTIONS=0;WIN64;RELEASE;PROFILING_ENABLED;JULIET_WIN32; ..\;..\Juliet\include;C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\um;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\shared; /std:c++20 /wd5267 /wd4061 /wd4505 /wd4514 /wd4577 /wd4625 /wd4710 /wd4711 /wd4746 /wd4820 /wd5045 /wd5220 /wd5245 $(SolutionDir)\bin\$(Configuration)\ @@ -394,8 +394,8 @@ cd $(SolutionDir) & misc\fbuild -ide -dist -monitor -cache $(ProjectName)-$(Configuration) - cd $(SolutionDir) & mics\fbuild -ide -dist -monitor -cache -clean $(ProjectName)-$(Configuration) - WIN32_LEAN_AND_MEAN;WIN32;_WIN32;__WINDOWS__;_HAS_EXCEPTIONS=0;WIN64;RELEASE;JULIET_WIN32; + cd $(SolutionDir) & misc\fbuild -ide -dist -monitor -cache -clean $(ProjectName)-$(Configuration) + _CRT_SECURE_NO_WARNINGS;_UNICODE;UNICODE;WIN32_LEAN_AND_MEAN;WIN32;_WIN32;__WINDOWS__;_HAS_EXCEPTIONS=0;WIN64;RELEASE;JULIET_WIN32; ..\;..\Juliet\include;C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\um;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\shared; /std:c++20 /wd5267 /wd4061 /wd4505 /wd4514 /wd4577 /wd4625 /wd4710 /wd4711 /wd4746 /wd4820 /wd5045 /wd5220 /wd5245 $(SolutionDir)\bin\$(Configuration)\ @@ -404,8 +404,8 @@ cd $(SolutionDir) & misc\fbuild -ide -dist -monitor -cache $(ProjectName)-$(Configuration) - cd $(SolutionDir) & mics\fbuild -ide -dist -monitor -cache -clean $(ProjectName)-$(Configuration) - WIN32_LEAN_AND_MEAN;WIN32;_WIN32;__WINDOWS__;_HAS_EXCEPTIONS=0;WIN64;DEBUG;PROFILING_ENABLED;JULIET_WIN32; + cd $(SolutionDir) & misc\fbuild -ide -dist -monitor -cache -clean $(ProjectName)-$(Configuration) + _CRT_SECURE_NO_WARNINGS;_UNICODE;UNICODE;WIN32_LEAN_AND_MEAN;WIN32;_WIN32;__WINDOWS__;_HAS_EXCEPTIONS=0;WIN64;DEBUG;PROFILING_ENABLED;JULIET_WIN32; ..\;..\Juliet\include;C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\um;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\shared; /std:c++20 $(SolutionDir)\bin\$(Configuration)\ @@ -414,8 +414,8 @@ cd $(SolutionDir) & misc\fbuild -ide -dist -monitor -cache $(ProjectName)-$(Configuration) - cd $(SolutionDir) & mics\fbuild -ide -dist -monitor -cache -clean $(ProjectName)-$(Configuration) - WIN32_LEAN_AND_MEAN;WIN32;_WIN32;__WINDOWS__;_HAS_EXCEPTIONS=0;WIN64;RELEASE;PROFILING_ENABLED;JULIET_WIN32; + cd $(SolutionDir) & misc\fbuild -ide -dist -monitor -cache -clean $(ProjectName)-$(Configuration) + _CRT_SECURE_NO_WARNINGS;_UNICODE;UNICODE;WIN32_LEAN_AND_MEAN;WIN32;_WIN32;__WINDOWS__;_HAS_EXCEPTIONS=0;WIN64;RELEASE;PROFILING_ENABLED;JULIET_WIN32; ..\;..\Juliet\include;C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\um;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\shared; /std:c++20 $(SolutionDir)\bin\$(Configuration)\ @@ -424,8 +424,8 @@ cd $(SolutionDir) & misc\fbuild -ide -dist -monitor -cache $(ProjectName)-$(Configuration) - cd $(SolutionDir) & mics\fbuild -ide -dist -monitor -cache -clean $(ProjectName)-$(Configuration) - WIN32_LEAN_AND_MEAN;WIN32;_WIN32;__WINDOWS__;_HAS_EXCEPTIONS=0;WIN64;RELEASE;JULIET_WIN32; + cd $(SolutionDir) & misc\fbuild -ide -dist -monitor -cache -clean $(ProjectName)-$(Configuration) + _CRT_SECURE_NO_WARNINGS;_UNICODE;UNICODE;WIN32_LEAN_AND_MEAN;WIN32;_WIN32;__WINDOWS__;_HAS_EXCEPTIONS=0;WIN64;RELEASE;JULIET_WIN32; ..\;..\Juliet\include;C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\um;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\shared; /std:c++20 $(SolutionDir)\bin\$(Configuration)\ diff --git a/JulietApp/main.cpp b/JulietApp/main.cpp index 8a45a89..d027ba8 100644 --- a/JulietApp/main.cpp +++ b/JulietApp/main.cpp @@ -43,6 +43,12 @@ namespace const char* GameFunctionTable[] = { "GameInit", "GameShutdown", "GameUpdate" }; } // namespace +struct Vertex +{ + float Position[2]; + float Color[4]; +}; + void JulietApplication::Init() { Log(LogLevel::Message, LogCategory::Tool, "Initializing Juliet Application..."); @@ -98,6 +104,17 @@ void JulietApplication::Init() Running = false; } + // Create Buffers + BufferCreateInfo bufferCI = {}; + bufferCI.Size = 256; + bufferCI.Usage = BufferUsage::StructuredBuffer; // Changed to StructuredBuffer As Requested + ConstantBuffer = CreateGraphicsBuffer(GraphicsDevice, bufferCI); + + TransferBufferCreateInfo transferCI = {}; + transferCI.Size = 256; + transferCI.Usage = TransferBufferUsage::Upload; + TransferBuffer = CreateGraphicsTransferBuffer(GraphicsDevice, transferCI); + if (vertexShader) { DestroyShader(GraphicsDevice, vertexShader); @@ -138,6 +155,14 @@ void JulietApplication::Shutdown() { DestroyGraphicsPipeline(GraphicsDevice, GraphicsPipeline); } + if (ConstantBuffer) + { + DestroyGraphicsBuffer(GraphicsDevice, ConstantBuffer); + } + if (TransferBuffer) + { + DestroyGraphicsTransferBuffer(GraphicsDevice, TransferBuffer); + } if (MainWindow && GraphicsDevice) { @@ -254,9 +279,38 @@ void JulietApplication::Update() colorTargetInfo.LoadOperation = LoadOperation::Clear; colorTargetInfo.StoreOperation = StoreOperation::Store; + if (ConstantBuffer && TransferBuffer) + { + void* ptr = MapGraphicsTransferBuffer(GraphicsDevice, TransferBuffer); + if (ptr) + { + Vertex* vertices = static_cast(ptr); + + // Triangle 1 + vertices[0] = { { -0.5f, -0.5f }, { 1.0f, 0.0f, 0.0f, 1.0f } }; // Red + vertices[1] = { { 0.0f, 0.5f }, { 0.0f, 1.0f, 0.0f, 1.0f } }; // Green + vertices[2] = { { 0.5f, -0.5f }, { 0.0f, 0.0f, 1.0f, 1.0f } }; // Blue + + // Triangle 2 + vertices[3] = { { -0.5f, 0.5f }, { 1.0f, 1.0f, 0.0f, 1.0f } }; // Yellow + vertices[4] = { { 0.0f, 0.8f }, { 0.0f, 1.0f, 1.0f, 1.0f } }; // Cyan + vertices[5] = { { 0.5f, 0.5f }, { 1.0f, 0.0f, 1.0f, 1.0f } }; // Magenta + + UnmapGraphicsTransferBuffer(GraphicsDevice, TransferBuffer); + } + + CopyBuffer(cmdList, ConstantBuffer, TransferBuffer, 256); + TransitionBufferToReadable(cmdList, ConstantBuffer); + } + RenderPass* renderPass = BeginRenderPass(cmdList, colorTargetInfo); BindGraphicsPipeline(renderPass, GraphicsPipeline); - DrawPrimitives(renderPass, 3, 1, 0, 0); + + // Pass descriptor index via Push Constants AFTER finding the pipeline (RootSignature) + uint32 descriptorIndex = GetDescriptorIndex(GraphicsDevice, ConstantBuffer); + SetPushConstants(cmdList, ShaderStage::Vertex, 0, 1, &descriptorIndex); + + DrawPrimitives(renderPass, 6, 1, 0, 0); EndRenderPass(renderPass); } diff --git a/JulietApp/main.h b/JulietApp/main.h index 1efaba0..6566154 100644 --- a/JulietApp/main.h +++ b/JulietApp/main.h @@ -8,6 +8,8 @@ namespace Juliet { + struct GraphicsTransferBuffer; + struct GraphicsBuffer; struct GraphicsDevice; struct Window; } // namespace Juliet @@ -21,10 +23,12 @@ class JulietApplication : public Juliet::IApplication bool IsRunning() override; private: - Juliet::Window* MainWindow = {}; - Juliet::GraphicsDevice* GraphicsDevice = {}; - Juliet::HotReloadCode GameCode = {}; - Juliet::GraphicsPipeline* GraphicsPipeline = {}; + Juliet::Window* MainWindow = {}; + Juliet::GraphicsDevice* GraphicsDevice = {}; + Juliet::HotReloadCode GameCode = {}; + Juliet::GraphicsPipeline* GraphicsPipeline = {}; + Juliet::GraphicsBuffer* ConstantBuffer = {}; + Juliet::GraphicsTransferBuffer* TransferBuffer = {}; bool Running = false; }; diff --git a/misc/Generate.bat b/misc/Generate.bat new file mode 100644 index 0000000..22a71d7 --- /dev/null +++ b/misc/Generate.bat @@ -0,0 +1,5 @@ +@echo off +setlocal + +fbuild gen-shader -summary +fbuild generatesolution -summary \ No newline at end of file