Compare commits

...

81 Commits

Author SHA1 Message Date
f23ef6c90e use short name in IDName 2025-01-14 12:54:19 +08:00
baa2e758f2 [WIP] 2025-01-09 00:48:15 +08:00
76103a869b [wip] 2025-01-08 13:26:27 +08:00
5738837008 update String<> names 2025-01-04 14:14:47 +08:00
3337eb6652 Merge branch 'devel_37_RenderFramework' of http://www.hyzgame.com:3000/hyzboy/ULRE into devel_37_RenderFramework
# Conflicts:
#	inc/hgl/graph/module/SwapchainModule.h
#	src/SceneGraph/module/GraphModule.cpp
2024-12-24 13:13:23 +08:00
c7ae16b2c8 created RenderTargetManager they are codes from TextureManager 2024-12-24 13:10:01 +08:00
07b71ec0fe few update 2024-12-24 02:45:02 +08:00
2516e9cfc1 splited InitDependentModules 2024-12-21 17:25:30 +08:00
bd9e587691 remove module_fullname from GraphModule. 2024-12-19 08:37:45 +08:00
260fb1b2ba few update about GraphModulesMap 2024-12-18 08:26:01 +08:00
34846acae0 [DON'T WORK] added dependent modules .... 2024-12-17 13:57:21 +08:00
d1c3934beb Use RenderFramework instead of GPUDevice at Init GraphModuleManager 2024-12-16 23:24:08 +08:00
7dd075b495 Merge branch 'devel_37_RenderFramework' of http://www.hyzgame.com:3000/hyzboy/ULRE into devel_37_RenderFramework
# Conflicts:
#	CMSceneGraph
#	CMUtil
#	inc/hgl/graph/module/GraphModule.h
2024-12-13 22:15:02 +08:00
ff475a69b1 GraphModuleManager construct include RenderFramework; 2024-12-13 00:30:44 +08:00
758acafe88 Added module_init in GraphModule, pareparing to splite "new" and "init" operation, because the dependency is must support. 2024-12-12 13:32:28 +08:00
c45047c482 suppported newly codes about Hash 2024-12-12 13:30:51 +08:00
6c160f5c53 supported new Comparator<> and ItemComparator<> 2024-12-12 13:30:11 +08:00
dd5a78cbaa renamed to Comparator.h from CompOperator.h 2024-12-05 13:55:56 +08:00
a1d8ad52cb use newly Compartor<> 2024-12-05 13:49:44 +08:00
4f335f7230 ordered module_list in RenderFramework 2024-11-19 00:20:35 +08:00
5217df7923 layout codes 2024-11-15 00:11:06 +08:00
abad1784c2 fixed Order for to release graph modules. 2024-11-14 23:40:26 +08:00
fda5b629a2 added to RenderCmdBuffer's Begin and End of Swapchain in RenderFramework::MainLoop 2024-11-14 00:24:13 +08:00
2ab78bf4e6 add transfer_family in DeviceAttribute 2024-11-13 00:16:41 +08:00
43b406ead0 use minImageCount in Swapchain 2024-11-13 00:15:53 +08:00
359c1cdc87 Init OK! but sumbit a null CmdBuffer is a Bug. 2024-11-13 00:01:26 +08:00
2bb1056b2a a part of RenderFramework::Init(..) 2024-11-12 01:51:14 +08:00
66b75aceb9 added InitRenderCmdBuffer/ClearRenderCmdBuffer in SwapchainModule 2024-11-12 01:50:40 +08:00
b775ffa920 BeginFrame/EndFrame for SwapchainModule/RenderFramework 2024-11-11 01:49:48 +08:00
9f37373631 use image_count instead of color_count in Swapchain 2024-11-11 01:18:28 +08:00
adc3c5bd81 all compile OK! but 100% can't run. 2024-11-09 19:28:31 +08:00
64e8410f3f redefrag SwapchainModule 2024-11-09 00:58:13 +08:00
25be75eefa Moved few codes to RenderPassManager from GPUDevice 2024-11-09 00:57:40 +08:00
c9855d7dee use XXHash3 instead of sha1-le in RenderPassManager 2024-11-09 00:41:15 +08:00
e3dccd6b06 Use XXHASH3_128bit instead of SHA1-LittleEndian in hash of RenderPass 2024-11-09 00:30:38 +08:00
21b2a3d5c8 moved new path about RenderPassManager 2024-11-09 00:20:21 +08:00
c5fd711c09 renamed to RenderPassManager from DeviceRenderPassManage 2024-11-09 00:13:21 +08:00
5d3f2cfdfd port DeviceRenderPassManage 2024-11-09 00:12:03 +08:00
6b466f63cf moved CreateFBO/CreateRT to TextureManager 2024-11-09 00:11:43 +08:00
336688b4f0 moved few codes to SwapchainModule 2024-11-09 00:10:27 +08:00
75fb0dd672 removed GraphManager.h/.cpp 2024-11-09 00:09:29 +08:00
c3a5518b38 moved Swapchain's codes to SwapchainModule 2024-11-06 00:34:23 +08:00
173d3e075a To add newly texture to set/map in TextureManager 2024-11-06 00:21:01 +08:00
8ff954b5c2 Added RenderFramework::GetTextureManager() 2024-11-06 00:19:37 +08:00
30d13ec2c7 removed device from VKTexture.h 2024-11-06 00:19:12 +08:00
acdbdcd8b5 few codes about TextureManager 2024-11-05 23:52:53 +08:00
95e9fe79a9 moved few codes to TextureManager 2024-11-05 23:12:35 +08:00
88f5948a2e moved LoadTexture2D/CreateTexture2DArray/LoadTextureCube to TextureManager from VKRenderResource 2024-11-05 23:02:38 +08:00
f6cc1ee619 Added GraphModuleManager::ReleaseModule(GraphModule *) 2024-11-05 23:01:45 +08:00
f1f562c709 restruct codes for TextureManager 2024-11-05 00:04:36 +08:00
1543ed8952 renamed to SortedSet instead of SortedSets 2024-11-04 23:06:57 +08:00
6c6e1c1a8d Renamed to VKTexture.....cpp from VKDeviceTexture....cpp 2024-10-30 22:22:55 +08:00
722faa1a27 added WorldCoord in LightCullMode.h 2024-10-30 00:51:50 +08:00
3e88b0b77f Added RenderBufferName.h,RenderWorkflow.h and few update. 2024-10-30 00:29:20 +08:00
5ba5a331a5 moved Check()/Comp()/From() to .cpp from ShaderVariableType.h 2024-10-29 23:40:32 +08:00
f741825ab7 Added WindowMode.h 2024-10-29 02:25:45 +08:00
6bc9352c80 added BlendOpAdvanced support, but no test. 2024-10-29 01:48:59 +08:00
e99b669ef3 removed graph_module_manager/swapchain_mode from GPUDevice. 2024-10-29 01:48:38 +08:00
ffc6f0a074 split to BlendMode.h/LightCullMode.h from RenderFramework.h 2024-10-29 01:47:24 +08:00
d1ad3f35ac moved few codes to SwapchainModule 2024-10-29 00:50:32 +08:00
4f870edc3b redefined RenderFramework 2024-10-29 00:50:15 +08:00
2ffe402fae update codes of about TextureLoader 2024-10-29 00:49:47 +08:00
d3df8d50ca used GetVkDevice() instead of GetVulkanDevice() 2024-10-29 00:36:48 +08:00
2221e10750 Added GraphManager/TextureManager, moved few codes to they are. 2024-10-29 00:34:02 +08:00
983281f6ad splited to GraphModuleManager.cpp 2024-10-25 23:17:14 +08:00
1183e44221 Added RegistryCommonModule.cpp 2024-10-24 00:29:16 +08:00
e52f7c13a9 use AnsiIDName instead of AnsiString in GraphModuleMap 2024-10-23 23:22:41 +08:00
7d586182c8 Added GraphModuleFactory/SwapchainModule, but can't run 2024-10-23 02:09:01 +08:00
c3522da518 little codes of RenderFramework/RenderModule 2024-10-23 01:13:15 +08:00
7a373d6bc0 InitGraphModuleManager/ClearGraphModuleManager in GPUDevice. 2024-10-23 01:12:36 +08:00
62f2e4f819 first edition of GraphModule/GraphModuleManager 2024-10-23 01:11:57 +08:00
427d337845 Added GraphModule.cpp/.h 2024-10-22 01:51:25 +08:00
a0b0027663 added Component.cpp/StaticMeshComponent.h/.cpp 2024-10-20 23:28:46 +08:00
83c1a067fe Added Owner in SceneNode, and then have few other change. 2024-10-20 23:17:04 +08:00
0df9d64dcf Moved Pipeline to MaterialRenderMap from MaterialRenderList 2024-10-20 21:41:27 +08:00
6e54a4051d litte modified GBufferFormat.cpp/.h 2024-10-20 01:41:38 +08:00
5195f62ac5 few change 2024-10-20 01:41:13 +08:00
4f67c0184d removed ## 2024-10-20 01:40:52 +08:00
dc374c0fc7 added CheckColorAttachmentFormatSupport/CheckDepthStencilAttachFormatSupport in GPUDevice 2024-10-20 01:19:06 +08:00
ceb4e3e5f3 renamed SwapchainPrefer colorspaces 2024-10-20 01:18:42 +08:00
59b3ec6bf3 preparing RenderFramework 2024-10-19 13:08:05 +08:00
117 changed files with 2906 additions and 1058 deletions

@ -1 +1 @@
Subproject commit 85436b5a7b0bc9347fcd3321a6895464470f1353
Subproject commit 0fae462338cd01c5a26d0a8f0175fe3729a65c94

2
CMCore

@ -1 +1 @@
Subproject commit 09d777261f4249ccdba5bef44d794742f4e3237a
Subproject commit 29e758f96317da6e01173faf4efa1dc4ca3a43b2

@ -1 +1 @@
Subproject commit 103b0d845dc9fdbc10e2e40ab0fa346d133dc1ae
Subproject commit aa7abe47631cdb687528400409ef295fd2c050b8

@ -1 +1 @@
Subproject commit 9ff596c42437ada641f62b4d0d2bfae535638666
Subproject commit 4949c2e3e82c8a88a783579aff120617c4ecfdab

2
CMUtil

@ -1 +1 @@
Subproject commit f7dce0304822280d0db23ae607783b7c3cd183fa
Subproject commit 57ff3a70c99265ed7bb97b3b6840709e84bac0c1

View File

@ -10,6 +10,7 @@
set_property(TARGET ${name} PROPERTY FOLDER "ULRE/Example/Basic")
endmacro()
CreateProject(00_first_app first_app.cpp)
CreateProject(01_draw_triangle_in_NDC draw_triangle_in_NDC.cpp)
CreateProject(02_draw_triangle_use_UBO draw_triangle_use_UBO.cpp)
CreateProject(03_auto_instance auto_instance.cpp)

View File

@ -0,0 +1,40 @@
#include<hgl/graph/RenderFramework.h>
#include<hgl/graph/module/RenderModule.h>
#include<hgl/graph/VKCommandBuffer.h>
#include<hgl/log/Logger.h>
using namespace hgl;
using namespace hgl::graph;
class TestRenderModule:public RenderModule
{
public:
RENDER_MODULE_CONSTRUCT(TestRenderModule)
void OnResize(const VkExtent2D &size) override
{
LOG_INFO(OS_TEXT("Resize: ")+OSString::numberOf(size.width)+OS_TEXT("x")+OSString::numberOf(size.height));
}
void OnFrameRender(const double,RenderCmdBuffer *cmd) override
{
LOG_INFO(OS_TEXT("Execute"));
//cmd->Begin
}
};//class TestGraphModule:public RenderModule
int os_main(int,os_char **)
{
RenderFramework rf;
if(!rf.Init(1280,720,OS_TEXT("FirstApp")))
return 1;
rf.AddModule<TestRenderModule>();
rf.Run();
return 0;
}

View File

@ -28,7 +28,7 @@ private:
bool InitTextRenderable()
{
UTF16String str;
U16String str;
LoadStringFromTextFile(str,OS_TEXT("res/text/DaoDeBible.txt"));

View File

@ -38,18 +38,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:
Window * win =nullptr;
VulkanInstance * inst =nullptr;
Window * win =nullptr;
VulkanInstance * inst =nullptr;
protected:
@ -84,10 +78,13 @@ public:
rr->static_descriptor.AddUBO(mtl::SBS_ViewportInfo.name,ubo_vp_info);
}
VulkanApplicationFramework()
{
RegistryCommonGraphModule();
}
virtual ~VulkanApplicationFramework()
{
CloseShaderCompiler();
win->Unjoin(this);
SAFE_CLEAR(db);
@ -102,9 +99,6 @@ public:
{
logger::InitLogger(OS_TEXT("VulkanTest"));
if(!InitShaderCompiler())
return(false);
SetClearColor(COLOR::MozillaCharcoal);
#ifdef _DEBUG

23
inc/hgl/graph/BlendMode.h Normal file
View File

@ -0,0 +1,23 @@
#pragma once
#include<hgl/graph/VKNamespace.h>
#include<hgl/TypeFunc.h>
VK_NAMESPACE_BEGIN
enum class BlendMode
{
Opaque,
Mask,
Transparent, ///<普通的Alpha混合透明
PreMulti, ///<预乘的Alpha混合透明
Add, ///<加法混合
Subtract, ///<减法混合
ReverseSubtract, ///<反减混合
Min, ///<最小混合
Max, ///<最大混合
ENUM_CLASS_RANGE(Opaque,Max)
};
VK_NAMESPACE_END

61
inc/hgl/graph/Component.h Normal file
View File

@ -0,0 +1,61 @@
#pragma once
#include<hgl/type/TypeInfo.h>
#include<hgl/graph/VK.h>
VK_NAMESPACE_BEGIN
class SceneNode;
class ComponentData
{
};//class ComponentData
class ComponentManager;
class Component
{
ComponentData *data;
SceneNode *owner_node;
ComponentManager *manager;
public:
virtual const size_t GetTypeHash()=0; ///<取得当前组件类型
SceneNode *GetOwnerNode()const{return owner_node;} ///<取得当前组件所属节点
ComponentManager *GetManager()const{return manager;} ///<取得当前组件所属管理器
public:
Component()
{
data=nullptr;
owner_node=nullptr;
manager=nullptr;
}
Component(SceneNode *sn,ComponentData *cd,ComponentManager *cm);
virtual ~Component()=default;
virtual void Update(const double delta_time){}; ///<更新组件
};//class Component
class ComponentManager
{
ObjectList<Component> component_list;
public:
virtual void Update(const double delta_time)
{
for(Component *c:component_list)
{
c->Update(delta_time);
}
}
};//class ComponentManager
VK_NAMESPACE_END

View File

@ -0,0 +1,45 @@
#pragma once
#include<hgl/graph/VKNamespace.h>
#include<hgl/TypeFunc.h>
VK_NAMESPACE_BEGIN
/**
*
*/
enum class LightingCullingMode
{
None, ///<不剔除
/**
*
*
*
*/
WorldCoord, ///<世界坐标剔除
/*
* Tile的剔除模式
* XY坐标划分成多个Tileznear/zfar形成一个VolumeVolume计算相交性
*/
Tile, ///<瓦片剔除
/**
* Tile的剔除模式的改进型
* Tile方法Tile后Tile内所有象素Tile的最远z值和最近z值
* XY与zNear/zFar得出一个VolumeVolume相交性
*/
TileVolume, ///<瓦片体积剔除
/**
* Tile的剔除模式的改进型
* TileVolume方法得出Volume后Volume按深度划分成多个Volume
* VolumeVolume与光源计算相交性
*/
Cluster, ///<集簇剔除
ENUM_CLASS_RANGE(None,Cluster)
};//enum class LightingCullingMode
VK_NAMESPACE_END

View File

@ -0,0 +1,73 @@
#pragma once
#include<hgl/graph/VK.h>
VK_NAMESPACE_BEGIN
enum class LightingModel:uint8
{
Unlit,
Gizmo, ///<Gizmo专用(Blinnphong的特定版本内置假的太阳光方向、高光系数等使其不需要外部UBO传入)
Blinnphong, ///<Blinnphong光照模型
FakePBR, ///<假PBR(使用Blinnphong+HalfLambert模拟)
MicroPBR, ///<微型PBR(只有BaseColor/Normal/Metallic/Roughness四个基础数据的PBR)
WebPBR, ///<Khronos为WebGL提供的PBR
FilamentPBR, ///<Filament引擎所提供的PBR
AMDPBR, ///<AMD Caulrdon框架所提供的PBR
BlenderPBR, ///<Blender所提供的PBR
ENUM_CLASS_RANGE(Unlit,BlenderPBR)
};//enum class LightingModel:uint8
constexpr const char *LightingModelName[]=
{
"Unlit",
"Gizmo",
"Blinnphong",
"FakePBR",
"MicroPBR",
"WebPBR",
"FilamentPBR",
"AMDPBR",
"BlenderPBR"
};
/**
*
*/
enum class SkyLightSource:uint8
{
PureColor, ///<纯色
GradientColor, ///<过渡色
Cubemap, ///<立方体贴图
IBL, ///<IBL立方体贴图
ENUM_CLASS_RANGE(PureColor,IBL)
};//enum class SkyLightSource:uint8
/**
*
*/
enum class AmbientLightSource:uint8
{
PureColor, ///<纯色
Distance, ///<距离(用于显示深邃场景比如峡谷、深井、管道越远越黑。理论等同AO)
LightProbe, ///<光线探针(也许也是Cubemap也许不是)
Cubemap, ///<本地Cubemap
};//enum class AmbientLightSource:uint8
VK_NAMESPACE_END

View File

@ -8,15 +8,48 @@ class RenderAssignBuffer;
class SceneNode;
struct CameraInfo;
struct RenderPipelineIndex:public Comparator<RenderPipelineIndex>
{
Material *material;
Pipeline *pipeline;
public:
const int compare(const RenderPipelineIndex &rli)const override
{
if(material<rli.material)return(-1);
if(material>rli.material)return(1);
if(pipeline<rli.pipeline)return(-1);
if(pipeline>rli.pipeline)return(1);
return(0);
}
public:
RenderPipelineIndex()
{
material=nullptr;
pipeline=nullptr;
}
RenderPipelineIndex(Material *m,Pipeline *p)
{
material=m;
pipeline=p;
}
};//struct RenderPipelineIndex
/**
*
* 线
*/
class MaterialRenderList
{
GPUDevice *device;
RenderCmdBuffer *cmd_buf;
Material *material;
RenderPipelineIndex rp_index;
CameraInfo *camera_info;
@ -33,7 +66,6 @@ private:
uint32_t first_instance; ///<第一个绘制实例(和instance渲染无关,对应InstanceRate的VAB)
uint32_t instance_count;
Pipeline * pipeline;
MaterialInstance * mi;
const PrimitiveDataBuffer * pdb;
@ -60,7 +92,6 @@ protected:
VABList * vab_list;
Pipeline * last_pipeline;
const PrimitiveDataBuffer * last_data_buffer;
const VDM * last_vdm;
const PrimitiveRenderData * last_render_data;
@ -75,20 +106,14 @@ protected:
public:
MaterialRenderList(GPUDevice *d,bool l2w,Material *m);
MaterialRenderList(GPUDevice *d,bool l2w,const RenderPipelineIndex &rpi);
~MaterialRenderList();
void Add(SceneNode *);
void SetCameraInfo(CameraInfo *ci)
{
camera_info=ci;
}
void SetCameraInfo(CameraInfo *ci){camera_info=ci;}
void Clear()
{
rn_list.Clear();
}
void Clear(){rn_list.Clear();}
void End();

View File

@ -2,7 +2,7 @@
#include<hgl/graph/MaterialRenderList.h>
VK_NAMESPACE_BEGIN
class MaterialRenderMap:public ObjectMap<Material *,MaterialRenderList>
class MaterialRenderMap:public ObjectMap<RenderPipelineIndex,MaterialRenderList>
{
public:

View File

@ -0,0 +1,61 @@
#pragma once
#include<hgl/graph/VK.h>
VK_NAMESPACE_BEGIN
const RENDER_BUFFER_NAME RenderBuffer_Swapchain ="Swapchain";
const RENDER_BUFFER_NAME RenderBuffer_Depth ="Depth";
const RENDER_BUFFER_NAME RenderBuffer_Stencil ="Stencil";
const RENDER_BUFFER_NAME VBuffer_MeshID ="VB_MeshID"; ///< 所绘制的Mesh编号, RGBA8UI格式
const RENDER_BUFFER_NAME VBuffer_TriangleID ="VB_TriangleID"; ///< 三角形编号, R8UI格式
const RENDER_BUFFER_NAME VBuffer_MaterialID ="VB_MaterialID"; ///< 材质ID与材质实例ID, RG8UI格式
const RENDER_BUFFER_NAME GBuffer_BaseColor ="GB_BaseColor"; ///<基础颜色(RGB565/RGB5A1/RGBA8/RGB10A2/RG11B10,RGBA16F)
const RENDER_BUFFER_NAME GBuffer_Luminance ="GB_Luminance"; ///<亮度(R8/R16F/R32F)
const RENDER_BUFFER_NAME GBuffer_CbCr ="GB_CbCr"; ///<色度(RG8/RG16F)
const RENDER_BUFFER_NAME GBuffer_Normal ="GB_Normal"; ///<法线(RG8,RG16F)
const RENDER_BUFFER_NAME GBuffer_BentNormal ="GB_BentNormal"; ///<弯曲法线(RG8,RG16F)
const RENDER_BUFFER_NAME GBuffer_Metallic ="GB_Metallic"; ///<金属度(R8/R16F/R32F)
const RENDER_BUFFER_NAME GBuffer_Roughness ="GB_Roughness"; ///<粗糙度(R8/R16F/R32F)
const RENDER_BUFFER_NAME GBuffer_Specular ="GB_Specular"; ///<高光(R8/R16F/R32F)
const RENDER_BUFFER_NAME GBuffer_Glossiness ="GB_Glossiness"; ///<光泽度(R8/R16F/R32F)
const RENDER_BUFFER_NAME GBuffer_Reflection ="GB_Reflection"; ///<反射(R8)
const RENDER_BUFFER_NAME GBuffer_Refraction ="GB_Refraction"; ///<折射(R8)
const RENDER_BUFFER_NAME GBuffer_ClearCoat ="GB_ClearCoat"; ///<透明涂层(R8/R16F/R32F)
const RENDER_BUFFER_NAME GBuffer_ClearCoatRoughness ="GB_ClearCoatRoughness"; ///<透明涂层粗糙度(R8/R16F/R32F)
const RENDER_BUFFER_NAME GBuffer_ClearCoatNormal ="GB_ClearCoatNormal"; ///<透明涂层法线(RG8/RG16F)
const RENDER_BUFFER_NAME GBuffer_IOR ="GB_IOR"; ///<折射率(R8/R16F/R32F)
const RENDER_BUFFER_NAME GBuffer_Tranmission ="GB_Tranmission"; ///<透射率(R8/R16F/R32F)
const RENDER_BUFFER_NAME GBuffer_Absorption ="GB_Absorption"; ///<吸收率(R8/R16F/R32F)
const RENDER_BUFFER_NAME GBuffer_MicroThickness ="GB_MicroThickness"; ///<微厚度(R8/R16F/R32F)
const RENDER_BUFFER_NAME GBuffer_AmbientOcclusion ="GB_AmbientOcclusion"; ///<环境光遮蔽(R8/R16F/R32F)
const RENDER_BUFFER_NAME GBuffer_Anisotropy ="GB_Anisotropy"; ///<各向异性(R8/R16F/R32F)
const RENDER_BUFFER_NAME GBuffer_AnisotropyDirection="GB_AnisotropyDirection"; ///<各向异性方向(RG8/RG16F/RG32F)
const RENDER_BUFFER_NAME GBuffer_Emissive ="GB_Emissive"; ///<自发光(RGB565/RGB5A1/RGBA8/RGB10A2/RG11B10,RGBA16F)
const RENDER_BUFFER_NAME GBuffer_SheenColor ="GB_SheenColor"; ///<光泽颜色(RGB565/RGB5A1/RGBA8/RGB10A2/RG11B10,RGBA16F)
const RENDER_BUFFER_NAME GBuffer_SheenRoughness ="GB_SheenRoughness"; ///<光泽粗糙度(R8/R16F/R32F)
const RENDER_BUFFER_NAME GBuffer_SubsurfaceColor ="GB_SubsurfaceColor"; ///<次表面颜色(RGB565/RGB5A1/RGBA8/RGB10A2/RG11B10,RGBA16F)
const RENDER_BUFFER_NAME GBuffer_ShadingModel ="GB_ShadingModel"; ///<着色模型(R4UI/R8UI)
const RENDER_BUFFER_NAME GBuffer_LightingChannels ="GB_LightingChannels"; ///<光照通道(R8UI)
const RENDER_BUFFER_NAME GBuffer_MotionVector ="GB_MotionVector"; ///<运动矢量(RG16F)
const RENDER_BUFFER_NAME GBuffer_LastScreenPosition ="GB_LastScreenPosition"; ///<上一帧屏幕位置(RG16I)
VK_NAMESPACE_END

View File

@ -0,0 +1,145 @@
#pragma once
#include<hgl/type/List.h>
#include<hgl/platform/Window.h>
#include<hgl/graph/BlendMode.h>
#include<hgl/graph/ViewportInfo.h>
#include<hgl/graph/module/GraphModuleMap.h>
#include<hgl/graph/VKDevice.h>
VK_NAMESPACE_BEGIN
class GPUDevice;
class TileData;
class TileFont;
class FontSource;
class VulkanInstance;
class RenderPassManager;
class TextureManager;
class SwapchainModule;
/**
*
*/
class RenderFramework:public io::WindowEvent
{
protected:
Window * win =nullptr;
VulkanInstance * inst =nullptr;
GPUDevice * device =nullptr;
protected:
GraphModulesMap graph_module_map;
List<GraphModule *> per_frame_module_list;
List<RenderModule *> render_module_list;
protected:
SwapchainModule * swapchain_module =nullptr;
protected:
RenderPassManager * render_pass_manager =nullptr;
TextureManager * texture_manager =nullptr;
protected:
ViewportInfo viewport_info;
private:
double last_time =0;
double cur_time =0;
int64 frame_count =0;
public:
const int64 GetFrameCount ()const noexcept{return frame_count;} ///<取得当前帧数
void RestartFrameCount ()noexcept{frame_count=0;} ///<重新开始统计帧数
public: //module
template<typename T>
T * GetModule(){return graph_module_map.Get<T>();} ///<获取指定类型的模块
GraphModule * GetModule(const AIDName &name,bool create=false); ///<获取指定名称的模块
//template<typename T> T *AddModule()
//{
// T *tm=new T(graph_module_manager);
// module_list.Add(tm);
// if(tm->IsPerFrame())
// per_frame_module_list.Add(tm);
// if(tm->IsRender())
// render_module_list.Add(tm);
// return tm;
//}
GPUDevice * GetDevice () {return device;}
VkDevice GetVkDevice ()const {return device->GetDevice();}
const GPUPhysicalDevice * GetPhysicalDevice ()const {return device->GetPhysicalDevice();} ///<取得物理设备
GPUDeviceAttribute *GetDeviceAttribute () {return device->GetDeviceAttribute();} ///<取得设备属性
SwapchainModule * GetSwapchain () {return swapchain_module;} ///<取得Swapchain模块
public: //manager
RenderPassManager * GetRenderPassManager(){return render_pass_manager;} ///<取得渲染通道管理器
TextureManager * GetTextureManager (){return texture_manager;} ///<取得纹理管理器
public: //event
virtual void OnResize(uint,uint)override;
virtual void OnActive(bool)override;
virtual void OnClose ()override;
public:
NO_COPY_NO_MOVE(RenderFramework)
private:
RenderFramework();
friend RenderFramework *CreateRenderFramework();
public:
virtual ~RenderFramework();
virtual bool Init(uint w,uint h,const OSString &app_name); ///<初始化
virtual void StartTime();
/**
* @pragma delta_time
*/
virtual void Update(const double delta_time){}
virtual void BeginFrame(); ///<开始当前帧
virtual void EndFrame(); ///<当前帧结束
virtual void MainLoop(); ///<主循环
virtual void Run();
public: //TileData
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字体
};//class RenderFramework
RenderFramework *CreateRenderFramework();
VK_NAMESPACE_END

View File

@ -2,7 +2,7 @@
#define HGL_GRAPH_RENDER_NODE_INCLUDE
#include<hgl/graph/VK.h>
#include<hgl/type/SortedSets.h>
#include<hgl/type/SortedSet.h>
namespace hgl
{
namespace graph
@ -11,9 +11,9 @@ namespace hgl
class MaterialInstance;
class SceneNode;
struct RenderNode
struct RenderNode:public Comparator<RenderNode>
{
uint index; ///<在MaterialRenderList中的索引
uint index; ///<在MaterialRenderList中的索引
SceneNode * scene_node;
@ -22,12 +22,17 @@ namespace hgl
Vector3f world_position;
float to_camera_distance;
public:
//该函数位于MaterialRenderList.cpp
const int compare(const RenderNode &)const override;
};
using RenderNodeList=List<RenderNode>;
using RenderNodePointerList=List<RenderNode *>;
using MaterialInstanceSets=SortedSets<MaterialInstance *>; ///<材质实例集合
using MaterialInstanceSets=SortedSet<MaterialInstance *>; ///<材质实例集合
}//namespace graph
}//namespace hgl
#endif//HGL_GRAPH_RENDER_NODE_INCLUDE

View File

@ -0,0 +1,30 @@
#pragma once
#include<hgl/graph/BlendMode.h>
#include<hgl/graph/RenderBufferName.h>
#include<hgl/type/SortedSet.h>
VK_NAMESPACE_BEGIN
enum class RenderOrder
{
First, ///<最先渲染
NearToFar, ///<从近到远
Irrorder, ///<无序渲染
FarToNear, ///<从远到近
Last, ///<最后渲染
ENUM_CLASS_RANGE(First,Last)
};//enum class RenderOrder
struct RenderWorkConfig
{
BlendMode blend_mode;
RenderOrder render_order;
SortedSet<RENDER_BUFFER_NAME> output_buffer;
};//struct RenderWorkConfig;
VK_NAMESPACE_END

View File

@ -10,7 +10,7 @@ namespace hgl
namespace graph
{
using SceneNodeID =uint64;
using SceneNodeName =UTF16IDName;
using SceneNodeName =U16IDName;
/**
* <br>
@ -19,6 +19,8 @@ namespace hgl
*/
class SceneNode:public SceneOrient ///场景节点类
{
SceneNode *Owner; ///<上级节点
SceneNodeID NodeID; ///<节点ID
SceneNodeName NodeName; ///<节点名称
@ -59,6 +61,8 @@ namespace hgl
{
SceneOrient::Clear();
Owner=nullptr;
BoundingBox.SetZero();
LocalBoundingBox.SetZero();
@ -74,8 +78,13 @@ namespace hgl
return(true);
}
Renderable *GetRenderable(){return render_obj;}
void SetRenderable(Renderable *);
void SetOwner(SceneNode *sn) {Owner=sn;}
SceneNode * GetOwner() noexcept{return Owner;}
const SceneNode * GetOwner()const noexcept{return Owner;}
void SetRenderable(Renderable *);
Renderable *GetRenderable() noexcept{return render_obj;}
const Renderable *GetRenderable()const noexcept{return render_obj;}
SceneNode *Add(SceneNode *sn)
{
@ -83,6 +92,7 @@ namespace hgl
return(nullptr);
ChildNode.Add(sn);
sn->SetOwner(this);
return sn;
}

View File

@ -12,13 +12,15 @@ namespace hgl
{
namespace graph
{
class TextureManager;
/**
* TileData是一种处理大量等同尺寸及格式贴图的管理机制(Tile的大小不必符合2次幂)
* Tile的增加或删除I/O消耗
*/
class TileData ///Tile纹理管理
{
GPUDevice *device;
TextureManager *texture_manager;
protected:
@ -52,7 +54,7 @@ namespace hgl
public:
TileData(GPUDevice *,Texture2D *,const uint tw,const uint th);
TileData(TextureManager *,Texture2D *,const uint tw,const uint th);
virtual ~TileData();
void BeginCommit();

View File

@ -1,10 +1,10 @@
#ifndef HGL_GRAPH_VULKAN_INCLUDE
#define HGL_GRAPH_VULKAN_INCLUDE
#pragma once
#include<hgl/type/List.h>
#include<hgl/math/Math.h>
#include<hgl/type/String.h>
#include<hgl/type/Map.h>
#include<hgl/type/IDName.h>
#include<hgl/graph/VKNamespace.h>
#include<hgl/graph/VKFormat.h>
#include<hgl/graph/VKPrimitiveType.h>
@ -25,6 +25,20 @@ constexpr size_t VK_DESCRIPTOR_TYPE_END_RANGE=VK_DESCRIPTOR_TYPE_INPUT_ATTACHMEN
constexpr size_t VK_DESCRIPTOR_TYPE_RANGE_SIZE=VK_DESCRIPTOR_TYPE_END_RANGE-VK_DESCRIPTOR_TYPE_BEGIN_RANGE+1;
#endif//VK_DESCRIPTOR_TYPE_RANGE_SIZE
DefineIDName(TEXTURE_NAME,char)
DefineIDName(SHADER_NAME,char)
DefineIDName(RENDER_BUFFER_NAME,char)
class TextureManager;
class GraphModule;
class RenderModule;
class GraphModuleManager;
class SwapchainModule;
void RegistryCommonGraphModule();
using BindingMap =Map<AnsiString,int>;
using BindingMapArray =BindingMap[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
@ -39,6 +53,12 @@ struct Swapchain;
class RenderTarget;
class RTSwapchain;
struct CopyBufferToImageInfo;
struct TextureData;
struct TextureCreateInfo;
struct Image2DRegion;
class Texture;
class Texture1D;
class Texture1DArray;
@ -70,7 +90,7 @@ class RenderCmdBuffer;
class TextureCmdBuffer;
class RenderPass;
class DeviceRenderPassManage;
class RenderPassManager;
class Fence;
class Semaphore;
@ -175,4 +195,3 @@ inline void copy(VkExtent3D &e3d,const VkExtent2D &e2d,const uint32 depth=1)
e3d.depth =depth;
}
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_INCLUDE

View File

@ -36,6 +36,7 @@ private:
}
public:
~DebugUtils()=default;
void SetName(VkObjectType,uint64_t,const char *);
@ -76,10 +77,10 @@ public:
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(VideoSessionParametersKHR, VIDEO_SESSION_PARAMETERS_KHR)
DU_FUNC(CuModuleNVX, CU_MODULE_NVX)
DU_FUNC(CuFunctionNVX, CU_FUNCTION_NVX)
DU_FUNC(DebugUtilsMessengerEXT, DEBUG_UTILS_MESSENGER_EXT)

View File

@ -4,7 +4,7 @@
#include<hgl/graph/VK.h>
#include<hgl/type/Map.h>
#include<hgl/type/ObjectList.h>
#include<hgl/type/SortedSets.h>
#include<hgl/type/SortedSet.h>
VK_NAMESPACE_BEGIN
class DeviceBuffer;
@ -20,7 +20,7 @@ class DescriptorSet
ObjectList<VkDescriptorImageInfo> image_list;
List<VkWriteDescriptorSet> wds_list;
SortedSets<uint32_t> binded_sets;
SortedSet<uint32_t> binded_sets;
bool is_dirty;

View File

@ -4,8 +4,6 @@
#include<hgl/type/List.h>
#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/BitmapData.h>
#include<hgl/graph/font/Font.h>
@ -18,6 +16,9 @@
#include<hgl/graph/VKDescriptorSetType.h>
VK_NAMESPACE_BEGIN
class SwapchainModule;
class TileData;
class TileFont;
class FontSource;
@ -30,31 +31,14 @@ struct CopyBufferToImageInfo;
class GPUDevice
{
GPUDeviceAttribute *attr;
DeviceQueue *texture_queue;
TextureCmdBuffer *texture_cmd_buf;
private:
DeviceRenderPassManage *render_pass_manage;
RenderPass *device_render_pass;
RTSwapchain *sc_rt;
RTSwapchain *CreateSwapchainRenderTarget();
void InitRenderPassManage();
void ClearRenderPassManage();
GPUDeviceAttribute *attr;
private:
VkCommandBuffer CreateCommandBuffer(const AnsiString &);
bool CreateSwapchainFBO(Swapchain *);
Swapchain *CreateSwapchain(const VkExtent2D &acquire_extent);
private:
friend class VulkanDeviceCreater;
@ -79,26 +63,10 @@ public:
const VkColorSpaceKHR GetColorSpace ()const {return attr->surface_format.colorSpace;}
VkQueue GetGraphicsQueue () {return attr->graphics_queue;}
RenderPass * GetRenderPass () {return device_render_pass;}
RTSwapchain * GetSwapchainRT () {return sc_rt;}
const VkExtent2D & GetSwapchainSize ()const {return sc_rt->GetExtent();}
void WaitIdle ()const {vkDeviceWaitIdle(attr->device);}
DebugUtils * GetDebugUtils (){return attr->debug_utils;}
public:
bool Resize (const VkExtent2D &);
bool Resize (const uint32_t &w,const uint32_t &h)
{
VkExtent2D extent={w,h};
return Resize(extent);
}
public: //内存相关
DeviceMemory *CreateMemory(const VkMemoryRequirements &,const uint32_t properties);
@ -160,57 +128,6 @@ public: //间接绘制
IndirectDrawIndexedBuffer * CreateIndirectDrawIndexedBuffer(const uint32_t cmd_count,SharingMode sm=SharingMode::Exclusive);
IndirectDispatchBuffer * CreateIndirectDispatchBuffer( const uint32_t cmd_count,SharingMode sm=SharingMode::Exclusive);
public: //Image
VkImage CreateImage (VkImageCreateInfo *);
void DestroyImage (VkImage);
private: //texture
bool CopyBufferToImage (const CopyBufferToImageInfo *info,VkPipelineStageFlags destinationStage);
bool CopyBufferToImage (Texture *,DeviceBuffer *buf,const VkBufferImageCopy *,const int count,const uint32_t base_layer,const uint32_t layer_count,VkPipelineStageFlags);//=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
bool CopyBufferToImage2D (Texture *tex,DeviceBuffer *buf,const VkBufferImageCopy *bic_list,const int bic_count, VkPipelineStageFlags dstStage){return CopyBufferToImage(tex,buf,bic_list, bic_count, 0,1,dstStage);}
bool CopyBufferToImage2D (Texture *tex,DeviceBuffer *buf,const VkBufferImageCopy *bic, VkPipelineStageFlags dstStage){return CopyBufferToImage(tex,buf,bic, 1, 0,1,dstStage);}
bool CopyBufferToImageCube (Texture *tex,DeviceBuffer *buf,const VkBufferImageCopy *bic_list,const int bic_count, VkPipelineStageFlags dstStage){return CopyBufferToImage(tex,buf,bic_list, bic_count, 0,6,dstStage);}
bool CopyBufferToImageCube (Texture *tex,DeviceBuffer *buf,const VkBufferImageCopy *bic, VkPipelineStageFlags dstStage){return CopyBufferToImage(tex,buf,bic, 1, 0,6,dstStage);}
bool CommitTexture2D (Texture2D *,DeviceBuffer *buf,VkPipelineStageFlags stage);
bool CommitTexture2DMipmaps (Texture2D *,DeviceBuffer *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); ///<提交纹理处理到队列
public: //Texture
bool CheckFormatSupport(const VkFormat,const uint32_t bits,ImageTiling tiling=ImageTiling::Optimal)const;
bool CheckTextureFormatSupport(const VkFormat fmt,ImageTiling tiling=ImageTiling::Optimal)const{return CheckFormatSupport(fmt,VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT,tiling);}
Texture2D *CreateTexture2D(TextureData *);
Texture2D *CreateTexture2D(TextureCreateInfo *ci);
Texture2DArray *CreateTexture2DArray(TextureData *);
Texture2DArray *CreateTexture2DArray(TextureCreateInfo *ci);
Texture2DArray *CreateTexture2DArray(const uint32_t w,const uint32_t h,const uint32 l,const VkFormat fmt,const bool mipmaps);
TextureCube *CreateTextureCube(TextureData *);
TextureCube *CreateTextureCube(TextureCreateInfo *ci);
void Clear(TextureCreateInfo *);
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);
// bool ChangeTexture2DArray(Texture2DArray *,DeviceBuffer *buf, const List<Image2DRegion> &, const uint32_t base_layer,const uint32_t layer_count,VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
bool ChangeTexture2DArray(Texture2DArray *,DeviceBuffer *buf, const RectScope2ui &, const uint32_t base_layer,const uint32_t layer_count,VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
bool ChangeTexture2DArray(Texture2DArray *,void *data,const uint32_t size,const RectScope2ui &, const uint32_t base_layer,const uint32_t layer_count,VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
public: //
Sampler *CreateSampler(VkSamplerCreateInfo *sci=nullptr);
@ -237,24 +154,6 @@ public:
Semaphore * CreateGPUSemaphore();
DeviceQueue *CreateQueue(const uint32_t fence_count=1,const bool create_signaled=false);
public: //FrameBuffer相关
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 *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字体
};//class GPUDevice
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_DEVICE_INCLUDE

View File

@ -24,11 +24,9 @@ struct GPUDeviceAttribute
uint32_t graphics_family =ERROR_FAMILY_INDEX;
uint32_t present_family =ERROR_FAMILY_INDEX;
uint32_t compute_family =ERROR_FAMILY_INDEX;
uint32_t transfer_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;
@ -39,6 +37,8 @@ struct GPUDeviceAttribute
VkSurfaceTransformFlagBitsKHR preTransform;
VkCompositeAlphaFlagBitsKHR compositeAlpha =VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
bool blendOpAdvance =false;
bool uint8_index_type=false;
bool uint32_index_type=false;

View File

@ -98,6 +98,8 @@ struct VulkanHardwareRequirement
uint32_t descriptor_pool; ///<描述符池大小(默认1024)
SupportLevel blendOperationAdvanced; ///<要求支持高级混合
public:
VulkanHardwareRequirement()
@ -110,6 +112,10 @@ public:
fullDrawIndexUint8=SupportLevel::Want;
fullDrawIndexUint32=SupportLevel::Want;
blendOperationAdvanced=SupportLevel::Want;
wideLines=SupportLevel::Want;
}
};
@ -159,7 +165,7 @@ constexpr const VkFormat SwapchainPreferFormatsDepth[]=
PF_D32F_S8U
};
constexpr const VkColorSpaceKHR SwapchainPreferColorSpacesNonlinear[]=
constexpr const VkColorSpaceKHR SwapchainPreferredNonlinearColorSpaces[]=
{
VK_COLOR_SPACE_SRGB_NONLINEAR_KHR,
VK_COLOR_SPACE_DISPLAY_P3_NONLINEAR_EXT,
@ -170,7 +176,7 @@ constexpr const VkColorSpaceKHR SwapchainPreferColorSpacesNonlinear[]=
VK_COLOR_SPACE_DISPLAY_NATIVE_AMD,
};
constexpr const VkColorSpaceKHR SwapchainPreferColorSpacesLinear[]=
constexpr const VkColorSpaceKHR SwapchainPreferredLinearColorSpaces[]=
{
VK_COLOR_SPACE_EXTENDED_SRGB_LINEAR_EXT,
VK_COLOR_SPACE_DISPLAY_P3_LINEAR_EXT,
@ -225,8 +231,8 @@ constexpr const PreferFormats PreferHDR32{SwapchainPreferFormatsHDR32, sizeof(
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)};
constexpr const PreferColorSpaces PreferNonlinear {SwapchainPreferredNonlinearColorSpaces, sizeof(SwapchainPreferredNonlinearColorSpaces )/sizeof(VkColorSpaceKHR)};
constexpr const PreferColorSpaces PreferLinear {SwapchainPreferredLinearColorSpaces, sizeof(SwapchainPreferredLinearColorSpaces )/sizeof(VkColorSpaceKHR)};
/**
* Vulkan设备创建器<br>
@ -283,7 +289,7 @@ public:
inline GPUDevice *CreateRenderDevice( VulkanInstance *vi,
Window *win,
const VulkanHardwareRequirement *req=nullptr,
const VulkanHardwareRequirement *req =nullptr,
const PreferFormats * spf_color =&PreferSDR,
const PreferColorSpaces * spf_color_space =&PreferNonlinear,
const PreferFormats * spf_depth =&PreferDepth)

View File

@ -11,14 +11,14 @@ class Framebuffer
VkExtent2D extent;
uint32_t attachment_count;
uint32_t color_count;
uint32_t image_count;
bool has_depth;
private:
friend class GPUDevice;
friend class TextureManager;
Framebuffer(VkDevice,VkFramebuffer,const VkExtent2D &,VkRenderPass,uint32_t color_count,bool depth);
Framebuffer(VkDevice,VkFramebuffer,const VkExtent2D &,VkRenderPass,uint32_t image_count,bool depth);
public:
@ -32,7 +32,7 @@ public:
const VkExtent2D & GetExtent ()const{return extent;}
const uint32_t GetAttachmentCount ()const{return attachment_count;} ///<获取渲染目标成分数量
const uint32_t GetColorCount ()const{return color_count;} ///<取得颜色成分数量
const uint32_t GetColorCount ()const{return image_count;} ///<取得颜色成分数量
const bool HasDepth ()const{return has_depth;} ///<是否包含深度成分
};//class Framebuffer

View File

@ -95,6 +95,6 @@ public:
MaterialInstance *CreateMI(const VILConfig *vil_cfg=nullptr);
};//class Material
using MaterialSets=SortedSets<Material *>;
using MaterialSets=SortedSet<Material *>;
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_MATERIAL_INCLUDE

View File

@ -2,7 +2,7 @@
#include<hgl/graph/VK.h>
#include<hgl/type/String.h>
#include<hgl/type/SortedSets.h>
#include<hgl/type/SortedSet.h>
VK_NAMESPACE_BEGIN
class GPUPhysicalDevice
@ -19,6 +19,7 @@ class GPUPhysicalDevice
VkPhysicalDeviceVulkan11Properties properties11;
VkPhysicalDeviceVulkan12Properties properties12;
VkPhysicalDeviceVulkan13Properties properties13;
VkPhysicalDeviceBlendOperationAdvancedPropertiesEXT blendOpAdvProperties;
VkPhysicalDeviceMemoryProperties memory_properties;
List<VkLayerProperties> layer_properties;
@ -29,8 +30,10 @@ private:
bool support_u8_index=false;
bool dynamic_state=false;
public:
bool blendOpAdvanced=false;
public:
const VkPhysicalDeviceFeatures & GetFeatures10 ()const{return features;}
const VkPhysicalDeviceVulkan11Features &GetFeatures11 ()const{return features11;}
@ -149,6 +152,13 @@ public:
const VkBool32 SupportU32Index ()const{return features.fullDrawIndexUint32;}
const VkBool32 SupportU8Index ()const{return support_u8_index;}
const VkBool32 SupportBlendOpAdvanced ()const{return blendOpAdvanced;}
const VkPhysicalDeviceBlendOperationAdvancedPropertiesEXT *GetBlendOpAdvancedProperties()const
{
return blendOpAdvanced?&blendOpAdvProperties:nullptr;
}
// support != open, so please don't direct use GetFeatures().
// open any features in CreateDevice()&SetDeviceFeatures() functions.
const bool SupportMDI ()const

View File

@ -6,6 +6,10 @@
#include<hgl/graph/VKInlinePipeline.h>
#include<hgl/io/DataOutputStream.h>
VK_NAMESPACE_BEGIN
/**
* 线<br>
* 线
*/
class Pipeline
{
VkDevice device;

View File

@ -29,7 +29,7 @@ protected:
private:
friend class DeviceRenderPassManage;
friend class RenderPassManager;
RenderPass(VkDevice d,VkPipelineCache pc,VkRenderPass rp,const List<VkFormat> &cf,VkFormat df);

View File

@ -13,7 +13,7 @@
#include<hgl/graph/VKMaterialInstance.h>
#include<hgl/graph/VKRenderable.h>
#include<hgl/graph/font/TextPrimitive.h>
#include<hgl/graph/StaticMesh.h>
#include<hgl/graph/mesh/StaticMesh.h>
#include<hgl/type/ObjectManage.h>
#include<hgl/shadergen/MaterialCreateInfo.h>
#include<hgl/graph/VKDescriptorBindingManage.h>
@ -34,7 +34,6 @@ using DescriptorSetID =int;
using PrimitiveID =int;
using RenderableID =int;
using SamplerID =int;
using TextureID =int;
using StaticMeshID =int;
class VertexAttribData;
@ -51,7 +50,6 @@ class RenderResource
ShaderModuleMapByName shader_module_by_name[VK_SHADER_STAGE_TYPE_COUNT];
Map<AnsiString,Material *> material_by_name;
Map<OSString,Texture *> texture_by_name;
IDObjectManage<MaterialID, Material> rm_material; ///<材质合集
IDObjectManage<MaterialInstanceID, MaterialInstance> rm_material_instance; ///<材质实例合集
@ -59,7 +57,6 @@ class RenderResource
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; ///<渲染实例集合集
IDObjectManage<StaticMeshID, StaticMesh> rm_static_mesh; ///<静态网格合集
@ -105,7 +102,6 @@ public: //添加数据到管理器如果指针为nullptr会返回-1
PrimitiveID Add(Primitive * p ){return rm_primitives.Add(p);}
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);}
StaticMeshID Add(StaticMesh * sm ){return rm_static_mesh.Add(sm);}
@ -159,14 +155,6 @@ public: //Material
Sampler * CreateSampler(VkSamplerCreateInfo *sci=nullptr);
Sampler * CreateSampler(Texture *);
public: //texture
Texture2D * LoadTexture2D(const OSString &,bool auto_mipmaps=false);
TextureCube * LoadTextureCube(const OSString &,bool auto_mipmaps=false);
Texture2DArray * CreateTexture2DArray(const AnsiString &name,const uint32_t width,const uint32_t height,const uint32_t layer,const VkFormat &fmt,bool auto_mipmaps=false);
bool LoadTexture2DToArray(Texture2DArray *,const uint32_t layer,const OSString &);
public: //Get
Material * GetMaterial (const MaterialID &id){return rm_material.Get(id);}
@ -175,7 +163,6 @@ public: //Get
Primitive * GetPrimitive (const PrimitiveID &id){return rm_primitives.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);}
StaticMesh * GetStaticMesh (const StaticMeshID &id){return rm_static_mesh.Get(id);}
@ -188,7 +175,6 @@ public: //Release
void Release(Primitive * p ){rm_primitives.Release(p);}
void Release(DeviceBuffer * buf ){rm_buffers.Release(buf);}
void Release(Sampler * s ){rm_samplers.Release(s);}
void Release(Texture * t ){rm_textures.Release(t);}
void Release(Renderable * r ){rm_renderables.Release(r);}
void Release(StaticMesh * sm ){rm_static_mesh.Release(sm);}

View File

@ -8,6 +8,7 @@
#include<hgl/graph/VKQueue.h>
#include<hgl/graph/VKPipeline.h>
VK_NAMESPACE_BEGIN
/**
*
*/
@ -32,7 +33,7 @@ protected:
protected:
friend class GPUDevice;
friend class TextureManager;
RenderTarget(DeviceQueue *,Semaphore *);
RenderTarget(DeviceQueue *,Semaphore *,RenderPass *_rp,Framebuffer *_fb,Texture2D **color_texture_list,const uint32_t color_count,Texture2D *depth_texture);
@ -82,7 +83,7 @@ public:
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;}
const uint32_t GetImageCount ()const {return swapchain->image_count;}
virtual Texture2D * GetColorTexture (const int index=0) override{return swapchain->sc_color[index];}
virtual Texture2D * GetDepthTexture () override{return swapchain->sc_depth;}
@ -98,7 +99,7 @@ public:
*
* @param present_complete_semaphore
*/
int AcquireNextImage();
uint32_t AcquireNextImage();
/**
*

View File

@ -12,7 +12,7 @@ VK_NAMESPACE_BEGIN
* <Br>
*
*/
struct PrimitiveDataBuffer
struct PrimitiveDataBuffer:public Comparator<PrimitiveDataBuffer>
{
uint32_t vab_count;
VkBuffer * vab_list;
@ -32,14 +32,14 @@ public:
PrimitiveDataBuffer(const uint32_t,IndexBuffer *,VertexDataManager *_v=nullptr);
~PrimitiveDataBuffer();
const bool Comp(const PrimitiveDataBuffer *pdb)const;
const int compare(const PrimitiveDataBuffer &pdb)const override;
};//struct PrimitiveDataBuffer
/**
* <Br>
*
*/
struct PrimitiveRenderData
struct PrimitiveRenderData:public ComparatorData<PrimitiveRenderData>
{
//因为要VAB是流式访问所以我们这个结构会被用做排序依据
//也因此把vertex_offset放在最前面
@ -59,9 +59,6 @@ public:
vertex_offset =vo;
first_index =fi;
}
CompOperatorMemcmp(const PrimitiveRenderData &);
CompOperatorMemcmpPointer(PrimitiveRenderData);
};
/**

View File

@ -3,7 +3,7 @@
#include<hgl/graph/VK.h>
#include<hgl/graph/VKVertexInputLayout.h>
#include<hgl/type/SortedSets.h>
#include<hgl/type/SortedSet.h>
VK_NAMESPACE_BEGIN

View File

@ -1,5 +1,4 @@
#ifndef HGL_GRAPH_VULKAN_SWAP_CHAIN_INCLUDE
#define HGL_GRAPH_VULKAN_SWAP_CHAIN_INCLUDE
#pragma once
#include<hgl/graph/VK.h>
#include<hgl/graph/VKTexture.h>
@ -10,12 +9,16 @@ struct Swapchain
public:
VkDevice device =VK_NULL_HANDLE;
VkExtent2D extent;
VkExtent2D extent;
VkSurfaceTransformFlagBitsKHR transform;
VkSwapchainKHR swap_chain =VK_NULL_HANDLE;
uint32_t color_count =0;
VkSurfaceFormatKHR surface_format;
VkFormat depth_format;
uint32_t image_count =0;
Texture2D ** sc_color =nullptr;
Texture2D * sc_depth =nullptr;
@ -27,4 +30,3 @@ public:
virtual ~Swapchain();
};//struct Swapchain
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_SWAP_CHAIN_INCLUDE

View File

@ -11,15 +11,22 @@ VK_NAMESPACE_BEGIN
BitmapData *LoadBitmapFromFile(const OSString &filename);
using TextureID=int;
class Texture
{
protected:
VkDevice device;
TextureManager *manager;
TextureID texture_id;
TextureData *data;
public:
TextureManager * GetManager () {return manager;}
const TextureID GetID ()const noexcept {return texture_id;}
TextureData * GetData () {return data;}
VkDeviceMemory GetDeviceMemory () {return data?(data->memory?data->memory->operator VkDeviceMemory():VK_NULL_HANDLE):VK_NULL_HANDLE;}
@ -40,9 +47,10 @@ public:
public:
Texture(VkDevice dev,TextureData *td)
Texture(TextureManager *tm,const TextureID &id,TextureData *td)
{
device=dev;
manager=tm;
texture_id=id;
data=td;
}
@ -95,7 +103,7 @@ class TextureCube:public Texture
{
public:
TextureCube(VkDevice dev,TextureData *td):Texture(dev,td){}
using Texture::Texture;
~TextureCube()=default;
static VkImageViewType GetImageViewType(){return VK_IMAGE_VIEW_TYPE_CUBE;}

View File

@ -0,0 +1,39 @@
#pragma once
#include<hgl/graph/VKNamespace.h>
#include<hgl/TypeFunc.h>
VK_NAMESPACE_BEGIN
enum class WindowMode
{
/**
*
*
*
*/
FullScreen, ///<全屏模式
/**
*
* FBO
*/
Windowed, ///<窗口模式
/**
*
* 西
*/
Borderless, ///<无边框窗口模式
/**
* ?
*
* ()
*/
FullScreenBorderless, ///<全屏无边框模式
ENUM_CLASS_RANGE(FullScreen,FullScreenBorderless)
};//enum class WindowMode
VK_NAMESPACE_END

View File

@ -0,0 +1,19 @@
#pragma once
#include<hgl/graph/Component.h>
#include<hgl/graph/mesh/StaticMesh.h>
VK_NAMESPACE_BEGIN
class StaticMeshComponentData:public ComponentData
{
StaticMesh *static_mesh;
};//class StaticMeshComponentData:public ComponentData
class StaticMeshComponent:public Component
{
};//class StaticMeshComponent:public Component
VK_NAMESPACE_END

View File

@ -0,0 +1,147 @@
#pragma once
#include<hgl/graph/VK.h>
VK_NAMESPACE_BEGIN
//Material models from Google Filament
//@see https://google.github.io/filament/Materials.html
enum class MaterialModels:uint8
{
Unlit=0,
Lit,
Subsurface,
Cloth,
};
enum class ColorMode
{
Unknow=0,
RGB,
Luminance,
YCbCr,
ENUM_CLASS_RANGE(Unknow,YCbCr)
};
enum class GBufferComponent:uint8
{
ShadingModel=0,
RGB,
Y,
CbCr,
Normal,
Depth,
Stencil,
Metallic,
Roughness,
Specular,
Glosses,
Emissive,
AmbientOcclusion,
Anisotropy,
Reflectance,
ClearCoat,
ClearCoatRoughness,
Opacity,
MotionVector,
WorldPosition,
ENUM_CLASS_RANGE(ShadingModel,WorldPosition)
};
struct GBufferComponentConfig
{
char name[32]; ///<成分名称
VkFormat format;
uint count; ///<成分数量
uint size[4]; ///<成分长度
GBufferComponent components[4]; ///<具体成份(分别对应xyzw四位)
public:
const uint GetComponentSize(const GBufferComponent &c)const noexcept;
};//struct GBufferComponent
constexpr const size_t GBUFFER_MAX_COMPONENTS=16;
/**
* GBuffer格式配置
*/
class GBufferFormat
{
uint count; ///<成分数量
GBufferComponentConfig components_list[GBUFFER_MAX_COMPONENTS]; ///<成分配置
int components_index[size_t(GBufferComponent::RANGE_SIZE)]; ///<成分索引
private:
friend class GPUDevice;
public:
const uint GetCount()const noexcept{return count;} ///<取得成分数量
const GBufferComponentConfig *GetConfig(const int index)const noexcept ///<通过索引取得成分配置
{
return (index<0||index>=count)?nullptr:components_list+index;
}
const VkFormat GetFormatFromComponent(const GBufferComponent &)const noexcept; ///<通过成分取得格式
const ColorMode GetColorMode()const noexcept; ///<取得颜色模式
const bool IsRGB ()const noexcept{return GetColorMode()==ColorMode::RGB;} ///<是否为RGB模式
const bool IsLuminance ()const noexcept{return GetColorMode()==ColorMode::Luminance;} ///<是否为Luminance模式
const bool IsYCbCr ()const noexcept{return GetColorMode()==ColorMode::YCbCr;} ///<是否为YCbCr模式
const uint GetNormalSize()const noexcept; ///<取得法线数据大小
public:
GBufferFormat()
{
count=0;
hgl_zero(components_list);
hgl_set(components_index,-1,size_t(GBufferComponent::RANGE_SIZE));
}
~GBufferFormat()=default;
};//class GBufferFormat
struct InitGBufferColorFormatConfig
{
};
bool InitGBufferFormat(GPUDevice *,GBufferFormat *);
//void InitGBufferFormat(GBufferFormat &bf)
//{
// bf.BaseColor =PF_A2BGR10UN;
//
// bf.Depth =PF_D24UN_S8U;
// bf.Stencil =PF_D24UN_S8U;
//
// bf.Normal =PF_RG8UN;
//
// bf.MetallicRoughness=PF_RG8UN;
//
// bf.Emissive =PF_A2BGR10UN;
// bf.AmbientOcclusion =PF_R8UN;
//
// bf.MotionVector =PF_RG16SN;
//}
VK_NAMESPACE_END

View File

@ -12,7 +12,7 @@ namespace hgl
/**
*
*/
struct Font
struct Font:public ComparatorData<Font>
{
os_char name[MAX_FONT_NAME_LENGTH]; ///<字体名称
@ -28,8 +28,6 @@ namespace hgl
Font();
Font(const os_char *,int,int,bool b=false,bool i=false,bool=true);
CompOperatorMemcmp(const Font &); ///<比较操作符重载
};//struct Font
}//namespace graph
}//namespace hgl

View File

@ -3,7 +3,7 @@
#include<hgl/type/StrChar.h>
#include<hgl/type/Map.h>
#include<hgl/type/SortedSets.h>
#include<hgl/type/SortedSet.h>
#include<hgl/graph/font/Font.h>
#include<hgl/type/UnicodeBlocks.h>
@ -71,7 +71,7 @@ namespace hgl
{
protected:
SortedSets<void *> ref_object;
SortedSet<void *> ref_object;
ObjectMap<u32char,CLA> cla_cache;

View File

@ -24,10 +24,10 @@ namespace hgl
friend class TextLayout;
friend class TextRender;
SortedSets<u32char> chars_sets;
SortedSet<u32char> chars_sets;
const SortedSets<u32char> &GetCharsSets()const{return chars_sets;}
void SetCharsSets(const SortedSets<u32char> &sl){chars_sets=sl;}
const SortedSet<u32char> &GetCharsSets()const{return chars_sets;}
void SetCharsSets(const SortedSet<u32char> &sl){chars_sets=sl;}
void ClearCharsSets(){chars_sets.Clear();}
private:

View File

@ -54,9 +54,9 @@ namespace hgl
public:
TextPrimitive *CreatePrimitive();
TextPrimitive *CreatePrimitive(const UTF16String &str);
TextPrimitive *CreatePrimitive(const U16String &str);
bool Layout(TextPrimitive *tr,const UTF16String &str);
bool Layout(TextPrimitive *tr,const U16String &str);
Renderable *CreateRenderable(TextPrimitive *text_primitive);

View File

@ -24,7 +24,7 @@ namespace hgl
TileResPool to_res;
SortedSets<u32char> not_bitmap_chars;
SortedSet<u32char> not_bitmap_chars;
public:
@ -37,7 +37,7 @@ namespace hgl
TileFont(TileData *td,FontSource *fs);
virtual ~TileFont();
bool Registry(TileUVFloatMap &,SortedSets<u32char> &chars_sets); ///<注册要使用的字符
bool Registry(TileUVFloatMap &,SortedSet<u32char> &chars_sets); ///<注册要使用的字符
void Unregistry(const List<u32char> &); ///<注销要使用的字符
};//class TileFont
}//namespace graph

View File

@ -0,0 +1,18 @@
#pragma once
#include<hgl/graph/module/GraphModule.h>
VK_NAMESPACE_BEGIN
class MaterialManager:public GraphModule
{
public:
GRAPH_MODULE_CONSTRUCT(MaterialManager)
virtual ~MaterialManager();
};//class MaterialManager:public GraphModule
VK_NAMESPACE_END

View File

@ -1,16 +1,18 @@
#ifndef HGL_VULKAN_DEVICE_RENDERPASS_MANAGE_INCLUDE
#define HGL_VULKAN_DEVICE_RENDERPASS_MANAGE_INCLUDE
#pragma once
#include<hgl/graph/VK.h>
#include<hgl/graph/module/GraphModule.h>
#include<hgl/type/Map.h>
#include<hgl/util/hash/Hash.h>
VK_NAMESPACE_BEGIN
using RenderPassHASHCode=util::HashCodeSHA1LE;
class DeviceRenderPassManage
using RenderPassHASHCode=util::HashCode<128/8>;
inline util::Hash *CreateRenderPassHash()
{
return util::CreateHash(util::HASH::xxH3_128);
}
class RenderPassManager:public GraphModule
{
VkDevice device;
VkPipelineCache pipeline_cache;
util::Hash *hash;
@ -21,8 +23,8 @@ private:
friend class GPUDevice;
DeviceRenderPassManage(VkDevice,VkPipelineCache);
~DeviceRenderPassManage();
GRAPH_MODULE_CONSTRUCT(RenderPassManager)
~RenderPassManager();
private:
@ -31,7 +33,8 @@ private:
const List<VkSubpassDependency> &dependency,
const RenderbufferInfo *);
public:
RenderPass * AcquireRenderPass( const RenderbufferInfo *,const uint subpass_count=2);
};//class DeviceRenderPassManage
};//class RenderPassManager
VK_NAMESPACE_END
#endif//HGL_VULKAN_DEVICE_RENDERPASS_MANAGE_INCLUDE

View File

@ -0,0 +1,27 @@
#pragma once
#include<hgl/graph/module/GraphModule.h>
VK_NAMESPACE_BEGIN
class RenderTargetManager:public GraphModule
{
public:
GRAPH_MODULE_CONSTRUCT(RenderTargetManager)
virtual ~RenderTargetManager();
public: //FrameBuffer相关
Framebuffer *CreateFBO(RenderPass *rp,ImageView **color_list,const uint image_count,ImageView *depth);
// Framebuffer *CreateFBO(RenderPass *,List<ImageView *> &color,ImageView *depth);
Framebuffer *CreateFBO(RenderPass *,ImageView *color,ImageView *depth);
Framebuffer *CreateFBO(RenderPass *,ImageView *);
public:
RenderTarget *CreateRT( const FramebufferInfo *fbi,RenderPass *,const uint32_t fence_count=1);
RenderTarget *CreateRT( const FramebufferInfo *fbi,const uint32_t fence_count=1);
};//class RenderTargetManager
VK_NAMESPACE_END

View File

@ -0,0 +1,128 @@
#pragma once
#include<hgl/graph/module/GraphModule.h>
#include<hgl/type/SortedSet.h>
#include<hgl/type/IDName.h>
#include<hgl/type/RectScope.h>
#include<hgl/type/object/ObjectBaseInfo.h>
#include<hgl/graph/ImageRegion.h>
#include<hgl/graph/VKTexture.h>
VK_NAMESPACE_BEGIN
struct TextureManagerData
{
};
class TextureManager:public GraphModule
{
DeviceQueue *texture_queue=nullptr;
TextureCmdBuffer *texture_cmd_buf=nullptr;
private:
TextureID texture_serial=0;
const TextureID AcquireID(){return texture_serial++;} ///<取得一个新的纹理ID
private:
SortedSet<VkImage> image_set;
SortedSet<Texture *> texture_set; ///<纹理合集
Map<TextureID,Texture *> texture_by_id;
Map<OSString,Texture *> texture_by_filename;
private:
const TextureID Add(Texture *);
const TextureID Add(Texture *,const OSString &);
public:
GRAPH_MODULE_CONSTRUCT(TextureManager)
virtual ~TextureManager();
const VkFormatProperties GetFormatProperties(const VkFormat)const;
public: //Buffer
DeviceBuffer *CreateTransferSourceBuffer(const VkDeviceSize,const void *data_ptr=nullptr);
private: //Image
VkImage CreateImage (VkImageCreateInfo *);
void DestroyImage (VkImage);
private: //texture
bool CopyBufferToImage (const CopyBufferToImageInfo *info,VkPipelineStageFlags destinationStage);
bool CopyBufferToImage (Texture *,DeviceBuffer *buf,const VkBufferImageCopy *,const int count,const uint32_t base_layer,const uint32_t layer_count,VkPipelineStageFlags);//=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
bool CopyBufferToImage2D (Texture *tex,DeviceBuffer *buf,const VkBufferImageCopy *bic_list,const int bic_count, VkPipelineStageFlags dstStage){return CopyBufferToImage(tex,buf,bic_list, bic_count, 0,1,dstStage);}
bool CopyBufferToImage2D (Texture *tex,DeviceBuffer *buf,const VkBufferImageCopy *bic, VkPipelineStageFlags dstStage){return CopyBufferToImage(tex,buf,bic, 1, 0,1,dstStage);}
bool CopyBufferToImageCube (Texture *tex,DeviceBuffer *buf,const VkBufferImageCopy *bic_list,const int bic_count, VkPipelineStageFlags dstStage){return CopyBufferToImage(tex,buf,bic_list, bic_count, 0,6,dstStage);}
bool CopyBufferToImageCube (Texture *tex,DeviceBuffer *buf,const VkBufferImageCopy *bic, VkPipelineStageFlags dstStage){return CopyBufferToImage(tex,buf,bic, 1, 0,6,dstStage);}
bool CommitTexture2D (Texture2D *,DeviceBuffer *buf,VkPipelineStageFlags stage);
bool CommitTexture2DMipmaps (Texture2D *,DeviceBuffer *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); ///<提交纹理处理到队列
public: //Format
bool CheckFormatSupport(const VkFormat,const uint32_t bits,ImageTiling tiling=ImageTiling::Optimal)const;
bool CheckTextureFormatSupport(const VkFormat fmt,ImageTiling tiling=ImageTiling::Optimal)const{return CheckFormatSupport(fmt,VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT,tiling);}
bool CheckColorAttachmentFormatSupport(const VkFormat fmt)const{return CheckFormatSupport(fmt,VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT,ImageTiling::Optimal);}
bool CheckDepthStencilAttachFormatSupport(const VkFormat fmt)const{return CheckFormatSupport(fmt,VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT,ImageTiling::Optimal);}
public: //Create/Chagne
Texture2D *CreateTexture2D(TextureData *);
Texture2D *CreateTexture2D(TextureCreateInfo *ci);
Texture2DArray *CreateTexture2DArray(TextureData *);
Texture2DArray *CreateTexture2DArray(TextureCreateInfo *ci);
Texture2DArray *CreateTexture2DArray(const uint32_t w,const uint32_t h,const uint32 l,const VkFormat fmt,const bool mipmaps);
TextureCube *CreateTextureCube(TextureData *);
TextureCube *CreateTextureCube(TextureCreateInfo *ci);
void Clear(TextureCreateInfo *);
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 *,const void *data,const VkDeviceSize size, const RectScope2ui &, VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
// bool ChangeTexture2DArray(Texture2DArray *,DeviceBuffer *buf, const List<Image2DRegion> &, const uint32_t base_layer,const uint32_t layer_count,VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
bool ChangeTexture2DArray(Texture2DArray *,DeviceBuffer *buf, const RectScope2ui &, const uint32_t base_layer,const uint32_t layer_count,VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
bool ChangeTexture2DArray(Texture2DArray *,const void *data,const VkDeviceSize size,const RectScope2ui &, const uint32_t base_layer,const uint32_t layer_count,VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
public:
void Release(Texture *);
void Destory(Texture *tex)
{
if(!tex)return;
Release(tex);
delete tex;
}
public: // Load
Texture2D * LoadTexture2D(const OSString &,bool auto_mipmaps=false);
TextureCube * LoadTextureCube(const OSString &,bool auto_mipmaps=false);
Texture2DArray * CreateTexture2DArray(const AnsiString &name,const uint32_t width,const uint32_t height,const uint32_t layer,const VkFormat &fmt,bool auto_mipmaps=false);
bool LoadTexture2DToArray(Texture2DArray *,const uint32_t layer,const OSString &);
};//class TextureManager
VK_NAMESPACE_END

View File

@ -1,7 +1,7 @@
#pragma once
#include<hgl/graph/VKNamespace.h>
#include<hgl/graph/StaticMeshLODPolicy.h>
#include<hgl/graph/mesh/StaticMeshLODPolicy.h>
#include<hgl/graph/ShadowPolicy.h>
VK_NAMESPACE_BEGIN

View File

@ -0,0 +1,17 @@
#pragma once
#include<hgl/graph/SceneNode.h>
VK_NAMESPACE_BEGIN
class StaticMeshNode:public SceneNode
{
StaticMesh *sm;
public:
};//class StaticMeshNode
VK_NAMESPACE_END

View File

@ -0,0 +1,118 @@
#pragma once
#include<hgl/graph/RenderFramework.h>
#include<initializer_list>
VK_NAMESPACE_BEGIN
class RenderCmdBuffer;
class RenderFramework;
using GraphModuleHashList=std::initializer_list<size_t>;
class GraphModule
{
RenderFramework *render_framework;
AIDName module_name;
bool module_inited;
bool module_enabled;
bool module_ready;
protected:
template<typename T>
T * GetModule(bool create=false){return render_framework->GetModule<T>(create);} ///<获取指定类型的模块
GraphModule * GetModule(const AIDName &name,bool create=false); ///<获取指定名称的模块
protected:
virtual void SetModuleEnabled(bool e){module_enabled=e;}
virtual void SetModuleReady(bool r){module_ready=r;}
public:
GPUDevice * GetDevice () {return render_framework->GetDevice();} ///<取得GPU设备
VkDevice GetVkDevice ()const {return render_framework->GetVkDevice();} ///<取得VkDevice
const GPUPhysicalDevice * GetPhysicalDevice ()const {return render_framework->GetPhysicalDevice();} ///<取得物理设备
GPUDeviceAttribute *GetDeviceAttribute () {return render_framework->GetDeviceAttribute();} ///<取得设备属性
RenderFramework * GetFramework () {return render_framework;} ///<取得渲染框架
const AIDName & GetName ()const {return module_name;} ///<取得模块名称(标准通用的名称比如Upscale供通用模块使用)
virtual const AIDName & GetFullName ()const {return module_name;} ///<取得名称(完整的私有名称比如FSR3Upscale,DLSS3Upscale)
virtual const bool IsPerFrame () {return false;} ///<是否每帧运行
virtual const bool IsRender () {return false;} ///<是否为渲染模块
const bool IsInited ()const {return module_inited;} ///<是否已经初始化
const bool IsEnabled ()const noexcept{return module_enabled;} ///<当前模块是否启用
const bool IsReady ()const noexcept{return module_ready;} ///<当前模块是否准备好
public:
NO_COPY_NO_MOVE(GraphModule)
protected:
GraphModule(RenderFramework *rf,const AIDName &name);
public:
virtual ~GraphModule();
virtual const size_t GetTypeHash()const=0;
static const GraphModuleHashList GetDependentModules(){return {};} ///<取得依赖的模块列表
public: //回调事件
virtual void OnRenderTarget(RenderTarget *){} ///<设置渲染目标
virtual void OnResize(const VkExtent2D &){} ///<窗口大小改变
virtual void OnPreFrame(){} ///<帧绘制前回调
virtual void OnPostFrame(){} ///<帧绘制后回调
};//class GraphModule
using GraphModuleMapByIDName=Map<AIDName,GraphModule *>;
//template<typename T,typename BASE> class GraphModuleInherit:public BASE
//{
//public:
//
// GraphModuleInherit(RenderFramework *rf):BASE(rf,typeid(T))
// {}
//
// static const size_t StaticHash()
// {
// return typeid(T).hash_code();
// }
//
//};//class GraphModuleInherit
#define GRAPH_MODULE_CREATE_FUNC(name) name *name::CreateModule(RenderFramework *rf,GraphModuleMapByIDName &dep_modules)
#define GRAPH_BASE_MODULE_CONSTRUCT(name,base_class) public:\
NO_COPY_NO_MOVE(name) \
static const size_t StaticHash(){return typeid(name).hash_code();} \
const size_t GetTypeHash()const override{return name::StaticHash();} \
static const AIDName &GetModuleName() \
{ \
static const AIDName id_name(#name); \
return id_name; \
} \
\
private: \
name(RenderFramework *rf):base_class(rf,GetModuleName()){} \
\
public: \
static name *CreateModule(RenderFramework *rf,GraphModuleMapByIDName &); \
static const GraphModuleHashList GetDependentModules();
#define GRAPH_MODULE_CONSTRUCT(name) GRAPH_BASE_MODULE_CONSTRUCT(name,GraphModule)
#define RENDER_MODULE_CONSTRUCT(name) GRAPH_BASE_MODULE_CONSTRUCT(name,RenderModule)
VK_NAMESPACE_END

View File

@ -0,0 +1,59 @@
#pragma once
#include<hgl/graph/VKNamespace.h>
#include<hgl/type/IDName.h>
#include<hgl/graph/module/GraphModule.h>
#include<hgl/graph/RenderFramework.h>
VK_NAMESPACE_BEGIN
class GraphModuleFactory
{
public:
GraphModuleFactory()=default;
virtual ~GraphModuleFactory()=default;
virtual GraphModule *Create(RenderFramework *)=0;
};//class GraphModuleFactory
bool RegistryGraphModuleFactory(const char *module_name,GraphModuleFactory *);
template<typename T> class RegistryGraphModule:public GraphModuleFactory
{
public:
GraphModule *Create(RenderFramework *rf) override
{
if(!rf)
return(nullptr);
Map<AIDName,GraphModule *> dgm_map;
//检查依赖模块
{
const auto &dependent_modules=T::GetDependentModules();
if(!dependent_modules.IsEmpty())
{
for(const AIDName &name:dependent_modules)
{
GraphModule *dgm=rf->GetModule(name,true);
if(!dgm)
return(nullptr);
dgm_map.Add(name,dgm);
}
}
}
T *gm=T::CreateModule(rf,dgm_map);
return(gm);
}
};//template<typename T> class RegistryGraphModule:public GraphModuleFactory
#define REGISTRY_GRAPH_MODULE(Class) {RegistryGraphModuleFactory(#Class,new RegistryGraphModule<Class>);}
VK_NAMESPACE_END

View File

@ -0,0 +1,56 @@
#pragma once
#include<hgl/graph/VK.h>
#include<hgl/type/IDName.h>
VK_NAMESPACE_BEGIN
class GraphModule;
class GraphModulesMap
{
SortedSet<GraphModule *> gm_set;
Map<AIDName,GraphModule *> gm_map_by_name;
Map<size_t,GraphModule *> gm_map_by_hash;
List<GraphModule *> gm_list; //按创建顺序记录,用于倒序释放
public:
bool Add(GraphModule *gm);
const bool IsEmpty()const
{
return gm_set.IsEmpty();
}
GraphModule *Get(const AIDName &name)
{
GraphModule *gm;
if(gm_map_by_name.Get(name,gm))
return gm;
return nullptr;
}
template<typename T>
T *Get()
{
GraphModule *gm;
return gm_map_by_hash.Get(GetTypeHash<T>(),gm)?(T *)gm:nullptr;
}
template<typename T>
const bool IsLoaded()const{return gm_map_by_hash.ContainsKey(T::GetTypeHash());}
const bool IsLoaded(const AIDName &name)const{return gm_map_by_name.ContainsKey(name);}
bool Release(GraphModule *gm); ///<释放一个模块
void Destory(); ///<销毁所有模块
};//class GraphModulesMap
VK_NAMESPACE_END

View File

@ -0,0 +1,32 @@
#pragma once
#include<hgl/graph/module/GraphModule.h>
#include<hgl/type/Size2.h>
VK_NAMESPACE_BEGIN
/**
*
*/
class RenderModule:public GraphModule
{
VkExtent2D current_extent;
public:
const bool IsPerFrame ()const noexcept{return true;} ///<每帧运行
const bool IsRender ()const noexcept{return true;} ///<渲染模块
public:
NO_COPY_NO_MOVE(RenderModule)
using GraphModule::GraphModule;
virtual ~RenderModule()=default;
virtual void OnResize(const VkExtent2D &ext)override{current_extent=ext;}
virtual void OnFrameRender(const double,RenderCmdBuffer *)=0; ///<帧绘制回调
};//class RenderModule
VK_NAMESPACE_END

View File

@ -0,0 +1,51 @@
#pragma once
#include<hgl/graph/module/RenderModule.h>
#include<hgl/graph/VKRenderTarget.h>
VK_NAMESPACE_BEGIN
class SwapchainModule:public GraphModule
{
Swapchain *swapchain=nullptr;
RTSwapchain *swapchain_rt=nullptr;
RenderPass *swapchain_rp=nullptr;
RenderCmdBuffer **cmd_buf=nullptr;
protected:
bool CreateSwapchainFBO();
bool CreateSwapchain();
bool CreateSwapchainRenderTarget();
void InitRenderCmdBuffer();
void ClearRenderCmdBuffer();
public:
virtual void OnResize(const VkExtent2D &)override; ///<窗口大小改变
public:
GRAPH_MODULE_CONSTRUCT(SwapchainModule)
virtual ~SwapchainModule();
bool BeginFrame();
void EndFrame();
public:
RenderPass * GetRenderPass () {return swapchain_rp;}
RTSwapchain * GetRenderTarget () {return swapchain_rt;}
const VkExtent2D & GetSwapchainSize()const {return swapchain_rt->GetExtent();}
RenderCmdBuffer *GetRenderCmdBuffer();
};//class SwapchainModule:public GraphModule
VK_NAMESPACE_END

View File

@ -6,7 +6,7 @@
#include<hgl/graph/VertexAttrib.h>
STD_MTL_NAMESPACE_BEGIN
struct Material2DCreateConfig:public MaterialCreateConfig
struct Material2DCreateConfig:public MaterialCreateConfig,public Comparator<Material2DCreateConfig>
{
CoordinateSystem2D coordinate_system; ///<使用的坐标系
@ -32,9 +32,9 @@ public:
position_format=VAT_VEC2;
}
int Comp(const Material2DCreateConfig &cfg)const
const int compare(const Material2DCreateConfig &cfg)const override
{
int off=MaterialCreateConfig::Comp(cfg);
int off=MaterialCreateConfig::compare(cfg);
if(off)return off;
@ -48,8 +48,6 @@ public:
return off;
}
CompOperator(const Material2DCreateConfig &,Comp)
};//struct Material2DCreateConfig:public MaterialCreateConfig
MaterialCreateInfo *CreateVertexColor2D(const Material2DCreateConfig *);

View File

@ -5,58 +5,8 @@
#include<hgl/graph/VertexAttrib.h>
STD_MTL_NAMESPACE_BEGIN
enum class LightingModel:uint8
{
Unlit,
Gizmo, ///<Gizmo专用(Blinnphong的特定版本内置假的太阳光方向、高光系数等使其不需要外部UBO传入)
Blinnphong, ///<Blinnphong光照模型
FakePBR, ///<假PBR(使用Blinnphong+HalfLambert模拟)
MicroPBR, ///<微型PBR(只有BaseColor/Normal/Metallic/Roughness四个基础数据的PBR)
WebPBR, ///<Khronos为WebGL提供的PBR
FilamentPBR, ///<Filament引擎所使用的PBR
AMDPBR, ///<AMD Caulrdon框架所使用的PBR
BlenderPBR, ///<Blender所使用的PBR
ENUM_CLASS_RANGE(Unlit,BlenderPBR)
};
constexpr const char *LightingModelName[]=
{
"Unlit",
"Gizmo",
"Blinnphong",
"FakePBR",
"MicroPBR",
"WebPBR",
"FilamentPBR",
"AMDPBR",
"BlenderPBR"
};
/**
*
*/
enum class SkyLightSource:uint8
{
PureColor, ///<纯色
Simplest, ///<极简(一行代码)
Cubemap, ///<立方体贴图
IBL, ///<IBL立方体贴图
ENUM_CLASS_RANGE(PureColor,IBL)
};
struct Material3DCreateConfig:public MaterialCreateConfig
struct Material3DCreateConfig:public MaterialCreateConfig,public Comparator<Material3DCreateConfig>
{
bool camera; ///<包含摄像机矩阵信息
@ -82,9 +32,9 @@ public:
// reverse_depth=false;
}
int Comp(const Material3DCreateConfig &cfg)const
const int compare(const Material3DCreateConfig &cfg)const override
{
int off=MaterialCreateConfig::Comp(cfg);
int off=MaterialCreateConfig::compare(cfg);
if(off)return off;
@ -98,8 +48,6 @@ public:
return off;
}
CompOperator(const Material3DCreateConfig &,Comp)
};//struct Material3DCreateConfig:public MaterialCreateConfig
MaterialCreateInfo *CreateVertexColor3D(const Material3DCreateConfig *);

View File

@ -13,7 +13,7 @@ class MaterialCreateInfo;
/**
*
*/
struct MaterialCreateConfig
struct MaterialCreateConfig:public Comparator<MaterialCreateConfig>
{
const GPUDeviceAttribute *dev_attr;
@ -42,7 +42,7 @@ public:
prim=p;
}
virtual int Comp(const MaterialCreateConfig &cfg)const
const int compare(const MaterialCreateConfig &cfg)const override
{
int off;
@ -59,8 +59,6 @@ public:
return off;
}
CompOperator(const MaterialCreateConfig &,Comp)
};//struct MaterialCreateConfig
STD_MTL_NAMESPACE_END
#endif//HGL_GRAPH_MTL_CONFIG_INCLUDE

View File

@ -6,7 +6,7 @@
#include<hgl/graph/VKInterpolation.h>
#include<hgl/graph/VKSamplerType.h>
#include<hgl/graph/VKImageType.h>
#include<hgl/CompOperator.h>
#include<hgl/Comparator.h>
namespace hgl
{
@ -28,7 +28,7 @@ namespace hgl
#pragma pack(push,1)
struct ShaderVariableType
struct ShaderVariableType:public Comparator<ShaderVariableType>
{
union
{
@ -156,91 +156,9 @@ namespace hgl
array_size=count;
}
const bool Check()const
{
if(!RangeCheck(base_type))return(false);
const bool Check()const;
RANGE_CHECK_RETURN_FALSE(base_type)
if(base_type==SVBaseType::Scalar)
return(true);
if(base_type==SVBaseType::Vector)
{
if(vector.vec_size<2||vector.vec_size>4)return(false);
return(true);
}
if(base_type==SVBaseType::Matrix)
{
if(matrix.m==0)
{
if(matrix.n<2||matrix.n>4)return(false);
}
else
{
if(matrix.n<2||matrix.n>4)return(false);
if(matrix.m<2||matrix.m>4)return(false);
}
return(true);
}
if(base_type==SVBaseType::Sampler)
return RangeCheck(sampler.type);
if(base_type==SVBaseType::Image)
return RangeCheck(image.type);
return(true);
}
int Comp(const ShaderVariableType &svt)const
{
int off=(int)base_type-(int)svt.base_type;
if(off)return(off);
if(base_type==SVBaseType::Scalar)
return int(scalar.type)-int(svt.scalar.type);
if(base_type==SVBaseType::Vector)
{
off=int(vector.type)-int(svt.vector.type);
if(off)return(off);
off=vector.vec_size-svt.vector.vec_size;
if(off)return(off);
return int(vector.type)-int(svt.vector.type);
}
if(base_type==SVBaseType::Matrix)
{
off=int(matrix.type)-int(svt.matrix.type);
if(off)return(off);
off=matrix.n-svt.matrix.n;
if(off)return(off);
return matrix.m-svt.matrix.m;
}
if(base_type==SVBaseType::Sampler)
return int(sampler.type)-int(svt.sampler.type);
if(base_type==SVBaseType::Image)
return int(image.type)-int(svt.image.type);
return 0;
}
CompOperator(const ShaderVariableType &,Comp)
const int compare(const ShaderVariableType &svt)const override;
const char *GetTypename()const;
@ -254,29 +172,7 @@ namespace hgl
return Check();
}
const bool From(const VAType &vat,const uint16 count=1)
{
array_size=count;
if(vat.vec_size==1)
{
base_type=SVBaseType::Scalar;
scalar.type=vat.basetype;
return(true);
}
else if(vat.vec_size<=4)
{
base_type=SVBaseType::Vector;
vector.type=vat.basetype;
vector.vec_size=vat.vec_size;
return(true);
}
return(false);
}
const bool From(const VAType &vat,const uint16 count=1);
static const ShaderVariableType Scalar(const VABaseType &vabt,const uint count=1)
{
@ -383,7 +279,7 @@ namespace hgl
using SVList=List<ShaderVariable>;
struct ShaderVariableArray
struct ShaderVariableArray:public Comparator<ShaderVariableArray>
{
uint count;
@ -406,44 +302,36 @@ namespace hgl
Clear();
}
int Comp(const ShaderVariableArray *sva)const
const int compare(const ShaderVariableArray &sva)const override
{
if(!sva)
return 1;
int off=count-sva->count;
int off=count-sva.count;
if(off)return off;
for(uint i=0;i<count;i++)
{
off=items[i].location-sva->items[i].location;
off=items[i].location-sva.items[i].location;
if(off)
return off;
if(items[i].type.ToCode()>sva->items[i].type.ToCode())
if(items[i].type.ToCode()>sva.items[i].type.ToCode())
return 1;
//ToCode返回的是uint64可能差值超大所以不能直接用-的结果
if(items[i].type.ToCode()<sva->items[i].type.ToCode())
if(items[i].type.ToCode()<sva.items[i].type.ToCode())
return -1;
off=int(items[i].interpolation)-int(sva->items[i].interpolation);
off=int(items[i].interpolation)-int(sva.items[i].interpolation);
if(off)
return off;
off=hgl::strcmp(items[i].name,sva->items[i].name);
off=hgl::strcmp(items[i].name,sva.items[i].name);
if(off)
return off;
}
return 0;
}
int Comp(const ShaderVariableArray &sva)const{return Comp(&sva);}
CompOperator(const ShaderVariableArray *,Comp)
CompOperator(const ShaderVariableArray &,Comp)
bool Init(const uint c=0)
{

View File

@ -2,7 +2,7 @@
#define HGL_GUI_LAYOUT_INCLUDE
#include<hgl/gui/Widget.h>
#include<hgl/type/SortedSets.h>
#include<hgl/type/SortedSet.h>
namespace hgl
{
namespace gui
@ -14,7 +14,7 @@ namespace hgl
{
protected:
SortedSets<Widget *> widgets_set;
SortedSet<Widget *> widgets_set;
public:

View File

@ -96,7 +96,7 @@ public:
void SetMain(const AnsiString &str){main_function=str;}
void SetMain(const char *str,const int len)
{
main_function.SetString(str,len);
main_function.fromString(str,len);
}
const AnsiString &GetOutputStruct()const{return output_struct;}

2
res

@ -1 +1 @@
Subproject commit e1a36d78f0eead5f6bb65493432c4690637b991d
Subproject commit 475d8ad43ceee084cd24f5d0bed59de9f6aa36fd

View File

@ -37,6 +37,7 @@ SET(GEOMETRY_FILES ${SG_INCLUDE_PATH}/InlineGeometry.h
SOURCE_GROUP("Geometry" FILES ${GEOMETRY_FILES})
SET(LIGHT_FILES ${SG_INCLUDE_PATH}/Light.h
${SG_INCLUDE_PATH}/LightCullMode.h
${SG_INCLUDE_PATH}/ShadowPolicy.h)
source_group("Light" FILES ${LIGHT_FILES})
@ -64,12 +65,14 @@ SET(SCENE_GRAPH_SOURCE RenderList.cpp
SOURCE_GROUP("Scene Graph" FILES ${SCENE_GRAPH_HEADER} ${SCENE_GRAPH_SOURCE})
SET(STATIC_MESH_HEADER_FILES ${SG_INCLUDE_PATH}/StaticMesh.h
${SG_INCLUDE_PATH}/StaticMeshLODPolicy.h)
SET(STATIC_MESH_HEADER_FILES ${SG_INCLUDE_PATH}/mesh/StaticMesh.h
${SG_INCLUDE_PATH}/mesh/StaticMeshLODPolicy.h
${SG_INCLUDE_PATH}/mesh/StaticMeshNode.h
)
SET(STATIC_MESH_SOURCE_FILES StaticMesh.cpp)
SET(STATIC_MESH_SOURCE_FILES mesh/StaticMesh.cpp)
SOURCE_GROUP("Scene Graph\\Static Mesh" FILES ${STATIC_MESH_HEADER_FILES} ${STATIC_MESH_SOURCE_FILES})
SOURCE_GROUP("Scene Graph\\Mesh\\Static Mesh" FILES ${STATIC_MESH_HEADER_FILES} ${STATIC_MESH_SOURCE_FILES})
SET(FONT_MANAGE_SOURCE ${SG_INCLUDE_PATH}/font/Font.h
${SG_INCLUDE_PATH}/font/FontManage.h
@ -136,12 +139,14 @@ SET(VK_MEMORY_SOURCE ${SG_INCLUDE_PATH}/VKMemory.h
Vulkan/VKArrayBuffer.cpp
)
SET(VK_DEVICE_TEXTURE_SOURCE Vulkan/Texture/BufferImageCopy2D.h
Vulkan/Texture/GenMipmaps.cpp
Vulkan/Texture/VKDeviceTexture.cpp
Vulkan/Texture/VKDeviceTexture2D.cpp
Vulkan/Texture/VKDeviceTexture2DArray.cpp
Vulkan/Texture/VKDeviceTextureCube.cpp)
SET(VK_IMAGE_SOURCE Vulkan/Texture/BufferImageCopy2D.h
Vulkan/VKDeviceImage.cpp)
SET(VK_DEVICE_TEXTURE_SOURCE Vulkan/Texture/GenMipmaps.cpp
Vulkan/Texture/VKTexture.cpp
Vulkan/Texture/VKTexture2D.cpp
Vulkan/Texture/VKTexture2DArray.cpp
Vulkan/Texture/VKTextureCube.cpp)
SET(VK_TEXTURE_LOADER_SOURCE ${SG_INCLUDE_PATH}/VKTextureCreateInfo.h
Vulkan/Texture/VKTextureLoader.h
@ -150,22 +155,16 @@ SET(VK_TEXTURE_LOADER_SOURCE ${SG_INCLUDE_PATH}/VKTextureCreateInfo.h
Vulkan/Texture/VKTextureCubeLoader.cpp)
SET(VK_DEVICE_CREATER_SOURCE ${SG_INCLUDE_PATH}/VKDevice.h
${SG_INCLUDE_PATH}/VKDeviceAttribute.h
${SG_INCLUDE_PATH}/VKDeviceCreater.h
Vulkan/VKDeviceAttribute.cpp
Vulkan/VKDeviceCreater.cpp
Vulkan/VKDevice.cpp)
${SG_INCLUDE_PATH}/VKDeviceAttribute.h
${SG_INCLUDE_PATH}/VKDeviceCreater.h
Vulkan/VKDeviceAttribute.cpp
Vulkan/VKDeviceCreater.cpp
Vulkan/VKDevice.cpp)
SET(VK_DEVICE_SOURCE Vulkan/VKDeviceMemory.cpp
Vulkan/VKDeviceBuffer.cpp
Vulkan/VKDeviceImage.cpp
Vulkan/VKDeviceSampler.cpp
Vulkan/VKDeviceMaterial.cpp
Vulkan/VKDeviceFramebuffer.cpp
Vulkan/VKDeviceSwapchain.cpp
Vulkan/VKDeviceRenderPass.cpp
Vulkan/VKDeviceRenderPassManage.cpp
Vulkan/VKDeviceRenderTarget.cpp)
Vulkan/VKDeviceMaterial.cpp)
SET(VK_PHYSICAL_DEVICE_SOURCE ${SG_INCLUDE_PATH}/VKPhysicalDevice.h
Vulkan/VKPhysicalDevice.cpp
@ -179,8 +178,9 @@ SOURCE_GROUP("Vulkan\\Device\\Debug" FILES ${VK_DEBUG_SOURCE})
SOURCE_GROUP("Vulkan\\Device\\Instance" FILES ${VK_INST_SOURCE})
SOURCE_GROUP("Vulkan\\Device\\Physical Device" FILES ${VK_PHYSICAL_DEVICE_SOURCE})
SOURCE_GROUP("Vulkan\\Device\\Memory" FILES ${VK_MEMORY_SOURCE})
SOURCE_GROUP("Vulkan\\Device\\Texture" FILES ${VK_DEVICE_TEXTURE_SOURCE})
SOURCE_GROUP("Vulkan\\Device\\Texture\\Loader" FILES ${VK_TEXTURE_LOADER_SOURCE})
SOURCE_GROUP("Vulkan\\Texture" FILES ${VK_DEVICE_TEXTURE_SOURCE})
SOURCE_GROUP("Vulkan\\Texture\\Loader" FILES ${VK_TEXTURE_LOADER_SOURCE})
SOURCE_GROUP("Vulkan\\Texture\\Image" FILES ${VK_IMAGE_SOURCE})
SET(VK_DESCRIPTOR_SETS_SOURCE ${SG_INCLUDE_PATH}/VKDescriptorSet.h
Vulkan/VKDescriptorSet.cpp
@ -259,6 +259,67 @@ SET(VK_RENDERABLE_SOURCE ${SG_INCLUDE_PATH}/VKRenderable.h
SOURCE_GROUP("Vulkan\\Renderable" FILES ${VK_RENDERABLE_SOURCE})
#-Component-------------------------------------------------------------
SET(SGC_HEADER_PATH ${SG_INCLUDE_PATH}/component)
SET(SGC_SOURCE_PATH component)
SET(SG_COMPONENT_HEADER ${SG_INCLUDE_PATH}/Component.h
${SGC_HEADER_PATH}/StaticMeshComponent.h)
SET(SG_COMPONENT_SOURCE ${SGC_SOURCE_PATH}/Component.cpp
${SGC_SOURCE_PATH}/StaticMeshComponent.cpp)
SOURCE_GROUP("Scene Graph\\Component" FILES ${SG_COMPONENT_HEADER} ${SG_COMPONENT_SOURCE})
#-GraphModule,RenderFramework-------------------------------------------
SET(SG_MODULE_HEADER_PATH ${SG_INCLUDE_PATH}/module)
SET(GRAPH_MODULE_HEADER ${SG_MODULE_HEADER_PATH}/GraphModule.h
${SG_MODULE_HEADER_PATH}/GraphModuleMap.h
${SG_MODULE_HEADER_PATH}/GraphModuleFactory.h
${SG_MODULE_HEADER_PATH}/RenderModule.h
${SG_MODULE_HEADER_PATH}/SwapchainModule.h)
SET(GRAPH_MODULE_SOURCE module/GraphModule.cpp
module/GraphModuleFactory.cpp
module/RenderModule.cpp
module/RegistryCommonModule.cpp
module/SwapchainModule.cpp)
SOURCE_GROUP("Render Framework\\Module" FILES ${GRAPH_MODULE_HEADER}
${GRAPH_MODULE_SOURCE})
SET(SG_MANAGER_HEADER_PATH ${SG_INCLUDE_PATH}/manager)
SET(GRAPH_MANAGER_HEADER ${SG_MANAGER_HEADER_PATH}/TextureManager.h
${SG_MANAGER_HEADER_PATH}/RenderPassManager.h
${SG_MANAGER_HEADER_PATH}/RenderTargetManager.h
${SG_MANAGER_HEADER_PATH}/MaterialManager.h
)
SET(GRAPH_MANAGER_SOURCE manager/TextureManager.cpp
manager/RenderPassManager.cpp
manager/RenderTargetManager.cpp
manager/RenderTargetManagerFBO.cpp
manager/MaterialManager.cpp
)
SOURCE_GROUP("Render Framework\\Manager" FILES ${GRAPH_MANAGER_HEADER} ${GRAPH_MANAGER_SOURCE})
SET(RENDER_FRAMEWORK_FILES ${SG_INCLUDE_PATH}/RenderFramework.h
${SG_INCLUDE_PATH}/RenderBufferName.h
${SG_INCLUDE_PATH}/RenderWorkflow.h
RenderFramework.cpp)
SOURCE_GROUP("Render Framework" FILES ${RENDER_FRAMEWORK_FILES})
SET(DEFERRED_RENDER_HEADER ${SG_INCLUDE_PATH}/deferred/GBufferFormat.h)
SET(DEFERRED_RENDER_SOURCE deferred/GBufferFormat.cpp)
SOURCE_GROUP("Graph Module\\Deferred Rendering" FILES ${DEFERRED_RENDER_HEADER} ${DEFERRED_RENDER_SOURCE})
IF(WIN32)
OPTION(FORCE_DISCETE_GPU "Force Discrete GPU" OFF)
@ -276,10 +337,7 @@ IF(UNIX)
ELSE()
IF(APPLE)
ELSE()
SET(VULKAN_SURFACE_SOURCE Vulkan/Platform/XCBVulkan.cpp)
ENDIF()
@ -287,6 +345,8 @@ IF(UNIX)
ENDIF(UNIX)
SET(VULKAN_SURFACE_SOURCE ${VULKAN_SURFACE_SOURCE} ${SG_INCLUDE_PATH}/WindowMode.h)
SOURCE_GROUP("Vulkan\\Surface" FILES ${VULKAN_SURFACE_SOURCE})
SET(VULKAN_RENDER_SOURCE ${VK_RR_SOURCE}
@ -301,6 +361,7 @@ SET(VULKAN_RENDER_SOURCE ${VK_RR_SOURCE}
${VK_PHYSICAL_DEVICE_SOURCE}
${VK_DESCRIPTOR_SETS_SOURCE}
${VK_SHADER_SOURCE}
${VK_IMAGE_SOURCE}
${VK_TEXTURE_SOURCE}
${VK_MATERIAL_SOURCE}
${VK_RENDER_PASS_SOURCE}
@ -309,8 +370,7 @@ SET(VULKAN_RENDER_SOURCE ${VK_RR_SOURCE}
${VK_RENDERABLE_SOURCE}
${VK_RENDER_DEVICE_SOURCE})
add_cm_library(ULRE.SceneGraph "ULRE" ${SCENE_GRAPH_HEADER}
${SCENE_GRAPH_SOURCE}
add_cm_library(ULRE.SceneGraph "ULRE" ${SCENE_GRAPH_HEADER} ${SCENE_GRAPH_SOURCE}
${SG_PRIMITIVE_SOURCE}
${GEOMETRY_FILES}
${LIGHT_FILES}
@ -319,8 +379,9 @@ add_cm_library(ULRE.SceneGraph "ULRE" ${SCENE_GRAPH_HEADER}
${TILE_SOURCE}
${SG_VDM_SOURCE}
${STATIC_MESH_HEADER_FILES}
${STATIC_MESH_SOURCE_FILES}
${STATIC_MESH_HEADER_FILES} ${STATIC_MESH_SOURCE_FILES}
${SG_COMPONENT_HEADER} ${SG_COMPONENT_SOURCE}
# ${FONT_MANAGE_SOURCE}
# ${FONT_SOURCE}
@ -330,4 +391,11 @@ add_cm_library(ULRE.SceneGraph "ULRE" ${SCENE_GRAPH_HEADER}
# ${TEXT_RENDERABLE_SOURCE}
${VULKAN_RENDER_SOURCE}
${VULKAN_SURFACE_SOURCE})
${VULKAN_SURFACE_SOURCE}
${GRAPH_MODULE_HEADER} ${GRAPH_MODULE_SOURCE}
${GRAPH_MANAGER_HEADER} ${GRAPH_MANAGER_SOURCE}
${RENDER_FRAMEWORK_FILES}
${DEFERRED_RENDER_HEADER} ${DEFERRED_RENDER_SOURCE}
)

View File

@ -26,22 +26,13 @@
VBOINDIRECT缓冲区便
*/
template<>
int Comparator<hgl::graph::RenderNode>::compare(const hgl::graph::RenderNode &obj_one,const hgl::graph::RenderNode &obj_two) const
VK_NAMESPACE_BEGIN
const int RenderNode::compare(const RenderNode &other)const
{
hgl::int64 off;
hgl::graph::Renderable *ri_one=obj_one.scene_node->GetRenderable();
hgl::graph::Renderable *ri_two=obj_two.scene_node->GetRenderable();
//比较管线
{
off=ri_one->GetPipeline()
-ri_two->GetPipeline();
if(off)
return off;
}
hgl::graph::Renderable *ri_one=other.scene_node->GetRenderable();
hgl::graph::Renderable *ri_two=scene_node->GetRenderable();
auto *prim_one=ri_one->GetPrimitive();
auto *prim_two=ri_two->GetPrimitive();
@ -72,8 +63,8 @@ int Comparator<hgl::graph::RenderNode>::compare(const hgl::graph::RenderNode &ob
//比较距离。。。。。。。。。。。。。。。。。。。。。还不知道这个是正了还是反了,等测出来确认后修改下面的返回值和这里的注释
float foff=obj_one.to_camera_distance
-obj_two.to_camera_distance;
float foff=other.to_camera_distance
-to_camera_distance;
if(foff>0)
return 1;
@ -81,18 +72,17 @@ int Comparator<hgl::graph::RenderNode>::compare(const hgl::graph::RenderNode &ob
return -1;
}
VK_NAMESPACE_BEGIN
MaterialRenderList::MaterialRenderList(GPUDevice *d,bool l2w,Material *m)
MaterialRenderList::MaterialRenderList(GPUDevice *d,bool l2w,const RenderPipelineIndex &rpi)
{
device=d;
cmd_buf=nullptr;
material=m;
rp_index=rpi;
camera_info=nullptr;
assign_buffer=new RenderAssignBuffer(device,material);
assign_buffer=new RenderAssignBuffer(device,rp_index.material);
vab_list=new VABList(material->GetVertexInput()->GetCount());
vab_list=new VABList(rp_index.material->GetVertexInput()->GetCount());
icb_draw=nullptr;
icb_draw_indexed=nullptr;
@ -215,7 +205,6 @@ void MaterialRenderList::UpdateMaterialInstance(SceneNode *sn)
void MaterialRenderList::RenderItem::Set(Renderable *ri)
{
pipeline=ri->GetPipeline();
mi =ri->GetMaterialInstance();
pdb =ri->GetDataBuffer();
prd =ri->GetRenderData();
@ -248,6 +237,7 @@ void MaterialRenderList::WriteICB(VkDrawIndirectCommand *dicp,RenderItem *ri)
dicp->firstVertex =ri->prd->vertex_offset;
dicp->firstInstance =ri->first_instance;
}
void MaterialRenderList::WriteICB(VkDrawIndexedIndirectCommand *diicp,RenderItem *ri)
{
diicp->indexCount =ri->prd->index_count;
@ -279,7 +269,6 @@ void MaterialRenderList::Stat()
ri->instance_count=1;
ri->Set(ro);
last_pipeline =ri->pipeline;
last_data_buffer=ri->pdb;
last_vdm =ri->pdb->vdm;
last_render_data=ri->prd;
@ -290,14 +279,13 @@ void MaterialRenderList::Stat()
{
ro=rn->scene_node->GetRenderable();
if(last_pipeline==ro->GetPipeline())
if(last_data_buffer->Comp(ro->GetDataBuffer()))
if(last_render_data->_Comp(ro->GetRenderData())==0)
{
++ri->instance_count;
++rn;
continue;
}
if(*last_data_buffer!=*ro->GetDataBuffer())
if(*last_render_data==*ro->GetRenderData())
{
++ri->instance_count;
++rn;
continue;
}
if(ri->pdb->vdm)
{
@ -317,7 +305,6 @@ void MaterialRenderList::Stat()
ri->instance_count=1;
ri->Set(ro);
last_pipeline =ri->pipeline;
last_data_buffer=ri->pdb;
last_vdm =ri->pdb->vdm;
last_render_data=ri->prd;
@ -411,17 +398,7 @@ void MaterialRenderList::ProcIndirectRender()
void MaterialRenderList::Render(RenderItem *ri)
{
if(last_pipeline!=ri->pipeline)
{
cmd_buf->BindPipeline(ri->pipeline);
last_pipeline=ri->pipeline;
last_data_buffer=nullptr;
//这里未来尝试换pipeline同时不换mi/primitive是否需要重新绑定mi/primitive
}
if(!ri->pdb->Comp(last_data_buffer)) //换buf了
if(*(ri->pdb)!=*last_data_buffer) //换buf了
{
if(indirect_draw_count) //如果有间接绘制的数据,赶紧给画了
ProcIndirectRender();
@ -432,7 +409,7 @@ void MaterialRenderList::Render(RenderItem *ri)
BindVAB(ri->pdb,ri->first_instance);
if(ri->pdb->ibo)
cmd_buf->BindIBO(ri->pdb->ibo);
cmd_buf->BindIBO(ri->pdb->ibo);
}
if(ri->pdb->vdm)
@ -459,15 +436,16 @@ void MaterialRenderList::Render(RenderCmdBuffer *rcb)
cmd_buf=rcb;
last_pipeline =nullptr;
cmd_buf->BindPipeline(rp_index.pipeline);
last_data_buffer=nullptr;
last_vdm =nullptr;
last_render_data=nullptr;
if(assign_buffer)
assign_buffer->Bind(material);
assign_buffer->Bind(rp_index.material);
cmd_buf->BindDescriptorSets(material);
cmd_buf->BindDescriptorSets(rp_index.material);
RenderItem *ri=ri_array.GetData();
for(uint i=0;i<ri_count;i++)

View File

@ -71,7 +71,7 @@ void RenderAssignBuffer::StatL2W(const RenderNodeList &rn_list)
RenderNode *rn=rn_list.GetData();
Matrix4f *l2wp=(Matrix4f *)(l2w_buffer->DeviceBuffer::Map());
for(uint i=0;i<rn_list.GetCount();i++)
for(int i=0;i<rn_list.GetCount();i++)
{
*l2wp=rn->scene_node->GetLocalToWorldMatrix();
++l2wp;
@ -215,7 +215,7 @@ void RenderAssignBuffer::WriteNode(const RenderNodeList &rn_list)
AssignData *adp=(AssignData *)(assign_vab->DeviceBuffer::Map());
for(uint i=0;i<rn_list.GetCount();i++)
for(int i=0;i<rn_list.GetCount();i++)
{
rn->l2w_index=i;

View File

@ -47,7 +47,7 @@ private:
private: //LocalToWorld矩阵数据
uint32 l2w_buffer_max_count; ///<LocalToWorld矩阵最大数量
int l2w_buffer_max_count; ///<LocalToWorld矩阵最大数量
DeviceBuffer *l2w_buffer; ///<LocalToWorld矩阵数据(UBO/SSBO)
void StatL2W(const RenderNodeList &);
@ -63,7 +63,7 @@ private: //材质实例数据
private: //分发数据
uint32 node_count; ///<节点数量
int node_count; ///<节点数量
VAB *assign_vab; ///<分发数据VAB(RG16UI格式R存L2W IDG存材质实例ID)
VkBuffer assign_buffer; ///<分发数据Buffer

View File

@ -0,0 +1,211 @@
#include<hgl/graph/RenderFramework.h>
#include<hgl/graph/manager/RenderPassManager.h>
#include<hgl/graph/manager/TextureManager.h>
#include<hgl/graph/module/SwapchainModule.h>
#include<hgl/graph/VKDeviceCreater.h>
#include<hgl/graph/VKCommandBuffer.h>
#include<hgl/Time.h>
#include<hgl/log/LogInfo.h>
VK_NAMESPACE_BEGIN
bool InitShaderCompiler();
void CloseShaderCompiler();
void InitGraphModuleFactory();
void ClearGraphModuleFactory();
namespace
{
static int RENDER_FRAMEWORK_COUNT=0;
}//namespace
GraphModule *CreateGraphModule(const AIDName &name,RenderFramework *rf);
namespace
{
hgl::graph::VulkanInstance *CreateVulkanInstance(const AnsiString &app_name)
{
CreateInstanceLayerInfo cili;
hgl_zero(cili);
cili.lunarg.standard_validation = true;
cili.khronos.validation = true;
InitVulkanInstanceProperties();
return CreateInstance("VulkanTest",nullptr,&cili);
}
}//namespace
GraphModule *RenderFramework::GetModule(const AIDName &name,bool create)
{
GraphModule *gm=graph_module_map.Get(name);
if(!gm)
{
gm=CreateGraphModule(name,this);
}
}
RenderFramework *CreateRenderFramework()
{
if(RENDER_FRAMEWORK_COUNT==0)
{
if(!InitShaderCompiler())
return(nullptr);
InitGraphModuleFactory();
RegistryCommonGraphModule();
}
++RENDER_FRAMEWORK_COUNT;
}
RenderFramework::RenderFramework(){}
RenderFramework::~RenderFramework()
{
graph_module_map.Destory();
--RENDER_FRAMEWORK_COUNT;
if(RENDER_FRAMEWORK_COUNT==0)
{
ClearGraphModuleFactory();
CloseShaderCompiler();
}
}
void RenderFramework::StartTime()
{
last_time=cur_time=GetDoubleTime();
}
void RenderFramework::BeginFrame()
{
cur_time=GetDoubleTime();
for(GraphModule *rm:per_frame_module_list)
{
if(rm->IsEnabled())
rm->OnPreFrame();
}
swapchain_module->BeginFrame();
}
void RenderFramework::EndFrame()
{
swapchain_module->EndFrame();
for(GraphModule *rm:per_frame_module_list)
{
if(rm->IsEnabled())
rm->OnPostFrame();
}
last_time=cur_time;
++frame_count;
}
void RenderFramework::MainLoop()
{
const double delta_time=cur_time-last_time;
BeginFrame();
RenderCmdBuffer *rcb=swapchain_module->GetRenderCmdBuffer();
if(rcb)
{
rcb->Begin();
rcb->BindFramebuffer(swapchain_module->GetRenderPass(),swapchain_module->GetRenderTarget()->GetFramebuffer());
for(RenderModule *rm:render_module_list)
{
if(rm->IsEnabled())
rm->OnFrameRender(delta_time,rcb);
}
rcb->End();
}
EndFrame();
}
void RenderFramework::Run()
{
if(!win)return;
if(!swapchain_module)return;
while(win->Update())
{
if(win->IsVisible())
MainLoop();
device->WaitIdle();
}
}
bool RenderFramework::Init(uint w,uint h,const OSString &app_name)
{
logger::InitLogger(app_name);
if(!InitShaderCompiler())
return(false);
InitNativeWindowSystem();
win=CreateRenderWindow(app_name);
if(!win)
return(false);
if(!win->Create(w,h))
{
delete win;
win=nullptr;
return(false);
}
inst=CreateVulkanInstance(ToAnsiString(app_name));
if(!inst)
return(false);
{
VulkanHardwareRequirement vh_req;
device=CreateRenderDevice(inst,win,&vh_req);
if(!device)
return(false);
graph_module_manager=InitGraphModuleManager(this);
render_pass_manager =graph_module_manager->GetModule<RenderPassManager>(true);
texture_manager =graph_module_manager->GetModule<TextureManager>(true);
swapchain_module =graph_module_manager->GetModule<SwapchainModule>(true);
}
win->Join(this);
return(true);
}
void RenderFramework::OnResize(uint w,uint h)
{
viewport_info.Set(w,h);
graph_module_manager->OnResize(VkExtent2D{.width=w,.height=h});
}
void RenderFramework::OnActive(bool)
{
}
void RenderFramework::OnClose()
{
}
VK_NAMESPACE_END

View File

@ -26,14 +26,15 @@ namespace hgl
if(ri)
{
Material *mtl=ri->GetMaterial();
RenderPipelineIndex rpi(ri->GetMaterial(),ri->GetPipeline());
MaterialRenderList *mrl;
if(!mrl_map.Get(mtl,mrl))
if(!mrl_map.Get(rpi,mrl))
{
mrl=new MaterialRenderList(device,true,mtl);
mrl=new MaterialRenderList(device,true,rpi);
mrl_map.Add(mtl,mrl);
mrl_map.Add(rpi,mrl);
}
mrl->Add(sn);
@ -92,10 +93,10 @@ namespace hgl
if(!ri)return;
Material *mtl=ri->GetMaterial();
RenderPipelineIndex rli(ri->GetMaterial(),ri->GetPipeline());
MaterialRenderList *mrl;
if(!mrl_map.Get(mtl,mrl)) //找到对应的
if(!mrl_map.Get(rli,mrl)) //找到对应的
return;
mrl->UpdateMaterialInstance(sn);

View File

@ -2,14 +2,15 @@
#include<hgl/log/LogInfo.h>
#include<hgl/graph/VKDevice.h>
#include<hgl/graph/VKBuffer.h>
#include<hgl/graph/manager/TextureManager.h>
namespace hgl
{
namespace graph
{
TileData::TileData(GPUDevice *dev,Texture2D *tt,const uint tw,const uint th)
TileData::TileData(TextureManager *tm,Texture2D *tt,const uint tw,const uint th)
{
device=dev;
texture_manager=tm;
tile_texture=tt;
@ -52,7 +53,7 @@ namespace hgl
tile_bytes=GetImageBytes(tile_texture->GetFormat(),tile_width*tile_height);
tile_buffer=device->CreateBuffer(VK_BUFFER_USAGE_TRANSFER_SRC_BIT,tile_bytes*tile_max_count,nullptr);
tile_buffer=texture_manager->CreateTransferSourceBuffer(tile_bytes*tile_max_count);
commit_ptr=nullptr;
}
@ -79,7 +80,7 @@ namespace hgl
tile_buffer->Unmap();
commit_ptr=nullptr;
if(!device->ChangeTexture2D(tile_texture,tile_buffer,commit_list))
if(!texture_manager->ChangeTexture2D(tile_texture,tile_buffer,commit_list))
return -2;
const int result=commit_list.GetCount();

View File

@ -5,7 +5,7 @@ DebugUtils *CreateDebugUtils(VkDevice device)
{
DebugUtilsFunction duf;
#define DUF_GETFUNC(n,N) duf.n=(PFN_vk##N##EXT)vkGetDeviceProcAddr(device,"vk"#N"EXT");if(!duf.##n)return(nullptr);
#define DUF_GETFUNC(n,N) duf.n=(PFN_vk##N##EXT)vkGetDeviceProcAddr(device,"vk"#N"EXT");if(!duf.n)return(nullptr);
DUF_GETFUNC(SetName, SetDebugUtilsObjectName );
DUF_GETFUNC(SetTag, SetDebugUtilsObjectTag );

View File

@ -67,4 +67,4 @@ void GenerateMipmaps(TextureCmdBuffer *texture_cmd_buf,VkImage image,VkImageAspe
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
subresourceRange);
}
VK_NAMESPACE_END
VK_NAMESPACE_END

View File

@ -1,12 +1,22 @@
#include<hgl/graph/VKDevice.h>
#include<hgl/graph/manager/TextureManager.h>
#include<hgl/graph/VKDevice.h>
#include<hgl/graph/VKCommandBuffer.h>
#include<hgl/graph/VKBuffer.h>
#include"CopyBufferToImage.h"
VK_NAMESPACE_BEGIN
bool GPUDevice::CheckFormatSupport(const VkFormat format,const uint32_t bits,ImageTiling tiling) const
DeviceBuffer *TextureManager::CreateTransferSourceBuffer(const VkDeviceSize size,const void *data)
{
const VkFormatProperties fp=attr->physical_device->GetFormatProperties(format);
if(size<=0)
return(nullptr);
return GetDevice()->CreateBuffer(VK_BUFFER_USAGE_TRANSFER_SRC_BIT,size,data);
}
bool TextureManager::CheckFormatSupport(const VkFormat format,const uint32_t bits,ImageTiling tiling) const
{
const VkFormatProperties fp=GetFormatProperties(format);
if(tiling==ImageTiling::Optimal)
return(fp.optimalTilingFeatures&bits);
@ -14,7 +24,7 @@ bool GPUDevice::CheckFormatSupport(const VkFormat format,const uint32_t bits,Ima
return(fp.linearTilingFeatures&bits);
}
void GPUDevice::Clear(TextureCreateInfo *tci)
void TextureManager::Clear(TextureCreateInfo *tci)
{
if(!tci)return;
@ -25,7 +35,7 @@ void GPUDevice::Clear(TextureCreateInfo *tci)
delete tci;
}
bool GPUDevice::CopyBufferToImage(const CopyBufferToImageInfo *info,VkPipelineStageFlags destinationStage)
bool TextureManager::CopyBufferToImage(const CopyBufferToImageInfo *info,VkPipelineStageFlags destinationStage)
{
if(!info)
return(false);
@ -75,7 +85,7 @@ bool GPUDevice::CopyBufferToImage(const CopyBufferToImageInfo *info,VkPipelineSt
return(true);
}
bool GPUDevice::CopyBufferToImage(Texture *tex,DeviceBuffer *buf,const VkBufferImageCopy *buffer_image_copy,const int count,const uint32_t base_layer,const uint32_t layer_count,VkPipelineStageFlags destinationStage)
bool TextureManager::CopyBufferToImage(Texture *tex,DeviceBuffer *buf,const VkBufferImageCopy *buffer_image_copy,const int count,const uint32_t base_layer,const uint32_t layer_count,VkPipelineStageFlags destinationStage)
{
if(!tex||!buf)
return(false);
@ -97,7 +107,7 @@ bool GPUDevice::CopyBufferToImage(Texture *tex,DeviceBuffer *buf,const VkBufferI
return CopyBufferToImage(&info,destinationStage);
}
bool GPUDevice::SubmitTexture(const VkCommandBuffer *cmd_bufs,const uint32_t count)
bool TextureManager::SubmitTexture(const VkCommandBuffer *cmd_bufs,const uint32_t count)
{
if(!cmd_bufs||count<=0)
return(false);

View File

@ -1,4 +1,5 @@
#include<hgl/graph/VKDevice.h>
#include<hgl/graph/manager/TextureManager.h>
#include<hgl/graph/VKDevice.h>
#include<hgl/graph/VKImageCreateInfo.h>
#include<hgl/graph/VKCommandBuffer.h>
#include<hgl/graph/VKBuffer.h>
@ -7,15 +8,19 @@
VK_NAMESPACE_BEGIN
void GenerateMipmaps(TextureCmdBuffer *texture_cmd_buf,VkImage image,VkImageAspectFlags aspect_mask,VkExtent3D extent,const uint32_t mipLevels,const uint32_t layer_count);
Texture2D *GPUDevice::CreateTexture2D(TextureData *tex_data)
Texture2D *TextureManager::CreateTexture2D(TextureData *tex_data)
{
if(!tex_data)
return(nullptr);
return(new Texture2D(attr->device,tex_data));
Texture2D *tex=new Texture2D(this,AcquireID(),tex_data);
Add(tex);
return tex;
}
Texture2D *GPUDevice::CreateTexture2D(TextureCreateInfo *tci)
Texture2D *TextureManager::CreateTexture2D(TextureCreateInfo *tci)
{
if(!tci)return(nullptr);
@ -39,11 +44,11 @@ Texture2D *GPUDevice::CreateTexture2D(TextureCreateInfo *tci)
return(nullptr);
}
tci->memory=CreateMemory(tci->image);
tci->memory=GetDevice()->CreateMemory(tci->image);
}
if(!tci->image_view)
tci->image_view=CreateImageView2D(attr->device,tci->format,tci->extent,tci->target_mipmaps,tci->aspect,tci->image);
tci->image_view=CreateImageView2D(GetVkDevice(),tci->format,tci->extent,tci->target_mipmaps,tci->aspect,tci->image);
TextureData *tex_data=new TextureData(tci);
@ -56,7 +61,7 @@ Texture2D *GPUDevice::CreateTexture2D(TextureCreateInfo *tci)
}
if((!tci->buffer)&&tci->pixels&&tci->total_bytes>0)
tci->buffer=CreateBuffer(VK_BUFFER_USAGE_TRANSFER_SRC_BIT,tci->total_bytes,tci->pixels);
tci->buffer=CreateTransferSourceBuffer(tci->total_bytes,tci->pixels);
if(tci->buffer)
{
@ -89,7 +94,7 @@ Texture2D *GPUDevice::CreateTexture2D(TextureCreateInfo *tci)
return tex;
}
bool GPUDevice::CommitTexture2D(Texture2D *tex,DeviceBuffer *buf,VkPipelineStageFlags destinationStage)
bool TextureManager::CommitTexture2D(Texture2D *tex,DeviceBuffer *buf,VkPipelineStageFlags destinationStage)
{
if(!tex||!buf)return(false);
@ -98,7 +103,7 @@ bool GPUDevice::CommitTexture2D(Texture2D *tex,DeviceBuffer *buf,VkPipelineStage
return CopyBufferToImage2D(tex,buf,&buffer_image_copy,destinationStage);
}
bool GPUDevice::CommitTexture2DMipmaps(Texture2D *tex,DeviceBuffer *buf,const VkExtent3D &extent,uint32_t total_bytes)
bool TextureManager::CommitTexture2DMipmaps(Texture2D *tex,DeviceBuffer *buf,const VkExtent3D &extent,uint32_t total_bytes)
{
if(!tex||!buf
||extent.width*extent.height<=0)
@ -144,7 +149,7 @@ bool GPUDevice::CommitTexture2DMipmaps(Texture2D *tex,DeviceBuffer *buf,const Vk
return CopyBufferToImage2D(tex,buf,buffer_image_copy,miplevel,VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
}
bool GPUDevice::ChangeTexture2D(Texture2D *tex,DeviceBuffer *buf,const List<Image2DRegion> &ir_list,VkPipelineStageFlags destinationStage)
bool TextureManager::ChangeTexture2D(Texture2D *tex,DeviceBuffer *buf,const List<Image2DRegion> &ir_list,VkPipelineStageFlags destinationStage)
{
if(!tex||!buf||ir_list.GetCount()<=0)
return(false);
@ -184,7 +189,7 @@ bool GPUDevice::ChangeTexture2D(Texture2D *tex,DeviceBuffer *buf,const List<Imag
return result;
}
bool GPUDevice::ChangeTexture2D(Texture2D *tex,DeviceBuffer *buf,const RectScope2ui &scope,VkPipelineStageFlags destinationStage)
bool TextureManager::ChangeTexture2D(Texture2D *tex,DeviceBuffer *buf,const RectScope2ui &scope,VkPipelineStageFlags destinationStage)
{
if(!tex||!buf
||scope.GetWidth()<=0
@ -202,7 +207,7 @@ bool GPUDevice::ChangeTexture2D(Texture2D *tex,DeviceBuffer *buf,const RectScope
return result;
}
bool GPUDevice::ChangeTexture2D(Texture2D *tex,void *data,const uint32_t size,const RectScope2ui &scope,VkPipelineStageFlags destinationStage)
bool TextureManager::ChangeTexture2D(Texture2D *tex,const void *data,const VkDeviceSize size,const RectScope2ui &scope,VkPipelineStageFlags destinationStage)
{
if(!tex||!data
||size<=0
@ -212,7 +217,7 @@ bool GPUDevice::ChangeTexture2D(Texture2D *tex,void *data,const uint32_t size,co
||scope.GetBottom()>tex->GetHeight())
return(false);
DeviceBuffer *buf=CreateBuffer(VK_BUFFER_USAGE_TRANSFER_SRC_BIT,size,data);
DeviceBuffer *buf=CreateTransferSourceBuffer(size,data);
bool result=ChangeTexture2D(tex,buf,scope,destinationStage);

View File

@ -1,4 +1,5 @@
#include<hgl/graph/VKDevice.h>
#include<hgl/graph/manager/TextureManager.h>
#include<hgl/graph/VKDevice.h>
#include<hgl/graph/VKImageCreateInfo.h>
#include<hgl/graph/VKCommandBuffer.h>
#include<hgl/graph/VKBuffer.h>
@ -7,15 +8,19 @@
VK_NAMESPACE_BEGIN
void GenerateMipmaps(TextureCmdBuffer *texture_cmd_buf,VkImage image,VkImageAspectFlags aspect_mask,VkExtent3D extent,const uint32_t mipLevels,const uint32_t layer_count);
Texture2DArray *GPUDevice::CreateTexture2DArray(TextureData *tex_data)
Texture2DArray *TextureManager::CreateTexture2DArray(TextureData *tex_data)
{
if(!tex_data)
return(nullptr);
return(new Texture2DArray(attr->device,tex_data));
Texture2DArray *tex=new Texture2DArray(this,AcquireID(),tex_data);
Add(tex);
return tex;
}
Texture2DArray *GPUDevice::CreateTexture2DArray(TextureCreateInfo *tci)
Texture2DArray *TextureManager::CreateTexture2DArray(TextureCreateInfo *tci)
{
if(!tci)return(nullptr);
@ -39,11 +44,11 @@ Texture2DArray *GPUDevice::CreateTexture2DArray(TextureCreateInfo *tci)
return(nullptr);
}
tci->memory=CreateMemory(tci->image);
tci->memory=GetDevice()->CreateMemory(tci->image);
}
if(!tci->image_view)
tci->image_view=CreateImageView2DArray(attr->device,tci->format,tci->extent,tci->target_mipmaps,tci->aspect,tci->image);
tci->image_view=CreateImageView2DArray(GetVkDevice(),tci->format,tci->extent,tci->target_mipmaps,tci->aspect,tci->image);
TextureData *tex_data=new TextureData(tci);
@ -91,7 +96,7 @@ Texture2DArray *GPUDevice::CreateTexture2DArray(TextureCreateInfo *tci)
return tex;
}
Texture2DArray *GPUDevice::CreateTexture2DArray(const uint32_t w,const uint32_t h,const uint32 l,const VkFormat fmt,const bool mipmaps)
Texture2DArray *TextureManager::CreateTexture2DArray(const uint32_t w,const uint32_t h,const uint32 l,const VkFormat fmt,const bool mipmaps)
{
if(w*h*l<=0)
return(nullptr);
@ -204,7 +209,7 @@ Texture2DArray *GPUDevice::CreateTexture2DArray(const uint32_t w,const uint32_t
// return result;
//}
bool GPUDevice::ChangeTexture2DArray(Texture2DArray *tex,DeviceBuffer *buf,const RectScope2ui &scope,const uint32_t base_layer,const uint32_t layer_count,VkPipelineStageFlags destinationStage)
bool TextureManager::ChangeTexture2DArray(Texture2DArray *tex,DeviceBuffer *buf,const RectScope2ui &scope,const uint32_t base_layer,const uint32_t layer_count,VkPipelineStageFlags destinationStage)
{
if(!tex||!buf
||base_layer<0
@ -224,7 +229,7 @@ bool GPUDevice::ChangeTexture2DArray(Texture2DArray *tex,DeviceBuffer *buf,const
return result;
}
bool GPUDevice::ChangeTexture2DArray(Texture2DArray *tex,void *data,const uint32_t size,const RectScope2ui &scope,const uint32_t base_layer,const uint32_t layer_count,VkPipelineStageFlags destinationStage)
bool TextureManager::ChangeTexture2DArray(Texture2DArray *tex,const void *data,const VkDeviceSize size,const RectScope2ui &scope,const uint32_t base_layer,const uint32_t layer_count,VkPipelineStageFlags destinationStage)
{
if(!tex||!data
||size<=0
@ -236,7 +241,7 @@ bool GPUDevice::ChangeTexture2DArray(Texture2DArray *tex,void *data,const uint32
||scope.GetBottom()>tex->GetHeight())
return(false);
DeviceBuffer *buf=CreateBuffer(VK_BUFFER_USAGE_TRANSFER_SRC_BIT,size,data);
DeviceBuffer *buf=CreateTransferSourceBuffer(size,data);
bool result=ChangeTexture2DArray(tex,buf,scope,base_layer,layer_count,destinationStage);

View File

@ -1,6 +1,8 @@
#include"VKTextureLoader.h"
#include<hgl/io/FileInputStream.h>
#include<hgl/log/LogInfo.h>
#include<hgl/graph/VKTexture.h>
#include<hgl/graph/manager/TextureManager.h>
VK_NAMESPACE_BEGIN
//template<> void VkTextureLoader<Texture2DArray,Texture2DArrayLoader>::OnExtent(VkExtent3D &extent)
@ -15,10 +17,13 @@ VK_NAMESPACE_BEGIN
// return device->CreateTexture2DArray(tci);
//}
bool LoadTexture2DLayerFromFile(GPUDevice *device,Texture2DArray *ta,const uint32_t layer,const OSString &filename,bool auto_mipmaps)
bool LoadTexture2DLayerFromFile(TextureManager *tm,Texture2DArray *ta,const uint32_t layer,const OSString &filename,bool auto_mipmaps)
{
if(!tm||filename.IsEmpty())
return(false);
//注依然是Texture2D则非Texture2DArray。因为这里LOAD的是2D纹理并不是2DArray纹理
VkTextureLoader<Texture2D,Texture2DLoader> loader(device,auto_mipmaps);
VkTextureLoader<Texture2D,Texture2DLoader> loader(tm,auto_mipmaps);
if(!loader.Load(filename))
return(false);
@ -33,6 +38,6 @@ bool LoadTexture2DLayerFromFile(GPUDevice *device,Texture2DArray *ta,const uint3
scope.Width=ta->GetWidth();
scope.Height=ta->GetHeight();
return device->ChangeTexture2DArray(ta,buf,scope,layer,1);
return tm->ChangeTexture2DArray(ta,buf,scope,layer,1);
}
VK_NAMESPACE_END

View File

@ -12,12 +12,15 @@ template<> void VkTextureLoader<Texture2D,Texture2DLoader>::OnExtent(VkExtent3D
template<> Texture2D *VkTextureLoader<Texture2D,Texture2DLoader>::OnCreateTexture(TextureCreateInfo *tci)
{
return device->CreateTexture2D(tci);
return tex_manager->CreateTexture2D(tci);
}
Texture2D *CreateTexture2DFromFile(GPUDevice *device,const OSString &filename,bool auto_mipmaps)
Texture2D *CreateTexture2DFromFile(TextureManager *tm,const OSString &filename,bool auto_mipmaps)
{
VkTextureLoader<Texture2D,Texture2DLoader> loader(device,auto_mipmaps);
if(!tm||filename.IsEmpty())
return(nullptr);
VkTextureLoader<Texture2D,Texture2DLoader> loader(tm,auto_mipmaps);
if(!loader.Load(filename))
return(nullptr);

View File

@ -1,3 +1,4 @@
#include<hgl/graph/manager/TextureManager.h>
#include<hgl/graph/VKDevice.h>
#include<hgl/graph/VKImageCreateInfo.h>
#include<hgl/graph/VKCommandBuffer.h>
@ -6,15 +7,19 @@
VK_NAMESPACE_BEGIN
void GenerateMipmaps(TextureCmdBuffer *texture_cmd_buf,VkImage image,VkImageAspectFlags aspect_mask,VkExtent3D extent,const uint32_t mipLevels,const uint32_t layer_count);
TextureCube *GPUDevice::CreateTextureCube(TextureData *tex_data)
TextureCube *TextureManager::CreateTextureCube(TextureData *tex_data)
{
if(!tex_data)
return(nullptr);
return(new TextureCube(attr->device,tex_data));
TextureCube *tex=new TextureCube(this,AcquireID(),tex_data);
Add(tex);
return tex;
}
TextureCube *GPUDevice::CreateTextureCube(TextureCreateInfo *tci)
TextureCube *TextureManager::CreateTextureCube(TextureCreateInfo *tci)
{
if(!tci)return(nullptr);
@ -34,11 +39,11 @@ TextureCube *GPUDevice::CreateTextureCube(TextureCreateInfo *tci)
return(nullptr);
}
tci->memory=CreateMemory(tci->image);
tci->memory=GetDevice()->CreateMemory(tci->image);
}
if(!tci->image_view)
tci->image_view=CreateImageViewCube(attr->device,tci->format,tci->extent,tci->target_mipmaps,tci->aspect,tci->image);
tci->image_view=CreateImageViewCube(GetVkDevice(),tci->format,tci->extent,tci->target_mipmaps,tci->aspect,tci->image);
TextureData *tex_data=new TextureData(tci);
@ -51,24 +56,24 @@ TextureCube *GPUDevice::CreateTextureCube(TextureCreateInfo *tci)
}
if((!tci->buffer)&&tci->pixels&&tci->total_bytes>0)
tci->buffer=CreateBuffer(VK_BUFFER_USAGE_TRANSFER_SRC_BIT,tci->total_bytes,tci->pixels);
tci->buffer=CreateTransferSourceBuffer(tci->total_bytes,tci->pixels);
if(tci->buffer)
{
texture_cmd_buf->Begin();
if(tci->target_mipmaps==tci->origin_mipmaps)
{
if(tci->target_mipmaps<=1) //本身不含mipmaps但也不要mipmaps
if(tci->target_mipmaps<=1) //本身不含mipmaps但也不要mipmaps
{
CommitTextureCube(tex,tci->buffer,tci->mipmap_zero_total_bytes,VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
}
else //本身有mipmaps数据
else //本身有mipmaps数据
{
CommitTextureCubeMipmaps(tex,tci->buffer,tci->extent,tci->mipmap_zero_total_bytes);
}
}
else
if(tci->origin_mipmaps<=1) //本身不含mipmaps数据,又想要mipmaps
if(tci->origin_mipmaps<=1) //本身不含mipmaps数据,又想要mipmaps
{
CommitTextureCube(tex,tci->buffer,tci->mipmap_zero_total_bytes,VK_PIPELINE_STAGE_TRANSFER_BIT);
GenerateMipmaps(texture_cmd_buf,tex->GetImage(),tex->GetAspect(),tci->extent,tex_data->miplevel,6);
@ -84,7 +89,7 @@ TextureCube *GPUDevice::CreateTextureCube(TextureCreateInfo *tci)
return tex;
}
bool GPUDevice::CommitTextureCube(TextureCube *tex,DeviceBuffer *buf,const uint32_t mipmaps_zero_bytes,VkPipelineStageFlags destinationStage)
bool TextureManager::CommitTextureCube(TextureCube *tex,DeviceBuffer *buf,const uint32_t mipmaps_zero_bytes,VkPipelineStageFlags destinationStage)
{
if(!tex||!buf||!mipmaps_zero_bytes)return(false);
@ -93,7 +98,7 @@ bool GPUDevice::CommitTextureCube(TextureCube *tex,DeviceBuffer *buf,const uint3
return CopyBufferToImageCube(tex,buf,&buffer_image_copy,destinationStage);
}
bool GPUDevice::CommitTextureCubeMipmaps(TextureCube *tex,DeviceBuffer *buf,const VkExtent3D &extent,uint32_t total_bytes)
bool TextureManager::CommitTextureCubeMipmaps(TextureCube *tex,DeviceBuffer *buf,const VkExtent3D &extent,uint32_t total_bytes)
{
if(!tex||!buf
||extent.width*extent.height<=0)
@ -216,4 +221,4 @@ bool GPUDevice::CommitTextureCubeMipmaps(TextureCube *tex,DeviceBuffer *buf,cons
// delete buf;
// return(result);
//}
VK_NAMESPACE_END
VK_NAMESPACE_END

View File

@ -12,12 +12,15 @@ template<> void VkTextureLoader<TextureCube,TextureCubeLoader>::OnExtent(VkExten
template<> TextureCube *VkTextureLoader<TextureCube,TextureCubeLoader>::OnCreateTexture(TextureCreateInfo *tci)
{
return device->CreateTextureCube(tci);
return tex_manager->CreateTextureCube(tci);
}
TextureCube *CreateTextureCubeFromFile(GPUDevice *device,const OSString &filename,bool auto_mipmaps)
TextureCube *CreateTextureCubeFromFile(TextureManager *tm,const OSString &filename,bool auto_mipmaps)
{
VkTextureLoader<TextureCube,TextureCubeLoader> loader(device,auto_mipmaps);
if(!tm||filename.IsEmpty())
return(nullptr);
VkTextureLoader<TextureCube,TextureCubeLoader> loader(tm,auto_mipmaps);
if(!loader.Load(filename))
return(nullptr);

View File

@ -1,8 +1,8 @@
#pragma once
#include<hgl/graph/VK.h>
#include<hgl/graph/VKDevice.h>
#include<hgl/graph/VKBuffer.h>
#include<hgl/graph/VKTexture.h>
#include<hgl/graph/TextureLoader.h>
#include<hgl/graph/manager/TextureManager.h>
#include<hgl/graph/VKTextureCreateInfo.h>
VK_NAMESPACE_BEGIN
@ -10,7 +10,7 @@ template<typename T,typename TL> class VkTextureLoader:public TL
{
protected:
GPUDevice *device;
TextureManager *tex_manager;
DeviceBuffer *buf;
T *tex;
@ -18,9 +18,9 @@ protected:
public:
VkTextureLoader(GPUDevice *dev,const bool am)
VkTextureLoader(TextureManager *tm,const bool am)
{
device=dev;
tex_manager=tm;
buf=nullptr;
tex=nullptr;
auto_mipmaps=am;
@ -39,7 +39,7 @@ public:
if(!CheckVulkanFormat(tex_format))
return(nullptr);
buf=device->CreateBuffer(VK_BUFFER_USAGE_TRANSFER_SRC_BIT,total_bytes);
buf=tex_manager->CreateTransferSourceBuffer(total_bytes);
if(!buf)
return(nullptr);
@ -75,7 +75,7 @@ public:
if(auto_mipmaps&&tex_file_header.mipmaps<=1)
{
if(device->CheckFormatSupport(tex_format,VK_FORMAT_FEATURE_BLIT_DST_BIT))
if(tex_manager->CheckFormatSupport(tex_format,VK_FORMAT_FEATURE_BLIT_DST_BIT))
{
tci->usage|=VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
tci->SetAutoMipmaps();

View File

@ -8,48 +8,23 @@
#include<hgl/graph/VKRenderPass.h>
#include<hgl/graph/VKFramebuffer.h>
#include<hgl/graph/VKDescriptorSet.h>
#include<hgl/graph/VKDeviceRenderPassManage.h>
#include<hgl/graph/module/GraphModule.h>
#include<hgl/graph/module/SwapchainModule.h>
VK_NAMESPACE_BEGIN
bool ClearGraphModuleManager(GPUDevice *dev);
GPUDevice::GPUDevice(GPUDeviceAttribute *da)
{
attr=da;
texture_queue=nullptr;
texture_cmd_buf=nullptr;
InitRenderPassManage();
sc_rt=nullptr;
Resize(attr->surface_caps.currentExtent);
texture_cmd_buf=CreateTextureCommandBuffer(attr->physical_device->GetDeviceName()+AnsiString(":TexCmdBuffer"));
texture_queue=CreateQueue();
}
GPUDevice::~GPUDevice()
{
ClearRenderPassManage();
SAFE_CLEAR(sc_rt);
SAFE_CLEAR(texture_queue);
SAFE_CLEAR(texture_cmd_buf);
delete attr;
}
bool GPUDevice::Resize(const VkExtent2D &extent)
{
SAFE_CLEAR(sc_rt);
attr->RefreshSurfaceCaps();
sc_rt=CreateSwapchainRenderTarget();
return(sc_rt);
}
VkCommandBuffer GPUDevice::CreateCommandBuffer(const AnsiString &name)
{
if(!attr->cmd_pool)

View File

@ -133,13 +133,17 @@ void GPUDeviceAttribute::GetQueueFamily()
video_decode_family = i;
}
#ifdef VK_ENABLE_BETA_EXTENSIONS
if(fp->queueFlags & VK_QUEUE_VIDEO_ENCODE_BIT_KHR)
{
if (video_encode_family == ERROR_FAMILY_INDEX)
video_encode_family = i;
}
#endif//VK_ENABLE_BETA_EXTENSIONS
if(fp->queueFlags & VK_QUEUE_TRANSFER_BIT)
{
if(transfer_family == ERROR_FAMILY_INDEX)
transfer_family = i;
}
if(fp->queueFlags & VK_QUEUE_COMPUTE_BIT)
{

View File

@ -71,20 +71,16 @@ namespace
// VK_EXT_SAMPLER_FILTER_MINMAX_EXTENSION_NAME,
VK_KHR_SPIRV_1_4_EXTENSION_NAME,
VK_EXT_LINE_RASTERIZATION_EXTENSION_NAME,
VK_IMG_FORMAT_PVRTC_EXTENSION_NAME,
VK_EXT_INDEX_TYPE_UINT8_EXTENSION_NAME,
VK_EXT_BLEND_OPERATION_ADVANCED_EXTENSION_NAME
};
for(const char *ext_name:require_ext_list)
if(physical_device->CheckExtensionSupport(ext_name))
ext_list->Add(ext_name);
if(require.lineRasterization>=VulkanHardwareRequirement::SupportLevel::Want)
ext_list->Add(VK_EXT_LINE_RASTERIZATION_EXTENSION_NAME);
if(require.texture_compression.PVRTC>=VulkanHardwareRequirement::SupportLevel::Want) //前面检测过了,所以这里不用再次检测是否支持
ext_list->Add(VK_IMG_FORMAT_PVRTC_EXTENSION_NAME);
if(require.fullDrawIndexUint8>=VulkanHardwareRequirement::SupportLevel::Want)
ext_list->Add(VK_EXT_INDEX_TYPE_UINT8_EXTENSION_NAME);
}
void SetDeviceFeatures(VkPhysicalDeviceFeatures *features,const VkPhysicalDeviceFeatures &pdf,const VulkanHardwareRequirement &require)
@ -219,7 +215,7 @@ VkDevice VulkanDeviceCreater::CreateDevice(const uint32_t graphics_family)
VkDeviceCreateInfo create_info;
create_info.sType =VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
create_info.pNext =nullptr;
//create_info.pNext =nullptr;
create_info.flags =0;
create_info.queueCreateInfoCount =1;
create_info.pQueueCreateInfos =&queue_info;
@ -229,18 +225,38 @@ VkDevice VulkanDeviceCreater::CreateDevice(const uint32_t graphics_family)
create_info.ppEnabledLayerNames =nullptr;
create_info.pEnabledFeatures =&features;
void **pNext=const_cast<void **>(&create_info.pNext);
VkPhysicalDeviceIndexTypeUint8FeaturesEXT index_type_uint8_features;
if(physical_device->SupportU8Index()
&&require.fullDrawIndexUint8>=VulkanHardwareRequirement::SupportLevel::Want)
{
create_info.pNext=&index_type_uint8_features;
*pNext=&index_type_uint8_features;
index_type_uint8_features.sType =VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INDEX_TYPE_UINT8_FEATURES_EXT;
index_type_uint8_features.pNext =nullptr;
//index_type_uint8_features.pNext =nullptr;
index_type_uint8_features.indexTypeUint8=VK_TRUE;
pNext=const_cast<void **>(&index_type_uint8_features.pNext);
}
VkPhysicalDeviceBlendOperationAdvancedFeaturesEXT blend_op_advanced_features;
if(physical_device->SupportBlendOpAdvanced()
&&require.blendOperationAdvanced>=VulkanHardwareRequirement::SupportLevel::Want)
{
*pNext=&blend_op_advanced_features;
blend_op_advanced_features.sType=VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BLEND_OPERATION_ADVANCED_FEATURES_EXT;
//blend_op_advanced_features.pNext=nullptr;
blend_op_advanced_features.advancedBlendCoherentOperations=VK_TRUE;
pNext=const_cast<void **>(&blend_op_advanced_features.pNext);
}
*pNext=nullptr;
VkDevice device;
if(vkCreateDevice(*physical_device,&create_info,nullptr,&device)==VK_SUCCESS)
@ -324,6 +340,12 @@ GPUDevice *VulkanDeviceCreater::CreateRenderDevice()
device_attr->uint32_index_type=true;
}
if(physical_device->SupportBlendOpAdvanced()
&&require.blendOperationAdvanced>=VulkanHardwareRequirement::SupportLevel::Want)
{
device_attr->blendOpAdvance=true;
}
device_attr->surface_format=surface_format;
GetDeviceQueue(device_attr);

View File

@ -1,8 +1,8 @@
#include<hgl/graph/VKDevice.h>
#include<hgl/graph/manager/TextureManager.h>
#include<hgl/graph/VKImageCreateInfo.h>
VK_NAMESPACE_BEGIN
VkImage GPUDevice::CreateImage(VkImageCreateInfo *ici)
VkImage TextureManager::CreateImage(VkImageCreateInfo *ici)
{
if(!ici)return(VK_NULL_HANDLE);
if(!CheckVulkanFormat(ici->format))return(VK_NULL_HANDLE);
@ -10,16 +10,23 @@ VkImage GPUDevice::CreateImage(VkImageCreateInfo *ici)
VkImage image;
if(vkCreateImage(attr->device,ici, nullptr, &image)!=VK_SUCCESS)
if(vkCreateImage(GetVkDevice(),ici, nullptr, &image)!=VK_SUCCESS)
return(nullptr);
image_set.Add(image);
return image;
}
void GPUDevice::DestroyImage(VkImage img)
void TextureManager::DestroyImage(VkImage img)
{
if(img==VK_NULL_HANDLE)return;
vkDestroyImage(attr->device,img,nullptr);
if(!image_set.Contains(img))
return;
image_set.Delete(img);
vkDestroyImage(GetVkDevice(),img,nullptr);
}
VK_NAMESPACE_END

View File

@ -48,9 +48,9 @@ MaterialParameters *GPUDevice::CreateMP(const MaterialDescriptorManager *desc_ma
if(!ds)return(nullptr);
#ifdef _DEBUG
const UTF8String addr_string=HexToString<u8char,uint64_t>((uint64_t)(ds->GetDescriptorSet()));
const U8String addr_string=HexToString<u8char,uint64_t>((uint64_t)(ds->GetDescriptorSet()));
LOG_INFO(U8_TEXT("Create [DescriptSets:")+addr_string+U8_TEXT("] OK! Material Name: \"")+(const UTF8String &)(desc_manager->GetMaterialName())+U8_TEXT("\" Type: ")+(u8char *)(GetDescriptorSetTypeName(desc_set_type)));
LOG_INFO(U8_TEXT("Create [DescriptSets:")+addr_string+U8_TEXT("] OK! Material Name: \"")+(const U8String &)(desc_manager->GetMaterialName())+U8_TEXT("\" Type: ")+(u8char *)(GetDescriptorSetTypeName(desc_set_type)));
#endif//_DEBUG
return(new MaterialParameters(desc_manager,desc_set_type,ds));

View File

@ -1,38 +0,0 @@
#include<hgl/graph/VKDevice.h>
#include<hgl/graph/VKDeviceAttribute.h>
#include<hgl/graph/VKPhysicalDevice.h>
#include<hgl/graph/VKDeviceRenderPassManage.h>
VK_NAMESPACE_BEGIN
void GPUDevice::InitRenderPassManage()
{
render_pass_manage=new DeviceRenderPassManage(attr->device,attr->pipeline_cache);
SwapchainRenderbufferInfo rbi(attr->surface_format.format,attr->physical_device->GetDepthFormat());
device_render_pass=render_pass_manage->AcquireRenderPass(&rbi);
#ifdef _DEBUG
if(attr->debug_utils)
attr->debug_utils->SetRenderPass(device_render_pass->GetVkRenderPass(),"MainDeviceRenderPass");
#endif//_DEBUG
}
void GPUDevice::ClearRenderPassManage()
{
SAFE_CLEAR(render_pass_manage);
}
RenderPass *GPUDevice::AcquireRenderPass(const RenderbufferInfo *rbi,const uint subpass_count)
{
for(const VkFormat &fmt:rbi->GetColorFormatList())
if(!attr->physical_device->IsColorAttachmentOptimal(fmt))
return(nullptr);
if(rbi->HasDepthOrStencil())
if(!attr->physical_device->IsDepthAttachmentOptimal(rbi->GetDepthFormat()))
return(nullptr);
return render_pass_manage->AcquireRenderPass(rbi,subpass_count);
}
VK_NAMESPACE_END

View File

@ -1,81 +0,0 @@
#include<hgl/graph/VKDevice.h>
VK_NAMESPACE_BEGIN
RenderTarget *GPUDevice::CreateRT(const FramebufferInfo *fbi,RenderPass *rp,const uint32_t fence_count)
{
if(!fbi)return(nullptr);
if(!rp)return(nullptr);
const uint32_t color_count=fbi->GetColorCount();
const VkExtent2D extent=fbi->GetExtent();
const VkFormat depth_format=fbi->GetDepthFormat();
AutoDeleteObjectArray<Texture2D> color_texture_list(color_count);
AutoDeleteArray<ImageView *> color_iv_list(color_count); //iv只是从Texture2D中取出来的无需一个个delete
Texture2D **tp=color_texture_list;
ImageView **iv=color_iv_list;
for(const VkFormat &fmt:fbi->GetColorFormatList())
{
Texture2D *color_texture=CreateTexture2D(new ColorAttachmentTextureCreateInfo(fmt,extent));
if(!color_texture)
return(nullptr);
*tp++=color_texture;
*iv++=color_texture->GetImageView();
}
Texture2D *depth_texture=(depth_format!=PF_UNDEFINED)?CreateTexture2D(new DepthAttachmentTextureCreateInfo(depth_format,extent)):nullptr;
Framebuffer *fb=CreateFBO(rp,color_iv_list,color_count,depth_texture?depth_texture->GetImageView():nullptr);
if(fb)
{
DeviceQueue *q=CreateQueue(fence_count,false);
Semaphore *render_complete_semaphore=CreateGPUSemaphore();
RenderTarget *rt=new RenderTarget(q,render_complete_semaphore,rp,fb,color_texture_list,color_count,depth_texture);
color_texture_list.DiscardObject();
return rt;
}
SAFE_CLEAR(depth_texture);
return nullptr;
}
RenderTarget *GPUDevice::CreateRT(const FramebufferInfo *fbi,const uint32_t fence_count)
{
if(!fbi)return(nullptr);
RenderPass *rp=AcquireRenderPass(fbi);
if(!rp)return(nullptr);
return CreateRT(fbi,rp,fence_count);
}
RTSwapchain *GPUDevice::CreateSwapchainRenderTarget()
{
Swapchain *sc=CreateSwapchain(attr->surface_caps.currentExtent);
if(!sc)
return(nullptr);
DeviceQueue *q=CreateQueue(sc->color_count,false);
Semaphore *render_complete_semaphore=CreateGPUSemaphore();
Semaphore *present_complete_semaphore=CreateGPUSemaphore();
RTSwapchain *srt=new RTSwapchain( attr->device,
sc,
q,
render_complete_semaphore,
present_complete_semaphore,
device_render_pass
);
return srt;
}
VK_NAMESPACE_END

View File

@ -1,155 +0,0 @@
#include<hgl/graph/VKDevice.h>
#include<hgl/graph/VKDeviceAttribute.h>
#include<hgl/graph/VKPhysicalDevice.h>
#include<iostream>
VK_NAMESPACE_BEGIN
namespace
{
//VkExtent2D SwapchainExtentClamp(const VkSurfaceCapabilitiesKHR &surface_caps,const VkExtent2D &acquire_extent)
//{
// VkExtent2D swapchain_extent;
// swapchain_extent.width =hgl_clamp(acquire_extent.width, surface_caps.minImageExtent.width, surface_caps.maxImageExtent.width );
// swapchain_extent.height =hgl_clamp(acquire_extent.height, surface_caps.minImageExtent.height, surface_caps.maxImageExtent.height );
// return swapchain_extent;
//}
VkSwapchainKHR CreateSwapChain(const GPUDeviceAttribute *dev_attr,const VkExtent2D &extent)
{
VkSwapchainCreateInfoKHR swapchain_ci;
swapchain_ci.sType =VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
swapchain_ci.pNext =nullptr;
swapchain_ci.flags =0;
swapchain_ci.surface =dev_attr->surface;
swapchain_ci.minImageCount =3;//rsa->surface_caps.minImageCount;
swapchain_ci.imageFormat =dev_attr->surface_format.format;
swapchain_ci.imageColorSpace =dev_attr->surface_format.colorSpace;
swapchain_ci.imageExtent =extent;
swapchain_ci.imageArrayLayers =1;
swapchain_ci.imageUsage =VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
swapchain_ci.queueFamilyIndexCount =0;
swapchain_ci.pQueueFamilyIndices =nullptr;
swapchain_ci.preTransform =dev_attr->preTransform;
swapchain_ci.compositeAlpha =dev_attr->compositeAlpha;
swapchain_ci.presentMode =VK_PRESENT_MODE_FIFO_KHR;
swapchain_ci.clipped =VK_TRUE;
swapchain_ci.oldSwapchain =VK_NULL_HANDLE;
if(dev_attr->surface_caps.supportedUsageFlags&VK_IMAGE_USAGE_TRANSFER_SRC_BIT)
swapchain_ci.imageUsage|=VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
if(dev_attr->surface_caps.supportedUsageFlags&VK_IMAGE_USAGE_TRANSFER_DST_BIT)
swapchain_ci.imageUsage|=VK_IMAGE_USAGE_TRANSFER_DST_BIT;
uint32_t queueFamilyIndices[2]={dev_attr->graphics_family, dev_attr->present_family};
if(dev_attr->graphics_family!=dev_attr->present_family)
{
// If the graphics and present queues are from different queue families,
// we either have to explicitly transfer ownership of images between
// the queues, or we have to create the swapchain with imageSharingMode
// as VK_SHARING_MODE_CONCURRENT
swapchain_ci.imageSharingMode=VK_SHARING_MODE_CONCURRENT;
swapchain_ci.queueFamilyIndexCount=2;
swapchain_ci.pQueueFamilyIndices=queueFamilyIndices;
}
else
{
swapchain_ci.imageSharingMode = VkSharingMode(SharingMode::Exclusive);
}
VkSwapchainKHR swap_chain;
VkResult result;
result=vkCreateSwapchainKHR(dev_attr->device,&swapchain_ci,nullptr,&swap_chain);
if(result!=VK_SUCCESS)
{
//LOG_ERROR(OS_TEXT("vkCreateSwapchainKHR failed, result = ")+OSString(result));
os_err<<"vkCreateSwapchainKHR failed, result="<<result<<std::endl;
return(VK_NULL_HANDLE);
}
#ifdef _DEBUG
if(dev_attr->debug_utils)
dev_attr->debug_utils->SetSwapchainKHR(swap_chain,"SwapChain");
#endif//_DEBUG
return(swap_chain);
}
}//namespace
bool GPUDevice::CreateSwapchainFBO(Swapchain *swapchain)
{
if(vkGetSwapchainImagesKHR(attr->device,swapchain->swap_chain,&(swapchain->color_count),nullptr)!=VK_SUCCESS)
return(false);
AutoDeleteArray<VkImage> sc_images(swapchain->color_count);
if(vkGetSwapchainImagesKHR(attr->device,swapchain->swap_chain,&(swapchain->color_count),sc_images)!=VK_SUCCESS)
return(false);
swapchain->sc_depth =CreateTexture2D(new SwapchainDepthTextureCreateInfo(attr->physical_device->GetDepthFormat(),swapchain->extent));
if(!swapchain->sc_depth)
return(false);
#ifdef _DEBUG
if(attr->debug_utils)
{
attr->debug_utils->SetImage(swapchain->sc_depth->GetImage(),"SwapchainDepthImage");
attr->debug_utils->SetImageView(swapchain->sc_depth->GetVulkanImageView(),"SwapchainDepthImageView");
attr->debug_utils->SetDeviceMemory(swapchain->sc_depth->GetDeviceMemory(),"SwapchainDepthMemory");
}
#endif//_DEBUG
swapchain->sc_color =hgl_zero_new<Texture2D *>(swapchain->color_count);
swapchain->sc_fbo =hgl_zero_new<Framebuffer *>(swapchain->color_count);
for(uint32_t i=0;i<swapchain->color_count;i++)
{
swapchain->sc_color[i]=CreateTexture2D(new SwapchainColorTextureCreateInfo(attr->surface_format.format,swapchain->extent,sc_images[i]));
if(!swapchain->sc_color[i])
return(false);
swapchain->sc_fbo[i]=CreateFBO( device_render_pass,
swapchain->sc_color[i]->GetImageView(),
swapchain->sc_depth->GetImageView());
#ifdef _DEBUG
if(attr->debug_utils)
{
attr->debug_utils->SetImage(swapchain->sc_color[i]->GetImage(),"SwapchainColorImage_"+AnsiString::numberOf(i));
attr->debug_utils->SetImageView(swapchain->sc_color[i]->GetVulkanImageView(),"SwapchainColorImageView_"+AnsiString::numberOf(i));
attr->debug_utils->SetFramebuffer(swapchain->sc_fbo[i]->GetFramebuffer(),"SwapchainFBO_"+AnsiString::numberOf(i));
}
#endif//_DEBUG
}
return(true);
}
Swapchain *GPUDevice::CreateSwapchain(const VkExtent2D &acquire_extent)
{
Swapchain *swapchain=new Swapchain;
swapchain->device =attr->device;
swapchain->extent =acquire_extent;
swapchain->swap_chain =CreateSwapChain(attr,acquire_extent);
if(swapchain->swap_chain)
if(CreateSwapchainFBO(swapchain))
return(swapchain);
delete swapchain;
swapchain=nullptr;
return(nullptr);
}
VK_NAMESPACE_END

View File

@ -14,10 +14,10 @@ Framebuffer::Framebuffer(VkDevice dev,VkFramebuffer fb,const VkExtent2D &ext,VkR
render_pass=rp;
extent=ext;
color_count=cc;
image_count=cc;
has_depth=depth;
attachment_count=color_count;
attachment_count=image_count;
if(has_depth)
++attachment_count;

View File

@ -70,6 +70,10 @@ GPUPhysicalDevice::GPUPhysicalDevice(VkInstance inst,VkPhysicalDevice pd)
if(func)
{
VkPhysicalDeviceFeatures2 features2;
VkPhysicalDeviceBlendOperationAdvancedFeaturesEXT boaf;
hgl_zero(features2);
hgl_zero(boaf);
features2.sType=VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2_KHR;
features2.pNext=&features11;
@ -81,11 +85,16 @@ GPUPhysicalDevice::GPUPhysicalDevice(VkInstance inst,VkPhysicalDevice pd)
features12.pNext=&features13;
features13.sType=VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES;
features13.pNext=nullptr;
features13.pNext=&boaf;
boaf.sType=VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BLEND_OPERATION_ADVANCED_FEATURES_EXT;
boaf.pNext=nullptr;
func(physical_device,&features2);
hgl_cpy(features,features2.features);
blendOpAdvanced=boaf.advancedBlendCoherentOperations;
}
else
{
@ -97,6 +106,7 @@ GPUPhysicalDevice::GPUPhysicalDevice(VkInstance inst,VkPhysicalDevice pd)
hgl_zero(properties11);
hgl_zero(properties12);
hgl_zero(properties13);
hgl_zero(blendOpAdvProperties);
auto func=(PFN_vkGetPhysicalDeviceProperties2KHR)vkGetInstanceProcAddr(inst,"vkGetPhysicalDeviceProperties2KHR");
@ -104,6 +114,8 @@ GPUPhysicalDevice::GPUPhysicalDevice(VkInstance inst,VkPhysicalDevice pd)
{
VkPhysicalDeviceProperties2 properties2;
hgl_zero(properties2);
properties2.sType=VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2_KHR;
properties2.pNext=&properties11;
@ -114,7 +126,10 @@ GPUPhysicalDevice::GPUPhysicalDevice(VkInstance inst,VkPhysicalDevice pd)
properties12.pNext=&properties13;
properties13.sType=VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_PROPERTIES;
properties13.pNext=nullptr;
properties13.pNext=&blendOpAdvProperties;
blendOpAdvProperties.sType=VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BLEND_OPERATION_ADVANCED_PROPERTIES_EXT;
blendOpAdvProperties.pNext=nullptr;
func(physical_device,&properties2);

View File

@ -3,7 +3,7 @@
#include<hgl/graph/VK.h>
#include<hgl/graph/VKDescriptorSetType.h>
#include<hgl/type/Map.h>
#include<hgl/type/SortedSets.h>
#include<hgl/type/SortedSet.h>
VK_NAMESPACE_BEGIN
struct PipelineLayoutData
{

View File

@ -136,90 +136,4 @@ Sampler *RenderResource::CreateSampler(Texture *tex)
return s;
}
Texture2D *CreateTexture2DFromFile(GPUDevice *device,const OSString &filename,bool auto_mipmaps);
Texture2D *RenderResource::LoadTexture2D(const OSString &filename,bool auto_mipmaps)
{
Texture2D *tex;
if(texture_by_name.Get(filename,(Texture *&)tex))
return tex;
tex=CreateTexture2DFromFile(device,filename,auto_mipmaps);
if(tex)
{
texture_by_name.Add(filename,tex);
Add(tex);
#ifdef _DEBUG
DebugUtils *du=device->GetDebugUtils();
if(du)
{
const UTF8String name=U8_TEXT("Tex2D:")+ToUTF8String(filename);
du->SetImage(tex->GetImage(),(char *)(name.c_str()));
}
#endif//_DEBUG
}
return tex;
}
Texture2DArray *RenderResource::CreateTexture2DArray(const AnsiString &name,const uint32_t width,const uint32_t height,const uint32_t layer,const VkFormat &fmt,bool auto_mipmaps)
{
Texture2DArray *ta=device->CreateTexture2DArray(width,height,layer,fmt,auto_mipmaps);
if(ta)
Add(ta);
else
return nullptr;
#ifdef _DEBUG
DebugUtils *du=device->GetDebugUtils();
if(du)
{
du->SetImage(ta->GetImage(),"Tex2DArrayImage:"+name);
du->SetImageView(ta->GetVulkanImageView(),"Tex2DArrayImageView:"+name);
du->SetDeviceMemory(ta->GetDeviceMemory(),"Tex2DArrayMemory:"+name);
}
#endif//_DEBUG
return ta;
}
bool LoadTexture2DLayerFromFile(GPUDevice *device,Texture2DArray *t2d,const uint32_t layer,const OSString &filename,bool auto_mipmaps);
bool RenderResource::LoadTexture2DToArray(Texture2DArray *ta,const uint32_t layer,const OSString &filename)
{
if(!ta)return(false);
if(!LoadTexture2DLayerFromFile(device,ta,layer,filename,false))
return(false);
return(true);
}
TextureCube *CreateTextureCubeFromFile(GPUDevice *device,const OSString &filename,bool auto_mipmaps);
TextureCube *RenderResource::LoadTextureCube(const OSString &filename,bool auto_mipmaps)
{
TextureCube *tex;
if(texture_by_name.Get(filename,(Texture *&)tex))
return tex;
tex=CreateTextureCubeFromFile(device,filename,auto_mipmaps);
if(tex)
{
texture_by_name.Add(filename,tex);
Add(tex);
}
return tex;
}
VK_NAMESPACE_END

View File

@ -29,8 +29,7 @@ RenderTarget::RenderTarget(DeviceQueue *q,Semaphore *s,RenderPass *_rp,Framebuff
color_count=cc;
if(color_count>0)
{
color_textures=new Texture2D *[color_count];
hgl_cpy(color_textures,ctl,color_count);
color_textures=hgl_new_copy(ctl,color_count);
extent.width=color_textures[0]->GetWidth();
extent.height=color_textures[0]->GetHeight();

View File

@ -24,25 +24,29 @@ PrimitiveDataBuffer::~PrimitiveDataBuffer()
delete[] vab_list;
}
const bool PrimitiveDataBuffer::Comp(const PrimitiveDataBuffer *pdb)const
const int PrimitiveDataBuffer::compare(const PrimitiveDataBuffer &pdb)const
{
if(!pdb)return(false);
ptrdiff_t off;
if(vdm&&pdb->vdm)
return (vdm==pdb->vdm);
off=&vdm-&pdb.vdm;
if(off)
return off;
if(vab_count!=pdb->vab_count)return(false);
off=vab_count-pdb.vab_count;
if(off)
return off;
for(uint32_t i=0;i<vab_count;i++)
{
if(vab_list[i]!=pdb->vab_list[i])return(false);
if(vab_offset[i]!=pdb->vab_offset[i])return(false);
}
off=hgl_cmp(vab_list,pdb.vab_list,vab_count);
if(off)
return off;
if(ibo!=pdb->ibo)
return(false);
off=hgl_cmp(vab_offset,pdb.vab_offset,vab_count);
if(off)
return off;
return(true);
off=ibo-pdb.ibo;
return off;
}
Renderable::Renderable(Primitive *r,MaterialInstance *mi,Pipeline *p,PrimitiveDataBuffer *pdb,PrimitiveRenderData *prd)
@ -61,7 +65,7 @@ Renderable *CreateRenderable(Primitive *prim,MaterialInstance *mi,Pipeline *p)
const VIL *vil=mi->GetVIL();
if(vil->Comp(p->GetVIL()))
if(*vil!=*p->GetVIL())
return(nullptr);
const uint32_t input_count=vil->GetVertexAttribCount(VertexInputGroup::Basic); //不统计Bone/LocalToWorld组的

View File

@ -4,9 +4,9 @@
VK_NAMESPACE_BEGIN
Swapchain::~Swapchain()
{
SAFE_CLEAR_OBJECT_ARRAY_OBJECT(sc_fbo,color_count);
SAFE_CLEAR_OBJECT_ARRAY_OBJECT(sc_fbo,image_count);
SAFE_CLEAR(sc_depth);
SAFE_CLEAR_OBJECT_ARRAY_OBJECT(sc_color,color_count)
SAFE_CLEAR_OBJECT_ARRAY_OBJECT(sc_color,image_count)
if(swap_chain)
{
@ -14,6 +14,6 @@ Swapchain::~Swapchain()
swap_chain=VK_NULL_HANDLE;
}
color_count=0;
image_count=0;
}
VK_NAMESPACE_END

View File

@ -27,15 +27,14 @@ RTSwapchain::RTSwapchain(VkDevice dev,Swapchain *sc,DeviceQueue *q,Semaphore *rc
RTSwapchain::~RTSwapchain()
{
delete present_complete_semaphore;
delete swapchain;
}
int RTSwapchain::AcquireNextImage()
uint32_t RTSwapchain::AcquireNextImage()
{
if(vkAcquireNextImageKHR(device,swapchain->swap_chain,UINT64_MAX,*(this->present_complete_semaphore),VK_NULL_HANDLE,&current_frame)==VK_SUCCESS)
return current_frame;
return -1;
return UINT32_MAX;
}
bool RTSwapchain::PresentBackbuffer(VkSemaphore *wait_semaphores,const uint32_t count)
@ -48,12 +47,12 @@ bool RTSwapchain::PresentBackbuffer(VkSemaphore *wait_semaphores,const uint32_t
if (!((result == VK_SUCCESS) || (result == VK_SUBOPTIMAL_KHR)))
{
if (result == VK_ERROR_OUT_OF_DATE_KHR) {
// Swap chain is no longer compatible with the surface and needs to be recreated
return false;
}
}
if (result == VK_ERROR_OUT_OF_DATE_KHR) {
// Swap chain is no longer compatible with the surface and needs to be recreated
return false;
}
}
return(true);
}

View File

@ -1,11 +1,14 @@
#include<hgl/graph/VKTexture.h>
#include<hgl/graph/VKImageView.h>
#include<hgl/graph/VKMemory.h>
#include<hgl/graph/manager/TextureManager.h>
VK_NAMESPACE_BEGIN
Texture::~Texture()
{
if(!data)return;
manager->Release(this);
if(data->image_view)
delete data->image_view;
@ -14,7 +17,7 @@ Texture::~Texture()
delete data->memory;
if(data->image)
vkDestroyImage(device,data->image,nullptr);
vkDestroyImage(manager->GetVkDevice(),data->image,nullptr);
}
}
VK_NAMESPACE_END

View File

@ -1,6 +1,8 @@
#include<hgl/graph/VKDevice.h>
#include<hgl/graph/VKPhysicalDevice.h>
#include<hgl/graph/TileData.h>
#include<hgl/graph/manager/TextureManager.h>
#include<hgl/graph/RenderFramework.h>
namespace
{
@ -61,7 +63,7 @@ namespace
}//namespace
VK_NAMESPACE_BEGIN
TileData *GPUDevice::CreateTileData(const VkFormat format,const uint width,const uint height,const uint count)
TileData *RenderFramework::CreateTileData(const VkFormat format,const uint width,const uint height,const uint count)
{
if(!CheckVulkanFormat(format))
return(nullptr);
@ -69,7 +71,7 @@ TileData *GPUDevice::CreateTileData(const VkFormat format,const uint width,const
if(width<=0||height<=0||count<=0)
return(nullptr);
const uint32_t max_2d_texture=attr->physical_device->GetMaxImage2D();
const uint32_t max_2d_texture=device->GetPhysicalDevice()->GetMaxImage2D();
uint tex_width,tex_height;
@ -84,16 +86,16 @@ TileData *GPUDevice::CreateTileData(const VkFormat format,const uint width,const
if(RangeCheck(vf->color))
{
tex=CreateTexture2D(new ColorTextureCreateInfo(format,extent));
tex=texture_manager->CreateTexture2D(new ColorTextureCreateInfo(format,extent));
}
else
if(RangeCheck(vf->depth))
{
tex=CreateTexture2D(new DepthTextureCreateInfo(format,extent));
tex=texture_manager->CreateTexture2D(new DepthTextureCreateInfo(format,extent));
}
else
return(nullptr);
return(new TileData(this,tex,width,height));
return(new TileData(texture_manager,tex,width,height));
}
VK_NAMESPACE_END

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