mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-20 23:52:40 +08:00
GFX Vulkan backend (#2414)
* vk: init directories * vk: context creation * vk: swapchain draft * vk: move swapchain to window * vk: acquire - submit - present * vk: begin/end render pass * vk: clear op works! * vk: validation errors cleared * vk: first triangle! ...no uniform buffers though * vk: update msvc project
This commit is contained in:
@@ -53,24 +53,31 @@
|
||||
<ClCompile Include="..\cocos\renderer\gfx-gles3\GLES3TextureView.cc" />
|
||||
<ClCompile Include="..\cocos\renderer\gfx-gles3\gles3w.c" />
|
||||
<ClCompile Include="..\cocos\renderer\gfx-gles3\GLES3Window.cc" />
|
||||
<ClCompile Include="..\cocos\renderer\gfx-vulkan\VKBindingLayout.cc" />
|
||||
<ClCompile Include="..\cocos\renderer\gfx-vulkan\VKBuffer.cc" />
|
||||
<ClCompile Include="..\cocos\renderer\gfx-vulkan\VKCommandAllocator.cc" />
|
||||
<ClCompile Include="..\cocos\renderer\gfx-vulkan\VKCommandBuffer.cc" />
|
||||
<ClCompile Include="..\cocos\renderer\gfx-vulkan\VKCommands.cc" />
|
||||
<ClCompile Include="..\cocos\renderer\gfx-vulkan\VKContext.cc" />
|
||||
<ClCompile Include="..\cocos\renderer\gfx-vulkan\VKDevice.cc" />
|
||||
<ClCompile Include="..\cocos\renderer\gfx-vulkan\VKFramebuffer.cc" />
|
||||
<ClCompile Include="..\cocos\renderer\gfx-vulkan\VKInputAssembler.cc" />
|
||||
<ClCompile Include="..\cocos\renderer\gfx-vulkan\VKPipelineLayout.cc" />
|
||||
<ClCompile Include="..\cocos\renderer\gfx-vulkan\VKPipelineState.cc" />
|
||||
<ClCompile Include="..\cocos\renderer\gfx-vulkan\VKQueue.cc" />
|
||||
<ClCompile Include="..\cocos\renderer\gfx-vulkan\VKRenderPass.cc" />
|
||||
<ClCompile Include="..\cocos\renderer\gfx-vulkan\VKSampler.cc" />
|
||||
<ClCompile Include="..\cocos\renderer\gfx-vulkan\VKShader.cc" />
|
||||
<ClCompile Include="..\cocos\renderer\gfx-vulkan\VKStd.cc" />
|
||||
<ClCompile Include="..\cocos\renderer\gfx-vulkan\VKTexture.cc" />
|
||||
<ClCompile Include="..\cocos\renderer\gfx-vulkan\VKTextureView.cc" />
|
||||
<ClCompile Include="..\cocos\renderer\gfx-vulkan\VKWindow.cc" />
|
||||
<ClCompile Include="..\cocos\renderer\gfx-vulkan\volk.c" />
|
||||
<ClCompile Include="..\cocos\scripting\js-bindings\auto\jsb_gfx_auto.cpp" />
|
||||
<ClCompile Include="..\cocos\scripting\js-bindings\auto\jsb_gles2_auto.cpp" />
|
||||
<ClCompile Include="..\cocos\scripting\js-bindings\auto\jsb_gles3_auto.cpp" />
|
||||
<ClCompile Include="..\cocos\scripting\js-bindings\manual\jsb_gfx_manual.cpp" />
|
||||
<ClCompile Include="..\external\sources\tommyds\tommy.c" />
|
||||
<ClCompile Include="..\external\sources\tommyds\tommyalloc.c" />
|
||||
<ClCompile Include="..\external\sources\tommyds\tommyarray.c" />
|
||||
<ClCompile Include="..\external\sources\tommyds\tommyarrayblk.c" />
|
||||
<ClCompile Include="..\external\sources\tommyds\tommyarrayblkof.c" />
|
||||
<ClCompile Include="..\external\sources\tommyds\tommyarrayof.c" />
|
||||
<ClCompile Include="..\external\sources\tommyds\tommyhash.c" />
|
||||
<ClCompile Include="..\external\sources\tommyds\tommyhashdyn.c" />
|
||||
<ClCompile Include="..\external\sources\tommyds\tommyhashlin.c" />
|
||||
<ClCompile Include="..\external\sources\tommyds\tommyhashtbl.c" />
|
||||
<ClCompile Include="..\external\sources\tommyds\tommylist.c" />
|
||||
<ClCompile Include="..\external\sources\tommyds\tommytree.c" />
|
||||
<ClCompile Include="..\external\sources\tommyds\tommytrie.c" />
|
||||
<ClCompile Include="..\external\sources\tommyds\tommytrieinp.c" />
|
||||
<ClCompile Include="..\cocos\audio\AudioEngine.cpp" />
|
||||
<ClCompile Include="..\cocos\audio\win32\AudioCache.cpp" />
|
||||
<ClCompile Include="..\cocos\audio\win32\AudioDecoder.cpp" />
|
||||
@@ -248,26 +255,36 @@
|
||||
<ClInclude Include="..\cocos\renderer\gfx-gles3\GLES3TextureView.h" />
|
||||
<ClInclude Include="..\cocos\renderer\gfx-gles3\gles3w.h" />
|
||||
<ClInclude Include="..\cocos\renderer\gfx-gles3\GLES3Window.h" />
|
||||
<ClInclude Include="..\cocos\renderer\gfx-vulkan\GFXVulkan.h" />
|
||||
<ClInclude Include="..\cocos\renderer\gfx-vulkan\VKBindingLayout.h" />
|
||||
<ClInclude Include="..\cocos\renderer\gfx-vulkan\VKBuffer.h" />
|
||||
<ClInclude Include="..\cocos\renderer\gfx-vulkan\VKCommandAllocator.h" />
|
||||
<ClInclude Include="..\cocos\renderer\gfx-vulkan\VKCommandBuffer.h" />
|
||||
<ClInclude Include="..\cocos\renderer\gfx-vulkan\VKCommands.h" />
|
||||
<ClInclude Include="..\cocos\renderer\gfx-vulkan\VKContext.h" />
|
||||
<ClInclude Include="..\cocos\renderer\gfx-vulkan\VKDevice.h" />
|
||||
<ClInclude Include="..\cocos\renderer\gfx-vulkan\VKFramebuffer.h" />
|
||||
<ClInclude Include="..\cocos\renderer\gfx-vulkan\VKGPUObjects.h" />
|
||||
<ClInclude Include="..\cocos\renderer\gfx-vulkan\VKInputAssembler.h" />
|
||||
<ClInclude Include="..\cocos\renderer\gfx-vulkan\VKPipelineLayout.h" />
|
||||
<ClInclude Include="..\cocos\renderer\gfx-vulkan\VKPipelineState.h" />
|
||||
<ClInclude Include="..\cocos\renderer\gfx-vulkan\VKQueue.h" />
|
||||
<ClInclude Include="..\cocos\renderer\gfx-vulkan\VKRenderPass.h" />
|
||||
<ClInclude Include="..\cocos\renderer\gfx-vulkan\VKSampler.h" />
|
||||
<ClInclude Include="..\cocos\renderer\gfx-vulkan\VKShader.h" />
|
||||
<ClInclude Include="..\cocos\renderer\gfx-vulkan\VKSPIRV.h" />
|
||||
<ClInclude Include="..\cocos\renderer\gfx-vulkan\VKStateCache.h" />
|
||||
<ClInclude Include="..\cocos\renderer\gfx-vulkan\VKStd.h" />
|
||||
<ClInclude Include="..\cocos\renderer\gfx-vulkan\VKTexture.h" />
|
||||
<ClInclude Include="..\cocos\renderer\gfx-vulkan\VKTextureView.h" />
|
||||
<ClInclude Include="..\cocos\renderer\gfx-vulkan\VKUtils.h" />
|
||||
<ClInclude Include="..\cocos\renderer\gfx-vulkan\VKWindow.h" />
|
||||
<ClInclude Include="..\cocos\renderer\gfx-vulkan\volk.h" />
|
||||
<ClInclude Include="..\cocos\scripting\js-bindings\auto\jsb_gfx_auto.hpp" />
|
||||
<ClInclude Include="..\cocos\scripting\js-bindings\auto\jsb_gles2_auto.hpp" />
|
||||
<ClInclude Include="..\cocos\scripting\js-bindings\auto\jsb_gles3_auto.hpp" />
|
||||
<ClInclude Include="..\cocos\scripting\js-bindings\manual\jsb_gfx_manual.hpp" />
|
||||
<ClInclude Include="..\external\sources\tommyds\tommy.h" />
|
||||
<ClInclude Include="..\external\sources\tommyds\tommyalloc.h" />
|
||||
<ClInclude Include="..\external\sources\tommyds\tommyarray.h" />
|
||||
<ClInclude Include="..\external\sources\tommyds\tommyarrayblk.h" />
|
||||
<ClInclude Include="..\external\sources\tommyds\tommyarrayblkof.h" />
|
||||
<ClInclude Include="..\external\sources\tommyds\tommyarrayof.h" />
|
||||
<ClInclude Include="..\external\sources\tommyds\tommychain.h" />
|
||||
<ClInclude Include="..\external\sources\tommyds\tommyhash.h" />
|
||||
<ClInclude Include="..\external\sources\tommyds\tommyhashdyn.h" />
|
||||
<ClInclude Include="..\external\sources\tommyds\tommyhashlin.h" />
|
||||
<ClInclude Include="..\external\sources\tommyds\tommyhashtbl.h" />
|
||||
<ClInclude Include="..\external\sources\tommyds\tommylist.h" />
|
||||
<ClInclude Include="..\external\sources\tommyds\tommytree.h" />
|
||||
<ClInclude Include="..\external\sources\tommyds\tommytrie.h" />
|
||||
<ClInclude Include="..\external\sources\tommyds\tommytrieinp.h" />
|
||||
<ClInclude Include="..\external\sources\tommyds\tommytypes.h" />
|
||||
<ClInclude Include="..\cocos\audio\include\AudioEngine.h" />
|
||||
<ClInclude Include="..\cocos\audio\include\Export.h" />
|
||||
<ClInclude Include="..\cocos\audio\win32\AudioCache.h" />
|
||||
@@ -509,12 +526,12 @@
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LibraryPath>$(EngineRoot)external\win32\libs;$(MSBuildProgramFiles32)\Microsoft SDKs\Windows\v7.1A\lib;$(LibraryPath)</LibraryPath>
|
||||
<TargetName>$(ProjectName)</TargetName>
|
||||
<IncludePath>$(ProjectDir)..\cocos\renderer;$(ProjectDir)..\cocos\renderer\core;$(ProjectDir)..\external\sources\tommyds;$(ProjectDir)..\external\sources\khronos;$(ProjectDir)..\external\sources\jemalloc\include-win;$(ProjectDir)..\external\sources\jemalloc\include-win\msvc_compat;$(IncludePath)</IncludePath>
|
||||
<IncludePath>$(ProjectDir)..\cocos\renderer;$(ProjectDir)..\cocos\renderer\core;$(ProjectDir)..\external\sources\tommyds;$(ProjectDir)..\external\sources\khronos;$(ProjectDir)..\external\sources\jemalloc\include-win;$(ProjectDir)..\external\sources\jemalloc\include-win\msvc_compat;$(ProjectDir)..\external\sources\glslang;$(IncludePath)</IncludePath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LibraryPath>$(EngineRoot)external\win32\libs;$(MSBuildProgramFiles32)\Microsoft SDKs\Windows\v7.1A\lib;$(LibraryPath)</LibraryPath>
|
||||
<TargetName>$(ProjectName)</TargetName>
|
||||
<IncludePath>$(ProjectDir)..\cocos\renderer\core;$(ProjectDir)..\external\sources\tommyds;$(ProjectDir)..\external\sources\khronos;$(ProjectDir)..\external\sources\jemalloc\include-win;$(ProjectDir)..\external\sources\jemalloc\include-win\msvc_compat;$(IncludePath)</IncludePath>
|
||||
<IncludePath>$(ProjectDir)..\cocos\renderer;$(ProjectDir)..\cocos\renderer\core;$(ProjectDir)..\external\sources\tommyds;$(ProjectDir)..\external\sources\khronos;$(ProjectDir)..\external\sources\jemalloc\include-win;$(ProjectDir)..\external\sources\jemalloc\include-win\msvc_compat;$(ProjectDir)..\external\sources\glslang;$(IncludePath)</IncludePath>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<PreBuildEvent>
|
||||
@@ -524,7 +541,7 @@
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>$(ProjectDir)..\cocos;$(ProjectDir)..\external\sources;$(ProjectDir)..\cocos\renderer\gfx;$(ProjectDir)..\cocos\renderer;$(ProjectDir)..\cocos\platform;$(ProjectDir)..\external\win32\include\zlib;$(ProjectDir)..\external\win32\include\v8;$(ProjectDir)..\external\sources\firefox;$(projectDir)..;$(ProjectDir)..\external\win32\include;$(ProjectDir)..\external\win32\include\uv;$(ProjectDir)..\cocos\editor-support</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;CC_STATIC;_USRDLL;_LIB;COCOS2D_DEBUG=1;JS_HAVE____INTN;JS_INTPTR_TYPE=int;XP_WIN;_CRT_SECURE_NO_WARNINGS;_WINDOWS;_WIN32;__MWERKS__;CC_CORE_EXPORTS;GLEW_BUILD;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>WIN32;CC_STATIC;_USRDLL;_LIB;COCOS2D_DEBUG=1;JS_HAVE____INTN;JS_INTPTR_TYPE=int;XP_WIN;_CRT_SECURE_NO_WARNINGS;_WINDOWS;_WIN32;__MWERKS__;CC_CORE_EXPORTS;GLEW_BUILD;VK_USE_PLATFORM_WIN32_KHR;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<MinimalRebuild>false</MinimalRebuild>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
||||
@@ -565,7 +582,7 @@ xcopy /Y /Q "$(ProjectDir)..\external\win32\libs\Debug\*.*" "$(OutDir)"</Command
|
||||
</Command>
|
||||
</PreBuildEvent>
|
||||
<ClCompile>
|
||||
<AdditionalIncludeDirectories>$(ProjectDir)..\cocos;$(ProjectDir)..\external\sources;$(ProjectDir)..\cocos\renderer\gfx;$(ProjectDir)..\cocos\renderer;$(ProjectDir)..\cocos\platform;$(ProjectDir)..\external\win32\include\zlib;$(ProjectDir)..\external\win32\include\v8;$(ProjectDir)..\external\sources\firefox;$(projectDir)..;$(ProjectDir)..\external\win32\include;$(ProjectDir)..\external\win32\include\uv;$(ProjectDir)..\cocos\editor-support</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>$(ProjectDir)..\cocos;$(ProjectDir)..\external\sources;$(ProjectDir)..\cocos\renderer\gfx;$(ProjectDir)..\cocos\renderer;$(ProjectDir)..\cocos\platform;$(ProjectDir)..\external\win32\include\zlib;$(ProjectDir)..\external\win32\include\v8;$(ProjectDir)..\external\sources\firefox;$(projectDir)..;$(ProjectDir)..\external\win32\include;$(ProjectDir)..\external\win32\include\uv;$(ProjectDir)..\cocos\editor-support;$(ProjectDir)..\external\sources\glslang</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>NDEBUG;WIN32;_WINDOWS;CC_STATIC;_USRDLL;USING_V8_SHARED;_LIB;JS_HAVE____INTN;JS_INTPTR_TYPE=int;XP_WIN;_CRT_SECURE_NO_WARNINGS;GLFW_EXPOSE_NATIVE_WIN32;GLFW_EXPOSE_NATIVE_WGL;_WIN32;__MWERKS__;CC_CORE_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||
<PrecompiledHeader>
|
||||
|
||||
@@ -380,45 +380,6 @@
|
||||
<ClCompile Include="..\external\sources\tommyds\tommy.c">
|
||||
<Filter>external\tommy</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\external\sources\tommyds\tommyalloc.c">
|
||||
<Filter>external\tommy</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\external\sources\tommyds\tommyarray.c">
|
||||
<Filter>external\tommy</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\external\sources\tommyds\tommyarrayblk.c">
|
||||
<Filter>external\tommy</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\external\sources\tommyds\tommyarrayblkof.c">
|
||||
<Filter>external\tommy</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\external\sources\tommyds\tommyarrayof.c">
|
||||
<Filter>external\tommy</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\external\sources\tommyds\tommyhash.c">
|
||||
<Filter>external\tommy</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\external\sources\tommyds\tommyhashdyn.c">
|
||||
<Filter>external\tommy</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\external\sources\tommyds\tommyhashlin.c">
|
||||
<Filter>external\tommy</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\external\sources\tommyds\tommyhashtbl.c">
|
||||
<Filter>external\tommy</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\external\sources\tommyds\tommylist.c">
|
||||
<Filter>external\tommy</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\external\sources\tommyds\tommytree.c">
|
||||
<Filter>external\tommy</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\external\sources\tommyds\tommytrie.c">
|
||||
<Filter>external\tommy</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\external\sources\tommyds\tommytrieinp.c">
|
||||
<Filter>external\tommy</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\cocos\scripting\js-bindings\auto\jsb_gfx_auto.cpp">
|
||||
<Filter>js-bindings\auto</Filter>
|
||||
</ClCompile>
|
||||
@@ -560,6 +521,66 @@
|
||||
<ClCompile Include="..\cocos\scripting\js-bindings\auto\jsb_gles2_auto.cpp">
|
||||
<Filter>js-bindings\auto</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\cocos\renderer\gfx-vulkan\VKBindingLayout.cc">
|
||||
<Filter>renderer\gfx-vulkan</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\cocos\renderer\gfx-vulkan\VKBuffer.cc">
|
||||
<Filter>renderer\gfx-vulkan</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\cocos\renderer\gfx-vulkan\VKCommandAllocator.cc">
|
||||
<Filter>renderer\gfx-vulkan</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\cocos\renderer\gfx-vulkan\VKCommandBuffer.cc">
|
||||
<Filter>renderer\gfx-vulkan</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\cocos\renderer\gfx-vulkan\VKCommands.cc">
|
||||
<Filter>renderer\gfx-vulkan</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\cocos\renderer\gfx-vulkan\VKContext.cc">
|
||||
<Filter>renderer\gfx-vulkan</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\cocos\renderer\gfx-vulkan\VKDevice.cc">
|
||||
<Filter>renderer\gfx-vulkan</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\cocos\renderer\gfx-vulkan\VKFramebuffer.cc">
|
||||
<Filter>renderer\gfx-vulkan</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\cocos\renderer\gfx-vulkan\VKInputAssembler.cc">
|
||||
<Filter>renderer\gfx-vulkan</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\cocos\renderer\gfx-vulkan\VKPipelineLayout.cc">
|
||||
<Filter>renderer\gfx-vulkan</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\cocos\renderer\gfx-vulkan\VKPipelineState.cc">
|
||||
<Filter>renderer\gfx-vulkan</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\cocos\renderer\gfx-vulkan\VKQueue.cc">
|
||||
<Filter>renderer\gfx-vulkan</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\cocos\renderer\gfx-vulkan\VKRenderPass.cc">
|
||||
<Filter>renderer\gfx-vulkan</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\cocos\renderer\gfx-vulkan\VKSampler.cc">
|
||||
<Filter>renderer\gfx-vulkan</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\cocos\renderer\gfx-vulkan\VKShader.cc">
|
||||
<Filter>renderer\gfx-vulkan</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\cocos\renderer\gfx-vulkan\VKStd.cc">
|
||||
<Filter>renderer\gfx-vulkan</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\cocos\renderer\gfx-vulkan\VKTexture.cc">
|
||||
<Filter>renderer\gfx-vulkan</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\cocos\renderer\gfx-vulkan\VKTextureView.cc">
|
||||
<Filter>renderer\gfx-vulkan</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\cocos\renderer\gfx-vulkan\VKWindow.cc">
|
||||
<Filter>renderer\gfx-vulkan</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\cocos\renderer\gfx-vulkan\volk.c">
|
||||
<Filter>renderer\gfx-vulkan</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\cocos\base\base64.h">
|
||||
@@ -1070,51 +1091,6 @@
|
||||
<ClInclude Include="..\external\sources\tommyds\tommy.h">
|
||||
<Filter>external\tommy</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\external\sources\tommyds\tommyalloc.h">
|
||||
<Filter>external\tommy</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\external\sources\tommyds\tommyarray.h">
|
||||
<Filter>external\tommy</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\external\sources\tommyds\tommyarrayblk.h">
|
||||
<Filter>external\tommy</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\external\sources\tommyds\tommyarrayblkof.h">
|
||||
<Filter>external\tommy</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\external\sources\tommyds\tommyarrayof.h">
|
||||
<Filter>external\tommy</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\external\sources\tommyds\tommychain.h">
|
||||
<Filter>external\tommy</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\external\sources\tommyds\tommyhash.h">
|
||||
<Filter>external\tommy</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\external\sources\tommyds\tommyhashdyn.h">
|
||||
<Filter>external\tommy</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\external\sources\tommyds\tommyhashlin.h">
|
||||
<Filter>external\tommy</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\external\sources\tommyds\tommyhashtbl.h">
|
||||
<Filter>external\tommy</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\external\sources\tommyds\tommylist.h">
|
||||
<Filter>external\tommy</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\external\sources\tommyds\tommytree.h">
|
||||
<Filter>external\tommy</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\external\sources\tommyds\tommytrie.h">
|
||||
<Filter>external\tommy</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\external\sources\tommyds\tommytrieinp.h">
|
||||
<Filter>external\tommy</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\external\sources\tommyds\tommytypes.h">
|
||||
<Filter>external\tommy</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\cocos\scripting\js-bindings\auto\jsb_gfx_auto.hpp">
|
||||
<Filter>js-bindings\auto</Filter>
|
||||
</ClInclude>
|
||||
@@ -1271,6 +1247,81 @@
|
||||
<ClInclude Include="..\cocos\scripting\js-bindings\auto\jsb_gles2_auto.hpp">
|
||||
<Filter>js-bindings\auto</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\cocos\renderer\gfx-vulkan\GFXVulkan.h">
|
||||
<Filter>renderer\gfx-vulkan</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\cocos\renderer\gfx-vulkan\VKBindingLayout.h">
|
||||
<Filter>renderer\gfx-vulkan</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\cocos\renderer\gfx-vulkan\VKBuffer.h">
|
||||
<Filter>renderer\gfx-vulkan</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\cocos\renderer\gfx-vulkan\VKCommandAllocator.h">
|
||||
<Filter>renderer\gfx-vulkan</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\cocos\renderer\gfx-vulkan\VKCommandBuffer.h">
|
||||
<Filter>renderer\gfx-vulkan</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\cocos\renderer\gfx-vulkan\VKCommands.h">
|
||||
<Filter>renderer\gfx-vulkan</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\cocos\renderer\gfx-vulkan\VKContext.h">
|
||||
<Filter>renderer\gfx-vulkan</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\cocos\renderer\gfx-vulkan\VKDevice.h">
|
||||
<Filter>renderer\gfx-vulkan</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\cocos\renderer\gfx-vulkan\VKFramebuffer.h">
|
||||
<Filter>renderer\gfx-vulkan</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\cocos\renderer\gfx-vulkan\VKGPUObjects.h">
|
||||
<Filter>renderer\gfx-vulkan</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\cocos\renderer\gfx-vulkan\VKInputAssembler.h">
|
||||
<Filter>renderer\gfx-vulkan</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\cocos\renderer\gfx-vulkan\VKPipelineLayout.h">
|
||||
<Filter>renderer\gfx-vulkan</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\cocos\renderer\gfx-vulkan\VKPipelineState.h">
|
||||
<Filter>renderer\gfx-vulkan</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\cocos\renderer\gfx-vulkan\VKQueue.h">
|
||||
<Filter>renderer\gfx-vulkan</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\cocos\renderer\gfx-vulkan\VKRenderPass.h">
|
||||
<Filter>renderer\gfx-vulkan</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\cocos\renderer\gfx-vulkan\VKSampler.h">
|
||||
<Filter>renderer\gfx-vulkan</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\cocos\renderer\gfx-vulkan\VKShader.h">
|
||||
<Filter>renderer\gfx-vulkan</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\cocos\renderer\gfx-vulkan\VKSPIRV.h">
|
||||
<Filter>renderer\gfx-vulkan</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\cocos\renderer\gfx-vulkan\VKStateCache.h">
|
||||
<Filter>renderer\gfx-vulkan</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\cocos\renderer\gfx-vulkan\VKStd.h">
|
||||
<Filter>renderer\gfx-vulkan</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\cocos\renderer\gfx-vulkan\VKTexture.h">
|
||||
<Filter>renderer\gfx-vulkan</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\cocos\renderer\gfx-vulkan\VKTextureView.h">
|
||||
<Filter>renderer\gfx-vulkan</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\cocos\renderer\gfx-vulkan\VKUtils.h">
|
||||
<Filter>renderer\gfx-vulkan</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\cocos\renderer\gfx-vulkan\VKWindow.h">
|
||||
<Filter>renderer\gfx-vulkan</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\cocos\renderer\gfx-vulkan\volk.h">
|
||||
<Filter>renderer\gfx-vulkan</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Filter Include="base">
|
||||
@@ -1384,6 +1435,9 @@
|
||||
<Filter Include="renderer\gfx-gles2">
|
||||
<UniqueIdentifier>{6cd7b083-875a-4f76-8de5-e7c3f7baba1d}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="renderer\gfx-vulkan">
|
||||
<UniqueIdentifier>{58b6724a-9662-42af-afa5-e49c7b9ade5b}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\cocos\math\Mat4.inl">
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
add_subdirectory(core)
|
||||
|
||||
if(COCOS_PLATFORM_WIN32)
|
||||
add_subdirectory(gfx-gles2)
|
||||
add_subdirectory(gfx-gles3)
|
||||
add_subdirectory(gfx-vulkan)
|
||||
elseif(COCOS_PLATFORM_IOS)
|
||||
add_subdirectory(gfx-gles3)
|
||||
add_subdirectory(gfx-metal)
|
||||
|
||||
@@ -306,15 +306,15 @@ Note:
|
||||
#define CC_TOSTR(s) #s
|
||||
|
||||
#if (CC_PLATFORM == CC_PLATFORM_WINDOWS)
|
||||
# ifdef CC_STATIC
|
||||
# define CC_CORE_API
|
||||
# else
|
||||
//# ifdef CC_STATIC
|
||||
//# define CC_CORE_API
|
||||
//# else
|
||||
# ifdef CC_CORE_EXPORTS
|
||||
# define CC_CORE_API __declspec(dllexport)
|
||||
# else
|
||||
# define CC_CORE_API __declspec(dllimport)
|
||||
# endif
|
||||
# endif
|
||||
//# endif
|
||||
#else
|
||||
# define CC_CORE_API
|
||||
#endif
|
||||
|
||||
@@ -44,9 +44,9 @@ protected:
|
||||
GFXDevice* _device = nullptr;
|
||||
GFXCommandAllocator* _allocator = nullptr;
|
||||
GFXCommandBufferType _type = GFXCommandBufferType::PRIMARY;
|
||||
uint _numDrawCalls = 0;
|
||||
uint _numInstances = 0;
|
||||
uint _numTriangles = 0;
|
||||
uint32_t _numDrawCalls = 0;
|
||||
uint32_t _numInstances = 0;
|
||||
uint32_t _numTriangles = 0;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
@@ -4,13 +4,15 @@
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
#define INITIAL_CAPACITY 1
|
||||
|
||||
template <typename T, typename = std::enable_if<std::is_base_of<GFXCmd, T>::value>>
|
||||
class GFXCommandPool {
|
||||
public:
|
||||
GFXCommandPool(): _freeCmds(1) {
|
||||
_frees = new T*[1];
|
||||
_count = 1;
|
||||
_freeIdx = 0;
|
||||
GFXCommandPool(): _freeCmds(INITIAL_CAPACITY) {
|
||||
_frees = new T*[INITIAL_CAPACITY];
|
||||
_count = INITIAL_CAPACITY;
|
||||
_freeIdx = INITIAL_CAPACITY - 1;
|
||||
for (uint i = 0; i < _count; ++i) {
|
||||
_frees[i] = CC_NEW(T);
|
||||
}
|
||||
|
||||
@@ -545,7 +545,7 @@ enum class GFXVsyncMode : uint8_t {
|
||||
RELAXED,
|
||||
// The presentation engine will always use the latest fully rendered image. Compared to OFF, no tearing will be observed. Compared to ON, battery power will be worse, especially for faster applications. If unsupported, "OFF" will be attempted next.
|
||||
MAILBOX,
|
||||
// The application is capped to using half the vertical sync time. FPS artificially capped to Half the display speed (usually 30fps) to maintain battery. Best possible battery savings. Worst possibly performance. Recommended for specific applications where battery saving is critical.
|
||||
// The application is capped to using half the vertical sync time. FPS artificially capped to Half the display speed (usually 30fps) to maintain battery. Best possible battery savings. Worst possible performance. Recommended for specific applications where battery saving is critical.
|
||||
HALF,
|
||||
};
|
||||
|
||||
@@ -621,7 +621,7 @@ struct GFXViewport {
|
||||
uint width = 0;
|
||||
uint height = 0;
|
||||
float minDepth = 0.0f;
|
||||
float maxDepth = 0.0f;
|
||||
float maxDepth = 1.0f;
|
||||
|
||||
bool operator ==(const GFXViewport& rs)
|
||||
{
|
||||
@@ -679,7 +679,7 @@ struct GFXWindowInfo {
|
||||
struct GFXContextInfo {
|
||||
uintptr_t windowHandle = 0;
|
||||
GFXContext* sharedCtx = nullptr;
|
||||
GFXVsyncMode vsyncMode = GFXVsyncMode::OFF;
|
||||
GFXVsyncMode vsyncMode = GFXVsyncMode::RELAXED;
|
||||
};
|
||||
|
||||
struct GFXBufferInfo {
|
||||
|
||||
@@ -14,6 +14,7 @@ class CC_CORE_API GFXDevice : public Object {
|
||||
virtual bool initialize(const GFXDeviceInfo& info) = 0;
|
||||
virtual void destroy() = 0;
|
||||
virtual void resize(uint width, uint height) = 0;
|
||||
virtual void begin() = 0;
|
||||
virtual void present() = 0;
|
||||
virtual GFXWindow* createWindow(const GFXWindowInfo& info) = 0;
|
||||
virtual GFXQueue* createQueue(const GFXQueueInfo& info) = 0;
|
||||
|
||||
@@ -16,6 +16,7 @@ public:
|
||||
bool initialize(const GFXDeviceInfo& info) override;
|
||||
void destroy() override;
|
||||
void resize(uint width, uint height) override;
|
||||
void begin() override {};
|
||||
void present() override;
|
||||
GFXWindow* createWindow(const GFXWindowInfo& info) override;
|
||||
GFXQueue* createQueue(const GFXQueueInfo& info) override;
|
||||
|
||||
@@ -1 +1 @@
|
||||
#include "GLES2Std.h"
|
||||
#include "GLES2Std.h"
|
||||
|
||||
@@ -16,6 +16,7 @@ public:
|
||||
bool initialize(const GFXDeviceInfo& info) override;
|
||||
void destroy() override;
|
||||
void resize(uint width, uint height) override;
|
||||
void begin() override {};
|
||||
void present() override;
|
||||
GFXWindow* createWindow(const GFXWindowInfo& info) override;
|
||||
GFXQueue* createQueue(const GFXQueueInfo& info) override;
|
||||
|
||||
@@ -14,13 +14,13 @@ GLES3Queue::~GLES3Queue() {
|
||||
|
||||
bool GLES3Queue::initialize(const GFXQueueInfo &info) {
|
||||
_type = info.type;
|
||||
_status = GFXStatus::SUCCESS;
|
||||
_status = GFXStatus::SUCCESS;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void GLES3Queue::destroy() {
|
||||
_status = GFXStatus::UNREADY;
|
||||
_status = GFXStatus::UNREADY;
|
||||
}
|
||||
|
||||
void GLES3Queue::submit(const std::vector<GFXCommandBuffer*>& cmd_buffs) {
|
||||
|
||||
@@ -1 +1 @@
|
||||
#include "GLES3Std.h"
|
||||
#include "GLES3Std.h"
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
set(TARGET_NAME GFXVulkan)
|
||||
|
||||
message(STATUS "Target: ${TARGET_NAME}...")
|
||||
# ---------------------------------------------------------------------
|
||||
# set include files
|
||||
|
||||
set(INCLUDE_FILES
|
||||
${GFX_EXTERNAL_PATH}/khronos
|
||||
${GFX_EXTERNAL_PATH}/glslang
|
||||
${COCOS_SRC_PATH}/renderer/core
|
||||
${COCOS_SRC_PATH}/renderer/gfx-vulkan
|
||||
)
|
||||
|
||||
add_subdirectory(${GFX_EXTERNAL_PATH}/glslang glslang)
|
||||
|
||||
if(WIN32)
|
||||
add_definitions("-DVK_USE_PLATFORM_WIN32_KHR")
|
||||
add_definitions("-DNOMINMAX")
|
||||
elseif(COCOS_PLATFORM_IOS)
|
||||
add_definitions("-DVK_USE_PLATFORM_IOS_MVK")
|
||||
elseif(COCOS_PLATFORM_OSX)
|
||||
add_definitions("-DVK_USE_PLATFORM_MACOS_MVK")
|
||||
else()
|
||||
add_definitions("-DVK_USE_PLATFORM_XLIB_KHR")
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
list(APPEND INCLUDE_FILES ${GFX_EXTERNAL_PATH}/pvrsdk/include)
|
||||
|
||||
if(COCOS_CPU_X64)
|
||||
set(PVRSDK_LIB_DIR ${GFX_EXTERNAL_PATH}/pvrsdk/lib/Windows_x86_64)
|
||||
else()
|
||||
set(PVRSDK_LIB_DIR ${GFX_EXTERNAL_PATH}/pvrsdk/lib/Windows_x86_32)
|
||||
endif()
|
||||
|
||||
link_libraries(
|
||||
${PVRSDK_LIB_DIR}/libEGL.lib
|
||||
${PVRSDK_LIB_DIR}/libGLESv2.lib
|
||||
)
|
||||
endif()
|
||||
|
||||
include_directories( ${INCLUDE_FILES} )
|
||||
|
||||
# ---------------------------------------------------------------------
|
||||
|
||||
file(GLOB_RECURSE HEADER_FILES *.h)
|
||||
file(GLOB_RECURSE SOURCE_CPP_FILES *.cpp *.cc)
|
||||
file(GLOB_RECURSE SOURCE_C_FILES *.c)
|
||||
|
||||
if(COCOS_PLATFORM_IOS OR COCOS_PLATFORM_OSX)
|
||||
file(GLOB_RECURSE SOURCE_MM_FILES *.m *.mm)
|
||||
endif()
|
||||
|
||||
set(ALL_FILES ${HEADER_FILES} ${SOURCE_CPP_FILES} ${SOURCE_C_FILES})
|
||||
|
||||
if(COCOS_PLATFORM_IOS OR COCOS_PLATFORM_OSX)
|
||||
set(ALL_FILES ${ALL_FILES} ${SOURCE_MM_FILES})
|
||||
endif()
|
||||
|
||||
if(COCOS_PLATFORM_IOS OR COCOS_PLATFORM_OSX)
|
||||
list(REMOVE_ITEM ALL_FILES "${COCOS_SRC_PATH}/renderer/gfx-vulkan/gles3w.c")
|
||||
else()
|
||||
list(REMOVE_ITEM ALL_FILES "${COCOS_SRC_PATH}/renderer/gfx-vulkan/gles3w.mm")
|
||||
endif()
|
||||
|
||||
add_definitions("-DCC_VK_EXPORTS")
|
||||
if(WIN32)
|
||||
add_definitions("-DGLEW_BUILD")
|
||||
endif()
|
||||
if(COCOS_UNICODE)
|
||||
add_definitions("-DUNICODE -D_UNICODE")
|
||||
endif()
|
||||
|
||||
if (COCOS_STATIC)
|
||||
add_library(${TARGET_NAME} STATIC ${HEADER_FILES} ${ALL_FILES})
|
||||
else()
|
||||
add_library(${TARGET_NAME} SHARED ${HEADER_FILES} ${ALL_FILES})
|
||||
endif()
|
||||
|
||||
target_link_libraries(${TARGET_NAME} Core glslang SPIRV)
|
||||
|
||||
set_target_properties(${TARGET_NAME} PROPERTIES OUTPUT_NAME CCGFXVulkan)
|
||||
set_target_properties(${TARGET_NAME} PROPERTIES OUTPUT_NAME_DEBUG CCGFXVulkan_d)
|
||||
|
||||
use_precompiled_header("${CMAKE_CURRENT_SOURCE_DIR}/VKStd.h" "${CMAKE_CURRENT_SOURCE_DIR}/VKStd.cpp" SOURCE_CPP_FILES)
|
||||
|
||||
message(STATUS "${TARGET_NAME} configuration completed.")
|
||||
@@ -0,0 +1,7 @@
|
||||
#ifndef CC_GFXVULKAN_VK_H_
|
||||
#define CC_GFXVULKAN_VK_H_
|
||||
|
||||
#include "VKStd.h"
|
||||
#include "VKDevice.h"
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,100 @@
|
||||
#include "VKStd.h"
|
||||
#include "VKBindingLayout.h"
|
||||
#include "VKCommands.h"
|
||||
#include "VKBuffer.h"
|
||||
#include "VKTextureView.h"
|
||||
#include "VKSampler.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
CCVKBindingLayout::CCVKBindingLayout(GFXDevice* device)
|
||||
: GFXBindingLayout(device)
|
||||
{
|
||||
}
|
||||
|
||||
CCVKBindingLayout::~CCVKBindingLayout()
|
||||
{
|
||||
}
|
||||
|
||||
bool CCVKBindingLayout::initialize(const GFXBindingLayoutInfo &info)
|
||||
{
|
||||
if (info.bindings.size())
|
||||
{
|
||||
_bindingUnits.resize(info.bindings.size());
|
||||
for (size_t i = 0; i < _bindingUnits.size(); ++i)
|
||||
{
|
||||
GFXBindingUnit& bindingUnit = _bindingUnits[i];
|
||||
const GFXBinding& binding = info.bindings[i];
|
||||
bindingUnit.binding = binding.binding;
|
||||
bindingUnit.type = binding.type;
|
||||
bindingUnit.name = binding.name;
|
||||
}
|
||||
}
|
||||
|
||||
_gpuBindingLayout = CC_NEW(CCVKGPUBindingLayout);
|
||||
_gpuBindingLayout->gpuBindings.resize(_bindingUnits.size());
|
||||
for (size_t i = 0; i < _gpuBindingLayout->gpuBindings.size(); ++i)
|
||||
{
|
||||
CCVKGPUBinding& gpuBinding = _gpuBindingLayout->gpuBindings[i];
|
||||
const GFXBindingUnit& bindingUnit = _bindingUnits[i];
|
||||
gpuBinding.binding = bindingUnit.binding;
|
||||
gpuBinding.type = bindingUnit.type;
|
||||
gpuBinding.name = bindingUnit.name;
|
||||
}
|
||||
|
||||
CCVKCmdFuncCreateBindingLayout((CCVKDevice*)_device, _gpuBindingLayout);
|
||||
|
||||
_status = GFXStatus::SUCCESS;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CCVKBindingLayout::destroy()
|
||||
{
|
||||
if (_gpuBindingLayout)
|
||||
{
|
||||
CCVKCmdFuncDestroyBindingLayout((CCVKDevice*)_device, _gpuBindingLayout);
|
||||
CC_DELETE(_gpuBindingLayout);
|
||||
_gpuBindingLayout = nullptr;
|
||||
}
|
||||
|
||||
_status = GFXStatus::UNREADY;
|
||||
}
|
||||
|
||||
void CCVKBindingLayout::update()
|
||||
{
|
||||
if (_isDirty && _gpuBindingLayout)
|
||||
{
|
||||
for (size_t i = 0; i < _bindingUnits.size(); ++i)
|
||||
{
|
||||
GFXBindingUnit& bindingUnit = _bindingUnits[i];
|
||||
switch (bindingUnit.type)
|
||||
{
|
||||
case GFXBindingType::UNIFORM_BUFFER:
|
||||
{
|
||||
if (bindingUnit.buffer)
|
||||
{
|
||||
_gpuBindingLayout->gpuBindings[i].gpuBuffer = ((CCVKBuffer*)bindingUnit.buffer)->gpuBuffer();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case GFXBindingType::SAMPLER:
|
||||
{
|
||||
if (bindingUnit.texView)
|
||||
{
|
||||
_gpuBindingLayout->gpuBindings[i].gpuTexView = ((CCVKTextureView*)bindingUnit.texView)->gpuTexView();
|
||||
}
|
||||
if (bindingUnit.sampler)
|
||||
{
|
||||
_gpuBindingLayout->gpuBindings[i].gpuSampler = ((CCVKSampler*)bindingUnit.sampler)->gpuSampler();
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:;
|
||||
}
|
||||
}
|
||||
_isDirty = false;
|
||||
}
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
@@ -0,0 +1,27 @@
|
||||
#ifndef CC_GFXVULKAN_CCVK_BINDING_LAYOUT_H_
|
||||
#define CC_GFXVULKAN_CCVK_BINDING_LAYOUT_H_
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class CCVKGPUBindingLayout;
|
||||
|
||||
class CC_VULKAN_API CCVKBindingLayout : public GFXBindingLayout
|
||||
{
|
||||
public:
|
||||
CCVKBindingLayout(GFXDevice* device);
|
||||
~CCVKBindingLayout();
|
||||
|
||||
public:
|
||||
bool initialize(const GFXBindingLayoutInfo& info);
|
||||
void destroy();
|
||||
void update();
|
||||
|
||||
CC_INLINE CCVKGPUBindingLayout* gpuBindingLayout() const { return _gpuBindingLayout; }
|
||||
|
||||
private:
|
||||
CCVKGPUBindingLayout* _gpuBindingLayout = nullptr;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,106 @@
|
||||
#include "VKStd.h"
|
||||
#include "VKBuffer.h"
|
||||
#include "VKCommands.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
CCVKBuffer::CCVKBuffer(GFXDevice* device)
|
||||
: GFXBuffer(device)
|
||||
{
|
||||
}
|
||||
|
||||
CCVKBuffer::~CCVKBuffer()
|
||||
{
|
||||
}
|
||||
|
||||
bool CCVKBuffer::initialize(const GFXBufferInfo& info)
|
||||
{
|
||||
_usage = info.usage;
|
||||
_memUsage = info.memUsage;
|
||||
_size = info.size;
|
||||
_stride = std::max(info.stride, 1u);
|
||||
_count = _size / _stride;
|
||||
_flags = info.flags;
|
||||
|
||||
if ((_flags & GFXBufferFlagBit::BAKUP_BUFFER) && _size > 0)
|
||||
{
|
||||
_buffer = (uint8_t*)CC_MALLOC(_size);
|
||||
_device->getMemoryStatus().bufferSize += _size;
|
||||
}
|
||||
|
||||
_gpuBuffer = CC_NEW(CCVKGPUBuffer);
|
||||
_gpuBuffer->usage = _usage;
|
||||
_gpuBuffer->memUsage = _memUsage;
|
||||
_gpuBuffer->size = _size;
|
||||
_gpuBuffer->stride = _stride;
|
||||
_gpuBuffer->count = _count;
|
||||
|
||||
//if (!(_usage & GFXBufferUsageBit::INDIRECT))
|
||||
//{
|
||||
// _gpuBuffer->buffer = _buffer;
|
||||
//}
|
||||
|
||||
CCVKCmdFuncCreateBuffer((CCVKDevice*)_device, _gpuBuffer);
|
||||
_device->getMemoryStatus().bufferSize += _size;
|
||||
_status = GFXStatus::SUCCESS;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CCVKBuffer::destroy()
|
||||
{
|
||||
if (_gpuBuffer)
|
||||
{
|
||||
CCVKCmdFuncDestroyBuffer((CCVKDevice*)_device, _gpuBuffer);
|
||||
_device->getMemoryStatus().bufferSize -= _size;
|
||||
CC_DELETE(_gpuBuffer);
|
||||
_gpuBuffer = nullptr;
|
||||
}
|
||||
|
||||
if (_buffer)
|
||||
{
|
||||
CC_FREE(_buffer);
|
||||
_device->getMemoryStatus().bufferSize -= _size;
|
||||
_buffer = nullptr;
|
||||
}
|
||||
|
||||
_status = GFXStatus::UNREADY;
|
||||
}
|
||||
|
||||
void CCVKBuffer::resize(uint size)
|
||||
{
|
||||
if (_size != size)
|
||||
{
|
||||
const uint old_size = _size;
|
||||
_size = size;
|
||||
_count = _size / _stride;
|
||||
|
||||
GFXMemoryStatus& status = _device->getMemoryStatus();
|
||||
_gpuBuffer->size = _size;
|
||||
_gpuBuffer->count = _count;
|
||||
CCVKCmdFuncResizeBuffer((CCVKDevice*)_device, _gpuBuffer);
|
||||
status.bufferSize -= old_size;
|
||||
status.bufferSize += _size;
|
||||
|
||||
if (_buffer)
|
||||
{
|
||||
const uint8_t* old_buff = _buffer;
|
||||
_buffer = (uint8_t*)CC_MALLOC(_size);
|
||||
memcpy(_buffer, old_buff, old_size);
|
||||
CC_FREE(_buffer);
|
||||
status.bufferSize -= old_size;
|
||||
status.bufferSize += _size;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CCVKBuffer::update(void* buffer, uint offset, uint size)
|
||||
{
|
||||
if (_buffer)
|
||||
{
|
||||
memcpy(_buffer + offset, buffer, size);
|
||||
}
|
||||
CCVKCmdFuncUpdateBuffer((CCVKDevice*)_device, _gpuBuffer, buffer, offset, size);
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
@@ -0,0 +1,28 @@
|
||||
#ifndef CC_GFXVULKAN_CCVK_BUFFER_H_
|
||||
#define CC_GFXVULKAN_CCVK_BUFFER_H_
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class CCVKGPUBuffer;
|
||||
|
||||
class CC_VULKAN_API CCVKBuffer : public GFXBuffer
|
||||
{
|
||||
public:
|
||||
CCVKBuffer(GFXDevice* device);
|
||||
~CCVKBuffer();
|
||||
|
||||
public:
|
||||
bool initialize(const GFXBufferInfo& info);
|
||||
void destroy();
|
||||
void resize(uint size);
|
||||
void update(void* buffer, uint offset, uint size);
|
||||
|
||||
CC_INLINE CCVKGPUBuffer* gpuBuffer() const { return _gpuBuffer; }
|
||||
|
||||
private:
|
||||
CCVKGPUBuffer* _gpuBuffer = nullptr;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,33 @@
|
||||
#include "VKStd.h"
|
||||
#include "VKCommandAllocator.h"
|
||||
#include "VKCommands.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
CCVKCommandAllocator::CCVKCommandAllocator(GFXDevice* device)
|
||||
: GFXCommandAllocator(device)
|
||||
{
|
||||
}
|
||||
|
||||
CCVKCommandAllocator::~CCVKCommandAllocator()
|
||||
{
|
||||
}
|
||||
|
||||
bool CCVKCommandAllocator::initialize(const GFXCommandAllocatorInfo& info)
|
||||
{
|
||||
_gpuCommandPool = CC_NEW(CCVKGPUCommandPool);
|
||||
|
||||
CCVKCmdFuncCreateCommandPool((CCVKDevice*)_device, _gpuCommandPool);
|
||||
|
||||
_status = GFXStatus::SUCCESS;
|
||||
return true;
|
||||
}
|
||||
|
||||
void CCVKCommandAllocator::destroy()
|
||||
{
|
||||
CCVKCmdFuncDestroyCommandPool((CCVKDevice*)_device, _gpuCommandPool);
|
||||
|
||||
_status = GFXStatus::UNREADY;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
@@ -0,0 +1,25 @@
|
||||
#ifndef CC_GFXVULKAN_CCVK_COMMAND_ALLOCATOR_H_
|
||||
#define CC_GFXVULKAN_CCVK_COMMAND_ALLOCATOR_H_
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class CCVKGPUCommandPool;
|
||||
|
||||
class CC_VULKAN_API CCVKCommandAllocator : public GFXCommandAllocator {
|
||||
public:
|
||||
CCVKCommandAllocator(GFXDevice* device);
|
||||
~CCVKCommandAllocator();
|
||||
|
||||
public:
|
||||
bool initialize(const GFXCommandAllocatorInfo& info);
|
||||
void destroy();
|
||||
|
||||
CC_INLINE CCVKGPUCommandPool* gpuCommandPool() { return _gpuCommandPool; }
|
||||
|
||||
private:
|
||||
CCVKGPUCommandPool* _gpuCommandPool;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,361 @@
|
||||
#include "VKStd.h"
|
||||
#include "VKCommandBuffer.h"
|
||||
#include "VKCommands.h"
|
||||
#include "VKCommandAllocator.h"
|
||||
#include "VKFramebuffer.h"
|
||||
|
||||
#include "VKPipelineState.h"
|
||||
#include "VKBindingLayout.h"
|
||||
#include "VKInputAssembler.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
CCVKCommandBuffer::CCVKCommandBuffer(GFXDevice* device)
|
||||
: GFXCommandBuffer(device)
|
||||
{
|
||||
}
|
||||
|
||||
CCVKCommandBuffer::~CCVKCommandBuffer()
|
||||
{
|
||||
}
|
||||
|
||||
bool CCVKCommandBuffer::initialize(const GFXCommandBufferInfo& info)
|
||||
{
|
||||
if (!info.allocator)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_allocator = info.allocator;
|
||||
_type = info.type;
|
||||
|
||||
_gpuCommandBuffer = CC_NEW(CCVKGPUCommandBuffer);
|
||||
_gpuCommandBuffer->type = _type;
|
||||
_gpuCommandBuffer->commandPool = ((CCVKCommandAllocator*)_allocator)->gpuCommandPool();
|
||||
CCVKCmdFuncAllocateCommandBuffer((CCVKDevice*)_device, _gpuCommandBuffer);
|
||||
|
||||
_status = GFXStatus::SUCCESS;
|
||||
return true;
|
||||
}
|
||||
|
||||
void CCVKCommandBuffer::destroy()
|
||||
{
|
||||
if (_gpuCommandBuffer)
|
||||
{
|
||||
CCVKCmdFuncFreeCommandBuffer((CCVKDevice*)_device, _gpuCommandBuffer);
|
||||
CC_DELETE(_gpuCommandBuffer);
|
||||
_gpuCommandBuffer = nullptr;
|
||||
}
|
||||
|
||||
_allocator = nullptr;
|
||||
_status = GFXStatus::UNREADY;
|
||||
}
|
||||
|
||||
void CCVKCommandBuffer::begin()
|
||||
{
|
||||
_curGPUPipelineState = nullptr;
|
||||
_curGPUBlendLayout = nullptr;
|
||||
_curGPUInputAssember = nullptr;
|
||||
_numDrawCalls = 0;
|
||||
_numInstances = 0;
|
||||
_numTriangles = 0;
|
||||
|
||||
VkCommandBufferBeginInfo beginInfo{ VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO };
|
||||
beginInfo.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
|
||||
|
||||
if (_type == GFXCommandBufferType::SECONDARY)
|
||||
{
|
||||
VkCommandBufferInheritanceInfo inheritance{ VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO };
|
||||
// TODO
|
||||
//beginInfo.pInheritanceInfo = &inheritance;
|
||||
}
|
||||
|
||||
VK_CHECK(vkBeginCommandBuffer(_gpuCommandBuffer->vkCommandBuffer, &beginInfo));
|
||||
}
|
||||
|
||||
void CCVKCommandBuffer::end()
|
||||
{
|
||||
if (_isStateInvalid)
|
||||
{
|
||||
BindStates();
|
||||
}
|
||||
_curGPUFBO = nullptr;
|
||||
|
||||
VK_CHECK(vkEndCommandBuffer(_gpuCommandBuffer->vkCommandBuffer));
|
||||
}
|
||||
|
||||
void CCVKCommandBuffer::beginRenderPass(GFXFramebuffer* fbo, const GFXRect& renderArea,
|
||||
GFXClearFlags clearFlags, const std::vector<GFXColor>& colors, float depth, int stencil)
|
||||
{
|
||||
_curGPUFBO = ((CCVKFramebuffer*)fbo)->gpuFBO();
|
||||
auto &renderPass = _curGPUFBO->isOffscreen ? _curGPUFBO->gpuRenderPass : _curGPUFBO->swapchain->renderPass;
|
||||
auto &barriers = renderPass->beginBarriers;
|
||||
auto &clearValues = renderPass->clearValues;
|
||||
auto attachmentCount = barriers.size();
|
||||
|
||||
if (attachmentCount)
|
||||
{
|
||||
for (uint32_t i = 0u; i < attachmentCount - 1; i++)
|
||||
{
|
||||
barriers[i].image = _curGPUFBO->isOffscreen ? _curGPUFBO->gpuColorViews[i]->gpuTexture->vkImage :
|
||||
_curGPUFBO->swapchain->swapchainImages[_curGPUFBO->swapchain->curImageIndex];
|
||||
clearValues[i].color = { colors[i].r, colors[i].g, colors[i].b, colors[i].a };
|
||||
}
|
||||
barriers[attachmentCount - 1].image = _curGPUFBO->isOffscreen ? _curGPUFBO->gpuDepthStencilView->gpuTexture->vkImage :
|
||||
_curGPUFBO->swapchain->depthStencilImages[_curGPUFBO->swapchain->curImageIndex];
|
||||
clearValues[attachmentCount - 1].depthStencil = { depth, (uint32_t)stencil };
|
||||
|
||||
vkCmdPipelineBarrier(_gpuCommandBuffer->vkCommandBuffer, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT,
|
||||
VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT,
|
||||
VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, barriers.size(), barriers.data());
|
||||
}
|
||||
|
||||
VkRenderPassBeginInfo passBeginInfo{ VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO };
|
||||
passBeginInfo.renderPass = _curGPUFBO->gpuRenderPass->vkRenderPass;
|
||||
passBeginInfo.framebuffer = _curGPUFBO->isOffscreen ? _curGPUFBO->vkFramebuffer :
|
||||
_curGPUFBO->swapchain->vkSwapchainFramebuffers[_curGPUFBO->swapchain->curImageIndex];
|
||||
passBeginInfo.renderArea.extent.width = renderArea.width;
|
||||
passBeginInfo.renderArea.extent.height = renderArea.height;
|
||||
passBeginInfo.clearValueCount = clearValues.size();
|
||||
passBeginInfo.pClearValues = clearValues.data();
|
||||
|
||||
vkCmdBeginRenderPass(_gpuCommandBuffer->vkCommandBuffer, &passBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
|
||||
|
||||
VkViewport viewport{ (float)renderArea.x, (float)(renderArea.height - renderArea.y), (float)renderArea.width, -(float)renderArea.height, 0, 1 };
|
||||
vkCmdSetViewport(_gpuCommandBuffer->vkCommandBuffer, 0, 1, &viewport);
|
||||
|
||||
VkRect2D scissor{ { renderArea.x, renderArea.y }, { renderArea.width, renderArea.height } };
|
||||
vkCmdSetScissor(_gpuCommandBuffer->vkCommandBuffer, 0, 1, &scissor);
|
||||
}
|
||||
|
||||
void CCVKCommandBuffer::endRenderPass()
|
||||
{
|
||||
vkCmdEndRenderPass(_gpuCommandBuffer->vkCommandBuffer);
|
||||
|
||||
auto &renderPass = _curGPUFBO->isOffscreen ? _curGPUFBO->gpuRenderPass : _curGPUFBO->swapchain->renderPass;
|
||||
auto &barriers = renderPass->endBarriers;
|
||||
auto attachmentCount = barriers.size();
|
||||
|
||||
if (attachmentCount)
|
||||
{
|
||||
for (uint32_t i = 0u; i < attachmentCount - 1; i++)
|
||||
{
|
||||
barriers[i].image = _curGPUFBO->isOffscreen ? _curGPUFBO->gpuColorViews[i]->gpuTexture->vkImage :
|
||||
_curGPUFBO->swapchain->swapchainImages[_curGPUFBO->swapchain->curImageIndex];
|
||||
}
|
||||
barriers[attachmentCount - 1].image = _curGPUFBO->isOffscreen ? _curGPUFBO->gpuDepthStencilView->gpuTexture->vkImage :
|
||||
_curGPUFBO->swapchain->depthStencilImages[_curGPUFBO->swapchain->curImageIndex];
|
||||
|
||||
vkCmdPipelineBarrier(_gpuCommandBuffer->vkCommandBuffer,
|
||||
VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT,
|
||||
VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_DEPENDENCY_BY_REGION_BIT,
|
||||
0, nullptr, 0, nullptr, barriers.size(), barriers.data());
|
||||
}
|
||||
|
||||
_curGPUFBO = nullptr;
|
||||
}
|
||||
|
||||
void CCVKCommandBuffer::bindPipelineState(GFXPipelineState* pso)
|
||||
{
|
||||
_curGPUPipelineState = ((CCVKPipelineState*)pso)->gpuPipelineState();
|
||||
vkCmdBindPipeline(_gpuCommandBuffer->vkCommandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, _curGPUPipelineState->vkPipeline);
|
||||
_isStateInvalid = true;
|
||||
}
|
||||
|
||||
void CCVKCommandBuffer::bindBindingLayout(GFXBindingLayout* layout)
|
||||
{
|
||||
_curGPUBlendLayout = ((CCVKBindingLayout*)layout)->gpuBindingLayout();
|
||||
_isStateInvalid = true;
|
||||
}
|
||||
|
||||
void CCVKCommandBuffer::bindInputAssembler(GFXInputAssembler* ia)
|
||||
{
|
||||
auto gpuInputAssembler = ((CCVKInputAssembler*)ia)->gpuInputAssembler();
|
||||
|
||||
vkCmdBindVertexBuffers(_gpuCommandBuffer->vkCommandBuffer, 0, gpuInputAssembler->vertexBuffers.size(),
|
||||
gpuInputAssembler->vertexBuffers.data(), gpuInputAssembler->vertexBufferOffsets.data());
|
||||
|
||||
if (gpuInputAssembler->gpuIndexBuffer)
|
||||
{
|
||||
vkCmdBindIndexBuffer(_gpuCommandBuffer->vkCommandBuffer, gpuInputAssembler->gpuIndexBuffer->vkBuffer, 0,
|
||||
gpuInputAssembler->gpuIndexBuffer->stride == 32 ? VK_INDEX_TYPE_UINT32 : VK_INDEX_TYPE_UINT16);
|
||||
}
|
||||
}
|
||||
|
||||
void CCVKCommandBuffer::setViewport(const GFXViewport& vp)
|
||||
{
|
||||
if (_curViewport != vp)
|
||||
{
|
||||
_curViewport = vp;
|
||||
VkViewport viewport{ (float)vp.left, (float)vp.top, (float)vp.width, (float)vp.height, vp.minDepth, vp.maxDepth };
|
||||
vkCmdSetViewport(_gpuCommandBuffer->vkCommandBuffer, 0, 1, &viewport);
|
||||
}
|
||||
}
|
||||
|
||||
void CCVKCommandBuffer::setScissor(const GFXRect& rect)
|
||||
{
|
||||
if (_curScissor != rect)
|
||||
{
|
||||
_curScissor = rect;
|
||||
VkRect2D scissor{ { rect.x, rect.y }, { rect.width, rect.height } };
|
||||
vkCmdSetScissor(_gpuCommandBuffer->vkCommandBuffer, 0, 1, &scissor);
|
||||
}
|
||||
}
|
||||
|
||||
void CCVKCommandBuffer::setLineWidth(const float width)
|
||||
{
|
||||
if (math::IsNotEqualF(_curLineWidth, width))
|
||||
{
|
||||
_curLineWidth = width;
|
||||
vkCmdSetLineWidth(_gpuCommandBuffer->vkCommandBuffer, width);
|
||||
}
|
||||
}
|
||||
|
||||
void CCVKCommandBuffer::setDepthBias(float constant, float clamp, float slope)
|
||||
{
|
||||
if (math::IsNotEqualF(_curDepthBias.constant, constant) ||
|
||||
math::IsNotEqualF(_curDepthBias.clamp, clamp) ||
|
||||
math::IsNotEqualF(_curDepthBias.slope, slope))
|
||||
{
|
||||
_curDepthBias.constant = constant;
|
||||
_curDepthBias.clamp = clamp;
|
||||
_curDepthBias.slope = slope;
|
||||
vkCmdSetDepthBias(_gpuCommandBuffer->vkCommandBuffer, constant, clamp, slope);
|
||||
}
|
||||
}
|
||||
|
||||
void CCVKCommandBuffer::setBlendConstants(const GFXColor& constants)
|
||||
{
|
||||
if (math::IsNotEqualF(_curBlendConstants.r, constants.r) ||
|
||||
math::IsNotEqualF(_curBlendConstants.g, constants.g) ||
|
||||
math::IsNotEqualF(_curBlendConstants.b, constants.b) ||
|
||||
math::IsNotEqualF(_curBlendConstants.a, constants.a))
|
||||
{
|
||||
_curBlendConstants.r = constants.r;
|
||||
_curBlendConstants.g = constants.g;
|
||||
_curBlendConstants.b = constants.b;
|
||||
_curBlendConstants.a = constants.a;
|
||||
vkCmdSetBlendConstants(_gpuCommandBuffer->vkCommandBuffer, reinterpret_cast<const float*>(&constants));
|
||||
}
|
||||
}
|
||||
|
||||
void CCVKCommandBuffer::setDepthBound(float minBounds, float maxBounds)
|
||||
{
|
||||
if (math::IsNotEqualF(_curDepthBounds.minBounds, minBounds) ||
|
||||
math::IsNotEqualF(_curDepthBounds.maxBounds, maxBounds))
|
||||
{
|
||||
_curDepthBounds.minBounds = minBounds;
|
||||
_curDepthBounds.maxBounds = maxBounds;
|
||||
vkCmdSetDepthBounds(_gpuCommandBuffer->vkCommandBuffer, minBounds, maxBounds);
|
||||
}
|
||||
}
|
||||
|
||||
void CCVKCommandBuffer::setStencilWriteMask(GFXStencilFace face, uint mask)
|
||||
{
|
||||
if ((_curStencilWriteMask.face != face) ||
|
||||
(_curStencilWriteMask.write_mask != mask))
|
||||
{
|
||||
_curStencilWriteMask.face = face;
|
||||
_curStencilWriteMask.write_mask = mask;
|
||||
vkCmdSetStencilWriteMask(_gpuCommandBuffer->vkCommandBuffer,
|
||||
face == GFXStencilFace::FRONT ? VK_STENCIL_FACE_FRONT_BIT : VK_STENCIL_FACE_BACK_BIT, mask);
|
||||
}
|
||||
}
|
||||
|
||||
void CCVKCommandBuffer::setStencilCompareMask(GFXStencilFace face, int reference, uint mask)
|
||||
{
|
||||
if ((_curStencilCompareMask.face != face) ||
|
||||
(_curStencilCompareMask.reference != reference) ||
|
||||
(_curStencilCompareMask.compareMask != mask))
|
||||
{
|
||||
_curStencilCompareMask.face = face;
|
||||
_curStencilCompareMask.reference = reference;
|
||||
_curStencilCompareMask.compareMask = mask;
|
||||
|
||||
VkStencilFaceFlagBits vkFace = (face == GFXStencilFace::FRONT ? VK_STENCIL_FACE_FRONT_BIT : VK_STENCIL_FACE_BACK_BIT);
|
||||
vkCmdSetStencilReference(_gpuCommandBuffer->vkCommandBuffer, vkFace, reference);
|
||||
vkCmdSetStencilCompareMask(_gpuCommandBuffer->vkCommandBuffer, vkFace, mask);
|
||||
}
|
||||
}
|
||||
|
||||
void CCVKCommandBuffer::draw(GFXInputAssembler* ia)
|
||||
{
|
||||
if ((_type == GFXCommandBufferType::PRIMARY && _curGPUFBO) ||
|
||||
(_type == GFXCommandBufferType::SECONDARY))
|
||||
{
|
||||
if (_isStateInvalid)
|
||||
{
|
||||
BindStates();
|
||||
}
|
||||
|
||||
CCVKGPUInputAssembler* gpuInputAssembler = ((CCVKInputAssembler*)ia)->gpuInputAssembler();
|
||||
GFXDrawInfo drawInfo;
|
||||
|
||||
if (gpuInputAssembler->gpuIndirectBuffer)
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
else
|
||||
{
|
||||
((CCVKInputAssembler*)ia)->extractDrawInfo(drawInfo);
|
||||
|
||||
if (gpuInputAssembler->gpuIndexBuffer && drawInfo.indexCount >= 0)
|
||||
{
|
||||
vkCmdDrawIndexed(_gpuCommandBuffer->vkCommandBuffer, drawInfo.indexCount, std::max(drawInfo.instanceCount, 1u),
|
||||
drawInfo.firstIndex, drawInfo.vertexOffset, drawInfo.firstInstance);
|
||||
}
|
||||
else
|
||||
{
|
||||
vkCmdDraw(_gpuCommandBuffer->vkCommandBuffer, drawInfo.vertexCount, std::max(drawInfo.instanceCount, 1u),
|
||||
drawInfo.firstVertex, drawInfo.firstInstance);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
CC_LOG_ERROR("Command 'draw' must be recorded inside a render pass.");
|
||||
}
|
||||
}
|
||||
|
||||
void CCVKCommandBuffer::updateBuffer(GFXBuffer* buff, void* data, uint size, uint offset)
|
||||
{
|
||||
if ((_type == GFXCommandBufferType::PRIMARY && _curGPUFBO) ||
|
||||
(_type == GFXCommandBufferType::SECONDARY))
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
CC_LOG_ERROR("Command 'updateBuffer' must be recorded inside a render pass.");
|
||||
}
|
||||
}
|
||||
|
||||
void CCVKCommandBuffer::copyBufferToTexture(GFXBuffer* src, GFXTexture* dst, GFXTextureLayout layout, const GFXBufferTextureCopyList& regions)
|
||||
{
|
||||
if ((_type == GFXCommandBufferType::PRIMARY && _curGPUFBO) ||
|
||||
(_type == GFXCommandBufferType::SECONDARY))
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
CC_LOG_ERROR("Command 'copyBufferToTexture' must be recorded inside a render pass.");
|
||||
}
|
||||
}
|
||||
|
||||
void CCVKCommandBuffer::execute(const std::vector<GFXCommandBuffer*>& cmd_buffs, uint32_t count)
|
||||
{
|
||||
for (uint i = 0; i < count; ++i)
|
||||
{
|
||||
CCVKCommandBuffer* cmd_buff = (CCVKCommandBuffer*)cmd_buffs[i];
|
||||
|
||||
_numDrawCalls += cmd_buff->getNumDrawCalls();
|
||||
_numInstances += cmd_buff->getNumInstances();
|
||||
_numTriangles += cmd_buff->getNumTris();
|
||||
}
|
||||
}
|
||||
|
||||
void CCVKCommandBuffer::BindStates()
|
||||
{
|
||||
_isStateInvalid = false;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
@@ -0,0 +1,67 @@
|
||||
#ifndef CC_GFXVULKAN_CCVK_COMMAND_BUFFER_H_
|
||||
#define CC_GFXVULKAN_CCVK_COMMAND_BUFFER_H_
|
||||
|
||||
#include "VKCommands.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class CC_VULKAN_API CCVKCommandBuffer : public GFXCommandBuffer
|
||||
{
|
||||
public:
|
||||
CCVKCommandBuffer(GFXDevice* device);
|
||||
~CCVKCommandBuffer();
|
||||
|
||||
friend class CCVKQueue;
|
||||
|
||||
public:
|
||||
bool initialize(const GFXCommandBufferInfo& info);
|
||||
void destroy();
|
||||
|
||||
void begin();
|
||||
void end();
|
||||
void beginRenderPass(GFXFramebuffer* fbo, const GFXRect& render_area, GFXClearFlags clear_flags, const std::vector<GFXColor>& colors, float depth, int stencil);
|
||||
void endRenderPass();
|
||||
void bindPipelineState(GFXPipelineState* pso);
|
||||
void bindBindingLayout(GFXBindingLayout* layout);
|
||||
void bindInputAssembler(GFXInputAssembler* ia);
|
||||
void setViewport(const GFXViewport& vp);
|
||||
void setScissor(const GFXRect& rect);
|
||||
void setLineWidth(const float width);
|
||||
void setDepthBias(float constant, float clamp, float slope);
|
||||
void setBlendConstants(const GFXColor& constants);
|
||||
void setDepthBound(float min_bounds, float max_bounds);
|
||||
void setStencilWriteMask(GFXStencilFace face, uint mask);
|
||||
void setStencilCompareMask(GFXStencilFace face, int reference, uint mask);
|
||||
void draw(GFXInputAssembler* ia);
|
||||
void updateBuffer(GFXBuffer* buff, void* data, uint size, uint offset);
|
||||
void copyBufferToTexture(GFXBuffer* src, GFXTexture* dst, GFXTextureLayout layout, const GFXBufferTextureCopyList& regions);
|
||||
void execute(const std::vector<GFXCommandBuffer*>& cmd_buffs, uint32_t count);
|
||||
|
||||
CCVKGPUCommandBuffer* gpuCommandBuffer() const { return _gpuCommandBuffer; }
|
||||
|
||||
private:
|
||||
void BindStates();
|
||||
|
||||
private:
|
||||
CCVKGPUCommandBuffer* _gpuCommandBuffer = nullptr;
|
||||
|
||||
CCVKGPUPipelineState* _curGPUPipelineState = nullptr;
|
||||
CCVKGPUBindingLayout* _curGPUBlendLayout = nullptr;
|
||||
CCVKGPUInputAssembler* _curGPUInputAssember = nullptr;
|
||||
|
||||
CCVKGPUFramebuffer* _curGPUFBO = nullptr;
|
||||
|
||||
GFXViewport _curViewport;
|
||||
GFXRect _curScissor;
|
||||
float _curLineWidth = 1.0f;
|
||||
CCVKDepthBias _curDepthBias;
|
||||
GFXColor _curBlendConstants;
|
||||
CCVKDepthBounds _curDepthBounds;
|
||||
CCVKStencilWriteMask _curStencilWriteMask;
|
||||
CCVKStencilCompareMask _curStencilCompareMask;
|
||||
bool _isStateInvalid = false;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,205 @@
|
||||
#ifndef CC_GFXVULKAN_COMMANDS_H_
|
||||
#define CC_GFXVULKAN_COMMANDS_H_
|
||||
|
||||
#include "VKGPUObjects.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class CCVKDevice;
|
||||
|
||||
struct CCVKDepthBias
|
||||
{
|
||||
float constant = 0.0f;
|
||||
float clamp = 0.0f;
|
||||
float slope = 0.0f;
|
||||
};
|
||||
|
||||
struct CCVKDepthBounds
|
||||
{
|
||||
float minBounds = 0.0f;
|
||||
float maxBounds = 0.0f;
|
||||
};
|
||||
|
||||
struct CCVKStencilWriteMask
|
||||
{
|
||||
GFXStencilFace face = GFXStencilFace::FRONT;
|
||||
uint32_t write_mask = 0;
|
||||
};
|
||||
|
||||
struct CCVKStencilCompareMask
|
||||
{
|
||||
GFXStencilFace face = GFXStencilFace::FRONT;
|
||||
int reference = 0;
|
||||
uint32_t compareMask = 0;
|
||||
};
|
||||
|
||||
struct CCVKTextureSubres
|
||||
{
|
||||
uint baseMipLevel = 0;
|
||||
uint levelCount = 1;
|
||||
uint baseArrayLayer = 0;
|
||||
uint layerCount = 1;
|
||||
};
|
||||
|
||||
struct CCVKBufferTextureCopy
|
||||
{
|
||||
uint buffOffset = 0;
|
||||
uint buffStride = 0;
|
||||
uint buffTexHeight = 0;
|
||||
uint texOffset[3] = { 0 };
|
||||
uint texExtent[3] = { 0 };
|
||||
CCVKTextureSubres texSubres;
|
||||
};
|
||||
|
||||
class CCVKCmdBeginRenderPass : public GFXCmd
|
||||
{
|
||||
public:
|
||||
CCVKGPUFramebuffer* gpuFBO = nullptr;
|
||||
GFXRect render_area;
|
||||
GFXClearFlags clear_flags = GFXClearFlagBit::NONE;
|
||||
uint num_clear_colors = 0;
|
||||
GFXColor clear_colors[GFX_MAX_ATTACHMENTS];
|
||||
float clear_depth = 1.0f;
|
||||
int clear_stencil = 0;
|
||||
|
||||
CCVKCmdBeginRenderPass() : GFXCmd(GFXCmdType::BEGIN_RENDER_PASS) {}
|
||||
|
||||
void clear()
|
||||
{
|
||||
gpuFBO = nullptr;
|
||||
num_clear_colors = 0;
|
||||
}
|
||||
};
|
||||
|
||||
enum class CCVKState : uint8_t
|
||||
{
|
||||
VIEWPORT,
|
||||
SCISSOR,
|
||||
LINE_WIDTH,
|
||||
DEPTH_BIAS,
|
||||
BLEND_CONSTANTS,
|
||||
DEPTH_BOUNDS,
|
||||
STENCIL_WRITE_MASK,
|
||||
STENCIL_COMPARE_MASK,
|
||||
COUNT,
|
||||
};
|
||||
|
||||
class CCVKCmdBindStates : public GFXCmd
|
||||
{
|
||||
public:
|
||||
CCVKGPUPipelineState* gpuPipelineState = nullptr;
|
||||
CCVKGPUBindingLayout* gpuBindingLayout = nullptr;
|
||||
CCVKGPUInputAssembler* gpuInputAssembler = nullptr;
|
||||
uint8_t state_flags[(int)CCVKState::COUNT] = { 0 };
|
||||
GFXViewport viewport;
|
||||
GFXRect scissor;
|
||||
float lineWidth = 1.0f;
|
||||
CCVKDepthBias depthBias;
|
||||
GFXColor blendConstants;
|
||||
CCVKDepthBounds depthBounds;
|
||||
CCVKStencilWriteMask stencilWriteMask;
|
||||
CCVKStencilCompareMask stencilCompareMask;
|
||||
|
||||
CCVKCmdBindStates() : GFXCmd(GFXCmdType::BIND_STATES) {}
|
||||
|
||||
void clear()
|
||||
{
|
||||
gpuPipelineState = nullptr;
|
||||
gpuBindingLayout = nullptr;
|
||||
gpuInputAssembler = nullptr;
|
||||
memset(state_flags, 0, sizeof(state_flags));
|
||||
}
|
||||
};
|
||||
|
||||
class CCVKCmdDraw : public GFXCmd
|
||||
{
|
||||
public:
|
||||
GFXDrawInfo draw_info;
|
||||
|
||||
CCVKCmdDraw() : GFXCmd(GFXCmdType::DRAW) {}
|
||||
void clear() {}
|
||||
};
|
||||
|
||||
class CCVKCmdUpdateBuffer : public GFXCmd
|
||||
{
|
||||
public:
|
||||
CCVKGPUBuffer* gpuBuffer = nullptr;
|
||||
uint8_t* buffer = nullptr;
|
||||
uint size = 0;
|
||||
uint offset = 0;
|
||||
|
||||
CCVKCmdUpdateBuffer() : GFXCmd(GFXCmdType::UPDATE_BUFFER) {}
|
||||
|
||||
void clear()
|
||||
{
|
||||
gpuBuffer = nullptr;
|
||||
buffer = nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
class CCVKCmdCopyBufferToTexture : public GFXCmd
|
||||
{
|
||||
public:
|
||||
CCVKGPUBuffer* gpuBuffer = nullptr;
|
||||
CCVKGPUTexture* gpuTexture = nullptr;
|
||||
GFXTextureLayout dst_layout;
|
||||
GFXBufferTextureCopyList regions;
|
||||
|
||||
CCVKCmdCopyBufferToTexture() : GFXCmd(GFXCmdType::COPY_BUFFER_TO_TEXTURE) {}
|
||||
|
||||
void clear()
|
||||
{
|
||||
gpuBuffer = nullptr;
|
||||
gpuTexture = nullptr;
|
||||
regions.clear();
|
||||
}
|
||||
};
|
||||
|
||||
class CCVKCmdPackage : public Object
|
||||
{
|
||||
public:
|
||||
CachedArray<GFXCmdType> cmds;
|
||||
CachedArray<CCVKCmdBeginRenderPass*> beginRenderPassCmds;
|
||||
CachedArray<CCVKCmdBindStates*> bindStatesCmds;
|
||||
CachedArray<CCVKCmdDraw*> drawCmds;
|
||||
CachedArray<CCVKCmdUpdateBuffer*> updateBufferCmds;
|
||||
CachedArray<CCVKCmdCopyBufferToTexture*> copyBufferToTextureCmds;
|
||||
};
|
||||
|
||||
CC_VULKAN_API void CCVKCmdFuncCreateRenderPass(CCVKDevice* device, CCVKGPURenderPass* gpuRenderPass);
|
||||
CC_VULKAN_API void CCVKCmdFuncDestroyRenderPass(CCVKDevice* device, CCVKGPURenderPass* gpuRenderPass);
|
||||
CC_VULKAN_API void CCVKCmdFuncGetDeviceQueue(CCVKDevice* device, CCVKGPUQueue* gpuQueue);
|
||||
CC_VULKAN_API void CCVKCmdFuncCreateCommandPool(CCVKDevice* device, CCVKGPUCommandPool* gpuCommandPool);
|
||||
CC_VULKAN_API void CCVKCmdFuncDestroyCommandPool(CCVKDevice* device, CCVKGPUCommandPool* gpuCommandPool);
|
||||
CC_VULKAN_API void CCVKCmdFuncAllocateCommandBuffer(CCVKDevice* device, CCVKGPUCommandBuffer* gpuCommandBuffer);
|
||||
CC_VULKAN_API void CCVKCmdFuncFreeCommandBuffer(CCVKDevice* device, CCVKGPUCommandBuffer* gpuCommandBuffer);
|
||||
|
||||
CC_VULKAN_API void CCVKCmdFuncCreateBuffer(CCVKDevice* device, CCVKGPUBuffer* gpuBuffer);
|
||||
CC_VULKAN_API void CCVKCmdFuncDestroyBuffer(CCVKDevice* device, CCVKGPUBuffer* gpuBuffer);
|
||||
CC_VULKAN_API void CCVKCmdFuncResizeBuffer(CCVKDevice* device, CCVKGPUBuffer* gpuBuffer);
|
||||
CC_VULKAN_API void CCVKCmdFuncUpdateBuffer(CCVKDevice* device, CCVKGPUBuffer* gpuBuffer, void* buffer, uint offset, uint size);
|
||||
CC_VULKAN_API void CCVKCmdFuncCreateTexture(CCVKDevice* device, CCVKGPUTexture* gpuTexture);
|
||||
CC_VULKAN_API void CCVKCmdFuncDestroyTexture(CCVKDevice* device, CCVKGPUTexture* gpuTexture);
|
||||
CC_VULKAN_API void CCVKCmdFuncCreateTextureView(CCVKDevice* device, CCVKGPUTextureView* gpuTextureView);
|
||||
CC_VULKAN_API void CCVKCmdFuncDestroyTextureView(CCVKDevice* device, CCVKGPUTextureView* gpuTextureView);
|
||||
CC_VULKAN_API void CCVKCmdFuncResizeTexture(CCVKDevice* device, CCVKGPUTexture* gpuTexture);
|
||||
CC_VULKAN_API void CCVKCmdFuncCreateSampler(CCVKDevice* device, CCVKGPUSampler* gpuSampler);
|
||||
CC_VULKAN_API void CCVKCmdFuncDestroySampler(CCVKDevice* device, CCVKGPUSampler* gpuSampler);
|
||||
CC_VULKAN_API void CCVKCmdFuncCreateShader(CCVKDevice* device, CCVKGPUShader* gpuShader);
|
||||
CC_VULKAN_API void CCVKCmdFuncDestroyShader(CCVKDevice* device, CCVKGPUShader* gpuShader);
|
||||
CC_VULKAN_API void CCVKCmdFuncCreateInputAssembler(CCVKDevice* device, CCVKGPUInputAssembler* gpuInputAssembler);
|
||||
CC_VULKAN_API void CCVKCmdFuncDestroyInputAssembler(CCVKDevice* device, CCVKGPUInputAssembler* gpuInputAssembler);
|
||||
CC_VULKAN_API void CCVKCmdFuncCreateFramebuffer(CCVKDevice* device, CCVKGPUFramebuffer* gpuFramebuffer);
|
||||
CC_VULKAN_API void CCVKCmdFuncDestroyFramebuffer(CCVKDevice* device, CCVKGPUFramebuffer* gpuFramebuffer);
|
||||
CC_VULKAN_API void CCVKCmdFuncCreateBindingLayout(CCVKDevice* device, CCVKGPUBindingLayout* gpuBindingLayout);
|
||||
CC_VULKAN_API void CCVKCmdFuncDestroyBindingLayout(CCVKDevice* device, CCVKGPUBindingLayout* gpuBindingLayout);
|
||||
CC_VULKAN_API void CCVKCmdFuncCreatePipelineLayout(CCVKDevice* device, CCVKGPUPipelineLayout* gpuPipelineLayout);
|
||||
CC_VULKAN_API void CCVKCmdFuncDestroyPipelineLayout(CCVKDevice* device, CCVKGPUPipelineLayout* gpuPipelineLayout);
|
||||
CC_VULKAN_API void CCVKCmdFuncCreatePipelineState(CCVKDevice* device, CCVKGPUPipelineState* gpuPipelineState);
|
||||
CC_VULKAN_API void CCVKCmdFuncDestroyPipelineState(CCVKDevice* device, CCVKGPUPipelineState* gpuPipelineState);
|
||||
|
||||
CC_VULKAN_API void CCVKCmdFuncCopyBuffersToTexture(CCVKDevice* device, uint8_t* const* buffers, CCVKGPUTexture* gpuTexture, const GFXBufferTextureCopyList& regions);
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,532 @@
|
||||
#include "VKStd.h"
|
||||
#include "VKContext.h"
|
||||
#include "VKUtils.h"
|
||||
#include "VKGPUObjects.h"
|
||||
#include "VKDevice.h"
|
||||
#include "VKRenderPass.h"
|
||||
#include "VKTexture.h"
|
||||
#include "VKTextureView.h"
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include "windows.h"
|
||||
|
||||
#define CC_GFX_DEBUG
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
namespace
|
||||
{
|
||||
#ifdef CC_GFX_DEBUG
|
||||
VKAPI_ATTR VkBool32 VKAPI_CALL debugUtilsMessengerCallback(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
|
||||
VkDebugUtilsMessageTypeFlagsEXT messageType, const VkDebugUtilsMessengerCallbackDataEXT *callbackData, void * user_data)
|
||||
{
|
||||
// Log debug messge
|
||||
if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT)
|
||||
{
|
||||
CC_LOG_WARNING("%s: %s", callbackData->pMessageIdName, callbackData->pMessage);
|
||||
}
|
||||
else if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT)
|
||||
{
|
||||
CC_LOG_ERROR("%s: %s", callbackData->pMessageIdName, callbackData->pMessage);
|
||||
assert(false);
|
||||
}
|
||||
return VK_FALSE;
|
||||
}
|
||||
|
||||
VKAPI_ATTR VkBool32 VKAPI_CALL debugReportCallback(VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT type,
|
||||
uint64_t object, size_t location, int32_t messageCode, const char *layerPrefix, const char *message, void *userData)
|
||||
{
|
||||
if (flags & VK_DEBUG_REPORT_ERROR_BIT_EXT)
|
||||
{
|
||||
CC_LOG_ERROR("VError: %s: %s", layerPrefix, message);
|
||||
assert(false);
|
||||
}
|
||||
else if (flags & VK_DEBUG_REPORT_WARNING_BIT_EXT)
|
||||
{
|
||||
CC_LOG_ERROR("VWarning: %s: %s", layerPrefix, message);
|
||||
}
|
||||
else if (flags & VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT)
|
||||
{
|
||||
CC_LOG_INFO("VPerfWarning: %s: %s", layerPrefix, message);
|
||||
}
|
||||
else
|
||||
{
|
||||
CC_LOG_INFO("VInfo: %s: %s", layerPrefix, message);
|
||||
}
|
||||
return VK_FALSE;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
CCVKContext::CCVKContext(GFXDevice* device)
|
||||
: GFXContext(device){
|
||||
}
|
||||
|
||||
CCVKContext::~CCVKContext() {
|
||||
}
|
||||
|
||||
bool CCVKContext::initialize(const GFXContextInfo &info) {
|
||||
|
||||
_vsyncMode = info.vsyncMode;
|
||||
_windowHandle = info.windowHandle;
|
||||
|
||||
if (!info.sharedCtx)
|
||||
{
|
||||
_isPrimaryContex = true;
|
||||
_windowHandle = info.windowHandle;
|
||||
|
||||
_gpuContext = CC_NEW(CCVKGPUContext);
|
||||
|
||||
// only enable the absolute essentials for now
|
||||
std::vector<const char *> requestedLayers
|
||||
{
|
||||
|
||||
};
|
||||
std::vector<const char *> requestedExtensions
|
||||
{
|
||||
VK_KHR_SURFACE_EXTENSION_NAME,
|
||||
};
|
||||
|
||||
///////////////////// Instance Creation /////////////////////
|
||||
|
||||
if (volkInitialize())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t availableLayerCount;
|
||||
VK_CHECK(vkEnumerateInstanceLayerProperties(&availableLayerCount, nullptr));
|
||||
std::vector<VkLayerProperties> supportedLayers(availableLayerCount);
|
||||
VK_CHECK(vkEnumerateInstanceLayerProperties(&availableLayerCount, supportedLayers.data()));
|
||||
|
||||
uint32_t availableExtensionCount;
|
||||
VK_CHECK(vkEnumerateInstanceExtensionProperties(nullptr, &availableExtensionCount, nullptr));
|
||||
std::vector<VkExtensionProperties> supportedExtensions(availableExtensionCount);
|
||||
VK_CHECK(vkEnumerateInstanceExtensionProperties(nullptr, &availableExtensionCount, supportedExtensions.data()));
|
||||
|
||||
#if defined(VK_USE_PLATFORM_ANDROID_KHR)
|
||||
requestedExtensions.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME);
|
||||
#elif defined(VK_USE_PLATFORM_WIN32_KHR)
|
||||
requestedExtensions.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
|
||||
#elif defined(VK_USE_PLATFORM_IOS_MVK)
|
||||
requestedExtensions.push_back(VK_MVK_IOS_SURFACE_EXTENSION_NAME);
|
||||
#elif defined(VK_USE_PLATFORM_MACOS_MVK)
|
||||
requestedExtensions.push_back(VK_MVK_MACOS_SURFACE_EXTENSION_NAME);
|
||||
#elif defined(VK_USE_PLATFORM_WAYLAND_KHR)
|
||||
requestedExtensions.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
|
||||
#elif defined(VK_USE_PLATFORM_XCB_KHR)
|
||||
requestedExtensions.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
|
||||
#else
|
||||
# pragma error Platform not supported
|
||||
#endif
|
||||
|
||||
#ifdef CC_GFX_DEBUG
|
||||
// Determine the optimal validation layers to enable that are necessary for useful debugging
|
||||
std::vector<std::vector<const char *>> validationLayerPriorityList
|
||||
{
|
||||
// The preferred validation layer is "VK_LAYER_KHRONOS_validation"
|
||||
{"VK_LAYER_KHRONOS_validation"},
|
||||
|
||||
// Otherwise we fallback to using the LunarG meta layer
|
||||
{"VK_LAYER_LUNARG_standard_validation"},
|
||||
|
||||
// Otherwise we attempt to enable the individual layers that compose the LunarG meta layer since it doesn't exist
|
||||
{
|
||||
"VK_LAYER_GOOGLE_threading",
|
||||
"VK_LAYER_LUNARG_parameter_validation",
|
||||
"VK_LAYER_LUNARG_object_tracker",
|
||||
"VK_LAYER_LUNARG_core_validation",
|
||||
"VK_LAYER_GOOGLE_unique_objects",
|
||||
},
|
||||
|
||||
// Otherwise as a last resort we fallback to attempting to enable the LunarG core layer
|
||||
{"VK_LAYER_LUNARG_core_validation"}
|
||||
};
|
||||
for (auto &validationLayers : validationLayerPriorityList)
|
||||
{
|
||||
bool found = true;
|
||||
for (auto &layer : validationLayers)
|
||||
{
|
||||
if (!isLayerSupported(layer, supportedLayers))
|
||||
{
|
||||
found = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found)
|
||||
{
|
||||
requestedLayers.insert(requestedLayers.end(), validationLayers.begin(), validationLayers.end());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Check if VK_EXT_debug_utils is supported, which supersedes VK_EXT_Debug_Report
|
||||
bool debugUtils = false;
|
||||
if (isExtensionSupported(VK_EXT_DEBUG_UTILS_EXTENSION_NAME, supportedExtensions))
|
||||
{
|
||||
debugUtils = true;
|
||||
requestedExtensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
|
||||
}
|
||||
else
|
||||
{
|
||||
requestedExtensions.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
|
||||
}
|
||||
#endif
|
||||
|
||||
// just filter out the unsupported layers & extensions
|
||||
for (auto &layer : requestedLayers)
|
||||
{
|
||||
if (isLayerSupported(layer, supportedLayers))
|
||||
{
|
||||
_layers.push_back(layer);
|
||||
}
|
||||
}
|
||||
for (auto &extension : requestedExtensions)
|
||||
{
|
||||
if (isExtensionSupported(extension, supportedExtensions))
|
||||
{
|
||||
_extensions.push_back(extension);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t apiVersion;
|
||||
vkEnumerateInstanceVersion(&apiVersion);
|
||||
|
||||
VkApplicationInfo app{ VK_STRUCTURE_TYPE_APPLICATION_INFO };
|
||||
app.pEngineName = "Cocos Creator";
|
||||
app.apiVersion = apiVersion;
|
||||
|
||||
VkInstanceCreateInfo instanceInfo{ VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO };
|
||||
instanceInfo.pApplicationInfo = &app;
|
||||
instanceInfo.enabledExtensionCount = toU32(_extensions.size());
|
||||
instanceInfo.ppEnabledExtensionNames = _extensions.data();
|
||||
instanceInfo.enabledLayerCount = toU32(_layers.size());
|
||||
instanceInfo.ppEnabledLayerNames = _layers.data();
|
||||
|
||||
#ifdef CC_GFX_DEBUG
|
||||
VkDebugUtilsMessengerCreateInfoEXT debugUtilsCreateInfo{ VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT };
|
||||
VkDebugReportCallbackCreateInfoEXT debugReportCreateInfo{ VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT };
|
||||
if (debugUtils)
|
||||
{
|
||||
debugUtilsCreateInfo.messageSeverity = VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT;
|
||||
debugUtilsCreateInfo.messageType = VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT;
|
||||
debugUtilsCreateInfo.pfnUserCallback = debugUtilsMessengerCallback;
|
||||
|
||||
instanceInfo.pNext = &debugUtilsCreateInfo;
|
||||
}
|
||||
else
|
||||
{
|
||||
debugReportCreateInfo.flags = VK_DEBUG_REPORT_ERROR_BIT_EXT | VK_DEBUG_REPORT_WARNING_BIT_EXT;
|
||||
debugReportCreateInfo.pfnCallback = debugReportCallback;
|
||||
|
||||
instanceInfo.pNext = &debugReportCreateInfo;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Create the Vulkan instance
|
||||
VK_CHECK(vkCreateInstance(&instanceInfo, nullptr, &_gpuContext->vkInstance));
|
||||
|
||||
volkLoadInstance(_gpuContext->vkInstance);
|
||||
|
||||
#ifdef CC_GFX_DEBUG
|
||||
if (debugUtils)
|
||||
{
|
||||
VK_CHECK(vkCreateDebugUtilsMessengerEXT(_gpuContext->vkInstance, &debugUtilsCreateInfo, nullptr, &_gpuContext->vkDebugUtilsMessenger));
|
||||
}
|
||||
else
|
||||
{
|
||||
VK_CHECK(vkCreateDebugReportCallbackEXT(_gpuContext->vkInstance, &debugReportCreateInfo, nullptr, &_gpuContext->vkDebugReport));
|
||||
}
|
||||
#endif
|
||||
|
||||
_majorVersion = VK_VERSION_MAJOR(apiVersion);
|
||||
_minorVersion = VK_VERSION_MINOR(apiVersion);
|
||||
|
||||
///////////////////// Surface Creation /////////////////////
|
||||
|
||||
#if defined(VK_USE_PLATFORM_ANDROID_KHR)
|
||||
VkAndroidSurfaceCreateInfoKHR surfaceCreateInfo{ VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR };
|
||||
surfaceCreateInfo.window = (ANativeWindow*)_windowHandle;
|
||||
VK_CHECK(vkCreateAndroidSurfaceKHR(_gpuContext->vkInstance, &surfaceCreateInfo, nullptr, &_gpuContext->vkSurface));
|
||||
#elif defined(VK_USE_PLATFORM_WIN32_KHR)
|
||||
VkWin32SurfaceCreateInfoKHR surfaceCreateInfo{ VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR };
|
||||
surfaceCreateInfo.hinstance = (HINSTANCE)GetModuleHandle(0);
|
||||
surfaceCreateInfo.hwnd = (HWND)_windowHandle;
|
||||
VK_CHECK(vkCreateWin32SurfaceKHR(_gpuContext->vkInstance, &surfaceCreateInfo, nullptr, &_gpuContext->vkSurface));
|
||||
#elif defined(VK_USE_PLATFORM_IOS_MVK)
|
||||
VkIOSSurfaceCreateInfoMVK surfaceCreateInfo{ VK_STRUCTURE_TYPE_IOS_SURFACE_CREATE_INFO_MVK };
|
||||
surfaceCreateInfo.pView = (void*)_windowHandle;
|
||||
VK_CHECK(vkCreateIOSSurfaceMVK(_gpuContext->vkInstance, &surfaceCreateInfo, nullptr, &_gpuContext->vkSurface));
|
||||
#elif defined(VK_USE_PLATFORM_MACOS_MVK)
|
||||
VkMacOSSurfaceCreateInfoMVK surfaceCreateInfo{ VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK };
|
||||
surfaceCreateInfo.pView = (void*)_windowHandle;
|
||||
VK_CHECK(vkCreateMacOSSurfaceMVK(_gpuContext->vkInstance, &surfaceCreateInfo, nullptr, &_gpuContext->vkSurface));
|
||||
#elif defined(VK_USE_PLATFORM_WAYLAND_KHR)
|
||||
VkWaylandSurfaceCreateInfoKHR surfaceCreateInfo{ VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR };
|
||||
surfaceCreateInfo.display = nullptr; // TODO
|
||||
surfaceCreateInfo.surface = (wl_surface*)_windowHandle;
|
||||
VK_CHECK(vkCreateWaylandSurfaceKHR(_gpuContext->vkInstance, &surfaceCreateInfo, nullptr, &_gpuContext->vkSurface));
|
||||
#elif defined(VK_USE_PLATFORM_XCB_KHR)
|
||||
VkXcbSurfaceCreateInfoKHR surfaceCreateInfo{ VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR };
|
||||
surfaceCreateInfo.connection = nullptr; // TODO
|
||||
surfaceCreateInfo.window = (xcb_window_t)_windowHandle;
|
||||
VK_CHECK(vkCreateXcbSurfaceKHR(_gpuContext->vkInstance, &surfaceCreateInfo, nullptr, &_gpuContext->vkSurface));
|
||||
#else
|
||||
# pragma error Platform not supported
|
||||
#endif
|
||||
|
||||
///////////////////// Physical Device Selection /////////////////////
|
||||
|
||||
// Querying valid physical devices on the machine
|
||||
uint32_t physicalDeviceCount{ 0 };
|
||||
VK_CHECK(vkEnumeratePhysicalDevices(_gpuContext->vkInstance, &physicalDeviceCount, nullptr));
|
||||
|
||||
if (physicalDeviceCount < 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<VkPhysicalDevice> physicalDeviceHandles(physicalDeviceCount);
|
||||
VK_CHECK(vkEnumeratePhysicalDevices(_gpuContext->vkInstance, &physicalDeviceCount, physicalDeviceHandles.data()));
|
||||
|
||||
std::vector<VkPhysicalDeviceProperties> physicalDeviceProperties(physicalDeviceCount);
|
||||
|
||||
uint32_t deviceIndex;
|
||||
for (deviceIndex = 0u; deviceIndex < physicalDeviceCount; ++deviceIndex)
|
||||
{
|
||||
VkPhysicalDeviceProperties& properties = physicalDeviceProperties[deviceIndex];
|
||||
vkGetPhysicalDeviceProperties(physicalDeviceHandles[deviceIndex], &properties);
|
||||
}
|
||||
|
||||
for (deviceIndex = 0u; deviceIndex < physicalDeviceCount; ++deviceIndex)
|
||||
{
|
||||
VkPhysicalDeviceProperties& properties = physicalDeviceProperties[deviceIndex];
|
||||
if (properties.deviceType == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
_gpuContext->physicalDevice = physicalDeviceHandles[deviceIndex];
|
||||
_gpuContext->physicalDeviceProperties = physicalDeviceProperties[deviceIndex];
|
||||
vkGetPhysicalDeviceFeatures(_gpuContext->physicalDevice, &_gpuContext->physicalDeviceFeatures);
|
||||
vkGetPhysicalDeviceMemoryProperties(_gpuContext->physicalDevice, &_gpuContext->physicalDeviceMemoryProperties);
|
||||
uint32_t queueFamilyPropertiesCount = 0;
|
||||
vkGetPhysicalDeviceQueueFamilyProperties(_gpuContext->physicalDevice, &queueFamilyPropertiesCount, nullptr);
|
||||
_gpuContext->queueFamilyProperties.resize(queueFamilyPropertiesCount);
|
||||
vkGetPhysicalDeviceQueueFamilyProperties(_gpuContext->physicalDevice, &queueFamilyPropertiesCount, _gpuContext->queueFamilyProperties.data());
|
||||
_gpuContext->queueFamilyPresentables.resize(queueFamilyPropertiesCount);
|
||||
for (uint32_t propertyIndex = 0U; propertyIndex < queueFamilyPropertiesCount; propertyIndex++)
|
||||
{
|
||||
vkGetPhysicalDeviceSurfaceSupportKHR(_gpuContext->physicalDevice, propertyIndex,
|
||||
_gpuContext->vkSurface, &_gpuContext->queueFamilyPresentables[propertyIndex]);
|
||||
}
|
||||
|
||||
///////////////////// Swapchain Preperation /////////////////////
|
||||
|
||||
_colorFmt = GFXFormat::BGRA8;
|
||||
_depthStencilFmt = GFXFormat::D24S8;
|
||||
|
||||
VkSurfaceCapabilitiesKHR surfaceCapabilities{};
|
||||
vkGetPhysicalDeviceSurfaceCapabilitiesKHR(_gpuContext->physicalDevice, _gpuContext->vkSurface, &surfaceCapabilities);
|
||||
|
||||
uint32_t surfaceFormatCount = 0u;
|
||||
VK_CHECK(vkGetPhysicalDeviceSurfaceFormatsKHR(_gpuContext->physicalDevice, _gpuContext->vkSurface, &surfaceFormatCount, nullptr));
|
||||
std::vector<VkSurfaceFormatKHR> surfaceFormats(surfaceFormatCount);
|
||||
VK_CHECK(vkGetPhysicalDeviceSurfaceFormatsKHR(_gpuContext->physicalDevice, _gpuContext->vkSurface, &surfaceFormatCount, surfaceFormats.data()));
|
||||
|
||||
uint32_t presentModeCount = 0u;
|
||||
VK_CHECK(vkGetPhysicalDeviceSurfacePresentModesKHR(_gpuContext->physicalDevice, _gpuContext->vkSurface, &presentModeCount, nullptr));
|
||||
std::vector<VkPresentModeKHR> presentModes(presentModeCount);
|
||||
VK_CHECK(vkGetPhysicalDeviceSurfacePresentModesKHR(_gpuContext->physicalDevice, _gpuContext->vkSurface, &presentModeCount, presentModes.data()));
|
||||
|
||||
VkExtent2D imageExtent{ surfaceCapabilities.currentExtent.width, surfaceCapabilities.currentExtent.height };
|
||||
|
||||
VkFormat colorFormat = VK_FORMAT_B8G8R8A8_UNORM;
|
||||
VkColorSpaceKHR colorSpace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR;
|
||||
// If the surface format list only includes one entry with VK_FORMAT_UNDEFINED,
|
||||
// there is no preferered format, so we assume VK_FORMAT_B8G8R8A8_UNORM
|
||||
if ((surfaceFormatCount == 1) && (surfaceFormats[0].format == VK_FORMAT_UNDEFINED))
|
||||
{
|
||||
colorFormat = VK_FORMAT_B8G8R8A8_UNORM;
|
||||
colorSpace = surfaceFormats[0].colorSpace;
|
||||
}
|
||||
else
|
||||
{
|
||||
// iterate over the list of available surface format and
|
||||
// check for the presence of VK_FORMAT_B8G8R8A8_UNORM
|
||||
bool imageFormatFound = false;
|
||||
for (auto&& surfaceFormat : surfaceFormats)
|
||||
{
|
||||
if (surfaceFormat.format == VK_FORMAT_B8G8R8A8_UNORM)
|
||||
{
|
||||
colorFormat = surfaceFormat.format;
|
||||
colorSpace = surfaceFormat.colorSpace;
|
||||
imageFormatFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// in case VK_FORMAT_B8G8R8A8_UNORM is not available
|
||||
// select the first available color format
|
||||
if (!imageFormatFound)
|
||||
{
|
||||
colorFormat = surfaceFormats[0].format;
|
||||
colorSpace = surfaceFormats[0].colorSpace;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::pair<GFXFormat, VkFormat>> depthFormatPriorityList =
|
||||
{
|
||||
{ GFXFormat::D32F_S8, VK_FORMAT_D32_SFLOAT_S8_UINT },
|
||||
{ GFXFormat::D24S8, VK_FORMAT_D24_UNORM_S8_UINT },
|
||||
{ GFXFormat::D16S8, VK_FORMAT_D16_UNORM_S8_UINT },
|
||||
{ GFXFormat::D32F, VK_FORMAT_D32_SFLOAT },
|
||||
{ GFXFormat::D16, VK_FORMAT_D16_UNORM }
|
||||
};
|
||||
for (auto& format : depthFormatPriorityList)
|
||||
{
|
||||
VkFormatProperties formatProperties;
|
||||
vkGetPhysicalDeviceFormatProperties(_gpuContext->physicalDevice, format.second, &formatProperties);
|
||||
// Format must support depth stencil attachment for optimal tiling
|
||||
if (formatProperties.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)
|
||||
{
|
||||
if (formatProperties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)
|
||||
{
|
||||
_depthStencilFmt = format.first;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Select a present mode for the swapchain
|
||||
|
||||
std::vector<VkPresentModeKHR> presentModePriorityList;
|
||||
|
||||
switch (_vsyncMode)
|
||||
{
|
||||
case GFXVsyncMode::OFF: presentModePriorityList.insert(presentModePriorityList.end(), { VK_PRESENT_MODE_IMMEDIATE_KHR, VK_PRESENT_MODE_FIFO_KHR }); break;
|
||||
case GFXVsyncMode::ON: presentModePriorityList.insert(presentModePriorityList.end(), { VK_PRESENT_MODE_FIFO_KHR }); break;
|
||||
case GFXVsyncMode::RELAXED: presentModePriorityList.insert(presentModePriorityList.end(), { VK_PRESENT_MODE_FIFO_RELAXED_KHR, VK_PRESENT_MODE_FIFO_KHR }); break;
|
||||
case GFXVsyncMode::MAILBOX: presentModePriorityList.insert(presentModePriorityList.end(), { VK_PRESENT_MODE_MAILBOX_KHR, VK_PRESENT_MODE_IMMEDIATE_KHR, VK_PRESENT_MODE_FIFO_KHR }); break;
|
||||
case GFXVsyncMode::HALF: presentModePriorityList.insert(presentModePriorityList.end(), { VK_PRESENT_MODE_FIFO_KHR }); break; // TODO
|
||||
}
|
||||
|
||||
VkPresentModeKHR swapchainPresentMode = VK_PRESENT_MODE_FIFO_KHR;
|
||||
|
||||
for (auto &presentMode : presentModePriorityList)
|
||||
{
|
||||
if (std::find(presentModes.begin(), presentModes.end(), presentMode) != presentModes.end())
|
||||
{
|
||||
swapchainPresentMode = presentMode;
|
||||
}
|
||||
}
|
||||
|
||||
// Determine the number of images
|
||||
uint32_t desiredNumberOfSwapchainImages = surfaceCapabilities.minImageCount + 1;
|
||||
if ((surfaceCapabilities.maxImageCount > 0) && (desiredNumberOfSwapchainImages > surfaceCapabilities.maxImageCount))
|
||||
{
|
||||
desiredNumberOfSwapchainImages = surfaceCapabilities.maxImageCount;
|
||||
}
|
||||
|
||||
// Find the transformation of the surface
|
||||
VkSurfaceTransformFlagBitsKHR preTransform;
|
||||
if (surfaceCapabilities.supportedTransforms & VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR)
|
||||
{
|
||||
// We prefer a non-rotated transform
|
||||
preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
|
||||
}
|
||||
else
|
||||
{
|
||||
preTransform = surfaceCapabilities.currentTransform;
|
||||
}
|
||||
|
||||
// Find a supported composite alpha format (not all devices support alpha opaque)
|
||||
VkCompositeAlphaFlagBitsKHR compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
|
||||
// Simply select the first composite alpha format available
|
||||
std::vector<VkCompositeAlphaFlagBitsKHR> compositeAlphaFlags = {
|
||||
VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR,
|
||||
VK_COMPOSITE_ALPHA_PRE_MULTIPLIED_BIT_KHR,
|
||||
VK_COMPOSITE_ALPHA_POST_MULTIPLIED_BIT_KHR,
|
||||
VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR,
|
||||
};
|
||||
for (auto& compositeAlphaFlag : compositeAlphaFlags)
|
||||
{
|
||||
if (surfaceCapabilities.supportedCompositeAlpha & compositeAlphaFlag)
|
||||
{
|
||||
compositeAlpha = compositeAlphaFlag;
|
||||
break;
|
||||
};
|
||||
}
|
||||
VkImageUsageFlags imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
|
||||
// Enable transfer source on swap chain images if supported
|
||||
if (surfaceCapabilities.supportedUsageFlags & VK_IMAGE_USAGE_TRANSFER_SRC_BIT)
|
||||
{
|
||||
imageUsage |= VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
|
||||
}
|
||||
|
||||
// Enable transfer destination on swap chain images if supported
|
||||
if (surfaceCapabilities.supportedUsageFlags & VK_IMAGE_USAGE_TRANSFER_DST_BIT)
|
||||
{
|
||||
imageUsage |= VK_IMAGE_USAGE_TRANSFER_DST_BIT;
|
||||
}
|
||||
|
||||
_gpuContext->swapchainCreateInfo.surface = _gpuContext->vkSurface;
|
||||
_gpuContext->swapchainCreateInfo.minImageCount = desiredNumberOfSwapchainImages;
|
||||
_gpuContext->swapchainCreateInfo.imageFormat = colorFormat;
|
||||
_gpuContext->swapchainCreateInfo.imageColorSpace = colorSpace;
|
||||
_gpuContext->swapchainCreateInfo.imageExtent = imageExtent;
|
||||
_gpuContext->swapchainCreateInfo.imageUsage = imageUsage;
|
||||
_gpuContext->swapchainCreateInfo.imageArrayLayers = 1;
|
||||
_gpuContext->swapchainCreateInfo.preTransform = preTransform;
|
||||
_gpuContext->swapchainCreateInfo.compositeAlpha = compositeAlpha;
|
||||
_gpuContext->swapchainCreateInfo.presentMode = swapchainPresentMode;
|
||||
_gpuContext->swapchainCreateInfo.clipped = VK_TRUE; // Setting clipped to VK_TRUE allows the implementation to discard rendering outside of the surface area
|
||||
|
||||
} else {
|
||||
CCVKContext* sharedCtx = (CCVKContext*)info.sharedCtx;
|
||||
|
||||
_majorVersion = sharedCtx->majorVersion();
|
||||
_minorVersion = sharedCtx->minorVersion();
|
||||
|
||||
// TODO
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CCVKContext::destroy()
|
||||
{
|
||||
if (_gpuContext)
|
||||
{
|
||||
if (_gpuContext->vkSurface != VK_NULL_HANDLE)
|
||||
{
|
||||
vkDestroySurfaceKHR(_gpuContext->vkInstance, _gpuContext->vkSurface, nullptr);
|
||||
_gpuContext->vkSurface = VK_NULL_HANDLE;
|
||||
}
|
||||
|
||||
#ifdef CC_GFX_DEBUG
|
||||
if (_gpuContext->vkDebugUtilsMessenger != VK_NULL_HANDLE)
|
||||
{
|
||||
vkDestroyDebugUtilsMessengerEXT(_gpuContext->vkInstance, _gpuContext->vkDebugUtilsMessenger, nullptr);
|
||||
_gpuContext->vkDebugUtilsMessenger = VK_NULL_HANDLE;
|
||||
}
|
||||
if (_gpuContext->vkDebugReport != VK_NULL_HANDLE)
|
||||
{
|
||||
vkDestroyDebugReportCallbackEXT(_gpuContext->vkInstance, _gpuContext->vkDebugReport, nullptr);
|
||||
_gpuContext->vkDebugReport = VK_NULL_HANDLE;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (_gpuContext->vkInstance != VK_NULL_HANDLE)
|
||||
{
|
||||
vkDestroyInstance(_gpuContext->vkInstance, nullptr);
|
||||
_gpuContext->vkInstance = VK_NULL_HANDLE;
|
||||
}
|
||||
|
||||
CC_DELETE(_gpuContext);
|
||||
_gpuContext = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
@@ -0,0 +1,48 @@
|
||||
#ifndef CC_GFXVULKAN_CCVK_CONTEXT_H_
|
||||
#define CC_GFXVULKAN_CCVK_CONTEXT_H_
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class CCVKDevice;
|
||||
class CCVKGPUDevice;
|
||||
class CCVKGPUContext;
|
||||
class CCVKGPUSwapchain;
|
||||
class CCVKGPUSemaphorePool;
|
||||
|
||||
class CC_VULKAN_API CCVKContext : public GFXContext {
|
||||
public:
|
||||
CCVKContext(GFXDevice* device);
|
||||
~CCVKContext();
|
||||
|
||||
public:
|
||||
bool initialize(const GFXContextInfo& info);
|
||||
void destroy();
|
||||
void present() {}
|
||||
|
||||
CC_INLINE bool checkExtension(const String& extension) const
|
||||
{
|
||||
return std::find_if(_extensions.begin(), _extensions.end(),
|
||||
[extension](auto &device_extension)
|
||||
{
|
||||
return std::strcmp(device_extension, extension.c_str()) == 0;
|
||||
}) != _extensions.end();
|
||||
}
|
||||
|
||||
CC_INLINE int majorVersion() const { return _majorVersion; }
|
||||
CC_INLINE int minorVersion() const { return _minorVersion; }
|
||||
CC_INLINE CCVKGPUContext* gpuContext() { return _gpuContext; }
|
||||
CC_INLINE const std::vector<const char *>& getLayers() const { return _layers; }
|
||||
CC_INLINE const std::vector<const char *>& getExtensions() const { return _extensions; }
|
||||
|
||||
private:
|
||||
CCVKGPUContext* _gpuContext = nullptr;
|
||||
bool _isPrimaryContex = false;
|
||||
int _majorVersion = 0;
|
||||
int _minorVersion = 0;
|
||||
std::vector<const char *> _layers;
|
||||
std::vector<const char *> _extensions;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif // CC_GFXVULKAN_CCVK_CONTEXT_H_
|
||||
@@ -0,0 +1,198 @@
|
||||
#include "VKStd.h"
|
||||
#include "VKContext.h"
|
||||
#include "gles3w.h"
|
||||
#import <QuartzCore/CAEAGLLayer.h>
|
||||
#import <UIKit/UIScreen.h>
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
#if (CC_PLATFORM == CC_PLATFORM_MAC_IOS)
|
||||
|
||||
bool VKContext::initialize(const GFXContextInfo &info)
|
||||
{
|
||||
|
||||
_vsyncMode = info.vsyncMode;
|
||||
_windowHandle = info.windowHandle;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
if (!info.sharedCtx)
|
||||
{
|
||||
_isPrimaryContex = true;
|
||||
_windowHandle = info.windowHandle;
|
||||
|
||||
CAEAGLLayer* eaglLayer = (CAEAGLLayer*)( ((UIView*)(_windowHandle)).layer);
|
||||
eaglLayer.opaque = TRUE;
|
||||
|
||||
EAGLContext* eagl_context = [[EAGLContext alloc]initWithAPI:kEAGLRenderingAPIOpenVK];
|
||||
if (!eagl_context)
|
||||
{
|
||||
CC_LOG_ERROR("Create EAGL context failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
_eaglContext = (intptr_t)eagl_context;
|
||||
_eaglSharedContext = (intptr_t)eagl_context;
|
||||
|
||||
if (!VKwInit())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
VKContext* sharedCtx = (VKContext*)info.sharedCtx;
|
||||
EAGLContext* eagl_shared_context = (EAGLContext*)sharedCtx->eagl_shared_ctx();
|
||||
EAGLContext* eagl_context = [[EAGLContext alloc] initWithAPI: [eagl_shared_context API] sharegroup: [eagl_shared_context sharegroup]];
|
||||
if (!eagl_context)
|
||||
{
|
||||
CC_LOG_ERROR("Create EGL context with share context [0x%p] failed.", eagl_shared_context);
|
||||
|
||||
_eaglContext = (intptr_t)eagl_context;
|
||||
_eaglSharedContext = (intptr_t)eagl_shared_context;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
_colorFmt = GFXFormat::RGBA8;
|
||||
_depthStencilFmt = GFXFormat::D24S8;
|
||||
|
||||
if (!MakeCurrent())
|
||||
return false;
|
||||
|
||||
return createCustomFrameBuffer();
|
||||
}
|
||||
|
||||
bool VKContext::createCustomFrameBuffer()
|
||||
{
|
||||
glGenFramebuffers(1, &_defaultFBO);
|
||||
if (0 == _defaultFBO)
|
||||
{
|
||||
CC_LOG_ERROR("Can not create default frame buffer");
|
||||
return false;
|
||||
}
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, _defaultFBO);
|
||||
|
||||
glGenRenderbuffers(1, &_defaultColorBuffer);
|
||||
if (0 == _defaultColorBuffer)
|
||||
{
|
||||
CC_LOG_ERROR("Can not create default color buffer");
|
||||
return false;
|
||||
}
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, _defaultColorBuffer);
|
||||
|
||||
CAEAGLLayer* eaglLayer = (CAEAGLLayer*)( ((UIView*)(_windowHandle)).layer);
|
||||
if (! [(EAGLContext*)_eaglContext renderbufferStorage:GL_RENDERBUFFER
|
||||
fromDrawable:eaglLayer])
|
||||
{
|
||||
CC_LOG_ERROR("Attaches EAGLDrawable as storage for the OpenGL ES renderbuffer object failed.");
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, 0);
|
||||
glDeleteRenderbuffers(1, &_defaultColorBuffer);
|
||||
return false;
|
||||
}
|
||||
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, _defaultColorBuffer);
|
||||
|
||||
GLint framebufferWidth = 0, framebufferHeight = 0;
|
||||
glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &framebufferWidth);
|
||||
glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &framebufferHeight);
|
||||
|
||||
glGenRenderbuffers(1, &_defaultDepthStencilBuffer);
|
||||
if (_defaultDepthStencilBuffer == 0)
|
||||
{
|
||||
// Application can run without depth/stencil buffer, so don't return false here.
|
||||
CC_LOG_ERROR("Can not create default depth/stencil buffer");
|
||||
}
|
||||
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, _defaultDepthStencilBuffer);
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8_OES, framebufferWidth, framebufferHeight);
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, _defaultDepthStencilBuffer);
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, _defaultDepthStencilBuffer);
|
||||
|
||||
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
|
||||
if (status != GL_FRAMEBUFFER_COMPLETE)
|
||||
{
|
||||
switch (status)
|
||||
{
|
||||
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
|
||||
{
|
||||
CC_LOG_ERROR("glCheckFramebufferStatus() - FRAMEBUFFER_INCOMPLETE_ATTACHMENT");
|
||||
break;
|
||||
}
|
||||
case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
|
||||
{
|
||||
CC_LOG_ERROR("glCheckFramebufferStatus() - FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT");
|
||||
break;
|
||||
}
|
||||
case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS:
|
||||
{
|
||||
CC_LOG_ERROR("glCheckFramebufferStatus() - FRAMEBUFFER_INCOMPLETE_DIMENSIONS");
|
||||
break;
|
||||
}
|
||||
case GL_FRAMEBUFFER_UNSUPPORTED:
|
||||
{
|
||||
CC_LOG_ERROR("glCheckFramebufferStatus() - FRAMEBUFFER_UNSUPPORTED");
|
||||
break;
|
||||
}
|
||||
default:;
|
||||
}
|
||||
destroyCustomFrameBuffer();
|
||||
return false;
|
||||
}
|
||||
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, _defaultColorBuffer);
|
||||
return true;
|
||||
}
|
||||
|
||||
void VKContext::destroyCustomFrameBuffer()
|
||||
{
|
||||
if (_defaultColorBuffer)
|
||||
{
|
||||
glDeleteRenderbuffers(1, &_defaultColorBuffer);
|
||||
_defaultColorBuffer = 0;
|
||||
}
|
||||
if (_defaultDepthStencilBuffer)
|
||||
{
|
||||
glDeleteRenderbuffers(1, &_defaultDepthStencilBuffer);
|
||||
_defaultDepthStencilBuffer = 0;
|
||||
}
|
||||
|
||||
if (_defaultFBO)
|
||||
{
|
||||
glDeleteFramebuffers(1, &_defaultFBO);
|
||||
_defaultFBO = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void VKContext::destroy()
|
||||
{
|
||||
destroyCustomFrameBuffer();
|
||||
|
||||
if (_eaglContext)
|
||||
{
|
||||
[(EAGLContext*)_eaglContext release];
|
||||
}
|
||||
|
||||
_isPrimaryContex = false;
|
||||
_windowHandle = 0;
|
||||
_vsyncMode = GFXVsyncMode::OFF;
|
||||
_isInitialized = false;
|
||||
}
|
||||
|
||||
void VKContext::present()
|
||||
{
|
||||
|
||||
if (! [(EAGLContext*)_eaglContext presentRenderbuffer:GL_RENDERBUFFER] )
|
||||
{
|
||||
CC_LOG_ERROR("Failed to present content.");
|
||||
}
|
||||
}
|
||||
|
||||
bool VKContext::MakeCurrentImpl()
|
||||
{
|
||||
return [EAGLContext setCurrentContext:(EAGLContext*)_eaglContext];
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
NS_CC_END
|
||||
@@ -0,0 +1,592 @@
|
||||
#include "VKStd.h"
|
||||
#include "VKDevice.h"
|
||||
#include "VKUtils.h"
|
||||
#include "VKStateCache.h"
|
||||
#include "VKContext.h"
|
||||
#include "VKWindow.h"
|
||||
#include "VKQueue.h"
|
||||
#include "VKCommandAllocator.h"
|
||||
#include "VKCommandBuffer.h"
|
||||
#include "VKBuffer.h"
|
||||
#include "VKTexture.h"
|
||||
#include "VKTextureView.h"
|
||||
#include "VKSampler.h"
|
||||
#include "VKShader.h"
|
||||
#include "VKInputAssembler.h"
|
||||
#include "VKRenderPass.h"
|
||||
#include "VKFramebuffer.h"
|
||||
#include "VKBindingLayout.h"
|
||||
#include "VKPipelineLayout.h"
|
||||
#include "VKPipelineState.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
CCVKDevice::CCVKDevice()
|
||||
{
|
||||
}
|
||||
|
||||
CCVKDevice::~CCVKDevice()
|
||||
{
|
||||
}
|
||||
|
||||
bool CCVKDevice::initialize(const GFXDeviceInfo& info)
|
||||
{
|
||||
_gfxAPI = GFXAPI::VULKAN;
|
||||
_deviceName = "Vulkan";
|
||||
_width = info.width;
|
||||
_height = info.height;
|
||||
_nativeWidth = info.nativeWidth;
|
||||
_nativeHeight = info.nativeHeight;
|
||||
_windowHandle = info.windowHandle;
|
||||
|
||||
stateCache = CC_NEW(CCVKStateCache);
|
||||
|
||||
GFXContextInfo contextCreateInfo;
|
||||
contextCreateInfo.windowHandle = _windowHandle;
|
||||
contextCreateInfo.sharedCtx = info.sharedCtx;
|
||||
|
||||
_context = CC_NEW(CCVKContext(this));
|
||||
if (!_context->initialize(contextCreateInfo))
|
||||
{
|
||||
destroy();
|
||||
return false;
|
||||
}
|
||||
auto context = ((CCVKContext*)_context)->gpuContext();
|
||||
auto &deviceFeatures = context->physicalDeviceFeatures;
|
||||
|
||||
// only enable the absolute essentials for now
|
||||
std::vector<const char *> requestedValidationLayers
|
||||
{
|
||||
|
||||
};
|
||||
std::vector<const char *> requestedExtensions
|
||||
{
|
||||
VK_KHR_SWAPCHAIN_EXTENSION_NAME,
|
||||
};
|
||||
VkPhysicalDeviceFeatures requestedFeatures{};
|
||||
// features should be enabled like this
|
||||
requestedFeatures.textureCompressionASTC_LDR = deviceFeatures.textureCompressionASTC_LDR;
|
||||
requestedFeatures.textureCompressionBC = deviceFeatures.textureCompressionBC;
|
||||
requestedFeatures.textureCompressionETC2 = deviceFeatures.textureCompressionETC2;
|
||||
|
||||
///////////////////// Device Creation /////////////////////
|
||||
|
||||
_gpuDevice = CC_NEW(CCVKGPUDevice);
|
||||
_gpuSemaphorePool = CC_NEW(CCVKGPUSemaphorePool(_gpuDevice));
|
||||
|
||||
// check extensions
|
||||
uint32_t availableLayerCount;
|
||||
VK_CHECK(vkEnumerateDeviceLayerProperties(context->physicalDevice, &availableLayerCount, nullptr));
|
||||
_gpuDevice->layers.resize(availableLayerCount);
|
||||
VK_CHECK(vkEnumerateDeviceLayerProperties(context->physicalDevice, &availableLayerCount, _gpuDevice->layers.data()));
|
||||
|
||||
uint32_t availableExtensionCount;
|
||||
VK_CHECK(vkEnumerateDeviceExtensionProperties(context->physicalDevice, nullptr, &availableExtensionCount, nullptr));
|
||||
_gpuDevice->extensions.resize(availableExtensionCount);
|
||||
VK_CHECK(vkEnumerateDeviceExtensionProperties(context->physicalDevice, nullptr, &availableExtensionCount, _gpuDevice->extensions.data()));
|
||||
|
||||
// just filter out the unsupported layers & extensions
|
||||
for (auto &layer : requestedValidationLayers)
|
||||
{
|
||||
if (isLayerSupported(layer, _gpuDevice->layers))
|
||||
{
|
||||
_layers.push_back(layer);
|
||||
}
|
||||
}
|
||||
for (auto &extension : requestedExtensions)
|
||||
{
|
||||
if (isExtensionSupported(extension, _gpuDevice->extensions))
|
||||
{
|
||||
_extensions.push_back(extension);
|
||||
}
|
||||
}
|
||||
|
||||
// prepare the device queues
|
||||
uint32_t queueFamilyPropertiesCount = toU32(context->queueFamilyProperties.size());
|
||||
std::vector<VkDeviceQueueCreateInfo> queueCreateInfos(queueFamilyPropertiesCount, { VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO });
|
||||
std::vector<std::vector<float>> queuePriorities(queueFamilyPropertiesCount);
|
||||
|
||||
for (uint32_t queueFamilyIndex = 0u; queueFamilyIndex < queueFamilyPropertiesCount; ++queueFamilyIndex)
|
||||
{
|
||||
const VkQueueFamilyProperties &queueFamilyProperty = context->queueFamilyProperties[queueFamilyIndex];
|
||||
|
||||
queuePriorities[queueFamilyIndex].resize(queueFamilyProperty.queueCount, 1.0f);
|
||||
|
||||
VkDeviceQueueCreateInfo &queueCreateInfo = queueCreateInfos[queueFamilyIndex];
|
||||
|
||||
queueCreateInfo.queueFamilyIndex = queueFamilyIndex;
|
||||
queueCreateInfo.queueCount = queueFamilyProperty.queueCount;
|
||||
queueCreateInfo.pQueuePriorities = queuePriorities[queueFamilyIndex].data();
|
||||
}
|
||||
|
||||
VkDeviceCreateInfo deviceCreateInfo{ VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO };
|
||||
|
||||
deviceCreateInfo.queueCreateInfoCount = toU32(queueCreateInfos.size());
|
||||
deviceCreateInfo.pQueueCreateInfos = queueCreateInfos.data();
|
||||
deviceCreateInfo.enabledLayerCount = toU32(_layers.size());
|
||||
deviceCreateInfo.ppEnabledLayerNames = _layers.data();
|
||||
deviceCreateInfo.enabledExtensionCount = toU32(_extensions.size());
|
||||
deviceCreateInfo.ppEnabledExtensionNames = _extensions.data();
|
||||
deviceCreateInfo.pEnabledFeatures = &requestedFeatures;
|
||||
deviceCreateInfo.pNext = nullptr;
|
||||
|
||||
VK_CHECK(vkCreateDevice(context->physicalDevice, &deviceCreateInfo, nullptr, &_gpuDevice->vkDevice));
|
||||
|
||||
///////////////////// Resource Initialization /////////////////////
|
||||
|
||||
for (uint32_t i = 0; i < context->swapchainCreateInfo.minImageCount; i++)
|
||||
{
|
||||
GFXTextureInfo depthStecnilTexInfo;
|
||||
depthStecnilTexInfo.type = GFXTextureType::TEX2D;
|
||||
depthStecnilTexInfo.usage = GFXTextureUsageBit::DEPTH_STENCIL_ATTACHMENT | GFXTextureUsageBit::SAMPLED;
|
||||
depthStecnilTexInfo.format = _context->getDepthStencilFormat();
|
||||
depthStecnilTexInfo.width = 1;
|
||||
depthStecnilTexInfo.height = 1;
|
||||
auto texture = (CCVKTexture*)createTexture(depthStecnilTexInfo);
|
||||
_depthStencilTextures.push_back(texture);
|
||||
|
||||
GFXTextureViewInfo depthStecnilTexViewInfo;
|
||||
depthStecnilTexViewInfo.texture = texture;
|
||||
depthStecnilTexViewInfo.type = GFXTextureViewType::TV2D;
|
||||
depthStecnilTexViewInfo.format = _context->getDepthStencilFormat();
|
||||
auto textureView = (CCVKTextureView*)createTextureView(depthStecnilTexViewInfo);
|
||||
_depthStencilTextureViews.push_back(textureView);
|
||||
}
|
||||
|
||||
GFXRenderPassInfo renderPassInfo;
|
||||
GFXColorAttachment colorAttachment;
|
||||
colorAttachment.format = _context->getColorFormat();
|
||||
colorAttachment.loadOp = GFXLoadOp::CLEAR;
|
||||
colorAttachment.storeOp = GFXStoreOp::STORE;
|
||||
colorAttachment.sampleCount = 1;
|
||||
colorAttachment.beginLayout = GFXTextureLayout::COLOR_ATTACHMENT_OPTIMAL;
|
||||
colorAttachment.endLayout = GFXTextureLayout::PRESENT_SRC;
|
||||
renderPassInfo.colorAttachments.emplace_back(colorAttachment);
|
||||
|
||||
GFXDepthStencilAttachment& depthStencilAttachment = renderPassInfo.depthStencilAttachment;
|
||||
depthStencilAttachment.format = _context->getDepthStencilFormat();
|
||||
depthStencilAttachment.depthLoadOp = GFXLoadOp::CLEAR;
|
||||
depthStencilAttachment.depthStoreOp = GFXStoreOp::STORE;
|
||||
depthStencilAttachment.stencilLoadOp = GFXLoadOp::CLEAR;
|
||||
depthStencilAttachment.stencilStoreOp = GFXStoreOp::STORE;
|
||||
depthStencilAttachment.sampleCount = 1;
|
||||
depthStencilAttachment.beginLayout = GFXTextureLayout::DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
|
||||
depthStencilAttachment.endLayout = GFXTextureLayout::PRESENT_SRC;
|
||||
|
||||
_renderPass = (CCVKRenderPass*)createRenderPass(renderPassInfo);
|
||||
_gpuSwapchain = CC_NEW(CCVKGPUSwapchain);
|
||||
_gpuSwapchain->renderPass = _renderPass->gpuRenderPass();
|
||||
|
||||
buildSwapchain();
|
||||
|
||||
GFXWindowInfo windowInfo;
|
||||
windowInfo.colorFmt = _context->getColorFormat();
|
||||
windowInfo.depthStencilFmt = _context->getDepthStencilFormat();
|
||||
windowInfo.isOffscreen = false;
|
||||
_window = createWindow(windowInfo);
|
||||
|
||||
GFXQueueInfo queueInfo;
|
||||
queueInfo.type = GFXQueueType::GRAPHICS;
|
||||
_queue = createQueue(queueInfo);
|
||||
|
||||
GFXCommandAllocatorInfo cmd_alloc_info;
|
||||
_cmdAllocator = createCommandAllocator(cmd_alloc_info);
|
||||
|
||||
String instanceLayers, instanceExtensions, deviceLayers, deviceExtensions;
|
||||
for (auto layer : ((CCVKContext*)_context)->getLayers())
|
||||
{
|
||||
instanceLayers += layer + String(" ");
|
||||
}
|
||||
for (auto extension : ((CCVKContext*)_context)->getExtensions())
|
||||
{
|
||||
instanceExtensions += extension + String(" ");
|
||||
}
|
||||
for (auto layer : _layers)
|
||||
{
|
||||
deviceLayers += layer + String(" ");
|
||||
}
|
||||
for (auto extension : _extensions)
|
||||
{
|
||||
deviceExtensions += extension + String(" ");
|
||||
}
|
||||
|
||||
String compressedFmts;
|
||||
if (deviceFeatures.textureCompressionETC2)
|
||||
{
|
||||
_features[(int)GFXFeature::FORMAT_ETC2] = true;
|
||||
compressedFmts += "etc2 ";
|
||||
}
|
||||
if (deviceFeatures.textureCompressionASTC_LDR)
|
||||
{
|
||||
_features[(int)GFXFeature::FORMAT_ASTC] = true;
|
||||
compressedFmts += "astc ";
|
||||
}
|
||||
|
||||
CC_LOG_INFO("Vulkan device initialized.");
|
||||
CC_LOG_INFO("DEVICE_NAME: %s", context->physicalDeviceProperties.deviceName);
|
||||
CC_LOG_INFO("VULKAN_VERSION: %d.%d", ((CCVKContext*)_context)->majorVersion(), ((CCVKContext*)_context)->minorVersion());
|
||||
CC_LOG_INFO("SCREEN_SIZE: %d x %d", _width, _height);
|
||||
CC_LOG_INFO("NATIVE_SIZE: %d x %d", _nativeWidth, _nativeHeight);
|
||||
CC_LOG_INFO("INSTANCE_LAYERS: %s", instanceLayers.c_str());
|
||||
CC_LOG_INFO("INSTANCE_EXTENSIONS: %s", instanceExtensions.c_str());
|
||||
CC_LOG_INFO("DEVICE_LAYERS: %s", deviceLayers.c_str());
|
||||
CC_LOG_INFO("DEVICE_EXTENSIONS: %s", deviceExtensions.c_str());
|
||||
CC_LOG_INFO("COMPRESSED_FORMATS: %s", compressedFmts.c_str());
|
||||
|
||||
this->begin();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CCVKDevice::destroy()
|
||||
{
|
||||
CC_SAFE_DESTROY(_cmdAllocator);
|
||||
CC_SAFE_DESTROY(_queue);
|
||||
CC_SAFE_DESTROY(_window);
|
||||
CC_SAFE_DESTROY(_renderPass);
|
||||
CC_SAFE_DELETE(_gpuSemaphorePool);
|
||||
|
||||
for (auto textureView : _depthStencilTextureViews)
|
||||
{
|
||||
CC_SAFE_DESTROY(textureView);
|
||||
}
|
||||
for (auto texture : _depthStencilTextures)
|
||||
{
|
||||
CC_SAFE_DESTROY(texture);
|
||||
}
|
||||
|
||||
if (_gpuSwapchain)
|
||||
{
|
||||
if (_gpuSwapchain->vkSwapchain != VK_NULL_HANDLE)
|
||||
{
|
||||
_gpuSwapchain->depthStencilImageViews.clear();
|
||||
_gpuSwapchain->depthStencilImages.clear();
|
||||
|
||||
for (auto framebuffer : _gpuSwapchain->vkSwapchainFramebuffers)
|
||||
{
|
||||
vkDestroyFramebuffer(_gpuDevice->vkDevice, framebuffer, nullptr);
|
||||
}
|
||||
_gpuSwapchain->vkSwapchainFramebuffers.clear();
|
||||
|
||||
for (auto imageView : _gpuSwapchain->vkSwapchainImageViews)
|
||||
{
|
||||
vkDestroyImageView(_gpuDevice->vkDevice, imageView, nullptr);
|
||||
}
|
||||
_gpuSwapchain->vkSwapchainImageViews.clear();
|
||||
_gpuSwapchain->swapchainImages.clear();
|
||||
|
||||
vkDestroySwapchainKHR(_gpuDevice->vkDevice, _gpuSwapchain->vkSwapchain, nullptr);
|
||||
_gpuSwapchain->vkSwapchain = VK_NULL_HANDLE;
|
||||
}
|
||||
|
||||
CC_DELETE(_gpuSwapchain);
|
||||
_gpuSwapchain = nullptr;
|
||||
}
|
||||
|
||||
if (_gpuDevice)
|
||||
{
|
||||
if (_gpuDevice->vkDevice != VK_NULL_HANDLE)
|
||||
{
|
||||
vkDestroyDevice(_gpuDevice->vkDevice, nullptr);
|
||||
_gpuDevice->vkDevice = VK_NULL_HANDLE;
|
||||
}
|
||||
|
||||
CC_DELETE(_gpuDevice);
|
||||
_gpuDevice = nullptr;
|
||||
}
|
||||
|
||||
CC_SAFE_DESTROY(_context);
|
||||
}
|
||||
|
||||
void CCVKDevice::resize(uint width, uint height)
|
||||
{
|
||||
_width = width;
|
||||
_height = height;
|
||||
buildSwapchain();
|
||||
_window->resize(_width, _height);
|
||||
}
|
||||
|
||||
void CCVKDevice::buildSwapchain()
|
||||
{
|
||||
auto context = ((CCVKContext*)_context)->gpuContext();
|
||||
context->swapchainCreateInfo.oldSwapchain = _gpuSwapchain->vkSwapchain;
|
||||
|
||||
VkSurfaceCapabilitiesKHR surfaceCapabilities;
|
||||
VK_CHECK(vkGetPhysicalDeviceSurfaceCapabilitiesKHR(context->physicalDevice, context->vkSurface, &surfaceCapabilities));
|
||||
if (surfaceCapabilities.currentExtent.width == (uint32_t)-1)
|
||||
{
|
||||
context->swapchainCreateInfo.imageExtent.width = _width;
|
||||
context->swapchainCreateInfo.imageExtent.height = _height;
|
||||
}
|
||||
else
|
||||
{
|
||||
_width = context->swapchainCreateInfo.imageExtent.width = surfaceCapabilities.currentExtent.width;
|
||||
_height = context->swapchainCreateInfo.imageExtent.height = surfaceCapabilities.currentExtent.height;
|
||||
}
|
||||
VK_CHECK(vkCreateSwapchainKHR(_gpuDevice->vkDevice, &context->swapchainCreateInfo, nullptr, &_gpuSwapchain->vkSwapchain));
|
||||
|
||||
if (context->swapchainCreateInfo.oldSwapchain != VK_NULL_HANDLE)
|
||||
{
|
||||
_gpuSwapchain->depthStencilImageViews.clear();
|
||||
_gpuSwapchain->depthStencilImages.clear();
|
||||
|
||||
for (auto framebuffer : _gpuSwapchain->vkSwapchainFramebuffers)
|
||||
{
|
||||
vkDestroyFramebuffer(_gpuDevice->vkDevice, framebuffer, nullptr);
|
||||
}
|
||||
_gpuSwapchain->vkSwapchainFramebuffers.clear();
|
||||
|
||||
for (auto imageView : _gpuSwapchain->vkSwapchainImageViews)
|
||||
{
|
||||
vkDestroyImageView(_gpuDevice->vkDevice, imageView, nullptr);
|
||||
}
|
||||
_gpuSwapchain->vkSwapchainImageViews.clear();
|
||||
_gpuSwapchain->swapchainImages.clear();
|
||||
|
||||
vkDestroySwapchainKHR(_gpuDevice->vkDevice, context->swapchainCreateInfo.oldSwapchain, nullptr);
|
||||
}
|
||||
|
||||
uint32_t imageCount;
|
||||
VK_CHECK(vkGetSwapchainImagesKHR(_gpuDevice->vkDevice, _gpuSwapchain->vkSwapchain, &imageCount, nullptr));
|
||||
_gpuSwapchain->swapchainImages.resize(imageCount);
|
||||
VK_CHECK(vkGetSwapchainImagesKHR(_gpuDevice->vkDevice, _gpuSwapchain->vkSwapchain, &imageCount, _gpuSwapchain->swapchainImages.data()));
|
||||
assert(imageCount == context->swapchainCreateInfo.minImageCount); // assert if swapchain image count assumption is broken
|
||||
|
||||
_gpuSwapchain->vkSwapchainImageViews.resize(imageCount);
|
||||
_gpuSwapchain->vkSwapchainFramebuffers.resize(imageCount);
|
||||
for (uint32_t i = 0; i < imageCount; i++)
|
||||
{
|
||||
_depthStencilTextures[i]->resize(_width, _height);
|
||||
_gpuSwapchain->depthStencilImages.push_back(((CCVKTexture*)_depthStencilTextures[i])->gpuTexture()->vkImage);
|
||||
|
||||
_depthStencilTextureViews[i]->destroy();
|
||||
GFXTextureViewInfo textureViewInfo;
|
||||
textureViewInfo.texture = _depthStencilTextures[i];
|
||||
textureViewInfo.type = GFXTextureViewType::TV2D;
|
||||
textureViewInfo.format = _context->getDepthStencilFormat();
|
||||
_depthStencilTextureViews[i]->initialize(textureViewInfo);
|
||||
_gpuSwapchain->depthStencilImageViews.push_back(((CCVKTextureView*)_depthStencilTextureViews[i])->gpuTexView()->vkImageView);
|
||||
|
||||
VkImageViewCreateInfo imageViewCreateInfo{ VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO };
|
||||
imageViewCreateInfo.image = _gpuSwapchain->swapchainImages[i];
|
||||
imageViewCreateInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
|
||||
imageViewCreateInfo.format = context->swapchainCreateInfo.imageFormat;
|
||||
imageViewCreateInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
||||
imageViewCreateInfo.subresourceRange.levelCount = 1;
|
||||
imageViewCreateInfo.subresourceRange.layerCount = 1;
|
||||
|
||||
VK_CHECK(vkCreateImageView(_gpuDevice->vkDevice, &imageViewCreateInfo, nullptr, &_gpuSwapchain->vkSwapchainImageViews[i]));
|
||||
|
||||
VkImageView attachments[] = { _gpuSwapchain->vkSwapchainImageViews[i], _depthStencilTextureViews[i]->gpuTexView()->vkImageView };
|
||||
|
||||
VkFramebufferCreateInfo framebufferCreateInfo{ VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO };
|
||||
framebufferCreateInfo.renderPass = _renderPass->gpuRenderPass()->vkRenderPass;
|
||||
framebufferCreateInfo.attachmentCount = COUNTOF(attachments);
|
||||
framebufferCreateInfo.pAttachments = attachments;
|
||||
framebufferCreateInfo.width = _width;
|
||||
framebufferCreateInfo.height = _height;
|
||||
framebufferCreateInfo.layers = 1;
|
||||
|
||||
VK_CHECK(vkCreateFramebuffer(_gpuDevice->vkDevice, &framebufferCreateInfo, 0, &_gpuSwapchain->vkSwapchainFramebuffers[i]));
|
||||
}
|
||||
}
|
||||
|
||||
void CCVKDevice::begin()
|
||||
{
|
||||
CCVKGPUQueue* queue = ((CCVKQueue*)_queue)->gpuQueue();
|
||||
|
||||
_gpuSemaphorePool->clear();
|
||||
VkSemaphore acquireSemaphore = _gpuSemaphorePool->alloc();
|
||||
VK_CHECK(vkAcquireNextImageKHR(_gpuDevice->vkDevice, _gpuSwapchain->vkSwapchain,
|
||||
~0ull, acquireSemaphore, VK_NULL_HANDLE, &_gpuSwapchain->curImageIndex));
|
||||
VK_CHECK(vkResetCommandPool(_gpuDevice->vkDevice, ((CCVKCommandAllocator*)_cmdAllocator)->gpuCommandPool()->vkCommandPool, 0));
|
||||
|
||||
queue->waitSemaphore = acquireSemaphore;
|
||||
queue->signalSemaphore = _gpuSemaphorePool->alloc();
|
||||
}
|
||||
|
||||
void CCVKDevice::present()
|
||||
{
|
||||
//((CCVKCommandAllocator*)_cmdAllocator)->releaseCmds();
|
||||
CCVKQueue* queue = (CCVKQueue*)_queue;
|
||||
_numDrawCalls = queue->_numDrawCalls;
|
||||
_numInstances = queue->_numInstances;
|
||||
_numTriangles = queue->_numTriangles;
|
||||
|
||||
VkPresentInfoKHR presentInfo{ VK_STRUCTURE_TYPE_PRESENT_INFO_KHR };
|
||||
presentInfo.waitSemaphoreCount = 1;
|
||||
presentInfo.pWaitSemaphores = &queue->gpuQueue()->waitSemaphore;
|
||||
presentInfo.swapchainCount = 1;
|
||||
presentInfo.pSwapchains = &_gpuSwapchain->vkSwapchain;
|
||||
presentInfo.pImageIndices = &_gpuSwapchain->curImageIndex;
|
||||
|
||||
VK_CHECK(vkQueuePresentKHR(queue->gpuQueue()->vkQueue, &presentInfo));
|
||||
|
||||
VK_CHECK(vkDeviceWaitIdle(_gpuDevice->vkDevice));
|
||||
|
||||
// Clear queue stats
|
||||
queue->_numDrawCalls = 0;
|
||||
queue->_numInstances = 0;
|
||||
queue->_numTriangles = 0;
|
||||
|
||||
this->begin();
|
||||
}
|
||||
|
||||
GFXWindow* CCVKDevice::createWindow(const GFXWindowInfo& info)
|
||||
{
|
||||
GFXWindow* window = CC_NEW(CCVKWindow(this));
|
||||
if (window->initialize(info))
|
||||
return window;
|
||||
|
||||
CC_SAFE_DESTROY(window);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
GFXQueue* CCVKDevice::createQueue(const GFXQueueInfo& info)
|
||||
{
|
||||
GFXQueue* queue = CC_NEW(CCVKQueue(this));
|
||||
if (queue->initialize(info))
|
||||
return queue;
|
||||
|
||||
CC_SAFE_DESTROY(queue);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
GFXCommandAllocator* CCVKDevice::createCommandAllocator(const GFXCommandAllocatorInfo& info)
|
||||
{
|
||||
GFXCommandAllocator* cmdAllocator = CC_NEW(CCVKCommandAllocator(this));
|
||||
if (cmdAllocator->initialize(info))
|
||||
return cmdAllocator;
|
||||
|
||||
CC_SAFE_DESTROY(cmdAllocator);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
GFXCommandBuffer* CCVKDevice::createCommandBuffer(const GFXCommandBufferInfo& info)
|
||||
{
|
||||
GFXCommandBuffer* gfx_cmd_buff = CC_NEW(CCVKCommandBuffer(this));
|
||||
if (gfx_cmd_buff->initialize(info))
|
||||
return gfx_cmd_buff;
|
||||
|
||||
CC_SAFE_DESTROY(gfx_cmd_buff)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
GFXBuffer* CCVKDevice::createBuffer(const GFXBufferInfo& info)
|
||||
{
|
||||
GFXBuffer* buffer = CC_NEW(CCVKBuffer(this));
|
||||
if (buffer->initialize(info))
|
||||
return buffer;
|
||||
|
||||
CC_SAFE_DESTROY(buffer);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
GFXTexture* CCVKDevice::createTexture(const GFXTextureInfo& info)
|
||||
{
|
||||
GFXTexture* texture = CC_NEW(CCVKTexture(this));
|
||||
if (texture->initialize(info))
|
||||
return texture;
|
||||
|
||||
CC_SAFE_DESTROY(texture);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
GFXTextureView* CCVKDevice::createTextureView(const GFXTextureViewInfo& info)
|
||||
{
|
||||
GFXTextureView* texView = CC_NEW(CCVKTextureView(this));
|
||||
if (texView->initialize(info))
|
||||
return texView;
|
||||
|
||||
CC_SAFE_DESTROY(texView);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
GFXSampler* CCVKDevice::createSampler(const GFXSamplerInfo& info)
|
||||
{
|
||||
GFXSampler* sampler = CC_NEW(CCVKSampler(this));
|
||||
if (sampler->initialize(info))
|
||||
return sampler;
|
||||
|
||||
CC_SAFE_DESTROY(sampler);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
GFXShader* CCVKDevice::createShader(const GFXShaderInfo& info)
|
||||
{
|
||||
GFXShader* shader = CC_NEW(CCVKShader(this));
|
||||
if (shader->initialize(info))
|
||||
return shader;
|
||||
|
||||
CC_SAFE_DESTROY(shader);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
GFXInputAssembler* CCVKDevice::createInputAssembler(const GFXInputAssemblerInfo& info)
|
||||
{
|
||||
GFXInputAssembler* inputAssembler = CC_NEW(CCVKInputAssembler(this));
|
||||
if (inputAssembler->initialize(info))
|
||||
return inputAssembler;
|
||||
|
||||
CC_SAFE_DESTROY(inputAssembler);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
GFXRenderPass* CCVKDevice::createRenderPass(const GFXRenderPassInfo& info)
|
||||
{
|
||||
GFXRenderPass* renderPass = CC_NEW(CCVKRenderPass(this));
|
||||
if (renderPass->initialize(info))
|
||||
return renderPass;
|
||||
|
||||
CC_SAFE_DESTROY(renderPass);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
GFXFramebuffer* CCVKDevice::createFramebuffer(const GFXFramebufferInfo& info)
|
||||
{
|
||||
GFXFramebuffer* framebuffer = CC_NEW(CCVKFramebuffer(this));
|
||||
if (framebuffer->initialize(info))
|
||||
return framebuffer;
|
||||
|
||||
CC_SAFE_DESTROY(framebuffer);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
GFXBindingLayout* CCVKDevice::createBindingLayout(const GFXBindingLayoutInfo& info)
|
||||
{
|
||||
GFXBindingLayout* bindingLayout = CC_NEW(CCVKBindingLayout(this));
|
||||
if (bindingLayout->initialize(info))
|
||||
return bindingLayout;
|
||||
|
||||
CC_SAFE_DESTROY(bindingLayout);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
GFXPipelineState* CCVKDevice::createPipelineState(const GFXPipelineStateInfo& info)
|
||||
{
|
||||
GFXPipelineState* pipelineState = CC_NEW(CCVKPipelineState(this));
|
||||
if (pipelineState->initialize(info))
|
||||
return pipelineState;
|
||||
|
||||
CC_SAFE_DESTROY(pipelineState);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
GFXPipelineLayout* CCVKDevice::createPipelineLayout(const GFXPipelineLayoutInfo& info)
|
||||
{
|
||||
GFXPipelineLayout* layout = CC_NEW(CCVKPipelineLayout(this));
|
||||
if (layout->initialize(info))
|
||||
return layout;
|
||||
|
||||
CC_SAFE_DESTROY(layout);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void CCVKDevice::copyBuffersToTexture(const GFXDataArray& buffers, GFXTexture* dst, const GFXBufferTextureCopyList& regions)
|
||||
{
|
||||
|
||||
CCVKCmdFuncCopyBuffersToTexture(this, buffers.datas.data(), ((CCVKTexture*)dst)->gpuTexture(), regions);
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
@@ -0,0 +1,74 @@
|
||||
#ifndef CC_GFXVULKAN_CCVK_DEVICE_H_
|
||||
#define CC_GFXVULKAN_CCVK_DEVICE_H_
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class CCVKStateCache;
|
||||
class CCVKGPUDevice;
|
||||
class CCVKGPUSwapchain;
|
||||
class CCVKGPUSemaphorePool;
|
||||
class CCVKTexture;
|
||||
class CCVKTextureView;
|
||||
class CCVKRenderPass;;
|
||||
|
||||
class CC_VULKAN_API CCVKDevice : public GFXDevice
|
||||
{
|
||||
public:
|
||||
CCVKDevice();
|
||||
~CCVKDevice();
|
||||
|
||||
CCVKStateCache* stateCache = nullptr;
|
||||
|
||||
public:
|
||||
bool initialize(const GFXDeviceInfo& info) override;
|
||||
void destroy() override;
|
||||
void resize(uint width, uint height) override;
|
||||
void begin() override;
|
||||
void present() override;
|
||||
GFXWindow* createWindow(const GFXWindowInfo& info) override;
|
||||
GFXQueue* createQueue(const GFXQueueInfo& info) override;
|
||||
GFXCommandAllocator* createCommandAllocator(const GFXCommandAllocatorInfo& info) override;
|
||||
GFXCommandBuffer* createCommandBuffer(const GFXCommandBufferInfo& info) override;
|
||||
GFXBuffer* createBuffer(const GFXBufferInfo& info) override;
|
||||
GFXTexture* createTexture(const GFXTextureInfo& info) override;
|
||||
GFXTextureView* createTextureView(const GFXTextureViewInfo& info) override;
|
||||
GFXSampler* createSampler(const GFXSamplerInfo& info) override;
|
||||
GFXShader* createShader(const GFXShaderInfo& info) override;
|
||||
GFXInputAssembler* createInputAssembler(const GFXInputAssemblerInfo& info) override;
|
||||
GFXRenderPass* createRenderPass(const GFXRenderPassInfo& info) override;
|
||||
GFXFramebuffer* createFramebuffer(const GFXFramebufferInfo& info) override;
|
||||
GFXBindingLayout* createBindingLayout(const GFXBindingLayoutInfo& info) override;
|
||||
virtual GFXPipelineState* createPipelineState(const GFXPipelineStateInfo& info) override;
|
||||
virtual GFXPipelineLayout* createPipelineLayout(const GFXPipelineLayoutInfo& info) override;
|
||||
virtual void copyBuffersToTexture(const GFXDataArray& buffers, GFXTexture* dst, const GFXBufferTextureCopyList& regions) override;
|
||||
|
||||
CC_INLINE bool checkExtension(const String& extension) const {
|
||||
return std::find_if(_extensions.begin(), _extensions.end(),
|
||||
[extension](auto &device_extension) {
|
||||
return std::strcmp(device_extension, extension.c_str()) == 0;
|
||||
}) != _extensions.end();
|
||||
}
|
||||
|
||||
CC_INLINE CCVKGPUDevice* gpuDevice() const { return _gpuDevice; }
|
||||
CC_INLINE CCVKGPUSwapchain* gpuSwapchain() { return _gpuSwapchain; }
|
||||
CC_INLINE CCVKGPUSemaphorePool* gpuSemaphorePool() { return _gpuSemaphorePool; }
|
||||
CC_INLINE const std::vector<const char *>& getLayers() const { return _layers; }
|
||||
CC_INLINE const std::vector<const char *>& getExtensions() const { return _extensions; }
|
||||
|
||||
private:
|
||||
void buildSwapchain();
|
||||
|
||||
CCVKGPUDevice* _gpuDevice = nullptr;
|
||||
CCVKGPUSemaphorePool* _gpuSemaphorePool = nullptr;
|
||||
CCVKGPUSwapchain* _gpuSwapchain = nullptr;
|
||||
std::vector<CCVKTextureView*> _depthStencilTextureViews;
|
||||
std::vector<CCVKTexture*> _depthStencilTextures;
|
||||
CCVKRenderPass* _renderPass;
|
||||
|
||||
std::vector<const char *> _layers;
|
||||
std::vector<const char *> _extensions;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif // CC_GFXVULKAN_CCVK_DEVICE_H_
|
||||
@@ -0,0 +1,69 @@
|
||||
#include "VKStd.h"
|
||||
#include "VKFramebuffer.h"
|
||||
#include "VKRenderPass.h"
|
||||
#include "VKCommands.h"
|
||||
#include "VKTextureView.h"
|
||||
#include "VKDevice.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
CCVKFramebuffer::CCVKFramebuffer(GFXDevice* device)
|
||||
: GFXFramebuffer(device)
|
||||
{
|
||||
}
|
||||
|
||||
CCVKFramebuffer::~CCVKFramebuffer()
|
||||
{
|
||||
}
|
||||
|
||||
bool CCVKFramebuffer::initialize(const GFXFramebufferInfo &info)
|
||||
{
|
||||
_renderPass = info.renderPass;
|
||||
_colorViews = info.colorViews;
|
||||
_depthStencilView = info.depthStencilView;
|
||||
_isOffscreen = info.isOffscreen;
|
||||
|
||||
_gpuFBO = CC_NEW(CCVKGPUFramebuffer);
|
||||
_gpuFBO->gpuRenderPass = ((CCVKRenderPass*)_renderPass)->gpuRenderPass();
|
||||
|
||||
if (_isOffscreen)
|
||||
{
|
||||
_gpuFBO->gpuColorViews.resize(_colorViews.size());
|
||||
for (size_t i = 0; i < _colorViews.size(); ++i)
|
||||
{
|
||||
CCVKTextureView* colorview = (CCVKTextureView*)_colorViews[i];
|
||||
_gpuFBO->gpuColorViews[i] = colorview->gpuTexView();
|
||||
}
|
||||
|
||||
if (_depthStencilView)
|
||||
{
|
||||
_gpuFBO->gpuDepthStencilView = ((CCVKTextureView*)_depthStencilView)->gpuTexView();
|
||||
}
|
||||
|
||||
_gpuFBO->isOffscreen = _isOffscreen;
|
||||
|
||||
}
|
||||
|
||||
CCVKCmdFuncCreateFramebuffer((CCVKDevice*)_device, _gpuFBO);
|
||||
|
||||
_status = GFXStatus::SUCCESS;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CCVKFramebuffer::destroy()
|
||||
{
|
||||
if (_gpuFBO)
|
||||
{
|
||||
if (_isOffscreen)
|
||||
{
|
||||
CCVKCmdFuncDestroyFramebuffer((CCVKDevice*)_device, _gpuFBO);
|
||||
}
|
||||
CC_DELETE(_gpuFBO);
|
||||
_gpuFBO = nullptr;
|
||||
}
|
||||
|
||||
_status = GFXStatus::UNREADY;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
@@ -0,0 +1,25 @@
|
||||
#ifndef CC_GFXVULKAN_CCVK_FRAMEBUFFER_H_
|
||||
#define CC_GFXVULKAN_CCVK_FRAMEBUFFER_H_
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class CCVKGPUFramebuffer;
|
||||
|
||||
class CC_VULKAN_API CCVKFramebuffer : public GFXFramebuffer {
|
||||
public:
|
||||
CCVKFramebuffer(GFXDevice* device);
|
||||
~CCVKFramebuffer();
|
||||
|
||||
public:
|
||||
bool initialize(const GFXFramebufferInfo& info);
|
||||
void destroy();
|
||||
|
||||
CC_INLINE CCVKGPUFramebuffer* gpuFBO() const { return _gpuFBO; }
|
||||
|
||||
private:
|
||||
CCVKGPUFramebuffer* _gpuFBO = nullptr;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,371 @@
|
||||
#ifndef CC_GFXVULKAN_GPU_OBJECTS_H_
|
||||
#define CC_GFXVULKAN_GPU_OBJECTS_H_
|
||||
|
||||
#include "volk.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class CCVKGPUContext
|
||||
{
|
||||
public:
|
||||
VkInstance vkInstance = VK_NULL_HANDLE;
|
||||
VkDebugUtilsMessengerEXT vkDebugUtilsMessenger = VK_NULL_HANDLE;
|
||||
VkDebugReportCallbackEXT vkDebugReport = VK_NULL_HANDLE;
|
||||
|
||||
VkPhysicalDevice physicalDevice = VK_NULL_HANDLE;
|
||||
VkPhysicalDeviceFeatures physicalDeviceFeatures{};
|
||||
VkPhysicalDeviceProperties physicalDeviceProperties{};
|
||||
VkPhysicalDeviceMemoryProperties physicalDeviceMemoryProperties{};
|
||||
vector<VkQueueFamilyProperties>::type queueFamilyProperties;
|
||||
vector<VkBool32>::type queueFamilyPresentables;
|
||||
|
||||
VkSurfaceKHR vkSurface = VK_NULL_HANDLE;
|
||||
|
||||
VkSwapchainCreateInfoKHR swapchainCreateInfo{ VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR };
|
||||
};
|
||||
|
||||
class CCVKGPUDevice : public Object
|
||||
{
|
||||
public:
|
||||
VkDevice vkDevice = VK_NULL_HANDLE;
|
||||
vector<VkLayerProperties>::type layers;
|
||||
vector<VkExtensionProperties>::type extensions;
|
||||
};
|
||||
|
||||
class CCVKGPURenderPass : public Object
|
||||
{
|
||||
public:
|
||||
GFXColorAttachmentList colorAttachments;
|
||||
GFXDepthStencilAttachment depthStencilAttachment;
|
||||
GFXSubPassList subPasses;
|
||||
VkRenderPass vkRenderPass;
|
||||
vector<VkClearValue>::type clearValues;
|
||||
vector<VkImageMemoryBarrier>::type beginBarriers;
|
||||
vector<VkImageMemoryBarrier>::type endBarriers;
|
||||
};
|
||||
|
||||
class CCVKGPUSwapchain
|
||||
{
|
||||
public:
|
||||
uint32_t curImageIndex;
|
||||
VkSwapchainKHR vkSwapchain = VK_NULL_HANDLE;
|
||||
vector<VkImageView>::type vkSwapchainImageViews;
|
||||
vector<VkFramebuffer>::type vkSwapchainFramebuffers;
|
||||
// external references
|
||||
vector<VkImage>::type swapchainImages;
|
||||
vector<VkImage>::type depthStencilImages;
|
||||
vector<VkImageView>::type depthStencilImageViews;
|
||||
CCVKGPURenderPass* renderPass;
|
||||
};
|
||||
|
||||
class CCVKGPUCommandPool : public Object
|
||||
{
|
||||
public:
|
||||
VkCommandPool vkCommandPool = VK_NULL_HANDLE;
|
||||
map<VkCommandBufferLevel, CachedArray<VkCommandBuffer>>::type commandBuffers;
|
||||
};
|
||||
|
||||
class CCVKGPUCommandBuffer : public Object
|
||||
{
|
||||
public:
|
||||
GFXCommandBufferType type;
|
||||
CCVKGPUCommandPool* commandPool = nullptr;
|
||||
VkCommandBuffer vkCommandBuffer = VK_NULL_HANDLE;
|
||||
};
|
||||
|
||||
class CCVKGPUQueue : public Object
|
||||
{
|
||||
public:
|
||||
GFXQueueType type;
|
||||
VkQueue vkQueue;
|
||||
uint32_t queueFamilyIndex;
|
||||
VkSemaphore waitSemaphore = VK_NULL_HANDLE;
|
||||
VkSemaphore signalSemaphore = VK_NULL_HANDLE;
|
||||
VkPipelineStageFlags submitStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
||||
CachedArray<VkCommandBuffer> commandBuffers;
|
||||
};
|
||||
|
||||
class CCVKGPUBuffer : public Object
|
||||
{
|
||||
public:
|
||||
GFXBufferUsage usage = GFXBufferUsage::NONE;
|
||||
GFXMemoryUsage memUsage = GFXMemoryUsage::NONE;
|
||||
uint size = 0;
|
||||
uint stride = 0;
|
||||
uint count = 0;
|
||||
VkBuffer vkBuffer = VK_NULL_HANDLE;
|
||||
VkDeviceMemory vkDeviceMemory = VK_NULL_HANDLE;
|
||||
void* buffer = nullptr;
|
||||
GFXDrawInfoList indirects;
|
||||
};
|
||||
typedef vector<CCVKGPUBuffer*>::type CCVKGPUBufferList;
|
||||
|
||||
class CCVKGPUTexture : public Object
|
||||
{
|
||||
public:
|
||||
GFXTextureType type = GFXTextureType::TEX2D;
|
||||
GFXTextureViewType viewType = GFXTextureViewType::TV2D;
|
||||
GFXFormat format = GFXFormat::UNKNOWN;
|
||||
GFXTextureUsage usage = GFXTextureUsageBit::NONE;
|
||||
uint width = 0;
|
||||
uint height = 0;
|
||||
uint depth = 1;
|
||||
uint size = 0;
|
||||
uint arrayLayer = 1;
|
||||
uint mipLevel = 1;
|
||||
GFXSampleCount samples = GFXSampleCount::X1;
|
||||
GFXTextureFlags flags = GFXTextureFlagBit::NONE;
|
||||
bool isPowerOf2 = false;
|
||||
VkImage vkImage = VK_NULL_HANDLE;
|
||||
VkDeviceMemory vkDeviceMemory = VK_NULL_HANDLE;
|
||||
//GLenum glTarget = 0;
|
||||
//GLenum glInternelFmt = 0;
|
||||
//GLenum glFormat = 0;
|
||||
//GLenum glType = 0;
|
||||
//GLenum glUsage = 0;
|
||||
//GLuint glTexture = 0;
|
||||
//GLenum glWrapS = 0;
|
||||
//GLenum glWrapT = 0;
|
||||
//GLenum glMinFilter = 0;
|
||||
//GLenum glMagFilter = 0;
|
||||
};
|
||||
|
||||
class CCVKGPUTextureView : public Object
|
||||
{
|
||||
public:
|
||||
CCVKGPUTexture* gpuTexture = nullptr;
|
||||
GFXTextureViewType type = GFXTextureViewType::TV2D;
|
||||
GFXFormat format = GFXFormat::UNKNOWN;
|
||||
uint baseLevel = 0;
|
||||
uint levelCount = 1;
|
||||
VkImageView vkImageView = VK_NULL_HANDLE;
|
||||
};
|
||||
|
||||
typedef vector<CCVKGPUTextureView*>::type CCVKGPUTextureViewList;
|
||||
|
||||
class CCVKGPUSampler : public Object {
|
||||
public:
|
||||
GFXFilter minFilter = GFXFilter::NONE;
|
||||
GFXFilter magFilter = GFXFilter::NONE;
|
||||
GFXFilter mipFilter = GFXFilter::NONE;
|
||||
GFXAddress addressU = GFXAddress::CLAMP;
|
||||
GFXAddress addressV = GFXAddress::CLAMP;
|
||||
GFXAddress addressW = GFXAddress::CLAMP;
|
||||
uint minLOD = 0;
|
||||
uint maxLOD = 1000;
|
||||
//GLuint gl_sampler = 0;
|
||||
//GLenum glMinFilter = 0;
|
||||
//GLenum glMagFilter = 0;
|
||||
//GLenum glWrapS = 0;
|
||||
//GLenum glWrapT = 0;
|
||||
//GLenum glWrapR = 0;
|
||||
};
|
||||
|
||||
struct CCVKGPUInput
|
||||
{
|
||||
uint binding = 0;
|
||||
String name;
|
||||
GFXType type = GFXType::UNKNOWN;
|
||||
uint stride = 0;
|
||||
uint count = 0;
|
||||
uint size = 0;
|
||||
//GLenum glType = 0;
|
||||
//GLint glLoc = -1;
|
||||
};
|
||||
typedef vector<CCVKGPUInput>::type CCVKGPUInputList;
|
||||
|
||||
struct CCVKGPUUniform
|
||||
{
|
||||
uint binding = GFX_INVALID_BINDING;
|
||||
String name;
|
||||
GFXType type = GFXType::UNKNOWN;
|
||||
uint stride = 0;
|
||||
uint count = 0;
|
||||
uint size = 0;
|
||||
uint offset = 0;
|
||||
//GLenum glType = 0;
|
||||
//GLint glLoc = -1;
|
||||
};
|
||||
typedef vector<CCVKGPUUniform>::type CCVKGPUUniformList;
|
||||
|
||||
struct CCVKGPUUniformBlock
|
||||
{
|
||||
uint binding = 0;
|
||||
uint idx = 0;
|
||||
String name;
|
||||
uint size = 0;
|
||||
CCVKGPUUniformList glUniforms;
|
||||
CCVKGPUUniformList glActiveUniforms;
|
||||
};
|
||||
typedef vector<CCVKGPUUniformBlock>::type CCVKGPUUniformBlockList;
|
||||
|
||||
struct CCVKGPUUniformSampler
|
||||
{
|
||||
uint binding = 0;
|
||||
String name;
|
||||
GFXType type = GFXType::UNKNOWN;
|
||||
vector<int>::type units;
|
||||
//GLenum glType = 0;
|
||||
//GLint glLoc = -1;
|
||||
};
|
||||
typedef vector<CCVKGPUUniformSampler>::type CCVKGPUUniformSamplerList;
|
||||
|
||||
struct CCVKGPUShaderStage
|
||||
{
|
||||
CCVKGPUShaderStage(GFXShaderType t, String s, GFXShaderMacroList m)
|
||||
: type(t)
|
||||
, source(s)
|
||||
, macros(m)
|
||||
{
|
||||
}
|
||||
GFXShaderType type;
|
||||
String source;
|
||||
GFXShaderMacroList macros;
|
||||
VkShaderModule vkShader = VK_NULL_HANDLE;
|
||||
};
|
||||
typedef vector<CCVKGPUShaderStage>::type CCVKGPUShaderStageList;
|
||||
|
||||
class CCVKGPUShader : public Object
|
||||
{
|
||||
public:
|
||||
String name;
|
||||
GFXUniformBlockList blocks;
|
||||
GFXUniformSamplerList samplers;
|
||||
CCVKGPUShaderStageList gpuStages;
|
||||
CCVKGPUInputList gpuInputs;
|
||||
CCVKGPUUniformBlockList gpuBlocks;
|
||||
CCVKGPUUniformSamplerList gpuSamplers;
|
||||
};
|
||||
|
||||
struct CCVKGPUAttribute
|
||||
{
|
||||
String name;
|
||||
//GLuint glBuffer = 0;
|
||||
//GLenum glType = 0;
|
||||
uint size = 0;
|
||||
uint count = 0;
|
||||
uint stride = 1;
|
||||
uint componentCount = 1;
|
||||
bool isNormalized = false;
|
||||
bool isInstanced = false;
|
||||
uint offset = 0;
|
||||
};
|
||||
typedef vector<CCVKGPUAttribute>::type CCVKGPUAttributeList;
|
||||
|
||||
class CCVKGPUInputAssembler : public Object
|
||||
{
|
||||
public:
|
||||
GFXAttributeList attributes;
|
||||
CCVKGPUBufferList gpuVertexBuffers;
|
||||
CCVKGPUBuffer* gpuIndexBuffer = nullptr;
|
||||
CCVKGPUBuffer* gpuIndirectBuffer = nullptr;
|
||||
vector<VkBuffer>::type vertexBuffers;
|
||||
vector<VkDeviceSize>::type vertexBufferOffsets;
|
||||
};
|
||||
|
||||
class CCVKGPUFramebuffer : public Object
|
||||
{
|
||||
public:
|
||||
CCVKGPURenderPass* gpuRenderPass = nullptr;
|
||||
CCVKGPUTextureViewList gpuColorViews;
|
||||
CCVKGPUTextureView* gpuDepthStencilView = nullptr;
|
||||
VkFramebuffer vkFramebuffer = VK_NULL_HANDLE;
|
||||
bool isOffscreen = false;
|
||||
CCVKGPUSwapchain* swapchain = nullptr;
|
||||
};
|
||||
|
||||
struct CCVKGPUBinding
|
||||
{
|
||||
uint binding = GFX_INVALID_BINDING;
|
||||
GFXBindingType type = GFXBindingType::UNKNOWN;
|
||||
String name;
|
||||
CCVKGPUBuffer* gpuBuffer = nullptr;
|
||||
CCVKGPUTextureView* gpuTexView = nullptr;
|
||||
CCVKGPUSampler* gpuSampler = nullptr;
|
||||
};
|
||||
typedef vector<CCVKGPUBinding>::type CCVKGPUBindingList;
|
||||
|
||||
class CCVKGPUBindingLayout : public Object
|
||||
{
|
||||
public:
|
||||
CCVKGPUBindingList gpuBindings;
|
||||
VkDescriptorSetLayout vkDescriptorSetLayout;
|
||||
};
|
||||
|
||||
class CCVKGPUPipelineLayout : public Object
|
||||
{
|
||||
public:
|
||||
GFXPushConstantRangeList pushConstantRanges;
|
||||
vector<CCVKGPUBindingLayout*>::type gpuBindingLayouts;
|
||||
VkPipelineLayout vkPipelineLayout;
|
||||
};
|
||||
|
||||
class CCVKGPUPipelineState : public Object
|
||||
{
|
||||
public:
|
||||
GFXPrimitiveMode primitive = GFXPrimitiveMode::TRIANGLE_LIST;
|
||||
CCVKGPUShader* gpuShader = nullptr;
|
||||
GFXInputState inputState;
|
||||
GFXRasterizerState rs;
|
||||
GFXDepthStencilState dss;
|
||||
GFXBlendState bs;
|
||||
GFXDynamicStateList dynamicStates;
|
||||
CCVKGPUPipelineLayout* gpuLayout = nullptr;
|
||||
CCVKGPURenderPass* gpuRenderPass = nullptr;
|
||||
VkPipeline vkPipeline = VK_NULL_HANDLE;
|
||||
VkPipelineCache vkPipelineCache = VK_NULL_HANDLE;
|
||||
};
|
||||
|
||||
class CCVKGPUSemaphorePool
|
||||
{
|
||||
public:
|
||||
CCVKGPUSemaphorePool(CCVKGPUDevice* device)
|
||||
: _device(device)
|
||||
{
|
||||
}
|
||||
|
||||
~CCVKGPUSemaphorePool()
|
||||
{
|
||||
for (auto semaphore : _semaphores)
|
||||
{
|
||||
vkDestroySemaphore(_device->vkDevice, semaphore, nullptr);
|
||||
}
|
||||
_semaphores.clear();
|
||||
_count = 0;
|
||||
}
|
||||
|
||||
VkSemaphore alloc()
|
||||
{
|
||||
if (_count < _semaphores.size())
|
||||
{
|
||||
return _semaphores[_count++];
|
||||
}
|
||||
|
||||
VkSemaphore semaphore = VK_NULL_HANDLE;
|
||||
VkSemaphoreCreateInfo createInfo{ VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO };
|
||||
VK_CHECK(vkCreateSemaphore(_device->vkDevice, &createInfo, nullptr, &semaphore));
|
||||
_semaphores.push_back(semaphore);
|
||||
_count++;
|
||||
|
||||
return semaphore;
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
_count = 0;
|
||||
}
|
||||
|
||||
uint size()
|
||||
{
|
||||
return _count;
|
||||
}
|
||||
|
||||
private:
|
||||
CCVKGPUDevice* _device;
|
||||
uint _count = 0;
|
||||
vector<VkSemaphore>::type _semaphores;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,71 @@
|
||||
#include "VKStd.h"
|
||||
#include "VKInputAssembler.h"
|
||||
#include "VKCommands.h"
|
||||
#include "VKBuffer.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
CCVKInputAssembler::CCVKInputAssembler(GFXDevice* device)
|
||||
: GFXInputAssembler(device)
|
||||
{
|
||||
}
|
||||
|
||||
CCVKInputAssembler::~CCVKInputAssembler()
|
||||
{
|
||||
}
|
||||
|
||||
bool CCVKInputAssembler::initialize(const GFXInputAssemblerInfo &info)
|
||||
{
|
||||
_attributes = info.attributes;
|
||||
_vertexBuffers = info.vertexBuffers;
|
||||
_indexBuffer = info.indexBuffer;
|
||||
_indirectBuffer = info.indirectBuffer;
|
||||
|
||||
if (_indexBuffer)
|
||||
{
|
||||
_indexCount = _indexBuffer->getCount();
|
||||
}
|
||||
else if (_vertexBuffers.size())
|
||||
{
|
||||
_vertexCount = _vertexBuffers[0]->getCount();
|
||||
}
|
||||
|
||||
_gpuInputAssembler = CC_NEW(CCVKGPUInputAssembler);
|
||||
_gpuInputAssembler->attributes = _attributes;
|
||||
_gpuInputAssembler->gpuVertexBuffers.resize(_vertexBuffers.size());
|
||||
|
||||
for (size_t i = 0; i < _gpuInputAssembler->gpuVertexBuffers.size(); ++i)
|
||||
{
|
||||
CCVKBuffer* vb = (CCVKBuffer*)_vertexBuffers[i];
|
||||
_gpuInputAssembler->gpuVertexBuffers[i] = vb->gpuBuffer();
|
||||
}
|
||||
|
||||
if (info.indexBuffer)
|
||||
{
|
||||
_gpuInputAssembler->gpuIndexBuffer = static_cast<CCVKBuffer*>(info.indexBuffer)->gpuBuffer();
|
||||
}
|
||||
|
||||
if (info.indirectBuffer)
|
||||
{
|
||||
_gpuInputAssembler->gpuIndirectBuffer = static_cast<CCVKBuffer*>(info.indirectBuffer)->gpuBuffer();
|
||||
}
|
||||
|
||||
CCVKCmdFuncCreateInputAssembler((CCVKDevice*)_device, _gpuInputAssembler);
|
||||
_status = GFXStatus::SUCCESS;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CCVKInputAssembler::destroy()
|
||||
{
|
||||
if (_gpuInputAssembler)
|
||||
{
|
||||
CCVKCmdFuncDestroyInputAssembler((CCVKDevice*)_device, _gpuInputAssembler);
|
||||
CC_DELETE(_gpuInputAssembler);
|
||||
_gpuInputAssembler = nullptr;
|
||||
}
|
||||
|
||||
_status = GFXStatus::UNREADY;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
@@ -0,0 +1,26 @@
|
||||
#ifndef CC_GFXVULKAN_CCVK_INPUT_ASSEMBLER_H_
|
||||
#define CC_GFXVULKAN_CCVK_INPUT_ASSEMBLER_H_
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class CCVKGPUInputAssembler;
|
||||
|
||||
class CC_VULKAN_API CCVKInputAssembler : public GFXInputAssembler
|
||||
{
|
||||
public:
|
||||
CCVKInputAssembler(GFXDevice* device);
|
||||
~CCVKInputAssembler();
|
||||
|
||||
public:
|
||||
bool initialize(const GFXInputAssemblerInfo& info);
|
||||
void destroy();
|
||||
|
||||
CC_INLINE CCVKGPUInputAssembler* gpuInputAssembler() const { return _gpuInputAssembler; }
|
||||
|
||||
private:
|
||||
CCVKGPUInputAssembler* _gpuInputAssembler = nullptr;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,49 @@
|
||||
#include "VKStd.h"
|
||||
#include "VKPipelineLayout.h"
|
||||
#include "VKCommands.h"
|
||||
#include "VKBindingLayout.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
CCVKPipelineLayout::CCVKPipelineLayout(GFXDevice* device)
|
||||
: GFXPipelineLayout(device)
|
||||
{
|
||||
}
|
||||
|
||||
CCVKPipelineLayout::~CCVKPipelineLayout()
|
||||
{
|
||||
}
|
||||
|
||||
bool CCVKPipelineLayout::initialize(const GFXPipelineLayoutInfo &info)
|
||||
{
|
||||
|
||||
_layouts = info.layouts;
|
||||
_pushConstantsRanges = info.pushConstantsRanges;
|
||||
|
||||
_gpuPipelineLayout = CC_NEW(CCVKGPUPipelineLayout);
|
||||
_gpuPipelineLayout->pushConstantRanges = _pushConstantsRanges;
|
||||
uint layoutCount = _layouts.size();
|
||||
_gpuPipelineLayout->gpuBindingLayouts.resize(layoutCount);
|
||||
for (uint i = 0u; i < layoutCount; i++)
|
||||
{
|
||||
_gpuPipelineLayout->gpuBindingLayouts[i] = ((CCVKBindingLayout*)_layouts[i])->gpuBindingLayout();
|
||||
}
|
||||
|
||||
CCVKCmdFuncCreatePipelineLayout((CCVKDevice*)_device, _gpuPipelineLayout);
|
||||
|
||||
_status = GFXStatus::SUCCESS;
|
||||
return true;
|
||||
}
|
||||
|
||||
void CCVKPipelineLayout::destroy()
|
||||
{
|
||||
if (_gpuPipelineLayout)
|
||||
{
|
||||
CCVKCmdFuncDestroyPipelineLayout((CCVKDevice*)_device, _gpuPipelineLayout);
|
||||
CC_DELETE(_gpuPipelineLayout);
|
||||
_gpuPipelineLayout = nullptr;
|
||||
}
|
||||
_status = GFXStatus::UNREADY;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
@@ -0,0 +1,25 @@
|
||||
#ifndef CC_GFXVULKAN_CCVK_PIPELINE_LAYOUT_H_
|
||||
#define CC_GFXVULKAN_CCVK_PIPELINE_LAYOUT_H_
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class CCVKGPUPipelineLayout;
|
||||
|
||||
class CC_VULKAN_API CCVKPipelineLayout : public GFXPipelineLayout
|
||||
{
|
||||
public:
|
||||
CCVKPipelineLayout(GFXDevice* device);
|
||||
~CCVKPipelineLayout();
|
||||
|
||||
public:
|
||||
bool initialize(const GFXPipelineLayoutInfo& info);
|
||||
void destroy();
|
||||
|
||||
CC_INLINE CCVKGPUPipelineLayout* gpuPipelineLayout() const { return _gpuPipelineLayout; }
|
||||
private:
|
||||
CCVKGPUPipelineLayout* _gpuPipelineLayout = nullptr;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,60 @@
|
||||
#include "VKStd.h"
|
||||
#include "VKPipelineState.h"
|
||||
#include "VKCommands.h"
|
||||
#include "VKShader.h"
|
||||
#include "VKRenderPass.h"
|
||||
#include "VKPipelineLayout.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
CCVKPipelineState::CCVKPipelineState(GFXDevice* device)
|
||||
: GFXPipelineState(device)
|
||||
{
|
||||
}
|
||||
|
||||
CCVKPipelineState::~CCVKPipelineState()
|
||||
{
|
||||
}
|
||||
|
||||
bool CCVKPipelineState::initialize(const GFXPipelineStateInfo &info)
|
||||
{
|
||||
_primitive = info.primitive;
|
||||
_shader = info.shader;
|
||||
_inputState = info.inputState;
|
||||
_rasterizerState = info.rasterizerState;
|
||||
_depthStencilState = info.depthStencilState;
|
||||
_blendState = info.blendState;
|
||||
_dynamicStates = info.dynamicStates;
|
||||
_layout = info.layout;
|
||||
_renderPass = info.renderPass;
|
||||
|
||||
_gpuPipelineState = CC_NEW(CCVKGPUPipelineState);
|
||||
_gpuPipelineState->primitive = _primitive;
|
||||
_gpuPipelineState->gpuShader = ((CCVKShader*)_shader)->gpuShader();
|
||||
_gpuPipelineState->inputState = _inputState;
|
||||
_gpuPipelineState->rs = _rasterizerState;
|
||||
_gpuPipelineState->dss = _depthStencilState;
|
||||
_gpuPipelineState->bs = _blendState;
|
||||
_gpuPipelineState->dynamicStates = _dynamicStates;
|
||||
_gpuPipelineState->gpuLayout = ((CCVKPipelineLayout*)_layout)->gpuPipelineLayout();
|
||||
_gpuPipelineState->gpuRenderPass = ((CCVKRenderPass*)_renderPass)->gpuRenderPass();
|
||||
|
||||
CCVKCmdFuncCreatePipelineState((CCVKDevice*)_device, _gpuPipelineState);
|
||||
|
||||
_status = GFXStatus::SUCCESS;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CCVKPipelineState::destroy()
|
||||
{
|
||||
if (_gpuPipelineState)
|
||||
{
|
||||
CCVKCmdFuncDestroyPipelineState((CCVKDevice*)_device, _gpuPipelineState);
|
||||
CC_DELETE(_gpuPipelineState);
|
||||
_gpuPipelineState = nullptr;
|
||||
}
|
||||
_status = GFXStatus::UNREADY;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
@@ -0,0 +1,26 @@
|
||||
#ifndef CC_GFXVULKAN_CCVK_PIPELINE_STATE_H_
|
||||
#define CC_GFXVULKAN_CCVK_PIPELINE_STATE_H_
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class CCVKGPUPipelineState;
|
||||
|
||||
class CC_VULKAN_API CCVKPipelineState : public GFXPipelineState
|
||||
{
|
||||
public:
|
||||
CCVKPipelineState(GFXDevice* device);
|
||||
~CCVKPipelineState();
|
||||
|
||||
public:
|
||||
bool initialize(const GFXPipelineStateInfo& info);
|
||||
void destroy();
|
||||
|
||||
CC_INLINE CCVKGPUPipelineState* gpuPipelineState() const { return _gpuPipelineState; }
|
||||
|
||||
private:
|
||||
CCVKGPUPipelineState* _gpuPipelineState = nullptr;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,72 @@
|
||||
#include "VKStd.h"
|
||||
#include "VKQueue.h"
|
||||
#include "VKDevice.h"
|
||||
#include "VKCommands.h"
|
||||
#include "VKCommandBuffer.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
CCVKQueue::CCVKQueue(GFXDevice* device)
|
||||
: GFXQueue(device)
|
||||
{
|
||||
}
|
||||
|
||||
CCVKQueue::~CCVKQueue()
|
||||
{
|
||||
}
|
||||
|
||||
bool CCVKQueue::initialize(const GFXQueueInfo &info)
|
||||
{
|
||||
_type = info.type;
|
||||
|
||||
_gpuQueue = CC_NEW(CCVKGPUQueue);
|
||||
_gpuQueue->type = _type;
|
||||
CCVKCmdFuncGetDeviceQueue((CCVKDevice*)_device, _gpuQueue);
|
||||
|
||||
_status = GFXStatus::SUCCESS;
|
||||
return true;
|
||||
}
|
||||
|
||||
void CCVKQueue::destroy()
|
||||
{
|
||||
if (_gpuQueue)
|
||||
{
|
||||
_gpuQueue->vkQueue = VK_NULL_HANDLE;
|
||||
CC_DELETE(_gpuQueue);
|
||||
_gpuQueue = nullptr;
|
||||
}
|
||||
_status = GFXStatus::UNREADY;
|
||||
}
|
||||
|
||||
void CCVKQueue::submit(const std::vector<GFXCommandBuffer*>& cmdBuffs)
|
||||
{
|
||||
if (!_isAsync)
|
||||
{
|
||||
_gpuQueue->commandBuffers.clear();
|
||||
uint32_t count = cmdBuffs.size();
|
||||
for (uint32_t i = 0u; i < count; ++i)
|
||||
{
|
||||
CCVKCommandBuffer* cmdBuffer = (CCVKCommandBuffer*)cmdBuffs[i];
|
||||
_gpuQueue->commandBuffers.push(cmdBuffer->_gpuCommandBuffer->vkCommandBuffer);
|
||||
_numDrawCalls += cmdBuffer->_numDrawCalls;
|
||||
_numInstances += cmdBuffer->_numInstances;
|
||||
_numTriangles += cmdBuffer->_numTriangles;
|
||||
}
|
||||
|
||||
VkSubmitInfo submitInfo{ VK_STRUCTURE_TYPE_SUBMIT_INFO };
|
||||
submitInfo.waitSemaphoreCount = 1;
|
||||
submitInfo.pWaitSemaphores = &_gpuQueue->waitSemaphore;
|
||||
submitInfo.pWaitDstStageMask = &_gpuQueue->submitStageMask;
|
||||
submitInfo.commandBufferCount = count;
|
||||
submitInfo.pCommandBuffers = &_gpuQueue->commandBuffers[0];
|
||||
submitInfo.signalSemaphoreCount = 1;
|
||||
submitInfo.pSignalSemaphores = &_gpuQueue->signalSemaphore;
|
||||
|
||||
VK_CHECK(vkQueueSubmit(_gpuQueue->vkQueue, 1, &submitInfo, VK_NULL_HANDLE));
|
||||
|
||||
_gpuQueue->waitSemaphore = _gpuQueue->signalSemaphore;
|
||||
_gpuQueue->signalSemaphore = ((CCVKDevice*)_device)->gpuSemaphorePool()->alloc();
|
||||
}
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
@@ -0,0 +1,33 @@
|
||||
#ifndef CC_GFXVULKAN_CCVK_QUEUE_H_
|
||||
#define CC_GFXVULKAN_CCVK_QUEUE_H_
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class CCVKGPUQueue;
|
||||
|
||||
class CC_VULKAN_API CCVKQueue : public GFXQueue {
|
||||
public:
|
||||
CCVKQueue(GFXDevice* device);
|
||||
~CCVKQueue();
|
||||
|
||||
friend class CCVKDevice;
|
||||
|
||||
public:
|
||||
bool initialize(const GFXQueueInfo& info);
|
||||
void destroy();
|
||||
void submit(const std::vector<GFXCommandBuffer*>& cmd_buffs);
|
||||
|
||||
CC_INLINE bool isAsync() const { return _isAsync; }
|
||||
CC_INLINE CCVKGPUQueue* gpuQueue() const { return _gpuQueue; }
|
||||
|
||||
private:
|
||||
CCVKGPUQueue* _gpuQueue;
|
||||
bool _isAsync = false;
|
||||
uint32_t _numDrawCalls = 0;
|
||||
uint32_t _numInstances = 0;
|
||||
uint32_t _numTriangles = 0;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,45 @@
|
||||
#include "VKStd.h"
|
||||
#include "VKRenderPass.h"
|
||||
#include "VKCommands.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
CCVKRenderPass::CCVKRenderPass(GFXDevice* device)
|
||||
: GFXRenderPass(device)
|
||||
{
|
||||
}
|
||||
|
||||
CCVKRenderPass::~CCVKRenderPass()
|
||||
{
|
||||
}
|
||||
|
||||
bool CCVKRenderPass::initialize(const GFXRenderPassInfo &info)
|
||||
{
|
||||
_colorAttachments = info.colorAttachments;
|
||||
_depthStencilAttachment = info.depthStencilAttachment;
|
||||
_subPasses = info.subPasses;
|
||||
|
||||
_gpuRenderPass = CC_NEW(CCVKGPURenderPass);
|
||||
_gpuRenderPass->colorAttachments = _colorAttachments;
|
||||
_gpuRenderPass->depthStencilAttachment = _depthStencilAttachment;
|
||||
_gpuRenderPass->subPasses = _subPasses;
|
||||
CCVKCmdFuncCreateRenderPass((CCVKDevice*)_device, _gpuRenderPass);
|
||||
|
||||
_status = GFXStatus::SUCCESS;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CCVKRenderPass::destroy()
|
||||
{
|
||||
if (_gpuRenderPass)
|
||||
{
|
||||
CCVKCmdFuncDestroyRenderPass((CCVKDevice*)_device, _gpuRenderPass);
|
||||
CC_DELETE(_gpuRenderPass);
|
||||
_gpuRenderPass = nullptr;
|
||||
}
|
||||
|
||||
_status = GFXStatus::UNREADY;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
@@ -0,0 +1,26 @@
|
||||
#ifndef CC_GFXVULKAN_CCVK_RENDER_PASS_H_
|
||||
#define CC_GFXVULKAN_CCVK_RENDER_PASS_H_
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class CCVKGPURenderPass;
|
||||
|
||||
class CC_VULKAN_API CCVKRenderPass : public GFXRenderPass
|
||||
{
|
||||
public:
|
||||
CCVKRenderPass(GFXDevice* device);
|
||||
~CCVKRenderPass();
|
||||
|
||||
public:
|
||||
bool initialize(const GFXRenderPassInfo& info);
|
||||
void destroy();
|
||||
|
||||
CC_INLINE CCVKGPURenderPass* gpuRenderPass() const { return _gpuRenderPass; }
|
||||
|
||||
private:
|
||||
CCVKGPURenderPass* _gpuRenderPass = nullptr;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,214 @@
|
||||
#ifndef CC_GFXVULKAN_SPIRV_H_
|
||||
#define CC_GFXVULKAN_SPIRV_H_
|
||||
|
||||
#include "SPIRV/GlslangToSpv.h"
|
||||
#include "glslang/public/ShaderLang.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
namespace
|
||||
{
|
||||
EShLanguage getShaderStage(GFXShaderType type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case GFXShaderType::VERTEX: return EShLangVertex;
|
||||
case GFXShaderType::CONTROL: return EShLangTessControl;
|
||||
case GFXShaderType::EVALUATION: return EShLangTessEvaluation;
|
||||
case GFXShaderType::GEOMETRY: return EShLangGeometry;
|
||||
case GFXShaderType::FRAGMENT: return EShLangFragment;
|
||||
case GFXShaderType::COMPUTE: return EShLangCompute;
|
||||
default:
|
||||
{
|
||||
CCASSERT(false, "Unsupported GFXShaderType, convert to EShLanguage failed.");
|
||||
return EShLangVertex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
glslang::EShTargetClientVersion getClientVersion(int vulkanMinorVersion)
|
||||
{
|
||||
switch (vulkanMinorVersion)
|
||||
{
|
||||
case 0: return glslang::EShTargetVulkan_1_0;
|
||||
case 1: return glslang::EShTargetVulkan_1_1;
|
||||
case 2: return glslang::EShTargetVulkan_1_2;
|
||||
default:
|
||||
{
|
||||
CCASSERT(false, "Unsupported vulkan version, convert to EShTargetClientVersion failed.");
|
||||
return glslang::EShTargetVulkan_1_0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
glslang::EShTargetLanguageVersion getTargetVersion(int vulkanMinorVersion)
|
||||
{
|
||||
switch (vulkanMinorVersion)
|
||||
{
|
||||
case 0: return glslang::EShTargetSpv_1_0;
|
||||
case 1: return glslang::EShTargetSpv_1_3;
|
||||
case 2: return glslang::EShTargetSpv_1_5;
|
||||
default:
|
||||
{
|
||||
CCASSERT(false, "Unsupported vulkan version, convert to EShTargetLanguageVersion failed.");
|
||||
return glslang::EShTargetSpv_1_0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool glslangInitialized = false;
|
||||
|
||||
const TBuiltInResource defaultTBuiltInResource{
|
||||
/* .MaxLights = */ 32,
|
||||
/* .MaxClipPlanes = */ 6,
|
||||
/* .MaxTextureUnits = */ 32,
|
||||
/* .MaxTextureCoords = */ 32,
|
||||
/* .MaxVertexAttribs = */ 64,
|
||||
/* .MaxVertexUniformComponents = */ 4096,
|
||||
/* .MaxVaryingFloats = */ 64,
|
||||
/* .MaxVertexTextureImageUnits = */ 32,
|
||||
/* .MaxCombinedTextureImageUnits = */ 80,
|
||||
/* .MaxTextureImageUnits = */ 32,
|
||||
/* .MaxFragmentUniformComponents = */ 4096,
|
||||
/* .MaxDrawBuffers = */ 32,
|
||||
/* .MaxVertexUniformVectors = */ 128,
|
||||
/* .MaxVaryingVectors = */ 8,
|
||||
/* .MaxFragmentUniformVectors = */ 16,
|
||||
/* .MaxVertexOutputVectors = */ 16,
|
||||
/* .MaxFragmentInputVectors = */ 15,
|
||||
/* .MinProgramTexelOffset = */ -8,
|
||||
/* .MaxProgramTexelOffset = */ 7,
|
||||
/* .MaxClipDistances = */ 8,
|
||||
/* .MaxComputeWorkGroupCountX = */ 65535,
|
||||
/* .MaxComputeWorkGroupCountY = */ 65535,
|
||||
/* .MaxComputeWorkGroupCountZ = */ 65535,
|
||||
/* .MaxComputeWorkGroupSizeX = */ 1024,
|
||||
/* .MaxComputeWorkGroupSizeY = */ 1024,
|
||||
/* .MaxComputeWorkGroupSizeZ = */ 64,
|
||||
/* .MaxComputeUniformComponents = */ 1024,
|
||||
/* .MaxComputeTextureImageUnits = */ 16,
|
||||
/* .MaxComputeImageUniforms = */ 8,
|
||||
/* .MaxComputeAtomicCounters = */ 8,
|
||||
/* .MaxComputeAtomicCounterBuffers = */ 1,
|
||||
/* .MaxVaryingComponents = */ 60,
|
||||
/* .MaxVertexOutputComponents = */ 64,
|
||||
/* .MaxGeometryInputComponents = */ 64,
|
||||
/* .MaxGeometryOutputComponents = */ 128,
|
||||
/* .MaxFragmentInputComponents = */ 128,
|
||||
/* .MaxImageUnits = */ 8,
|
||||
/* .MaxCombinedImageUnitsAndFragmentOutputs = */ 8,
|
||||
/* .MaxCombinedShaderOutputResources = */ 8,
|
||||
/* .MaxImageSamples = */ 0,
|
||||
/* .MaxVertexImageUniforms = */ 0,
|
||||
/* .MaxTessControlImageUniforms = */ 0,
|
||||
/* .MaxTessEvaluationImageUniforms = */ 0,
|
||||
/* .MaxGeometryImageUniforms = */ 0,
|
||||
/* .MaxFragmentImageUniforms = */ 8,
|
||||
/* .MaxCombinedImageUniforms = */ 8,
|
||||
/* .MaxGeometryTextureImageUnits = */ 16,
|
||||
/* .MaxGeometryOutputVertices = */ 256,
|
||||
/* .MaxGeometryTotalOutputComponents = */ 1024,
|
||||
/* .MaxGeometryUniformComponents = */ 1024,
|
||||
/* .MaxGeometryVaryingComponents = */ 64,
|
||||
/* .MaxTessControlInputComponents = */ 128,
|
||||
/* .MaxTessControlOutputComponents = */ 128,
|
||||
/* .MaxTessControlTextureImageUnits = */ 16,
|
||||
/* .MaxTessControlUniformComponents = */ 1024,
|
||||
/* .MaxTessControlTotalOutputComponents = */ 4096,
|
||||
/* .MaxTessEvaluationInputComponents = */ 128,
|
||||
/* .MaxTessEvaluationOutputComponents = */ 128,
|
||||
/* .MaxTessEvaluationTextureImageUnits = */ 16,
|
||||
/* .MaxTessEvaluationUniformComponents = */ 1024,
|
||||
/* .MaxTessPatchComponents = */ 120,
|
||||
/* .MaxPatchVertices = */ 32,
|
||||
/* .MaxTessGenLevel = */ 64,
|
||||
/* .MaxViewports = */ 16,
|
||||
/* .MaxVertexAtomicCounters = */ 0,
|
||||
/* .MaxTessControlAtomicCounters = */ 0,
|
||||
/* .MaxTessEvaluationAtomicCounters = */ 0,
|
||||
/* .MaxGeometryAtomicCounters = */ 0,
|
||||
/* .MaxFragmentAtomicCounters = */ 8,
|
||||
/* .MaxCombinedAtomicCounters = */ 8,
|
||||
/* .MaxAtomicCounterBindings = */ 1,
|
||||
/* .MaxVertexAtomicCounterBuffers = */ 0,
|
||||
/* .MaxTessControlAtomicCounterBuffers = */ 0,
|
||||
/* .MaxTessEvaluationAtomicCounterBuffers = */ 0,
|
||||
/* .MaxGeometryAtomicCounterBuffers = */ 0,
|
||||
/* .MaxFragmentAtomicCounterBuffers = */ 1,
|
||||
/* .MaxCombinedAtomicCounterBuffers = */ 1,
|
||||
/* .MaxAtomicCounterBufferSize = */ 16384,
|
||||
/* .MaxTransformFeedbackBuffers = */ 4,
|
||||
/* .MaxTransformFeedbackInterleavedComponents = */ 64,
|
||||
/* .MaxCullDistances = */ 8,
|
||||
/* .MaxCombinedClipAndCullDistances = */ 8,
|
||||
/* .MaxSamples = */ 4,
|
||||
/* .maxMeshOutputVerticesNV = */ 256,
|
||||
/* .maxMeshOutputPrimitivesNV = */ 512,
|
||||
/* .maxMeshWorkGroupSizeX_NV = */ 32,
|
||||
/* .maxMeshWorkGroupSizeY_NV = */ 1,
|
||||
/* .maxMeshWorkGroupSizeZ_NV = */ 1,
|
||||
/* .maxTaskWorkGroupSizeX_NV = */ 32,
|
||||
/* .maxTaskWorkGroupSizeY_NV = */ 1,
|
||||
/* .maxTaskWorkGroupSizeZ_NV = */ 1,
|
||||
/* .maxMeshViewCountNV = */ 4,
|
||||
|
||||
/* .limits = */ {
|
||||
/* .nonInductiveForLoops = */ 1,
|
||||
/* .whileLoops = */ 1,
|
||||
/* .doWhileLoops = */ 1,
|
||||
/* .generalUniformIndexing = */ 1,
|
||||
/* .generalAttributeMatrixVectorIndexing = */ 1,
|
||||
/* .generalVaryingIndexing = */ 1,
|
||||
/* .generalSamplerIndexing = */ 1,
|
||||
/* .generalVariableIndexing = */ 1,
|
||||
/* .generalConstantMatrixVectorIndexing = */ 1,
|
||||
} };
|
||||
|
||||
const std::vector<unsigned int> GLSL2SPIRV(GFXShaderType type, String source, int vulkanMinorVersion = 2)
|
||||
{
|
||||
if (!glslangInitialized)
|
||||
{
|
||||
glslang::InitializeProcess();
|
||||
glslangInitialized = true;
|
||||
}
|
||||
|
||||
auto stage = getShaderStage(type);
|
||||
auto string = source.c_str();
|
||||
glslang::TShader shader(stage);
|
||||
shader.setStrings(&string, 1);
|
||||
|
||||
int clientInputSemanticsVersion = 100 + vulkanMinorVersion * 10;
|
||||
glslang::EShTargetClientVersion clientVersion = getClientVersion(vulkanMinorVersion);
|
||||
glslang::EShTargetLanguageVersion targetVersion = getTargetVersion(vulkanMinorVersion);
|
||||
|
||||
shader.setEnvInput(glslang::EShSourceGlsl, stage, glslang::EShClientVulkan, clientInputSemanticsVersion);
|
||||
shader.setEnvClient(glslang::EShClientVulkan, clientVersion);
|
||||
shader.setEnvTarget(glslang::EShTargetSpv, targetVersion);
|
||||
|
||||
EShMessages messages = (EShMessages)(EShMsgSpvRules | EShMsgVulkanRules);
|
||||
|
||||
if (!shader.parse(&defaultTBuiltInResource, clientInputSemanticsVersion, false, messages))
|
||||
{
|
||||
CC_LOG_ERROR("GLSL Parsing Failed:\n%s\n%s", shader.getInfoLog(), shader.getInfoDebugLog());
|
||||
}
|
||||
|
||||
glslang::TProgram program;
|
||||
program.addShader(&shader);
|
||||
|
||||
if (!program.link(messages))
|
||||
{
|
||||
CC_LOG_ERROR("GLSL Linking Failed:\n%s\n%s", program.getInfoLog(), program.getInfoDebugLog());
|
||||
}
|
||||
|
||||
std::vector<unsigned int> spirv;
|
||||
spv::SpvBuildLogger logger;
|
||||
glslang::SpvOptions spvOptions;
|
||||
glslang::GlslangToSpv(*program.getIntermediate(stage), spirv, &logger, &spvOptions);
|
||||
|
||||
return std::move(spirv);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
NS_CC_END
|
||||
@@ -0,0 +1,55 @@
|
||||
#include "VKStd.h"
|
||||
#include "VKSampler.h"
|
||||
#include "VKCommands.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
CCVKSampler::CCVKSampler(GFXDevice* device)
|
||||
: GFXSampler(device) {
|
||||
}
|
||||
|
||||
CCVKSampler::~CCVKSampler() {
|
||||
}
|
||||
|
||||
bool CCVKSampler::initialize(const GFXSamplerInfo &info) {
|
||||
_name = info.name;
|
||||
_minFilter = info.minFilter;
|
||||
_magFilter = info.magFilter;
|
||||
_mipFilter = info.mipFilter;
|
||||
_addressU = info.addressU;
|
||||
_addressV = info.addressV;
|
||||
_addressW = info.addressW;
|
||||
_maxAnisotropy = info.maxAnisotropy;
|
||||
_cmpFunc = info.cmpFunc;
|
||||
_borderColor = info.borderColor;
|
||||
_minLOD = info.minLOD;
|
||||
_maxLOD = info.maxLOD;
|
||||
_mipLODBias = info.mipLODBias;
|
||||
|
||||
_gpuSampler = CC_NEW(CCVKGPUSampler);
|
||||
_gpuSampler->minFilter = _minFilter;
|
||||
_gpuSampler->magFilter = _magFilter;
|
||||
_gpuSampler->mipFilter = _mipFilter;
|
||||
_gpuSampler->addressU = _addressU;
|
||||
_gpuSampler->addressV = _addressV;
|
||||
_gpuSampler->addressW = _addressW;
|
||||
_gpuSampler->minLOD = _minLOD;
|
||||
_gpuSampler->maxLOD = _maxLOD;
|
||||
|
||||
_status = GFXStatus::SUCCESS;
|
||||
|
||||
CCVKCmdFuncCreateSampler((CCVKDevice*)_device, _gpuSampler);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CCVKSampler::destroy() {
|
||||
if (_gpuSampler) {
|
||||
CCVKCmdFuncDestroySampler((CCVKDevice*)_device, _gpuSampler);
|
||||
CC_DELETE(_gpuSampler);
|
||||
_gpuSampler = nullptr;
|
||||
}
|
||||
_status = GFXStatus::UNREADY;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
@@ -0,0 +1,25 @@
|
||||
#ifndef CC_GFXVULKAN_CCVK_SAMPLER_H_
|
||||
#define CC_GFXVULKAN_CCVK_SAMPLER_H_
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class CCVKGPUSampler;
|
||||
|
||||
class CC_VULKAN_API CCVKSampler : public GFXSampler {
|
||||
public:
|
||||
CCVKSampler(GFXDevice* device);
|
||||
~CCVKSampler();
|
||||
|
||||
public:
|
||||
bool initialize(const GFXSamplerInfo& info);
|
||||
void destroy();
|
||||
|
||||
CC_INLINE CCVKGPUSampler* gpuSampler() const { return _gpuSampler; }
|
||||
|
||||
private:
|
||||
CCVKGPUSampler* _gpuSampler = nullptr;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,52 @@
|
||||
#include "VKStd.h"
|
||||
#include "VKShader.h"
|
||||
#include "VKCommands.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
CCVKShader::CCVKShader(GFXDevice* device)
|
||||
: GFXShader(device)
|
||||
{
|
||||
}
|
||||
|
||||
CCVKShader::~CCVKShader()
|
||||
{
|
||||
}
|
||||
|
||||
bool CCVKShader::initialize(const GFXShaderInfo &info)
|
||||
{
|
||||
_name = info.name;
|
||||
_stages = info.stages;
|
||||
_blocks = info.blocks;
|
||||
_samplers = info.samplers;
|
||||
|
||||
_gpuShader = CC_NEW(CCVKGPUShader);
|
||||
_gpuShader->name = _name;
|
||||
_gpuShader->blocks = _blocks;
|
||||
_gpuShader->samplers = _samplers;
|
||||
for (const auto& stage : _stages)
|
||||
{
|
||||
CCVKGPUShaderStage gpuShaderStage = { stage.type, stage.source, stage.macros };
|
||||
_gpuShader->gpuStages.emplace_back(std::move(gpuShaderStage));
|
||||
}
|
||||
|
||||
CCVKCmdFuncCreateShader((CCVKDevice*)_device, _gpuShader);
|
||||
|
||||
_status = GFXStatus::SUCCESS;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CCVKShader::destroy()
|
||||
{
|
||||
if (_gpuShader)
|
||||
{
|
||||
CCVKCmdFuncDestroyShader((CCVKDevice*)_device, _gpuShader);
|
||||
CC_DELETE(_gpuShader);
|
||||
_gpuShader = nullptr;
|
||||
}
|
||||
|
||||
_status = GFXStatus::UNREADY;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
@@ -0,0 +1,24 @@
|
||||
#ifndef CC_GFXVULKAN_CCVK_SHADER_H_
|
||||
#define CC_GFXVULKAN_CCVK_SHADER_H_
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class CCVKGPUShader;
|
||||
|
||||
class CC_VULKAN_API CCVKShader : public GFXShader {
|
||||
public:
|
||||
CCVKShader(GFXDevice* device);
|
||||
~CCVKShader();
|
||||
|
||||
public:
|
||||
bool initialize(const GFXShaderInfo& info);
|
||||
void destroy();
|
||||
|
||||
CC_INLINE CCVKGPUShader* gpuShader() const { return _gpuShader; }
|
||||
private:
|
||||
CCVKGPUShader* _gpuShader = nullptr;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,34 @@
|
||||
#ifndef CC_GFXVULKAN_STATE_CACHE_H_
|
||||
#define CC_GFXVULKAN_STATE_CACHE_H_
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class CCVKStateCache : public Object {
|
||||
public:
|
||||
//GLuint glArrayBuffer = 0;
|
||||
//GLuint glElementArrayBuffer = 0;
|
||||
//GLuint glUniformBuffer = 0;
|
||||
//GLuint glBindUBOs[GFX_MAX_BUFFER_BINDINGS] = { 0 };
|
||||
//GLuint glVAO = 0;
|
||||
uint texUint = 0;
|
||||
//GLuint glTextures[GFX_MAX_TEXTURE_UNITS] = { 0 };
|
||||
//GLuint glSamplers[GFX_MAX_TEXTURE_UNITS] = { 0 };
|
||||
//GLuint glProgram = 0;
|
||||
bool glEnabledAttribLocs[GFX_MAX_VERTEX_ATTRIBUTES] = { false };
|
||||
bool glCurrentAttribLocs[GFX_MAX_VERTEX_ATTRIBUTES] = { false };
|
||||
//GLuint glFramebuffer = 0;
|
||||
//GLuint glReadFBO = 0;
|
||||
GFXViewport viewport;
|
||||
GFXRect scissor;
|
||||
GFXRasterizerState rs;
|
||||
GFXDepthStencilState dss;
|
||||
GFXBlendState bs;
|
||||
bool isCullFaceEnabled = true;
|
||||
bool isStencilTestEnabled = false;
|
||||
|
||||
CCVKStateCache() {}
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1 @@
|
||||
#include "VKStd.h"
|
||||
@@ -0,0 +1,41 @@
|
||||
#ifndef __CC_GFXVULKAN_VK_STD_H__
|
||||
#define __CC_GFXVULKAN_VK_STD_H__
|
||||
|
||||
#include <Core.h>
|
||||
|
||||
#if (CC_PLATFORM == CC_PLATFORM_WINDOWS)
|
||||
# if defined(CC_STATIC)
|
||||
# define CC_VULKAN_API
|
||||
# else
|
||||
# ifdef CC_VK_EXPORTS
|
||||
# define CC_VULKAN_API __declspec(dllexport)
|
||||
# else
|
||||
# define CC_VULKAN_API __declspec(dllimport)
|
||||
# endif
|
||||
# endif
|
||||
#else
|
||||
# define CC_VULKAN_API
|
||||
#endif
|
||||
|
||||
#define VK_CHECK(x) \
|
||||
do \
|
||||
{ \
|
||||
VkResult err = x; \
|
||||
if (err) \
|
||||
{ \
|
||||
CC_LOG_ERROR("Detected Vulkan error: %d", err); \
|
||||
abort(); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define ASSERT_VK_HANDLE(handle) \
|
||||
do \
|
||||
{ \
|
||||
if ((handle) == VK_NULL_HANDLE) \
|
||||
{ \
|
||||
CC_LOG_ERROR("Handle is NULL"); \
|
||||
abort(); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,158 @@
|
||||
#include "VKStd.h"
|
||||
#include "VKTexture.h"
|
||||
#include "VKCommands.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
CCVKTexture::CCVKTexture(GFXDevice* device)
|
||||
: GFXTexture(device)
|
||||
{
|
||||
}
|
||||
|
||||
CCVKTexture::~CCVKTexture()
|
||||
{
|
||||
}
|
||||
|
||||
bool CCVKTexture::initialize(const GFXTextureInfo &info)
|
||||
{
|
||||
_type = info.type;
|
||||
_usage = info.usage;
|
||||
_format = info.format;
|
||||
_width = info.width;
|
||||
_height = info.height;
|
||||
_depth = info.depth;
|
||||
_arrayLayer = info.arrayLayer;
|
||||
_mipLevel = info.mipLevel;
|
||||
_samples = info.samples;
|
||||
_flags = info.flags;
|
||||
_size = GFXFormatSize(_format, _width, _height, _depth);
|
||||
|
||||
if (_flags & GFXTextureFlags::BAKUP_BUFFER)
|
||||
{
|
||||
_buffer = (uint8_t*)CC_MALLOC(_size);
|
||||
_device->getMemoryStatus().textureSize += _size;
|
||||
}
|
||||
|
||||
_gpuTexture = CC_NEW(CCVKGPUTexture);
|
||||
_gpuTexture->type = _type;
|
||||
|
||||
switch (_type)
|
||||
{
|
||||
case GFXTextureType::TEX1D:
|
||||
{
|
||||
if (_arrayLayer)
|
||||
{
|
||||
_gpuTexture->viewType = _arrayLayer <= 1 ? GFXTextureViewType::TV1D : GFXTextureViewType::TV1D_ARRAY;
|
||||
}
|
||||
else
|
||||
{
|
||||
_gpuTexture->viewType = GFXTextureViewType::TV1D;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case GFXTextureType::TEX2D:
|
||||
{
|
||||
if (_arrayLayer)
|
||||
{
|
||||
if (_arrayLayer <= 1)
|
||||
{
|
||||
_gpuTexture->viewType = GFXTextureViewType::TV2D;
|
||||
}
|
||||
else if (_flags & GFXTextureFlagBit::CUBEMAP)
|
||||
{
|
||||
_gpuTexture->viewType = GFXTextureViewType::CUBE;
|
||||
}
|
||||
else
|
||||
{
|
||||
_gpuTexture->viewType = GFXTextureViewType::TV2D_ARRAY;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_gpuTexture->viewType = GFXTextureViewType::TV2D;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case GFXTextureType::TEX3D:
|
||||
{
|
||||
_gpuTexture->viewType = GFXTextureViewType::TV3D;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
_gpuTexture->viewType = GFXTextureViewType::TV2D;
|
||||
}
|
||||
}
|
||||
|
||||
_gpuTexture->format = _format;
|
||||
_gpuTexture->usage = _usage;
|
||||
_gpuTexture->width = _width;
|
||||
_gpuTexture->height = _height;
|
||||
_gpuTexture->depth = _depth;
|
||||
_gpuTexture->size = _size;
|
||||
_gpuTexture->arrayLayer = _arrayLayer;
|
||||
_gpuTexture->mipLevel = _mipLevel;
|
||||
_gpuTexture->samples = _samples;
|
||||
_gpuTexture->flags = _flags;
|
||||
_gpuTexture->isPowerOf2 = math::IsPowerOfTwo(_width) && math::IsPowerOfTwo(_height);
|
||||
|
||||
CCVKCmdFuncCreateTexture((CCVKDevice*)_device, _gpuTexture);
|
||||
_device->getMemoryStatus().textureSize += _size;
|
||||
_status = GFXStatus::SUCCESS;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CCVKTexture::destroy()
|
||||
{
|
||||
if (_gpuTexture)
|
||||
{
|
||||
CCVKCmdFuncDestroyTexture((CCVKDevice*)_device, _gpuTexture);
|
||||
_device->getMemoryStatus().textureSize -= _size;
|
||||
CC_DELETE(_gpuTexture);
|
||||
_gpuTexture = nullptr;
|
||||
}
|
||||
|
||||
if (_buffer)
|
||||
{
|
||||
CC_FREE(_buffer);
|
||||
_device->getMemoryStatus().textureSize -= _size;
|
||||
_buffer = nullptr;
|
||||
}
|
||||
|
||||
_status = GFXStatus::UNREADY;
|
||||
}
|
||||
|
||||
void CCVKTexture::resize(uint width, uint height)
|
||||
{
|
||||
uint size = GFXFormatSize(_format, width, height, _depth);
|
||||
if (_size != size)
|
||||
{
|
||||
const uint old_size = _size;
|
||||
_width = width;
|
||||
_height = height;
|
||||
_size = size;
|
||||
|
||||
GFXMemoryStatus& status = _device->getMemoryStatus();
|
||||
_gpuTexture->width = _width;
|
||||
_gpuTexture->height = _height;
|
||||
_gpuTexture->size = _size;
|
||||
CCVKCmdFuncResizeTexture((CCVKDevice*)_device, _gpuTexture);
|
||||
status.bufferSize -= old_size;
|
||||
status.bufferSize += _size;
|
||||
|
||||
if (_buffer)
|
||||
{
|
||||
const uint8_t* old_buff = _buffer;
|
||||
_buffer = (uint8_t*)CC_MALLOC(_size);
|
||||
memcpy(_buffer, old_buff, old_size);
|
||||
CC_FREE(_buffer);
|
||||
status.bufferSize -= old_size;
|
||||
status.bufferSize += _size;
|
||||
}
|
||||
}
|
||||
|
||||
_status = GFXStatus::UNREADY;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
@@ -0,0 +1,26 @@
|
||||
#ifndef CC_GFXVULKAN_CCVK_TEXTURE_H_
|
||||
#define CC_GFXVULKAN_CCVK_TEXTURE_H_
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class CCVKGPUTexture;
|
||||
|
||||
class CC_VULKAN_API CCVKTexture : public GFXTexture {
|
||||
public:
|
||||
CCVKTexture(GFXDevice* device);
|
||||
~CCVKTexture();
|
||||
|
||||
public:
|
||||
bool initialize(const GFXTextureInfo& info);
|
||||
void destroy();
|
||||
void resize(uint width, uint height);
|
||||
|
||||
CC_INLINE CCVKGPUTexture* gpuTexture() const { return _gpuTexture; }
|
||||
|
||||
private:
|
||||
CCVKGPUTexture* _gpuTexture = nullptr;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,54 @@
|
||||
#include "VKStd.h"
|
||||
#include "VKTextureView.h"
|
||||
#include "VKTexture.h"
|
||||
#include "VKCommands.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
CCVKTextureView::CCVKTextureView(GFXDevice* device)
|
||||
: GFXTextureView(device)
|
||||
{
|
||||
}
|
||||
|
||||
CCVKTextureView::~CCVKTextureView()
|
||||
{
|
||||
}
|
||||
|
||||
bool CCVKTextureView::initialize(const GFXTextureViewInfo &info)
|
||||
{
|
||||
|
||||
_texture = info.texture;
|
||||
_type = info.type;
|
||||
_format = info.format;
|
||||
_baseLevel = info.baseLevel;
|
||||
_levelCount = info.levelCount;
|
||||
_baseLayer = info.baseLayer;
|
||||
_layerCount = info.layerCount;
|
||||
|
||||
_gpuTexView = CC_NEW(CCVKGPUTextureView);
|
||||
_gpuTexView->gpuTexture = static_cast<CCVKTexture*>(_texture)->gpuTexture();
|
||||
_gpuTexView->type = _type;
|
||||
_gpuTexView->format = _format;
|
||||
_gpuTexView->baseLevel = info.baseLevel;
|
||||
_gpuTexView->levelCount = info.levelCount;
|
||||
|
||||
CCVKCmdFuncCreateTextureView((CCVKDevice*)_device, _gpuTexView);
|
||||
|
||||
_status = GFXStatus::SUCCESS;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CCVKTextureView::destroy()
|
||||
{
|
||||
if (_gpuTexView)
|
||||
{
|
||||
CCVKCmdFuncDestroyTextureView((CCVKDevice*)_device, _gpuTexView);
|
||||
CC_DELETE(_gpuTexView);
|
||||
_gpuTexView = nullptr;
|
||||
}
|
||||
_texture = nullptr;
|
||||
_status = GFXStatus::UNREADY;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
@@ -0,0 +1,25 @@
|
||||
#ifndef CC_GFXVULKAN_CCVK_TEXTURE_VIEW_H_
|
||||
#define CC_GFXVULKAN_CCVK_TEXTURE_VIEW_H_
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class CCVKGPUTextureView;
|
||||
|
||||
class CC_VULKAN_API CCVKTextureView : public GFXTextureView {
|
||||
public:
|
||||
CCVKTextureView(GFXDevice* device);
|
||||
~CCVKTextureView();
|
||||
|
||||
public:
|
||||
bool initialize(const GFXTextureViewInfo& info);
|
||||
void destroy();
|
||||
|
||||
CC_INLINE CCVKGPUTextureView* gpuTexView() const { return _gpuTexView; }
|
||||
|
||||
private:
|
||||
CCVKGPUTextureView* _gpuTexView = nullptr;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,52 @@
|
||||
#ifndef __CC_GFXVULKAN_VK_UTILS_H__
|
||||
#define __CC_GFXVULKAN_VK_UTILS_H__
|
||||
|
||||
#include "volk.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
template <typename T, size_t Size>
|
||||
char(*countof_helper(T(&_Array)[Size]))[Size];
|
||||
|
||||
#define COUNTOF(array) (sizeof(*countof_helper(array)) + 0)
|
||||
|
||||
template <class T>
|
||||
uint32_t toU32(T value)
|
||||
{
|
||||
static_assert(std::is_arithmetic<T>::value, "T must be numeric");
|
||||
|
||||
if (static_cast<uintmax_t>(value) > static_cast<uintmax_t>(std::numeric_limits<uint32_t>::max()))
|
||||
{
|
||||
throw std::runtime_error("to_u32() failed, value is too big to be converted to uint32_t");
|
||||
}
|
||||
|
||||
return static_cast<uint32_t>(value);
|
||||
}
|
||||
|
||||
bool isLayerSupported(const char * required, const std::vector<VkLayerProperties> &available)
|
||||
{
|
||||
for (auto &availableLayer : available)
|
||||
{
|
||||
if (strcmp(availableLayer.layerName, required) == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isExtensionSupported(const char * required, const std::vector<VkExtensionProperties> &available)
|
||||
{
|
||||
for (auto &availableExtension : available)
|
||||
{
|
||||
if (strcmp(availableExtension.extensionName, required) == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,176 @@
|
||||
#include "VKStd.h"
|
||||
#include "VKWindow.h"
|
||||
#include "VKCommands.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
CCVKWindow::CCVKWindow(GFXDevice* device)
|
||||
: GFXWindow(device)
|
||||
{
|
||||
}
|
||||
|
||||
CCVKWindow::~CCVKWindow()
|
||||
{
|
||||
}
|
||||
|
||||
bool CCVKWindow::initialize(const GFXWindowInfo &info)
|
||||
{
|
||||
_title = info.title;
|
||||
_left = info.left;
|
||||
_top = info.top;
|
||||
_width = info.width;
|
||||
_height = info.height;
|
||||
_nativeWidth = _width;
|
||||
_nativeHeight = _height;
|
||||
_colorFmt = info.colorFmt;
|
||||
_depthStencilFmt = info.depthStencilFmt;
|
||||
_isOffscreen = info.isOffscreen;
|
||||
_isFullscreen = info.isFullscreen;
|
||||
|
||||
// Create render pass
|
||||
|
||||
GFXRenderPassInfo renderPassInfo;
|
||||
|
||||
GFXColorAttachment colorAttachment;
|
||||
colorAttachment.format = _colorFmt;
|
||||
colorAttachment.loadOp = GFXLoadOp::CLEAR;
|
||||
colorAttachment.storeOp = GFXStoreOp::STORE;
|
||||
colorAttachment.sampleCount = 1;
|
||||
colorAttachment.beginLayout = GFXTextureLayout::COLOR_ATTACHMENT_OPTIMAL;
|
||||
colorAttachment.endLayout = GFXTextureLayout::PRESENT_SRC;
|
||||
renderPassInfo.colorAttachments.emplace_back(colorAttachment);
|
||||
|
||||
GFXDepthStencilAttachment& depthStencilAttachment = renderPassInfo.depthStencilAttachment;
|
||||
depthStencilAttachment.format = _depthStencilFmt;
|
||||
depthStencilAttachment.depthLoadOp = GFXLoadOp::CLEAR;
|
||||
depthStencilAttachment.depthStoreOp = GFXStoreOp::STORE;
|
||||
depthStencilAttachment.stencilLoadOp = GFXLoadOp::CLEAR;
|
||||
depthStencilAttachment.stencilStoreOp = GFXStoreOp::STORE;
|
||||
depthStencilAttachment.sampleCount = 1;
|
||||
depthStencilAttachment.beginLayout = GFXTextureLayout::DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
|
||||
depthStencilAttachment.endLayout = GFXTextureLayout::PRESENT_SRC;
|
||||
|
||||
_renderPass = _device->createRenderPass(renderPassInfo);
|
||||
|
||||
// Create texture & texture views
|
||||
if (_isOffscreen)
|
||||
{
|
||||
if (_colorFmt != GFXFormat::UNKNOWN)
|
||||
{
|
||||
GFXTextureInfo colorTexInfo;
|
||||
colorTexInfo.type = GFXTextureType::TEX2D;
|
||||
colorTexInfo.usage = GFXTextureUsageBit::COLOR_ATTACHMENT | GFXTextureUsageBit::SAMPLED;
|
||||
colorTexInfo.format = _colorFmt;
|
||||
colorTexInfo.width = _width;
|
||||
colorTexInfo.height = _height;
|
||||
colorTexInfo.depth = 1;
|
||||
colorTexInfo.arrayLayer = 1;
|
||||
colorTexInfo.mipLevel = 1;
|
||||
_colorTex = _device->createTexture(colorTexInfo);
|
||||
|
||||
GFXTextureViewInfo colorTexViewInfo;
|
||||
colorTexViewInfo.texture = _colorTex;
|
||||
colorTexViewInfo.type = GFXTextureViewType::TV2D;
|
||||
colorTexViewInfo.format = _colorFmt;
|
||||
colorTexViewInfo.baseLevel = 0;
|
||||
colorTexViewInfo.levelCount = 1;
|
||||
colorTexViewInfo.baseLayer = 0;
|
||||
colorTexViewInfo.layerCount = 1;
|
||||
_colorTexView = _device->createTextureView(colorTexViewInfo);
|
||||
}
|
||||
if (_depthStencilFmt != GFXFormat::UNKNOWN)
|
||||
{
|
||||
GFXTextureInfo depthStecnilTexInfo;
|
||||
depthStecnilTexInfo.type = GFXTextureType::TEX2D;
|
||||
depthStecnilTexInfo.usage = GFXTextureUsageBit::DEPTH_STENCIL_ATTACHMENT | GFXTextureUsageBit::SAMPLED;
|
||||
depthStecnilTexInfo.format = _depthStencilFmt;
|
||||
depthStecnilTexInfo.width = _width;
|
||||
depthStecnilTexInfo.height = _height;
|
||||
depthStecnilTexInfo.depth = 1;
|
||||
depthStecnilTexInfo.arrayLayer = 1;
|
||||
depthStecnilTexInfo.mipLevel = 1;
|
||||
_depthStencilTex = _device->createTexture(depthStecnilTexInfo);
|
||||
|
||||
GFXTextureViewInfo depthStecnilTexViewInfo;
|
||||
depthStecnilTexViewInfo.texture = _depthStencilTex;
|
||||
depthStecnilTexViewInfo.type = GFXTextureViewType::TV2D;
|
||||
depthStecnilTexViewInfo.format = _colorFmt;
|
||||
depthStecnilTexViewInfo.baseLevel = 0;
|
||||
depthStecnilTexViewInfo.levelCount = 1;
|
||||
depthStecnilTexViewInfo.baseLayer = 0;
|
||||
depthStecnilTexViewInfo.layerCount = 1;
|
||||
_depthStencilTexView = _device->createTextureView(depthStecnilTexViewInfo);
|
||||
}
|
||||
}
|
||||
|
||||
GFXFramebufferInfo fboInfo;
|
||||
fboInfo.renderPass = _renderPass;
|
||||
if (_colorTexView)
|
||||
fboInfo.colorViews.push_back(_colorTexView);
|
||||
fboInfo.depthStencilView = _depthStencilTexView;
|
||||
fboInfo.isOffscreen = _isOffscreen;
|
||||
_framebuffer = _device->createFramebuffer(fboInfo);
|
||||
|
||||
_status = GFXStatus::SUCCESS;
|
||||
return true;
|
||||
}
|
||||
|
||||
void CCVKWindow::destroy()
|
||||
{
|
||||
CC_SAFE_DESTROY(_renderPass);
|
||||
CC_SAFE_DESTROY(_colorTexView);
|
||||
CC_SAFE_DESTROY(_colorTex);
|
||||
CC_SAFE_DESTROY(_depthStencilTexView);
|
||||
CC_SAFE_DESTROY(_depthStencilTex);
|
||||
CC_SAFE_DESTROY(_framebuffer);
|
||||
|
||||
_status = GFXStatus::UNREADY;
|
||||
}
|
||||
|
||||
void CCVKWindow::resize(uint width, uint height)
|
||||
{
|
||||
_width = width;
|
||||
_height = height;
|
||||
|
||||
if (width > _nativeWidth || height > _nativeHeight)
|
||||
{
|
||||
_nativeWidth = width;
|
||||
_nativeHeight = height;
|
||||
|
||||
if (_colorTex)
|
||||
{
|
||||
_colorTex->resize(width, height);
|
||||
_colorTexView->destroy();
|
||||
|
||||
GFXTextureViewInfo colorTexViewInfo;
|
||||
colorTexViewInfo.type = GFXTextureViewType::TV2D;
|
||||
colorTexViewInfo.format = _colorFmt;
|
||||
_colorTexView->initialize(colorTexViewInfo);
|
||||
}
|
||||
|
||||
if (_depthStencilTex)
|
||||
{
|
||||
_depthStencilTex->resize(width, height);
|
||||
_depthStencilTexView->destroy();
|
||||
|
||||
GFXTextureViewInfo depth_stencil_tex_view__info;
|
||||
depth_stencil_tex_view__info.type = GFXTextureViewType::TV2D;
|
||||
depth_stencil_tex_view__info.format = _depthStencilFmt;
|
||||
_depthStencilTexView->initialize(depth_stencil_tex_view__info);
|
||||
}
|
||||
|
||||
if (_framebuffer)
|
||||
{
|
||||
_framebuffer->destroy();
|
||||
|
||||
GFXFramebufferInfo fboInfo;
|
||||
fboInfo.isOffscreen = _isOffscreen;
|
||||
fboInfo.renderPass = _renderPass;
|
||||
fboInfo.colorViews.push_back(_colorTexView);
|
||||
fboInfo.depthStencilView = _depthStencilTexView;
|
||||
_framebuffer->initialize(fboInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
@@ -0,0 +1,20 @@
|
||||
#ifndef CC_GFXVULKAN_CCVK_WINDOW_H_
|
||||
#define CC_GFXVULKAN_CCVK_WINDOW_H_
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class CC_VULKAN_API CCVKWindow : public GFXWindow
|
||||
{
|
||||
public:
|
||||
CCVKWindow(GFXDevice* device);
|
||||
~CCVKWindow();
|
||||
|
||||
public:
|
||||
bool initialize(const GFXWindowInfo& info);
|
||||
void destroy();
|
||||
void resize(uint width, uint height);
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user