Giter Site home page Giter Site logo

gametechdev / introductiontovulkan Goto Github PK

View Code? Open in Web Editor NEW
1.3K 155.0 210.0 1.61 MB

Source code examples for "API without Secrets: Introduction to Vulkan" tutorial

Home Page: https://software.intel.com/en-us/articles/api-without-secrets-introduction-to-vulkan-preface

License: Apache License 2.0

CMake 1.03% C++ 96.07% GLSL 1.73% Batchfile 0.64% Shell 0.54%
vulkan vulkan-api vulkan-demos cpp tutorial tutorials intel

introductiontovulkan's Introduction

DISCONTINUATION OF PROJECT

This project will no longer be maintained by Intel.

Intel has ceased development and contributions including, but not limited to, maintenance, bug fixes, new releases, or updates, to this project.

Intel no longer accepts patches to this project.

If you have an ongoing need to use this project, are interested in independently developing it, or would like to maintain patches for the open source software community, please create your own fork of this project.

API without Secrets: Introduction to Vulkan

by Pawel Lapinski

Source code examples for "API without Secrets: Introduction to Vulkan" tutorial which can be found at:

https://software.intel.com/en-us/articles/api-without-secrets-introduction-to-vulkan-preface

Special thanks to Slawomir Cygan for help and for patiently answering my many, many questions!

Drivers:

Vulkan drivers and other related resources can be found at https://www.khronos.org/vulkan/

Tutorials:

Introduction to a Vulkan world

Tutorial presents how to create all resources necessary to use Vulkan inside our application: function pointers loading, Vulkan instance creation, physical device enumeration, logical device creation and queue set up.


Integrating Vulkan with OS

This lesson focuses on a swap chain creation. Swap chain enables us to display Vulkan-generated image in an application window. To display anything simple command buffers are allocated and recorded.


Graphics pipeline and drawing

Here I present render pass, framebuffer and pipeline objects which are necessary to render arbitrary geometry. It is also shown how to convert GLSL shaders into SPIR-V and create shader modules from it.


Buffers, memory objects and fences

This tutorial shows how to set up vertex attributes and bind buffer with a vertex data. Here we also create memory object (which is used by buffer) and fences.


Copying data between buffers

In this example staging resources are presented. They are used as an intermediate resources for copying data between CPU and GPU. This way, resources involved in rendering can be bound only to a device local (very fast) memory.


Using textures in shaders

This tutorial shows what resources are needed and how they should be prepared to be able to use textures (or other shader resources) in shader programs.


Using buffers in shaders

Here it is shown how to add uniform buffer to descriptor sets, how to provide data for projection matrix through it and how to use it inside shader.

introductiontovulkan's People

Contributors

1ace avatar codergirl42 avatar davebookout-intel avatar ds-hwang avatar ekzuzy avatar lanphon avatar s-ol avatar sfblackl-intel avatar texkiller avatar whydoubt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

introductiontovulkan's Issues

X Error of failed request: BadDrawable (invalid Pixmap or Window parameter)

I'm getting the same issue as that referred to in the pull request #10 except its even when using the x11 switch.

I'm running this in Arch Linux.

> DISPLAY=:8 optirun --verbose -b primus ./build/02-Swapchain
[ 8503.931368] [INFO]Response: Yes. X is active.

[ 8503.931394] [INFO]Running application using primus.
X Error of failed request:  BadDrawable (invalid Pixmap or Window parameter)
  Major opcode of failed request:  14 (X_GetGeometry)
  Resource id in failed request:  0x200001
  Serial number of failed request:  37
  Current serial number in output stream:  37

Stage to wait for semaphore in tutorial 3

Tutorial 3 uses mostly the same drawing code as tutorial 2, but since we're doing a drawing operation instead of a transfer operation now, shouldn't VK_PIPELINE_STAGE_TRANSFER_BIT be changed to something like VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT with regards to waiting on the image available semaphore?

linux segmentation fault

using 6578ecc

  1. git clone
  2. build.sh xcb
  3. ./01-The_Beginning
    => segmentation fault and gdb says:
    (gdb) bt
    #0 0x000000000060c438 in vkCreateInstance ()
    #1 0x00000000004064e6 in Tutorial::Tutorial01::CreateInstance (this=0x7fffffffe800) at /home/ville/projects/IntroductionToVulkan/Project/Tutorial01/Tutorial01.cpp:124
    #2 0x0000000000406283 in Tutorial::Tutorial01::PrepareVulkan (this=0x7fffffffe800) at /home/ville/projects/IntroductionToVulkan/Project/Tutorial01/Tutorial01.cpp:40
    #3 0x000000000040612e in main (argc=1, argv=0x7fffffffe938) at /home/ville/projects/IntroductionToVulkan/Project/Tutorial01/main.cpp:23

All the programs show this whether xcb/x11 or debug/release. I suspect i have the right things installed. I am able to run "vkcube" from https://github.com/krh/vkcube

Multiple Queue

In VulkanCommon::CreateDevice #L318 queueCreateInfoCount should be changed to queue_create_infos.size() from 1 to cover the case when multiple queue are needed

VK_API_VERSION macro is not defined in latest Vulkan SDK

In the latest LunarG SDK (1.0.17.0), the macro VK_API_VERSION is not defined any more.

From the latest vulkan.h file from the SDK:

// DEPRECATED: This define has been removed. Specific version defines (e.g. VK_API_VERSION_1_0), or the VK_MAKE_VERSION macro, should be used instead.
//#define VK_API_VERSION VK_MAKE_VERSION(1, 0, 0)

I've found this issue when compiling the Tutorial01.cpp file, specifically ~ line 110:

VkApplicationInfo application_info = {
      ...
      VK_API_VERSION   // uint32_t  apiVersion
    };

The solution I found is to use VK_API_VERSION_1_0, as the comment said.

Perhaps a solution that would would work with older version is something like

#if VK_HEADER_VERSION >= 17
  #define VK_API_VERSION VK_API_VERSION_1_0
#else
 // Just use the macro already defined in vulkan.h
#endif

CMake error when using with vcpkg

Hi!
Thank you for these great in depth tutorials!

I am using vcpkg in Visual Studio by default and no one except vcpkg is allowed to redefine add_executable, otherwise you're stuck in an infitie recursion, because add_executable calls itself.

The error is:

1> [CMake]   Maximum recursion depth of 1000 exceeded

Here are the necessary fixes to the CMakeLists.txt:

macro( my_add_executable _type _number _name )
	set( TARGET_NAME "${_number}-${_name}" )
	file( GLOB PROJECT_FILES "${CMAKE_CURRENT_LIST_DIR}/${_type}/${_number}/*.*" )
	add_executable( ${TARGET_NAME} ${ARGN} ${PROJECT_FILES} )
	target_compile_definitions( ${TARGET_NAME} PRIVATE USE_SWAPCHAIN_EXTENSIONS )
	target_link_libraries( ${TARGET_NAME} ${PLATFORM_LIBRARY} )
	set_property( TARGET ${TARGET_NAME} PROPERTY FOLDER "${_type}" )

	if( EXISTS "${CMAKE_SOURCE_DIR}/${_type}/${_number}/Data" )
		file( GLOB DATA_FILES "${CMAKE_SOURCE_DIR}/${_type}/${_number}/Data/*.*" )
		file( COPY ${DATA_FILES} DESTINATION "${CMAKE_SOURCE_DIR}/build/Data/${_type}/${_number}/" )
	endif()
endmacro()

# ...

add_executable( "01-The_Beginning" ${ALL_BASIC_SHARED_FILES}
	Tutorials/01/Tutorial01.h
	Tutorials/01/main.cpp
	Tutorials/01/Tutorial01.cpp )

target_link_libraries( "01-The_Beginning" ${PLATFORM_LIBRARY} )
set_property( TARGET "01-The_Beginning" PROPERTY FOLDER "Tutorials" )

my_add_executable( "Tutorials" "02" "Swapchain" ${ALL_BASIC_SHARED_FILES} )

my_add_executable( "Tutorials" "03" "First_Triangle" ${ALL_BASIC_AND_ADVANCED_SHARED_FILES} )

my_add_executable( "Tutorials" "04" "Vertex_Attributes" ${ALL_BASIC_AND_ADVANCED_SHARED_FILES} )

my_add_executable( "Tutorials" "05" "Staging_Resources" ${ALL_BASIC_AND_ADVANCED_SHARED_FILES} )

my_add_executable( "Tutorials" "06" "Descriptor_Sets" ${ALL_BASIC_AND_ADVANCED_SHARED_FILES} )

my_add_executable( "Tutorials" "07" "Uniform_Buffers" ${ALL_BASIC_AND_ADVANCED_SHARED_FILES} )

So basically just rename add_executable to something else. Maybe you find a more fitting name than my_add_executable.

'TRANSFER_DST image usage is not supported by the swap chain!'

I used CMake for Visual Studio 2014 64bit.

Once I create the projects, then I compile the tutorial projects.

However, it seems to crash directly after it outputs:
TRANSFER_DST image usage is not supported by the swap chain!

I really appreciate the feedback.

Windows shaders loading from wrong relative path

If you use build.bat to create the project for you it runs from the generated build directory (where the .vcxproj files are), and the shader paths need to be modified to "../TutorialXX/DataXX/...". It might be better to copy the shaders there with a post-build step.

Triangle coordinates

Chapter 3 uses the following coordinates for the triangle:

vec2 pos[3] = vec2[3]( vec2(-0.7, 0.7), vec2(0.7, 0.7), vec2(0.0, -0.7) );

However, when considering normalized device coordinates, shouldn't the triangle be pointing downwards?

Convert CRLF to LF

This commit seems to convert LF to CRLF in all source files.
561ac8c
We need to remove this commit and git push --force

Draw loop should not be destroying and recreating framebuffers each frame

In Tutorial4 onwards, the render loop is destroying and recreating framebuffers every frame. Creation and destruction of objects in Vulkan are not lightweight operations - they are expected to have a sizeable runtime cost, and indeed do on some implementations.
This is documented in the Vulkan spec itself in fact, the second paragraph here: https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#fundamentals-objectmodel-lifetime

The offending lines are here in Tutorial04, for instance:

bool Tutorial04::CreateFramebuffer( VkFramebuffer &framebuffer, VkImageView image_view ) {

These objects should be created once and re-used, the same as all other objects in a robust Vulkan application.

Validation Layer Failure

Hello. If you enable VK_LAYER_LUNARG_standard_validation in sample 2(I did not test other samples) you will get invalid surface pointer after vkCreateWin32SurfaceKHR call. It may be bug in your code or bug in driver. I do not see the error. However, if you run e.g. Stardust demo it works fine.

Tutorial 02 (Swap chains) use PresentQueue where GraphicsQueue should be used

Currently in Tutorial02.cpp:798 there's a call:
if( vkQueueSubmit( Vulkan.PresentQueue, 1, &submit_info, VK_NULL_HANDLE ) != VK_SUCCESS )

If I get it right, Vulkan.PresentQueue is incorrectly used instead of Vulkan.GraphicsQueue.
Otherwise Vulkan.GraphicsQueue is never used.
This works for 99% people because both handles point to the same queue in most cases.

(very minor) namespace comment in Tutorial01.cpp

Just a very minor thing. The comment signaling the end of the namespace 'ApiWithoutSecrets' reads '// namespace Tutorial'. Aka

namespace ApiWithoutSecrets {
// more code here
} // namespace Tutorial

really nothing major though.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.