266 Commits

Author SHA1 Message Date
6820ee8c74 completed AutoMergeMaterialInstance,test ok. next step is to support texture2d array 2023-09-20 21:53:30 +08:00
ddb5a0b77a use VIL instead of MI in to sort for RenderNode 2023-09-20 18:56:09 +08:00
69646971ce used VIL instead of MI in MaterialRenderList 2023-09-20 17:19:46 +08:00
e71ec4be85 Added few RenderPass::CreatePipeline functions. 2023-09-20 17:15:13 +08:00
dbe2370a44 1.used uvec2/ushort2 in AssignVBO
2.completed first step then merge MI buffer
2023-09-20 15:55:14 +08:00
00d2677066 update RenderAssignBuffer,but can't run. 2023-09-19 22:04:34 +08:00
4208e47534 newly material instance stat,but can't run. 2023-09-19 21:45:54 +08:00
2dedeaad90 layouted codes of VKMaterialInstance.h 2023-09-19 21:45:28 +08:00
083600a95f added mi_max_count in Material 2023-09-19 21:44:48 +08:00
902dc20340 used ActiveMemoryBlockManager to manage data of material instances in Material class. 2023-09-19 21:09:09 +08:00
164498446a fixed crash in RenderAssignBuffer.cpp because not check ubo_mi before use. 2023-09-19 21:07:07 +08:00
cef5ad073b a few update 2023-09-07 18:09:31 +08:00
c2279c553d fixed a spell error in word. 2023-09-06 17:06:12 +08:00
d959e7988d moved few values to VKRenderAssign.h 2023-09-06 16:55:04 +08:00
202bff5870 moved few codes to RenderAssignBuffer.cpp from MaterialRenderList.cpp 2023-09-06 16:24:05 +08:00
8437d8d561 named values and macro about RenderAssignBuffer 2023-09-06 15:57:52 +08:00
714fc3dcb7 use hgl_min in MaterialCreateInfo.cpp 2023-09-05 23:36:59 +08:00
e030738a5f removed old codes of L2W in AssignBuffer 2023-09-05 20:52:55 +08:00
28b2b53d03 renamed to RenderAssignBuffer from RenderExtraBuffer 2023-09-05 20:48:47 +08:00
8bb742f3f4 OK???? 3rd_draw_triangle_use_RenderList run OK!. 2023-09-05 20:19:53 +08:00
6e8932fc2f comments few codes and then start next step. 2023-09-05 10:28:03 +08:00
9661336325 used uint8 color in third_triangle.cpp 2023-08-18 18:39:25 +08:00
ef84e5c699 renamed to RTSwapchain instead of SwapchainRenderTarget 2023-08-17 11:08:21 +08:00
3b106a3b42 updated CMCore, test can Run OK!. 2023-08-15 14:42:08 +08:00
74003df08b updated list/pool/map....,but can't run. 2023-08-14 21:03:20 +08:00
95c67ba857 fixed name of color. 2023-07-29 01:54:01 +08:00
f51c7c6964 optimized Sort() in MaterialRenderList 2023-07-28 20:41:02 +08:00
3fe8d9f90d Merge branch 'new_RenderList' of h 2023-07-28 20:23:46 +08:00
7967150722 upgraded codes and then it can run. 2023-07-28 20:17:46 +08:00
51a6da3d9f update #include, but the codes can't compile. 2023-07-22 12:16:26 +08:00
dd047c1644 added WinVulkan.cpp 2023-07-09 22:32:14 +08:00
df80b1af3b update submodules. 2023-06-21 20:17:12 +08:00
64235b12b6 used AutoDelete<>.Finish() at CreateMaterial. 2023-06-15 16:07:11 +08:00
0557ff2bae added check of brand name 2023-06-14 21:03:30 +08:00
b43d4cc5a3 fixed a bug that error in getting the value of features/properties of vkPhysicalDevice 2023-06-14 20:17:10 +08:00
b72144a28b reordered the creating vkdevice 2023-06-14 19:58:56 +08:00
d05f1109b5 removed MaterialData 2023-06-14 18:20:23 +08:00
3de67f8cf1 updated RenderResource::CreateMaterial 2023-06-14 17:55:06 +08:00
9816592bf6 optimized codes of RenderSource::CreateMaterial 2023-06-14 16:55:22 +08:00
82f3ad070b optimized codes about CreateMaterial 2023-06-14 16:49:19 +08:00
b021b05cb0 renamed values in MaterialCreateInfo::SetMaterialInstance 2023-06-13 18:02:00 +08:00
5749d8ec8a optimized ShaderModuleMapByName in RenderResource 2023-06-12 16:30:16 +08:00
e6560dfe5f renamed values. 2023-06-12 15:45:34 +08:00
8f6260f440 fixed bug at GPUDevice::ChangeTexture2D 2023-06-07 20:25:32 +08:00
18850b0e27 BufferImageCopy supported RectScope2<> 2023-06-07 20:23:13 +08:00
de2926a6d5 standalone GPUDevice::CreateMP 2023-06-06 21:03:13 +08:00
1a8bd0a607 removed GPUDevice::CreateMP(Material *,const DescriptorSetType &) 2023-06-06 20:52:23 +08:00
ffaa6b5362 few about MaterialInstance 2023-06-05 21:39:12 +08:00
9d3ea89861 moved CreateMI to Material from GPUDevice. 2023-06-05 20:17:16 +08:00
7f1532dc6e updated example programs that are second_triangle and third_triangle 2023-06-05 17:10:52 +08:00
01cdb7661b used UTF8String instead of OSString in shader_module_by_name and material_by_name of RenderResource 2023-06-05 17:07:37 +08:00
ab6a8435a1 optimized codes of ShaderCreateInfo::ProcDefine 2023-06-05 17:01:13 +08:00
d17932c7a4 removed source codes about "Load Material file" 2023-06-05 17:00:22 +08:00
f4a8406ad8 support MI_MAX_COUNT in ShaderGen 2023-06-02 20:45:19 +08:00
22bc5f6653 rename params name 2023-06-02 14:23:33 +08:00
fc94ee82b4 layout and renamed value 2023-06-02 14:22:07 +08:00
f8fe0e46d6 added WriteMaterialInstance in RenderExtraBuffer 2023-06-01 21:25:50 +08:00
e076b72f1a splited MaterialRenderList and MaterialRenderMap, RenderExtraBuffer 2023-06-01 15:08:45 +08:00
a04742c347 completed MaterialInstance codes in ShaderGen 2023-06-01 14:47:05 +08:00
1668a0c973 added InitLogger at VulkanAppFramework::Init 2023-06-01 14:46:21 +08:00
e2dd652c3a added few codes about MaterialInstance 2023-05-31 20:14:45 +08:00
a2c3438c58 added main_function value and SetMain function at ShaderCreateInfo class. 2023-05-31 20:14:13 +08:00
5521c53c94 to supported new version of GLSLCompiler.dll 2023-05-31 17:18:14 +08:00
71fd42cfc8 updated VKDeviceCreater.cpp 2023-05-30 17:57:12 +08:00
222ff2961f renamed to AccessVAD from CreateCADA 2023-05-29 21:43:39 +08:00
ed5aac2a9d layout codes. 2023-05-22 21:28:48 +08:00
233523231e Move the ShaderStageBind to the PrimitiveCreate inside, and renamed to PrimitiveVertexBuffer 2023-05-22 21:26:43 +08:00
3523afc6c2 added fourth_triangle.cpp, not ok!!! 2023-05-22 15:29:07 +08:00
6b498d7e91 updated PureColor2D material codes 2023-05-22 14:31:37 +08:00
fa7ecb91ac supported MaterialInstance in ShaderGen module. 2023-05-22 14:30:38 +08:00
d5b719152f removed Material::GetMaterialData() 2023-05-22 14:29:39 +08:00
410a386423 added ShaderDescriptorInfo::AddStruct 2023-05-22 14:29:16 +08:00
641ba4431f changed to UTF8 encode 2023-05-19 22:23:40 +08:00
c485941342 added PureColor2D.cpp 2023-05-19 22:22:55 +08:00
198fe55216 added HandoverMI and GetMI at MFCommon.h 2023-05-19 22:22:30 +08:00
ad7c652cd4 added Interpolation at ShaderCreateInfo 2023-05-19 22:21:49 +08:00
46b6797bce added comments. 2023-05-16 16:56:32 +08:00
c8dbd40333 removed VertexColor2D.h 2023-05-16 15:27:51 +08:00
35844d52bc finished Std2DMaterial and new VertexColor2D, and fixed first_triangle,second_triangle,third_triangle samples. 2023-05-16 15:21:32 +08:00
36d872359e updated README.md 2023-05-16 02:33:19 +08:00
8086fb76f1 fixed a few compile error. 2023-05-16 02:23:45 +08:00
d660691cec added MFGetPosition.h 2023-05-15 22:05:21 +08:00
c5699fd1af 1.splited CoordinateSystem.h, MaterialConfig.h,RenderTargetOutputConfig.h,Material2DConfig.h,StdMaterial.h/.cpp,UBOCommon.h,MFCommon.h
2.adjust namespace.
2023-05-15 21:52:57 +08:00
9316135942 used simply VAT at ShaderCreateInfoVertex.h 2023-05-13 14:59:46 +08:00
8340209697 renamed to JointID/JointWeight instead of BoneID/BoneWeight 2023-05-13 03:14:38 +08:00
aa217c6fc5 added SortedSets<MaterialInstance *> at RenderNode.h/.cpp 2023-05-12 21:37:28 +08:00
d5b69fbe71 removed mi_data from Material 2023-05-12 21:36:52 +08:00
58c62ddb59 renamed two functions that are CreateArrayInUBO and CreateArrayInSSBO 2023-05-12 21:36:17 +08:00
7f3132236f improved MaterialCreateInfo::AddUBO 2023-05-12 20:30:29 +08:00
f8ff6d9cf0 added SBS_MaterialInstance,GetMI at StdMaterial.h 2023-05-12 20:29:27 +08:00
8855f0b880 renamed MaterialID to MaterialInstanceID 2023-05-12 20:28:44 +08:00
254264ac5e moved to .cpp about ChoosePhysicalDevice 2023-05-12 00:32:12 +08:00
9a24aa237d fixed TextureFormat example. 2023-05-12 00:31:20 +08:00
ff184ecd7a added many CreateRenderDevice 2023-05-11 23:40:25 +08:00
81ab733429 added prefer colorspace 2023-05-11 23:33:05 +08:00
05885e443a added VulkanDeviceCreater::ChooseSurfaceFormat 2023-05-11 21:56:07 +08:00
71c543413a fix include 2023-05-11 21:17:06 +08:00
d6d2d337c9 added VKDeviceCreater.h 2023-05-11 21:14:35 +08:00
4ef1283fce added uint8 IndexType 2023-05-11 21:07:26 +08:00
7c4a27771f created VulkanDeviceCreateInfo and added Swapchain prefer formats list. 2023-05-11 00:56:26 +08:00
a97440e1fc renamed to sc_fbo from render_frame 2023-05-11 00:55:44 +08:00
e1cfc1e5b8 created a standalone VKPhysicalDeviceCapsOutput.cpp that from VKDeviceCreater.cpp 2023-05-11 00:54:47 +08:00
2c602e9045 added comments. 2023-05-10 21:58:36 +08:00
f46b1382ee added line_rasterization in VKDevice.h/VKDeviceCreater.cpp 2023-05-10 21:56:32 +08:00
459fb3afc4 added dynamic state check at VKDeviceCreater.cpp 2023-05-10 21:48:26 +08:00
27f33e07cb added "Vulkan hardware requirement" at GPUDevice class. 2023-05-10 21:26:15 +08:00
9c956e1c65 1.added RenderTargetOutputConfig at MaterialCreateInfo.
2.added MaterialInstance's data at MaterialCreateInfo.
2023-05-10 11:26:42 +08:00
004504e027 added comments at VKDeviceMaterial.cpp 2023-05-10 02:32:03 +08:00
7c3d9ecf91 added MIData at Material 2023-05-09 22:03:02 +08:00
3f1b8be5d0 added WIP at MaterialInstance 2023-05-08 22:04:00 +08:00
f3ab0a5608 added AddMaterialID and comments at ShaderCreateInfoVertex.h 2023-05-08 18:24:34 +08:00
8e64816af8 Merge branch 'new_RenderList' of https://github.com/hyzboy/ULRE into new_RenderList 2023-05-08 18:19:15 +08:00
5718b1795f supported material group at MaterialRenderList::Bind 2023-05-08 18:18:34 +08:00
c8cbf020eb updated examples that are first_triangle.cpp and second_triangle.cpp 2023-05-08 09:50:45 +08:00
9535a4486e removed old RenderList 2023-05-07 01:07:26 +08:00
9781e6a9b3 upgraded example/Vulkan/third_triangle.cpp 2023-05-07 00:42:06 +08:00
958183bb29 finished the branch,,,local to world in VertexInputStreaming. 2023-05-06 22:19:50 +08:00
abfc84feff fixed RenderList2D and third_triangle example. 2023-05-06 19:30:08 +08:00
12e64d7ce0 added BindVBO and BindIBO functions at VKCommandBuffer.h/.cpp 2023-05-06 19:29:38 +08:00
34b7937ee2 1.moved IndexBufferData to VK.h from VKPrimitive.h
2.renamed to GetIndexBufferData from GetIndexBuffer of Primitive
2023-05-06 19:28:42 +08:00
2336c7cdf1 optimized names and comment 2023-05-06 10:38:35 +08:00
21201b1695 finished to stat render list,maked buffer list....next step to bind buffer. 2023-05-05 21:12:53 +08:00
2eac17ac61 removed VertexInputDataGroup, Renderable only have basic vertexinputdata 2023-05-05 21:11:39 +08:00
1e03e28f0b updated codes of RenderNode2D/RenderList2D 2023-05-04 22:01:00 +08:00
30c736b7c8 optimized VertexAttribData class 2023-05-04 19:35:09 +08:00
7031270476 VKRenderable and CommandBufferRender supported newly VertexInputLayout 2023-05-04 19:11:18 +08:00
6bdbf87446 PrimitiveCreater supported newly VertexInputLayout 2023-05-04 19:10:22 +08:00
110c141073 ShaderCreateInfoVertex supported VertexInputGroup and VertexInputRate 2023-05-04 19:08:13 +08:00
b9bd4f6c4b renamed a value. 2023-05-02 18:56:55 +08:00
8b0ef244e0 moved VAN to CMSceneGraph from VertexAttribData 2023-04-30 20:42:08 +08:00
c232feb40a temporary to disable the RenderList and RenderNode 2023-04-28 11:10:50 +08:00
db0a8ee256 Created VertexInputData at VKRenderable.h 2023-04-28 11:09:22 +08:00
b26e25df61 newly RenderNode2D/List 2023-04-26 20:52:31 +08:00
cd03ee8211 added RenderNode2D.cpp 2023-04-25 19:18:07 +08:00
48b5479ade first RenderList2D 2023-04-25 18:08:26 +08:00
1ec88c65f8 added comment about memory property in VKDeviceBuffer.cpp 2023-04-25 15:21:23 +08:00
ba6af7a596 renamed to DynamicBufferAccess instead of UBODynamicAccess 2023-04-25 11:43:15 +08:00
d163f914c7 1.added GetRangeSize at VKArrayBuffer
2.renamed to align_size instead of unit_size
2023-04-25 11:36:50 +08:00
0e589e8bcd removed PerObject of DescriptorSetType 2023-04-21 20:27:28 +08:00
011fbdb55d update codes...but can't compile 2023-04-20 21:49:48 +08:00
e488b4c3d3 added half codes. 2023-03-29 21:34:50 +08:00
49f37447d0 added comment at RenderList2D 2023-03-29 21:19:06 +08:00
f280068d50 renamed to InlineDescriptor instead of GlobalDescriptor 2023-03-29 17:27:05 +08:00
137248a274 add lost #include 2023-03-29 16:45:57 +08:00
ec45b977d1 added DescriptorSetType values in AddUBO of MaterialCreateInfo 2023-03-29 16:45:37 +08:00
38f9a2896f optimized codes of VKArrayBuffer 2023-03-29 11:45:15 +08:00
59b02bcb8c optimized VKArrayBuffer 2023-03-28 22:24:22 +08:00
05e96c58ba added VKUBODynamic.h and support from VKArrayBuffer.h 2023-03-28 21:52:08 +08:00
cb09767151 optimized DescriptorBinding::Bind 2023-03-27 12:01:33 +08:00
554220699f added newly functions at MaterialParameters that used index instead of name 2023-03-27 12:00:53 +08:00
3937206fcb upgraded DescriptorBinding 2023-03-27 10:22:55 +08:00
88f23d9a07 Merge branch 'master' of https://github.com/hyzboy/ULRE 2023-03-26 00:04:50 +08:00
15324d9c86 layout codes. 2023-03-26 00:04:31 +08:00
6c3e674d23 used DescriptorBinding in Global Binding 2023-03-25 23:12:08 +08:00
fefdc19674 added GetBindingMap at MaterialDescriptorManager and MaterialParameters 2023-03-25 23:11:43 +08:00
18a4212935 Merge branch 'master' of https://github.com/hyzboy/ULRE 2023-03-25 15:48:09 +08:00
0457d28577 fixed lost of #include 2023-03-25 15:47:08 +08:00
fd39d08fda Update README.md 2023-03-24 22:43:04 +08:00
8e52595123 standalone RenderList2D 2023-03-24 22:14:43 +08:00
19a20411d8 supported SSBAlign in ArrayBuffer 2023-03-24 22:14:05 +08:00
8363275b36 moved codes to .cpp from VKArrayBuffer.h 2023-03-24 20:39:02 +08:00
939bbfeb1f splite RenderNode2D/3D,RenderList2D/3D 2023-03-23 21:43:10 +08:00
f555c77a83 not run. 2023-03-22 21:40:49 +08:00
160ba000d3 want to split RenderList2D/3D 2023-03-22 21:19:23 +08:00
5f830b8d57 changed GPUArrayBuffer to non-template 2023-03-22 21:18:46 +08:00
5d9aab7dda used RenderablePrimitiveCreater and ZeroToOne coordinate system at third_triangle.cpp 2023-03-22 19:41:06 +08:00
cde2d9f86b used AutoDelete<MaterialCreateInfo> instead of delete operator. 2023-03-22 19:39:53 +08:00
d26eb482e7 used DESCRIPTOR_SET_TYPE_COUNT instead of "int(DescriptorSetType::RANGE_SIZE)" 2023-03-22 19:39:03 +08:00
eb8e0a921b used DESCRIPTOR_SET_TYPE_COUNT instead of "(size_t)DescriptorSetType::RANGE_SIZE" 2023-03-22 19:37:48 +08:00
9fd13680d1 used RenderablePrimitiveCreater in second_triangle.cpp 2023-03-22 18:15:45 +08:00
8af96ed4a5 added a test that it's zero2one coordinate system at second_triangle.cpp 2023-03-22 17:56:36 +08:00
57b480754c renamed name of example project 2023-03-22 16:09:11 +08:00
ac42dcdb26 finished auto bound GlobalDescriptor 2023-03-22 15:58:59 +08:00
e1c3b95de7 next work: support 3-way coordinate system in VertexColor2D material. 2023-03-22 02:41:19 +08:00
ee061e4a1a Bind ViewportInfo to Global in VulkanAppFramework 2023-03-22 02:40:26 +08:00
f2c6c24ddf added BindGlobalDescriptor at RenderResource 2023-03-22 02:35:37 +08:00
76f5dcb884 1.added GetDescriptorCount at MaterialParameters
2.renamed to GetBoundCount from GetCount
2023-03-22 02:35:05 +08:00
157c09eff0 added GetBindCount at MaterialDescriptorManager 2023-03-22 02:31:39 +08:00
9f8e63788d used 2d array at binding_map of MaterialDescriptorManager 2023-03-21 22:28:01 +08:00
a7c761e1c5 renamed value. 2023-03-21 21:46:16 +08:00
44620abc21 added SetGlobal/GetGlobal/Free at RenderResource 2023-03-21 21:37:03 +08:00
8bf1ad2a46 added a standard material that it's VertexColor2DNDC. 2023-03-21 21:01:16 +08:00
d26cae0086 removed shadergen namespace 2023-03-21 18:05:48 +08:00
bc9fc9b50f fixed a bug that it don't Add(mtl) at RenderResource::CreateMaterial(MaterialCreateInfo *) 2023-03-21 18:05:27 +08:00
fb4c8ed8c2 removed SPVParseData 2023-03-21 18:04:26 +08:00
0dae30fa06 updated first_triangle.cpp 2023-03-21 14:37:51 +08:00
48b5a978b8 added a newly RenderResource::CreateMaterialInstance(MaterialCreateInfo *,...) 2023-03-21 14:36:48 +08:00
694add27ae first tested ok that AutoMaterial in first_triangle example. 2023-03-21 14:17:33 +08:00
251bbd2705 added "all_dslb=nullptr" at construct function of MaterialDescriptorManager. 2023-03-21 14:16:48 +08:00
3bfc31b57f added a safe check at ~PipelineLayoutData() 2023-03-21 14:15:58 +08:00
8c8a218a3a added GetCount() at MaterialDescriptorInfo class. 2023-03-21 14:15:33 +08:00
9302cbc3ef finished write codes of CreateMaterial from MaterialCreateInfo 2023-03-20 22:09:37 +08:00
696d3259aa renamed to ChangeOrAdd from Update at Map template. 2023-03-20 16:20:32 +08:00
85530e6d57 renamed to MaterialDescriptorManager from MaterialDescriptorSets 2023-03-20 13:55:47 +08:00
81e2aac321 optimized MaterialDescriptorSets 2023-03-20 13:51:25 +08:00
35a282ef5e used DESCRIPTOR_SET_TYPE_COUNT 2023-03-20 13:35:04 +08:00
3a378be660 removed sd_list for MaterialDescriptorSets 2023-03-19 20:41:12 +08:00
aed56a35e0 use GetSPVData/GetSPVSize instead of GetCode/GetCodeSize 2023-03-19 20:23:54 +08:00
09277924f1 comment sd_list_by_set_type array and GetDescriptorList function at MaterialDescriptorSets 2023-03-19 20:18:56 +08:00
c4a4ec5ebc used "uint32_t *" for SPVDATA 2023-03-19 20:18:10 +08:00
703d444cbb added GetInput at ShaderCreateInfoVertex 2023-03-19 20:17:27 +08:00
159c808dad added GetCode/GetCodeSize at ShaderCreateInfo 2023-03-19 20:17:02 +08:00
facdec5556 1.removed VertexShaderModule
2.added VertexInput at MaterialData
3.newly CreateShaderModule/CreateMaterial functions at GPUDevice/RenderResource class.
2023-03-19 19:41:21 +08:00
42f63c5ef1 renamed few values at VKShaderModule 2023-03-19 13:37:55 +08:00
5f4dd09f92 updated ShaderStage 2023-03-18 21:07:21 +08:00
9872f74160 used short funcname. 2023-03-18 17:58:57 +08:00
529d6b7939 used newly ShaderAttributeArray 2023-03-17 21:06:05 +08:00
f748301787 split standalone VKUUID.h/DebugOutProperties.h 2023-03-17 18:15:55 +08:00
165f9d2a5f rename and layout. 2023-03-17 16:21:12 +08:00
4de8139936 reanmed to ShaderAttribute instead of ShaderStage 2023-03-17 16:06:11 +08:00
9ee5f0adaa renamed files of shadergen 2023-03-17 10:14:07 +08:00
555e8fc066 renamed many source of ShaderGen 2023-03-17 10:08:41 +08:00
f564f55e7b added StandardMaterial 2023-03-16 21:54:03 +08:00
31b5bb6d4f added VertexColor2DMaterial at MaterialCreaterTest.cpp 2023-03-15 17:50:33 +08:00
5ba705cd6b updated layout of codes 2023-03-15 14:55:10 +08:00
9cfb88235a fixed a bug that Illegal class copy used 2023-03-15 11:53:13 +08:00
eceaf9ba68 layout codes. 2023-03-15 11:32:38 +08:00
14e7074b3f used ShaderDescriptorManager * instead of ShaderDescriptorManager 2023-03-15 11:09:51 +08:00
f79599b1d4 updated shadergen 2023-03-14 22:22:35 +08:00
2cc0dca050 renamed many values. 2023-03-13 21:58:27 +08:00
ece7fa5f32 writed ProcSubpassInput,ProcStruct,ProcUBO,ProcConst,ProcSampler at ShaderCreater 2023-03-10 02:15:26 +08:00
68b24903bb Added ProcOutput() at ShaderCreaterFragment 2023-03-10 01:47:01 +08:00
6ee832c39f updated ShaderGen->ShaderCreater. 2023-03-09 23:21:52 +08:00
26f7c915c8 update Input/Output 2023-03-08 21:41:57 +08:00
2ac91b80ac added GLSLCompiler.cpp/.h 2023-03-08 14:02:51 +08:00
eed16928e9 optmized layout of shadergen 2023-03-06 21:30:32 +08:00
6b8e76b75f split codes of ShaderGen 2023-03-06 14:06:20 +08:00
ca36b4454b optimized comments 2023-03-04 18:42:25 +08:00
ba65d1abf2 renamed to PerMaterial instead of PerMaterialInstance 2023-03-04 18:21:03 +08:00
ef8f630056 1.define VAT
2.renamed to UBOStruct instead of UBOCodes.
3.moved AddInput/AddOutput to ShaderCreater from VertexShaderCreater
4.moved descriptor object to MDM from SDM
2023-03-04 16:57:50 +08:00
7a0acaf63e 1.moved descriptor to MaterialDescriptorManager from ShaderDescriptorManager.
2.added UBOCodes in MaterialDescriptorManager
2023-03-04 05:11:51 +08:00
d54aff2a42 first added codes of ShaderGen 2023-03-03 23:02:40 +08:00
84d0dc99c8 moved codes of about camera to CameraAppFramework. 2023-03-02 20:33:44 +08:00
b4dccf7814 use standalone DescriptorSetType,ShaderDescriptor,ShaderStage 2023-03-02 20:19:25 +08:00
f2d5209681 used VulkanFormat::BaseType instead of VulkanNumberType 2023-03-01 15:39:20 +08:00
0abe38de98 LoadMaterial use ConstBufferReader 2023-02-23 19:01:01 +08:00
6536b715c3 added comment. 2023-02-23 17:58:08 +08:00
26b907f611 updated CMSceneGraph 2023-02-23 16:14:31 +08:00
99939bd83d optimized CreatePipeline of RenderPass class 2023-02-23 14:43:57 +08:00
844636a46b optimized first_triangle based on RenderablePrimitiveCreater class. 2023-02-23 13:49:18 +08:00
a6b71a449e optimized name of values. 2023-02-23 13:25:05 +08:00
e31a6cca13 commented binding_list of VKMaterialDescriptorSets, because I don't know it's function. 2023-02-23 12:40:23 +08:00
cce2cab12c renamed to PerMaterialInstance instead of PerMaterial 2023-02-23 12:31:42 +08:00
3dbb1c40b7 updated all descript set in RenderList 2023-02-22 21:59:35 +08:00
af4b9cd6d4 renamed to DescriptorSetType instead of DescriptorSetsType 2023-02-22 21:53:51 +08:00
b35ef27610 upgraded to newly DescriptorSetType 2023-02-22 21:50:18 +08:00
95064488db rename and layout codes. 2023-02-21 22:32:03 +08:00
df8156cfe1 support new VILConfig 2023-02-21 18:36:42 +08:00
f990539633 supported half_float and 8bit unorm format at first_triangle example. 2023-02-21 18:35:08 +08:00
2fb443bcb4 updated codes to support newly CM??? modules. 2023-02-19 19:28:47 +08:00
b8a83a25eb use VKDescriptorSet instead of VKDescriptorSets 2023-02-13 11:50:55 +08:00
251d851f65 upgraded codes based on newly CM... library. 2023-02-13 11:48:53 +08:00
8fc83ba9b3 added PipelineCacheCreateInfo struct. 2022-10-28 17:57:09 +08:00
f8646ca880 renamed Semaphore instead of GPUSemaphore,
renamed Queue instead of GPUQueue
2022-10-14 19:40:16 +08:00
fc2c8021ba renamed Fence instead of GPUFence 2022-10-14 19:27:29 +08:00
b980457ba2 renamed DeviceBuffer/DeviceMemory instead of GPUBuffer/GPUMemory, 2022-10-14 17:52:35 +08:00
2e6a8e794f renamed to BaseColor instead Color in VAN. 2022-10-12 16:30:15 +08:00
1bc810d8e9 Update README.md 2022-10-11 19:19:31 +08:00
cd2f278e84 renamed to VertexInputLayout instead of VertexAttributeBinding 2022-10-11 19:16:06 +08:00
bb3b06f168 added Debug log. 2022-09-29 18:29:21 +08:00
cc02b719e6 improved codes of Debug 2022-09-27 19:41:28 +08:00
981a1adf4c Layouted codes of VKPhysicalDevice.h 2022-09-27 10:43:08 +08:00
28e48a0142 added QueueBegin/End/Insert at DebugUtils 2022-09-26 22:06:17 +08:00
a0a5ab5da4 added more type to DeubgMaker/DebugUtils 2022-09-26 17:06:04 +08:00
d98df3ee9c added DebugUtils/DebugMaker test 2022-09-26 16:11:42 +08:00
12760ab5c5 added VKDebugUtils.h/.cpp 2022-09-26 12:14:52 +08:00
206 changed files with 7737 additions and 3191 deletions

2
CMCore

Submodule CMCore updated: 48abdf2a89...072153aa91

2
CMUtil

Submodule CMUtil updated: c3addef6b7...c0990c52eb

View File

@@ -24,6 +24,7 @@ SET(ULRE CMCore
CMSceneGraph
CMUtil
ULRE.Util
ULRE.ShaderGen
ULRE.SceneGraph
${HGL_GLM_LIB}
${RENDER_LIBRARY}

BIN
GLSLCompiler.dll Normal file

Binary file not shown.

View File

@@ -1,21 +1,25 @@
# ULRE
experiment project - Ultra Light Rendering Engine
experiment project - Ultra Lightweight Rendering Engine
ULRE is a project of experimental nature,Used to experiment with various rendering related techniques,And do some examples.
In the future, its compilicated version will be integrated into CMGameEngine.Used to replace the old rendering engine.
Platform: Windows,Linux (WIP: Android)
Platform: Windows,Linux (WIP: Android,macOS,iOS)
Graphics API: Vulkan
Milestone:
On May 6 of 2023, a test was completed, and the entire scene was drawn with only one DrawCall. Although it still has a lot of unfinished work, it is still a very important milestone.
#
ULRE是一个试验性质的工程用于试验各种渲染相关的技术以及做一些范例。在未来它的复杂化版本会被整合到CMGameEngine中用于替代旧的渲染引擎。
平台: Windows,Linux (开发中: Android)
平台: Windows,Linux (开发中: Android,macOS,iOS)
图形API: Vulkan
里程碑:
ULRE是一个试验性质的工程用于试验各种渲染相关的技术以及做一些范例。在未来它的复杂化版本会被整合到CMGameEngine中用于替代旧的渲染引擎
2023年5月6日完成了一个测试只用了一次DrawCall就绘制出了整个场景。虽然它还有很多未完成的工作但它依然是一个非常重要的里程碑

View File

@@ -37,9 +37,9 @@ private:
MaterialInstance * material_instance =nullptr;
Renderable * render_obj =nullptr;
GPUBuffer * ubo_camera_info =nullptr;
GPUBuffer * ubo_color_material =nullptr;
GPUBuffer * ubo_line_config =nullptr;
DeviceBuffer * ubo_camera_info =nullptr;
DeviceBuffer * ubo_color_material =nullptr;
DeviceBuffer * ubo_line_config =nullptr;
Pipeline * pipeline =nullptr;
@@ -62,9 +62,9 @@ private:
return(true);
}
GPUBuffer *CreateUBO(const AnsiString &name,const VkDeviceSize size,void *data)
DeviceBuffer *CreateUBO(const AnsiString &name,const VkDeviceSize size,void *data)
{
GPUBuffer *ubo=db->CreateUBO(size,data);
DeviceBuffer *ubo=db->CreateUBO(size,data);
if(!ubo)
return(nullptr);
@@ -82,7 +82,7 @@ private:
cam.RefreshCameraInfo();
{
MaterialParameters *mp_global=material_instance->GetMP(DescriptorSetsType::Global);
MaterialParameters *mp_global=material_instance->GetMP(DescriptorSetType::Global);
if(!mp_global)
return(false);
@@ -95,7 +95,7 @@ private:
{
MaterialParameters *mp_value=material_instance->GetMP(DescriptorSetsType::Value);
MaterialParameters *mp_value=material_instance->GetMP(DescriptorSetType::Value);
if(!mp_value)
return(false);

View File

@@ -44,8 +44,8 @@ private:
MaterialInstance * material_instance =nullptr;
Renderable * render_obj =nullptr;
GPUBuffer * ubo_camera_info =nullptr;
GPUBuffer * ubo_rb_config =nullptr;
DeviceBuffer * ubo_camera_info =nullptr;
DeviceBuffer * ubo_rb_config =nullptr;
Pipeline * pipeline =nullptr;
@@ -54,15 +54,15 @@ private:
bool InitMaterial()
{
//2D渲染Position坐标全部是使用整数这里强制要求Position输入流使用RGBA16I格式
VABConfigInfo vab_config;
VILConfig vil_config;
VAConfig va_cfg;
va_cfg.format=VF_V4I16;
va_cfg.instance=false;
vab_config.Add("Position",va_cfg);
vil_config.Add("Position",va_cfg);
material_instance=db->CreateMaterialInstance(OS_TEXT("res/material/RoundedBox"),&vab_config);
material_instance=db->CreateMaterialInstance(OS_TEXT("res/material/RoundedBox"),&vil_config);
if(!material_instance)
return(false);
@@ -74,9 +74,9 @@ private:
return(true);
}
GPUBuffer *CreateUBO(const AnsiString &name,const VkDeviceSize size,void *data)
DeviceBuffer *CreateUBO(const AnsiString &name,const VkDeviceSize size,void *data)
{
GPUBuffer *ubo=db->CreateUBO(size,data);
DeviceBuffer *ubo=db->CreateUBO(size,data);
if(!ubo)
return(nullptr);
@@ -94,7 +94,7 @@ private:
cam.RefreshCameraInfo();
{
MaterialParameters *mp_global=material_instance->GetMP(DescriptorSetsType::Global);
MaterialParameters *mp_global=material_instance->GetMP(DescriptorSetType::Global);
if(!mp_global)
return(false);
@@ -108,7 +108,7 @@ private:
}
{
MaterialParameters *mp_value=material_instance->GetMP(DescriptorSetsType::Value);
MaterialParameters *mp_value=material_instance->GetMP(DescriptorSetType::Value);
if(!mp_value)
return(false);

View File

@@ -5,3 +5,16 @@ SET(VULKAN_APP_FRAMEWORK ${CMAKE_CURRENT_SOURCE_DIR}/common/VulkanAppFramework.h
add_subdirectory(Vulkan)
add_subdirectory(2dVector)
add_subdirectory(GUI)
macro(CreateProject name)
add_executable(${name} ${ARGN})
target_link_libraries(${name} ${ULRE})
IF(WIN32)
set_target_properties(${name} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY ${ULRE_RUNTIME_PATH})
ENDIF()
set_property(TARGET ${name} PROPERTY FOLDER "ULRE/Example")
endmacro()
CreateProject(MaterialCreaterTest MaterialCreaterTest.cpp)

View File

@@ -0,0 +1,126 @@
#include<hgl/shadergen/MaterialCreateInfo.h>
using namespace hgl;
using namespace hgl::graph;
using namespace hgl::shadergen;
bool PureColor2DMaterial()
{
MaterialCreateInfo mc("PureColor2D",1,false); //一个新材质1个RT输出默认使用Vertex/Fragment shader
//vertex部分
{
ShaderCreateInfoVertex *vsc=mc.GetVS(); //获取vertex shader creater
//以下代码会被展开为
/*
layout(location=?) in vec3 Position; //位置属性
*/
vsc->AddInput("vec2","Position"); //添加一个vec3类型的position属性输入
vsc->SetShaderCodes(R"(
void main()
{
gl_Position=vec4(Position,0,1);
})");
}
//添加一个名称为ColorMaterial的UBO定义,其内部有一个vec4 color的属性
//该代码会被展开为
/*
struct ColorMaterial
{
vec4 color;
};
*/
mc.AddStruct("ColorMaterial","vec4 color;");
//添加一个UBO该代码会被展开为
/*
layout(set=?,binding=?) uniform ColorMaterial mtl;
*/
mc.AddUBO( VK_SHADER_STAGE_FRAGMENT_BIT, //这个UBO出现在fragment shader
DescriptorSetType::PerMaterial, //它属于材质合集
"ColorMaterial", //UBO名称为ColorMaterial
"mtl"); //UBO变量名称为mtl
//fragment部分
{
ShaderCreateInfoFragment *fsc=mc.GetFS(); //获取fragment shader creater
//以下代码会被展开为
/*
layout(location=?) out vec4 Color; //颜色输出
*/
fsc->AddOutput("vec4","Color"); //添加一个vec4类型的color属性输出
fsc->SetShaderCodes(R"(
void main()
{
Color=mtl.color;
})");
}
mc.CreateShader();
return(true);
}
bool VertexColor2DMaterial()
{
MaterialCreateInfo mc("VertexColor2D",1,false);
//vertex部分
{
ShaderCreateInfoVertex *vsc=mc.GetVS();
vsc->AddInput("vec2","Position");
vsc->AddInput("vec4","Color");
vsc->AddOutput("vec4","Color");
vsc->SetShaderCodes(R"(
void main()
{
Output.Color=Color;
gl_Position=vec4(Position,0,1);
})");
}
//fragment部分
{
ShaderCreateInfoFragment *fsc=mc.GetFS();
fsc->AddOutput("vec4","Color");
fsc->SetShaderCodes(R"(
void main()
{
Color=Input.Color;
})");
}
mc.CreateShader();
return(true);
}
namespace glsl_compiler
{
bool Init();
void Close();
}//namespace glsl_compiler
int main()
{
if(!glsl_compiler::Init())
return -1;
PureColor2DMaterial();
VertexColor2DMaterial();
glsl_compiler::Close();
return 0;
}

View File

@@ -40,10 +40,10 @@ private:
MaterialInstance * material_instance =nullptr;
Pipeline * pipeline_solid =nullptr;
GPUBuffer * ubo_atomsphere =nullptr;
DeviceBuffer * ubo_atomsphere =nullptr;
AtmosphereData atomsphere_data;
Primitive * ro_sphere =nullptr;
Primitive * ro_sphere =nullptr;
private:
@@ -67,7 +67,7 @@ private:
return(false);
{
MaterialParameters *mp=material_instance->GetMP(DescriptorSetsType::Value);
MaterialParameters *mp=material_instance->GetMP(DescriptorSetType::Value);
if(!mp)return(false);
@@ -81,7 +81,7 @@ private:
bool InitScene()
{
ro_sphere=inline_geometry::CreateSphere(db,material_instance->GetVAB(),128);
ro_sphere=inline_geometry::CreateSphere(db,material_instance->GetVIL(),128);
render_root.CreateSubNode(scale(100),db->CreateRenderable(ro_sphere,material_instance,pipeline_solid));

View File

@@ -10,41 +10,43 @@
set_property(TARGET ${name} PROPERTY FOLDER "ULRE/Example/Vulkan/${group}")
endmacro()
CreateProject("Basic" 1st_triangle first_triangle.cpp)
CreateProject("Basic" 2nd_triangle second_triangle.cpp)
CreateProject("Basic" 3rd_triangle third_triangle.cpp)
CreateProject("Basic" FragCoord FragCoordTest.cpp)
CreateProject("Basic" indices_rect indices_rect.cpp)
CreateProject("Basic" FullScreenTriangle FullScreenTriangle.cpp)
CreateProject("Basic" InstanceTriangle InstanceTriangle.cpp)
CreateProject("Basic" 1st_draw_triangle_in_NDC first_triangle.cpp)
CreateProject("Basic" 2nd_draw_triangle_use_UBO second_triangle.cpp)
CreateProject("Basic" 3rd_AutoInstance third_triangle.cpp)
CreateProject("Basic" 4th_AutoMergeMaterialInstance fourth_triangle.cpp)
#CreateProject("Basic" FragCoord FragCoordTest.cpp)
#CreateProject("Basic" indices_rect indices_rect.cpp)
#CreateProject("Basic" FullScreenTriangle FullScreenTriangle.cpp)
#CreateProject("Basic" InstanceTriangle InstanceTriangle.cpp)
CreateProject("Texture" TextureFormat TextureFormat.cpp)
CreateProject("Texture" texture_rect texture_rect.cpp)
#CreateProject("Texture" texture_rect texture_rect.cpp)
#CreateProject("Texture" HQFilterTexture HQFilterTexture.cpp)
#CreateProject(06.Geometry2D Geometry2D.cpp)
CreateProject("Geometry2D" RectanglePrimitive RectanglePrimitive.cpp)
CreateProject("Tile" DrawTile DrawTile.cpp)
CreateProject("Tile" DrawText DrawText.cpp)
#CreateProject("Geometry2D" RectanglePrimitive RectanglePrimitive.cpp)
#CreateProject("Tile" DrawTile DrawTile.cpp)
#CreateProject("Tile" DrawText DrawText.cpp)
CreateProject("Geometry3D " Geometry3D Geometry3D.cpp)
#CreateProject("Geometry3D " Geometry3D Geometry3D.cpp)
CreateProject("Scene" SceneTree SceneTree.cpp)
#CreateProject("Scene" SceneTree SceneTree.cpp)
#CreateProject("Scene" LoadStaticMesh LoadStaticMesh.cpp LoadScene.cpp)
CreateProject("Scene" InlineGeometryScene InlineGeometryScene.cpp)
#CreateProject("Scene" InlineGeometryScene InlineGeometryScene.cpp)
CreateProject("Scene/Sky" SkyColor SkyColor.cpp)
CreateProject("Scene/Sky" Atmosphere Atmosphere.cpp)
#CreateProject("Scene/Sky" SkyColor SkyColor.cpp)
#CreateProject("Scene/Sky" Atmosphere Atmosphere.cpp)
CreateProject("Advanced Rendering" OffscreenRender OffscreenRender.cpp)
#CreateProject("Advanced Rendering" OffscreenRender OffscreenRender.cpp)
#CreateProject(12.PBRBasic PBRBasic.cpp)
#CreateProject(12.Deferred Deferred.cpp)
CreateProject("Advanced Rendering" DeferredRender DeferredRender.cpp)
#CreateProject("Advanced Rendering" DeferredRender DeferredRender.cpp)
#CreateProject(14.AutoMaterial auto_material.cpp)
CreateProject("Texture" Cubemap Cubemap.cpp)
CreateProject("Texture" EquirectangularMap EquirectangularMap.cpp)
CreateProject("Picking" RayPicking RayPicking.cpp)
#CreateProject("Texture" Cubemap Cubemap.cpp)
#CreateProject("Texture" EquirectangularMap EquirectangularMap.cpp)
#CreateProject("Picking" RayPicking RayPicking.cpp)
CreateProject("Landscape" TerrainSimple TerrainSimple.cpp)
#CreateProject("Landscape" TerrainSimple TerrainSimple.cpp)

View File

@@ -35,8 +35,8 @@ private:
Pipeline * sky_pipeline =nullptr;
Pipeline * solid_pipeline =nullptr;
GPUBuffer * ubo_light =nullptr;
GPUBuffer * ubo_phong =nullptr;
DeviceBuffer * ubo_light =nullptr;
DeviceBuffer * ubo_phong =nullptr;
Sampler * sampler =nullptr;
TextureCube * texture =nullptr;
@@ -98,7 +98,7 @@ private:
sky_mi=db->CreateMaterialInstance(sky_material);
if(!sky_mi)return(false);
if(!sky_mi->BindSampler(DescriptorSetsType::Value,"tex" ,texture, sampler))return(false);
if(!sky_mi->BindImageSampler(DescriptorSetType::Value,"tex" ,texture, sampler))return(false);
sky_pipeline=CreatePipeline(sky_mi,InlinePipeline::Sky,Prim::Triangles);
if(!sky_pipeline)return(false);
@@ -111,7 +111,7 @@ private:
envmap_mi=db->CreateMaterialInstance(envmap_material);
if(!envmap_mi)return(false);
if(!envmap_mi->BindSampler(DescriptorSetsType::Value,"EnvCubemap" ,texture, sampler))return(false);
if(!envmap_mi->BindImageSampler(DescriptorSetType::Value,"EnvCubemap" ,texture, sampler))return(false);
solid_pipeline=CreatePipeline(envmap_mi,InlinePipeline::Solid3D,Prim::Triangles);
}
@@ -128,17 +128,17 @@ private:
aci.size=GetCameraInfo().zfar;
ro_axis=CreateAxis(db,axis_mi->GetVAB(),&aci);
ro_axis=CreateAxis(db,axis_mi->GetVIL(),&aci);
}
{
struct CubeCreateInfo cci;
ro_cube=CreateCube(db,sky_mi->GetVAB(),&cci);
ro_cube=CreateCube(db,sky_mi->GetVIL(),&cci);
}
{
ro_sphere=CreateSphere(db,envmap_mi->GetVAB(),64);
ro_sphere=CreateSphere(db,envmap_mi->GetVIL(),64);
}
}

View File

@@ -59,7 +59,7 @@ private:
public:
bool Submit(GPUSemaphore *sem)
bool Submit(Semaphore *sem)
{
return rt->Submit(cmd,sem);
}
@@ -67,7 +67,7 @@ private:
PhongPointLight lights;
GPUBuffer *ubo_lights;
DeviceBuffer *ubo_lights;
struct SubpassParam
{
@@ -80,7 +80,7 @@ private:
SubpassParam sp_gbuffer;
SubpassParam sp_composition;
Primitive *ro_plane,
Primitive *ro_plane,
*ro_cube,
*ro_sphere,
*ro_torus,
@@ -136,6 +136,22 @@ private:
};
gbuffer.sampler=db->CreateSampler(&sci);
#ifdef _DEBUG
{
auto da=device->GetDeviceAttribute();
if(da->debug_maker)
{
da->debug_maker->SetSampler(*(gbuffer.sampler), "[debug maker] GBuffer_Sampler");
}
if(da->debug_utils)
{
da->debug_utils->SetSampler(*(gbuffer.sampler), "[debug utils] GBuffer_Sampler");
}
}
#endif//_DEBUG
}
bool InitGBuffer()
@@ -144,7 +160,7 @@ private:
fbi.SetExtent(SCREEN_WIDTH,SCREEN_HEIGHT);
gbuffer.rt=device->CreateRenderTarget(&fbi);
gbuffer.rt=device->CreateRT(&fbi);
if(!gbuffer.rt)return(false);
@@ -154,6 +170,39 @@ private:
CreateGBufferSampler();
#ifdef _DEBUG
{
auto da=device->GetDeviceAttribute();
VkQueue q=*(gbuffer.rt->GetQueue());
VkFramebuffer fbo= gbuffer.rt->GetFramebuffer()->GetFramebuffer();
VkRenderPass rp= gbuffer.rp->GetVkRenderPass();
VkSemaphore sem=*(gbuffer.rt->GetRenderCompleteSemaphore());
VkCommandBuffer cb=*(gbuffer.cmd);
VkSampler s=*(gbuffer.sampler);
if(da->debug_maker)
{
da->debug_maker->SetQueue( q, "[debug maker] GBufferQueue");
da->debug_maker->SetFramebuffer( fbo,"[debug maker] GBufferFBO");
da->debug_maker->SetRenderPass( rp, "[debug maker] GBufferRenderpass");
da->debug_maker->SetCommandBuffer( cb, "[debug maker] GBufferCommandBuffer");
da->debug_maker->SetSampler( s, "[debug maker] GBufferSampler");
da->debug_maker->SetSemaphore( sem,"[debug maker] GBufferSemaphore");
}
if(da->debug_utils)
{
da->debug_utils->SetQueue( q, "[debug utils] GBufferQueue");
da->debug_utils->SetFramebuffer( fbo,"[debug utils] GBufferFBO");
da->debug_utils->SetRenderPass( rp, "[debug utils] GBufferRenderpass");
da->debug_utils->SetCommandBuffer( cb, "[debug utils] GBufferCommandBuffer");
da->debug_utils->SetSampler( s, "[debug utils] GBufferSampler");
da->debug_utils->SetSemaphore( sem,"[debug utils] GBufferSemaphore");
}
}
#endif//_DEBUG
return(gbuffer.rt);
}
@@ -175,9 +224,28 @@ private:
return(false);
sp->pipeline_fan =gbuffer.rp->CreatePipeline(sp->material_instance,InlinePipeline::Solid3D,Prim::Fan);
if(!sp->pipeline_fan)
return(false);
#ifdef _DEBUG
{
auto da=device->GetDeviceAttribute();
return sp->pipeline_fan;
if(da->debug_maker)
{
da->debug_maker->SetPipeline(*(sp->pipeline_triangles), "[debug maker] GBuffer_Pipeline_Triangles");
da->debug_maker->SetPipeline(*(sp->pipeline_fan), "[debug maker] GBuffer_Pipeline_Fan");
}
if(da->debug_utils)
{
da->debug_utils->SetPipeline(*(sp->pipeline_triangles), "[debug utils] GBuffer_Pipeline_Triangles");
da->debug_utils->SetPipeline(*(sp->pipeline_fan), "[debug utils] GBuffer_Pipeline_Fan");
}
}
#endif//_DEBUG
return(true);
}
bool InitCompositionPipeline(SubpassParam *sp)
@@ -194,7 +262,7 @@ private:
}
Sampler *CreateSampler(Texture *tex)
{
{
VkSamplerCreateInfo sci=
{
VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,
@@ -243,50 +311,50 @@ private:
BindCameraUBO(sp_gbuffer.material_instance);
{
MaterialParameters *mp=sp_gbuffer.material_instance->GetMP(DescriptorSetsType::Value);
MaterialParameters *mp=sp_gbuffer.material_instance->GetMP(DescriptorSetType::Value);
if(!mp)
return(false);
mp->BindSampler("TexColor" ,texture.color, texture.color_sampler);
mp->BindSampler("TexNormal" ,texture.normal, texture.normal_sampler);
mp->BindImageSampler("TexColor" ,texture.color, texture.color_sampler);
mp->BindImageSampler("TexNormal" ,texture.normal, texture.normal_sampler);
mp->Update();
}
BindCameraUBO(sp_composition.material_instance);
{
MaterialParameters *mp=sp_composition.material_instance->GetMP(DescriptorSetsType::Value);
MaterialParameters *mp=sp_composition.material_instance->GetMP(DescriptorSetType::Value);
if(!mp)
return(false);
mp->BindUBO("lights",ubo_lights);
mp->BindSampler("GB_Color" ,gbuffer.rt->GetColorTexture((uint)GBufferAttachment::Color),gbuffer.sampler);
mp->BindSampler("GB_Normal" ,gbuffer.rt->GetColorTexture((uint)GBufferAttachment::Normal),gbuffer.sampler);
mp->BindSampler("GB_Depth" ,gbuffer.rt->GetDepthTexture(),gbuffer.sampler);
mp->BindImageSampler("GB_Color" ,gbuffer.rt->GetColorTexture((uint)GBufferAttachment::Color),gbuffer.sampler);
mp->BindImageSampler("GB_Normal" ,gbuffer.rt->GetColorTexture((uint)GBufferAttachment::Normal),gbuffer.sampler);
mp->BindImageSampler("GB_Depth" ,gbuffer.rt->GetDepthTexture(),gbuffer.sampler);
mp->Update();
}
return(true);
}
void CreateRenderObject(const VAB *vab)
void CreateRenderObject(const VIL *vil)
{
using namespace inline_geometry;
{
struct PlaneCreateInfo pci;
ro_plane=CreatePlane(db,vab,&pci);
ro_plane=CreatePlane(db,vil,&pci);
}
{
struct CubeCreateInfo cci;
ro_cube=CreateCube(db,vab,&cci);
ro_cube=CreateCube(db,vil,&cci);
}
{
ro_sphere=CreateSphere(db,vab,64);
ro_sphere=CreateSphere(db,vil,64);
}
{
@@ -301,7 +369,7 @@ private:
tci.uv_scale.x=4;
tci.uv_scale.y=1;
ro_torus=CreateTorus(db,vab,&tci);
ro_torus=CreateTorus(db,vil,&tci);
}
{
@@ -311,7 +379,7 @@ private:
cci.radius=10;
cci.numberSlices=32;
ro_cylinder=CreateCylinder(db,vab,&cci);
ro_cylinder=CreateCylinder(db,vil,&cci);
}
{
@@ -322,13 +390,13 @@ private:
cci.numberSlices=128;
cci.numberStacks=32;
ro_cone=CreateCone(db,vab,&cci);
ro_cone=CreateCone(db,vil,&cci);
}
}
bool InitCompositionRenderable()
{
ro_gbc_plane=inline_geometry::CreateGBufferCompositionRectangle(db,sp_composition.material_instance->GetVAB());
ro_gbc_plane=inline_geometry::CreateGBufferCompositionRectangle(db,sp_composition.material_instance->GetVIL());
if(!ro_gbc_plane)return(false);
ro_gbc_plane_ri=db->CreateRenderable(ro_gbc_plane,sp_composition.material_instance,sp_composition.pipeline_fan);
@@ -339,7 +407,7 @@ private:
bool InitScene(SubpassParam *sp)
{
CreateRenderObject(sp->material_instance->GetVAB());
CreateRenderObject(sp->material_instance->GetVIL());
render_root.CreateSubNode( scale(100,100,1), db->CreateRenderable(ro_plane ,sp->material_instance,sp->pipeline_fan ));
render_root.CreateSubNode( db->CreateRenderable(ro_torus ,sp->material_instance,sp->pipeline_triangles));
render_root.CreateSubNode( scale(20,20,20), db->CreateRenderable(ro_sphere ,sp->material_instance,sp->pipeline_triangles));
@@ -362,12 +430,14 @@ private:
if(!gbuffer.cmd->BindFramebuffer(gbuffer.rt->GetRenderPass(),gbuffer.rt->GetFramebuffer()))
return(false);
gbuffer.cmd->BeginRegion("GBuffer Begin",Color4f(1,0,0,1));
if(!gbuffer.cmd->BeginRenderPass())
return(false);
render_list->Render(gbuffer.cmd);
gbuffer.cmd->EndRenderPass();
gbuffer.cmd->EndRegion();
gbuffer.cmd->End();
return(true);
@@ -404,13 +474,13 @@ public:
{
const double timer=GetDoubleTime();
// White
lights.position = Vector4f(0.0f, 0.0f, 25.0f, 0.0f);
lights.color = Vector4f(15.0f);
lights.radius = 155.0f;
// White
lights.position = Vector4f(0.0f, 0.0f, 25.0f, 0.0f);
lights.color = Vector4f(15.0f);
lights.radius = 155.0f;
lights.position.x = sin(rad2deg(timer/100)) * 100.0f;
lights.position.y = cos(rad2deg(timer/100)) * 100.0f;
lights.position.x = sin(rad2deg(timer/100)) * 100.0f;
lights.position.y = cos(rad2deg(timer/100)) * 100.0f;
ubo_lights->Write(&lights);
}
@@ -441,8 +511,8 @@ public:
render_root.RefreshMatrix();
render_list->Expend(GetCameraInfo(),&render_root);
CameraAppFramework::Draw();
CameraAppFramework::Draw();
}
};//class TestApp:public CameraAppFramework

View File

@@ -165,7 +165,7 @@ private:
sampler=db->CreateSampler();
if(!material_instance->BindSampler(DescriptorSetsType::Value,"tex",tile_data->GetTexture(),sampler))return(false);
if(!material_instance->BindImageSampler(DescriptorSetType::Value,"tex",tile_data->GetTexture(),sampler))return(false);
return(true);
}

View File

@@ -26,8 +26,8 @@ private:
Pipeline * solid_pipeline =nullptr;
GPUBuffer * ubo_light =nullptr;
GPUBuffer * ubo_phong =nullptr;
DeviceBuffer * ubo_light =nullptr;
DeviceBuffer * ubo_phong =nullptr;
Sampler * sampler =nullptr;
Texture2D * texture =nullptr;
@@ -54,7 +54,7 @@ private:
envmap_mi=db->CreateMaterialInstance(OS_TEXT("res/material/EnvEquirectangularMap"));
if(!envmap_mi)return(false);
if(!envmap_mi->BindSampler(DescriptorSetsType::Value,"Envmap" ,texture, sampler))return(false);
if(!envmap_mi->BindImageSampler(DescriptorSetType::Value,"Envmap" ,texture, sampler))return(false);
}
solid_pipeline=CreatePipeline(envmap_mi,InlinePipeline::Solid3D,Prim::Triangles);
@@ -64,7 +64,7 @@ private:
void CreateRenderObject()
{
ro_sphere=inline_geometry::CreateSphere(db,envmap_mi->GetVAB(),128);
ro_sphere=inline_geometry::CreateSphere(db,envmap_mi->GetVIL(),128);
}
bool InitUBO()

View File

@@ -17,18 +17,18 @@ class TestApp:public CameraAppFramework
{
Color4f color;
GPUBuffer *ubo_color=nullptr;
DeviceBuffer *ubo_color=nullptr;
private:
SceneNode render_root;
RenderList *render_list=nullptr;
SceneNode render_root;
RenderList * render_list =nullptr;
Material * material =nullptr;
MaterialInstance * material_instance =nullptr;
Pipeline * pipeline =nullptr;
Primitive * ro_plane_grid[3];
Primitive * ro_plane_grid[3]{};
private:
@@ -76,18 +76,18 @@ private:
pgci.color.Set(0.5,0,0,1);
pgci.side_color.Set(1,0,0,1);
const VAB *vab=material_instance->GetVAB();
const VIL *vil=material_instance->GetVIL();
ro_plane_grid[0]=CreatePlaneGrid(db,vab,&pgci);
ro_plane_grid[0]=CreatePlaneGrid(db,vil,&pgci);
pgci.color.Set(0,0.5,0,1);
pgci.side_color.Set(0,1,0,1);
ro_plane_grid[1]=CreatePlaneGrid(db,vab,&pgci);
ro_plane_grid[1]=CreatePlaneGrid(db,vil,&pgci);
pgci.color.Set(0,0,0.5,1);
pgci.side_color.Set(0,0,1,1);
ro_plane_grid[2]=CreatePlaneGrid(db,vab,&pgci);
ro_plane_grid[2]=CreatePlaneGrid(db,vil,&pgci);
}
bool InitScene()

View File

@@ -49,8 +49,8 @@ private:
Pipeline * axis_pipeline =nullptr;
Pipeline * pipeline_solid =nullptr;
GPUBuffer * ubo_light =nullptr;
GPUBuffer * ubo_phong =nullptr;
DeviceBuffer * ubo_light =nullptr;
DeviceBuffer * ubo_phong =nullptr;
struct
{
@@ -129,13 +129,13 @@ private:
if(!material_instance)return(false);
{
MaterialParameters *mp_texture=material_instance->GetMP(DescriptorSetsType::Value);
MaterialParameters *mp_texture=material_instance->GetMP(DescriptorSetType::Value);
if(!mp_texture)
return(false);
mp_texture->BindSampler("TexColor" ,texture.color, texture.sampler);
mp_texture->BindSampler("TexNormal" ,texture.normal, texture.sampler);
mp_texture->BindImageSampler("TexColor" ,texture.color, texture.sampler);
mp_texture->BindImageSampler("TexNormal" ,texture.normal, texture.sampler);
}
}
@@ -154,10 +154,10 @@ private:
aci.size=200;
ro_axis=CreateAxis(db,axis_mi->GetVAB(),&aci);
ro_axis=CreateAxis(db,axis_mi->GetVIL(),&aci);
}
const VAB *vab=material_instance->GetVAB();
const VIL *vil=material_instance->GetVIL();
{
struct CubeCreateInfo cci;
@@ -166,11 +166,11 @@ private:
cci.tex_coord=true;
cci.color_type=CubeCreateInfo::ColorType::SameColor;
cci.color[0]=Vector4f(1,1,1,1);
ro_cube=CreateCube(db,vab,&cci);
ro_cube=CreateCube(db,vil,&cci);
}
{
ro_sphere=CreateSphere(db,vab,64);
ro_sphere=CreateSphere(db,vil,64);
}
{
@@ -185,7 +185,7 @@ private:
tci.uv_scale.x=4;
tci.uv_scale.y=1;
ro_torus=CreateTorus(db,vab,&tci);
ro_torus=CreateTorus(db,vil,&tci);
}
{
@@ -195,7 +195,7 @@ private:
cci.radius=10;
cci.numberSlices=32;
ro_cylinder=CreateCylinder(db,vab,&cci);
ro_cylinder=CreateCylinder(db,vil,&cci);
}
{
@@ -206,7 +206,7 @@ private:
cci.numberSlices=128;
cci.numberStacks=32;
ro_cone=CreateCone(db,vab,&cci);
ro_cone=CreateCone(db,vil,&cci);
}
}
@@ -216,7 +216,7 @@ private:
ubo_phong=db->CreateUBO(sizeof(PhongMaterial),&phong);
{
MaterialParameters *mp_value=material_instance->GetMP(DescriptorSetsType::Value);
MaterialParameters *mp_value=material_instance->GetMP(DescriptorSetType::Value);
if(!mp_value)
return(false);

View File

@@ -56,8 +56,8 @@ private:
Primitive *primitive=db->CreatePrimitive(VERTEX_COUNT);
if(!primitive)return(false);
if(!primitive->Set(VAN::Position, db->CreateVBO(VF_V2F,VERTEX_COUNT,position_data)))return(false);
if(!primitive->Set(VAN::Color, db->CreateVBO(VF_V4F,VERTEX_COUNT,color_data)))return(false);
if(!primitive->Set(VAN::Position, db->CreateVBO(VF_V2F,VERTEX_COUNT,position_data )))return(false);
if(!primitive->Set(VAN::Color, db->CreateVBO(VF_V4F,VERTEX_COUNT,color_data )))return(false);
render_obj=db->CreateRenderable(primitive,material_instance,pipeline);
return(true);

View File

@@ -16,7 +16,7 @@ class TestApp:public CameraAppFramework
Camera cam;
MaterialInstance * material_instance =nullptr;
GPUBuffer * ubo_camera_info =nullptr;
DeviceBuffer * ubo_camera_info =nullptr;
};
struct:public RenderObject
@@ -80,7 +80,7 @@ public:
{
FramebufferInfo fbi(UPF_RGBA8,OFFSCREEN_SIZE,OFFSCREEN_SIZE);
os.render_taget=device->CreateRenderTarget(&fbi);
os.render_taget=device->CreateRT(&fbi);
if(!os.render_taget)return(false);
os.command_buffer=device->CreateRenderCommandBuffer();
@@ -107,7 +107,7 @@ public:
cci.center_color=Vector4f(1,1,1,1);
cci.border_color=Vector4f(1,1,1,0);
Primitive *primitive=CreateCircle(db,os.material_instance->GetVAB(),&cci);
Primitive *primitive=CreateCircle(db,os.material_instance->GetVIL(),&cci);
if(!primitive)return(false);
os.renderable=db->CreateRenderable(primitive,os.material_instance,os.pipeline);
@@ -135,7 +135,7 @@ public:
cube.sampler=db->CreateSampler();
if(!cube.sampler)return(false);
if(!cube.material_instance->BindSampler(DescriptorSetsType::Value,"tex",os.render_taget->GetColorTexture(),cube.sampler))
if(!cube.material_instance->BindImageSampler(DescriptorSetType::Value,"tex",os.render_taget->GetColorTexture(),cube.sampler))
return(false);
{
@@ -145,7 +145,7 @@ public:
cci.tex_coord=true;
Primitive *primitive=CreateCube(db,cube.material_instance->GetVAB(),&cci);
Primitive *primitive=CreateCube(db,cube.material_instance->GetVIL(),&cci);
if(!primitive)return(false);
cube.renderable=db->CreateRenderable(primitive,cube.material_instance,cube.pipeline);

View File

@@ -31,7 +31,7 @@ class TestApp:public CameraAppFramework
{
Color4f color;
GPUBuffer *ubo_color=nullptr;
DeviceBuffer *ubo_color=nullptr;
private:
@@ -97,17 +97,17 @@ private:
pgci.color.Set(0.25,0,0,1);
pgci.side_color.Set(1,0,0,1);
const VAB *vab=material_instance->GetVAB();
const VIL *vil=material_instance->GetVIL();
ro_plane_grid=CreatePlaneGrid(db,vab,&pgci);
ro_plane_grid=CreatePlaneGrid(db,vil,&pgci);
}
{
ro_line=db->CreatePrimitive(2);
if(!ro_line)return(false);
if(!ro_line->Set(VAN::Position, vbo_pos=db->CreateVBO(VF_V3F,2,position_data)))return(false);
if(!ro_line->Set(VAN::Color, db->CreateVBO(VF_V4F,2,color_data)))return(false);
if(!ro_line->Set(VAN::Position, vbo_pos=db->CreateVBO(VF_V3F,2,position_data )))return(false);
if(!ro_line->Set(VAN::Color, db->CreateVBO(VF_V4F,2,color_data )))return(false);
}
return(true);

View File

@@ -59,7 +59,7 @@ private:
sampler=db->CreateSampler();
if(!material_instance->BindSampler(DescriptorSetsType::Value,"tex",texture,sampler))return(false);
if(!material_instance->BindImageSampler(DescriptorSetType::Value,"tex",texture,sampler))return(false);
return(true);
}

View File

@@ -33,8 +33,8 @@ private:
Material * material =nullptr;
MaterialInstance * material_instance =nullptr;
GPUBuffer * ubo_color =nullptr;
GPUBuffer * ubo_sun =nullptr;
DeviceBuffer * ubo_color =nullptr;
DeviceBuffer * ubo_sun =nullptr;
Primitive * primitive =nullptr;
@@ -67,7 +67,7 @@ private:
void CreateRenderObject()
{
primitive=inline_geometry::CreateSphere(db,material_instance->GetVAB(),40);
primitive=inline_geometry::CreateSphere(db,material_instance->GetVIL(),40);
}
bool InitUBO()
@@ -84,7 +84,7 @@ private:
if(!ubo_sun)return(false);
{
MaterialParameters *mp=material_instance->GetMP(DescriptorSetsType::Value);
MaterialParameters *mp=material_instance->GetMP(DescriptorSetType::Value);
if(!mp)return(false);

View File

@@ -21,7 +21,7 @@ class TestApp:public CameraAppFramework
{
SkyColorConfig scc;
GPUBuffer *ubo_color=nullptr;
DeviceBuffer *ubo_color=nullptr;
private:
@@ -32,7 +32,7 @@ private:
MaterialInstance * material_instance =nullptr;
Pipeline * pipeline =nullptr;
GPUBuffer * ubo_sky_color =nullptr;
DeviceBuffer * ubo_sky_color =nullptr;
Primitive * ro_skyphere =nullptr;
@@ -71,7 +71,7 @@ private:
if(!ubo_sky_color)
return(false);
if(!material_instance->BindUBO(DescriptorSetsType::Value,"sky_color",ubo_sky_color))
if(!material_instance->BindUBO(DescriptorSetType::Value,"sky_color",ubo_sky_color))
return(false);
return(true);
@@ -88,9 +88,9 @@ private:
void CreateRenderObject()
{
const VAB *vab=material_instance->GetVAB();
const VIL *vil=material_instance->GetVIL();
ro_skyphere=inline_geometry::CreateDome(db,vab,64);
ro_skyphere=inline_geometry::CreateDome(db,vil,64);
}
bool InitScene()

View File

@@ -28,7 +28,7 @@ constexpr uint32_t SCREEN_HEIGHT=720;
/**
* <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
Primitive *CreateRenderableTerrain(RenderResource *db,const VAB *vab,const TerrainCreateInfo *tci)
Primitive *CreateRenderableTerrain(RenderResource *db,const VIL *vil,const TerrainCreateInfo *tci)
{
}
@@ -36,7 +36,7 @@ class TestApp:public CameraAppFramework
{
Color4f color;
GPUBuffer *ubo_color=nullptr;
DeviceBuffer *ubo_color=nullptr;
private:
@@ -95,9 +95,9 @@ private:
pgci.color.Set(0.75,0.75,0.75);
pgci.side_color.Set(1,0,0,1);
const VAB *vab=material_instance->GetVAB();
const VIL *vil=material_instance->GetVIL();
renderable=CreatePlaneGrid(db,vab,&pgci);
renderable=CreatePlaneGrid(db,vil,&pgci);
}
bool InitScene()

View File

@@ -1,4 +1,5 @@
#include<iostream>
#include<iomanip>
#include<hgl/graph/VK.h>
#include<hgl/graph/VKDevice.h>
#include<hgl/graph/VKInstance.h>
@@ -86,35 +87,36 @@ int main(int,char **)
for(uint32_t i=0;i<count;i++)
{
std::cout<<i<<". ";
std::cout<<std::setw(4)<<i<<". ";
std::cout<<" Format [ID:"<<vf->format<<"]["<<vf->name<<"] ";
std::cout<<"Format [ID:"<<std::setw(10)<<vf->format<<"]["<<std::setw(16)<<vf->name<<"]";
if(vf->compress_type!=TextureCompressType::NONE)
std::cout<<"use "<<texture_compress_name[size_t(vf->compress_type)]<<" compress.";
else
std::cout<<vf->bytes<<" bytes/pixel.";
if(vf->depth!=VulkanNumberType::NONE)
std::cout<<"[Depth:"<<data_type_name[size_t(vf->depth)]<<"]";
if(vf->depth!=VulkanBaseType::NONE)
std::cout<<"[ Depth:"<<std::setw(8)<<data_type_name[size_t(vf->depth)]<<"]";
if(vf->stencil!=VulkanNumberType::NONE)
std::cout<<"[Stencil:"<<data_type_name[size_t(vf->stencil)]<<"]";
if(vf->stencil!=VulkanBaseType::NONE)
std::cout<<"[Stencil:"<<std::setw(8)<<data_type_name[size_t(vf->stencil)]<<"]";
if((vf->depth==VulkanNumberType::NONE)
&&(vf->stencil==VulkanNumberType::NONE))
std::cout<<"[Color:"<<data_type_name[size_t(vf->color)]<<"]";
if((vf->depth==VulkanBaseType::NONE)
&&(vf->stencil==VulkanBaseType::NONE))
std::cout<<"[ Color:"<<std::setw(8)<<data_type_name[size_t(vf->color)]<<"]";
{
const VkFormatProperties fp=physical_device->GetFormatProperties(vf->format);
if(fp.optimalTilingFeatures&VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)
std::cout<<"[Optimal]";
if(fp.linearTilingFeatures&VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)
std::cout<<"[Linear]";
if(fp.bufferFeatures&VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)
std::cout<<"[Buffer]";
char olb[]="[ ]";
if(fp.optimalTilingFeatures&VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT )olb[1]='O';
if(fp.linearTilingFeatures&VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT )olb[2]='L';
if(fp.bufferFeatures&VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT )olb[2]='B';
std::cout<<olb;
}
if(vf->compress_type!=TextureCompressType::NONE)
std::cout<<" use "<<texture_compress_name[size_t(vf->compress_type)]<<" compress.";
else
std::cout<<std::setw(4)<<vf->bytes<<" bytes/pixel.";
std::cout<<std::endl;

View File

@@ -3,8 +3,12 @@
#include"VulkanAppFramework.h"
#include<hgl/math/Math.h>
#include<hgl/math/HalfFloat.h>
#include<hgl/filesystem/FileSystem.h>
#include<hgl/graph/SceneInfo.h>
#include<hgl/graph/VKVertexInputConfig.h>
#include<hgl/graph/VKRenderablePrimitiveCreater.h>
#include<hgl/graph/mtl/2d/Material2DCreateConfig.h>
using namespace hgl;
using namespace hgl::graph;
@@ -14,23 +18,55 @@ constexpr uint32_t SCREEN_HEIGHT=720;
constexpr uint32_t VERTEX_COUNT=3;
constexpr float position_data[VERTEX_COUNT][2]=
constexpr float position_data_float[VERTEX_COUNT*2]=
{
{ 0.0, -0.5},
{-0.5, 0.5},
{ 0.5, 0.5}
0.0, -0.5,
-0.5, 0.5,
0.5, 0.5
};
constexpr float color_data[VERTEX_COUNT][4]=
{ {1,0,0,1},
{0,1,0,1},
{0,0,1,1}
#define USE_HALF_FLOAT_POSITION
#ifdef USE_HALF_FLOAT_POSITION
constexpr VkFormat PositionFormat=VF_V2HF;
half_float position_data_hf[VERTEX_COUNT*2];
#define position_data position_data_hf
#else
constexpr VkFormat PositionFormat=VF_V2F;
#define position_data position_data_float
#endif//USE_HALF_FLOAT_POSITION
#define USE_UNORM8_COLOR
#ifdef USE_UNORM8_COLOR
constexpr uint8 color_data[VERTEX_COUNT*4]=
{ 255,0,0,255,
0,255,0,255,
0,0,255,255
};
constexpr VkFormat ColorFormat=VF_V4UN8;
#else
constexpr float color_data[VERTEX_COUNT*4]=
{ 1,0,0,1,
0,1,0,1,
0,0,1,1
};
constexpr VkFormat ColorFormat=VF_V4F;
#endif//USE_UNORM8_COLOR
class TestApp:public VulkanApplicationFramework
{
private:
#if defined(USE_HALF_FLOAT_POSITION)||defined(USE_UNORM8_COLOR)
VILConfig vil_config;
#endif
MaterialInstance * material_instance =nullptr;
Renderable * render_obj =nullptr;
@@ -38,29 +74,52 @@ private:
private:
bool InitMaterial()
void InitVIL()
{
material_instance=db->CreateMaterialInstance(OS_TEXT("res/material/VertexColor2DNDC"));
#ifdef USE_HALF_FLOAT_POSITION
vil_config.Add(VAN::Position,PositionFormat);
#endif//USE_HALF_FLOAT_POSITION
if(!material_instance)
return(false);
#ifdef USE_UNORM8_COLOR
vil_config.Add(VAN::Color,ColorFormat);
#endif//USE_HALF_FLOAT_POSITION
}
bool InitAutoMaterial()
{
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"VertexColor2d");
cfg.coordinate_system=CoordinateSystem2D::NDC;
cfg.local_to_world=false;
AutoDelete<mtl::MaterialCreateInfo> mci=mtl::CreateVertexColor2D(&cfg);
material_instance=db->CreateMaterialInstance(mci,&vil_config);
return material_instance;
}
bool InitPipeline()
{
// pipeline=db->CreatePipeline(material_instance,sc_render_target,OS_TEXT("res/pipeline/solid2d"));
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D,Prim::Triangles); //等同上一行为Framework重载默认使用swapchain的render target
return pipeline;
return pipeline;
}
bool InitVBO()
{
Primitive *primitive=db->CreatePrimitive(VERTEX_COUNT);
if(!primitive)return(false);
RenderablePrimitiveCreater rpc(db,VERTEX_COUNT);
if(!primitive->Set(VAN::Position, db->CreateVBO(VF_V2F,VERTEX_COUNT,position_data)))return(false);
if(!primitive->Set(VAN::Color, db->CreateVBO(VF_V4F,VERTEX_COUNT,color_data)))return(false);
#ifdef USE_HALF_FLOAT_POSITION
Float32toFloat16(position_data_hf,position_data_float,VERTEX_COUNT*2);
#endif//USE_HALF_FLOAT_POSITION
if(!rpc.SetVBO(VAN::Position, PositionFormat, position_data))return(false);
if(!rpc.SetVBO(VAN::Color, ColorFormat, color_data ))return(false);
render_obj=db->CreateRenderable(primitive,material_instance,pipeline);
return(true);
render_obj=rpc.Create(material_instance,pipeline);
return(render_obj);
}
public:
@@ -70,7 +129,12 @@ public:
if(!VulkanApplicationFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
return(false);
if(!InitMaterial())
InitVIL();
if(!InitAutoMaterial())
return(false);
if(!InitPipeline())
return(false);
if(!InitVBO())

View File

@@ -0,0 +1,147 @@
// AutoMergeMaterialInstance
// 该范例主要演示使用一个材质下的不同材质实例传递颜色参数绘制三角形并依赖RenderList中的自动合并功能让同一材质下所有不同材质实例的对象一次渲染完成。
#include"VulkanAppFramework.h"
#include<hgl/math/Math.h>
#include<hgl/filesystem/FileSystem.h>
#include<hgl/graph/VKRenderablePrimitiveCreater.h>
#include<hgl/graph/mtl/2d/Material2DCreateConfig.h>
#include<hgl/graph/RenderList.h>
#include<hgl/color/Color.h>
using namespace hgl;
using namespace hgl::graph;
constexpr uint32_t SCREEN_WIDTH=1024;
constexpr uint32_t SCREEN_HEIGHT=1024;
constexpr uint32_t VERTEX_COUNT=3;
constexpr float position_data[VERTEX_COUNT*2]=
{
0.0, 0.0,
-0.1, 0.9,
0.1, 0.9
};
constexpr uint DRAW_OBJECT_COUNT=12;
class TestApp:public VulkanApplicationFramework
{
private:
SceneNode render_root;
RenderList * render_list =nullptr;
Material * material =nullptr;
struct
{
MaterialInstance * mi;
Renderable * r;
}render_obj[DRAW_OBJECT_COUNT]{};
Pipeline * pipeline =nullptr;
private:
bool InitMaterial()
{
{
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"PureColor2D");
cfg.coordinate_system=CoordinateSystem2D::NDC;
cfg.local_to_world=true;
AutoDelete<mtl::MaterialCreateInfo> mci=mtl::CreatePureColor2D(&cfg);
material=db->CreateMaterial(mci);
if(!material)
return(false);
for(uint i=0;i<DRAW_OBJECT_COUNT;i++)
{
render_obj[i].mi=db->CreateMaterialInstance(material);
if(!render_obj[i].mi)
return(false);
Color4f color=GetColor4f((COLOR)(i+int(COLOR::Blue)),1.0);
render_obj[i].mi->WriteMIData(color,sizeof(Color4f)); //设置MaterialInstance的数据
}
}
pipeline=CreatePipeline(material,InlinePipeline::Solid2D,Prim::Triangles);
return pipeline;
}
bool InitVBO()
{
RenderablePrimitiveCreater rpc(db,VERTEX_COUNT);
if(!rpc.SetVBO(VAN::Position, VF_V2F, position_data))return(false);
for(uint i=0;i<DRAW_OBJECT_COUNT;i++)
{
render_obj[i].r=rpc.Create(render_obj[i].mi,pipeline);
if(!render_obj[i].r)
return(false);
render_root.CreateSubNode(rotate(deg2rad(360/DRAW_OBJECT_COUNT*i),Vector3f(0,0,1)),render_obj[i].r);
}
render_root.RefreshMatrix();
render_list->Expend(&render_root);
return(true);
}
public:
~TestApp()
{
SAFE_CLEAR(render_list);
}
bool Init()
{
if(!VulkanApplicationFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
return(false);
render_list=new RenderList(device);
if(!InitMaterial())
return(false);
if(!InitVBO())
return(false);
BuildCommandBuffer(render_list);
return(true);
}
void Resize(int w,int h)override
{
VulkanApplicationFramework::Resize(w,h);
BuildCommandBuffer(render_list);
}
};//class TestApp:public VulkanApplicationFramework
int main(int,char **)
{
TestApp app;
if(!app.Init())
return(-1);
while(app.Run());
return 0;
}

View File

@@ -1,10 +1,12 @@
// third_triangle
// 该范例主要演示使用2D坐系统直接绘制一个渐变色的三角形
// second_triangle
// 该范例主要演示使用2D坐系统直接绘制一个渐变色的三角形,使用UBO传递Viewport信息
#include"VulkanAppFramework.h"
#include<hgl/math/Math.h>
#include<hgl/filesystem/FileSystem.h>
#include<hgl/graph/SceneInfo.h>
#include<hgl/graph/VKRenderablePrimitiveCreater.h>
#include<hgl/graph/mtl/2d/Material2DCreateConfig.h>
using namespace hgl;
using namespace hgl::graph;
@@ -14,19 +16,22 @@ constexpr uint32_t SCREEN_HEIGHT=720;
constexpr uint32_t VERTEX_COUNT=3;
constexpr float position_data[VERTEX_COUNT][2]=
static float position_data[VERTEX_COUNT][2]=
{
{SCREEN_WIDTH*0.5, SCREEN_HEIGHT*0.25},
{SCREEN_WIDTH*0.75, SCREEN_HEIGHT*0.75},
{SCREEN_WIDTH*0.25, SCREEN_HEIGHT*0.75}
{0.5, 0.25},
{0.75, 0.75},
{0.25, 0.75}
};
constexpr float color_data[VERTEX_COUNT][4]=
{ {1,0,0,1},
{
{1,0,0,1},
{0,1,0,1},
{0,0,1,1}
};
//#define USE_ZERO2ONE_COORD //使用左上角0,0右下角1,1的坐标系
class TestApp:public VulkanApplicationFramework
{
private:
@@ -40,12 +45,24 @@ private:
bool InitMaterial()
{
material_instance=db->CreateMaterialInstance(OS_TEXT("res/material/VertexColor2D"));
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"VertexColor2D");
#ifdef USE_ZERO2ONE_COORD
cfg.coordinate_system=CoordinateSystem2D::ZeroToOne;
#else
cfg.coordinate_system=CoordinateSystem2D::Ortho;
#endif//USE_ZERO2ONE_COORD
cfg.local_to_world=false;
AutoDelete<mtl::MaterialCreateInfo> mci=mtl::CreateVertexColor2D(&cfg);
material_instance=db->CreateMaterialInstance(mci);
if(!material_instance)
return(false);
BindCameraUBO(material_instance);
db->global_descriptor.Bind(material_instance->GetMaterial());
// pipeline=db->CreatePipeline(material_instance,sc_render_target,OS_TEXT("res/pipeline/solid2d"));
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D,Prim::Triangles); //等同上一行为Framework重载默认使用swapchain的render target
@@ -55,13 +72,22 @@ private:
bool InitVBO()
{
Primitive *primitive=db->CreatePrimitive(VERTEX_COUNT);
if(!primitive)return(false);
RenderablePrimitiveCreater rpc(db,VERTEX_COUNT);
if(!primitive->Set(VAN::Position, db->CreateVBO(VF_V2F,VERTEX_COUNT,position_data)))return(false);
if(!primitive->Set(VAN::Color, db->CreateVBO(VF_V4F,VERTEX_COUNT,color_data)))return(false);
#ifndef USE_ZERO2ONE_COORD //使用ortho坐标系
for(uint i=0;i<VERTEX_COUNT;i++)
{
position_data[i][0]*=SCREEN_WIDTH;
position_data[i][1]*=SCREEN_HEIGHT;
}
#endif//USE_ZERO2ONE_COORD
if(!rpc.SetVBO(VAN::Position, VF_V2F, position_data))return(false);
if(!rpc.SetVBO(VAN::Color, VF_V4F, color_data ))return(false);
render_obj=db->CreateRenderable(primitive,material_instance,pipeline);
render_obj=rpc.Create(material_instance,pipeline);
return(true);
}

View File

@@ -50,7 +50,7 @@ private:
Texture2D * texture =nullptr;
Sampler * sampler =nullptr;
MaterialInstance * material_instance =nullptr;
Renderable *renderable =nullptr;
Renderable * renderable =nullptr;
Pipeline * pipeline =nullptr;
private:
@@ -73,7 +73,7 @@ private:
sampler=db->CreateSampler();
if(!material_instance->BindSampler(DescriptorSetsType::Value,"tex",texture,sampler))return(false);
if(!material_instance->BindImageSampler(DescriptorSetType::Value,"tex",texture,sampler))return(false);
return(true);
}

View File

@@ -1,29 +1,33 @@
// second_triangle
// 该范例主要演示使用场景树系统绘制三角形
// AutoInstance
// 该范例主要演示使用RenderList系统绘制多个三角形并利用RenderList进行排序以及自动合并进行Instance渲染
#include"VulkanAppFramework.h"
#include<hgl/math/Math.h>
#include<hgl/filesystem/FileSystem.h>
#include<hgl/graph/VKRenderablePrimitiveCreater.h>
#include<hgl/graph/VKVertexInputConfig.h>
#include<hgl/graph/mtl/2d/Material2DCreateConfig.h>
#include<hgl/graph/RenderList.h>
using namespace hgl;
using namespace hgl::graph;
constexpr uint32_t SCREEN_WIDTH=1280;
constexpr uint32_t SCREEN_HEIGHT=720;
constexpr uint32_t SCREEN_WIDTH=1024;
constexpr uint32_t SCREEN_HEIGHT=1024;
constexpr uint32_t VERTEX_COUNT=3;
constexpr float position_data[VERTEX_COUNT][2]=
constexpr float position_data[VERTEX_COUNT*2]=
{
{SCREEN_WIDTH*0.5, SCREEN_HEIGHT*0.25},
{SCREEN_WIDTH*0.25, SCREEN_HEIGHT*0.75},
{SCREEN_WIDTH*0.75, SCREEN_HEIGHT*0.75}
0.0, 0.0,
-0.1, 0.9,
0.1, 0.9
};
constexpr float color_data[VERTEX_COUNT][4]=
{ {1,0,0,1},
{0,1,0,1},
{0,0,1,1}
constexpr uint8 color_data[VERTEX_COUNT][4]=
{ {255,0,0,255},
{0,255,0,255},
{0,0,255,255}
};
class TestApp:public VulkanApplicationFramework
@@ -42,34 +46,48 @@ private:
bool InitMaterial()
{
material_instance=db->CreateMaterialInstance(OS_TEXT("res/material/VertexColor2D"));
{
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"VertexColor2D");
cfg.coordinate_system=CoordinateSystem2D::NDC;
cfg.local_to_world=true;
AutoDelete<mtl::MaterialCreateInfo> mci=mtl::CreateVertexColor2D(&cfg);
VILConfig vil_config;
vil_config.Add(VAN::Color,VF_V4UN8);
material_instance=db->CreateMaterialInstance(mci,&vil_config);
}
if(!material_instance)
return(false);
BindCameraUBO(material_instance);
// pipeline=db->CreatePipeline(material_instance,sc_render_target,OS_TEXT("res/pipeline/solid2d"));
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D,Prim::Triangles); //等同上一行为Framework重载默认使用swapchain的render target
return pipeline;
}
bool InitVBO()
{
Primitive *primitive=db->CreatePrimitive(VERTEX_COUNT);
if(!primitive)return(false);
RenderablePrimitiveCreater rpc(db,VERTEX_COUNT);
if(!primitive->Set(VAN::Position, db->CreateVBO(VF_V2F,VERTEX_COUNT,position_data)))return(false);
if(!primitive->Set(VAN::Color, db->CreateVBO(VF_V4F,VERTEX_COUNT,color_data)))return(false);
if(!rpc.SetVBO(VAN::Position, VF_V2F, position_data))return(false);
if(!rpc.SetVBO(VAN::Color, VF_V4UN8, color_data ))return(false);
render_obj=db->CreateRenderable(primitive,material_instance,pipeline);
render_obj=rpc.Create(material_instance,pipeline);
render_root.CreateSubNode(render_obj);
if(!render_obj)
return(false);
for(uint i=0;i<12;i++)
render_root.CreateSubNode(rotate(deg2rad(30*i),Vector3f(0,0,1)),render_obj);
render_root.RefreshMatrix();
render_list->Expend(GetCameraInfo(),&render_root);
render_list->Expend(&render_root);
return(true);
}

View File

@@ -2,13 +2,13 @@
#include<hgl/platform/Window.h>
#include<hgl/graph/VKInstance.h>
#include<hgl/graph/VKPhysicalDevice.h>
#include<hgl/graph/VKDevice.h>
#include<hgl/graph/VKDeviceCreater.h>
#include<hgl/graph/VKSemaphore.h>
#include<hgl/graph/VKBuffer.h>
#include<hgl/graph/VKShaderModule.h>
#include<hgl/graph/VKImageView.h>
#include<hgl/graph/VKPrimitive.h>
#include<hgl/graph/VKDescriptorSets.h>
#include<hgl/graph/VKDescriptorSet.h>
#include<hgl/graph/VKRenderPass.h>
#include<hgl/graph/VKPipeline.h>
#include<hgl/graph/VKCommandBuffer.h>
@@ -20,8 +20,10 @@
#include<hgl/graph/VKRenderTarget.h>
#include<hgl/graph/VKRenderResource.h>
#include<hgl/graph/RenderList.h>
#include<hgl/type/Color.h>
#include<hgl/graph/mtl/UBOCommon.h>
#include<hgl/color/Color.h>
#include<hgl/Time.h>
#include<hgl/log/LogInfo.h>
//#include<hgl/graph/LookAtCameraControl.h>
#include<hgl/graph/FirstPersonCameraControl.h>
@@ -33,6 +35,12 @@ using namespace hgl;
using namespace hgl::io;
using namespace hgl::graph;
namespace hgl{namespace graph
{
bool InitShaderCompiler();
void CloseShaderCompiler();
}}//namespace hgl::graph
class VulkanApplicationFramework:WindowEvent
{
protected:
@@ -44,7 +52,7 @@ protected:
GPUDevice * device =nullptr;
RenderPass * device_render_pass =nullptr;
SwapchainRenderTarget * sc_render_target =nullptr;
RTSwapchain * sc_render_target =nullptr;
protected:
@@ -59,15 +67,16 @@ protected:
RenderResource * db =nullptr;
protected:
Camera * camera =nullptr;
GPUBuffer * ubo_camera_info =nullptr;
ViewportInfo vp_info;
DeviceBuffer * ubo_vp_info =nullptr;
public:
virtual ~VulkanApplicationFramework()
{
SAFE_CLEAR(camera);
CloseShaderCompiler();
win->Unjoin(this);
SAFE_CLEAR(db);
@@ -80,6 +89,11 @@ public:
virtual bool Init(int w,int h)
{
logger::InitLogger(OS_TEXT("VulkanTest"));
if(!InitShaderCompiler())
return(false);
clear_color.Set(0,0,0,1);
#ifdef _DEBUG
@@ -105,7 +119,6 @@ public:
cili.lunarg.standard_validation = true;
cili.khronos.validation = true;
//cili.RenderDoc.Capture = true;
inst=CreateInstance("VulkanTest",nullptr,&cili);
@@ -127,48 +140,20 @@ public:
win->Join(this);
{
camera=new Camera;
vp_info.Set(w,h);
camera->width=w;
camera->height=h;
camera->vp_width=w;
camera->vp_height=h;
ubo_vp_info=db->CreateUBO(sizeof(ViewportInfo),&vp_info);
camera->pos=Vector3f(10,10,10);
camera->RefreshCameraInfo();
ubo_camera_info=db->CreateUBO(sizeof(CameraInfo),&camera->info);
db->global_descriptor.AddUBO(mtl::SBS_ViewportInfo.name,ubo_vp_info);
}
return(true);
}
const CameraInfo &GetCameraInfo()
{
return camera->info;
}
GPUBuffer *GetCameraInfoBuffer()
{
return ubo_camera_info;
}
bool BindCameraUBO(MaterialInstance *mi)
{
return mi->BindUBO(DescriptorSetsType::Global,"g_camera",ubo_camera_info);
}
virtual void Resize(int w,int h)
{
camera->width=w;
camera->height=h;
camera->vp_width=w;
camera->vp_height=h;
camera->RefreshCameraInfo();
ubo_camera_info->Write(&camera->info);
vp_info.Set(w,h);
ubo_vp_info->Write(&vp_info);
}
void SetClearColor(const Color4f &cc)
@@ -212,20 +197,20 @@ public:
{
if(!ri)return(false);
const IndexBuffer *ib=ri->GetIndexBuffer();
const VertexInputData *vid=ri->GetVertexInputData();
cb->Begin();
cb->BindFramebuffer(rp,fb);
cb->SetClearColor(0,clear_color);
cb->BeginRenderPass();
cb->BindPipeline(ri->GetPipeline());
cb->BindDescriptorSets(ri);
cb->BindDescriptorSets(ri->GetMaterial());
cb->BindVBO(ri);
if (ib)
cb->DrawIndexed(ib->GetCount(),ri->GetInstanceCount());
if (vid->index_buffer->buffer)
cb->DrawIndexed(vid->index_buffer->buffer->GetCount());
else
cb->Draw(ri->GetDrawCount(),ri->GetInstanceCount());
cb->Draw(vid->vertex_count);
cb->EndRenderPass();
cb->End();
@@ -456,6 +441,10 @@ class CameraAppFramework:public VulkanApplicationFramework
protected:
Camera * camera =nullptr;
DeviceBuffer * ubo_camera_info =nullptr;
FirstPersonCameraControl *camera_control=nullptr;
CameraKeyboardControl * ckc=nullptr;
@@ -469,6 +458,7 @@ public:
{
SAFE_CLEAR(ckc);
SAFE_CLEAR(cmc);
SAFE_CLEAR(camera);
}
virtual bool Init(int w,int h)
@@ -482,7 +472,7 @@ public:
virtual void InitCamera(int w,int h)
{
camera_control=new FirstPersonCameraControl(camera);
camera_control=new FirstPersonCameraControl(&vp_info,camera);
camera_control->Refresh(); //更新矩阵计算
@@ -491,26 +481,47 @@ public:
win->Join(ckc);
win->Join(cmc);
camera=new Camera;
camera->pos=Vector3f(10,10,10);
RefreshCameraInfo(&camera_control->GetCameraInfo(),&vp_info,camera);
ubo_camera_info=db->CreateUBO(sizeof(CameraInfo),&camera_control->GetCameraInfo());
}
void Resize(int w,int h)override
{
camera->width=w;
camera->height=h;
camera->vp_width=w;
camera->vp_height=h;
vp_info.Set(w,h);
camera_control->Refresh();
ubo_camera_info->Write(&camera->info);
ubo_camera_info->Write(&camera_control->GetCameraInfo());
}
const CameraInfo &GetCameraInfo()
{
return camera_control->GetCameraInfo();
}
DeviceBuffer *GetCameraInfoBuffer()
{
return ubo_camera_info;
}
bool BindCameraUBO(MaterialInstance *mi)
{
return mi->BindUBO(DescriptorSetType::Global,"g_camera",ubo_camera_info);
}
virtual void BuildCommandBuffer(uint32_t index)=0;
virtual void Draw()override
{
camera_control->Refresh(); //更新相机矩阵
ubo_camera_info->Write(&camera->info); //写入缓冲区
camera_control->Refresh(); //更新相机矩阵
ubo_camera_info->Write(&camera_control->GetCameraInfo()); //写入缓冲区
const uint32_t index=AcquireNextImage();

View File

@@ -0,0 +1,17 @@
#pragma once
#include<hgl/TypeFunc.h>
namespace hgl
{
namespace graph
{
enum class CoordinateSystem2D
{
NDC,
ZeroToOne, //左上角为0,0右下角为1,1
Ortho, //左上角为0,0右下角为(width-1),(height-1)
ENUM_CLASS_RANGE(NDC,Ortho)
};
}//namespace graph
}//namespace hgl

View File

@@ -4,7 +4,7 @@
#include<hgl/graph/VK.h>
#include<hgl/math/Vector.h>
#include<hgl/type/RectScope.h>
#include<hgl/type/Color4f.h>
#include<hgl/color/Color4f.h>
#include<hgl/graph/AABB.h>
namespace hgl
{
@@ -20,12 +20,12 @@ namespace hgl
RectScope2f scope;
};//struct RectangleCreateInfo
Primitive *CreateRectangle(RenderResource *db,const VAB *vab,const RectangleCreateInfo *rci);
Primitive *CreateRectangle(RenderResource *db,const VIL *vil,const RectangleCreateInfo *rci);
/**
* 创建延迟渲染用全屏平面
*/
Primitive *CreateGBufferCompositionRectangle(RenderResource *db,const VAB *vab);
Primitive *CreateGBufferCompositionRectangle(RenderResource *db,const VIL *vil);
/**
* 圆角矩形创建信息(扇形/线圈)
@@ -36,7 +36,7 @@ namespace hgl
uint32_t round_per; ///<圆角精度
};//struct RoundRectangleCreateInfo:public RectangleCreateInfo
Primitive *CreateRoundRectangle(RenderResource *db,const VAB *vab,const RoundRectangleCreateInfo *rci);
Primitive *CreateRoundRectangle(RenderResource *db,const VIL *vil,const RoundRectangleCreateInfo *rci);
/**
* 圆形创建信息
@@ -56,7 +56,7 @@ namespace hgl
/**
* 创建一个2D圆形(扇形/线圈)
*/
Primitive *CreateCircle(RenderResource *db,const VAB *vab,const CircleCreateInfo *cci);
Primitive *CreateCircle(RenderResource *db,const VIL *vil,const CircleCreateInfo *cci);
/**
* 平面网格创建信息
@@ -75,7 +75,7 @@ namespace hgl
/**
* 创建一个平面网格(线条)
*/
Primitive *CreatePlaneGrid(RenderResource *db,const VAB *vab,const PlaneGridCreateInfo *pgci);
Primitive *CreatePlaneGrid(RenderResource *db,const VIL *vil,const PlaneGridCreateInfo *pgci);
struct PlaneCreateInfo
{
@@ -93,7 +93,7 @@ namespace hgl
/**
* 创建一个平面(三角形)
*/
Primitive *CreatePlane(RenderResource *db,const VAB *vab,const PlaneCreateInfo *pci);
Primitive *CreatePlane(RenderResource *db,const VIL *vil,const PlaneCreateInfo *pci);
struct CubeCreateInfo
{
@@ -129,7 +129,7 @@ namespace hgl
/**
* 创建一个立方体(三角形)
*/
Primitive *CreateCube(RenderResource *db,const VAB *vab,const CubeCreateInfo *cci);
Primitive *CreateCube(RenderResource *db,const VIL *vil,const CubeCreateInfo *cci);
struct BoundingBoxCreateInfo
{
@@ -160,17 +160,17 @@ namespace hgl
/**
* 创建一个绑定盒(线条)
*/
Primitive *CreateBoundingBox(RenderResource *db,const VAB *vab,const BoundingBoxCreateInfo *cci);
Primitive *CreateBoundingBox(RenderResource *db,const VIL *vil,const BoundingBoxCreateInfo *cci);
/**
* 创建一个球心坐标为0,0,0半径为1的球体(三角形)
*/
Primitive *CreateSphere(RenderResource *db,const VAB *vab,const uint numberSlices);
Primitive *CreateSphere(RenderResource *db,const VIL *vil,const uint numberSlices);
/**
* 创建一个穹顶(三角形)
*/
Primitive *CreateDome(RenderResource *db,const VAB *vab, const uint numberSlices);
Primitive *CreateDome(RenderResource *db,const VIL *vil, const uint numberSlices);
struct TorusCreateInfo
{
@@ -186,7 +186,7 @@ namespace hgl
/**
* 创建一个圆环(三角形)
*/
Primitive *CreateTorus(RenderResource *db,const VAB *vab,const TorusCreateInfo *tci);
Primitive *CreateTorus(RenderResource *db,const VIL *vil,const TorusCreateInfo *tci);
struct CylinderCreateInfo
{
@@ -198,7 +198,7 @@ namespace hgl
/**
* 创建一个圆柱(三角形)
*/
Primitive *CreateCylinder(RenderResource *db,const VAB *vab,const CylinderCreateInfo *cci);
Primitive *CreateCylinder(RenderResource *db,const VIL *vil,const CylinderCreateInfo *cci);
struct ConeCreateInfo
{
@@ -211,7 +211,7 @@ namespace hgl
/**
* 创建一个圆锥(三角形)
*/
Primitive *CreateCone(RenderResource *db,const VAB *vab,const ConeCreateInfo *cci);
Primitive *CreateCone(RenderResource *db,const VIL *vil,const ConeCreateInfo *cci);
struct AxisCreateInfo
{
@@ -232,7 +232,7 @@ namespace hgl
/**
* 创建一个坐标线(线条)
*/
Primitive *CreateAxis(RenderResource *db,const VAB *vab,const AxisCreateInfo *aci);
Primitive *CreateAxis(RenderResource *db,const VIL *vil,const AxisCreateInfo *aci);
}//namespace inline_geometry
}//namespace graph
};//namespace hgl

View File

@@ -0,0 +1,75 @@
#pragma once
#include<hgl/graph/RenderNode.h>
#include<hgl/graph/VKVBOList.h>
VK_NAMESPACE_BEGIN
class RenderAssignBuffer;
/**
* 同一材质的对象渲染列表
*/
class MaterialRenderList
{
GPUDevice *device;
RenderCmdBuffer *cmd_buf;
Material *mtl;
RenderNodeList rn_list;
private:
RenderAssignBuffer *assign_buffer;
struct RenderItem
{
uint32_t first;
uint32_t count;
Pipeline * pipeline;
MaterialInstance * mi;
const VertexInputData * vid;
public:
void Set(Renderable *);
};
MaterialInstanceSets mi_set;
DataArray<RenderItem> ri_array;
uint ri_count;
void StatMI();
void Stat();
protected:
VBOList * vbo_list;
const VIL * last_vil;
Pipeline * last_pipeline;
const VertexInputData * last_vid;
uint last_index;
void Bind(MaterialInstance *);
bool Bind(const VertexInputData *,const uint);
void Render(RenderItem *);
public:
MaterialRenderList(GPUDevice *d,Material *m);
~MaterialRenderList();
void Add(Renderable *ri,const Matrix4f &mat);
void Clear()
{
rn_list.Clear();
}
void End();
void Render(RenderCmdBuffer *);
};//class MaterialRenderList
VK_NAMESPACE_END

View File

@@ -0,0 +1,32 @@
#pragma once
#include<hgl/graph/MaterialRenderList.h>
VK_NAMESPACE_BEGIN
class MaterialRenderMap:public ObjectMap<Material *,MaterialRenderList>
{
public:
MaterialRenderMap()=default;
virtual ~MaterialRenderMap()=default;
void Begin()
{
for(auto *it:data_list)
it->value->Clear();
}
void End()
{
for(auto *it:data_list)
it->value->End();
}
void Render(RenderCmdBuffer *rcb)
{
if(!rcb)return;
for(auto *it:data_list)
it->value->Render(rcb);
}
};//class MaterialRenderMap
VK_NAMESPACE_END

View File

@@ -8,45 +8,45 @@ namespace hgl
{
namespace graph
{
struct ShaderStageBind
{
AnsiString name;
uint binding;
VAD * data =nullptr;
VBO * vbo =nullptr;
public:
~ShaderStageBind()
{
SAFE_CLEAR(data);
}
};//struct ShaderStageBind
using ShaderStageBindMap=MapObject<AnsiString,ShaderStageBind>;
/**
* 可绘制图元创建器
*/
class PrimitiveCreater
{
struct PrimitiveVertexBuffer
{
AnsiString name;
uint binding;
VAD * data =nullptr;
VBO * vbo =nullptr;
public:
~PrimitiveVertexBuffer()
{
SAFE_CLEAR(data);
}
};//struct PrimitiveVertexBuffer
using PVBMap=ObjectMap<AnsiString,PrimitiveVertexBuffer>;
protected:
RenderResource *db;
Material *mtl;
const VAB *vab;
const VIL *vil;
protected:
uint32 vertices_number;
IndexBuffer * ibo;
ShaderStageBindMap ssb_map;
PVBMap vbo_map;
public:
PrimitiveCreater(RenderResource *sdb,const VAB *);
PrimitiveCreater(RenderResource *sdb,const VIL *);
virtual ~PrimitiveCreater()=default;
virtual bool Init(const uint32 vertices_count); ///<初始化,参数为顶点数量
@@ -54,9 +54,9 @@ namespace hgl
VAD * CreateVAD(const AnsiString &name); ///<创建一个顶点属性缓冲区
template<typename T>
T * CreateVADA(const AnsiString &name) ///<创建一个顶点属性缓冲区以及访问器
T * AccessVAD(const AnsiString &name) ///<创建一个顶点属性缓冲区以及访问器
{
const VkFormat format=vab->GetFormat(name);
const VkFormat format=vil->GetVulkanFormat(name);
if(format!=T::GetVulkanFormat())
return(nullptr);
@@ -66,11 +66,11 @@ namespace hgl
if(!vad)
return(nullptr);
T *vada=T::Create(vad);
T *access=T::Create(vad);
vada->Begin();
access->Begin();
return vada;
return access;
}
bool WriteVAD(const AnsiString &name,const void *data,const uint32_t bytes); ///<直接写入顶点属性数据
@@ -78,7 +78,7 @@ namespace hgl
uint16 * CreateIBO16(uint count,const uint16 *data=nullptr); ///<创建16位的索引缓冲区
uint32 * CreateIBO32(uint count,const uint32 *data=nullptr); ///<创建32位的索引缓冲区
virtual Primitive * Finish(); ///<结束并创建可渲染对象
virtual Primitive * Finish(); ///<结束并创建可渲染对象
};//class PrimitiveCreater
}//namespace graph
}//namespace hgl

View File

@@ -2,72 +2,42 @@
#define HGL_GRAPH_RENDER_LIST_INCLUDE
#include<hgl/graph/VK.h>
#include<hgl/graph/Camera.h>
#include<hgl/graph/SceneNode.h>
#include<hgl/graph/RenderNode.h>
#include<hgl/graph/MaterialRenderMap.h>
#include<hgl/graph/VKArrayBuffer.h>
#include<hgl/graph/SceneInfo.h>
#include<hgl/type/Color4f.h>
#include<hgl/type/SortedSets.h>
#include<hgl/graph/VKMaterial.h>
namespace hgl
{
namespace graph
{
using MVPArrayBuffer=GPUArrayBuffer<MVPMatrix>;
using MaterialSets=SortedSets<Material *>;
/**
* 渲染对象列表<br>
* 已经展开的渲染对象列表产生mvp用UBO/SSBO等数据最终创建RenderCommandBuffer
* 该类会长期保存使用过的材质信息避重新分配造成的时间和空间浪费。如需彻底清空列表请使用Clear()函数
*/
class RenderList
{
GPUDevice * device;
RenderCmdBuffer *cmd_buf;
protected:
private:
GPUDevice * device;
CameraInfo camera_info;
RenderNodeList render_node_list; ///<场景节点列表
MaterialSets material_sets; ///<材质合集
RenderNodeComparator render_node_comparator;
private:
MVPArrayBuffer *mvp_array;
List<Renderable *> ri_list;
VkDescriptorSet ds_list[(size_t)DescriptorSetsType::RANGE_SIZE];
DescriptorSets *renderable_desc_sets;
uint32_t ubo_offset;
uint32_t ubo_align;
uint renderable_count; ///<可渲染对象数量
MaterialRenderMap mrl_map; ///<按材质分类的渲染列表
protected:
virtual bool Begin();
virtual bool Expend(SceneNode *);
virtual void End();
private:
Pipeline * last_pipeline;
MaterialParameters *last_mp[(size_t)DescriptorSetsType::RANGE_SIZE];
uint32_t last_vbo;
void Render(Renderable *);
virtual bool ExpendNode(SceneNode *);
public:
RenderList(GPUDevice *);
virtual ~RenderList();
virtual bool Expend(const CameraInfo &,SceneNode *);
virtual bool Expend(SceneNode *); ///<展开场景树到渲染列表
virtual bool Render(RenderCmdBuffer *);
};//class RenderList
virtual bool Render(RenderCmdBuffer *); ///<渲染所有对象
virtual void Clear(); ///<彻底清理
};//class RenderList
}//namespace graph
}//namespace hgl
#endif//HGL_GRAPH_RENDER_LIST_INCLUDE

View File

@@ -1,39 +1,29 @@
#ifndef HGL_GRAPH_RENDER_NODE_INCLUDE
#define HGL_GRAPH_RENDER_NODE_INCLUDE
#include<hgl/math/Vector.h>
#include<hgl/type/List.h>
#include<hgl/graph/SceneInfo.h>
#include<hgl/graph/VK.h>
#include<hgl/type/SortedSets.h>
namespace hgl
{
namespace graph
{
class Renderable;
class Material;
class MaterialInstance;
class GPUDevice;
struct VertexInputData;
struct IndexBufferData;
struct RenderNode
{
MVPMatrix matrix;
Vector3f WorldCenter;
float distance_to_camera_square;
// float distance_to_camera;
Matrix4f local_to_world;
Renderable *ri;
};
public:
using RenderNodeList=List<RenderNode>;
/**
* 取得渲染对象ubo独占区大小
*/
virtual const uint32 GetUBOBytes()const{return sizeof(MVPMatrix);}
};//struct RenderNode
using RenderNodeList=List<RenderNode *>;
using MaterialInstanceSets=SortedSets<MaterialInstance *>; ///<材质实例集合
}//namespace graph
}//namespace hgl
using RenderNodePointer=hgl::graph::RenderNode *;
using RenderNodeComparator=Comparator<RenderNodePointer>;
#endif//HGL_GRAPH_RENDER_NODE_INCLUDE

View File

@@ -0,0 +1,18 @@
#ifndef HGL_GRAPH_RT_OUTPUT_CONFIG_INCLUDE
#define HGL_GRAPH_RT_OUTPUT_CONFIG_INCLUDE
#include<hgl/type/DataType.h>
namespace hgl
{
namespace graph
{
struct RenderTargetOutputConfig
{
uint color; ///<要输出几个颜色缓冲区
bool depth; ///<是否输出到深度缓冲区
bool stencil; ///<是否输出到模板缓冲区
};
}//namespace graph
}//namespace hgl
#endif//HGL_GRAPH_RT_OUTPUT_CONFIG_INCLUDE

View File

@@ -7,7 +7,7 @@ namespace hgl
{
namespace graph
{
/**
/**
* MVP矩阵
*/
struct MVPMatrix

View File

@@ -1,7 +1,7 @@
#ifndef HGL_GRAPH_SCENE_NODE_INCLUDE
#define HGL_GRAPH_SCENE_NODE_INCLUDE
#include<hgl/type/List.h>
#include<hgl/type/ObjectList.h>
#include<hgl/graph/SceneOrient.h>
#include<hgl/graph/VK.h>
#include<hgl/graph/AABB.h>
@@ -43,7 +43,7 @@ namespace hgl
void Clear()
{
SubNode.ClearData();
SubNode.Clear();
render_obj=nullptr;
}

View File

@@ -0,0 +1,25 @@
#ifndef HGL_GRAPH_STATIC_RENDER_MANAGER_INCLUDE
#define HGL_GRAPH_STATIC_RENDER_MANAGER_INCLUDE
#include<hgl/graph/VK.h>
VK_NAMESPACE_BEGIN
class RawMesh
{
};
/**
* 静态渲染管理器<br>
* 静态渲染指的是不会产生资源变动的内容,而不是指不会动的内容。
*/
class StaticRenderManager
{
public:
virtual ~StaticRenderManager()=default;
};//class StaticRenderManager
VK_NAMESPACE_END
#endif//HGL_GRAPH_STATIC_RENDER_MANAGER_INCLUDE

View File

@@ -3,8 +3,8 @@
#include<hgl/io/InputStream.h>
#include<hgl/type/String.h>
#include<hgl/graph/Bitmap.h>
#include<hgl/graph/VKFormat.h>
#include<hgl/graph/BitmapData.h>
namespace hgl
{
namespace graph

View File

@@ -1,32 +1,17 @@
#ifndef HGL_GRAPH_TILE_DATA_INCLUDE
#define HGL_GRAPH_TILE_DATA_INCLUDE
#include<hgl/type/Map.h>
#include<hgl/type/Pool.h>
#include<hgl/type/RectScope.h>
#include<hgl/graph/Bitmap.h>
#include<hgl/graph/BitmapData.h>
#include<hgl/graph/ImageRegion.h>
#include<hgl/graph/tile/TileObject.h>
#include<hgl/graph/VKTexture.h>
VK_NAMESPACE_USING
namespace hgl
{
namespace graph
{
using TileUVPixel=RectScope2i;
using TileUVFloat=RectScope2f;
using TileUVFloatList=List<TileUVFloat>;
using TileUVFloatMap=Map<u32char,TileUVFloat>;
struct TileObject
{
int col,row; //当前tile在整个纹理中的tile位置
TileUVPixel uv_pixel; //以象素为单位的tile位置和尺寸
TileUVFloat uv_float; //以浮点为单位的tile位置和尺寸
};//struct TileObject
/**
* TileData是一种处理大量等同尺寸及格式贴图的管理机制程序会自动根据显卡最大贴图处理能力来创建尽可能符合需求的贴图。(注Tile的大小不必符合2次幂)
* Tile的增加或删除程序会自动排序尽可能小的减少I/O消耗。
@@ -48,7 +33,7 @@ namespace hgl
protected:
GPUBuffer *tile_buffer; ///<Tile暂存缓冲区
DeviceBuffer *tile_buffer; ///<Tile暂存缓冲区
List<Image2DRegion> commit_list;
uint8 *commit_ptr;

View File

@@ -1,11 +1,10 @@
#ifndef HGL_GRAPH_VULKAN_INCLUDE
#define HGL_GRAPH_VULKAN_INCLUDE
#include<hgl/math/Math.h>
#include<hgl/type/List.h>
#include<hgl/math/Math.h>
#include<hgl/type/String.h>
#include<hgl/type/Map.h>
#include<iostream>
#include<hgl/graph/VKNamespace.h>
#include<hgl/graph/VKFormat.h>
#include<hgl/graph/VKPrimitiveType.h>
@@ -33,12 +32,12 @@ class VulkanInstance;
class GPUPhysicalDevice;
class GPUDevice;
struct GPUDeviceAttribute;
class GPUQueue;
class DeviceQueue;
class ImageView;
class Framebuffer;
struct Swapchain;
class RenderTarget;
class SwapchainRenderTarget;
class RTSwapchain;
class Texture;
class Texture1D;
@@ -51,15 +50,21 @@ class TextureCubeArray;
class Sampler;
class GPUMemory;
class GPUBuffer;
struct GPUBufferData;
class DeviceMemory;
class DeviceBuffer;
struct DeviceBufferData;
class VertexAttribBuffer;
using VBO=VertexAttribBuffer;
class IndexBuffer;
struct IndexBufferData
{
IndexBuffer *buffer=nullptr;
VkDeviceSize offset=0;
};
class GPUCmdBuffer;
class RenderCmdBuffer;
class TextureCmdBuffer;
@@ -67,46 +72,18 @@ class TextureCmdBuffer;
class RenderPass;
class DeviceRenderPassManage;
class GPUFence;
class GPUSemaphore;
enum class DescriptorSetsType
{
//设计使其对应shader中的set
Global=0, ///<全局参数(如太阳光等)
Material, ///<材质中永远不变的参数
// Texture, ///<材质中的纹理参数
Value, ///<材质中的变量参数
Primitive, ///<渲染实例参数(如Local2World matrix)
ENUM_CLASS_RANGE(Global,Primitive)
};//
const DescriptorSetsType CheckDescriptorSetsType(const char *str);
constexpr char *DescriptSetsTypeName[]=
{
"Global","Material","Value","Renderable"
};
inline const char *GetDescriptorSetsTypeName(const enum class DescriptorSetsType &type)
{
ENUM_CLASS_RANGE_ERROR_RETURN_NULLPTR(type);
return DescriptSetsTypeName[(size_t)type];
}
class Fence;
class Semaphore;
struct PipelineLayoutData;
class DescriptorSets;
class DescriptorSet;
struct ShaderStage;
struct ShaderAttribute;
class ShaderResource;
class ShaderModule;
class VertexShaderModule;
class ShaderModuleMap;
class MaterialDescriptorSets;
class MaterialDescriptorManager;
class Material;
class MaterialParameters;
@@ -115,20 +92,14 @@ struct PipelineData;
enum class InlinePipeline;
class Pipeline;
struct VAConfig
{
VkFormat format=PF_UNDEFINED;
bool instance=false;
struct VAConfig;
class VILConfig;
class VertexInput;
public:
struct VertexInputFormat;
CompOperatorMemcmp(const VAConfig &);
};
using VABConfigInfo=Map<AnsiString,VAConfig>;
class VertexAttributeBinding;
using VAB=VertexAttributeBinding;
class VertexInputLayout;
using VIL=VertexInputLayout;
class Primitive;
class Renderable;
@@ -166,38 +137,13 @@ inline const uint32_t GetMipLevel(const VkExtent3D &ext)
/**
* 索引类型,等同于VkIndexType
*/
enum IndexType
enum IndexType:uint
{
U16=0,
U32
U32,
U8=VK_INDEX_TYPE_UINT8_EXT,
};
enum class ShaderStageBit
{
Vertex =VK_SHADER_STAGE_VERTEX_BIT,
TessControl =VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
TessEval =VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
Geometry =VK_SHADER_STAGE_GEOMETRY_BIT,
Fragment =VK_SHADER_STAGE_FRAGMENT_BIT,
Compute =VK_SHADER_STAGE_COMPUTE_BIT
};//enum class ShaderStageBit
inline const uint GetShaderCountByBits(const uint32_t bits)
{
uint comp=(uint)VK_SHADER_STAGE_VERTEX_BIT;
uint result=0;
for(uint i=0;i<6;i++)
{
if(bits&comp)
++result;
comp<<=1;
}
return result;
}
/**
* max-lengths:
*
@@ -218,61 +164,5 @@ inline void copy(VkExtent3D &e3d,const VkExtent2D &e2d,const uint32 depth=1)
e3d.height =e2d.height;
e3d.depth =depth;
}
inline void debug_out_vk_version(const uint32_t version)
{
std::cout<<VK_VERSION_MAJOR(version)<<"."
<<VK_VERSION_MINOR(version)<<"."
<<VK_VERSION_PATCH(version);
}
template<typename T>
inline hgl::String<T> VkUUID2String(const uint8_t *pipelineCacheUUID)
{
T *hstr=new T[VK_UUID_SIZE*2+1];
DataToLowerHexStr(hstr,pipelineCacheUUID,VK_UUID_SIZE);
return hgl::String<T>::newOf(hstr,VK_UUID_SIZE*2);
}
inline void debug_out(const char *front,const hgl::List<VkLayerProperties> &layer_properties)
{
const int property_count=layer_properties.GetCount();
if(property_count<=0)return;
const VkLayerProperties *lp=layer_properties.GetData();
for(int i=0;i<property_count;i++)
{
std::cout<<front<<" Layer Propertyes ["<<i<<"] : "<<lp->layerName<<" [spec: ";
debug_out_vk_version(lp->specVersion);
std::cout<<", impl: ";
debug_out_vk_version(lp->implementationVersion);
std::cout<<"] desc: "<<lp->description<<std::endl;
++lp;
}
}
inline void debug_out(const char *front,const hgl::List<VkExtensionProperties> &extension_properties)
{
const int extension_count=extension_properties.GetCount();
if(extension_count<=0)return;
VkExtensionProperties *ep=extension_properties.GetData();
for(int i=0;i<extension_count;i++)
{
std::cout<<front<<" Extension Propertyes ["<<i<<"] : "<<ep->extensionName<<" ver: ";
debug_out_vk_version(ep->specVersion);
std::cout<<std::endl;
++ep;
}
}
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_INCLUDE

View File

@@ -1,90 +1,75 @@
#ifndef HGL_GRAPH_VULKAN_ARRAY_BUFFER_INCLUDE
#define HGL_GRAPH_VULKAN_ARRAY_BUFFER_INCLUDE
#include<hgl/graph/VKBuffer.h>
#include<hgl/graph/VKDevice.h>
#include<hgl/graph/VKMemoryAllocator.h>
#include<hgl/type/Collection.h>
#include<hgl/graph/VK.h>
#include<hgl/graph/VKDynamicBufferAccess.h>
namespace hgl
{
class Collection;
namespace graph
{
class VKMemoryAllocator;
/**
* GPU数据阵列缓冲区<br>
* 它用于储存多份相同格式的数据常用于多物件渲染instance等
*/
template<typename T> class GPUArrayBuffer
class GPUArrayBuffer
{
protected:
GPUDevice *device;
VkBufferUsageFlags buffer_usage_flags;
VKMemoryAllocator *vk_ma;
uint align_size;
uint range_size;
uint32_t ubo_offset_alignment;
VKMemoryAllocator *vk_ma;
Collection *coll;
protected:
void * Map(const uint32 start,const uint32 count);
void Flush(const uint32 count);
private:
GPUArrayBuffer(VKMemoryAllocator *,const uint,const uint);
friend class GPUDevice;
public:
GPUArrayBuffer(GPUDevice *dev,VkBufferUsageFlags flags)
virtual ~GPUArrayBuffer();
const uint32_t GetAlignSize()const{return align_size;} ///<数据对齐字节数
const uint32_t GetRangeSize()const{return range_size;} ///<单次渲染访问最大字节数
DeviceBuffer * GetBuffer();
uint32 Alloc(const uint32 max_count); ///<预分配空间
void Clear();
template<typename T>
bool Start(DynamicBufferAccess<T> *dba,const uint32 start,const uint32 count)
{
device=dev;
buffer_usage_flags=flags;
if(!dba)return(false);
{
ubo_offset_alignment=device->GetUBOAlign();
void *ptr=Map(start,count);
const uint32_t unit_size=hgl_align<uint32_t>(sizeof(T),ubo_offset_alignment);
if(!ptr)return(false);
vk_ma=new VKMemoryAllocator(device,buffer_usage_flags,unit_size); // construct function is going to set AllocUnitSize by minUniformOffsetAlignment
MemoryBlock *mb=new MemoryBlock(vk_ma);
coll=new Collection(unit_size,mb);
}
dba->Start((uchar *)ptr,align_size,count);
return(true);
}
virtual ~GPUArrayBuffer()
template<typename T>
void End(DynamicBufferAccess<T> *dba)
{
delete coll;
}
if(!dba)return;
const uint32_t GetOffsetAlignment()const
{
return ubo_offset_alignment;
}
Flush(dba->GetCount());
const uint32_t GetUnitSize()const
{
return coll->GetUnitBytes();
}
GPUBuffer *GetBuffer()
{
return vk_ma->GetBuffer();
}
uint32 Alloc(const uint32 max_count) ///<预分配空间
{
if(!coll->Alloc(max_count))
return(0);
return coll->GetAllocCount();
}
void Clear()
{
coll->Clear();
}
T *Map(const uint32 start,const uint32 count)
{
return (T *)(coll->Map(start,count));
}
void Flush(const uint32 count)
{
vk_ma->Flush(count*GetUnitSize());
dba->Restart();
}
};//class GPUArrayBuffer
}//namespace graph

View File

@@ -4,19 +4,19 @@
#include<hgl/graph/VK.h>
#include<hgl/graph/VKMemory.h>
VK_NAMESPACE_BEGIN
struct GPUBufferData
struct DeviceBufferData
{
VkBuffer buffer;
GPUMemory * memory=nullptr;
VkBuffer buffer=nullptr;
DeviceMemory * memory=nullptr;
VkDescriptorBufferInfo info;
};//struct GPUBufferData
};//struct DeviceBufferData
class GPUBuffer
class DeviceBuffer
{
protected:
VkDevice device;
GPUBufferData buf;
DeviceBufferData buf;
private:
@@ -24,7 +24,7 @@ private:
friend class VertexAttribBuffer;
friend class IndexBuffer;
GPUBuffer(VkDevice d,const GPUBufferData &b)
DeviceBuffer(VkDevice d,const DeviceBufferData &b)
{
device=d;
buf=b;
@@ -32,10 +32,10 @@ private:
public:
virtual ~GPUBuffer();
virtual ~DeviceBuffer();
VkBuffer GetBuffer ()const{return buf.buffer;}
GPUMemory * GetMemory ()const{return buf.memory;}
DeviceMemory * GetMemory ()const{return buf.memory;}
const VkDescriptorBufferInfo * GetBufferInfo ()const{return &buf.info;}
void * Map () {return buf.memory->Map();}
@@ -47,6 +47,6 @@ public:
bool Write (const void *ptr,uint32_t start,uint32_t size) {return buf.memory->Write(ptr,start,size);}
bool Write (const void *ptr,uint32_t size) {return buf.memory->Write(ptr,0,size);}
bool Write (const void *ptr) {return buf.memory->Write(ptr);}
};//class GPUBuffer
};//class DeviceBuffer
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_BUFFER_INCLUDE

View File

@@ -2,9 +2,10 @@
#define HGL_GRAPH_VULKAN_COMMAND_BUFFER_INCLUDE
#include<hgl/graph/VK.h>
#include<hgl/graph/VKVBOList.h>
#include<hgl/graph/VKPipeline.h>
#include<hgl/graph/VKDescriptorSets.h>
#include<hgl/type/Color4f.h>
#include<hgl/graph/VKDescriptorSet.h>
#include<hgl/color/Color4f.h>
VK_NAMESPACE_BEGIN
class GPUCmdBuffer
{
@@ -27,11 +28,11 @@ public:
bool End(){return(vkEndCommandBuffer(cmd_buf)==VK_SUCCESS);}
#ifdef _DEBUG
void SetDebugName(const char *);
void BeginRegion(const char *,const Color4f &);
void SetDebugName(const UTF8String &);
void BeginRegion(const UTF8String &,const Color4f &);
void EndRegion();
#else
void BeginRegion(const char *,const Color4f &){}
void BeginRegion(const UTF8String &,const Color4f &){}
void EndRegion(){}
#endif//_DEBUG
};//class GPUCmdBuffer
@@ -105,7 +106,7 @@ public:
return(true);
}
bool BindDescriptorSets(DescriptorSets *dsl)
bool BindDescriptorSets(DescriptorSet *dsl)
{
if(!dsl)return(false);
@@ -118,7 +119,7 @@ public:
return(true);
}
bool BindDescriptorSets(DescriptorSets *dsl,const uint32_t offset)
bool BindDescriptorSets(DescriptorSet *dsl,const uint32_t offset)
{
if(!dsl)return(false);
@@ -140,14 +141,14 @@ public:
return(true);
}
bool BindDescriptorSets(Renderable *ri);
bool BindDescriptorSets(Material *);
bool PushDescriptorSet(VkPipelineLayout pipeline_layout,uint32_t set,uint32_t count,const VkWriteDescriptorSet *write_desc_set)
{
vkCmdPushDescriptorSetKHR(cmd_buf,VK_PIPELINE_BIND_POINT_GRAPHICS,pipeline_layout,set,count,write_desc_set);
}
void PushConstants(ShaderStageBit shader_stage_bit,uint32_t offset,uint32_t size,const void *pValues)
void PushConstants(VkShaderStageFlagBits shader_stage_bit,uint32_t offset,uint32_t size,const void *pValues)
{
vkCmdPushConstants(cmd_buf,pipeline_layout,(VkShaderStageFlagBits)shader_stage_bit,offset,size,pValues);
}
@@ -155,6 +156,24 @@ public:
void PushConstants(const void *data,const uint32_t size) {vkCmdPushConstants(cmd_buf,pipeline_layout,VK_SHADER_STAGE_VERTEX_BIT,0, size,data);}
void PushConstants(const void *data,const uint32_t offset,const uint32_t size) {vkCmdPushConstants(cmd_buf,pipeline_layout,VK_SHADER_STAGE_VERTEX_BIT,offset, size,data);}
void BindVBO(const uint32_t first,const uint32_t count,const VkBuffer *vbo,const VkDeviceSize *offsets)
{
vkCmdBindVertexBuffers(cmd_buf,first,count,vbo,offsets);
}
bool BindVBO(VBOList *vbo_list)
{
if(!vbo_list)return(false);
if(!vbo_list->IsFull())return(false);
vkCmdBindVertexBuffers(cmd_buf,0,vbo_list->binding_count,vbo_list->buffer_list,vbo_list->buffer_offset);
return(true);
}
void BindIBO(const IndexBufferData *);
bool BindVBO(Renderable *);
void SetViewport (uint32_t first,uint32_t count,const VkViewport *vp) {vkCmdSetViewport(cmd_buf,first,count,vp);}
@@ -176,7 +195,7 @@ public: //draw
void DrawIndexed (const uint32_t index_count ) {vkCmdDrawIndexed(cmd_buf,index_count,1,0,0,0);}
void Draw (const uint32_t vertex_count,const uint32_t instance_count) {vkCmdDraw(cmd_buf,vertex_count,instance_count,0,0);}
void DrawIndexed (const uint32_t index_count ,const uint32_t instance_count) {vkCmdDrawIndexed(cmd_buf,index_count,instance_count,0,0,0);}
template<typename ...ARGS> void Draw (ARGS...args) {vkCmdDraw(cmd_buf,args...);}
template<typename ...ARGS> void DrawIndexed (ARGS...args) {vkCmdDrawIndexed(cmd_buf,args...);}

View File

@@ -2,65 +2,85 @@
#define HGL_GRAPH_VULKAN_DEBUG_MAKER_INCLUDE
#include<hgl/graph/VK.h>
#include<hgl/type/Color4f.h>
#include<hgl/color/Color4f.h>
VK_NAMESPACE_BEGIN
struct DebugMakerFunction
{
PFN_vkDebugMarkerSetObjectTagEXT SetObjectTag;
PFN_vkDebugMarkerSetObjectNameEXT SetObjectName;
PFN_vkCmdDebugMarkerBeginEXT Begin;
PFN_vkCmdDebugMarkerEndEXT End;
PFN_vkCmdDebugMarkerInsertEXT Insert;
PFN_vkDebugMarkerSetObjectTagEXT SetObjectTag;
PFN_vkDebugMarkerSetObjectNameEXT SetObjectName;
PFN_vkCmdDebugMarkerBeginEXT Begin;
PFN_vkCmdDebugMarkerEndEXT End;
PFN_vkCmdDebugMarkerInsertEXT Insert;
};//struct DebugMakerFunction
class DebugMaker
{
VkDevice device;
DebugMakerFunction dmf;
VkDevice device;
DebugMakerFunction dmf;
protected:
void SetObjectName(uint64_t object, VkDebugReportObjectTypeEXT objectType, const char *name);
void SetObjectTag(uint64_t object, VkDebugReportObjectTypeEXT objectType, uint64_t name, size_t tagSize, const void* tag);
void SetObjectName(uint64_t object, VkDebugReportObjectTypeEXT objectType, const char *name);
void SetObjectTag(uint64_t object, VkDebugReportObjectTypeEXT objectType, uint64_t name, size_t tagSize, const void* tag);
private:
friend DebugMaker *CreateDebugMaker(VkDevice device);
friend DebugMaker *CreateDebugMaker(VkDevice device);
DebugMaker(VkDevice dev,const DebugMakerFunction &f)
{
device=dev;
dmf=f;
}
DebugMaker(VkDevice dev,const DebugMakerFunction &f)
{
device=dev;
dmf=f;
}
public:
void Begin(VkCommandBuffer cmdbuffer, const char * pMarkerName, const Color4f &color);
void Insert(VkCommandBuffer cmdbuffer, const char *markerName, const Color4f &color);
void End(VkCommandBuffer cmdBuffer);
#define DEBUG_MAKER_SET_FUNC(type,MNAME) void Set##type##Name(Vk##type obj,const char *name){SetObjectName((uint64_t)obj,VK_DEBUG_REPORT_OBJECT_TYPE_##MNAME##_EXT,name);}
void Begin(VkCommandBuffer cmdbuffer, const char * pMarkerName, const Color4f &color);
void Insert(VkCommandBuffer cmdbuffer, const char *markerName, const Color4f &color);
void End(VkCommandBuffer cmdBuffer);
#define DEBUG_MAKER_SET_FUNC(type,MNAME) void Set##type(Vk##type obj,const char *name){SetObjectName((uint64_t)obj,VK_DEBUG_REPORT_OBJECT_TYPE_##MNAME##_EXT,name);}
DEBUG_MAKER_SET_FUNC(CommandBuffer, COMMAND_BUFFER)
DEBUG_MAKER_SET_FUNC(Queue, QUEUE)
DEBUG_MAKER_SET_FUNC(Image, IMAGE)
DEBUG_MAKER_SET_FUNC(Sampler, SAMPLER)
DEBUG_MAKER_SET_FUNC(Buffer, BUFFER)
DEBUG_MAKER_SET_FUNC(DeviceMemory, DEVICE_MEMORY)
DEBUG_MAKER_SET_FUNC(ShaderModule, SHADER_MODULE)
DEBUG_MAKER_SET_FUNC(Pipeline, PIPELINE)
DEBUG_MAKER_SET_FUNC(PipelineLayout, PIPELINE_LAYOUT)
DEBUG_MAKER_SET_FUNC(RenderPass, RENDER_PASS)
DEBUG_MAKER_SET_FUNC(Framebuffer, FRAMEBUFFER)
DEBUG_MAKER_SET_FUNC(DescriptorSetLayout, DESCRIPTOR_SET_LAYOUT)
DEBUG_MAKER_SET_FUNC(DescriptorSet, DESCRIPTOR_SET)
DEBUG_MAKER_SET_FUNC(Semaphore, SEMAPHORE)
DEBUG_MAKER_SET_FUNC(Fence, FENCE)
DEBUG_MAKER_SET_FUNC(Event, EVENT)
#undef DEBUG_MAKER_SET_FUNC
DEBUG_MAKER_SET_FUNC(Instance, INSTANCE)
DEBUG_MAKER_SET_FUNC(PhysicalDevice, PHYSICAL_DEVICE)
DEBUG_MAKER_SET_FUNC(Device, DEVICE)
DEBUG_MAKER_SET_FUNC(Queue, QUEUE)
DEBUG_MAKER_SET_FUNC(Semaphore, SEMAPHORE)
DEBUG_MAKER_SET_FUNC(CommandBuffer, COMMAND_BUFFER)
DEBUG_MAKER_SET_FUNC(Fence, FENCE)
DEBUG_MAKER_SET_FUNC(DeviceMemory, DEVICE_MEMORY)
DEBUG_MAKER_SET_FUNC(Buffer, BUFFER)
DEBUG_MAKER_SET_FUNC(Image, IMAGE)
DEBUG_MAKER_SET_FUNC(Event, EVENT)
DEBUG_MAKER_SET_FUNC(QueryPool, QUERY_POOL)
DEBUG_MAKER_SET_FUNC(BufferView, BUFFER_VIEW)
DEBUG_MAKER_SET_FUNC(ShaderModule, SHADER_MODULE)
DEBUG_MAKER_SET_FUNC(PipelineCache, PIPELINE_CACHE)
DEBUG_MAKER_SET_FUNC(PipelineLayout, PIPELINE_LAYOUT)
DEBUG_MAKER_SET_FUNC(RenderPass, RENDER_PASS)
DEBUG_MAKER_SET_FUNC(Pipeline, PIPELINE)
DEBUG_MAKER_SET_FUNC(DescriptorSetLayout, DESCRIPTOR_SET_LAYOUT)
DEBUG_MAKER_SET_FUNC(Sampler, SAMPLER)
DEBUG_MAKER_SET_FUNC(DescriptorPool, DESCRIPTOR_POOL)
DEBUG_MAKER_SET_FUNC(DescriptorSet, DESCRIPTOR_SET)
DEBUG_MAKER_SET_FUNC(Framebuffer, FRAMEBUFFER)
DEBUG_MAKER_SET_FUNC(CommandPool, COMMAND_POOL)
DEBUG_MAKER_SET_FUNC(SurfaceKHR, SURFACE_KHR)
DEBUG_MAKER_SET_FUNC(SwapchainKHR, SWAPCHAIN_KHR)
DEBUG_MAKER_SET_FUNC(DebugReportCallbackEXT, DEBUG_REPORT_CALLBACK_EXT)
DEBUG_MAKER_SET_FUNC(DisplayKHR, DISPLAY_KHR)
DEBUG_MAKER_SET_FUNC(DisplayModeKHR, DISPLAY_MODE_KHR)
DEBUG_MAKER_SET_FUNC(ValidationCacheEXT, VALIDATION_CACHE_EXT)
DEBUG_MAKER_SET_FUNC(SamplerYcbcrConversion, SAMPLER_YCBCR_CONVERSION)
DEBUG_MAKER_SET_FUNC(DescriptorUpdateTemplate, DESCRIPTOR_UPDATE_TEMPLATE)
DEBUG_MAKER_SET_FUNC(CuModuleNVX, CU_MODULE_NVX)
DEBUG_MAKER_SET_FUNC(CuFunctionNVX, CU_FUNCTION_NVX)
DEBUG_MAKER_SET_FUNC(AccelerationStructureKHR, ACCELERATION_STRUCTURE_KHR)
DEBUG_MAKER_SET_FUNC(AccelerationStructureNV, ACCELERATION_STRUCTURE_NV)
#undef DEBUG_MAKER_SET_FUNC
};//class DebugMaker
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_DEBUG_MAKER_INCLUDE

View File

@@ -0,0 +1,105 @@
#ifndef HGL_GRAPH_VULKAN_DEBUG_UTILS_INCLUDE
#define HGL_GRAPH_VULKAN_DEBUG_UTILS_INCLUDE
#include<hgl/graph/VK.h>
#include<hgl/color/Color4f.h>
VK_NAMESPACE_BEGIN
struct DebugUtilsFunction
{
PFN_vkSetDebugUtilsObjectNameEXT SetName;
PFN_vkSetDebugUtilsObjectTagEXT SetTag;
PFN_vkQueueBeginDebugUtilsLabelEXT QueueBegin;
PFN_vkQueueEndDebugUtilsLabelEXT QueueEnd;
PFN_vkQueueInsertDebugUtilsLabelEXT QueueInsert;
PFN_vkCmdBeginDebugUtilsLabelEXT CmdBegin;
PFN_vkCmdEndDebugUtilsLabelEXT CmdEnd;
PFN_vkCmdInsertDebugUtilsLabelEXT CmdInsert;
};//struct DebugUtilsFunction
class DebugUtils
{
VkDevice device;
DebugUtilsFunction duf;
private:
friend DebugUtils *CreateDebugUtils(VkDevice);
DebugUtils(VkDevice dev,const DebugUtilsFunction &f)
{
device=dev;
duf=f;
}
public:
~DebugUtils()=default;
void SetName(VkObjectType,uint64_t,const char *);
#define DU_FUNC(n,N) void Set##n(Vk##n obj,const char *name){SetName(VK_OBJECT_TYPE_##N,(uint64_t)obj,name);}
DU_FUNC(Instance ,INSTANCE )
DU_FUNC(PhysicalDevice ,PHYSICAL_DEVICE )
DU_FUNC(Device ,DEVICE )
DU_FUNC(Queue ,QUEUE )
DU_FUNC(Semaphore ,SEMAPHORE )
DU_FUNC(CommandBuffer ,COMMAND_BUFFER )
DU_FUNC(Fence ,FENCE )
DU_FUNC(DeviceMemory ,DEVICE_MEMORY )
DU_FUNC(Buffer ,BUFFER )
DU_FUNC(Image ,IMAGE )
DU_FUNC(Event ,EVENT )
DU_FUNC(QueryPool ,QUERY_POOL )
DU_FUNC(BufferView ,BUFFER_VIEW )
DU_FUNC(ImageView ,IMAGE_VIEW )
DU_FUNC(ShaderModule ,SHADER_MODULE )
DU_FUNC(PipelineCache ,PIPELINE_CACHE )
DU_FUNC(PipelineLayout ,PIPELINE_LAYOUT )
DU_FUNC(RenderPass ,RENDER_PASS )
DU_FUNC(Pipeline ,PIPELINE )
DU_FUNC(DescriptorSetLayout ,DESCRIPTOR_SET_LAYOUT )
DU_FUNC(Sampler ,SAMPLER )
DU_FUNC(DescriptorPool ,DESCRIPTOR_POOL )
DU_FUNC(DescriptorSet ,DESCRIPTOR_SET )
DU_FUNC(Framebuffer ,FRAMEBUFFER )
DU_FUNC(CommandPool ,COMMAND_POOL )
DU_FUNC(SamplerYcbcrConversion, SAMPLER_YCBCR_CONVERSION)
DU_FUNC(DescriptorUpdateTemplate, DESCRIPTOR_UPDATE_TEMPLATE)
DU_FUNC(PrivateDataSlot, PRIVATE_DATA_SLOT)
DU_FUNC(SurfaceKHR, SURFACE_KHR)
DU_FUNC(SwapchainKHR, SWAPCHAIN_KHR)
DU_FUNC(DisplayKHR, DISPLAY_KHR)
DU_FUNC(DisplayModeKHR, DISPLAY_MODE_KHR)
DU_FUNC(DebugReportCallbackEXT, DEBUG_REPORT_CALLBACK_EXT)
#ifdef VK_ENABLE_BETA_EXTENSIONS
DU_FUNC(VideoSessionKHR, VIDEO_SESSION_KHR)
DU_FUNC(VideoSessionParametersKHR, VIDEO_SESSION_PARAMETERS_KH)
#endif//VK_ENABLE_BETA_EXTENSIONS
DU_FUNC(CuModuleNVX, CU_MODULE_NVX)
DU_FUNC(CuFunctionNVX, CU_FUNCTION_NVX)
DU_FUNC(DebugUtilsMessengerEXT, DEBUG_UTILS_MESSENGER_EXT)
DU_FUNC(AccelerationStructureKHR, ACCELERATION_STRUCTURE_KHR)
DU_FUNC(ValidationCacheEXT, VALIDATION_CACHE_EXT)
DU_FUNC(AccelerationStructureNV, ACCELERATION_STRUCTURE_NV)
DU_FUNC(PerformanceConfigurationINTEL, PERFORMANCE_CONFIGURATION_INTEL)
DU_FUNC(DeferredOperationKHR, DEFERRED_OPERATION_KHR)
DU_FUNC(IndirectCommandsLayoutNV, INDIRECT_COMMANDS_LAYOUT_NV)
// DU_FUNC(BufferCollectionFuchsia, BUFFER_COLLECTION_FUCHSIA)
#undef DU_FUNC
void QueueBegin (VkQueue,const char *,const Color4f &color=Color4f(1,1,1,1));
void QueueEnd (VkQueue q){duf.QueueEnd(q);}
void QueueInsert (VkQueue q,const char *,const Color4f &color=Color4f(1,1,1,1));
void CmdBegin (VkCommandBuffer,const char *,const Color4f &color=Color4f(1,1,1,1));
void CmdEnd (VkCommandBuffer cmd_buf){duf.CmdEnd(cmd_buf);}
void CmdInsert (VkCommandBuffer cmd_buf,const char *,const Color4f &color=Color4f(1,1,1,1));
};//class DebugUtils
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_DEBUG_UTILS_INCLUDE

View File

@@ -0,0 +1,100 @@
#ifndef HGL_GRAPH_DESCRIPTOR_BINDING_MANAGE_INCLUDE
#define HGL_GRAPH_DESCRIPTOR_BINDING_MANAGE_INCLUDE
#include<hgl/type/Map.h>
#include<hgl/type/String.h>
#include<hgl/graph/VKDescriptorSetType.h>
namespace hgl
{
namespace graph
{
class DeviceBuffer;
class Texture;
class Material;
class DescriptorBinding
{
DescriptorSetType set_type;
Map<AnsiString,DeviceBuffer *> ubo_map;
Map<AnsiString,DeviceBuffer *> ssbo_map;
Map<AnsiString,Texture *> texture_map;
public:
DescriptorBinding(const DescriptorSetType &dst)
{
set_type=dst;
}
bool AddUBO(const AnsiString &name,DeviceBuffer *buf)
{
if(!buf)return(false);
if(name.IsEmpty())return(false);
return ubo_map.Add(name,buf);
}
DeviceBuffer *GetUBO(const AnsiString &name)
{
if(name.IsEmpty())return(nullptr);
return GetListObject(ubo_map,name);
}
void RemoveUBO(DeviceBuffer *buf)
{
if(!buf)return;
ubo_map.DeleteByValue(buf);
}
bool AddSSBO(const AnsiString &name,DeviceBuffer *buf)
{
if(!buf)return(false);
if(name.IsEmpty())return(false);
return ssbo_map.Add(name,buf);
}
DeviceBuffer *GetSSBO(const AnsiString &name)
{
if(name.IsEmpty())return(nullptr);
return GetListObject(ssbo_map,name);
}
void RemoveSSBO(DeviceBuffer *buf)
{
if(!buf)return;
ssbo_map.DeleteByValue(buf);
}
bool AddTexture(const AnsiString &name,Texture *tex)
{
if(!tex)return(false);
if(name.IsEmpty())return(false);
return texture_map.Add(name,tex);
}
Texture *GetTexture(const AnsiString &name)
{
if(name.IsEmpty())return(nullptr);
return GetListObject(texture_map,name);
}
void RemoveTexture(Texture *tex)
{
if(!tex)return;
texture_map.DeleteByValue(tex);
}
bool Bind(Material *);
};//class DescriptorBinding
}//namespace graph
}//namespace hgl
#endif//HGL_GRAPH_DESCRIPTOR_BINDING_MANAGE_INCLUDE

View File

@@ -1,13 +1,14 @@
#ifndef HGL_GRAPH_VULKAN_DESCRIPTOR_SETS_LAYOUT_INCLUDE
#define HGL_GRAPH_VULKAN_DESCRIPTOR_SETS_LAYOUT_INCLUDE
#ifndef HGL_GRAPH_VULKAN_DESCRIPTOR_SET_INCLUDE
#define HGL_GRAPH_VULKAN_DESCRIPTOR_SET_INCLUDE
#include<hgl/graph/VK.h>
#include<hgl/type/Map.h>
#include<hgl/type/ObjectList.h>
#include<hgl/type/SortedSets.h>
VK_NAMESPACE_BEGIN
class GPUBuffer;
class DeviceBuffer;
class DescriptorSets
class DescriptorSet
{
VkDevice device;
int binding_count;
@@ -23,11 +24,9 @@ class DescriptorSets
bool is_dirty;
private:
public:
friend class GPUDevice;
DescriptorSets(VkDevice dev,const int bc,VkPipelineLayout pl,VkDescriptorSet ds)
DescriptorSet(VkDevice dev,const int bc,VkPipelineLayout pl,VkDescriptorSet ds)
{
device =dev;
binding_count =bc;
@@ -37,9 +36,7 @@ private:
is_dirty=true;
}
public:
~DescriptorSets()=default;
~DescriptorSet()=default;
const uint32_t GetCount ()const{return binding_count;}
const VkDescriptorSet GetDescriptorSet ()const{return desc_set;}
@@ -49,14 +46,14 @@ public:
void Clear();
bool BindUBO (const int binding,const GPUBuffer *buf,bool dynamic=false);
bool BindUBO (const int binding,const GPUBuffer *buf,const VkDeviceSize offset,const VkDeviceSize range,bool dynamic=false);
bool BindSSBO (const int binding,const GPUBuffer *buf,bool dynamic=false);
bool BindSSBO (const int binding,const GPUBuffer *buf,const VkDeviceSize offset,const VkDeviceSize range,bool dynamic=false);
bool BindUBO (const int binding,const DeviceBuffer *buf,bool dynamic=false);
bool BindUBO (const int binding,const DeviceBuffer *buf,const VkDeviceSize offset,const VkDeviceSize range,bool dynamic=false);
bool BindSSBO (const int binding,const DeviceBuffer *buf,bool dynamic=false);
bool BindSSBO (const int binding,const DeviceBuffer *buf,const VkDeviceSize offset,const VkDeviceSize range,bool dynamic=false);
bool BindSampler(const int binding,Texture *,Sampler *);
bool BindImageSampler(const int binding,Texture *,Sampler *);
bool BindInputAttachment(const int binding,ImageView *);
void Update();
};//class DescriptorSets
};//class DescriptorSet
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_DESCRIPTOR_SETS_LAYOUT_INCLUDE
#endif//HGL_GRAPH_VULKAN_DESCRIPTOR_SET_INCLUDE

View File

@@ -5,8 +5,9 @@
#include<hgl/type/String.h>
#include<hgl/type/Map.h>
#include<hgl/type/RectScope.h>
#include<hgl/graph/ImageRegion.h>
#include<hgl/platform/Window.h>
#include<hgl/graph/Bitmap.h>
#include<hgl/graph/BitmapData.h>
#include<hgl/graph/font/Font.h>
#include<hgl/graph/VK.h>
#include<hgl/graph/VKDeviceAttribute.h>
@@ -15,35 +16,19 @@
#include<hgl/graph/VertexAttribData.h>
#include<hgl/graph/VKShaderModuleMap.h>
#include<hgl/graph/VKArrayBuffer.h>
namespace hgl
{
namespace graph
{
class TileData;
class TileFont;
class FontSource;
}//namespace graph
}//namespace hgl
#include<hgl/graph/VKDescriptorSetType.h>
VK_NAMESPACE_BEGIN
/*
* GPU设备创建信息
*/
struct GPUDeviceCreateInfo
{
VkPhysicalDeviceType device_type =VK_PHYSICAL_DEVICE_TYPE_MAX_ENUM;
uint32_t swapchain_image_count =0;
VkSurfaceFormatKHR color_format ={PF_A2BGR10UN,VK_COLOR_SPACE_SRGB_NONLINEAR_KHR};
VkFormat depth_format =VK_FORMAT_UNDEFINED;
};//struct GPUDeviceCreateInfo
class TileData;
class TileFont;
class FontSource;
class GPUArrayBuffer;
class GPUDevice
{
GPUDeviceAttribute *attr;
GPUQueue *texture_queue;
DeviceQueue *texture_queue;
TextureCmdBuffer *texture_cmd_buf;
private:
@@ -51,9 +36,9 @@ private:
DeviceRenderPassManage *render_pass_manage;
RenderPass *device_render_pass;
SwapchainRenderTarget *swapchainRT;
RTSwapchain *sc_rt;
SwapchainRenderTarget *CreateSwapchainRenderTarget();
RTSwapchain *CreateSwapchainRenderTarget();
void InitRenderPassManage();
void ClearRenderPassManage();
@@ -68,7 +53,7 @@ private:
private:
friend GPUDevice *CreateRenderDevice(VulkanInstance *inst,const GPUPhysicalDevice *physical_device,VkSurfaceKHR surface,const VkExtent2D &extent);
friend class VulkanDeviceCreater;
GPUDevice(GPUDeviceAttribute *da);
@@ -92,9 +77,9 @@ public:
RenderPass * GetRenderPass () {return device_render_pass;}
SwapchainRenderTarget * GetSwapchainRT () {return swapchainRT;}
RTSwapchain * GetSwapchainRT () {return sc_rt;}
const VkExtent2D & GetSwapchainSize ()const {return swapchainRT->GetExtent();}
const VkExtent2D & GetSwapchainSize ()const {return sc_rt->GetExtent();}
void WaitIdle ()const {vkDeviceWaitIdle(attr->device);}
@@ -110,40 +95,45 @@ public:
public: //内存相关
GPUMemory *CreateMemory(const VkMemoryRequirements &,const uint32_t properties);
GPUMemory *CreateMemory(VkImage,const uint32 flag=VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
DeviceMemory *CreateMemory(const VkMemoryRequirements &,const uint32_t properties);
DeviceMemory *CreateMemory(VkImage,const uint32 flag=VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
private: //Buffer相关
bool CreateBuffer(GPUBufferData *buf,VkBufferUsageFlags buf_usage,VkDeviceSize range,VkDeviceSize size,const void *data,SharingMode sharing_mode);
bool CreateBuffer(GPUBufferData *buf,VkBufferUsageFlags buf_usage, VkDeviceSize size,const void *data,SharingMode sharing_mode){return CreateBuffer(buf,buf_usage,size,size,data,sharing_mode);}
bool CreateBuffer(DeviceBufferData *buf,VkBufferUsageFlags buf_usage,VkDeviceSize range,VkDeviceSize size,const void *data,SharingMode sharing_mode);
bool CreateBuffer(DeviceBufferData *buf,VkBufferUsageFlags buf_usage, VkDeviceSize size,const void *data,SharingMode sharing_mode){return CreateBuffer(buf,buf_usage,size,size,data,sharing_mode);}
public: //Buffer相关
GPUBuffer * CreateBuffer(VkBufferUsageFlags buf_usage,VkDeviceSize range,VkDeviceSize size,const void *data, SharingMode sm=SharingMode::Exclusive);
GPUBuffer * CreateBuffer(VkBufferUsageFlags buf_usage,VkDeviceSize range,VkDeviceSize size, SharingMode sm=SharingMode::Exclusive){return CreateBuffer(buf_usage,range,size,nullptr,sm);}
GPUBuffer * CreateBuffer(VkBufferUsageFlags buf_usage, VkDeviceSize size,const void *data, SharingMode sm=SharingMode::Exclusive){return CreateBuffer(buf_usage,size,size,data,sm);}
GPUBuffer * CreateBuffer(VkBufferUsageFlags buf_usage, VkDeviceSize size, SharingMode sm=SharingMode::Exclusive){return CreateBuffer(buf_usage,size,size,nullptr,sm);}
DeviceBuffer * CreateBuffer(VkBufferUsageFlags buf_usage,VkDeviceSize range,VkDeviceSize size,const void *data, SharingMode sm=SharingMode::Exclusive);
DeviceBuffer * CreateBuffer(VkBufferUsageFlags buf_usage,VkDeviceSize range,VkDeviceSize size, SharingMode sm=SharingMode::Exclusive){return CreateBuffer(buf_usage,range,size,nullptr,sm);}
DeviceBuffer * CreateBuffer(VkBufferUsageFlags buf_usage, VkDeviceSize size,const void *data, SharingMode sm=SharingMode::Exclusive){return CreateBuffer(buf_usage,size,size,data,sm);}
DeviceBuffer * CreateBuffer(VkBufferUsageFlags buf_usage, VkDeviceSize size, SharingMode sm=SharingMode::Exclusive){return CreateBuffer(buf_usage,size,size,nullptr,sm);}
VBO * CreateVBO (VkFormat format, uint32_t count,const void *data, SharingMode sm=SharingMode::Exclusive);
VBO * CreateVBO (VkFormat format, uint32_t count, SharingMode sm=SharingMode::Exclusive){return CreateVBO(format,count,nullptr,sm);}
VBO * CreateVBO (const VAD *vad, SharingMode sm=SharingMode::Exclusive){return CreateVBO(vad->GetVulkanFormat(),vad->GetCount(),vad->GetData(),sm);}
VBO * CreateVBO (const VAD *vad, SharingMode sm=SharingMode::Exclusive){return CreateVBO(vad->GetFormat(),vad->GetCount(),vad->GetData(),sm);}
IndexBuffer * CreateIBO (IndexType type, uint32_t count,const void * data, SharingMode sm=SharingMode::Exclusive);
IndexBuffer * CreateIBO8 ( uint32_t count,const void * data, SharingMode sm=SharingMode::Exclusive){return CreateIBO(IndexType::U8, count,(void *)data,sm);}
IndexBuffer * CreateIBO16 ( uint32_t count,const uint16 *data, SharingMode sm=SharingMode::Exclusive){return CreateIBO(IndexType::U16, count,(void *)data,sm);}
IndexBuffer * CreateIBO32 ( uint32_t count,const uint32 *data, SharingMode sm=SharingMode::Exclusive){return CreateIBO(IndexType::U32, count,(void *)data,sm);}
IndexBuffer * CreateIBO (IndexType type, uint32_t count, SharingMode sm=SharingMode::Exclusive){return CreateIBO(type, count,nullptr,sm);}
IndexBuffer * CreateIBO8 ( uint32_t count, SharingMode sm=SharingMode::Exclusive){return CreateIBO(IndexType::U8, count,nullptr,sm);}
IndexBuffer * CreateIBO16 ( uint32_t count, SharingMode sm=SharingMode::Exclusive){return CreateIBO(IndexType::U16, count,nullptr,sm);}
IndexBuffer * CreateIBO32 ( uint32_t count, SharingMode sm=SharingMode::Exclusive){return CreateIBO(IndexType::U32, count,nullptr,sm);}
const VkDeviceSize GetUBOAlign();
const VkDeviceSize GetSSBOAlign();
const VkDeviceSize GetUBORange();
const VkDeviceSize GetSSBORange();
#define CREATE_BUFFER_OBJECT(LargeName,type) GPUBuffer *Create##LargeName( VkDeviceSize size,void *data, SharingMode sm=SharingMode::Exclusive) {return CreateBuffer(VK_BUFFER_USAGE_##type##_BUFFER_BIT,size ,size,data, sm);} \
GPUBuffer *Create##LargeName( VkDeviceSize size, SharingMode sm=SharingMode::Exclusive) {return CreateBuffer(VK_BUFFER_USAGE_##type##_BUFFER_BIT,size ,size,nullptr, sm);} \
GPUBuffer *Create##LargeName(VkDeviceSize range,VkDeviceSize size,void *data, SharingMode sm=SharingMode::Exclusive) {return CreateBuffer(VK_BUFFER_USAGE_##type##_BUFFER_BIT,range,size,data, sm);} \
GPUBuffer *Create##LargeName(VkDeviceSize range,VkDeviceSize size, SharingMode sm=SharingMode::Exclusive) {return CreateBuffer(VK_BUFFER_USAGE_##type##_BUFFER_BIT,range,size,nullptr, sm);}
#define CREATE_BUFFER_OBJECT(LargeName,type) DeviceBuffer *Create##LargeName( VkDeviceSize size,void *data, SharingMode sm=SharingMode::Exclusive) {return CreateBuffer(VK_BUFFER_USAGE_##type##_BUFFER_BIT,size ,size,data, sm);} \
DeviceBuffer *Create##LargeName( VkDeviceSize size, SharingMode sm=SharingMode::Exclusive) {return CreateBuffer(VK_BUFFER_USAGE_##type##_BUFFER_BIT,size ,size,nullptr, sm);} \
DeviceBuffer *Create##LargeName(VkDeviceSize range,VkDeviceSize size,void *data, SharingMode sm=SharingMode::Exclusive) {return CreateBuffer(VK_BUFFER_USAGE_##type##_BUFFER_BIT,range,size,data, sm);} \
DeviceBuffer *Create##LargeName(VkDeviceSize range,VkDeviceSize size, SharingMode sm=SharingMode::Exclusive) {return CreateBuffer(VK_BUFFER_USAGE_##type##_BUFFER_BIT,range,size,nullptr, sm);}
CREATE_BUFFER_OBJECT(UBO,UNIFORM)
CREATE_BUFFER_OBJECT(SSBO,STORAGE)
@@ -151,6 +141,9 @@ public: //Buffer相关
#undef CREATE_BUFFER_OBJECT
GPUArrayBuffer *CreateArrayInUBO(const VkDeviceSize &uint_size);
GPUArrayBuffer *CreateArrayInSSBO(const VkDeviceSize &uint_size);
public: //Image
VkImage CreateImage (VkImageCreateInfo *);
@@ -158,13 +151,13 @@ public: //Image
private: //texture
bool CommitTexture (Texture *,GPUBuffer *buf,const VkBufferImageCopy *,const int count,const uint32_t layer_count,VkPipelineStageFlags);//=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
bool CommitTexture (Texture *,DeviceBuffer *buf,const VkBufferImageCopy *,const int count,const uint32_t layer_count,VkPipelineStageFlags);//=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
bool CommitTexture2D (Texture2D *,GPUBuffer *buf,VkPipelineStageFlags stage);
bool CommitTexture2DMipmaps (Texture2D *,GPUBuffer *buf,const VkExtent3D &,uint32_t);
bool CommitTexture2D (Texture2D *,DeviceBuffer *buf,VkPipelineStageFlags stage);
bool CommitTexture2DMipmaps (Texture2D *,DeviceBuffer *buf,const VkExtent3D &,uint32_t);
bool CommitTextureCube (TextureCube *,GPUBuffer *buf,const uint32_t mipmaps_zero_bytes,VkPipelineStageFlags stage);
bool CommitTextureCubeMipmaps (TextureCube *,GPUBuffer *buf,const VkExtent3D &,uint32_t);
bool CommitTextureCube (TextureCube *,DeviceBuffer *buf,const uint32_t mipmaps_zero_bytes,VkPipelineStageFlags stage);
bool CommitTextureCubeMipmaps (TextureCube *,DeviceBuffer *buf,const VkExtent3D &,uint32_t);
bool SubmitTexture (const VkCommandBuffer *cmd_bufs,const uint32_t count=1); ///<提交纹理处理到队列
@@ -182,32 +175,9 @@ public: //Texture
void Clear(TextureCreateInfo *);
bool ChangeTexture2D(Texture2D *,GPUBuffer *buf,const List<Image2DRegion> &, VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
bool ChangeTexture2D(Texture2D *,GPUBuffer *buf,uint32_t left,uint32_t top,uint32_t width,uint32_t height, VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
bool ChangeTexture2D(Texture2D *,void *data, uint32_t left,uint32_t top,uint32_t width,uint32_t height,uint32_t size,VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
template<typename T>
bool ChangeTexture2D(Texture2D *tex,GPUBuffer *buf,const RectScope2<T> &rs)
{
return ChangeTexture2D( tex,
buf,
rs.GetLeft(),
rs.GetTop(),
rs.GetWidth(),
rs.GetHeight());
}
template<typename T>
bool ChangeTexture2D(Texture2D *tex,void *data,const RectScope2<T> &rs,uint32_t size)
{
return ChangeTexture2D( tex,
data,
rs.GetLeft(),
rs.GetTop(),
rs.GetWidth(),
rs.GetHeight(),
size);
}
bool ChangeTexture2D(Texture2D *,DeviceBuffer *buf, const List<Image2DRegion> &,VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
bool ChangeTexture2D(Texture2D *,DeviceBuffer *buf, const RectScope2ui &, VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
bool ChangeTexture2D(Texture2D *,void *data,const uint32_t size,const RectScope2ui &, VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
public: //
@@ -216,20 +186,11 @@ public: //
public: //shader & material
PipelineLayoutData *CreatePipelineLayoutData(const MaterialDescriptorSets *);
void Destroy(PipelineLayoutData *);
ShaderModule *CreateShaderModule(VkShaderStageFlagBits,const uint32_t *,const size_t);
DescriptorSets * CreateDescriptorSets(const PipelineLayoutData *,const DescriptorSetsType &type)const;
MaterialParameters *CreateMP(const MaterialDescriptorSets *,const PipelineLayoutData *,const DescriptorSetsType &);
MaterialParameters *CreateMP(Material *,const DescriptorSetsType &);
ShaderModule *CreateShaderModule(ShaderResource *);
Material *CreateMaterial(const UTF8String &mtl_name,ShaderModuleMap *shader_maps,MaterialDescriptorSets *);
Material *CreateMaterial(const UTF8String &mtl_name,const VertexShaderModule *vertex_shader_module,const ShaderModule *fragment_shader_module,MaterialDescriptorSets *);
Material *CreateMaterial(const UTF8String &mtl_name,const VertexShaderModule *vertex_shader_module,const ShaderModule *geometry_shader_module,const ShaderModule *fragment_shader_module,MaterialDescriptorSets *);
PipelineLayoutData *CreatePipelineLayoutData(const MaterialDescriptorManager *desc_manager);
MaterialInstance *CreateMI(Material *,const VABConfigInfo *vab_cfg=nullptr);
MaterialParameters *CreateMP(const MaterialDescriptorManager *desc_manager,const PipelineLayoutData *pld,const DescriptorSetType &desc_set_type);
public: //Command Buffer 相关
@@ -238,32 +199,30 @@ public: //Command Buffer 相关
public:
RenderPass * AcquireRenderPass( const RenderbufferInfo *,const uint subpass_count=2);
RenderPass * AcquireRenderPass( const RenderbufferInfo *,const uint subpass_count=2);
GPUFence * CreateFence(bool);
GPUSemaphore * CreateGPUSemaphore();
Fence * CreateFence(bool);
Semaphore * CreateGPUSemaphore();
GPUQueue * CreateQueue(const uint32_t fence_count=1,const bool create_signaled=false);
DeviceQueue *CreateQueue(const uint32_t fence_count=1,const bool create_signaled=false);
public: //FrameBuffer相关
Framebuffer *CreateFramebuffer(RenderPass *rp,ImageView **color_list,const uint color_count,ImageView *depth);
// Framebuffer *CreateFramebuffer(RenderPass *,List<ImageView *> &color,ImageView *depth);
Framebuffer *CreateFramebuffer(RenderPass *,ImageView *color,ImageView *depth);
Framebuffer *CreateFramebuffer(RenderPass *,ImageView *);
Framebuffer *CreateFBO(RenderPass *rp,ImageView **color_list,const uint color_count,ImageView *depth);
// Framebuffer *CreateFBO(RenderPass *,List<ImageView *> &color,ImageView *depth);
Framebuffer *CreateFBO(RenderPass *,ImageView *color,ImageView *depth);
Framebuffer *CreateFBO(RenderPass *,ImageView *);
public:
RenderTarget *CreateRenderTarget( const FramebufferInfo *fbi,RenderPass *,const uint32_t fence_count=1);
RenderTarget *CreateRenderTarget( const FramebufferInfo *fbi,const uint32_t fence_count=1);
RenderTarget *CreateRT( const FramebufferInfo *fbi,RenderPass *,const uint32_t fence_count=1);
RenderTarget *CreateRT( const FramebufferInfo *fbi,const uint32_t fence_count=1);
public:
TileData *CreateTileData(const VkFormat video_format,const uint width,const uint height,const uint count); ///<创建一个Tile数据集
TileFont *CreateTileFont(FontSource *fs,int limit_count=-1); ///<创建一个Tile字体
TileFont *CreateTileFont(FontSource *fs,int limit_count=-1); ///<创建一个Tile字体
};//class GPUDevice
GPUDevice *CreateRenderDevice(VulkanInstance *inst,Window *win,const GPUPhysicalDevice *physical_device=nullptr);
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_DEVICE_INCLUDE

View File

@@ -5,6 +5,7 @@
#ifdef _DEBUG
#include<hgl/graph/VKDebugMaker.h>
#include<hgl/graph/VKDebugUtils.h>
#endif//_DEBUG
VK_NAMESPACE_BEGIN
@@ -21,17 +22,18 @@ struct GPUDeviceAttribute
VkSurfaceKHR surface =VK_NULL_HANDLE;
VkSurfaceCapabilitiesKHR surface_caps;
uint32_t graphics_family =ERROR_FAMILY_INDEX;
uint32_t present_family =ERROR_FAMILY_INDEX;
uint32_t compute_family =ERROR_FAMILY_INDEX;
uint32_t graphics_family =ERROR_FAMILY_INDEX;
uint32_t present_family =ERROR_FAMILY_INDEX;
uint32_t compute_family =ERROR_FAMILY_INDEX;
uint32_t video_decode_family =ERROR_FAMILY_INDEX;
#ifdef VK_ENABLE_BETA_EXTENSIONS
uint32_t video_encode_family =ERROR_FAMILY_INDEX;
#endif//VK_ENABLE_BETA_EXTENSIONS
VkQueue graphics_queue =VK_NULL_HANDLE;
VkQueue present_queue =VK_NULL_HANDLE;
List<VkQueueFamilyProperties> family_properties;
List<VkBool32> supports_present;
List<VkSurfaceFormatKHR> surface_formats_list;
VkSurfaceFormatKHR surface_format;
List<VkPresentModeKHR> present_modes;
@@ -44,9 +46,10 @@ struct GPUDeviceAttribute
VkDescriptorPool desc_pool =VK_NULL_HANDLE;
VkPipelineCache pipeline_cache =VK_NULL_HANDLE;
#ifdef _DEBUG
DebugMaker * debug_maker =nullptr;
DebugUtils * debug_utils =nullptr;
#endif//_DEBUG
public:

View File

@@ -0,0 +1,312 @@
#pragma once
#include<hgl/graph/VK.h>
#include<hgl/graph/VKDevice.h>
VK_NAMESPACE_BEGIN
struct VulkanHardwareRequirement
{
uint min_1d_image_size;
uint min_2d_image_size;
uint min_3d_image_size;
uint min_cube_image_size;
uint min_array_image_layers;
uint min_vertex_input_attribute; ///<最小顶点输入属性数量需求
uint min_color_attachments; ///<最小颜色输出成份数量需求
uint min_push_constant_size; ///<最小push constant大小
uint min_ubo_range; ///<最小ubo range需求
uint min_ssbo_range; ///<最小ssbo range需求
uint min_draw_indirect_count; ///<最小间接绘制次数需求
bool geometry_shader; ///<要求支持几何着色器
bool tessellation_shader; ///<要求支持细分着色器
// bool compute_shader; ///<要求支持计算着色器
bool multi_draw_indirect; ///<要求支持MultiDrawIndirect
bool wide_lines; ///<要求支持宽线条
bool line_rasterization; ///<要支持线条特性(这功能mac/ios平台不支持)
bool large_points; ///<要求支持绘制大点
bool texture_cube_array; ///<要求支持立方体数组纹理
bool uint8_draw_index; ///<要求支持8位索引
bool uint32_draw_index; ///<要求支持32位索引(不建议使用)
struct
{
bool bc,etc2,astc_ldr,astc_hdr,pvrtc; ///<要求支持的压缩纹理格式
}texture_compression;
//dynamic_state VK_EXT_extended_dynamic_state
// cull mode
// front face
// primitive topology
// viewport
// scissor
// bind vbo
// depth test
// depth write
// depth compare op
// depth bounds test
// stencil test
// stencil op
//dynamic_state[1] VK_EXT_extended_dynamic_state2
// patch control points
// rasterizer discard
// depth bias
// logic op
// primitive restart
//dynamic_state[2] VK_EXT_extended_dynamic_state3
// tess domain origin
// depth clamp
// discard polygon mode
// rasterization samples
// sample mask
// alpha to coverage
// alpha to one
// logic op enable
// color blend
// color blend equation
// color write mask
// depth clamp
// Color blend advanced
// line rasterization mode
// line stipple
// depth clip -1 to 1
// shading rate image enable
bool dynamic_state[3]; ///<要求支持动态状态
// 1.3 特性
bool dynamic_rendering; ///<要求支持动态渲染
uint32_t descriptor_pool; ///<描述符池大小(默认1024)
public:
VulkanHardwareRequirement()
{
hgl_zero(*this);
descriptor_pool=1024;
}
};
constexpr const VkFormat SwapchainPreferFormatsLDR[]=
{
PF_RGB5A1,
PF_BGR5A1,
PF_A1RGB5,
PF_RGB565,
PF_BGR565,
};
constexpr const VkFormat SwapchainPreferFormatsSDR[]=
{
PF_RGBA8UN,//PF_RGBA8s,
PF_BGRA8UN,//PF_BGRA8s,
PF_ABGR8UN,//PF_ABGR8s,
PF_A2RGB10UN,
PF_A2BGR10UN,
// PF_B10GR11UF
};
constexpr const VkFormat SwapchainPreferFormatsHDR16[]=
{
PF_RGBA16UN,PF_RGBA16SN,PF_RGBA16F
};
constexpr const VkFormat SwapchainPreferFormatsHDR32[]=
{
PF_RGB32F,
PF_RGBA32F
};
constexpr const VkFormat SwapchainPreferFormatsHDR[]=
{
PF_RGBA16UN,PF_RGBA16SN,PF_RGBA16F,
PF_RGB32F,PF_RGBA32F
};
constexpr const VkFormat SwapchainPreferFormatsDepth[]=
{
PF_D16UN,
PF_X8_D24UN,
PF_D16UN_S8U,
PF_D24UN_S8U,
PF_D32F,
PF_D32F_S8U
};
constexpr const VkColorSpaceKHR SwapchainPreferColorSpacesNonlinear[]=
{
VK_COLOR_SPACE_SRGB_NONLINEAR_KHR,
VK_COLOR_SPACE_DISPLAY_P3_NONLINEAR_EXT,
VK_COLOR_SPACE_DCI_P3_NONLINEAR_EXT,
VK_COLOR_SPACE_BT709_NONLINEAR_EXT,
VK_COLOR_SPACE_ADOBERGB_NONLINEAR_EXT,
VK_COLOR_SPACE_EXTENDED_SRGB_NONLINEAR_EXT,
VK_COLOR_SPACE_DISPLAY_NATIVE_AMD,
};
constexpr const VkColorSpaceKHR SwapchainPreferColorSpacesLinear[]=
{
VK_COLOR_SPACE_EXTENDED_SRGB_LINEAR_EXT,
VK_COLOR_SPACE_DISPLAY_P3_LINEAR_EXT,
VK_COLOR_SPACE_BT709_LINEAR_EXT,
VK_COLOR_SPACE_BT2020_LINEAR_EXT,
VK_COLOR_SPACE_HDR10_ST2084_EXT,
VK_COLOR_SPACE_DOLBYVISION_EXT,
VK_COLOR_SPACE_HDR10_HLG_EXT,
VK_COLOR_SPACE_ADOBERGB_LINEAR_EXT,
};
struct PreferFormats
{
//偏好格式需从低质量到高质量排列
const VkFormat *formats;
uint count;
public:
const int Find(const VkFormat fmt)const
{
for(uint i=0;i<count;i++)
if(fmt==formats[i])
return i;
return -1;
}
};
struct PreferColorSpaces
{
//偏好格式需从低质量到高质量排列
const VkColorSpaceKHR *colorspaces;
uint count;
public:
const int Find(const VkColorSpaceKHR cs)const
{
for(uint i=0;i<count;i++)
if(cs==colorspaces[i])
return i;
return -1;
}
};
constexpr const PreferFormats PreferLDR {SwapchainPreferFormatsLDR, sizeof(SwapchainPreferFormatsLDR )/sizeof(VkFormat)};
constexpr const PreferFormats PreferSDR {SwapchainPreferFormatsSDR, sizeof(SwapchainPreferFormatsSDR )/sizeof(VkFormat)};
constexpr const PreferFormats PreferHDR16{SwapchainPreferFormatsHDR16, sizeof(SwapchainPreferFormatsHDR16 )/sizeof(VkFormat)};
constexpr const PreferFormats PreferHDR32{SwapchainPreferFormatsHDR32, sizeof(SwapchainPreferFormatsHDR32 )/sizeof(VkFormat)};
constexpr const PreferFormats PreferHDR {SwapchainPreferFormatsHDR, sizeof(SwapchainPreferFormatsHDR )/sizeof(VkFormat)};
constexpr const PreferFormats PreferDepth{SwapchainPreferFormatsDepth, sizeof(SwapchainPreferFormatsDepth )/sizeof(VkFormat)};
constexpr const PreferColorSpaces PreferNonlinear {SwapchainPreferColorSpacesNonlinear, sizeof(SwapchainPreferColorSpacesNonlinear )/sizeof(VkColorSpaceKHR)};
constexpr const PreferColorSpaces PreferLinear {SwapchainPreferColorSpacesLinear, sizeof(SwapchainPreferColorSpacesLinear )/sizeof(VkColorSpaceKHR)};
/**
* Vulkan设备创建器<br>
* 将此功能定义为类是为了让开发者方便重载处理
*/
class VulkanDeviceCreater
{
protected:
VulkanInstance *instance;
Window *window;
const GPUPhysicalDevice *physical_device;
VulkanHardwareRequirement require;
VkExtent2D extent;
const PreferFormats * perfer_color_formats;
const PreferColorSpaces * perfer_color_spaces;
const PreferFormats * perfer_depth_formats;
VkSurfaceKHR surface;
VkSurfaceFormatKHR surface_format;
CharPointerList ext_list;
VkPhysicalDeviceFeatures features={};
protected:
VkDevice CreateDevice(const uint32_t);
public:
VulkanDeviceCreater(VulkanInstance *vi,
Window *win,
const PreferFormats *spf_color,
const PreferColorSpaces *spf_color_space,
const PreferFormats *spf_depth,
const VulkanHardwareRequirement *req);
virtual bool ChoosePhysicalDevice();
virtual bool RequirementCheck();
virtual void ChooseSurfaceFormat();
virtual GPUDevice *CreateRenderDevice();
public:
virtual GPUDevice *Create();
};//class VulkanDeviceCreater
inline GPUDevice *CreateRenderDevice( VulkanInstance *vi,
Window *win,
const PreferFormats * spf_color =&PreferSDR,
const PreferColorSpaces * spf_color_space =&PreferNonlinear,
const PreferFormats * spf_depth =&PreferDepth,
const VulkanHardwareRequirement *req=nullptr)
{
VulkanDeviceCreater vdc(vi,win,spf_color,spf_color_space,spf_depth,req);
return vdc.Create();
}
inline GPUDevice *CreateRenderDeviceLDR(VulkanInstance *vi,
Window *win,
const VulkanHardwareRequirement *req=nullptr)
{
return CreateRenderDevice(vi,win,&PreferLDR,&PreferNonlinear,&PreferDepth,req);
}
inline GPUDevice *CreateRenderDeviceSDR(VulkanInstance *vi,
Window *win,
const VulkanHardwareRequirement *req=nullptr)
{
return CreateRenderDevice(vi,win,&PreferSDR,&PreferNonlinear,&PreferDepth,req);
}
inline GPUDevice *CreateRenderDeviceHDR16( VulkanInstance *vi,
Window *win,
const VulkanHardwareRequirement *req=nullptr)
{
return CreateRenderDevice(vi,win,&PreferHDR16,&PreferLinear,&PreferDepth,req);
}
inline GPUDevice *CreateRenderDeviceHDR32( VulkanInstance *vi,
Window *win,
const VulkanHardwareRequirement *req=nullptr)
{
return CreateRenderDevice(vi,win,&PreferHDR32,&PreferLinear,&PreferDepth,req);
}
inline GPUDevice *CreateRenderDeviceHDR(VulkanInstance *vi,
Window *win,
const VulkanHardwareRequirement *req=nullptr)
{
return CreateRenderDevice(vi,win,&PreferHDR,&PreferLinear,&PreferDepth,req);
}
VK_NAMESPACE_END

View File

@@ -0,0 +1,79 @@
#ifndef HGL_GRAPH_DYNAMIC_BUFFER_ACCESS_INCLUDE
#define HGL_GRAPH_DYNAMIC_BUFFER_ACCESS_INCLUDE
#include<hgl/graph/VKArrayBuffer.h>
VK_NAMESPACE_BEGIN
template<typename T> class DynamicBufferAccess
{
uchar *pointer;
uchar *current;
uint align_size;
uint count;
uint index;
private:
DynamicBufferAccess()
{
Restart();
}
void Restart()
{
pointer=nullptr;
current=nullptr;
align_size=0;
count=0;
index=0;
}
void Start(uchar *buf,const uint as,const uint c)
{
current=pointer=buf;
align_size=as;
count=c;
index=0;
}
friend class GPUArrayBuffer;
public:
const uint GetCount()const{return count;}
const uint GetCurrentIndex()const{return index;}
const uint GetOffsetBytes()const{return index*align_size;}
bool Write(uchar *src)
{
if(!src)return(false);
if(index>=count)return(false);
memcpy(current,src,sizeof(T));
current+=align_size;
++index;
return(true);
}
bool Write(uchar *src,const uint c)
{
if(!src)return(false);
if(c<=0)return(false);
if(index+c>count)return(false);
for(uint i=0;i<c;i++)
{
memcpy(current,src,sizeof(T));
current+=align_size;
src+=sizeof(T);
}
index+=c;
return(true);
}
};//template<typename T> class DynamicBufferAccess
VK_NAMESPACE_END
#endif//HGL_GRAPH_DYNAMIC_BUFFER_ACCESS_INCLUDE

View File

@@ -3,7 +3,7 @@
#include<hgl/graph/VK.h>
VK_NAMESPACE_BEGIN
class GPUFence
class Fence
{
VkDevice device;
VkFence fence;
@@ -12,7 +12,7 @@ private:
friend class GPUDevice;
GPUFence(VkDevice d,VkFence f)
Fence(VkDevice d,VkFence f)
{
device=d;
fence=f;
@@ -20,9 +20,9 @@ private:
public:
~GPUFence();
~Fence();
operator VkFence(){return fence;}
};//class GPUFence
};//class Fence
VK_NAMESPACE_END
#endif//HGL_VULKAN_GRAPH_FENCE_INCLUDE

View File

@@ -35,5 +35,7 @@ public:
const uint32_t GetColorCount ()const{return color_count;} ///<取得颜色成分数量
const bool HasDepth ()const{return has_depth;} ///<是否包含深度成分
};//class Framebuffer
using FBO=Framebuffer;
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_FRAMEBUFFER_INCLUDE

View File

@@ -7,7 +7,7 @@ namespace hgl
{
namespace graph
{
class IndexBuffer:public GPUBuffer
class IndexBuffer:public DeviceBuffer
{
IndexType index_type;
uint32_t count;
@@ -16,7 +16,7 @@ namespace hgl
friend class GPUDevice;
IndexBuffer(VkDevice d,const GPUBufferData &vb,IndexType it,uint32_t _count):GPUBuffer(d,vb)
IndexBuffer(VkDevice d,const DeviceBufferData &vb,IndexType it,uint32_t _count):DeviceBuffer(d,vb)
{
index_type=it;
count=_count;
@@ -26,9 +26,9 @@ namespace hgl
~IndexBuffer()=default;
const IndexType GetType ()const{return index_type;}
const uint32 GetCount()const{return count;}
};//class IndexBuffer:public GPUBuffer
const IndexType GetType ()const{return index_type;}
const uint32 GetCount()const{return count;}
};//class IndexBuffer:public DeviceBuffer
}//namespace graph
}//namespace hgl
#endif//HGL_GRAPH_VULKAN_INDEX_BUFFER_INCLUDE

View File

@@ -2,7 +2,7 @@
#define HGL_GRAPH_VULKAN_INSTANCE_INCLUDE
#include<hgl/type/String.h>
#include<hgl/type/List.h>
#include<hgl/type/ObjectList.h>
#include<hgl/platform/Window.h>
#include<hgl/graph/VKPhysicalDevice.h>
#include<hgl/graph/VKDebugOut.h>
@@ -23,7 +23,9 @@ VK_NAMESPACE_BEGIN
struct
{
VK_BOOL1BIT(synchronization2)
VK_BOOL1BIT(validation)
VK_BOOL1BIT(profiles)
}khronos;
struct

View File

@@ -5,72 +5,88 @@
#include<hgl/type/Map.h>
#include<hgl/type/String.h>
#include<hgl/graph/VKShaderModuleMap.h>
#include<hgl/graph/VKDescriptorSetType.h>
namespace hgl
{
class ActiveMemoryBlockManager;
}
VK_NAMESPACE_BEGIN
using ShaderStageCreateInfoList=List<VkPipelineShaderStageCreateInfo>;
struct MaterialData
{
UTF8String name;
ShaderModuleMap *shader_maps;
MaterialDescriptorSets *mds;
VertexShaderModule *vertex_sm;
ShaderStageCreateInfoList shader_stage_list;
PipelineLayoutData *pipeline_layout_data;
struct
{
MaterialParameters *m,*g,*r;
}mp;
private:
friend class Material;
~MaterialData();
};//struct MaterialData
/**
* 材质类<br>
* 用于管理shader提供DescriptorSetLayoutCreater
*/
class Material
{
MaterialData *data;
AnsiString name;
VertexInput *vertex_input;
ShaderModuleMap *shader_maps;
MaterialDescriptorManager *desc_manager;
ShaderStageCreateInfoList shader_stage_list;
PipelineLayoutData *pipeline_layout_data;
MaterialParameters *mp_array[DESCRIPTOR_SET_TYPE_COUNT];
uint32_t mi_data_bytes; ///<实例数据大小
uint32_t mi_max_count; ///<实例一次渲染最大数量限制
ActiveMemoryBlockManager *mi_data_manager;
private:
friend GPUDevice;
friend class RenderResource;
MaterialData *GetMaterialData(){return data;}
Material(const AnsiString &);
public:
Material(MaterialData *md):data(md){}
~Material();
virtual ~Material();
const UTF8String & GetName ()const{return data->name;}
const UTF8String & GetName ()const{return name;}
VertexShaderModule * GetVertexShaderModule () {return data->vertex_sm;}
const VertexInput * GetVertexInput ()const{return vertex_input;}
const ShaderStageCreateInfoList & GetStageList ()const{return data->shader_stage_list;}
const ShaderStageCreateInfoList & GetStageList ()const{return shader_stage_list;}
const MaterialDescriptorSets * GetDescriptorSets ()const{return data->mds;}
const MaterialDescriptorManager * GetDescriptorSets ()const{return desc_manager;}
const VkPipelineLayout GetPipelineLayout ()const;
const PipelineLayoutData * GetPipelineLayoutData ()const{return data->pipeline_layout_data;}
const PipelineLayoutData * GetPipelineLayoutData ()const{return pipeline_layout_data;}
public:
MaterialParameters * GetMP (const DescriptorSetsType &type)
MaterialParameters * GetMP (const DescriptorSetType &type)
{
if(type==DescriptorSetsType::Material )return data->mp.m;else
if(type==DescriptorSetsType::Primitive )return data->mp.r;else
if(type==DescriptorSetsType::Global )return data->mp.g;else
return(nullptr);
RANGE_CHECK_RETURN_NULLPTR(type)
return mp_array[size_t(type)];
}
const bool hasSet (const DescriptorSetType &type)const;
const VIL * GetDefaultVIL()const;
VIL * CreateVIL(const VILConfig *format_map=nullptr);
bool Release(VIL *);
const uint GetVILCount();
public:
const bool HasMI ()const{return mi_data_bytes>0;}
const uint32_t GetMIDataBytes ()const{return mi_data_bytes;}
const uint32_t GetMIMaxCount ()const{return mi_max_count;}
void ReleaseMI(int); ///<释放材质实例
void *GetMIData(int); ///<取得指定ID号的材质实例数据访问指针
MaterialInstance *CreateMI(const VILConfig *vil_cfg=nullptr);
};//class Material
using MaterialSets=SortedSets<Material *>;
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_MATERIAL_INCLUDE

View File

@@ -0,0 +1,56 @@
#ifndef HGL_GRAPH_VULKAN_MATERIAL_DESCRIPTOR_MANAGER_INCLUDE
#define HGL_GRAPH_VULKAN_MATERIAL_DESCRIPTOR_MANAGER_INCLUDE
#include<hgl/graph/VK.h>
#include<hgl/graph/VKShaderDescriptorSet.h>
VK_NAMESPACE_BEGIN
using BindingMap=Map<AnsiString,int>;
using BindingMapArray=BindingMap[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
class MaterialDescriptorManager
{
UTF8String mtl_name;
BindingMapArray binding_map[DESCRIPTOR_SET_TYPE_COUNT];
private:
VkDescriptorSetLayoutBinding *all_dslb;
DescriptorSetLayoutCreateInfo dsl_ci[DESCRIPTOR_SET_TYPE_COUNT];
public:
MaterialDescriptorManager(const UTF8String &,ShaderDescriptor *,const uint);
MaterialDescriptorManager(const UTF8String &,const ShaderDescriptorSetArray &);
~MaterialDescriptorManager();
const UTF8String &GetMaterialName()const{return mtl_name;}
const uint GetBindCount(const DescriptorSetType &set_type)const
{
RANGE_CHECK_RETURN(set_type,0)
return dsl_ci[size_t(set_type)].bindingCount;
}
const BindingMapArray &GetBindingMap(const DescriptorSetType &set_type)const
{
return binding_map[size_t(set_type)];
}
const int GetBinding(const DescriptorSetType &set_type,const VkDescriptorType &desc_type,const AnsiString &name)const;
const int GetUBO (const DescriptorSetType &set_type,const AnsiString &name,bool dynamic)const{return GetBinding(set_type,dynamic?VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,name);}
const int GetSSBO (const DescriptorSetType &set_type,const AnsiString &name,bool dynamic)const{return GetBinding(set_type,dynamic?VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,name);}
const int GetImageSampler (const DescriptorSetType &set_type,const AnsiString &name )const{return GetBinding(set_type,VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,name);}
const int GetInputAttachment(const DescriptorSetType &set_type,const AnsiString &name )const{return GetBinding(set_type,VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT,name);}
const DescriptorSetLayoutCreateInfo *GetDSLCI(const DescriptorSetType &type)const{return dsl_ci+size_t(type);}
const bool hasSet(const DescriptorSetType &type)const{return dsl_ci[size_t(type)].bindingCount>0;}
//!sd_list_by_set_type[size_t(type)].IsEmpty();}
};//class MaterialDescriptorManager
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_MATERIAL_DESCRIPTOR_MANAGER_INCLUDE

View File

@@ -1,56 +0,0 @@
#ifndef HGL_GRAPH_VULKAN_MATERIAL_DESCRIPTOR_SETS_INCLUDE
#define HGL_GRAPH_VULKAN_MATERIAL_DESCRIPTOR_SETS_INCLUDE
#include<hgl/graph/VK.h>
VK_NAMESPACE_BEGIN
struct ShaderDescriptor
{
char name[128];
VkDescriptorType desc_type;
DescriptorSetsType set_type;
uint32_t set;
uint32_t binding;
uint32_t stage_flag;
};
using ShaderDescriptorList=List<ShaderDescriptor *>;
class MaterialDescriptorSets
{
UTF8String mtl_name;
ShaderDescriptor *sd_list;
uint sd_count;
ShaderDescriptorList descriptor_list[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
Map<AnsiString,ShaderDescriptor *> sd_by_name;
Map<AnsiString,int> binding_map[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
int *binding_list[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
private:
DescriptorSetLayoutCreateInfo sds[size_t(DescriptorSetsType::RANGE_SIZE)];
public:
MaterialDescriptorSets(const UTF8String &,ShaderDescriptor *,const uint);
~MaterialDescriptorSets();
const UTF8String &GetMaterialName()const{return mtl_name;}
const int GetBinding(const VkDescriptorType &desc_type,const AnsiString &name)const;
const int GetUBO (const AnsiString &name,bool dynamic)const{return GetBinding(dynamic?VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,name);}
const int GetSSBO (const AnsiString &name,bool dynamic)const{return GetBinding(dynamic?VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,name);}
const int GetSampler (const AnsiString &name )const{return GetBinding(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,name);}
const int GetAttachment (const AnsiString &name )const{return GetBinding(VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT,name);}
const DescriptorSetLayoutCreateInfo *GetBinding(const DescriptorSetsType &type)const{return sds+size_t(type);}
};//class MaterialDescriptorSets
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_MATERIAL_DESCRIPTOR_SETS_INCLUDE

View File

@@ -1,37 +1,83 @@
#ifndef HGL_GRAPH_VULKAN_MATERIAL_INSTANCE_INCLUDE
#ifndef HGL_GRAPH_VULKAN_MATERIAL_INSTANCE_INCLUDE
#define HGL_GRAPH_VULKAN_MATERIAL_INSTANCE_INCLUDE
#include<hgl/graph/VK.h>
#include<hgl/graph/VKMaterial.h>
VK_NAMESPACE_BEGIN
/**
* <summary>
*
* layout(location=?) in uint MaterialInstanceID
*
* #define MI_MAX_COUNT ??? //该值由引擎根据 UBORange/sizeof(MaterialInstance) 计算出来
*
* struct MaterialInstance //这部分数据即为材质实例的具体数据每一个材质实例类负责提供具体数据。由RenderList合并成一整个UBO
* { //该类数据由DescriptorSetType为PerMaterial的参数构成
* vec4 BaseColor;
* vec4 Emissive;
* vec4 ARM;
* };
*
* layout(set=?,binding=?) uniform Material
* {
* MaterialInstance mi[MI_MAX_COUNT]
* }mtl;
*
* void main()
* {
* MaterialInstance mi=mtl.mi[(MaterialInstanceID>=MI_MAX_COUNT)?:0:MaterialInstanceID]; //如果超出范围则使用0号材质实例数据
*
* vec4 BaseColor =mi.BaseColor;
* vec4 Emissive =mi.Emissive;
*
* float AO =mi.ARM.x;
* float Roughness =mi.ARM.y;
* float Metallic =mi.ARM.z;
*
* </summary>
*/
/**
* 材质实例类<br>
* 材质实例类本质只是提供一个数据区供RenderList合并成一个大UBO。
*/
class MaterialInstance
{
protected:
Material *material;
VAB *vab;
VIL *vil;
MaterialParameters *mp_value;
private:
friend class GPUDevice;
MaterialInstance(Material *,VAB *,MaterialParameters *);
int mi_id;
public:
virtual ~MaterialInstance();
Material * GetMaterial () {return material;}
Material *GetMaterial(){return material;}
const VIL * GetVIL ()const {return vil;}
const VAB *GetVAB()const{return vab;}
MaterialParameters *GetMP(){return mp_value;}
MaterialParameters *GetMP(const DescriptorSetsType &type);
private:
friend class Material;
MaterialInstance(Material *,VIL *,const int);
public:
virtual ~MaterialInstance()
{
material->ReleaseMI(mi_id);
}
const int GetMIID ()const{return mi_id;} ///<取得材质实例ID
void * GetMIData (){return material->GetMIData(mi_id);} ///<取得材质实例数据
void WriteMIData (const void *data,const int size); ///<写入材质实例数据
bool BindUBO(const DescriptorSetsType &type,const AnsiString &name,GPUBuffer *ubo,bool dynamic=false);
bool BindSSBO(const DescriptorSetsType &type,const AnsiString &name,GPUBuffer *ubo,bool dynamic=false);
bool BindSampler(const DescriptorSetsType &type,const AnsiString &name,Texture *tex,Sampler *sampler);
bool BindUBO(const DescriptorSetType &type,const AnsiString &name,DeviceBuffer *ubo,bool dynamic=false);
bool BindSSBO(const DescriptorSetType &type,const AnsiString &name,DeviceBuffer *ubo,bool dynamic=false);
bool BindImageSampler(const DescriptorSetType &type,const AnsiString &name,Texture *tex,Sampler *sampler);
};//class MaterialInstance
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_MATERIAL_INSTANCE_INCLUDE

View File

@@ -1,53 +1,60 @@
#ifndef HGL_GRAPH_VULKAN_MATERIAL_PARAMETERS_INCLUDE
#ifndef HGL_GRAPH_VULKAN_MATERIAL_PARAMETERS_INCLUDE
#define HGL_GRAPH_VULKAN_MATERIAL_PARAMETERS_INCLUDE
#include<hgl/graph/VK.h>
#include<hgl/type/String.h>
#include<hgl/graph/VKDescriptorSets.h>
#include<hgl/graph/VKDescriptorSet.h>
#include<hgl/graph/VKDescriptorSetType.h>
#include<hgl/graph/VKMaterialDescriptorManager.h>
#include<hgl/graph/VKArrayBuffer.h>
VK_NAMESPACE_BEGIN
class MaterialParameters
{
const MaterialDescriptorSets *mds;
protected:
DescriptorSetsType ds_type;
const MaterialDescriptorManager *desc_manager;
DescriptorSets *descriptor_sets;
DescriptorSetType set_type;
private:
friend class GPUDevice;
MaterialParameters(const MaterialDescriptorSets *,const DescriptorSetsType &type,DescriptorSets *);
DescriptorSet *descriptor_set;
public:
const DescriptorSetsType GetType (){return ds_type;}
DescriptorSets * GetDescriptorSet (){return descriptor_sets;}
const VkDescriptorSet GetVkDescriptorSet ()const{return descriptor_sets->GetDescriptorSet();}
const DescriptorSetType GetType (){return set_type;}
DescriptorSet * GetDescriptorSet (){return descriptor_set;}
const VkDescriptorSet GetVkDescriptorSet ()const{return descriptor_set->GetDescriptorSet();}
const uint32_t GetCount ()const{return descriptor_sets->GetCount();}
const bool IsReady ()const{return descriptor_sets->IsReady();}
const uint32_t GetDescriptorCount ()const{return desc_manager->GetBindCount(set_type);} ///<获取总共需要绑定的描述符数量
const BindingMapArray & GetBindingMap ()const{return desc_manager->GetBindingMap(set_type);}
const uint32_t GetBoundCount ()const{return descriptor_set->GetCount();} ///<获取已经绑好的数量
const bool IsReady ()const{return descriptor_set->IsReady();} ///<是否全部绑好了
public:
#define MP_TYPE_IS(name) const bool is##name()const{return ds_type==DescriptorSetsType::name;}
MP_TYPE_IS(Material)
// MP_TYPE_IS(Texture)
MP_TYPE_IS(Value)
MP_TYPE_IS(Primitive)
#define MP_TYPE_IS(name) const bool is##name()const{return set_type==DescriptorSetType::name;}
MP_TYPE_IS(Instance)
MP_TYPE_IS(PerMaterial)
MP_TYPE_IS(PerFrame)
MP_TYPE_IS(Global)
#undef MP_TYPE_IS
public:
MaterialParameters(const MaterialDescriptorManager *,const DescriptorSetType &type,DescriptorSet *);
virtual ~MaterialParameters();
bool BindUBO(const AnsiString &name,GPUBuffer *ubo,bool dynamic=false);
bool BindSSBO(const AnsiString &name,GPUBuffer *ubo,bool dynamic=false);
bool BindSampler(const AnsiString &name,Texture *tex,Sampler *sampler);
bool BindUBO(const int &index,DeviceBuffer *ubo,bool dynamic=false);
bool BindSSBO(const int &index,DeviceBuffer *ubo,bool dynamic=false);
bool BindImageSampler(const int &index,Texture *tex,Sampler *sampler);
bool BindInputAttachment(const int &index,ImageView *);
bool BindUBO(const AnsiString &name,DeviceBuffer *ubo,bool dynamic=false);
bool BindSSBO(const AnsiString &name,DeviceBuffer *ubo,bool dynamic=false);
bool BindImageSampler(const AnsiString &name,Texture *tex,Sampler *sampler);
bool BindInputAttachment(const AnsiString &name,ImageView *);
void Update();
};//class MaterialParameters
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_MATERIAL_PARAMETERS_INCLUDE
#endif//HGL_GRAPH_VULKAN_MATERIAL_PARAMETERS_INCLUDE

View File

@@ -3,7 +3,7 @@
#include<hgl/graph/VK.h>
VK_NAMESPACE_BEGIN
class GPUMemory
class DeviceMemory
{
VkDevice device;
VkDeviceMemory memory;
@@ -18,11 +18,11 @@ private:
friend class GPUDevice;
GPUMemory(VkDevice dev,VkDeviceMemory dm,const VkMemoryRequirements &mr,const uint32 i,const uint32_t p,const VkDeviceSize cas);
DeviceMemory(VkDevice dev,VkDeviceMemory dm,const VkMemoryRequirements &mr,const uint32 i,const uint32_t p,const VkDeviceSize cas);
public:
virtual ~GPUMemory();
virtual ~DeviceMemory();
operator VkDeviceMemory(){return memory;}
@@ -47,6 +47,6 @@ public:
void Flush (VkDeviceSize,VkDeviceSize);
void Flush (VkDeviceSize size){Flush(0,size);}
};//class GPUMemory
};//class DeviceMemory
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_MEMORY_INCLUDE

View File

@@ -11,7 +11,7 @@ class VKMemoryAllocator:public AbstractMemoryAllocator
uint32_t buffer_usage_flag_bits;
GPUBuffer *gpu_buffer;
DeviceBuffer *gpu_buffer;
VkDeviceSize range; //ubo之类需要一个一次访问范围
@@ -25,7 +25,7 @@ public:
const uint32_t GetBufferUsageFlagBits ()const{return buffer_usage_flag_bits;}
GPUBuffer * GetBuffer (){return gpu_buffer;}
DeviceBuffer * GetBuffer (){return gpu_buffer;}
public:

View File

@@ -28,19 +28,8 @@ class GPUPhysicalDevice
private:
bool dynamic_state=false;
public:
GPUPhysicalDevice(VkInstance,VkPhysicalDevice);
~GPUPhysicalDevice()=default;
operator VkPhysicalDevice() {return physical_device;}
operator const VkPhysicalDevice()const {return physical_device;}
const int GetMemoryType(uint32_t,VkMemoryPropertyFlags)const;
VkPhysicalDeviceType GetDeviceType()const{return properties.deviceType;}
const char * GetDeviceName()const{return properties.deviceName;}
public:
const VkPhysicalDeviceFeatures & GetFeatures10 ()const{return features;}
const VkPhysicalDeviceVulkan11Features &GetFeatures11 ()const{return features11;}
@@ -51,19 +40,32 @@ public:
const VkPhysicalDeviceMemoryProperties &GetMemoryProperties ()const{return memory_properties;}
const VkPhysicalDeviceLimits & GetLimits ()const{return properties.limits;}
public:
GPUPhysicalDevice(VkInstance,VkPhysicalDevice);
~GPUPhysicalDevice()=default;
operator VkPhysicalDevice() {return physical_device;}
operator const VkPhysicalDevice()const {return physical_device;}
const uint32_t GetVulkanVersion()const{return properties.apiVersion;}
const int GetMemoryType(uint32_t,VkMemoryPropertyFlags)const;
VkPhysicalDeviceType GetDeviceType()const{return properties.deviceType;}
const char * GetDeviceName()const{return properties.deviceName;}
const bool GetLayerVersion(const AnsiString &,uint32_t &spec,uint32_t &impl)const;
const uint32_t GetExtensionVersion(const AnsiString &name)const;
const bool CheckExtensionSupport(const AnsiString &name)const;
public:
const uint32_t GetUBORange ()const{return properties.limits.maxUniformBufferRange;}
const VkDeviceSize GetUBOAlign ()const{return properties.limits.minUniformBufferOffsetAlignment;}
const uint32_t GetSSBORange ()const{return properties.limits.maxStorageBufferRange;}
const VkDeviceSize GetSSBOAlign ()const{return properties.limits.minStorageBufferOffsetAlignment;}
const uint32_t GetConstantSize ()const{return properties.limits.maxPushConstantsSize;}
const uint32_t GetConstantSize ()const{return properties.limits.maxPushConstantsSize;}
public:
@@ -83,6 +85,28 @@ public:
const bool isIntegratedGPU ()const{return(properties.deviceType==VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU);} ///<是否是集成显卡
const bool isVirtualGPU ()const{return(properties.deviceType==VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU);} ///<是否是虚拟显卡
#define HGL_VK_IS_BRAND(name) (hgl::stricmp(properties.deviceName,#name,sizeof(#name))==0)
const bool isMicrosoft ()const{return HGL_VK_IS_BRAND(Microsoft);}
const bool isMesa ()const{return HGL_VK_IS_BRAND(Mesa );}
const bool isAMD ()const{return HGL_VK_IS_BRAND(AMD )
||HGL_VK_IS_BRAND(ATI )
||HGL_VK_IS_BRAND(Radeon );}
const bool isNvidia ()const{return HGL_VK_IS_BRAND(nVidia )
||HGL_VK_IS_BRAND(GeForce )
||HGL_VK_IS_BRAND(Quadro )
||HGL_VK_IS_BRAND(TITAN )
||HGL_VK_IS_BRAND(Tegra );}
const bool isIntel ()const{return HGL_VK_IS_BRAND(Intel );}
const bool isQualcomm ()const{return HGL_VK_IS_BRAND(Adreno );}
const bool isApple ()const{return HGL_VK_IS_BRAND(Apple );}
const bool isImgTec ()const{return HGL_VK_IS_BRAND(ImgTec )
||HGL_VK_IS_BRAND(PowerVR );}
const bool isARM ()const{return HGL_VK_IS_BRAND(Arm )
||HGL_VK_IS_BRAND(Mali );}
#undef HGL_VK_IS_BRAND
public:
VkFormatProperties GetFormatProperties(const VkFormat format)const
@@ -114,7 +138,6 @@ public:
const bool IsSTBAtomicSupport (const VkFormat format)const{return BufferSupport(format,VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_ATOMIC_BIT);}
const bool IsVBOSupport (const VkFormat format)const{return BufferSupport(format,VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT);}
public:
const VkBool32 SupportGeometryShader ()const{return features.geometryShader;}
@@ -122,26 +145,24 @@ public:
// support != open, so please don't direct use GetFeatures().
// open any features in CreateDevice()&SetDeviceFeatures() functions.
const bool SupportMDI ()const
const bool SupportMDI ()const
{
// the device is supported MDI, but MaxDrawIndirectCount is 1.
return (features.multiDrawIndirect&&properties.limits.maxDrawIndirectCount>1);
}
const uint32_t GetMaxMDICount ()const
const uint32_t GetMaxMDICount ()const
{
return properties.limits.maxDrawIndirectCount;
}
const uint32_t GetMaxImage1D ()const{return properties.limits.maxImageDimension1D;}
const uint32_t GetMaxImage2D ()const{return properties.limits.maxImageDimension2D;}
const uint32_t GetMaxImage3D ()const{return properties.limits.maxImageDimension3D;}
const uint32_t GetMaxImageCube ()const{return properties.limits.maxImageDimensionCube;}
const uint32_t GetMaxImageArrayLayers ()const{return properties.limits.maxImageArrayLayers;}
const uint32_t GetMaxUBORange ()const{return properties.limits.maxUniformBufferRange;}
const uint32_t GetMaxSSBORange ()const{return properties.limits.maxStorageBufferRange;}
const uint32_t GetMaxBoundDescriptorSets()const{return properties.limits.maxBoundDescriptorSets;}
const uint32_t GetMaxImage1D ()const{return properties.limits.maxImageDimension1D;}
const uint32_t GetMaxImage2D ()const{return properties.limits.maxImageDimension2D;}
const uint32_t GetMaxImage3D ()const{return properties.limits.maxImageDimension3D;}
const uint32_t GetMaxImageCube ()const{return properties.limits.maxImageDimensionCube;}
const uint32_t GetMaxImageArrayLayers ()const{return properties.limits.maxImageArrayLayers;}
const uint32_t GetMaxBoundDescriptorSets ()const{return properties.limits.maxBoundDescriptorSets;}
const uint32_t GetMaxVertexInputAttributes ()const{return properties.limits.maxVertexInputAttributes;}
const uint32_t GetMaxVertexInputBindings ()const{return properties.limits.maxVertexInputBindings;}

View File

@@ -35,6 +35,8 @@ public:
operator VkPipeline(){return pipeline;}
const PipelineData *GetData()const{return data;}
const bool IsAlphaTest()const{return data->alpha_test>0;}
const bool IsAlphaBlend()const{return data->alpha_blend;}
};//class GraphicsPipeline

View File

@@ -26,10 +26,9 @@ class Primitive
protected:
uint32_t draw_count;
uint32_t vertex_count;
IndexBuffer *indices_buffer=nullptr;
VkDeviceSize indices_offset=0;
IndexBufferData index_buffer_data;
protected:
@@ -46,42 +45,34 @@ protected:
public:
Primitive(const uint32_t dc=0):draw_count(dc){}
Primitive(const uint32_t vc=0):vertex_count(vc){}
virtual ~Primitive()=default;
const uint GetRefCount()const{return ref_count;}
void SetBoundingBox(const AABB &aabb){BoundingBox=aabb;}
void SetBoundingBox(const AABB &aabb){BoundingBox=aabb;}
const AABB & GetBoundingBox()const {return BoundingBox;}
bool Set(const AnsiString &name,VBO *vb,VkDeviceSize offset=0);
bool Set(const AnsiString &name,VBO *vb,VkDeviceSize offset=0);
bool Set(IndexBuffer *ib,VkDeviceSize offset=0)
bool Set(IndexBuffer *ib,VkDeviceSize offset=0)
{
if(!ib)return(false);
indices_buffer=ib;
indices_offset=offset;
index_buffer_data.buffer=ib;
index_buffer_data.offset=offset;
return(true);
}
public:
void SetDrawCount(const uint32_t dc){draw_count=dc;} ///<设置当前对象绘制需要多少个顶点
virtual const uint32_t GetDrawCount()const ///<取得当前对象绘制需要多少个顶点
{
if(indices_buffer)
return indices_buffer->GetCount();
const uint32_t GetVertexCount ()const {return vertex_count;}
return draw_count;
}
VBO * GetVBO (const AnsiString &,VkDeviceSize *);
VkBuffer GetBuffer (const AnsiString &,VkDeviceSize *);
const int GetBufferCount ()const {return buffer_list.GetCount();}
VBO * GetVBO (const AnsiString &,VkDeviceSize *);
VkBuffer GetBuffer (const AnsiString &,VkDeviceSize *);
const int GetBufferCount ()const {return buffer_list.GetCount();}
IndexBuffer * GetIndexBuffer () {return indices_buffer;}
const VkDeviceSize GetIndexBufferOffset()const {return indices_offset;}
const IndexBufferData * GetIndexBufferData ()const {return &index_buffer_data;}
};//class Primitive
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_PRIMITIVE_INCLUDE

View File

@@ -4,7 +4,7 @@
#include<hgl/graph/VK.h>
#include<hgl/graph/VKFence.h>
VK_NAMESPACE_BEGIN
class GPUQueue
class DeviceQueue
{
protected:
@@ -12,7 +12,7 @@ protected:
VkQueue queue;
uint32_t current_fence;
GPUFence **fence_list;
Fence **fence_list;
uint32_t fence_count;
SubmitInfo submit_info;
@@ -21,18 +21,20 @@ private:
friend class GPUDevice;
GPUQueue(VkDevice dev,VkQueue q,GPUFence **,const uint32_t fc);
DeviceQueue(VkDevice dev,VkQueue q,Fence **,const uint32_t fc);
public:
virtual ~GPUQueue();
virtual ~DeviceQueue();
operator VkQueue(){return queue;}
VkResult Present(const VkPresentInfoKHR *pi){return vkQueuePresentKHR(queue,pi);}
bool WaitQueue();
bool WaitFence(const bool wait_all=true,const uint64_t time_out=HGL_NANO_SEC_PER_SEC);
bool Submit(const VkCommandBuffer &cmd_buf,GPUSemaphore *wait_sem,GPUSemaphore *complete_sem);
bool Submit(const VkCommandBuffer *cmd_buf,const uint32_t count,GPUSemaphore *wait_sem,GPUSemaphore *complete_sem);
};//class SumbitQueue
bool Submit(const VkCommandBuffer &cmd_buf,Semaphore *wait_sem,Semaphore *complete_sem);
bool Submit(const VkCommandBuffer *cmd_buf,const uint32_t count,Semaphore *wait_sem,Semaphore *complete_sem);
};//class DeviceQueue
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_SUBMIT_QUEUE_INCLUDE

View File

@@ -3,7 +3,7 @@
#include<hgl/graph/VK.h>
#include<hgl/graph/VKPipeline.h>
#include<hgl/type/List.h>
#include<hgl/type/ObjectList.h>
VK_NAMESPACE_BEGIN
/**
* RenderPass功能封装<br>
@@ -25,7 +25,7 @@ protected:
ObjectList<Pipeline> pipeline_list;
Pipeline *CreatePipeline(Material *,PipelineData *,const VAB *);
Pipeline *CreatePipeline(PipelineData *,const ShaderStageCreateInfoList &,VkPipelineLayout,const VIL *);
private:
@@ -54,14 +54,15 @@ public:
public:
Pipeline *CreatePipeline(MaterialInstance *, const PipelineData *);
Pipeline *CreatePipeline(MaterialInstance *, const InlinePipeline &);
Pipeline *CreatePipeline(Material *,const VIL *,const PipelineData *, const Prim &,const bool prim_restart=false);
Pipeline *CreatePipeline(Material *,const VIL *,const InlinePipeline &, const Prim &,const bool prim_restart=false);
public:
Pipeline *CreatePipeline(Material *mtl, const PipelineData *, const Prim &,const bool prim_restart=false);
Pipeline *CreatePipeline(Material *mtl, const InlinePipeline &, const Prim &,const bool prim_restart=false);
Pipeline *CreatePipeline(MaterialInstance *, const InlinePipeline &, const Prim &prim,const bool prim_restart=false);
Pipeline *CreatePipeline(MaterialInstance *, const PipelineData *, const Prim &prim,const bool prim_restart=false);
Pipeline *CreatePipeline(MaterialInstance *, const OSString &, const Prim &prim,const bool prim_restart=false);
Pipeline *CreatePipeline(MaterialInstance *, const InlinePipeline &, const Prim &,const bool prim_restart=false);
Pipeline *CreatePipeline(MaterialInstance *, const PipelineData *, const Prim &,const bool prim_restart=false);
Pipeline *CreatePipeline(MaterialInstance *, const OSString &, const Prim &,const bool prim_restart=false);
};//class RenderPass
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_RENDER_PASS_INCLUDE

View File

@@ -3,7 +3,7 @@
#include<hgl/graph/VKMaterial.h>
#include<hgl/graph/VKPipeline.h>
#include<hgl/graph/VKDescriptorSets.h>
#include<hgl/graph/VKDescriptorSet.h>
#include<hgl/graph/VKPrimitive.h>
#include<hgl/graph/VKBuffer.h>
#include<hgl/graph/VKSampler.h>
@@ -13,12 +13,15 @@
#include<hgl/graph/VertexAttribData.h>
#include<hgl/graph/VKRenderable.h>
#include<hgl/graph/font/TextPrimitive.h>
#include<hgl/type/ResManage.h>
#include<hgl/type/ObjectManage.h>
#include<hgl/shadergen/MaterialCreateInfo.h>
#include<hgl/graph/VKDescriptorBindingManage.h>
VK_NAMESPACE_BEGIN
using MaterialID =int;
using MaterialInstanceID =int;
using BufferID =int;
using DescriptorSetsID =int;
using DescriptorSetID =int;
using PrimitiveID =int;
using RenderableID =int;
using SamplerID =int;
@@ -26,6 +29,9 @@ using TextureID =int;
class VertexAttribData;
using ShaderModuleMapByName=ObjectMap<AnsiString,ShaderModule>;
constexpr const size_t VK_SHADER_STAGE_TYPE_COUNT=20;//GetBitOffset((uint32_t)VK_SHADER_STAGE_CLUSTER_CULLING_BIT_HUAWEI)+1;
/**
* 资源管理,用于管理场景内所需的所有数据
*/
@@ -33,31 +39,36 @@ class RenderResource
{
GPUDevice *device;
MapObject<OSString,ShaderModule> shader_module_by_name;
Map<OSString,Material *> material_by_name;
ShaderModuleMapByName shader_module_by_name[VK_SHADER_STAGE_TYPE_COUNT];
Map<AnsiString,Material *> material_by_name;
Map<OSString,Texture *> texture_by_name;
IDResManage<MaterialID, Material> rm_material; ///<材质合集
IDResManage<MaterialInstanceID, MaterialInstance> rm_material_instance; ///<材质实例合集
IDResManage<DescriptorSetsID, DescriptorSets> rm_desc_sets; ///<描述符合集
IDResManage<PrimitiveID, Primitive> rm_primitives; ///<图元合集
IDResManage<BufferID, GPUBuffer> rm_buffers; ///<顶点缓冲区合集
IDResManage<SamplerID, Sampler> rm_samplers; ///<采样器合集
IDResManage<TextureID, Texture> rm_textures; ///<纹理合集
IDResManage<RenderableID, Renderable> rm_renderables; ///<渲染实例集合集
IDObjectManage<MaterialID, Material> rm_material; ///<材质合集
IDObjectManage<MaterialInstanceID, MaterialInstance> rm_material_instance; ///<材质实例合集
IDObjectManage<DescriptorSetID, DescriptorSet> rm_desc_sets; ///<描述符合集
IDObjectManage<PrimitiveID, Primitive> rm_primitives; ///<图元合集
IDObjectManage<BufferID, DeviceBuffer> rm_buffers; ///<顶点缓冲区合集
IDObjectManage<SamplerID, Sampler> rm_samplers; ///<采样器合集
IDObjectManage<TextureID, Texture> rm_textures; ///<纹理合集
IDObjectManage<RenderableID, Renderable> rm_renderables; ///<渲染实例集合集
public:
RenderResource(GPUDevice *dev):device(dev){}
//注:并非一定要走这里,这里只是提供一个注册和自动绑定的机制
DescriptorBinding global_descriptor; ///<全局属性描述符绑定管理
public:
RenderResource(GPUDevice *dev):device(dev),global_descriptor(DescriptorSetType::Global){}
virtual ~RenderResource()=default;
public: //Add
MaterialID Add(Material * mtl ){return rm_material.Add(mtl);}
MaterialInstanceID Add(MaterialInstance * mi ){return rm_material_instance.Add(mi);}
DescriptorSetsID Add(DescriptorSets * ds ){return rm_desc_sets.Add(ds);}
DescriptorSetID Add(DescriptorSet * ds ){return rm_desc_sets.Add(ds);}
PrimitiveID Add(Primitive * p ){return rm_primitives.Add(p);}
BufferID Add(GPUBuffer * buf ){return rm_buffers.Add(buf);}
BufferID Add(DeviceBuffer * buf ){return rm_buffers.Add(buf);}
SamplerID Add(Sampler * s ){return rm_samplers.Add(s);}
TextureID Add(Texture * t ){return rm_textures.Add(t);}
RenderableID Add(Renderable * r ){return rm_renderables.Add(r);}
@@ -66,10 +77,10 @@ public: // VBO/VAO
VBO *CreateVBO(VkFormat format,uint32_t count,const void *data,SharingMode sm=SharingMode::Exclusive);
VBO *CreateVBO(VkFormat format,uint32_t count,SharingMode sm=SharingMode::Exclusive){return CreateVBO(format,count,nullptr,sm);}
VBO *CreateVBO(const VAD *vad,SharingMode sm=SharingMode::Exclusive){return CreateVBO(vad->GetVulkanFormat(),vad->GetCount(),vad->GetData(),sm);}
VBO *CreateVBO(const VAD *vad,SharingMode sm=SharingMode::Exclusive){return CreateVBO(vad->GetFormat(),vad->GetCount(),vad->GetData(),sm);}
#define SCENE_DB_CREATE_FUNC(name) GPUBuffer *Create##name(VkDeviceSize size,void *data,SharingMode sm=SharingMode::Exclusive); \
GPUBuffer *Create##name(VkDeviceSize size,SharingMode sm=SharingMode::Exclusive);
#define SCENE_DB_CREATE_FUNC(name) DeviceBuffer *Create##name(VkDeviceSize size,void *data,SharingMode sm=SharingMode::Exclusive); \
DeviceBuffer *Create##name(VkDeviceSize size,SharingMode sm=SharingMode::Exclusive);
SCENE_DB_CREATE_FUNC(UBO)
SCENE_DB_CREATE_FUNC(SSBO)
@@ -87,11 +98,12 @@ public: // VBO/VAO
public: //Material
const ShaderModule *CreateShaderModule(const OSString &filename,ShaderResource *shader_resource);
const ShaderModule *CreateShaderModule(const AnsiString &shader_module_name,const ShaderCreateInfo *);
Material * CreateMaterial(const OSString &);
MaterialInstance * CreateMaterialInstance(Material *,const VABConfigInfo *vab_cfg=nullptr);
MaterialInstance * CreateMaterialInstance(const OSString &,const VABConfigInfo *vab_cfg=nullptr);
Material * CreateMaterial(const mtl::MaterialCreateInfo *);
MaterialInstance * CreateMaterialInstance(Material *,const VILConfig *vil_cfg=nullptr);
MaterialInstance * CreateMaterialInstance(const mtl::MaterialCreateInfo *,const VILConfig *vil_cfg=nullptr);
Primitive * CreatePrimitive(const uint32_t vertex_count=0);
@@ -109,12 +121,12 @@ public: //Get
Material * GetMaterial (const MaterialID &id){return rm_material.Get(id);}
MaterialInstance * GetMaterialInstance (const MaterialInstanceID &id){return rm_material_instance.Get(id);}
DescriptorSets * GetDescSets (const DescriptorSetsID &id){return rm_desc_sets.Get(id);}
DescriptorSet * GetDescSets (const DescriptorSetID &id){return rm_desc_sets.Get(id);}
Primitive * GetPrimitive (const PrimitiveID &id){return rm_primitives.Get(id);}
GPUBuffer * GetBuffer (const BufferID &id){return rm_buffers.Get(id);}
DeviceBuffer * GetBuffer (const BufferID &id){return rm_buffers.Get(id);}
Sampler * GetSampler (const SamplerID &id){return rm_samplers.Get(id);}
Texture * GetTexture (const TextureID &id){return rm_textures.Get(id);}
Renderable * GetRenderable (const RenderableID &id){return rm_renderables.Get(id);}
Renderable * GetRenderable (const RenderableID &id){return rm_renderables.Get(id);}
};//class RenderResource
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_DATABASE_INCLUDE

View File

@@ -15,14 +15,14 @@ class RenderTarget
{
protected:
GPUQueue *queue;
DeviceQueue *queue;
RenderPass *render_pass;
Framebuffer *fbo;
VkExtent2D extent;
GPUSemaphore *render_complete_semaphore =nullptr;
Semaphore *render_complete_semaphore =nullptr;
protected:
@@ -34,13 +34,14 @@ protected:
friend class GPUDevice;
RenderTarget(GPUQueue *,GPUSemaphore *);
RenderTarget(GPUQueue *,GPUSemaphore *,RenderPass *_rp,Framebuffer *_fb,Texture2D **color_texture_list,const uint32_t color_count,Texture2D *depth_texture);
RenderTarget(DeviceQueue *,Semaphore *);
RenderTarget(DeviceQueue *,Semaphore *,RenderPass *_rp,Framebuffer *_fb,Texture2D **color_texture_list,const uint32_t color_count,Texture2D *depth_texture);
public:
virtual ~RenderTarget();
DeviceQueue * GetQueue () {return queue;}
const VkExtent2D & GetExtent ()const {return extent;}
virtual RenderPass * GetRenderPass () {return render_pass;}
virtual const VkRenderPass GetVkRenderPass ()const {return render_pass->GetVkRenderPass();}
@@ -52,8 +53,8 @@ public:
public: // command buffer
GPUSemaphore * GetRenderCompleteSemaphore (){return render_complete_semaphore;}
virtual bool Submit (RenderCmdBuffer *,GPUSemaphore *present_complete_semaphore=nullptr);
Semaphore * GetRenderCompleteSemaphore (){return render_complete_semaphore;}
virtual bool Submit (RenderCmdBuffer *,Semaphore *present_complete_semaphore=nullptr);
bool WaitQueue(){return queue->WaitQueue();}
bool WaitFence(){return queue->WaitFence();}
@@ -62,23 +63,23 @@ public: // command buffer
/**
* 交换链专用渲染目标
*/
class SwapchainRenderTarget:public RenderTarget
class RTSwapchain:public RenderTarget
{
VkDevice device;
Swapchain *swapchain;
PresentInfo present_info;
GPUSemaphore *present_complete_semaphore=nullptr;
Semaphore *present_complete_semaphore=nullptr;
uint32_t current_frame;
public:
SwapchainRenderTarget(VkDevice dev,Swapchain *sc,GPUQueue *q,GPUSemaphore *rcs,GPUSemaphore *pcs,RenderPass *rp);
~SwapchainRenderTarget();
RTSwapchain(VkDevice dev,Swapchain *sc,DeviceQueue *q,Semaphore *rcs,Semaphore *pcs,RenderPass *rp);
~RTSwapchain();
Framebuffer * GetFramebuffer ()override {return swapchain->render_frame[current_frame];}
Framebuffer * GetFramebuffer (const uint32_t index) {return swapchain->render_frame[index];}
Framebuffer * GetFramebuffer ()override {return swapchain->sc_fbo[current_frame];}
Framebuffer * GetFramebuffer (const uint32_t index) {return swapchain->sc_fbo[index];}
const uint32_t GetColorCount ()const override {return 1;}
const uint32_t GetImageCount ()const {return swapchain->color_count;}
@@ -89,7 +90,7 @@ public:
public:
const uint32_t GetCurrentFrameIndices ()const {return current_frame;}
GPUSemaphore * GetPresentCompleteSemaphore () {return present_complete_semaphore;}
Semaphore * GetPresentCompleteSemaphore () {return present_complete_semaphore;}
public:
@@ -108,7 +109,7 @@ public:
bool PresentBackbuffer();
bool Submit(VkCommandBuffer);
bool Submit(VkCommandBuffer,GPUSemaphore *);
};//class SwapchainRenderTarget:public RenderTarget
bool Submit(VkCommandBuffer,Semaphore *);
};//class RTSwapchain:public RenderTarget
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_RENDER_TARGET_INCLUDE

View File

@@ -3,14 +3,49 @@
#include<hgl/graph/VKPrimitive.h>
#include<hgl/graph/VKPipeline.h>
#include<hgl/graph/VKDescriptorSets.h>
#include<hgl/graph/VKDescriptorSet.h>
#include<hgl/graph/VKMaterial.h>
#include<hgl/graph/VKMaterialParameters.h>
#include<hgl/graph/VKMaterialInstance.h>
#include<hgl/graph/VertexAttrib.h>
VK_NAMESPACE_BEGIN
struct VertexInputData
{
uint32_t binding_count;
VkBuffer *buffer_list;
VkDeviceSize *buffer_offset;
uint32_t vertex_count;
const IndexBufferData *index_buffer;
public:
VertexInputData(const uint32_t,const uint32_t,const IndexBufferData *);
~VertexInputData();
const bool Comp(const VertexInputData *vid)const
{
if(!vid)return(false);
if(binding_count!=vid->binding_count)return(false);
for(uint32_t i=0;i<binding_count;i++)
{
if(buffer_list[i]!=vid->buffer_list[i])return(false);
if(buffer_offset[i]!=vid->buffer_offset[i])return(false);
}
if(vertex_count!=vid->vertex_count)return(false);
if(index_buffer!=vid->index_buffer)return(false);
return(true);
}
};//struct VertexInputData
/**
* 可渲染对象<br>
* RenderList会统一管理Shader中的LocalToWorld数据使用DynamicUBO/DynamicSSBO实现。
*/
class Renderable ///可渲染对象实例
{
@@ -18,17 +53,13 @@ class Renderable
MaterialInstance * mat_inst;
Primitive * primitive;
uint32_t buffer_count;
VkBuffer * buffer_list;
VkDeviceSize * buffer_size;
uint32_t buffer_hash;
VertexInputData * vertex_input;
private:
friend Renderable *CreateRenderable(Primitive *,MaterialInstance *,Pipeline *);
Renderable(Primitive *,MaterialInstance *,Pipeline *,const uint32_t,VkBuffer *,VkDeviceSize *);
Renderable(Primitive *,MaterialInstance *,Pipeline *,VertexInputData *);
public:
@@ -43,20 +74,7 @@ public:
Primitive * GetPrimitive (){return primitive;}
const AABB & GetBoundingBox ()const{return primitive->GetBoundingBox();}
const uint32_t GetBufferCount ()const{return buffer_count;}
VkBuffer * GetBuffer ()const{return buffer_list;}
VkDeviceSize * GetBufferSize ()const{return buffer_size;}
IndexBuffer * GetIndexBuffer ()const{return primitive->GetIndexBuffer();}
const uint32_t GetIndexBufferOffset()const{return primitive->GetIndexBufferOffset();}
const uint32_t GetDrawCount ()const{return primitive->GetDrawCount();}
const uint32_t GetBufferHash ()const{return buffer_hash;}
MaterialParameters *GetMP (const DescriptorSetsType &type){return mat_inst->GetMP(type);}
public: //instance support
virtual const uint32_t GetInstanceCount ()const{return 1;}
const VertexInputData * GetVertexInputData ()const{return vertex_input;}
};//class Renderable
Renderable *CreateRenderable(Primitive *,MaterialInstance *,Pipeline *);

View File

@@ -0,0 +1,53 @@
#ifndef HGL_VK_RENDERABLE_PRIMITIVE_CREATER_INCLUDE
#define HGL_VK_RENDERABLE_PRIMITIVE_CREATER_INCLUDE
#include<hgl/graph/VKRenderResource.h>
VK_NAMESPACE_BEGIN
class RenderablePrimitiveCreater
{
RenderResource *rr;
uint32_t vertex_count;
Primitive *prim;
public:
RenderablePrimitiveCreater(RenderResource *_rr,uint32_t vc)
{
rr=_rr;
vertex_count=vc;
prim=rr->CreatePrimitive(vertex_count);
}
bool SetVBO(const AnsiString &name,const VkFormat &fmt,const void *buf)
{
VBO *vbo=rr->CreateVBO(fmt,vertex_count,buf);
if(!vbo)
return(false);
prim->Set(name,vbo);
return(true);
}
bool SetIBO(const IndexType &it,const void *buf)
{
IndexBuffer *ibo=rr->CreateIBO(it,vertex_count,buf);
if(!ibo)
return(false);
prim->Set(ibo);
return(true);
}
Renderable *Create(MaterialInstance *mi,Pipeline *p)
{
return rr->CreateRenderable(prim,mi,p);
}
};//class RenderablePrimitiveCreater
VK_NAMESPACE_END
#endif // HGL_VK_RENDERABLE_PRIMITIVE_CREATER_INCLUDE

View File

@@ -3,7 +3,7 @@
#include<hgl/graph/VK.h>
VK_NAMESPACE_BEGIN
class GPUSemaphore
class Semaphore
{
VkDevice device;
VkSemaphore sem;
@@ -12,7 +12,7 @@ private:
friend class GPUDevice;
GPUSemaphore(VkDevice d,VkSemaphore s)
Semaphore(VkDevice d,VkSemaphore s)
{
device=d;
sem=s;
@@ -20,11 +20,11 @@ private:
public:
~GPUSemaphore();
~Semaphore();
operator VkSemaphore(){return sem;}
operator const VkSemaphore *()const{return &sem;}
};//class GPUSemaphore
};//class Semaphore
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_SEMAPHORE_INCLUDE

View File

@@ -1,7 +1,8 @@
#ifndef HGL_GRAPH_VULKAN_SHADER_MODULE_INCLUDE
#define HGL_GRAPH_VULKAN_SHADER_MODULE_INCLUDE
#include<hgl/graph/VKShaderResource.h>
#include<hgl/graph/VK.h>
#include<hgl/graph/VKVertexInputLayout.h>
#include<hgl/type/SortedSets.h>
VK_NAMESPACE_BEGIN
@@ -19,13 +20,9 @@ private:
VkPipelineShaderStageCreateInfo *stage_create_info;
protected:
ShaderResource *shader_resource;
public:
ShaderModule(VkDevice dev,VkPipelineShaderStageCreateInfo *pssci,ShaderResource *);
ShaderModule(VkDevice dev,VkPipelineShaderStageCreateInfo *pssci);
virtual ~ShaderModule();
const int IncRef(){return ++ref_count;}
@@ -45,49 +42,8 @@ public:
const bool IsMesh ()const{return stage_create_info->stage==VK_SHADER_STAGE_MESH_BIT_NV;}
const VkPipelineShaderStageCreateInfo * GetCreateInfo ()const{return stage_create_info;}
operator VkShaderModule ()const{return stage_create_info->module;}
};//class ShaderModule
/**
* 顶点Shader模块<br>
* 由于顶点shader在最前方执行所以它比其它shader多了VertexInput的数据
*/
class VertexShaderModule:public ShaderModule
{
uint32_t attr_count;
VertexAttribType *type_list;
const AnsiString **name_list;
ShaderStage **ssi_list;
private:
SortedSets<VAB *> vab_sets;
public:
VertexShaderModule(VkDevice dev,VkPipelineShaderStageCreateInfo *pssci,ShaderResource *sr);
virtual ~VertexShaderModule();
/**
* 获取输入流绑定点需要注意的时这里获取的binding并非是shader中的binding/location而是绑定顺序的序列号。对应vkCmdBindVertexBuffer的缓冲区序列号
*/
const int GetStageInputBinding(const AnsiString &name)const{return shader_resource->GetStageInputBinding(name);}
const ShaderStage * GetStageInput (const AnsiString &name)const{return shader_resource->GetStageInput(name);}
const uint GetStageInputCount () const{return shader_resource->GetStageInputCount();}
const ShaderStageList & GetStageInputs () const{return shader_resource->GetStageInputs();}
//const uint32_t GetAttrCount()const{return attr_count;}
//const VkVertexInputBindingDescription * GetDescList ()const{return binding_list;}
//const VkVertexInputAttributeDescription * GetAttrList ()const{return attribute_list;}
//const VkVertexInputBindingDescription * GetDesc (const uint32_t index)const{return (index>=attr_count?nullptr:binding_list+index);}
//const VkVertexInputAttributeDescription * GetAttr (const uint32_t index)const{return (index>=attr_count?nullptr:attribute_list+index);}
public:
VAB * CreateVAB(const VABConfigInfo *format_map=nullptr);
bool Release(VAB *);
const uint32_t GetInstanceCount()const{return vab_sets.GetCount();}
};//class VertexShaderModule:public ShaderModule
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_SHADER_MODULE_INCLUDE

View File

@@ -4,65 +4,39 @@
#include<hgl/type/String.h>
#include<hgl/type/List.h>
#include<hgl/type/StringList.h>
#include<hgl/graph/VK.h>
#include<hgl/graph/VKShaderStage.h>
#include<hgl/graph/VKStruct.h>
VK_NAMESPACE_BEGIN
struct ShaderStage
{
AnsiString name;
uint location;
VertexAttribType type; ///<成份数量(如vec4中的4)
bool global; ///<是否全局数据
bool dynamic; ///<是否动态数量
};//struct ShaderStage
using ShaderStageList =ObjectList<ShaderStage>;
class ShaderResource
{
VkShaderStageFlagBits stage_flag;
const void *spv_data;
const uint32_t *spv_data;
uint32 spv_size;
ShaderStageList stage_inputs;
ShaderStageList stage_outputs;
ShaderStageIO stage_io;
public:
ShaderResource(const VkShaderStageFlagBits &,const void *,const uint32);
virtual ~ShaderResource()=default;
ShaderResource(const VkShaderStageFlagBits &,const uint32_t *,const uint32);
virtual ~ShaderResource();
const VkShaderStageFlagBits GetStage ()const {return stage_flag;}
const os_char * GetStageName ()const;
const VkShaderStageFlagBits GetStage ()const {return stage_flag;}
const char * GetStageName ()const {return GetShaderStageName(stage_flag);}
const uint32_t * GetCode ()const {return (uint32_t *)spv_data;}
const uint32_t GetCodeSize ()const {return spv_size;}
const uint32_t * GetSPVData ()const {return spv_data;}
const uint32_t GetSPVSize ()const {return spv_size;}
ShaderStageList & GetStageInputs () {return stage_inputs;}
ShaderStageList & GetStageOutputs () {return stage_outputs;}
ShaderAttributeArray & GetInputs () {return stage_io.input;}
// ShaderAttributeArray & GetOutputs () {return stage_io.output;}
const uint GetStageInputCount ()const {return stage_inputs.GetCount();}
const uint GetStageOutputCount ()const {return stage_outputs.GetCount();}
const uint GetInputCount ()const {return stage_io.input.count;}
// const uint GetOutputCount ()const {return stage_io.output.count;}
const ShaderStage * GetStageInput (const AnsiString &)const;
const int GetStageInputBinding(const AnsiString &)const;
const ShaderAttribute * GetInput (const AnsiString &)const;
const int GetInputBinding (const AnsiString &)const;
};//class ShaderResource
ShaderResource *LoadShaderResource(const uint8 *origin_filedata,const int64 filesize);
struct ShaderModuleCreateInfo:public vkstruct_flag<VkShaderModuleCreateInfo,VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO>
{
public:
ShaderModuleCreateInfo(ShaderResource *sr)
{
codeSize=sr->GetCodeSize();
pCode =sr->GetCode();
}
};//struct ShaderModuleCreateInfo
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_SHADER_RESOURCE_INCLUDE
#endif//HGL_GRAPH_VULKAN_SHADER_RESOURCE_INCLUDE

View File

@@ -15,12 +15,12 @@ public:
VkSwapchainKHR swap_chain =VK_NULL_HANDLE;
uint32_t color_count=0;
uint32_t color_count =0;
Texture2D ** sc_color =nullptr;
Texture2D * sc_depth =nullptr;
Framebuffer ** render_frame =nullptr;
Framebuffer ** sc_fbo =nullptr;
public:

View File

@@ -4,7 +4,7 @@
#include<hgl/graph/VK.h>
#include<hgl/graph/VKMemory.h>
#include<hgl/graph/VKImageView.h>
#include<hgl/graph/Bitmap.h>
#include<hgl/graph/BitmapData.h>
#include<hgl/type/String.h>
#include<hgl/graph/VKTextureCreateInfo.h>
VK_NAMESPACE_BEGIN
@@ -27,7 +27,7 @@ public:
VkImageLayout GetImageLayout () {return data?data->image_layout:VK_IMAGE_LAYOUT_UNDEFINED;}
VkImageView GetVulkanImageView () {return data?data->image_view->GetImageView():VK_NULL_HANDLE;}
GPUMemory * GetMemory () {return data?data->memory:nullptr;}
DeviceMemory * GetMemory () {return data?data->memory:nullptr;}
ImageView * GetImageView () {return data?data->image_view:nullptr;}
const uint32 GetMipLevel ()const {return data?data->miplevel:0;}

View File

@@ -20,13 +20,13 @@ struct TextureCreateInfo
VkImageLayout image_layout;
VkImage image; //如果没有IMAGE则创建。交换链等会直接提供image所以存在外部传入现像)
GPUMemory * memory; //同时需分配内存并绑定
DeviceMemory * memory; //同时需分配内存并绑定
ImageView * image_view; //如果没有imageview则创建
void * pixels; //如果没有buffer但有pixels则根据pixels和以上条件创建buffer
VkDeviceSize total_bytes;
GPUBuffer * buffer; //如果pixels也没有则代表不会立即写入图像数据
DeviceBuffer * buffer; //如果pixels也没有则代表不会立即写入图像数据
public:
@@ -152,7 +152,7 @@ public:
return(true);
}
bool SetData(GPUBuffer *buf,const VkExtent3D &ext)
bool SetData(DeviceBuffer *buf,const VkExtent3D &ext)
{
if(!buf)return(false);
if(ext.width<=0||ext.height<=0||ext.depth<=0)return(false);
@@ -292,7 +292,7 @@ struct SwapchainDepthTextureCreateInfo:public TextureCreateInfo
struct TextureData
{
GPUMemory * memory;
DeviceMemory * memory;
VkImage image;
VkImageLayout image_layout;
ImageView * image_view;

57
inc/hgl/graph/VKVBOList.h Normal file
View File

@@ -0,0 +1,57 @@
#pragma once
VK_NAMESPACE_BEGIN
class VBOList
{
uint32_t binding_count;
VkBuffer *buffer_list;
VkDeviceSize *buffer_offset;
uint32_t write_count;
friend class RenderCmdBuffer;
public:
VBOList(const uint32 bc)
{
binding_count=bc;
buffer_list=new VkBuffer[binding_count];
buffer_offset=new VkDeviceSize[binding_count];
write_count=0;
}
~VBOList()
{
delete[] buffer_offset;
delete[] buffer_list;
}
void Restart()
{
write_count=0;
}
const bool IsFull()const
{
return write_count>=binding_count;
}
void Add(const VkBuffer buf,const VkDeviceSize offset)
{
buffer_list[write_count]=buf;
buffer_offset[write_count]=offset;
++write_count;
}
void Add(const VkBuffer *buf,const VkDeviceSize *offset,const uint32_t count)
{
hgl_cpy(buffer_list +write_count,buf, count);
hgl_cpy(buffer_offset+write_count,offset,count);
write_count+=count;
}
};//class VBOList
VK_NAMESPACE_END

View File

@@ -7,7 +7,7 @@ namespace hgl
{
namespace graph
{
class VertexAttribBuffer:public GPUBuffer
class VertexAttribBuffer:public DeviceBuffer
{
VkFormat format; ///<<3C><><EFBFBD>ݸ<EFBFBD>ʽ
uint32_t stride; ///<<3C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD>
@@ -17,7 +17,7 @@ namespace hgl
friend class GPUDevice;
VertexAttribBuffer(VkDevice d,const GPUBufferData &vb,VkFormat fmt,uint32_t _stride,uint32_t _count):GPUBuffer(d,vb)
VertexAttribBuffer(VkDevice d,const DeviceBufferData &vb,VkFormat fmt,uint32_t _stride,uint32_t _count):DeviceBuffer(d,vb)
{
format=fmt;
stride=_stride;
@@ -31,7 +31,7 @@ namespace hgl
const VkFormat GetFormat()const { return format; }
const uint32_t GetStride()const { return stride; }
const uint32_t GetCount ()const { return count; }
};//class VertexAttribBuffer:public GPUBuffer
};//class VertexAttribBuffer:public DeviceBuffer
using VBO=VertexAttribBuffer;
}//namespace graph

View File

@@ -6,27 +6,6 @@ namespace hgl
{
namespace graph
{
/**
* 预定义一些顶点属性名称可用可不用。但一般默认shader会使用这些名称
*/
namespace VertexAttribName
{
#define VAN_DEFINE(name) constexpr char name[]=#name;
VAN_DEFINE(Position)
VAN_DEFINE(Normal)
VAN_DEFINE(Color)
VAN_DEFINE(Tangent)
VAN_DEFINE(Bitangent)
VAN_DEFINE(TexCoord)
VAN_DEFINE(Metallic)
VAN_DEFINE(Specular)
VAN_DEFINE(Roughness)
VAN_DEFINE(Emission)
#undef VAN_DEFINE
}//namespace VertexAttribName
#define VAN VertexAttribName
/**
* 顶点属性数据
*/
@@ -36,18 +15,19 @@ namespace hgl
protected:
const uint32_t vec_size; ///<每个数据成员数(比如二维坐标为2、三维坐标为3)
uint32_t count; ///<数据个数
VkFormat format;
const uint32_t stride; ///<每组数据字节
const uint32_t total_bytes; ///<字节数
VkFormat vk_format; ///<在Vulkan中的数据类型
uint32_t count; ///<数据个
uint32_t total_bytes; ///<字节数
public:
VertexAttribData(uint32_t c,uint32_t dc,uint32_t cs,VkFormat fmt):count(c),vec_size(dc),stride(cs),total_bytes(cs*c),vk_format(fmt)
VertexAttribData(uint32_t c,const VkFormat vf,const uint32_t t)
{
count=c;
format=vf;
total_bytes=t;
mem_data = hgl_malloc(total_bytes); //在很多情况下hgl_malloc分配的内存是对齐的这样有效率上的提升
}
@@ -57,10 +37,8 @@ namespace hgl
hgl_free(mem_data);
}
const VkFormat GetVulkanFormat ()const{return vk_format;} ///<取得数据类型
const uint32_t GetVecSize ()const{return vec_size;} ///<取数缓冲区元数据成份数量
const VkFormat GetFormat ()const{return format;} ///<取得数据类型
const uint32_t GetCount ()const{return count;} ///<取得数据数量
const uint32_t GetStride ()const{return stride;} ///<取得每一组数据字节数
void * GetData ()const{return mem_data;} ///<取得数据指针
const uint32_t GetTotalBytes ()const{return total_bytes;} ///<取得数据字节数
};//class VertexAttribData
@@ -70,11 +48,9 @@ namespace hgl
/**
* 根据格式要求,创建对应的顶点属性数据区(VAD)
* @param vertex_count 顶点数量
* @param fmt Vulkan格式
* @param vec_size vec数量
* @param stride 单个数据字节数
* @param vif 格式
*/
VAD *CreateVertexAttribData(const uint32_t vertex_count,const VkFormat fmt,const int vec_size,const uint stride);
VAD *CreateVertexAttribData(const uint32_t vertex_count,const VertexInputFormat *vif);
//这个函数比较重要就不搞成CreateVAD的简写了
}//namespace graph
}//namespace hgl

View File

@@ -1,8 +1,8 @@
#ifndef HGL_GRAPH_VERTEX_ATTRIB_DATA_ACCESS_INCLUDE
#define HGL_GRAPH_VERTEX_ATTRIB_DATA_ACCESS_INCLUDE
#include<hgl/type/Color3f.h>
#include<hgl/type/Color4f.h>
#include<hgl/color/Color3f.h>
#include<hgl/color/Color4f.h>
#include<hgl/type/RectScope.h>
#include<hgl/type/String.h>
#include<hgl/graph/VertexAttribData.h>
@@ -60,7 +60,7 @@ namespace hgl
{
if(!data||offset>=count)
{
LOG_HINT(OS_TEXT("VertexAttribDataAccess::Get() out,offset:")+OSString::valueOf(offset));
LOG_HINT(OS_TEXT("VertexAttribDataAccess::Get() out,offset:")+OSString::numberOf(offset));
return(nullptr);
}
@@ -76,7 +76,7 @@ namespace hgl
{
if(access)
{
LOG_HINT(OS_TEXT("VertexAttribDataAccess::Begin() access!=0,offset:")+OSString::valueOf(offset));
LOG_HINT(OS_TEXT("VertexAttribDataAccess::Begin() access!=0,offset:")+OSString::numberOf(offset));
return(nullptr);
}
@@ -106,7 +106,7 @@ namespace hgl
{
if(!this->access||this->access+C*number>this->data_end)
{
LOG_HINT(OS_TEXT("VertexAttribDataAccess::Write(const T *,number) out,number:")+OSString::valueOf(number));
LOG_HINT(OS_TEXT("VertexAttribDataAccess::Write(const T *,number) out,number:")+OSString::numberOf(number));
return(false);
}
@@ -134,7 +134,7 @@ namespace hgl
{
if(!vad)return(nullptr);
if(vad->GetVulkanFormat()!=VKFMT)
if(vad->GetFormat()!=VKFMT)
return(nullptr);
return(new VertexAttribDataAccess1<T,VKFMT>(vad->GetCount(),(T *)vad->GetData()));
@@ -201,7 +201,7 @@ namespace hgl
{
if(!this->access||this->access+count>this->data_end)
{
LOG_HINT(OS_TEXT("VertexAttribDataAccess1::Write(const T,")+OSString::valueOf(count)+OS_TEXT(") out"));
LOG_HINT(OS_TEXT("VertexAttribDataAccess1::Write(const T,")+OSString::numberOf(count)+OS_TEXT(") out"));
return(false);
}
@@ -227,7 +227,7 @@ namespace hgl
{
if(!vad)return(nullptr);
if(vad->GetVulkanFormat()!=VKFMT)
if(vad->GetFormat()!=VKFMT)
return(nullptr);
return(new VertexAttribDataAccess2<T,VKFMT>(vad->GetCount(),(T *)vad->GetData()));
@@ -328,7 +328,7 @@ namespace hgl
{
if(!this->access||this->access+(count<<1)>this->data_end)
{
LOG_HINT(OS_TEXT("VertexAttribDataAccess1::Write(const Vector2f &,")+OSString::valueOf(count)+OS_TEXT(") out"));
LOG_HINT(OS_TEXT("VertexAttribDataAccess1::Write(const Vector2f &,")+OSString::numberOf(count)+OS_TEXT(") out"));
return(false);
}
@@ -526,7 +526,7 @@ namespace hgl
{
if(!vad)return(nullptr);
if(vad->GetVulkanFormat()!=VKFMT)
if(vad->GetFormat()!=VKFMT)
return(nullptr);
return(new VertexAttribDataAccess3<T,VKFMT>(vad->GetCount(),(T *)vad->GetData()));
@@ -633,7 +633,7 @@ namespace hgl
{
if(!this->access||this->access+(count*3)>this->data_end)
{
LOG_HINT(OS_TEXT("VertexAttribDataAccess3::Write(const Vector3f,")+OSString::valueOf(count)+OS_TEXT(") out"));
LOG_HINT(OS_TEXT("VertexAttribDataAccess3::Write(const Vector3f,")+OSString::numberOf(count)+OS_TEXT(") out"));
return(false);
}
@@ -657,7 +657,7 @@ namespace hgl
{
if(!this->access||this->access+(count*3)>this->data_end)
{
LOG_HINT(OS_TEXT("VertexAttribDataAccess3::Write(const Vector3f,")+OSString::valueOf(count)+OS_TEXT(") out"));
LOG_HINT(OS_TEXT("VertexAttribDataAccess3::Write(const Vector3f,")+OSString::numberOf(count)+OS_TEXT(") out"));
return(false);
}
@@ -798,7 +798,7 @@ namespace hgl
{
if(!vad)return(nullptr);
if(vad->GetVulkanFormat()!=VKFMT)
if(vad->GetFormat()!=VKFMT)
return(nullptr);
return(new VertexAttribDataAccess4<T,VKFMT>(vad->GetCount(),(T *)vad->GetData()));
@@ -948,7 +948,7 @@ namespace hgl
{
if(!this->access||this->access+(count<<2)>this->data_end)
{
LOG_HINT(OS_TEXT("VertexAttribDataAccess4::Write(const Vector4f,")+OSString::valueOf(count)+OS_TEXT(") out"));
LOG_HINT(OS_TEXT("VertexAttribDataAccess4::Write(const Vector4f,")+OSString::numberOf(count)+OS_TEXT(") out"));
return(false);
}
@@ -973,7 +973,7 @@ namespace hgl
{
if(!this->access||this->access+(count<<2)>this->data_end)
{
LOG_HINT(OS_TEXT("VertexAttribDataAccess4::Write(const Vector4f,")+OSString::valueOf(count)+OS_TEXT(") out"));
LOG_HINT(OS_TEXT("VertexAttribDataAccess4::Write(const Vector4f,")+OSString::numberOf(count)+OS_TEXT(") out"));
return(false);
}

View File

@@ -14,9 +14,9 @@ namespace hgl
*/
class FontManage
{
MapObject<Font,FontSource> sources;
ObjectMap<Font,FontSource> sources;
MapObject<FontConfig,TileFont> tilefonts;
ObjectMap<FontConfig,TileFont> tilefonts;
};//class FontManage
}//namespace graph
}//namespace hgl

View File

@@ -73,7 +73,7 @@ namespace hgl
SortedSets<void *> ref_object;
MapObject<u32char,CLA> cla_cache;
ObjectMap<u32char,CLA> cla_cache;
public:
@@ -98,7 +98,7 @@ namespace hgl
Font fnt;
MapObject<u32char,FontBitmap> chars_bitmap; ///<字符位图
ObjectMap<u32char,FontBitmap> chars_bitmap; ///<字符位图
protected:

View File

@@ -2,7 +2,7 @@
#define HGL_GRAPH_TEXT_RENDER_INCLUDE
#include<hgl/graph/VK.h>
#include<hgl/type/Color4f.h>
#include<hgl/color/Color4f.h>
namespace hgl
{
@@ -31,25 +31,25 @@ namespace hgl
TextLayout * tl_engine;
Color4f color;
GPUBuffer * ubo_color;
DeviceBuffer * ubo_color;
SortedSets<TextPrimitive *> tr_sets;
private:
friend TextRender *CreateTextRender(GPUDevice *,FontSource *,RenderPass *,GPUBuffer *,int limit=-1);
friend TextRender *CreateTextRender(GPUDevice *,FontSource *,RenderPass *,DeviceBuffer *,int limit=-1);
TextRender(GPUDevice *dev,FontSource *);
bool InitTileFont(int limit);
bool InitTextLayoutEngine();
bool InitUBO();
bool InitMaterial(RenderPass *,GPUBuffer *);
bool InitMaterial(RenderPass *,DeviceBuffer *);
public:
~TextRender();
bool Init(RenderPass *rp,GPUBuffer *ubo_camera_info,int limit);
bool Init(RenderPass *rp,DeviceBuffer *ubo_camera_info,int limit);
public:
@@ -82,7 +82,7 @@ namespace hgl
* 创建一个文本渲染器
* @param limit 节数限制(-1表示自动)
*/
TextRender *CreateTextRender(GPUDevice *,FontSource *,RenderPass *,GPUBuffer *,int limit);
TextRender *CreateTextRender(GPUDevice *,FontSource *,RenderPass *,DeviceBuffer *,int limit);
}//namespace graph
}//namespace hgl
#endif//HGL_GRAPH_TEXT_RENDER_INCLUDE

View File

@@ -3,13 +3,15 @@
#include<hgl/graph/TileData.h>
#include<hgl/graph/font/FontSource.h>
#include<hgl/type/ResPool.h>
#include<hgl/type/RefObjectPool.h>
namespace hgl
{
namespace graph
{
using TileResPool=ResPool<u32char,TileObject *>;
using TileUVFloatMap=Map<u32char,RectScope2f>;
using TileResPool=RefObjectPool<u32char,TileObject *>;
/**
* Tile字符管理<br>

View File

@@ -0,0 +1,30 @@
#ifndef HGL_GRAPH_MTL_2D_CREATE_CONFIG_INCLUDE
#define HGL_GRAPH_MTL_2D_CREATE_CONFIG_INCLUDE
#include<hgl/graph/mtl/MaterialConfig.h>
#include<hgl/graph/CoordinateSystem.h>
STD_MTL_NAMESPACE_BEGIN
struct Material2DCreateConfig:public MaterialCreateConfig
{
CoordinateSystem2D coordinate_system; ///<使用的坐标系
bool local_to_world; ///<包含LocalToWorld矩阵
public:
Material2DCreateConfig(const GPUDeviceAttribute *da,const AnsiString &name):MaterialCreateConfig(da,name)
{
rt_output.color=1; //输出一个颜色
rt_output.depth=false; //不输出深度
rt_output.stencil=false; //不输出stencil
coordinate_system=CoordinateSystem2D::NDC;
local_to_world=false;
}
};//struct Material2DCreateConfig:public MaterialCreateConfig
MaterialCreateInfo *CreateVertexColor2D(const Material2DCreateConfig *);
MaterialCreateInfo *CreatePureColor2D(const Material2DCreateConfig *);
STD_MTL_NAMESPACE_END
#endif//HGL_GRAPH_MTL_2D_CREATE_CONFIG_INCLUDE

View File

@@ -0,0 +1,37 @@
#ifndef HGL_GRAPH_MTL_CONFIG_INCLUDE
#define HGL_GRAPH_MTL_CONFIG_INCLUDE
#include<hgl/graph/mtl/StdMaterial.h>
#include<hgl/type/String.h>
#include<hgl/graph/RenderTargetOutputConfig.h>
#include<hgl/graph/VK.h>
STD_MTL_NAMESPACE_BEGIN
class MaterialCreateInfo;
/**
* 材质配置结构
*/
struct MaterialCreateConfig
{
const GPUDeviceAttribute *dev_attr;
AnsiString mtl_name; ///<材质名称
RenderTargetOutputConfig rt_output; ///<渲染目标输出配置
uint32 shader_stage_flag_bit; ///<需要的shader
public:
MaterialCreateConfig(const GPUDeviceAttribute *da,const AnsiString &name)
{
dev_attr=da;
mtl_name=name;
shader_stage_flag_bit=VK_SHADER_STAGE_VERTEX_BIT|VK_SHADER_STAGE_FRAGMENT_BIT;
}
};//struct MaterialCreateConfig
STD_MTL_NAMESPACE_END
#endif//HGL_GRAPH_MTL_CONFIG_INCLUDE

View File

@@ -0,0 +1,46 @@
#ifndef HGL_GRAPH_MATERIAL_VERTEX_FORMAT_INCLUDE
#define HGL_GRAPH_MATERIAL_VERTEX_FORMAT_INCLUDE
#include<hgl/type/DataType.h>
namespace hgl
{
namespace graph
{
/**
* Local 2 World <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ŷ<EFBFBD><C5B7><EFBFBD>
*
* 1.Push Constants <20><><EFBFBD><EFBFBD>
*
* 2.UBO <20>д<EFBFBD><D0B4><EFBFBD>matrix4f<34><66><EFBFBD>У<EFBFBD>vertex attrib<69>д<EFBFBD><D0B4><EFBFBD>ID
* UBOͨ<4F><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ16k/64k<34><6B>һ<EFBFBD><D2BB>matrix4fΪ64<36>ֽڡ<D6BD>
*
* 3.Vertex Attribute
*/
/**
* <20><><EFBFBD>ʶ<EFBFBD><CAB6><EFBFBD><EFBFBD>
*/
union MaterialVertexFormat
{
struct
{
uint position:3;
bool normal:1;
bool tangent:1;
bool bitangent:1;
uint color:4;
uint texcoord:4;
bool local2world:1;
bool skeleton:1;
};
uint32 format;
};//union MaterialVertexFormat
}//namespace graph
}//namespace hgl
#endif//HGL_GRAPH_MATERIAL_VERTEX_FORMAT_INCLUDE

View File

@@ -0,0 +1,18 @@
#ifndef HGL_GRAPH_MTL_SHADER_BUFFER_INCLUDE
#define HGL_GRAPH_MTL_SHADER_BUFFER_INCLUDE
#include<hgl/type/DataType.h>
namespace hgl
{
namespace graph
{
struct ShaderBufferSource
{
const char *struct_name;
const char *name;
const char *codes;
};
}//namespace graph
}//namespace hgl
#endif//HGL_GRAPH_MTL_SHADER_BUFFER_INCLUDE

View File

@@ -0,0 +1,16 @@
#pragma once
#define STD_MTL_NAMESPACE_BEGIN namespace hgl{namespace graph{namespace mtl{
#define STD_MTL_NAMESPACE_END }}}
#define STD_MTL_NAMESPACE_USING using namespace hgl::graph::mtl;
namespace hgl
{
namespace graph
{
namespace mtl
{
}//namespace mtl
}//namespace graph
}//namespace hgl

View File

@@ -0,0 +1,77 @@
#pragma once
#include<hgl/graph/mtl/StdMaterial.h>
#include<hgl/graph/mtl/ShaderBuffer.h>
STD_MTL_NAMESPACE_BEGIN
constexpr const ShaderBufferSource SBS_ViewportInfo=
{
"ViewportInfo",
"viewport",
R"(
mat4 ortho_matrix;
vec2 canvas_resolution;
vec2 viewport_resolution;
vec2 inv_viewport_resolution;
)"
};
constexpr const ShaderBufferSource SBS_CameraInfo=
{
"CameraInfo",
"camera",
R"(
mat4 projection;
mat4 inverse_projection;
mat4 view;
mat4 inverse_view;
mat4 vp;
mat4 inverse_vp;
mat4 sky;
vec3 pos; //eye
vec3 view_line; //pos-target
vec3 world_up;
float znear,zfar;)"
};
// UBO必须严格指定数组的大小
// SSBO则不需要使用[]方式指定为动态大小数组
constexpr const ShaderBufferSource SBS_LocalToWorld=
{
"LocalToWorldData",
"l2w",
R"(
mat4 mats[L2W_MAX_COUNT];)"
};
constexpr const char MaterialInstanceStruct[]="MaterialInstance";
constexpr const ShaderBufferSource SBS_MaterialInstance=
{
"MaterialInstanceData",
"mtl",
R"(
MaterialInstance mi[MI_MAX_COUNT];)"
};
constexpr const ShaderBufferSource SBS_JointInfo=
{
"JointInfo",
"joint",
R"(
mat4 mats[];
)"
};
STD_MTL_NAMESPACE_END

Some files were not shown because too many files have changed in this diff Show More