Merge branch 'SaschaWillems:master' into master

This commit is contained in:
robotchaoX 2023-06-09 13:27:15 +08:00 committed by GitHub
commit 7e9d3c8fec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 101 additions and 14 deletions

View file

@ -1,5 +1,4 @@
cmake_minimum_required(VERSION 3.4 FATAL_ERROR)
cmake_policy(VERSION 2.8)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
set(NAME vulkanExamples)

View file

@ -86,7 +86,7 @@ Note that some examples require specific device features, and if you are on a mu
## Shaders
Vulkan consumes shaders in an intermediate representation called SPIR-V. This makes it possible to use different shader languages by compiling them to that bytecode format. The primary shader language used here is [GLSL](data/shaders/glsl) but thanks to an external contribution you'll also find [HLSL](data/shaders/hlsl) shader sources.
Vulkan consumes shaders in an intermediate representation called SPIR-V. This makes it possible to use different shader languages by compiling them to that bytecode format. The primary shader language used here is [GLSL](data/shaders/glsl) but most samples also come with [HLSL](data/shaders/hlsl) shader sources.
## A note on synchronization

View file

@ -3,7 +3,7 @@
*
* Relevant code parts are marked with [POI]
*
* Copyright (C) 2018 by Sascha Willems - www.saschawillems.de
* Copyright (C) 2018-2023 by Sascha Willems - www.saschawillems.de
*
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
*/
@ -191,11 +191,11 @@ public:
std::array<VkDescriptorPoolSize, 2> descriptorPoolSizes{};
// Uniform buffers : 1 for scene and 1 per object (scene and local matrices)
// Uniform buffers : 1 per object
descriptorPoolSizes[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
descriptorPoolSizes[0].descriptorCount = 1 + static_cast<uint32_t>(cubes.size());
descriptorPoolSizes[0].descriptorCount = static_cast<uint32_t>(cubes.size());
// Combined image samples : 1 per mesh texture
// Combined image samples : 1 per object texture
descriptorPoolSizes[1].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
descriptorPoolSizes[1].descriptorCount = static_cast<uint32_t>(cubes.size());

View file

@ -1,7 +1,7 @@
/*
* Vulkan Example - Using VK_KHR_dynamic_rendering for rendering without framebuffers and render passes (wip)
*
* Copyright (C) 2022 by Sascha Willems - www.saschawillems.de
* Copyright (C) 2022-2023 by Sascha Willems - www.saschawillems.de
*
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
*/
@ -119,7 +119,7 @@ public:
0,
VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
VK_IMAGE_LAYOUT_UNDEFINED,
VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
VkImageSubresourceRange{ VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT, 0, 1, 0, 1 });
@ -128,7 +128,7 @@ public:
VkRenderingAttachmentInfoKHR colorAttachment{};
colorAttachment.sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO_KHR;
colorAttachment.imageView = swapChain.buffers[i].view;
colorAttachment.imageLayout = VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL_KHR;
colorAttachment.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
colorAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
colorAttachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
colorAttachment.clearValue.color = { 0.0f,0.0f,0.0f,0.0f };

View file

@ -77,6 +77,8 @@ public:
enabledDeviceExtensions.push_back(VK_KHR_CREATE_RENDERPASS_2_EXTENSION_NAME);
enabledDeviceExtensions.push_back(VK_KHR_DEPTH_STENCIL_RESOLVE_EXTENSION_NAME);
enabledInstanceExtensions.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
enabledShaderObjectFeaturesEXT.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_OBJECT_FEATURES_EXT;
enabledShaderObjectFeaturesEXT.shaderObject = VK_TRUE;
@ -281,7 +283,7 @@ public:
VkRenderingAttachmentInfoKHR colorAttachment{};
colorAttachment.sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO_KHR;
colorAttachment.imageView = swapChain.buffers[i].view;
colorAttachment.imageLayout = VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL_KHR;
colorAttachment.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
colorAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
colorAttachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
colorAttachment.clearValue.color = { 0.0f,0.0f,0.0f,0.0f };
@ -327,6 +329,7 @@ public:
vertexInputBinding.binding = 0;
vertexInputBinding.inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
vertexInputBinding.stride = sizeof(vkglTF::Vertex);
vertexInputBinding.divisor = 1;
std::vector<VkVertexInputAttributeDescription2EXT> vertexAttributes = {
{ VK_STRUCTURE_TYPE_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION_2_EXT, nullptr, 0, 0, VK_FORMAT_R32G32B32_SFLOAT, offsetof(vkglTF::Vertex, pos) },
@ -344,7 +347,8 @@ public:
vkCmdBindShadersEXT(drawCmdBuffers[i], 2, stages, shaders);
scene.draw(drawCmdBuffers[i]);
drawUI(drawCmdBuffers[i]);
// @todo: Currently disabled, the UI needs to be adopated to work with shader objects
// drawUI(drawCmdBuffers[i]);
// End dynamic rendering
vkCmdEndRenderingKHR(drawCmdBuffers[i]);

View file

@ -1,7 +1,7 @@
/*
* Vulkan Example - Dynamic terrain tessellation
*
* Copyright (C) 2016 by Sascha Willems - www.saschawillems.de
* Copyright (C) 2016-2023 by Sascha Willems - www.saschawillems.de
*
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
*/
@ -105,7 +105,7 @@ public:
camera.setPerspective(60.0f, (float)width / (float)height, 0.1f, 512.0f);
camera.setRotation(glm::vec3(-12.0f, 159.0f, 0.0f));
camera.setTranslation(glm::vec3(18.0f, 22.5f, 57.5f));
camera.movementSpeed = 7.5f;
camera.movementSpeed = 10.0f;
}
~VulkanExample()
@ -420,7 +420,7 @@ public:
vertices[index].pos[0] = x * wx + wx / 2.0f - (float)PATCH_SIZE * wx / 2.0f;
vertices[index].pos[1] = 0.0f;
vertices[index].pos[2] = y * wy + wy / 2.0f - (float)PATCH_SIZE * wy / 2.0f;
vertices[index].uv = glm::vec2((float)x / PATCH_SIZE, (float)y / PATCH_SIZE) * UV_SCALE;
vertices[index].uv = glm::vec2((float)x / (PATCH_SIZE - 1), (float)y / (PATCH_SIZE - 1)) * UV_SCALE;
}
}

View file

@ -0,0 +1,15 @@
/* Copyright (c) 2023, Sascha Willems
*
* SPDX-License-Identifier: MIT
*
*/
struct VSOutput
{
[[vk::location(0)]] float4 color : COLOR0;
};
float4 main(VSOutput input) : SV_TARGET
{
return float4(input.color);
}

Binary file not shown.

View file

@ -0,0 +1,50 @@
/* Copyright (c) 2023, Sascha Willems
*
* SPDX-License-Identifier: MIT
*
*/
struct UBO
{
float4x4 projection;
float4x4 model;
float4x4 view;
};
cbuffer ubo : register(b0) { UBO ubo; }
struct VertexOutput
{
float4 position: SV_Position;
float4 color: COLOR0;
};
static const float4 positions[3] = {
float4( 0.0, -1.0, 0.0, 1.0),
float4(-1.0, 1.0, 0.0, 1.0),
float4( 1.0, 1.0, 0.0, 1.0)
};
static const float4 colors[3] = {
float4(0.0, 1.0, 0.0, 1.0),
float4(0.0, 0.0, 1.0, 1.0),
float4(1.0, 0.0, 0.0, 1.0)
};
[outputtopology("triangle")]
[numthreads(1, 1, 1)]
void main(out indices uint3 triangles[1], out vertices VertexOutput vertices[3], uint3 DispatchThreadID : SV_DispatchThreadID)
{
float4x4 mvp = mul(ubo.projection, mul(ubo.view, ubo.model));
float4 offset = float4(0.0, 0.0, (float)DispatchThreadID, 0.0);
SetMeshOutputCounts(3, 1);
for (uint i = 0; i < 3; i++) {
vertices[i].position = mul(mvp, positions[i] + offset);
vertices[i].color = colors[i];
}
SetMeshOutputCounts(3, 1);
triangles[0] = uint3(0, 1, 2);
}

Binary file not shown.

View file

@ -0,0 +1,19 @@
/* Copyright (c) 2023, Sascha Willems
*
* SPDX-License-Identifier: MIT
*
*/
struct DummyPayLoad
{
uint dummyData;
};
// We don't use pay loads in this sample, but the fn call requires one
groupshared DummyPayLoad dummyPayLoad;
[numthreads(1,1,1)]
void main()
{
DispatchMesh(3, 1, 1, dummyPayLoad);
}

Binary file not shown.