diff --git a/util/test/demos/CMakeLists.txt b/util/test/demos/CMakeLists.txt index 3e8cb31c8..9bf64b5f9 100644 --- a/util/test/demos/CMakeLists.txt +++ b/util/test/demos/CMakeLists.txt @@ -7,7 +7,6 @@ set(VULKAN_SRC vk/vk_helpers.cpp vk/vk_test.cpp vk/vk_adv_cbuffer_zoo.cpp - vk/vk_awkward_triangle.cpp vk/vk_buffer_address.cpp vk/vk_cbuffer_zoo.cpp vk/vk_descriptor_index.cpp @@ -20,6 +19,7 @@ set(VULKAN_SRC vk/vk_secondary_cmdbuf.cpp vk/vk_simple_triangle.cpp vk/vk_structured_buffer_nested.cpp + vk/vk_vertex_attr_zoo.cpp vk/vk_video_textures.cpp vk/vk_vs_max_desc_set.cpp) @@ -44,7 +44,8 @@ set(OPENGL_SRC gl/gl_simple_triangle.cpp gl/gl_spirv_shader.cpp gl/gl_unsized_ms_fbo_attachment.cpp - gl/gl_vao_0.cpp) + gl/gl_vao_0.cpp + gl/gl_vertex_attr_zoo.cpp) set(SRC main.cpp test_common.cpp diff --git a/util/test/demos/d3d11/d3d11_test.cpp b/util/test/demos/d3d11/d3d11_test.cpp index feed07cf1..585c21841 100644 --- a/util/test/demos/d3d11/d3d11_test.cpp +++ b/util/test/demos/d3d11/d3d11_test.cpp @@ -552,3 +552,10 @@ ID3D11GeometryShaderPtr D3D11GraphicsTest::CreateGS(ID3DBlobPtr blob, (UINT)strides.size(), 0, NULL, &ret)); return ret; } + +ID3D11GeometryShaderPtr D3D11GraphicsTest::CreateGS(ID3DBlobPtr blob) +{ + ID3D11GeometryShaderPtr ret; + CHECK_HR(dev->CreateGeometryShader(blob->GetBufferPointer(), blob->GetBufferSize(), NULL, &ret)); + return ret; +} diff --git a/util/test/demos/d3d11/d3d11_test.h b/util/test/demos/d3d11/d3d11_test.h index f412ec715..8db2f82b6 100644 --- a/util/test/demos/d3d11/d3d11_test.h +++ b/util/test/demos/d3d11/d3d11_test.h @@ -75,6 +75,7 @@ struct D3D11GraphicsTest : public GraphicsTest ID3D11VertexShaderPtr CreateVS(ID3DBlobPtr blob); ID3D11PixelShaderPtr CreatePS(ID3DBlobPtr blob); ID3D11ComputeShaderPtr CreateCS(ID3DBlobPtr blob); + ID3D11GeometryShaderPtr CreateGS(ID3DBlobPtr blob); ID3D11GeometryShaderPtr CreateGS(ID3DBlobPtr blob, const std::vector &sodecl, const std::vector &strides); diff --git a/util/test/demos/d3d11/d3d11_vertex_attr_zoo.cpp b/util/test/demos/d3d11/d3d11_vertex_attr_zoo.cpp new file mode 100644 index 000000000..75d6c6c72 --- /dev/null +++ b/util/test/demos/d3d11/d3d11_vertex_attr_zoo.cpp @@ -0,0 +1,232 @@ +/****************************************************************************** + * The MIT License (MIT) + * + * Copyright (c) 2015-2019 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" + +TEST(D3D11_Vertex_Attr_Zoo, D3D11GraphicsTest) +{ + static constexpr const char *Description = + "Draws a triangle but using different kinds of vertex attributes, including doubles, arrays, " + "matrices, and formats that require manual decode as they are vertex-buffer exclusive on " + "some hardware such as USCALED."; + + struct vertin + { + int16_t i16[4]; + uint16_t u16[4]; + double df[2]; + float arr0[2]; + float arr1[2]; + float arr2[2]; + float mat0[2]; + float mat1[2]; + }; + + std::string common = R"EOSHADER( + +struct a2v +{ + float4 SNorm : SNORM; + float4 UNorm : UNORM; + uint4 UInt : UINT; + float2 Array[3] : ARRAY; + float2x2 Matrix : MATRIX; +}; + +struct v2f +{ + float4 pos : SV_Position; + a2v data; +}; + +)EOSHADER"; + + std::string vertex = R"EOSHADER( + +v2f main(in a2v IN, in uint idx : SV_VertexID) +{ + float2 pos[3] = {float2(-0.5f, 0.5f), float2(0.0f, -0.5f), float2(0.5f, 0.5f)}; + + v2f OUT = (v2f)0; + OUT.pos = float4(pos[idx], 0.0f, 1.0f); + OUT.data = IN; + return OUT; +} + +)EOSHADER"; + + std::string pixel = R"EOSHADER( + +float4 main(in v2f IN) : SV_Target0 +{ + // check values came through correctly + + // SNorm should be in [-1, 1] + if(any(clamp(IN.data.SNorm, -1.0, 1.0) != IN.data.SNorm)) + return float4(0.1f, 0, 0, 1); + + // UNorm should be in [0, 1] + if(any(clamp(IN.data.UNorm, 0.0, 1.0) != IN.data.UNorm)) + return float4(0.2f, 0, 0, 1); + + // Similar for UInt + if(IN.data.UInt.x > 65535 || IN.data.UInt.y > 65535 || IN.data.UInt.z > 65535 || IN.data.UInt.w > 65535) + return float4(0.3f, 0, 0, 1); + + return float4(0, 1.0f, 0, 1); +} + +)EOSHADER"; + + std::string geom = R"EOSHADER( + +[maxvertexcount(3)] +void main(triangle v2f input[3], inout TriangleStream TriStream) +{ + for(int i = 0; i < 3; i++) + { + v2f output = input[i]; + output.pos = float4(output.pos.yx, 0.4f, 1.2f); + TriStream.Append(output); + } + + TriStream.RestartStrip(); +} + +)EOSHADER"; + + int main() + { + // initialise, create window, create device, etc + if(!Init()) + return 3; + + vertin triangle[] = { + { + {32767, -32768, 32767, -32767}, + {12345, 6789, 1234, 567}, + {9.8765432109, -5.6789012345}, + {1.0f, 2.0f}, + {3.0f, 4.0f}, + {5.0f, 6.0f}, + {7.0, 8.0f}, + {9.0f, 10.0f}, + }, + { + {32766, -32766, 16000, -16000}, + {56, 7890, 123, 4567}, + {-7.89012345678, 6.54321098765}, + {11.0f, 12.0f}, + {13.0f, 14.0f}, + {15.0f, 16.0f}, + {17.0, 18.0f}, + {19.0f, 20.0f}, + }, + { + {5, -5, 0, 0}, + {8765, 43210, 987, 65432}, + {0.1234567890123, 4.5678901234}, + {21.0f, 22.0f}, + {23.0f, 24.0f}, + {25.0f, 26.0f}, + {27.0, 28.0f}, + {29.0f, 30.0f}, + }, + }; + + ID3DBlobPtr vsblob = Compile(common + vertex, "main", "vs_4_0"); + ID3DBlobPtr psblob = Compile(common + pixel, "main", "ps_4_0"); + ID3DBlobPtr gsblob = Compile(common + geom, "main", "gs_4_0"); + + D3D11_INPUT_ELEMENT_DESC layoutdesc[] = { + { + "SNORM", 0, DXGI_FORMAT_R16G16B16A16_SNORM, 0, offsetof(vertin, i16), + D3D11_INPUT_PER_VERTEX_DATA, 0, + }, + { + "UNORM", 0, DXGI_FORMAT_R16G16B16A16_UNORM, 0, offsetof(vertin, u16), + D3D11_INPUT_PER_VERTEX_DATA, 0, + }, + { + "UINT", 0, DXGI_FORMAT_R16G16B16A16_UINT, 0, offsetof(vertin, u16), + D3D11_INPUT_PER_VERTEX_DATA, 0, + }, + { + "ARRAY", 0, DXGI_FORMAT_R32G32_FLOAT, 0, offsetof(vertin, arr0), + D3D11_INPUT_PER_VERTEX_DATA, 0, + }, + { + "ARRAY", 1, DXGI_FORMAT_R32G32_FLOAT, 0, offsetof(vertin, arr1), + D3D11_INPUT_PER_VERTEX_DATA, 0, + }, + { + "ARRAY", 2, DXGI_FORMAT_R32G32_FLOAT, 0, offsetof(vertin, arr2), + D3D11_INPUT_PER_VERTEX_DATA, 0, + }, + { + "MATRIX", 0, DXGI_FORMAT_R32G32_FLOAT, 0, offsetof(vertin, mat0), + D3D11_INPUT_PER_VERTEX_DATA, 0, + }, + { + "MATRIX", 1, DXGI_FORMAT_R32G32_FLOAT, 0, offsetof(vertin, mat1), + D3D11_INPUT_PER_VERTEX_DATA, 0, + }, + }; + + ID3D11InputLayoutPtr layout; + CHECK_HR(dev->CreateInputLayout(layoutdesc, ARRAY_COUNT(layoutdesc), vsblob->GetBufferPointer(), + vsblob->GetBufferSize(), &layout)); + + ID3D11VertexShaderPtr vs = CreateVS(vsblob); + ID3D11PixelShaderPtr ps = CreatePS(psblob); + ID3D11GeometryShaderPtr gs = CreateGS(gsblob); + + ID3D11BufferPtr vb = MakeBuffer().Vertex().Data(triangle); + + while(Running()) + { + ClearRenderTargetView(bbRTV, {0.4f, 0.5f, 0.6f, 1.0f}); + + IASetVertexBuffer(vb, sizeof(vertin), 0); + ctx->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); + ctx->IASetInputLayout(layout); + + ctx->VSSetShader(vs, NULL, 0); + ctx->GSSetShader(gs, NULL, 0); + ctx->PSSetShader(ps, 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/d3d12/d3d12_vertex_attr_zoo.cpp b/util/test/demos/d3d12/d3d12_vertex_attr_zoo.cpp new file mode 100644 index 000000000..a19631214 --- /dev/null +++ b/util/test/demos/d3d12/d3d12_vertex_attr_zoo.cpp @@ -0,0 +1,242 @@ +/****************************************************************************** + * The MIT License (MIT) + * + * Copyright (c) 2018-2019 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" + +TEST(D3D12_Vertex_Attr_Zoo, D3D12GraphicsTest) +{ + static constexpr const char *Description = + "Draws a triangle but using different kinds of vertex attributes, including doubles, arrays, " + "matrices, and formats that require manual decode as they are vertex-buffer exclusive on " + "some hardware such as USCALED."; + + struct vertin + { + int16_t i16[4]; + uint16_t u16[4]; + double df[2]; + float arr0[2]; + float arr1[2]; + float arr2[2]; + float mat0[2]; + float mat1[2]; + }; + + std::string common = R"EOSHADER( + +struct a2v +{ + float4 SNorm : SNORM; + float4 UNorm : UNORM; + uint4 UInt : UINT; + float2 Array[3] : ARRAY; + float2x2 Matrix : MATRIX; +}; + +struct v2f +{ + float4 pos : SV_Position; + a2v data; +}; + +)EOSHADER"; + + std::string vertex = R"EOSHADER( + +v2f main(in a2v IN, in uint idx : SV_VertexID) +{ + float2 pos[3] = {float2(-0.5f, 0.5f), float2(0.0f, -0.5f), float2(0.5f, 0.5f)}; + + v2f OUT = (v2f)0; + OUT.pos = float4(pos[idx], 0.0f, 1.0f); + OUT.data = IN; + return OUT; +} + +)EOSHADER"; + + std::string pixel = R"EOSHADER( + +float4 main(in v2f IN) : SV_Target0 +{ + // check values came through correctly + + // SNorm should be in [-1, 1] + if(any(clamp(IN.data.SNorm, -1.0, 1.0) != IN.data.SNorm)) + return float4(0.1f, 0, 0, 1); + + // UNorm should be in [0, 1] + if(any(clamp(IN.data.UNorm, 0.0, 1.0) != IN.data.UNorm)) + return float4(0.2f, 0, 0, 1); + + // Similar for UInt + if(IN.data.UInt.x > 65535 || IN.data.UInt.y > 65535 || IN.data.UInt.z > 65535 || IN.data.UInt.w > 65535) + return float4(0.3f, 0, 0, 1); + + return float4(0, 1.0f, 0, 1); +} + +)EOSHADER"; + + std::string geom = R"EOSHADER( + +[maxvertexcount(3)] +void main(triangle v2f input[3], inout TriangleStream TriStream) +{ + for(int i = 0; i < 3; i++) + { + v2f output = input[i]; + output.pos = float4(output.pos.yx, 0.4f, 1.2f); + TriStream.Append(output); + } + + TriStream.RestartStrip(); +} + +)EOSHADER"; + + int main() + { + // initialise, create window, create device, etc + if(!Init()) + return 3; + + vertin triangle[] = { + { + {32767, -32768, 32767, -32767}, + {12345, 6789, 1234, 567}, + {9.8765432109, -5.6789012345}, + {1.0f, 2.0f}, + {3.0f, 4.0f}, + {5.0f, 6.0f}, + {7.0, 8.0f}, + {9.0f, 10.0f}, + }, + { + {32766, -32766, 16000, -16000}, + {56, 7890, 123, 4567}, + {-7.89012345678, 6.54321098765}, + {11.0f, 12.0f}, + {13.0f, 14.0f}, + {15.0f, 16.0f}, + {17.0, 18.0f}, + {19.0f, 20.0f}, + }, + { + {5, -5, 0, 0}, + {8765, 43210, 987, 65432}, + {0.1234567890123, 4.5678901234}, + {21.0f, 22.0f}, + {23.0f, 24.0f}, + {25.0f, 26.0f}, + {27.0, 28.0f}, + {29.0f, 30.0f}, + }, + }; + + ID3DBlobPtr vsblob = Compile(common + vertex, "main", "vs_4_0"); + ID3DBlobPtr psblob = Compile(common + pixel, "main", "ps_4_0"); + ID3DBlobPtr gsblob = Compile(common + geom, "main", "gs_4_0"); + + ID3D12ResourcePtr vb = MakeBuffer().Data(triangle); + + ID3D12RootSignaturePtr sig = MakeSig({}); + + ID3D12PipelineStatePtr pso = MakePSO().RootSig(sig).VS(vsblob).PS(psblob).GS(gsblob).InputLayout({ + { + "SNORM", 0, DXGI_FORMAT_R16G16B16A16_SNORM, 0, offsetof(vertin, i16), + D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0, + }, + { + "UNORM", 0, DXGI_FORMAT_R16G16B16A16_UNORM, 0, offsetof(vertin, u16), + D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0, + }, + { + "UINT", 0, DXGI_FORMAT_R16G16B16A16_UINT, 0, offsetof(vertin, u16), + D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0, + }, + { + "ARRAY", 0, DXGI_FORMAT_R32G32_FLOAT, 0, offsetof(vertin, arr0), + D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0, + }, + { + "ARRAY", 1, DXGI_FORMAT_R32G32_FLOAT, 0, offsetof(vertin, arr1), + D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0, + }, + { + "ARRAY", 2, DXGI_FORMAT_R32G32_FLOAT, 0, offsetof(vertin, arr2), + D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0, + }, + { + "MATRIX", 0, DXGI_FORMAT_R32G32_FLOAT, 0, offsetof(vertin, mat0), + D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0, + }, + { + "MATRIX", 1, DXGI_FORMAT_R32G32_FLOAT, 0, offsetof(vertin, mat1), + D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0, + }, + }); + + ResourceBarrier(vb, D3D12_RESOURCE_STATE_COMMON, D3D12_RESOURCE_STATE_VERTEX_AND_CONSTANT_BUFFER); + + 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); + + ClearRenderTargetView(cmd, rtv, {0.4f, 0.5f, 0.6f, 1.0f}); + + cmd->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST); + + IASetVertexBuffer(cmd, vb, sizeof(vertin), 0); + cmd->SetPipelineState(pso); + cmd->SetGraphicsRootSignature(sig); + + RSSetViewport(cmd, {0.0f, 0.0f, (float)screenWidth, (float)screenHeight, 0.0f, 1.0f}); + RSSetScissorRect(cmd, {0, 0, screenWidth, screenHeight}); + + OMSetRenderTargets(cmd, {rtv}, {}); + + cmd->DrawInstanced(3, 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 07e3ee90c..d434b5d28 100644 --- a/util/test/demos/demos.vcxproj +++ b/util/test/demos/demos.vcxproj @@ -152,6 +152,7 @@ + @@ -159,6 +160,7 @@ + @@ -193,6 +195,7 @@ + true @@ -202,7 +205,7 @@ - + diff --git a/util/test/demos/demos.vcxproj.filters b/util/test/demos/demos.vcxproj.filters index 9f845e0ad..2c6d63fce 100644 --- a/util/test/demos/demos.vcxproj.filters +++ b/util/test/demos/demos.vcxproj.filters @@ -127,9 +127,6 @@ D3D11\demos - - Vulkan\demos - OpenGL\demos @@ -285,6 +282,18 @@ D3D12\demos + + Vulkan\demos + + + OpenGL\demos + + + D3D11\demos + + + D3D12\demos + diff --git a/util/test/demos/gl/gl_vertex_attr_zoo.cpp b/util/test/demos/gl/gl_vertex_attr_zoo.cpp new file mode 100644 index 000000000..f2502e80e --- /dev/null +++ b/util/test/demos/gl/gl_vertex_attr_zoo.cpp @@ -0,0 +1,254 @@ +/****************************************************************************** + * The MIT License (MIT) + * + * Copyright (c) 2015-2019 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" + +TEST(GL_Vertex_Attr_Zoo, OpenGLGraphicsTest) +{ + static constexpr const char *Description = + "Draws a triangle but using different kinds of vertex attributes, including doubles, arrays, " + "and matrices."; + + struct vertin + { + int16_t i16[4]; + uint16_t u16[4]; + double df[2]; + float arr0[2]; + float arr1[2]; + float arr2[2]; + float mat0[2]; + float mat1[2]; + }; + + std::string vertex = R"EOSHADER( +#version 450 core + +layout(location = 0) in vec4 InSNorm; +layout(location = 1) in vec4 InUNorm; +layout(location = 2) in uvec4 InUInt; +layout(location = 3) in dvec2 InDouble; +layout(location = 4) in vec2 InArray[3]; +layout(location = 7) in mat2x2 InMatrix; + +layout(location = 0) out vec4 OutSNorm; +layout(location = 1) out vec4 OutUNorm; +layout(location = 2) out uvec4 OutUInt; +layout(location = 3) out dvec2 OutDouble; +layout(location = 4) out vec2 OutArray[3]; +layout(location = 7) out mat2x2 OutMatrix; + +void main() +{ + const vec4 verts[3] = vec4[3](vec4(-0.5, 0.5, 0.0, 1.0), vec4(0.0, -0.5, 0.0, 1.0), + vec4(0.5, 0.5, 0.0, 1.0)); + + gl_Position = verts[gl_VertexID]; + + OutSNorm = InSNorm; + OutDouble = InDouble; + OutUInt = InUInt; + OutUNorm = InUNorm; + OutArray = InArray; + OutMatrix = InMatrix; +} + +)EOSHADER"; + + std::string pixel = R"EOSHADER( +#version 450 core + +layout(location = 0) in vec4 InSNorm; +layout(location = 1) in vec4 InUNorm; +layout(location = 2) flat in uvec4 InUInt; +layout(location = 3) flat in dvec2 InDouble; +layout(location = 4) in vec2 InArray[3]; +layout(location = 7) in mat2x2 InMatrix; + +layout(location = 0, index = 0) out vec4 Color; + +void main() +{ + Color = vec4(0, 1.0f, 0, 1); + + // check values came through correctly + + // SNorm should be in [-1, 1] + if(clamp(InSNorm, -1.0, 1.0) != InSNorm) + Color = vec4(0.1f, 0, 0, 1); + + // UNorm should be in [0, 1] + if(clamp(InUNorm, 0.0, 1.0) != InUNorm) + Color = vec4(0.2f, 0, 0, 1); + + // Similar for UInt + if(InUInt.x > 65535 || InUInt.y > 65535 || InUInt.z > 65535 || InUInt.w > 65535) + Color = vec4(0.3f, 0, 0, 1); + + // doubles are all in range [-10, 10] + if(clamp(InDouble, -10.0, 10.0) != InDouble) + Color = vec4(0.4f, 0, 0, 1); +} + +)EOSHADER"; + + std::string geom = R"EOSHADER( +#version 450 core + +layout(triangles) in; +layout(triangle_strip, max_vertices = 3) out; + +layout(location = 0) in vec4 InSNorm[3]; +layout(location = 1) in vec4 InUNorm[3]; +layout(location = 2) in uvec4 InUInt[3]; +layout(location = 3) in dvec2 InDouble[3]; +layout(location = 4) in vec2 InArray[3][3]; +layout(location = 7) in mat2x2 InMatrix[3]; + +layout(location = 0) out vec4 OutSNorm; +layout(location = 1) out vec4 OutUNorm; +layout(location = 2) out uvec4 OutUInt; +layout(location = 3) out dvec2 OutDouble; +layout(location = 4) out vec2 OutArray[3]; +layout(location = 7) out mat2x2 OutMatrix; + +void main() +{ + for(int i = 0; i < 3; i++) + { + gl_Position = vec4(gl_in[i].gl_Position.yx, 0.4f, 1.2f); + + OutSNorm = InSNorm[i]; + OutDouble = InDouble[i]; + OutUInt = InUInt[i]; + OutUNorm = InUNorm[i]; + OutArray = InArray[i]; + OutMatrix = InMatrix[i]; + + EmitVertex(); + } + EndPrimitive(); +} + +)EOSHADER"; + + int main() + { + // initialise, create window, create context, etc + if(!Init()) + return 3; + + GLuint vao = MakeVAO(); + glBindVertexArray(vao); + + vertin triangle[] = { + { + {32767, -32768, 32767, -32767}, + {12345, 6789, 1234, 567}, + {9.8765432109, -5.6789012345}, + {1.0f, 2.0f}, + {3.0f, 4.0f}, + {5.0f, 6.0f}, + {7.0, 8.0f}, + {9.0f, 10.0f}, + }, + { + {32766, -32766, 16000, -16000}, + {56, 7890, 123, 4567}, + {-7.89012345678, 6.54321098765}, + {11.0f, 12.0f}, + {13.0f, 14.0f}, + {15.0f, 16.0f}, + {17.0, 18.0f}, + {19.0f, 20.0f}, + }, + { + {5, -5, 0, 0}, + {8765, 43210, 987, 65432}, + {0.1234567890123, 4.5678901234}, + {21.0f, 22.0f}, + {23.0f, 24.0f}, + {25.0f, 26.0f}, + {27.0, 28.0f}, + {29.0f, 30.0f}, + }, + }; + + GLuint vb = MakeBuffer(); + glBindBuffer(GL_ARRAY_BUFFER, vb); + glBufferStorage(GL_ARRAY_BUFFER, sizeof(triangle), triangle, 0); + + // R16G16B16A16_SNORM + glVertexAttribPointer(0, 4, GL_SHORT, GL_TRUE, sizeof(vertin), (void *)offsetof(vertin, i16)); + // R16G16B16A16_UNORM + glVertexAttribPointer(1, 4, GL_UNSIGNED_SHORT, GL_TRUE, sizeof(vertin), + (void *)offsetof(vertin, u16)); + // R16G16B16A16_UINT + glVertexAttribIPointer(2, 4, GL_UNSIGNED_SHORT, sizeof(vertin), (void *)offsetof(vertin, u16)); + + // R64G64_FLOAT + glVertexAttribLPointer(3, 2, GL_DOUBLE, sizeof(vertin), (void *)offsetof(vertin, df)); + + // Array[] + glVertexAttribPointer(4, 2, GL_FLOAT, GL_FALSE, sizeof(vertin), (void *)offsetof(vertin, arr0)); + glVertexAttribPointer(5, 2, GL_FLOAT, GL_FALSE, sizeof(vertin), (void *)offsetof(vertin, arr1)); + glVertexAttribPointer(6, 2, GL_FLOAT, GL_FALSE, sizeof(vertin), (void *)offsetof(vertin, arr2)); + + // Matrix + glVertexAttribPointer(7, 2, GL_FLOAT, GL_FALSE, sizeof(vertin), (void *)offsetof(vertin, mat0)); + glVertexAttribPointer(8, 2, GL_FLOAT, GL_FALSE, sizeof(vertin), (void *)offsetof(vertin, mat1)); + + glEnableVertexAttribArray(0); + glEnableVertexAttribArray(1); + glEnableVertexAttribArray(2); + glEnableVertexAttribArray(3); + glEnableVertexAttribArray(4); + glEnableVertexAttribArray(5); + glEnableVertexAttribArray(6); + glEnableVertexAttribArray(7); + glEnableVertexAttribArray(8); + + GLuint program = MakeProgram(vertex, pixel, geom); + + while(Running()) + { + float col[] = {0.4f, 0.5f, 0.6f, 1.0f}; + glClearBufferfv(GL_COLOR, 0, col); + + glBindVertexArray(vao); + + glUseProgram(program); + + glViewport(0, 0, GLsizei(screenWidth), GLsizei(screenHeight)); + + glDrawArrays(GL_TRIANGLES, 0, 3); + + Present(); + } + + return 0; + } +}; + +REGISTER_TEST(); diff --git a/util/test/demos/vk/vk_awkward_triangle.cpp b/util/test/demos/vk/vk_awkward_triangle.cpp deleted file mode 100644 index 7b84457a9..000000000 --- a/util/test/demos/vk/vk_awkward_triangle.cpp +++ /dev/null @@ -1,173 +0,0 @@ -/****************************************************************************** - * The MIT License (MIT) - * - * Copyright (c) 2018-2019 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" - -TEST(VK_Awkward_Triangle, VulkanGraphicsTest) -{ - static constexpr const char *Description = - "Draws a triangle but using vertex buffers in formats that only support VBs and not " - "any other type of buffer use (i.e. requiring manual decode)"; - - struct vertin - { - int16_t pos[3]; - uint16_t col[4]; - double uv[3]; - }; - - std::string common = R"EOSHADER( - -#version 420 core - -struct v2f -{ - vec4 pos; - vec4 col; - vec4 uv; -}; - -)EOSHADER"; - - std::string vertex = R"EOSHADER( - -layout(location = 0) in vec3 Position; -layout(location = 1) in vec4 Color; -layout(location = 2) in dvec3 UV; - -layout(location = 0) out v2f vertOut; - -void main() -{ - vertOut.pos = vec4(Position.xyz, 1); - gl_Position = vertOut.pos; - vertOut.col = Color; - vertOut.uv = vec4(UV.xyz, 1); -} - -)EOSHADER"; - - std::string pixel = R"EOSHADER( - -layout(location = 0) in v2f vertIn; - -layout(location = 0, index = 0) out vec4 Color; - -void main() -{ - Color = vertIn.col/65535.0f; -} - -)EOSHADER"; - - int main() - { - features.shaderFloat64 = true; - - // initialise, create window, create context, etc - if(!Init()) - return 3; - - VkPipelineLayout layout = createPipelineLayout(vkh::PipelineLayoutCreateInfo()); - - vkh::GraphicsPipelineCreateInfo pipeCreateInfo; - - pipeCreateInfo.layout = layout; - pipeCreateInfo.renderPass = swapRenderPass; - - pipeCreateInfo.vertexInputState.vertexBindingDescriptions = {vkh::vertexBind(0, vertin)}; - - pipeCreateInfo.vertexInputState.vertexAttributeDescriptions = { - vkh::vertexAttrFormatted(0, 0, vertin, pos, VK_FORMAT_R16G16B16_SNORM), - vkh::vertexAttrFormatted(1, 0, vertin, col, VK_FORMAT_R16G16B16A16_USCALED), - vkh::vertexAttrFormatted(2, 0, vertin, uv, VK_FORMAT_R64G64B64_SFLOAT), - }; - - pipeCreateInfo.stages = { - CompileShaderModule(common + vertex, ShaderLang::glsl, ShaderStage::vert, "main"), - CompileShaderModule(common + pixel, ShaderLang::glsl, ShaderStage::frag, "main"), - }; - - VkPipeline pipe = createGraphicsPipeline(pipeCreateInfo); - - vertin triangle[] = { - { - {-16000, 16000, 0}, - {51515, 2945, 5893, 492}, - {8.2645198430, 1.8813003880, -3.96710837683597}, - }, - { - {0, -16000, 0}, {1786, 32356, 8394, 1835}, {1.646793901, 6.86148531, -1.19476386246190}, - }, - { - {16000, 16000, 0}, {8523, 9924, 49512, 3942}, {5.206423972, 9.58934003, -5.408522446462}, - }, - }; - - AllocatedBuffer vb(allocator, - vkh::BufferCreateInfo(sizeof(triangle), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | - VK_BUFFER_USAGE_TRANSFER_DST_BIT), - VmaAllocationCreateInfo({0, VMA_MEMORY_USAGE_CPU_TO_GPU})); - - vb.upload(triangle); - - 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(swapRenderPass, swapFramebuffers[swapIndex], scissor), - VK_SUBPASS_CONTENTS_INLINE); - - vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, pipe); - vkCmdSetViewport(cmd, 0, 1, &viewport); - vkCmdSetScissor(cmd, 0, 1, &scissor); - vkh::cmdBindVertexBuffers(cmd, 0, {vb.buffer}, {0}); - vkCmdDraw(cmd, 3, 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(); \ No newline at end of file diff --git a/util/test/demos/vk/vk_vertex_attr_zoo.cpp b/util/test/demos/vk/vk_vertex_attr_zoo.cpp new file mode 100644 index 000000000..f67bed390 --- /dev/null +++ b/util/test/demos/vk/vk_vertex_attr_zoo.cpp @@ -0,0 +1,291 @@ +/****************************************************************************** + * The MIT License (MIT) + * + * Copyright (c) 2018-2019 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" + +TEST(VK_Vertex_Attr_Zoo, VulkanGraphicsTest) +{ + static constexpr const char *Description = + "Draws a triangle but using different kinds of vertex attributes, including doubles, arrays, " + "matrices, and formats that require manual decode as they are vertex-buffer exclusive on " + "some hardware such as USCALED."; + + struct vertin + { + int16_t i16[4]; + uint16_t u16[4]; + double df[2]; + float arr0[2]; + float arr1[2]; + float arr2[2]; + float mat0[2]; + float mat1[2]; + }; + + std::string vertex = R"EOSHADER( +#version 450 core + +layout(location = 0) in vec4 InSNorm; +layout(location = 1) in vec4 InUNorm; +layout(location = 2) in vec4 InUScaled; +layout(location = 3) in uvec4 InUInt; +layout(location = 4) in dvec2 InDouble; +layout(location = 5) in vec2 InArray[3]; +layout(location = 8) in mat2x2 InMatrix; + +layout(location = 0) out vec4 OutSNorm; +layout(location = 1) out vec4 OutUNorm; +layout(location = 2) out vec4 OutUScaled; +layout(location = 3) out uvec4 OutUInt; +layout(location = 4) out dvec2 OutDouble; +layout(location = 5) out vec2 OutArray[3]; +layout(location = 8) out mat2x2 OutMatrix; + +void main() +{ + const vec4 verts[3] = vec4[3](vec4(-0.5, 0.5, 0.0, 1.0), vec4(0.0, -0.5, 0.0, 1.0), + vec4(0.5, 0.5, 0.0, 1.0)); + + gl_Position = verts[gl_VertexIndex]; + + OutSNorm = InSNorm; + OutUScaled = InUScaled; + OutDouble = InDouble; + OutUInt = InUInt; + OutUNorm = InUNorm; + OutArray = InArray; + OutMatrix = InMatrix; +} + +)EOSHADER"; + + std::string pixel = R"EOSHADER( +#version 450 core + +layout(location = 0) in vec4 InSNorm; +layout(location = 1) in vec4 InUNorm; +layout(location = 2) in vec4 InUScaled; +layout(location = 3) flat in uvec4 InUInt; +layout(location = 4) flat in dvec2 InDouble; +layout(location = 5) in vec2 InArray[3]; +layout(location = 8) in mat2x2 InMatrix; + +layout(location = 0, index = 0) out vec4 Color; + +void main() +{ + Color = vec4(0, 1.0f, 0, 1); + + // check values came through correctly + + // SNorm should be in [-1, 1] + if(clamp(InSNorm, -1.0, 1.0) != InSNorm) + Color = vec4(0.1f, 0, 0, 1); + + // UNorm should be in [0, 1] + if(clamp(InUNorm, 0.0, 1.0) != InUNorm) + Color = vec4(0.2f, 0, 0, 1); + + // UScaled was sourced from 16-bit and is non-zero so should be in that range + if(clamp(InUScaled, 1.0, 65535.0) != InUScaled) + Color = vec4(0.3f, 0, 0, 1); + + // Similar for UInt + if(InUInt.x > 65535 || InUInt.y > 65535 || InUInt.z > 65535 || InUInt.w > 65535) + Color = vec4(0.4f, 0, 0, 1); + + // doubles are all in range [-10, 10] + if(clamp(InDouble, -10.0, 10.0) != InDouble) + Color = vec4(0.5f, 0, 0, 1); +} + +)EOSHADER"; + + std::string geom = R"EOSHADER( +#version 450 core + +layout(triangles) in; +layout(triangle_strip, max_vertices = 3) out; + +layout(location = 0) in vec4 InSNorm[3]; +layout(location = 1) in vec4 InUNorm[3]; +layout(location = 2) in vec4 InUScaled[3]; +layout(location = 3) in uvec4 InUInt[3]; +layout(location = 4) in dvec2 InDouble[3]; +layout(location = 5) in vec2 InArray[3][3]; +layout(location = 8) in mat2x2 InMatrix[3]; + +layout(location = 0) out vec4 OutSNorm; +layout(location = 1) out vec4 OutUNorm; +layout(location = 2) out vec4 OutUScaled; +layout(location = 3) out uvec4 OutUInt; +layout(location = 4) out dvec2 OutDouble; +layout(location = 5) out vec2 OutArray[3]; +layout(location = 8) out mat2x2 OutMatrix; + +void main() +{ + for(int i = 0; i < 3; i++) + { + gl_Position = vec4(gl_in[i].gl_Position.yx, 0.4f, 1.2f); + + OutSNorm = InSNorm[i]; + OutUScaled = InUScaled[i]; + OutDouble = InDouble[i]; + OutUInt = InUInt[i]; + OutUNorm = InUNorm[i]; + OutArray = InArray[i]; + OutMatrix = InMatrix[i]; + + EmitVertex(); + } + EndPrimitive(); +} + +)EOSHADER"; + + void Prepare(int argc, char **argv) + { + // we could have fallbacks for these, but they're supported everywhere we run our tests + features.shaderFloat64 = VK_TRUE; + features.geometryShader = VK_TRUE; + + VulkanGraphicsTest::Prepare(argc, argv); + } + + int main() + { + // initialise, create window, create context, etc + if(!Init()) + return 3; + + VkPipelineLayout layout = createPipelineLayout(vkh::PipelineLayoutCreateInfo()); + + vkh::GraphicsPipelineCreateInfo pipeCreateInfo; + + pipeCreateInfo.layout = layout; + pipeCreateInfo.renderPass = swapRenderPass; + + pipeCreateInfo.vertexInputState.vertexBindingDescriptions = {vkh::vertexBind(0, vertin)}; + + pipeCreateInfo.vertexInputState.vertexAttributeDescriptions = { + vkh::vertexAttrFormatted(0, 0, vertin, i16, VK_FORMAT_R16G16B16A16_SNORM), + vkh::vertexAttrFormatted(1, 0, vertin, u16, VK_FORMAT_R16G16B16A16_UNORM), + vkh::vertexAttrFormatted(2, 0, vertin, u16, VK_FORMAT_R16G16B16A16_USCALED), + vkh::vertexAttrFormatted(3, 0, vertin, u16, VK_FORMAT_R16G16B16A16_UINT), + vkh::vertexAttrFormatted(4, 0, vertin, df, VK_FORMAT_R64G64_SFLOAT), + vkh::vertexAttrFormatted(5, 0, vertin, arr0, VK_FORMAT_R32G32_SFLOAT), + vkh::vertexAttrFormatted(6, 0, vertin, arr1, VK_FORMAT_R32G32_SFLOAT), + vkh::vertexAttrFormatted(7, 0, vertin, arr2, VK_FORMAT_R32G32_SFLOAT), + vkh::vertexAttrFormatted(8, 0, vertin, mat0, VK_FORMAT_R32G32_SFLOAT), + vkh::vertexAttrFormatted(9, 0, vertin, mat1, VK_FORMAT_R32G32_SFLOAT), + }; + + pipeCreateInfo.stages = { + CompileShaderModule(vertex, ShaderLang::glsl, ShaderStage::vert, "main"), + CompileShaderModule(pixel, ShaderLang::glsl, ShaderStage::frag, "main"), + CompileShaderModule(geom, ShaderLang::glsl, ShaderStage::geom, "main"), + }; + + VkPipeline pipe = createGraphicsPipeline(pipeCreateInfo); + + vertin triangle[] = { + { + {32767, -32768, 32767, -32767}, + {12345, 6789, 1234, 567}, + {9.8765432109, -5.6789012345}, + {1.0f, 2.0f}, + {3.0f, 4.0f}, + {5.0f, 6.0f}, + {7.0, 8.0f}, + {9.0f, 10.0f}, + }, + { + {32766, -32766, 16000, -16000}, + {56, 7890, 123, 4567}, + {-7.89012345678, 6.54321098765}, + {11.0f, 12.0f}, + {13.0f, 14.0f}, + {15.0f, 16.0f}, + {17.0, 18.0f}, + {19.0f, 20.0f}, + }, + { + {5, -5, 0, 0}, + {8765, 43210, 987, 65432}, + {0.1234567890123, 4.5678901234}, + {21.0f, 22.0f}, + {23.0f, 24.0f}, + {25.0f, 26.0f}, + {27.0, 28.0f}, + {29.0f, 30.0f}, + }, + }; + + AllocatedBuffer vb(allocator, + vkh::BufferCreateInfo(sizeof(triangle), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | + VK_BUFFER_USAGE_TRANSFER_DST_BIT), + VmaAllocationCreateInfo({0, VMA_MEMORY_USAGE_CPU_TO_GPU})); + + vb.upload(triangle); + + 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(swapRenderPass, swapFramebuffers[swapIndex], scissor), + VK_SUBPASS_CONTENTS_INLINE); + + vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, pipe); + vkCmdSetViewport(cmd, 0, 1, &viewport); + vkCmdSetScissor(cmd, 0, 1, &scissor); + vkh::cmdBindVertexBuffers(cmd, 0, {vb.buffer}, {0}); + vkCmdDraw(cmd, 3, 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(); \ No newline at end of file diff --git a/util/test/tests/D3D11/D3D11_Vertex_Attr_Zoo.py b/util/test/tests/D3D11/D3D11_Vertex_Attr_Zoo.py new file mode 100644 index 000000000..791ac282c --- /dev/null +++ b/util/test/tests/D3D11/D3D11_Vertex_Attr_Zoo.py @@ -0,0 +1,94 @@ +import copy +import rdtest +import renderdoc as rd + + +class D3D11_Vertex_Attr_Zoo(rdtest.TestCase): + demos_test_name = 'D3D11_Vertex_Attr_Zoo' + + def check_capture(self): + draw = self.find_draw("Draw") + + self.check(draw is not None) + + self.controller.SetFrameEvent(draw.eventId, False) + + # Make an output so we can pick pixels + out: rd.ReplayOutput = self.controller.CreateOutput(rd.CreateHeadlessWindowingData(100, 100), rd.ReplayOutputType.Texture) + + self.check(out is not None) + + ref = { + 0: { + 'SNORM': [1.0, -1.0, 1.0, -1.0], + 'UNORM': [12345.0/65535.0, 6789.0/65535.0, 1234.0/65535.0, 567.0/65535.0], + 'UINT': [12345, 6789, 1234, 567], + 'ARRAY0': [1.0, 2.0], + 'ARRAY1': [3.0, 4.0], + 'ARRAY2': [5.0, 6.0], + 'MATRIX0': [7.0, 8.0], + 'MATRIX1': [9.0, 10.0], + }, + 1: { + 'SNORM': [32766.0/32767.0, -32766.0/32767.0, 16000.0/32767.0, -16000.0/32767.0], + 'UNORM': [56.0/65535.0, 7890.0/65535.0, 123.0/65535.0, 4567.0/65535.0], + 'UINT': [56, 7890, 123, 4567], + 'ARRAY0': [11.0, 12.0], + 'ARRAY1': [13.0, 14.0], + 'ARRAY2': [15.0, 16.0], + 'MATRIX0': [17.0, 18.0], + 'MATRIX1': [19.0, 20.0], + }, + 2: { + 'SNORM': [5.0/32767.0, -5.0/32767.0, 0.0, 0.0], + 'UNORM': [8765.0/65535.0, 43210.0/65535.0, 987.0/65535.0, 65432.0/65535.0], + 'UINT': [8765, 43210, 987, 65432], + 'ARRAY0': [21.0, 22.0], + 'ARRAY1': [23.0, 24.0], + 'ARRAY2': [25.0, 26.0], + 'MATRIX0': [27.0, 28.0], + 'MATRIX1': [29.0, 30.0], + }, + } + + in_ref = copy.deepcopy(ref) + vsout_ref = copy.deepcopy(ref) + gsout_ref = ref + + vsout_ref[0]['SV_Position'] = [-0.5, 0.5, 0.0, 1.0] + gsout_ref[0]['SV_Position'] = [0.5, -0.5, 0.4, 1.2] + + vsout_ref[1]['SV_Position'] = [0.0, -0.5, 0.0, 1.0] + gsout_ref[1]['SV_Position'] = [-0.5, 0.0, 0.4, 1.2] + + vsout_ref[2]['SV_Position'] = [0.5, 0.5, 0.0, 1.0] + gsout_ref[2]['SV_Position'] = [0.5, 0.5, 0.4, 1.2] + + self.check_mesh_data(in_ref, self.get_vsin(draw)) + rdtest.log.success("Vertex input data is as expected") + + self.check_mesh_data(vsout_ref, self.get_postvs(rd.MeshDataStage.VSOut)) + + rdtest.log.success("Vertex output data is as expected") + + self.check_mesh_data(gsout_ref, self.get_postvs(rd.MeshDataStage.GSOut)) + + rdtest.log.success("Geometry output data is as expected") + + pipe: rd.PipeState = self.controller.GetPipelineState() + + tex = rd.TextureDisplay() + tex.resourceId = pipe.GetOutputTargets()[0].resourceId + out.SetTextureDisplay(tex) + + texdetails = self.get_texture(tex.resourceId) + + picked: rd.PixelValue = out.PickPixel(tex.resourceId, False, + int(texdetails.width / 2), int(texdetails.height / 2), 0, 0, 0) + + if not rdtest.value_compare(picked.floatValue, [0.0, 1.0, 0.0, 1.0]): + raise rdtest.TestFailureException("Picked value {} doesn't match expectation".format(picked.floatValue)) + + rdtest.log.success("Triangle picked value is as expected") + + out.Shutdown() diff --git a/util/test/tests/D3D12/D3D12_Vertex_Attr_Zoo.py b/util/test/tests/D3D12/D3D12_Vertex_Attr_Zoo.py new file mode 100644 index 000000000..69b0cb08e --- /dev/null +++ b/util/test/tests/D3D12/D3D12_Vertex_Attr_Zoo.py @@ -0,0 +1,94 @@ +import copy +import rdtest +import renderdoc as rd + + +class D3D12_Vertex_Attr_Zoo(rdtest.TestCase): + demos_test_name = 'D3D12_Vertex_Attr_Zoo' + + def check_capture(self): + draw = self.find_draw("Draw") + + self.check(draw is not None) + + self.controller.SetFrameEvent(draw.eventId, False) + + # Make an output so we can pick pixels + out: rd.ReplayOutput = self.controller.CreateOutput(rd.CreateHeadlessWindowingData(100, 100), rd.ReplayOutputType.Texture) + + self.check(out is not None) + + ref = { + 0: { + 'SNORM': [1.0, -1.0, 1.0, -1.0], + 'UNORM': [12345.0/65535.0, 6789.0/65535.0, 1234.0/65535.0, 567.0/65535.0], + 'UINT': [12345, 6789, 1234, 567], + 'ARRAY0': [1.0, 2.0], + 'ARRAY1': [3.0, 4.0], + 'ARRAY2': [5.0, 6.0], + 'MATRIX0': [7.0, 8.0], + 'MATRIX1': [9.0, 10.0], + }, + 1: { + 'SNORM': [32766.0/32767.0, -32766.0/32767.0, 16000.0/32767.0, -16000.0/32767.0], + 'UNORM': [56.0/65535.0, 7890.0/65535.0, 123.0/65535.0, 4567.0/65535.0], + 'UINT': [56, 7890, 123, 4567], + 'ARRAY0': [11.0, 12.0], + 'ARRAY1': [13.0, 14.0], + 'ARRAY2': [15.0, 16.0], + 'MATRIX0': [17.0, 18.0], + 'MATRIX1': [19.0, 20.0], + }, + 2: { + 'SNORM': [5.0/32767.0, -5.0/32767.0, 0.0, 0.0], + 'UNORM': [8765.0/65535.0, 43210.0/65535.0, 987.0/65535.0, 65432.0/65535.0], + 'UINT': [8765, 43210, 987, 65432], + 'ARRAY0': [21.0, 22.0], + 'ARRAY1': [23.0, 24.0], + 'ARRAY2': [25.0, 26.0], + 'MATRIX0': [27.0, 28.0], + 'MATRIX1': [29.0, 30.0], + }, + } + + in_ref = copy.deepcopy(ref) + vsout_ref = copy.deepcopy(ref) + gsout_ref = ref + + vsout_ref[0]['SV_Position'] = [-0.5, 0.5, 0.0, 1.0] + gsout_ref[0]['SV_Position'] = [0.5, -0.5, 0.4, 1.2] + + vsout_ref[1]['SV_Position'] = [0.0, -0.5, 0.0, 1.0] + gsout_ref[1]['SV_Position'] = [-0.5, 0.0, 0.4, 1.2] + + vsout_ref[2]['SV_Position'] = [0.5, 0.5, 0.0, 1.0] + gsout_ref[2]['SV_Position'] = [0.5, 0.5, 0.4, 1.2] + + self.check_mesh_data(in_ref, self.get_vsin(draw)) + rdtest.log.success("Vertex input data is as expected") + + self.check_mesh_data(vsout_ref, self.get_postvs(rd.MeshDataStage.VSOut)) + + rdtest.log.success("Vertex output data is as expected") + + self.check_mesh_data(gsout_ref, self.get_postvs(rd.MeshDataStage.GSOut)) + + rdtest.log.success("Geometry output data is as expected") + + pipe: rd.PipeState = self.controller.GetPipelineState() + + tex = rd.TextureDisplay() + tex.resourceId = pipe.GetOutputTargets()[0].resourceId + out.SetTextureDisplay(tex) + + texdetails = self.get_texture(tex.resourceId) + + picked: rd.PixelValue = out.PickPixel(tex.resourceId, False, + int(texdetails.width / 2), int(texdetails.height / 2), 0, 0, 0) + + if not rdtest.value_compare(picked.floatValue, [0.0, 1.0, 0.0, 1.0]): + raise rdtest.TestFailureException("Picked value {} doesn't match expectation".format(picked.floatValue)) + + rdtest.log.success("Triangle picked value is as expected") + + out.Shutdown() diff --git a/util/test/tests/GL/GL_Vertex_Attr_Zoo.py b/util/test/tests/GL/GL_Vertex_Attr_Zoo.py new file mode 100644 index 000000000..d620243cc --- /dev/null +++ b/util/test/tests/GL/GL_Vertex_Attr_Zoo.py @@ -0,0 +1,110 @@ +import copy +import rdtest +import renderdoc as rd + + +class GL_Vertex_Attr_Zoo(rdtest.TestCase): + demos_test_name = 'GL_Vertex_Attr_Zoo' + + def check_capture(self): + draw = self.find_draw("Draw") + + self.check(draw is not None) + + self.controller.SetFrameEvent(draw.eventId, False) + + # Make an output so we can pick pixels + out: rd.ReplayOutput = self.controller.CreateOutput(rd.CreateHeadlessWindowingData(100, 100), rd.ReplayOutputType.Texture) + + self.check(out is not None) + + ref = { + 0: { + 'SNorm': [1.0, -1.0, 1.0, -1.0], + 'UNorm': [12345.0/65535.0, 6789.0/65535.0, 1234.0/65535.0, 567.0/65535.0], + 'UInt': [12345, 6789, 1234, 567], + 'Double': [9.8765432109, -5.6789012345], + 'Array[0]': [1.0, 2.0], + 'Array[1]': [3.0, 4.0], + 'Array[2]': [5.0, 6.0], + 'Matrix:row0': [7.0, 8.0], + 'Matrix:row1': [9.0, 10.0], + }, + 1: { + 'SNorm': [32766.0/32767.0, -32766.0/32767.0, 16000.0/32767.0, -16000.0/32767.0], + 'UNorm': [56.0/65535.0, 7890.0/65535.0, 123.0/65535.0, 4567.0/65535.0], + 'UInt': [56, 7890, 123, 4567], + 'Double': [-7.89012345678, 6.54321098765], + 'Array[0]': [11.0, 12.0], + 'Array[1]': [13.0, 14.0], + 'Array[2]': [15.0, 16.0], + 'Matrix:row0': [17.0, 18.0], + 'Matrix:row1': [19.0, 20.0], + }, + 2: { + 'SNorm': [5.0/32767.0, -5.0/32767.0, 0.0, 0.0], + 'UNorm': [8765.0/65535.0, 43210.0/65535.0, 987.0/65535.0, 65432.0/65535.0], + 'UInt': [8765, 43210, 987, 65432], + 'Double': [0.1234567890123, 4.5678901234], + 'Array[0]': [21.0, 22.0], + 'Array[1]': [23.0, 24.0], + 'Array[2]': [25.0, 26.0], + 'Matrix:row0': [27.0, 28.0], + 'Matrix:row1': [29.0, 30.0], + }, + } + + # Copy the ref values and prepend 'In' + in_ref = {} + for idx in ref: + in_ref[idx] = {} + for key in ref[idx]: + in_ref[idx]['In' + key] = ref[idx][key] + + # Copy the ref values and prepend 'Out' + out_ref = {} + for idx in ref: + out_ref[idx] = {} + for key in ref[idx]: + out_ref[idx]['Out' + key] = ref[idx][key] + + vsout_ref = copy.deepcopy(out_ref) + gsout_ref = out_ref + + vsout_ref[0]['gl_Position'] = [-0.5, 0.5, 0.0, 1.0] + gsout_ref[0]['gl_Position'] = [0.5, -0.5, 0.4, 1.2] + + vsout_ref[1]['gl_Position'] = [0.0, -0.5, 0.0, 1.0] + gsout_ref[1]['gl_Position'] = [-0.5, 0.0, 0.4, 1.2] + + vsout_ref[2]['gl_Position'] = [0.5, 0.5, 0.0, 1.0] + gsout_ref[2]['gl_Position'] = [0.5, 0.5, 0.4, 1.2] + + self.check_mesh_data(in_ref, self.get_vsin(draw)) + rdtest.log.success("Vertex input data is as expected") + + self.check_mesh_data(vsout_ref, self.get_postvs(rd.MeshDataStage.VSOut)) + + rdtest.log.success("Vertex output data is as expected") + + self.check_mesh_data(gsout_ref, self.get_postvs(rd.MeshDataStage.GSOut)) + + rdtest.log.success("Geometry output data is as expected") + + pipe: rd.PipeState = self.controller.GetPipelineState() + + tex = rd.TextureDisplay() + tex.resourceId = pipe.GetOutputTargets()[0].resourceId + out.SetTextureDisplay(tex) + + texdetails = self.get_texture(tex.resourceId) + + picked: rd.PixelValue = out.PickPixel(tex.resourceId, False, + int(texdetails.width / 2), int(texdetails.height / 2), 0, 0, 0) + + if not rdtest.value_compare(picked.floatValue, [0.0, 1.0, 0.0, 1.0]): + raise rdtest.TestFailureException("Picked value {} doesn't match expectation".format(picked.floatValue)) + + rdtest.log.success("Triangle picked value is as expected") + + out.Shutdown() diff --git a/util/test/tests/Vulkan/VK_Vertex_Attr_Zoo.py b/util/test/tests/Vulkan/VK_Vertex_Attr_Zoo.py new file mode 100644 index 000000000..9495153da --- /dev/null +++ b/util/test/tests/Vulkan/VK_Vertex_Attr_Zoo.py @@ -0,0 +1,118 @@ +import copy +import rdtest +import renderdoc as rd + + +class VK_Vertex_Attr_Zoo(rdtest.TestCase): + demos_test_name = 'VK_Vertex_Attr_Zoo' + + def check_capture(self): + draw = self.find_draw("Draw") + + self.check(draw is not None) + + self.controller.SetFrameEvent(draw.eventId, False) + + # Make an output so we can pick pixels + out: rd.ReplayOutput = self.controller.CreateOutput(rd.CreateHeadlessWindowingData(100, 100), rd.ReplayOutputType.Texture) + + self.check(out is not None) + + ref = { + 0: { + 'SNorm': [1.0, -1.0, 1.0, -1.0], + 'UNorm': [12345.0/65535.0, 6789.0/65535.0, 1234.0/65535.0, 567.0/65535.0], + 'UScaled': [12345.0, 6789.0, 1234.0, 567.0], + 'UInt': [12345, 6789, 1234, 567], + 'Double': [9.8765432109, -5.6789012345], + 'Array[0]': [1.0, 2.0], + 'Array[1]': [3.0, 4.0], + 'Array[2]': [5.0, 6.0], + 'Matrix:row0': [7.0, 8.0], + 'Matrix:row1': [9.0, 10.0], + }, + 1: { + 'SNorm': [32766.0/32767.0, -32766.0/32767.0, 16000.0/32767.0, -16000.0/32767.0], + 'UNorm': [56.0/65535.0, 7890.0/65535.0, 123.0/65535.0, 4567.0/65535.0], + 'UScaled': [56.0, 7890.0, 123.0, 4567.0], + 'UInt': [56, 7890, 123, 4567], + 'Double': [-7.89012345678, 6.54321098765], + 'Array[0]': [11.0, 12.0], + 'Array[1]': [13.0, 14.0], + 'Array[2]': [15.0, 16.0], + 'Matrix:row0': [17.0, 18.0], + 'Matrix:row1': [19.0, 20.0], + }, + 2: { + 'SNorm': [5.0/32767.0, -5.0/32767.0, 0.0, 0.0], + 'UNorm': [8765.0/65535.0, 43210.0/65535.0, 987.0/65535.0, 65432.0/65535.0], + 'UScaled': [8765.0, 43210.0, 987.0, 65432.0], + 'UInt': [8765, 43210, 987, 65432], + 'Double': [0.1234567890123, 4.5678901234], + 'Array[0]': [21.0, 22.0], + 'Array[1]': [23.0, 24.0], + 'Array[2]': [25.0, 26.0], + 'Matrix:row0': [27.0, 28.0], + 'Matrix:row1': [29.0, 30.0], + }, + } + + # Copy the ref values and prepend 'In' + in_ref = {} + for idx in ref: + in_ref[idx] = {} + for key in ref[idx]: + in_ref[idx]['In' + key] = ref[idx][key] + + # Copy the ref values and prepend 'Out' + out_ref = {} + for idx in ref: + out_ref[idx] = {} + for key in ref[idx]: + out_ref[idx]['Out' + key] = ref[idx][key] + + vsout_ref = copy.deepcopy(out_ref) + gsout_ref = out_ref + + vsout_ref[0]['gl_PerVertex.gl_Position'] = [-0.5, 0.5, 0.0, 1.0] + gsout_ref[0]['gl_PerVertex.gl_Position'] = [0.5, -0.5, 0.4, 1.2] + + vsout_ref[1]['gl_PerVertex.gl_Position'] = [0.0, -0.5, 0.0, 1.0] + gsout_ref[1]['gl_PerVertex.gl_Position'] = [-0.5, 0.0, 0.4, 1.2] + + vsout_ref[2]['gl_PerVertex.gl_Position'] = [0.5, 0.5, 0.0, 1.0] + gsout_ref[2]['gl_PerVertex.gl_Position'] = [0.5, 0.5, 0.4, 1.2] + + self.check_mesh_data(in_ref, self.get_vsin(draw)) + rdtest.log.success("Vertex input data is as expected") + + self.check_mesh_data(vsout_ref, self.get_postvs(rd.MeshDataStage.VSOut)) + + rdtest.log.success("Vertex output data is as expected") + + # This is optional to account for drivers without XFB + postgs_data = self.get_postvs(rd.MeshDataStage.GSOut) + if len(postgs_data) > 0: + self.check_mesh_data(gsout_ref, postgs_data) + + rdtest.log.success("Geometry output data is as expected") + else: + rdtest.log.print("Geometry output not tested") + + pipe: rd.PipeState = self.controller.GetPipelineState() + + tex = rd.TextureDisplay() + tex.resourceId = pipe.GetOutputTargets()[0].resourceId + out.SetTextureDisplay(tex) + + texdetails = self.get_texture(tex.resourceId) + + picked: rd.PixelValue = out.PickPixel(tex.resourceId, False, + int(texdetails.width / 2), int(texdetails.height / 2), 0, 0, 0) + + if not rdtest.value_compare(picked.floatValue, [0.0, 1.0, 0.0, 1.0]): + raise rdtest.TestFailureException("Picked value {} doesn't match expectation".format(picked.floatValue)) + + rdtest.log.success("Triangle picked value is as expected") + + out.Shutdown()