diff --git a/util/test/demos/d3d11/d3d11_template.cpp b/util/test/demos/d3d11/d3d11_template.cpp new file mode 100644 index 000000000..6b5801de6 --- /dev/null +++ b/util/test/demos/d3d11/d3d11_template.cpp @@ -0,0 +1,61 @@ +/****************************************************************************** + * The MIT License (MIT) + * + * Copyright (c) 2019-2023 Baldur Karlsson + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + ******************************************************************************/ + +#include "d3d11_test.h" + +RD_TEST(D3D11_Template, D3D11GraphicsTest) +{ + static constexpr const char *Description = "Blank test template to be copied & modified."; + + int main() + { + // initialise, create window, create device, etc + if(!Init()) + return 3; + + while(Running()) + { + ClearRenderTargetView(bbRTV, {0.2f, 0.2f, 0.2f, 1.0f}); + + IASetVertexBuffer(DefaultTriVB, sizeof(DefaultA2V), 0); + ctx->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); + ctx->IASetInputLayout(defaultLayout); + + ctx->VSSetShader(DefaultTriVS, NULL, 0); + ctx->PSSetShader(DefaultTriPS, NULL, 0); + + RSSetViewport({0.0f, 0.0f, (float)screenWidth, (float)screenHeight, 0.0f, 1.0f}); + + ctx->OMSetRenderTargets(1, &bbRTV.GetInterfacePtr(), NULL); + + ctx->Draw(3, 0); + + Present(); + } + + return 0; + } +}; + +REGISTER_TEST(); diff --git a/util/test/demos/d3d11/d3d11_test.cpp b/util/test/demos/d3d11/d3d11_test.cpp index 67fa22fea..1d64125ad 100644 --- a/util/test/demos/d3d11/d3d11_test.cpp +++ b/util/test/demos/d3d11/d3d11_test.cpp @@ -339,6 +339,16 @@ float4 main(float4 pos : SV_Position) : SV_Target0 swapBlitVS = CreateVS(Compile(D3DFullscreenQuadVertex, "main", "vs_4_0")); swapBlitPS = CreatePS(Compile(blitPixel, "main", "ps_5_0")); } + + ID3DBlobPtr vsblob = Compile(D3DDefaultVertex, "main", "vs_4_0"); + ID3DBlobPtr psblob = Compile(D3DDefaultPixel, "main", "ps_4_0"); + + CreateDefaultInputLayout(vsblob); + + DefaultTriVS = CreateVS(vsblob); + DefaultTriPS = CreatePS(psblob); + + DefaultTriVB = MakeBuffer().Vertex().Data(DefaultTri); } void D3D11GraphicsTest::Shutdown() diff --git a/util/test/demos/d3d11/d3d11_test.h b/util/test/demos/d3d11/d3d11_test.h index 8f0f48c1e..ee864583a 100644 --- a/util/test/demos/d3d11/d3d11_test.h +++ b/util/test/demos/d3d11/d3d11_test.h @@ -174,6 +174,11 @@ struct D3D11GraphicsTest : public GraphicsTest DXGI_ADAPTER_DESC adapterDesc = {}; + ID3D11VertexShaderPtr DefaultTriVS; + ID3D11PixelShaderPtr DefaultTriPS; + + ID3D11BufferPtr DefaultTriVB; + ID3D11VertexShaderPtr swapBlitVS; ID3D11PixelShaderPtr swapBlitPS; diff --git a/util/test/demos/d3d12/d3d12_template.cpp b/util/test/demos/d3d12/d3d12_template.cpp new file mode 100644 index 000000000..3c76cb110 --- /dev/null +++ b/util/test/demos/d3d12/d3d12_template.cpp @@ -0,0 +1,70 @@ +/****************************************************************************** + * The MIT License (MIT) + * + * Copyright (c) 2019-2023 Baldur Karlsson + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + ******************************************************************************/ + +#include "d3d12_test.h" + +RD_TEST(D3D12_Template, D3D12GraphicsTest) +{ + static constexpr const char *Description = "Blank test template to be copied & modified."; + + int main() + { + // initialise, create window, create device, etc + if(!Init()) + return 3; + + while(Running()) + { + ID3D12GraphicsCommandListPtr cmd = GetCommandBuffer(); + + Reset(cmd); + + ID3D12ResourcePtr bb = StartUsingBackbuffer(cmd, D3D12_RESOURCE_STATE_RENDER_TARGET); + + ClearRenderTargetView(cmd, BBRTV, {0.2f, 0.2f, 0.2f, 1.0f}); + + cmd->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST); + + IASetVertexBuffer(cmd, DefaultTriVB, sizeof(DefaultA2V), 0); + cmd->SetPipelineState(DefaultTriPSO); + cmd->SetGraphicsRootSignature(DefaultTriSig); + + SetMainWindowViewScissor(cmd); + + OMSetRenderTargets(cmd, {BBRTV}, {}); + + cmd->DrawInstanced(3, 1, 0, 0); + + FinishUsingBackbuffer(cmd, D3D12_RESOURCE_STATE_RENDER_TARGET); + + cmd->Close(); + + SubmitAndPresent({cmd}); + } + + return 0; + } +}; + +REGISTER_TEST(); diff --git a/util/test/demos/d3d12/d3d12_test.cpp b/util/test/demos/d3d12/d3d12_test.cpp index decf019c8..733f0cb04 100644 --- a/util/test/demos/d3d12/d3d12_test.cpp +++ b/util/test/demos/d3d12/d3d12_test.cpp @@ -459,6 +459,20 @@ void D3D12GraphicsTest::PostDeviceCreate() infoqueue->AddStorageFilterEntries(&filter); } + + { + ID3DBlobPtr vsblob = Compile(D3DDefaultVertex, "main", "vs_4_0"); + ID3DBlobPtr psblob = Compile(D3DDefaultPixel, "main", "ps_4_0"); + + DefaultTriVB = MakeBuffer().Data(DefaultTri); + + DefaultTriSig = MakeSig({}); + + DefaultTriPSO = MakePSO().RootSig(DefaultTriSig).InputLayout().VS(vsblob).PS(psblob); + + ResourceBarrier(DefaultTriVB, D3D12_RESOURCE_STATE_COMMON, + D3D12_RESOURCE_STATE_VERTEX_AND_CONSTANT_BUFFER); + } } HRESULT D3D12GraphicsTest::EnumAdapterByLuid(LUID luid, IDXGIAdapterPtr &pAdapter) @@ -584,6 +598,8 @@ ID3D12ResourcePtr D3D12GraphicsTest::StartUsingBackbuffer(ID3D12GraphicsCommandL if(useState != D3D12_RESOURCE_STATE_PRESENT) ResourceBarrier(cmd, bbTex[texIdx], D3D12_RESOURCE_STATE_PRESENT, useState); + BBRTV = MakeRTV(bb).Format(DXGI_FORMAT_R8G8B8A8_UNORM_SRGB).CreateCPU(31); + return bbTex[texIdx]; } @@ -623,6 +639,12 @@ void D3D12GraphicsTest::GPUSync() WaitForSingleObject(m_GPUSyncHandle, 10000); } +void D3D12GraphicsTest::SubmitAndPresent(const std::vector &cmds) +{ + Submit(cmds); + Present(); +} + void D3D12GraphicsTest::Present() { if(swap) @@ -1114,6 +1136,12 @@ void D3D12GraphicsTest::RSSetScissorRect(ID3D12GraphicsCommandListPtr cmd, D3D12 cmd->RSSetScissorRects(1, &rect); } +void D3D12GraphicsTest::SetMainWindowViewScissor(ID3D12GraphicsCommandListPtr cmd) +{ + RSSetViewport(cmd, {0.0f, 0.0f, (float)screenWidth, (float)screenHeight, 0.0f, 1.0f}); + RSSetScissorRect(cmd, {0, 0, screenWidth, screenHeight}); +} + void D3D12GraphicsTest::OMSetRenderTargets(ID3D12GraphicsCommandListPtr cmd, const std::vector &rtvs, ID3D12ResourcePtr dsv) diff --git a/util/test/demos/d3d12/d3d12_test.h b/util/test/demos/d3d12/d3d12_test.h index cacccdf3c..58ad4206e 100644 --- a/util/test/demos/d3d12/d3d12_test.h +++ b/util/test/demos/d3d12/d3d12_test.h @@ -174,6 +174,8 @@ struct D3D12GraphicsTest : public GraphicsTest void RSSetViewport(ID3D12GraphicsCommandListPtr cmd, D3D12_VIEWPORT view); void RSSetScissorRect(ID3D12GraphicsCommandListPtr cmd, D3D12_RECT rect); + void SetMainWindowViewScissor(ID3D12GraphicsCommandListPtr cmd); + void OMSetRenderTargets(ID3D12GraphicsCommandListPtr cmd, const std::vector &rtvs, ID3D12ResourcePtr dsv); void OMSetRenderTargets(ID3D12GraphicsCommandListPtr cmd, @@ -186,6 +188,7 @@ struct D3D12GraphicsTest : public GraphicsTest void FinishUsingBackbuffer(ID3D12GraphicsCommandListPtr cmd, D3D12_RESOURCE_STATES usedState); void Submit(const std::vector &cmds); void GPUSync(); + void SubmitAndPresent(const std::vector &cmds); void Present(); DXGI_FORMAT backbufferFmt = DXGI_FORMAT_R8G8B8A8_UNORM; @@ -199,10 +202,15 @@ struct D3D12GraphicsTest : public GraphicsTest ID3D12ResourcePtr bbTex[2]; uint32_t texIdx = 0; + D3D12_CPU_DESCRIPTOR_HANDLE BBRTV; ID3D12RootSignaturePtr swapBlitSig; ID3D12PipelineStatePtr swapBlitPso; + ID3D12ResourcePtr DefaultTriVB; + ID3D12RootSignaturePtr DefaultTriSig; + ID3D12PipelineStatePtr DefaultTriPSO; + D3D_FEATURE_LEVEL minFeatureLevel = D3D_FEATURE_LEVEL_11_0; bool gpuva = false, m_12On7 = false, m_DXILSupport = false; diff --git a/util/test/demos/demos.vcxproj b/util/test/demos/demos.vcxproj index a56041868..19b54ca8f 100644 --- a/util/test/demos/demos.vcxproj +++ b/util/test/demos/demos.vcxproj @@ -176,6 +176,7 @@ + @@ -215,6 +216,7 @@ + @@ -269,6 +271,7 @@ + true @@ -331,6 +334,7 @@ + diff --git a/util/test/demos/demos.vcxproj.filters b/util/test/demos/demos.vcxproj.filters index b482be2d8..d3cc6524c 100644 --- a/util/test/demos/demos.vcxproj.filters +++ b/util/test/demos/demos.vcxproj.filters @@ -661,6 +661,18 @@ OpenGL + + OpenGL\demos + + + Vulkan\demos + + + D3D11\demos + + + D3D12\demos + diff --git a/util/test/demos/gl/gl_template.cpp b/util/test/demos/gl/gl_template.cpp new file mode 100644 index 000000000..fdd0260f9 --- /dev/null +++ b/util/test/demos/gl/gl_template.cpp @@ -0,0 +1,53 @@ +/****************************************************************************** + * The MIT License (MIT) + * + * Copyright (c) 2019-2023 Baldur Karlsson + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + ******************************************************************************/ + +#include "gl_test.h" + +RD_TEST(GL_Template, OpenGLGraphicsTest) +{ + static constexpr const char *Description = "Blank test template to be copied & modified."; + + int main() + { + // initialise, create window, create context, etc + if(!Init()) + return 3; + + while(Running()) + { + glClearBufferfv(GL_COLOR, 0, DefaultClearCol); + + glBindVertexArray(DefaultTriVAO); + glUseProgram(DefaultTriProgram); + glViewport(0, 0, GLsizei(screenWidth), GLsizei(screenHeight)); + glDrawArrays(GL_TRIANGLES, 0, 3); + + Present(); + } + + return 0; + } +}; + +REGISTER_TEST(); diff --git a/util/test/demos/gl/gl_test.cpp b/util/test/demos/gl/gl_test.cpp index d648a9ab1..6a304417d 100644 --- a/util/test/demos/gl/gl_test.cpp +++ b/util/test/demos/gl/gl_test.cpp @@ -104,6 +104,16 @@ void OpenGLGraphicsTest::PostInit() glGetString(GL_VERSION)); swapBlitFBO = MakeFBO(); + + DefaultTriVB = MakeBuffer(); + glBindBuffer(GL_ARRAY_BUFFER, DefaultTriVB); + glBufferData(GL_ARRAY_BUFFER, sizeof(DefaultTri), DefaultTri, GL_STATIC_DRAW); + + DefaultTriVAO = MakeVAO(); + glBindVertexArray(DefaultTriVAO); + ConfigureDefaultVAO(); + + DefaultTriProgram = MakeProgram(GLDefaultVertex, GLDefaultPixel); } void OpenGLGraphicsTest::Shutdown() diff --git a/util/test/demos/gl/gl_test.h b/util/test/demos/gl/gl_test.h index 391891358..7014f2360 100644 --- a/util/test/demos/gl/gl_test.h +++ b/util/test/demos/gl/gl_test.h @@ -71,8 +71,13 @@ struct OpenGLGraphicsTest : public GraphicsTest bool vsync = false; + GLuint DefaultTriVAO; + GLuint DefaultTriVB; + GLuint DefaultTriProgram; GLuint swapBlitFBO; + static constexpr GLfloat DefaultClearCol[] = {0.2f, 0.2f, 0.2f, 1.0f}; + GraphicsWindow *mainWindow = NULL; void *mainContext = NULL; bool inited = false; diff --git a/util/test/demos/vk/vk_helpers.cpp b/util/test/demos/vk/vk_helpers.cpp index 1da3afe58..8186afde1 100644 --- a/util/test/demos/vk/vk_helpers.cpp +++ b/util/test/demos/vk/vk_helpers.cpp @@ -24,6 +24,7 @@ #include #include +#include "../test_common.h" #include "vk_headers.h" #include "vk_helpers.h" @@ -78,6 +79,22 @@ VkFormat _FormatFromObj() return VK_FORMAT_R32_SFLOAT; } +template <> +VkFormat _FormatFromObj() +{ + return VK_FORMAT_R32G32B32A32_SFLOAT; +} +template <> +VkFormat _FormatFromObj() +{ + return VK_FORMAT_R32G32B32_SFLOAT; +} +template <> +VkFormat _FormatFromObj() +{ + return VK_FORMAT_R32G32_SFLOAT; +} + void updateDescriptorSets(VkDevice device, const std::vector &writes, const std::vector &copies) { @@ -105,6 +122,17 @@ void cmdPipelineBarrier(VkCommandBuffer cmd, const std::vector bufs, std::initializer_list offsets) @@ -113,6 +141,13 @@ void cmdBindVertexBuffers(VkCommandBuffer cmd, uint32_t firstBinding, &(*offsets.begin())); } +void cmdBindVertexBuffers(VkCommandBuffer cmd, std::initializer_list bufs) +{ + VkDeviceSize offsets[32] = {}; + TEST_ASSERT(bufs.size() < 32, "More than 32 VBs being bound"); + vkCmdBindVertexBuffers(cmd, 0, (uint32_t)bufs.size(), &(*bufs.begin()), offsets); +} + void cmdBindDescriptorSets(VkCommandBuffer cmd, VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout, uint32_t firstSet, std::vector sets, std::vector dynamicOffsets) diff --git a/util/test/demos/vk/vk_helpers.h b/util/test/demos/vk/vk_helpers.h index 4f622a0a7..3edde9c96 100644 --- a/util/test/demos/vk/vk_helpers.h +++ b/util/test/demos/vk/vk_helpers.h @@ -158,9 +158,18 @@ void cmdPipelineBarrier(VkCommandBuffer cmd, const std::vector bufs, - std::initializer_list offsets); + std::initializer_list offsets = {}); + +void cmdBindVertexBuffers(VkCommandBuffer cmd, std::initializer_list bufs); void cmdBindDescriptorSets(VkCommandBuffer cmd, VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout, uint32_t firstSet, diff --git a/util/test/demos/vk/vk_template.cpp b/util/test/demos/vk/vk_template.cpp new file mode 100644 index 000000000..e73197d39 --- /dev/null +++ b/util/test/demos/vk/vk_template.cpp @@ -0,0 +1,67 @@ +/****************************************************************************** + * The MIT License (MIT) + * + * Copyright (c) 2019-2023 Baldur Karlsson + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + ******************************************************************************/ + +#include "vk_test.h" + +RD_TEST(VK_Template, VulkanGraphicsTest) +{ + static constexpr const char *Description = "Blank test template to be copied & modified."; + + int main() + { + // initialise, create window, create context, etc + if(!Init()) + return 3; + + while(Running()) + { + VkCommandBuffer cmd = GetCommandBuffer(); + + vkBeginCommandBuffer(cmd, vkh::CommandBufferBeginInfo()); + + VkImage swapimg = StartUsingBackbuffer(cmd); + + vkh::cmdClearImage(cmd, swapimg, vkh::ClearColorValue(0.2f, 0.2f, 0.2f, 1.0f)); + + vkCmdBeginRenderPass(cmd, mainWindow->beginRP(), VK_SUBPASS_CONTENTS_INLINE); + + vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, DefaultTriPipe); + mainWindow->setViewScissor(cmd); + vkh::cmdBindVertexBuffers(cmd, {DefaultTriVB.buffer}); + vkCmdDraw(cmd, 3, 1, 0, 0); + + vkCmdEndRenderPass(cmd); + + FinishUsingBackbuffer(cmd); + + vkEndCommandBuffer(cmd); + + SubmitAndPresent({cmd}); + } + + return 0; + } +}; + +REGISTER_TEST(); diff --git a/util/test/demos/vk/vk_test.cpp b/util/test/demos/vk/vk_test.cpp index 7d83e8f60..3bffc6351 100644 --- a/util/test/demos/vk/vk_test.cpp +++ b/util/test/demos/vk/vk_test.cpp @@ -751,6 +751,35 @@ bool VulkanGraphicsTest::Init() headlessCmds = new VulkanCommands(this); + { + VkPipelineLayout layout = createPipelineLayout(vkh::PipelineLayoutCreateInfo()); + + vkh::GraphicsPipelineCreateInfo pipeCreateInfo; + + pipeCreateInfo.layout = layout; + pipeCreateInfo.renderPass = mainWindow->rp; + + pipeCreateInfo.vertexInputState.vertexBindingDescriptions = {vkh::vertexBind(0, DefaultA2V)}; + pipeCreateInfo.vertexInputState.vertexAttributeDescriptions = { + vkh::vertexAttr(0, 0, DefaultA2V, pos), vkh::vertexAttr(1, 0, DefaultA2V, col), + vkh::vertexAttr(2, 0, DefaultA2V, uv), + }; + + pipeCreateInfo.stages = { + CompileShaderModule(VKDefaultVertex, ShaderLang::glsl, ShaderStage::vert, "main"), + CompileShaderModule(VKDefaultPixel, ShaderLang::glsl, ShaderStage::frag, "main"), + }; + + DefaultTriPipe = createGraphicsPipeline(pipeCreateInfo); + + DefaultTriVB = AllocatedBuffer( + this, vkh::BufferCreateInfo(sizeof(DefaultTri), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | + VK_BUFFER_USAGE_TRANSFER_DST_BIT), + VmaAllocationCreateInfo({0, VMA_MEMORY_USAGE_CPU_TO_GPU})); + + DefaultTriVB.upload(DefaultTri); + } + return true; } @@ -877,6 +906,12 @@ void VulkanGraphicsTest::Submit(int index, int totalSubmits, const std::vectorSubmit(cmds, seccmds, queue, VK_NULL_HANDLE, VK_NULL_HANDLE); } +void VulkanGraphicsTest::SubmitAndPresent(const std::vector &cmds) +{ + Submit(0, 1, cmds, {}); + Present(); +} + void VulkanGraphicsTest::Present() { mainWindow->Present(queue); @@ -1393,6 +1428,12 @@ VulkanWindow::~VulkanWindow() delete m_Win; } +void VulkanWindow::setViewScissor(VkCommandBuffer cmd) +{ + vkCmdSetViewport(cmd, 0, 1, &viewport); + vkCmdSetScissor(cmd, 0, 1, &scissor); +} + bool VulkanWindow::CreateSwapchain() { std::lock_guard lock(m_Test->mutex); @@ -1674,22 +1715,6 @@ bool VulkanGraphicsTest::hasExt(const char *ext) [ext](const char *a) { return !strcmp(a, ext); }) != devExts.end(); } -template <> -VkFormat vkh::_FormatFromObj() -{ - return VK_FORMAT_R32G32B32A32_SFLOAT; -} -template <> -VkFormat vkh::_FormatFromObj() -{ - return VK_FORMAT_R32G32B32_SFLOAT; -} -template <> -VkFormat vkh::_FormatFromObj() -{ - return VK_FORMAT_R32G32_SFLOAT; -} - AllocatedImage::AllocatedImage(VulkanGraphicsTest *test, const VkImageCreateInfo &imgInfo, const VmaAllocationCreateInfo &allocInfo) { diff --git a/util/test/demos/vk/vk_test.h b/util/test/demos/vk/vk_test.h index 39202435f..e5fbc815b 100644 --- a/util/test/demos/vk/vk_test.h +++ b/util/test/demos/vk/vk_test.h @@ -139,6 +139,9 @@ struct VulkanWindow : public GraphicsWindow, public VulkanCommands virtual ~VulkanWindow(); void Shutdown(); + vkh::RenderPassBeginInfo beginRP() { return vkh::RenderPassBeginInfo(rp, GetFB(), scissor); } + void setViewScissor(VkCommandBuffer cmd); + size_t GetCount() { return imgs.size(); } VkImage GetImage(size_t idx = ~0U) { @@ -197,12 +200,19 @@ struct VulkanGraphicsTest : public GraphicsTest VulkanWindow *MakeWindow(int width, int height, const char *title); bool Running(); - VkImage StartUsingBackbuffer(VkCommandBuffer cmd, VkAccessFlags nextUse, VkImageLayout layout, + VkImage StartUsingBackbuffer(VkCommandBuffer cmd, + VkAccessFlags nextUse = VK_ACCESS_TRANSFER_WRITE_BIT | + VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, + VkImageLayout layout = VK_IMAGE_LAYOUT_GENERAL, VulkanWindow *window = NULL); - void FinishUsingBackbuffer(VkCommandBuffer cmd, VkAccessFlags prevUse, VkImageLayout layout, + void FinishUsingBackbuffer(VkCommandBuffer cmd, + VkAccessFlags prevUse = VK_ACCESS_TRANSFER_WRITE_BIT | + VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, + VkImageLayout layout = VK_IMAGE_LAYOUT_GENERAL, VulkanWindow *window = NULL); void Submit(int index, int totalSubmits, const std::vector &cmds, const std::vector &seccmds = {}); + void SubmitAndPresent(const std::vector &cmds); void Present(); VkPipelineShaderStageCreateInfo CompileShaderModule( @@ -314,6 +324,9 @@ struct VulkanGraphicsTest : public GraphicsTest VulkanCommands *headlessCmds = NULL; + VkPipeline DefaultTriPipe; + AllocatedBuffer DefaultTriVB; + // VMA bool vmaDedicated = false; VmaAllocator allocator = VK_NULL_HANDLE;