Compare commits
73 Commits
devel_36_P
...
devel_39_C
Author | SHA1 | Date | |
---|---|---|---|
d43a877be1 | |||
a4cc34d03b | |||
b77ede95e5 | |||
be3a8a2b00 | |||
b6a92e8cd3 | |||
7306581616 | |||
2e2f306b6b | |||
cf81e7bcff | |||
68089e13bc | |||
eee00f3c8c | |||
52b6e88522 | |||
383a568daa | |||
ce095f97f2 | |||
774f106738 | |||
0706f27354 | |||
62e9d2f904 | |||
d5df06dca3 | |||
9c3e16032e | |||
55765cf112 | |||
c5e9f151fc | |||
2f1ccda442 | |||
f88f6378b7 | |||
b63edb2f89 | |||
21c7f36d03 | |||
54d8726145 | |||
9f0625ed4e | |||
e5a46f3ee8 | |||
7ec1c095cc | |||
3807d9fcbf | |||
0d67993326 | |||
052e2c673a | |||
7c745df910 | |||
a03770fd00 | |||
3c2f7ad705 | |||
93e38fc14f | |||
dd0cf9bf51 | |||
dcefb261ad | |||
d63af2d8de | |||
fda6001451 | |||
f0a582271e | |||
74a5847bbc | |||
2576675265 | |||
ffaa038f99 | |||
768ebde879 | |||
af03f2967c | |||
e24286a87f | |||
99f833ef42 | |||
0735e783e6 | |||
053e579071 | |||
6e12a411b1 | |||
022cc4a2f3 | |||
906aba2459 | |||
b47b096039 | |||
63dac1ef74 | |||
0a072d846b | |||
7326765057 | |||
a569d08269 | |||
6fdf0e1fbd | |||
2e53b48fff | |||
aafdbdd4ea | |||
82a3ec4922 | |||
6141dbf4d5 | |||
c8adc9af24 | |||
79b0b2ef76 | |||
ab36f67412 | |||
487d3c4978 | |||
0a2862a051 | |||
10fbcfef14 | |||
414142283b | |||
96c3718b2a | |||
014d783e73 | |||
ff8222c256 | |||
911afc06f6 |
8
.editorconfig
Normal file
8
.editorconfig
Normal file
@@ -0,0 +1,8 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
|
2
CMCore
2
CMCore
Submodule CMCore updated: 5aad7d8141...b78d31d8a0
Submodule CMPlatform updated: aa7abe4763...67e8e95665
Submodule CMSceneGraph updated: 4949c2e3e8...f74d7045fa
@@ -8,21 +8,22 @@ set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/CMCMakeModule)
|
||||
|
||||
set(ULRE_3RDPTY_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/3rdpty)
|
||||
|
||||
include_directories(${ULRE_3RDPTY_ROOT_PATH}/NvTriStrip)
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/inc)
|
||||
|
||||
SET(ROOT_INCLUDE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/inc)
|
||||
SET(ULRE_RUNTIME_PATH ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
include(math)
|
||||
include(vulkan)
|
||||
include(use_cm_module)
|
||||
|
||||
use_cm_module(Core)
|
||||
use_cm_module(Util)
|
||||
use_cm_module(Platform)
|
||||
use_cm_module(AssetsManage)
|
||||
use_cm_module(SceneGraph)
|
||||
|
||||
SET(ULRE CMCore
|
||||
CMPlatform
|
||||
CMAssetsManage
|
||||
CMSceneGraph
|
||||
CMUtil
|
||||
ULRE.Work
|
||||
ULRE.Util
|
||||
ULRE.ShaderGen
|
||||
ULRE.SceneGraph
|
||||
@@ -30,12 +31,11 @@ SET(ULRE CMCore
|
||||
${RENDER_LIBRARY}
|
||||
${Vulkan_LIBRARIES})
|
||||
|
||||
include_directories(${ULRE_3RDPTY_ROOT_PATH}/NvTriStrip)
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/inc)
|
||||
|
||||
SET(ROOT_INCLUDE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/inc)
|
||||
|
||||
SET(ULRE_RUNTIME_PATH ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
use_cm_module(Core)
|
||||
use_cm_module(Util)
|
||||
use_cm_module(Platform)
|
||||
use_cm_module(AssetsManage)
|
||||
use_cm_module(SceneGraph)
|
||||
|
||||
add_subdirectory(src)
|
||||
|
||||
|
@@ -10,6 +10,7 @@
|
||||
set_property(TARGET ${name} PROPERTY FOLDER "ULRE/Example/Basic")
|
||||
endmacro()
|
||||
|
||||
CreateProject(00_RenderFrameworkTest rf_test.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)
|
||||
|
@@ -1,18 +1,14 @@
|
||||
// 该范例主要演示使用RenderList系统绘制多个三角形,并利用RenderList进行排序以及自动合并进行Instance渲染
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/WorkManager.h>
|
||||
#include<hgl/math/Math.h>
|
||||
#include<hgl/graph/PrimitiveCreater.h>
|
||||
#include<hgl/graph/VKVertexInputConfig.h>
|
||||
#include<hgl/graph/mtl/Material2DCreateConfig.h>
|
||||
#include<hgl/graph/RenderList.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
constexpr uint32_t SCREEN_WIDTH=1024;
|
||||
constexpr uint32_t SCREEN_HEIGHT=1024;
|
||||
|
||||
constexpr uint32_t VERTEX_COUNT=3;
|
||||
|
||||
constexpr uint32_t TRIANGLE_NUMBER=12;
|
||||
@@ -31,12 +27,15 @@ constexpr uint8 color_data[VERTEX_COUNT][4]=
|
||||
{0,0,255,255}
|
||||
};
|
||||
|
||||
class TestApp:public VulkanApplicationFramework
|
||||
class TestApp:public WorkObject
|
||||
{
|
||||
Color4f clear_color =Color4f(0.2f,0.2f,0.2f,1.0f);
|
||||
|
||||
private:
|
||||
|
||||
AutoDelete<RenderList> render_list =nullptr;
|
||||
|
||||
SceneNode render_root;
|
||||
RenderList * render_list =nullptr;
|
||||
|
||||
MaterialInstance * material_instance =nullptr;
|
||||
Renderable * render_obj =nullptr;
|
||||
@@ -48,7 +47,7 @@ private:
|
||||
bool InitMaterial()
|
||||
{
|
||||
{
|
||||
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"VertexColor2D",Prim::Triangles);
|
||||
mtl::Material2DCreateConfig cfg(GetDeviceAttribute(),"VertexColor2D",Prim::Triangles);
|
||||
|
||||
cfg.coordinate_system=CoordinateSystem2D::NDC;
|
||||
cfg.local_to_world=true;
|
||||
@@ -73,14 +72,11 @@ private:
|
||||
|
||||
bool InitVBO()
|
||||
{
|
||||
PrimitiveCreater rpc(device,material_instance->GetVIL());
|
||||
|
||||
rpc.Init("Triangle",VERTEX_COUNT);
|
||||
|
||||
if(!rpc.WriteVAB(VAN::Position, VF_V2F, position_data))return(false);
|
||||
if(!rpc.WriteVAB(VAN::Color, VF_V4UN8, color_data ))return(false);
|
||||
|
||||
render_obj=db->CreateRenderable(&rpc,material_instance,pipeline);
|
||||
render_obj=CreateRenderable("Triangle",VERTEX_COUNT,material_instance,pipeline,
|
||||
{
|
||||
{VAN::Position, VF_V2F, position_data},
|
||||
{VAN::Color, VF_V4UN8, color_data }
|
||||
});
|
||||
|
||||
if(!render_obj)
|
||||
return(false);
|
||||
@@ -90,7 +86,7 @@ private:
|
||||
|
||||
for(uint i=0;i<TRIANGLE_NUMBER;i++)
|
||||
{
|
||||
rad=deg2rad<double>((360/TRIANGLE_NUMBER)*i); //这里一定要加<float>或<float>,否则结果用int保存会出现问题
|
||||
rad=deg2rad<double>((360.0f/double(TRIANGLE_NUMBER))*i); //这里一定要加<float>或<float>,否则结果用int保存会出现问题
|
||||
mat=rotate(rad,Vector3f(0,0,1));
|
||||
|
||||
render_root.Add(new SceneNode(mat,render_obj));
|
||||
@@ -105,38 +101,28 @@ private:
|
||||
|
||||
public:
|
||||
|
||||
~TestApp()
|
||||
TestApp(RenderFramework *rf):WorkObject(rf,rf->GetSwapchainRenderTarget())
|
||||
{
|
||||
SAFE_CLEAR(render_list);
|
||||
}
|
||||
|
||||
bool Init(uint w,uint h)
|
||||
{
|
||||
if(!VulkanApplicationFramework::Init(w,h))
|
||||
return(false);
|
||||
|
||||
render_list=new RenderList(device);
|
||||
render_list=rf->CreateRenderList();
|
||||
|
||||
if(!InitMaterial())
|
||||
return(false);
|
||||
return;
|
||||
|
||||
if(!InitVBO())
|
||||
return(false);
|
||||
|
||||
BuildCommandBuffer(render_list);
|
||||
|
||||
return(true);
|
||||
return;
|
||||
}
|
||||
|
||||
void Resize(uint w,uint h)override
|
||||
void Render(double delta_time,graph::RenderCmdBuffer *cmd)override
|
||||
{
|
||||
VulkanApplicationFramework::Resize(w,h);
|
||||
cmd->SetClearColor(0,clear_color);
|
||||
|
||||
BuildCommandBuffer(render_list);
|
||||
cmd->BeginRenderPass();
|
||||
render_list->Render(cmd);
|
||||
cmd->EndRenderPass();
|
||||
}
|
||||
};//class TestApp:public VulkanApplicationFramework
|
||||
};//class TestApp:public WorkObject
|
||||
|
||||
int main(int,char **)
|
||||
int os_main(int,os_char **)
|
||||
{
|
||||
return RunApp<TestApp>(SCREEN_WIDTH,SCREEN_HEIGHT);
|
||||
return RunFramework<TestApp>(OS_TEXT("AutoInstance"),1024,1024);
|
||||
}
|
||||
|
@@ -1,18 +1,14 @@
|
||||
// 该范例主要演示使用一个材质下的不同材质实例传递颜色参数绘制三角形,并依赖RenderList中的自动合并功能,让同一材质下所有不同材质实例的对象一次渲染完成。
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/WorkManager.h>
|
||||
#include<hgl/math/Math.h>
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/mtl/Material2DCreateConfig.h>
|
||||
#include<hgl/graph/RenderList.h>
|
||||
#include<hgl/color/Color.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
constexpr uint32_t SCREEN_WIDTH=1024;
|
||||
constexpr uint32_t SCREEN_HEIGHT=1024;
|
||||
|
||||
constexpr uint32_t VERTEX_COUNT=3;
|
||||
|
||||
constexpr float position_data[VERTEX_COUNT*2]=
|
||||
@@ -23,15 +19,19 @@ constexpr float position_data[VERTEX_COUNT*2]=
|
||||
};
|
||||
|
||||
constexpr uint DRAW_OBJECT_COUNT=12;
|
||||
constexpr double TRI_ROTATE_ANGLE=360.0f/DRAW_OBJECT_COUNT;
|
||||
|
||||
#define USE_MATERIAL_FILE true //是否使用材质文件
|
||||
|
||||
class TestApp:public VulkanApplicationFramework
|
||||
class TestApp:public WorkObject
|
||||
{
|
||||
Color4f clear_color =Color4f(0.2f,0.2f,0.2f,1.0f);
|
||||
|
||||
private:
|
||||
|
||||
AutoDelete<RenderList> render_list =nullptr;
|
||||
|
||||
SceneNode render_root;
|
||||
RenderList * render_list =nullptr;
|
||||
|
||||
Material * material =nullptr;
|
||||
|
||||
@@ -48,7 +48,7 @@ private:
|
||||
bool InitMaterial()
|
||||
{
|
||||
{
|
||||
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"PureColor2D",Prim::Triangles);
|
||||
mtl::Material2DCreateConfig cfg(GetDeviceAttribute(),"PureColor2D",Prim::Triangles);
|
||||
|
||||
cfg.coordinate_system=CoordinateSystem2D::NDC;
|
||||
cfg.local_to_world=true;
|
||||
@@ -83,15 +83,9 @@ private:
|
||||
|
||||
bool InitVBOAndRenderList()
|
||||
{
|
||||
PrimitiveCreater pc(device,material->GetDefaultVIL());
|
||||
Primitive *prim=CreatePrimitive("Triangle",VERTEX_COUNT,material->GetDefaultVIL(),
|
||||
{{VAN::Position, VF_V2F, position_data}});
|
||||
|
||||
if(!pc.Init("Triangle",VERTEX_COUNT))
|
||||
return(false);
|
||||
|
||||
if(!pc.WriteVAB(VAN::Position, VF_V2F, position_data))
|
||||
return(false);
|
||||
|
||||
Primitive *prim=pc.Create();
|
||||
if(!prim)
|
||||
return(false);
|
||||
|
||||
@@ -106,7 +100,7 @@ private:
|
||||
if(!render_obj[i].r)
|
||||
return(false);
|
||||
|
||||
mat=rotate(deg2rad<double>(double(360/DRAW_OBJECT_COUNT*i)),AxisVector::Z);
|
||||
mat=rotate(deg2rad<double>(TRI_ROTATE_ANGLE*i),AxisVector::Z);
|
||||
|
||||
render_root.Add(new SceneNode(mat,render_obj[i].r));
|
||||
}
|
||||
@@ -120,45 +114,28 @@ private:
|
||||
|
||||
public:
|
||||
|
||||
~TestApp()
|
||||
TestApp(RenderFramework *rf):WorkObject(rf,rf->GetSwapchainRenderTarget())
|
||||
{
|
||||
SAFE_CLEAR(render_list);
|
||||
}
|
||||
|
||||
bool Init()
|
||||
{
|
||||
if(!VulkanApplicationFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
|
||||
return(false);
|
||||
|
||||
render_list=new RenderList(device);
|
||||
render_list=rf->CreateRenderList();
|
||||
|
||||
if(!InitMaterial())
|
||||
return(false);
|
||||
return;
|
||||
|
||||
if(!InitVBOAndRenderList())
|
||||
return(false);
|
||||
|
||||
BuildCommandBuffer(render_list);
|
||||
|
||||
return(true);
|
||||
return;
|
||||
}
|
||||
|
||||
void Resize(uint w,uint h)override
|
||||
void Render(double delta_time,graph::RenderCmdBuffer *cmd)override
|
||||
{
|
||||
VulkanApplicationFramework::Resize(w,h);
|
||||
cmd->SetClearColor(0,clear_color);
|
||||
|
||||
BuildCommandBuffer(render_list);
|
||||
cmd->BeginRenderPass();
|
||||
render_list->Render(cmd);
|
||||
cmd->EndRenderPass();
|
||||
}
|
||||
};//class TestApp:public VulkanApplicationFramework
|
||||
|
||||
int main(int,char **)
|
||||
int os_main(int,os_char **)
|
||||
{
|
||||
TestApp app;
|
||||
|
||||
if(!app.Init())
|
||||
return(-1);
|
||||
|
||||
while(app.Run());
|
||||
|
||||
return 0;
|
||||
return RunFramework<TestApp>(OS_TEXT("AutoInstance"),1024,1024);
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
// 该范例主要演示使用NDC坐标系直接绘制一个渐变色的三角形
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/WorkManager.h>
|
||||
#include<hgl/math/HalfFloat.h>
|
||||
#include<hgl/graph/VKVertexInputConfig.h>
|
||||
#include<hgl/graph/PrimitiveCreater.h>
|
||||
@@ -39,7 +39,8 @@ constexpr VkFormat PositionFormat=VF_V2F;
|
||||
|
||||
#ifdef USE_UNORM8_COLOR
|
||||
constexpr uint8 color_data[VERTEX_COUNT*4]=
|
||||
{ 255,0,0,255,
|
||||
{
|
||||
255,0,0,255,
|
||||
0,255,0,255,
|
||||
0,0,255,255
|
||||
};
|
||||
@@ -47,7 +48,8 @@ constexpr uint8 color_data[VERTEX_COUNT*4]=
|
||||
constexpr VkFormat ColorFormat=VF_V4UN8;
|
||||
#else
|
||||
constexpr float color_data[VERTEX_COUNT*4]=
|
||||
{ 1,0,0,1,
|
||||
{
|
||||
1,0,0,1,
|
||||
0,1,0,1,
|
||||
0,0,1,1
|
||||
};
|
||||
@@ -55,10 +57,12 @@ constexpr float color_data[VERTEX_COUNT*4]=
|
||||
constexpr VkFormat ColorFormat=VF_V4F;
|
||||
#endif//USE_UNORM8_COLOR
|
||||
|
||||
class TestApp:public VulkanApplicationFramework
|
||||
class TestApp:public WorkObject
|
||||
{
|
||||
private:
|
||||
|
||||
Color4f clear_color=Color4f(0.2f,0.2f,0.2f,1.0f);
|
||||
|
||||
#if defined(USE_HALF_FLOAT_POSITION)||defined(USE_UNORM8_COLOR)
|
||||
VILConfig vil_config;
|
||||
#endif
|
||||
@@ -83,7 +87,7 @@ private:
|
||||
|
||||
bool InitAutoMaterial()
|
||||
{
|
||||
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"VertexColor2d",Prim::Triangles);
|
||||
mtl::Material2DCreateConfig cfg(GetDeviceAttribute(),"VertexColor2d",Prim::Triangles);
|
||||
|
||||
cfg.coordinate_system=CoordinateSystem2D::NDC;
|
||||
cfg.local_to_world=false;
|
||||
@@ -105,54 +109,47 @@ private:
|
||||
|
||||
bool InitVBO()
|
||||
{
|
||||
PrimitiveCreater rpc(device,material_instance->GetVIL());
|
||||
|
||||
rpc.Init("Triangle",VERTEX_COUNT);
|
||||
|
||||
#ifdef USE_HALF_FLOAT_POSITION
|
||||
Float32toFloat16(position_data_hf,position_data_float,VERTEX_COUNT*2);
|
||||
#endif//USE_HALF_FLOAT_POSITION
|
||||
|
||||
if(!rpc.WriteVAB(VAN::Position, PositionFormat, position_data))return(false);
|
||||
if(!rpc.WriteVAB(VAN::Color, ColorFormat, color_data ))return(false);
|
||||
|
||||
render_obj=db->CreateRenderable(&rpc,material_instance,pipeline);
|
||||
render_obj=CreateRenderable("Triangle",VERTEX_COUNT,material_instance,pipeline,
|
||||
{
|
||||
{VAN::Position,PositionFormat,position_data},
|
||||
{VAN::Color, ColorFormat, color_data}
|
||||
});
|
||||
return(render_obj);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
bool Init(uint w,uint h)
|
||||
|
||||
TestApp(RenderFramework *rf):WorkObject(rf,rf->GetSwapchainRenderTarget())
|
||||
{
|
||||
if(!VulkanApplicationFramework::Init(w,h))
|
||||
return(false);
|
||||
|
||||
InitVIL();
|
||||
|
||||
if(!InitAutoMaterial())
|
||||
return(false);
|
||||
return;
|
||||
|
||||
if(!InitPipeline())
|
||||
return(false);
|
||||
return;
|
||||
|
||||
if(!InitVBO())
|
||||
return(false);
|
||||
|
||||
if(!BuildCommandBuffer(render_obj))
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
return;
|
||||
}
|
||||
|
||||
void Resize(uint w,uint h)override
|
||||
void Tick(double)override{}
|
||||
|
||||
void Render(double delta_time,graph::RenderCmdBuffer *cmd)
|
||||
{
|
||||
VulkanApplicationFramework::Resize(w,h);
|
||||
cmd->SetClearColor(0,clear_color);
|
||||
|
||||
BuildCommandBuffer(render_obj);
|
||||
cmd->BeginRenderPass();
|
||||
cmd->Render(render_obj);
|
||||
cmd->EndRenderPass();
|
||||
}
|
||||
};//class TestApp:public VulkanApplicationFramework
|
||||
};//class TestApp:public WorkObject
|
||||
|
||||
int main(int,char **)
|
||||
int os_main(int,os_char **)
|
||||
{
|
||||
return RunApp<TestApp>(SCREEN_WIDTH,SCREEN_HEIGHT);
|
||||
return RunFramework<TestApp>(OS_TEXT("Draw triangle in NDC space"));
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
// 该范例主要演示使用2D坐系统直接绘制一个渐变色的三角形,使用UBO传递Viewport信息
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/WorkManager.h>
|
||||
#include<hgl/graph/VKVertexInputConfig.h>
|
||||
#include<hgl/graph/PrimitiveCreater.h>
|
||||
#include<hgl/graph/mtl/Material2DCreateConfig.h>
|
||||
@@ -17,7 +17,7 @@ static float position_data_float[VERTEX_COUNT][2]=
|
||||
{0.25, 0.75}
|
||||
};
|
||||
|
||||
static uint16 position_data_u16[VERTEX_COUNT][2]={};
|
||||
static int16 position_data[VERTEX_COUNT][2]={};
|
||||
|
||||
constexpr uint8 color_data[VERTEX_COUNT*4]=
|
||||
{
|
||||
@@ -26,12 +26,17 @@ constexpr uint8 color_data[VERTEX_COUNT*4]=
|
||||
0,0,255,255
|
||||
};
|
||||
|
||||
//#define USE_ZERO2ONE_COORD //使用左上角0,0右下角1,1的坐标系
|
||||
constexpr VAType POSITION_SHADER_FORMAT =VAT_IVEC2;
|
||||
constexpr VkFormat POSITION_DATA_FORMAT =VF_V2I16;
|
||||
|
||||
class TestApp:public VulkanApplicationFramework
|
||||
constexpr VkFormat COLOR_DATA_FORMAT =VF_V4UN8;
|
||||
|
||||
class TestApp:public WorkObject
|
||||
{
|
||||
private:
|
||||
|
||||
Color4f clear_color =Color4f(0.2f,0.2f,0.2f,1.0f);
|
||||
|
||||
MaterialInstance * material_instance =nullptr;
|
||||
Renderable * render_obj =nullptr;
|
||||
|
||||
@@ -41,23 +46,19 @@ private:
|
||||
|
||||
bool InitMaterial()
|
||||
{
|
||||
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"VertexColor2D",Prim::Triangles);
|
||||
mtl::Material2DCreateConfig cfg(GetDeviceAttribute(),"VertexColor2D",Prim::Triangles);
|
||||
|
||||
VILConfig vil_config;
|
||||
|
||||
#ifdef USE_ZERO2ONE_COORD
|
||||
cfg.coordinate_system=CoordinateSystem2D::ZeroToOne;
|
||||
#else
|
||||
cfg.coordinate_system=CoordinateSystem2D::Ortho;
|
||||
cfg.coordinate_system =CoordinateSystem2D::Ortho;
|
||||
|
||||
cfg.position_format =VAT_UVEC2; //这里指定shader中使用uvec2当做顶点输入格式
|
||||
cfg.position_format = POSITION_SHADER_FORMAT; //这里指定shader中使用ivec2当做顶点输入格式
|
||||
// ^
|
||||
// + 这上下两种格式要配套,否则会出错
|
||||
// v
|
||||
vil_config.Add(VAN::Position,VF_V2U16); //这里指定VAB中使用RG16U当做顶点数据格式
|
||||
#endif//USE_ZERO2ONE_COORD
|
||||
vil_config.Add(VAN::Position, POSITION_DATA_FORMAT); //这里指定VAB中使用RG16I当做顶点数据格式
|
||||
|
||||
vil_config.Add(VAN::Color,VF_V4UN8); //这里指定VAB中使用RGBA8UNorm当做颜色数据格式
|
||||
vil_config.Add(VAN::Color, COLOR_DATA_FORMAT); //这里指定VAB中使用RGBA8UNorm当做颜色数据格式
|
||||
|
||||
cfg.local_to_world=false;
|
||||
|
||||
@@ -76,58 +77,44 @@ private:
|
||||
|
||||
bool InitVBO()
|
||||
{
|
||||
PrimitiveCreater rpc(device,material_instance->GetVIL());
|
||||
const auto ext=GetExtent2D();
|
||||
|
||||
rpc.Init("Triangle",VERTEX_COUNT);
|
||||
for(uint i=0;i<VERTEX_COUNT;i++)
|
||||
{
|
||||
position_data[i][0]=position_data_float[i][0]*ext.width;
|
||||
position_data[i][1]=position_data_float[i][1]*ext.height;
|
||||
}
|
||||
|
||||
#ifdef USE_ZERO2ONE_COORD //使用0 to 1坐标系
|
||||
if(!rpc.WriteVAB(VAN::Position, VF_V2F, position_data_float ))return(false);
|
||||
#else //使用ortho坐标系
|
||||
if(!rpc.WriteVAB(VAN::Position, VF_V2U16, position_data_u16 ))return(false);
|
||||
#endif//USE_ZERO2ONE_COORD
|
||||
|
||||
if(!rpc.WriteVAB(VAN::Color, VF_V4UN8, color_data ))return(false);
|
||||
|
||||
render_obj=db->CreateRenderable(&rpc,material_instance,pipeline);
|
||||
return(true);
|
||||
render_obj=CreateRenderable("Triangle",VERTEX_COUNT,material_instance,pipeline,
|
||||
{
|
||||
{VAN::Position,POSITION_DATA_FORMAT,position_data},
|
||||
{VAN::Color, COLOR_DATA_FORMAT, color_data}
|
||||
});
|
||||
return(render_obj);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
bool Init(uint w,uint h)
|
||||
|
||||
TestApp(RenderFramework *rf):WorkObject(rf,rf->GetSwapchainRenderTarget())
|
||||
{
|
||||
if(!VulkanApplicationFramework::Init(w,h))
|
||||
return(false);
|
||||
|
||||
#ifndef USE_ZERO2ONE_COORD
|
||||
for(uint i=0;i<VERTEX_COUNT;i++)
|
||||
{
|
||||
position_data_u16[i][0]=position_data_float[i][0]*w;
|
||||
position_data_u16[i][1]=position_data_float[i][1]*h;
|
||||
}
|
||||
#endif//
|
||||
|
||||
if(!InitMaterial())
|
||||
return(false);
|
||||
return;
|
||||
|
||||
if(!InitVBO())
|
||||
return(false);
|
||||
|
||||
if(!BuildCommandBuffer(render_obj))
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
return;
|
||||
}
|
||||
|
||||
void Resize(uint w,uint h)override
|
||||
void Render(double delta_time,graph::RenderCmdBuffer *cmd)override
|
||||
{
|
||||
VulkanApplicationFramework::Resize(w,h);
|
||||
cmd->SetClearColor(0,clear_color);
|
||||
|
||||
BuildCommandBuffer(render_obj);
|
||||
cmd->BeginRenderPass();
|
||||
cmd->Render(render_obj);
|
||||
cmd->EndRenderPass();
|
||||
}
|
||||
};//class TestApp:public VulkanApplicationFramework
|
||||
};//class TestApp:public WorkObject
|
||||
|
||||
int main(int,char **)
|
||||
int os_main(int,os_char **)
|
||||
{
|
||||
return RunApp<TestApp>(1280,720);
|
||||
return RunFramework<TestApp>(OS_TEXT("Draw triangle use UBO"));
|
||||
}
|
||||
|
103
example/Basic/rf_test.cpp
Normal file
103
example/Basic/rf_test.cpp
Normal file
@@ -0,0 +1,103 @@
|
||||
#include<hgl/WorkManager.h>
|
||||
#include<hgl/graph/VKVertexInputConfig.h>
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
#include<hgl/graph/mtl/Material2DCreateConfig.h>
|
||||
#include<hgl/graph/VKMaterialInstance.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
constexpr uint32_t SCREEN_WIDTH=1280;
|
||||
constexpr uint32_t SCREEN_HEIGHT=720;
|
||||
|
||||
constexpr uint32_t VERTEX_COUNT=3;
|
||||
|
||||
constexpr float position_data[VERTEX_COUNT*2]=
|
||||
{
|
||||
0.0, -0.5,
|
||||
-0.5, 0.5,
|
||||
0.5, 0.5
|
||||
};
|
||||
|
||||
constexpr float color_data[VERTEX_COUNT*4]=
|
||||
{
|
||||
1,0,0,1,
|
||||
0,1,0,1,
|
||||
0,0,1,1
|
||||
};
|
||||
|
||||
class TestApp:public WorkObject
|
||||
{
|
||||
private:
|
||||
|
||||
Color4f clear_color =Color4f(0.2f,0.2f,0.2f,1.0f);
|
||||
|
||||
MaterialInstance * material_instance =nullptr;
|
||||
Renderable * render_obj =nullptr;
|
||||
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
private:
|
||||
|
||||
bool InitAutoMaterial()
|
||||
{
|
||||
mtl::Material2DCreateConfig cfg(GetDeviceAttribute(),"VertexColor2D",Prim::Triangles);
|
||||
|
||||
cfg.coordinate_system=CoordinateSystem2D::NDC;
|
||||
cfg.local_to_world=false;
|
||||
|
||||
AutoDelete<mtl::MaterialCreateInfo> mci=mtl::CreateVertexColor2D(&cfg);
|
||||
|
||||
material_instance=CreateMaterialInstance(mci);
|
||||
|
||||
return material_instance;
|
||||
}
|
||||
|
||||
bool InitPipeline()
|
||||
{
|
||||
// pipeline=db->CreatePipeline(material_instance,sc_render_target,OS_TEXT("res/pipeline/solid2d"));
|
||||
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D,Prim::Triangles); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
bool InitVBO()
|
||||
{
|
||||
render_obj=CreateRenderable("Triangle",VERTEX_COUNT,material_instance,pipeline,
|
||||
{
|
||||
{VAN::Position,VF_V2F,position_data},
|
||||
{VAN::Color, VF_V4F,color_data}
|
||||
});
|
||||
return(render_obj);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
TestApp(RenderFramework *rf):WorkObject(rf,rf->GetSwapchainRenderTarget())
|
||||
{
|
||||
if(!InitAutoMaterial())
|
||||
return;
|
||||
|
||||
if(!InitPipeline())
|
||||
return;
|
||||
|
||||
if(!InitVBO())
|
||||
return;
|
||||
}
|
||||
|
||||
void Tick(double)override{}
|
||||
|
||||
void Render(double delta_time,graph::RenderCmdBuffer *cmd)
|
||||
{
|
||||
cmd->SetClearColor(0,clear_color);
|
||||
|
||||
cmd->BeginRenderPass();
|
||||
cmd->Render(render_obj);
|
||||
cmd->EndRenderPass();
|
||||
}
|
||||
};//class TestApp:public WorkObject
|
||||
|
||||
int os_main(int,os_char **)
|
||||
{
|
||||
return RunFramework<TestApp>(OS_TEXT("RenderFramework Test"));
|
||||
}
|
@@ -1,6 +1,6 @@
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/common)
|
||||
|
||||
SET(VULKAN_APP_FRAMEWORK ${CMAKE_CURRENT_SOURCE_DIR}/common/VulkanAppFramework.h)
|
||||
SET(VULKAN_APP_FRAMEWORK ${CMAKE_CURRENT_SOURCE_DIR}/common/VulkanAppFramework.h)
|
||||
|
||||
add_subdirectory(Basic)
|
||||
add_subdirectory(Texture)
|
||||
|
@@ -55,7 +55,7 @@ protected:
|
||||
|
||||
GPUDevice * device =nullptr;
|
||||
RenderPass * device_render_pass =nullptr;
|
||||
RTSwapchain * sc_render_target =nullptr;
|
||||
SwapchainRenderTarget * sc_render_target =nullptr;
|
||||
|
||||
protected:
|
||||
|
||||
@@ -220,12 +220,12 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
bool BuildCommandBuffer(RenderCmdBuffer *cb,RenderPass *rp,Framebuffer *fb,Renderable *ri)
|
||||
bool BuildCommandBuffer(RenderCmdBuffer *cb,Framebuffer *fbo,Renderable *ri)
|
||||
{
|
||||
if(!ri)return(false);
|
||||
|
||||
cb->Begin();
|
||||
cb->BindFramebuffer(rp,fb);
|
||||
cb->BindFramebuffer(fbo);
|
||||
cb->SetClearColor(0,clear_color);
|
||||
cb->BeginRenderPass();
|
||||
cb->BindPipeline(ri->GetPipeline());
|
||||
@@ -238,19 +238,12 @@ public:
|
||||
return(true);
|
||||
}
|
||||
|
||||
void BuildCommandBuffer(RenderCmdBuffer *cb,RenderTarget *rt,Renderable *ri)
|
||||
{
|
||||
if(!cb||!rt||!ri)
|
||||
return;
|
||||
|
||||
BuildCommandBuffer(cb,rt->GetRenderPass(),rt->GetFramebuffer(),ri);
|
||||
}
|
||||
|
||||
bool BuildCommandBuffer(uint32_t index,Renderable *ri)
|
||||
{
|
||||
if(!ri)return(false);
|
||||
|
||||
return BuildCommandBuffer(cmd_buf[index],sc_render_target->GetRenderPass(),sc_render_target->GetFramebuffer(index),ri);
|
||||
return BuildCommandBuffer(cmd_buf[index],
|
||||
sc_render_target->GetFramebuffer(),ri);
|
||||
}
|
||||
|
||||
bool BuildCommandBuffer(Renderable *ri)
|
||||
@@ -277,7 +270,7 @@ public:
|
||||
RenderCmdBuffer *cb=cmd_buf[index];
|
||||
|
||||
cb->Begin();
|
||||
cb->BindFramebuffer(sc_render_target->GetRenderPass(),sc_render_target->GetFramebuffer(index));
|
||||
cb->BindFramebuffer(sc_render_target->GetFramebuffer(index));
|
||||
cb->SetClearColor(0,clear_color);
|
||||
cb->BeginRenderPass();
|
||||
rl->Render(cb);
|
||||
@@ -624,4 +617,4 @@ template<typename T> int RunApp(uint w,uint h)
|
||||
while(app.Run());
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
87
inc/hgl/WorkManager.h
Normal file
87
inc/hgl/WorkManager.h
Normal file
@@ -0,0 +1,87 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/WorkObject.h>
|
||||
#include<hgl/graph/VKRenderTargetSwapchain.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
/**
|
||||
* 工作管理器,管理一个序列的WorkObject<br>
|
||||
*/
|
||||
class WorkManager
|
||||
{
|
||||
protected:
|
||||
|
||||
graph::RenderFramework *render_framework;
|
||||
|
||||
uint fps=60;
|
||||
double frame_time=1.0f/double(fps);
|
||||
|
||||
double last_update_time=0;
|
||||
double last_render_time=0;
|
||||
double cur_time=0;
|
||||
|
||||
WorkObject *cur_work_object=nullptr;
|
||||
|
||||
public:
|
||||
|
||||
WorkManager(graph::RenderFramework *rf)
|
||||
{
|
||||
render_framework=rf;
|
||||
}
|
||||
|
||||
virtual ~WorkManager()
|
||||
{
|
||||
SAFE_CLEAR(cur_work_object);
|
||||
}
|
||||
|
||||
void SetFPS(uint f)
|
||||
{
|
||||
fps=f;
|
||||
frame_time=1.0f/double(fps);
|
||||
}
|
||||
|
||||
void Tick(WorkObject *wo);
|
||||
|
||||
virtual void Render(WorkObject *wo);
|
||||
|
||||
void Run(WorkObject *wo);
|
||||
};//class WorkManager
|
||||
|
||||
class SwapchainWorkManager:public WorkManager,public io::WindowEvent
|
||||
{
|
||||
graph::SwapchainModule *swapchain_module;
|
||||
|
||||
public:
|
||||
|
||||
SwapchainWorkManager(graph::RenderFramework *rf):WorkManager(rf)
|
||||
{
|
||||
swapchain_module=rf->GetSwapchainModule();
|
||||
|
||||
render_framework->Join(this);
|
||||
}
|
||||
|
||||
~SwapchainWorkManager()
|
||||
{
|
||||
render_framework->Unjoin(this);
|
||||
}
|
||||
|
||||
void Render(WorkObject *wo) override;
|
||||
|
||||
void OnResize(uint w,uint h) override;
|
||||
};
|
||||
|
||||
template<typename WO> int RunFramework(const OSString &title,uint width=1280,uint height=720)
|
||||
{
|
||||
graph::RenderFramework rf(title);
|
||||
|
||||
if(!rf.Init(width,height))
|
||||
return(-1);
|
||||
|
||||
SwapchainWorkManager wm(&rf);
|
||||
|
||||
wm.Run(new WO(&rf));
|
||||
|
||||
return 0;
|
||||
}
|
||||
}//namespcae hgl
|
101
inc/hgl/WorkObject.h
Normal file
101
inc/hgl/WorkObject.h
Normal file
@@ -0,0 +1,101 @@
|
||||
#pragma once
|
||||
#include<hgl/type/object/TickObject.h>
|
||||
#include<hgl/graph/RenderFramework.h>
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
#include<hgl/Time.h>
|
||||
//#include<iostream>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph::mtl
|
||||
{
|
||||
class MaterialCreateInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 工作对象</p>
|
||||
*
|
||||
* WorkObject被定义为工作对象,所有的渲染控制都需要被写在WorkObject的Render函数下。
|
||||
*/
|
||||
class WorkObject:public TickObject
|
||||
{
|
||||
graph::RenderFramework *render_framework=nullptr;
|
||||
graph::IRenderTarget *cur_render_target=nullptr;
|
||||
graph::RenderPass *render_pass=nullptr;
|
||||
|
||||
bool destroy_flag=false;
|
||||
|
||||
bool renderable=true;
|
||||
bool render_dirty=true;
|
||||
|
||||
protected:
|
||||
|
||||
graph::RenderResource *db=nullptr; //暂时的,未来会被更好的机制替代
|
||||
|
||||
public:
|
||||
|
||||
graph::RenderFramework * GetRenderFramework (){return render_framework;}
|
||||
graph::GPUDevice * GetDevice (){return render_framework->GetDevice();}
|
||||
graph::GPUDeviceAttribute * GetDeviceAttribute (){return render_framework->GetDeviceAttribute();}
|
||||
|
||||
const VkExtent2D & GetExtent2D (){return cur_render_target->GetExtent();}
|
||||
|
||||
public:
|
||||
|
||||
const bool IsDestroy()const{return destroy_flag;}
|
||||
const bool IsRenderable()const{return renderable;}
|
||||
const bool IsRenderDirty()const{return render_dirty;}
|
||||
|
||||
void MarkDestory(){destroy_flag=true;}
|
||||
void SetRenderable(bool r){renderable=r;}
|
||||
void MarkRenderDirty(){render_dirty=true;}
|
||||
|
||||
public:
|
||||
|
||||
WorkObject(graph::RenderFramework *,graph::IRenderTarget *);
|
||||
virtual ~WorkObject()=default;
|
||||
|
||||
virtual void OnRenderTargetSwitch(graph::RenderFramework *rf,graph::IRenderTarget *rt);
|
||||
|
||||
virtual void OnResize(const VkExtent2D &){}
|
||||
|
||||
virtual void Tick(double){}
|
||||
|
||||
virtual void Render(double delta_time,graph::RenderCmdBuffer *cmd)=0;
|
||||
|
||||
virtual void Render(double delta_time);
|
||||
|
||||
public:
|
||||
|
||||
template<typename ...ARGS>
|
||||
graph::Pipeline *CreatePipeline(ARGS...args)
|
||||
{
|
||||
return render_pass->CreatePipeline(args...);
|
||||
}
|
||||
|
||||
graph::MaterialInstance *CreateMaterialInstance(const graph::mtl::MaterialCreateInfo *mci,const graph::VILConfig *vil_cfg=nullptr)
|
||||
{
|
||||
return db->CreateMaterialInstance(mci,vil_cfg);
|
||||
}
|
||||
|
||||
graph::Primitive *CreatePrimitive( const AnsiString &name,
|
||||
const uint32_t vertices_count,
|
||||
const graph::VIL *vil,
|
||||
const std::initializer_list<graph::VertexAttribDataPtr> &vad_list);
|
||||
|
||||
graph::Renderable *CreateRenderable(const AnsiString &name,
|
||||
const uint32_t vertices_count,
|
||||
graph::MaterialInstance *mi,
|
||||
graph::Pipeline *pipeline,
|
||||
const std::initializer_list<graph::VertexAttribDataPtr> &vad_list);
|
||||
};//class WorkObject
|
||||
|
||||
/**
|
||||
* 但我们认为游戏开发者不应该关注如何控制渲染,而应该关注如何处理游戏逻辑.
|
||||
* 所以我们在WorkObject的基础上再提供RenderWorkObject派生类,用于直接封装好的渲染场景树控制。
|
||||
*
|
||||
* 开发者仅需要将要渲染的物件放置于场景树即可。
|
||||
|
||||
* 但开发者也可以直接使用WorkObject,自行管理这些事。
|
||||
* */
|
||||
}//namespcae hgl
|
45
inc/hgl/graph/LightCullMode.h
Normal file
45
inc/hgl/graph/LightCullMode.h
Normal 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坐标划分成多个Tile,再配合znear/zfar形成一个Volume。所有光源和Volume计算相交性
|
||||
*/
|
||||
Tile, ///<瓦片剔除
|
||||
|
||||
/**
|
||||
* 基于Tile的剔除模式的改进型
|
||||
* 同Tile方法,得出Tile后,再通过遍历Tile内所有象素,得出当前Tile的最远z值和最近z值。
|
||||
* 根据XY与zNear/zFar得出一个Volume,计算所有光源与Volume相交性。
|
||||
*/
|
||||
TileVolume, ///<瓦片体积剔除
|
||||
|
||||
/**
|
||||
* 基于Tile的剔除模式的改进型
|
||||
* 同TileVolume方法得出Volume后,再将Volume按深度划分成多个Volume。
|
||||
* 剔除掉没有象素的Volume,再将剩下的Volume与光源计算相交性。
|
||||
*/
|
||||
Cluster, ///<集簇剔除
|
||||
|
||||
ENUM_CLASS_RANGE(None,Cluster)
|
||||
};//enum class LightingCullingMode
|
||||
|
||||
VK_NAMESPACE_END
|
87
inc/hgl/graph/RenderFramework.h
Normal file
87
inc/hgl/graph/RenderFramework.h
Normal file
@@ -0,0 +1,87 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/platform/Window.h>
|
||||
#include<hgl/graph/VKDevice.h>
|
||||
#include<hgl/graph/VKCommandBuffer.h>
|
||||
#include<hgl/graph/module/SwapchainModule.h>
|
||||
#include<hgl/graph/module/GraphModuleManager.h>
|
||||
#include<hgl/graph/RenderList.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
class FontSource;
|
||||
class TileFont;
|
||||
class RenderPassManager;
|
||||
class TextureManager;
|
||||
class RenderTargetManager;
|
||||
|
||||
class RenderModule;
|
||||
|
||||
class RenderFramework:public io::WindowEvent
|
||||
{
|
||||
OSString app_name;
|
||||
|
||||
Window * win =nullptr;
|
||||
VulkanInstance * inst =nullptr;
|
||||
|
||||
GPUDevice * device =nullptr;
|
||||
|
||||
RenderResource * render_resource =nullptr;
|
||||
|
||||
protected:
|
||||
|
||||
GraphModuleManager * module_manager =nullptr;
|
||||
|
||||
RenderPassManager * rp_manager =nullptr;
|
||||
|
||||
TextureManager * tex_manager =nullptr;
|
||||
RenderTargetManager * rt_manager =nullptr;
|
||||
|
||||
SwapchainModule * sc_module =nullptr;
|
||||
|
||||
public:
|
||||
|
||||
Window * GetWindow ()const{return win;}
|
||||
GPUDevice * GetDevice ()const{return device;}
|
||||
VkDevice GetVkDevice ()const{return device->GetDevice();}
|
||||
const GPUPhysicalDevice * GetPhysicalDevice ()const{return device->GetPhysicalDevice();}
|
||||
GPUDeviceAttribute * GetDeviceAttribute ()const{return device->GetDeviceAttribute();}
|
||||
|
||||
RenderResource * GetRenderResource ()const{return render_resource;}
|
||||
|
||||
public:
|
||||
|
||||
GraphModuleManager * GetModuleManager (){return module_manager;}
|
||||
|
||||
RenderPassManager * GetRenderPassManager (){return rp_manager;}
|
||||
TextureManager * GetTextureManager (){return tex_manager;}
|
||||
RenderTargetManager * GetRenderTargetManager (){return rt_manager;}
|
||||
|
||||
SwapchainModule * GetSwapchainModule (){return sc_module;}
|
||||
SwapchainRenderTarget * GetSwapchainRenderTarget(){return sc_module?sc_module->GetRenderTarget():nullptr;}
|
||||
|
||||
public:
|
||||
|
||||
RenderFramework(const OSString &);
|
||||
virtual ~RenderFramework();
|
||||
|
||||
virtual bool Init(uint w,uint h);
|
||||
|
||||
public:
|
||||
|
||||
RenderList *CreateRenderList()
|
||||
{
|
||||
return(new RenderList(device));
|
||||
}
|
||||
|
||||
TileFont *CreateTileFont(FontSource *fs,int limit_count=-1); ///<创建只使用一种字符的Tile字符管理对象
|
||||
|
||||
public: // event
|
||||
|
||||
virtual void OnResize(uint w,uint h);
|
||||
virtual void OnActive(bool);
|
||||
virtual void OnClose();
|
||||
|
||||
};//class RenderFramework
|
||||
|
||||
VK_NAMESPACE_END
|
@@ -1,10 +1,10 @@
|
||||
#ifndef HGL_GRAPH_SCENE_NODE_INCLUDE
|
||||
#define HGL_GRAPH_SCENE_NODE_INCLUDE
|
||||
#pragma once
|
||||
|
||||
#include<hgl/type/ObjectList.h>
|
||||
#include<hgl/type/IDName.h>
|
||||
#include<hgl/graph/SceneOrient.h>
|
||||
#include<hgl/graph/AABB.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
@@ -111,4 +111,3 @@ namespace hgl
|
||||
SceneNode *Duplication(SceneNode *); ///<复制一个场景节点
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
#endif//HGL_GRAPH_SCENE_NODE_INCLUDE
|
||||
|
@@ -1,5 +1,4 @@
|
||||
#ifndef HGL_GRAPH_SCENE_ORIENT_INCLUDE
|
||||
#define HGL_GRAPH_SCENE_ORIENT_INCLUDE
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/graph/SceneMatrix.h>
|
||||
@@ -51,4 +50,3 @@ namespace hgl
|
||||
};//class SceneOrient
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
#endif//HGL_GRAPH_SCENE_ORIENT_INCLUDE
|
||||
|
@@ -9,23 +9,18 @@ namespace hgl
|
||||
* 场景管理器<Br>
|
||||
* 管理一个场景中的所有资源与场景节点
|
||||
*/
|
||||
class SceneManager
|
||||
class SceneWorld
|
||||
{
|
||||
SceneNode *root_node;
|
||||
|
||||
|
||||
|
||||
public:
|
||||
|
||||
SceneNode *GetSceneRoot() {return root_node;}
|
||||
const SceneNode *GetSceneRoot()const{return root_node;}
|
||||
|
||||
const uint GetNodeCount()const { return node_list.GetCount(); }
|
||||
|
||||
|
||||
public:
|
||||
|
||||
|
||||
|
||||
};//class SceneManager
|
||||
};//class SceneWorld
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
@@ -12,13 +12,15 @@ namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
class TextureManager;
|
||||
|
||||
/**
|
||||
* TileData是一种处理大量等同尺寸及格式贴图的管理机制,程序会自动根据显卡最大贴图处理能力来创建尽可能符合需求的贴图。(注:Tile的大小不必符合2次幂)
|
||||
* Tile的增加或删除,程序会自动排序,尽可能小的减少I/O消耗。
|
||||
*/
|
||||
class TileData ///Tile纹理管理
|
||||
{
|
||||
GPUDevice *device;
|
||||
TextureManager *tex_manager;
|
||||
|
||||
protected:
|
||||
|
||||
@@ -51,8 +53,8 @@ namespace hgl
|
||||
Texture2D * GetTexture ()const{return tile_texture;} ///<取得贴图
|
||||
|
||||
public:
|
||||
|
||||
TileData(GPUDevice *,Texture2D *,const uint tw,const uint th);
|
||||
|
||||
TileData(TextureManager *,Texture2D *,const uint tw,const uint th);
|
||||
virtual ~TileData();
|
||||
|
||||
void BeginCommit();
|
||||
|
@@ -1,5 +1,4 @@
|
||||
#ifndef HGL_GRAPH_VULKAN_INCLUDE
|
||||
#define HGL_GRAPH_VULKAN_INCLUDE
|
||||
#pragma once
|
||||
|
||||
#include<hgl/type/List.h>
|
||||
#include<hgl/math/Math.h>
|
||||
@@ -9,6 +8,7 @@
|
||||
#include<hgl/graph/VKFormat.h>
|
||||
#include<hgl/graph/VKPrimitiveType.h>
|
||||
#include<hgl/graph/VKStruct.h>
|
||||
#include<hgl/graph/ViewportInfo.h>
|
||||
#include<hgl/graph/VKRenderbufferInfo.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
@@ -25,9 +25,21 @@ 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
|
||||
|
||||
struct VertexAttribDataPtr
|
||||
{
|
||||
const char * name;
|
||||
const VkFormat format;
|
||||
const void * data;
|
||||
};
|
||||
|
||||
using BindingMap =Map<AnsiString,int>;
|
||||
using BindingMapArray =BindingMap[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
|
||||
|
||||
class DescriptorBinding;
|
||||
|
||||
class GraphModule;
|
||||
class RenderFramework;
|
||||
|
||||
class VulkanInstance;
|
||||
class GPUPhysicalDevice;
|
||||
class GPUDevice;
|
||||
@@ -36,8 +48,12 @@ class DeviceQueue;
|
||||
class ImageView;
|
||||
class Framebuffer;
|
||||
struct Swapchain;
|
||||
class IRenderTarget;
|
||||
class RenderTarget;
|
||||
class RTSwapchain;
|
||||
class MultiFrameRenderTarget;
|
||||
class SwapchainRenderTarget;
|
||||
|
||||
struct CopyBufferToImageInfo;
|
||||
|
||||
class Texture;
|
||||
class Texture1D;
|
||||
@@ -50,9 +66,12 @@ class TextureCubeArray;
|
||||
|
||||
class Sampler;
|
||||
|
||||
class TileData;
|
||||
|
||||
class DeviceMemory;
|
||||
class DeviceBuffer;
|
||||
struct DeviceBufferData;
|
||||
template<typename T> class DeviceBufferMap;
|
||||
|
||||
struct PrimitiveDataBuffer;
|
||||
struct PrimitiveRenderData;
|
||||
@@ -174,5 +193,5 @@ inline void copy(VkExtent3D &e3d,const VkExtent2D &e2d,const uint32 depth=1)
|
||||
e3d.height =e2d.height;
|
||||
e3d.depth =depth;
|
||||
}
|
||||
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_VULKAN_INCLUDE
|
||||
|
@@ -1,8 +1,8 @@
|
||||
#ifndef HGL_GRAPH_VULKAN_BUFFER_INCLUDE
|
||||
#define HGL_GRAPH_VULKAN_BUFFER_INCLUDE
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/graph/VKMemory.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
struct DeviceBufferData
|
||||
{
|
||||
@@ -50,5 +50,40 @@ public:
|
||||
virtual bool Write (const void *ptr,uint32_t size) {return buf.memory->Write(ptr,0,size);}
|
||||
bool Write (const void *ptr) {return buf.memory->Write(ptr);}
|
||||
};//class DeviceBuffer
|
||||
|
||||
template<typename T> class DeviceBufferMap
|
||||
{
|
||||
DeviceBuffer *dev_buf;
|
||||
T data_map;
|
||||
|
||||
public:
|
||||
|
||||
static const VkDeviceSize GetSize()
|
||||
{
|
||||
return sizeof(T);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
DeviceBufferMap(DeviceBuffer *buf)
|
||||
{
|
||||
dev_buf=buf;
|
||||
}
|
||||
|
||||
virtual ~DeviceBufferMap()
|
||||
{
|
||||
delete dev_buf;
|
||||
}
|
||||
|
||||
operator DeviceBuffer *(){return dev_buf;}
|
||||
|
||||
T *data(){return &data_map;}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if(dev_buf)
|
||||
dev_buf->Write(&data_map,sizeof(T));
|
||||
}
|
||||
};
|
||||
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_VULKAN_BUFFER_INCLUDE
|
||||
|
@@ -5,6 +5,7 @@
|
||||
#include<hgl/graph/VKVABList.h>
|
||||
#include<hgl/graph/VKPipeline.h>
|
||||
#include<hgl/graph/VKDescriptorSet.h>
|
||||
#include<hgl/graph/VKRenderable.h>
|
||||
#include<hgl/color/Color4f.h>
|
||||
VK_NAMESPACE_BEGIN
|
||||
class GPUCmdBuffer
|
||||
@@ -15,6 +16,8 @@ protected:
|
||||
|
||||
VkCommandBuffer cmd_buf;
|
||||
|
||||
bool cmd_begin;
|
||||
|
||||
public:
|
||||
|
||||
GPUCmdBuffer(const GPUDeviceAttribute *attr,VkCommandBuffer cb);
|
||||
@@ -23,9 +26,19 @@ public:
|
||||
operator VkCommandBuffer(){return cmd_buf;}
|
||||
operator const VkCommandBuffer()const{return cmd_buf;}
|
||||
operator const VkCommandBuffer *()const{return &cmd_buf;}
|
||||
|
||||
const bool IsBegin()const{return cmd_begin;}
|
||||
|
||||
bool Begin();
|
||||
bool End(){return(vkEndCommandBuffer(cmd_buf)==VK_SUCCESS);}
|
||||
virtual bool Begin();
|
||||
virtual bool End()
|
||||
{
|
||||
if(!cmd_begin)
|
||||
return(false);
|
||||
|
||||
cmd_begin=false;
|
||||
|
||||
return(vkEndCommandBuffer(cmd_buf)==VK_SUCCESS);
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
void SetDebugName(const AnsiString &);
|
||||
@@ -37,6 +50,8 @@ public:
|
||||
#endif//_DEBUG
|
||||
};//class GPUCmdBuffer
|
||||
|
||||
class DescriptorBinding;
|
||||
|
||||
class RenderCmdBuffer:public GPUCmdBuffer
|
||||
{
|
||||
uint32_t cv_count;
|
||||
@@ -44,17 +59,29 @@ class RenderCmdBuffer:public GPUCmdBuffer
|
||||
VkRect2D render_area;
|
||||
VkViewport viewport;
|
||||
|
||||
Framebuffer *fbo;
|
||||
RenderPassBeginInfo rp_begin;
|
||||
VkPipelineLayout pipeline_layout;
|
||||
|
||||
void SetFBO(Framebuffer *);
|
||||
DescriptorBinding *desc_binding=nullptr;
|
||||
|
||||
private:
|
||||
|
||||
void SetClear();
|
||||
|
||||
public:
|
||||
|
||||
RenderCmdBuffer(const GPUDeviceAttribute *attr,VkCommandBuffer cb);
|
||||
~RenderCmdBuffer();
|
||||
|
||||
void SetDescriptorBinding(DescriptorBinding *db) { desc_binding=db; }
|
||||
|
||||
bool End() override
|
||||
{
|
||||
desc_binding=nullptr;
|
||||
|
||||
return GPUCmdBuffer::End();
|
||||
}
|
||||
|
||||
void SetRenderArea(const VkRect2D &ra){render_area=ra;}
|
||||
void SetRenderArea(const VkExtent2D &);
|
||||
void SetViewport(const VkViewport &vp){viewport=vp;}
|
||||
@@ -78,7 +105,7 @@ public:
|
||||
|
||||
//以上设定在Begin开始后即不可改变
|
||||
|
||||
bool BindFramebuffer(RenderPass *rp,Framebuffer *fb);
|
||||
bool BindFramebuffer(Framebuffer *);
|
||||
|
||||
bool BeginRenderPass();
|
||||
void NextSubpass(){vkCmdNextSubpass(cmd_buf,VK_SUBPASS_CONTENTS_INLINE);}
|
||||
@@ -216,6 +243,19 @@ public: //draw
|
||||
void Draw (const PrimitiveDataBuffer *prb,const PrimitiveRenderData *prd,const uint32_t instance_count=1,const uint32_t first_instance=0);
|
||||
|
||||
public: //dynamic state
|
||||
|
||||
public:
|
||||
|
||||
void Render(Renderable *ri)
|
||||
{
|
||||
if(!ri)return;
|
||||
|
||||
BindPipeline(ri->GetPipeline());
|
||||
BindDescriptorSets(ri->GetMaterial());
|
||||
BindDataBuffer(ri->GetDataBuffer());
|
||||
|
||||
Draw(ri->GetDataBuffer(),ri->GetRenderData());
|
||||
}
|
||||
};//class RenderCmdBuffer:public GPUCmdBuffer
|
||||
|
||||
class TextureCmdBuffer:public GPUCmdBuffer
|
||||
|
@@ -3,6 +3,7 @@
|
||||
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/color/Color4f.h>
|
||||
#include<hgl/graph/VKTexture.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
struct DebugUtilsFunction
|
||||
@@ -92,6 +93,13 @@ public:
|
||||
// DU_FUNC(BufferCollectionFuchsia, BUFFER_COLLECTION_FUCHSIA)
|
||||
|
||||
#undef DU_FUNC
|
||||
|
||||
void SetTexture(Texture *tex,const AnsiString &info)
|
||||
{
|
||||
SetImage( tex->GetImage(), info+"_Image" );
|
||||
SetImageView( tex->GetVulkanImageView(), info+"_ImageView" );
|
||||
SetDeviceMemory(tex->GetDeviceMemory(), info+"_Memory" );
|
||||
}
|
||||
|
||||
void QueueBegin (VkQueue,const char *,const Color4f &color=Color4f(1,1,1,1));
|
||||
void QueueEnd (VkQueue q){duf.QueueEnd(q);}
|
||||
|
@@ -1,112 +1,109 @@
|
||||
#ifndef HGL_GRAPH_DESCRIPTOR_BINDING_MANAGE_INCLUDE
|
||||
#define HGL_GRAPH_DESCRIPTOR_BINDING_MANAGE_INCLUDE
|
||||
#pragma once
|
||||
|
||||
#include<hgl/type/Map.h>
|
||||
#include<hgl/type/String.h>
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/graph/VKDescriptorSetType.h>
|
||||
namespace hgl
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
class DeviceBuffer;
|
||||
class Texture;
|
||||
class Material;
|
||||
class MaterialParameters;
|
||||
|
||||
/**
|
||||
* 描述符绑定器<Br>
|
||||
* 一般用于注册通用数据,为材质进行自动绑定。
|
||||
*/
|
||||
class DescriptorBinding
|
||||
{
|
||||
namespace graph
|
||||
DescriptorSetType set_type; ///<描述符合集类型
|
||||
|
||||
Map<AnsiString,DeviceBuffer *> ubo_map;
|
||||
Map<AnsiString,DeviceBuffer *> ssbo_map;
|
||||
Map<AnsiString,Texture *> texture_map;
|
||||
|
||||
public:
|
||||
|
||||
DescriptorBinding(const DescriptorSetType &dst)
|
||||
{
|
||||
class DeviceBuffer;
|
||||
class Texture;
|
||||
class Material;
|
||||
class MaterialParameters;
|
||||
set_type=dst;
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述符绑定器<Br>
|
||||
* 一般用于注册通用数据,为材质进行自动绑定。
|
||||
*/
|
||||
class DescriptorBinding
|
||||
{
|
||||
DescriptorSetType set_type; ///<描述符合集类型
|
||||
bool AddUBO(const AnsiString &name,DeviceBuffer *buf)
|
||||
{
|
||||
if(!buf)return(false);
|
||||
if(name.IsEmpty())return(false);
|
||||
|
||||
Map<AnsiString,DeviceBuffer *> ubo_map;
|
||||
Map<AnsiString,DeviceBuffer *> ssbo_map;
|
||||
Map<AnsiString,Texture *> texture_map;
|
||||
return ubo_map.Add(name,buf);
|
||||
}
|
||||
|
||||
public:
|
||||
DeviceBuffer *GetUBO(const AnsiString &name)
|
||||
{
|
||||
if(name.IsEmpty())return(nullptr);
|
||||
|
||||
DescriptorBinding(const DescriptorSetType &dst)
|
||||
{
|
||||
set_type=dst;
|
||||
}
|
||||
return GetObjectFromList(ubo_map,name);
|
||||
}
|
||||
|
||||
bool AddUBO(const AnsiString &name,DeviceBuffer *buf)
|
||||
{
|
||||
if(!buf)return(false);
|
||||
if(name.IsEmpty())return(false);
|
||||
void RemoveUBO(DeviceBuffer *buf)
|
||||
{
|
||||
if(!buf)return;
|
||||
|
||||
return ubo_map.Add(name,buf);
|
||||
}
|
||||
ubo_map.DeleteByValue(buf);
|
||||
}
|
||||
|
||||
DeviceBuffer *GetUBO(const AnsiString &name)
|
||||
{
|
||||
if(name.IsEmpty())return(nullptr);
|
||||
bool AddSSBO(const AnsiString &name,DeviceBuffer *buf)
|
||||
{
|
||||
if(!buf)return(false);
|
||||
if(name.IsEmpty())return(false);
|
||||
|
||||
return GetObjectFromList(ubo_map,name);
|
||||
}
|
||||
return ssbo_map.Add(name,buf);
|
||||
}
|
||||
|
||||
void RemoveUBO(DeviceBuffer *buf)
|
||||
{
|
||||
if(!buf)return;
|
||||
DeviceBuffer *GetSSBO(const AnsiString &name)
|
||||
{
|
||||
if(name.IsEmpty())return(nullptr);
|
||||
|
||||
ubo_map.DeleteByValue(buf);
|
||||
}
|
||||
return GetObjectFromList(ssbo_map,name);
|
||||
}
|
||||
|
||||
bool AddSSBO(const AnsiString &name,DeviceBuffer *buf)
|
||||
{
|
||||
if(!buf)return(false);
|
||||
if(name.IsEmpty())return(false);
|
||||
void RemoveSSBO(DeviceBuffer *buf)
|
||||
{
|
||||
if(!buf)return;
|
||||
|
||||
return ssbo_map.Add(name,buf);
|
||||
}
|
||||
ssbo_map.DeleteByValue(buf);
|
||||
}
|
||||
|
||||
DeviceBuffer *GetSSBO(const AnsiString &name)
|
||||
{
|
||||
if(name.IsEmpty())return(nullptr);
|
||||
bool AddTexture(const AnsiString &name,Texture *tex)
|
||||
{
|
||||
if(!tex)return(false);
|
||||
if(name.IsEmpty())return(false);
|
||||
|
||||
return GetObjectFromList(ssbo_map,name);
|
||||
}
|
||||
return texture_map.Add(name,tex);
|
||||
}
|
||||
|
||||
void RemoveSSBO(DeviceBuffer *buf)
|
||||
{
|
||||
if(!buf)return;
|
||||
Texture *GetTexture(const AnsiString &name)
|
||||
{
|
||||
if(name.IsEmpty())return(nullptr);
|
||||
|
||||
ssbo_map.DeleteByValue(buf);
|
||||
}
|
||||
return GetObjectFromList(texture_map,name);
|
||||
}
|
||||
|
||||
bool AddTexture(const AnsiString &name,Texture *tex)
|
||||
{
|
||||
if(!tex)return(false);
|
||||
if(name.IsEmpty())return(false);
|
||||
void RemoveTexture(Texture *tex)
|
||||
{
|
||||
if(!tex)return;
|
||||
|
||||
return texture_map.Add(name,tex);
|
||||
}
|
||||
texture_map.DeleteByValue(tex);
|
||||
}
|
||||
|
||||
Texture *GetTexture(const AnsiString &name)
|
||||
{
|
||||
if(name.IsEmpty())return(nullptr);
|
||||
private:
|
||||
|
||||
return GetObjectFromList(texture_map,name);
|
||||
}
|
||||
void BindUBO(MaterialParameters *,const BindingMap &,bool dynamic);
|
||||
|
||||
void RemoveTexture(Texture *tex)
|
||||
{
|
||||
if(!tex)return;
|
||||
public:
|
||||
|
||||
texture_map.DeleteByValue(tex);
|
||||
}
|
||||
bool Bind(Material *);
|
||||
};//class DescriptorBinding
|
||||
|
||||
private:
|
||||
|
||||
void BindUBO(MaterialParameters *,const BindingMap &,bool dynamic);
|
||||
|
||||
public:
|
||||
|
||||
bool Bind(Material *);
|
||||
};//class DescriptorBinding
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
#endif//HGL_GRAPH_DESCRIPTOR_BINDING_MANAGE_INCLUDE
|
||||
VK_NAMESPACE_END
|
||||
|
@@ -32,29 +32,10 @@ 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();
|
||||
|
||||
private:
|
||||
|
||||
VkCommandBuffer CreateCommandBuffer(const AnsiString &);
|
||||
|
||||
bool CreateSwapchainFBO(Swapchain *);
|
||||
|
||||
Swapchain *CreateSwapchain(const VkExtent2D &acquire_extent);
|
||||
|
||||
private:
|
||||
|
||||
friend class VulkanDeviceCreater;
|
||||
@@ -79,15 +60,11 @@ 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);}
|
||||
|
||||
|
||||
#ifdef _DEBUG
|
||||
DebugUtils * GetDebugUtils (){return attr->debug_utils;}
|
||||
#endif//_DEBUG
|
||||
|
||||
public:
|
||||
|
||||
@@ -141,7 +118,13 @@ public: //Buffer相关
|
||||
#define CREATE_BUFFER_OBJECT(LargeName,type) DeviceBuffer *Create##LargeName( VkDeviceSize size,void *data, SharingMode sm=SharingMode::Exclusive) {return CreateBuffer(VK_BUFFER_USAGE_##type##_BUFFER_BIT,size ,size,data, sm);} \
|
||||
DeviceBuffer *Create##LargeName( VkDeviceSize size, SharingMode sm=SharingMode::Exclusive) {return CreateBuffer(VK_BUFFER_USAGE_##type##_BUFFER_BIT,size ,size,nullptr, sm);} \
|
||||
DeviceBuffer *Create##LargeName(VkDeviceSize range,VkDeviceSize size,void *data, SharingMode sm=SharingMode::Exclusive) {return CreateBuffer(VK_BUFFER_USAGE_##type##_BUFFER_BIT,range,size,data, sm);} \
|
||||
DeviceBuffer *Create##LargeName(VkDeviceSize range,VkDeviceSize size, SharingMode sm=SharingMode::Exclusive) {return CreateBuffer(VK_BUFFER_USAGE_##type##_BUFFER_BIT,range,size,nullptr, sm);}
|
||||
DeviceBuffer *Create##LargeName(VkDeviceSize range,VkDeviceSize size, SharingMode sm=SharingMode::Exclusive) {return CreateBuffer(VK_BUFFER_USAGE_##type##_BUFFER_BIT,range,size,nullptr, sm);} \
|
||||
\
|
||||
template<typename T> T *Create##LargeName() \
|
||||
{ \
|
||||
DeviceBuffer *buf=Create##LargeName(T::GetSize()); \
|
||||
return(buf?new T(buf):nullptr); \
|
||||
}
|
||||
|
||||
CREATE_BUFFER_OBJECT(UBO,UNIFORM)
|
||||
CREATE_BUFFER_OBJECT(SSBO,STORAGE)
|
||||
@@ -160,57 +143,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);
|
||||
@@ -231,25 +163,11 @@ public: //Command Buffer 相关
|
||||
|
||||
public:
|
||||
|
||||
RenderPass * AcquireRenderPass( const RenderbufferInfo *,const uint subpass_count=2);
|
||||
|
||||
Fence * CreateFence(bool);
|
||||
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数据集
|
||||
|
@@ -1,13 +1,13 @@
|
||||
#ifndef HGL_GRAPH_VULKAN_FRAMEBUFFER_INCLUDE
|
||||
#define HGL_GRAPH_VULKAN_FRAMEBUFFER_INCLUDE
|
||||
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/graph/VKRenderPass.h>
|
||||
VK_NAMESPACE_BEGIN
|
||||
class Framebuffer
|
||||
{
|
||||
VkDevice device;
|
||||
VkFramebuffer frame_buffer;
|
||||
VkRenderPass render_pass;
|
||||
RenderPass *render_pass;
|
||||
|
||||
VkExtent2D extent;
|
||||
uint32_t attachment_count;
|
||||
@@ -16,9 +16,9 @@ class Framebuffer
|
||||
|
||||
private:
|
||||
|
||||
friend class GPUDevice;
|
||||
friend class RenderTargetManager;
|
||||
|
||||
Framebuffer(VkDevice,VkFramebuffer,const VkExtent2D &,VkRenderPass,uint32_t color_count,bool depth);
|
||||
Framebuffer(VkDevice,VkFramebuffer,const VkExtent2D &,RenderPass *,uint32_t color_count,bool depth);
|
||||
|
||||
public:
|
||||
|
||||
@@ -27,7 +27,7 @@ public:
|
||||
operator VkFramebuffer(){return frame_buffer;}
|
||||
|
||||
const VkFramebuffer GetFramebuffer ()const{return frame_buffer;}
|
||||
const VkRenderPass GetRenderPass ()const{return render_pass;}
|
||||
RenderPass * GetRenderPass ()const{return render_pass;}
|
||||
|
||||
const VkExtent2D & GetExtent ()const{return extent;}
|
||||
|
||||
|
@@ -14,11 +14,13 @@ class GPUPhysicalDevice
|
||||
VkPhysicalDeviceVulkan11Features features11;
|
||||
VkPhysicalDeviceVulkan12Features features12;
|
||||
VkPhysicalDeviceVulkan13Features features13;
|
||||
VkPhysicalDeviceVulkan14Features features14;
|
||||
|
||||
VkPhysicalDeviceProperties properties;
|
||||
VkPhysicalDeviceVulkan11Properties properties11;
|
||||
VkPhysicalDeviceVulkan12Properties properties12;
|
||||
VkPhysicalDeviceVulkan13Properties properties13;
|
||||
VkPhysicalDeviceVulkan14Properties properties14;
|
||||
|
||||
VkPhysicalDeviceMemoryProperties memory_properties;
|
||||
List<VkLayerProperties> layer_properties;
|
||||
@@ -36,6 +38,7 @@ public:
|
||||
const VkPhysicalDeviceVulkan11Features &GetFeatures11 ()const{return features11;}
|
||||
const VkPhysicalDeviceVulkan12Features &GetFeatures12 ()const{return features12;}
|
||||
const VkPhysicalDeviceVulkan13Features &GetFeatures13 ()const{return features13;}
|
||||
const VkPhysicalDeviceVulkan14Features &GetFeatures14 ()const{return features14;}
|
||||
|
||||
const VkPhysicalDeviceProperties & GetProperties ()const{return properties;}
|
||||
const VkPhysicalDeviceMemoryProperties &GetMemoryProperties ()const{return memory_properties;}
|
||||
@@ -66,7 +69,11 @@ public:
|
||||
const uint32_t GetSSBORange ()const{return properties.limits.maxStorageBufferRange;}
|
||||
const VkDeviceSize GetSSBOAlign ()const{return properties.limits.minStorageBufferOffsetAlignment;}
|
||||
|
||||
const uint32_t GetConstantSize ()const{return properties.limits.maxPushConstantsSize;}
|
||||
const uint32_t GetConstantSize ()const{return properties.limits.maxPushConstantsSize;}
|
||||
|
||||
const VkDeviceSize GetMaxBufferSize()const{return properties13.maxBufferSize;}
|
||||
|
||||
const uint32_t GetMaxPushDescriptors()const{return properties14.maxPushDescriptors;}
|
||||
|
||||
public:
|
||||
|
||||
@@ -182,6 +189,9 @@ public:
|
||||
const VkBool32 SupportYcbcrConversion ()const{return features11.samplerYcbcrConversion;}
|
||||
const VkBool32 SupportClampMirrorToEdge ()const{return features12.samplerMirrorClampToEdge;}
|
||||
|
||||
const VkBool32 SupportSmoothLines ()const{return features14.smoothLines;}
|
||||
const VkBool32 SupportStippledSmoothLines ()const{return features14.stippledSmoothLines;}
|
||||
|
||||
const void GetPointSize(float &granularity,float &min_size,float &max_size) const
|
||||
{
|
||||
granularity =properties.limits.pointSizeGranularity;
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#ifndef HGL_GRAPH_VULKAN_SUBMIT_QUEUE_INCLUDE
|
||||
#ifndef HGL_GRAPH_VULKAN_SUBMIT_QUEUE_INCLUDE
|
||||
#define HGL_GRAPH_VULKAN_SUBMIT_QUEUE_INCLUDE
|
||||
|
||||
#include<hgl/graph/VK.h>
|
||||
@@ -31,10 +31,18 @@ public:
|
||||
|
||||
VkResult Present(const VkPresentInfoKHR *pi){return vkQueuePresentKHR(queue,pi);}
|
||||
|
||||
/**
|
||||
* 等待Submit的队列完成操作。这个操作会阻塞当前线程,所以在Submit后请不要立即使用它。而是在下一次队列提交前再做这个操作。
|
||||
*/
|
||||
bool WaitQueue();
|
||||
|
||||
/**
|
||||
* 等待Queue命令执行完成的fence信号
|
||||
*/
|
||||
bool WaitFence(const bool wait_all=true,const uint64_t time_out=HGL_NANO_SEC_PER_SEC);
|
||||
bool Submit(const VkCommandBuffer &cmd_buf,Semaphore *wait_sem,Semaphore *complete_sem);
|
||||
|
||||
bool Submit(const VkCommandBuffer *cmd_buf,const uint32_t count,Semaphore *wait_sem,Semaphore *complete_sem);
|
||||
bool Submit(GPUCmdBuffer *cmd_buf,Semaphore *wait_sem,Semaphore *complete_sem);
|
||||
};//class DeviceQueue
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_VULKAN_SUBMIT_QUEUE_INCLUDE
|
||||
|
@@ -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);
|
||||
|
||||
@@ -37,8 +37,10 @@ public:
|
||||
|
||||
virtual ~RenderPass();
|
||||
|
||||
VkRenderPass GetVkRenderPass(){return render_pass;}
|
||||
VkPipelineCache GetPipelineCache(){return pipeline_cache;}
|
||||
operator const VkRenderPass()const{return render_pass;}
|
||||
|
||||
const VkRenderPass GetVkRenderPass()const{return render_pass;}
|
||||
const VkPipelineCache GetPipelineCache()const{return pipeline_cache;}
|
||||
|
||||
const uint GetColorCount()const{return color_formats.GetCount();}
|
||||
const List<VkFormat> & GetColorFormat()const{return color_formats;}
|
||||
|
@@ -34,11 +34,8 @@ using DescriptorSetID =int;
|
||||
using PrimitiveID =int;
|
||||
using RenderableID =int;
|
||||
using SamplerID =int;
|
||||
using TextureID =int;
|
||||
using StaticMeshID =int;
|
||||
|
||||
class VertexAttribData;
|
||||
|
||||
using ShaderModuleMapByName=ObjectMap<AnsiString,ShaderModule>;
|
||||
constexpr const size_t VK_SHADER_STAGE_TYPE_COUNT=20;//GetBitOffset((uint32_t)VK_SHADER_STAGE_CLUSTER_CULLING_BIT_HUAWEI)+1;
|
||||
|
||||
@@ -51,7 +48,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 +55,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 +100,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 +153,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 +161,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 +173,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);}
|
||||
|
@@ -1,5 +1,4 @@
|
||||
#ifndef HGL_GRAPH_VULKAN_RENDER_TARGET_INCLUDE
|
||||
#define HGL_GRAPH_VULKAN_RENDER_TARGET_INCLUDE
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/graph/VKRenderPass.h>
|
||||
@@ -7,109 +6,77 @@
|
||||
#include<hgl/graph/VKSwapchain.h>
|
||||
#include<hgl/graph/VKQueue.h>
|
||||
#include<hgl/graph/VKPipeline.h>
|
||||
#include<hgl/graph/VKCommandBuffer.h>
|
||||
#include<hgl/graph/VKDescriptorBindingManage.h>
|
||||
//#include<iostream>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
/**
|
||||
* 渲染目标
|
||||
*/
|
||||
class RenderTarget
|
||||
|
||||
class RenderFramework;
|
||||
|
||||
using UBOViewportInfo=DeviceBufferMap<graph::ViewportInfo>;
|
||||
|
||||
class IRenderTarget
|
||||
{
|
||||
protected:
|
||||
RenderFramework *render_framework;
|
||||
|
||||
DeviceQueue *queue;
|
||||
|
||||
RenderPass *render_pass;
|
||||
Framebuffer *fbo;
|
||||
|
||||
VkExtent2D extent;
|
||||
|
||||
UBOViewportInfo *ubo_vp_info;
|
||||
|
||||
DescriptorBinding desc_binding;
|
||||
|
||||
public:
|
||||
|
||||
RenderFramework * GetRenderFramework ()const{return render_framework;}
|
||||
GPUDevice * GetDevice ()const;
|
||||
VkDevice GetVkDevice ()const;
|
||||
DescriptorBinding * GetDescriptorBinding(){return &desc_binding;}
|
||||
|
||||
const VkExtent2D &GetExtent ()const{return extent;}
|
||||
|
||||
virtual uint32_t GetColorCount ()=0;
|
||||
virtual bool hasDepth ()=0;
|
||||
|
||||
public:
|
||||
|
||||
void OnResize(const VkExtent2D &ext);
|
||||
|
||||
public:
|
||||
|
||||
IRenderTarget(RenderFramework *,const VkExtent2D &);
|
||||
virtual ~IRenderTarget();
|
||||
|
||||
Semaphore *render_complete_semaphore =nullptr;
|
||||
virtual Framebuffer * GetFramebuffer ()=0;
|
||||
virtual RenderPass * GetRenderPass ()=0;
|
||||
|
||||
protected:
|
||||
virtual Texture2D * GetColorTexture (const int index=0)=0;
|
||||
virtual Texture2D * GetDepthTexture ()=0;
|
||||
|
||||
uint32_t color_count;
|
||||
Texture2D **color_textures;
|
||||
Texture2D *depth_texture;
|
||||
public: // Command Buffer
|
||||
|
||||
protected:
|
||||
virtual DeviceQueue * GetQueue ()=0;
|
||||
virtual Semaphore * GetRenderCompleteSemaphore()=0;
|
||||
|
||||
friend class GPUDevice;
|
||||
virtual RenderCmdBuffer * GetRenderCmdBuffer ()=0;
|
||||
|
||||
RenderTarget(DeviceQueue *,Semaphore *);
|
||||
RenderTarget(DeviceQueue *,Semaphore *,RenderPass *_rp,Framebuffer *_fb,Texture2D **color_texture_list,const uint32_t color_count,Texture2D *depth_texture);
|
||||
virtual bool Submit (Semaphore *wait_sem)=0;
|
||||
|
||||
virtual bool Submit (){return Submit(nullptr);}
|
||||
|
||||
virtual bool WaitQueue ()=0;
|
||||
virtual bool WaitFence ()=0;
|
||||
|
||||
virtual RenderCmdBuffer * BeginRender ()=0;
|
||||
virtual void EndRender ()=0;
|
||||
|
||||
public:
|
||||
|
||||
virtual ~RenderTarget();
|
||||
|
||||
DeviceQueue * GetQueue () {return queue;}
|
||||
const VkExtent2D & GetExtent ()const {return extent;}
|
||||
virtual RenderPass * GetRenderPass () {return render_pass;}
|
||||
virtual const VkRenderPass GetVkRenderPass ()const {return render_pass->GetVkRenderPass();}
|
||||
virtual const uint32_t GetColorCount ()const {return fbo->GetColorCount();}
|
||||
virtual Framebuffer * GetFramebuffer () {return fbo;}
|
||||
virtual void Bind (Material *mtl)
|
||||
{
|
||||
if(mtl)
|
||||
desc_binding.Bind(mtl);
|
||||
}
|
||||
};//class IRenderTarget
|
||||
|
||||
virtual Texture2D * GetColorTexture (const int index=0){return color_textures[index];}
|
||||
virtual Texture2D * GetDepthTexture (){return depth_texture;}
|
||||
|
||||
public: // command buffer
|
||||
|
||||
Semaphore * GetRenderCompleteSemaphore (){return render_complete_semaphore;}
|
||||
virtual bool Submit (RenderCmdBuffer *,Semaphore *present_complete_semaphore=nullptr);
|
||||
|
||||
bool WaitQueue(){return queue->WaitQueue();}
|
||||
bool WaitFence(){return queue->WaitFence();}
|
||||
};//class RenderTarget
|
||||
|
||||
/**
|
||||
* 交换链专用渲染目标
|
||||
*/
|
||||
class RTSwapchain:public RenderTarget
|
||||
{
|
||||
VkDevice device;
|
||||
Swapchain *swapchain;
|
||||
PresentInfo present_info;
|
||||
|
||||
Semaphore *present_complete_semaphore=nullptr;
|
||||
|
||||
uint32_t current_frame;
|
||||
|
||||
public:
|
||||
|
||||
RTSwapchain(VkDevice dev,Swapchain *sc,DeviceQueue *q,Semaphore *rcs,Semaphore *pcs,RenderPass *rp);
|
||||
~RTSwapchain();
|
||||
|
||||
Framebuffer * GetFramebuffer ()override {return swapchain->sc_fbo[current_frame];}
|
||||
Framebuffer * GetFramebuffer (const uint32_t index) {return swapchain->sc_fbo[index];}
|
||||
|
||||
const uint32_t GetColorCount ()const override {return 1;}
|
||||
const uint32_t GetImageCount ()const {return swapchain->color_count;}
|
||||
|
||||
virtual Texture2D * GetColorTexture (const int index=0) override{return swapchain->sc_color[index];}
|
||||
virtual Texture2D * GetDepthTexture () override{return swapchain->sc_depth;}
|
||||
|
||||
public:
|
||||
|
||||
const uint32_t GetCurrentFrameIndices ()const {return current_frame;}
|
||||
Semaphore * GetPresentCompleteSemaphore () {return present_complete_semaphore;}
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* 请求下一帧画面的索引
|
||||
* @param present_complete_semaphore 推送完成信号
|
||||
*/
|
||||
int AcquireNextImage();
|
||||
|
||||
/**
|
||||
* 推送后台画面到前台
|
||||
* @param render_complete_semaphore 渲染完成信号
|
||||
*/
|
||||
bool PresentBackbuffer(VkSemaphore *wait_semaphores,const uint32_t wait_semaphore_count);
|
||||
|
||||
bool PresentBackbuffer();
|
||||
|
||||
bool Submit(VkCommandBuffer);
|
||||
bool Submit(VkCommandBuffer,Semaphore *);
|
||||
};//class RTSwapchain:public RenderTarget
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_VULKAN_RENDER_TARGET_INCLUDE
|
||||
|
38
inc/hgl/graph/VKRenderTargetData.h
Normal file
38
inc/hgl/graph/VKRenderTargetData.h
Normal file
@@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/VK.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
struct RenderTargetData
|
||||
{
|
||||
Framebuffer * fbo;
|
||||
DeviceQueue * queue;
|
||||
Semaphore * render_complete_semaphore;
|
||||
|
||||
RenderCmdBuffer * cmd_buf;
|
||||
|
||||
uint32_t color_count; ///<颜色成分数量
|
||||
Texture2D ** color_textures; ///<颜色成分纹理列表
|
||||
Texture2D * depth_texture; ///<深度成分纹理
|
||||
|
||||
public:
|
||||
|
||||
Texture2D *GetColorTexture(const uint32_t index)
|
||||
{
|
||||
if(index>=color_count)
|
||||
return(nullptr);
|
||||
|
||||
return color_textures[index];
|
||||
}
|
||||
|
||||
bool Submit(Semaphore *wait_sem);
|
||||
|
||||
RenderCmdBuffer *BeginRender(DescriptorBinding *);
|
||||
|
||||
void EndRender();
|
||||
|
||||
virtual void Clear();
|
||||
};//struct RenderTargetData
|
||||
|
||||
VK_NAMESPACE_END
|
97
inc/hgl/graph/VKRenderTargetMultiFrame.h
Normal file
97
inc/hgl/graph/VKRenderTargetMultiFrame.h
Normal file
@@ -0,0 +1,97 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/VKRenderTarget.h>
|
||||
#include<hgl/graph/VKRenderTargetData.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* 多帧渲染目标
|
||||
*/
|
||||
class MultiFrameRenderTarget:public IRenderTarget
|
||||
{
|
||||
protected:
|
||||
|
||||
uint32_t frame_number;
|
||||
uint32_t current_frame;
|
||||
|
||||
RenderTargetData *rtd_list;
|
||||
|
||||
protected:
|
||||
|
||||
friend class RenderTargetManager;
|
||||
|
||||
MultiFrameRenderTarget(RenderFramework *rf,const uint32_t fn,RenderTargetData *rtl):IRenderTarget(rf,rtl[0].fbo->GetExtent())
|
||||
{
|
||||
frame_number=fn;
|
||||
current_frame=0;
|
||||
|
||||
rtd_list=rtl;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
virtual ~MultiFrameRenderTarget() override
|
||||
{
|
||||
for(uint32_t i=0;i<frame_number;i++)
|
||||
rtd_list[i].Clear();
|
||||
|
||||
delete[] rtd_list;
|
||||
}
|
||||
|
||||
virtual bool NextFrame()
|
||||
{
|
||||
++current_frame;
|
||||
|
||||
if(current_frame>=frame_number)
|
||||
current_frame=0;
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
uint32_t GetCurrentFrameIndices ()const{return current_frame;}
|
||||
uint32_t GetFrameCount ()const{return frame_number;}
|
||||
|
||||
public:
|
||||
|
||||
Framebuffer * GetFramebuffer ()override{return rtd_list[current_frame].fbo;}
|
||||
RenderPass * GetRenderPass ()override{return rtd_list[current_frame].fbo->GetRenderPass();}
|
||||
|
||||
uint32_t GetColorCount ()override{return rtd_list[current_frame].color_count;}
|
||||
|
||||
Texture2D * GetColorTexture (const int index=0) override{return rtd_list[current_frame].GetColorTexture(index);}
|
||||
Texture2D * GetDepthTexture () override{return rtd_list[current_frame].depth_texture;}
|
||||
|
||||
|
||||
bool hasDepth ()override{return rtd_list[current_frame].depth_texture;}
|
||||
|
||||
public: // Command Buffer
|
||||
|
||||
DeviceQueue * GetQueue ()override{return rtd_list[current_frame].queue;}
|
||||
Semaphore * GetRenderCompleteSemaphore ()override{return rtd_list[current_frame].render_complete_semaphore;}
|
||||
RenderCmdBuffer * GetRenderCmdBuffer ()override{return rtd_list[current_frame].cmd_buf;}
|
||||
|
||||
Framebuffer * GetFramebuffer (const uint32_t index){return rtd_list[index].fbo;}
|
||||
RenderCmdBuffer * GetRenderCmdBuffer (const uint32_t index){return rtd_list[index].cmd_buf;}
|
||||
|
||||
virtual bool Submit (Semaphore *wait_sem)override{return rtd_list[current_frame].Submit(wait_sem);}
|
||||
|
||||
bool WaitQueue ()override{return rtd_list[current_frame].queue->WaitQueue();}
|
||||
bool WaitFence ()override{return rtd_list[current_frame].queue->WaitFence();}
|
||||
|
||||
public:
|
||||
|
||||
virtual RenderCmdBuffer *BeginRender()override
|
||||
{
|
||||
//std::cout<<"Begin Render frame="<<current_frame<<std::endl;
|
||||
return rtd_list[current_frame].BeginRender(GetDescriptorBinding());
|
||||
}
|
||||
|
||||
virtual void EndRender() override
|
||||
{
|
||||
//std::cout<<"End Render frame="<<current_frame<<std::endl;
|
||||
rtd_list[current_frame].EndRender();
|
||||
}
|
||||
};//class MultiFrameRenderTarget
|
||||
|
||||
VK_NAMESPACE_END
|
85
inc/hgl/graph/VKRenderTargetSingle.h
Normal file
85
inc/hgl/graph/VKRenderTargetSingle.h
Normal file
@@ -0,0 +1,85 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/VKRenderTarget.h>
|
||||
#include<hgl/graph/VKRenderTargetData.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* 单帧渲染目标
|
||||
*/
|
||||
class RenderTarget:public IRenderTarget
|
||||
{
|
||||
RenderTargetData *data;
|
||||
|
||||
protected:
|
||||
|
||||
friend class SwapchainModule;
|
||||
friend class RenderTargetManager;
|
||||
|
||||
RenderTarget(RenderFramework *rf,RenderTargetData *rtd):IRenderTarget(rf,rtd->fbo->GetExtent())
|
||||
{
|
||||
data=rtd;
|
||||
|
||||
data->cmd_buf->SetDescriptorBinding(GetDescriptorBinding());
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
virtual ~RenderTarget() override
|
||||
{
|
||||
if(data)
|
||||
{
|
||||
data->Clear();
|
||||
delete data;
|
||||
}
|
||||
}
|
||||
|
||||
Framebuffer * GetFramebuffer ()override{return data->fbo;}
|
||||
RenderPass * GetRenderPass ()override{return data->fbo->GetRenderPass();}
|
||||
|
||||
uint32_t GetColorCount ()override{return data->color_count;}
|
||||
|
||||
bool hasDepth ()override{return data->depth_texture;}
|
||||
|
||||
Texture2D * GetColorTexture (const int index=0) override{return data->GetColorTexture(index);}
|
||||
Texture2D * GetDepthTexture () override{return data->depth_texture;}
|
||||
|
||||
public: // Command Buffer
|
||||
|
||||
DeviceQueue * GetQueue ()override{return data->queue;}
|
||||
Semaphore * GetRenderCompleteSemaphore()override{return data->render_complete_semaphore;}
|
||||
|
||||
RenderCmdBuffer * GetRenderCmdBuffer ()override{return data->cmd_buf;}
|
||||
|
||||
virtual bool Submit (Semaphore *wait_sem)override
|
||||
{
|
||||
if(!data)
|
||||
return(false);
|
||||
|
||||
return data->Submit(wait_sem);
|
||||
}
|
||||
|
||||
bool WaitQueue ()override{return data->queue->WaitQueue();}
|
||||
bool WaitFence ()override{return data->queue->WaitFence();}
|
||||
|
||||
public:
|
||||
|
||||
virtual RenderCmdBuffer *BeginRender()override
|
||||
{
|
||||
if(!data)
|
||||
return(nullptr);
|
||||
|
||||
return data->BeginRender(GetDescriptorBinding());
|
||||
}
|
||||
|
||||
virtual void EndRender() override
|
||||
{
|
||||
if(!data)
|
||||
return;
|
||||
|
||||
data->EndRender();
|
||||
}
|
||||
};//class RenderTarget
|
||||
|
||||
VK_NAMESPACE_END
|
35
inc/hgl/graph/VKRenderTargetSwapchain.h
Normal file
35
inc/hgl/graph/VKRenderTargetSwapchain.h
Normal file
@@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/VKRenderTargetMultiFrame.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* 交换链专用渲染目标
|
||||
*/
|
||||
class SwapchainRenderTarget:public MultiFrameRenderTarget
|
||||
{
|
||||
Swapchain *swapchain;
|
||||
PresentInfo present_info;
|
||||
|
||||
Semaphore *present_complete_semaphore=nullptr;
|
||||
|
||||
private:
|
||||
|
||||
SwapchainRenderTarget(RenderFramework *rf,Swapchain *sc,Semaphore *pcs,RenderTargetData *rtdl);
|
||||
|
||||
friend class SwapchainModule;
|
||||
friend class RenderTargetManager;
|
||||
|
||||
public:
|
||||
|
||||
~SwapchainRenderTarget() override;
|
||||
|
||||
public:
|
||||
|
||||
bool NextFrame ()override; ///<获取下一帧的索引
|
||||
|
||||
bool Submit ()override; ///<提交当前帧的渲染,交推送到前台
|
||||
};//class SwapchainRenderTarget:public MultiFrameRenderTarget
|
||||
|
||||
VK_NAMESPACE_END
|
@@ -1,30 +1,41 @@
|
||||
#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>
|
||||
#include<hgl/type/List.h>
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
struct SwapchainImage
|
||||
{
|
||||
Texture2D * color =nullptr;
|
||||
Texture2D * depth =nullptr;
|
||||
|
||||
Framebuffer * fbo =nullptr;
|
||||
|
||||
RenderCmdBuffer * cmd_buf =nullptr;
|
||||
|
||||
public:
|
||||
|
||||
~SwapchainImage();
|
||||
};//struct SwapchainImage
|
||||
|
||||
struct Swapchain
|
||||
{
|
||||
public:
|
||||
|
||||
VkDevice device =VK_NULL_HANDLE;
|
||||
VkDevice device =VK_NULL_HANDLE;
|
||||
|
||||
VkExtent2D extent;
|
||||
VkExtent2D extent;
|
||||
VkSurfaceTransformFlagBitsKHR transform;
|
||||
|
||||
VkSwapchainKHR swap_chain =VK_NULL_HANDLE;
|
||||
VkSwapchainKHR swap_chain =VK_NULL_HANDLE;
|
||||
VkSurfaceFormatKHR surface_format {};
|
||||
VkFormat depth_format =VK_FORMAT_UNDEFINED;
|
||||
|
||||
uint32_t color_count =0;
|
||||
uint32_t image_count =0;
|
||||
|
||||
Texture2D ** sc_color =nullptr;
|
||||
Texture2D * sc_depth =nullptr;
|
||||
|
||||
Framebuffer ** sc_fbo =nullptr;
|
||||
SwapchainImage * sc_image =nullptr;
|
||||
|
||||
public:
|
||||
|
||||
virtual ~Swapchain();
|
||||
};//struct Swapchain
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_VULKAN_SWAP_CHAIN_INCLUDE
|
||||
|
@@ -11,15 +11,23 @@ VK_NAMESPACE_BEGIN
|
||||
|
||||
BitmapData *LoadBitmapFromFile(const OSString &filename);
|
||||
|
||||
using TextureID=int;
|
||||
class TextureManager;
|
||||
|
||||
class Texture
|
||||
{
|
||||
protected:
|
||||
|
||||
TextureManager *manager;
|
||||
TextureID texture_id;
|
||||
|
||||
VkDevice device;
|
||||
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 +48,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;
|
||||
}
|
||||
|
||||
@@ -94,8 +103,8 @@ public:
|
||||
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;}
|
||||
|
68
inc/hgl/graph/module/GraphModule.h
Normal file
68
inc/hgl/graph/module/GraphModule.h
Normal file
@@ -0,0 +1,68 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/type/TypeInfo.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
class TextureManager;
|
||||
class RenderTargetManager;
|
||||
class RenderPassManager;
|
||||
|
||||
class GraphModule
|
||||
{
|
||||
RenderFramework *render_framework;
|
||||
|
||||
public:
|
||||
|
||||
RenderFramework * GetRenderFramework ()const{return render_framework;} ///<取得渲染框架
|
||||
GPUDevice * GetDevice (); ///<取得GPU设备
|
||||
VkDevice GetVkDevice ()const; ///<取得VkDevice
|
||||
const GPUPhysicalDevice * GetPhysicalDevice ()const; ///<取得物理设备
|
||||
GPUDeviceAttribute *GetDeviceAttribute ()const; ///<取得设备属性
|
||||
VkPipelineCache GetPipelineCache ()const; ///<取得PipelineCache
|
||||
|
||||
public:
|
||||
|
||||
virtual void OnResize(const VkExtent2D &){}; ///<窗口大小改变
|
||||
|
||||
public:
|
||||
|
||||
GraphModule(RenderFramework *rf){render_framework=rf;}
|
||||
virtual ~GraphModule()=default;
|
||||
|
||||
virtual const size_t GetTypeHash()const noexcept=0;
|
||||
virtual const AnsiString &GetName()const=0;
|
||||
};//class GraphModule
|
||||
|
||||
template<typename T,typename BASE> class GraphModuleInherit:public BASE
|
||||
{
|
||||
AnsiString manager_name;
|
||||
|
||||
public:
|
||||
|
||||
const size_t GetTypeHash()const noexcept override
|
||||
{
|
||||
return typeid(T).hash_code();
|
||||
}
|
||||
|
||||
const AnsiString &GetName()const override
|
||||
{
|
||||
return manager_name;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
GraphModuleInherit(RenderFramework *rf,const AnsiString &name):BASE(rf)
|
||||
{
|
||||
manager_name=name;
|
||||
}
|
||||
|
||||
virtual ~GraphModuleInherit()=default;
|
||||
};//class GraphModuleInherit
|
||||
|
||||
#define GRAPH_MODULE_CLASS(class_name) class class_name:public GraphModuleInherit<class_name,GraphModule>
|
||||
|
||||
#define GRAPH_MODULE_CONSTRUCT(class_name) class_name::class_name(RenderFramework *rf):GraphModuleInherit<class_name,GraphModule>(rf,#class_name)
|
||||
|
||||
VK_NAMESPACE_END
|
56
inc/hgl/graph/module/GraphModuleManager.h
Normal file
56
inc/hgl/graph/module/GraphModuleManager.h
Normal file
@@ -0,0 +1,56 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/type/Map.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
class GraphModuleManager
|
||||
{
|
||||
RenderFramework *render_framework;
|
||||
|
||||
protected:
|
||||
|
||||
List<GraphModule *> module_list;
|
||||
Map<size_t,GraphModule *> module_map;
|
||||
|
||||
public:
|
||||
|
||||
GraphModuleManager(RenderFramework *rf){render_framework=rf;}
|
||||
|
||||
virtual ~GraphModuleManager();
|
||||
|
||||
public:
|
||||
|
||||
RenderFramework * GetRenderFramework ()const{return render_framework;} ///<取得渲染框架
|
||||
GPUDevice * GetDevice ()const; ///<取得GPU设备
|
||||
|
||||
public:
|
||||
|
||||
GraphModule * Get(const size_t type_hash) {return GetObjectFromList(module_map,type_hash);} ///<取得指定类型的模块
|
||||
template<typename T>
|
||||
T * Get() {return((T *)Get(typeid(T).hash_code()));} ///<取得指定类型的模块
|
||||
|
||||
bool Contains(const size_t &type_hash)const {return module_map.ContainsKey(type_hash);} ///<确认是否包含指定类型的模块
|
||||
|
||||
template<typename T>
|
||||
bool Contains()const{return Contains(typeid(T).hash_code());} ///<确认是否包含指定类型的模块
|
||||
|
||||
bool Registry(GraphModule *); ///<注册一个模块
|
||||
bool Unregistry(GraphModule *); ///<注销一个模块
|
||||
|
||||
template<typename T>
|
||||
T *GetOrCreate() ///<注册一个模块
|
||||
{
|
||||
if(Contains<T>())
|
||||
return Get<T>();
|
||||
|
||||
T *result=new T(render_framework);
|
||||
|
||||
Registry(result);
|
||||
|
||||
return result;
|
||||
}
|
||||
};//class GraphModuleManager
|
||||
|
||||
VK_NAMESPACE_END
|
27
inc/hgl/graph/module/RenderModule.h
Normal file
27
inc/hgl/graph/module/RenderModule.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/module/GraphModule.h>
|
||||
#include<hgl/type/Size2.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* 渲染模块基类
|
||||
*/
|
||||
class RenderModule:public GraphModule
|
||||
{
|
||||
public:
|
||||
|
||||
NO_COPY_NO_MOVE(RenderModule)
|
||||
|
||||
using GraphModule::GraphModule;
|
||||
virtual ~RenderModule()=default;
|
||||
|
||||
virtual bool OnFrameRender(const double,RenderCmdBuffer *)=0; ///<帧绘制回调
|
||||
};//class RenderModule
|
||||
|
||||
#define RENDER_MODULE_CLASS(class_name) class class_name:public GraphModuleInherit<class_name,RenderModule>
|
||||
|
||||
#define RENDER_MODULE_CONSTRUCT(class_name) class_name::class_name(GPUDevice *dev):GraphModuleInherit<class_name,RenderModule>(dev,#class_name)
|
||||
|
||||
VK_NAMESPACE_END
|
@@ -1,32 +1,30 @@
|
||||
#pragma once
|
||||
#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::HashCode<128/8>;
|
||||
|
||||
inline util::Hash *CreateRenderPassHash()
|
||||
{
|
||||
return util::CreateHash(util::HASH::xxH3_128);
|
||||
}
|
||||
|
||||
class DeviceRenderPassManage
|
||||
GRAPH_MODULE_CLASS(RenderPassManager)
|
||||
{
|
||||
VkDevice device;
|
||||
VkPipelineCache pipeline_cache;
|
||||
|
||||
util::Hash *hash;
|
||||
|
||||
Map<RenderPassHASHCode,RenderPass *> RenderPassList;
|
||||
|
||||
private:
|
||||
|
||||
friend class GPUDevice;
|
||||
RenderPassManager(RenderFramework *);
|
||||
~RenderPassManager();
|
||||
|
||||
DeviceRenderPassManage(VkDevice,VkPipelineCache);
|
||||
~DeviceRenderPassManage();
|
||||
friend class GraphModuleManager;
|
||||
|
||||
private:
|
||||
|
||||
@@ -35,6 +33,9 @@ private:
|
||||
const List<VkSubpassDependency> &dependency,
|
||||
const RenderbufferInfo *);
|
||||
|
||||
public:
|
||||
|
||||
RenderPass * AcquireRenderPass( const RenderbufferInfo *,const uint subpass_count=2);
|
||||
};//class DeviceRenderPassManage
|
||||
};//class RenderPassManager
|
||||
|
||||
VK_NAMESPACE_END
|
33
inc/hgl/graph/module/RenderTargetManager.h
Normal file
33
inc/hgl/graph/module/RenderTargetManager.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/module/GraphModule.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
class TextureManager;
|
||||
class RenderPassManager;
|
||||
|
||||
GRAPH_MODULE_CLASS(RenderTargetManager)
|
||||
{
|
||||
TextureManager *tex_manager;
|
||||
RenderPassManager *rp_manager;
|
||||
|
||||
public:
|
||||
|
||||
RenderTargetManager(RenderFramework *,TextureManager *tm,RenderPassManager *rpm);
|
||||
virtual ~RenderTargetManager()=default;
|
||||
|
||||
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
|
46
inc/hgl/graph/module/SwapchainModule.h
Normal file
46
inc/hgl/graph/module/SwapchainModule.h
Normal file
@@ -0,0 +1,46 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/module/GraphModule.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
GRAPH_MODULE_CLASS(SwapchainModule)
|
||||
{
|
||||
TextureManager * tex_manager =nullptr;
|
||||
RenderTargetManager * rt_manager =nullptr;
|
||||
RenderPassManager * rp_manager =nullptr;
|
||||
|
||||
RenderPass * sc_render_pass =nullptr;
|
||||
|
||||
SwapchainRenderTarget * sc_render_target=nullptr;
|
||||
|
||||
protected:
|
||||
|
||||
bool CreateSwapchainFBO(Swapchain *);
|
||||
Swapchain *CreateSwapchain();
|
||||
bool CreateSwapchainRenderTarget();
|
||||
|
||||
public:
|
||||
|
||||
virtual void OnResize(const VkExtent2D &)override; ///<窗口大小改变
|
||||
|
||||
public:
|
||||
|
||||
SwapchainModule(RenderFramework *,TextureManager *tm,RenderTargetManager *rtm,RenderPassManager *rpm);
|
||||
virtual ~SwapchainModule();
|
||||
|
||||
// RenderCmdBuffer *BeginRender();
|
||||
|
||||
//void EndRender();
|
||||
|
||||
public:
|
||||
|
||||
RenderPass * GetRenderPass ()const{return sc_render_pass;}
|
||||
|
||||
bool GetSwapchainSize(VkExtent2D *)const;
|
||||
|
||||
SwapchainRenderTarget * GetRenderTarget ()const{return sc_render_target;}
|
||||
bool AcquireNextImage()const;
|
||||
};//class SwapchainModule:public GraphModule
|
||||
|
||||
VK_NAMESPACE_END
|
126
inc/hgl/graph/module/TextureManager.h
Normal file
126
inc/hgl/graph/module/TextureManager.h
Normal file
@@ -0,0 +1,126 @@
|
||||
#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
|
||||
|
||||
GRAPH_MODULE_CLASS(TextureManager)
|
||||
{
|
||||
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;
|
||||
|
||||
const TextureID Add(Texture *);
|
||||
const TextureID Add(Texture *,const OSString &);
|
||||
|
||||
public:
|
||||
|
||||
TextureManager(RenderFramework *rf);
|
||||
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 &);
|
||||
|
||||
public: //TileData
|
||||
|
||||
TileData *CreateTileData(const VkFormat video_format,const uint width,const uint height,const uint count); ///<创建一个Tile数据集
|
||||
|
||||
};//class TextureManager
|
||||
VK_NAMESPACE_END
|
0
inc/hgl/graph/module/VkModuleDebugUtil.h
Normal file
0
inc/hgl/graph/module/VkModuleDebugUtil.h
Normal file
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/mtl/StdMaterial.h>
|
||||
#include<hgl/graph/mtl/ShaderBuffer.h>
|
||||
#include<hgl/graph/mtl/ShaderBufferSource.h>
|
||||
#include<hgl/math/Vector.h>
|
||||
STD_MTL_NAMESPACE_BEGIN
|
||||
namespace blinnphong
|
||||
|
@@ -1,18 +0,0 @@
|
||||
#ifndef HGL_GRAPH_MTL_SHADER_BUFFER_INCLUDE
|
||||
#define HGL_GRAPH_MTL_SHADER_BUFFER_INCLUDE
|
||||
|
||||
#include<hgl/type/DataType.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
struct ShaderBufferSource
|
||||
{
|
||||
const char *struct_name;
|
||||
const char *name;
|
||||
const char *codes;
|
||||
};
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
#endif//HGL_GRAPH_MTL_SHADER_BUFFER_INCLUDE
|
11
inc/hgl/graph/mtl/ShaderBufferSource.h
Normal file
11
inc/hgl/graph/mtl/ShaderBufferSource.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
namespace hgl::graph
|
||||
{
|
||||
struct ShaderBufferSource
|
||||
{
|
||||
const char *struct_name;
|
||||
const char *name;
|
||||
const char *codes;
|
||||
};
|
||||
}//namespace hgl::graph
|
@@ -2,58 +2,55 @@
|
||||
|
||||
#include<hgl/type/String.h>
|
||||
|
||||
#define STD_MTL_NAMESPACE_BEGIN namespace hgl{namespace graph{namespace mtl{
|
||||
#define STD_MTL_NAMESPACE_END }}}
|
||||
#define STD_MTL_NAMESPACE_BEGIN namespace hgl::graph::mtl{
|
||||
#define STD_MTL_NAMESPACE_END }
|
||||
|
||||
#define STD_MTL_NAMESPACE hgl::graph::mtl
|
||||
#define STD_MTL_NAMESPACE_USING using namespace STD_MTL_NAMESPACE;
|
||||
|
||||
#define STD_MTL_FUNC_NAMESPACE_BEGIN namespace hgl{namespace graph{namespace mtl{namespace func{
|
||||
#define STD_MTL_FUNC_NAMESPACE_END }}}}
|
||||
#define STD_MTL_FUNC_NAMESPACE_BEGIN namespace hgl::graph::mtl::func{
|
||||
#define STD_MTL_FUNC_NAMESPACE_END }
|
||||
|
||||
#define STD_MTL_FUNC_NAMESPACE hgl::graph::mtl::func
|
||||
#define STD_MTL_FUNC_NAMESPACE_USING using namespace STD_MTL_FUNC_NAMESPACE;
|
||||
|
||||
namespace hgl
|
||||
namespace hgl::graph
|
||||
{
|
||||
namespace graph
|
||||
class ShaderCreateInfoVertex;
|
||||
class ShaderCreateInfoGeometry;
|
||||
class ShaderCreateInfoFragment;
|
||||
|
||||
namespace mtl
|
||||
{
|
||||
class ShaderCreateInfoVertex;
|
||||
class ShaderCreateInfoGeometry;
|
||||
class ShaderCreateInfoFragment;
|
||||
|
||||
namespace mtl
|
||||
namespace func
|
||||
{
|
||||
namespace func
|
||||
{
|
||||
}//namespace func
|
||||
}//namespace func
|
||||
|
||||
class MaterialCreateInfo;
|
||||
struct MaterialCreateConfig;
|
||||
class MaterialCreateInfo;
|
||||
struct MaterialCreateConfig;
|
||||
|
||||
class StdMaterial
|
||||
{
|
||||
protected:
|
||||
class StdMaterial
|
||||
{
|
||||
protected:
|
||||
|
||||
MaterialCreateInfo *mci;
|
||||
MaterialCreateInfo *mci;
|
||||
|
||||
protected:
|
||||
protected:
|
||||
|
||||
virtual bool BeginCustomShader(){return true;/*some work before create shader*/};
|
||||
virtual bool BeginCustomShader(){return true;/*some work before create shader*/};
|
||||
|
||||
virtual bool CustomVertexShader(ShaderCreateInfoVertex *)=0;
|
||||
virtual bool CustomGeometryShader(ShaderCreateInfoGeometry *){return false;}
|
||||
virtual bool CustomFragmentShader(ShaderCreateInfoFragment *)=0;
|
||||
virtual bool CustomVertexShader(ShaderCreateInfoVertex *)=0;
|
||||
virtual bool CustomGeometryShader(ShaderCreateInfoGeometry *){return false;}
|
||||
virtual bool CustomFragmentShader(ShaderCreateInfoFragment *)=0;
|
||||
|
||||
virtual bool EndCustomShader(){return true;/*some work after create shader*/};
|
||||
virtual bool EndCustomShader(){return true;/*some work after create shader*/};
|
||||
|
||||
public:
|
||||
public:
|
||||
|
||||
StdMaterial(const MaterialCreateConfig *);
|
||||
virtual ~StdMaterial()=default;
|
||||
StdMaterial(const MaterialCreateConfig *);
|
||||
virtual ~StdMaterial()=default;
|
||||
|
||||
virtual MaterialCreateInfo *Create();
|
||||
};//class StdMaterial
|
||||
}//namespace mtl
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
virtual MaterialCreateInfo *Create();
|
||||
};//class StdMaterial
|
||||
}//namespace mtl
|
||||
}//namespace hgl::graph
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/mtl/StdMaterial.h>
|
||||
#include<hgl/graph/mtl/ShaderBuffer.h>
|
||||
#include<hgl/graph/mtl/ShaderBufferSource.h>
|
||||
|
||||
STD_MTL_NAMESPACE_BEGIN
|
||||
constexpr const ShaderBufferSource SBS_ViewportInfo=
|
||||
|
@@ -1,24 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/mtl/StdMaterial.h>
|
||||
#include<hgl/graph/mtl/ShaderBuffer.h>
|
||||
|
||||
STD_MTL_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* 所有UBO的基类,它即向生成器提供代码,也可以为渲染器提供数据
|
||||
*/
|
||||
class UniformBuffer
|
||||
{
|
||||
private:
|
||||
|
||||
ShaderBufferSource *sbs;
|
||||
|
||||
public:
|
||||
|
||||
virtual const AnsiString &GetStructName ()const{return sbs->struct_name;} ///<取得结构名称
|
||||
virtual const AnsiString &GetDefaultValueName ()const{return sbs->name;} ///<取得默认变量名称
|
||||
virtual const AnsiString &GetShaderCodes ()const{return sbs->codes;} ///<取得Shader代码
|
||||
};//class UniformBuffer
|
||||
|
||||
STD_MTL_NAMESPACE_END
|
@@ -7,10 +7,10 @@
|
||||
#include<hgl/shadergen/ShaderCreateInfoMap.h>
|
||||
#include<hgl/graph/RenderTargetOutputConfig.h>
|
||||
#include<hgl/graph/mtl/MaterialConfig.h>
|
||||
#include<hgl/graph/mtl/ShaderBuffer.h>
|
||||
#include<hgl/graph/mtl/ShaderBufferSource.h>
|
||||
#include<hgl/graph/VKSamplerType.h>
|
||||
|
||||
namespace hgl{namespace graph
|
||||
namespace hgl::graph
|
||||
{
|
||||
struct GPUDeviceAttribute;
|
||||
struct UBODescriptor;
|
||||
@@ -92,5 +92,4 @@ namespace hgl{namespace graph
|
||||
bool CreateShader();
|
||||
};//class MaterialCreateInfo
|
||||
}//namespace mtl
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
}//namespace hgl::graph
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/VKShaderDescriptorSet.h>
|
||||
#include<hgl/graph/mtl/ShaderBuffer.h>
|
||||
#include<hgl/graph/mtl/ShaderBufferSource.h>
|
||||
#include<hgl/type/Map.h>
|
||||
|
||||
namespace hgl{namespace graph{
|
||||
|
@@ -1,6 +1,7 @@
|
||||
add_subdirectory(Util)
|
||||
add_subdirectory(ShaderGen)
|
||||
add_subdirectory(SceneGraph)
|
||||
add_subdirectory(Work)
|
||||
#add_subdirectory(Tools)
|
||||
add_subdirectory(GUI)
|
||||
add_subdirectory(JoltPhysics/Build)
|
||||
#add_subdirectory(GUI)
|
||||
#add_subdirectory(JoltPhysics/Build)
|
||||
|
@@ -37,7 +37,7 @@ namespace hgl
|
||||
bool ThemeForm::BeginRender()
|
||||
{
|
||||
if(!cmd_buf->Begin())return(false);
|
||||
if(!cmd_buf->BindFramebuffer(render_target->GetRenderPass(),render_target->GetFramebuffer()))return(false);
|
||||
if(!cmd_buf->BindRenderTarget(render_target->GetRenderPass(),render_target->GetFramebuffer()))return(false);
|
||||
|
||||
cmd_buf->SetClearColor(0,0,0,0,1.0f);
|
||||
|
||||
|
@@ -31,7 +31,7 @@ SET(GEOMETRY_FILES ${SG_INCLUDE_PATH}/InlineGeometry.h
|
||||
#${SG_INCLUDE_PATH}/Mesh.h
|
||||
#${SG_INCLUDE_PATH}/Spline.h
|
||||
InlineGeometry.cpp
|
||||
#Mesh.cpp
|
||||
#Mesh.cpp
|
||||
)
|
||||
|
||||
SOURCE_GROUP("Geometry" FILES ${GEOMETRY_FILES})
|
||||
@@ -41,28 +41,60 @@ SET(LIGHT_FILES ${SG_INCLUDE_PATH}/Light.h
|
||||
|
||||
source_group("Light" FILES ${LIGHT_FILES})
|
||||
|
||||
SET(SCENE_GRAPH_HEADER ${SG_INCLUDE_PATH}/SceneManager.h
|
||||
${SG_INCLUDE_PATH}/SceneNodeAttributes.h
|
||||
${SG_INCLUDE_PATH}/SceneNode.h
|
||||
${SG_INCLUDE_PATH}/ShadowPolicy.h
|
||||
${SG_INCLUDE_PATH}/RenderNode.h
|
||||
${SG_INCLUDE_PATH}/SceneMatrix.h
|
||||
${SG_INCLUDE_PATH}/SceneOrient.h
|
||||
SET(SGM_HEADER_PATH ${SG_INCLUDE_PATH}/module)
|
||||
SET(SGM_SOURCE_PATH module)
|
||||
|
||||
SET(GRAPH_MODULE_FILES ${SGM_HEADER_PATH}/GraphModule.h
|
||||
${SGM_HEADER_PATH}/GraphModuleManager.h
|
||||
${SGM_HEADER_PATH}/RenderPassManager.h
|
||||
${SGM_HEADER_PATH}/TextureManager.h
|
||||
${SGM_HEADER_PATH}/RenderTargetManager.h
|
||||
|
||||
${SGM_HEADER_PATH}/RenderModule.h
|
||||
${SGM_HEADER_PATH}/SwapchainModule.h
|
||||
|
||||
${SGM_SOURCE_PATH}/GraphModule.cpp
|
||||
${SGM_SOURCE_PATH}/GraphModuleManager.cpp
|
||||
${SGM_SOURCE_PATH}/RenderPassManager.cpp
|
||||
${SGM_SOURCE_PATH}/TextureManager.cpp
|
||||
${SGM_SOURCE_PATH}/RenderTargetManager.cpp
|
||||
|
||||
${SGM_SOURCE_PATH}/SwapChainModule.cpp
|
||||
)
|
||||
|
||||
source_group("Framework\\Module" FILES ${GRAPH_MODULE_FILES})
|
||||
|
||||
SET(GRAPH_FRAMEWORK_FILES ${SG_INCLUDE_PATH}/RenderFramework.h
|
||||
RenderFramework.cpp)
|
||||
|
||||
source_group("Framework" FILES ${GRAPH_FRAMEWORK_FILES})
|
||||
|
||||
SET(SG_SCENE_SOURCE ${SG_INCLUDE_PATH}/SceneWorld.h
|
||||
${SG_INCLUDE_PATH}/SceneNodeAttributes.h
|
||||
${SG_INCLUDE_PATH}/SceneNode.h
|
||||
${SG_INCLUDE_PATH}/SceneMatrix.h
|
||||
${SG_INCLUDE_PATH}/SceneOrient.h
|
||||
Scene/SceneNode.cpp
|
||||
Scene/SceneOrient.cpp
|
||||
Scene/SceneMatrix.cpp
|
||||
Scene/SceneWorld.cpp
|
||||
)
|
||||
|
||||
SET(SG_RENDER_SOURCE ${SG_INCLUDE_PATH}/RenderNode.h
|
||||
${SG_INCLUDE_PATH}/RenderList.h
|
||||
${SG_INCLUDE_PATH}/MaterialRenderList.h
|
||||
${SG_INCLUDE_PATH}/MaterialRenderMap.h
|
||||
# ${SG_INCLUDE_PATH}/ShadowPolicy.h
|
||||
render/RenderList.cpp
|
||||
render/MaterialRenderList.cpp
|
||||
render/RenderAssignBuffer.h
|
||||
render/RenderAssignBuffer.cpp
|
||||
)
|
||||
|
||||
SET(SCENE_GRAPH_SOURCE RenderList.cpp
|
||||
MaterialRenderList.cpp
|
||||
RenderAssignBuffer.h
|
||||
RenderAssignBuffer.cpp
|
||||
SceneNode.cpp
|
||||
SceneOrient.cpp
|
||||
SceneMatrix.cpp
|
||||
)
|
||||
SOURCE_GROUP("Scene Graph\\Scene" FILES ${SG_SCENE_SOURCE})
|
||||
SOURCE_GROUP("Scene Graph\\Render" FILES ${SG_RENDER_SOURCE})
|
||||
|
||||
SOURCE_GROUP("Scene Graph" FILES ${SCENE_GRAPH_HEADER} ${SCENE_GRAPH_SOURCE})
|
||||
SET(SCENE_GRAPH_FILES ${SG_SCENE_SOURCE} ${SG_RENDER_SOURCE})
|
||||
|
||||
SET(STATIC_MESH_HEADER_FILES ${SG_INCLUDE_PATH}/StaticMesh.h
|
||||
${SG_INCLUDE_PATH}/StaticMeshLODPolicy.h)
|
||||
@@ -161,11 +193,7 @@ SET(VK_DEVICE_SOURCE Vulkan/VKDeviceMemory.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/VKDeviceFramebuffer.cpp)
|
||||
|
||||
SET(VK_PHYSICAL_DEVICE_SOURCE ${SG_INCLUDE_PATH}/VKPhysicalDevice.h
|
||||
Vulkan/VKPhysicalDevice.cpp
|
||||
@@ -223,7 +251,6 @@ SET(VK_RENDER_CONTEXT_SOURCE ${SG_INCLUDE_PATH}/VKRenderContext.h
|
||||
SET(VK_RENDER_PASS_SOURCE ${SG_INCLUDE_PATH}/VKFramebuffer.h
|
||||
${SG_INCLUDE_PATH}/VKPipeline.h
|
||||
${SG_INCLUDE_PATH}/VKRenderPass.h
|
||||
${SG_INCLUDE_PATH}/VKRenderTarget.h
|
||||
${SG_INCLUDE_PATH}/VKSwapchain.h
|
||||
${SG_INCLUDE_PATH}/VKSemaphore.h
|
||||
${SG_INCLUDE_PATH}/VKFence.h
|
||||
@@ -235,13 +262,23 @@ SET(VK_RENDER_PASS_SOURCE ${SG_INCLUDE_PATH}/VKFramebuffer.h
|
||||
Vulkan/VKPipelineCache.cpp
|
||||
#Vulkan/VKSubpass.cpp
|
||||
Vulkan/VKRenderPass.cpp
|
||||
Vulkan/VKRenderTarget.cpp
|
||||
Vulkan/VKSwapchainRenderTarget.cpp
|
||||
Vulkan/VKSwapchain.cpp
|
||||
)
|
||||
|
||||
SOURCE_GROUP("Vulkan\\Render Pass" FILES ${VK_RENDER_PASS_SOURCE})
|
||||
|
||||
SET(VK_RENDER_TARGET_SOURCE ${SG_INCLUDE_PATH}/VKRenderTarget.h
|
||||
${SG_INCLUDE_PATH}/VKRenderTargetData.h
|
||||
${SG_INCLUDE_PATH}/VKRenderTargetSingle.h
|
||||
${SG_INCLUDE_PATH}/VKRenderTargetMultiFrame.h
|
||||
${SG_INCLUDE_PATH}/VKRenderTargetSwapchain.h
|
||||
Vulkan/VKRenderTarget.cpp
|
||||
Vulkan/VKRenderTargetData.cpp
|
||||
Vulkan/VKSwapchainRenderTarget.cpp
|
||||
)
|
||||
|
||||
SOURCE_GROUP("Vulkan\\Render Target" FILES ${VK_RENDER_TARGET_SOURCE})
|
||||
|
||||
SOURCE_GROUP("Vulkan\\Render Context" FILES ${VK_RENDER_CONTEXT_SOURCE})
|
||||
|
||||
SET(VK_CMD_BUFFER_SOURCE ${SG_INCLUDE_PATH}/VKCommandBuffer.h
|
||||
@@ -272,17 +309,29 @@ ENDIF(WIN32)
|
||||
IF(UNIX)
|
||||
|
||||
IF(ANDROID)
|
||||
SET(VULKAN_SURFACE_SOURCE Vulkan/Platform/AndroidVulkan.cpp)
|
||||
SET(VULKAN_SURFACE_SOURCE Vulkan/platform/AndroidVulkan.cpp)
|
||||
ELSE()
|
||||
IF(APPLE)
|
||||
|
||||
|
||||
|
||||
IF(APPLE)
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL "iOS" OR CMAKE_OSX_SYSROOT MATCHES ".*iPhone.*")
|
||||
message(STATUS "Targeting iOS")
|
||||
set(VULKAN_SURFACE_SOURCE Vulkan/platform/iOSVulkan.cpp)
|
||||
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR CMAKE_OSX_SYSROOT MATCHES ".*MacOSX.*")
|
||||
message(STATUS "Targeting macOS")
|
||||
set(VULKAN_SURFACE_SOURCE Vulkan/platform/MacVulkan.cpp)
|
||||
else()
|
||||
message(FATAL_ERROR "Unknown Apple platform")
|
||||
endif()
|
||||
ELSE()
|
||||
|
||||
SET(VULKAN_SURFACE_SOURCE Vulkan/Platform/XCBVulkan.cpp)
|
||||
find_package(PkgConfig REQUIRED)
|
||||
pkg_check_modules(WAYLAND_CLIENT wayland-client)
|
||||
if(WAYLAND_CLIENT_FOUND)
|
||||
message(STATUS "Targeting Wayland")
|
||||
set(VULKAN_SURFACE_SOURCE Vulkan/platform/WaylandVulkan.cpp)
|
||||
else()
|
||||
message(STATUS "Targeting XCB")
|
||||
set(VULKAN_SURFACE_SOURCE Vulkan/platform/XCBVulkan.cpp)
|
||||
endif()
|
||||
ENDIF()
|
||||
|
||||
ENDIF()
|
||||
|
||||
ENDIF(UNIX)
|
||||
@@ -304,17 +353,20 @@ SET(VULKAN_RENDER_SOURCE ${VK_RR_SOURCE}
|
||||
${VK_TEXTURE_SOURCE}
|
||||
${VK_MATERIAL_SOURCE}
|
||||
${VK_RENDER_PASS_SOURCE}
|
||||
${VK_RENDER_TARGET_SOURCE}
|
||||
#${VK_RENDER_CONTEXT_SOURCE}
|
||||
${VK_CMD_BUFFER_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_FILES}
|
||||
${SG_PRIMITIVE_SOURCE}
|
||||
${GEOMETRY_FILES}
|
||||
${LIGHT_FILES}
|
||||
|
||||
${GRAPH_MODULE_FILES}
|
||||
${GRAPH_FRAMEWORK_FILES}
|
||||
|
||||
${SG_TEXTURE_SOURCE}
|
||||
${TILE_SOURCE}
|
||||
${SG_VDM_SOURCE}
|
||||
|
132
src/SceneGraph/RenderFramework.cpp
Normal file
132
src/SceneGraph/RenderFramework.cpp
Normal file
@@ -0,0 +1,132 @@
|
||||
#include<hgl/graph/RenderFramework.h>
|
||||
#include<hgl/graph/VKInstance.h>
|
||||
#include<hgl/graph/VKDeviceCreater.h>
|
||||
#include<hgl/graph/module/RenderPassManager.h>
|
||||
#include<hgl/graph/module/TextureManager.h>
|
||||
#include<hgl/graph/module/RenderTargetManager.h>
|
||||
#include<hgl/graph/module/SwapchainModule.h>
|
||||
#include<hgl/graph/module/RenderModule.h>
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
#include<hgl/graph/VKCommandBuffer.h>
|
||||
#include<hgl/log/Logger.h>
|
||||
#include<hgl/Time.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
bool InitShaderCompiler();
|
||||
void CloseShaderCompiler();
|
||||
|
||||
namespace
|
||||
{
|
||||
static int RENDER_FRAMEWORK_COUNT=0;
|
||||
|
||||
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(app_name,nullptr,&cili);
|
||||
}
|
||||
}//namespace
|
||||
|
||||
RenderFramework::RenderFramework(const OSString &an)
|
||||
{
|
||||
app_name=an;
|
||||
}
|
||||
|
||||
RenderFramework::~RenderFramework()
|
||||
{
|
||||
SAFE_CLEAR(render_resource)
|
||||
SAFE_CLEAR(module_manager)
|
||||
|
||||
--RENDER_FRAMEWORK_COUNT;
|
||||
|
||||
if(RENDER_FRAMEWORK_COUNT==0)
|
||||
{
|
||||
CloseShaderCompiler();
|
||||
}
|
||||
}
|
||||
|
||||
bool RenderFramework::Init(uint w,uint h)
|
||||
{
|
||||
if(RENDER_FRAMEWORK_COUNT==0)
|
||||
{
|
||||
if(!InitShaderCompiler())
|
||||
return(false);
|
||||
|
||||
logger::InitLogger(app_name);
|
||||
|
||||
InitNativeWindowSystem();
|
||||
}
|
||||
|
||||
++RENDER_FRAMEWORK_COUNT;
|
||||
|
||||
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);
|
||||
|
||||
win->Join(this);
|
||||
|
||||
module_manager=new GraphModuleManager(this);
|
||||
|
||||
rp_manager=module_manager->GetOrCreate<RenderPassManager>();
|
||||
|
||||
if(!rp_manager)
|
||||
return(false);
|
||||
|
||||
tex_manager=module_manager->GetOrCreate<TextureManager>();
|
||||
|
||||
if(!tex_manager)
|
||||
return(false);
|
||||
|
||||
rt_manager=new RenderTargetManager(this,tex_manager,rp_manager);
|
||||
module_manager->Registry(rt_manager);
|
||||
|
||||
sc_module=new SwapchainModule(this,tex_manager,rt_manager,rp_manager);
|
||||
module_manager->Registry(sc_module);
|
||||
|
||||
render_resource=new RenderResource(device);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void RenderFramework::OnResize(uint w,uint h)
|
||||
{
|
||||
VkExtent2D ext(w,h);
|
||||
|
||||
sc_module->OnResize(ext); //其实swapchain_module并不需要传递尺寸数据过去
|
||||
}
|
||||
|
||||
void RenderFramework::OnActive(bool)
|
||||
{
|
||||
}
|
||||
|
||||
void RenderFramework::OnClose()
|
||||
{
|
||||
}
|
||||
|
||||
VK_NAMESPACE_END
|
@@ -2,14 +2,15 @@
|
||||
#include<hgl/log/LogInfo.h>
|
||||
#include<hgl/graph/VKDevice.h>
|
||||
#include<hgl/graph/VKBuffer.h>
|
||||
#include<hgl/graph/module/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;
|
||||
tex_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=tex_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(!tex_manager->ChangeTexture2D(tile_texture,tile_buffer,commit_list))
|
||||
return -2;
|
||||
|
||||
const int result=commit_list.GetCount();
|
||||
|
@@ -1,11 +1,11 @@
|
||||
#include<hgl/graph/VKDebugUtils.h>
|
||||
#include<hgl/graph/VKDebugUtils.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
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 );
|
||||
|
@@ -169,6 +169,35 @@ namespace
|
||||
#undef OUTPUT_PHYSICAL_DEVICE_FEATURE
|
||||
}
|
||||
|
||||
void DebugOut(const VkPhysicalDeviceVulkan14Features &features)
|
||||
{
|
||||
std::cout<<"Vulkan 1.4 features"<<std::endl;
|
||||
|
||||
#define OUTPUT_PHYSICAL_DEVICE_FEATURE(name) std::cout<<std::setw(60)<<std::right<<#name<<": "<<(features.name?"true":"false")<<std::endl;
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(globalPriorityQuery)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(shaderSubgroupRotate)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(shaderSubgroupRotateClustered)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(shaderFloatControls2)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(shaderExpectAssume)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(rectangularLines)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(bresenhamLines)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(smoothLines)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(stippledRectangularLines)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(stippledBresenhamLines)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(stippledSmoothLines)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(vertexAttributeInstanceRateDivisor)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(vertexAttributeInstanceRateZeroDivisor)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(indexTypeUint8)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(dynamicRenderingLocalRead)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(maintenance5)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(maintenance6)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(pipelineProtectedAccess)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(pipelineRobustness)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(hostImageCopy)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(pushDescriptor)
|
||||
#undef OUTPUT_PHYSICAL_DEVICE_FEATURE
|
||||
}
|
||||
|
||||
void DebugOutVersion(uint32_t version)
|
||||
{
|
||||
std::cout<<VK_VERSION_MAJOR(version)<<"."<<VK_VERSION_MINOR(version)<<"."<<VK_VERSION_PATCH(version)<<std::endl;
|
||||
@@ -372,10 +401,14 @@ namespace
|
||||
|
||||
void OutputPhysicalDeviceCaps(const GPUPhysicalDevice *pd)
|
||||
{
|
||||
DebugOut(pd->GetProperties());
|
||||
const VkPhysicalDeviceProperties &pdp=pd->GetProperties();
|
||||
|
||||
DebugOut(pdp);
|
||||
DebugOut(pd->GetFeatures10());
|
||||
DebugOut(pd->GetFeatures11());
|
||||
DebugOut(pd->GetFeatures12());
|
||||
DebugOut(pd->GetFeatures13());
|
||||
|
||||
if(pdp.apiVersion>=VK_MAKE_VERSION(1,1,0))DebugOut(pd->GetFeatures11());
|
||||
if(pdp.apiVersion>=VK_MAKE_VERSION(1,2,0))DebugOut(pd->GetFeatures12());
|
||||
if(pdp.apiVersion>=VK_MAKE_VERSION(1,3,0))DebugOut(pd->GetFeatures13());
|
||||
if(pdp.apiVersion>=VK_MAKE_VERSION(1,4,0))DebugOut(pd->GetFeatures14());
|
||||
}
|
||||
VK_NAMESPACE_END
|
||||
|
@@ -1,12 +1,21 @@
|
||||
#include<hgl/graph/VKDevice.h>
|
||||
#include<hgl/graph/module/TextureManager.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,18 +23,7 @@ bool GPUDevice::CheckFormatSupport(const VkFormat format,const uint32_t bits,Ima
|
||||
return(fp.linearTilingFeatures&bits);
|
||||
}
|
||||
|
||||
void GPUDevice::Clear(TextureCreateInfo *tci)
|
||||
{
|
||||
if(!tci)return;
|
||||
|
||||
if(tci->image)DestroyImage(tci->image);
|
||||
if(tci->image_view)delete tci->image_view;
|
||||
if(tci->memory)delete tci->memory;
|
||||
|
||||
delete tci;
|
||||
}
|
||||
|
||||
bool GPUDevice::CopyBufferToImage(const CopyBufferToImageInfo *info,VkPipelineStageFlags destinationStage)
|
||||
bool TextureManager::CopyBufferToImage(const CopyBufferToImageInfo *info,VkPipelineStageFlags destinationStage)
|
||||
{
|
||||
if(!info)
|
||||
return(false);
|
||||
@@ -75,7 +73,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 +95,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);
|
||||
|
@@ -1,21 +1,37 @@
|
||||
#include<hgl/graph/VKDevice.h>
|
||||
#include<hgl/graph/module/TextureManager.h>
|
||||
#include<hgl/graph/VKImageCreateInfo.h>
|
||||
#include<hgl/graph/VKCommandBuffer.h>
|
||||
#include<hgl/graph/VKBuffer.h>
|
||||
#include<hgl/graph/VKTexture.h>
|
||||
#include<hgl/graph/VKDevice.h>
|
||||
#include"CopyBufferToImage.h"
|
||||
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);
|
||||
|
||||
Texture2D *tex=new Texture2D(this,AcquireID(),tex_data);
|
||||
|
||||
return(new Texture2D(attr->device,tex_data));
|
||||
Add(tex);
|
||||
|
||||
return tex;
|
||||
}
|
||||
|
||||
Texture2D *GPUDevice::CreateTexture2D(TextureCreateInfo *tci)
|
||||
void TextureManager::Clear(TextureCreateInfo *tci)
|
||||
{
|
||||
if(!tci)return;
|
||||
|
||||
if(tci->image)DestroyImage(tci->image);
|
||||
if(tci->image_view)delete tci->image_view;
|
||||
if(tci->memory)delete tci->memory;
|
||||
|
||||
delete tci;
|
||||
}
|
||||
|
||||
Texture2D *TextureManager::CreateTexture2D(TextureCreateInfo *tci)
|
||||
{
|
||||
if(!tci)return(nullptr);
|
||||
|
||||
@@ -39,11 +55,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 +72,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 +105,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 +114,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 +160,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 +200,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 +218,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
|
||||
@@ -211,8 +227,8 @@ bool GPUDevice::ChangeTexture2D(Texture2D *tex,void *data,const uint32_t size,co
|
||||
||scope.GetRight()>tex->GetWidth()
|
||||
||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);
|
||||
|
||||
|
@@ -1,21 +1,26 @@
|
||||
#include<hgl/graph/VKDevice.h>
|
||||
#include<hgl/graph/module/TextureManager.h>
|
||||
#include<hgl/graph/VKImageCreateInfo.h>
|
||||
#include<hgl/graph/VKCommandBuffer.h>
|
||||
#include<hgl/graph/VKBuffer.h>
|
||||
#include<hgl/graph/VKTexture.h>
|
||||
#include<hgl/graph/VKDevice.h>
|
||||
#include"CopyBufferToImage.h"
|
||||
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);
|
||||
|
||||
@@ -38,12 +43,12 @@ Texture2DArray *GPUDevice::CreateTexture2DArray(TextureCreateInfo *tci)
|
||||
Clear(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
|
||||
@@ -235,8 +240,8 @@ bool GPUDevice::ChangeTexture2DArray(Texture2DArray *tex,void *data,const uint32
|
||||
||scope.GetRight()>tex->GetWidth()
|
||||
||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);
|
||||
|
||||
|
@@ -1,20 +1,25 @@
|
||||
#include<hgl/graph/VKDevice.h>
|
||||
#include<hgl/graph/module/TextureManager.h>
|
||||
#include<hgl/graph/VKImageCreateInfo.h>
|
||||
#include<hgl/graph/VKCommandBuffer.h>
|
||||
#include<hgl/graph/VKBuffer.h>
|
||||
#include<hgl/graph/VKDevice.h>
|
||||
#include"BufferImageCopy2D.h"
|
||||
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);
|
||||
|
||||
@@ -33,12 +38,12 @@ TextureCube *GPUDevice::CreateTextureCube(TextureCreateInfo *tci)
|
||||
Clear(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) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>mipmaps<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҳ<EFBFBD><EFBFBD>Ҫmipmaps
|
||||
if(tci->target_mipmaps<=1) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>mipmaps<70><73><EFBFBD><EFBFBD>Ҳ<EFBFBD><D2B2>Ҫmipmaps
|
||||
{
|
||||
CommitTextureCube(tex,tci->buffer,tci->mipmap_zero_total_bytes,VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
||||
}
|
||||
else //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>mipmaps<70><73><EFBFBD><EFBFBD>
|
||||
else //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>mipmaps<70><73><EFBFBD><EFBFBD>
|
||||
{
|
||||
CommitTextureCubeMipmaps(tex,tci->buffer,tci->extent,tci->mipmap_zero_total_bytes);
|
||||
}
|
||||
}
|
||||
else
|
||||
if(tci->origin_mipmaps<=1) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>mipmaps<EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD>Ҫmipmaps
|
||||
if(tci->origin_mipmaps<=1) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>mipmaps<70><73><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD>Ҫ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)
|
||||
|
@@ -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/module/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
|
||||
|
@@ -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);
|
||||
|
@@ -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);
|
||||
|
@@ -3,24 +3,25 @@
|
||||
#include<hgl/graph/VKDevice.h>
|
||||
#include<hgl/graph/VKBuffer.h>
|
||||
#include<hgl/graph/TextureLoader.h>
|
||||
#include<hgl/graph/module/TextureManager.h>
|
||||
#include<hgl/graph/VKTextureCreateInfo.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
template<typename T,typename TL> class VkTextureLoader:public TL
|
||||
{
|
||||
protected:
|
||||
|
||||
GPUDevice *device;
|
||||
|
||||
TextureManager *tex_manager;
|
||||
DeviceBuffer *buf;
|
||||
T *tex;
|
||||
|
||||
bool auto_mipmaps;
|
||||
|
||||
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;
|
||||
@@ -38,8 +39,8 @@ 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 +76,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();
|
||||
|
@@ -6,6 +6,8 @@ GPUCmdBuffer::GPUCmdBuffer(const GPUDeviceAttribute *attr,VkCommandBuffer cb)
|
||||
{
|
||||
dev_attr=attr;
|
||||
cmd_buf=cb;
|
||||
|
||||
cmd_begin=false;
|
||||
}
|
||||
|
||||
GPUCmdBuffer::~GPUCmdBuffer()
|
||||
@@ -22,6 +24,7 @@ bool GPUCmdBuffer::Begin()
|
||||
if(vkBeginCommandBuffer(cmd_buf, &cmd_buf_info)!=VK_SUCCESS)
|
||||
return(false);
|
||||
|
||||
cmd_begin=true;
|
||||
return(true);
|
||||
}
|
||||
|
||||
|
@@ -5,6 +5,7 @@
|
||||
#include<hgl/graph/VKDeviceAttribute.h>
|
||||
#include<hgl/graph/VKPhysicalDevice.h>
|
||||
#include<hgl/graph/VKIndexBuffer.h>
|
||||
#include<hgl/graph/VKRenderTarget.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
RenderCmdBuffer::RenderCmdBuffer(const GPUDeviceAttribute *attr,VkCommandBuffer cb):GPUCmdBuffer(attr,cb)
|
||||
@@ -15,7 +16,6 @@ RenderCmdBuffer::RenderCmdBuffer(const GPUDeviceAttribute *attr,VkCommandBuffer
|
||||
hgl_zero(render_area);
|
||||
hgl_zero(viewport);
|
||||
|
||||
fbo=nullptr;
|
||||
pipeline_layout=VK_NULL_HANDLE;
|
||||
}
|
||||
|
||||
@@ -25,13 +25,8 @@ RenderCmdBuffer::~RenderCmdBuffer()
|
||||
hgl_free(clear_values);
|
||||
}
|
||||
|
||||
void RenderCmdBuffer::SetFBO(Framebuffer *fb)
|
||||
void RenderCmdBuffer::SetClear()
|
||||
{
|
||||
if(fbo==fb)return;
|
||||
|
||||
fbo=fb;
|
||||
cv_count=fbo->GetAttachmentCount();
|
||||
|
||||
if(cv_count>0)
|
||||
{
|
||||
clear_values=hgl_align_realloc<VkClearValue>(clear_values,cv_count);
|
||||
@@ -44,11 +39,6 @@ void RenderCmdBuffer::SetFBO(Framebuffer *fb)
|
||||
hgl_free(clear_values);
|
||||
clear_values=nullptr;
|
||||
}
|
||||
|
||||
render_area.offset.x=0;
|
||||
render_area.offset.y=0;
|
||||
render_area.extent.width=0;
|
||||
render_area.extent.height=0;
|
||||
}
|
||||
|
||||
void RenderCmdBuffer::SetRenderArea(const VkExtent2D &ext2d)
|
||||
@@ -58,18 +48,19 @@ void RenderCmdBuffer::SetRenderArea(const VkExtent2D &ext2d)
|
||||
render_area.extent=ext2d;
|
||||
}
|
||||
|
||||
bool RenderCmdBuffer::BindFramebuffer(RenderPass *rp,Framebuffer *fb)
|
||||
bool RenderCmdBuffer::BindFramebuffer(Framebuffer *fbo)
|
||||
{
|
||||
if(!rp||!fb)return(false);
|
||||
if(!fbo)return(false);
|
||||
|
||||
SetFBO(fb);
|
||||
cv_count=fbo->GetAttachmentCount();
|
||||
SetClear();
|
||||
|
||||
render_area.offset.x=0;
|
||||
render_area.offset.y=0;
|
||||
render_area.extent=fb->GetExtent();
|
||||
render_area.extent=fbo->GetExtent();
|
||||
|
||||
rp_begin.renderPass = rp->GetVkRenderPass();
|
||||
rp_begin.framebuffer = *fb;
|
||||
rp_begin.renderPass = *fbo->GetRenderPass();
|
||||
rp_begin.framebuffer = *fbo;
|
||||
rp_begin.renderArea = render_area;
|
||||
rp_begin.clearValueCount = cv_count;
|
||||
rp_begin.pClearValues = clear_values;
|
||||
@@ -100,6 +91,9 @@ bool RenderCmdBuffer::BindDescriptorSets(Material *mtl)
|
||||
{
|
||||
if(!mtl)return(false);
|
||||
|
||||
if(desc_binding)
|
||||
desc_binding->Bind(mtl);
|
||||
|
||||
{
|
||||
uint32_t count=0;
|
||||
|
||||
|
@@ -73,7 +73,7 @@ void DescriptorSet::Clear()
|
||||
image_list.Clear();
|
||||
wds_list.Clear();
|
||||
binded_sets.Clear();
|
||||
is_dirty=true;
|
||||
is_dirty=false;
|
||||
}
|
||||
|
||||
bool DescriptorSet::BindUBO(const int binding,const DeviceBuffer *buf,bool dynamic)
|
||||
@@ -191,6 +191,6 @@ void DescriptorSet::Update()
|
||||
if(wds_list.GetCount()>0)
|
||||
vkUpdateDescriptorSets(device,wds_list.GetCount(),wds_list.GetData(),0,nullptr);
|
||||
|
||||
is_dirty=false;
|
||||
Clear();
|
||||
}
|
||||
VK_NAMESPACE_END
|
||||
|
@@ -1,55 +1,18 @@
|
||||
#include<hgl/graph/VKDevice.h>
|
||||
#include<hgl/type/Pair.h>
|
||||
#include<hgl/graph/VKSemaphore.h>
|
||||
#include<hgl/graph/VKTexture.h>
|
||||
#include<hgl/graph/VKImageView.h>
|
||||
#include<hgl/graph/VKPipeline.h>
|
||||
#include<hgl/graph/VKCommandBuffer.h>
|
||||
#include<hgl/graph/VKRenderPass.h>
|
||||
#include<hgl/graph/VKFramebuffer.h>
|
||||
#include<hgl/graph/VKDescriptorSet.h>
|
||||
#include<hgl/graph/VKDeviceRenderPassManage.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
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)
|
||||
|
@@ -1,4 +1,7 @@
|
||||
#include<hgl/graph/VKDevice.h>
|
||||
#include<hgl/graph/module/RenderTargetManager.h>
|
||||
#include<hgl/graph/VKRenderPass.h>
|
||||
#include<hgl/graph/VKImageView.h>
|
||||
#include<hgl/graph/VKFramebuffer.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
VkFramebuffer CreateVulkanFramebuffer(VkDevice device,RenderPass *rp,const VkExtent2D &extent,VkImageView *attachments,const uint attachmentCount)
|
||||
@@ -20,7 +23,7 @@ VkFramebuffer CreateVulkanFramebuffer(VkDevice device,RenderPass *rp,const VkExt
|
||||
return fb;
|
||||
}
|
||||
|
||||
Framebuffer *GPUDevice::CreateFBO(RenderPass *rp,ImageView **color_list,const uint color_count,ImageView *depth)
|
||||
Framebuffer *RenderTargetManager::CreateFBO(RenderPass *rp,ImageView **color_list,const uint color_count,ImageView *depth)
|
||||
{
|
||||
uint att_count=color_count;
|
||||
|
||||
@@ -70,15 +73,15 @@ Framebuffer *GPUDevice::CreateFBO(RenderPass *rp,ImageView **color_list,const ui
|
||||
extent.height=color_list[0]->GetExtent().height;
|
||||
}
|
||||
|
||||
VkFramebuffer fbo=CreateVulkanFramebuffer(GetDevice(),rp,extent,attachments,att_count);
|
||||
VkFramebuffer fbo=CreateVulkanFramebuffer(GetVkDevice(),rp,extent,attachments,att_count);
|
||||
|
||||
if(!fbo)
|
||||
return(nullptr);
|
||||
|
||||
return(new Framebuffer(GetDevice(),fbo,extent,rp->GetVkRenderPass(),color_count,depth));
|
||||
return(new Framebuffer(GetVkDevice(),fbo,extent,rp,color_count,depth));
|
||||
}
|
||||
//
|
||||
//Framebuffer *GPUDevice::CreateFBO(RenderPass *rp,List<ImageView *> &color,ImageView *depth)
|
||||
//Framebuffer *RenderTargetManager::CreateFBO(RenderPass *rp,List<ImageView *> &color,ImageView *depth)
|
||||
//{
|
||||
// if(!rp)return(nullptr);
|
||||
//
|
||||
@@ -89,7 +92,7 @@ Framebuffer *GPUDevice::CreateFBO(RenderPass *rp,ImageView **color_list,const ui
|
||||
// return CreateFBO(rp,color.GetData(),color.GetCount(),depth);
|
||||
//}
|
||||
|
||||
Framebuffer *GPUDevice::CreateFBO(RenderPass *rp,ImageView *color,ImageView *depth)
|
||||
Framebuffer *RenderTargetManager::CreateFBO(RenderPass *rp,ImageView *color,ImageView *depth)
|
||||
{
|
||||
if(!rp)return(nullptr);
|
||||
if(!color&&!depth)return(nullptr);
|
||||
@@ -97,7 +100,7 @@ Framebuffer *GPUDevice::CreateFBO(RenderPass *rp,ImageView *color,ImageView *dep
|
||||
return CreateFBO(rp,&color,1,depth);
|
||||
}
|
||||
|
||||
Framebuffer *GPUDevice::CreateFBO(RenderPass *rp,ImageView *iv)
|
||||
Framebuffer *RenderTargetManager::CreateFBO(RenderPass *rp,ImageView *iv)
|
||||
{
|
||||
if(!rp)return(nullptr);
|
||||
if(!iv)return(nullptr);
|
||||
|
@@ -1,8 +1,8 @@
|
||||
#include<hgl/graph/VKDevice.h>
|
||||
#include<hgl/graph/module/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,16 @@ 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);
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
void GPUDevice::DestroyImage(VkImage img)
|
||||
void TextureManager::DestroyImage(VkImage img)
|
||||
{
|
||||
if(img==VK_NULL_HANDLE)return;
|
||||
|
||||
vkDestroyImage(attr->device,img,nullptr);
|
||||
vkDestroyImage(GetVkDevice(),img,nullptr);
|
||||
}
|
||||
VK_NAMESPACE_END
|
||||
|
@@ -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
|
@@ -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
|
@@ -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
|
@@ -7,7 +7,7 @@
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
Framebuffer::Framebuffer(VkDevice dev,VkFramebuffer fb,const VkExtent2D &ext,VkRenderPass rp,uint32_t cc,bool depth)
|
||||
Framebuffer::Framebuffer(VkDevice dev,VkFramebuffer fb,const VkExtent2D &ext,RenderPass *rp,uint32_t cc,bool depth)
|
||||
{
|
||||
device=dev;
|
||||
frame_buffer=fb;
|
||||
|
@@ -20,7 +20,7 @@ VulkanInstance *CreateInstance(const AnsiString &app_name,VKDebugOut *out,Create
|
||||
app_info.applicationVersion = 1;
|
||||
app_info.pEngineName = "CMGameEngine/ULRE";
|
||||
app_info.engineVersion = 1;
|
||||
app_info.apiVersion = VK_API_VERSION_1_3;
|
||||
app_info.apiVersion = VK_API_VERSION_1_4;
|
||||
|
||||
ext_list.Add(VK_KHR_SURFACE_EXTENSION_NAME);
|
||||
ext_list.Add(HGL_VK_SURFACE_EXTENSION_NAME); //此宏在VKSurfaceExtensionName.h中定义
|
||||
|
@@ -64,6 +64,7 @@ GPUPhysicalDevice::GPUPhysicalDevice(VkInstance inst,VkPhysicalDevice pd)
|
||||
hgl_zero(features11);
|
||||
hgl_zero(features12);
|
||||
hgl_zero(features13);
|
||||
hgl_zero(features14);
|
||||
|
||||
auto func=(PFN_vkGetPhysicalDeviceFeatures2KHR)vkGetInstanceProcAddr(inst,"vkGetPhysicalDeviceFeatures2KHR");
|
||||
|
||||
@@ -81,7 +82,10 @@ 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=&features14;
|
||||
|
||||
features14.sType=VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_4_FEATURES;
|
||||
features14.pNext=nullptr;
|
||||
|
||||
func(physical_device,&features2);
|
||||
|
||||
@@ -97,6 +101,7 @@ GPUPhysicalDevice::GPUPhysicalDevice(VkInstance inst,VkPhysicalDevice pd)
|
||||
hgl_zero(properties11);
|
||||
hgl_zero(properties12);
|
||||
hgl_zero(properties13);
|
||||
hgl_zero(properties14);
|
||||
|
||||
auto func=(PFN_vkGetPhysicalDeviceProperties2KHR)vkGetInstanceProcAddr(inst,"vkGetPhysicalDeviceProperties2KHR");
|
||||
|
||||
@@ -114,7 +119,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=&properties14;
|
||||
|
||||
properties14.sType=VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_4_PROPERTIES;
|
||||
properties14.pNext=nullptr;
|
||||
|
||||
func(physical_device,&properties2);
|
||||
|
||||
@@ -163,7 +171,11 @@ GPUPhysicalDevice::GPUPhysicalDevice(VkInstance inst,VkPhysicalDevice pd)
|
||||
debug_queue_family_properties_out(debug_front.c_str(),queue_family_properties);
|
||||
}
|
||||
|
||||
support_u8_index=CheckExtensionSupport(VK_EXT_INDEX_TYPE_UINT8_EXTENSION_NAME);
|
||||
if(features14.indexTypeUint8)
|
||||
support_u8_index=true;
|
||||
else
|
||||
support_u8_index=CheckExtensionSupport(VK_EXT_INDEX_TYPE_UINT8_EXTENSION_NAME);
|
||||
|
||||
dynamic_state=CheckExtensionSupport(VK_EXT_EXTENDED_DYNAMIC_STATE_EXTENSION_NAME);
|
||||
}
|
||||
|
||||
|
@@ -1,5 +1,6 @@
|
||||
#include<hgl/graph/VKQueue.h>
|
||||
#include<hgl/graph/VKSemaphore.h>
|
||||
#include<hgl/graph/VKCommandBuffer.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
namespace
|
||||
@@ -66,6 +67,10 @@ bool DeviceQueue::Submit(const VkCommandBuffer *cmd_buf,const uint32_t cb_count,
|
||||
submit_info.pWaitSemaphores =nullptr;
|
||||
}
|
||||
|
||||
// wait 信号的意思是等待这个Image有效
|
||||
// signal 则是这个queue已执行完成,和fence功能类似。
|
||||
// 所以Wait信号一般是上一次的signal信号
|
||||
|
||||
if(complete_sem)
|
||||
{
|
||||
cs=*complete_sem;
|
||||
@@ -91,8 +96,13 @@ bool DeviceQueue::Submit(const VkCommandBuffer *cmd_buf,const uint32_t cb_count,
|
||||
return(result==VK_SUCCESS);
|
||||
}
|
||||
|
||||
bool DeviceQueue::Submit(const VkCommandBuffer &cmd_buf,Semaphore *wait_sem,Semaphore *complete_sem)
|
||||
bool DeviceQueue::Submit(GPUCmdBuffer *cmd_buf,Semaphore *wait_sem,Semaphore *complete_sem)
|
||||
{
|
||||
return Submit(&cmd_buf,1,wait_sem,complete_sem);
|
||||
if(cmd_buf->IsBegin())
|
||||
cmd_buf->End();
|
||||
|
||||
VkCommandBuffer vk_cmd=*cmd_buf;
|
||||
|
||||
return Submit(&vk_cmd,1,wait_sem,complete_sem);
|
||||
}
|
||||
VK_NAMESPACE_END
|
||||
|
@@ -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 U8String name=U8_TEXT("Tex2D:")+ToU8String(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
|
||||
|
@@ -1,66 +1,37 @@
|
||||
#include<hgl/graph/VKRenderTarget.h>
|
||||
#include<hgl/graph/VKDevice.h>
|
||||
#include<hgl/graph/VKSwapchain.h>
|
||||
#include<hgl/graph/VKCommandBuffer.h>
|
||||
#include<hgl/graph/VKSemaphore.h>
|
||||
#include<hgl/graph/VKFramebuffer.h>
|
||||
#include<hgl/graph/RenderFramework.h>
|
||||
#include<hgl/graph/VKBuffer.h>
|
||||
|
||||
#include<hgl/graph/mtl/UBOCommon.h> //未来UBO统合看能不能不引用
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
RenderTarget::RenderTarget(DeviceQueue *q,Semaphore *s)
|
||||
{
|
||||
queue=q;
|
||||
render_pass=nullptr;
|
||||
fbo=nullptr;
|
||||
|
||||
color_count=0;
|
||||
color_textures=nullptr;
|
||||
depth_texture=nullptr;
|
||||
render_complete_semaphore=s;
|
||||
GPUDevice *IRenderTarget::GetDevice ()const{return render_framework->GetDevice();}
|
||||
VkDevice IRenderTarget::GetVkDevice()const{return render_framework->GetDevice()->GetDevice();}
|
||||
|
||||
IRenderTarget::IRenderTarget(RenderFramework *rf,const VkExtent2D &ext):desc_binding(DescriptorSetType::RenderTarget)
|
||||
{
|
||||
render_framework=rf;
|
||||
|
||||
ubo_vp_info=GetDevice()->CreateUBO<UBOViewportInfo>();
|
||||
|
||||
desc_binding.AddUBO(mtl::SBS_ViewportInfo.name,*ubo_vp_info);
|
||||
|
||||
OnResize(ext);
|
||||
}
|
||||
|
||||
RenderTarget::RenderTarget(DeviceQueue *q,Semaphore *s,RenderPass *_rp,Framebuffer *_fb,Texture2D **ctl,const uint32_t cc,Texture2D *dt)
|
||||
IRenderTarget::~IRenderTarget()
|
||||
{
|
||||
queue=q;
|
||||
render_pass=_rp;
|
||||
fbo=_fb;
|
||||
|
||||
depth_texture=dt;
|
||||
|
||||
color_count=cc;
|
||||
if(color_count>0)
|
||||
{
|
||||
color_textures=new Texture2D *[color_count];
|
||||
hgl_cpy(color_textures,ctl,color_count);
|
||||
|
||||
extent.width=color_textures[0]->GetWidth();
|
||||
extent.height=color_textures[0]->GetHeight();
|
||||
}
|
||||
else
|
||||
{
|
||||
color_textures=nullptr;
|
||||
|
||||
if(depth_texture)
|
||||
{
|
||||
extent.width=depth_texture->GetWidth();
|
||||
extent.height=depth_texture->GetHeight();
|
||||
}
|
||||
}
|
||||
|
||||
render_complete_semaphore=s;
|
||||
SAFE_CLEAR(ubo_vp_info);
|
||||
}
|
||||
|
||||
RenderTarget::~RenderTarget()
|
||||
void IRenderTarget::OnResize(const VkExtent2D &ext)
|
||||
{
|
||||
SAFE_CLEAR(queue);
|
||||
SAFE_CLEAR(depth_texture);
|
||||
SAFE_CLEAR_OBJECT_ARRAY_OBJECT(color_textures,color_count);
|
||||
|
||||
SAFE_CLEAR(render_complete_semaphore);
|
||||
SAFE_CLEAR(fbo);
|
||||
extent=ext;
|
||||
|
||||
ubo_vp_info->data()->Set(ext.width,ext.height);
|
||||
|
||||
ubo_vp_info->Update();
|
||||
}
|
||||
|
||||
bool RenderTarget::Submit(RenderCmdBuffer *command_buffer,Semaphore *present_complete_semaphore)
|
||||
{
|
||||
return queue->Submit(*command_buffer,present_complete_semaphore,render_complete_semaphore);
|
||||
}
|
||||
VK_NAMESPACE_END
|
||||
VK_NAMESPACE_END
|
||||
|
44
src/SceneGraph/Vulkan/VKRenderTargetData.cpp
Normal file
44
src/SceneGraph/Vulkan/VKRenderTargetData.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
#include<hgl/graph/VKRenderTargetData.h>
|
||||
#include<hgl/graph/VKDevice.h>
|
||||
#include<hgl/graph/VKSemaphore.h>
|
||||
#include<hgl/graph/VKFramebuffer.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
bool RenderTargetData::Submit(Semaphore *wait_sem)
|
||||
{
|
||||
if(!queue||!cmd_buf||!render_complete_semaphore)
|
||||
return(false);
|
||||
|
||||
return queue->Submit(cmd_buf,wait_sem,render_complete_semaphore);
|
||||
}
|
||||
|
||||
RenderCmdBuffer *RenderTargetData::BeginRender(DescriptorBinding *db)
|
||||
{
|
||||
if(!cmd_buf)
|
||||
return(nullptr);
|
||||
|
||||
cmd_buf->Begin();
|
||||
cmd_buf->SetDescriptorBinding(db);
|
||||
cmd_buf->BindFramebuffer(fbo);
|
||||
return cmd_buf;
|
||||
}
|
||||
|
||||
void RenderTargetData::EndRender()
|
||||
{
|
||||
if(!cmd_buf)
|
||||
return;
|
||||
|
||||
cmd_buf->End();
|
||||
}
|
||||
|
||||
void RenderTargetData::Clear()
|
||||
{
|
||||
SAFE_CLEAR(queue);
|
||||
SAFE_CLEAR(render_complete_semaphore);
|
||||
SAFE_CLEAR(fbo);
|
||||
SAFE_CLEAR_OBJECT_ARRAY_OBJECT(color_textures,color_count);
|
||||
SAFE_CLEAR(depth_texture);
|
||||
}
|
||||
|
||||
VK_NAMESPACE_END
|
@@ -28,9 +28,12 @@ const int PrimitiveDataBuffer::compare(const PrimitiveDataBuffer &pdb)const
|
||||
{
|
||||
ptrdiff_t off;
|
||||
|
||||
off=&vdm-&pdb.vdm;
|
||||
if(off)
|
||||
return off;
|
||||
if(vdm&&pdb.vdm)
|
||||
{
|
||||
off=(ptrdiff_t)vdm-(ptrdiff_t)pdb.vdm;
|
||||
if(off)
|
||||
return off;
|
||||
}
|
||||
|
||||
off=vab_count-pdb.vab_count;
|
||||
if(off)
|
||||
|
@@ -1,12 +1,23 @@
|
||||
#include<hgl/graph/VKSwapchain.h>
|
||||
#include<hgl/graph/VKTexture.h>
|
||||
#include<hgl/graph/VKFramebuffer.h>
|
||||
#include<hgl/graph/VKCommandBuffer.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
SwapchainImage::~SwapchainImage()
|
||||
{
|
||||
delete cmd_buf;
|
||||
delete fbo;
|
||||
|
||||
if(depth)
|
||||
delete depth;
|
||||
|
||||
delete color;
|
||||
}
|
||||
|
||||
Swapchain::~Swapchain()
|
||||
{
|
||||
SAFE_CLEAR_OBJECT_ARRAY_OBJECT(sc_fbo,color_count);
|
||||
SAFE_CLEAR(sc_depth);
|
||||
SAFE_CLEAR_OBJECT_ARRAY_OBJECT(sc_color,color_count)
|
||||
SAFE_CLEAR_ARRAY(sc_image);
|
||||
|
||||
if(swap_chain)
|
||||
{
|
||||
@@ -14,6 +25,6 @@ Swapchain::~Swapchain()
|
||||
swap_chain=VK_NULL_HANDLE;
|
||||
}
|
||||
|
||||
color_count=0;
|
||||
image_count=0;
|
||||
}
|
||||
VK_NAMESPACE_END
|
||||
|
@@ -1,12 +1,11 @@
|
||||
#include<hgl/graph/VKRenderTarget.h>
|
||||
#include<hgl/graph/VKRenderTargetSwapchain.h>
|
||||
#include<hgl/graph/VKDevice.h>
|
||||
#include<hgl/graph/VKSemaphore.h>
|
||||
//#include<iostream>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
RTSwapchain::RTSwapchain(VkDevice dev,Swapchain *sc,DeviceQueue *q,Semaphore *rcs,Semaphore *pcs,RenderPass *rp):RenderTarget(q,rcs)
|
||||
SwapchainRenderTarget::SwapchainRenderTarget(RenderFramework *rf,Swapchain *sc,Semaphore *pcs,RenderTargetData *rtl):MultiFrameRenderTarget(rf,sc->image_count,rtl)
|
||||
{
|
||||
device=dev;
|
||||
|
||||
swapchain=sc;
|
||||
|
||||
present_info.waitSemaphoreCount = 0;
|
||||
@@ -14,64 +13,51 @@ RTSwapchain::RTSwapchain(VkDevice dev,Swapchain *sc,DeviceQueue *q,Semaphore *rc
|
||||
present_info.swapchainCount = 1;
|
||||
present_info.pResults = nullptr;
|
||||
present_info.pSwapchains = &(swapchain->swap_chain);
|
||||
|
||||
render_pass=rp;
|
||||
|
||||
extent=swapchain->extent;
|
||||
|
||||
current_frame=0;
|
||||
|
||||
present_complete_semaphore=pcs;
|
||||
}
|
||||
|
||||
RTSwapchain::~RTSwapchain()
|
||||
SwapchainRenderTarget::~SwapchainRenderTarget()
|
||||
{
|
||||
delete present_complete_semaphore;
|
||||
delete swapchain;
|
||||
}
|
||||
|
||||
int RTSwapchain::AcquireNextImage()
|
||||
bool SwapchainRenderTarget::NextFrame()
|
||||
{
|
||||
if(vkAcquireNextImageKHR(device,swapchain->swap_chain,UINT64_MAX,*(this->present_complete_semaphore),VK_NULL_HANDLE,¤t_frame)==VK_SUCCESS)
|
||||
return current_frame;
|
||||
|
||||
return -1;
|
||||
return(vkAcquireNextImageKHR(GetVkDevice(),
|
||||
swapchain->swap_chain,
|
||||
UINT64_MAX,
|
||||
*present_complete_semaphore,
|
||||
VK_NULL_HANDLE,
|
||||
¤t_frame)==VK_SUCCESS);
|
||||
}
|
||||
|
||||
bool RTSwapchain::PresentBackbuffer(VkSemaphore *wait_semaphores,const uint32_t count)
|
||||
bool SwapchainRenderTarget::Submit()
|
||||
{
|
||||
present_info.waitSemaphoreCount =count;
|
||||
present_info.pWaitSemaphores =wait_semaphores;
|
||||
RenderTargetData *rtd=rtd_list+current_frame;
|
||||
|
||||
if(!rtd->Submit(present_complete_semaphore))
|
||||
return(false);
|
||||
|
||||
DeviceQueue *queue=GetQueue();
|
||||
|
||||
VkSemaphore wait_semaphores=*rtd->render_complete_semaphore;
|
||||
|
||||
present_info.waitSemaphoreCount =1;
|
||||
present_info.pWaitSemaphores =&wait_semaphores;
|
||||
present_info.pImageIndices =¤t_frame;
|
||||
|
||||
VkResult result=queue->Present(&present_info);
|
||||
|
||||
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)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool RTSwapchain::PresentBackbuffer()
|
||||
{
|
||||
VkSemaphore sem=*render_complete_semaphore;
|
||||
|
||||
return this->PresentBackbuffer(&sem,1);
|
||||
}
|
||||
|
||||
bool RTSwapchain::Submit(VkCommandBuffer cb)
|
||||
{
|
||||
return queue->Submit(cb,present_complete_semaphore,render_complete_semaphore);
|
||||
}
|
||||
|
||||
bool RTSwapchain::Submit(VkCommandBuffer cb,Semaphore *pce)
|
||||
{
|
||||
return queue->Submit(cb,pce,render_complete_semaphore);
|
||||
}
|
||||
VK_NAMESPACE_END
|
||||
|
@@ -1,6 +1,7 @@
|
||||
#include<hgl/graph/VKTexture.h>
|
||||
#include<hgl/graph/VKImageView.h>
|
||||
#include<hgl/graph/VKMemory.h>
|
||||
#include<hgl/graph/module/TextureManager.h>
|
||||
VK_NAMESPACE_BEGIN
|
||||
Texture::~Texture()
|
||||
{
|
||||
@@ -14,7 +15,7 @@ Texture::~Texture()
|
||||
delete data->memory;
|
||||
|
||||
if(data->image)
|
||||
vkDestroyImage(device,data->image,nullptr);
|
||||
vkDestroyImage(manager->GetVkDevice(),data->image,nullptr);
|
||||
}
|
||||
}
|
||||
VK_NAMESPACE_END
|
||||
|
@@ -1,6 +1,6 @@
|
||||
#include<hgl/graph/VKDevice.h>
|
||||
#include<hgl/graph/VKPhysicalDevice.h>
|
||||
#include<hgl/graph/VKPhysicalDevice.h>
|
||||
#include<hgl/graph/TileData.h>
|
||||
#include<hgl/graph/module/TextureManager.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
@@ -61,7 +61,7 @@ namespace
|
||||
}//namespace
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
TileData *GPUDevice::CreateTileData(const VkFormat format,const uint width,const uint height,const uint count)
|
||||
TileData *TextureManager::CreateTileData(const VkFormat format,const uint width,const uint height,const uint count)
|
||||
{
|
||||
if(!CheckVulkanFormat(format))
|
||||
return(nullptr);
|
||||
@@ -69,7 +69,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=GetPhysicalDevice()->GetMaxImage2D();
|
||||
|
||||
uint tex_width,tex_height;
|
||||
|
||||
|
@@ -1,5 +1,7 @@
|
||||
#include<hgl/graph/font/TileFont.h>
|
||||
#include<hgl/graph/VKDevice.h>
|
||||
#include<hgl/graph/RenderFramework.h>
|
||||
#include<hgl/graph/module/TextureManager.h>
|
||||
#include<hgl/graph/module/SwapchainModule.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
/**
|
||||
@@ -7,7 +9,7 @@ VK_NAMESPACE_BEGIN
|
||||
* @param f 字体需求信息
|
||||
* @param limit_count 缓冲字符数量上限
|
||||
*/
|
||||
TileFont *GPUDevice::CreateTileFont(FontSource *fs,int limit_count)
|
||||
TileFont *RenderFramework::CreateTileFont(FontSource *fs,int limit_count)
|
||||
{
|
||||
if(!fs)return(nullptr);
|
||||
|
||||
@@ -15,7 +17,13 @@ TileFont *GPUDevice::CreateTileFont(FontSource *fs,int limit_count)
|
||||
|
||||
if(limit_count<=0)
|
||||
{
|
||||
const VkExtent2D &ext=GetSwapchainSize();
|
||||
VkExtent2D ext;
|
||||
|
||||
if(!sc_module->GetSwapchainSize(&ext))
|
||||
{
|
||||
ext.width=1920;
|
||||
ext.height=1080;
|
||||
}
|
||||
|
||||
limit_count=(ext.width/height)*(ext.height/height); //按全屏幕放满不一样的字符为上限
|
||||
}
|
||||
@@ -23,7 +31,7 @@ TileFont *GPUDevice::CreateTileFont(FontSource *fs,int limit_count)
|
||||
if(!fs)
|
||||
return(nullptr);
|
||||
|
||||
TileData *td=CreateTileData(UPF_R8,height,height,limit_count);
|
||||
TileData *td=tex_manager->CreateTileData(UPF_R8,height,height,limit_count);
|
||||
|
||||
if(!td)
|
||||
return nullptr;
|
||||
|
14
src/SceneGraph/module/GraphModule.cpp
Normal file
14
src/SceneGraph/module/GraphModule.cpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#include<hgl/graph/module/GraphModule.h>
|
||||
#include<hgl/graph/RenderFramework.h>
|
||||
#include<hgl/graph/VKDevice.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
GPUDevice * GraphModule::GetDevice () {return render_framework->GetDevice();}
|
||||
VkDevice GraphModule::GetVkDevice ()const {return render_framework->GetVkDevice();}
|
||||
const GPUPhysicalDevice * GraphModule::GetPhysicalDevice ()const {return render_framework->GetPhysicalDevice();}
|
||||
GPUDeviceAttribute *GraphModule::GetDeviceAttribute ()const {return render_framework->GetDeviceAttribute();}
|
||||
|
||||
VkPipelineCache GraphModule::GetPipelineCache ()const {return render_framework->GetDeviceAttribute()->pipeline_cache;}
|
||||
|
||||
VK_NAMESPACE_END
|
59
src/SceneGraph/module/GraphModuleManager.cpp
Normal file
59
src/SceneGraph/module/GraphModuleManager.cpp
Normal file
@@ -0,0 +1,59 @@
|
||||
#include<hgl/graph/module/GraphModule.h>
|
||||
#include<hgl/graph/module/GraphModuleManager.h>
|
||||
#include<hgl/graph/RenderFramework.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
GPUDevice *GraphModuleManager::GetDevice()const
|
||||
{
|
||||
return render_framework->GetDevice();
|
||||
}
|
||||
|
||||
bool GraphModuleManager::Registry(GraphModule *gm)
|
||||
{
|
||||
if(!gm)
|
||||
return(false);
|
||||
|
||||
const size_t type_hash=gm->GetTypeHash();
|
||||
|
||||
if(module_map.ContainsKey(type_hash))
|
||||
return(false);
|
||||
|
||||
module_list.Add(gm);
|
||||
module_map.Add(type_hash,gm);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool GraphModuleManager::Unregistry(GraphModule *gm)
|
||||
{
|
||||
if(!gm)
|
||||
return(false);
|
||||
|
||||
const size_t type_hash=gm->GetTypeHash();
|
||||
|
||||
if(!module_map.ContainsKey(type_hash))
|
||||
return(false);
|
||||
|
||||
if(module_list.DeleteByValue(gm)<0)
|
||||
return(false);
|
||||
|
||||
delete gm;
|
||||
return(true);
|
||||
}
|
||||
|
||||
GraphModuleManager::~GraphModuleManager()
|
||||
{
|
||||
GraphModule **gm=module_list.last();
|
||||
GraphModule **begin=module_list.begin();
|
||||
|
||||
while(gm>=begin)
|
||||
{
|
||||
delete *gm;
|
||||
--gm;
|
||||
}
|
||||
|
||||
module_list.Clear();
|
||||
}
|
||||
|
||||
VK_NAMESPACE_END
|
@@ -1,5 +1,6 @@
|
||||
#include<hgl/graph/VKDeviceRenderPassManage.h>
|
||||
#include<hgl/graph/module/RenderPassManager.h>
|
||||
#include<hgl/graph/VKRenderPass.h>
|
||||
#include<hgl/graph/VKPhysicalDevice.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
void CreateSubpassDependency(List<VkSubpassDependency> &subpass_dependency_list,const uint32_t count)
|
||||
@@ -74,9 +75,9 @@ inline void CreateInputAttachmentReference(VkAttachmentReference *ref_list, uint
|
||||
|
||||
bool CreateAttachmentDescription(List<VkAttachmentDescription> &desc_list,const RenderbufferInfo *rbi)
|
||||
{
|
||||
const uint color_count=rbi->GetColorCount();
|
||||
const uint image_count=rbi->GetColorCount();
|
||||
|
||||
const uint count=(rbi->HasDepthOrStencil())?color_count+1:color_count;
|
||||
const uint count=(rbi->HasDepthOrStencil())?image_count+1:image_count;
|
||||
|
||||
desc_list.SetCount(count);
|
||||
|
||||
@@ -97,7 +98,7 @@ bool CreateAttachmentDescription(List<VkAttachmentDescription> &desc_list,const
|
||||
|
||||
desc=desc_list.GetData();
|
||||
const VkFormat *cf=rbi->GetColorFormat();
|
||||
for(uint i=0;i<color_count;i++)
|
||||
for(uint i=0;i<image_count;i++)
|
||||
{
|
||||
desc->finalLayout = rbi->GetColorLayout();
|
||||
desc->format = *cf;
|
||||
@@ -184,15 +185,12 @@ bool CreateDepthAttachment( List<VkAttachmentReference> &ref_list,List<VkAttachm
|
||||
return(true);
|
||||
}
|
||||
|
||||
DeviceRenderPassManage::DeviceRenderPassManage(VkDevice dev,VkPipelineCache pc)
|
||||
GRAPH_MODULE_CONSTRUCT(RenderPassManager)
|
||||
{
|
||||
device=dev;
|
||||
pipeline_cache=pc;
|
||||
|
||||
hash=CreateRenderPassHash();
|
||||
}
|
||||
|
||||
DeviceRenderPassManage::~DeviceRenderPassManage()
|
||||
RenderPassManager::~RenderPassManager()
|
||||
{
|
||||
SAFE_CLEAR(hash);
|
||||
|
||||
@@ -250,7 +248,7 @@ namespace
|
||||
// }
|
||||
|
||||
void HashRenderPass(RenderPassHASHCode *code,const RenderbufferInfo *rbi,const uint8 subpass_count)
|
||||
{
|
||||
{
|
||||
util::Hash *hash=CreateRenderPassHash();
|
||||
|
||||
hash->Init();
|
||||
@@ -265,10 +263,10 @@ namespace
|
||||
}
|
||||
}
|
||||
|
||||
RenderPass *DeviceRenderPassManage::CreateRenderPass( const List<VkAttachmentDescription> &desc_list,
|
||||
const List<VkSubpassDescription> &subpass,
|
||||
const List<VkSubpassDependency> &dependency,
|
||||
const RenderbufferInfo *rbi)
|
||||
RenderPass *RenderPassManager::CreateRenderPass(const List<VkAttachmentDescription> &desc_list,
|
||||
const List<VkSubpassDescription> &subpass,
|
||||
const List<VkSubpassDependency> &dependency,
|
||||
const RenderbufferInfo *rbi)
|
||||
{
|
||||
const VkFormat depth_format=rbi->GetDepthFormat();
|
||||
|
||||
@@ -285,14 +283,26 @@ RenderPass *DeviceRenderPassManage::CreateRenderPass( const List<VkAttachmentD
|
||||
|
||||
VkRenderPass render_pass;
|
||||
|
||||
if(vkCreateRenderPass(device,&rp_info,nullptr,&render_pass)!=VK_SUCCESS)
|
||||
if(vkCreateRenderPass(GetVkDevice(),&rp_info,nullptr,&render_pass)!=VK_SUCCESS)
|
||||
return(nullptr);
|
||||
|
||||
return(new RenderPass(device,pipeline_cache,render_pass,rbi->GetColorFormatList(),depth_format));
|
||||
return(new RenderPass(GetVkDevice(),GetPipelineCache(),render_pass,rbi->GetColorFormatList(),depth_format));
|
||||
}
|
||||
|
||||
RenderPass *DeviceRenderPassManage::AcquireRenderPass(const RenderbufferInfo *rbi,const uint subpass_count)
|
||||
RenderPass *RenderPassManager::AcquireRenderPass(const RenderbufferInfo *rbi,const uint subpass_count)
|
||||
{
|
||||
{
|
||||
const auto *phy_dev=GetPhysicalDevice();
|
||||
|
||||
for(const VkFormat &fmt:rbi->GetColorFormatList())
|
||||
if(!phy_dev->IsColorAttachmentOptimal(fmt))
|
||||
return(nullptr);
|
||||
|
||||
if(rbi->HasDepthOrStencil())
|
||||
if(!phy_dev->IsDepthAttachmentOptimal(rbi->GetDepthFormat()))
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
RenderPassHASHCode hash;
|
||||
RenderPass *rp=nullptr;
|
||||
|
81
src/SceneGraph/module/RenderTargetManager.cpp
Normal file
81
src/SceneGraph/module/RenderTargetManager.cpp
Normal file
@@ -0,0 +1,81 @@
|
||||
#include<hgl/graph/module/RenderTargetManager.h>
|
||||
#include<hgl/graph/VKRenderTargetSingle.h>
|
||||
#include<hgl/graph/VKDevice.h>
|
||||
#include<hgl/graph/module/TextureManager.h>
|
||||
#include<hgl/graph/module/RenderPassManager.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
RenderTargetManager::RenderTargetManager(RenderFramework *rf,TextureManager *tm,RenderPassManager *rpm):GraphModuleInherit<RenderTargetManager,GraphModule>(rf,"RenderTargetManager")
|
||||
{
|
||||
tex_manager=tm;
|
||||
rp_manager=rpm;
|
||||
}
|
||||
|
||||
RenderTarget *RenderTargetManager::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=tex_manager->CreateTexture2D(new ColorAttachmentTextureCreateInfo(fmt,extent));
|
||||
|
||||
if(!color_texture)
|
||||
return(nullptr);
|
||||
|
||||
*tp++=color_texture;
|
||||
*iv++=color_texture->GetImageView();
|
||||
}
|
||||
|
||||
Texture2D *depth_texture=(depth_format!=PF_UNDEFINED)?tex_manager->CreateTexture2D(new DepthAttachmentTextureCreateInfo(depth_format,extent)):nullptr;
|
||||
|
||||
Framebuffer *fb=CreateFBO(rp,color_iv_list,color_count,depth_texture?depth_texture->GetImageView():nullptr);
|
||||
|
||||
if(fb)
|
||||
{
|
||||
RenderTargetData *rtd=new RenderTargetData{};
|
||||
|
||||
GPUDevice *dev=GetDevice();
|
||||
|
||||
rtd->fbo =fb;
|
||||
rtd->queue =dev->CreateQueue(fence_count,false);
|
||||
rtd->render_complete_semaphore =dev->CreateGPUSemaphore();
|
||||
|
||||
rtd->cmd_buf =dev->CreateRenderCommandBuffer("");
|
||||
|
||||
rtd->color_count =color_count;
|
||||
rtd->color_textures =hgl_new_copy<Texture2D *>(color_texture_list,color_count);
|
||||
rtd->depth_texture =depth_texture;
|
||||
|
||||
color_texture_list.DiscardObject();
|
||||
|
||||
return(new RenderTarget(GetRenderFramework(),rtd));
|
||||
}
|
||||
|
||||
SAFE_CLEAR(depth_texture);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
RenderTarget *RenderTargetManager::CreateRT(const FramebufferInfo *fbi,const uint32_t fence_count)
|
||||
{
|
||||
if(!fbi)return(nullptr);
|
||||
|
||||
RenderPass *rp=rp_manager->AcquireRenderPass(fbi);
|
||||
|
||||
if(!rp)return(nullptr);
|
||||
|
||||
return CreateRT(fbi,rp,fence_count);
|
||||
}
|
||||
|
||||
VK_NAMESPACE_END
|
302
src/SceneGraph/module/SwapchainModule.cpp
Normal file
302
src/SceneGraph/module/SwapchainModule.cpp
Normal file
@@ -0,0 +1,302 @@
|
||||
#include<hgl/graph/module/SwapchainModule.h>
|
||||
#include<hgl/graph/module/RenderPassManager.h>
|
||||
#include<hgl/graph/module/TextureManager.h>
|
||||
#include<hgl/graph/module/RenderTargetManager.h>
|
||||
#include<hgl/graph/VKDevice.h>
|
||||
#include<hgl/graph/VKSwapchain.h>
|
||||
#include<hgl/graph/VKDeviceAttribute.h>
|
||||
#include<hgl/graph/VKRenderTargetSwapchain.h>
|
||||
#include<hgl/graph/VKCommandBuffer.h>
|
||||
#include<hgl/graph/VKSemaphore.h>
|
||||
|
||||
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 CreateVulkanSwapChain(const GPUDeviceAttribute *dev_attr)
|
||||
{
|
||||
VkSwapchainCreateInfoKHR swapchain_ci;
|
||||
|
||||
uint32_t image_count;
|
||||
|
||||
if(dev_attr->surface_caps.maxImageCount<3)
|
||||
image_count=dev_attr->surface_caps.maxImageCount;
|
||||
else
|
||||
if(dev_attr->surface_caps.maxImageCount>3)
|
||||
image_count=3;
|
||||
else
|
||||
image_count=dev_attr->surface_caps.minImageCount;
|
||||
|
||||
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 =image_count;
|
||||
swapchain_ci.imageFormat =dev_attr->surface_format.format;
|
||||
swapchain_ci.imageColorSpace =dev_attr->surface_format.colorSpace;
|
||||
swapchain_ci.imageExtent =dev_attr->surface_caps.currentExtent;
|
||||
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 SwapchainModule::CreateSwapchainFBO(Swapchain *swapchain)
|
||||
{
|
||||
if(vkGetSwapchainImagesKHR(swapchain->device,swapchain->swap_chain,&(swapchain->image_count),nullptr)!=VK_SUCCESS)
|
||||
return(false);
|
||||
|
||||
AutoDeleteArray<VkImage> sc_images(swapchain->image_count);
|
||||
|
||||
if(vkGetSwapchainImagesKHR(swapchain->device,swapchain->swap_chain,&(swapchain->image_count),sc_images)!=VK_SUCCESS)
|
||||
return(false);
|
||||
|
||||
swapchain->sc_image=hgl_zero_new<SwapchainImage>(swapchain->image_count);
|
||||
|
||||
AnsiString num_string;
|
||||
GPUDevice *device=GetDevice();
|
||||
auto *dev_attr=GetDeviceAttribute();
|
||||
|
||||
for(uint32_t i=0;i<swapchain->image_count;i++)
|
||||
{
|
||||
swapchain->sc_image[i].color=tex_manager->CreateTexture2D(new SwapchainColorTextureCreateInfo(swapchain->surface_format.format,swapchain->extent,sc_images[i]));
|
||||
|
||||
if(!swapchain->sc_image[i].color)
|
||||
return(false);
|
||||
|
||||
swapchain->sc_image[i].depth=tex_manager->CreateTexture2D(new SwapchainDepthTextureCreateInfo(swapchain->depth_format,swapchain->extent));
|
||||
|
||||
if(!swapchain->sc_image[i].depth)
|
||||
return(false);
|
||||
|
||||
swapchain->sc_image[i].fbo=rt_manager->CreateFBO( sc_render_pass,
|
||||
swapchain->sc_image[i].color->GetImageView(),
|
||||
swapchain->sc_image[i].depth->GetImageView());
|
||||
|
||||
AnsiString num_string=AnsiString::numberOf(i);
|
||||
|
||||
swapchain->sc_image[i].cmd_buf=device->CreateRenderCommandBuffer(AnsiString("Swapchain_RenderCmdBuffer_")+num_string);
|
||||
|
||||
#ifdef _DEBUG
|
||||
if(dev_attr->debug_utils)
|
||||
{
|
||||
dev_attr->debug_utils->SetTexture(swapchain->sc_image[i].color,"SwapchainColor_"+num_string);
|
||||
dev_attr->debug_utils->SetTexture(swapchain->sc_image[i].depth,"SwapchainDepth_"+num_string);
|
||||
|
||||
dev_attr->debug_utils->SetFramebuffer(swapchain->sc_image[i].fbo->GetFramebuffer(),"SwapchainFBO_"+num_string);
|
||||
}
|
||||
#endif//_DEBUG
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
Swapchain *SwapchainModule::CreateSwapchain()
|
||||
{
|
||||
auto *dev_attr=GetDeviceAttribute();
|
||||
|
||||
if(!dev_attr)
|
||||
return(nullptr);
|
||||
|
||||
Swapchain *swapchain=new Swapchain;
|
||||
|
||||
swapchain->device =dev_attr->device;
|
||||
swapchain->extent =dev_attr->surface_caps.currentExtent;
|
||||
swapchain->transform =dev_attr->surface_caps.currentTransform;
|
||||
swapchain->surface_format =dev_attr->surface_format;
|
||||
swapchain->depth_format =dev_attr->physical_device->GetDepthFormat();
|
||||
|
||||
swapchain->swap_chain=CreateVulkanSwapChain(dev_attr);
|
||||
|
||||
if(swapchain->swap_chain)
|
||||
{
|
||||
if(CreateSwapchainFBO(swapchain))
|
||||
return swapchain;
|
||||
}
|
||||
|
||||
delete swapchain;
|
||||
swapchain=nullptr;
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
struct SwapchainRenderTargetData:public RenderTargetData
|
||||
{
|
||||
void Clear() override
|
||||
{
|
||||
delete render_complete_semaphore;
|
||||
delete queue;
|
||||
|
||||
delete[] color_textures;
|
||||
}
|
||||
};//
|
||||
}//namespace
|
||||
|
||||
bool SwapchainModule::CreateSwapchainRenderTarget()
|
||||
{
|
||||
Swapchain *swapchain=CreateSwapchain();
|
||||
|
||||
if(!swapchain)
|
||||
return(false);
|
||||
|
||||
GPUDevice *device=GetDevice();
|
||||
|
||||
SwapchainRenderTargetData *rtd_list=new SwapchainRenderTargetData[swapchain->image_count];
|
||||
SwapchainRenderTargetData *rtd=rtd_list;
|
||||
|
||||
SwapchainImage *sc_image=swapchain->sc_image;
|
||||
|
||||
for(uint32_t i=0;i<swapchain->image_count;i++)
|
||||
{
|
||||
rtd->fbo =sc_image->fbo;
|
||||
rtd->queue =device->CreateQueue(swapchain->image_count,false);
|
||||
rtd->render_complete_semaphore =device->CreateGPUSemaphore();
|
||||
|
||||
rtd->cmd_buf =sc_image->cmd_buf;
|
||||
|
||||
rtd->color_count =1;
|
||||
rtd->color_textures =new Texture2D*[1];
|
||||
rtd->color_textures[0] =sc_image->color;
|
||||
rtd->depth_texture =sc_image->depth;
|
||||
|
||||
++rtd;
|
||||
++sc_image;
|
||||
}
|
||||
|
||||
sc_render_target=new SwapchainRenderTarget( GetRenderFramework(),
|
||||
swapchain,
|
||||
device->CreateGPUSemaphore(),
|
||||
rtd_list
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
SwapchainModule::~SwapchainModule()
|
||||
{
|
||||
SAFE_CLEAR(sc_render_target);
|
||||
}
|
||||
|
||||
SwapchainModule::SwapchainModule(RenderFramework *rf,TextureManager *tm,RenderTargetManager *rtm,RenderPassManager *rpm):GraphModuleInherit<SwapchainModule,GraphModule>(rf,"SwapchainModule")
|
||||
{
|
||||
tex_manager=tm;
|
||||
rt_manager=rtm;
|
||||
rp_manager=rpm;
|
||||
|
||||
auto *dev_attr=GetDeviceAttribute();
|
||||
|
||||
SwapchainRenderbufferInfo rbi(dev_attr->surface_format.format,dev_attr->physical_device->GetDepthFormat());
|
||||
|
||||
sc_render_pass=rp_manager->AcquireRenderPass(&rbi);
|
||||
|
||||
#ifdef _DEBUG
|
||||
{
|
||||
if(dev_attr->debug_utils)
|
||||
dev_attr->debug_utils->SetRenderPass(sc_render_pass->GetVkRenderPass(),"SwapchainRenderPass");
|
||||
}
|
||||
#endif//_DEBUG
|
||||
|
||||
if(!CreateSwapchainRenderTarget())
|
||||
return;
|
||||
}
|
||||
|
||||
void SwapchainModule::OnResize(const VkExtent2D &extent)
|
||||
{
|
||||
SAFE_CLEAR(sc_render_target)
|
||||
|
||||
GPUDeviceAttribute *dev_attr=GetDeviceAttribute();
|
||||
|
||||
dev_attr->RefreshSurfaceCaps();
|
||||
|
||||
CreateSwapchainRenderTarget();
|
||||
}
|
||||
//
|
||||
//RenderCmdBuffer *SwapchainModule::BeginRender()
|
||||
//{
|
||||
// return sc_render_target->AcquireNextImage();
|
||||
//}
|
||||
//
|
||||
//void SwapchainModule::EndRender()
|
||||
//{
|
||||
// sc_render_target->Submit();
|
||||
// sc_render_target->PresentBackbuffer();
|
||||
// sc_render_target->WaitQueue();
|
||||
// sc_render_target->WaitFence();
|
||||
//}
|
||||
|
||||
bool SwapchainModule::GetSwapchainSize(VkExtent2D *ext)const
|
||||
{
|
||||
if(!ext||!sc_render_target)
|
||||
return(false);
|
||||
|
||||
*ext=sc_render_target->GetExtent();
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool SwapchainModule::AcquireNextImage()const
|
||||
{
|
||||
if(!sc_render_target)
|
||||
return(false);
|
||||
|
||||
return sc_render_target->NextFrame();
|
||||
}
|
||||
|
||||
VK_NAMESPACE_END
|
163
src/SceneGraph/module/TextureManager.cpp
Normal file
163
src/SceneGraph/module/TextureManager.cpp
Normal file
@@ -0,0 +1,163 @@
|
||||
#include<hgl/graph/module/TextureManager.h>
|
||||
#include<hgl/graph/VKDevice.h>
|
||||
#include<hgl/graph/VKCommandBuffer.h>
|
||||
#include<hgl/graph/module/RenderPassManager.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
const VkFormatProperties TextureManager::GetFormatProperties(const VkFormat format) const
|
||||
{
|
||||
return GetPhysicalDevice()->GetFormatProperties(format);
|
||||
}
|
||||
|
||||
GRAPH_MODULE_CONSTRUCT(TextureManager)
|
||||
{
|
||||
auto dev=GetDevice();
|
||||
auto phy_device=GetPhysicalDevice();
|
||||
|
||||
texture_cmd_buf=dev->CreateTextureCommandBuffer(phy_device->GetDeviceName()+AnsiString(":TexCmdBuffer"));
|
||||
|
||||
if(!texture_cmd_buf)
|
||||
return;
|
||||
|
||||
texture_queue=dev->CreateQueue();
|
||||
|
||||
if(!texture_queue)
|
||||
return;
|
||||
|
||||
texture_serial=0;
|
||||
}
|
||||
|
||||
TextureManager::~TextureManager()
|
||||
{
|
||||
SAFE_CLEAR(texture_queue);
|
||||
SAFE_CLEAR(texture_cmd_buf);
|
||||
}
|
||||
|
||||
const TextureID TextureManager::Add(Texture *tex)
|
||||
{
|
||||
if(!tex)
|
||||
return(-1);
|
||||
|
||||
if(tex->GetManager()!=this)
|
||||
return(-2);
|
||||
|
||||
if(texture_set.Contains(tex))
|
||||
return tex->GetID();
|
||||
|
||||
texture_set.Add(tex);
|
||||
texture_by_id.Add(tex->GetID(),tex);
|
||||
|
||||
return tex->GetID();
|
||||
}
|
||||
|
||||
const TextureID TextureManager::Add(Texture *tex,const OSString &tn)
|
||||
{
|
||||
TextureID id=Add(tex);
|
||||
|
||||
if(id<0)
|
||||
return id;
|
||||
|
||||
if(!tn.IsEmpty())
|
||||
texture_by_filename.Add(tn,tex);
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
void TextureManager::Release(Texture *tex)
|
||||
{
|
||||
if(!tex)
|
||||
return;
|
||||
|
||||
if(!texture_set.Contains(tex))
|
||||
return;
|
||||
|
||||
texture_set.Delete(tex);
|
||||
texture_by_id.DeleteByKey(tex->GetID());
|
||||
texture_by_filename.DeleteByValue(tex);
|
||||
}
|
||||
|
||||
Texture2D *CreateTexture2DFromFile(TextureManager *tm,const OSString &filename,bool auto_mipmaps);
|
||||
|
||||
Texture2D *TextureManager::LoadTexture2D(const OSString &filename,bool auto_mipmaps)
|
||||
{
|
||||
Texture2D *tex;
|
||||
|
||||
if(texture_by_filename.Get(filename,(Texture *&)tex))
|
||||
return tex;
|
||||
|
||||
tex=CreateTexture2DFromFile(this,filename,auto_mipmaps);
|
||||
|
||||
if(tex)
|
||||
{
|
||||
Add(tex,filename);
|
||||
|
||||
//#ifdef _DEBUG
|
||||
// DebugUtils *du=device->GetDebugUtils();
|
||||
|
||||
// if(du)
|
||||
// {
|
||||
// const U8String name=U8_TEXT("Tex2D:")+ToUTF8String(filename);
|
||||
//
|
||||
// du->SetImage(tex->GetImage(),(char *)(name.c_str()));
|
||||
// }
|
||||
//#endif//_DEBUG
|
||||
}
|
||||
|
||||
return tex;
|
||||
}
|
||||
|
||||
Texture2DArray *TextureManager::CreateTexture2DArray(const AnsiString &name,const uint32_t width,const uint32_t height,const uint32_t layer,const VkFormat &fmt,bool auto_mipmaps)
|
||||
{
|
||||
Texture2DArray *ta=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(TextureManager *tm,Texture2DArray *t2d,const uint32_t layer,const OSString &filename,bool auto_mipmaps);
|
||||
|
||||
bool TextureManager::LoadTexture2DToArray(Texture2DArray *ta,const uint32_t layer,const OSString &filename)
|
||||
{
|
||||
if(!ta)return(false);
|
||||
|
||||
if(!LoadTexture2DLayerFromFile(this,ta,layer,filename,false))
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
TextureCube *CreateTextureCubeFromFile(TextureManager *tm,const OSString &filename,bool auto_mipmaps);
|
||||
|
||||
TextureCube *TextureManager::LoadTextureCube(const OSString &filename,bool auto_mipmaps)
|
||||
{
|
||||
TextureCube *tex;
|
||||
|
||||
if(texture_by_filename.Get(filename,(Texture *&)tex))
|
||||
return tex;
|
||||
|
||||
tex=CreateTextureCubeFromFile(this,filename,auto_mipmaps);
|
||||
|
||||
if(tex)
|
||||
{
|
||||
Add(tex,filename);
|
||||
}
|
||||
|
||||
return tex;
|
||||
}
|
||||
|
||||
VK_NAMESPACE_END
|
@@ -279,7 +279,7 @@ void MaterialRenderList::Stat()
|
||||
{
|
||||
ro=rn->scene_node->GetRenderable();
|
||||
|
||||
if(*last_data_buffer!=*ro->GetDataBuffer())
|
||||
if(*last_data_buffer==*ro->GetDataBuffer())
|
||||
if(*last_render_data==*ro->GetRenderData())
|
||||
{
|
||||
++ri->instance_count;
|
||||
@@ -398,7 +398,7 @@ void MaterialRenderList::ProcIndirectRender()
|
||||
|
||||
void MaterialRenderList::Render(RenderItem *ri)
|
||||
{
|
||||
if(*(ri->pdb)!=*last_data_buffer) //换buf了
|
||||
if(!last_data_buffer||*(ri->pdb)!=*last_data_buffer) //换buf了
|
||||
{
|
||||
if(indirect_draw_count) //如果有间接绘制的数据,赶紧给画了
|
||||
ProcIndirectRender();
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user