diff options
| author | Tim Foley <tfoleyNV@users.noreply.github.com> | 2018-06-28 11:14:48 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-06-28 11:14:48 -0700 |
| commit | dfe13b54286b27dd15f591455bbb86b7798285c2 (patch) | |
| tree | 4a11f01feaae059b6c11bdfbe12a614228af6dd5 /tools | |
| parent | 22033f06573f900dc030c487b2c30feddf3d8f16 (diff) | |
Share graphics API layer between tests/examples (#603)
The `render-test` project has an in-progress graphics API abstraction layer, and it makes sense to share this code with our examples rather than write a bunch of redundant code between examples and tests.
Most of this change is just moving files from `tools/render-test/*` to a new library project at `tools/slang-graphics/`. The most complicated code change there is renaming from `render_test` to `slang_graphics`.
The existing `hello` example was ported to use the graphics API layer instead of raw D3D11 API calls. It is still hard-coded to use the D3D11 back-end and the `SLANG_DXBC` target, so more work is needed if we want to actually support multiple APIs in the examples.
I also went ahead and implemented an extremely rudimentary set of APIs to abstract over the Windows platform calls that were being made in the example, so that we could potentially run that same example on other platforms. I did *not* port `render-test` to use those APIs, and I also did not implement them for anything but Windows (my assumption is that for most other platforms we would just use SDL2, and require people to ensure it is installed to their machine before building Slang examples).
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/render-test/options.h | 4 | ||||
| -rw-r--r-- | tools/render-test/png-serialize-util.h | 6 | ||||
| -rw-r--r-- | tools/render-test/render-test.vcxproj | 42 | ||||
| -rw-r--r-- | tools/render-test/render-test.vcxproj.filters | 93 | ||||
| -rw-r--r-- | tools/render-test/shader-input-layout.h | 2 | ||||
| -rw-r--r-- | tools/render-test/window.h | 10 | ||||
| -rw-r--r-- | tools/slang-graphics/circular-resource-heap-d3d12.cpp (renamed from tools/render-test/circular-resource-heap-d3d12.cpp) | 24 | ||||
| -rw-r--r-- | tools/slang-graphics/circular-resource-heap-d3d12.h (renamed from tools/render-test/circular-resource-heap-d3d12.h) | 68 | ||||
| -rw-r--r-- | tools/slang-graphics/d3d-util.cpp (renamed from tools/render-test/d3d-util.cpp) | 2 | ||||
| -rw-r--r-- | tools/slang-graphics/d3d-util.h (renamed from tools/render-test/d3d-util.h) | 2 | ||||
| -rw-r--r-- | tools/slang-graphics/descriptor-heap-d3d12.cpp (renamed from tools/render-test/descriptor-heap-d3d12.cpp) | 6 | ||||
| -rw-r--r-- | tools/slang-graphics/descriptor-heap-d3d12.h (renamed from tools/render-test/descriptor-heap-d3d12.h) | 20 | ||||
| -rw-r--r-- | tools/slang-graphics/render-d3d11.cpp (renamed from tools/render-test/render-d3d11.cpp) | 6 | ||||
| -rw-r--r-- | tools/slang-graphics/render-d3d11.h (renamed from tools/render-test/render-d3d11.h) | 4 | ||||
| -rw-r--r-- | tools/slang-graphics/render-d3d12.cpp (renamed from tools/render-test/render-d3d12.cpp) | 6 | ||||
| -rw-r--r-- | tools/slang-graphics/render-d3d12.h (renamed from tools/render-test/render-d3d12.h) | 4 | ||||
| -rw-r--r-- | tools/slang-graphics/render-gl.cpp (renamed from tools/render-test/render-gl.cpp) | 38 | ||||
| -rw-r--r-- | tools/slang-graphics/render-gl.h (renamed from tools/render-test/render-gl.h) | 4 | ||||
| -rw-r--r-- | tools/slang-graphics/render-vk.cpp (renamed from tools/render-test/render-vk.cpp) | 156 | ||||
| -rw-r--r-- | tools/slang-graphics/render-vk.h (renamed from tools/render-test/render-vk.h) | 4 | ||||
| -rw-r--r-- | tools/slang-graphics/render.cpp (renamed from tools/render-test/render.cpp) | 2 | ||||
| -rw-r--r-- | tools/slang-graphics/render.h (renamed from tools/render-test/render.h) | 2 | ||||
| -rw-r--r-- | tools/slang-graphics/resource-d3d12.cpp (renamed from tools/render-test/resource-d3d12.cpp) | 4 | ||||
| -rw-r--r-- | tools/slang-graphics/resource-d3d12.h (renamed from tools/render-test/resource-d3d12.h) | 8 | ||||
| -rw-r--r-- | tools/slang-graphics/slang-graphics.vcxproj | 212 | ||||
| -rw-r--r-- | tools/slang-graphics/slang-graphics.vcxproj.filters | 111 | ||||
| -rw-r--r-- | tools/slang-graphics/surface.cpp (renamed from tools/render-test/surface.cpp) | 16 | ||||
| -rw-r--r-- | tools/slang-graphics/surface.h (renamed from tools/render-test/surface.h) | 18 | ||||
| -rw-r--r-- | tools/slang-graphics/vk-api.cpp (renamed from tools/render-test/vk-api.cpp) | 16 | ||||
| -rw-r--r-- | tools/slang-graphics/vk-api.h (renamed from tools/render-test/vk-api.h) | 10 | ||||
| -rw-r--r-- | tools/slang-graphics/vk-device-queue.cpp (renamed from tools/render-test/vk-device-queue.cpp) | 20 | ||||
| -rw-r--r-- | tools/slang-graphics/vk-device-queue.h (renamed from tools/render-test/vk-device-queue.h) | 12 | ||||
| -rw-r--r-- | tools/slang-graphics/vk-module.cpp (renamed from tools/render-test/vk-module.cpp) | 14 | ||||
| -rw-r--r-- | tools/slang-graphics/vk-module.h (renamed from tools/render-test/vk-module.h) | 4 | ||||
| -rw-r--r-- | tools/slang-graphics/vk-swap-chain.cpp (renamed from tools/render-test/vk-swap-chain.cpp) | 46 | ||||
| -rw-r--r-- | tools/slang-graphics/vk-swap-chain.h (renamed from tools/render-test/vk-swap-chain.h) | 12 | ||||
| -rw-r--r-- | tools/slang-graphics/vk-util.cpp (renamed from tools/render-test/vk-util.cpp) | 2 | ||||
| -rw-r--r-- | tools/slang-graphics/vk-util.h (renamed from tools/render-test/vk-util.h) | 14 | ||||
| -rw-r--r-- | tools/slang-graphics/window.cpp | 245 | ||||
| -rw-r--r-- | tools/slang-graphics/window.h | 69 |
40 files changed, 925 insertions, 413 deletions
diff --git a/tools/render-test/options.h b/tools/render-test/options.h index a14acec15..82c018f66 100644 --- a/tools/render-test/options.h +++ b/tools/render-test/options.h @@ -9,6 +9,8 @@ namespace renderer_test { +using namespace slang_graphics; + struct Options { enum @@ -25,7 +27,7 @@ struct Options // Raw HLSL or GLSL input, bypassing Slang Native, }; - + enum class ShaderProgramType { diff --git a/tools/render-test/png-serialize-util.h b/tools/render-test/png-serialize-util.h index fe3b4f873..dad17ae74 100644 --- a/tools/render-test/png-serialize-util.h +++ b/tools/render-test/png-serialize-util.h @@ -2,10 +2,12 @@ #pragma once #include "surface.h" - + namespace renderer_test { -struct PngSerializeUtil +using namespace slang_graphics; + +struct PngSerializeUtil { static Slang::Result write(const char* filename, const Surface& surface); diff --git a/tools/render-test/render-test.vcxproj b/tools/render-test/render-test.vcxproj index 915d0d753..66ad9e7ed 100644 --- a/tools/render-test/render-test.vcxproj +++ b/tools/render-test/render-test.vcxproj @@ -99,7 +99,7 @@ <PrecompiledHeader>NotUsing</PrecompiledHeader> <WarningLevel>Level3</WarningLevel> <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> - <AdditionalIncludeDirectories>..\..;..\..\external;..\..\source;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories>..\..;..\..\external;..\..\source;..\slang-graphics;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <DebugInformationFormat>EditAndContinue</DebugInformationFormat> <Optimization>Disabled</Optimization> <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> @@ -117,7 +117,7 @@ <PrecompiledHeader>NotUsing</PrecompiledHeader> <WarningLevel>Level3</WarningLevel> <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> - <AdditionalIncludeDirectories>..\..;..\..\external;..\..\source;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories>..\..;..\..\external;..\..\source;..\slang-graphics;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <DebugInformationFormat>EditAndContinue</DebugInformationFormat> <Optimization>Disabled</Optimization> <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> @@ -135,7 +135,7 @@ <PrecompiledHeader>NotUsing</PrecompiledHeader> <WarningLevel>Level3</WarningLevel> <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> - <AdditionalIncludeDirectories>..\..;..\..\external;..\..\source;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories>..\..;..\..\external;..\..\source;..\slang-graphics;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <Optimization>Full</Optimization> <FunctionLevelLinking>true</FunctionLevelLinking> <IntrinsicFunctions>true</IntrinsicFunctions> @@ -157,7 +157,7 @@ <PrecompiledHeader>NotUsing</PrecompiledHeader> <WarningLevel>Level3</WarningLevel> <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> - <AdditionalIncludeDirectories>..\..;..\..\external;..\..\source;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories>..\..;..\..\external;..\..\source;..\slang-graphics;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <Optimization>Full</Optimization> <FunctionLevelLinking>true</FunctionLevelLinking> <IntrinsicFunctions>true</IntrinsicFunctions> @@ -175,50 +175,19 @@ </PostBuildEvent> </ItemDefinitionGroup> <ItemGroup> - <ClInclude Include="circular-resource-heap-d3d12.h" /> - <ClInclude Include="d3d-util.h" /> - <ClInclude Include="descriptor-heap-d3d12.h" /> <ClInclude Include="options.h" /> <ClInclude Include="png-serialize-util.h" /> - <ClInclude Include="render-d3d11.h" /> - <ClInclude Include="render-d3d12.h" /> - <ClInclude Include="render-gl.h" /> - <ClInclude Include="render-vk.h" /> - <ClInclude Include="render.h" /> - <ClInclude Include="resource-d3d12.h" /> <ClInclude Include="shader-input-layout.h" /> <ClInclude Include="shader-renderer-util.h" /> <ClInclude Include="slang-support.h" /> - <ClInclude Include="surface.h" /> - <ClInclude Include="vk-api.h" /> - <ClInclude Include="vk-device-queue.h" /> - <ClInclude Include="vk-module.h" /> - <ClInclude Include="vk-swap-chain.h" /> - <ClInclude Include="vk-util.h" /> - <ClInclude Include="window.h" /> </ItemGroup> <ItemGroup> - <ClCompile Include="circular-resource-heap-d3d12.cpp" /> - <ClCompile Include="d3d-util.cpp" /> - <ClCompile Include="descriptor-heap-d3d12.cpp" /> <ClCompile Include="main.cpp" /> <ClCompile Include="options.cpp" /> <ClCompile Include="png-serialize-util.cpp" /> - <ClCompile Include="render-d3d11.cpp" /> - <ClCompile Include="render-d3d12.cpp" /> - <ClCompile Include="render-gl.cpp" /> - <ClCompile Include="render-vk.cpp" /> - <ClCompile Include="render.cpp" /> - <ClCompile Include="resource-d3d12.cpp" /> <ClCompile Include="shader-input-layout.cpp" /> <ClCompile Include="shader-renderer-util.cpp" /> <ClCompile Include="slang-support.cpp" /> - <ClCompile Include="surface.cpp" /> - <ClCompile Include="vk-api.cpp" /> - <ClCompile Include="vk-device-queue.cpp" /> - <ClCompile Include="vk-module.cpp" /> - <ClCompile Include="vk-swap-chain.cpp" /> - <ClCompile Include="vk-util.cpp" /> </ItemGroup> <ItemGroup> <ProjectReference Include="..\..\source\core\core.vcxproj"> @@ -227,6 +196,9 @@ <ProjectReference Include="..\..\source\slang\slang.vcxproj"> <Project>{DB00DA62-0533-4AFD-B59F-A67D5B3A0808}</Project> </ProjectReference> + <ProjectReference Include="..\slang-graphics\slang-graphics.vcxproj"> + <Project>{222F7498-B40C-4F3F-A704-DDEB91A4484A}</Project> + </ProjectReference> </ItemGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <ImportGroup Label="ExtensionTargets"> diff --git a/tools/render-test/render-test.vcxproj.filters b/tools/render-test/render-test.vcxproj.filters index b2f48a397..ff3d52a7e 100644 --- a/tools/render-test/render-test.vcxproj.filters +++ b/tools/render-test/render-test.vcxproj.filters @@ -9,39 +9,12 @@ </Filter> </ItemGroup> <ItemGroup> - <ClInclude Include="circular-resource-heap-d3d12.h"> - <Filter>Header Files</Filter> - </ClInclude> - <ClInclude Include="d3d-util.h"> - <Filter>Header Files</Filter> - </ClInclude> - <ClInclude Include="descriptor-heap-d3d12.h"> - <Filter>Header Files</Filter> - </ClInclude> <ClInclude Include="options.h"> <Filter>Header Files</Filter> </ClInclude> <ClInclude Include="png-serialize-util.h"> <Filter>Header Files</Filter> </ClInclude> - <ClInclude Include="render-d3d11.h"> - <Filter>Header Files</Filter> - </ClInclude> - <ClInclude Include="render-d3d12.h"> - <Filter>Header Files</Filter> - </ClInclude> - <ClInclude Include="render-gl.h"> - <Filter>Header Files</Filter> - </ClInclude> - <ClInclude Include="render-vk.h"> - <Filter>Header Files</Filter> - </ClInclude> - <ClInclude Include="render.h"> - <Filter>Header Files</Filter> - </ClInclude> - <ClInclude Include="resource-d3d12.h"> - <Filter>Header Files</Filter> - </ClInclude> <ClInclude Include="shader-input-layout.h"> <Filter>Header Files</Filter> </ClInclude> @@ -51,38 +24,8 @@ <ClInclude Include="slang-support.h"> <Filter>Header Files</Filter> </ClInclude> - <ClInclude Include="surface.h"> - <Filter>Header Files</Filter> - </ClInclude> - <ClInclude Include="vk-api.h"> - <Filter>Header Files</Filter> - </ClInclude> - <ClInclude Include="vk-device-queue.h"> - <Filter>Header Files</Filter> - </ClInclude> - <ClInclude Include="vk-module.h"> - <Filter>Header Files</Filter> - </ClInclude> - <ClInclude Include="vk-swap-chain.h"> - <Filter>Header Files</Filter> - </ClInclude> - <ClInclude Include="vk-util.h"> - <Filter>Header Files</Filter> - </ClInclude> - <ClInclude Include="window.h"> - <Filter>Header Files</Filter> - </ClInclude> </ItemGroup> <ItemGroup> - <ClCompile Include="circular-resource-heap-d3d12.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="d3d-util.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="descriptor-heap-d3d12.cpp"> - <Filter>Source Files</Filter> - </ClCompile> <ClCompile Include="main.cpp"> <Filter>Source Files</Filter> </ClCompile> @@ -92,24 +35,6 @@ <ClCompile Include="png-serialize-util.cpp"> <Filter>Source Files</Filter> </ClCompile> - <ClCompile Include="render-d3d11.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="render-d3d12.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="render-gl.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="render-vk.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="render.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="resource-d3d12.cpp"> - <Filter>Source Files</Filter> - </ClCompile> <ClCompile Include="shader-input-layout.cpp"> <Filter>Source Files</Filter> </ClCompile> @@ -119,23 +44,5 @@ <ClCompile Include="slang-support.cpp"> <Filter>Source Files</Filter> </ClCompile> - <ClCompile Include="surface.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="vk-api.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="vk-device-queue.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="vk-module.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="vk-swap-chain.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="vk-util.cpp"> - <Filter>Source Files</Filter> - </ClCompile> </ItemGroup> </Project>
\ No newline at end of file diff --git a/tools/render-test/shader-input-layout.h b/tools/render-test/shader-input-layout.h index 7537527ab..19a7e59d0 100644 --- a/tools/render-test/shader-input-layout.h +++ b/tools/render-test/shader-input-layout.h @@ -7,6 +7,8 @@ namespace renderer_test { +using namespace slang_graphics; + enum class ShaderInputType { Buffer, Texture, Sampler, CombinedTextureSampler diff --git a/tools/render-test/window.h b/tools/render-test/window.h deleted file mode 100644 index 5d0a89ee4..000000000 --- a/tools/render-test/window.h +++ /dev/null @@ -1,10 +0,0 @@ -// window.h -#pragma once - -namespace renderer_test { - -typedef struct Window Window; - -Window* createWindow(); - -} // renderer_test diff --git a/tools/render-test/circular-resource-heap-d3d12.cpp b/tools/slang-graphics/circular-resource-heap-d3d12.cpp index ae8e13822..8b63819a5 100644 --- a/tools/render-test/circular-resource-heap-d3d12.cpp +++ b/tools/slang-graphics/circular-resource-heap-d3d12.cpp @@ -1,6 +1,6 @@ #include "circular-resource-heap-d3d12.h" -namespace renderer_test { +namespace slang_graphics { using namespace Slang; D3D12CircularResourceHeap::D3D12CircularResourceHeap(): @@ -24,8 +24,8 @@ void D3D12CircularResourceHeap::_freeBlockListResources(const Block* start) { if (start) { - const Block* block = start; - do + const Block* block = start; + do { ID3D12Resource* resource = block->m_resource; @@ -36,12 +36,12 @@ void D3D12CircularResourceHeap::_freeBlockListResources(const Block* start) block = block->m_next; } while (block != start); - } + } } Result D3D12CircularResourceHeap::init(ID3D12Device* device, const Desc& desc, D3D12CounterFence* fence) { - assert(m_blocks == nullptr); + assert(m_blocks == nullptr); assert(desc.m_blockSize > 0); m_fence = fence; @@ -57,14 +57,14 @@ void D3D12CircularResourceHeap::addSync(uint64_t signalValue) PendingEntry entry; entry.m_completedValue = signalValue; entry.m_cursor = m_front; - m_pendingQueue.Add(entry); + m_pendingQueue.Add(entry); } void D3D12CircularResourceHeap::updateCompleted() { const uint64_t completedValue = m_fence->getCompletedValue(); - -#if 0 + +#if 0 while (m_pendingQueue.Count() != 0) { const PendingEntry& entry = m_pendingQueue[0]; @@ -170,7 +170,7 @@ D3D12CircularResourceHeap::Cursor D3D12CircularResourceHeap::allocate(size_t siz m_front = m_back; } - // If front and back are in the same block then front MUST be ahead of back (as that defined as + // If front and back are in the same block then front MUST be ahead of back (as that defined as // an invariant and is required for block insertion to be possible Block* block = m_front.m_block; @@ -191,7 +191,7 @@ D3D12CircularResourceHeap::Cursor D3D12CircularResourceHeap::allocate(size_t siz } // Okay I can't fit into current block... - + // If the next block contains front, we need to add a block, else we can use that block if (block->m_next == m_back.m_block) { @@ -200,7 +200,7 @@ D3D12CircularResourceHeap::Cursor D3D12CircularResourceHeap::allocate(size_t siz newBlock->m_next = block->m_next; block->m_next = newBlock; } - + // Use the block we are going to add to block = block->m_next; uint8_t* cur = (uint8_t*)((size_t(block->m_start) + alignment - 1) & ~(alignment - 1)); @@ -219,4 +219,4 @@ D3D12CircularResourceHeap::Cursor D3D12CircularResourceHeap::allocate(size_t siz return cursor; } -} // namespace renderer_test +} // namespace slang_graphics diff --git a/tools/render-test/circular-resource-heap-d3d12.h b/tools/slang-graphics/circular-resource-heap-d3d12.h index baa9a9b0c..a200d3bbc 100644 --- a/tools/render-test/circular-resource-heap-d3d12.h +++ b/tools/slang-graphics/circular-resource-heap-d3d12.h @@ -6,25 +6,25 @@ #include "resource-d3d12.h" -namespace renderer_test { - -/*! \brief The D3D12CircularResourceHeap is a heap that is suited for size constrained real-time resources allocation that -is transitory in nature. It is designed to allocate resources which are used and discarded, often used where in -previous versions of DirectX the 'DISCARD' flag was used. - -The idea is to have a heap which chunks of resource can be allocated, and used for GPU execution, -and that the heap is able through the addSync/updateCompleted idiom is able to track when the usage of the resources is -completed allowing them to be reused. The heap is arranged as circularly, with new allocations made from the front, and the back -being updated as the GPU updating the back when it is informed anything using prior parts of the heap have completed. In this -arrangement all the heap between the back and the front can be thought of as in use or potentially in use by the GPU. All the heap -from the front back around to the back, is free and can be allocated from. It is the responsibility of the user of the Heap to make -sure the invariant holds, but in most normal usage it does so simply. - -Another feature of the heap is that it does not require upfront knowledge of how big a heap is needed. The backing resources will be expanded -dynamically with requests as needed. The only requirement is that know single request can be larger than m_blockSize specified in the Desc +namespace slang_graphics { + +/*! \brief The D3D12CircularResourceHeap is a heap that is suited for size constrained real-time resources allocation that +is transitory in nature. It is designed to allocate resources which are used and discarded, often used where in +previous versions of DirectX the 'DISCARD' flag was used. + +The idea is to have a heap which chunks of resource can be allocated, and used for GPU execution, +and that the heap is able through the addSync/updateCompleted idiom is able to track when the usage of the resources is +completed allowing them to be reused. The heap is arranged as circularly, with new allocations made from the front, and the back +being updated as the GPU updating the back when it is informed anything using prior parts of the heap have completed. In this +arrangement all the heap between the back and the front can be thought of as in use or potentially in use by the GPU. All the heap +from the front back around to the back, is free and can be allocated from. It is the responsibility of the user of the Heap to make +sure the invariant holds, but in most normal usage it does so simply. + +Another feature of the heap is that it does not require upfront knowledge of how big a heap is needed. The backing resources will be expanded +dynamically with requests as needed. The only requirement is that know single request can be larger than m_blockSize specified in the Desc used to initialize the heap. This is because all the backing resources are allocated to a single size. This limitation means the D3D12CircularResourceHeap -may not be the best use for example for uploading a texture - because it's design is really around transitory uploads or write backs, and so more suited -to constant buffers, vertex buffer, index buffers and the like. +may not be the best use for example for uploading a texture - because it's design is really around transitory uploads or write backs, and so more suited +to constant buffers, vertex buffer, index buffers and the like. To upload a texture at program startup it is most likely better to use a D3D12ResourceScopeManager. @@ -35,7 +35,7 @@ typedef D3D12CircularResourceHeap Heap; Heap::Cursor cursor = heap.allocateVertexBuffer(sizeof(Vertex) * numVerts); Memory:copy(cursor.m_position, verts, sizeof(Vertex) * numVerts); -// Do a command using the GPU handle +// Do a command using the GPU handle m_commandList->... // Do another command using the GPU handle @@ -66,7 +66,7 @@ new blocks in front of front. So it must be possible to do an block insertion be |--B---F-----| |----------| When B and F are on top of one another it means there is nothing in the list. NOTE this also means that a move of front can never place it -top of the back. +top of the back. https://msdn.microsoft.com/en-us/library/windows/desktop/dn899125%28v=vs.85%29.aspx https://msdn.microsoft.com/en-us/library/windows/desktop/mt426646%28v=vs.85%29.aspx @@ -79,18 +79,18 @@ class D3D12CircularResourceHeap public: typedef D3D12CircularResourceHeap ThisType; - /// The alignment used for VERTEX_BUFFER allocations + /// The alignment used for VERTEX_BUFFER allocations /// Strictly speaking it seems the hardware can handle 4 byte alignment, but since often in use /// data will be copied from CPU memory to the allocation, using 16 byte alignment is superior as allows /// significantly faster memcpy. /// The sample that shows sizeof(float) - 4 bytes is appropriate is at the link below. /// https://msdn.microsoft.com/en-us/library/windows/desktop/mt426646%28v=vs.85%29.aspx - enum + enum { VERTEX_BUFFER_ALIGNMENT = 16, }; - struct Desc + struct Desc { void init() { @@ -117,7 +117,7 @@ class D3D12CircularResourceHeap /// Cursor position struct Cursor { - /// Get GpuHandle + /// Get GpuHandle SLANG_FORCE_INLINE D3D12_GPU_VIRTUAL_ADDRESS getGpuHandle() const { return m_block->m_resource->GetGPUVirtualAddress() + size_t(m_position - m_block->m_start); } /// Must have a block and position SLANG_FORCE_INLINE bool isValid() const { return m_block != nullptr; } @@ -135,11 +135,11 @@ class D3D12CircularResourceHeap /// Must be called before used /// Block size must be at least as large as the _largest_ thing allocated - /// Also note depending on alignment of a resource allocation, the block size might also need to take into account the - /// maximum alignment use. It is a REQUIREMENT that a newly allocated resource block is large enough to hold any + /// Also note depending on alignment of a resource allocation, the block size might also need to take into account the + /// maximum alignment use. It is a REQUIREMENT that a newly allocated resource block is large enough to hold any /// allocation taking into account the alignment used. Slang::Result init(ID3D12Device* device, const Desc& desc, D3D12CounterFence* fence); - + /// Get the block size SLANG_FORCE_INLINE size_t getBlockSize() const { return m_desc.m_blockSize; } @@ -153,7 +153,7 @@ class D3D12CircularResourceHeap /// Create filled in constant buffer SLANG_FORCE_INLINE Cursor newConstantBuffer(const void* data, size_t size) { Cursor cursor = allocateConstantBuffer(size); ::memcpy(cursor.m_position, data, size); return cursor; } - /// Create in filled in constant buffer + /// Create in filled in constant buffer template <typename T> SLANG_FORCE_INLINE Cursor newConstantBuffer(const T& in) { return newConstantBuffer(&in, sizeof(T)); } @@ -172,12 +172,12 @@ class D3D12CircularResourceHeap ~D3D12CircularResourceHeap(); protected: - + struct Block { ID3D12Resource* m_resource; ///< The mapped resource uint8_t* m_start; ///< Once created the resource is mapped to here - Block* m_next; ///< Points to next block in the list + Block* m_next; ///< Points to next block in the list }; struct PendingEntry { @@ -193,14 +193,14 @@ class D3D12CircularResourceHeap Slang::List<PendingEntry> m_pendingQueue; ///< Holds the list of pending positions. When the fence value is greater than the value on the queue entry, the entry is done. // Allocation is made from the front, and freed from the back. - Cursor m_back; ///< Current back position. - Cursor m_front; ///< Current front position. - + Cursor m_back; ///< Current back position. + Cursor m_front; ///< Current front position. + Desc m_desc; ///< Describes the heap D3D12CounterFence* m_fence; ///< The fence to use ID3D12Device* m_device; ///< The device that resources will be constructed on }; -} // namespace renderer_test +} // namespace slang_graphics diff --git a/tools/render-test/d3d-util.cpp b/tools/slang-graphics/d3d-util.cpp index 08aa563ca..b2c3f87ee 100644 --- a/tools/render-test/d3d-util.cpp +++ b/tools/slang-graphics/d3d-util.cpp @@ -6,7 +6,7 @@ // We will use the C standard library just for printing error messages. #include <stdio.h> -namespace renderer_test { +namespace slang_graphics { using namespace Slang; /* static */D3D_PRIMITIVE_TOPOLOGY D3DUtil::getPrimitiveTopology(PrimitiveTopology topology) diff --git a/tools/render-test/d3d-util.h b/tools/slang-graphics/d3d-util.h index b7a268fd8..b5f154e6e 100644 --- a/tools/render-test/d3d-util.h +++ b/tools/slang-graphics/d3d-util.h @@ -13,7 +13,7 @@ #include <D3Dcommon.h> #include <DXGIFormat.h> -namespace renderer_test { +namespace slang_graphics { class D3DUtil { diff --git a/tools/render-test/descriptor-heap-d3d12.cpp b/tools/slang-graphics/descriptor-heap-d3d12.cpp index 5bd238528..23c56d46d 100644 --- a/tools/render-test/descriptor-heap-d3d12.cpp +++ b/tools/slang-graphics/descriptor-heap-d3d12.cpp @@ -1,7 +1,7 @@ #include "descriptor-heap-d3d12.h" -namespace renderer_test { +namespace slang_graphics { using namespace Slang; D3D12DescriptorHeap::D3D12DescriptorHeap(): @@ -30,7 +30,7 @@ Result D3D12DescriptorHeap::init(ID3D12Device* device, const D3D12_CPU_DESCRIPTO SLANG_RETURN_ON_FAIL(init(device, numHandles, type, flags)); D3D12_CPU_DESCRIPTOR_HANDLE dst = m_heap->GetCPUDescriptorHandleForHeapStart(); - // Copy them all + // Copy them all for (int i = 0; i < numHandles; i++, dst.ptr += m_descriptorSize) { D3D12_CPU_DESCRIPTOR_HANDLE src = handles[i]; @@ -43,5 +43,5 @@ Result D3D12DescriptorHeap::init(ID3D12Device* device, const D3D12_CPU_DESCRIPTO return SLANG_OK; } -} // namespace renderer_test +} // namespace slang_graphics diff --git a/tools/render-test/descriptor-heap-d3d12.h b/tools/slang-graphics/descriptor-heap-d3d12.h index 1d0302d2c..6ddb583dc 100644 --- a/tools/render-test/descriptor-heap-d3d12.h +++ b/tools/slang-graphics/descriptor-heap-d3d12.h @@ -6,7 +6,7 @@ #include "../../slang-com-ptr.h" -namespace renderer_test { +namespace slang_graphics { /*! \brief A simple class to manage an underlying Dx12 Descriptor Heap. Allocations are made linearly in order. It is not possible to free individual allocations, but all allocations can be deallocated with 'deallocateAll'. */ @@ -30,13 +30,13 @@ class D3D12DescriptorHeap /// Allocate a number of descriptors. Returns the start index (or -1 if not possible) SLANG_FORCE_INLINE int allocate(int numDescriptors); - /// + /// SLANG_FORCE_INLINE int placeAt(int index); /// Deallocates all allocations, and starts allocation from the start of the underlying heap again SLANG_FORCE_INLINE void deallocateAll() { m_currentIndex = 0; } - /// Get the size of each + /// Get the size of each SLANG_FORCE_INLINE int getDescriptorSize() const { return m_descriptorSize; } /// Get the GPU heap start @@ -68,7 +68,7 @@ int D3D12DescriptorHeap::allocate() assert(m_currentIndex < m_totalSize); if (m_currentIndex < m_totalSize) { - return m_currentIndex++; + return m_currentIndex++; } return -1; } @@ -94,22 +94,22 @@ SLANG_FORCE_INLINE int D3D12DescriptorHeap::placeAt(int index) // --------------------------------------------------------------------------- SLANG_FORCE_INLINE D3D12_CPU_DESCRIPTOR_HANDLE D3D12DescriptorHeap::getCpuHandle(int index) const -{ - assert(index >= 0 && index < m_totalSize); +{ + assert(index >= 0 && index < m_totalSize); D3D12_CPU_DESCRIPTOR_HANDLE start = m_heap->GetCPUDescriptorHandleForHeapStart(); D3D12_CPU_DESCRIPTOR_HANDLE dst; dst.ptr = start.ptr + m_descriptorSize * index; return dst; -} +} // --------------------------------------------------------------------------- SLANG_FORCE_INLINE D3D12_GPU_DESCRIPTOR_HANDLE D3D12DescriptorHeap::getGpuHandle(int index) const -{ - assert(index >= 0 && index < m_totalSize); +{ + assert(index >= 0 && index < m_totalSize); D3D12_GPU_DESCRIPTOR_HANDLE start = m_heap->GetGPUDescriptorHandleForHeapStart(); D3D12_GPU_DESCRIPTOR_HANDLE dst; dst.ptr = start.ptr + m_descriptorSize * index; return dst; } -} // namespace renderer_test +} // namespace slang_graphics diff --git a/tools/render-test/render-d3d11.cpp b/tools/slang-graphics/render-d3d11.cpp index 109c5aca1..4f9749e39 100644 --- a/tools/render-test/render-d3d11.cpp +++ b/tools/slang-graphics/render-d3d11.cpp @@ -4,7 +4,7 @@ #include "render-d3d11.h" -#include "options.h" +//WORKING: #include "options.h" #include "render.h" #include "d3d-util.h" @@ -12,7 +12,7 @@ // In order to use the Slang API, we need to include its header -#include <slang.h> +//#include <slang.h> #include "../../slang-com-ptr.h" @@ -40,7 +40,7 @@ // using namespace Slang; -namespace renderer_test { +namespace slang_graphics { class D3D11Renderer : public Renderer { diff --git a/tools/render-test/render-d3d11.h b/tools/slang-graphics/render-d3d11.h index 59142731d..7b3d25e9f 100644 --- a/tools/render-test/render-d3d11.h +++ b/tools/slang-graphics/render-d3d11.h @@ -1,10 +1,10 @@ // render-d3d11.h #pragma once -namespace renderer_test { +namespace slang_graphics { class Renderer; Renderer* createD3D11Renderer(); -} // renderer_test +} // slang_graphics diff --git a/tools/render-test/render-d3d12.cpp b/tools/slang-graphics/render-d3d12.cpp index 7603332b4..24c9ecacb 100644 --- a/tools/render-test/render-d3d12.cpp +++ b/tools/slang-graphics/render-d3d12.cpp @@ -3,14 +3,14 @@ #include "render-d3d12.h" -#include "options.h" +//WORKING:#include "options.h" #include "render.h" #include "surface.h" // In order to use the Slang API, we need to include its header -#include <slang.h> +//WORKING:#include <slang.h> // We will be rendering with Direct3D 12, so we need to include // the Windows and D3D12 headers @@ -46,7 +46,7 @@ #define ENABLE_DEBUG_LAYER 1 -namespace renderer_test { +namespace slang_graphics { using namespace Slang; class D3D12Renderer : public Renderer diff --git a/tools/render-test/render-d3d12.h b/tools/slang-graphics/render-d3d12.h index 259af7f7b..5f0eea4d2 100644 --- a/tools/render-test/render-d3d12.h +++ b/tools/slang-graphics/render-d3d12.h @@ -1,10 +1,10 @@ // render-d3d12.h #pragma once -namespace renderer_test { +namespace slang_graphics { class Renderer; Renderer* createD3D12Renderer(); -} // renderer_test +} // slang_graphics diff --git a/tools/render-test/render-gl.cpp b/tools/slang-graphics/render-gl.cpp index dc9f0c43a..f85a81ca4 100644 --- a/tools/render-test/render-gl.cpp +++ b/tools/slang-graphics/render-gl.cpp @@ -1,7 +1,7 @@ // render-gl.cpp #include "render-gl.h" -#include "options.h" +//WORKING:#include "options.h" #include "render.h" #include <assert.h> @@ -73,12 +73,12 @@ using namespace Slang; -namespace renderer_test { +namespace slang_graphics { class GLRenderer : public Renderer { public: - + // Renderer implementation virtual SlangResult initialize(const Desc& desc, void* inWindowHandle) override; virtual void setClearColor(const float color[4]) override; @@ -176,7 +176,7 @@ public: { glDeleteTextures(1, &m_handle); } - } + } Usage m_initialUsage; GLRenderer* m_renderer; @@ -228,7 +228,7 @@ public: m_renderer->glDeleteProgram(m_id); } } - + GLuint m_id; GLRenderer* m_renderer; }; @@ -253,7 +253,7 @@ public: void flushStateForDraw(); GLuint loadShader(GLenum stage, char const* source); void debugCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message); - + /// Returns GlPixelFormat::Unknown if not an equivalent static GlPixelFormat _getGlPixelFormat(Format format); @@ -265,7 +265,7 @@ public: HDC m_hdc; HGLRC m_glContext; float m_clearColor[4] = { 0, 0, 0, 0 }; - + RefPtr<ShaderProgramImpl> m_boundShaderProgram; RefPtr<InputLayoutImpl> m_boundInputLayout; @@ -282,7 +282,7 @@ public: MAP_GL_EXTENSION_FUNCS(DECLARE_GL_EXTENSION_FUNC) #undef DECLARE_GL_EXTENSION_FUNC - static const GlPixelFormatInfo s_pixelFormatInfos[]; /// Maps GlPixelFormat to a format info + static const GlPixelFormatInfo s_pixelFormatInfos[]; /// Maps GlPixelFormat to a format info }; /* static */GLRenderer::GlPixelFormat GLRenderer::_getGlPixelFormat(Format format) @@ -294,7 +294,7 @@ public: } } -/* static */ const GLRenderer::GlPixelFormatInfo GLRenderer::s_pixelFormatInfos[] = +/* static */ const GLRenderer::GlPixelFormatInfo GLRenderer::s_pixelFormatInfos[] = { // internalType, format, formatType { 0, 0, 0}, // GlPixelFormat::Unknown @@ -356,7 +356,7 @@ void GLRenderer::bindBufferImpl(int target, UInt startSlot, UInt slotCount, Buff BufferResourceImpl* buffer = static_cast<BufferResourceImpl*>(buffers[ii]); GLuint bufferID = buffer ? buffer->m_handle : 0; - + assert(!offsets || !offsets[ii]); glBindBufferBase(target, (GLuint)slot, bufferID); @@ -605,7 +605,7 @@ TextureResource* GLRenderer::createTextureResource(Resource::Usage initialUsage, const GLint internalFormat = info.internalFormat; const GLenum format = info.format; const GLenum formatType = info.formatType; - + RefPtr<TextureResourceImpl> texture(new TextureResourceImpl(initialUsage, srcDesc, this)); GLenum target = 0; @@ -665,7 +665,7 @@ TextureResource* GLRenderer::createTextureResource(Resource::Usage initialUsage, } glBindTexture(target, handle); - + int slice = 0; for (int i = 0; i < effectiveArraySize; i++) { @@ -681,7 +681,7 @@ TextureResource* GLRenderer::createTextureResource(Resource::Usage initialUsage, { target = GL_TEXTURE_CUBE_MAP; glBindTexture(target, handle); - + int slice = 0; for (int j = 0; j < 6; j++) { @@ -719,7 +719,7 @@ TextureResource* GLRenderer::createTextureResource(Resource::Usage initialUsage, glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(target, GL_TEXTURE_WRAP_R, GL_REPEAT); - + // Assume regular sampling (might be superseded - if a combined sampler wanted) glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); @@ -750,7 +750,7 @@ static GLenum _calcTarget(Resource::Usage usage) } } -BufferResource* GLRenderer::createBufferResource(Resource::Usage initialUsage, const BufferResource::Desc& descIn, const void* initData) +BufferResource* GLRenderer::createBufferResource(Resource::Usage initialUsage, const BufferResource::Desc& descIn, const void* initData) { BufferResource::Desc desc(descIn); desc.setDefaults(initialUsage); @@ -758,7 +758,7 @@ BufferResource* GLRenderer::createBufferResource(Resource::Usage initialUsage, c const GLenum target = _calcTarget(initialUsage); // TODO: should derive from desc... const GLenum usage = _calcUsage(initialUsage); - + GLuint bufferID = 0; glGenBuffers(1, &bufferID); glBindBuffer(target, bufferID); @@ -842,7 +842,7 @@ void GLRenderer::setVertexBuffers(UInt startSlot, UInt slotCount, BufferResource BufferResourceImpl* buffer = static_cast<BufferResourceImpl*>(buffers[ii]); GLuint bufferID = buffer ? buffer->m_handle : 0; - + m_boundVertexStreamBuffers[slot] = bufferID; m_boundVertexStreamStrides[slot] = strides[ii]; m_boundVertexStreamOffsets[slot] = offsets[ii]; @@ -857,7 +857,7 @@ void GLRenderer::setShaderProgram(ShaderProgram* programIn) glUseProgram(programID); } -void GLRenderer::draw(UInt vertexCount, UInt startVertex = 0) +void GLRenderer::draw(UInt vertexCount, UInt startVertex = 0) { flushStateForDraw(); @@ -884,7 +884,7 @@ BindingState* GLRenderer::createBindingState(const BindingState::Desc& bindingSt auto& dstDetail = dstDetails[i]; const auto& srcBinding = srcBindings[i]; - + switch (srcBinding.bindingType) { case BindingType::Texture: diff --git a/tools/render-test/render-gl.h b/tools/slang-graphics/render-gl.h index 4e6de970c..2b211cda4 100644 --- a/tools/render-test/render-gl.h +++ b/tools/slang-graphics/render-gl.h @@ -1,10 +1,10 @@ // render-d3d11.h #pragma once -namespace renderer_test { +namespace slang_graphics { class Renderer; Renderer* createGLRenderer(); -} // renderer_test +} // slang_graphics diff --git a/tools/render-test/render-vk.cpp b/tools/slang-graphics/render-vk.cpp index bbdc2f08c..d7cd93e67 100644 --- a/tools/render-test/render-vk.cpp +++ b/tools/slang-graphics/render-vk.cpp @@ -1,7 +1,7 @@ // render-vk.cpp #include "render-vk.h" -#include "options.h" +//WORKING:#include "options.h" #include "render.h" #include "../../source/core/smart-pointer.h" @@ -26,14 +26,14 @@ # endif #endif -namespace renderer_test { +namespace slang_graphics { using namespace Slang; class VKRenderer : public Renderer { public: enum { kMaxRenderTargets = 8, kMaxAttachments = kMaxRenderTargets + 1 }; - + // Renderer implementation virtual SlangResult initialize(const Desc& desc, void* inWindowHandle) override; virtual void setClearColor(const float color[4]) override; @@ -66,12 +66,12 @@ public: class Buffer { public: - /// Initialize a buffer with specified size, and memory props + /// Initialize a buffer with specified size, and memory props Result init(const VulkanApi& api, size_t bufferSize, VkBufferUsageFlags usage, VkMemoryPropertyFlags reqMemoryProperties); /// Returns true if has been initialized bool isInitialized() const { return m_api != nullptr; } - + // Default Ctor Buffer(): m_api(nullptr) @@ -91,7 +91,7 @@ public: VkDeviceMemory m_memory; const VulkanApi* m_api; }; - + class InputLayoutImpl : public InputLayout { public: @@ -148,10 +148,10 @@ public: } Usage m_initialUsage; - - VkImage m_image = VK_NULL_HANDLE; + + VkImage m_image = VK_NULL_HANDLE; VkDeviceMemory m_imageMemory = VK_NULL_HANDLE; - + const VulkanApi* m_api; }; @@ -168,8 +168,8 @@ public: VkPipelineShaderStageCreateInfo m_compute; VkPipelineShaderStageCreateInfo m_vertex; VkPipelineShaderStageCreateInfo m_fragment; - - List<char> m_buffers[2]; //< To keep storage of code in scope + + List<char> m_buffers[2]; //< To keep storage of code in scope }; struct BindingDetail @@ -185,7 +185,7 @@ public: typedef BindingState Parent; BindingStateImpl(const Desc& desc, const VulkanApi* api): - Parent(desc), + Parent(desc), m_api(api) { } @@ -263,7 +263,7 @@ public: VkBool32 handleDebugMessage(VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject, size_t location, int32_t msgCode, const char* pLayerPrefix, const char* pMsg); - + VkPipelineShaderStageCreateInfo compileEntryPoint( ShaderProgram::KernelDesc const& kernelDesc, VkShaderStageFlagBits stage, @@ -272,7 +272,7 @@ public: static VKAPI_ATTR VkBool32 VKAPI_CALL debugMessageCallback(VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject, size_t location, int32_t msgCode, const char* pLayerPrefix, const char* pMsg, void* pUserData); - /// Returns true if m_currentPipeline matches the current configuration + /// Returns true if m_currentPipeline matches the current configuration Pipeline* _getPipeline(); bool _isEqual(const Pipeline& pipeline) const; Slang::Result _createPipeline(RefPtr<Pipeline>& pipelineOut); @@ -293,7 +293,7 @@ public: Pipeline* m_currentPipeline = nullptr; List<BoundVertexBuffer> m_boundVertexBuffers; - + VkPrimitiveTopology m_primitiveTopology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; VkDevice m_device = VK_NULL_HANDLE; @@ -351,7 +351,7 @@ Result VKRenderer::Buffer::init(const VulkanApi& api, size_t bufferSize, VkBuffe bool VKRenderer::_isEqual(const Pipeline& pipeline) const { - return + return pipeline.m_bindingState == m_currentBindingState && pipeline.m_primitiveTopology == m_primitiveTopology && pipeline.m_inputLayout == m_currentInputLayout && @@ -364,7 +364,7 @@ VKRenderer::Pipeline* VKRenderer::_getPipeline() { return m_currentPipeline; } - + // Look for a match in the cache for (int i = 0; i < int(m_pipelineCache.Count()); ++i) { @@ -415,7 +415,7 @@ Slang::Result VKRenderer::_createPipeline(RefPtr<Pipeline>& pipelineOut) const auto& srcBinding = srcBindings[i]; VkDescriptorSetLayoutBinding dstBinding = {}; - + dstBinding.descriptorCount = 1; switch (srcBinding.bindingType) @@ -447,7 +447,7 @@ Slang::Result VKRenderer::_createPipeline(RefPtr<Pipeline>& pipelineOut) } case BindingType::Texture: { - dstBinding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; + dstBinding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; dstBinding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; dstBindings.Add(dstBinding); @@ -457,7 +457,7 @@ Slang::Result VKRenderer::_createPipeline(RefPtr<Pipeline>& pipelineOut) } case BindingType::Sampler: { - dstBinding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; + dstBinding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; dstBinding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; dstBindings.Add(dstBinding); @@ -506,8 +506,8 @@ Slang::Result VKRenderer::_createPipeline(RefPtr<Pipeline>& pipelineOut) } } VkDescriptorPoolCreateInfo descriptorPoolInfo = { VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO }; - - descriptorPoolInfo.maxSets = 128; // TODO: actually pick a size. + + descriptorPoolInfo.maxSets = 128; // TODO: actually pick a size. descriptorPoolInfo.poolSizeCount = uint32_t(poolSizes.Count()); descriptorPoolInfo.pPoolSizes = poolSizes.Buffer(); @@ -521,13 +521,13 @@ Slang::Result VKRenderer::_createPipeline(RefPtr<Pipeline>& pipelineOut) descriptorSetLayoutInfo.pBindings = dstBindings.Buffer(); SLANG_VK_CHECK(m_api.vkCreateDescriptorSetLayout(m_device, &descriptorSetLayoutInfo, nullptr, &pipeline->m_descriptorSetLayout)); - } - + } + // Create a descriptor set based on our layout { VkDescriptorSetAllocateInfo descriptorSetAllocInfo = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO }; descriptorSetAllocInfo.descriptorPool = pipeline->m_descriptorPool; - descriptorSetAllocInfo.descriptorSetCount = 1; + descriptorSetAllocInfo.descriptorSetCount = 1; descriptorSetAllocInfo.pSetLayouts = &pipeline->m_descriptorSetLayout; SLANG_VK_CHECK(m_api.vkAllocateDescriptorSets(m_device, &descriptorSetAllocInfo, &pipeline->m_descriptorSet)); @@ -586,7 +586,7 @@ Slang::Result VKRenderer::_createPipeline(RefPtr<Pipeline>& pipelineOut) } writeInfo.pBufferInfo = &bufferInfos.Last(); - + writes.Add(writeInfo); break; } @@ -640,7 +640,7 @@ Slang::Result VKRenderer::_createPipeline(RefPtr<Pipeline>& pipelineOut) { m_api.vkUpdateDescriptorSets(m_device, uint32_t(writes.Count()), writes.Buffer(), 0, nullptr); } - + // Create a pipeline layout based on our descriptor set layout(s) VkPipelineLayoutCreateInfo pipelineLayoutInfo = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO }; @@ -683,7 +683,7 @@ Slang::Result VKRenderer::_createPipeline(RefPtr<Pipeline>& pipelineOut) if (m_currentInputLayout) { vertexInputBindingDescription.binding = 0; - vertexInputBindingDescription.stride = m_currentInputLayout->m_vertexSize; + vertexInputBindingDescription.stride = m_currentInputLayout->m_vertexSize; vertexInputBindingDescription.inputRate = VK_VERTEX_INPUT_RATE_VERTEX; const auto& srcAttributeDescs = m_currentInputLayout->m_vertexDescs; @@ -713,7 +713,7 @@ Slang::Result VKRenderer::_createPipeline(RefPtr<Pipeline>& pipelineOut) VkRect2D scissor = {}; scissor.offset = { 0, 0 }; scissor.extent = { uint32_t(width), uint32_t(height) }; - + VkPipelineViewportStateCreateInfo viewportState = {}; viewportState.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; viewportState.viewportCount = 1; @@ -752,7 +752,7 @@ Slang::Result VKRenderer::_createPipeline(RefPtr<Pipeline>& pipelineOut) colorBlending.blendConstants[3] = 0.0f; VkGraphicsPipelineCreateInfo pipelineInfo = { VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO }; - + pipelineInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; pipelineInfo.stageCount = 2; pipelineInfo.pStages = shaderStages; @@ -834,11 +834,11 @@ Result VKRenderer::_beginPass() VkViewport& dstViewport = viewports[i]; dstViewport.x = 0.0f; - dstViewport.y = 0.0f; - dstViewport.width = float(width); - dstViewport.height = float(height); - dstViewport.minDepth = 0.0f; - dstViewport.maxDepth = 1.0f; + dstViewport.y = 0.0f; + dstViewport.width = float(width); + dstViewport.height = float(height); + dstViewport.minDepth = 0.0f; + dstViewport.maxDepth = 1.0f; } m_api.vkCmdSetScissor(cmdBuffer, 0, numRenderTargets, rects); @@ -937,7 +937,7 @@ VkPipelineShaderStageCreateInfo VKRenderer::compileEntryPoint( bufferOut.InsertRange(0, dataBegin, codeSize); char* codeBegin = bufferOut.Buffer(); - + VkShaderModuleCreateInfo moduleCreateInfo = { VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO }; moduleCreateInfo.pCode = (uint32_t*)codeBegin; moduleCreateInfo.codeSize = codeSize; @@ -950,7 +950,7 @@ VkPipelineShaderStageCreateInfo VKRenderer::compileEntryPoint( shaderStageCreateInfo.module = module; shaderStageCreateInfo.pName = "main"; - + return shaderStageCreateInfo; } @@ -968,7 +968,7 @@ SlangResult VKRenderer::initialize(const Desc& desc, void* inWindowHandle) applicationInfo.pEngineName = "slang-render-test"; applicationInfo.apiVersion = VK_API_VERSION_1_0; - char const* instanceExtensions[] = + char const* instanceExtensions[] = { VK_KHR_SURFACE_EXTENSION_NAME, @@ -993,7 +993,7 @@ SlangResult VKRenderer::initialize(const Desc& desc, void* inWindowHandle) #if ENABLE_VALIDATION_LAYER const char* layerNames[] = { "VK_LAYER_LUNARG_standard_validation" }; - instanceCreateInfo.enabledLayerCount = SLANG_COUNT_OF(layerNames); + instanceCreateInfo.enabledLayerCount = SLANG_COUNT_OF(layerNames); instanceCreateInfo.ppEnabledLayerNames = layerNames; #endif @@ -1020,9 +1020,9 @@ SlangResult VKRenderer::initialize(const Desc& desc, void* inWindowHandle) // TODO: allow override of selected device uint32_t selectedDeviceIndex = 0; - + SLANG_RETURN_ON_FAIL(m_api.initPhysicalDevice(physicalDevices[selectedDeviceIndex])); - + int queueFamilyIndex = m_api.findQueue(VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT); assert(queueFamilyIndex >= 0); @@ -1070,7 +1070,7 @@ SlangResult VKRenderer::initialize(const Desc& desc, void* inWindowHandle) platformDesc = &winPlatformDesc; #endif - SLANG_RETURN_ON_FAIL(m_swapChain.init(&m_deviceQueue, desc, platformDesc)); + SLANG_RETURN_ON_FAIL(m_swapChain.init(&m_deviceQueue, desc, platformDesc)); } // depth/stencil? @@ -1181,7 +1181,7 @@ void VKRenderer::clearFrame() } void VKRenderer::presentFrame() -{ +{ _endRender(); const bool vsync = true; @@ -1244,7 +1244,7 @@ static VkBufferUsageFlags _calcBufferUsageFlags(int bindFlags, int cpuAccessFlag usage |= VK_BUFFER_USAGE_TRANSFER_DST_BIT; } - return usage; + return usage; } static VkImageUsageFlagBits _calcImageUsageFlags(Resource::BindFlag::Enum bind) @@ -1284,7 +1284,7 @@ static VkImageUsageFlagBits _calcImageUsageFlags(int bindFlags) static VkImageUsageFlags _calcImageUsageFlags(int bindFlags, int cpuAccessFlags, const void* initData) { VkImageUsageFlags usage = _calcImageUsageFlags(bindFlags); - + usage |= VK_IMAGE_USAGE_SAMPLED_BIT; if (cpuAccessFlags & Resource::AccessFlag::Read) @@ -1300,7 +1300,7 @@ static VkImageUsageFlags _calcImageUsageFlags(int bindFlags, int cpuAccessFlags, return usage; } -void VKRenderer::_transitionImageLayout(VkImage image, VkFormat format, const TextureResource::Desc& desc, VkImageLayout oldLayout, VkImageLayout newLayout) +void VKRenderer::_transitionImageLayout(VkImage image, VkFormat format, const TextureResource::Desc& desc, VkImageLayout oldLayout, VkImageLayout newLayout) { VkImageMemoryBarrier barrier = {}; barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; @@ -1318,7 +1318,7 @@ void VKRenderer::_transitionImageLayout(VkImage image, VkFormat format, const Te VkPipelineStageFlags sourceStage; VkPipelineStageFlags destinationStage; - if (oldLayout == VK_IMAGE_LAYOUT_UNDEFINED && newLayout == VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL) + if (oldLayout == VK_IMAGE_LAYOUT_UNDEFINED && newLayout == VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL) { barrier.srcAccessMask = 0; barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; @@ -1326,7 +1326,7 @@ void VKRenderer::_transitionImageLayout(VkImage image, VkFormat format, const Te sourceStage = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; destinationStage = VK_PIPELINE_STAGE_TRANSFER_BIT; } - else if (oldLayout == VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL && newLayout == VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL) + else if (oldLayout == VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL && newLayout == VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL) { barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; @@ -1334,7 +1334,7 @@ void VKRenderer::_transitionImageLayout(VkImage image, VkFormat format, const Te sourceStage = VK_PIPELINE_STAGE_TRANSFER_BIT; destinationStage = VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT; } - else + else { assert(!"unsupported layout transition!"); return; @@ -1403,10 +1403,10 @@ TextureResource* VKRenderer::createTextureResource(Resource::Usage initialUsage, imageInfo.mipLevels = desc.numMipLevels; imageInfo.arrayLayers = arraySize; - + imageInfo.format = format; - imageInfo.tiling = VK_IMAGE_TILING_OPTIMAL; + imageInfo.tiling = VK_IMAGE_TILING_OPTIMAL; imageInfo.usage = _calcImageUsageFlags(desc.bindFlags, desc.cpuAccessFlags, initData); imageInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE; @@ -1415,7 +1415,7 @@ TextureResource* VKRenderer::createTextureResource(Resource::Usage initialUsage, SLANG_VK_RETURN_NULL_ON_FAIL(m_api.vkCreateImage(m_device, &imageInfo, nullptr, &texture->m_image)); } - + VkMemoryRequirements memRequirements; m_api.vkGetImageMemoryRequirements(m_device, texture->m_image, &memRequirements); @@ -1424,18 +1424,18 @@ TextureResource* VKRenderer::createTextureResource(Resource::Usage initialUsage, VkMemoryPropertyFlags reqMemoryProperties = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; VkMemoryAllocateInfo allocInfo = {VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO}; - + int memoryTypeIndex = m_api.findMemoryTypeIndex(memRequirements.memoryTypeBits, reqMemoryProperties); assert(memoryTypeIndex >= 0); - + VkMemoryPropertyFlags actualMemoryProperites = m_api.m_deviceMemoryProperties.memoryTypes[memoryTypeIndex].propertyFlags; - + allocInfo.allocationSize = memRequirements.size; allocInfo.memoryTypeIndex = memoryTypeIndex; SLANG_VK_RETURN_NULL_ON_FAIL(m_api.vkAllocateMemory(m_device, &allocInfo, nullptr, &texture->m_imageMemory)); } - + // Bind the memory to the image m_api.vkBindImageMemory(m_device, texture->m_image, texture->m_imageMemory, 0); @@ -1463,8 +1463,8 @@ TextureResource* VKRenderer::createTextureResource(Resource::Usage initialUsage, bufferSize += (rowSizeInBytes * numRows) * mipSize.depth; } - - // Calculate the total size taking into account the array + + // Calculate the total size taking into account the array bufferSize *= arraySize; Buffer uploadBuffer; @@ -1478,7 +1478,7 @@ TextureResource* VKRenderer::createTextureResource(Resource::Usage initialUsage, uint8_t* dstData; m_api.vkMapMemory(m_device, uploadBuffer.m_memory, 0, bufferSize, 0, (void**)&dstData); - + for (int i = 0; i < arraySize; ++i) { for (int j = 0; j < int(mipSizes.Count()); ++j) @@ -1491,12 +1491,12 @@ TextureResource* VKRenderer::createTextureResource(Resource::Usage initialUsage, for (int k = 0; k < mipSize.depth; k++) { - const uint8_t* srcData = (const uint8_t*)(initData->subResources[subResourceIndex]); + const uint8_t* srcData = (const uint8_t*)(initData->subResources[subResourceIndex]); for (int l = 0; l < numRows; l++) { ::memcpy(dstData, srcData, dstRowSizeInBytes); - + dstData += dstRowSizeInBytes; srcData += srcRowStride; } @@ -1510,7 +1510,7 @@ TextureResource* VKRenderer::createTextureResource(Resource::Usage initialUsage, } _transitionImageLayout(texture->m_image, format, texture->getDesc(), VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); - + { size_t srcOffset = 0; for (int i = 0; i < arraySize; ++i) @@ -1518,21 +1518,21 @@ TextureResource* VKRenderer::createTextureResource(Resource::Usage initialUsage, for (int j = 0; j < int(mipSizes.Count()); ++j) { const auto& mipSize = mipSizes[j]; - + const int rowSizeInBytes = Surface::calcRowSize(desc.format, mipSize.width); const int numRows = Surface::calcNumRows(desc.format, mipSize.height); // https://www.khronos.org/registry/vulkan/specs/1.1-extensions/man/html/VkBufferImageCopy.html // bufferRowLength and bufferImageHeight specify the data in buffer memory as a subregion of a larger two- or three-dimensional image, - // and control the addressing calculations of data in buffer memory. If either of these values is zero, that aspect of the buffer memory + // and control the addressing calculations of data in buffer memory. If either of these values is zero, that aspect of the buffer memory // is considered to be tightly packed according to the imageExtent. VkBufferImageCopy region = {}; region.bufferOffset = srcOffset; region.bufferRowLength = 0; //rowSizeInBytes; - region.bufferImageHeight = 0; - + region.bufferImageHeight = 0; + region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; region.imageSubresource.mipLevel = j; region.imageSubresource.baseArrayLayer = i; @@ -1567,7 +1567,7 @@ BufferResource* VKRenderer::createBufferResource(Resource::Usage initialUsage, c VkMemoryPropertyFlags reqMemoryProperties = 0; VkBufferUsageFlags usage = _calcBufferUsageFlags(desc.bindFlags, desc.cpuAccessFlags, initData); - + switch (initialUsage) { case Resource::Usage::ConstantBuffer: @@ -1599,7 +1599,7 @@ BufferResource* VKRenderer::createBufferResource(Resource::Usage initialUsage, c // Copy from staging buffer to real buffer VkCommandBuffer commandBuffer = m_deviceQueue.getCommandBuffer(); - + VkBufferCopy copyInfo = {}; copyInfo.size = bufferSize; m_api.vkCmdCopyBuffer(commandBuffer, buffer->m_uploadBuffer.m_buffer, buffer->m_buffer.m_buffer, 1, ©Info); @@ -1610,7 +1610,7 @@ BufferResource* VKRenderer::createBufferResource(Resource::Usage initialUsage, c return buffer.detach(); } -InputLayout* VKRenderer::createInputLayout(const InputElementDesc* elements, UInt numElements) +InputLayout* VKRenderer::createInputLayout(const InputElementDesc* elements, UInt numElements) { RefPtr<InputLayoutImpl> layout(new InputLayoutImpl); @@ -1632,8 +1632,8 @@ InputLayout* VKRenderer::createInputLayout(const InputElementDesc* elements, UIn return nullptr; } - dstDesc.offset = uint32_t(srcDesc.offset); - + dstDesc.offset = uint32_t(srcDesc.offset); + const size_t elementSize = RendererUtil::getFormatSize(srcDesc.format); assert(elementSize > 0); const size_t endElement = srcDesc.offset + elementSize; @@ -1857,7 +1857,7 @@ static VkImageViewType _calcImageViewType(TextureResource::Type type, const Text BindingState* VKRenderer::createBindingState(const BindingState::Desc& bindingStateDesc) -{ +{ RefPtr<BindingStateImpl> bindingState(new BindingStateImpl(bindingStateDesc, &m_api)); const auto& srcBindings = bindingStateDesc.m_bindings; @@ -1895,7 +1895,7 @@ BindingState* VKRenderer::createBindingState(const BindingState::Desc& bindingSt // Not sure how to handle typeless? if (bufferResourceDesc.elementSize == 0) { - info.format = VK_FORMAT_R32_SFLOAT; // DXGI_FORMAT_R32_TYPELESS ? + info.format = VK_FORMAT_R32_SFLOAT; // DXGI_FORMAT_R32_TYPELESS ? } info.buffer = bufferResource->m_buffer.m_buffer; @@ -1905,7 +1905,7 @@ BindingState* VKRenderer::createBindingState(const BindingState::Desc& bindingSt SLANG_VK_RETURN_NULL_ON_FAIL(m_api.vkCreateBufferView(m_device, &info, nullptr, &dstDetail.m_uav)); } - // TODO: Setup views. + // TODO: Setup views. // VkImageView srv @@ -1914,10 +1914,10 @@ BindingState* VKRenderer::createBindingState(const BindingState::Desc& bindingSt case BindingType::Sampler: { VkSamplerCreateInfo samplerInfo = { VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO }; - + samplerInfo.magFilter = VK_FILTER_LINEAR; samplerInfo.minFilter = VK_FILTER_LINEAR; - + samplerInfo.addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT; samplerInfo.addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT; samplerInfo.addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT; @@ -1960,7 +1960,7 @@ BindingState* VKRenderer::createBindingState(const BindingState::Desc& bindingSt } // Create the image view - + VkImageViewCreateInfo viewInfo = {}; viewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; viewInfo.image = textureResource->m_image; @@ -1978,7 +1978,7 @@ BindingState* VKRenderer::createBindingState(const BindingState::Desc& bindingSt viewInfo.components.a = VK_COMPONENT_SWIZZLE_IDENTITY; SLANG_VK_RETURN_NULL_ON_FAIL(m_api.vkCreateImageView(m_device, &viewInfo, nullptr, &dstDetail.m_srv)); - + break; } case BindingType::CombinedTextureSampler: diff --git a/tools/render-test/render-vk.h b/tools/slang-graphics/render-vk.h index 7f6d789d0..720f35a2c 100644 --- a/tools/render-test/render-vk.h +++ b/tools/slang-graphics/render-vk.h @@ -1,10 +1,10 @@ // render-vk.h #pragma once -namespace renderer_test { +namespace slang_graphics { class Renderer; Renderer* createVKRenderer(); -} // renderer_test +} // slang_graphics diff --git a/tools/render-test/render.cpp b/tools/slang-graphics/render.cpp index bfb7aeb94..3595f73c1 100644 --- a/tools/render-test/render.cpp +++ b/tools/slang-graphics/render.cpp @@ -3,7 +3,7 @@ #include "../../source/core/slang-math.h" -namespace renderer_test { +namespace slang_graphics { using namespace Slang; /* static */const Resource::BindFlag::Enum Resource::s_requiredBinding[] = diff --git a/tools/render-test/render.h b/tools/slang-graphics/render.h index 6a3c58a05..92e9c0930 100644 --- a/tools/render-test/render.h +++ b/tools/slang-graphics/render.h @@ -10,7 +10,7 @@ #include "../../source/core/smart-pointer.h" #include "../../source/core/list.h" -namespace renderer_test { +namespace slang_graphics { // Had to move here, because Options needs types defined here typedef intptr_t Int; diff --git a/tools/render-test/resource-d3d12.cpp b/tools/slang-graphics/resource-d3d12.cpp index 160c7f898..bb39d2529 100644 --- a/tools/render-test/resource-d3d12.cpp +++ b/tools/slang-graphics/resource-d3d12.cpp @@ -1,7 +1,7 @@ // resource-d3d12.cpp #include "resource-d3d12.h" -namespace renderer_test { +namespace slang_graphics { using namespace Slang; /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! D3D12BarrierSubmitter !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ @@ -97,7 +97,7 @@ Result D3D12CounterFence::init(ID3D12Device* device, uint64_t initialValue) UInt64 D3D12CounterFence::nextSignal(ID3D12CommandQueue* commandQueue) { - // Increment the fence value. Save on the frame - we'll know that frame is done when the fence value >= + // Increment the fence value. Save on the frame - we'll know that frame is done when the fence value >= m_currentValue++; // Schedule a Signal command in the queue. Result res = commandQueue->Signal(m_fence, m_currentValue); diff --git a/tools/render-test/resource-d3d12.h b/tools/slang-graphics/resource-d3d12.h index 1f0ba638b..6040291cc 100644 --- a/tools/render-test/resource-d3d12.h +++ b/tools/slang-graphics/resource-d3d12.h @@ -13,11 +13,11 @@ #include "../../slang-com-ptr.h" #include "d3d-util.h" -namespace renderer_test { +namespace slang_graphics { // Enables more conservative barriers - restoring the state of resources after they are used. // Should not need to be enabled in normal builds, as the barriers should correctly sync resources -// If enabling fixes an issue it implies regular barriers are not correctly used. +// If enabling fixes an issue it implies regular barriers are not correctly used. #define SLANG_ENABLE_CONSERVATIVE_RESOURCE_BARRIERS 0 struct D3D12BarrierSubmitter @@ -26,7 +26,7 @@ struct D3D12BarrierSubmitter /// Expand one space to hold a barrier SLANG_FORCE_INLINE D3D12_RESOURCE_BARRIER& expandOne() { return (m_numBarriers < MAX_BARRIERS) ? m_barriers[m_numBarriers++] : _expandOne(); } - /// Flush barriers to command list + /// Flush barriers to command list SLANG_FORCE_INLINE void flush() { if (m_numBarriers > 0) _flush(); } /// Transition resource from prevState to nextState @@ -79,7 +79,7 @@ public: /// Get the completed value SLANG_FORCE_INLINE uint64_t getCompletedValue() const { return m_fence->GetCompletedValue(); } - /// Waits for the the specified value + /// Waits for the the specified value void waitUntilCompleted(uint64_t completedValue); /// Ctor diff --git a/tools/slang-graphics/slang-graphics.vcxproj b/tools/slang-graphics/slang-graphics.vcxproj new file mode 100644 index 000000000..ce7502326 --- /dev/null +++ b/tools/slang-graphics/slang-graphics.vcxproj @@ -0,0 +1,212 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <ItemGroup Label="ProjectConfigurations"> + <ProjectConfiguration Include="Debug|Win32"> + <Configuration>Debug</Configuration> + <Platform>Win32</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Debug|x64"> + <Configuration>Debug</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|Win32"> + <Configuration>Release</Configuration> + <Platform>Win32</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|x64"> + <Configuration>Release</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + </ItemGroup> + <PropertyGroup Label="Globals"> + <ProjectGuid>{222F7498-B40C-4F3F-A704-DDEB91A4484A}</ProjectGuid> + <IgnoreWarnCompileDuplicatedFilename>true</IgnoreWarnCompileDuplicatedFilename> + <Keyword>Win32Proj</Keyword> + <RootNamespace>slang-graphics</RootNamespace> + <WindowsTargetPlatformVersion>10.0.14393.0</WindowsTargetPlatformVersion> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> + <ConfigurationType>StaticLibrary</ConfigurationType> + <UseDebugLibraries>true</UseDebugLibraries> + <CharacterSet>Unicode</CharacterSet> + <PlatformToolset>v140</PlatformToolset> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> + <ConfigurationType>StaticLibrary</ConfigurationType> + <UseDebugLibraries>true</UseDebugLibraries> + <CharacterSet>Unicode</CharacterSet> + <PlatformToolset>v140</PlatformToolset> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> + <ConfigurationType>StaticLibrary</ConfigurationType> + <UseDebugLibraries>false</UseDebugLibraries> + <CharacterSet>Unicode</CharacterSet> + <PlatformToolset>v140</PlatformToolset> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> + <ConfigurationType>StaticLibrary</ConfigurationType> + <UseDebugLibraries>false</UseDebugLibraries> + <CharacterSet>Unicode</CharacterSet> + <PlatformToolset>v140</PlatformToolset> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> + <ImportGroup Label="ExtensionSettings"> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <PropertyGroup Label="UserMacros" /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <OutDir>..\..\bin\windows-x86\debug\</OutDir> + <IntDir>..\..\intermediate\windows-x86\debug\slang-graphics\</IntDir> + <TargetName>slang-graphics</TargetName> + <TargetExt>.lib</TargetExt> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <OutDir>..\..\bin\windows-x64\debug\</OutDir> + <IntDir>..\..\intermediate\windows-x64\debug\slang-graphics\</IntDir> + <TargetName>slang-graphics</TargetName> + <TargetExt>.lib</TargetExt> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <OutDir>..\..\bin\windows-x86\release\</OutDir> + <IntDir>..\..\intermediate\windows-x86\release\slang-graphics\</IntDir> + <TargetName>slang-graphics</TargetName> + <TargetExt>.lib</TargetExt> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <OutDir>..\..\bin\windows-x64\release\</OutDir> + <IntDir>..\..\intermediate\windows-x64\release\slang-graphics\</IntDir> + <TargetName>slang-graphics</TargetName> + <TargetExt>.lib</TargetExt> + </PropertyGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <ClCompile> + <PrecompiledHeader>NotUsing</PrecompiledHeader> + <WarningLevel>Level3</WarningLevel> + <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <AdditionalIncludeDirectories>..\..;..\..\external;..\..\source;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <DebugInformationFormat>EditAndContinue</DebugInformationFormat> + <Optimization>Disabled</Optimization> + <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> + </ClCompile> + <Link> + <SubSystem>Windows</SubSystem> + <GenerateDebugInformation>true</GenerateDebugInformation> + </Link> + <PostBuildEvent> + <Command>"$(SolutionDir)tools\copy-hlsl-libs.bat" "$(WindowsSdkDir)Redist/D3D/x86/" "../../bin/windows-x86/debug/"</Command> + </PostBuildEvent> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <ClCompile> + <PrecompiledHeader>NotUsing</PrecompiledHeader> + <WarningLevel>Level3</WarningLevel> + <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <AdditionalIncludeDirectories>..\..;..\..\external;..\..\source;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <DebugInformationFormat>EditAndContinue</DebugInformationFormat> + <Optimization>Disabled</Optimization> + <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> + </ClCompile> + <Link> + <SubSystem>Windows</SubSystem> + <GenerateDebugInformation>true</GenerateDebugInformation> + </Link> + <PostBuildEvent> + <Command>"$(SolutionDir)tools\copy-hlsl-libs.bat" "$(WindowsSdkDir)Redist/D3D/x64/" "../../bin/windows-x64/debug/"</Command> + </PostBuildEvent> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <ClCompile> + <PrecompiledHeader>NotUsing</PrecompiledHeader> + <WarningLevel>Level3</WarningLevel> + <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <AdditionalIncludeDirectories>..\..;..\..\external;..\..\source;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <Optimization>Full</Optimization> + <FunctionLevelLinking>true</FunctionLevelLinking> + <IntrinsicFunctions>true</IntrinsicFunctions> + <MinimalRebuild>false</MinimalRebuild> + <StringPooling>true</StringPooling> + <RuntimeLibrary>MultiThreaded</RuntimeLibrary> + </ClCompile> + <Link> + <SubSystem>Windows</SubSystem> + <EnableCOMDATFolding>true</EnableCOMDATFolding> + <OptimizeReferences>true</OptimizeReferences> + </Link> + <PostBuildEvent> + <Command>"$(SolutionDir)tools\copy-hlsl-libs.bat" "$(WindowsSdkDir)Redist/D3D/x86/" "../../bin/windows-x86/release/"</Command> + </PostBuildEvent> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <ClCompile> + <PrecompiledHeader>NotUsing</PrecompiledHeader> + <WarningLevel>Level3</WarningLevel> + <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <AdditionalIncludeDirectories>..\..;..\..\external;..\..\source;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <Optimization>Full</Optimization> + <FunctionLevelLinking>true</FunctionLevelLinking> + <IntrinsicFunctions>true</IntrinsicFunctions> + <MinimalRebuild>false</MinimalRebuild> + <StringPooling>true</StringPooling> + <RuntimeLibrary>MultiThreaded</RuntimeLibrary> + </ClCompile> + <Link> + <SubSystem>Windows</SubSystem> + <EnableCOMDATFolding>true</EnableCOMDATFolding> + <OptimizeReferences>true</OptimizeReferences> + </Link> + <PostBuildEvent> + <Command>"$(SolutionDir)tools\copy-hlsl-libs.bat" "$(WindowsSdkDir)Redist/D3D/x64/" "../../bin/windows-x64/release/"</Command> + </PostBuildEvent> + </ItemDefinitionGroup> + <ItemGroup> + <ClInclude Include="circular-resource-heap-d3d12.h" /> + <ClInclude Include="d3d-util.h" /> + <ClInclude Include="descriptor-heap-d3d12.h" /> + <ClInclude Include="render-d3d11.h" /> + <ClInclude Include="render-d3d12.h" /> + <ClInclude Include="render-gl.h" /> + <ClInclude Include="render-vk.h" /> + <ClInclude Include="render.h" /> + <ClInclude Include="resource-d3d12.h" /> + <ClInclude Include="surface.h" /> + <ClInclude Include="vk-api.h" /> + <ClInclude Include="vk-device-queue.h" /> + <ClInclude Include="vk-module.h" /> + <ClInclude Include="vk-swap-chain.h" /> + <ClInclude Include="vk-util.h" /> + <ClInclude Include="window.h" /> + </ItemGroup> + <ItemGroup> + <ClCompile Include="circular-resource-heap-d3d12.cpp" /> + <ClCompile Include="d3d-util.cpp" /> + <ClCompile Include="descriptor-heap-d3d12.cpp" /> + <ClCompile Include="render-d3d11.cpp" /> + <ClCompile Include="render-d3d12.cpp" /> + <ClCompile Include="render-gl.cpp" /> + <ClCompile Include="render-vk.cpp" /> + <ClCompile Include="render.cpp" /> + <ClCompile Include="resource-d3d12.cpp" /> + <ClCompile Include="surface.cpp" /> + <ClCompile Include="vk-api.cpp" /> + <ClCompile Include="vk-device-queue.cpp" /> + <ClCompile Include="vk-module.cpp" /> + <ClCompile Include="vk-swap-chain.cpp" /> + <ClCompile Include="vk-util.cpp" /> + <ClCompile Include="window.cpp" /> + </ItemGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> + <ImportGroup Label="ExtensionTargets"> + </ImportGroup> +</Project>
\ No newline at end of file diff --git a/tools/slang-graphics/slang-graphics.vcxproj.filters b/tools/slang-graphics/slang-graphics.vcxproj.filters new file mode 100644 index 000000000..b1e4c42a3 --- /dev/null +++ b/tools/slang-graphics/slang-graphics.vcxproj.filters @@ -0,0 +1,111 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <ItemGroup> + <Filter Include="Header Files"> + <UniqueIdentifier>{21EB8090-0D4E-1035-B6D3-48EBA215DCB7}</UniqueIdentifier> + </Filter> + <Filter Include="Source Files"> + <UniqueIdentifier>{E9C7FDCE-D52A-8D73-7EB0-C5296AF258F6}</UniqueIdentifier> + </Filter> + </ItemGroup> + <ItemGroup> + <ClInclude Include="circular-resource-heap-d3d12.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="d3d-util.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="descriptor-heap-d3d12.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="render-d3d11.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="render-d3d12.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="render-gl.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="render-vk.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="render.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="resource-d3d12.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="surface.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="vk-api.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="vk-device-queue.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="vk-module.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="vk-swap-chain.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="vk-util.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="window.h"> + <Filter>Header Files</Filter> + </ClInclude> + </ItemGroup> + <ItemGroup> + <ClCompile Include="circular-resource-heap-d3d12.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="d3d-util.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="descriptor-heap-d3d12.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="render-d3d11.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="render-d3d12.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="render-gl.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="render-vk.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="render.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="resource-d3d12.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="surface.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="vk-api.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="vk-device-queue.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="vk-module.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="vk-swap-chain.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="vk-util.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="window.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + </ItemGroup> +</Project>
\ No newline at end of file diff --git a/tools/render-test/surface.cpp b/tools/slang-graphics/surface.cpp index eabe555c3..9d91f8778 100644 --- a/tools/render-test/surface.cpp +++ b/tools/slang-graphics/surface.cpp @@ -6,7 +6,7 @@ #include "../../source/core/list.h" -namespace renderer_test { +namespace slang_graphics { using namespace Slang; class MallocSurfaceAllocator: public SurfaceAllocator @@ -80,10 +80,10 @@ void MallocSurfaceAllocator::deallocate(Surface& surface) return int(pixelSize * width); } -/* static */int Surface::calcNumRows(Format format, int height) -{ +/* static */int Surface::calcNumRows(Format format, int height) +{ // Don't have any compressed types, so number of rows is same as the height - return height; + return height; } void Surface::init() @@ -94,7 +94,7 @@ void Surface::init() m_data = nullptr; m_numRows = 0; m_rowStrideInBytes = 0; - // NOTE! does not clear the allocator. + // NOTE! does not clear the allocator. // If called with an allocation memory will leak! } @@ -141,7 +141,7 @@ void Surface::setUnowned(int width, int height, Format format, int strideInBytes m_data = (uint8_t*)data; m_numRows = Surface::calcNumRows(format, height); - + const int rowSizeInBytes = Surface::calcRowSize(format, width); assert((strideInBytes > 0 && rowSizeInBytes <= strideInBytes) || (strideInBytes < 0 && rowSizeInBytes <= -strideInBytes)); } @@ -209,8 +209,8 @@ SlangResult Surface::set(int width, int height, Format format, int srcRowStride, for (int i = 0; i < m_numRows; i++) { - ::memcpy(dstRow, srcRow, rowSize); - + ::memcpy(dstRow, srcRow, rowSize); + srcRow += srcRowStride; dstRow += m_rowStrideInBytes; } diff --git a/tools/render-test/surface.h b/tools/slang-graphics/surface.h index c7460238f..026ba25ed 100644 --- a/tools/render-test/surface.h +++ b/tools/slang-graphics/surface.h @@ -2,8 +2,8 @@ #pragma once #include "render.h" - -namespace renderer_test { + +namespace slang_graphics { class Surface; @@ -21,7 +21,7 @@ class Surface { public: - enum + enum { kDefaultAlignment = sizeof(void*) }; @@ -35,11 +35,11 @@ class Surface void init(); /// Set unowned - void setUnowned(int width, int height, Format format, int strideInBytes, void* data); + void setUnowned(int width, int height, Format format, int strideInBytes, void* data); /// Set the contents - the memory will be owned by this surface (ie will be freed by the allocator when goes out of scope or is deallocated) Slang::Result set(int width, int height, Format format, int strideInBytes, const void* data, SurfaceAllocator* allocator); - + template <typename T> T* calcNextRow(T* ptr) const { return (T*)calcNextRow((void*)ptr); } template <typename T> @@ -53,7 +53,7 @@ class Surface /// Flips the contents vertically in place void flipInplaceVertically(); - + /// True if has some contents bool hasContents() const { return m_data != nullptr; } @@ -65,7 +65,7 @@ class Surface } /// Dtor ~Surface(); - + /// Get the size of the row in bytes static int calcRowSize(Format format, int width); /// Calculates the number of rows @@ -73,8 +73,8 @@ class Surface int m_width; int m_height; - Format m_format; - + Format m_format; + uint8_t* m_data; /// The data that makes up the image. If nullptr, has no data. Pointer to first 'row' of the image. int m_numRows; ///< Total amount of rows (typically same as height, but in compressed formats may be less) diff --git a/tools/render-test/vk-api.cpp b/tools/slang-graphics/vk-api.cpp index df222d8ad..0ffbf46eb 100644 --- a/tools/render-test/vk-api.cpp +++ b/tools/slang-graphics/vk-api.cpp @@ -3,13 +3,13 @@ #include "../../source/core/list.h" -namespace renderer_test { +namespace slang_graphics { using namespace Slang; // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! VulkanApi !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -#define VK_API_CHECK_FUNCTION(x) && (x != nullptr) -#define VK_API_CHECK_FUNCTIONS(FUNCTION_LIST) true FUNCTION_LIST(VK_API_CHECK_FUNCTION) +#define VK_API_CHECK_FUNCTION(x) && (x != nullptr) +#define VK_API_CHECK_FUNCTIONS(FUNCTION_LIST) true FUNCTION_LIST(VK_API_CHECK_FUNCTION) bool VulkanApi::areDefined(ProcType type) const { @@ -92,10 +92,10 @@ int VulkanApi::findMemoryTypeIndex(uint32_t typeBits, VkMemoryPropertyFlags prop assert(typeBits); const int numMemoryTypes = int(m_deviceMemoryProperties.memoryTypeCount); - - // bit holds current test bit against typeBits. Ie bit == 1 << typeBits - - uint32_t bit = 1; + + // bit holds current test bit against typeBits. Ie bit == 1 << typeBits + + uint32_t bit = 1; for (int i = 0; i < numMemoryTypes; ++i, bit += bit) { auto const& memoryType = m_deviceMemoryProperties.memoryTypes[i]; @@ -104,7 +104,7 @@ int VulkanApi::findMemoryTypeIndex(uint32_t typeBits, VkMemoryPropertyFlags prop return i; } } - + //assert(!"failed to find a usable memory type"); return -1; } diff --git a/tools/render-test/vk-api.h b/tools/slang-graphics/vk-api.h index 521d6301d..0cbd3faf7 100644 --- a/tools/render-test/vk-api.h +++ b/tools/slang-graphics/vk-api.h @@ -3,7 +3,7 @@ #include "vk-module.h" -namespace renderer_test { +namespace slang_graphics { #define VK_API_GLOBAL_PROCS(x) \ x(vkGetInstanceProcAddr) \ @@ -154,17 +154,17 @@ struct VulkanApi { VK_API_ALL_PROCS(VK_API_DECLARE_PROC) - enum class ProcType + enum class ProcType { Global, - Instance, + Instance, Device, }; - /// Returns true if all the functions in the class are defined + /// Returns true if all the functions in the class are defined bool areDefined(ProcType type) const; - /// Sets up global parameters + /// Sets up global parameters Slang::Result initGlobalProcs(const VulkanModule& module); /// Initialize the instance functions Slang::Result initInstanceProcs(VkInstance instance); diff --git a/tools/render-test/vk-device-queue.cpp b/tools/slang-graphics/vk-device-queue.cpp index d40442c22..9e978117f 100644 --- a/tools/render-test/vk-device-queue.cpp +++ b/tools/slang-graphics/vk-device-queue.cpp @@ -5,7 +5,7 @@ #include <stdio.h> #include <assert.h> -namespace renderer_test { +namespace slang_graphics { using namespace Slang; VulkanDeviceQueue::~VulkanDeviceQueue() @@ -33,12 +33,12 @@ SlangResult VulkanDeviceQueue::init(const VulkanApi& api, VkQueue queue, int que m_semaphores[i] = VK_NULL_HANDLE; m_currentSemaphores[i] = VK_NULL_HANDLE; } - + m_numCommandBuffers = kMaxCommandBuffers; m_queueIndex = queueIndex; m_queue = queue; - + VkCommandPoolCreateInfo poolCreateInfo = {}; poolCreateInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; poolCreateInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; @@ -75,7 +75,7 @@ SlangResult VulkanDeviceQueue::init(const VulkanApi& api, VkQueue queue, int que { api.vkCreateSemaphore(api.m_device, &semaphoreCreateInfo, nullptr, &m_semaphores[i]); } - + // Second step of flush to prime command buffer flushStepB(); @@ -101,7 +101,7 @@ void VulkanDeviceQueue::flushStepA() submitInfo.pWaitDstStageMask = &stageFlags; submitInfo.commandBufferCount = 1; submitInfo.pCommandBuffers = &m_commandBuffer; - + // Signal semaphores if (isCurrent(EventType::EndFrame)) { @@ -116,7 +116,7 @@ void VulkanDeviceQueue::flushStepA() // mark signaled fence value fence.value = m_nextFenceValue; fence.active = true; - + // increment fence value m_nextFenceValue++; @@ -147,10 +147,10 @@ void VulkanDeviceQueue::_updateFenceAtIndex( int fenceIndex, bool blocking) } void VulkanDeviceQueue::flushStepB() -{ +{ m_commandBufferIndex = (m_commandBufferIndex + 1) % m_numCommandBuffers; m_commandBuffer = m_commandBuffers[m_commandBufferIndex]; - + // non-blocking update of fence values for (int i = 0; i < m_numCommandBuffers; ++i) { @@ -159,7 +159,7 @@ void VulkanDeviceQueue::flushStepB() // blocking update of fence values _updateFenceAtIndex(m_commandBufferIndex, true); - + m_api->vkResetCommandBuffer(m_commandBuffer, 0); //m_api.vkResetCommandPool(m_api->m_device, m_commandPool, 0); @@ -185,7 +185,7 @@ void VulkanDeviceQueue::flushAndWait() VkSemaphore VulkanDeviceQueue::makeCurrent(EventType eventType) { - assert(!isCurrent(eventType)); + assert(!isCurrent(eventType)); VkSemaphore semaphore = m_semaphores[int(eventType)]; m_currentSemaphores[int(eventType)] = semaphore; return semaphore; diff --git a/tools/render-test/vk-device-queue.h b/tools/slang-graphics/vk-device-queue.h index 8381f5166..01ed16f5d 100644 --- a/tools/render-test/vk-device-queue.h +++ b/tools/slang-graphics/vk-device-queue.h @@ -3,11 +3,11 @@ #include "vk-api.h" -namespace renderer_test { +namespace slang_graphics { struct VulkanDeviceQueue { - enum + enum { kMaxCommandBuffers = 8, }; @@ -24,7 +24,7 @@ struct VulkanDeviceQueue /// Flushes the current command list, and steps to next (internally this is equivalent to a stepA followed by stepB) void flush(); - /// Performs a full flush, and then waits for idle. + /// Performs a full flush, and then waits for idle. void flushAndWait(); /// Blocks until all work submitted to GPU has completed @@ -49,7 +49,7 @@ struct VulkanDeviceQueue /// Get the API const VulkanApi* getApi() const { return m_api; } - /// Flushes the current command list + /// Flushes the current command list void flushStepA(); /// Steps to next command buffer and opens. May block if command buffer is still in use void flushStepB(); @@ -58,7 +58,7 @@ struct VulkanDeviceQueue ~VulkanDeviceQueue(); protected: - + struct Fence { VkFence fence; @@ -77,7 +77,7 @@ struct VulkanDeviceQueue VkCommandBuffer m_commandBuffers[kMaxCommandBuffers] = { VK_NULL_HANDLE }; Fence m_fences[kMaxCommandBuffers] = { {VK_NULL_HANDLE, 0, 0u} }; - + VkCommandBuffer m_commandBuffer = VK_NULL_HANDLE; VkSemaphore m_semaphores[int(EventType::CountOf)]; diff --git a/tools/render-test/vk-module.cpp b/tools/slang-graphics/vk-module.cpp index e98bd08cd..460e6550c 100644 --- a/tools/render-test/vk-module.cpp +++ b/tools/slang-graphics/vk-module.cpp @@ -5,13 +5,13 @@ #include <stdio.h> #include <assert.h> -#if SLANG_WINDOWS_FAMILY +#if SLANG_WINDOWS_FAMILY # include <windows.h> #else # include <dlfcn.h> #endif -namespace renderer_test { +namespace slang_graphics { using namespace Slang; // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! VulkanModule !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! @@ -28,8 +28,8 @@ Slang::Result VulkanModule::init() #if SLANG_WINDOWS_FAMILY dynamicLibraryName = "vulkan-1.dll"; - HMODULE module = ::LoadLibraryA(dynamicLibraryName); - m_module = (void*)module; + HMODULE module = ::LoadLibraryA(dynamicLibraryName); + m_module = (void*)module; #else dynamicLibraryName = "libvulkan.so.1"; m_module = dlopen(dynamicLibraryName, RTLD_NOW); @@ -53,7 +53,7 @@ PFN_vkVoidFunction VulkanModule::getFunction(const char* name) const } #if SLANG_WINDOWS_FAMILY return (PFN_vkVoidFunction)::GetProcAddress((HMODULE)m_module, name); -#else +#else return (PFN_vkVoidFunction)dlsym(m_module, name); #endif } @@ -65,8 +65,8 @@ void VulkanModule::destroy() return; } -#if SLANG_WINDOWS_FAMILY - ::FreeLibrary((HMODULE)m_module); +#if SLANG_WINDOWS_FAMILY + ::FreeLibrary((HMODULE)m_module); #else dlclose(m_module); #endif diff --git a/tools/render-test/vk-module.h b/tools/slang-graphics/vk-module.h index 0aed2303f..c72334db5 100644 --- a/tools/render-test/vk-module.h +++ b/tools/slang-graphics/vk-module.h @@ -14,7 +14,7 @@ #define VK_NO_PROTOTYPES #include <vulkan/vulkan.h> -namespace renderer_test { +namespace slang_graphics { struct VulkanModule { @@ -27,7 +27,7 @@ struct VulkanModule /// Initialize Slang::Result init(); /// Destroy - void destroy(); + void destroy(); /// Dtor ~VulkanModule() { destroy(); } diff --git a/tools/render-test/vk-swap-chain.cpp b/tools/slang-graphics/vk-swap-chain.cpp index 7b8b6221c..a6704e9d7 100644 --- a/tools/render-test/vk-swap-chain.cpp +++ b/tools/slang-graphics/vk-swap-chain.cpp @@ -8,7 +8,7 @@ #include <stdlib.h> #include <stdio.h> -namespace renderer_test { +namespace slang_graphics { using namespace Slang; static int _indexOf(List<VkSurfaceFormatKHR>& formatsIn, VkFormat format) @@ -32,7 +32,7 @@ SlangResult VulkanSwapChain::init(VulkanDeviceQueue* deviceQueue, const Desc& de m_deviceQueue = deviceQueue; m_api = deviceQueue->getApi(); - + // Make sure it's not set initially m_format = VK_FORMAT_UNDEFINED; @@ -54,9 +54,9 @@ SlangResult VulkanSwapChain::init(VulkanDeviceQueue* deviceQueue, const Desc& de VkXlibSurfaceCreateInfoKHR surfaceCreateInfo = {}; surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR; - surfaceCreateInfo.dpy = platformDesc->m_display; + surfaceCreateInfo.dpy = platformDesc->m_display; surfaceCreateInfo.window = platformDesc->m_window; - + SLANG_VK_RETURN_ON_FAIL(m_api->vkCreateXlibSurfaceKHR(m_api->m_instance, &surfaceCreateInfo, nullptr, &m_surface)); #endif @@ -113,7 +113,7 @@ void VulkanSwapChain::getWindowSize(int* widthOut, int* heightOut) const #else auto platformDesc = _getPlatformDesc<XPlatformDesc>(); - XWindowAttributes winAttr = {}; + XWindowAttributes winAttr = {}; XGetWindowAttributes(platformDesc->m_display, platformDesc->m_window, &winAttr); *widthOut = winAttr.width; @@ -128,7 +128,7 @@ SlangResult VulkanSwapChain::_createFrameBuffers(VkRenderPass renderPass) for (int i = 0; i < int(m_images.Count()); ++i) { Image& image = m_images[i]; - VkImageView attachments[] = + VkImageView attachments[] = { image.m_imageView }; @@ -183,7 +183,7 @@ SlangResult VulkanSwapChain::_createSwapChain() return SLANG_OK; } - int width, height; + int width, height; getWindowSize(&width, &height); VkExtent2D imageExtent = {}; @@ -231,8 +231,8 @@ SlangResult VulkanSwapChain::_createSwapChain() { m_presentMode = presentOptions[j]; break; - } - } + } + } if (m_presentMode == VK_PRESENT_MODE_MAX_ENUM_KHR) { @@ -262,29 +262,29 @@ SlangResult VulkanSwapChain::_createSwapChain() uint32_t numSwapChainImages = 0; m_api->vkGetSwapchainImagesKHR(m_api->m_device, m_swapChain, &numSwapChainImages, nullptr); - + { List<VkImage> images; images.SetSize(numSwapChainImages); m_api->vkGetSwapchainImagesKHR(m_api->m_device, m_swapChain, &numSwapChainImages, images.Buffer()); - + m_images.SetSize(numSwapChainImages); for (int i = 0; i < int(numSwapChainImages); ++i) { Image& dstImage = m_images[i]; dstImage.m_image = images[i]; - + } } { VkImageViewCreateInfo createInfo = {}; createInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; - + createInfo.viewType = VK_IMAGE_VIEW_TYPE_2D; createInfo.format = m_format; - + createInfo.components.r = VK_COMPONENT_SWIZZLE_IDENTITY; createInfo.components.g = VK_COMPONENT_SWIZZLE_IDENTITY; createInfo.components.b = VK_COMPONENT_SWIZZLE_IDENTITY; @@ -301,7 +301,7 @@ SlangResult VulkanSwapChain::_createSwapChain() Image& image = m_images[i]; createInfo.image = image.m_image; - + SLANG_VK_RETURN_ON_FAIL(m_api->vkCreateImageView(m_api->m_device, &createInfo, nullptr, &image.m_imageView)); } } @@ -318,7 +318,7 @@ void VulkanSwapChain::_destroySwapChain() { if (!hasValidSwapChain()) { - return; + return; } m_deviceQueue->waitForIdle(); @@ -351,7 +351,7 @@ void VulkanSwapChain::_destroySwapChain() VulkanSwapChain::~VulkanSwapChain() { _destroySwapChain(); - + if (m_surface) { m_api->vkDestroySurfaceKHR(m_api->m_instance, m_surface, nullptr); @@ -370,7 +370,7 @@ int VulkanSwapChain::nextFrontImageIndex() } VkSemaphore beginFrameSemaphore = m_deviceQueue->makeCurrent(VulkanDeviceQueue::EventType::BeginFrame); - + uint32_t swapChainIndex = 0; VkResult result = m_api->vkAcquireNextImageKHR(m_api->m_device, m_swapChain, UINT64_MAX, beginFrameSemaphore, VK_NULL_HANDLE, &swapChainIndex); @@ -392,15 +392,15 @@ void VulkanSwapChain::present(bool vsync) } VkSemaphore endFrameSemaphore = m_deviceQueue->makeCurrent(VulkanDeviceQueue::EventType::EndFrame); - + m_deviceQueue->flushStepA(); - + uint32_t swapChainIndices[] = { uint32_t(m_currentSwapChainIndex) }; VkPresentInfoKHR presentInfo = {}; presentInfo.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR; presentInfo.swapchainCount = 1; - presentInfo.pSwapchains = &m_swapChain; + presentInfo.pSwapchains = &m_swapChain; presentInfo.pImageIndices = swapChainIndices; presentInfo.waitSemaphoreCount = 1; presentInfo.pWaitSemaphores = &endFrameSemaphore; @@ -408,9 +408,9 @@ void VulkanSwapChain::present(bool vsync) VkResult result = m_api->vkQueuePresentKHR(m_deviceQueue->getQueue(), &presentInfo); m_deviceQueue->makeCompleted(VulkanDeviceQueue::EventType::EndFrame); - + m_deviceQueue->flushStepB(); - + if (result != VK_SUCCESS || m_vsync != vsync) { m_vsync = vsync; diff --git a/tools/render-test/vk-swap-chain.h b/tools/slang-graphics/vk-swap-chain.h index 2c9fb588d..7c04af70c 100644 --- a/tools/render-test/vk-swap-chain.h +++ b/tools/slang-graphics/vk-swap-chain.h @@ -8,11 +8,11 @@ #include "../../source/core/list.h" -namespace renderer_test { +namespace slang_graphics { struct VulkanSwapChain { - /* enum + /* enum { kMaxImages = 8, }; */ @@ -31,7 +31,7 @@ struct VulkanSwapChain #else struct XPlatformDesc : public PlatformDesc { - Display* m_display; + Display* m_display; Window m_window; }; #endif @@ -67,7 +67,7 @@ struct VulkanSwapChain /// Create the frame buffers (they must be compatible with the supplied renderPass) SlangResult createFrameBuffers(VkRenderPass renderPass); - /// Returned the desc used to construct the swap chain. + /// Returned the desc used to construct the swap chain. /// Is invalid if init hasn't returned with successful result. const Desc& getDesc() const { return m_desc; } @@ -99,7 +99,7 @@ struct VulkanSwapChain protected: - + template <typename T> void _setPlatformDesc(const T& desc) { @@ -129,7 +129,7 @@ struct VulkanSwapChain int m_currentSwapChainIndex = 0; - Slang::List<Image> m_images; + Slang::List<Image> m_images; VulkanDeviceQueue* m_deviceQueue = nullptr; const VulkanApi* m_api = nullptr; diff --git a/tools/render-test/vk-util.cpp b/tools/slang-graphics/vk-util.cpp index 925001144..374a3876d 100644 --- a/tools/render-test/vk-util.cpp +++ b/tools/slang-graphics/vk-util.cpp @@ -4,7 +4,7 @@ #include <stdlib.h> #include <stdio.h> -namespace renderer_test { +namespace slang_graphics { /* static */VkFormat VulkanUtil::getVkFormat(Format format) { diff --git a/tools/render-test/vk-util.h b/tools/slang-graphics/vk-util.h index 2d98a1c0f..420c0a57a 100644 --- a/tools/render-test/vk-util.h +++ b/tools/slang-graphics/vk-util.h @@ -12,10 +12,10 @@ #define SLANG_VK_RETURN_NULL_ON_FAIL(x) { VkResult _res = x; if (_res != VK_SUCCESS) { VulkanUtil::handleFail(_res); return nullptr; } } -/// Is similar to SLANG_VK_RETURN_ON_FAIL, but does not return. Will call checkFail on failure - which asserts on debug builds. -#define SLANG_VK_CHECK(x) { VkResult _res = x; if (_res != VK_SUCCESS) { VulkanUtil::checkFail(_res); } } - -namespace renderer_test { +/// Is similar to SLANG_VK_RETURN_ON_FAIL, but does not return. Will call checkFail on failure - which asserts on debug builds. +#define SLANG_VK_CHECK(x) { VkResult _res = x; if (_res != VK_SUCCESS) { VulkanUtil::checkFail(_res); } } + +namespace slang_graphics { // Utility functions for Vulkan struct VulkanUtil @@ -24,17 +24,17 @@ struct VulkanUtil /// Returns VK_FORMAT_UNDEFINED if a match is not found static VkFormat getVkFormat(Format format); - /// Called by SLANG_VK_RETURN_FAIL if a res is a failure. + /// Called by SLANG_VK_RETURN_FAIL if a res is a failure. /// On debug builds this will cause an assertion on failure. static Slang::Result handleFail(VkResult res); /// Called when a failure has occurred with SLANG_VK_CHECK - will typically assert. static void checkFail(VkResult res); - /// Get the VkPrimitiveTopology for the given topology. + /// Get the VkPrimitiveTopology for the given topology. /// Returns VK_PRIMITIVE_TOPOLOGY_MAX_ENUM on failure static VkPrimitiveTopology getVkPrimitiveTopology(PrimitiveTopology topology); - /// Returns Slang::Result equivalent of a VkResult + /// Returns Slang::Result equivalent of a VkResult static Slang::Result toSlangResult(VkResult res); }; diff --git a/tools/slang-graphics/window.cpp b/tools/slang-graphics/window.cpp new file mode 100644 index 000000000..7aef88c12 --- /dev/null +++ b/tools/slang-graphics/window.cpp @@ -0,0 +1,245 @@ +// window.cpp +#include "window.h" +#pragma once + +#include <stdio.h> + +#ifdef _MSC_VER +#include <stddef.h> +#if (_MSC_VER < 1900) +#define snprintf sprintf_s +#endif +#endif + + +#if _WIN32 +#include <Windows.h> +#else +#error "The slang-graphics library currently only supports Windows platforms" +#endif + +namespace slang_graphics { + +#if _WIN32 + +struct OSString +{ + OSString(char const* begin, char const* end) + { + _initialize(begin, end - begin); + } + + OSString(char const* begin) + { + _initialize(begin, strlen(begin)); + } + + ~OSString() + { + free(mBegin); + } + + operator WCHAR const*() + { + return mBegin; + } + +private: + WCHAR* mBegin; + WCHAR* mEnd; + + void _initialize(char const* input, size_t inputSize) + { + const DWORD dwFlags = 0; + int outputCodeUnitCount = ::MultiByteToWideChar(CP_UTF8, dwFlags, input, int(inputSize), nullptr, 0); + + WCHAR* buffer = (WCHAR*)malloc(sizeof(WCHAR) * (outputCodeUnitCount + 1)); + + ::MultiByteToWideChar(CP_UTF8, dwFlags, input, int(inputSize), buffer, outputCodeUnitCount); + buffer[outputCodeUnitCount] = 0; + + mBegin = buffer; + mEnd = buffer + outputCodeUnitCount; + } +}; + +struct ApplicationContext +{ + HINSTANCE instance; + int showCommand = SW_SHOWDEFAULT; + int resultCode = 0; +}; + +/// Run an application given the specified callback and command-line arguments. +int runApplication( + ApplicationFunc func, + int argc, + char const* const* argv) +{ + ApplicationContext context; + context.instance = (HINSTANCE) GetModuleHandle(0); + func(&context); + return context.resultCode; +} + +int runWindowsApplication( + ApplicationFunc func, + void* instance, + int showCommand) +{ + ApplicationContext context; + context.instance = (HINSTANCE) instance; + context.showCommand = showCommand; + func(&context); + return context.resultCode; +} + +struct Window +{ + HWND handle; +}; + +static LRESULT CALLBACK windowProc( + HWND windowHandle, + UINT message, + WPARAM wParam, + LPARAM lParam) +{ + // TODO: Actually implement some reasonable logic here. + switch (message) + { + case WM_CLOSE: + PostQuitMessage(0); + return 0; + } + + return DefWindowProcW(windowHandle, message, wParam, lParam); +} + + +static ATOM createWindowClassAtom() +{ + WNDCLASSEXW windowClassDesc; + windowClassDesc.cbSize = sizeof(windowClassDesc); + windowClassDesc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW; + windowClassDesc.lpfnWndProc = &windowProc; + windowClassDesc.cbClsExtra = 0; + windowClassDesc.cbWndExtra = 0; + windowClassDesc.hInstance = (HINSTANCE) GetModuleHandle(0); + windowClassDesc.hIcon = 0; + windowClassDesc.hCursor = 0; + windowClassDesc.hbrBackground = 0; + windowClassDesc.lpszMenuName = 0; + windowClassDesc.lpszClassName = L"SlangGraphicsWindow"; + windowClassDesc.hIconSm = 0; + ATOM windowClassAtom = RegisterClassExW(&windowClassDesc); + return windowClassAtom; +} + +static ATOM getWindowClassAtom() +{ + static ATOM windowClassAtom = createWindowClassAtom(); + return windowClassAtom; +} + +Window* createWindow(WindowDesc const& desc) +{ + Window* window = new Window(); + + OSString windowTitle(desc.title); + + DWORD windowExtendedStyle = 0; + DWORD windowStyle = 0; + + HINSTANCE instance = (HINSTANCE) GetModuleHandle(0); + + HWND windowHandle = CreateWindowExW( + windowExtendedStyle, + (LPWSTR) getWindowClassAtom(), + windowTitle, + windowStyle, + 0, 0, // x, y + desc.width, desc.height, + NULL, // parent + NULL, // menu + instance, + window); + + if(!windowHandle) + { + delete window; + return nullptr; + } + + window->handle = windowHandle; + return window; +} + +void showWindow(Window* window) +{ + ShowWindow(window->handle, SW_SHOW); +} + +void* getPlatformWindowHandle(Window* window) +{ + return window->handle; +} + +bool dispatchEvents(ApplicationContext* context) +{ + for(;;) + { + MSG message; + + int result = PeekMessageW(&message, NULL, 0, 0, PM_REMOVE); + if (result != 0) + { + if (message.message == WM_QUIT) + { + context->resultCode = (int)message.wParam; + return false; + } + + TranslateMessage(&message); + DispatchMessageW(&message); + } + else + { + return true; + } + } + +} + +void exitApplication(ApplicationContext* context, int resultCode) +{ + ExitProcess(resultCode); +} + +int reportError(char const* message, ...) +{ + va_list args; + va_start(args, message); + + static const int kBufferSize = 1024; + char messageBuffer[kBufferSize]; + vsnprintf(messageBuffer, kBufferSize - 1, message, args); + messageBuffer[kBufferSize - 1] = 0; + + va_end(args); + + fputs(messageBuffer, stderr); + + OSString wideMessageBuffer(messageBuffer); + OutputDebugStringW(wideMessageBuffer); + + return 1; +} + +#else + +// TODO: put an SDL version here + +#endif + +} // slang_graphics diff --git a/tools/slang-graphics/window.h b/tools/slang-graphics/window.h new file mode 100644 index 000000000..91c8286d5 --- /dev/null +++ b/tools/slang-graphics/window.h @@ -0,0 +1,69 @@ +// window.h +#pragma once + +namespace slang_graphics { + +struct WindowDesc +{ + char const* title; + int width; + int height; +}; + +typedef struct Window Window; + +Window* createWindow(WindowDesc const& desc); +void showWindow(Window* window); +void* getPlatformWindowHandle(Window* window); + +/// Opaque state provided by platform for a running application. +typedef struct ApplicationContext ApplicationContext; + +/// User-defined application entry-point function. +typedef void(*ApplicationFunc)(ApplicationContext* context); + +/// Dispatch any pending events for application. +/// +/// @returns `true` if application should keep running. +bool dispatchEvents(ApplicationContext* context); + +/// Exit the application with a given result code +void exitApplication(ApplicationContext* context, int resultCode); + +/// Report an error to an appropriate logging destination. +int reportError(char const* message, ...); + +/// Run an application given the specified callback and command-line arguments. +int runApplication( + ApplicationFunc func, + int argc, + char const* const* argv); + +#define SG_CONSOLE_MAIN(APPLICATION_ENTRY) \ + int main(int argc, char** argv) { \ + return slang_graphics::runApplication(&(APPLIATION_ENTRY), argc, argv); \ + } + +#ifdef _WIN32 + +int runWindowsApplication( + ApplicationFunc func, + void* instance, + int showCommand); + +#define SG_UI_MAIN(APPLICATION_ENTRY) \ + int __stdcall WinMain( \ + void* instance, \ + void* /* prevInstance */, \ + void* /* commandLine */, \ + int showCommand) { \ + return slang_graphics::runWindowsApplication(&(APPLICATION_ENTRY), instance, showCommand); \ + } + +#else + +#define SG_UI_MAIN(APPLICATION_ENTRY) SG_CONSOLE_MAIN(APPLICATION_ENTRY) + +#endif + +} // slang_graphics |
