Added tutorials "06 - Descriptor Sets" and "07 - Uniform Buffers". Added functions for projection matrices generation to Tools. Added function for loading images from files (with stb_image library). Updated README.md file with description of Tutorial06.

This commit is contained in:
plapins
2016-06-22 23:23:22 +02:00
parent 37d04f3be5
commit c064ec5a4a
26 changed files with 10307 additions and 6 deletions

Binary file not shown.

View File

@@ -0,0 +1,46 @@
Tutorial07/Data07/shader.frag
Warning, version 430 is not yet complete; most version-specific features are present, but some are missing.
Linked fragment stage:
// Module Version 10000
// Generated by (magic number): 80001
// Id's are bound by 20
Capability Shader
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint Fragment 4 "main" 9 17
ExecutionMode 4 OriginLowerLeft
Source GLSL 430
Name 4 "main"
Name 9 "o_Color"
Name 13 "u_Texture"
Name 17 "v_Texcoord"
Decorate 9(o_Color) Location 0
Decorate 13(u_Texture) DescriptorSet 0
Decorate 13(u_Texture) Binding 0
Decorate 17(v_Texcoord) Location 0
2: TypeVoid
3: TypeFunction 2
6: TypeFloat 32
7: TypeVector 6(float) 4
8: TypePointer Output 7(fvec4)
9(o_Color): 8(ptr) Variable Output
10: TypeImage 6(float) 2D sampled format:Unknown
11: TypeSampledImage 10
12: TypePointer UniformConstant 11
13(u_Texture): 12(ptr) Variable UniformConstant
15: TypeVector 6(float) 2
16: TypePointer Input 15(fvec2)
17(v_Texcoord): 16(ptr) Variable Input
4(main): 2 Function None 3
5: Label
14: 11 Load 13(u_Texture)
18: 15(fvec2) Load 17(v_Texcoord)
19: 7(fvec4) ImageSampleImplicitLod 14 18
Store 9(o_Color) 19
Return
FunctionEnd

View File

@@ -0,0 +1,21 @@
// Copyright 2016 Intel Corporation All Rights Reserved
//
// Intel makes no representations about the suitability of this software for any purpose.
// THIS SOFTWARE IS PROVIDED ""AS IS."" INTEL SPECIFICALLY DISCLAIMS ALL WARRANTIES,
// EXPRESS OR IMPLIED, AND ALL LIABILITY, INCLUDING CONSEQUENTIAL AND OTHER INDIRECT DAMAGES,
// FOR THE USE OF THIS SOFTWARE, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PROPRIETARY
// RIGHTS, AND INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
// Intel does not assume any responsibility for any errors which may appear in this software
// nor any responsibility to update it.
#version 430
layout(set=0, binding=0) uniform sampler2D u_Texture;
layout(location = 0) in vec2 v_Texcoord;
layout(location = 0) out vec4 o_Color;
void main() {
o_Color = texture( u_Texture, v_Texcoord );
}

View File

@@ -0,0 +1,30 @@
// Copyright 2016 Intel Corporation All Rights Reserved
//
// Intel makes no representations about the suitability of this software for any purpose.
// THIS SOFTWARE IS PROVIDED ""AS IS."" INTEL SPECIFICALLY DISCLAIMS ALL WARRANTIES,
// EXPRESS OR IMPLIED, AND ALL LIABILITY, INCLUDING CONSEQUENTIAL AND OTHER INDIRECT DAMAGES,
// FOR THE USE OF THIS SOFTWARE, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PROPRIETARY
// RIGHTS, AND INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
// Intel does not assume any responsibility for any errors which may appear in this software
// nor any responsibility to update it.
#version 450
layout(set=0, binding=1) uniform u_UniformBuffer {
mat4 u_ProjectionMatrix;
};
layout(location = 0) in vec4 i_Position;
layout(location = 1) in vec2 i_Texcoord;
out gl_PerVertex
{
vec4 gl_Position;
};
layout(location = 0) out vec2 v_Texcoord;
void main() {
gl_Position = u_ProjectionMatrix * i_Position;
v_Texcoord = i_Texcoord;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 512 KiB

Binary file not shown.

View File

@@ -0,0 +1,71 @@
Tutorial07/Data07/shader.vert
Warning, version 450 is not yet complete; most version-specific features are present, but some are missing.
Linked vertex stage:
// Module Version 10000
// Generated by (magic number): 80001
// Id's are bound by 32
Capability Shader
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint Vertex 4 "main" 10 21 28 30
Source GLSL 450
Name 4 "main"
Name 8 "gl_PerVertex"
MemberName 8(gl_PerVertex) 0 "gl_Position"
Name 10 ""
Name 14 "u_UniformBuffer"
MemberName 14(u_UniformBuffer) 0 "u_ProjectionMatrix"
Name 16 ""
Name 21 "i_Position"
Name 28 "v_Texcoord"
Name 30 "i_Texcoord"
MemberDecorate 8(gl_PerVertex) 0 BuiltIn Position
Decorate 8(gl_PerVertex) Block
MemberDecorate 14(u_UniformBuffer) 0 ColMajor
MemberDecorate 14(u_UniformBuffer) 0 Offset 0
MemberDecorate 14(u_UniformBuffer) 0 MatrixStride 16
Decorate 14(u_UniformBuffer) Block
Decorate 16 DescriptorSet 0
Decorate 16 Binding 1
Decorate 21(i_Position) Location 0
Decorate 28(v_Texcoord) Location 0
Decorate 30(i_Texcoord) Location 1
2: TypeVoid
3: TypeFunction 2
6: TypeFloat 32
7: TypeVector 6(float) 4
8(gl_PerVertex): TypeStruct 7(fvec4)
9: TypePointer Output 8(gl_PerVertex)
10: 9(ptr) Variable Output
11: TypeInt 32 1
12: 11(int) Constant 0
13: TypeMatrix 7(fvec4) 4
14(u_UniformBuffer): TypeStruct 13
15: TypePointer Uniform 14(u_UniformBuffer)
16: 15(ptr) Variable Uniform
17: TypePointer Uniform 13
20: TypePointer Input 7(fvec4)
21(i_Position): 20(ptr) Variable Input
24: TypePointer Output 7(fvec4)
26: TypeVector 6(float) 2
27: TypePointer Output 26(fvec2)
28(v_Texcoord): 27(ptr) Variable Output
29: TypePointer Input 26(fvec2)
30(i_Texcoord): 29(ptr) Variable Input
4(main): 2 Function None 3
5: Label
18: 17(ptr) AccessChain 16 12
19: 13 Load 18
22: 7(fvec4) Load 21(i_Position)
23: 7(fvec4) MatrixTimesVector 19 22
25: 24(ptr) AccessChain 10 12
Store 25 23
31: 26(fvec2) Load 30(i_Texcoord)
Store 28(v_Texcoord) 31
Return
FunctionEnd

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,171 @@
// Copyright 2016 Intel Corporation All Rights Reserved
//
// Intel makes no representations about the suitability of this software for any purpose.
// THIS SOFTWARE IS PROVIDED ""AS IS."" INTEL SPECIFICALLY DISCLAIMS ALL WARRANTIES,
// EXPRESS OR IMPLIED, AND ALL LIABILITY, INCLUDING CONSEQUENTIAL AND OTHER INDIRECT DAMAGES,
// FOR THE USE OF THIS SOFTWARE, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PROPRIETARY
// RIGHTS, AND INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
// Intel does not assume any responsibility for any errors which may appear in this software
// nor any responsibility to update it.
#if !defined(TUTORIAL_07_HEADER)
#define TUTORIAL_07_HEADER
#include "VulkanCommon.h"
#include "Tools.h"
namespace ApiWithoutSecrets {
// ************************************************************ //
// BufferParameters //
// //
// Vulkan Buffer's parameters container class //
// ************************************************************ //
struct BufferParameters {
VkBuffer Handle;
VkDeviceMemory Memory;
uint32_t Size;
BufferParameters() :
Handle( VK_NULL_HANDLE ),
Memory( VK_NULL_HANDLE ),
Size( 0 ) {
}
};
// ************************************************************ //
// DescriptorParameters //
// //
// Container class for descriptor related resources //
// ************************************************************ //
struct DescriptorSetParameters {
VkDescriptorPool Pool;
VkDescriptorSetLayout Layout;
VkDescriptorSet Handle;
DescriptorSetParameters() :
Pool( VK_NULL_HANDLE ),
Layout( VK_NULL_HANDLE ),
Handle( VK_NULL_HANDLE ) {
}
};
// ************************************************************ //
// VertexData //
// //
// Struct describing data type and format of vertex attributes //
// ************************************************************ //
struct VertexData {
float x, y, z, w;
float u, v;
};
// ************************************************************ //
// RenderingResourcesData //
// //
// Struct containing data used during rendering process //
// ************************************************************ //
struct RenderingResourcesData {
VkFramebuffer Framebuffer;
VkCommandBuffer CommandBuffer;
VkSemaphore ImageAvailableSemaphore;
VkSemaphore FinishedRenderingSemaphore;
VkFence Fence;
RenderingResourcesData() :
Framebuffer( VK_NULL_HANDLE ),
CommandBuffer( VK_NULL_HANDLE ),
ImageAvailableSemaphore( VK_NULL_HANDLE ),
FinishedRenderingSemaphore( VK_NULL_HANDLE ),
Fence( VK_NULL_HANDLE ) {
}
};
// ************************************************************ //
// VulkanTutorial04Parameters //
// //
// Vulkan specific parameters //
// ************************************************************ //
struct VulkanTutorial07Parameters {
VkRenderPass RenderPass;
ImageParameters Image;
BufferParameters UniformBuffer;
DescriptorSetParameters DescriptorSet;
VkPipelineLayout PipelineLayout;
VkPipeline GraphicsPipeline;
BufferParameters VertexBuffer;
BufferParameters StagingBuffer;
VkCommandPool CommandPool;
std::vector<RenderingResourcesData> RenderingResources;
static const size_t ResourcesCount = 3;
VulkanTutorial07Parameters() :
RenderPass( VK_NULL_HANDLE ),
Image(),
DescriptorSet(),
PipelineLayout(),
GraphicsPipeline( VK_NULL_HANDLE ),
VertexBuffer(),
StagingBuffer(),
CommandPool( VK_NULL_HANDLE ),
RenderingResources( ResourcesCount ) {
}
};
// ************************************************************ //
// Tutorial04 //
// //
// Class for presenting Vulkan usage topics //
// ************************************************************ //
class Tutorial07 : public VulkanCommon {
public:
Tutorial07();
~Tutorial07();
bool CreateRenderingResources();
bool CreateStagingBuffer();
bool CreateTexture();
bool CreateUniformBuffer();
bool CreateDescriptorSetLayout();
bool CreateDescriptorPool();
bool AllocateDescriptorSet();
bool UpdateDescriptorSet();
bool CreateRenderPass();
bool CreatePipelineLayout();
bool CreatePipeline();
bool CreateVertexBuffer();
bool Draw() override;
private:
VulkanTutorial07Parameters Vulkan;
bool CreateCommandBuffers();
bool CreateCommandPool(uint32_t queue_family_index, VkCommandPool *pool);
bool AllocateCommandBuffers(VkCommandPool pool, uint32_t count, VkCommandBuffer *command_buffers);
bool CreateSemaphores();
bool CreateFences();
bool CreateBuffer(VkBufferUsageFlags usage, VkMemoryPropertyFlagBits memoryProperty, BufferParameters &buffer);
bool AllocateBufferMemory(VkBuffer buffer, VkMemoryPropertyFlagBits property, VkDeviceMemory *memory);
bool CreateImage( uint32_t width, uint32_t height, VkImage *image );
bool AllocateImageMemory( VkImage image, VkMemoryPropertyFlagBits property, VkDeviceMemory *memory );
bool CreateImageView( ImageParameters &image_parameters );
bool CreateSampler( VkSampler *sampler );
bool CopyTextureData( char *texture_data, uint32_t data_size, uint32_t width, uint32_t height );
const std::array<float, 16> GetUniformBufferData() const;
bool CopyUniformBufferData();
Tools::AutoDeleter<VkShaderModule, PFN_vkDestroyShaderModule> CreateShaderModule( const char* filename );
const std::vector<float>& GetVertexData() const;
bool CopyVertexData();
bool PrepareFrame( VkCommandBuffer command_buffer, const ImageParameters &image_parameters, VkFramebuffer &framebuffer );
bool CreateFramebuffer( VkFramebuffer &framebuffer, VkImageView image_view );
void DestroyBuffer( BufferParameters& buffer );
bool ChildOnWindowSizeChanged() override;
void ChildClear() override;
};
} // namespace ApiWithoutSecrets
#endif // TUTORIAL_07_HEADER

View File

@@ -0,0 +1,71 @@
// Copyright 2016 Intel Corporation All Rights Reserved
//
// Intel makes no representations about the suitability of this software for any purpose.
// THIS SOFTWARE IS PROVIDED ""AS IS."" INTEL SPECIFICALLY DISCLAIMS ALL WARRANTIES,
// EXPRESS OR IMPLIED, AND ALL LIABILITY, INCLUDING CONSEQUENTIAL AND OTHER INDIRECT DAMAGES,
// FOR THE USE OF THIS SOFTWARE, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PROPRIETARY
// RIGHTS, AND INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
// Intel does not assume any responsibility for any errors which may appear in this software
// nor any responsibility to update it.
#include "Tutorial07.h"
int main( int argc, char **argv ) {
ApiWithoutSecrets::OS::Window window;
ApiWithoutSecrets::Tutorial07 tutorial07;
// Window creation
if( !window.Create( "07 - Uniform Buffers" ) ) {
return -1;
}
// Vulkan preparations and initialization
if( !tutorial07.PrepareVulkan( window.GetParameters() ) ) {
return -1;
}
// Tutorial 06
if( !tutorial07.CreateRenderingResources() ) {
return -1;
}
if( !tutorial07.CreateStagingBuffer() ) {
return -1;
}
if( !tutorial07.CreateTexture() ) {
return -1;
}
if( !tutorial07.CreateUniformBuffer() ) {
return -1;
}
if( !tutorial07.CreateDescriptorSetLayout() ) {
return -1;
}
if( !tutorial07.CreateDescriptorPool() ) {
return -1;
}
if( !tutorial07.AllocateDescriptorSet() ) {
return -1;
}
if( !tutorial07.UpdateDescriptorSet() ) {
return -1;
}
if( !tutorial07.CreateRenderPass() ) {
return -1;
}
if( !tutorial07.CreatePipelineLayout() ) {
return -1;
}
if( !tutorial07.CreatePipeline() ) {
return -1;
}
if( !tutorial07.CreateVertexBuffer() ) {
return -1;
}
// Rendering loop
if( !window.RenderingLoop( tutorial07 ) ) {
return -1;
}
return 0;
}