diff --git a/util/test/demos/CMakeLists.txt b/util/test/demos/CMakeLists.txt index dab92749d..965bedb68 100644 --- a/util/test/demos/CMakeLists.txt +++ b/util/test/demos/CMakeLists.txt @@ -18,6 +18,7 @@ set(VULKAN_SRC vk/vk_int8_ibuffer.cpp vk/vk_khr_buffer_address.cpp vk/vk_line_raster.cpp + vk/vk_mesh_zoo.cpp vk/vk_misaligned_dirty.cpp vk/vk_multi_thread_windows.cpp vk/vk_overlay_test.cpp @@ -50,6 +51,7 @@ set(OPENGL_SRC gl/gl_entry_points.cpp gl/gl_large_bcn_arrays.cpp gl/gl_map_overrun.cpp + gl/gl_mesh_zoo.cpp gl/gl_midframe_context_create.cpp gl/gl_mip_gen_rt.cpp gl/gl_multi_window.cpp diff --git a/util/test/demos/d3d11/d3d11_mesh_zoo.cpp b/util/test/demos/d3d11/d3d11_mesh_zoo.cpp new file mode 100644 index 000000000..72d112af6 --- /dev/null +++ b/util/test/demos/d3d11/d3d11_mesh_zoo.cpp @@ -0,0 +1,189 @@ +/****************************************************************************** + * The MIT License (MIT) + * + * Copyright (c) 2019-2020 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_Mesh_Zoo, D3D11GraphicsTest) +{ + static constexpr const char *Description = "Draws some primitives for testing the mesh view."; + + std::string vertex = R"EOSHADER( + +struct vertin +{ + float3 pos : POSITION; + float4 col : COLOR0; +}; + +struct v2f +{ + float4 pos : SV_POSITION; + float4 col : COLOR0; +}; + +cbuffer consts : register(b0) +{ + float4 scale; + float4 offset; +}; + +v2f main(vertin IN, uint vid : SV_VertexID, uint inst : SV_InstanceID) +{ + v2f OUT = (v2f)0; + + OUT.pos = float4(IN.pos.xy * scale.xy + offset.xy, IN.pos.z, 1.0f); + OUT.col = IN.col; + + if(inst > 0) + { + OUT.pos *= 0.3f; + OUT.pos.xy += 0.1f; + OUT.col.z = 1.0f; + } + + return OUT; +} + +)EOSHADER"; + + std::string pixel = R"EOSHADER( + +struct v2f +{ + float4 pos : SV_POSITION; + float4 col : COLOR0; +}; + +float4 main(v2f IN) : SV_Target0 +{ + return IN.col; +} + +)EOSHADER"; + + int main() + { + // initialise, create window, create device, etc + if(!Init()) + return 3; + + ID3DBlobPtr vsblob = Compile(vertex, "main", "vs_4_0"); + ID3DBlobPtr psblob = Compile(pixel, "main", "ps_4_0"); + + CreateDefaultInputLayout(vsblob); + + ID3D11VertexShaderPtr vs = CreateVS(vsblob); + ID3D11PixelShaderPtr ps = CreatePS(psblob); + + const DefaultA2V test[] = { + // single color quad + {Vec3f(50.0f, 250.0f, 0.2f), Vec4f(0.0f, 1.0f, 0.0f, 1.0f), Vec2f(0.0f, 0.0f)}, + {Vec3f(250.0f, 250.0f, 0.2f), Vec4f(0.0f, 1.0f, 0.0f, 1.0f), Vec2f(0.0f, 0.0f)}, + {Vec3f(50.0f, 50.0f, 0.2f), Vec4f(0.0f, 1.0f, 0.0f, 1.0f), Vec2f(0.0f, 0.0f)}, + + {Vec3f(250.0f, 250.0f, 0.2f), Vec4f(0.0f, 1.0f, 0.0f, 1.0f), Vec2f(0.0f, 0.0f)}, + {Vec3f(250.0f, 50.0f, 0.2f), Vec4f(0.0f, 1.0f, 0.0f, 1.0f), Vec2f(0.0f, 0.0f)}, + {Vec3f(50.0f, 50.0f, 0.2f), Vec4f(0.0f, 1.0f, 0.0f, 1.0f), Vec2f(0.0f, 0.0f)}, + + // points, to test vertex picking + {Vec3f(50.0f, 250.0f, 0.2f), Vec4f(0.0f, 1.0f, 0.0f, 1.0f), Vec2f(0.0f, 0.0f)}, + {Vec3f(250.0f, 250.0f, 0.2f), Vec4f(0.0f, 1.0f, 0.0f, 1.0f), Vec2f(0.0f, 0.0f)}, + {Vec3f(250.0f, 50.0f, 0.2f), Vec4f(0.0f, 1.0f, 0.0f, 1.0f), Vec2f(0.0f, 0.0f)}, + {Vec3f(50.0f, 50.0f, 0.2f), Vec4f(0.0f, 1.0f, 0.0f, 1.0f), Vec2f(0.0f, 0.0f)}, + + {Vec3f(70.0f, 170.0f, 0.1f), Vec4f(1.0f, 0.0f, 1.0f, 1.0f), Vec2f(0.0f, 0.0f)}, + {Vec3f(170.0f, 170.0f, 0.1f), Vec4f(1.0f, 0.0f, 1.0f, 1.0f), Vec2f(0.0f, 0.0f)}, + {Vec3f(70.0f, 70.0f, 0.1f), Vec4f(1.0f, 0.0f, 1.0f, 1.0f), Vec2f(0.0f, 0.0f)}, + }; + + ID3D11BufferPtr vb = MakeBuffer().Vertex().Data(test); + + Vec4f cbufferdata[] = { + Vec4f(2.0f / (float)screenWidth, 2.0f / (float)screenHeight, 1.0f, 1.0f), + Vec4f(-1.0f, -1.0f, 0.0f, 0.0f), + }; + + ID3D11BufferPtr cb = MakeBuffer().Constant().Data(cbufferdata); + + ID3D11Texture2DPtr bbDepth = + MakeTexture(DXGI_FORMAT_D32_FLOAT_S8X24_UINT, screenWidth, screenHeight).DSV(); + ID3D11DepthStencilViewPtr bbDSV = MakeDSV(bbDepth); + + CD3D11_DEPTH_STENCIL_DESC dd = CD3D11_DEPTH_STENCIL_DESC(CD3D11_DEFAULT()); + dd.DepthEnable = TRUE; + dd.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL; + dd.DepthFunc = D3D11_COMPARISON_LESS; + dd.StencilEnable = FALSE; + dd.StencilWriteMask = dd.StencilReadMask = 0xff; + + ID3D11DepthStencilStatePtr ds; + CHECK_HR(dev->CreateDepthStencilState(&dd, &ds)); + + while(Running()) + { + ClearRenderTargetView(bbRTV, {0.4f, 0.5f, 0.6f, 1.0f}); + + ctx->ClearDepthStencilView(bbDSV, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0); + + IASetVertexBuffer(vb, sizeof(DefaultA2V), 0); + ctx->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); + ctx->IASetInputLayout(defaultLayout); + ctx->OMSetDepthStencilState(ds, 0); + + ctx->VSSetShader(vs, NULL, 0); + ctx->PSSetShader(ps, NULL, 0); + + ctx->VSSetConstantBuffers(0, 1, &cb.GetInterfacePtr()); + + RSSetViewport({0.0f, 0.0f, (float)screenWidth, (float)screenHeight, 0.0f, 1.0f}); + + ctx->OMSetRenderTargets(1, &bbRTV.GetInterfacePtr(), bbDSV); + + // a previous draw for testing 'whole pass' rendering + ctx->Draw(3, 10); + + setMarker("Quad"); + + // draw two instances so we can test rendering other instances + ctx->DrawInstanced(6, 2, 0, 0); + + setMarker("Points"); + + ctx->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_POINTLIST); + + ctx->Draw(4, 6); + + setMarker("Stride 0"); + IASetVertexBuffer(vb, 0, 0); + + ctx->Draw(1, 0); + + Present(); + } + + return 0; + } +}; + +REGISTER_TEST(); diff --git a/util/test/demos/d3d12/d3d12_mesh_zoo.cpp b/util/test/demos/d3d12/d3d12_mesh_zoo.cpp new file mode 100644 index 000000000..4a4f046f1 --- /dev/null +++ b/util/test/demos/d3d12/d3d12_mesh_zoo.cpp @@ -0,0 +1,209 @@ +/****************************************************************************** + * The MIT License (MIT) + * + * Copyright (c) 2019-2020 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_Mesh_Zoo, D3D12GraphicsTest) +{ + static constexpr const char *Description = "Draws some primitives for testing the mesh view."; + + std::string vertex = R"EOSHADER( + +struct vertin +{ + float3 pos : POSITION; + float4 col : COLOR0; +}; + +struct v2f +{ + float4 pos : SV_POSITION; + float4 col : COLOR0; +}; + +cbuffer consts : register(b0) +{ + float4 scale; + float4 offset; +}; + +v2f main(vertin IN, uint vid : SV_VertexID, uint inst : SV_InstanceID) +{ + v2f OUT = (v2f)0; + + OUT.pos = float4(IN.pos.xy * scale.xy + offset.xy, IN.pos.z, 1.0f); + OUT.col = IN.col; + + if(inst > 0) + { + OUT.pos *= 0.3f; + OUT.pos.xy += 0.1f; + OUT.col.z = 1.0f; + } + + return OUT; +} + +)EOSHADER"; + + std::string pixel = R"EOSHADER( + +struct v2f +{ + float4 pos : SV_POSITION; + float4 col : COLOR0; +}; + +float4 main(v2f IN) : SV_Target0 +{ + return IN.col; +} + +)EOSHADER"; + + int main() + { + // initialise, create window, create device, etc + if(!Init()) + return 3; + + ID3DBlobPtr vsblob = Compile(vertex, "main", "vs_4_0"); + ID3DBlobPtr psblob = Compile(pixel, "main", "ps_4_0"); + + const DefaultA2V test[] = { + // single color quad + {Vec3f(50.0f, 250.0f, 0.2f), Vec4f(0.0f, 1.0f, 0.0f, 1.0f), Vec2f(0.0f, 0.0f)}, + {Vec3f(250.0f, 250.0f, 0.2f), Vec4f(0.0f, 1.0f, 0.0f, 1.0f), Vec2f(0.0f, 0.0f)}, + {Vec3f(50.0f, 50.0f, 0.2f), Vec4f(0.0f, 1.0f, 0.0f, 1.0f), Vec2f(0.0f, 0.0f)}, + + {Vec3f(250.0f, 250.0f, 0.2f), Vec4f(0.0f, 1.0f, 0.0f, 1.0f), Vec2f(0.0f, 0.0f)}, + {Vec3f(250.0f, 50.0f, 0.2f), Vec4f(0.0f, 1.0f, 0.0f, 1.0f), Vec2f(0.0f, 0.0f)}, + {Vec3f(50.0f, 50.0f, 0.2f), Vec4f(0.0f, 1.0f, 0.0f, 1.0f), Vec2f(0.0f, 0.0f)}, + + // points, to test vertex picking + {Vec3f(50.0f, 250.0f, 0.2f), Vec4f(0.0f, 1.0f, 0.0f, 1.0f), Vec2f(0.0f, 0.0f)}, + {Vec3f(250.0f, 250.0f, 0.2f), Vec4f(0.0f, 1.0f, 0.0f, 1.0f), Vec2f(0.0f, 0.0f)}, + {Vec3f(250.0f, 50.0f, 0.2f), Vec4f(0.0f, 1.0f, 0.0f, 1.0f), Vec2f(0.0f, 0.0f)}, + {Vec3f(50.0f, 50.0f, 0.2f), Vec4f(0.0f, 1.0f, 0.0f, 1.0f), Vec2f(0.0f, 0.0f)}, + + {Vec3f(70.0f, 170.0f, 0.1f), Vec4f(1.0f, 0.0f, 1.0f, 1.0f), Vec2f(0.0f, 0.0f)}, + {Vec3f(170.0f, 170.0f, 0.1f), Vec4f(1.0f, 0.0f, 1.0f, 1.0f), Vec2f(0.0f, 0.0f)}, + {Vec3f(70.0f, 70.0f, 0.1f), Vec4f(1.0f, 0.0f, 1.0f, 1.0f), Vec2f(0.0f, 0.0f)}, + }; + + ID3D12ResourcePtr vb = MakeBuffer().Data(test); + + Vec4f cbufferdata[] = { + Vec4f(2.0f / (float)screenWidth, 2.0f / (float)screenHeight, 1.0f, 1.0f), + Vec4f(-1.0f, -1.0f, 0.0f, 0.0f), + }; + + ID3D12RootSignaturePtr sig = MakeSig({ + constParam(D3D12_SHADER_VISIBILITY_VERTEX, 0, 0, sizeof(cbufferdata) / sizeof(uint32_t)), + }); + + D3D12PSOCreator creator = MakePSO().RootSig(sig).InputLayout().VS(vsblob).PS(psblob).DSV( + DXGI_FORMAT_D32_FLOAT_S8X24_UINT); + + creator.GraphicsDesc.DepthStencilState.DepthEnable = TRUE; + creator.GraphicsDesc.DepthStencilState.DepthWriteMask = D3D12_DEPTH_WRITE_MASK_ALL; + creator.GraphicsDesc.DepthStencilState.StencilEnable = FALSE; + + ID3D12PipelineStatePtr pso = creator; + + creator.GraphicsDesc.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_POINT; + + ID3D12PipelineStatePtr pointspso = creator; + + ResourceBarrier(vb, D3D12_RESOURCE_STATE_COMMON, D3D12_RESOURCE_STATE_VERTEX_AND_CONSTANT_BUFFER); + + ID3D12ResourcePtr dsv = MakeTexture(DXGI_FORMAT_D32_FLOAT_S8X24_UINT, screenWidth, screenHeight) + .DSV() + .InitialState(D3D12_RESOURCE_STATE_DEPTH_WRITE); + + while(Running()) + { + ID3D12GraphicsCommandListPtr cmd = GetCommandBuffer(); + + Reset(cmd); + + ID3D12ResourcePtr bb = StartUsingBackbuffer(cmd, D3D12_RESOURCE_STATE_RENDER_TARGET); + + D3D12_CPU_DESCRIPTOR_HANDLE rtv = + MakeRTV(bb).Format(DXGI_FORMAT_R8G8B8A8_UNORM_SRGB).CreateCPU(0); + + OMSetRenderTargets(cmd, {rtv}, MakeDSV(dsv).CreateCPU(0)); + + ClearRenderTargetView(cmd, rtv, {0.4f, 0.5f, 0.6f, 1.0f}); + ClearDepthStencilView(cmd, dsv, D3D12_CLEAR_FLAG_DEPTH | D3D12_CLEAR_FLAG_STENCIL, 1.0f, 0); + + cmd->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST); + + IASetVertexBuffer(cmd, vb, sizeof(DefaultA2V), 0); + cmd->SetPipelineState(pso); + cmd->SetGraphicsRootSignature(sig); + + cmd->SetGraphicsRoot32BitConstants(0, sizeof(cbufferdata) / sizeof(uint32_t), &cbufferdata, 0); + + RSSetViewport(cmd, {0.0f, 0.0f, (float)screenWidth, (float)screenHeight, 0.0f, 1.0f}); + RSSetScissorRect(cmd, {0, 0, screenWidth, screenHeight}); + + // a previous draw for testing 'whole pass' rendering + cmd->DrawInstanced(3, 1, 10, 0); + + setMarker(cmd, "Quad"); + + // draw two instances so we can test rendering other instances + cmd->DrawInstanced(6, 2, 0, 0); + + setMarker(cmd, "Points"); + + cmd->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_POINTLIST); + + cmd->SetPipelineState(pointspso); + + cmd->SetGraphicsRoot32BitConstants(0, sizeof(cbufferdata) / sizeof(uint32_t), &cbufferdata, 0); + + cmd->DrawInstanced(4, 1, 6, 0); + + setMarker(cmd, "Stride 0"); + + IASetVertexBuffer(cmd, vb, 0, 0); + + cmd->DrawInstanced(1, 1, 0, 0); + + FinishUsingBackbuffer(cmd, D3D12_RESOURCE_STATE_RENDER_TARGET); + + cmd->Close(); + + Submit({cmd}); + + Present(); + } + + return 0; + } +}; + +REGISTER_TEST(); diff --git a/util/test/demos/demos.vcxproj b/util/test/demos/demos.vcxproj index dd0a334c3..70f1f365f 100644 --- a/util/test/demos/demos.vcxproj +++ b/util/test/demos/demos.vcxproj @@ -134,6 +134,7 @@ + @@ -160,6 +161,7 @@ + @@ -188,6 +190,7 @@ + @@ -222,6 +225,7 @@ + diff --git a/util/test/demos/demos.vcxproj.filters b/util/test/demos/demos.vcxproj.filters index e9da0395a..65752347c 100644 --- a/util/test/demos/demos.vcxproj.filters +++ b/util/test/demos/demos.vcxproj.filters @@ -382,6 +382,18 @@ OpenGL\demos + + D3D11\demos + + + D3D12\demos + + + OpenGL\demos + + + Vulkan\demos + diff --git a/util/test/demos/gl/gl_mesh_zoo.cpp b/util/test/demos/gl/gl_mesh_zoo.cpp new file mode 100644 index 000000000..b8c120915 --- /dev/null +++ b/util/test/demos/gl/gl_mesh_zoo.cpp @@ -0,0 +1,216 @@ +/****************************************************************************** + * The MIT License (MIT) + * + * Copyright (c) 2019-2020 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_Mesh_Zoo, OpenGLGraphicsTest) +{ + static constexpr const char *Description = "Draws some primitives for testing the mesh view."; + + std::string common = R"EOSHADER( + +#version 420 core + +)EOSHADER"; + + std::string vertex = R"EOSHADER( + +layout(location = 0) in vec3 Position; +layout(location = 1) in vec4 Color; + +layout(binding = 0, std140) uniform constsbuf +{ + vec4 scale; + vec4 offset; +}; + +out vec4 col; + +void main() +{ + vec4 pos = vec4(Position.xy * scale.xy + offset.xy, Position.z, 1.0f); + col = Color; + + if(gl_InstanceID > 0) + { + pos *= 0.3f; + pos.xy += vec2(0.1f); + col.z = 1.0f; + } + + gl_Position = pos; +} + +)EOSHADER"; + + std::string pixel = R"EOSHADER( + +in vec4 col; + +layout(location = 0, index = 0) out vec4 Color; + +void main() +{ + Color = col; +} + +)EOSHADER"; + + int main() + { + // initialise, create window, create context, etc + if(!Init()) + return 3; + + const DefaultA2V test[] = { + // single color quad + {Vec3f(50.0f, 250.0f, 0.2f), Vec4f(0.0f, 1.0f, 0.0f, 1.0f), Vec2f(0.0f, 0.0f)}, + {Vec3f(250.0f, 250.0f, 0.2f), Vec4f(0.0f, 1.0f, 0.0f, 1.0f), Vec2f(0.0f, 0.0f)}, + {Vec3f(50.0f, 50.0f, 0.2f), Vec4f(0.0f, 1.0f, 0.0f, 1.0f), Vec2f(0.0f, 0.0f)}, + + {Vec3f(250.0f, 250.0f, 0.2f), Vec4f(0.0f, 1.0f, 0.0f, 1.0f), Vec2f(0.0f, 0.0f)}, + {Vec3f(250.0f, 50.0f, 0.2f), Vec4f(0.0f, 1.0f, 0.0f, 1.0f), Vec2f(0.0f, 0.0f)}, + {Vec3f(50.0f, 50.0f, 0.2f), Vec4f(0.0f, 1.0f, 0.0f, 1.0f), Vec2f(0.0f, 0.0f)}, + + // points, to test vertex picking + {Vec3f(50.0f, 250.0f, 0.2f), Vec4f(0.0f, 1.0f, 0.0f, 1.0f), Vec2f(0.0f, 0.0f)}, + {Vec3f(250.0f, 250.0f, 0.2f), Vec4f(0.0f, 1.0f, 0.0f, 1.0f), Vec2f(0.0f, 0.0f)}, + {Vec3f(250.0f, 50.0f, 0.2f), Vec4f(0.0f, 1.0f, 0.0f, 1.0f), Vec2f(0.0f, 0.0f)}, + {Vec3f(50.0f, 50.0f, 0.2f), Vec4f(0.0f, 1.0f, 0.0f, 1.0f), Vec2f(0.0f, 0.0f)}, + + {Vec3f(70.0f, 170.0f, 0.1f), Vec4f(1.0f, 0.0f, 1.0f, 1.0f), Vec2f(0.0f, 0.0f)}, + {Vec3f(170.0f, 170.0f, 0.1f), Vec4f(1.0f, 0.0f, 1.0f, 1.0f), Vec2f(0.0f, 0.0f)}, + {Vec3f(70.0f, 70.0f, 0.1f), Vec4f(1.0f, 0.0f, 1.0f, 1.0f), Vec2f(0.0f, 0.0f)}, + }; + + GLuint vao = MakeVAO(); + glBindVertexArray(vao); + + GLuint vb = MakeBuffer(); + glBindBuffer(GL_ARRAY_BUFFER, vb); + glBufferStorage(GL_ARRAY_BUFFER, sizeof(test), test, 0); + + Vec4f cbufferdata[] = { + Vec4f(2.0f / (float)screenWidth, 2.0f / (float)screenHeight, 1.0f, 1.0f), + Vec4f(-1.0f, -1.0f, 0.0f, 0.0f), + }; + + GLuint cb = MakeBuffer(); + glBindBuffer(GL_UNIFORM_BUFFER, cb); + glBufferStorage(GL_UNIFORM_BUFFER, sizeof(cbufferdata), cbufferdata, 0); + + glBindBufferBase(GL_UNIFORM_BUFFER, 0, cb); + + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(DefaultA2V), (void *)(0)); + glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, sizeof(DefaultA2V), (void *)(sizeof(Vec3f))); + glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(DefaultA2V), + (void *)(sizeof(Vec3f) + sizeof(Vec4f))); + + glEnableVertexAttribArray(0); + glEnableVertexAttribArray(1); + glEnableVertexAttribArray(2); + + GLuint stride0vao = MakeVAO(); + glBindVertexArray(stride0vao); + + // need to specify this using modern bindings, glVertexAttribPointer stride 0 is interpreted as + // 'tightly packed' + glVertexAttribFormat(0, 3, GL_FLOAT, GL_FALSE, offsetof(DefaultA2V, pos)); + glVertexAttribFormat(1, 3, GL_FLOAT, GL_FALSE, offsetof(DefaultA2V, col)); + glVertexAttribFormat(2, 3, GL_FLOAT, GL_FALSE, offsetof(DefaultA2V, uv)); + + glVertexAttribBinding(0, 0); + glVertexAttribBinding(1, 0); + glVertexAttribBinding(2, 0); + + glBindVertexBuffer(0, vb, 0, 0); + + glEnableVertexAttribArray(0); + glEnableVertexAttribArray(1); + glEnableVertexAttribArray(2); + + GLuint program = MakeProgram(common + vertex, common + pixel); + + GLuint fbo = MakeFBO(); + glBindFramebuffer(GL_FRAMEBUFFER, fbo); + + // Color render texture + GLuint attachments[] = {MakeTexture(), MakeTexture(), MakeTexture()}; + + glBindTexture(GL_TEXTURE_2D, attachments[0]); + glTexStorage2D(GL_TEXTURE_2D, 1, GL_SRGB8_ALPHA8, screenWidth, screenHeight); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, attachments[0], 0); + + glBindTexture(GL_TEXTURE_2D, attachments[1]); + glTexStorage2D(GL_TEXTURE_2D, 1, GL_DEPTH24_STENCIL8, screenWidth, screenHeight); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, + attachments[1], 0); + + glDepthMask(GL_TRUE); + glEnable(GL_DEPTH_TEST); + glDisable(GL_DEPTH_CLAMP); + glDisable(GL_STENCIL_TEST); + + while(Running()) + { + glBindFramebuffer(GL_FRAMEBUFFER, fbo); + float col[] = {0.4f, 0.5f, 0.6f, 1.0f}; + glClearBufferfv(GL_COLOR, 0, col); + glClearBufferfi(GL_DEPTH_STENCIL, 0, 1.0f, 0); + + glBindVertexArray(vao); + + glUseProgram(program); + + glViewport(0, 0, GLsizei(screenWidth), GLsizei(screenHeight)); + + glDrawArrays(GL_TRIANGLES, 10, 3); + + setMarker("Quad"); + + glDrawArraysInstanced(GL_TRIANGLES, 0, 6, 2); + + setMarker("Points"); + + glDrawArrays(GL_POINTS, 6, 4); + + setMarker("Stride 0"); + + glBindVertexArray(stride0vao); + + glDrawArrays(GL_POINTS, 0, 1); + + glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo); + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); + glBlitFramebuffer(0, 0, screenWidth, screenHeight, 0, 0, screenWidth, screenHeight, + GL_COLOR_BUFFER_BIT, GL_LINEAR); + + Present(); + } + + return 0; + } +}; + +REGISTER_TEST(); diff --git a/util/test/demos/vk/vk_mesh_zoo.cpp b/util/test/demos/vk/vk_mesh_zoo.cpp new file mode 100644 index 000000000..2a26bd758 --- /dev/null +++ b/util/test/demos/vk/vk_mesh_zoo.cpp @@ -0,0 +1,260 @@ +/****************************************************************************** + * The MIT License (MIT) + * + * Copyright (c) 2019-2020 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_Mesh_Zoo, VulkanGraphicsTest) +{ + static constexpr const char *Description = "Draws some primitives for testing the mesh view."; + + std::string common = R"EOSHADER( + +#version 420 core + +)EOSHADER"; + + std::string vertex = R"EOSHADER( + +layout(location = 0) in vec3 Position; +layout(location = 1) in vec4 Color; + +layout(push_constant, std140) uniform pushbuf +{ + vec4 scale; + vec4 offset; +}; + +layout(location = 0) out vec4 vertOutcol; + +void main() +{ + vec4 pos = vec4(Position.xy * scale.xy + offset.xy, Position.z, 1.0f); + vertOutcol = Color; + + if(gl_InstanceIndex > 0) + { + pos *= 0.3f; + pos.xy += vec2(0.1f); + vertOutcol.z = 1.0f; + } + + gl_Position = pos * vec4(1, -1, 1, 1); +#if defined(USE_POINTS) + gl_PointSize = 1.0f; +#endif +} + +)EOSHADER"; + + std::string pixel = R"EOSHADER( + +layout(location = 0) in vec4 vertIncol; + +layout(location = 0, index = 0) out vec4 Color; + +void main() +{ + Color = vertIncol; +} + +)EOSHADER"; + + int main() + { + // initialise, create window, create context, etc + if(!Init()) + return 3; + + const DefaultA2V test[] = { + // single color quad + {Vec3f(50.0f, 250.0f, 0.2f), Vec4f(0.0f, 1.0f, 0.0f, 1.0f), Vec2f(0.0f, 0.0f)}, + {Vec3f(250.0f, 250.0f, 0.2f), Vec4f(0.0f, 1.0f, 0.0f, 1.0f), Vec2f(0.0f, 0.0f)}, + {Vec3f(50.0f, 50.0f, 0.2f), Vec4f(0.0f, 1.0f, 0.0f, 1.0f), Vec2f(0.0f, 0.0f)}, + + {Vec3f(250.0f, 250.0f, 0.2f), Vec4f(0.0f, 1.0f, 0.0f, 1.0f), Vec2f(0.0f, 0.0f)}, + {Vec3f(250.0f, 50.0f, 0.2f), Vec4f(0.0f, 1.0f, 0.0f, 1.0f), Vec2f(0.0f, 0.0f)}, + {Vec3f(50.0f, 50.0f, 0.2f), Vec4f(0.0f, 1.0f, 0.0f, 1.0f), Vec2f(0.0f, 0.0f)}, + + // points, to test vertex picking + {Vec3f(50.0f, 250.0f, 0.2f), Vec4f(0.0f, 1.0f, 0.0f, 1.0f), Vec2f(0.0f, 0.0f)}, + {Vec3f(250.0f, 250.0f, 0.2f), Vec4f(0.0f, 1.0f, 0.0f, 1.0f), Vec2f(0.0f, 0.0f)}, + {Vec3f(250.0f, 50.0f, 0.2f), Vec4f(0.0f, 1.0f, 0.0f, 1.0f), Vec2f(0.0f, 0.0f)}, + {Vec3f(50.0f, 50.0f, 0.2f), Vec4f(0.0f, 1.0f, 0.0f, 1.0f), Vec2f(0.0f, 0.0f)}, + + {Vec3f(70.0f, 170.0f, 0.1f), Vec4f(1.0f, 0.0f, 1.0f, 1.0f), Vec2f(0.0f, 0.0f)}, + {Vec3f(170.0f, 170.0f, 0.1f), Vec4f(1.0f, 0.0f, 1.0f, 1.0f), Vec2f(0.0f, 0.0f)}, + {Vec3f(70.0f, 70.0f, 0.1f), Vec4f(1.0f, 0.0f, 1.0f, 1.0f), Vec2f(0.0f, 0.0f)}, + }; + + // create depth-stencil image + AllocatedImage depthimg(this, vkh::ImageCreateInfo(mainWindow->scissor.extent.width, + mainWindow->scissor.extent.height, 0, + VK_FORMAT_D32_SFLOAT_S8_UINT, + VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT), + VmaAllocationCreateInfo({0, VMA_MEMORY_USAGE_GPU_ONLY})); + + VkImageView dsvview = createImageView(vkh::ImageViewCreateInfo( + depthimg.image, VK_IMAGE_VIEW_TYPE_2D, VK_FORMAT_D32_SFLOAT_S8_UINT, {}, + vkh::ImageSubresourceRange(VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT))); + + // create renderpass using the DS image + vkh::RenderPassCreator renderPassCreateInfo; + + renderPassCreateInfo.attachments.push_back(vkh::AttachmentDescription( + mainWindow->format, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL)); + renderPassCreateInfo.attachments.push_back(vkh::AttachmentDescription( + VK_FORMAT_D32_SFLOAT_S8_UINT, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_GENERAL, + VK_ATTACHMENT_LOAD_OP_CLEAR, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_SAMPLE_COUNT_1_BIT, + VK_ATTACHMENT_LOAD_OP_CLEAR, VK_ATTACHMENT_STORE_OP_DONT_CARE)); + + renderPassCreateInfo.addSubpass({VkAttachmentReference({0, VK_IMAGE_LAYOUT_GENERAL})}, 1, + VK_IMAGE_LAYOUT_GENERAL); + + VkRenderPass renderPass = createRenderPass(renderPassCreateInfo); + + // create framebuffers using swapchain images and DS image + std::vector fbs; + fbs.resize(mainWindow->GetCount()); + + for(size_t i = 0; i < mainWindow->GetCount(); i++) + fbs[i] = createFramebuffer(vkh::FramebufferCreateInfo( + renderPass, {mainWindow->GetView(i), dsvview}, mainWindow->scissor.extent)); + + VkPipelineLayout layout = createPipelineLayout(vkh::PipelineLayoutCreateInfo( + {}, + { + vkh::PushConstantRange(VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(Vec4f) * 2), + })); + + vkh::GraphicsPipelineCreateInfo pipeCreateInfo; + + pipeCreateInfo.layout = layout; + pipeCreateInfo.renderPass = renderPass; + + 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(common + vertex, ShaderLang::glsl, ShaderStage::vert, "main"), + CompileShaderModule(common + pixel, ShaderLang::glsl, ShaderStage::frag, "main"), + }; + + pipeCreateInfo.depthStencilState.depthTestEnable = VK_TRUE; + pipeCreateInfo.depthStencilState.depthWriteEnable = VK_TRUE; + pipeCreateInfo.depthStencilState.stencilTestEnable = VK_FALSE; + pipeCreateInfo.depthStencilState.back = pipeCreateInfo.depthStencilState.front; + + VkPipeline pipe = createGraphicsPipeline(pipeCreateInfo); + + pipeCreateInfo.stages[0] = CompileShaderModule(common + "\n#define USE_POINTS\n" + vertex, + ShaderLang::glsl, ShaderStage::vert, "main"), + pipeCreateInfo.inputAssemblyState.topology = VK_PRIMITIVE_TOPOLOGY_POINT_LIST; + + VkPipeline pointspipe = createGraphicsPipeline(pipeCreateInfo); + + pipeCreateInfo.vertexInputState.vertexBindingDescriptions = {{0, 0, VK_VERTEX_INPUT_RATE_VERTEX}}; + + VkPipeline stride0pipe = createGraphicsPipeline(pipeCreateInfo); + + AllocatedBuffer vb(this, + vkh::BufferCreateInfo(sizeof(test), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | + VK_BUFFER_USAGE_TRANSFER_DST_BIT), + VmaAllocationCreateInfo({0, VMA_MEMORY_USAGE_CPU_TO_GPU})); + + vb.upload(test); + + Vec4f cbufferdata[] = { + Vec4f(2.0f / (float)screenWidth, 2.0f / (float)screenHeight, 1.0f, 1.0f), + Vec4f(-1.0f, -1.0f, 0.0f, 0.0f), + }; + + AllocatedBuffer cb( + this, vkh::BufferCreateInfo(sizeof(cbufferdata), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT | + VK_BUFFER_USAGE_TRANSFER_DST_BIT), + VmaAllocationCreateInfo({0, VMA_MEMORY_USAGE_CPU_TO_GPU})); + + cb.upload(cbufferdata); + + while(Running()) + { + VkCommandBuffer cmd = GetCommandBuffer(); + + vkBeginCommandBuffer(cmd, vkh::CommandBufferBeginInfo()); + + VkImage swapimg = + StartUsingBackbuffer(cmd, VK_ACCESS_TRANSFER_WRITE_BIT, VK_IMAGE_LAYOUT_GENERAL); + + vkCmdClearColorImage(cmd, swapimg, VK_IMAGE_LAYOUT_GENERAL, + vkh::ClearColorValue(0.4f, 0.5f, 0.6f, 1.0f), 1, + vkh::ImageSubresourceRange()); + + vkCmdBeginRenderPass( + cmd, vkh::RenderPassBeginInfo(renderPass, fbs[mainWindow->imgIndex], mainWindow->scissor, + {{}, vkh::ClearValue(1.0f, 0)}), + VK_SUBPASS_CONTENTS_INLINE); + + vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, pipe); + vkCmdPushConstants(cmd, layout, VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(cbufferdata), + &cbufferdata); + vkCmdSetViewport(cmd, 0, 1, &mainWindow->viewport); + vkCmdSetScissor(cmd, 0, 1, &mainWindow->scissor); + vkh::cmdBindVertexBuffers(cmd, 0, {vb.buffer}, {0}); + + vkCmdDraw(cmd, 3, 1, 10, 0); + + setMarker(cmd, "Quad"); + + vkCmdDraw(cmd, 6, 2, 0, 0); + + setMarker(cmd, "Points"); + + vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, pointspipe); + + vkCmdDraw(cmd, 4, 1, 6, 0); + + setMarker(cmd, "Stride 0"); + + vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, stride0pipe); + + vkCmdDraw(cmd, 1, 1, 0, 0); + + vkCmdEndRenderPass(cmd); + + FinishUsingBackbuffer(cmd, VK_ACCESS_TRANSFER_WRITE_BIT, VK_IMAGE_LAYOUT_GENERAL); + + vkEndCommandBuffer(cmd); + + Submit(0, 1, {cmd}); + + Present(); + } + + return 0; + } +}; + +REGISTER_TEST(); diff --git a/util/test/rdtest/__init__.py b/util/test/rdtest/__init__.py index a5fb09da4..a549272db 100644 --- a/util/test/rdtest/__init__.py +++ b/util/test/rdtest/__init__.py @@ -4,3 +4,4 @@ from .runner import * from .analyse import * from .testcase import * from .shared.Texture_Zoo import * +from .shared.Mesh_Zoo import * diff --git a/util/test/rdtest/shared/Mesh_Zoo.py b/util/test/rdtest/shared/Mesh_Zoo.py new file mode 100644 index 000000000..375a3b0e3 --- /dev/null +++ b/util/test/rdtest/shared/Mesh_Zoo.py @@ -0,0 +1,349 @@ +import renderdoc as rd +import rdtest +from typing import List, Tuple +import time +import os + +# Not a real test, re-used by API-specific tests +class Mesh_Zoo(): + def __init__(self): + self.out = None + self.cfg = rd.MeshDisplay() + + def cache_output(self): + self.out.SetMeshDisplay(self.cfg) + + self.out.Display() + + pixels: bytes = self.out.ReadbackOutputTexture() + dim = self.out.GetDimensions() + + pitch = dim[0]*3 + self.rows = [pixels[row_start:row_start + pitch] for row_start in range(0, dim[1] * pitch, pitch)] + + rdtest.png_save(rdtest.get_tmp_path('output.png'), self.rows, dim, False) + + def find_draw(self, name): + draw = None + + for d in self.controller.GetDrawcalls(): + if name in d.name: + draw = d + break + + if draw is None: + raise rdtest.TestFailureException("Couldn't find '{}' draw".format(name)) + + return draw + + # To avoid needing to do image comparisons, we instead do quad region probes to see which colours are present. That + # way we can programmatically check that the wireframe we expect to be there, is there + def get_region_cols(self, region): + x0, y0, x1, y1 = region + cols = [] + for y in range(y0, y1+1): + for x in range(x0, x1+1): + col = tuple(self.rows[y][x*3:x*3+3]) + + # skip pure gray, this comes from the checkerboard or frustum, all our lines and data are coloured + if col[0] == col[1] and col[1] == col[2]: + continue + + if col not in cols: + cols.append(col) + return cols + + def check_region(self, region, test): + colors = self.get_region_cols(region) + + if not test(colors): + tmp_path = rdtest.get_tmp_path('output.png') + rdtest.png_save(tmp_path, self.rows, self.out.GetDimensions(), False) + raise rdtest.TestFailureException("Expected line segment wrong, colors: {}".format(colors), tmp_path) + + def check_vertex(self, x, y, result): + pick = self.out.PickVertex(x, y) + + if not rdtest.value_compare(result, pick): + raise rdtest.TestFailureException("When picking ({},{}) expected vertex {} in instance {}, but found {} in {}".format(x, y, result[0], result[1], pick[0], pick[1])) + + rdtest.log.success("Picking {},{} returns vertex {} in instance {} as expected".format(x, y, result[0], result[1])) + + def check_capture(self, capture_filename: str, controller: rd.ReplayController): + self.controller = controller + + self.controller.SetFrameEvent(self.find_draw("Quad").next.eventId, False) + + self.out: rd.ReplayOutput = self.controller.CreateOutput(rd.CreateHeadlessWindowingData(200, 200), + rd.ReplayOutputType.Mesh) + + self.cfg = rd.MeshDisplay() + + cam: rd.Camera = rd.InitCamera(rd.CameraType.FPSLook) + + cam.SetPosition(0, 0, 0) + cam.SetFPSRotation(0, 0, 0) + + self.cfg.type = rd.MeshDataStage.VSOut + self.cfg.cam = cam + + # Position is always first, so getting the postvs data will give us + inst0: rd.MeshFormat = self.controller.GetPostVSData(0, 0, self.cfg.type) + self.cfg.position = inst0 + + # Color is after position, float4 = 16 bytes + self.cfg.second = self.cfg.position + self.cfg.second.vertexByteOffset += 16 + + # Configure an ortho camera, even though we don't really have a camera + self.cfg.ortho = True + self.cfg.position.nearPlane = 1.0 + self.cfg.position.farPlane = 100.0 + self.cfg.aspect = 1.0 + self.cfg.wireframeDraw = True + self.cfg.position.meshColor = rd.FloatVector(1.0, 0.0, 1.0, 1.0) + + self.cache_output() + + # We should have a single quad, check each outside edge and the inside diagonal. + # All these line segments should have some colors (not including the background checkerboard or the frustum) + self.check_region((55, 95, 65, 95), lambda x: x != []) # Left edge + self.check_region((85, 60, 85, 70), lambda x: x != []) # Top edge + self.check_region((105, 100, 115, 100), lambda x: x != []) # Right edge + self.check_region((90, 130, 90, 140), lambda x: x != []) # Bottom edge + self.check_region((65, 120, 75, 120), lambda x: x != []) # Bottom-Left of diagonal + self.check_region((105, 70, 110, 70), lambda x: x != []) # Top-right of diagonal + + rdtest.log.success("Base rendering is as expected") + + self.cfg.solidShadeMode = rd.SolidShade.Secondary + self.cfg.wireframeDraw = False + + # allow for blending with white for the frustum + isred = lambda col: col[0] > col[1] and col[1] == col[2] + isgreen = lambda col: col[1] > col[0] and col[0] == col[2] + isblue = lambda col: col[2] > col[0] and col[0] == col[1] + + isredgreen = lambda col: isred(col) or isgreen(col) or col[2] == 0 + + iscyan = lambda col: col[1] == col[2] and col[0] < col[1] + + self.cache_output() + + # The secondary color should be completely green + self.check_region((85, 70, 85, 125), lambda x: all([isgreen(i) for i in x])) + self.check_region((65, 100, 105, 100), lambda x: all([isgreen(i) for i in x])) + # this line segment isn't in the first instance + self.check_region((65, 55, 105, 55), lambda x: x == []) + # this line segment isn't in the second instance + self.check_region((65, 125, 105, 125), lambda x: all([isgreen(i) for i in x])) + + rdtest.log.success("Secondary rendering of instance 0 is as expected") + + # Out of bounds should look the same as without highlighting at all, check the corners are all still green + self.cfg.highlightVert = 9 + + self.cache_output() + + self.check_region((55, 60, 65, 70), lambda x: all([isgreen(i) for i in x])) + self.check_region((105, 60, 115, 70), lambda x: all([isgreen(i) for i in x])) + self.check_region((55, 130, 65, 140), lambda x: all([isgreen(i) for i in x])) + self.check_region((105, 130, 115, 140), lambda x: all([isgreen(i) for i in x])) + + vert_regions = [ + (55, 60, 65, 70), + (110, 60, 120, 70), + (55, 130, 65, 140), + + (110, 60, 120, 70), + (110, 130, 120, 140), + (55, 130, 65, 140), + ] + + for vert in range(6): + self.cfg.highlightVert = vert + + self.cache_output() + + tri = int(vert / 3) + + # Check that the triangle we're highlighting is red and the other is green + if tri == 0: + self.check_region((65, 75, 75, 85), lambda x: all([isred(i) for i in x])) + self.check_region((100, 115, 110, 125), lambda x: all([isgreen(i) for i in x])) + else: + self.check_region((65, 75, 75, 85), lambda x: all([isgreen(i) for i in x])) + self.check_region((100, 115, 110, 125), lambda x: all([isred(i) for i in x])) + + # The corners that touch should be red and green - that is no other colours but red and green, but at least + # some red and some green + self.check_region((65, 115, 75, 125), + lambda x: all([isredgreen(i) for i in x]) and + any([isred(i) for i in x]) and + any([isgreen(i) for i in x])) + + # check that there's blue in this vertex's region + self.check_region(vert_regions[vert], lambda x: any([isblue(i) for i in x])) + + rdtest.log.success("Rendering of highlighted vertices is as expected") + + self.cfg.highlightVert = rd.MeshDisplay.NoHighlight + inst1: rd.MeshFormat = self.controller.GetPostVSData(1, 0, self.cfg.type) + + self.cfg.curInstance = 1 + self.cfg.second.vertexResourceId = self.cfg.position.vertexResourceId = inst1.vertexResourceId + self.cfg.second.vertexByteOffset = self.cfg.position.vertexByteOffset = inst1.vertexByteOffset + self.cfg.second.vertexByteOffset += 16 + + self.cache_output() + + # The secondary color should be completely cyan + self.check_region((85, 70, 85, 125), lambda x: all([iscyan(i) for i in x])) + self.check_region((65, 100, 105, 100), lambda x: all([iscyan(i) for i in x])) + # this line segment isn't in the first instance + self.check_region((65, 55, 105, 55), lambda x: all([iscyan(i) for i in x])) + # this line segment isn't in the second instance + self.check_region((65, 125, 105, 125), lambda x: x == []) + + rdtest.log.success("Secondary rendering of instance 1 is as expected") + + self.cfg.solidShadeMode = rd.SolidShade.NoSolid + self.cfg.showAllInstances = True + + self.cache_output() + + # wireframe for original quad should still be present + self.check_region((55, 95, 65, 95), lambda x: x != []) + self.check_region((85, 60, 85, 70), lambda x: x != []) + self.check_region((105, 100, 115, 100), lambda x: x != []) + self.check_region((90, 130, 90, 140), lambda x: x != []) + self.check_region((65, 120, 75, 120), lambda x: x != []) + self.check_region((105, 70, 110, 70), lambda x: x != []) + + # But now we'll have an additional instance + self.check_region((75, 55, 85, 55), lambda x: x != []) + self.check_region((125, 85, 135, 85), lambda x: x != []) + self.check_region((105, 110, 105, 120), lambda x: x != []) + + self.cfg.showWholePass = True + + self.cache_output() + + # same again + self.check_region((55, 95, 65, 95), lambda x: x != []) + self.check_region((85, 60, 85, 70), lambda x: x != []) + self.check_region((105, 100, 115, 100), lambda x: x != []) + self.check_region((90, 130, 90, 140), lambda x: x != []) + self.check_region((65, 120, 75, 120), lambda x: x != []) + self.check_region((105, 70, 110, 70), lambda x: x != []) + self.check_region((75, 55, 85, 55), lambda x: x != []) + self.check_region((125, 85, 135, 85), lambda x: x != []) + self.check_region((105, 110, 105, 120), lambda x: x != []) + + # But now an extra previous draw + self.check_region((30, 105, 40, 105), lambda x: x != []) + self.check_region((50, 80, 50, 90), lambda x: x != []) + self.check_region((45, 130, 55, 130), lambda x: x != []) + self.check_region((30, 150, 40, 150), lambda x: x != []) + + rdtest.log.success("Mesh rendering is as expected") + + self.cfg.showWholePass = False + self.cfg.showAllInstances = False + + # Go back to instance 0. We can ignore cfg.second now + self.cfg.curInstance = 0 + self.cfg.position.vertexResourceId = inst0.vertexResourceId + self.cfg.position.vertexByteOffset = inst0.vertexByteOffset + + self.cache_output() + + # Just above top-left, no result + self.check_vertex(55, 60, (rd.ReplayOutput.NoResult, rd.ReplayOutput.NoResult)) + # Just inside top-left, first vertex + self.check_vertex(65, 70, (0, 0)) + # Outside top-right, inside the second instance, but because we only have one instance showing should return + # no result + self.check_vertex(115, 60, (rd.ReplayOutput.NoResult, rd.ReplayOutput.NoResult)) + self.check_vertex(80, 60, (rd.ReplayOutput.NoResult, rd.ReplayOutput.NoResult)) + # In the first triangle near the top right + self.check_vertex(105, 70, (1, 0)) + # In the second triangle near the top right + self.check_vertex(110, 70, (3, 0)) + # In the second triangle near the middle, would be in the second instance + self.check_vertex(95, 110, (4, 0)) + # In the second triangle near the bottom right + self.check_vertex(110, 130, (4, 0)) + + rdtest.log.success("Instance 0 picking is as expected") + + # if we look at only instance 1, the results should change + self.cfg.curInstance = 1 + self.cfg.position.vertexResourceId = inst1.vertexResourceId + self.cfg.position.vertexByteOffset = inst1.vertexByteOffset + + self.cache_output() + + self.check_vertex(55, 60, (rd.ReplayOutput.NoResult, rd.ReplayOutput.NoResult)) + self.check_vertex(65, 70, (rd.ReplayOutput.NoResult, rd.ReplayOutput.NoResult)) + self.check_vertex(115, 60, (1, 1)) + self.check_vertex(80, 60, (0, 1)) + self.check_vertex(105, 70, (1, 1)) + self.check_vertex(110, 70, (1, 1)) + self.check_vertex(95, 110, (5, 1)) + self.check_vertex(110, 130, (rd.ReplayOutput.NoResult, rd.ReplayOutput.NoResult)) + + rdtest.log.success("Instance 1 picking is as expected") + + # Now look at both instances together, this goes 'in order' so if there is overlap the first instance wins + self.cfg.showAllInstances = True + + self.cache_output() + + self.check_vertex(55, 60, (rd.ReplayOutput.NoResult, rd.ReplayOutput.NoResult)) + self.check_vertex(65, 70, (0, 0)) + self.check_vertex(115, 60, (1, 1)) + self.check_vertex(80, 60, (0, 1)) + self.check_vertex(105, 70, (1, 0)) + self.check_vertex(110, 70, (3, 0)) + self.check_vertex(95, 110, (4, 0)) + self.check_vertex(110, 130, (4, 0)) + + rdtest.log.success("Both instance picking is as expected") + + self.controller.SetFrameEvent(self.find_draw("Points").next.eventId, False) + + # Only one instance, just check we can see the points + self.cfg.curInstance = 0 + self.cfg.position = self.controller.GetPostVSData(0, 0, self.cfg.type) + self.cfg.position.nearPlane = 1.0 + self.cfg.position.farPlane = 100.0 + + self.cache_output() + + # Picking points doesn't have any primitive, it should pick as long as it's close to the point + self.check_vertex(55, 60, (0, 0)) + self.check_vertex(65, 70, (0, 0)) + + self.check_vertex(105, 65, (1, 0)) + self.check_vertex(115, 135, (2, 0)) + self.check_vertex(65, 130, (3, 0)) + self.check_vertex(60, 125, (3, 0)) + + rdtest.log.success("Point picking is as expected") + + self.controller.SetFrameEvent(self.find_draw("Stride 0").next.eventId, False) + + self.cfg.position = self.controller.GetPostVSData(0, 0, self.cfg.type) + self.cfg.position.nearPlane = 1.0 + self.cfg.position.farPlane = 100.0 + + self.cache_output() + + # Stride of 0 is unusual but valid, ensure vertex picking still works + self.check_vertex(55, 60, (0, 0)) + self.check_vertex(65, 70, (0, 0)) + + self.check_vertex(105, 65, (rd.ReplayOutput.NoResult, rd.ReplayOutput.NoResult)) + self.check_vertex(115, 135, (rd.ReplayOutput.NoResult, rd.ReplayOutput.NoResult)) + diff --git a/util/test/tests/D3D11/D3D11_Mesh_Zoo.py b/util/test/tests/D3D11/D3D11_Mesh_Zoo.py new file mode 100644 index 000000000..18e9c6781 --- /dev/null +++ b/util/test/tests/D3D11/D3D11_Mesh_Zoo.py @@ -0,0 +1,13 @@ +import rdtest +import renderdoc as rd + + +class D3D11_Mesh_Zoo(rdtest.TestCase): + demos_test_name = 'D3D11_Mesh_Zoo' + + def __init__(self): + rdtest.TestCase.__init__(self) + self.zoo_helper = rdtest.Mesh_Zoo() + + def check_capture(self): + self.zoo_helper.check_capture(self.capture_filename, self.controller) \ No newline at end of file diff --git a/util/test/tests/D3D12/D3D12_Mesh_Zoo.py b/util/test/tests/D3D12/D3D12_Mesh_Zoo.py new file mode 100644 index 000000000..24006c791 --- /dev/null +++ b/util/test/tests/D3D12/D3D12_Mesh_Zoo.py @@ -0,0 +1,13 @@ +import rdtest +import renderdoc as rd + + +class D3D12_Mesh_Zoo(rdtest.TestCase): + demos_test_name = 'D3D12_Mesh_Zoo' + + def __init__(self): + rdtest.TestCase.__init__(self) + self.zoo_helper = rdtest.Mesh_Zoo() + + def check_capture(self): + self.zoo_helper.check_capture(self.capture_filename, self.controller) diff --git a/util/test/tests/GL/GL_Mesh_Zoo.py b/util/test/tests/GL/GL_Mesh_Zoo.py new file mode 100644 index 000000000..0f24618b6 --- /dev/null +++ b/util/test/tests/GL/GL_Mesh_Zoo.py @@ -0,0 +1,13 @@ +import rdtest +import renderdoc as rd + + +class GL_Mesh_Zoo(rdtest.TestCase): + demos_test_name = 'GL_Mesh_Zoo' + + def __init__(self): + rdtest.TestCase.__init__(self) + self.zoo_helper = rdtest.Mesh_Zoo() + + def check_capture(self): + self.zoo_helper.check_capture(self.capture_filename, self.controller) \ No newline at end of file diff --git a/util/test/tests/Vulkan/VK_Mesh_Zoo.py b/util/test/tests/Vulkan/VK_Mesh_Zoo.py new file mode 100644 index 000000000..cca27f9bb --- /dev/null +++ b/util/test/tests/Vulkan/VK_Mesh_Zoo.py @@ -0,0 +1,13 @@ +import rdtest +import renderdoc as rd + + +class VK_Mesh_Zoo(rdtest.TestCase): + demos_test_name = 'VK_Mesh_Zoo' + + def __init__(self): + rdtest.TestCase.__init__(self) + self.zoo_helper = rdtest.Mesh_Zoo() + + def check_capture(self): + self.zoo_helper.check_capture(self.capture_filename, self.controller)