Skip to content

Commit 1a849df

Browse files
committed
Improvement, structure, and other changes
1 parent a371687 commit 1a849df

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+2982
-2042
lines changed

CMakeLists.txt

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -68,37 +68,37 @@ ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/common/Importer)
6868
####################################!
6969
# Vulkan Samples
7070
####################################!
71-
####################################
7271
# Basic Samples
73-
####################################
72+
####################################!
7473
ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/Samples/StartupWindow)
7574
ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/Samples/Triangle)
7675
ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/Samples/Cube)
77-
ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/Samples/Texture)
78-
ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/Samples/NormalMap)
79-
ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/Samples/SkyBox)
80-
ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/Samples/PushConstant)
81-
ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/Samples/Instance)
8276

83-
ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/Samples/MultiSampling)
84-
85-
ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/Samples/ParticleSystem)
8677

87-
####################################
78+
####################################!
8879
# Vulkan Internal Samples
89-
####################################
80+
####################################!
9081
ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/Samples/Memory)
9182
ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/Samples/ExternalMemoryfd)
9283
ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/Samples/Cachepipeline)
93-
94-
ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/Samples/VideoPlayback)
95-
9684
ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/Samples/ShaderInfo)
9785

9886

99-
#######################################
87+
####################################!
88+
# Advanced
89+
####################################!
90+
ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/Samples/Texture)
91+
ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/Samples/Instance)
92+
ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/Samples/NormalMap)
93+
ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/Samples/SkyBox)
94+
ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/Samples/PushConstant)
95+
ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/Samples/MultiSampling)
96+
ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/Samples/VectorField2D)
97+
ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/Samples/VideoPlayback)
98+
99+
####################################!
100100
# Compute Shader Based Samples
101-
#######################################
101+
####################################!
102102
ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/Samples/ReactionDiffusion)
103103
ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/Samples/Mandelbrot)
104104
ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/Samples/GameOfLife)
@@ -107,14 +107,12 @@ ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/Samples/SubGroup)
107107
ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/Samples/Prime)
108108

109109

110-
111110
####################################
112111
# SPIR-V Compiler
113112
####################################
114113
FIND_PROGRAM(GLSLLANGVALIDATOR glslangValidator)
115114
FIND_PROGRAM(GLSLC glslc)
116115

117-
118116
####################################
119117
# Shader Source Files
120118
####################################
@@ -158,7 +156,7 @@ FOREACH(GLSL ${GLSL_SOURCE_FILES})
158156
ADD_CUSTOM_COMMAND(
159157
OUTPUT ${SPIRV}
160158
COMMAND ${CMAKE_COMMAND} -E make_directory "${EXECUTABLE_OUTPUT_PATH}/Shaders/"
161-
COMMAND ${GLSLLANGVALIDATOR} --define-macro gl_InstanceID=gl_InstanceIndex --define-macro gl_VertexID=gl_VertexIndex -I${CMAKE_CURRENT_SOURCE_DIR}/Shaders/common --target-env vulkan1.1 ${SPIRV_BUILD_SETTINGS} -o ${SPIRV} ${GLSL}
159+
COMMAND ${GLSLLANGVALIDATOR} --define-macro gl_InstanceID=gl_InstanceIndex --define-macro gl_VertexID=gl_VertexIndex -I${CMAKE_CURRENT_SOURCE_DIR}/Shaders/common --target-env vulkan1.1 ${SPIRV_BUILD_SETTINGS} -o ${SPIRV} ${GLSL}
162160
DEPENDS ${GLSL})
163161
ELSEIF(GLSLC)
164162
IF(CMAKE_BUILD_TYPE STREQUAL "Release")
@@ -170,7 +168,7 @@ FOREACH(GLSL ${GLSL_SOURCE_FILES})
170168
ADD_CUSTOM_COMMAND(
171169
OUTPUT ${SPIRV}
172170
COMMAND ${CMAKE_COMMAND} -E make_directory "${EXECUTABLE_OUTPUT_PATH}/Shaders/"
173-
COMMAND ${GLSLC} -Dgl_InstanceID=gl_InstanceIndex -Dgl_VertexID=gl_VertexIndex -I${CMAKE_CURRENT_SOURCE_DIR}/Shaders/common --target-spv=spv1.3 -x glsl ${SPIRV_BUILD_SETTINGS} -Werror --target-env=vulkan1.1 -o ${SPIRV} ${GLSL}
171+
COMMAND ${GLSLC} -Dgl_InstanceID=gl_InstanceIndex -Dgl_VertexID=gl_VertexIndex -I${CMAKE_CURRENT_SOURCE_DIR}/Shaders/common --target-spv=spv1.3 -x glsl ${SPIRV_BUILD_SETTINGS} -Werror --target-env=vulkan1.1 -o ${SPIRV} ${GLSL}
174172
DEPENDS ${GLSL})
175173
ENDIF()
176174

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,6 @@ memory on the device between various heap.
7575

7676
## License
7777

78-
This project is licensed under the GPL+3 License - see the [LICENSE](LICENSE) file for details
78+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details
7979

8080
Models downloaded from Morgan McGuire's [Computer Graphics Archive](https://casual-effects.com/data)

Samples/Cachepipeline/cachepipeline.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
namespace vksample {
77

88
/**
9-
* @brief
10-
*
9+
* @brief
10+
*
1111
*/
1212
class CachePipeline : public vksample::VKSampleSessionBase {
1313
public:
@@ -34,9 +34,9 @@ namespace vksample {
3434
int height = 512;
3535

3636
auto vertShaderCode =
37-
vksample::IOUtil::readFileData<uint32_t>(this->vertexShaderPath, this->getFileSystem());
37+
fragcore::IOUtil::readFileData<uint32_t>(this->vertexShaderPath, this->getFileSystem());
3838
auto fragShaderCode =
39-
vksample::IOUtil::readFileData<uint32_t>(this->fragmentShaderPath, this->getFileSystem());
39+
fragcore::IOUtil::readFileData<uint32_t>(this->fragmentShaderPath, this->getFileSystem());
4040

4141
VkShaderModule vertShaderModule = fvkcore::VKHelper::createShaderModule(getDevice(), vertShaderCode);
4242
VkShaderModule fragShaderModule = fvkcore::VKHelper::createShaderModule(getDevice(), fragShaderCode);

Samples/Cube/Cube.cpp

Lines changed: 32 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace vksample {
1515
* @brief
1616
*
1717
*/
18-
class Cube : public VKWindow {
18+
class Cube : public VKBaseSampleWindow {
1919
private:
2020
VkBuffer vertexBuffer = VK_NULL_HANDLE;
2121
VkDeviceMemory vertexMemory = VK_NULL_HANDLE;
@@ -24,24 +24,21 @@ namespace vksample {
2424
VkPipelineLayout pipelineLayout = VK_NULL_HANDLE;
2525
VkDescriptorSetLayout descriptorSetLayout = VK_NULL_HANDLE;
2626

27-
VkDescriptorPool descpool = VK_NULL_HANDLE;
28-
2927
std::vector<VkDescriptorSet> descriptorSets;
28+
3029
VkBuffer uniformBuffer{};
30+
VkDeviceSize uniformMemSize{};
3131
VkDeviceMemory uniformBufferMemory{};
3232
std::vector<void *> mapMemory;
3333

34-
VkDeviceSize uniformMemSize{};
3534
CameraController camera;
3635

37-
const std::string vertexShaderPath = "Shaders/triangle-mvp.vert.spv";
38-
const std::string fragmentShaderPath = "Shaders/triangle-mvp.frag.spv";
36+
const std::string vertexShaderPath = "Shaders/vertexinterpolation/VertexInterpolation.vert.spv";
37+
const std::string fragmentShaderPath = "Shaders/vertexinterpolation/VertexInterpolation.frag.spv";
3938

4039
struct UniformBufferBlock {
41-
glm::mat4 model;
42-
glm::mat4 view;
43-
glm::mat4 proj;
44-
} mvp{};
40+
glm::mat4 modelViewProjection;
41+
} StageBuffer{};
4542

4643
using Vertex = struct _vertex_t {
4744
float pos[3];
@@ -50,16 +47,21 @@ namespace vksample {
5047

5148
public:
5249
Cube(std::shared_ptr<VulkanCore> &core, std::shared_ptr<VKDevice> &device)
53-
: VKWindow(core, device, -1, -1, -1, -1) {
50+
: VKBaseSampleWindow(core, device, -1, -1, -1, -1) {
5451
this->setTitle("Cube");
5552
this->show();
5653

57-
this->camera.enableNavigation(false);
54+
/* Default camera position and orientation. */
55+
this->camera.setPosition(glm::vec3(-2.5f));
56+
this->camera.lookAt(glm::vec3(0.f));
57+
58+
this->camera.enableNavigation(true);
59+
this->camera.enableLook(true);
5860
}
5961

6062
void release() override {
6163

62-
vkDestroyDescriptorPool(getDevice(), this->descpool, nullptr);
64+
vkDestroyDescriptorPool(getDevice(), this->getDescriptorPool(), nullptr);
6365

6466
vkDestroyBuffer(getDevice(), this->vertexBuffer, nullptr);
6567
vkFreeMemory(getDevice(), this->vertexMemory, nullptr);
@@ -116,9 +118,9 @@ namespace vksample {
116118
VkPipeline createGraphicPipeline() {
117119

118120
const auto vertShaderCode =
119-
vksample::IOUtil::readFileData<uint32_t>(this->vertexShaderPath, this->getFileSystem());
121+
fragcore::IOUtil::readFileData<uint32_t>(this->vertexShaderPath, this->getFileSystem());
120122
const auto fragShaderCode =
121-
vksample::IOUtil::readFileData<uint32_t>(this->fragmentShaderPath, this->getFileSystem());
123+
fragcore::IOUtil::readFileData<uint32_t>(this->fragmentShaderPath, this->getFileSystem());
122124

123125
VkShaderModule vertShaderModule = VKHelper::createShaderModule(getDevice(), vertShaderCode);
124126
VkShaderModule fragShaderModule = VKHelper::createShaderModule(getDevice(), fragShaderCode);
@@ -170,7 +172,7 @@ namespace vksample {
170172
uboLayoutBinding.pImmutableSamplers = nullptr;
171173
uboLayoutBinding.stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
172174

173-
VKHelper::createDescriptorSetLayout(this->getDevice(), descriptorSetLayout, {uboLayoutBinding});
175+
VKHelper::createDescriptorSetLayout(this->getDevice(), descriptorSetLayout, {uboLayoutBinding}, 0);
174176

175177
VkPipelineInputAssemblyStateCreateInfo inputAssembly{};
176178
inputAssembly.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
@@ -236,7 +238,7 @@ namespace vksample {
236238
depthStencil.depthBoundsTestEnable = VK_FALSE;
237239
depthStencil.stencilTestEnable = VK_FALSE;
238240

239-
VKHelper::createPipelineLayout(getDevice(), pipelineLayout, {descriptorSetLayout});
241+
VKHelper::createPipelineLayout(getDevice(), pipelineLayout, 0, {descriptorSetLayout});
240242

241243
VkDynamicState dynamicStateEnables[1];
242244
dynamicStateEnables[0] = VK_DYNAMIC_STATE_VIEWPORT;
@@ -276,8 +278,8 @@ namespace vksample {
276278

277279
this->uniformMemSize = sizeof(UniformBufferBlock);
278280

279-
this->uniformMemSize +=
280-
uniformMemSize % getVKDevice()->getPhysicalDevices()[0]->getDeviceLimits().nonCoherentAtomSize;
281+
const size_t uniform_align_size = getPhysicalDevice()->getDeviceLimits().minUniformBufferOffsetAlignment;
282+
this->uniformMemSize = Math::align(this->uniformMemSize, uniform_align_size);
281283

282284
const VkDeviceSize uniformBufferSize = this->getSwapChainImageCount() * uniformMemSize;
283285

@@ -298,26 +300,14 @@ namespace vksample {
298300
this->mapMemory[i] = &_data[this->uniformMemSize * i];
299301
}
300302

301-
VkDescriptorPoolSize poolSize{};
302-
poolSize.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
303-
poolSize.descriptorCount = static_cast<uint32_t>(getSwapChainImageCount());
304-
305-
VkDescriptorPoolCreateInfo poolInfo{};
306-
poolInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
307-
poolInfo.poolSizeCount = 1;
308-
poolInfo.pPoolSizes = &poolSize;
309-
poolInfo.maxSets = static_cast<uint32_t>(getSwapChainImageCount());
310-
311-
VKS_VALIDATE(vkCreateDescriptorPool(getDevice(), &poolInfo, nullptr, &descpool));
312-
313303
/* Create pipeline. */
314304
this->graphicsPipeline = createGraphicPipeline();
315305

316306
/* */
317307
std::vector<VkDescriptorSetLayout> layouts(getSwapChainImageCount(), descriptorSetLayout);
318308
VkDescriptorSetAllocateInfo allocdescInfo{};
319309
allocdescInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
320-
allocdescInfo.descriptorPool = descpool;
310+
allocdescInfo.descriptorPool = getDescriptorPool();
321311
allocdescInfo.descriptorSetCount = static_cast<uint32_t>(getSwapChainImageCount());
322312
allocdescInfo.pSetLayouts = layouts.data();
323313

@@ -412,8 +402,12 @@ namespace vksample {
412402
renderPassInfo.clearValueCount = clearValues.size();
413403
renderPassInfo.pClearValues = clearValues.data();
414404

415-
VkViewport viewport = {
416-
.x = 0, .y = 0, .width = (float)width, .height = (float)height, .minDepth = 0, .maxDepth = 1.0f};
405+
const VkViewport viewport = {.x = 0,
406+
.y = static_cast<float>(height),
407+
.width = (float)width,
408+
.height = (float)-height,
409+
.minDepth = 0,
410+
.maxDepth = 1.0f};
417411
vkCmdSetViewport(cmd, 0, 1, &viewport);
418412

419413
vkCmdBeginRenderPass(cmd, &renderPassInfo, VK_SUBPASS_CONTENTS_INLINE);
@@ -445,17 +439,12 @@ namespace vksample {
445439
this->camera.update(this->getTimer().deltaTime<float>());
446440

447441
const float elapsedTime = this->getTimer().getElapsed<float>();
448-
449-
this->mvp.proj = this->camera.getProjectionMatrix();
450-
this->mvp.model = glm::mat4(1.0f);
451-
this->mvp.view = glm::mat4(1.0f);
452-
this->mvp.view = glm::translate(this->mvp.view, glm::vec3(0, 0, -5));
453-
this->mvp.model =
454-
glm::rotate(this->mvp.model, glm::radians(elapsedTime * 45.0f), glm::vec3(0.0f, 1.0f, 0.0f));
455-
this->mvp.model = glm::scale(this->mvp.model, glm::vec3(0.95f));
442+
this->StageBuffer.modelViewProjection =
443+
(camera.getProjectionMatrix() * camera.getViewMatrix() *
444+
glm::rotate(glm::mat4(1), glm::radians(elapsedTime * 45.0f), glm::vec3(0.0f, 1.0f, 0.0f)));
456445

457446
/* Copy new uniform data. */
458-
memcpy(this->mapMemory[this->getCurrentFrameIndex()], &mvp, (size_t)sizeof(this->mvp));
447+
memcpy(this->mapMemory[this->getCurrentFrameIndex()], &StageBuffer, (size_t)sizeof(this->StageBuffer));
459448

460449
// Setup the range
461450
VkMappedMemoryRange stagingRange{};

0 commit comments

Comments
 (0)