mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-09-22 21:55:52 +00:00
Add some helpers to make minimal templates for each autotest API
This commit is contained in:
@@ -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();
|
||||
@@ -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()
|
||||
|
||||
@@ -174,6 +174,11 @@ struct D3D11GraphicsTest : public GraphicsTest
|
||||
|
||||
DXGI_ADAPTER_DESC adapterDesc = {};
|
||||
|
||||
ID3D11VertexShaderPtr DefaultTriVS;
|
||||
ID3D11PixelShaderPtr DefaultTriPS;
|
||||
|
||||
ID3D11BufferPtr DefaultTriVB;
|
||||
|
||||
ID3D11VertexShaderPtr swapBlitVS;
|
||||
ID3D11PixelShaderPtr swapBlitPS;
|
||||
|
||||
|
||||
@@ -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();
|
||||
@@ -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<ID3D12GraphicsCommandListPtr> &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<ID3D12ResourcePtr> &rtvs,
|
||||
ID3D12ResourcePtr dsv)
|
||||
|
||||
@@ -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<ID3D12ResourcePtr> &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<ID3D12GraphicsCommandListPtr> &cmds);
|
||||
void GPUSync();
|
||||
void SubmitAndPresent(const std::vector<ID3D12GraphicsCommandListPtr> &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;
|
||||
|
||||
@@ -176,6 +176,7 @@
|
||||
<ClCompile Include="d3d11\d3d11_structured_buffer_nested.cpp" />
|
||||
<ClCompile Include="d3d11\d3d11_structured_buffer_read.cpp" />
|
||||
<ClCompile Include="d3d11\d3d11_swapchain_zoo.cpp" />
|
||||
<ClCompile Include="d3d11\d3d11_template.cpp" />
|
||||
<ClCompile Include="d3d11\d3d11_test.cpp" />
|
||||
<ClCompile Include="d3d11\d3d11_texture_3d.cpp" />
|
||||
<ClCompile Include="d3d11\d3d11_texture_zoo.cpp" />
|
||||
@@ -215,6 +216,7 @@
|
||||
<ClCompile Include="d3d12\d3d12_simple_dispatch.cpp" />
|
||||
<ClCompile Include="d3d12\d3d12_simple_triangle.cpp" />
|
||||
<ClCompile Include="d3d12\d3d12_swapchain_zoo.cpp" />
|
||||
<ClCompile Include="d3d12\d3d12_template.cpp" />
|
||||
<ClCompile Include="d3d12\d3d12_test.cpp" />
|
||||
<ClCompile Include="d3d12\d3d12_texture_zoo.cpp" />
|
||||
<ClCompile Include="d3d12\d3d12_untyped_backbuffer_descriptor.cpp" />
|
||||
@@ -269,6 +271,7 @@
|
||||
<ClCompile Include="gl\gl_spirv_shader.cpp" />
|
||||
<ClCompile Include="gl\gl_state_trashing.cpp" />
|
||||
<ClCompile Include="gl\gl_structured_buffer_nested.cpp" />
|
||||
<ClCompile Include="gl\gl_template.cpp" />
|
||||
<ClCompile Include="gl\gl_test.cpp" />
|
||||
<ClCompile Include="gl\gl_test_linux.cpp">
|
||||
<ExcludedFromBuild>true</ExcludedFromBuild>
|
||||
@@ -331,6 +334,7 @@
|
||||
<ClCompile Include="vk\vk_spec_constants.cpp" />
|
||||
<ClCompile Include="vk\vk_spirv_13_shaders.cpp" />
|
||||
<ClCompile Include="vk\vk_sync2.cpp" />
|
||||
<ClCompile Include="vk\vk_template.cpp" />
|
||||
<ClCompile Include="vk\vk_texture_zoo.cpp" />
|
||||
<ClCompile Include="vk\vk_triangle_fan.cpp" />
|
||||
<ClCompile Include="vk\vk_buffer_truncation.cpp" />
|
||||
|
||||
@@ -661,6 +661,18 @@
|
||||
<ClCompile Include="gl\gl_test_android.cpp">
|
||||
<Filter>OpenGL</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="gl\gl_template.cpp">
|
||||
<Filter>OpenGL\demos</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="vk\vk_template.cpp">
|
||||
<Filter>Vulkan\demos</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="d3d11\d3d11_template.cpp">
|
||||
<Filter>D3D11\demos</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="d3d12\d3d12_template.cpp">
|
||||
<Filter>D3D12\demos</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Filter Include="D3D11">
|
||||
|
||||
@@ -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();
|
||||
@@ -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()
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
#include <assert.h>
|
||||
#include <algorithm>
|
||||
#include "../test_common.h"
|
||||
#include "vk_headers.h"
|
||||
|
||||
#include "vk_helpers.h"
|
||||
@@ -78,6 +79,22 @@ VkFormat _FormatFromObj<float>()
|
||||
return VK_FORMAT_R32_SFLOAT;
|
||||
}
|
||||
|
||||
template <>
|
||||
VkFormat _FormatFromObj<Vec4f>()
|
||||
{
|
||||
return VK_FORMAT_R32G32B32A32_SFLOAT;
|
||||
}
|
||||
template <>
|
||||
VkFormat _FormatFromObj<Vec3f>()
|
||||
{
|
||||
return VK_FORMAT_R32G32B32_SFLOAT;
|
||||
}
|
||||
template <>
|
||||
VkFormat _FormatFromObj<Vec2f>()
|
||||
{
|
||||
return VK_FORMAT_R32G32_SFLOAT;
|
||||
}
|
||||
|
||||
void updateDescriptorSets(VkDevice device, const std::vector<VkWriteDescriptorSet> &writes,
|
||||
const std::vector<VkCopyDescriptorSet> &copies)
|
||||
{
|
||||
@@ -105,6 +122,17 @@ void cmdPipelineBarrier(VkCommandBuffer cmd, const std::vector<VkImageMemoryBarr
|
||||
img.data());
|
||||
}
|
||||
|
||||
void cmdClearImage(VkCommandBuffer cmd, VkImage img, const ClearColorValue &col, VkImageLayout layout)
|
||||
{
|
||||
vkCmdClearColorImage(cmd, img, layout, col, 1, vkh::ImageSubresourceRange());
|
||||
}
|
||||
|
||||
void cmdClearImage(VkCommandBuffer cmd, VkImage img, const ClearDepthStencilValue &ds,
|
||||
VkImageLayout layout)
|
||||
{
|
||||
vkCmdClearDepthStencilImage(cmd, img, layout, ds, 1, vkh::ImageSubresourceRange());
|
||||
}
|
||||
|
||||
void cmdBindVertexBuffers(VkCommandBuffer cmd, uint32_t firstBinding,
|
||||
std::initializer_list<VkBuffer> bufs,
|
||||
std::initializer_list<VkDeviceSize> offsets)
|
||||
@@ -113,6 +141,13 @@ void cmdBindVertexBuffers(VkCommandBuffer cmd, uint32_t firstBinding,
|
||||
&(*offsets.begin()));
|
||||
}
|
||||
|
||||
void cmdBindVertexBuffers(VkCommandBuffer cmd, std::initializer_list<VkBuffer> 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<VkDescriptorSet> sets, std::vector<uint32_t> dynamicOffsets)
|
||||
|
||||
@@ -158,9 +158,18 @@ void cmdPipelineBarrier(VkCommandBuffer cmd, const std::vector<VkImageMemoryBarr
|
||||
VkPipelineStageFlags dstStageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
|
||||
VkDependencyFlags dependencyFlags = 0);
|
||||
|
||||
struct ClearColorValue;
|
||||
struct ClearDepthStencilValue;
|
||||
void cmdClearImage(VkCommandBuffer cmd, VkImage img, const ClearColorValue &col,
|
||||
VkImageLayout layout = VK_IMAGE_LAYOUT_GENERAL);
|
||||
void cmdClearImage(VkCommandBuffer cmd, VkImage img, const ClearDepthStencilValue &ds,
|
||||
VkImageLayout layout = VK_IMAGE_LAYOUT_GENERAL);
|
||||
|
||||
void cmdBindVertexBuffers(VkCommandBuffer cmd, uint32_t firstBinding,
|
||||
std::initializer_list<VkBuffer> bufs,
|
||||
std::initializer_list<VkDeviceSize> offsets);
|
||||
std::initializer_list<VkDeviceSize> offsets = {});
|
||||
|
||||
void cmdBindVertexBuffers(VkCommandBuffer cmd, std::initializer_list<VkBuffer> bufs);
|
||||
|
||||
void cmdBindDescriptorSets(VkCommandBuffer cmd, VkPipelineBindPoint pipelineBindPoint,
|
||||
VkPipelineLayout layout, uint32_t firstSet,
|
||||
|
||||
@@ -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();
|
||||
@@ -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::vector<V
|
||||
headlessCmds->Submit(cmds, seccmds, queue, VK_NULL_HANDLE, VK_NULL_HANDLE);
|
||||
}
|
||||
|
||||
void VulkanGraphicsTest::SubmitAndPresent(const std::vector<VkCommandBuffer> &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<std::mutex> 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<Vec4f>()
|
||||
{
|
||||
return VK_FORMAT_R32G32B32A32_SFLOAT;
|
||||
}
|
||||
template <>
|
||||
VkFormat vkh::_FormatFromObj<Vec3f>()
|
||||
{
|
||||
return VK_FORMAT_R32G32B32_SFLOAT;
|
||||
}
|
||||
template <>
|
||||
VkFormat vkh::_FormatFromObj<Vec2f>()
|
||||
{
|
||||
return VK_FORMAT_R32G32_SFLOAT;
|
||||
}
|
||||
|
||||
AllocatedImage::AllocatedImage(VulkanGraphicsTest *test, const VkImageCreateInfo &imgInfo,
|
||||
const VmaAllocationCreateInfo &allocInfo)
|
||||
{
|
||||
|
||||
@@ -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<VkCommandBuffer> &cmds,
|
||||
const std::vector<VkCommandBuffer> &seccmds = {});
|
||||
void SubmitAndPresent(const std::vector<VkCommandBuffer> &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;
|
||||
|
||||
Reference in New Issue
Block a user