mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-09-28 08:35:50 +00:00
Add test for mesh view - vertex picking and mesh rendering
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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();
|
||||
@@ -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();
|
||||
@@ -134,6 +134,7 @@
|
||||
<ClCompile Include="d3d11\d3d11_helpers.cpp" />
|
||||
<ClCompile Include="d3d11\d3d11_many_rtvs.cpp" />
|
||||
<ClCompile Include="d3d11\d3d11_map_overrun.cpp" />
|
||||
<ClCompile Include="d3d11\d3d11_mesh_zoo.cpp" />
|
||||
<ClCompile Include="d3d11\d3d11_midframe_create.cpp" />
|
||||
<ClCompile Include="d3d11\d3d11_mip_gen_rt.cpp" />
|
||||
<ClCompile Include="d3d11\d3d11_mip_rtv.cpp" />
|
||||
@@ -160,6 +161,7 @@
|
||||
<ClCompile Include="d3d11\d3d11_video_textures.cpp" />
|
||||
<ClCompile Include="d3d12\d3d12_cbuffer_zoo.cpp" />
|
||||
<ClCompile Include="d3d12\d3d12_helpers.cpp" />
|
||||
<ClCompile Include="d3d12\d3d12_mesh_zoo.cpp" />
|
||||
<ClCompile Include="d3d12\d3d12_overlay_test.cpp" />
|
||||
<ClCompile Include="d3d12\d3d12_resource_lifetimes.cpp" />
|
||||
<ClCompile Include="d3d12\d3d12_shader_editing.cpp" />
|
||||
@@ -188,6 +190,7 @@
|
||||
<ClCompile Include="gl\gl_entry_points.cpp" />
|
||||
<ClCompile Include="gl\gl_large_bcn_arrays.cpp" />
|
||||
<ClCompile Include="gl\gl_map_overrun.cpp" />
|
||||
<ClCompile Include="gl\gl_mesh_zoo.cpp" />
|
||||
<ClCompile Include="gl\gl_midframe_context_create.cpp" />
|
||||
<ClCompile Include="gl\gl_mip_gen_rt.cpp" />
|
||||
<ClCompile Include="gl\gl_multi_window.cpp" />
|
||||
@@ -222,6 +225,7 @@
|
||||
<ClCompile Include="test_common.cpp" />
|
||||
<ClCompile Include="texture_zoo.cpp" />
|
||||
<ClCompile Include="vk\vk_khr_buffer_address.cpp" />
|
||||
<ClCompile Include="vk\vk_mesh_zoo.cpp" />
|
||||
<ClCompile Include="vk\vk_parameter_zoo.cpp" />
|
||||
<ClCompile Include="vk\vk_imageless_framebuffer.cpp" />
|
||||
<ClCompile Include="vk\vk_image_layouts.cpp" />
|
||||
|
||||
@@ -382,6 +382,18 @@
|
||||
<ClCompile Include="gl\gl_unshared_context.cpp">
|
||||
<Filter>OpenGL\demos</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="d3d11\d3d11_mesh_zoo.cpp">
|
||||
<Filter>D3D11\demos</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="d3d12\d3d12_mesh_zoo.cpp">
|
||||
<Filter>D3D12\demos</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="gl\gl_mesh_zoo.cpp">
|
||||
<Filter>OpenGL\demos</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="vk\vk_mesh_zoo.cpp">
|
||||
<Filter>Vulkan\demos</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Filter Include="D3D11">
|
||||
|
||||
@@ -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();
|
||||
@@ -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<VkFramebuffer> 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();
|
||||
Reference in New Issue
Block a user