Compare commits
238 Commits
optimize_p
...
devel_25_M
Author | SHA1 | Date | |
---|---|---|---|
6820ee8c74 | |||
ddb5a0b77a | |||
69646971ce | |||
e71ec4be85 | |||
dbe2370a44 | |||
00d2677066 | |||
4208e47534 | |||
2dedeaad90 | |||
083600a95f | |||
902dc20340 | |||
164498446a | |||
cef5ad073b | |||
c2279c553d | |||
d959e7988d | |||
202bff5870 | |||
8437d8d561 | |||
714fc3dcb7 | |||
e030738a5f | |||
28b2b53d03 | |||
8bb742f3f4 | |||
6e8932fc2f | |||
9661336325 | |||
ef84e5c699 | |||
3b106a3b42 | |||
74003df08b | |||
95c67ba857 | |||
f51c7c6964 | |||
3fe8d9f90d | |||
7967150722 | |||
51a6da3d9f | |||
dd047c1644 | |||
df80b1af3b | |||
64235b12b6 | |||
0557ff2bae | |||
b43d4cc5a3 | |||
b72144a28b | |||
d05f1109b5 | |||
3de67f8cf1 | |||
9816592bf6 | |||
82f3ad070b | |||
b021b05cb0 | |||
5749d8ec8a | |||
e6560dfe5f | |||
8f6260f440 | |||
18850b0e27 | |||
de2926a6d5 | |||
1a8bd0a607 | |||
ffaa6b5362 | |||
9d3ea89861 | |||
7f1532dc6e | |||
01cdb7661b | |||
ab6a8435a1 | |||
d17932c7a4 | |||
f4a8406ad8 | |||
22bc5f6653 | |||
fc94ee82b4 | |||
f8fe0e46d6 | |||
e076b72f1a | |||
a04742c347 | |||
1668a0c973 | |||
e2dd652c3a | |||
a2c3438c58 | |||
5521c53c94 | |||
71fd42cfc8 | |||
222ff2961f | |||
ed5aac2a9d | |||
233523231e | |||
3523afc6c2 | |||
6b498d7e91 | |||
fa7ecb91ac | |||
d5b719152f | |||
410a386423 | |||
641ba4431f | |||
c485941342 | |||
198fe55216 | |||
ad7c652cd4 | |||
46b6797bce | |||
c8dbd40333 | |||
35844d52bc | |||
36d872359e | |||
8086fb76f1 | |||
d660691cec | |||
c5699fd1af | |||
9316135942 | |||
8340209697 | |||
aa217c6fc5 | |||
d5b69fbe71 | |||
58c62ddb59 | |||
7f3132236f | |||
f8ff6d9cf0 | |||
8855f0b880 | |||
254264ac5e | |||
9a24aa237d | |||
ff184ecd7a | |||
81ab733429 | |||
05885e443a | |||
71c543413a | |||
d6d2d337c9 | |||
4ef1283fce | |||
7c4a27771f | |||
a97440e1fc | |||
e1cfc1e5b8 | |||
2c602e9045 | |||
f46b1382ee | |||
459fb3afc4 | |||
27f33e07cb | |||
9c956e1c65 | |||
004504e027 | |||
7c3d9ecf91 | |||
3f1b8be5d0 | |||
f3ab0a5608 | |||
8e64816af8 | |||
5718b1795f | |||
c8cbf020eb | |||
9535a4486e | |||
9781e6a9b3 | |||
958183bb29 | |||
abfc84feff | |||
12e64d7ce0 | |||
34b7937ee2 | |||
2336c7cdf1 | |||
21201b1695 | |||
2eac17ac61 | |||
1e03e28f0b | |||
30c736b7c8 | |||
7031270476 | |||
6bdbf87446 | |||
110c141073 | |||
b9bd4f6c4b | |||
8b0ef244e0 | |||
c232feb40a | |||
db0a8ee256 | |||
b26e25df61 | |||
cd03ee8211 | |||
48b5479ade | |||
1ec88c65f8 | |||
ba6af7a596 | |||
d163f914c7 | |||
0e589e8bcd | |||
011fbdb55d | |||
e488b4c3d3 | |||
49f37447d0 | |||
f280068d50 | |||
137248a274 | |||
ec45b977d1 | |||
38f9a2896f | |||
59b02bcb8c | |||
05e96c58ba | |||
cb09767151 | |||
554220699f | |||
3937206fcb | |||
88f23d9a07 | |||
15324d9c86 | |||
6c3e674d23 | |||
fefdc19674 | |||
18a4212935 | |||
0457d28577 | |||
fd39d08fda | |||
8e52595123 | |||
19a20411d8 | |||
8363275b36 | |||
939bbfeb1f | |||
f555c77a83 | |||
160ba000d3 | |||
5f830b8d57 | |||
5d9aab7dda | |||
cde2d9f86b | |||
d26eb482e7 | |||
eb8e0a921b | |||
9fd13680d1 | |||
8af96ed4a5 | |||
57b480754c | |||
ac42dcdb26 | |||
e1c3b95de7 | |||
ee061e4a1a | |||
f2c6c24ddf | |||
76f5dcb884 | |||
157c09eff0 | |||
9f8e63788d | |||
a7c761e1c5 | |||
44620abc21 | |||
8bf1ad2a46 | |||
d26cae0086 | |||
bc9fc9b50f | |||
fb4c8ed8c2 | |||
0dae30fa06 | |||
48b5a978b8 | |||
694add27ae | |||
251bbd2705 | |||
3bfc31b57f | |||
8c8a218a3a | |||
9302cbc3ef | |||
696d3259aa | |||
85530e6d57 | |||
81e2aac321 | |||
35a282ef5e | |||
3a378be660 | |||
aed56a35e0 | |||
09277924f1 | |||
c4a4ec5ebc | |||
703d444cbb | |||
159c808dad | |||
facdec5556 | |||
42f63c5ef1 | |||
5f4dd09f92 | |||
9872f74160 | |||
529d6b7939 | |||
f748301787 | |||
165f9d2a5f | |||
4de8139936 | |||
9ee5f0adaa | |||
555e8fc066 | |||
f564f55e7b | |||
31b5bb6d4f | |||
5ba705cd6b | |||
9cfb88235a | |||
eceaf9ba68 | |||
14e7074b3f | |||
f79599b1d4 | |||
2cc0dca050 | |||
ece7fa5f32 | |||
68b24903bb | |||
6ee832c39f | |||
26f7c915c8 | |||
2ac91b80ac | |||
eed16928e9 | |||
6b8e76b75f | |||
ca36b4454b | |||
ba65d1abf2 | |||
ef8f630056 | |||
7a0acaf63e | |||
d54aff2a42 | |||
84d0dc99c8 | |||
b4dccf7814 | |||
f2d5209681 | |||
0abe38de98 | |||
6536b715c3 | |||
26b907f611 |
Submodule CMAssetsManage updated: 1e14c1b01d...9582bfafcc
2
CMCore
2
CMCore
Submodule CMCore updated: ac5931ce26...072153aa91
Submodule CMPlatform updated: ef90beb450...5e8b83cce4
Submodule CMSceneGraph updated: 09fe2f07ba...bde86e8016
2
CMUtil
2
CMUtil
Submodule CMUtil updated: 9f94d5082b...c0990c52eb
@@ -24,6 +24,7 @@ SET(ULRE CMCore
|
||||
CMSceneGraph
|
||||
CMUtil
|
||||
ULRE.Util
|
||||
ULRE.ShaderGen
|
||||
ULRE.SceneGraph
|
||||
${HGL_GLM_LIB}
|
||||
${RENDER_LIBRARY}
|
||||
|
BIN
GLSLCompiler.dll
Normal file
BIN
GLSLCompiler.dll
Normal file
Binary file not shown.
14
README.md
14
README.md
@@ -1,17 +1,25 @@
|
||||
# ULRE
|
||||
experiment project - Ultra Light Rendering Engine
|
||||
experiment project - Ultra Lightweight Rendering Engine
|
||||
|
||||
ULRE is a project of experimental nature,Used to experiment with various rendering related techniques,And do some examples.
|
||||
|
||||
In the future, its compilicated version will be integrated into CMGameEngine.Used to replace the old rendering engine.
|
||||
|
||||
Platform: Windows,Linux (WIP: Android)
|
||||
Platform: Windows,Linux (WIP: Android,macOS,iOS)
|
||||
|
||||
Graphics API: Vulkan
|
||||
|
||||
Milestone:
|
||||
|
||||
On May 6 of 2023, a test was completed, and the entire scene was drawn with only one DrawCall. Although it still has a lot of unfinished work, it is still a very important milestone.
|
||||
|
||||
#
|
||||
ULRE是一个试验性质的工程,用于试验各种渲染相关的技术,以及做一些范例。在未来它的复杂化版本会被整合到CMGameEngine中,用于替代旧的渲染引擎。
|
||||
|
||||
平台: Windows,Linux (开发中: Android)
|
||||
平台: Windows,Linux (开发中: Android,macOS,iOS)
|
||||
|
||||
图形API: Vulkan
|
||||
|
||||
里程碑:
|
||||
|
||||
2023年5月6日,完成了一个测试,只用了一次DrawCall就绘制出了整个场景。虽然它还有很多未完成的工作,但它依然是一个非常重要的里程碑。
|
@@ -37,9 +37,9 @@ private:
|
||||
|
||||
MaterialInstance * material_instance =nullptr;
|
||||
Renderable * render_obj =nullptr;
|
||||
DeviceBuffer * ubo_camera_info =nullptr;
|
||||
DeviceBuffer * ubo_color_material =nullptr;
|
||||
DeviceBuffer * ubo_line_config =nullptr;
|
||||
DeviceBuffer * ubo_camera_info =nullptr;
|
||||
DeviceBuffer * ubo_color_material =nullptr;
|
||||
DeviceBuffer * ubo_line_config =nullptr;
|
||||
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
|
@@ -5,3 +5,16 @@ SET(VULKAN_APP_FRAMEWORK ${CMAKE_CURRENT_SOURCE_DIR}/common/VulkanAppFramework.h
|
||||
add_subdirectory(Vulkan)
|
||||
add_subdirectory(2dVector)
|
||||
add_subdirectory(GUI)
|
||||
|
||||
macro(CreateProject name)
|
||||
add_executable(${name} ${ARGN})
|
||||
target_link_libraries(${name} ${ULRE})
|
||||
|
||||
IF(WIN32)
|
||||
set_target_properties(${name} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY ${ULRE_RUNTIME_PATH})
|
||||
ENDIF()
|
||||
|
||||
set_property(TARGET ${name} PROPERTY FOLDER "ULRE/Example")
|
||||
endmacro()
|
||||
|
||||
CreateProject(MaterialCreaterTest MaterialCreaterTest.cpp)
|
||||
|
126
example/MaterialCreaterTest.cpp
Normal file
126
example/MaterialCreaterTest.cpp
Normal file
@@ -0,0 +1,126 @@
|
||||
#include<hgl/shadergen/MaterialCreateInfo.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
using namespace hgl::shadergen;
|
||||
|
||||
bool PureColor2DMaterial()
|
||||
{
|
||||
MaterialCreateInfo mc("PureColor2D",1,false); //一个新材质,1个RT输出,默认使用Vertex/Fragment shader
|
||||
|
||||
//vertex部分
|
||||
{
|
||||
ShaderCreateInfoVertex *vsc=mc.GetVS(); //获取vertex shader creater
|
||||
|
||||
//以下代码会被展开为
|
||||
/*
|
||||
layout(location=?) in vec3 Position; //位置属性
|
||||
*/
|
||||
vsc->AddInput("vec2","Position"); //添加一个vec3类型的position属性输入
|
||||
|
||||
vsc->SetShaderCodes(R"(
|
||||
void main()
|
||||
{
|
||||
gl_Position=vec4(Position,0,1);
|
||||
})");
|
||||
}
|
||||
|
||||
//添加一个名称为ColorMaterial的UBO定义,其内部有一个vec4 color的属性
|
||||
//该代码会被展开为
|
||||
/*
|
||||
struct ColorMaterial
|
||||
{
|
||||
vec4 color;
|
||||
};
|
||||
*/
|
||||
mc.AddStruct("ColorMaterial","vec4 color;");
|
||||
|
||||
//添加一个UBO,该代码会被展开为
|
||||
/*
|
||||
layout(set=?,binding=?) uniform ColorMaterial mtl;
|
||||
*/
|
||||
mc.AddUBO( VK_SHADER_STAGE_FRAGMENT_BIT, //这个UBO出现在fragment shader
|
||||
DescriptorSetType::PerMaterial, //它属于材质合集
|
||||
"ColorMaterial", //UBO名称为ColorMaterial
|
||||
"mtl"); //UBO变量名称为mtl
|
||||
|
||||
//fragment部分
|
||||
{
|
||||
ShaderCreateInfoFragment *fsc=mc.GetFS(); //获取fragment shader creater
|
||||
|
||||
//以下代码会被展开为
|
||||
/*
|
||||
layout(location=?) out vec4 Color; //颜色输出
|
||||
*/
|
||||
fsc->AddOutput("vec4","Color"); //添加一个vec4类型的color属性输出
|
||||
|
||||
fsc->SetShaderCodes(R"(
|
||||
void main()
|
||||
{
|
||||
Color=mtl.color;
|
||||
})");
|
||||
}
|
||||
|
||||
mc.CreateShader();
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool VertexColor2DMaterial()
|
||||
{
|
||||
MaterialCreateInfo mc("VertexColor2D",1,false);
|
||||
|
||||
//vertex部分
|
||||
{
|
||||
ShaderCreateInfoVertex *vsc=mc.GetVS();
|
||||
|
||||
vsc->AddInput("vec2","Position");
|
||||
vsc->AddInput("vec4","Color");
|
||||
|
||||
vsc->AddOutput("vec4","Color");
|
||||
|
||||
vsc->SetShaderCodes(R"(
|
||||
void main()
|
||||
{
|
||||
Output.Color=Color;
|
||||
|
||||
gl_Position=vec4(Position,0,1);
|
||||
})");
|
||||
}
|
||||
|
||||
//fragment部分
|
||||
{
|
||||
ShaderCreateInfoFragment *fsc=mc.GetFS();
|
||||
|
||||
fsc->AddOutput("vec4","Color");
|
||||
|
||||
fsc->SetShaderCodes(R"(
|
||||
void main()
|
||||
{
|
||||
Color=Input.Color;
|
||||
})");
|
||||
}
|
||||
|
||||
mc.CreateShader();
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
namespace glsl_compiler
|
||||
{
|
||||
bool Init();
|
||||
void Close();
|
||||
}//namespace glsl_compiler
|
||||
|
||||
int main()
|
||||
{
|
||||
if(!glsl_compiler::Init())
|
||||
return -1;
|
||||
|
||||
PureColor2DMaterial();
|
||||
VertexColor2DMaterial();
|
||||
|
||||
glsl_compiler::Close();
|
||||
|
||||
return 0;
|
||||
}
|
@@ -10,41 +10,43 @@
|
||||
set_property(TARGET ${name} PROPERTY FOLDER "ULRE/Example/Vulkan/${group}")
|
||||
endmacro()
|
||||
|
||||
CreateProject("Basic" 1st_triangle first_triangle.cpp)
|
||||
CreateProject("Basic" 2nd_triangle second_triangle.cpp)
|
||||
CreateProject("Basic" 3rd_triangle third_triangle.cpp)
|
||||
CreateProject("Basic" FragCoord FragCoordTest.cpp)
|
||||
CreateProject("Basic" indices_rect indices_rect.cpp)
|
||||
CreateProject("Basic" FullScreenTriangle FullScreenTriangle.cpp)
|
||||
CreateProject("Basic" InstanceTriangle InstanceTriangle.cpp)
|
||||
CreateProject("Basic" 1st_draw_triangle_in_NDC first_triangle.cpp)
|
||||
CreateProject("Basic" 2nd_draw_triangle_use_UBO second_triangle.cpp)
|
||||
CreateProject("Basic" 3rd_AutoInstance third_triangle.cpp)
|
||||
CreateProject("Basic" 4th_AutoMergeMaterialInstance fourth_triangle.cpp)
|
||||
|
||||
#CreateProject("Basic" FragCoord FragCoordTest.cpp)
|
||||
#CreateProject("Basic" indices_rect indices_rect.cpp)
|
||||
#CreateProject("Basic" FullScreenTriangle FullScreenTriangle.cpp)
|
||||
#CreateProject("Basic" InstanceTriangle InstanceTriangle.cpp)
|
||||
|
||||
CreateProject("Texture" TextureFormat TextureFormat.cpp)
|
||||
CreateProject("Texture" texture_rect texture_rect.cpp)
|
||||
#CreateProject("Texture" texture_rect texture_rect.cpp)
|
||||
#CreateProject("Texture" HQFilterTexture HQFilterTexture.cpp)
|
||||
#CreateProject(06.Geometry2D Geometry2D.cpp)
|
||||
|
||||
CreateProject("Geometry2D" RectanglePrimitive RectanglePrimitive.cpp)
|
||||
CreateProject("Tile" DrawTile DrawTile.cpp)
|
||||
CreateProject("Tile" DrawText DrawText.cpp)
|
||||
#CreateProject("Geometry2D" RectanglePrimitive RectanglePrimitive.cpp)
|
||||
#CreateProject("Tile" DrawTile DrawTile.cpp)
|
||||
#CreateProject("Tile" DrawText DrawText.cpp)
|
||||
|
||||
CreateProject("Geometry3D " Geometry3D Geometry3D.cpp)
|
||||
#CreateProject("Geometry3D " Geometry3D Geometry3D.cpp)
|
||||
|
||||
CreateProject("Scene" SceneTree SceneTree.cpp)
|
||||
#CreateProject("Scene" SceneTree SceneTree.cpp)
|
||||
#CreateProject("Scene" LoadStaticMesh LoadStaticMesh.cpp LoadScene.cpp)
|
||||
CreateProject("Scene" InlineGeometryScene InlineGeometryScene.cpp)
|
||||
#CreateProject("Scene" InlineGeometryScene InlineGeometryScene.cpp)
|
||||
|
||||
CreateProject("Scene/Sky" SkyColor SkyColor.cpp)
|
||||
CreateProject("Scene/Sky" Atmosphere Atmosphere.cpp)
|
||||
#CreateProject("Scene/Sky" SkyColor SkyColor.cpp)
|
||||
#CreateProject("Scene/Sky" Atmosphere Atmosphere.cpp)
|
||||
|
||||
CreateProject("Advanced Rendering" OffscreenRender OffscreenRender.cpp)
|
||||
#CreateProject("Advanced Rendering" OffscreenRender OffscreenRender.cpp)
|
||||
|
||||
#CreateProject(12.PBRBasic PBRBasic.cpp)
|
||||
#CreateProject(12.Deferred Deferred.cpp)
|
||||
CreateProject("Advanced Rendering" DeferredRender DeferredRender.cpp)
|
||||
#CreateProject("Advanced Rendering" DeferredRender DeferredRender.cpp)
|
||||
#CreateProject(14.AutoMaterial auto_material.cpp)
|
||||
|
||||
CreateProject("Texture" Cubemap Cubemap.cpp)
|
||||
CreateProject("Texture" EquirectangularMap EquirectangularMap.cpp)
|
||||
CreateProject("Picking" RayPicking RayPicking.cpp)
|
||||
#CreateProject("Texture" Cubemap Cubemap.cpp)
|
||||
#CreateProject("Texture" EquirectangularMap EquirectangularMap.cpp)
|
||||
#CreateProject("Picking" RayPicking RayPicking.cpp)
|
||||
|
||||
CreateProject("Landscape" TerrainSimple TerrainSimple.cpp)
|
||||
#CreateProject("Landscape" TerrainSimple TerrainSimple.cpp)
|
||||
|
@@ -160,7 +160,7 @@ private:
|
||||
|
||||
fbi.SetExtent(SCREEN_WIDTH,SCREEN_HEIGHT);
|
||||
|
||||
gbuffer.rt=device->CreateRenderTarget(&fbi);
|
||||
gbuffer.rt=device->CreateRT(&fbi);
|
||||
|
||||
if(!gbuffer.rt)return(false);
|
||||
|
||||
|
@@ -21,14 +21,14 @@ class TestApp:public CameraAppFramework
|
||||
|
||||
private:
|
||||
|
||||
SceneNode render_root;
|
||||
RenderList *render_list=nullptr;
|
||||
SceneNode render_root;
|
||||
RenderList * render_list =nullptr;
|
||||
|
||||
Material * material =nullptr;
|
||||
MaterialInstance * material_instance =nullptr;
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
Primitive * ro_plane_grid[3];
|
||||
Primitive * ro_plane_grid[3]{};
|
||||
|
||||
private:
|
||||
|
||||
|
@@ -80,7 +80,7 @@ public:
|
||||
{
|
||||
FramebufferInfo fbi(UPF_RGBA8,OFFSCREEN_SIZE,OFFSCREEN_SIZE);
|
||||
|
||||
os.render_taget=device->CreateRenderTarget(&fbi);
|
||||
os.render_taget=device->CreateRT(&fbi);
|
||||
if(!os.render_taget)return(false);
|
||||
|
||||
os.command_buffer=device->CreateRenderCommandBuffer();
|
||||
|
@@ -1,4 +1,5 @@
|
||||
#include<iostream>
|
||||
#include<iomanip>
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/graph/VKDevice.h>
|
||||
#include<hgl/graph/VKInstance.h>
|
||||
@@ -86,35 +87,36 @@ int main(int,char **)
|
||||
|
||||
for(uint32_t i=0;i<count;i++)
|
||||
{
|
||||
std::cout<<i<<". ";
|
||||
std::cout<<std::setw(4)<<i<<". ";
|
||||
|
||||
std::cout<<" Format [ID:"<<vf->format<<"]["<<vf->name<<"] ";
|
||||
std::cout<<"Format [ID:"<<std::setw(10)<<vf->format<<"]["<<std::setw(16)<<vf->name<<"]";
|
||||
|
||||
if(vf->compress_type!=TextureCompressType::NONE)
|
||||
std::cout<<"use "<<texture_compress_name[size_t(vf->compress_type)]<<" compress.";
|
||||
else
|
||||
std::cout<<vf->bytes<<" bytes/pixel.";
|
||||
|
||||
if(vf->depth!=VulkanNumberType::NONE)
|
||||
std::cout<<"[Depth:"<<data_type_name[size_t(vf->depth)]<<"]";
|
||||
if(vf->depth!=VulkanBaseType::NONE)
|
||||
std::cout<<"[ Depth:"<<std::setw(8)<<data_type_name[size_t(vf->depth)]<<"]";
|
||||
|
||||
if(vf->stencil!=VulkanNumberType::NONE)
|
||||
std::cout<<"[Stencil:"<<data_type_name[size_t(vf->stencil)]<<"]";
|
||||
if(vf->stencil!=VulkanBaseType::NONE)
|
||||
std::cout<<"[Stencil:"<<std::setw(8)<<data_type_name[size_t(vf->stencil)]<<"]";
|
||||
|
||||
if((vf->depth==VulkanNumberType::NONE)
|
||||
&&(vf->stencil==VulkanNumberType::NONE))
|
||||
std::cout<<"[Color:"<<data_type_name[size_t(vf->color)]<<"]";
|
||||
if((vf->depth==VulkanBaseType::NONE)
|
||||
&&(vf->stencil==VulkanBaseType::NONE))
|
||||
std::cout<<"[ Color:"<<std::setw(8)<<data_type_name[size_t(vf->color)]<<"]";
|
||||
|
||||
{
|
||||
const VkFormatProperties fp=physical_device->GetFormatProperties(vf->format);
|
||||
|
||||
if(fp.optimalTilingFeatures&VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)
|
||||
std::cout<<"[Optimal]";
|
||||
if(fp.linearTilingFeatures&VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)
|
||||
std::cout<<"[Linear]";
|
||||
if(fp.bufferFeatures&VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)
|
||||
std::cout<<"[Buffer]";
|
||||
char olb[]="[ ]";
|
||||
|
||||
if(fp.optimalTilingFeatures&VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT )olb[1]='O';
|
||||
if(fp.linearTilingFeatures&VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT )olb[2]='L';
|
||||
if(fp.bufferFeatures&VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT )olb[2]='B';
|
||||
|
||||
std::cout<<olb;
|
||||
}
|
||||
|
||||
if(vf->compress_type!=TextureCompressType::NONE)
|
||||
std::cout<<" use "<<texture_compress_name[size_t(vf->compress_type)]<<" compress.";
|
||||
else
|
||||
std::cout<<std::setw(4)<<vf->bytes<<" bytes/pixel.";
|
||||
|
||||
std::cout<<std::endl;
|
||||
|
||||
|
@@ -6,7 +6,9 @@
|
||||
#include<hgl/math/HalfFloat.h>
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/SceneInfo.h>
|
||||
#include<hgl/graph/VKVertexInputConfig.h>
|
||||
#include<hgl/graph/VKRenderablePrimitiveCreater.h>
|
||||
#include<hgl/graph/mtl/2d/Material2DCreateConfig.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
@@ -61,6 +63,10 @@ class TestApp:public VulkanApplicationFramework
|
||||
{
|
||||
private:
|
||||
|
||||
#if defined(USE_HALF_FLOAT_POSITION)||defined(USE_UNORM8_COLOR)
|
||||
VILConfig vil_config;
|
||||
#endif
|
||||
|
||||
MaterialInstance * material_instance =nullptr;
|
||||
Renderable * render_obj =nullptr;
|
||||
|
||||
@@ -68,11 +74,8 @@ private:
|
||||
|
||||
private:
|
||||
|
||||
bool InitMaterial()
|
||||
void InitVIL()
|
||||
{
|
||||
#if defined(USE_HALF_FLOAT_POSITION)||defined(USE_UNORM8_COLOR)
|
||||
VILConfig vil_config;
|
||||
|
||||
#ifdef USE_HALF_FLOAT_POSITION
|
||||
vil_config.Add(VAN::Position,PositionFormat);
|
||||
#endif//USE_HALF_FLOAT_POSITION
|
||||
@@ -80,19 +83,28 @@ private:
|
||||
#ifdef USE_UNORM8_COLOR
|
||||
vil_config.Add(VAN::Color,ColorFormat);
|
||||
#endif//USE_HALF_FLOAT_POSITION
|
||||
}
|
||||
|
||||
material_instance=db->CreateMaterialInstance(OS_TEXT("res/material/VertexColor2DNDC"),&vil_config);
|
||||
#else
|
||||
material_instance=db->CreateMaterialInstance(OS_TEXT("res/material/VertexColor2DNDC"));
|
||||
#endif//
|
||||
bool InitAutoMaterial()
|
||||
{
|
||||
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"VertexColor2d");
|
||||
|
||||
if(!material_instance)
|
||||
return(false);
|
||||
cfg.coordinate_system=CoordinateSystem2D::NDC;
|
||||
cfg.local_to_world=false;
|
||||
|
||||
AutoDelete<mtl::MaterialCreateInfo> mci=mtl::CreateVertexColor2D(&cfg);
|
||||
|
||||
material_instance=db->CreateMaterialInstance(mci,&vil_config);
|
||||
|
||||
return material_instance;
|
||||
}
|
||||
|
||||
bool InitPipeline()
|
||||
{
|
||||
// pipeline=db->CreatePipeline(material_instance,sc_render_target,OS_TEXT("res/pipeline/solid2d"));
|
||||
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D,Prim::Triangles); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||
|
||||
return pipeline;
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
bool InitVBO()
|
||||
@@ -117,7 +129,12 @@ public:
|
||||
if(!VulkanApplicationFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
|
||||
return(false);
|
||||
|
||||
if(!InitMaterial())
|
||||
InitVIL();
|
||||
|
||||
if(!InitAutoMaterial())
|
||||
return(false);
|
||||
|
||||
if(!InitPipeline())
|
||||
return(false);
|
||||
|
||||
if(!InitVBO())
|
||||
|
147
example/Vulkan/fourth_triangle.cpp
Normal file
147
example/Vulkan/fourth_triangle.cpp
Normal file
@@ -0,0 +1,147 @@
|
||||
// AutoMergeMaterialInstance
|
||||
// 该范例主要演示使用一个材质下的不同材质实例传递颜色参数绘制三角形,并依赖RenderList中的自动合并功能,让同一材质下所有不同材质实例的对象一次渲染完成。
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/math/Math.h>
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/VKRenderablePrimitiveCreater.h>
|
||||
#include<hgl/graph/mtl/2d/Material2DCreateConfig.h>
|
||||
#include<hgl/graph/RenderList.h>
|
||||
#include<hgl/color/Color.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
constexpr uint32_t SCREEN_WIDTH=1024;
|
||||
constexpr uint32_t SCREEN_HEIGHT=1024;
|
||||
|
||||
constexpr uint32_t VERTEX_COUNT=3;
|
||||
|
||||
constexpr float position_data[VERTEX_COUNT*2]=
|
||||
{
|
||||
0.0, 0.0,
|
||||
-0.1, 0.9,
|
||||
0.1, 0.9
|
||||
};
|
||||
|
||||
constexpr uint DRAW_OBJECT_COUNT=12;
|
||||
|
||||
class TestApp:public VulkanApplicationFramework
|
||||
{
|
||||
private:
|
||||
|
||||
SceneNode render_root;
|
||||
RenderList * render_list =nullptr;
|
||||
|
||||
Material * material =nullptr;
|
||||
|
||||
struct
|
||||
{
|
||||
MaterialInstance * mi;
|
||||
Renderable * r;
|
||||
}render_obj[DRAW_OBJECT_COUNT]{};
|
||||
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
private:
|
||||
|
||||
bool InitMaterial()
|
||||
{
|
||||
{
|
||||
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"PureColor2D");
|
||||
|
||||
cfg.coordinate_system=CoordinateSystem2D::NDC;
|
||||
cfg.local_to_world=true;
|
||||
|
||||
AutoDelete<mtl::MaterialCreateInfo> mci=mtl::CreatePureColor2D(&cfg);
|
||||
|
||||
material=db->CreateMaterial(mci);
|
||||
|
||||
if(!material)
|
||||
return(false);
|
||||
|
||||
for(uint i=0;i<DRAW_OBJECT_COUNT;i++)
|
||||
{
|
||||
render_obj[i].mi=db->CreateMaterialInstance(material);
|
||||
|
||||
if(!render_obj[i].mi)
|
||||
return(false);
|
||||
|
||||
Color4f color=GetColor4f((COLOR)(i+int(COLOR::Blue)),1.0);
|
||||
|
||||
render_obj[i].mi->WriteMIData(color,sizeof(Color4f)); //设置MaterialInstance的数据
|
||||
}
|
||||
}
|
||||
|
||||
pipeline=CreatePipeline(material,InlinePipeline::Solid2D,Prim::Triangles);
|
||||
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
bool InitVBO()
|
||||
{
|
||||
RenderablePrimitiveCreater rpc(db,VERTEX_COUNT);
|
||||
|
||||
if(!rpc.SetVBO(VAN::Position, VF_V2F, position_data))return(false);
|
||||
|
||||
for(uint i=0;i<DRAW_OBJECT_COUNT;i++)
|
||||
{
|
||||
render_obj[i].r=rpc.Create(render_obj[i].mi,pipeline);
|
||||
|
||||
if(!render_obj[i].r)
|
||||
return(false);
|
||||
|
||||
render_root.CreateSubNode(rotate(deg2rad(360/DRAW_OBJECT_COUNT*i),Vector3f(0,0,1)),render_obj[i].r);
|
||||
}
|
||||
|
||||
render_root.RefreshMatrix();
|
||||
|
||||
render_list->Expend(&render_root);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
~TestApp()
|
||||
{
|
||||
SAFE_CLEAR(render_list);
|
||||
}
|
||||
|
||||
bool Init()
|
||||
{
|
||||
if(!VulkanApplicationFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
|
||||
return(false);
|
||||
|
||||
render_list=new RenderList(device);
|
||||
|
||||
if(!InitMaterial())
|
||||
return(false);
|
||||
|
||||
if(!InitVBO())
|
||||
return(false);
|
||||
|
||||
BuildCommandBuffer(render_list);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Resize(int w,int h)override
|
||||
{
|
||||
VulkanApplicationFramework::Resize(w,h);
|
||||
|
||||
BuildCommandBuffer(render_list);
|
||||
}
|
||||
};//class TestApp:public VulkanApplicationFramework
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
TestApp app;
|
||||
|
||||
if(!app.Init())
|
||||
return(-1);
|
||||
|
||||
while(app.Run());
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,10 +1,12 @@
|
||||
// third_triangle
|
||||
// 该范例主要演示使用2D坐系统直接绘制一个渐变色的三角形
|
||||
// second_triangle
|
||||
// 该范例主要演示使用2D坐系统直接绘制一个渐变色的三角形,使用UBO传递Viewport信息
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/math/Math.h>
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/SceneInfo.h>
|
||||
#include<hgl/graph/VKRenderablePrimitiveCreater.h>
|
||||
#include<hgl/graph/mtl/2d/Material2DCreateConfig.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
@@ -14,11 +16,11 @@ constexpr uint32_t SCREEN_HEIGHT=720;
|
||||
|
||||
constexpr uint32_t VERTEX_COUNT=3;
|
||||
|
||||
constexpr float position_data[VERTEX_COUNT][2]=
|
||||
static float position_data[VERTEX_COUNT][2]=
|
||||
{
|
||||
{SCREEN_WIDTH*0.5, SCREEN_HEIGHT*0.25},
|
||||
{SCREEN_WIDTH*0.75, SCREEN_HEIGHT*0.75},
|
||||
{SCREEN_WIDTH*0.25, SCREEN_HEIGHT*0.75}
|
||||
{0.5, 0.25},
|
||||
{0.75, 0.75},
|
||||
{0.25, 0.75}
|
||||
};
|
||||
|
||||
constexpr float color_data[VERTEX_COUNT][4]=
|
||||
@@ -28,6 +30,8 @@ constexpr float color_data[VERTEX_COUNT][4]=
|
||||
{0,0,1,1}
|
||||
};
|
||||
|
||||
//#define USE_ZERO2ONE_COORD //使用左上角0,0右下角1,1的坐标系
|
||||
|
||||
class TestApp:public VulkanApplicationFramework
|
||||
{
|
||||
private:
|
||||
@@ -41,12 +45,24 @@ private:
|
||||
|
||||
bool InitMaterial()
|
||||
{
|
||||
material_instance=db->CreateMaterialInstance(OS_TEXT("res/material/VertexColor2D"));
|
||||
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"VertexColor2D");
|
||||
|
||||
#ifdef USE_ZERO2ONE_COORD
|
||||
cfg.coordinate_system=CoordinateSystem2D::ZeroToOne;
|
||||
#else
|
||||
cfg.coordinate_system=CoordinateSystem2D::Ortho;
|
||||
#endif//USE_ZERO2ONE_COORD
|
||||
|
||||
cfg.local_to_world=false;
|
||||
|
||||
AutoDelete<mtl::MaterialCreateInfo> mci=mtl::CreateVertexColor2D(&cfg);
|
||||
|
||||
material_instance=db->CreateMaterialInstance(mci);
|
||||
|
||||
if(!material_instance)
|
||||
return(false);
|
||||
|
||||
BindCameraUBO(material_instance);
|
||||
db->global_descriptor.Bind(material_instance->GetMaterial());
|
||||
|
||||
// pipeline=db->CreatePipeline(material_instance,sc_render_target,OS_TEXT("res/pipeline/solid2d"));
|
||||
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D,Prim::Triangles); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||
@@ -56,13 +72,22 @@ private:
|
||||
|
||||
bool InitVBO()
|
||||
{
|
||||
Primitive *primitive=db->CreatePrimitive(VERTEX_COUNT);
|
||||
if(!primitive)return(false);
|
||||
RenderablePrimitiveCreater rpc(db,VERTEX_COUNT);
|
||||
|
||||
if(!primitive->Set(VAN::Position, db->CreateVBO(VF_V2F,VERTEX_COUNT,position_data )))return(false);
|
||||
if(!primitive->Set(VAN::Color, db->CreateVBO(VF_V4F,VERTEX_COUNT,color_data )))return(false);
|
||||
#ifndef USE_ZERO2ONE_COORD //使用ortho坐标系
|
||||
|
||||
for(uint i=0;i<VERTEX_COUNT;i++)
|
||||
{
|
||||
position_data[i][0]*=SCREEN_WIDTH;
|
||||
position_data[i][1]*=SCREEN_HEIGHT;
|
||||
}
|
||||
|
||||
#endif//USE_ZERO2ONE_COORD
|
||||
|
||||
if(!rpc.SetVBO(VAN::Position, VF_V2F, position_data))return(false);
|
||||
if(!rpc.SetVBO(VAN::Color, VF_V4F, color_data ))return(false);
|
||||
|
||||
render_obj=db->CreateRenderable(primitive,material_instance,pipeline);
|
||||
render_obj=rpc.Create(material_instance,pipeline);
|
||||
return(true);
|
||||
}
|
||||
|
||||
|
@@ -50,7 +50,7 @@ private:
|
||||
Texture2D * texture =nullptr;
|
||||
Sampler * sampler =nullptr;
|
||||
MaterialInstance * material_instance =nullptr;
|
||||
Renderable * renderable =nullptr;
|
||||
Renderable * renderable =nullptr;
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
private:
|
||||
|
@@ -1,29 +1,33 @@
|
||||
// second_triangle
|
||||
// 该范例主要演示使用场景树系统绘制三角形
|
||||
// AutoInstance
|
||||
// 该范例主要演示使用RenderList系统绘制多个三角形,并利用RenderList进行排序以及自动合并进行Instance渲染
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/math/Math.h>
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/VKRenderablePrimitiveCreater.h>
|
||||
#include<hgl/graph/VKVertexInputConfig.h>
|
||||
#include<hgl/graph/mtl/2d/Material2DCreateConfig.h>
|
||||
#include<hgl/graph/RenderList.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
constexpr uint32_t SCREEN_WIDTH=1280;
|
||||
constexpr uint32_t SCREEN_HEIGHT=720;
|
||||
constexpr uint32_t SCREEN_WIDTH=1024;
|
||||
constexpr uint32_t SCREEN_HEIGHT=1024;
|
||||
|
||||
constexpr uint32_t VERTEX_COUNT=3;
|
||||
|
||||
constexpr float position_data[VERTEX_COUNT][2]=
|
||||
constexpr float position_data[VERTEX_COUNT*2]=
|
||||
{
|
||||
{SCREEN_WIDTH*0.5, SCREEN_HEIGHT*0.25},
|
||||
{SCREEN_WIDTH*0.25, SCREEN_HEIGHT*0.75},
|
||||
{SCREEN_WIDTH*0.75, SCREEN_HEIGHT*0.75}
|
||||
0.0, 0.0,
|
||||
-0.1, 0.9,
|
||||
0.1, 0.9
|
||||
};
|
||||
|
||||
constexpr float color_data[VERTEX_COUNT][4]=
|
||||
{ {1,0,0,1},
|
||||
{0,1,0,1},
|
||||
{0,0,1,1}
|
||||
constexpr uint8 color_data[VERTEX_COUNT][4]=
|
||||
{ {255,0,0,255},
|
||||
{0,255,0,255},
|
||||
{0,0,255,255}
|
||||
};
|
||||
|
||||
class TestApp:public VulkanApplicationFramework
|
||||
@@ -42,37 +46,48 @@ private:
|
||||
|
||||
bool InitMaterial()
|
||||
{
|
||||
material_instance=db->CreateMaterialInstance(OS_TEXT("res/material/VertexColor2D"));
|
||||
{
|
||||
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"VertexColor2D");
|
||||
|
||||
cfg.coordinate_system=CoordinateSystem2D::NDC;
|
||||
cfg.local_to_world=true;
|
||||
|
||||
AutoDelete<mtl::MaterialCreateInfo> mci=mtl::CreateVertexColor2D(&cfg);
|
||||
|
||||
VILConfig vil_config;
|
||||
|
||||
vil_config.Add(VAN::Color,VF_V4UN8);
|
||||
|
||||
material_instance=db->CreateMaterialInstance(mci,&vil_config);
|
||||
}
|
||||
|
||||
if(!material_instance)
|
||||
return(false);
|
||||
|
||||
BindCameraUBO(material_instance);
|
||||
|
||||
// pipeline=db->CreatePipeline(material_instance,sc_render_target,OS_TEXT("res/pipeline/solid2d"));
|
||||
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D,Prim::Triangles); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||
|
||||
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
bool InitVBO()
|
||||
{
|
||||
Primitive *primitive=db->CreatePrimitive(VERTEX_COUNT);
|
||||
if(!primitive)return(false);
|
||||
RenderablePrimitiveCreater rpc(db,VERTEX_COUNT);
|
||||
|
||||
if(!primitive->Set(VAN::Position, db->CreateVBO(VF_V2F,VERTEX_COUNT,position_data )))return(false);
|
||||
if(!primitive->Set(VAN::Color, db->CreateVBO(VF_V4F,VERTEX_COUNT,color_data )))return(false);
|
||||
if(!rpc.SetVBO(VAN::Position, VF_V2F, position_data))return(false);
|
||||
if(!rpc.SetVBO(VAN::Color, VF_V4UN8, color_data ))return(false);
|
||||
|
||||
render_obj=db->CreateRenderable(primitive,material_instance,pipeline);
|
||||
render_obj=rpc.Create(material_instance,pipeline);
|
||||
|
||||
if(!render_obj)
|
||||
return(false);
|
||||
|
||||
render_root.CreateSubNode(render_obj);
|
||||
|
||||
for(uint i=0;i<12;i++)
|
||||
render_root.CreateSubNode(rotate(deg2rad(30*i),Vector3f(0,0,1)),render_obj);
|
||||
|
||||
render_root.RefreshMatrix();
|
||||
|
||||
render_list->Expend(GetCameraInfo(),&render_root);
|
||||
render_list->Expend(&render_root);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
@@ -2,7 +2,7 @@
|
||||
#include<hgl/platform/Window.h>
|
||||
#include<hgl/graph/VKInstance.h>
|
||||
#include<hgl/graph/VKPhysicalDevice.h>
|
||||
#include<hgl/graph/VKDevice.h>
|
||||
#include<hgl/graph/VKDeviceCreater.h>
|
||||
#include<hgl/graph/VKSemaphore.h>
|
||||
#include<hgl/graph/VKBuffer.h>
|
||||
#include<hgl/graph/VKShaderModule.h>
|
||||
@@ -20,8 +20,10 @@
|
||||
#include<hgl/graph/VKRenderTarget.h>
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
#include<hgl/graph/RenderList.h>
|
||||
#include<hgl/graph/mtl/UBOCommon.h>
|
||||
#include<hgl/color/Color.h>
|
||||
#include<hgl/Time.h>
|
||||
#include<hgl/log/LogInfo.h>
|
||||
|
||||
//#include<hgl/graph/LookAtCameraControl.h>
|
||||
#include<hgl/graph/FirstPersonCameraControl.h>
|
||||
@@ -33,6 +35,12 @@ using namespace hgl;
|
||||
using namespace hgl::io;
|
||||
using namespace hgl::graph;
|
||||
|
||||
namespace hgl{namespace graph
|
||||
{
|
||||
bool InitShaderCompiler();
|
||||
void CloseShaderCompiler();
|
||||
}}//namespace hgl::graph
|
||||
|
||||
class VulkanApplicationFramework:WindowEvent
|
||||
{
|
||||
protected:
|
||||
@@ -44,7 +52,7 @@ protected:
|
||||
|
||||
GPUDevice * device =nullptr;
|
||||
RenderPass * device_render_pass =nullptr;
|
||||
SwapchainRenderTarget * sc_render_target =nullptr;
|
||||
RTSwapchain * sc_render_target =nullptr;
|
||||
|
||||
protected:
|
||||
|
||||
@@ -59,15 +67,16 @@ protected:
|
||||
RenderResource * db =nullptr;
|
||||
|
||||
protected:
|
||||
|
||||
Camera * camera =nullptr;
|
||||
DeviceBuffer * ubo_camera_info =nullptr;
|
||||
|
||||
ViewportInfo vp_info;
|
||||
DeviceBuffer * ubo_vp_info =nullptr;
|
||||
|
||||
public:
|
||||
|
||||
virtual ~VulkanApplicationFramework()
|
||||
{
|
||||
SAFE_CLEAR(camera);
|
||||
CloseShaderCompiler();
|
||||
|
||||
win->Unjoin(this);
|
||||
|
||||
SAFE_CLEAR(db);
|
||||
@@ -80,6 +89,11 @@ public:
|
||||
|
||||
virtual bool Init(int w,int h)
|
||||
{
|
||||
logger::InitLogger(OS_TEXT("VulkanTest"));
|
||||
|
||||
if(!InitShaderCompiler())
|
||||
return(false);
|
||||
|
||||
clear_color.Set(0,0,0,1);
|
||||
|
||||
#ifdef _DEBUG
|
||||
@@ -105,7 +119,6 @@ public:
|
||||
|
||||
cili.lunarg.standard_validation = true;
|
||||
cili.khronos.validation = true;
|
||||
//cili.RenderDoc.Capture = true;
|
||||
|
||||
inst=CreateInstance("VulkanTest",nullptr,&cili);
|
||||
|
||||
@@ -127,48 +140,20 @@ public:
|
||||
win->Join(this);
|
||||
|
||||
{
|
||||
camera=new Camera;
|
||||
vp_info.Set(w,h);
|
||||
|
||||
camera->width=w;
|
||||
camera->height=h;
|
||||
camera->vp_width=w;
|
||||
camera->vp_height=h;
|
||||
ubo_vp_info=db->CreateUBO(sizeof(ViewportInfo),&vp_info);
|
||||
|
||||
camera->pos=Vector3f(10,10,10);
|
||||
|
||||
camera->RefreshCameraInfo();
|
||||
|
||||
ubo_camera_info=db->CreateUBO(sizeof(CameraInfo),&camera->info);
|
||||
db->global_descriptor.AddUBO(mtl::SBS_ViewportInfo.name,ubo_vp_info);
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
const CameraInfo &GetCameraInfo()
|
||||
{
|
||||
return camera->info;
|
||||
}
|
||||
|
||||
DeviceBuffer *GetCameraInfoBuffer()
|
||||
{
|
||||
return ubo_camera_info;
|
||||
}
|
||||
|
||||
bool BindCameraUBO(MaterialInstance *mi)
|
||||
{
|
||||
return mi->BindUBO(DescriptorSetType::Global,"g_camera",ubo_camera_info);
|
||||
}
|
||||
|
||||
virtual void Resize(int w,int h)
|
||||
{
|
||||
camera->width=w;
|
||||
camera->height=h;
|
||||
camera->vp_width=w;
|
||||
camera->vp_height=h;
|
||||
|
||||
camera->RefreshCameraInfo();
|
||||
|
||||
ubo_camera_info->Write(&camera->info);
|
||||
vp_info.Set(w,h);
|
||||
ubo_vp_info->Write(&vp_info);
|
||||
}
|
||||
|
||||
void SetClearColor(const Color4f &cc)
|
||||
@@ -212,20 +197,20 @@ public:
|
||||
{
|
||||
if(!ri)return(false);
|
||||
|
||||
const IndexBuffer *ib=ri->GetIndexBuffer();
|
||||
const VertexInputData *vid=ri->GetVertexInputData();
|
||||
|
||||
cb->Begin();
|
||||
cb->BindFramebuffer(rp,fb);
|
||||
cb->SetClearColor(0,clear_color);
|
||||
cb->BeginRenderPass();
|
||||
cb->BindPipeline(ri->GetPipeline());
|
||||
cb->BindDescriptorSets(ri);
|
||||
cb->BindDescriptorSets(ri->GetMaterial());
|
||||
cb->BindVBO(ri);
|
||||
|
||||
if (ib)
|
||||
cb->DrawIndexed(ib->GetCount(),ri->GetInstanceCount());
|
||||
if (vid->index_buffer->buffer)
|
||||
cb->DrawIndexed(vid->index_buffer->buffer->GetCount());
|
||||
else
|
||||
cb->Draw(ri->GetDrawCount(),ri->GetInstanceCount());
|
||||
cb->Draw(vid->vertex_count);
|
||||
|
||||
cb->EndRenderPass();
|
||||
cb->End();
|
||||
@@ -456,6 +441,10 @@ class CameraAppFramework:public VulkanApplicationFramework
|
||||
|
||||
protected:
|
||||
|
||||
Camera * camera =nullptr;
|
||||
|
||||
DeviceBuffer * ubo_camera_info =nullptr;
|
||||
|
||||
FirstPersonCameraControl *camera_control=nullptr;
|
||||
|
||||
CameraKeyboardControl * ckc=nullptr;
|
||||
@@ -469,6 +458,7 @@ public:
|
||||
{
|
||||
SAFE_CLEAR(ckc);
|
||||
SAFE_CLEAR(cmc);
|
||||
SAFE_CLEAR(camera);
|
||||
}
|
||||
|
||||
virtual bool Init(int w,int h)
|
||||
@@ -482,7 +472,7 @@ public:
|
||||
|
||||
virtual void InitCamera(int w,int h)
|
||||
{
|
||||
camera_control=new FirstPersonCameraControl(camera);
|
||||
camera_control=new FirstPersonCameraControl(&vp_info,camera);
|
||||
|
||||
camera_control->Refresh(); //更新矩阵计算
|
||||
|
||||
@@ -491,26 +481,47 @@ public:
|
||||
|
||||
win->Join(ckc);
|
||||
win->Join(cmc);
|
||||
|
||||
camera=new Camera;
|
||||
|
||||
camera->pos=Vector3f(10,10,10);
|
||||
|
||||
RefreshCameraInfo(&camera_control->GetCameraInfo(),&vp_info,camera);
|
||||
|
||||
ubo_camera_info=db->CreateUBO(sizeof(CameraInfo),&camera_control->GetCameraInfo());
|
||||
}
|
||||
|
||||
void Resize(int w,int h)override
|
||||
{
|
||||
camera->width=w;
|
||||
camera->height=h;
|
||||
camera->vp_width=w;
|
||||
camera->vp_height=h;
|
||||
vp_info.Set(w,h);
|
||||
|
||||
camera_control->Refresh();
|
||||
|
||||
ubo_camera_info->Write(&camera->info);
|
||||
ubo_camera_info->Write(&camera_control->GetCameraInfo());
|
||||
}
|
||||
|
||||
const CameraInfo &GetCameraInfo()
|
||||
{
|
||||
return camera_control->GetCameraInfo();
|
||||
}
|
||||
|
||||
DeviceBuffer *GetCameraInfoBuffer()
|
||||
{
|
||||
return ubo_camera_info;
|
||||
}
|
||||
|
||||
bool BindCameraUBO(MaterialInstance *mi)
|
||||
{
|
||||
return mi->BindUBO(DescriptorSetType::Global,"g_camera",ubo_camera_info);
|
||||
}
|
||||
|
||||
virtual void BuildCommandBuffer(uint32_t index)=0;
|
||||
|
||||
virtual void Draw()override
|
||||
{
|
||||
camera_control->Refresh(); //更新相机矩阵
|
||||
ubo_camera_info->Write(&camera->info); //写入缓冲区
|
||||
camera_control->Refresh(); //更新相机矩阵
|
||||
|
||||
ubo_camera_info->Write(&camera_control->GetCameraInfo()); //写入缓冲区
|
||||
|
||||
const uint32_t index=AcquireNextImage();
|
||||
|
||||
|
17
inc/hgl/graph/CoordinateSystem.h
Normal file
17
inc/hgl/graph/CoordinateSystem.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/TypeFunc.h>
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
enum class CoordinateSystem2D
|
||||
{
|
||||
NDC,
|
||||
ZeroToOne, //左上角为0,0;右下角为1,1
|
||||
Ortho, //左上角为0,0;右下角为(width-1),(height-1)
|
||||
|
||||
ENUM_CLASS_RANGE(NDC,Ortho)
|
||||
};
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
75
inc/hgl/graph/MaterialRenderList.h
Normal file
75
inc/hgl/graph/MaterialRenderList.h
Normal file
@@ -0,0 +1,75 @@
|
||||
#pragma once
|
||||
#include<hgl/graph/RenderNode.h>
|
||||
#include<hgl/graph/VKVBOList.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
class RenderAssignBuffer;
|
||||
|
||||
/**
|
||||
* 同一材质的对象渲染列表
|
||||
*/
|
||||
class MaterialRenderList
|
||||
{
|
||||
GPUDevice *device;
|
||||
RenderCmdBuffer *cmd_buf;
|
||||
|
||||
Material *mtl;
|
||||
|
||||
RenderNodeList rn_list;
|
||||
|
||||
private:
|
||||
|
||||
RenderAssignBuffer *assign_buffer;
|
||||
|
||||
struct RenderItem
|
||||
{
|
||||
uint32_t first;
|
||||
uint32_t count;
|
||||
|
||||
Pipeline * pipeline;
|
||||
MaterialInstance * mi;
|
||||
const VertexInputData * vid;
|
||||
|
||||
public:
|
||||
|
||||
void Set(Renderable *);
|
||||
};
|
||||
|
||||
MaterialInstanceSets mi_set;
|
||||
DataArray<RenderItem> ri_array;
|
||||
uint ri_count;
|
||||
|
||||
void StatMI();
|
||||
void Stat();
|
||||
|
||||
protected:
|
||||
|
||||
VBOList * vbo_list;
|
||||
|
||||
const VIL * last_vil;
|
||||
Pipeline * last_pipeline;
|
||||
const VertexInputData * last_vid;
|
||||
uint last_index;
|
||||
|
||||
void Bind(MaterialInstance *);
|
||||
bool Bind(const VertexInputData *,const uint);
|
||||
|
||||
void Render(RenderItem *);
|
||||
|
||||
public:
|
||||
|
||||
MaterialRenderList(GPUDevice *d,Material *m);
|
||||
~MaterialRenderList();
|
||||
|
||||
void Add(Renderable *ri,const Matrix4f &mat);
|
||||
|
||||
void Clear()
|
||||
{
|
||||
rn_list.Clear();
|
||||
}
|
||||
|
||||
void End();
|
||||
|
||||
void Render(RenderCmdBuffer *);
|
||||
};//class MaterialRenderList
|
||||
VK_NAMESPACE_END
|
32
inc/hgl/graph/MaterialRenderMap.h
Normal file
32
inc/hgl/graph/MaterialRenderMap.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
#include<hgl/graph/MaterialRenderList.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
class MaterialRenderMap:public ObjectMap<Material *,MaterialRenderList>
|
||||
{
|
||||
public:
|
||||
|
||||
MaterialRenderMap()=default;
|
||||
virtual ~MaterialRenderMap()=default;
|
||||
|
||||
void Begin()
|
||||
{
|
||||
for(auto *it:data_list)
|
||||
it->value->Clear();
|
||||
}
|
||||
|
||||
void End()
|
||||
{
|
||||
for(auto *it:data_list)
|
||||
it->value->End();
|
||||
}
|
||||
|
||||
void Render(RenderCmdBuffer *rcb)
|
||||
{
|
||||
if(!rcb)return;
|
||||
|
||||
for(auto *it:data_list)
|
||||
it->value->Render(rcb);
|
||||
}
|
||||
};//class MaterialRenderMap
|
||||
VK_NAMESPACE_END
|
@@ -8,28 +8,28 @@ namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
struct ShaderStageBind
|
||||
{
|
||||
AnsiString name;
|
||||
uint binding;
|
||||
VAD * data =nullptr;
|
||||
VBO * vbo =nullptr;
|
||||
|
||||
public:
|
||||
|
||||
~ShaderStageBind()
|
||||
{
|
||||
SAFE_CLEAR(data);
|
||||
}
|
||||
};//struct ShaderStageBind
|
||||
|
||||
using ShaderStageBindMap=ObjectMap<AnsiString,ShaderStageBind>;
|
||||
|
||||
/**
|
||||
* 可绘制图元创建器
|
||||
*/
|
||||
class PrimitiveCreater
|
||||
{
|
||||
struct PrimitiveVertexBuffer
|
||||
{
|
||||
AnsiString name;
|
||||
uint binding;
|
||||
VAD * data =nullptr;
|
||||
VBO * vbo =nullptr;
|
||||
|
||||
public:
|
||||
|
||||
~PrimitiveVertexBuffer()
|
||||
{
|
||||
SAFE_CLEAR(data);
|
||||
}
|
||||
};//struct PrimitiveVertexBuffer
|
||||
|
||||
using PVBMap=ObjectMap<AnsiString,PrimitiveVertexBuffer>;
|
||||
|
||||
protected:
|
||||
|
||||
RenderResource *db;
|
||||
@@ -42,7 +42,7 @@ namespace hgl
|
||||
uint32 vertices_number;
|
||||
|
||||
IndexBuffer * ibo;
|
||||
ShaderStageBindMap ssb_map;
|
||||
PVBMap vbo_map;
|
||||
|
||||
public:
|
||||
|
||||
@@ -54,9 +54,9 @@ namespace hgl
|
||||
VAD * CreateVAD(const AnsiString &name); ///<创建一个顶点属性缓冲区
|
||||
|
||||
template<typename T>
|
||||
T * CreateVADA(const AnsiString &name) ///<创建一个顶点属性缓冲区以及访问器
|
||||
T * AccessVAD(const AnsiString &name) ///<创建一个顶点属性缓冲区以及访问器
|
||||
{
|
||||
const VkFormat format=vil->GetFormat(name);
|
||||
const VkFormat format=vil->GetVulkanFormat(name);
|
||||
|
||||
if(format!=T::GetVulkanFormat())
|
||||
return(nullptr);
|
||||
@@ -66,11 +66,11 @@ namespace hgl
|
||||
if(!vad)
|
||||
return(nullptr);
|
||||
|
||||
T *vada=T::Create(vad);
|
||||
T *access=T::Create(vad);
|
||||
|
||||
vada->Begin();
|
||||
access->Begin();
|
||||
|
||||
return vada;
|
||||
return access;
|
||||
}
|
||||
|
||||
bool WriteVAD(const AnsiString &name,const void *data,const uint32_t bytes); ///<直接写入顶点属性数据
|
||||
|
@@ -2,72 +2,42 @@
|
||||
#define HGL_GRAPH_RENDER_LIST_INCLUDE
|
||||
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/graph/Camera.h>
|
||||
#include<hgl/graph/SceneNode.h>
|
||||
#include<hgl/graph/RenderNode.h>
|
||||
#include<hgl/graph/MaterialRenderMap.h>
|
||||
#include<hgl/graph/VKArrayBuffer.h>
|
||||
#include<hgl/graph/SceneInfo.h>
|
||||
#include<hgl/color/Color4f.h>
|
||||
#include<hgl/type/SortedSets.h>
|
||||
#include<hgl/graph/VKMaterial.h>
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
using MVPArrayBuffer=GPUArrayBuffer<MVPMatrix>;
|
||||
using MaterialSets=SortedSets<Material *>;
|
||||
|
||||
/**
|
||||
* 渲染对象列表<br>
|
||||
* 已经展开的渲染对象列表,产生mvp用UBO/SSBO等数据,最终创建RenderCommandBuffer
|
||||
* 该类会长期保存使用过的材质信息,避重新分配造成的时间和空间浪费。如需彻底清空列表请使用Clear()函数
|
||||
*/
|
||||
class RenderList
|
||||
{
|
||||
GPUDevice * device;
|
||||
RenderCmdBuffer *cmd_buf;
|
||||
protected:
|
||||
|
||||
private:
|
||||
GPUDevice * device;
|
||||
|
||||
CameraInfo camera_info;
|
||||
|
||||
RenderNodeList render_node_list; ///<场景节点列表
|
||||
MaterialSets material_sets; ///<材质合集
|
||||
|
||||
RenderNodeComparator render_node_comparator;
|
||||
|
||||
private:
|
||||
|
||||
MVPArrayBuffer *mvp_array;
|
||||
List<Renderable *> ri_list;
|
||||
|
||||
VkDescriptorSet ds_list[(size_t)DescriptorSetType::RANGE_SIZE];
|
||||
DescriptorSet *renderable_desc_sets;
|
||||
|
||||
uint32_t ubo_offset;
|
||||
uint32_t ubo_align;
|
||||
uint renderable_count; ///<可渲染对象数量
|
||||
MaterialRenderMap mrl_map; ///<按材质分类的渲染列表
|
||||
|
||||
protected:
|
||||
|
||||
virtual bool Begin();
|
||||
virtual bool Expend(SceneNode *);
|
||||
virtual void End();
|
||||
|
||||
private:
|
||||
|
||||
Pipeline * last_pipeline;
|
||||
MaterialParameters *last_mp[(size_t)DescriptorSetType::RANGE_SIZE];
|
||||
uint32_t last_vbo;
|
||||
|
||||
void Render(Renderable *);
|
||||
virtual bool ExpendNode(SceneNode *);
|
||||
|
||||
public:
|
||||
|
||||
RenderList(GPUDevice *);
|
||||
virtual ~RenderList();
|
||||
|
||||
virtual bool Expend(const CameraInfo &,SceneNode *);
|
||||
virtual bool Expend(SceneNode *); ///<展开场景树到渲染列表
|
||||
|
||||
virtual bool Render(RenderCmdBuffer *);
|
||||
};//class RenderList
|
||||
virtual bool Render(RenderCmdBuffer *); ///<渲染所有对象
|
||||
|
||||
virtual void Clear(); ///<彻底清理
|
||||
};//class RenderList
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
#endif//HGL_GRAPH_RENDER_LIST_INCLUDE
|
||||
|
@@ -1,39 +1,29 @@
|
||||
#ifndef HGL_GRAPH_RENDER_NODE_INCLUDE
|
||||
#define HGL_GRAPH_RENDER_NODE_INCLUDE
|
||||
|
||||
#include<hgl/math/Vector.h>
|
||||
#include<hgl/type/List.h>
|
||||
#include<hgl/graph/SceneInfo.h>
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/type/SortedSets.h>
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
class Renderable;
|
||||
class Material;
|
||||
class MaterialInstance;
|
||||
class GPUDevice;
|
||||
struct VertexInputData;
|
||||
struct IndexBufferData;
|
||||
|
||||
struct RenderNode
|
||||
{
|
||||
MVPMatrix matrix;
|
||||
|
||||
Vector3f WorldCenter;
|
||||
|
||||
float distance_to_camera_square;
|
||||
// float distance_to_camera;
|
||||
Matrix4f local_to_world;
|
||||
|
||||
Renderable *ri;
|
||||
};
|
||||
|
||||
public:
|
||||
using RenderNodeList=List<RenderNode>;
|
||||
|
||||
/**
|
||||
* 取得渲染对象ubo独占区大小
|
||||
*/
|
||||
virtual const uint32 GetUBOBytes()const{return sizeof(MVPMatrix);}
|
||||
};//struct RenderNode
|
||||
|
||||
using RenderNodeList=List<RenderNode *>;
|
||||
using MaterialInstanceSets=SortedSets<MaterialInstance *>; ///<材质实例集合
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
|
||||
using RenderNodePointer=hgl::graph::RenderNode *;
|
||||
using RenderNodeComparator=Comparator<RenderNodePointer>;
|
||||
|
||||
#endif//HGL_GRAPH_RENDER_NODE_INCLUDE
|
||||
|
18
inc/hgl/graph/RenderTargetOutputConfig.h
Normal file
18
inc/hgl/graph/RenderTargetOutputConfig.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#ifndef HGL_GRAPH_RT_OUTPUT_CONFIG_INCLUDE
|
||||
#define HGL_GRAPH_RT_OUTPUT_CONFIG_INCLUDE
|
||||
|
||||
#include<hgl/type/DataType.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
struct RenderTargetOutputConfig
|
||||
{
|
||||
uint color; ///<要输出几个颜色缓冲区
|
||||
bool depth; ///<是否输出到深度缓冲区
|
||||
bool stencil; ///<是否输出到模板缓冲区
|
||||
};
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
#endif//HGL_GRAPH_RT_OUTPUT_CONFIG_INCLUDE
|
@@ -7,7 +7,7 @@ namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
/**
|
||||
/**
|
||||
* MVP矩阵
|
||||
*/
|
||||
struct MVPMatrix
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#ifndef HGL_GRAPH_SCENE_NODE_INCLUDE
|
||||
#define HGL_GRAPH_SCENE_NODE_INCLUDE
|
||||
|
||||
#include<hgl/type/List.h>
|
||||
#include<hgl/type/ObjectList.h>
|
||||
#include<hgl/graph/SceneOrient.h>
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/graph/AABB.h>
|
||||
@@ -43,7 +43,7 @@ namespace hgl
|
||||
|
||||
void Clear()
|
||||
{
|
||||
SubNode.ClearData();
|
||||
SubNode.Clear();
|
||||
render_obj=nullptr;
|
||||
}
|
||||
|
||||
|
25
inc/hgl/graph/StaticRenderManager.h
Normal file
25
inc/hgl/graph/StaticRenderManager.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#ifndef HGL_GRAPH_STATIC_RENDER_MANAGER_INCLUDE
|
||||
#define HGL_GRAPH_STATIC_RENDER_MANAGER_INCLUDE
|
||||
|
||||
#include<hgl/graph/VK.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
class RawMesh
|
||||
{
|
||||
};
|
||||
|
||||
/**
|
||||
* 静态渲染管理器<br>
|
||||
* 静态渲染指的是不会产生资源变动的内容,而不是指不会动的内容。
|
||||
*/
|
||||
class StaticRenderManager
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
virtual ~StaticRenderManager()=default;
|
||||
|
||||
};//class StaticRenderManager
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_STATIC_RENDER_MANAGER_INCLUDE
|
@@ -3,8 +3,8 @@
|
||||
|
||||
#include<hgl/io/InputStream.h>
|
||||
#include<hgl/type/String.h>
|
||||
#include<hgl/graph/Bitmap.h>
|
||||
#include<hgl/graph/VKFormat.h>
|
||||
#include<hgl/graph/BitmapData.h>
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
|
@@ -1,32 +1,17 @@
|
||||
#ifndef HGL_GRAPH_TILE_DATA_INCLUDE
|
||||
#define HGL_GRAPH_TILE_DATA_INCLUDE
|
||||
|
||||
#include<hgl/type/Map.h>
|
||||
#include<hgl/type/Pool.h>
|
||||
#include<hgl/type/RectScope.h>
|
||||
#include<hgl/graph/Bitmap.h>
|
||||
#include<hgl/graph/BitmapData.h>
|
||||
#include<hgl/graph/ImageRegion.h>
|
||||
#include<hgl/graph/tile/TileObject.h>
|
||||
#include<hgl/graph/VKTexture.h>
|
||||
|
||||
VK_NAMESPACE_USING
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
using TileUVPixel=RectScope2i;
|
||||
using TileUVFloat=RectScope2f;
|
||||
|
||||
using TileUVFloatList=List<TileUVFloat>;
|
||||
using TileUVFloatMap=Map<u32char,TileUVFloat>;
|
||||
|
||||
struct TileObject
|
||||
{
|
||||
int col,row; //当前tile在整个纹理中的tile位置
|
||||
|
||||
TileUVPixel uv_pixel; //以象素为单位的tile位置和尺寸
|
||||
TileUVFloat uv_float; //以浮点为单位的tile位置和尺寸
|
||||
};//struct TileObject
|
||||
|
||||
/**
|
||||
* TileData是一种处理大量等同尺寸及格式贴图的管理机制,程序会自动根据显卡最大贴图处理能力来创建尽可能符合需求的贴图。(注:Tile的大小不必符合2次幂)
|
||||
* Tile的增加或删除,程序会自动排序,尽可能小的减少I/O消耗。
|
||||
|
@@ -1,11 +1,10 @@
|
||||
#ifndef HGL_GRAPH_VULKAN_INCLUDE
|
||||
#define HGL_GRAPH_VULKAN_INCLUDE
|
||||
|
||||
#include<hgl/math/Math.h>
|
||||
#include<hgl/type/List.h>
|
||||
#include<hgl/math/Math.h>
|
||||
#include<hgl/type/String.h>
|
||||
#include<hgl/type/Map.h>
|
||||
#include<iostream>
|
||||
#include<hgl/graph/VKNamespace.h>
|
||||
#include<hgl/graph/VKFormat.h>
|
||||
#include<hgl/graph/VKPrimitiveType.h>
|
||||
@@ -33,12 +32,12 @@ class VulkanInstance;
|
||||
class GPUPhysicalDevice;
|
||||
class GPUDevice;
|
||||
struct GPUDeviceAttribute;
|
||||
class Queue;
|
||||
class DeviceQueue;
|
||||
class ImageView;
|
||||
class Framebuffer;
|
||||
struct Swapchain;
|
||||
class RenderTarget;
|
||||
class SwapchainRenderTarget;
|
||||
class RTSwapchain;
|
||||
|
||||
class Texture;
|
||||
class Texture1D;
|
||||
@@ -60,6 +59,12 @@ using VBO=VertexAttribBuffer;
|
||||
|
||||
class IndexBuffer;
|
||||
|
||||
struct IndexBufferData
|
||||
{
|
||||
IndexBuffer *buffer=nullptr;
|
||||
VkDeviceSize offset=0;
|
||||
};
|
||||
|
||||
class GPUCmdBuffer;
|
||||
class RenderCmdBuffer;
|
||||
class TextureCmdBuffer;
|
||||
@@ -70,43 +75,15 @@ class DeviceRenderPassManage;
|
||||
class Fence;
|
||||
class Semaphore;
|
||||
|
||||
enum class DescriptorSetType
|
||||
{
|
||||
//设计使其对应shader中的set
|
||||
|
||||
Global=0, ///<全局参数(如太阳光等)
|
||||
PerFrame, ///<帧参数(如摄像机等)
|
||||
PerMaterialInstance,///<材质实例参数(如纹理等)
|
||||
PerObject, ///<对象参数(如模型矩阵等)
|
||||
|
||||
Instance,
|
||||
Skeleton,
|
||||
|
||||
ENUM_CLASS_RANGE(Global,Skeleton)
|
||||
};//
|
||||
|
||||
constexpr char *DescriptSetsTypeName[]=
|
||||
{
|
||||
"Global","PerFrame","PerMaterialInstance","PerObject","Instance","Skeleton"
|
||||
};
|
||||
|
||||
inline const char *GetDescriptorSetTypeName(const enum class DescriptorSetType &type)
|
||||
{
|
||||
RANGE_CHECK_RETURN_NULLPTR(type);
|
||||
|
||||
return DescriptSetsTypeName[(size_t)type];
|
||||
}
|
||||
|
||||
struct PipelineLayoutData;
|
||||
class DescriptorSet;
|
||||
|
||||
struct ShaderStage;
|
||||
struct ShaderAttribute;
|
||||
|
||||
class ShaderResource;
|
||||
class ShaderModule;
|
||||
class VertexShaderModule;
|
||||
class ShaderModuleMap;
|
||||
class MaterialDescriptorSets;
|
||||
class MaterialDescriptorManager;
|
||||
|
||||
class Material;
|
||||
class MaterialParameters;
|
||||
@@ -115,39 +92,11 @@ struct PipelineData;
|
||||
enum class InlinePipeline;
|
||||
class Pipeline;
|
||||
|
||||
struct VAConfig
|
||||
{
|
||||
VkFormat format;
|
||||
bool instance;
|
||||
struct VAConfig;
|
||||
class VILConfig;
|
||||
class VertexInput;
|
||||
|
||||
public:
|
||||
|
||||
VAConfig()
|
||||
{
|
||||
format=PF_UNDEFINED;
|
||||
instance=false;
|
||||
}
|
||||
|
||||
VAConfig(const VkFormat fmt,bool inst=false)
|
||||
{
|
||||
format=fmt;
|
||||
instance=inst;
|
||||
}
|
||||
|
||||
CompOperatorMemcmp(const VAConfig &);
|
||||
};
|
||||
|
||||
class VILConfig:public Map<AnsiString,VAConfig>
|
||||
{
|
||||
public:
|
||||
|
||||
using Map<AnsiString,VAConfig>::Map;
|
||||
|
||||
bool Add(const AnsiString &name,const VkFormat fmt,const bool inst=false)
|
||||
{
|
||||
return Map<AnsiString,VAConfig>::Add(name,VAConfig(fmt,inst));
|
||||
}
|
||||
};
|
||||
struct VertexInputFormat;
|
||||
|
||||
class VertexInputLayout;
|
||||
using VIL=VertexInputLayout;
|
||||
@@ -188,38 +137,13 @@ inline const uint32_t GetMipLevel(const VkExtent3D &ext)
|
||||
/**
|
||||
* 索引类型,等同于VkIndexType
|
||||
*/
|
||||
enum IndexType
|
||||
enum IndexType:uint
|
||||
{
|
||||
U16=0,
|
||||
U32
|
||||
U32,
|
||||
U8=VK_INDEX_TYPE_UINT8_EXT,
|
||||
};
|
||||
|
||||
enum class ShaderStageBit
|
||||
{
|
||||
Vertex =VK_SHADER_STAGE_VERTEX_BIT,
|
||||
TessControl =VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
|
||||
TessEval =VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
|
||||
Geometry =VK_SHADER_STAGE_GEOMETRY_BIT,
|
||||
Fragment =VK_SHADER_STAGE_FRAGMENT_BIT,
|
||||
Compute =VK_SHADER_STAGE_COMPUTE_BIT
|
||||
};//enum class ShaderStageBit
|
||||
|
||||
inline const uint GetShaderCountByBits(const uint32_t bits)
|
||||
{
|
||||
uint comp=(uint)VK_SHADER_STAGE_VERTEX_BIT;
|
||||
uint result=0;
|
||||
|
||||
for(uint i=0;i<6;i++)
|
||||
{
|
||||
if(bits&comp)
|
||||
++result;
|
||||
|
||||
comp<<=1;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* max-lengths:
|
||||
*
|
||||
@@ -240,61 +164,5 @@ inline void copy(VkExtent3D &e3d,const VkExtent2D &e2d,const uint32 depth=1)
|
||||
e3d.height =e2d.height;
|
||||
e3d.depth =depth;
|
||||
}
|
||||
|
||||
inline void debug_out_vk_version(const uint32_t version)
|
||||
{
|
||||
std::cout<<VK_VERSION_MAJOR(version)<<"."
|
||||
<<VK_VERSION_MINOR(version)<<"."
|
||||
<<VK_VERSION_PATCH(version);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline hgl::String<T> VkUUID2String(const uint8_t *pipelineCacheUUID)
|
||||
{
|
||||
T *hstr=new T[VK_UUID_SIZE*2+1];
|
||||
|
||||
DataToLowerHexStr(hstr,pipelineCacheUUID,VK_UUID_SIZE);
|
||||
|
||||
return hgl::String<T>::newOf(hstr,VK_UUID_SIZE*2);
|
||||
}
|
||||
|
||||
inline void debug_out(const char *front,const hgl::List<VkLayerProperties> &layer_properties)
|
||||
{
|
||||
const int property_count=layer_properties.GetCount();
|
||||
|
||||
if(property_count<=0)return;
|
||||
|
||||
const VkLayerProperties *lp=layer_properties.GetData();
|
||||
|
||||
for(int i=0;i<property_count;i++)
|
||||
{
|
||||
std::cout<<front<<" Layer Propertyes ["<<i<<"] : "<<lp->layerName<<" [spec: ";
|
||||
debug_out_vk_version(lp->specVersion);
|
||||
|
||||
std::cout<<", impl: ";
|
||||
debug_out_vk_version(lp->implementationVersion);
|
||||
|
||||
std::cout<<"] desc: "<<lp->description<<std::endl;
|
||||
++lp;
|
||||
}
|
||||
}
|
||||
|
||||
inline void debug_out(const char *front,const hgl::List<VkExtensionProperties> &extension_properties)
|
||||
{
|
||||
const int extension_count=extension_properties.GetCount();
|
||||
|
||||
if(extension_count<=0)return;
|
||||
|
||||
VkExtensionProperties *ep=extension_properties.GetData();
|
||||
for(int i=0;i<extension_count;i++)
|
||||
{
|
||||
std::cout<<front<<" Extension Propertyes ["<<i<<"] : "<<ep->extensionName<<" ver: ";
|
||||
|
||||
debug_out_vk_version(ep->specVersion);
|
||||
|
||||
std::cout<<std::endl;
|
||||
++ep;
|
||||
}
|
||||
}
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_VULKAN_INCLUDE
|
||||
|
@@ -1,90 +1,75 @@
|
||||
#ifndef HGL_GRAPH_VULKAN_ARRAY_BUFFER_INCLUDE
|
||||
#define HGL_GRAPH_VULKAN_ARRAY_BUFFER_INCLUDE
|
||||
|
||||
#include<hgl/graph/VKBuffer.h>
|
||||
#include<hgl/graph/VKDevice.h>
|
||||
#include<hgl/graph/VKMemoryAllocator.h>
|
||||
#include<hgl/type/Collection.h>
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/graph/VKDynamicBufferAccess.h>
|
||||
namespace hgl
|
||||
{
|
||||
class Collection;
|
||||
|
||||
namespace graph
|
||||
{
|
||||
class VKMemoryAllocator;
|
||||
|
||||
/**
|
||||
* GPU数据阵列缓冲区<br>
|
||||
* 它用于储存多份相同格式的数据,常用于多物件渲染,instance等
|
||||
*/
|
||||
template<typename T> class GPUArrayBuffer
|
||||
class GPUArrayBuffer
|
||||
{
|
||||
protected:
|
||||
|
||||
GPUDevice *device;
|
||||
VkBufferUsageFlags buffer_usage_flags;
|
||||
VKMemoryAllocator *vk_ma;
|
||||
uint align_size;
|
||||
uint range_size;
|
||||
|
||||
uint32_t ubo_offset_alignment;
|
||||
VKMemoryAllocator *vk_ma;
|
||||
|
||||
Collection *coll;
|
||||
|
||||
protected:
|
||||
|
||||
void * Map(const uint32 start,const uint32 count);
|
||||
void Flush(const uint32 count);
|
||||
|
||||
private:
|
||||
|
||||
GPUArrayBuffer(VKMemoryAllocator *,const uint,const uint);
|
||||
|
||||
friend class GPUDevice;
|
||||
|
||||
public:
|
||||
|
||||
GPUArrayBuffer(GPUDevice *dev,VkBufferUsageFlags flags)
|
||||
virtual ~GPUArrayBuffer();
|
||||
|
||||
const uint32_t GetAlignSize()const{return align_size;} ///<数据对齐字节数
|
||||
const uint32_t GetRangeSize()const{return range_size;} ///<单次渲染访问最大字节数
|
||||
|
||||
DeviceBuffer * GetBuffer();
|
||||
|
||||
uint32 Alloc(const uint32 max_count); ///<预分配空间
|
||||
void Clear();
|
||||
|
||||
template<typename T>
|
||||
bool Start(DynamicBufferAccess<T> *dba,const uint32 start,const uint32 count)
|
||||
{
|
||||
device=dev;
|
||||
buffer_usage_flags=flags;
|
||||
if(!dba)return(false);
|
||||
|
||||
{
|
||||
ubo_offset_alignment=device->GetUBOAlign();
|
||||
void *ptr=Map(start,count);
|
||||
|
||||
const uint32_t unit_size=hgl_align<uint32_t>(sizeof(T),ubo_offset_alignment);
|
||||
if(!ptr)return(false);
|
||||
|
||||
vk_ma=new VKMemoryAllocator(device,buffer_usage_flags,unit_size); // construct function is going to set AllocUnitSize by minUniformOffsetAlignment
|
||||
MemoryBlock *mb=new MemoryBlock(vk_ma);
|
||||
|
||||
coll=new Collection(unit_size,mb);
|
||||
}
|
||||
dba->Start((uchar *)ptr,align_size,count);
|
||||
return(true);
|
||||
}
|
||||
|
||||
virtual ~GPUArrayBuffer()
|
||||
template<typename T>
|
||||
void End(DynamicBufferAccess<T> *dba)
|
||||
{
|
||||
delete coll;
|
||||
}
|
||||
if(!dba)return;
|
||||
|
||||
const uint32_t GetOffsetAlignment()const
|
||||
{
|
||||
return ubo_offset_alignment;
|
||||
}
|
||||
Flush(dba->GetCount());
|
||||
|
||||
const uint32_t GetUnitSize()const
|
||||
{
|
||||
return coll->GetUnitBytes();
|
||||
}
|
||||
|
||||
DeviceBuffer *GetBuffer()
|
||||
{
|
||||
return vk_ma->GetBuffer();
|
||||
}
|
||||
|
||||
uint32 Alloc(const uint32 max_count) ///<预分配空间
|
||||
{
|
||||
if(!coll->Alloc(max_count))
|
||||
return(0);
|
||||
|
||||
return coll->GetAllocCount();
|
||||
}
|
||||
|
||||
void Clear()
|
||||
{
|
||||
coll->Clear();
|
||||
}
|
||||
|
||||
T *Map(const uint32 start,const uint32 count)
|
||||
{
|
||||
return (T *)(coll->Map(start,count));
|
||||
}
|
||||
|
||||
void Flush(const uint32 count)
|
||||
{
|
||||
vk_ma->Flush(count*GetUnitSize());
|
||||
dba->Restart();
|
||||
}
|
||||
};//class GPUArrayBuffer
|
||||
}//namespace graph
|
||||
|
@@ -2,6 +2,7 @@
|
||||
#define HGL_GRAPH_VULKAN_COMMAND_BUFFER_INCLUDE
|
||||
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/graph/VKVBOList.h>
|
||||
#include<hgl/graph/VKPipeline.h>
|
||||
#include<hgl/graph/VKDescriptorSet.h>
|
||||
#include<hgl/color/Color4f.h>
|
||||
@@ -140,14 +141,14 @@ public:
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool BindDescriptorSets(Renderable *ri);
|
||||
bool BindDescriptorSets(Material *);
|
||||
|
||||
bool PushDescriptorSet(VkPipelineLayout pipeline_layout,uint32_t set,uint32_t count,const VkWriteDescriptorSet *write_desc_set)
|
||||
{
|
||||
vkCmdPushDescriptorSetKHR(cmd_buf,VK_PIPELINE_BIND_POINT_GRAPHICS,pipeline_layout,set,count,write_desc_set);
|
||||
}
|
||||
|
||||
void PushConstants(ShaderStageBit shader_stage_bit,uint32_t offset,uint32_t size,const void *pValues)
|
||||
void PushConstants(VkShaderStageFlagBits shader_stage_bit,uint32_t offset,uint32_t size,const void *pValues)
|
||||
{
|
||||
vkCmdPushConstants(cmd_buf,pipeline_layout,(VkShaderStageFlagBits)shader_stage_bit,offset,size,pValues);
|
||||
}
|
||||
@@ -155,6 +156,24 @@ public:
|
||||
void PushConstants(const void *data,const uint32_t size) {vkCmdPushConstants(cmd_buf,pipeline_layout,VK_SHADER_STAGE_VERTEX_BIT,0, size,data);}
|
||||
void PushConstants(const void *data,const uint32_t offset,const uint32_t size) {vkCmdPushConstants(cmd_buf,pipeline_layout,VK_SHADER_STAGE_VERTEX_BIT,offset, size,data);}
|
||||
|
||||
void BindVBO(const uint32_t first,const uint32_t count,const VkBuffer *vbo,const VkDeviceSize *offsets)
|
||||
{
|
||||
vkCmdBindVertexBuffers(cmd_buf,first,count,vbo,offsets);
|
||||
}
|
||||
|
||||
bool BindVBO(VBOList *vbo_list)
|
||||
{
|
||||
if(!vbo_list)return(false);
|
||||
|
||||
if(!vbo_list->IsFull())return(false);
|
||||
|
||||
vkCmdBindVertexBuffers(cmd_buf,0,vbo_list->binding_count,vbo_list->buffer_list,vbo_list->buffer_offset);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void BindIBO(const IndexBufferData *);
|
||||
|
||||
bool BindVBO(Renderable *);
|
||||
|
||||
void SetViewport (uint32_t first,uint32_t count,const VkViewport *vp) {vkCmdSetViewport(cmd_buf,first,count,vp);}
|
||||
@@ -176,7 +195,7 @@ public: //draw
|
||||
void DrawIndexed (const uint32_t index_count ) {vkCmdDrawIndexed(cmd_buf,index_count,1,0,0,0);}
|
||||
void Draw (const uint32_t vertex_count,const uint32_t instance_count) {vkCmdDraw(cmd_buf,vertex_count,instance_count,0,0);}
|
||||
void DrawIndexed (const uint32_t index_count ,const uint32_t instance_count) {vkCmdDrawIndexed(cmd_buf,index_count,instance_count,0,0,0);}
|
||||
|
||||
|
||||
template<typename ...ARGS> void Draw (ARGS...args) {vkCmdDraw(cmd_buf,args...);}
|
||||
template<typename ...ARGS> void DrawIndexed (ARGS...args) {vkCmdDrawIndexed(cmd_buf,args...);}
|
||||
|
||||
|
100
inc/hgl/graph/VKDescriptorBindingManage.h
Normal file
100
inc/hgl/graph/VKDescriptorBindingManage.h
Normal file
@@ -0,0 +1,100 @@
|
||||
#ifndef HGL_GRAPH_DESCRIPTOR_BINDING_MANAGE_INCLUDE
|
||||
#define HGL_GRAPH_DESCRIPTOR_BINDING_MANAGE_INCLUDE
|
||||
|
||||
#include<hgl/type/Map.h>
|
||||
#include<hgl/type/String.h>
|
||||
#include<hgl/graph/VKDescriptorSetType.h>
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
class DeviceBuffer;
|
||||
class Texture;
|
||||
class Material;
|
||||
|
||||
class DescriptorBinding
|
||||
{
|
||||
DescriptorSetType set_type;
|
||||
|
||||
Map<AnsiString,DeviceBuffer *> ubo_map;
|
||||
Map<AnsiString,DeviceBuffer *> ssbo_map;
|
||||
Map<AnsiString,Texture *> texture_map;
|
||||
|
||||
public:
|
||||
|
||||
DescriptorBinding(const DescriptorSetType &dst)
|
||||
{
|
||||
set_type=dst;
|
||||
}
|
||||
|
||||
bool AddUBO(const AnsiString &name,DeviceBuffer *buf)
|
||||
{
|
||||
if(!buf)return(false);
|
||||
if(name.IsEmpty())return(false);
|
||||
|
||||
return ubo_map.Add(name,buf);
|
||||
}
|
||||
|
||||
DeviceBuffer *GetUBO(const AnsiString &name)
|
||||
{
|
||||
if(name.IsEmpty())return(nullptr);
|
||||
|
||||
return GetListObject(ubo_map,name);
|
||||
}
|
||||
|
||||
void RemoveUBO(DeviceBuffer *buf)
|
||||
{
|
||||
if(!buf)return;
|
||||
|
||||
ubo_map.DeleteByValue(buf);
|
||||
}
|
||||
|
||||
bool AddSSBO(const AnsiString &name,DeviceBuffer *buf)
|
||||
{
|
||||
if(!buf)return(false);
|
||||
if(name.IsEmpty())return(false);
|
||||
|
||||
return ssbo_map.Add(name,buf);
|
||||
}
|
||||
|
||||
DeviceBuffer *GetSSBO(const AnsiString &name)
|
||||
{
|
||||
if(name.IsEmpty())return(nullptr);
|
||||
|
||||
return GetListObject(ssbo_map,name);
|
||||
}
|
||||
|
||||
void RemoveSSBO(DeviceBuffer *buf)
|
||||
{
|
||||
if(!buf)return;
|
||||
|
||||
ssbo_map.DeleteByValue(buf);
|
||||
}
|
||||
|
||||
bool AddTexture(const AnsiString &name,Texture *tex)
|
||||
{
|
||||
if(!tex)return(false);
|
||||
if(name.IsEmpty())return(false);
|
||||
|
||||
return texture_map.Add(name,tex);
|
||||
}
|
||||
|
||||
Texture *GetTexture(const AnsiString &name)
|
||||
{
|
||||
if(name.IsEmpty())return(nullptr);
|
||||
|
||||
return GetListObject(texture_map,name);
|
||||
}
|
||||
|
||||
void RemoveTexture(Texture *tex)
|
||||
{
|
||||
if(!tex)return;
|
||||
|
||||
texture_map.DeleteByValue(tex);
|
||||
}
|
||||
|
||||
bool Bind(Material *);
|
||||
};//class DescriptorBinding
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
#endif//HGL_GRAPH_DESCRIPTOR_BINDING_MANAGE_INCLUDE
|
@@ -1,8 +1,9 @@
|
||||
#ifndef HGL_GRAPH_VULKAN_DESCRIPTOR_SETS_LAYOUT_INCLUDE
|
||||
#define HGL_GRAPH_VULKAN_DESCRIPTOR_SETS_LAYOUT_INCLUDE
|
||||
#ifndef HGL_GRAPH_VULKAN_DESCRIPTOR_SET_INCLUDE
|
||||
#define HGL_GRAPH_VULKAN_DESCRIPTOR_SET_INCLUDE
|
||||
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/type/Map.h>
|
||||
#include<hgl/type/ObjectList.h>
|
||||
#include<hgl/type/SortedSets.h>
|
||||
VK_NAMESPACE_BEGIN
|
||||
class DeviceBuffer;
|
||||
@@ -23,9 +24,7 @@ class DescriptorSet
|
||||
|
||||
bool is_dirty;
|
||||
|
||||
private:
|
||||
|
||||
friend class GPUDevice;
|
||||
public:
|
||||
|
||||
DescriptorSet(VkDevice dev,const int bc,VkPipelineLayout pl,VkDescriptorSet ds)
|
||||
{
|
||||
@@ -37,8 +36,6 @@ private:
|
||||
is_dirty=true;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
~DescriptorSet()=default;
|
||||
|
||||
const uint32_t GetCount ()const{return binding_count;}
|
||||
@@ -59,4 +56,4 @@ public:
|
||||
void Update();
|
||||
};//class DescriptorSet
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_VULKAN_DESCRIPTOR_SETS_LAYOUT_INCLUDE
|
||||
#endif//HGL_GRAPH_VULKAN_DESCRIPTOR_SET_INCLUDE
|
||||
|
@@ -5,8 +5,9 @@
|
||||
#include<hgl/type/String.h>
|
||||
#include<hgl/type/Map.h>
|
||||
#include<hgl/type/RectScope.h>
|
||||
#include<hgl/graph/ImageRegion.h>
|
||||
#include<hgl/platform/Window.h>
|
||||
#include<hgl/graph/Bitmap.h>
|
||||
#include<hgl/graph/BitmapData.h>
|
||||
#include<hgl/graph/font/Font.h>
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/graph/VKDeviceAttribute.h>
|
||||
@@ -15,35 +16,19 @@
|
||||
#include<hgl/graph/VertexAttribData.h>
|
||||
#include<hgl/graph/VKShaderModuleMap.h>
|
||||
#include<hgl/graph/VKArrayBuffer.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
class TileData;
|
||||
class TileFont;
|
||||
class FontSource;
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
#include<hgl/graph/VKDescriptorSetType.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
/*
|
||||
* GPU设备创建信息
|
||||
*/
|
||||
struct GPUDeviceCreateInfo
|
||||
{
|
||||
VkPhysicalDeviceType device_type =VK_PHYSICAL_DEVICE_TYPE_MAX_ENUM;
|
||||
|
||||
uint32_t swapchain_image_count =0;
|
||||
VkSurfaceFormatKHR color_format ={PF_A2BGR10UN,VK_COLOR_SPACE_SRGB_NONLINEAR_KHR};
|
||||
VkFormat depth_format =VK_FORMAT_UNDEFINED;
|
||||
};//struct GPUDeviceCreateInfo
|
||||
class TileData;
|
||||
class TileFont;
|
||||
class FontSource;
|
||||
class GPUArrayBuffer;
|
||||
|
||||
class GPUDevice
|
||||
{
|
||||
GPUDeviceAttribute *attr;
|
||||
|
||||
Queue *texture_queue;
|
||||
DeviceQueue *texture_queue;
|
||||
TextureCmdBuffer *texture_cmd_buf;
|
||||
|
||||
private:
|
||||
@@ -51,9 +36,9 @@ private:
|
||||
DeviceRenderPassManage *render_pass_manage;
|
||||
RenderPass *device_render_pass;
|
||||
|
||||
SwapchainRenderTarget *swapchainRT;
|
||||
RTSwapchain *sc_rt;
|
||||
|
||||
SwapchainRenderTarget *CreateSwapchainRenderTarget();
|
||||
RTSwapchain *CreateSwapchainRenderTarget();
|
||||
|
||||
void InitRenderPassManage();
|
||||
void ClearRenderPassManage();
|
||||
@@ -68,7 +53,7 @@ private:
|
||||
|
||||
private:
|
||||
|
||||
friend GPUDevice *CreateRenderDevice(VulkanInstance *inst,const GPUPhysicalDevice *physical_device,VkSurfaceKHR surface,const VkExtent2D &extent);
|
||||
friend class VulkanDeviceCreater;
|
||||
|
||||
GPUDevice(GPUDeviceAttribute *da);
|
||||
|
||||
@@ -92,9 +77,9 @@ public:
|
||||
|
||||
RenderPass * GetRenderPass () {return device_render_pass;}
|
||||
|
||||
SwapchainRenderTarget * GetSwapchainRT () {return swapchainRT;}
|
||||
RTSwapchain * GetSwapchainRT () {return sc_rt;}
|
||||
|
||||
const VkExtent2D & GetSwapchainSize ()const {return swapchainRT->GetExtent();}
|
||||
const VkExtent2D & GetSwapchainSize ()const {return sc_rt->GetExtent();}
|
||||
|
||||
void WaitIdle ()const {vkDeviceWaitIdle(attr->device);}
|
||||
|
||||
@@ -128,17 +113,22 @@ public: //Buffer相关
|
||||
|
||||
VBO * CreateVBO (VkFormat format, uint32_t count,const void *data, SharingMode sm=SharingMode::Exclusive);
|
||||
VBO * CreateVBO (VkFormat format, uint32_t count, SharingMode sm=SharingMode::Exclusive){return CreateVBO(format,count,nullptr,sm);}
|
||||
VBO * CreateVBO (const VAD *vad, SharingMode sm=SharingMode::Exclusive){return CreateVBO(vad->GetVulkanFormat(),vad->GetCount(),vad->GetData(),sm);}
|
||||
VBO * CreateVBO (const VAD *vad, SharingMode sm=SharingMode::Exclusive){return CreateVBO(vad->GetFormat(),vad->GetCount(),vad->GetData(),sm);}
|
||||
|
||||
IndexBuffer * CreateIBO (IndexType type, uint32_t count,const void * data, SharingMode sm=SharingMode::Exclusive);
|
||||
IndexBuffer * CreateIBO8 ( uint32_t count,const void * data, SharingMode sm=SharingMode::Exclusive){return CreateIBO(IndexType::U8, count,(void *)data,sm);}
|
||||
IndexBuffer * CreateIBO16 ( uint32_t count,const uint16 *data, SharingMode sm=SharingMode::Exclusive){return CreateIBO(IndexType::U16, count,(void *)data,sm);}
|
||||
IndexBuffer * CreateIBO32 ( uint32_t count,const uint32 *data, SharingMode sm=SharingMode::Exclusive){return CreateIBO(IndexType::U32, count,(void *)data,sm);}
|
||||
|
||||
IndexBuffer * CreateIBO (IndexType type, uint32_t count, SharingMode sm=SharingMode::Exclusive){return CreateIBO(type, count,nullptr,sm);}
|
||||
IndexBuffer * CreateIBO8 ( uint32_t count, SharingMode sm=SharingMode::Exclusive){return CreateIBO(IndexType::U8, count,nullptr,sm);}
|
||||
IndexBuffer * CreateIBO16 ( uint32_t count, SharingMode sm=SharingMode::Exclusive){return CreateIBO(IndexType::U16, count,nullptr,sm);}
|
||||
IndexBuffer * CreateIBO32 ( uint32_t count, SharingMode sm=SharingMode::Exclusive){return CreateIBO(IndexType::U32, count,nullptr,sm);}
|
||||
|
||||
const VkDeviceSize GetUBOAlign();
|
||||
const VkDeviceSize GetSSBOAlign();
|
||||
const VkDeviceSize GetUBORange();
|
||||
const VkDeviceSize GetSSBORange();
|
||||
|
||||
#define CREATE_BUFFER_OBJECT(LargeName,type) 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);} \
|
||||
@@ -151,6 +141,9 @@ public: //Buffer相关
|
||||
|
||||
#undef CREATE_BUFFER_OBJECT
|
||||
|
||||
GPUArrayBuffer *CreateArrayInUBO(const VkDeviceSize &uint_size);
|
||||
GPUArrayBuffer *CreateArrayInSSBO(const VkDeviceSize &uint_size);
|
||||
|
||||
public: //Image
|
||||
|
||||
VkImage CreateImage (VkImageCreateInfo *);
|
||||
@@ -182,32 +175,9 @@ public: //Texture
|
||||
|
||||
void Clear(TextureCreateInfo *);
|
||||
|
||||
bool ChangeTexture2D(Texture2D *,DeviceBuffer *buf,const List<Image2DRegion> &, VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
||||
bool ChangeTexture2D(Texture2D *,DeviceBuffer *buf,uint32_t left,uint32_t top,uint32_t width,uint32_t height, VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
||||
bool ChangeTexture2D(Texture2D *,void *data, uint32_t left,uint32_t top,uint32_t width,uint32_t height,uint32_t size,VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
||||
|
||||
template<typename T>
|
||||
bool ChangeTexture2D(Texture2D *tex,DeviceBuffer *buf,const RectScope2<T> &rs)
|
||||
{
|
||||
return ChangeTexture2D( tex,
|
||||
buf,
|
||||
rs.GetLeft(),
|
||||
rs.GetTop(),
|
||||
rs.GetWidth(),
|
||||
rs.GetHeight());
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool ChangeTexture2D(Texture2D *tex,void *data,const RectScope2<T> &rs,uint32_t size)
|
||||
{
|
||||
return ChangeTexture2D( tex,
|
||||
data,
|
||||
rs.GetLeft(),
|
||||
rs.GetTop(),
|
||||
rs.GetWidth(),
|
||||
rs.GetHeight(),
|
||||
size);
|
||||
}
|
||||
bool ChangeTexture2D(Texture2D *,DeviceBuffer *buf, const List<Image2DRegion> &,VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
||||
bool ChangeTexture2D(Texture2D *,DeviceBuffer *buf, const RectScope2ui &, VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
||||
bool ChangeTexture2D(Texture2D *,void *data,const uint32_t size,const RectScope2ui &, VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
||||
|
||||
public: //
|
||||
|
||||
@@ -216,20 +186,11 @@ public: //
|
||||
|
||||
public: //shader & material
|
||||
|
||||
PipelineLayoutData *CreatePipelineLayoutData(const MaterialDescriptorSets *);
|
||||
void Destroy(PipelineLayoutData *);
|
||||
ShaderModule *CreateShaderModule(VkShaderStageFlagBits,const uint32_t *,const size_t);
|
||||
|
||||
DescriptorSet * CreateDescriptorSets(const PipelineLayoutData *,const DescriptorSetType &type)const;
|
||||
MaterialParameters *CreateMP(const MaterialDescriptorSets *,const PipelineLayoutData *,const DescriptorSetType &);
|
||||
MaterialParameters *CreateMP(Material *,const DescriptorSetType &);
|
||||
|
||||
ShaderModule *CreateShaderModule(ShaderResource *);
|
||||
|
||||
Material *CreateMaterial(const UTF8String &mtl_name,ShaderModuleMap *shader_maps,MaterialDescriptorSets *);
|
||||
Material *CreateMaterial(const UTF8String &mtl_name,const VertexShaderModule *vertex_shader_module,const ShaderModule *fragment_shader_module,MaterialDescriptorSets *);
|
||||
Material *CreateMaterial(const UTF8String &mtl_name,const VertexShaderModule *vertex_shader_module,const ShaderModule *geometry_shader_module,const ShaderModule *fragment_shader_module,MaterialDescriptorSets *);
|
||||
PipelineLayoutData *CreatePipelineLayoutData(const MaterialDescriptorManager *desc_manager);
|
||||
|
||||
MaterialInstance *CreateMI(Material *,const VILConfig *vil_cfg=nullptr);
|
||||
MaterialParameters *CreateMP(const MaterialDescriptorManager *desc_manager,const PipelineLayoutData *pld,const DescriptorSetType &desc_set_type);
|
||||
|
||||
public: //Command Buffer 相关
|
||||
|
||||
@@ -243,27 +204,25 @@ public:
|
||||
Fence * CreateFence(bool);
|
||||
Semaphore * CreateGPUSemaphore();
|
||||
|
||||
Queue * CreateQueue(const uint32_t fence_count=1,const bool create_signaled=false);
|
||||
DeviceQueue *CreateQueue(const uint32_t fence_count=1,const bool create_signaled=false);
|
||||
|
||||
public: //FrameBuffer相关
|
||||
|
||||
Framebuffer *CreateFramebuffer(RenderPass *rp,ImageView **color_list,const uint color_count,ImageView *depth);
|
||||
// Framebuffer *CreateFramebuffer(RenderPass *,List<ImageView *> &color,ImageView *depth);
|
||||
Framebuffer *CreateFramebuffer(RenderPass *,ImageView *color,ImageView *depth);
|
||||
Framebuffer *CreateFramebuffer(RenderPass *,ImageView *);
|
||||
Framebuffer *CreateFBO(RenderPass *rp,ImageView **color_list,const uint color_count,ImageView *depth);
|
||||
// Framebuffer *CreateFBO(RenderPass *,List<ImageView *> &color,ImageView *depth);
|
||||
Framebuffer *CreateFBO(RenderPass *,ImageView *color,ImageView *depth);
|
||||
Framebuffer *CreateFBO(RenderPass *,ImageView *);
|
||||
|
||||
public:
|
||||
|
||||
RenderTarget *CreateRenderTarget( const FramebufferInfo *fbi,RenderPass *,const uint32_t fence_count=1);
|
||||
RenderTarget *CreateRenderTarget( const FramebufferInfo *fbi,const uint32_t fence_count=1);
|
||||
RenderTarget *CreateRT( const FramebufferInfo *fbi,RenderPass *,const uint32_t fence_count=1);
|
||||
RenderTarget *CreateRT( const FramebufferInfo *fbi,const uint32_t fence_count=1);
|
||||
|
||||
public:
|
||||
|
||||
TileData *CreateTileData(const VkFormat video_format,const uint width,const uint height,const uint count); ///<创建一个Tile数据集
|
||||
|
||||
TileFont *CreateTileFont(FontSource *fs,int limit_count=-1); ///<创建一个Tile字体
|
||||
TileFont *CreateTileFont(FontSource *fs,int limit_count=-1); ///<创建一个Tile字体
|
||||
};//class GPUDevice
|
||||
|
||||
GPUDevice *CreateRenderDevice(VulkanInstance *inst,Window *win,const GPUPhysicalDevice *physical_device=nullptr);
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_VULKAN_DEVICE_INCLUDE
|
||||
|
@@ -22,30 +22,31 @@ struct GPUDeviceAttribute
|
||||
VkSurfaceKHR surface =VK_NULL_HANDLE;
|
||||
VkSurfaceCapabilitiesKHR surface_caps;
|
||||
|
||||
uint32_t graphics_family =ERROR_FAMILY_INDEX;
|
||||
uint32_t present_family =ERROR_FAMILY_INDEX;
|
||||
uint32_t compute_family =ERROR_FAMILY_INDEX;
|
||||
uint32_t graphics_family =ERROR_FAMILY_INDEX;
|
||||
uint32_t present_family =ERROR_FAMILY_INDEX;
|
||||
uint32_t compute_family =ERROR_FAMILY_INDEX;
|
||||
uint32_t video_decode_family =ERROR_FAMILY_INDEX;
|
||||
|
||||
#ifdef VK_ENABLE_BETA_EXTENSIONS
|
||||
uint32_t video_encode_family =ERROR_FAMILY_INDEX;
|
||||
#endif//VK_ENABLE_BETA_EXTENSIONS
|
||||
|
||||
VkQueue graphics_queue =VK_NULL_HANDLE;
|
||||
VkQueue present_queue =VK_NULL_HANDLE;
|
||||
|
||||
List<VkQueueFamilyProperties> family_properties;
|
||||
List<VkBool32> supports_present;
|
||||
|
||||
List<VkSurfaceFormatKHR> surface_formats_list;
|
||||
VkSurfaceFormatKHR surface_format;
|
||||
List<VkPresentModeKHR> present_modes;
|
||||
|
||||
VkSurfaceTransformFlagBitsKHR preTransform;
|
||||
VkCompositeAlphaFlagBitsKHR compositeAlpha =VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
|
||||
|
||||
|
||||
VkDevice device =VK_NULL_HANDLE;
|
||||
VkCommandPool cmd_pool =VK_NULL_HANDLE;
|
||||
|
||||
VkDescriptorPool desc_pool =VK_NULL_HANDLE;
|
||||
|
||||
VkPipelineCache pipeline_cache =VK_NULL_HANDLE;
|
||||
|
||||
|
||||
#ifdef _DEBUG
|
||||
DebugMaker * debug_maker =nullptr;
|
||||
DebugUtils * debug_utils =nullptr;
|
||||
|
312
inc/hgl/graph/VKDeviceCreater.h
Normal file
312
inc/hgl/graph/VKDeviceCreater.h
Normal file
@@ -0,0 +1,312 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/graph/VKDevice.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
struct VulkanHardwareRequirement
|
||||
{
|
||||
uint min_1d_image_size;
|
||||
uint min_2d_image_size;
|
||||
uint min_3d_image_size;
|
||||
uint min_cube_image_size;
|
||||
uint min_array_image_layers;
|
||||
|
||||
uint min_vertex_input_attribute; ///<最小顶点输入属性数量需求
|
||||
uint min_color_attachments; ///<最小颜色输出成份数量需求
|
||||
|
||||
uint min_push_constant_size; ///<最小push constant大小
|
||||
uint min_ubo_range; ///<最小ubo range需求
|
||||
uint min_ssbo_range; ///<最小ssbo range需求
|
||||
|
||||
uint min_draw_indirect_count; ///<最小间接绘制次数需求
|
||||
|
||||
bool geometry_shader; ///<要求支持几何着色器
|
||||
bool tessellation_shader; ///<要求支持细分着色器
|
||||
// bool compute_shader; ///<要求支持计算着色器
|
||||
|
||||
bool multi_draw_indirect; ///<要求支持MultiDrawIndirect
|
||||
|
||||
bool wide_lines; ///<要求支持宽线条
|
||||
bool line_rasterization; ///<要支持线条特性(这功能mac/ios平台不支持)
|
||||
bool large_points; ///<要求支持绘制大点
|
||||
|
||||
bool texture_cube_array; ///<要求支持立方体数组纹理
|
||||
|
||||
bool uint8_draw_index; ///<要求支持8位索引
|
||||
bool uint32_draw_index; ///<要求支持32位索引(不建议使用)
|
||||
|
||||
struct
|
||||
{
|
||||
bool bc,etc2,astc_ldr,astc_hdr,pvrtc; ///<要求支持的压缩纹理格式
|
||||
}texture_compression;
|
||||
|
||||
//dynamic_state VK_EXT_extended_dynamic_state
|
||||
// cull mode
|
||||
// front face
|
||||
// primitive topology
|
||||
// viewport
|
||||
// scissor
|
||||
// bind vbo
|
||||
// depth test
|
||||
// depth write
|
||||
// depth compare op
|
||||
// depth bounds test
|
||||
// stencil test
|
||||
// stencil op
|
||||
//dynamic_state[1] VK_EXT_extended_dynamic_state2
|
||||
// patch control points
|
||||
// rasterizer discard
|
||||
// depth bias
|
||||
// logic op
|
||||
// primitive restart
|
||||
//dynamic_state[2] VK_EXT_extended_dynamic_state3
|
||||
// tess domain origin
|
||||
// depth clamp
|
||||
// discard polygon mode
|
||||
// rasterization samples
|
||||
// sample mask
|
||||
// alpha to coverage
|
||||
// alpha to one
|
||||
// logic op enable
|
||||
// color blend
|
||||
// color blend equation
|
||||
// color write mask
|
||||
// depth clamp
|
||||
// Color blend advanced
|
||||
// line rasterization mode
|
||||
// line stipple
|
||||
// depth clip -1 to 1
|
||||
// shading rate image enable
|
||||
bool dynamic_state[3]; ///<要求支持动态状态
|
||||
|
||||
// 1.3 特性
|
||||
bool dynamic_rendering; ///<要求支持动态渲染
|
||||
|
||||
uint32_t descriptor_pool; ///<描述符池大小(默认1024)
|
||||
|
||||
public:
|
||||
|
||||
VulkanHardwareRequirement()
|
||||
{
|
||||
hgl_zero(*this);
|
||||
|
||||
descriptor_pool=1024;
|
||||
}
|
||||
};
|
||||
|
||||
constexpr const VkFormat SwapchainPreferFormatsLDR[]=
|
||||
{
|
||||
PF_RGB5A1,
|
||||
PF_BGR5A1,
|
||||
PF_A1RGB5,
|
||||
PF_RGB565,
|
||||
PF_BGR565,
|
||||
};
|
||||
|
||||
constexpr const VkFormat SwapchainPreferFormatsSDR[]=
|
||||
{
|
||||
PF_RGBA8UN,//PF_RGBA8s,
|
||||
PF_BGRA8UN,//PF_BGRA8s,
|
||||
PF_ABGR8UN,//PF_ABGR8s,
|
||||
PF_A2RGB10UN,
|
||||
PF_A2BGR10UN,
|
||||
// PF_B10GR11UF
|
||||
};
|
||||
|
||||
constexpr const VkFormat SwapchainPreferFormatsHDR16[]=
|
||||
{
|
||||
PF_RGBA16UN,PF_RGBA16SN,PF_RGBA16F
|
||||
};
|
||||
|
||||
constexpr const VkFormat SwapchainPreferFormatsHDR32[]=
|
||||
{
|
||||
PF_RGB32F,
|
||||
PF_RGBA32F
|
||||
};
|
||||
|
||||
constexpr const VkFormat SwapchainPreferFormatsHDR[]=
|
||||
{
|
||||
PF_RGBA16UN,PF_RGBA16SN,PF_RGBA16F,
|
||||
PF_RGB32F,PF_RGBA32F
|
||||
};
|
||||
|
||||
constexpr const VkFormat SwapchainPreferFormatsDepth[]=
|
||||
{
|
||||
PF_D16UN,
|
||||
PF_X8_D24UN,
|
||||
PF_D16UN_S8U,
|
||||
PF_D24UN_S8U,
|
||||
PF_D32F,
|
||||
PF_D32F_S8U
|
||||
};
|
||||
|
||||
constexpr const VkColorSpaceKHR SwapchainPreferColorSpacesNonlinear[]=
|
||||
{
|
||||
VK_COLOR_SPACE_SRGB_NONLINEAR_KHR,
|
||||
VK_COLOR_SPACE_DISPLAY_P3_NONLINEAR_EXT,
|
||||
VK_COLOR_SPACE_DCI_P3_NONLINEAR_EXT,
|
||||
VK_COLOR_SPACE_BT709_NONLINEAR_EXT,
|
||||
VK_COLOR_SPACE_ADOBERGB_NONLINEAR_EXT,
|
||||
VK_COLOR_SPACE_EXTENDED_SRGB_NONLINEAR_EXT,
|
||||
VK_COLOR_SPACE_DISPLAY_NATIVE_AMD,
|
||||
};
|
||||
|
||||
constexpr const VkColorSpaceKHR SwapchainPreferColorSpacesLinear[]=
|
||||
{
|
||||
VK_COLOR_SPACE_EXTENDED_SRGB_LINEAR_EXT,
|
||||
VK_COLOR_SPACE_DISPLAY_P3_LINEAR_EXT,
|
||||
VK_COLOR_SPACE_BT709_LINEAR_EXT,
|
||||
VK_COLOR_SPACE_BT2020_LINEAR_EXT,
|
||||
VK_COLOR_SPACE_HDR10_ST2084_EXT,
|
||||
VK_COLOR_SPACE_DOLBYVISION_EXT,
|
||||
VK_COLOR_SPACE_HDR10_HLG_EXT,
|
||||
VK_COLOR_SPACE_ADOBERGB_LINEAR_EXT,
|
||||
};
|
||||
|
||||
struct PreferFormats
|
||||
{
|
||||
//偏好格式需从低质量到高质量排列
|
||||
const VkFormat *formats;
|
||||
uint count;
|
||||
|
||||
public:
|
||||
|
||||
const int Find(const VkFormat fmt)const
|
||||
{
|
||||
for(uint i=0;i<count;i++)
|
||||
if(fmt==formats[i])
|
||||
return i;
|
||||
|
||||
return -1;
|
||||
}
|
||||
};
|
||||
|
||||
struct PreferColorSpaces
|
||||
{
|
||||
//偏好格式需从低质量到高质量排列
|
||||
const VkColorSpaceKHR *colorspaces;
|
||||
uint count;
|
||||
|
||||
public:
|
||||
|
||||
const int Find(const VkColorSpaceKHR cs)const
|
||||
{
|
||||
for(uint i=0;i<count;i++)
|
||||
if(cs==colorspaces[i])
|
||||
return i;
|
||||
|
||||
return -1;
|
||||
}
|
||||
};
|
||||
|
||||
constexpr const PreferFormats PreferLDR {SwapchainPreferFormatsLDR, sizeof(SwapchainPreferFormatsLDR )/sizeof(VkFormat)};
|
||||
constexpr const PreferFormats PreferSDR {SwapchainPreferFormatsSDR, sizeof(SwapchainPreferFormatsSDR )/sizeof(VkFormat)};
|
||||
constexpr const PreferFormats PreferHDR16{SwapchainPreferFormatsHDR16, sizeof(SwapchainPreferFormatsHDR16 )/sizeof(VkFormat)};
|
||||
constexpr const PreferFormats PreferHDR32{SwapchainPreferFormatsHDR32, sizeof(SwapchainPreferFormatsHDR32 )/sizeof(VkFormat)};
|
||||
constexpr const PreferFormats PreferHDR {SwapchainPreferFormatsHDR, sizeof(SwapchainPreferFormatsHDR )/sizeof(VkFormat)};
|
||||
constexpr const PreferFormats PreferDepth{SwapchainPreferFormatsDepth, sizeof(SwapchainPreferFormatsDepth )/sizeof(VkFormat)};
|
||||
|
||||
constexpr const PreferColorSpaces PreferNonlinear {SwapchainPreferColorSpacesNonlinear, sizeof(SwapchainPreferColorSpacesNonlinear )/sizeof(VkColorSpaceKHR)};
|
||||
constexpr const PreferColorSpaces PreferLinear {SwapchainPreferColorSpacesLinear, sizeof(SwapchainPreferColorSpacesLinear )/sizeof(VkColorSpaceKHR)};
|
||||
|
||||
/**
|
||||
* Vulkan设备创建器<br>
|
||||
* 将此功能定义为类是为了让开发者方便重载处理
|
||||
*/
|
||||
class VulkanDeviceCreater
|
||||
{
|
||||
protected:
|
||||
|
||||
VulkanInstance *instance;
|
||||
Window *window;
|
||||
const GPUPhysicalDevice *physical_device;
|
||||
|
||||
VulkanHardwareRequirement require;
|
||||
|
||||
VkExtent2D extent;
|
||||
|
||||
const PreferFormats * perfer_color_formats;
|
||||
const PreferColorSpaces * perfer_color_spaces;
|
||||
const PreferFormats * perfer_depth_formats;
|
||||
|
||||
VkSurfaceKHR surface;
|
||||
|
||||
VkSurfaceFormatKHR surface_format;
|
||||
|
||||
CharPointerList ext_list;
|
||||
VkPhysicalDeviceFeatures features={};
|
||||
|
||||
protected:
|
||||
|
||||
VkDevice CreateDevice(const uint32_t);
|
||||
|
||||
public:
|
||||
|
||||
VulkanDeviceCreater(VulkanInstance *vi,
|
||||
Window *win,
|
||||
const PreferFormats *spf_color,
|
||||
const PreferColorSpaces *spf_color_space,
|
||||
const PreferFormats *spf_depth,
|
||||
const VulkanHardwareRequirement *req);
|
||||
|
||||
virtual bool ChoosePhysicalDevice();
|
||||
|
||||
virtual bool RequirementCheck();
|
||||
|
||||
virtual void ChooseSurfaceFormat();
|
||||
|
||||
virtual GPUDevice *CreateRenderDevice();
|
||||
|
||||
public:
|
||||
|
||||
virtual GPUDevice *Create();
|
||||
};//class VulkanDeviceCreater
|
||||
|
||||
inline GPUDevice *CreateRenderDevice( VulkanInstance *vi,
|
||||
Window *win,
|
||||
const PreferFormats * spf_color =&PreferSDR,
|
||||
const PreferColorSpaces * spf_color_space =&PreferNonlinear,
|
||||
const PreferFormats * spf_depth =&PreferDepth,
|
||||
const VulkanHardwareRequirement *req=nullptr)
|
||||
{
|
||||
VulkanDeviceCreater vdc(vi,win,spf_color,spf_color_space,spf_depth,req);
|
||||
|
||||
return vdc.Create();
|
||||
}
|
||||
|
||||
inline GPUDevice *CreateRenderDeviceLDR(VulkanInstance *vi,
|
||||
Window *win,
|
||||
const VulkanHardwareRequirement *req=nullptr)
|
||||
{
|
||||
return CreateRenderDevice(vi,win,&PreferLDR,&PreferNonlinear,&PreferDepth,req);
|
||||
}
|
||||
|
||||
inline GPUDevice *CreateRenderDeviceSDR(VulkanInstance *vi,
|
||||
Window *win,
|
||||
const VulkanHardwareRequirement *req=nullptr)
|
||||
{
|
||||
return CreateRenderDevice(vi,win,&PreferSDR,&PreferNonlinear,&PreferDepth,req);
|
||||
}
|
||||
|
||||
inline GPUDevice *CreateRenderDeviceHDR16( VulkanInstance *vi,
|
||||
Window *win,
|
||||
const VulkanHardwareRequirement *req=nullptr)
|
||||
{
|
||||
return CreateRenderDevice(vi,win,&PreferHDR16,&PreferLinear,&PreferDepth,req);
|
||||
}
|
||||
|
||||
inline GPUDevice *CreateRenderDeviceHDR32( VulkanInstance *vi,
|
||||
Window *win,
|
||||
const VulkanHardwareRequirement *req=nullptr)
|
||||
{
|
||||
return CreateRenderDevice(vi,win,&PreferHDR32,&PreferLinear,&PreferDepth,req);
|
||||
}
|
||||
|
||||
inline GPUDevice *CreateRenderDeviceHDR(VulkanInstance *vi,
|
||||
Window *win,
|
||||
const VulkanHardwareRequirement *req=nullptr)
|
||||
{
|
||||
return CreateRenderDevice(vi,win,&PreferHDR,&PreferLinear,&PreferDepth,req);
|
||||
}
|
||||
VK_NAMESPACE_END
|
79
inc/hgl/graph/VKDynamicBufferAccess.h
Normal file
79
inc/hgl/graph/VKDynamicBufferAccess.h
Normal file
@@ -0,0 +1,79 @@
|
||||
#ifndef HGL_GRAPH_DYNAMIC_BUFFER_ACCESS_INCLUDE
|
||||
#define HGL_GRAPH_DYNAMIC_BUFFER_ACCESS_INCLUDE
|
||||
|
||||
#include<hgl/graph/VKArrayBuffer.h>
|
||||
VK_NAMESPACE_BEGIN
|
||||
template<typename T> class DynamicBufferAccess
|
||||
{
|
||||
uchar *pointer;
|
||||
uchar *current;
|
||||
|
||||
uint align_size;
|
||||
|
||||
uint count;
|
||||
uint index;
|
||||
|
||||
private:
|
||||
|
||||
DynamicBufferAccess()
|
||||
{
|
||||
Restart();
|
||||
}
|
||||
|
||||
void Restart()
|
||||
{
|
||||
pointer=nullptr;
|
||||
current=nullptr;
|
||||
align_size=0;
|
||||
count=0;
|
||||
index=0;
|
||||
}
|
||||
|
||||
void Start(uchar *buf,const uint as,const uint c)
|
||||
{
|
||||
current=pointer=buf;
|
||||
align_size=as;
|
||||
count=c;
|
||||
index=0;
|
||||
}
|
||||
|
||||
friend class GPUArrayBuffer;
|
||||
|
||||
public:
|
||||
|
||||
const uint GetCount()const{return count;}
|
||||
const uint GetCurrentIndex()const{return index;}
|
||||
const uint GetOffsetBytes()const{return index*align_size;}
|
||||
|
||||
bool Write(uchar *src)
|
||||
{
|
||||
if(!src)return(false);
|
||||
if(index>=count)return(false);
|
||||
|
||||
memcpy(current,src,sizeof(T));
|
||||
current+=align_size;
|
||||
++index;
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool Write(uchar *src,const uint c)
|
||||
{
|
||||
if(!src)return(false);
|
||||
if(c<=0)return(false);
|
||||
if(index+c>count)return(false);
|
||||
|
||||
for(uint i=0;i<c;i++)
|
||||
{
|
||||
memcpy(current,src,sizeof(T));
|
||||
current+=align_size;
|
||||
src+=sizeof(T);
|
||||
}
|
||||
|
||||
index+=c;
|
||||
|
||||
return(true);
|
||||
}
|
||||
};//template<typename T> class DynamicBufferAccess
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_DYNAMIC_BUFFER_ACCESS_INCLUDE
|
@@ -35,5 +35,7 @@ public:
|
||||
const uint32_t GetColorCount ()const{return color_count;} ///<取得颜色成分数量
|
||||
const bool HasDepth ()const{return has_depth;} ///<是否包含深度成分
|
||||
};//class Framebuffer
|
||||
|
||||
using FBO=Framebuffer;
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_VULKAN_FRAMEBUFFER_INCLUDE
|
||||
|
@@ -26,8 +26,8 @@ namespace hgl
|
||||
|
||||
~IndexBuffer()=default;
|
||||
|
||||
const IndexType GetType ()const{return index_type;}
|
||||
const uint32 GetCount()const{return count;}
|
||||
const IndexType GetType ()const{return index_type;}
|
||||
const uint32 GetCount()const{return count;}
|
||||
};//class IndexBuffer:public DeviceBuffer
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
|
@@ -2,7 +2,7 @@
|
||||
#define HGL_GRAPH_VULKAN_INSTANCE_INCLUDE
|
||||
|
||||
#include<hgl/type/String.h>
|
||||
#include<hgl/type/List.h>
|
||||
#include<hgl/type/ObjectList.h>
|
||||
#include<hgl/platform/Window.h>
|
||||
#include<hgl/graph/VKPhysicalDevice.h>
|
||||
#include<hgl/graph/VKDebugOut.h>
|
||||
@@ -23,7 +23,9 @@ VK_NAMESPACE_BEGIN
|
||||
|
||||
struct
|
||||
{
|
||||
VK_BOOL1BIT(synchronization2)
|
||||
VK_BOOL1BIT(validation)
|
||||
VK_BOOL1BIT(profiles)
|
||||
}khronos;
|
||||
|
||||
struct
|
||||
|
@@ -5,61 +5,59 @@
|
||||
#include<hgl/type/Map.h>
|
||||
#include<hgl/type/String.h>
|
||||
#include<hgl/graph/VKShaderModuleMap.h>
|
||||
#include<hgl/graph/VKDescriptorSetType.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
class ActiveMemoryBlockManager;
|
||||
}
|
||||
VK_NAMESPACE_BEGIN
|
||||
using ShaderStageCreateInfoList=List<VkPipelineShaderStageCreateInfo>;
|
||||
|
||||
using MaterialParameterArray=MaterialParameters *[size_t(DescriptorSetType::RANGE_SIZE)];
|
||||
|
||||
struct MaterialData
|
||||
{
|
||||
UTF8String name;
|
||||
|
||||
ShaderModuleMap *shader_maps;
|
||||
MaterialDescriptorSets *mds;
|
||||
|
||||
VertexShaderModule *vertex_sm;
|
||||
|
||||
ShaderStageCreateInfoList shader_stage_list;
|
||||
|
||||
PipelineLayoutData *pipeline_layout_data;
|
||||
|
||||
MaterialParameterArray mp_array;
|
||||
|
||||
private:
|
||||
|
||||
friend class Material;
|
||||
|
||||
~MaterialData();
|
||||
};//struct MaterialData
|
||||
|
||||
/**
|
||||
* 材质类<br>
|
||||
* 用于管理shader,提供DescriptorSetLayoutCreater
|
||||
*/
|
||||
class Material
|
||||
{
|
||||
MaterialData *data;
|
||||
AnsiString name;
|
||||
|
||||
VertexInput *vertex_input;
|
||||
|
||||
ShaderModuleMap *shader_maps;
|
||||
|
||||
MaterialDescriptorManager *desc_manager;
|
||||
|
||||
ShaderStageCreateInfoList shader_stage_list;
|
||||
|
||||
PipelineLayoutData *pipeline_layout_data;
|
||||
|
||||
MaterialParameters *mp_array[DESCRIPTOR_SET_TYPE_COUNT];
|
||||
|
||||
uint32_t mi_data_bytes; ///<实例数据大小
|
||||
uint32_t mi_max_count; ///<实例一次渲染最大数量限制
|
||||
|
||||
ActiveMemoryBlockManager *mi_data_manager;
|
||||
|
||||
private:
|
||||
|
||||
friend GPUDevice;
|
||||
friend class RenderResource;
|
||||
|
||||
MaterialData *GetMaterialData(){return data;}
|
||||
Material(const AnsiString &);
|
||||
|
||||
public:
|
||||
|
||||
Material(MaterialData *md):data(md){}
|
||||
~Material();
|
||||
virtual ~Material();
|
||||
|
||||
const UTF8String & GetName ()const{return data->name;}
|
||||
const UTF8String & GetName ()const{return name;}
|
||||
|
||||
VertexShaderModule * GetVertexShaderModule () {return data->vertex_sm;}
|
||||
const VertexInput * GetVertexInput ()const{return vertex_input;}
|
||||
|
||||
const ShaderStageCreateInfoList & GetStageList ()const{return data->shader_stage_list;}
|
||||
const ShaderStageCreateInfoList & GetStageList ()const{return shader_stage_list;}
|
||||
|
||||
const MaterialDescriptorSets * GetDescriptorSets ()const{return data->mds;}
|
||||
const MaterialDescriptorManager * GetDescriptorSets ()const{return desc_manager;}
|
||||
const VkPipelineLayout GetPipelineLayout ()const;
|
||||
const PipelineLayoutData * GetPipelineLayoutData ()const{return data->pipeline_layout_data;}
|
||||
const PipelineLayoutData * GetPipelineLayoutData ()const{return pipeline_layout_data;}
|
||||
|
||||
public:
|
||||
|
||||
@@ -67,10 +65,28 @@ public:
|
||||
{
|
||||
RANGE_CHECK_RETURN_NULLPTR(type)
|
||||
|
||||
return data->mp_array[size_t(type)];
|
||||
return mp_array[size_t(type)];
|
||||
}
|
||||
|
||||
const bool hasSet (const DescriptorSetType &type)const;
|
||||
|
||||
const VIL * GetDefaultVIL()const;
|
||||
VIL * CreateVIL(const VILConfig *format_map=nullptr);
|
||||
bool Release(VIL *);
|
||||
const uint GetVILCount();
|
||||
|
||||
public:
|
||||
|
||||
const bool HasMI ()const{return mi_data_bytes>0;}
|
||||
const uint32_t GetMIDataBytes ()const{return mi_data_bytes;}
|
||||
const uint32_t GetMIMaxCount ()const{return mi_max_count;}
|
||||
|
||||
void ReleaseMI(int); ///<释放材质实例
|
||||
void *GetMIData(int); ///<取得指定ID号的材质实例数据访问指针
|
||||
|
||||
MaterialInstance *CreateMI(const VILConfig *vil_cfg=nullptr);
|
||||
};//class Material
|
||||
|
||||
using MaterialSets=SortedSets<Material *>;
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_VULKAN_MATERIAL_INCLUDE
|
||||
|
56
inc/hgl/graph/VKMaterialDescriptorManager.h
Normal file
56
inc/hgl/graph/VKMaterialDescriptorManager.h
Normal file
@@ -0,0 +1,56 @@
|
||||
#ifndef HGL_GRAPH_VULKAN_MATERIAL_DESCRIPTOR_MANAGER_INCLUDE
|
||||
#define HGL_GRAPH_VULKAN_MATERIAL_DESCRIPTOR_MANAGER_INCLUDE
|
||||
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/graph/VKShaderDescriptorSet.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
using BindingMap=Map<AnsiString,int>;
|
||||
using BindingMapArray=BindingMap[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
|
||||
|
||||
class MaterialDescriptorManager
|
||||
{
|
||||
UTF8String mtl_name;
|
||||
|
||||
BindingMapArray binding_map[DESCRIPTOR_SET_TYPE_COUNT];
|
||||
|
||||
private:
|
||||
|
||||
VkDescriptorSetLayoutBinding *all_dslb;
|
||||
|
||||
DescriptorSetLayoutCreateInfo dsl_ci[DESCRIPTOR_SET_TYPE_COUNT];
|
||||
|
||||
public:
|
||||
|
||||
MaterialDescriptorManager(const UTF8String &,ShaderDescriptor *,const uint);
|
||||
MaterialDescriptorManager(const UTF8String &,const ShaderDescriptorSetArray &);
|
||||
~MaterialDescriptorManager();
|
||||
|
||||
const UTF8String &GetMaterialName()const{return mtl_name;}
|
||||
|
||||
const uint GetBindCount(const DescriptorSetType &set_type)const
|
||||
{
|
||||
RANGE_CHECK_RETURN(set_type,0)
|
||||
|
||||
return dsl_ci[size_t(set_type)].bindingCount;
|
||||
}
|
||||
|
||||
const BindingMapArray &GetBindingMap(const DescriptorSetType &set_type)const
|
||||
{
|
||||
return binding_map[size_t(set_type)];
|
||||
}
|
||||
|
||||
const int GetBinding(const DescriptorSetType &set_type,const VkDescriptorType &desc_type,const AnsiString &name)const;
|
||||
|
||||
const int GetUBO (const DescriptorSetType &set_type,const AnsiString &name,bool dynamic)const{return GetBinding(set_type,dynamic?VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,name);}
|
||||
const int GetSSBO (const DescriptorSetType &set_type,const AnsiString &name,bool dynamic)const{return GetBinding(set_type,dynamic?VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,name);}
|
||||
const int GetImageSampler (const DescriptorSetType &set_type,const AnsiString &name )const{return GetBinding(set_type,VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,name);}
|
||||
const int GetInputAttachment(const DescriptorSetType &set_type,const AnsiString &name )const{return GetBinding(set_type,VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT,name);}
|
||||
|
||||
const DescriptorSetLayoutCreateInfo *GetDSLCI(const DescriptorSetType &type)const{return dsl_ci+size_t(type);}
|
||||
|
||||
const bool hasSet(const DescriptorSetType &type)const{return dsl_ci[size_t(type)].bindingCount>0;}
|
||||
//!sd_list_by_set_type[size_t(type)].IsEmpty();}
|
||||
};//class MaterialDescriptorManager
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_VULKAN_MATERIAL_DESCRIPTOR_MANAGER_INCLUDE
|
@@ -1,61 +0,0 @@
|
||||
#ifndef HGL_GRAPH_VULKAN_MATERIAL_DESCRIPTOR_SETS_INCLUDE
|
||||
#define HGL_GRAPH_VULKAN_MATERIAL_DESCRIPTOR_SETS_INCLUDE
|
||||
|
||||
#include<hgl/graph/VK.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
struct ShaderDescriptor
|
||||
{
|
||||
char name[128];
|
||||
|
||||
VkDescriptorType desc_type;
|
||||
DescriptorSetType set_type;
|
||||
uint32_t set;
|
||||
uint32_t binding;
|
||||
uint32_t stage_flag;
|
||||
};
|
||||
|
||||
using ShaderDescriptorList=List<ShaderDescriptor *>;
|
||||
|
||||
class MaterialDescriptorSets
|
||||
{
|
||||
UTF8String mtl_name;
|
||||
|
||||
ShaderDescriptor *sd_list;
|
||||
uint sd_count;
|
||||
|
||||
ShaderDescriptorList sd_list_by_desc_type[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
|
||||
ShaderDescriptorList sd_list_by_set_type[size_t(DescriptorSetType::RANGE_SIZE)];
|
||||
|
||||
// Map<AnsiString,ShaderDescriptor *> sd_by_name;
|
||||
Map<AnsiString,int> binding_map[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
|
||||
|
||||
// int *binding_list[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
|
||||
|
||||
private:
|
||||
|
||||
DescriptorSetLayoutCreateInfo dsl_ci[size_t(DescriptorSetType::RANGE_SIZE)];
|
||||
|
||||
public:
|
||||
|
||||
MaterialDescriptorSets(const UTF8String &,ShaderDescriptor *,const uint);
|
||||
~MaterialDescriptorSets();
|
||||
|
||||
const UTF8String &GetMaterialName()const{return mtl_name;}
|
||||
|
||||
const int GetBinding(const VkDescriptorType &desc_type,const AnsiString &name)const;
|
||||
|
||||
const int GetUBO (const AnsiString &name,bool dynamic)const{return GetBinding(dynamic?VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,name);}
|
||||
const int GetSSBO (const AnsiString &name,bool dynamic)const{return GetBinding(dynamic?VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,name);}
|
||||
const int GetImageSampler (const AnsiString &name )const{return GetBinding(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,name);}
|
||||
const int GetInputAttachment(const AnsiString &name )const{return GetBinding(VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT,name);}
|
||||
|
||||
const DescriptorSetLayoutCreateInfo *GetDSLCI(const DescriptorSetType &type)const{return dsl_ci+size_t(type);}
|
||||
|
||||
const ShaderDescriptorList &GetDescriptorList(const DescriptorSetType &type)const{return sd_list_by_set_type[size_t(type)];}
|
||||
|
||||
const bool hasSet(const DescriptorSetType &type)const{return !sd_list_by_set_type[size_t(type)].IsEmpty();}
|
||||
};//class MaterialDescriptorSets
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_VULKAN_MATERIAL_DESCRIPTOR_SETS_INCLUDE
|
@@ -4,29 +4,76 @@
|
||||
#include<hgl/graph/VKMaterial.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* <summary>
|
||||
*
|
||||
* layout(location=?) in uint MaterialInstanceID
|
||||
*
|
||||
* #define MI_MAX_COUNT ??? //该值由引擎根据 UBORange/sizeof(MaterialInstance) 计算出来
|
||||
*
|
||||
* struct MaterialInstance //这部分数据,即为材质实例的具体数据,每一个材质实例类负责提供具体数据。由RenderList合并成一整个UBO
|
||||
* { //该类数据,由DescriptorSetType为PerMaterial的参数构成
|
||||
* vec4 BaseColor;
|
||||
* vec4 Emissive;
|
||||
* vec4 ARM;
|
||||
* };
|
||||
*
|
||||
* layout(set=?,binding=?) uniform Material
|
||||
* {
|
||||
* MaterialInstance mi[MI_MAX_COUNT]
|
||||
* }mtl;
|
||||
*
|
||||
* void main()
|
||||
* {
|
||||
* MaterialInstance mi=mtl.mi[(MaterialInstanceID>=MI_MAX_COUNT)?:0:MaterialInstanceID]; //如果超出范围则使用0号材质实例数据
|
||||
*
|
||||
* vec4 BaseColor =mi.BaseColor;
|
||||
* vec4 Emissive =mi.Emissive;
|
||||
*
|
||||
* float AO =mi.ARM.x;
|
||||
* float Roughness =mi.ARM.y;
|
||||
* float Metallic =mi.ARM.z;
|
||||
*
|
||||
* </summary>
|
||||
*/
|
||||
|
||||
/**
|
||||
* 材质实例类<br>
|
||||
* 材质实例类本质只是提供一个数据区,供RenderList合并成一个大UBO。
|
||||
*/
|
||||
class MaterialInstance
|
||||
{
|
||||
protected:
|
||||
|
||||
Material *material;
|
||||
|
||||
VIL *vil;
|
||||
|
||||
MaterialParameters *mp_per_mi; ///<材质实例独有参数,对应PerMaterial合集
|
||||
|
||||
private:
|
||||
|
||||
friend class GPUDevice;
|
||||
|
||||
MaterialInstance(Material *,VIL *);
|
||||
int mi_id;
|
||||
|
||||
public:
|
||||
|
||||
virtual ~MaterialInstance()=default;
|
||||
Material * GetMaterial () {return material;}
|
||||
|
||||
Material *GetMaterial(){return material;}
|
||||
const VIL * GetVIL ()const {return vil;}
|
||||
|
||||
const VIL *GetVIL()const{return vil;}
|
||||
MaterialParameters *GetMP(){return mp_per_mi;}
|
||||
MaterialParameters *GetMP(const DescriptorSetType &type){return material->GetMP(type);}
|
||||
private:
|
||||
|
||||
friend class Material;
|
||||
|
||||
MaterialInstance(Material *,VIL *,const int);
|
||||
|
||||
public:
|
||||
|
||||
virtual ~MaterialInstance()
|
||||
{
|
||||
material->ReleaseMI(mi_id);
|
||||
}
|
||||
|
||||
const int GetMIID ()const{return mi_id;} ///<取得材质实例ID
|
||||
void * GetMIData (){return material->GetMIData(mi_id);} ///<取得材质实例数据
|
||||
void WriteMIData (const void *data,const int size); ///<写入材质实例数据
|
||||
|
||||
bool BindUBO(const DescriptorSetType &type,const AnsiString &name,DeviceBuffer *ubo,bool dynamic=false);
|
||||
bool BindSSBO(const DescriptorSetType &type,const AnsiString &name,DeviceBuffer *ubo,bool dynamic=false);
|
||||
@@ -34,4 +81,3 @@ public:
|
||||
};//class MaterialInstance
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_VULKAN_MATERIAL_INSTANCE_INCLUDE
|
||||
|
||||
|
@@ -1,48 +1,54 @@
|
||||
#ifndef HGL_GRAPH_VULKAN_MATERIAL_PARAMETERS_INCLUDE
|
||||
#ifndef HGL_GRAPH_VULKAN_MATERIAL_PARAMETERS_INCLUDE
|
||||
#define HGL_GRAPH_VULKAN_MATERIAL_PARAMETERS_INCLUDE
|
||||
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/type/String.h>
|
||||
#include<hgl/graph/VKDescriptorSet.h>
|
||||
#include<hgl/graph/VKDescriptorSetType.h>
|
||||
#include<hgl/graph/VKMaterialDescriptorManager.h>
|
||||
#include<hgl/graph/VKArrayBuffer.h>
|
||||
VK_NAMESPACE_BEGIN
|
||||
class MaterialParameters
|
||||
{
|
||||
const MaterialDescriptorSets *mds;
|
||||
protected:
|
||||
|
||||
const MaterialDescriptorManager *desc_manager;
|
||||
|
||||
DescriptorSetType set_type;
|
||||
|
||||
DescriptorSet *descriptor_set;
|
||||
|
||||
private:
|
||||
|
||||
friend class GPUDevice;
|
||||
|
||||
MaterialParameters(const MaterialDescriptorSets *,const DescriptorSetType &type,DescriptorSet *);
|
||||
|
||||
public:
|
||||
|
||||
const DescriptorSetType GetType (){return set_type;}
|
||||
DescriptorSet * GetDescriptorSet (){return descriptor_set;}
|
||||
const VkDescriptorSet GetVkDescriptorSet ()const{return descriptor_set->GetDescriptorSet();}
|
||||
|
||||
const uint32_t GetCount ()const{return descriptor_set->GetCount();}
|
||||
const bool IsReady ()const{return descriptor_set->IsReady();}
|
||||
const uint32_t GetDescriptorCount ()const{return desc_manager->GetBindCount(set_type);} ///<获取总共需要绑定的描述符数量
|
||||
const BindingMapArray & GetBindingMap ()const{return desc_manager->GetBindingMap(set_type);}
|
||||
|
||||
const uint32_t GetBoundCount ()const{return descriptor_set->GetCount();} ///<获取已经绑好的数量
|
||||
const bool IsReady ()const{return descriptor_set->IsReady();} ///<是否全部绑好了
|
||||
|
||||
public:
|
||||
|
||||
#define MP_TYPE_IS(name) const bool is##name()const{return set_type==DescriptorSetType::name;}
|
||||
MP_TYPE_IS(Skeleton)
|
||||
MP_TYPE_IS(Instance)
|
||||
MP_TYPE_IS(PerObject)
|
||||
MP_TYPE_IS(PerMaterialInstance)
|
||||
MP_TYPE_IS(PerMaterial)
|
||||
MP_TYPE_IS(PerFrame)
|
||||
MP_TYPE_IS(Global)
|
||||
#undef MP_TYPE_IS
|
||||
|
||||
public:
|
||||
|
||||
MaterialParameters(const MaterialDescriptorManager *,const DescriptorSetType &type,DescriptorSet *);
|
||||
virtual ~MaterialParameters();
|
||||
|
||||
bool BindUBO(const int &index,DeviceBuffer *ubo,bool dynamic=false);
|
||||
bool BindSSBO(const int &index,DeviceBuffer *ubo,bool dynamic=false);
|
||||
bool BindImageSampler(const int &index,Texture *tex,Sampler *sampler);
|
||||
bool BindInputAttachment(const int &index,ImageView *);
|
||||
|
||||
bool BindUBO(const AnsiString &name,DeviceBuffer *ubo,bool dynamic=false);
|
||||
bool BindSSBO(const AnsiString &name,DeviceBuffer *ubo,bool dynamic=false);
|
||||
bool BindImageSampler(const AnsiString &name,Texture *tex,Sampler *sampler);
|
||||
@@ -51,4 +57,4 @@ public:
|
||||
void Update();
|
||||
};//class MaterialParameters
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_VULKAN_MATERIAL_PARAMETERS_INCLUDE
|
||||
#endif//HGL_GRAPH_VULKAN_MATERIAL_PARAMETERS_INCLUDE
|
||||
|
@@ -25,7 +25,7 @@ public:
|
||||
|
||||
const uint32_t GetBufferUsageFlagBits ()const{return buffer_usage_flag_bits;}
|
||||
|
||||
DeviceBuffer * GetBuffer (){return gpu_buffer;}
|
||||
DeviceBuffer * GetBuffer (){return gpu_buffer;}
|
||||
|
||||
public:
|
||||
|
||||
|
@@ -48,6 +48,8 @@ public:
|
||||
operator VkPhysicalDevice() {return physical_device;}
|
||||
operator const VkPhysicalDevice()const {return physical_device;}
|
||||
|
||||
const uint32_t GetVulkanVersion()const{return properties.apiVersion;}
|
||||
|
||||
const int GetMemoryType(uint32_t,VkMemoryPropertyFlags)const;
|
||||
|
||||
VkPhysicalDeviceType GetDeviceType()const{return properties.deviceType;}
|
||||
@@ -88,8 +90,13 @@ public:
|
||||
const bool isMicrosoft ()const{return HGL_VK_IS_BRAND(Microsoft);}
|
||||
const bool isMesa ()const{return HGL_VK_IS_BRAND(Mesa );}
|
||||
const bool isAMD ()const{return HGL_VK_IS_BRAND(AMD )
|
||||
||HGL_VK_IS_BRAND(ATI );}
|
||||
const bool isNvidia ()const{return HGL_VK_IS_BRAND(nVidia );}
|
||||
||HGL_VK_IS_BRAND(ATI )
|
||||
||HGL_VK_IS_BRAND(Radeon );}
|
||||
const bool isNvidia ()const{return HGL_VK_IS_BRAND(nVidia )
|
||||
||HGL_VK_IS_BRAND(GeForce )
|
||||
||HGL_VK_IS_BRAND(Quadro )
|
||||
||HGL_VK_IS_BRAND(TITAN )
|
||||
||HGL_VK_IS_BRAND(Tegra );}
|
||||
const bool isIntel ()const{return HGL_VK_IS_BRAND(Intel );}
|
||||
const bool isQualcomm ()const{return HGL_VK_IS_BRAND(Adreno );}
|
||||
const bool isApple ()const{return HGL_VK_IS_BRAND(Apple );}
|
||||
@@ -155,8 +162,6 @@ public:
|
||||
const uint32_t GetMaxImage3D ()const{return properties.limits.maxImageDimension3D;}
|
||||
const uint32_t GetMaxImageCube ()const{return properties.limits.maxImageDimensionCube;}
|
||||
const uint32_t GetMaxImageArrayLayers ()const{return properties.limits.maxImageArrayLayers;}
|
||||
const uint32_t GetMaxUBORange ()const{return properties.limits.maxUniformBufferRange;}
|
||||
const uint32_t GetMaxSSBORange ()const{return properties.limits.maxStorageBufferRange;}
|
||||
const uint32_t GetMaxBoundDescriptorSets ()const{return properties.limits.maxBoundDescriptorSets;}
|
||||
|
||||
const uint32_t GetMaxVertexInputAttributes ()const{return properties.limits.maxVertexInputAttributes;}
|
||||
|
@@ -35,6 +35,8 @@ public:
|
||||
|
||||
operator VkPipeline(){return pipeline;}
|
||||
|
||||
const PipelineData *GetData()const{return data;}
|
||||
|
||||
const bool IsAlphaTest()const{return data->alpha_test>0;}
|
||||
const bool IsAlphaBlend()const{return data->alpha_blend;}
|
||||
};//class GraphicsPipeline
|
||||
|
@@ -26,10 +26,9 @@ class Primitive
|
||||
|
||||
protected:
|
||||
|
||||
uint32_t draw_count;
|
||||
uint32_t vertex_count;
|
||||
|
||||
IndexBuffer *indices_buffer=nullptr;
|
||||
VkDeviceSize indices_offset=0;
|
||||
IndexBufferData index_buffer_data;
|
||||
|
||||
protected:
|
||||
|
||||
@@ -46,42 +45,34 @@ protected:
|
||||
|
||||
public:
|
||||
|
||||
Primitive(const uint32_t dc=0):draw_count(dc){}
|
||||
Primitive(const uint32_t vc=0):vertex_count(vc){}
|
||||
virtual ~Primitive()=default;
|
||||
|
||||
const uint GetRefCount()const{return ref_count;}
|
||||
|
||||
void SetBoundingBox(const AABB &aabb){BoundingBox=aabb;}
|
||||
void SetBoundingBox(const AABB &aabb){BoundingBox=aabb;}
|
||||
const AABB & GetBoundingBox()const {return BoundingBox;}
|
||||
|
||||
bool Set(const AnsiString &name,VBO *vb,VkDeviceSize offset=0);
|
||||
bool Set(const AnsiString &name,VBO *vb,VkDeviceSize offset=0);
|
||||
|
||||
bool Set(IndexBuffer *ib,VkDeviceSize offset=0)
|
||||
bool Set(IndexBuffer *ib,VkDeviceSize offset=0)
|
||||
{
|
||||
if(!ib)return(false);
|
||||
|
||||
indices_buffer=ib;
|
||||
indices_offset=offset;
|
||||
index_buffer_data.buffer=ib;
|
||||
index_buffer_data.offset=offset;
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
void SetDrawCount(const uint32_t dc){draw_count=dc;} ///<设置当前对象绘制需要多少个顶点
|
||||
virtual const uint32_t GetDrawCount()const ///<取得当前对象绘制需要多少个顶点
|
||||
{
|
||||
if(indices_buffer)
|
||||
return indices_buffer->GetCount();
|
||||
const uint32_t GetVertexCount ()const {return vertex_count;}
|
||||
|
||||
return draw_count;
|
||||
}
|
||||
VBO * GetVBO (const AnsiString &,VkDeviceSize *);
|
||||
VkBuffer GetBuffer (const AnsiString &,VkDeviceSize *);
|
||||
const int GetBufferCount ()const {return buffer_list.GetCount();}
|
||||
|
||||
VBO * GetVBO (const AnsiString &,VkDeviceSize *);
|
||||
VkBuffer GetBuffer (const AnsiString &,VkDeviceSize *);
|
||||
const int GetBufferCount ()const {return buffer_list.GetCount();}
|
||||
|
||||
IndexBuffer * GetIndexBuffer () {return indices_buffer;}
|
||||
const VkDeviceSize GetIndexBufferOffset()const {return indices_offset;}
|
||||
const IndexBufferData * GetIndexBufferData ()const {return &index_buffer_data;}
|
||||
};//class Primitive
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_VULKAN_PRIMITIVE_INCLUDE
|
||||
|
@@ -4,7 +4,7 @@
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/graph/VKFence.h>
|
||||
VK_NAMESPACE_BEGIN
|
||||
class Queue
|
||||
class DeviceQueue
|
||||
{
|
||||
protected:
|
||||
|
||||
@@ -21,11 +21,11 @@ private:
|
||||
|
||||
friend class GPUDevice;
|
||||
|
||||
Queue(VkDevice dev,VkQueue q,Fence **,const uint32_t fc);
|
||||
DeviceQueue(VkDevice dev,VkQueue q,Fence **,const uint32_t fc);
|
||||
|
||||
public:
|
||||
|
||||
virtual ~Queue();
|
||||
virtual ~DeviceQueue();
|
||||
|
||||
operator VkQueue(){return queue;}
|
||||
|
||||
@@ -35,6 +35,6 @@ public:
|
||||
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);
|
||||
};//class SumbitQueue
|
||||
};//class DeviceQueue
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_VULKAN_SUBMIT_QUEUE_INCLUDE
|
||||
|
@@ -3,7 +3,7 @@
|
||||
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/graph/VKPipeline.h>
|
||||
#include<hgl/type/List.h>
|
||||
#include<hgl/type/ObjectList.h>
|
||||
VK_NAMESPACE_BEGIN
|
||||
/**
|
||||
* RenderPass功能封装<br>
|
||||
@@ -54,9 +54,15 @@ public:
|
||||
|
||||
public:
|
||||
|
||||
Pipeline *CreatePipeline(MaterialInstance *, const InlinePipeline &, const Prim &prim,const bool prim_restart=false);
|
||||
Pipeline *CreatePipeline(MaterialInstance *, const PipelineData *, const Prim &prim,const bool prim_restart=false);
|
||||
Pipeline *CreatePipeline(MaterialInstance *, const OSString &, const Prim &prim,const bool prim_restart=false);
|
||||
Pipeline *CreatePipeline(Material *,const VIL *,const PipelineData *, const Prim &,const bool prim_restart=false);
|
||||
Pipeline *CreatePipeline(Material *,const VIL *,const InlinePipeline &, const Prim &,const bool prim_restart=false);
|
||||
|
||||
Pipeline *CreatePipeline(Material *mtl, const PipelineData *, const Prim &,const bool prim_restart=false);
|
||||
Pipeline *CreatePipeline(Material *mtl, const InlinePipeline &, const Prim &,const bool prim_restart=false);
|
||||
|
||||
Pipeline *CreatePipeline(MaterialInstance *, const InlinePipeline &, const Prim &,const bool prim_restart=false);
|
||||
Pipeline *CreatePipeline(MaterialInstance *, const PipelineData *, const Prim &,const bool prim_restart=false);
|
||||
Pipeline *CreatePipeline(MaterialInstance *, const OSString &, const Prim &,const bool prim_restart=false);
|
||||
};//class RenderPass
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_VULKAN_RENDER_PASS_INCLUDE
|
||||
|
@@ -13,7 +13,10 @@
|
||||
#include<hgl/graph/VertexAttribData.h>
|
||||
#include<hgl/graph/VKRenderable.h>
|
||||
#include<hgl/graph/font/TextPrimitive.h>
|
||||
#include<hgl/type/ResManage.h>
|
||||
#include<hgl/type/ObjectManage.h>
|
||||
#include<hgl/shadergen/MaterialCreateInfo.h>
|
||||
#include<hgl/graph/VKDescriptorBindingManage.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
using MaterialID =int;
|
||||
using MaterialInstanceID =int;
|
||||
@@ -26,6 +29,9 @@ using TextureID =int;
|
||||
|
||||
class VertexAttribData;
|
||||
|
||||
using ShaderModuleMapByName=ObjectMap<AnsiString,ShaderModule>;
|
||||
constexpr const size_t VK_SHADER_STAGE_TYPE_COUNT=20;//GetBitOffset((uint32_t)VK_SHADER_STAGE_CLUSTER_CULLING_BIT_HUAWEI)+1;
|
||||
|
||||
/**
|
||||
* 资源管理,用于管理场景内所需的所有数据
|
||||
*/
|
||||
@@ -33,22 +39,27 @@ class RenderResource
|
||||
{
|
||||
GPUDevice *device;
|
||||
|
||||
ObjectMap<OSString,ShaderModule> shader_module_by_name;
|
||||
Map<OSString,Material *> material_by_name;
|
||||
ShaderModuleMapByName shader_module_by_name[VK_SHADER_STAGE_TYPE_COUNT];
|
||||
Map<AnsiString,Material *> material_by_name;
|
||||
Map<OSString,Texture *> texture_by_name;
|
||||
|
||||
IDResManage<MaterialID, Material> rm_material; ///<材质合集
|
||||
IDResManage<MaterialInstanceID, MaterialInstance> rm_material_instance; ///<材质实例合集
|
||||
IDResManage<DescriptorSetID, DescriptorSet> rm_desc_sets; ///<描述符合集
|
||||
IDResManage<PrimitiveID, Primitive> rm_primitives; ///<图元合集
|
||||
IDResManage<BufferID, DeviceBuffer> rm_buffers; ///<顶点缓冲区合集
|
||||
IDResManage<SamplerID, Sampler> rm_samplers; ///<采样器合集
|
||||
IDResManage<TextureID, Texture> rm_textures; ///<纹理合集
|
||||
IDResManage<RenderableID, Renderable> rm_renderables; ///<渲染实例集合集
|
||||
IDObjectManage<MaterialID, Material> rm_material; ///<材质合集
|
||||
IDObjectManage<MaterialInstanceID, MaterialInstance> rm_material_instance; ///<材质实例合集
|
||||
IDObjectManage<DescriptorSetID, DescriptorSet> rm_desc_sets; ///<描述符合集
|
||||
IDObjectManage<PrimitiveID, Primitive> rm_primitives; ///<图元合集
|
||||
IDObjectManage<BufferID, DeviceBuffer> rm_buffers; ///<顶点缓冲区合集
|
||||
IDObjectManage<SamplerID, Sampler> rm_samplers; ///<采样器合集
|
||||
IDObjectManage<TextureID, Texture> rm_textures; ///<纹理合集
|
||||
IDObjectManage<RenderableID, Renderable> rm_renderables; ///<渲染实例集合集
|
||||
|
||||
public:
|
||||
|
||||
RenderResource(GPUDevice *dev):device(dev){}
|
||||
//注:并非一定要走这里,这里只是提供一个注册和自动绑定的机制
|
||||
DescriptorBinding global_descriptor; ///<全局属性描述符绑定管理
|
||||
|
||||
public:
|
||||
|
||||
RenderResource(GPUDevice *dev):device(dev),global_descriptor(DescriptorSetType::Global){}
|
||||
virtual ~RenderResource()=default;
|
||||
|
||||
public: //Add
|
||||
@@ -66,7 +77,7 @@ public: // VBO/VAO
|
||||
|
||||
VBO *CreateVBO(VkFormat format,uint32_t count,const void *data,SharingMode sm=SharingMode::Exclusive);
|
||||
VBO *CreateVBO(VkFormat format,uint32_t count,SharingMode sm=SharingMode::Exclusive){return CreateVBO(format,count,nullptr,sm);}
|
||||
VBO *CreateVBO(const VAD *vad,SharingMode sm=SharingMode::Exclusive){return CreateVBO(vad->GetVulkanFormat(),vad->GetCount(),vad->GetData(),sm);}
|
||||
VBO *CreateVBO(const VAD *vad,SharingMode sm=SharingMode::Exclusive){return CreateVBO(vad->GetFormat(),vad->GetCount(),vad->GetData(),sm);}
|
||||
|
||||
#define SCENE_DB_CREATE_FUNC(name) DeviceBuffer *Create##name(VkDeviceSize size,void *data,SharingMode sm=SharingMode::Exclusive); \
|
||||
DeviceBuffer *Create##name(VkDeviceSize size,SharingMode sm=SharingMode::Exclusive);
|
||||
@@ -87,11 +98,12 @@ public: // VBO/VAO
|
||||
|
||||
public: //Material
|
||||
|
||||
const ShaderModule *CreateShaderModule(const OSString &filename,ShaderResource *shader_resource);
|
||||
const ShaderModule *CreateShaderModule(const AnsiString &shader_module_name,const ShaderCreateInfo *);
|
||||
|
||||
Material * CreateMaterial(const OSString &);
|
||||
Material * CreateMaterial(const mtl::MaterialCreateInfo *);
|
||||
|
||||
MaterialInstance * CreateMaterialInstance(Material *,const VILConfig *vil_cfg=nullptr);
|
||||
MaterialInstance * CreateMaterialInstance(const OSString &,const VILConfig *vil_cfg=nullptr);
|
||||
MaterialInstance * CreateMaterialInstance(const mtl::MaterialCreateInfo *,const VILConfig *vil_cfg=nullptr);
|
||||
|
||||
Primitive * CreatePrimitive(const uint32_t vertex_count=0);
|
||||
|
||||
@@ -114,7 +126,7 @@ public: //Get
|
||||
DeviceBuffer * GetBuffer (const BufferID &id){return rm_buffers.Get(id);}
|
||||
Sampler * GetSampler (const SamplerID &id){return rm_samplers.Get(id);}
|
||||
Texture * GetTexture (const TextureID &id){return rm_textures.Get(id);}
|
||||
Renderable * GetRenderable (const RenderableID &id){return rm_renderables.Get(id);}
|
||||
Renderable * GetRenderable (const RenderableID &id){return rm_renderables.Get(id);}
|
||||
};//class RenderResource
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_VULKAN_DATABASE_INCLUDE
|
||||
|
@@ -15,7 +15,7 @@ class RenderTarget
|
||||
{
|
||||
protected:
|
||||
|
||||
Queue *queue;
|
||||
DeviceQueue *queue;
|
||||
|
||||
RenderPass *render_pass;
|
||||
Framebuffer *fbo;
|
||||
@@ -34,14 +34,14 @@ protected:
|
||||
|
||||
friend class GPUDevice;
|
||||
|
||||
RenderTarget(Queue *,Semaphore *);
|
||||
RenderTarget(Queue *,Semaphore *,RenderPass *_rp,Framebuffer *_fb,Texture2D **color_texture_list,const uint32_t color_count,Texture2D *depth_texture);
|
||||
RenderTarget(DeviceQueue *,Semaphore *);
|
||||
RenderTarget(DeviceQueue *,Semaphore *,RenderPass *_rp,Framebuffer *_fb,Texture2D **color_texture_list,const uint32_t color_count,Texture2D *depth_texture);
|
||||
|
||||
public:
|
||||
|
||||
virtual ~RenderTarget();
|
||||
|
||||
Queue * GetQueue () {return queue;}
|
||||
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();}
|
||||
@@ -53,7 +53,7 @@ public:
|
||||
|
||||
public: // command buffer
|
||||
|
||||
Semaphore * GetRenderCompleteSemaphore (){return render_complete_semaphore;}
|
||||
Semaphore * GetRenderCompleteSemaphore (){return render_complete_semaphore;}
|
||||
virtual bool Submit (RenderCmdBuffer *,Semaphore *present_complete_semaphore=nullptr);
|
||||
|
||||
bool WaitQueue(){return queue->WaitQueue();}
|
||||
@@ -63,7 +63,7 @@ public: // command buffer
|
||||
/**
|
||||
* 交换链专用渲染目标
|
||||
*/
|
||||
class SwapchainRenderTarget:public RenderTarget
|
||||
class RTSwapchain:public RenderTarget
|
||||
{
|
||||
VkDevice device;
|
||||
Swapchain *swapchain;
|
||||
@@ -75,11 +75,11 @@ class SwapchainRenderTarget:public RenderTarget
|
||||
|
||||
public:
|
||||
|
||||
SwapchainRenderTarget(VkDevice dev,Swapchain *sc,Queue *q,Semaphore *rcs,Semaphore *pcs,RenderPass *rp);
|
||||
~SwapchainRenderTarget();
|
||||
RTSwapchain(VkDevice dev,Swapchain *sc,DeviceQueue *q,Semaphore *rcs,Semaphore *pcs,RenderPass *rp);
|
||||
~RTSwapchain();
|
||||
|
||||
Framebuffer * GetFramebuffer ()override {return swapchain->render_frame[current_frame];}
|
||||
Framebuffer * GetFramebuffer (const uint32_t index) {return swapchain->render_frame[index];}
|
||||
Framebuffer * GetFramebuffer ()override {return swapchain->sc_fbo[current_frame];}
|
||||
Framebuffer * GetFramebuffer (const uint32_t index) {return swapchain->sc_fbo[index];}
|
||||
|
||||
const uint32_t GetColorCount ()const override {return 1;}
|
||||
const uint32_t GetImageCount ()const {return swapchain->color_count;}
|
||||
@@ -90,7 +90,7 @@ public:
|
||||
public:
|
||||
|
||||
const uint32_t GetCurrentFrameIndices ()const {return current_frame;}
|
||||
Semaphore * GetPresentCompleteSemaphore () {return present_complete_semaphore;}
|
||||
Semaphore * GetPresentCompleteSemaphore () {return present_complete_semaphore;}
|
||||
|
||||
public:
|
||||
|
||||
@@ -110,6 +110,6 @@ public:
|
||||
|
||||
bool Submit(VkCommandBuffer);
|
||||
bool Submit(VkCommandBuffer,Semaphore *);
|
||||
};//class SwapchainRenderTarget:public RenderTarget
|
||||
};//class RTSwapchain:public RenderTarget
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_VULKAN_RENDER_TARGET_INCLUDE
|
||||
|
@@ -7,10 +7,45 @@
|
||||
#include<hgl/graph/VKMaterial.h>
|
||||
#include<hgl/graph/VKMaterialParameters.h>
|
||||
#include<hgl/graph/VKMaterialInstance.h>
|
||||
#include<hgl/graph/VertexAttrib.h>
|
||||
VK_NAMESPACE_BEGIN
|
||||
struct VertexInputData
|
||||
{
|
||||
uint32_t binding_count;
|
||||
VkBuffer *buffer_list;
|
||||
VkDeviceSize *buffer_offset;
|
||||
|
||||
uint32_t vertex_count;
|
||||
|
||||
const IndexBufferData *index_buffer;
|
||||
|
||||
public:
|
||||
|
||||
VertexInputData(const uint32_t,const uint32_t,const IndexBufferData *);
|
||||
~VertexInputData();
|
||||
|
||||
const bool Comp(const VertexInputData *vid)const
|
||||
{
|
||||
if(!vid)return(false);
|
||||
|
||||
if(binding_count!=vid->binding_count)return(false);
|
||||
|
||||
for(uint32_t i=0;i<binding_count;i++)
|
||||
{
|
||||
if(buffer_list[i]!=vid->buffer_list[i])return(false);
|
||||
if(buffer_offset[i]!=vid->buffer_offset[i])return(false);
|
||||
}
|
||||
|
||||
if(vertex_count!=vid->vertex_count)return(false);
|
||||
|
||||
if(index_buffer!=vid->index_buffer)return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
};//struct VertexInputData
|
||||
|
||||
/**
|
||||
* 可渲染对象<br>
|
||||
* RenderList会统一管理Shader中的LocalToWorld数据,使用DynamicUBO/DynamicSSBO实现。
|
||||
*/
|
||||
class Renderable ///可渲染对象实例
|
||||
{
|
||||
@@ -18,17 +53,13 @@ class Renderable
|
||||
MaterialInstance * mat_inst;
|
||||
Primitive * primitive;
|
||||
|
||||
uint32_t buffer_count;
|
||||
VkBuffer * buffer_list;
|
||||
VkDeviceSize * buffer_size;
|
||||
|
||||
uint32_t buffer_hash;
|
||||
VertexInputData * vertex_input;
|
||||
|
||||
private:
|
||||
|
||||
friend Renderable *CreateRenderable(Primitive *,MaterialInstance *,Pipeline *);
|
||||
|
||||
Renderable(Primitive *,MaterialInstance *,Pipeline *,const uint32_t,VkBuffer *,VkDeviceSize *);
|
||||
Renderable(Primitive *,MaterialInstance *,Pipeline *,VertexInputData *);
|
||||
|
||||
public:
|
||||
|
||||
@@ -43,20 +74,7 @@ public:
|
||||
Primitive * GetPrimitive (){return primitive;}
|
||||
const AABB & GetBoundingBox ()const{return primitive->GetBoundingBox();}
|
||||
|
||||
const uint32_t GetBufferCount ()const{return buffer_count;}
|
||||
VkBuffer * GetBuffer ()const{return buffer_list;}
|
||||
VkDeviceSize * GetBufferSize ()const{return buffer_size;}
|
||||
IndexBuffer * GetIndexBuffer ()const{return primitive->GetIndexBuffer();}
|
||||
const uint32_t GetIndexBufferOffset()const{return primitive->GetIndexBufferOffset();}
|
||||
const uint32_t GetDrawCount ()const{return primitive->GetDrawCount();}
|
||||
|
||||
const uint32_t GetBufferHash ()const{return buffer_hash;}
|
||||
|
||||
MaterialParameters *GetMP (const DescriptorSetType &type){return mat_inst->GetMP(type);}
|
||||
|
||||
public: //instance support
|
||||
|
||||
virtual const uint32_t GetInstanceCount ()const{return 1;}
|
||||
const VertexInputData * GetVertexInputData ()const{return vertex_input;}
|
||||
};//class Renderable
|
||||
|
||||
Renderable *CreateRenderable(Primitive *,MaterialInstance *,Pipeline *);
|
||||
|
@@ -1,7 +1,8 @@
|
||||
#ifndef HGL_GRAPH_VULKAN_SHADER_MODULE_INCLUDE
|
||||
#define HGL_GRAPH_VULKAN_SHADER_MODULE_INCLUDE
|
||||
|
||||
#include<hgl/graph/VKShaderResource.h>
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/graph/VKVertexInputLayout.h>
|
||||
#include<hgl/type/SortedSets.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
@@ -19,13 +20,9 @@ private:
|
||||
|
||||
VkPipelineShaderStageCreateInfo *stage_create_info;
|
||||
|
||||
protected:
|
||||
|
||||
ShaderResource *shader_resource;
|
||||
|
||||
public:
|
||||
|
||||
ShaderModule(VkDevice dev,VkPipelineShaderStageCreateInfo *pssci,ShaderResource *);
|
||||
ShaderModule(VkDevice dev,VkPipelineShaderStageCreateInfo *pssci);
|
||||
virtual ~ShaderModule();
|
||||
|
||||
const int IncRef(){return ++ref_count;}
|
||||
@@ -48,48 +45,5 @@ public:
|
||||
|
||||
operator VkShaderModule ()const{return stage_create_info->module;}
|
||||
};//class ShaderModule
|
||||
|
||||
/**
|
||||
* 顶点Shader模块<br>
|
||||
* 由于顶点shader在最前方执行,所以它比其它shader多了VertexInput的数据
|
||||
*/
|
||||
class VertexShaderModule:public ShaderModule
|
||||
{
|
||||
uint32_t attr_count;
|
||||
VertexAttribType *type_list;
|
||||
const AnsiString **name_list;
|
||||
ShaderStage **ssi_list;
|
||||
|
||||
private:
|
||||
|
||||
SortedSets<VIL *> vil_sets;
|
||||
|
||||
public:
|
||||
|
||||
VertexShaderModule(VkDevice dev,VkPipelineShaderStageCreateInfo *pssci,ShaderResource *sr);
|
||||
virtual ~VertexShaderModule();
|
||||
|
||||
/**
|
||||
* 获取输入流绑定点,需要注意的时,这里获取的binding并非是shader中的binding/location,而是绑定顺序的序列号。对应vkCmdBindVertexBuffer的缓冲区序列号
|
||||
*/
|
||||
const int GetStageInputBinding(const AnsiString &name)const{return shader_resource->GetStageInputBinding(name);}
|
||||
const ShaderStage * GetStageInput (const AnsiString &name)const{return shader_resource->GetStageInput(name);}
|
||||
const uint GetStageInputCount () const{return shader_resource->GetStageInputCount();}
|
||||
const ShaderStageList & GetStageInputs () const{return shader_resource->GetStageInputs();}
|
||||
|
||||
//const uint32_t GetAttrCount()const{return attr_count;}
|
||||
|
||||
//const VkVertexInputBindingDescription * GetBindList ()const{return binding_list;}
|
||||
//const VkVertexInputAttributeDescription * GetAttrList ()const{return attribute_list;}
|
||||
|
||||
//const VkVertexInputBindingDescription * GetBind (const uint32_t index)const{return (index>=attr_count?nullptr:binding_list+index);}
|
||||
//const VkVertexInputAttributeDescription * GetAttr (const uint32_t index)const{return (index>=attr_count?nullptr:attribute_list+index);}
|
||||
|
||||
public:
|
||||
|
||||
VIL * CreateVIL(const VILConfig *format_map=nullptr);
|
||||
bool Release(VIL *);
|
||||
const uint32_t GetInstanceCount()const{return vil_sets.GetCount();}
|
||||
};//class VertexShaderModule:public ShaderModule
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_VULKAN_SHADER_MODULE_INCLUDE
|
||||
|
@@ -4,64 +4,39 @@
|
||||
#include<hgl/type/String.h>
|
||||
#include<hgl/type/List.h>
|
||||
#include<hgl/type/StringList.h>
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/graph/VKShaderStage.h>
|
||||
#include<hgl/graph/VKStruct.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
struct ShaderStage
|
||||
{
|
||||
AnsiString name;
|
||||
uint location;
|
||||
|
||||
VertexAttribType type; ///<成份数量(如vec4中的4)
|
||||
|
||||
bool dynamic; ///<是否动态数据
|
||||
};//struct ShaderStage
|
||||
|
||||
using ShaderStageList =ObjectList<ShaderStage>;
|
||||
|
||||
class ShaderResource
|
||||
{
|
||||
VkShaderStageFlagBits stage_flag;
|
||||
|
||||
const void *spv_data;
|
||||
const uint32_t *spv_data;
|
||||
uint32 spv_size;
|
||||
|
||||
ShaderStageList stage_inputs;
|
||||
// ShaderStageList stage_outputs;
|
||||
ShaderStageIO stage_io;
|
||||
|
||||
public:
|
||||
|
||||
ShaderResource(const VkShaderStageFlagBits &,const void *,const uint32);
|
||||
virtual ~ShaderResource()=default;
|
||||
ShaderResource(const VkShaderStageFlagBits &,const uint32_t *,const uint32);
|
||||
virtual ~ShaderResource();
|
||||
|
||||
const VkShaderStageFlagBits GetStage ()const {return stage_flag;}
|
||||
const os_char * GetStageName ()const;
|
||||
const VkShaderStageFlagBits GetStage ()const {return stage_flag;}
|
||||
const char * GetStageName ()const {return GetShaderStageName(stage_flag);}
|
||||
|
||||
const uint32_t * GetCode ()const {return (uint32_t *)spv_data;}
|
||||
const uint32_t GetCodeSize ()const {return spv_size;}
|
||||
const uint32_t * GetSPVData ()const {return spv_data;}
|
||||
const uint32_t GetSPVSize ()const {return spv_size;}
|
||||
|
||||
ShaderStageList & GetStageInputs () {return stage_inputs;}
|
||||
// ShaderStageList & GetStageOutputs () {return stage_outputs;}
|
||||
ShaderAttributeArray & GetInputs () {return stage_io.input;}
|
||||
// ShaderAttributeArray & GetOutputs () {return stage_io.output;}
|
||||
|
||||
const uint GetStageInputCount ()const {return stage_inputs.GetCount();}
|
||||
// const uint GetStageOutputCount ()const {return stage_outputs.GetCount();}
|
||||
const uint GetInputCount ()const {return stage_io.input.count;}
|
||||
// const uint GetOutputCount ()const {return stage_io.output.count;}
|
||||
|
||||
const ShaderStage * GetStageInput (const AnsiString &)const;
|
||||
const int GetStageInputBinding(const AnsiString &)const;
|
||||
const ShaderAttribute * GetInput (const AnsiString &)const;
|
||||
const int GetInputBinding (const AnsiString &)const;
|
||||
};//class ShaderResource
|
||||
|
||||
ShaderResource *LoadShaderResource(const uint8 *origin_filedata,const int64 filesize);
|
||||
|
||||
struct ShaderModuleCreateInfo:public vkstruct_flag<VkShaderModuleCreateInfo,VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO>
|
||||
{
|
||||
public:
|
||||
|
||||
ShaderModuleCreateInfo(ShaderResource *sr)
|
||||
{
|
||||
codeSize=sr->GetCodeSize();
|
||||
pCode =sr->GetCode();
|
||||
}
|
||||
};//struct ShaderModuleCreateInfo
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_VULKAN_SHADER_RESOURCE_INCLUDE
|
||||
#endif//HGL_GRAPH_VULKAN_SHADER_RESOURCE_INCLUDE
|
||||
|
@@ -15,12 +15,12 @@ public:
|
||||
|
||||
VkSwapchainKHR swap_chain =VK_NULL_HANDLE;
|
||||
|
||||
uint32_t color_count=0;
|
||||
uint32_t color_count =0;
|
||||
|
||||
Texture2D ** sc_color =nullptr;
|
||||
Texture2D * sc_depth =nullptr;
|
||||
|
||||
Framebuffer ** render_frame =nullptr;
|
||||
Framebuffer ** sc_fbo =nullptr;
|
||||
|
||||
public:
|
||||
|
||||
|
@@ -4,7 +4,7 @@
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/graph/VKMemory.h>
|
||||
#include<hgl/graph/VKImageView.h>
|
||||
#include<hgl/graph/Bitmap.h>
|
||||
#include<hgl/graph/BitmapData.h>
|
||||
#include<hgl/type/String.h>
|
||||
#include<hgl/graph/VKTextureCreateInfo.h>
|
||||
VK_NAMESPACE_BEGIN
|
||||
@@ -27,7 +27,7 @@ public:
|
||||
VkImageLayout GetImageLayout () {return data?data->image_layout:VK_IMAGE_LAYOUT_UNDEFINED;}
|
||||
VkImageView GetVulkanImageView () {return data?data->image_view->GetImageView():VK_NULL_HANDLE;}
|
||||
|
||||
DeviceMemory * GetMemory () {return data?data->memory:nullptr;}
|
||||
DeviceMemory * GetMemory () {return data?data->memory:nullptr;}
|
||||
ImageView * GetImageView () {return data?data->image_view:nullptr;}
|
||||
|
||||
const uint32 GetMipLevel ()const {return data?data->miplevel:0;}
|
||||
|
57
inc/hgl/graph/VKVBOList.h
Normal file
57
inc/hgl/graph/VKVBOList.h
Normal file
@@ -0,0 +1,57 @@
|
||||
#pragma once
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
class VBOList
|
||||
{
|
||||
uint32_t binding_count;
|
||||
VkBuffer *buffer_list;
|
||||
VkDeviceSize *buffer_offset;
|
||||
|
||||
uint32_t write_count;
|
||||
|
||||
friend class RenderCmdBuffer;
|
||||
|
||||
public:
|
||||
|
||||
VBOList(const uint32 bc)
|
||||
{
|
||||
binding_count=bc;
|
||||
buffer_list=new VkBuffer[binding_count];
|
||||
buffer_offset=new VkDeviceSize[binding_count];
|
||||
|
||||
write_count=0;
|
||||
}
|
||||
|
||||
~VBOList()
|
||||
{
|
||||
delete[] buffer_offset;
|
||||
delete[] buffer_list;
|
||||
}
|
||||
|
||||
void Restart()
|
||||
{
|
||||
write_count=0;
|
||||
}
|
||||
|
||||
const bool IsFull()const
|
||||
{
|
||||
return write_count>=binding_count;
|
||||
}
|
||||
|
||||
void Add(const VkBuffer buf,const VkDeviceSize offset)
|
||||
{
|
||||
buffer_list[write_count]=buf;
|
||||
buffer_offset[write_count]=offset;
|
||||
|
||||
++write_count;
|
||||
}
|
||||
|
||||
void Add(const VkBuffer *buf,const VkDeviceSize *offset,const uint32_t count)
|
||||
{
|
||||
hgl_cpy(buffer_list +write_count,buf, count);
|
||||
hgl_cpy(buffer_offset+write_count,offset,count);
|
||||
|
||||
write_count+=count;
|
||||
}
|
||||
};//class VBOList
|
||||
VK_NAMESPACE_END
|
@@ -6,27 +6,6 @@ namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
/**
|
||||
* 预定义一些顶点属性名称,可用可不用。但一般默认shader会使用这些名称
|
||||
*/
|
||||
namespace VertexAttribName
|
||||
{
|
||||
#define VAN_DEFINE(name) constexpr char name[]=#name;
|
||||
VAN_DEFINE(Position)
|
||||
VAN_DEFINE(Normal)
|
||||
VAN_DEFINE(Color)
|
||||
VAN_DEFINE(Tangent)
|
||||
VAN_DEFINE(Bitangent)
|
||||
VAN_DEFINE(TexCoord)
|
||||
VAN_DEFINE(Metallic)
|
||||
VAN_DEFINE(Specular)
|
||||
VAN_DEFINE(Roughness)
|
||||
VAN_DEFINE(Emission)
|
||||
#undef VAN_DEFINE
|
||||
}//namespace VertexAttribName
|
||||
|
||||
#define VAN VertexAttribName
|
||||
|
||||
/**
|
||||
* 顶点属性数据
|
||||
*/
|
||||
@@ -36,18 +15,19 @@ namespace hgl
|
||||
|
||||
protected:
|
||||
|
||||
const uint32_t vec_size; ///<每个数据成员数(比如二维坐标为2、三维坐标为3)
|
||||
uint32_t count; ///<数据个数
|
||||
VkFormat format;
|
||||
|
||||
const uint32_t stride; ///<每组数据字节数
|
||||
const uint32_t total_bytes; ///<字节数
|
||||
|
||||
VkFormat vk_format; ///<在Vulkan中的数据类型
|
||||
uint32_t count; ///<数据个数
|
||||
uint32_t total_bytes; ///<字节数
|
||||
|
||||
public:
|
||||
|
||||
VertexAttribData(uint32_t c,uint32_t dc,uint32_t cs,VkFormat fmt):count(c),vec_size(dc),stride(cs),total_bytes(cs*c),vk_format(fmt)
|
||||
VertexAttribData(uint32_t c,const VkFormat vf,const uint32_t t)
|
||||
{
|
||||
count=c;
|
||||
format=vf;
|
||||
total_bytes=t;
|
||||
|
||||
mem_data = hgl_malloc(total_bytes); //在很多情况下,hgl_malloc分配的内存是对齐的,这样有效率上的提升
|
||||
}
|
||||
|
||||
@@ -57,10 +37,8 @@ namespace hgl
|
||||
hgl_free(mem_data);
|
||||
}
|
||||
|
||||
const VkFormat GetVulkanFormat ()const{return vk_format;} ///<取得数据类型
|
||||
const uint32_t GetVecSize ()const{return vec_size;} ///<取数缓冲区元数据成份数量
|
||||
const VkFormat GetFormat ()const{return format;} ///<取得数据类型
|
||||
const uint32_t GetCount ()const{return count;} ///<取得数据数量
|
||||
const uint32_t GetStride ()const{return stride;} ///<取得每一组数据字节数
|
||||
void * GetData ()const{return mem_data;} ///<取得数据指针
|
||||
const uint32_t GetTotalBytes ()const{return total_bytes;} ///<取得数据字节数
|
||||
};//class VertexAttribData
|
||||
@@ -70,11 +48,9 @@ namespace hgl
|
||||
/**
|
||||
* 根据格式要求,创建对应的顶点属性数据区(VAD)
|
||||
* @param vertex_count 顶点数量
|
||||
* @param fmt Vulkan格式
|
||||
* @param vec_size vec数量
|
||||
* @param stride 单个数据字节数
|
||||
* @param vif 格式
|
||||
*/
|
||||
VAD *CreateVertexAttribData(const uint32_t vertex_count,const VkFormat fmt,const int vec_size,const uint stride);
|
||||
VAD *CreateVertexAttribData(const uint32_t vertex_count,const VertexInputFormat *vif);
|
||||
//这个函数比较重要,就不搞成CreateVAD的简写了
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
|
@@ -134,7 +134,7 @@ namespace hgl
|
||||
{
|
||||
if(!vad)return(nullptr);
|
||||
|
||||
if(vad->GetVulkanFormat()!=VKFMT)
|
||||
if(vad->GetFormat()!=VKFMT)
|
||||
return(nullptr);
|
||||
|
||||
return(new VertexAttribDataAccess1<T,VKFMT>(vad->GetCount(),(T *)vad->GetData()));
|
||||
@@ -227,7 +227,7 @@ namespace hgl
|
||||
{
|
||||
if(!vad)return(nullptr);
|
||||
|
||||
if(vad->GetVulkanFormat()!=VKFMT)
|
||||
if(vad->GetFormat()!=VKFMT)
|
||||
return(nullptr);
|
||||
|
||||
return(new VertexAttribDataAccess2<T,VKFMT>(vad->GetCount(),(T *)vad->GetData()));
|
||||
@@ -526,7 +526,7 @@ namespace hgl
|
||||
{
|
||||
if(!vad)return(nullptr);
|
||||
|
||||
if(vad->GetVulkanFormat()!=VKFMT)
|
||||
if(vad->GetFormat()!=VKFMT)
|
||||
return(nullptr);
|
||||
|
||||
return(new VertexAttribDataAccess3<T,VKFMT>(vad->GetCount(),(T *)vad->GetData()));
|
||||
@@ -798,7 +798,7 @@ namespace hgl
|
||||
{
|
||||
if(!vad)return(nullptr);
|
||||
|
||||
if(vad->GetVulkanFormat()!=VKFMT)
|
||||
if(vad->GetFormat()!=VKFMT)
|
||||
return(nullptr);
|
||||
|
||||
return(new VertexAttribDataAccess4<T,VKFMT>(vad->GetCount(),(T *)vad->GetData()));
|
||||
|
@@ -3,13 +3,15 @@
|
||||
|
||||
#include<hgl/graph/TileData.h>
|
||||
#include<hgl/graph/font/FontSource.h>
|
||||
#include<hgl/type/ResPool.h>
|
||||
#include<hgl/type/RefObjectPool.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
using TileResPool=ResPool<u32char,TileObject *>;
|
||||
using TileUVFloatMap=Map<u32char,RectScope2f>;
|
||||
|
||||
using TileResPool=RefObjectPool<u32char,TileObject *>;
|
||||
|
||||
/**
|
||||
* Tile字符管理<br>
|
||||
|
30
inc/hgl/graph/mtl/2d/Material2DCreateConfig.h
Normal file
30
inc/hgl/graph/mtl/2d/Material2DCreateConfig.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#ifndef HGL_GRAPH_MTL_2D_CREATE_CONFIG_INCLUDE
|
||||
#define HGL_GRAPH_MTL_2D_CREATE_CONFIG_INCLUDE
|
||||
|
||||
#include<hgl/graph/mtl/MaterialConfig.h>
|
||||
#include<hgl/graph/CoordinateSystem.h>
|
||||
|
||||
STD_MTL_NAMESPACE_BEGIN
|
||||
struct Material2DCreateConfig:public MaterialCreateConfig
|
||||
{
|
||||
CoordinateSystem2D coordinate_system; ///<使用的坐标系
|
||||
|
||||
bool local_to_world; ///<包含LocalToWorld矩阵
|
||||
|
||||
public:
|
||||
|
||||
Material2DCreateConfig(const GPUDeviceAttribute *da,const AnsiString &name):MaterialCreateConfig(da,name)
|
||||
{
|
||||
rt_output.color=1; //输出一个颜色
|
||||
rt_output.depth=false; //不输出深度
|
||||
rt_output.stencil=false; //不输出stencil
|
||||
|
||||
coordinate_system=CoordinateSystem2D::NDC;
|
||||
local_to_world=false;
|
||||
}
|
||||
};//struct Material2DCreateConfig:public MaterialCreateConfig
|
||||
|
||||
MaterialCreateInfo *CreateVertexColor2D(const Material2DCreateConfig *);
|
||||
MaterialCreateInfo *CreatePureColor2D(const Material2DCreateConfig *);
|
||||
STD_MTL_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_MTL_2D_CREATE_CONFIG_INCLUDE
|
37
inc/hgl/graph/mtl/MaterialConfig.h
Normal file
37
inc/hgl/graph/mtl/MaterialConfig.h
Normal file
@@ -0,0 +1,37 @@
|
||||
#ifndef HGL_GRAPH_MTL_CONFIG_INCLUDE
|
||||
#define HGL_GRAPH_MTL_CONFIG_INCLUDE
|
||||
|
||||
#include<hgl/graph/mtl/StdMaterial.h>
|
||||
#include<hgl/type/String.h>
|
||||
#include<hgl/graph/RenderTargetOutputConfig.h>
|
||||
#include<hgl/graph/VK.h>
|
||||
|
||||
STD_MTL_NAMESPACE_BEGIN
|
||||
class MaterialCreateInfo;
|
||||
|
||||
/**
|
||||
* 材质配置结构
|
||||
*/
|
||||
struct MaterialCreateConfig
|
||||
{
|
||||
const GPUDeviceAttribute *dev_attr;
|
||||
|
||||
AnsiString mtl_name; ///<材质名称
|
||||
|
||||
RenderTargetOutputConfig rt_output; ///<渲染目标输出配置
|
||||
|
||||
uint32 shader_stage_flag_bit; ///<需要的shader
|
||||
|
||||
public:
|
||||
|
||||
MaterialCreateConfig(const GPUDeviceAttribute *da,const AnsiString &name)
|
||||
{
|
||||
dev_attr=da;
|
||||
|
||||
mtl_name=name;
|
||||
|
||||
shader_stage_flag_bit=VK_SHADER_STAGE_VERTEX_BIT|VK_SHADER_STAGE_FRAGMENT_BIT;
|
||||
}
|
||||
};//struct MaterialCreateConfig
|
||||
STD_MTL_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_MTL_CONFIG_INCLUDE
|
46
inc/hgl/graph/mtl/MaterialVertexFormat.h
Normal file
46
inc/hgl/graph/mtl/MaterialVertexFormat.h
Normal file
@@ -0,0 +1,46 @@
|
||||
#ifndef HGL_GRAPH_MATERIAL_VERTEX_FORMAT_INCLUDE
|
||||
#define HGL_GRAPH_MATERIAL_VERTEX_FORMAT_INCLUDE
|
||||
|
||||
#include<hgl/type/DataType.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
/**
|
||||
* Local 2 World <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ŷ<EFBFBD><C5B7><EFBFBD>
|
||||
*
|
||||
* 1.Push Constants <20><><EFBFBD><EFBFBD>
|
||||
*
|
||||
* 2.UBO <20>д<EFBFBD><D0B4><EFBFBD>matrix4f<34><66><EFBFBD>У<EFBFBD>vertex attrib<69>д<EFBFBD><D0B4><EFBFBD>ID
|
||||
* UBOͨ<4F><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ16k/64k<34><6B>һ<EFBFBD><D2BB>matrix4fΪ64<36>ֽڡ<D6BD>
|
||||
*
|
||||
* 3.Vertex Attribute
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* <20><><EFBFBD>ʶ<EFBFBD><CAB6><EFBFBD><EFBFBD>ṹ
|
||||
*/
|
||||
union MaterialVertexFormat
|
||||
{
|
||||
struct
|
||||
{
|
||||
uint position:3;
|
||||
bool normal:1;
|
||||
bool tangent:1;
|
||||
bool bitangent:1;
|
||||
uint color:4;
|
||||
uint texcoord:4;
|
||||
|
||||
bool local2world:1;
|
||||
bool skeleton:1;
|
||||
};
|
||||
|
||||
uint32 format;
|
||||
};//union MaterialVertexFormat
|
||||
|
||||
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
#endif//HGL_GRAPH_MATERIAL_VERTEX_FORMAT_INCLUDE
|
18
inc/hgl/graph/mtl/ShaderBuffer.h
Normal file
18
inc/hgl/graph/mtl/ShaderBuffer.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#ifndef HGL_GRAPH_MTL_SHADER_BUFFER_INCLUDE
|
||||
#define HGL_GRAPH_MTL_SHADER_BUFFER_INCLUDE
|
||||
|
||||
#include<hgl/type/DataType.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
struct ShaderBufferSource
|
||||
{
|
||||
const char *struct_name;
|
||||
const char *name;
|
||||
const char *codes;
|
||||
};
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
#endif//HGL_GRAPH_MTL_SHADER_BUFFER_INCLUDE
|
16
inc/hgl/graph/mtl/StdMaterial.h
Normal file
16
inc/hgl/graph/mtl/StdMaterial.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#define STD_MTL_NAMESPACE_BEGIN namespace hgl{namespace graph{namespace mtl{
|
||||
#define STD_MTL_NAMESPACE_END }}}
|
||||
|
||||
#define STD_MTL_NAMESPACE_USING using namespace hgl::graph::mtl;
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
namespace mtl
|
||||
{
|
||||
}//namespace mtl
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
77
inc/hgl/graph/mtl/UBOCommon.h
Normal file
77
inc/hgl/graph/mtl/UBOCommon.h
Normal file
@@ -0,0 +1,77 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/mtl/StdMaterial.h>
|
||||
#include<hgl/graph/mtl/ShaderBuffer.h>
|
||||
|
||||
STD_MTL_NAMESPACE_BEGIN
|
||||
constexpr const ShaderBufferSource SBS_ViewportInfo=
|
||||
{
|
||||
"ViewportInfo",
|
||||
"viewport",
|
||||
|
||||
R"(
|
||||
mat4 ortho_matrix;
|
||||
|
||||
vec2 canvas_resolution;
|
||||
vec2 viewport_resolution;
|
||||
vec2 inv_viewport_resolution;
|
||||
)"
|
||||
};
|
||||
|
||||
constexpr const ShaderBufferSource SBS_CameraInfo=
|
||||
{
|
||||
"CameraInfo",
|
||||
"camera",
|
||||
|
||||
R"(
|
||||
mat4 projection;
|
||||
mat4 inverse_projection;
|
||||
|
||||
mat4 view;
|
||||
mat4 inverse_view;
|
||||
|
||||
mat4 vp;
|
||||
mat4 inverse_vp;
|
||||
|
||||
mat4 sky;
|
||||
|
||||
vec3 pos; //eye
|
||||
vec3 view_line; //pos-target
|
||||
vec3 world_up;
|
||||
|
||||
float znear,zfar;)"
|
||||
};
|
||||
|
||||
// UBO必须严格指定数组的大小
|
||||
// SSBO则不需要,使用[]方式指定为动态大小数组
|
||||
|
||||
constexpr const ShaderBufferSource SBS_LocalToWorld=
|
||||
{
|
||||
"LocalToWorldData",
|
||||
"l2w",
|
||||
|
||||
R"(
|
||||
mat4 mats[L2W_MAX_COUNT];)"
|
||||
};
|
||||
|
||||
constexpr const char MaterialInstanceStruct[]="MaterialInstance";
|
||||
|
||||
constexpr const ShaderBufferSource SBS_MaterialInstance=
|
||||
{
|
||||
"MaterialInstanceData",
|
||||
"mtl",
|
||||
|
||||
R"(
|
||||
MaterialInstance mi[MI_MAX_COUNT];)"
|
||||
};
|
||||
|
||||
constexpr const ShaderBufferSource SBS_JointInfo=
|
||||
{
|
||||
"JointInfo",
|
||||
"joint",
|
||||
|
||||
R"(
|
||||
mat4 mats[];
|
||||
)"
|
||||
};
|
||||
STD_MTL_NAMESPACE_END
|
@@ -23,7 +23,7 @@ namespace hgl
|
||||
|
||||
ObjectMap<Form *,ThemeForm> form_list;
|
||||
|
||||
RenderTarget *CreateRenderTarget(const uint32_t,const uint32_t,const VkFormat);
|
||||
RenderTarget *CreateRT(const uint32_t,const uint32_t,const VkFormat);
|
||||
|
||||
protected:
|
||||
|
||||
|
95
inc/hgl/shadergen/MaterialCreateInfo.h
Normal file
95
inc/hgl/shadergen/MaterialCreateInfo.h
Normal file
@@ -0,0 +1,95 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/shadergen/MaterialDescriptorInfo.h>
|
||||
#include<hgl/shadergen/ShaderCreateInfoVertex.h>
|
||||
#include<hgl/shadergen/ShaderCreateInfoGeometry.h>
|
||||
#include<hgl/shadergen/ShaderCreateInfoFragment.h>
|
||||
#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/VKSamplerType.h>
|
||||
|
||||
namespace hgl{namespace graph
|
||||
{
|
||||
struct GPUDeviceAttribute;
|
||||
struct UBODescriptor;
|
||||
|
||||
namespace mtl
|
||||
{
|
||||
class MaterialCreateInfo
|
||||
{
|
||||
protected:
|
||||
|
||||
const MaterialCreateConfig *config;
|
||||
uint32_t ubo_range;
|
||||
uint32_t ssbo_range;
|
||||
|
||||
MaterialDescriptorInfo mdi; ///<材质描述符管理器
|
||||
|
||||
AnsiString mi_codes; ///<MaterialInstance代码
|
||||
uint32_t mi_data_bytes; ///<MaterialInstance数据长度
|
||||
uint32_t mi_shader_stage; ///<MaterialInstance着色器阶段
|
||||
uint32_t mi_max_count;
|
||||
UBODescriptor *mi_ubo;
|
||||
|
||||
uint32_t l2w_shader_stage;
|
||||
uint32_t l2w_max_count;
|
||||
UBODescriptor *l2w_ubo;
|
||||
|
||||
ShaderCreateInfoMap shader_map; ///<着色器列表
|
||||
|
||||
ShaderCreateInfoVertex *vert;
|
||||
ShaderCreateInfoGeometry *geom;
|
||||
ShaderCreateInfoFragment *frag;
|
||||
|
||||
public:
|
||||
|
||||
const AnsiString &GetName ()const{return config->mtl_name;}
|
||||
|
||||
const uint32 GetShaderStage ()const{return config->shader_stage_flag_bit;}
|
||||
|
||||
bool hasShader (const VkShaderStageFlagBits ss)const{return config->shader_stage_flag_bit&ss;}
|
||||
|
||||
bool hasVertex ()const{return hasShader(VK_SHADER_STAGE_VERTEX_BIT);}
|
||||
// bool hasTessCtrl ()const{return hasShader(VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT);}
|
||||
// bool hasTessEval ()const{return hasShader(VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT);}
|
||||
bool hasGeometry ()const{return hasShader(VK_SHADER_STAGE_GEOMETRY_BIT);}
|
||||
bool hasFragment ()const{return hasShader(VK_SHADER_STAGE_FRAGMENT_BIT);}
|
||||
// bool hasCompute ()const{return hasShader(VK_SHADER_STAGE_COMPUTE_BIT);}
|
||||
|
||||
ShaderCreateInfoVertex * GetVS()const{return vert;}
|
||||
ShaderCreateInfoGeometry * GetGS()const{return geom;}
|
||||
ShaderCreateInfoFragment * GetFS()const{return frag;}
|
||||
|
||||
const ShaderCreateInfoMap &GetShaderMap()const{return shader_map;}
|
||||
|
||||
public:
|
||||
|
||||
const MaterialDescriptorInfo &GetMDI()const{return mdi;}
|
||||
|
||||
const uint32_t GetMIDataBytes ()const{return mi_data_bytes;}
|
||||
const uint32_t GetMIMaxCount ()const{return mi_max_count;}
|
||||
|
||||
public:
|
||||
|
||||
MaterialCreateInfo(const MaterialCreateConfig *);
|
||||
~MaterialCreateInfo()=default;
|
||||
|
||||
bool SetMaterialInstance(const AnsiString &mi_glsl_codes,const uint32_t mi_struct_bytes,const uint32_t shader_stage_flag_bits);
|
||||
|
||||
bool SetLocalToWorld(const uint32_t shader_stage_flag_bits);
|
||||
|
||||
bool AddStruct(const AnsiString &ubo_typename,const AnsiString &codes);
|
||||
bool AddStruct(const ShaderBufferSource &ss){return AddStruct(ss.struct_name,ss.codes);}
|
||||
|
||||
bool AddUBO(const VkShaderStageFlagBits flag_bits,const DescriptorSetType set_type,const AnsiString &type_name,const AnsiString &name);
|
||||
bool AddSampler(const VkShaderStageFlagBits flag_bits,const DescriptorSetType set_type,const SamplerType &st,const AnsiString &name);
|
||||
|
||||
bool AddUBO(const uint32_t flag_bits,const DescriptorSetType &set_type,const ShaderBufferSource &ss);
|
||||
|
||||
bool CreateShader();
|
||||
};//class MaterialCreateInfo
|
||||
}//namespace mtl
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
72
inc/hgl/shadergen/MaterialDescriptorInfo.h
Normal file
72
inc/hgl/shadergen/MaterialDescriptorInfo.h
Normal file
@@ -0,0 +1,72 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/VKShaderDescriptorSet.h>
|
||||
#include<hgl/graph/mtl/ShaderBuffer.h>
|
||||
#include<hgl/type/Map.h>
|
||||
|
||||
namespace hgl{namespace graph{
|
||||
/**
|
||||
* 材质描述符管理</p>
|
||||
* 该类使用于SHADER生成前,用于统计编号set/binding
|
||||
*/
|
||||
class MaterialDescriptorInfo
|
||||
{
|
||||
uint descriptor_count;
|
||||
ShaderDescriptorSetArray desc_set_array;
|
||||
|
||||
Map<AnsiString,AnsiString> struct_map;
|
||||
Map<AnsiString,UBODescriptor *> ubo_map;
|
||||
Map<AnsiString,SamplerDescriptor *> sampler_map;
|
||||
|
||||
public:
|
||||
|
||||
MaterialDescriptorInfo();
|
||||
~MaterialDescriptorInfo()=default;
|
||||
|
||||
bool AddStruct(const AnsiString &name,const AnsiString &code)
|
||||
{
|
||||
struct_map.Add(name,code);
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool AddStruct(const ShaderBufferSource &ss)
|
||||
{
|
||||
return(AddStruct(ss.struct_name,ss.codes));
|
||||
}
|
||||
|
||||
bool GetStruct(const AnsiString &name,AnsiString &code)
|
||||
{
|
||||
return(struct_map.Get(name,code));
|
||||
}
|
||||
|
||||
bool hasStruct(const AnsiString &name) const
|
||||
{
|
||||
return(struct_map.KeyExist(name));
|
||||
}
|
||||
|
||||
const UBODescriptor *AddUBO(uint32_t shader_stage_flag_bits,DescriptorSetType set_type,UBODescriptor *sd);
|
||||
const SamplerDescriptor *AddSampler(uint32_t shader_stage_flag_bits,DescriptorSetType set_type,SamplerDescriptor *sd);
|
||||
|
||||
UBODescriptor *GetUBO(const AnsiString &name);
|
||||
SamplerDescriptor *GetSampler(const AnsiString &name);
|
||||
|
||||
const DescriptorSetType GetSetType(const AnsiString &)const;
|
||||
|
||||
void Resort(); //排序产生set号与binding号
|
||||
|
||||
const uint GetCount()const
|
||||
{
|
||||
return descriptor_count;
|
||||
}
|
||||
|
||||
const ShaderDescriptorSetArray &Get()const
|
||||
{
|
||||
return desc_set_array;
|
||||
}
|
||||
|
||||
const bool hasSet(const DescriptorSetType &type)const
|
||||
{
|
||||
return desc_set_array[size_t(type)].count>0;
|
||||
}
|
||||
};//class MaterialDescriptorInfo
|
||||
}}//namespace hgl::graph
|
97
inc/hgl/shadergen/ShaderCreateInfo.h
Normal file
97
inc/hgl/shadergen/ShaderCreateInfo.h
Normal file
@@ -0,0 +1,97 @@
|
||||
#ifndef HGL_SHADER_CREATE_INFO_INCLUDE
|
||||
#define HGL_SHADER_CREATE_INFO_INCLUDE
|
||||
|
||||
#include<hgl/graph/VertexAttrib.h>
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/graph/VKInterpolation.h>
|
||||
#include<hgl/type/StringList.h>
|
||||
|
||||
namespace hgl{namespace graph
|
||||
{
|
||||
struct SPVData;
|
||||
|
||||
class MaterialDescriptorInfo;
|
||||
class ShaderDescriptorInfo;
|
||||
|
||||
struct UBODescriptor;
|
||||
|
||||
class ShaderCreateInfo
|
||||
{
|
||||
protected:
|
||||
|
||||
VkShaderStageFlagBits shader_stage; ///<着色器阶段
|
||||
|
||||
MaterialDescriptorInfo *mdi;
|
||||
|
||||
protected:
|
||||
|
||||
AnsiStringList define_macro_list;
|
||||
AnsiStringList define_value_list;
|
||||
uint32_t define_macro_max_length;
|
||||
uint32_t define_value_max_length;
|
||||
|
||||
AnsiString output_struct;
|
||||
|
||||
AnsiString mi_codes;
|
||||
|
||||
AnsiStringList function_list;
|
||||
AnsiString main_function;
|
||||
|
||||
AnsiString final_shader;
|
||||
|
||||
SPVData *spv_data;
|
||||
|
||||
protected:
|
||||
|
||||
virtual bool ProcHeader(){return(true);}
|
||||
|
||||
virtual bool ProcDefine();
|
||||
|
||||
virtual bool ProcSubpassInput();
|
||||
virtual bool ProcInput(ShaderCreateInfo *);
|
||||
virtual bool ProcOutput();
|
||||
|
||||
virtual bool ProcStruct();
|
||||
|
||||
virtual bool ProcMI();
|
||||
|
||||
virtual bool ProcUBO();
|
||||
virtual bool ProcSSBO();
|
||||
virtual bool ProcConst();
|
||||
virtual bool ProcSampler();
|
||||
|
||||
bool CompileToSPV();
|
||||
|
||||
public:
|
||||
|
||||
ShaderDescriptorInfo *sdm;
|
||||
|
||||
VkShaderStageFlagBits GetShaderStage()const{return shader_stage;}
|
||||
|
||||
public:
|
||||
|
||||
ShaderCreateInfo(VkShaderStageFlagBits ss,MaterialDescriptorInfo *m);
|
||||
virtual ~ShaderCreateInfo();
|
||||
|
||||
bool AddDefine(const AnsiString &m,const AnsiString &v);
|
||||
|
||||
int AddOutput(const graph::VAT &type,const AnsiString &name,Interpolation inter=Interpolation::Smooth);
|
||||
int AddOutput(const AnsiString &type,const AnsiString &name,Interpolation inter=Interpolation::Smooth);
|
||||
|
||||
void AddFunction(const AnsiString &str){function_list.Add(str);}
|
||||
|
||||
void SetMaterialInstance(UBODescriptor *,const AnsiString &);
|
||||
void SetLocalToWorld(UBODescriptor *);
|
||||
|
||||
void SetMain(const AnsiString &str){main_function=str;}
|
||||
|
||||
const AnsiString &GetOutputStruct()const{return output_struct;}
|
||||
const AnsiString &GetShaderSource()const{return final_shader;}
|
||||
|
||||
bool CreateShader(ShaderCreateInfo *);
|
||||
|
||||
const uint32 *GetSPVData()const;
|
||||
const size_t GetSPVSize()const;
|
||||
};//class ShaderCreateInfo
|
||||
}}//namespace hgl::graph
|
||||
#endif//HGL_SHADER_CREATE_INFO_INCLUDE
|
22
inc/hgl/shadergen/ShaderCreateInfoFragment.h
Normal file
22
inc/hgl/shadergen/ShaderCreateInfoFragment.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/shadergen/ShaderCreateInfo.h>
|
||||
|
||||
namespace hgl{namespace graph{
|
||||
enum class MaterialType
|
||||
{
|
||||
Color, ///<<3C><>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD>
|
||||
};
|
||||
|
||||
class ShaderCreateInfoFragment:public ShaderCreateInfo
|
||||
{
|
||||
bool ProcOutput() override;
|
||||
|
||||
public:
|
||||
|
||||
ShaderCreateInfoFragment(MaterialDescriptorInfo *m):ShaderCreateInfo(VK_SHADER_STAGE_FRAGMENT_BIT,m){}
|
||||
~ShaderCreateInfoFragment()=default;
|
||||
|
||||
void UseDefaultMain();
|
||||
};
|
||||
}}//namespace hgl::graph
|
13
inc/hgl/shadergen/ShaderCreateInfoGeometry.h
Normal file
13
inc/hgl/shadergen/ShaderCreateInfoGeometry.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/shadergen/ShaderCreateInfo.h>
|
||||
|
||||
namespace hgl{namespace graph{
|
||||
class ShaderCreateInfoGeometry:public ShaderCreateInfo
|
||||
{
|
||||
public:
|
||||
|
||||
ShaderCreateInfoGeometry(MaterialDescriptorInfo *m):ShaderCreateInfo(VK_SHADER_STAGE_GEOMETRY_BIT,m){}
|
||||
~ShaderCreateInfoGeometry()=default;
|
||||
};
|
||||
}}//namespace hgl::graph
|
25
inc/hgl/shadergen/ShaderCreateInfoMap.h
Normal file
25
inc/hgl/shadergen/ShaderCreateInfoMap.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/shadergen/ShaderCreateInfo.h>
|
||||
|
||||
namespace hgl{namespace graph{
|
||||
class ShaderCreateInfoMap:public ObjectMap<VkShaderStageFlagBits,ShaderCreateInfo>
|
||||
{
|
||||
public:
|
||||
|
||||
using ObjectMap<VkShaderStageFlagBits,ShaderCreateInfo>::ObjectMap;
|
||||
|
||||
bool Add(ShaderCreateInfo *sc)
|
||||
{
|
||||
if(!sc)return(false);
|
||||
|
||||
VkShaderStageFlagBits flag=sc->GetShaderStage();
|
||||
|
||||
if(KeyExist(flag))
|
||||
return(false);
|
||||
|
||||
ObjectMap<VkShaderStageFlagBits,ShaderCreateInfo>::Add(flag,sc);
|
||||
return(true);
|
||||
}
|
||||
};
|
||||
}}//namespace hgl::graph
|
26
inc/hgl/shadergen/ShaderCreateInfoVertex.h
Normal file
26
inc/hgl/shadergen/ShaderCreateInfoVertex.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/shadergen/ShaderCreateInfo.h>
|
||||
#include<hgl/graph/VKShaderStage.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
class ShaderCreateInfoVertex:public ShaderCreateInfo
|
||||
{
|
||||
bool ProcInput(ShaderCreateInfo *) override;
|
||||
|
||||
public:
|
||||
|
||||
ShaderCreateInfoVertex(MaterialDescriptorInfo *m):ShaderCreateInfo(VK_SHADER_STAGE_VERTEX_BIT,m){}
|
||||
~ShaderCreateInfoVertex()=default;
|
||||
|
||||
int AddInput(const graph::VAT &type,const AnsiString &name,const VkVertexInputRate input_rate=VK_VERTEX_INPUT_RATE_VERTEX,const VertexInputGroup &group=VertexInputGroup::Basic);
|
||||
int AddInput(const AnsiString &type,const AnsiString &name,const VkVertexInputRate input_rate=VK_VERTEX_INPUT_RATE_VERTEX,const VertexInputGroup &group=VertexInputGroup::Basic);
|
||||
|
||||
void AddJoint();
|
||||
void AddAssign();
|
||||
};//class ShaderCreateInfoVertex:public ShaderCreateInfo
|
||||
}//namespace graph
|
||||
}//namespace hgl::graph
|
71
inc/hgl/shadergen/ShaderDescriptorInfo.h
Normal file
71
inc/hgl/shadergen/ShaderDescriptorInfo.h
Normal file
@@ -0,0 +1,71 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/type/Map.h>
|
||||
#include<hgl/type/StringList.h>
|
||||
#include<hgl/graph/VKShaderStage.h>
|
||||
#include<hgl/graph/VKDescriptorSetType.h>
|
||||
#include<hgl/shadergen/MaterialDescriptorInfo.h>
|
||||
|
||||
namespace hgl{namespace graph
|
||||
{
|
||||
using UBODescriptorList=List<const UBODescriptor *>;
|
||||
using SamplerDescriptorList=List<const SamplerDescriptor *>;
|
||||
using ConstValueDescriptorList=ObjectList<ConstValueDescriptor>;
|
||||
using SubpassInputDescriptorList=ObjectList<SubpassInputDescriptor>;
|
||||
|
||||
/**
|
||||
* Shader数据管理器,用于生成正式Shader前的资源统计
|
||||
*/
|
||||
class ShaderDescriptorInfo
|
||||
{
|
||||
VkShaderStageFlagBits stage_flag;
|
||||
|
||||
ShaderStageIO stage_io;
|
||||
|
||||
AnsiStringList struct_list; //用到的结构列表
|
||||
|
||||
//ubo/object在这里以及MaterialDescriptorInfo中均有一份,mdi中的用于产生set/binding号,这里的用于产生shader
|
||||
UBODescriptorList ubo_list;
|
||||
SamplerDescriptorList sampler_list;
|
||||
|
||||
ConstValueDescriptorList const_value_list;
|
||||
SubpassInputDescriptorList subpass_input;
|
||||
|
||||
ShaderPushConstant push_constant;
|
||||
|
||||
public:
|
||||
|
||||
ShaderDescriptorInfo(VkShaderStageFlagBits);
|
||||
~ShaderDescriptorInfo()=default;
|
||||
|
||||
const VkShaderStageFlagBits GetStageFlag()const { return stage_flag; }
|
||||
const AnsiString GetStageName()const { return AnsiString(GetShaderStageName(stage_flag)); }
|
||||
|
||||
public:
|
||||
|
||||
const ShaderStageIO & GetShaderStageIO()const{return stage_io;}
|
||||
|
||||
const AnsiStringList & GetStructList()const{return struct_list;}
|
||||
|
||||
const UBODescriptorList & GetUBOList()const{return ubo_list;}
|
||||
const SamplerDescriptorList & GetSamplerList()const{return sampler_list;}
|
||||
|
||||
const ConstValueDescriptorList & GetConstList()const{return const_value_list;}
|
||||
|
||||
const SubpassInputDescriptorList & GetSubpassInputList()const{return subpass_input;}
|
||||
|
||||
public:
|
||||
|
||||
bool AddInput(ShaderAttribute *);
|
||||
bool AddOutput(ShaderAttribute *);
|
||||
|
||||
void AddStruct(const AnsiString &);
|
||||
bool AddUBO(DescriptorSetType type,const UBODescriptor *sd);
|
||||
bool AddSampler(DescriptorSetType type,const SamplerDescriptor *sd);
|
||||
|
||||
bool AddConstValue(ConstValueDescriptor *sd);
|
||||
bool AddSubpassInput(const AnsiString name,uint8_t index);
|
||||
|
||||
void SetPushConstant(const AnsiString name,uint8_t offset,uint8_t size);
|
||||
};//class ShaderDescriptorInfo
|
||||
}}//namespace hgl::graph
|
115
inc/hgl/shadergen/StandardMaterial.h
Normal file
115
inc/hgl/shadergen/StandardMaterial.h
Normal file
@@ -0,0 +1,115 @@
|
||||
#include<hgl/shadergen/ShaderDescriptorInfo.h>
|
||||
#include<hgl/CompOperator.h>
|
||||
|
||||
namespace hgl{namespace graph
|
||||
{
|
||||
using ParamPreciseFlagBits=uint8;
|
||||
using PPFB=ParamPreciseFlagBits;
|
||||
|
||||
constexpr const PPFB PPFB_None =0x00; ///<参数没有出现在任何地方
|
||||
constexpr const PPFB PPFB_Global =0x01; ///<参数出现在全局(使用一个const值处理)
|
||||
constexpr const PPFB PPFB_Vertex =0x02; ///<参数出现在顶点(在vertex shader使用一个顶点值处理)
|
||||
constexpr const PPFB PPFB_Texture =0x04; ///<参数出现在纹理(在fragment shader使用一个纹理处理)
|
||||
|
||||
using TextureComponentFlagBits=uint8;
|
||||
using TCFB=TextureComponentFlagBits;
|
||||
|
||||
constexpr const TCFB TCFB_Luminance =0x01; ///<亮度
|
||||
constexpr const TCFB TCFB_Alpha =0x02; ///<透明度
|
||||
constexpr const TCFB TCFB_Red =0x04; ///<红色
|
||||
constexpr const TCFB TCFB_Green =0x08; ///<绿色
|
||||
constexpr const TCFB TCFB_Blue =0x10; ///<蓝色
|
||||
constexpr const TCFB TCFB_Cb =0x20; ///<Cb
|
||||
constexpr const TCFB TCFB_Cr =0x40; ///<Cr
|
||||
|
||||
//constexpr const TCFB TCFB_NormalX =0x80;
|
||||
//constexpr const TCFB TCFB_NormalY =0x100;
|
||||
//constexpr const TCFB TCFB_NormalZ =0x200;
|
||||
//constexpr const TCFB TCFB_Metallic =0x400;
|
||||
//constexpr const TCFB TCFB_Roughness =0x800;
|
||||
//constexpr const TCFB TCFB_AO =0x1000;
|
||||
//constexpr const TCFB TCFB_Emissive =0x2000;
|
||||
//constexpr const TCFB TCFB_Specular =0x4000;
|
||||
//constexpr const TCFB TCFB_SpecularPower =0x8000;
|
||||
|
||||
constexpr const TCFB TCFB_RGB =TCFB_Red|TCFB_Green|TCFB_Blue;
|
||||
constexpr const TCFB TCFB_RGBA =TCFB_RGB|TCFB_Alpha;
|
||||
constexpr const TCFB TCFB_YCbCr =TCFB_Luminance|TCFB_Cb|TCFB_Cr;
|
||||
constexpr const TCFB TCFB_YCbCrAlpha =TCFB_YCbCr|TCFB_Alpha;
|
||||
constexpr const TCFB TCFB_LumAlpha =TCFB_Luminance|TCFB_Alpha;
|
||||
constexpr const TCFB TCFB_LumRGB =TCFB_Luminance|TCFB_RGB;
|
||||
//constexpr const TCFB TCFB_Normal2C =TCFB_NormalX|TCFB_NormalY;
|
||||
//constexpr const TCFB TCFB_Normal =TCFB_Normal2C|TCFB_NormalZ;
|
||||
|
||||
/**
|
||||
* 标准材质,依赖内建的Shader自动生成器
|
||||
*/
|
||||
struct StandardMaterial
|
||||
{
|
||||
};//struct StandardMaterial
|
||||
|
||||
/**
|
||||
* 标准2D材质
|
||||
*/
|
||||
struct Standard2DMaterial:public StandardMaterial
|
||||
{
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
bool z_test :1; ///<是否进行Z测试
|
||||
bool z_write :1; ///<是否写入Z值
|
||||
|
||||
bool ortho_matrix :1; ///<是否使用ortho坐标系
|
||||
bool position_matrix:1; ///<是否包含pos变换矩阵
|
||||
bool color_uv :1; ///<是否包含颜色纹理坐标
|
||||
bool color_uv_matrix:1; ///<是否包含颜色纹理坐标变换矩阵
|
||||
bool alpha_uv :1; ///<是否包含透明纹理坐标
|
||||
bool alpha_uv_matrix:1; ///<是否包含透明纹理坐标变换矩阵
|
||||
};
|
||||
|
||||
uint8 flags;
|
||||
}vert;
|
||||
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
bool discard:1; ///<是否使用discard
|
||||
bool blur:1; ///<是否模糊
|
||||
};
|
||||
}frag;
|
||||
|
||||
TCFB color_texture; ///<颜色纹理格式
|
||||
TCFB alpha_texture; ///<透明纹理格式(即便颜色纹理包含Alpha,也有可能存在独立的alpha纹理)
|
||||
|
||||
PPFB color; ///<是否包含颜色缩放系数
|
||||
PPFB alpha; ///<是否包含alpha缩放系数
|
||||
uint8 color_format;
|
||||
|
||||
PPFB lum; ///<是否包含亮度调整
|
||||
PPFB hue; ///<是否包含色调调整
|
||||
PPFB contrast; ///<是否包含对比度调整
|
||||
|
||||
PPFB outline; ///<是否描边
|
||||
|
||||
public:
|
||||
|
||||
CompOperatorMemcmp(const Standard2DMaterial &);
|
||||
|
||||
void Reset()
|
||||
{
|
||||
hgl_zero(*this);
|
||||
}
|
||||
};//struct Standard2DMaterial:public StandardMaterial
|
||||
|
||||
struct Vertex2DNDCMaterial:public Standard2DMaterial
|
||||
{
|
||||
Vertex2DNDCMaterial()
|
||||
{
|
||||
Reset();
|
||||
|
||||
color=PPFB_Vertex;
|
||||
}
|
||||
};
|
||||
}}//namespace hgl::graph
|
@@ -1,4 +1,5 @@
|
||||
add_subdirectory(Util)
|
||||
add_subdirectory(ShaderGen)
|
||||
add_subdirectory(SceneGraph)
|
||||
#add_subdirectory(Tools)
|
||||
add_subdirectory(GUI)
|
||||
|
@@ -27,14 +27,14 @@ namespace hgl
|
||||
return GetDefaultThemeEngine();
|
||||
}
|
||||
|
||||
RenderTarget *ThemeEngine::CreateRenderTarget(const uint32_t w,const uint32_t h,const VkFormat format)
|
||||
RenderTarget *ThemeEngine::CreateRT(const uint32_t w,const uint32_t h,const VkFormat format)
|
||||
{
|
||||
const uint width=power_to_2(w);
|
||||
const uint height=power_to_2(h);
|
||||
|
||||
FramebufferInfo fbi(format,w,h);
|
||||
|
||||
return device->CreateRenderTarget(&fbi);
|
||||
return device->CreateRT(&fbi);
|
||||
}
|
||||
|
||||
bool ThemeEngine::Registry(Form *f,const VkFormat format)
|
||||
@@ -46,7 +46,7 @@ namespace hgl
|
||||
|
||||
Vector2f size=f->GetSize();
|
||||
|
||||
RenderTarget *rt=CreateRenderTarget(size.x,size.y,format);
|
||||
RenderTarget *rt=CreateRT(size.x,size.y,format);
|
||||
|
||||
if(!rt)return(false);
|
||||
|
||||
@@ -97,7 +97,7 @@ namespace hgl
|
||||
}
|
||||
}
|
||||
|
||||
graph::RenderTarget *rt=CreateRenderTarget(w,h,format);
|
||||
graph::RenderTarget *rt=CreateRT(w,h,format);
|
||||
|
||||
if(!rt)return(false);
|
||||
|
||||
|
@@ -18,32 +18,38 @@ SET(TILE_SOURCE ${SG_INCLUDE_PATH}/TileData.h
|
||||
|
||||
SOURCE_GROUP("Tile" FILES ${TILE_SOURCE})
|
||||
|
||||
SET(SCENE_GRAPH_HEADER ${SG_INCLUDE_PATH}/Light.h
|
||||
${SG_INCLUDE_PATH}/SceneInfo.h
|
||||
SET(GEOMETRY_FILES ${SG_INCLUDE_PATH}/InlineGeometry.h
|
||||
#${SG_INCLUDE_PATH}/Mesh.h
|
||||
#${SG_INCLUDE_PATH}/Spline.h
|
||||
InlineGeometry.cpp
|
||||
#Mesh.cpp
|
||||
${SG_INCLUDE_PATH}/PrimitiveCreater.h
|
||||
PrimitiveCreater.cpp
|
||||
)
|
||||
|
||||
SOURCE_GROUP("Geometry" FILES ${GEOMETRY_FILES})
|
||||
|
||||
SET(LIGHT_FILES ${SG_INCLUDE_PATH}/Light.h)
|
||||
|
||||
source_group("Light" FILES ${LIGHT_FILES})
|
||||
|
||||
SET(SCENE_GRAPH_HEADER ${SG_INCLUDE_PATH}/SceneInfo.h
|
||||
${SG_INCLUDE_PATH}/SceneNode.h
|
||||
${SG_INCLUDE_PATH}/RenderNode.h
|
||||
${SG_INCLUDE_PATH}/SceneOrient.h
|
||||
${SG_INCLUDE_PATH}/RenderList.h
|
||||
${SG_INCLUDE_PATH}/InlineGeometry.h
|
||||
#${SG_INCLUDE_PATH}/Mesh.h
|
||||
#${SG_INCLUDE_PATH}/Material.h
|
||||
#${SG_INCLUDE_PATH}/Spline.h
|
||||
${SG_INCLUDE_PATH}/MaterialRenderList.h
|
||||
${SG_INCLUDE_PATH}/MaterialRenderMap.h
|
||||
)
|
||||
|
||||
SET(SCENE_GRAPH_SOURCE RenderList.cpp
|
||||
MaterialRenderList.cpp
|
||||
RenderAssignBuffer.h
|
||||
RenderAssignBuffer.cpp
|
||||
SceneNode.cpp
|
||||
SceneOrient.cpp
|
||||
InlineGeometry.cpp
|
||||
#InlinePipeline.cpp
|
||||
#Material.cpp
|
||||
#Mesh.cpp
|
||||
#SceneFile.cpp
|
||||
)
|
||||
SceneOrient.cpp)
|
||||
|
||||
SET(PRIMITIVE_CREATER_FILES ${SG_INCLUDE_PATH}/PrimitiveCreater.h
|
||||
PrimitiveCreater.cpp)
|
||||
|
||||
SOURCE_GROUP("PrimitiveCreater" FILES ${PRIMITIVE_CREATER_FILES})
|
||||
SOURCE_GROUP("Scene Graph" FILES ${SCENE_GRAPH_HEADER} ${SCENE_GRAPH_SOURCE})
|
||||
|
||||
SET(FONT_MANAGE_SOURCE ${SG_INCLUDE_PATH}/font/Font.h
|
||||
${SG_INCLUDE_PATH}/font/FontManage.h
|
||||
@@ -79,9 +85,6 @@ IF(WIN32)
|
||||
SOURCE_GROUP("Font\\Source\\Windows" FILES ${FONT_SOURCE_OS})
|
||||
ENDIF(WIN32)
|
||||
|
||||
SOURCE_GROUP("Header Files" FILES ${SCENE_GRAPH_HEADER})
|
||||
SOURCE_GROUP("Source Files" FILES ${SCENE_GRAPH_SOURCE})
|
||||
|
||||
SET(VK_RR_SOURCE ${SG_INCLUDE_PATH}/VKRenderResource.h
|
||||
${SG_INCLUDE_PATH}/VKRenderablePrimitiveCreater.h
|
||||
Vulkan/VKRenderResource.cpp
|
||||
@@ -94,8 +97,8 @@ SET(VK_RR_SHADER_FILES ${SG_INCLUDE_PATH}/VKShaderResource.h
|
||||
|
||||
SOURCE_GROUP("Vulkan\\RenderResource\\Shader" FILES ${VK_RR_SHADER_FILES})
|
||||
|
||||
SET(VK_RR_MATERIAL_FILES ${SG_INCLUDE_PATH}/VKMaterialDescriptorSets.h
|
||||
Vulkan/VKMaterialDescriptorSets.cpp)
|
||||
SET(VK_RR_MATERIAL_FILES ${SG_INCLUDE_PATH}/VKMaterialDescriptorManager.h
|
||||
Vulkan/VKMaterialDescriptorManager.cpp)
|
||||
|
||||
SOURCE_GROUP("Vulkan\\RenderResource\\Material" FILES ${VK_RR_MATERIAL_FILES})
|
||||
|
||||
@@ -117,6 +120,7 @@ SET(VK_MEMORY_SOURCE ${SG_INCLUDE_PATH}/VKMemory.h
|
||||
Vulkan/VKMemory.cpp
|
||||
Vulkan/VKMemoryAllocator.cpp
|
||||
Vulkan/VKBuffer.cpp
|
||||
Vulkan/VKArrayBuffer.cpp
|
||||
)
|
||||
|
||||
SET(VK_DEVICE_TEXTURE_SOURCE Vulkan/Texture/BufferImageCopy2D.h
|
||||
@@ -129,13 +133,15 @@ SET(VK_TEXTURE_LOADER_SOURCE ${SG_INCLUDE_PATH}/VKTextureCreateInfo.h
|
||||
Vulkan/Texture/VKTextureLoader.h
|
||||
Vulkan/Texture/VKTexture2DLoader.cpp
|
||||
Vulkan/Texture/VKTextureCubeLoader.cpp)
|
||||
|
||||
SET(VK_DEVICE_CREATER_SOURCE ${SG_INCLUDE_PATH}/VKDevice.h
|
||||
${SG_INCLUDE_PATH}/VKDeviceAttribute.h
|
||||
${SG_INCLUDE_PATH}/VKDeviceCreater.h
|
||||
Vulkan/VKDeviceAttribute.cpp
|
||||
Vulkan/VKDeviceCreater.cpp
|
||||
Vulkan/VKDevice.cpp)
|
||||
|
||||
SET(VK_DEVICE_SOURCE ${SG_INCLUDE_PATH}/VKDevice.h
|
||||
${SG_INCLUDE_PATH}/VKDeviceAttribute.h
|
||||
Vulkan/VKDeviceAttribute.cpp
|
||||
Vulkan/VKDeviceCreater.cpp
|
||||
Vulkan/VKDevice.cpp
|
||||
Vulkan/VKDeviceMemory.cpp
|
||||
SET(VK_DEVICE_SOURCE Vulkan/VKDeviceMemory.cpp
|
||||
Vulkan/VKDeviceBuffer.cpp
|
||||
Vulkan/VKDeviceImage.cpp
|
||||
Vulkan/VKDeviceSampler.cpp
|
||||
@@ -148,9 +154,12 @@ SET(VK_DEVICE_SOURCE ${SG_INCLUDE_PATH}/VKDevice.h
|
||||
|
||||
SET(VK_PHYSICAL_DEVICE_SOURCE ${SG_INCLUDE_PATH}/VKPhysicalDevice.h
|
||||
Vulkan/VKPhysicalDevice.cpp
|
||||
Vulkan/VKProperties.cpp)
|
||||
Vulkan/VKProperties.cpp
|
||||
Vulkan/DebugOutProperties.h
|
||||
Vulkan/Debug/VKPhysicalDeviceCapsOutput.cpp)
|
||||
|
||||
SOURCE_GROUP("Vulkan\\Device" FILES ${VK_DEVICE_SOURCE})
|
||||
SOURCE_GROUP("Vulkan\\Device\\Creater" FILES ${VK_DEVICE_CREATER_SOURCE})
|
||||
SOURCE_GROUP("Vulkan\\Device\\Debug" FILES ${VK_DEBUG_SOURCE})
|
||||
SOURCE_GROUP("Vulkan\\Device\\Instance" FILES ${VK_INST_SOURCE})
|
||||
SOURCE_GROUP("Vulkan\\Device\\Physical Device" FILES ${VK_PHYSICAL_DEVICE_SOURCE})
|
||||
@@ -180,6 +189,9 @@ SET(VK_TEXTURE_SOURCE ${SG_INCLUDE_PATH}/VKImageView.h
|
||||
SET(VK_MATERIAL_SOURCE ${SG_INCLUDE_PATH}/VKMaterial.h
|
||||
${SG_INCLUDE_PATH}/VKMaterialParameters.h
|
||||
${SG_INCLUDE_PATH}/VKMaterialInstance.h
|
||||
${SG_INCLUDE_PATH}/VKDescriptorBindingManage.h
|
||||
${SG_INCLUDE_PATH}/VKDynamicBufferAccess.h
|
||||
Vulkan/VKDescriptorBindingManage.cpp
|
||||
Vulkan/VKMaterial.cpp
|
||||
Vulkan/VKMaterialParameters.cpp
|
||||
Vulkan/VKMaterialInstance.cpp)
|
||||
@@ -238,8 +250,30 @@ IF(WIN32)
|
||||
IF(FORCE_DISCETE_GPU)
|
||||
SET(RENDER_DEVICE_SOURCE ForceDiscreteGPU.c)
|
||||
ENDIF()
|
||||
|
||||
SET(VULKAN_SURFACE_SOURCE Vulkan/Platform/WinVulkan.cpp)
|
||||
ENDIF(WIN32)
|
||||
|
||||
IF(UNIX)
|
||||
|
||||
IF(ANDROID)
|
||||
SET(VULKAN_SURFACE_SOURCE Vulkan/Platform/AndroidVulkan.cpp)
|
||||
ELSE()
|
||||
IF(APPLE)
|
||||
|
||||
|
||||
|
||||
ELSE()
|
||||
|
||||
SET(VULKAN_SURFACE_SOURCE Vulkan/Platform/XCBVulkan.cpp)
|
||||
ENDIF()
|
||||
|
||||
ENDIF()
|
||||
|
||||
ENDIF(UNIX)
|
||||
|
||||
SOURCE_GROUP("Vulkan\\Surface" FILES ${VULKAN_SURFACE_SOURCE})
|
||||
|
||||
SET(VULKAN_RENDER_SOURCE ${VK_RR_SOURCE}
|
||||
${VK_RR_SHADER_FILES}
|
||||
${VK_RR_MATERIAL_FILES}
|
||||
@@ -247,6 +281,7 @@ SET(VULKAN_RENDER_SOURCE ${VK_RR_SOURCE}
|
||||
${VK_DEBUG_SOURCE}
|
||||
${VK_MEMORY_SOURCE}
|
||||
${VK_DEVICE_SOURCE}
|
||||
${VK_DEVICE_CREATER_SOURCE}
|
||||
${VK_DEVICE_TEXTURE_SOURCE}
|
||||
${VK_TEXTURE_LOADER_SOURCE}
|
||||
${VK_PHYSICAL_DEVICE_SOURCE}
|
||||
@@ -262,18 +297,19 @@ SET(VULKAN_RENDER_SOURCE ${VK_RR_SOURCE}
|
||||
|
||||
add_cm_library(ULRE.SceneGraph "ULRE" ${SCENE_GRAPH_HEADER}
|
||||
${SCENE_GRAPH_SOURCE}
|
||||
${GEOMETRY_FILES}
|
||||
${LIGHT_FILES}
|
||||
|
||||
${SG_TEXTURE_SOURCE}
|
||||
${TILE_SOURCE}
|
||||
${SG_VAD_SOURCE}
|
||||
|
||||
${PRIMITIVE_CREATER_FILES}
|
||||
# ${FONT_MANAGE_SOURCE}
|
||||
# ${FONT_SOURCE}
|
||||
# ${FONT_SOURCE_OS}
|
||||
# ${TILE_FONT_SOURCE}
|
||||
# ${FONT_LAYOUT_SOURCE}
|
||||
# ${TEXT_RENDERABLE_SOURCE}
|
||||
|
||||
${FONT_MANAGE_SOURCE}
|
||||
${FONT_SOURCE}
|
||||
${FONT_SOURCE_OS}
|
||||
${TILE_FONT_SOURCE}
|
||||
${FONT_LAYOUT_SOURCE}
|
||||
${TEXT_RENDERABLE_SOURCE}
|
||||
|
||||
${VULKAN_RENDER_SOURCE})
|
||||
${VULKAN_RENDER_SOURCE}
|
||||
${VULKAN_SURFACE_SOURCE})
|
||||
|
@@ -21,7 +21,7 @@ namespace hgl
|
||||
if(!rc.Init(4))
|
||||
return(nullptr);
|
||||
|
||||
AutoDelete<VB2f> vertex=rc.CreateVADA<VB2f>(VAN::Position);
|
||||
AutoDelete<VB2f> vertex=rc.AccessVAD<VB2f>(VAN::Position);
|
||||
|
||||
if(!vertex)
|
||||
return(nullptr);
|
||||
@@ -49,7 +49,7 @@ namespace hgl
|
||||
if(!rc.Init(4))
|
||||
return(nullptr);
|
||||
|
||||
AutoDelete<VB2f> vertex=rc.CreateVADA<VB2f>(VAN::Position);
|
||||
AutoDelete<VB2f> vertex=rc.AccessVAD<VB2f>(VAN::Position);
|
||||
|
||||
vertex->WriteRectFan(rci->scope);
|
||||
}
|
||||
@@ -63,7 +63,7 @@ namespace hgl
|
||||
if(!rc.Init(rci->round_per*4))
|
||||
return(nullptr);
|
||||
|
||||
AutoDelete<VB2f> vertex=rc.CreateVADA<VB2f>(VAN::Position);
|
||||
AutoDelete<VB2f> vertex=rc.AccessVAD<VB2f>(VAN::Position);
|
||||
|
||||
Vector2f *coord=new Vector2f[rci->round_per];
|
||||
|
||||
@@ -131,8 +131,8 @@ namespace hgl
|
||||
if(!rc.Init(cci->field_count))return(nullptr);
|
||||
}
|
||||
|
||||
AutoDelete<VB2f> vertex=rc.CreateVADA<VB2f>(VAN::Position);
|
||||
AutoDelete<VB4f> color=rc.CreateVADA<VB4f>(VAN::Color);
|
||||
AutoDelete<VB2f> vertex=rc.AccessVAD<VB2f>(VAN::Position);
|
||||
AutoDelete<VB4f> color=rc.AccessVAD<VB4f>(VAN::Color);
|
||||
|
||||
if(!vertex)
|
||||
return(nullptr);
|
||||
@@ -169,7 +169,7 @@ namespace hgl
|
||||
if(!rc.Init(((pgci->step.x+1)+(pgci->step.y+1))*2))
|
||||
return(nullptr);
|
||||
|
||||
AutoDelete<VB3f> vertex=rc.CreateVADA<VB3f>(VAN::Position);
|
||||
AutoDelete<VB3f> vertex=rc.AccessVAD<VB3f>(VAN::Position);
|
||||
for(uint row=0;row<=pgci->step.x;row++)
|
||||
{
|
||||
float pos=float(row)/float(pgci->step.x);
|
||||
@@ -186,7 +186,7 @@ namespace hgl
|
||||
to(pgci->coord[0],pgci->coord[3],pos));
|
||||
}
|
||||
|
||||
AutoDelete<VB4f> color=rc.CreateVADA<VB4f>(VAN::Color);
|
||||
AutoDelete<VB4f> color=rc.AccessVAD<VB4f>(VAN::Color);
|
||||
if(color)
|
||||
{
|
||||
for(uint row=0;row<=pgci->step.x;row++)
|
||||
@@ -224,19 +224,19 @@ namespace hgl
|
||||
rc.WriteVAD(VAN::Position,xy_vertices,sizeof(xy_vertices));
|
||||
|
||||
{
|
||||
AutoDelete<VB3f> normal=rc.CreateVADA<VB3f>(VAN::Normal);
|
||||
AutoDelete<VB3f> normal=rc.AccessVAD<VB3f>(VAN::Normal);
|
||||
|
||||
if(normal)normal->RepeatWrite(xy_normal,4);
|
||||
}
|
||||
|
||||
{
|
||||
AutoDelete<VB3f> tangent=rc.CreateVADA<VB3f>(VAN::Tangent);
|
||||
AutoDelete<VB3f> tangent=rc.AccessVAD<VB3f>(VAN::Tangent);
|
||||
|
||||
tangent->RepeatWrite(xy_tangent,4);
|
||||
}
|
||||
|
||||
{
|
||||
AutoDelete<VB2f> tex_coord=rc.CreateVADA<VB2f>(VAN::TexCoord);
|
||||
AutoDelete<VB2f> tex_coord=rc.AccessVAD<VB2f>(VAN::TexCoord);
|
||||
|
||||
if(tex_coord)
|
||||
{
|
||||
@@ -323,7 +323,7 @@ namespace hgl
|
||||
{
|
||||
RANGE_CHECK_RETURN_NULLPTR(cci->color_type);
|
||||
|
||||
AutoDelete<VB4f> color=rc.CreateVADA<VB4f>(VAN::Color);
|
||||
AutoDelete<VB4f> color=rc.AccessVAD<VB4f>(VAN::Color);
|
||||
|
||||
if(color)
|
||||
{
|
||||
@@ -461,10 +461,10 @@ namespace hgl
|
||||
if(!rc.Init(numberVertices))
|
||||
return(nullptr);
|
||||
|
||||
AutoDelete<VB3f> vertex=rc.CreateVADA<VB3f>(VAN::Position);
|
||||
AutoDelete<VB3f> normal=rc.CreateVADA<VB3f>(VAN::Normal);
|
||||
AutoDelete<VB3f> tangent=rc.CreateVADA<VB3f>(VAN::Tangent);
|
||||
AutoDelete<VB2f> tex_coord=rc.CreateVADA<VB2f>(VAN::TexCoord);
|
||||
AutoDelete<VB3f> vertex=rc.AccessVAD<VB3f>(VAN::Position);
|
||||
AutoDelete<VB3f> normal=rc.AccessVAD<VB3f>(VAN::Normal);
|
||||
AutoDelete<VB3f> tangent=rc.AccessVAD<VB3f>(VAN::Tangent);
|
||||
AutoDelete<VB2f> tex_coord=rc.AccessVAD<VB2f>(VAN::TexCoord);
|
||||
|
||||
float *vp=vertex->Get();
|
||||
float *np=normal?normal->Get():nullptr;
|
||||
@@ -542,10 +542,10 @@ namespace hgl
|
||||
if(!rc.Init(numberVertices))
|
||||
return(nullptr);
|
||||
|
||||
AutoDelete<VB3f> vertex=rc.CreateVADA<VB3f>(VAN::Position);
|
||||
AutoDelete<VB3f> normal=rc.CreateVADA<VB3f>(VAN::Normal);
|
||||
AutoDelete<VB3f> tangent=rc.CreateVADA<VB3f>(VAN::Tangent);
|
||||
AutoDelete<VB2f> tex_coord=rc.CreateVADA<VB2f>(VAN::TexCoord);
|
||||
AutoDelete<VB3f> vertex=rc.AccessVAD<VB3f>(VAN::Position);
|
||||
AutoDelete<VB3f> normal=rc.AccessVAD<VB3f>(VAN::Normal);
|
||||
AutoDelete<VB3f> tangent=rc.AccessVAD<VB3f>(VAN::Tangent);
|
||||
AutoDelete<VB2f> tex_coord=rc.AccessVAD<VB2f>(VAN::TexCoord);
|
||||
|
||||
float *vp=vertex->Get();
|
||||
float *np=normal?normal->Get():nullptr;
|
||||
@@ -679,10 +679,10 @@ namespace hgl
|
||||
if(!rc.Init(numberVertices))
|
||||
return(nullptr);
|
||||
|
||||
AutoDelete<VB3f> vertex=rc.CreateVADA<VB3f>(VAN::Position);
|
||||
AutoDelete<VB3f> normal=rc.CreateVADA<VB3f>(VAN::Normal);
|
||||
AutoDelete<VB3f> tangent=rc.CreateVADA<VB3f>(VAN::Tangent);
|
||||
AutoDelete<VB2f> tex_coord=rc.CreateVADA<VB2f>(VAN::TexCoord);
|
||||
AutoDelete<VB3f> vertex=rc.AccessVAD<VB3f>(VAN::Position);
|
||||
AutoDelete<VB3f> normal=rc.AccessVAD<VB3f>(VAN::Normal);
|
||||
AutoDelete<VB3f> tangent=rc.AccessVAD<VB3f>(VAN::Tangent);
|
||||
AutoDelete<VB2f> tex_coord=rc.AccessVAD<VB2f>(VAN::TexCoord);
|
||||
|
||||
float *vp=vertex->Get();
|
||||
float *np=normal?normal->Get():nullptr;
|
||||
@@ -814,10 +814,10 @@ namespace hgl
|
||||
if (cci->numberSlices < 3 || numberVertices > GLUS_MAX_VERTICES || numberIndices > GLUS_MAX_INDICES)
|
||||
return nullptr;
|
||||
|
||||
AutoDelete<VB3f> vertex=rc.CreateVADA<VB3f>(VAN::Position);
|
||||
AutoDelete<VB3f> normal=rc.CreateVADA<VB3f>(VAN::Normal);
|
||||
AutoDelete<VB3f> tangent=rc.CreateVADA<VB3f>(VAN::Tangent);
|
||||
AutoDelete<VB2f> tex_coord=rc.CreateVADA<VB2f>(VAN::TexCoord);
|
||||
AutoDelete<VB3f> vertex=rc.AccessVAD<VB3f>(VAN::Position);
|
||||
AutoDelete<VB3f> normal=rc.AccessVAD<VB3f>(VAN::Normal);
|
||||
AutoDelete<VB3f> tangent=rc.AccessVAD<VB3f>(VAN::Tangent);
|
||||
AutoDelete<VB2f> tex_coord=rc.AccessVAD<VB2f>(VAN::TexCoord);
|
||||
|
||||
float *vp=vertex->Get();
|
||||
float *np=normal?normal->Get():nullptr;
|
||||
@@ -1036,10 +1036,10 @@ namespace hgl
|
||||
if (cci->numberSlices < 3 || cci->numberStacks < 1 || numberVertices > GLUS_MAX_VERTICES || numberIndices > GLUS_MAX_INDICES)
|
||||
return nullptr;
|
||||
|
||||
AutoDelete<VB3f> vertex=rc.CreateVADA<VB3f>(VAN::Position);
|
||||
AutoDelete<VB3f> normal=rc.CreateVADA<VB3f>(VAN::Normal);
|
||||
AutoDelete<VB3f> tangent=rc.CreateVADA<VB3f>(VAN::Tangent);
|
||||
AutoDelete<VB2f> tex_coord=rc.CreateVADA<VB2f>(VAN::TexCoord);
|
||||
AutoDelete<VB3f> vertex=rc.AccessVAD<VB3f>(VAN::Position);
|
||||
AutoDelete<VB3f> normal=rc.AccessVAD<VB3f>(VAN::Normal);
|
||||
AutoDelete<VB3f> tangent=rc.AccessVAD<VB3f>(VAN::Tangent);
|
||||
AutoDelete<VB2f> tex_coord=rc.AccessVAD<VB2f>(VAN::TexCoord);
|
||||
|
||||
float *vp=vertex->Get();
|
||||
float *np=normal?normal->Get():nullptr;
|
||||
@@ -1150,8 +1150,8 @@ namespace hgl
|
||||
if(!rc.Init(6))
|
||||
return(nullptr);
|
||||
|
||||
AutoDelete<VB3f> vertex=rc.CreateVADA<VB3f>(VAN::Position);
|
||||
AutoDelete<VB4f> color=rc.CreateVADA<VB4f>(VAN::Color);
|
||||
AutoDelete<VB3f> vertex=rc.AccessVAD<VB3f>(VAN::Position);
|
||||
AutoDelete<VB4f> color=rc.AccessVAD<VB4f>(VAN::Color);
|
||||
|
||||
if(!vertex||!color)
|
||||
return(nullptr);
|
||||
@@ -1195,7 +1195,7 @@ namespace hgl
|
||||
if(!rc.Init(8))
|
||||
return(nullptr);
|
||||
|
||||
AutoDelete<VB3f> vertex=rc.CreateVADA<VB3f>(VAN::Position);
|
||||
AutoDelete<VB3f> vertex=rc.AccessVAD<VB3f>(VAN::Position);
|
||||
|
||||
if(!vertex)return(nullptr);
|
||||
|
||||
@@ -1205,7 +1205,7 @@ namespace hgl
|
||||
{
|
||||
RANGE_CHECK_RETURN_NULLPTR(cci->color_type);
|
||||
|
||||
AutoDelete<VB4f> color=rc.CreateVADA<VB4f>(VAN::Color);
|
||||
AutoDelete<VB4f> color=rc.AccessVAD<VB4f>(VAN::Color);
|
||||
|
||||
if(color)
|
||||
{
|
||||
|
312
src/SceneGraph/MaterialRenderList.cpp
Normal file
312
src/SceneGraph/MaterialRenderList.cpp
Normal file
@@ -0,0 +1,312 @@
|
||||
#include<hgl/graph/MaterialRenderList.h>
|
||||
#include<hgl/graph/VKRenderable.h>
|
||||
#include<hgl/graph/VKDevice.h>
|
||||
#include<hgl/graph/VKCommandBuffer.h>
|
||||
#include<hgl/graph/VKVertexInput.h>
|
||||
#include<hgl/graph/VKRenderAssign.h>
|
||||
#include<hgl/util/sort/Sort.h>
|
||||
#include"RenderAssignBuffer.h"
|
||||
|
||||
/**
|
||||
*
|
||||
* 理论上讲,我们需要按以下顺序排序
|
||||
*
|
||||
* for(material)
|
||||
* for(pipeline)
|
||||
* for(material_instance)
|
||||
* for(vbo)
|
||||
*/
|
||||
|
||||
template<>
|
||||
int Comparator<hgl::graph::RenderNode>::compare(const hgl::graph::RenderNode &obj_one,const hgl::graph::RenderNode &obj_two) const
|
||||
{
|
||||
int off;
|
||||
|
||||
hgl::graph::Renderable *ri_one=obj_one.ri;
|
||||
hgl::graph::Renderable *ri_two=obj_two.ri;
|
||||
|
||||
//比较管线
|
||||
{
|
||||
off=ri_one->GetPipeline()
|
||||
-ri_two->GetPipeline();
|
||||
|
||||
if(off)
|
||||
return off;
|
||||
}
|
||||
|
||||
//比较顶点输入格式
|
||||
{
|
||||
off=ri_one->GetMaterialInstance()->GetVIL()
|
||||
-ri_two->GetMaterialInstance()->GetVIL();
|
||||
|
||||
if(off)
|
||||
return off;
|
||||
}
|
||||
|
||||
//比较模型
|
||||
{
|
||||
off=ri_one->GetPrimitive()
|
||||
-ri_two->GetPrimitive();
|
||||
|
||||
if(off)
|
||||
return off;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
MaterialRenderList::MaterialRenderList(GPUDevice *d,Material *m)
|
||||
{
|
||||
device=d;
|
||||
cmd_buf=nullptr;
|
||||
mtl=m;
|
||||
assign_buffer=new RenderAssignBuffer(d,mtl->GetMIDataBytes());
|
||||
|
||||
vbo_list=new VBOList(mtl->GetVertexInput()->GetCount());
|
||||
}
|
||||
|
||||
MaterialRenderList::~MaterialRenderList()
|
||||
{
|
||||
SAFE_CLEAR(vbo_list);
|
||||
SAFE_CLEAR(assign_buffer)
|
||||
}
|
||||
|
||||
void MaterialRenderList::Add(Renderable *ri,const Matrix4f &mat)
|
||||
{
|
||||
RenderNode rn;
|
||||
|
||||
rn.local_to_world=mat;
|
||||
rn.ri=ri;
|
||||
|
||||
rn_list.Add(rn);
|
||||
}
|
||||
|
||||
void MaterialRenderList::End()
|
||||
{
|
||||
//排序
|
||||
Sort(rn_list.GetArray());
|
||||
|
||||
const uint node_count=rn_list.GetCount();
|
||||
|
||||
if(node_count<=0)return;
|
||||
|
||||
if(mtl->HasMI())
|
||||
StatMI();
|
||||
|
||||
Stat();
|
||||
|
||||
//写入LocalToWorld数据
|
||||
assign_buffer->WriteNode(rn_list.GetData(),node_count,mi_set);
|
||||
}
|
||||
|
||||
void MaterialRenderList::RenderItem::Set(Renderable *ri)
|
||||
{
|
||||
pipeline =ri->GetPipeline();
|
||||
mi =ri->GetMaterialInstance();
|
||||
vid =ri->GetVertexInputData();
|
||||
}
|
||||
|
||||
void MaterialRenderList::StatMI()
|
||||
{
|
||||
mi_set.Clear();
|
||||
|
||||
for(RenderNode &rn:rn_list)
|
||||
mi_set.Add(rn.ri->GetMaterialInstance());
|
||||
|
||||
if(mi_set.GetCount()>mtl->GetMIMaxCount())
|
||||
{
|
||||
//超出最大数量了怎么办???
|
||||
}
|
||||
}
|
||||
|
||||
void MaterialRenderList::Stat()
|
||||
{
|
||||
const uint count=rn_list.GetCount();
|
||||
RenderNode *rn=rn_list.GetData();
|
||||
|
||||
ri_array.Clear();
|
||||
ri_array.Alloc(count);
|
||||
|
||||
RenderItem *ri=ri_array.GetData();
|
||||
|
||||
ri_count=1;
|
||||
|
||||
ri->first=0;
|
||||
ri->count=1;
|
||||
ri->Set(rn->ri);
|
||||
|
||||
last_pipeline =ri->pipeline;
|
||||
last_vil =ri->mi->GetVIL();
|
||||
last_vid =ri->vid;
|
||||
|
||||
++rn;
|
||||
|
||||
for(uint i=1;i<count;i++)
|
||||
{
|
||||
if(last_pipeline==rn->ri->GetPipeline())
|
||||
if(last_vil==rn->ri->GetMaterialInstance()->GetVIL())
|
||||
if(last_vid->Comp(rn->ri->GetVertexInputData()))
|
||||
{
|
||||
++ri->count;
|
||||
++rn;
|
||||
continue;
|
||||
}
|
||||
|
||||
++ri_count;
|
||||
++ri;
|
||||
|
||||
ri->first=i;
|
||||
ri->count=1;
|
||||
ri->Set(rn->ri);
|
||||
|
||||
last_pipeline =ri->pipeline;
|
||||
last_vil =ri->mi->GetVIL();
|
||||
last_vid =ri->vid;
|
||||
|
||||
++rn;
|
||||
}
|
||||
}
|
||||
|
||||
void MaterialRenderList::Bind(MaterialInstance *mi)
|
||||
{
|
||||
if(!mi)return;
|
||||
|
||||
assign_buffer->Bind(mi);
|
||||
|
||||
cmd_buf->BindDescriptorSets(mi->GetMaterial());
|
||||
}
|
||||
|
||||
bool MaterialRenderList::Bind(const VertexInputData *vid,const uint ri_index)
|
||||
{
|
||||
//binding号都是在VertexInput::CreateVIL时连续紧密排列生成的,所以bind时first_binding写0就行了。
|
||||
|
||||
const VIL *vil=last_vil;
|
||||
|
||||
if(vil->GetCount(VertexInputGroup::Basic)!=vid->binding_count)
|
||||
return(false); //这里基本不太可能,因为CreateRenderable时就会检查值是否一样
|
||||
|
||||
vbo_list->Restart();
|
||||
|
||||
//Basic组,它所有的VBO信息均来自于Primitive,由vid参数传递进来
|
||||
{
|
||||
vbo_list->Add(vid->buffer_list,vid->buffer_offset,vid->binding_count);
|
||||
}
|
||||
|
||||
//if(!vbo_list.IsFull()) //Joint组,暂未支持
|
||||
//{
|
||||
// const uint joint_id_binding_count=vil->GetCount(VertexInputGroup::JointID);
|
||||
|
||||
// if(joint_id_binding_count>0) //有矩阵信息
|
||||
// {
|
||||
// count+=joint_id_binding_count;
|
||||
|
||||
// if(count<binding_count) //JointWeight组
|
||||
// {
|
||||
// const uint joing_weight_binding_count=vil->GetCount(VertexInputGroup::JointWeight);
|
||||
|
||||
// if(joing_weight_binding_count!=1)
|
||||
// {
|
||||
// ++count;
|
||||
// }
|
||||
// else //JointWieght不为1是个bug,除非未来支持8权重
|
||||
// {
|
||||
// return(false);
|
||||
// }
|
||||
// }
|
||||
// else //有JointID没有JointWeight? 这是个BUG
|
||||
// {
|
||||
// return(false);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
if(!vbo_list->IsFull()) //Assign组
|
||||
{
|
||||
const uint assign_binding_count=vil->GetCount(VertexInputGroup::Assign);
|
||||
|
||||
if(assign_binding_count>0)
|
||||
{
|
||||
if(assign_binding_count!=1)
|
||||
return(false);
|
||||
|
||||
vbo_list->Add(assign_buffer->GetAssignVBO(),ASSIGN_VBO_STRIDE_BYTES*ri_index);
|
||||
}
|
||||
}
|
||||
|
||||
//if(count!=binding_count)
|
||||
//{
|
||||
// //还有没支持的绑定组????
|
||||
|
||||
// return(false);
|
||||
//}
|
||||
|
||||
cmd_buf->BindVBO(vbo_list);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void MaterialRenderList::Render(RenderItem *ri)
|
||||
{
|
||||
if(last_pipeline!=ri->pipeline)
|
||||
{
|
||||
cmd_buf->BindPipeline(ri->pipeline);
|
||||
last_pipeline=ri->pipeline;
|
||||
|
||||
last_vid=nullptr;
|
||||
|
||||
//这里未来尝试换pipeline同时不换mi/primitive是否需要重新绑定mi/primitive
|
||||
}
|
||||
|
||||
if(last_vil!=ri->mi->GetVIL())
|
||||
{
|
||||
Bind(ri->mi);
|
||||
last_vil=ri->mi->GetVIL();
|
||||
|
||||
last_vid=nullptr;
|
||||
}
|
||||
|
||||
if(!ri->vid->Comp(last_vid))
|
||||
{
|
||||
Bind(ri->vid,ri->first);
|
||||
last_vid=ri->vid;
|
||||
}
|
||||
|
||||
const IndexBufferData *ibd=last_vid->index_buffer;
|
||||
|
||||
if(ibd->buffer)
|
||||
{
|
||||
cmd_buf->BindIBO(ibd);
|
||||
|
||||
cmd_buf->DrawIndexed(ibd->buffer->GetCount(),ri->count);
|
||||
}
|
||||
else
|
||||
{
|
||||
cmd_buf->Draw(last_vid->vertex_count,ri->count);
|
||||
}
|
||||
}
|
||||
|
||||
void MaterialRenderList::Render(RenderCmdBuffer *rcb)
|
||||
{
|
||||
if(!rcb)return;
|
||||
const uint count=rn_list.GetCount();
|
||||
|
||||
if(count<=0)return;
|
||||
|
||||
if(ri_count<=0)return;
|
||||
|
||||
cmd_buf=rcb;
|
||||
|
||||
RenderItem *ri=ri_array.GetData();
|
||||
|
||||
last_pipeline =nullptr;
|
||||
last_vil =nullptr;
|
||||
last_vid =nullptr;
|
||||
|
||||
for(uint i=0;i<ri_count;i++)
|
||||
{
|
||||
Render(ri);
|
||||
++ri;
|
||||
}
|
||||
}
|
||||
VK_NAMESPACE_END
|
@@ -28,32 +28,32 @@ namespace hgl
|
||||
if(!vil)return(nullptr);
|
||||
if(name.IsEmpty())return(nullptr);
|
||||
|
||||
const auto *va=vil->GetConfig(name);
|
||||
const VertexInputFormat *vif=vil->GetConfig(name);
|
||||
|
||||
if(!va)
|
||||
if(!vif)
|
||||
return(nullptr);
|
||||
|
||||
ShaderStageBind *ssb;
|
||||
PrimitiveVertexBuffer *pvb;
|
||||
|
||||
if(ssb_map.Get(name,ssb))
|
||||
return ssb->data;
|
||||
if(vbo_map.Get(name,pvb))
|
||||
return pvb->data;
|
||||
|
||||
VAD *vad=hgl::graph::CreateVertexAttribData(vertices_number,va->format,va->vec_size,va->stride);
|
||||
VAD *vad=hgl::graph::CreateVertexAttribData(vertices_number,vif);
|
||||
|
||||
if(!vad)
|
||||
return(nullptr);
|
||||
|
||||
ssb=new ShaderStageBind;
|
||||
pvb=new PrimitiveVertexBuffer;
|
||||
|
||||
ssb->data =vad;
|
||||
ssb->name =name;
|
||||
ssb->binding=va->binding;
|
||||
pvb->data =vad;
|
||||
pvb->name =name;
|
||||
pvb->binding=vif->binding;
|
||||
|
||||
ssb->vbo =nullptr;
|
||||
pvb->vbo =nullptr;
|
||||
|
||||
ssb_map.Add(name,ssb);
|
||||
vbo_map.Add(name,pvb);
|
||||
|
||||
return ssb->data;
|
||||
return pvb->data;
|
||||
}
|
||||
|
||||
bool PrimitiveCreater::WriteVAD(const AnsiString &name,const void *data,const uint32_t bytes)
|
||||
@@ -63,28 +63,28 @@ namespace hgl
|
||||
if(!data)return(false);
|
||||
if(!bytes)return(false);
|
||||
|
||||
ShaderStageBind *ssb;
|
||||
PrimitiveVertexBuffer *pvb;
|
||||
|
||||
if(ssb_map.Get(name,ssb))
|
||||
if(vbo_map.Get(name,pvb))
|
||||
return false;
|
||||
|
||||
const auto *va=vil->GetConfig(name);
|
||||
const VertexInputFormat *vif=vil->GetConfig(name);
|
||||
|
||||
if(!va)
|
||||
if(!vif)
|
||||
return(false);
|
||||
|
||||
if(va->stride*vertices_number!=bytes)
|
||||
if(vif->stride*vertices_number!=bytes)
|
||||
return(false);
|
||||
|
||||
ssb=new ShaderStageBind;
|
||||
pvb=new PrimitiveVertexBuffer;
|
||||
|
||||
ssb->data =nullptr;
|
||||
ssb->name =name;
|
||||
ssb->binding=va->binding;
|
||||
pvb->data =nullptr;
|
||||
pvb->name =name;
|
||||
pvb->binding=vif->binding;
|
||||
|
||||
ssb->vbo =db->CreateVBO(va->format,vertices_number,data);
|
||||
pvb->vbo =db->CreateVBO(vif->format,vertices_number,data);
|
||||
|
||||
ssb_map.Add(name,ssb);
|
||||
vbo_map.Add(name,pvb);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -107,20 +107,20 @@ namespace hgl
|
||||
|
||||
Primitive *PrimitiveCreater::Finish()
|
||||
{
|
||||
const uint si_count=vil->GetAttrCount();
|
||||
const uint si_count=vil->GetCount();
|
||||
|
||||
if(ssb_map.GetCount()!=si_count)
|
||||
if(vbo_map.GetCount()!=si_count)
|
||||
return(nullptr);
|
||||
|
||||
Primitive *primitive=db->CreatePrimitive(vertices_number);
|
||||
|
||||
const auto *sp=ssb_map.GetDataList();
|
||||
const auto *sp=vbo_map.GetDataList();
|
||||
for(uint i=0;i<si_count;i++)
|
||||
{
|
||||
if((*sp)->right->vbo)
|
||||
primitive->Set((*sp)->left,(*sp)->right->vbo);
|
||||
if((*sp)->value->vbo)
|
||||
primitive->Set((*sp)->key,(*sp)->value->vbo);
|
||||
else
|
||||
primitive->Set((*sp)->left,db->CreateVBO((*sp)->right->data));
|
||||
primitive->Set((*sp)->key,db->CreateVBO((*sp)->value->data));
|
||||
|
||||
++sp;
|
||||
}
|
||||
|
152
src/SceneGraph/RenderAssignBuffer.cpp
Normal file
152
src/SceneGraph/RenderAssignBuffer.cpp
Normal file
@@ -0,0 +1,152 @@
|
||||
#include"RenderAssignBuffer.h"
|
||||
#include<hgl/graph/VKVertexAttribBuffer.h>
|
||||
#include<hgl/graph/VKDevice.h>
|
||||
#include<hgl/graph/VKMaterialInstance.h>
|
||||
#include<hgl/graph/RenderNode.h>
|
||||
#include<hgl/graph/VKRenderable.h>
|
||||
#include<hgl/graph/VKRenderAssign.h>
|
||||
#include<hgl/graph/mtl/UBOCommon.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
RenderAssignBuffer::RenderAssignBuffer(GPUDevice *dev,const uint mi_bytes)
|
||||
{
|
||||
hgl_zero(*this);
|
||||
|
||||
device=dev;
|
||||
|
||||
mi_data_bytes=mi_bytes;
|
||||
|
||||
ubo_mi=nullptr;
|
||||
mi_count=0;
|
||||
}
|
||||
|
||||
VkBuffer RenderAssignBuffer::GetAssignVBO()const
|
||||
{
|
||||
return vbo_assigns->GetBuffer();
|
||||
}
|
||||
|
||||
void RenderAssignBuffer::Bind(MaterialInstance *mi)const
|
||||
{
|
||||
const VIL *vil=mi->GetVIL();
|
||||
|
||||
const uint assign_binding_count=vil->GetCount(VertexInputGroup::Assign);
|
||||
|
||||
if(assign_binding_count<=0)return;
|
||||
|
||||
mi->BindUBO(DescriptorSetType::PerFrame,mtl::SBS_LocalToWorld.name,ubo_l2w);
|
||||
mi->BindUBO(DescriptorSetType::PerMaterial,mtl::SBS_MaterialInstance.name,ubo_mi);
|
||||
}
|
||||
|
||||
void RenderAssignBuffer::Clear()
|
||||
{
|
||||
SAFE_CLEAR(ubo_l2w);
|
||||
SAFE_CLEAR(ubo_mi);
|
||||
SAFE_CLEAR(vbo_assigns);
|
||||
|
||||
node_count=0;
|
||||
mi_count=0;
|
||||
}
|
||||
|
||||
void RenderAssignBuffer::Alloc(const uint nc,const uint mc)
|
||||
{
|
||||
Clear();
|
||||
|
||||
{
|
||||
node_count=nc;
|
||||
|
||||
ubo_l2w=device->CreateUBO(node_count*sizeof(Matrix4f));
|
||||
}
|
||||
|
||||
if(mi_data_bytes>0&&mc>0)
|
||||
{
|
||||
mi_count=mc;
|
||||
|
||||
ubo_mi=device->CreateUBO(mi_data_bytes*mi_count);
|
||||
}
|
||||
|
||||
vbo_assigns=device->CreateVBO(ASSIGN_VBO_FMT,node_count);
|
||||
}
|
||||
|
||||
void RenderAssignBuffer::WriteNode(RenderNode *render_node,const uint count,const MaterialInstanceSets &mi_set)
|
||||
{
|
||||
RenderNode *rn;
|
||||
|
||||
Alloc(count,mi_set.GetCount());
|
||||
|
||||
if(ubo_mi)
|
||||
{
|
||||
uint8 *mip=(uint8 *)(ubo_mi->Map());
|
||||
|
||||
for(MaterialInstance *mi:mi_set)
|
||||
{
|
||||
memcpy(mip,mi->GetMIData(),mi_data_bytes);
|
||||
mip+=mi_data_bytes;
|
||||
}
|
||||
|
||||
ubo_mi->Unmap();
|
||||
}
|
||||
|
||||
uint16 *idp=(uint16 *)(vbo_assigns->Map());
|
||||
|
||||
{
|
||||
Matrix4f *tp=(hgl::Matrix4f *)(ubo_l2w->Map());
|
||||
Matrix4f *l2w=tp;
|
||||
|
||||
rn=render_node;
|
||||
|
||||
for(uint i=0;i<count;i++)
|
||||
{
|
||||
*l2w=rn->local_to_world;
|
||||
++l2w;
|
||||
|
||||
*idp=i;
|
||||
++idp;
|
||||
|
||||
*idp=mi_set.Find(rn->ri->GetMaterialInstance());
|
||||
++idp;
|
||||
|
||||
++rn;
|
||||
}
|
||||
|
||||
ubo_l2w->Unmap();
|
||||
}
|
||||
|
||||
vbo_assigns->Unmap();
|
||||
}
|
||||
|
||||
//void WriteMaterialInstance(RenderNode *render_node,const uint count,const MaterialInstanceSets &mi_set)
|
||||
//{
|
||||
// //MaterialInstance ID
|
||||
// {
|
||||
// uint8 *tp=(uint8 *)(mi_id->Map());
|
||||
|
||||
// for(uint i=0;i<count;i++)
|
||||
// {
|
||||
// *tp=mi_set.Find(render_node->ri->GetMaterialInstance());
|
||||
// ++tp;
|
||||
// ++render_node;
|
||||
// }
|
||||
// mi_id->Unmap();
|
||||
// }
|
||||
|
||||
// //MaterialInstance Data
|
||||
// {
|
||||
// //const uint count=mi_set.GetCount();
|
||||
|
||||
// //uint8 *tp=(uint8 *)(mi_data_buffer->Map());
|
||||
// //const MaterialInstance **mi=mi_set.GetData();
|
||||
|
||||
// //for(uint i=0;i<count;i++)
|
||||
// //{
|
||||
// // memcpy(tp,(*mi)->GetData(),mi_size);
|
||||
//
|
||||
// // ++mi;
|
||||
// // tp+=mi_size;
|
||||
// //}
|
||||
|
||||
// //mi_data_buffer->Unmap();
|
||||
// }
|
||||
//}
|
||||
|
||||
VK_NAMESPACE_END
|
67
src/SceneGraph/RenderAssignBuffer.h
Normal file
67
src/SceneGraph/RenderAssignBuffer.h
Normal file
@@ -0,0 +1,67 @@
|
||||
#pragma once
|
||||
#include<hgl/graph/RenderNode.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
// ubo_range大致分为三档:
|
||||
//
|
||||
// 16k: Mali-T系列或更早、Mali-G71为16k
|
||||
//
|
||||
// 64k: 大部分手机与PC均为64k
|
||||
//
|
||||
// >64k: Intel 核显与 PowerVR 为128MB,AMD显卡为4GB,可视为随显存无上限。
|
||||
//
|
||||
// 我们使用uint8类型在vertex input中保存MaterialInstance ID,表示范围0-255。
|
||||
// 所以MaterialInstance结构容量按16k/64k分为两个档次,64字节和256字节
|
||||
|
||||
// 如果一定要使用超过16K/64K硬件限制的容量,有两种办法
|
||||
// 一、分多次渲染,使用UBO Offset偏移UBO数据区。
|
||||
// 二、使用SSBO,但这样会导致性能下降,所以不推荐使用。
|
||||
|
||||
// 但我们不解决这个问题
|
||||
// 我们天然要求将材质实例数据分为两个等级,同时要求一次渲染不能超过256种材质实例。
|
||||
// 所以 UBO Range为16k时,实例数据不能超过64字节。UBO Range为64k时,实例数据不能超过256字节。
|
||||
|
||||
|
||||
struct RenderNode;
|
||||
class MaterialInstance;
|
||||
|
||||
/*
|
||||
* 渲染节点额外提供的数据
|
||||
*/
|
||||
class RenderAssignBuffer
|
||||
{
|
||||
private:
|
||||
|
||||
GPUDevice *device;
|
||||
|
||||
uint node_count; ///<渲染节点数量
|
||||
DeviceBuffer *ubo_l2w; ///<Local2World数据
|
||||
|
||||
uint32_t mi_data_bytes; ///<材质实例数据字节数
|
||||
uint32_t mi_count; ///<材质实例数量
|
||||
DeviceBuffer *ubo_mi; ///<材质实例数据
|
||||
|
||||
//Assign VBO
|
||||
VBO *vbo_assigns; ///<RG16UI格式的VertexInputStream,,,,X:L2W ID,Y:MI ID
|
||||
|
||||
private:
|
||||
|
||||
void Alloc(const uint nc,const uint mc);
|
||||
|
||||
void Clear();
|
||||
|
||||
public:
|
||||
|
||||
VkBuffer GetAssignVBO()const;
|
||||
|
||||
void Bind(MaterialInstance *)const;
|
||||
|
||||
public:
|
||||
|
||||
RenderAssignBuffer(GPUDevice *dev,const uint32_t mi_bytes);
|
||||
~RenderAssignBuffer(){Clear();}
|
||||
|
||||
void WriteNode(RenderNode *render_node,const uint count,const MaterialInstanceSets &mi_set);
|
||||
|
||||
};//struct RenderAssignBuffer
|
||||
VK_NAMESPACE_END
|
@@ -1,5 +1,4 @@
|
||||
#include<hgl/graph/RenderList.h>
|
||||
#include<hgl/graph/Camera.h>
|
||||
#include<hgl/graph/SceneNode.h>
|
||||
#include<hgl/graph/VKBuffer.h>
|
||||
#include<hgl/graph/VKPrimitive.h>
|
||||
@@ -9,69 +8,6 @@
|
||||
#include<hgl/graph/VKRenderable.h>
|
||||
#include<hgl/util/sort/Sort.h>
|
||||
|
||||
/**
|
||||
* 理论上讲,我们需要按以下顺序排序
|
||||
*
|
||||
* for(pipeline)
|
||||
* for(material_instance)
|
||||
* for(vbo)
|
||||
* for(distance)
|
||||
*/
|
||||
|
||||
template<>
|
||||
int Comparator<RenderNodePointer>::compare(const RenderNodePointer &obj_one,const RenderNodePointer &obj_two) const
|
||||
{
|
||||
int off;
|
||||
|
||||
hgl::graph::Renderable *ri_one=obj_one->ri;
|
||||
hgl::graph::Renderable *ri_two=obj_two->ri;
|
||||
|
||||
//比较管线
|
||||
{
|
||||
off=ri_one->GetPipeline()
|
||||
-ri_two->GetPipeline();
|
||||
|
||||
if(off)
|
||||
return off;
|
||||
}
|
||||
|
||||
//比较材质实例
|
||||
{
|
||||
for(int i =(int)hgl::graph::DescriptorSetType::BEGIN_RANGE;
|
||||
i<=(int)hgl::graph::DescriptorSetType::END_RANGE;
|
||||
i++)
|
||||
{
|
||||
off=ri_one->GetMP((hgl::graph::DescriptorSetType)i)
|
||||
-ri_two->GetMP((hgl::graph::DescriptorSetType)i);
|
||||
|
||||
if(off)
|
||||
return off;
|
||||
}
|
||||
}
|
||||
|
||||
//比较vbo+ebo
|
||||
{
|
||||
off=ri_one->GetBufferHash()
|
||||
-ri_two->GetBufferHash();
|
||||
|
||||
if(off)
|
||||
return off;
|
||||
}
|
||||
|
||||
//比较距离
|
||||
{
|
||||
const double dist=obj_one->distance_to_camera_square-
|
||||
obj_two->distance_to_camera_square;
|
||||
|
||||
//由于距离差距可能会小于1,但又返回int,所以需要做如此处理
|
||||
|
||||
if(dist>0)return 1;else
|
||||
if(dist<0)return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
@@ -79,89 +15,14 @@ namespace hgl
|
||||
RenderList::RenderList(GPUDevice *dev)
|
||||
{
|
||||
device =dev;
|
||||
cmd_buf =nullptr;
|
||||
|
||||
hgl_zero(camera_info);
|
||||
|
||||
mvp_array =new MVPArrayBuffer(device,VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
|
||||
|
||||
ubo_offset =0;
|
||||
ubo_align =0;
|
||||
|
||||
last_pipeline =nullptr;
|
||||
hgl_zero(last_mp);
|
||||
last_vbo =0;
|
||||
renderable_count=0;
|
||||
}
|
||||
|
||||
RenderList::~RenderList()
|
||||
{
|
||||
delete mvp_array;
|
||||
}
|
||||
|
||||
bool RenderList::Begin()
|
||||
{
|
||||
render_node_list.ClearData();
|
||||
mvp_array->Clear();
|
||||
ri_list.ClearData();
|
||||
|
||||
material_sets.ClearData();
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void RenderList::End()
|
||||
{
|
||||
if(render_node_list.GetCount()<=0)return;
|
||||
|
||||
//排序
|
||||
Sort(render_node_list,&render_node_comparator);
|
||||
|
||||
//产生MVP矩阵UBO数据
|
||||
{
|
||||
const uint32_t count=render_node_list.GetCount();
|
||||
|
||||
{
|
||||
//按当前总节点数量分配UBO
|
||||
mvp_array->Alloc(count);
|
||||
mvp_array->Clear();
|
||||
|
||||
ri_list.ClearData();
|
||||
ri_list.SetCount(count);
|
||||
}
|
||||
|
||||
{
|
||||
ubo_align=mvp_array->GetUnitSize();
|
||||
|
||||
char *mp=(char *)(mvp_array->Map(0,count));
|
||||
Renderable **ri=ri_list.GetData();
|
||||
|
||||
for(RenderNode *node:render_node_list) //未来可能要在Expend处考虑做去重
|
||||
{
|
||||
memcpy(mp,&(node->matrix),MVPMatrixBytes);
|
||||
mp+=ubo_align;
|
||||
|
||||
(*ri)=node->ri;
|
||||
++ri;
|
||||
}
|
||||
|
||||
mvp_array->Flush(count);
|
||||
}
|
||||
}
|
||||
|
||||
//为所有的材质绑定
|
||||
for(Material *mtl:material_sets)
|
||||
{
|
||||
MaterialParameters *mp=mtl->GetMP(DescriptorSetType::PerObject);
|
||||
|
||||
if(mp)
|
||||
{
|
||||
if(mp->BindUBO("r_scene_info",mvp_array->GetBuffer(),true))
|
||||
mp->Update();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool RenderList::Expend(SceneNode *sn)
|
||||
bool RenderList::ExpendNode(SceneNode *sn)
|
||||
{
|
||||
if(!sn)return(false);
|
||||
|
||||
@@ -169,135 +30,54 @@ namespace hgl
|
||||
|
||||
if(ri)
|
||||
{
|
||||
RenderNode *rn=new RenderNode;
|
||||
Material *mtl=ri->GetMaterial();
|
||||
MaterialRenderList *mrl;
|
||||
|
||||
rn->matrix.Set(sn->GetLocalToWorldMatrix(),camera_info.vp,camera_info.view);
|
||||
if(!mrl_map.Get(mtl,mrl))
|
||||
{
|
||||
mrl=new MaterialRenderList(device,mtl);
|
||||
|
||||
rn->WorldCenter=sn->GetWorldCenter();
|
||||
mrl_map.Add(mtl,mrl);
|
||||
}
|
||||
|
||||
mrl->Add(ri,sn->GetLocalToWorldMatrix());
|
||||
|
||||
rn->distance_to_camera_square=length_squared(rn->WorldCenter,camera_info.pos);
|
||||
// rn->distance_to_camera=sqrtf(rn->distance_to_camera_square);
|
||||
|
||||
rn->ri=ri;
|
||||
|
||||
render_node_list.Add(rn);
|
||||
|
||||
material_sets.Add(ri->GetMaterial());
|
||||
++renderable_count;
|
||||
}
|
||||
|
||||
for(SceneNode *sub:sn->SubNode)
|
||||
Expend(sub);
|
||||
ExpendNode(sub);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool RenderList::Expend(const CameraInfo &ci,SceneNode *sn)
|
||||
bool RenderList::Expend(SceneNode *sn)
|
||||
{
|
||||
if(!device|!sn)return(false);
|
||||
|
||||
camera_info=ci;
|
||||
|
||||
Begin();
|
||||
Expend(sn);
|
||||
End();
|
||||
mrl_map.Begin();
|
||||
ExpendNode(sn);
|
||||
mrl_map.End();
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void RenderList::Render(Renderable *ri)
|
||||
{
|
||||
if(last_pipeline!=ri->GetPipeline())
|
||||
{
|
||||
last_pipeline=ri->GetPipeline();
|
||||
|
||||
cmd_buf->BindPipeline(last_pipeline);
|
||||
}
|
||||
|
||||
{
|
||||
uint32_t ds_count=0;
|
||||
uint32_t first_set=0;
|
||||
MaterialParameters *mp;
|
||||
|
||||
ENUM_CLASS_FOR(DescriptorSetType,int,i)
|
||||
{
|
||||
if(i==(int)DescriptorSetType::PerObject)continue;
|
||||
|
||||
mp=ri->GetMP((DescriptorSetType)i);
|
||||
|
||||
if(last_mp[i]!=mp)
|
||||
{
|
||||
last_mp[i]=mp;
|
||||
|
||||
if(mp)
|
||||
{
|
||||
ds_list[ds_count]=mp->GetVkDescriptorSet();
|
||||
++ds_count;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(mp)
|
||||
++first_set;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
mp=ri->GetMP(DescriptorSetType::PerObject);
|
||||
|
||||
if(mp)
|
||||
{
|
||||
ds_list[ds_count]=mp->GetVkDescriptorSet();
|
||||
++ds_count;
|
||||
|
||||
cmd_buf->BindDescriptorSets(ri->GetPipelineLayout(),first_set,ds_list,ds_count,&ubo_offset,1);
|
||||
}
|
||||
else
|
||||
{
|
||||
cmd_buf->BindDescriptorSets(ri->GetPipelineLayout(),first_set,ds_list,ds_count,nullptr,0);
|
||||
}
|
||||
|
||||
ubo_offset+=ubo_align;
|
||||
}
|
||||
}
|
||||
|
||||
if(last_vbo!=ri->GetBufferHash())
|
||||
{
|
||||
last_vbo=ri->GetBufferHash();
|
||||
|
||||
cmd_buf->BindVBO(ri);
|
||||
}
|
||||
|
||||
const IndexBuffer *ib=ri->GetIndexBuffer();
|
||||
|
||||
if(ib)
|
||||
{
|
||||
cmd_buf->DrawIndexed(ib->GetCount());
|
||||
}
|
||||
else
|
||||
{
|
||||
cmd_buf->Draw(ri->GetDrawCount());
|
||||
}
|
||||
}
|
||||
|
||||
bool RenderList::Render(RenderCmdBuffer *cb)
|
||||
{
|
||||
if(!cb)
|
||||
return(false);
|
||||
|
||||
if(ri_list.GetCount()<=0)
|
||||
if(renderable_count<=0)
|
||||
return(true);
|
||||
|
||||
cmd_buf=cb;
|
||||
|
||||
last_pipeline=nullptr;
|
||||
hgl_zero(last_mp);
|
||||
last_vbo=0;
|
||||
ubo_offset=0;
|
||||
|
||||
for(Renderable *ri:ri_list)
|
||||
Render(ri);
|
||||
mrl_map.Render(cb);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void RenderList::Clear()
|
||||
{
|
||||
mrl_map.Clear();
|
||||
}
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
|
@@ -1,5 +1,4 @@
|
||||
#include<hgl/graph/SceneNode.h>
|
||||
#include<hgl/graph/RenderList.h>
|
||||
#include<hgl/graph/VKRenderable.h>
|
||||
namespace hgl
|
||||
{
|
||||
|
58
src/SceneGraph/StaticRenderManage.md
Normal file
58
src/SceneGraph/StaticRenderManage.md
Normal file
@@ -0,0 +1,58 @@
|
||||
# 静态渲染管理
|
||||
|
||||
## 静态渲染的意义是什么?
|
||||
|
||||
静态渲染管理中的“静态”并不是指在场景中静止不动的所有物件,而是说大部分时间都会出现在场景中的物件。它包含地形、花草树木、房屋、常见人物,武器装备等等。如果归划好,可以将绝大部分的物件都划入静态渲染中。
|
||||
|
||||
它的意义为的是所有添加进管理器的模型原始资源,都会一直存在。与它们本身是否显示在画面中,并无关联。为的是避开对显存资源的动态调配。
|
||||
|
||||
在静态渲染管理器中的所有模型,会根据顶点数据格式(Vertex Input Format)分类。每种格式所有模型共用一套超大VBO(Vertex Buffer Object),以达到在渲染时渲染不同模型不会切换VBO的效果,并进一步达成“一个格式,一次Drawcall全部画完”的极致效果。
|
||||
|
||||
## 材质的定义
|
||||
|
||||
1.Material 材质可以简单理解为是Shader的包装。
|
||||
|
||||
2.Material Instance 材质实例是指同一材质下,不同的参数配置。
|
||||
|
||||
## 我们需要做什么?
|
||||
|
||||
1.在Shader中,建立两个UBO或SSBO
|
||||
|
||||
```glsl
|
||||
//一个用于存所有Local to World矩阵的数组
|
||||
|
||||
#define MI_MAX_COUNT (UBORange/sizeof(mat4))
|
||||
|
||||
layout(set=?,binding=?) uniform LocalToWorldData
|
||||
{
|
||||
mat4 mats[L2W_MAX_COUNT];
|
||||
}l2w;
|
||||
```
|
||||
|
||||
```glsl
|
||||
//一个用于存所有MaterialInstance数据的数组
|
||||
|
||||
#define MI_MAX_COUNT (UBORange/sizeof(MaterialInstance))
|
||||
|
||||
layout(set=?,binding=?) uniform MaterialInstanceData
|
||||
{
|
||||
MaterialInstance mi_array[MI_MAX_COUNT];
|
||||
}mi;
|
||||
```
|
||||
|
||||
2.建立一个RG8UI或RG16UI的Vertex Input Stream,用于保存访问LocalToWorld/MaterialInstance的索引
|
||||
|
||||
```glsl
|
||||
layout(location=?) in uvec2 Assign; //Local To World矩阵ID与材质ID输入数据流
|
||||
|
||||
mat4 GetLocalToWorld()
|
||||
{
|
||||
return l2w.mats[Assign.x];
|
||||
}
|
||||
|
||||
MaterialInstance GetMaterialInstance()
|
||||
{
|
||||
return mi.mi_array[Assign.y];
|
||||
}
|
||||
```
|
||||
|
@@ -94,54 +94,54 @@ namespace hgl
|
||||
|
||||
struct VulkanTexturePixelFormat
|
||||
{
|
||||
VkFormat format;
|
||||
VkFormat format;
|
||||
|
||||
uint8 channels; //颜色通道数
|
||||
char colors[4];
|
||||
uint8 bits[4];
|
||||
VulkanNumberType type;
|
||||
uint8 channels; //颜色通道数
|
||||
char colors[4];
|
||||
uint8 bits[4];
|
||||
VulkanBaseType type;
|
||||
};//
|
||||
|
||||
constexpr VulkanTexturePixelFormat pf_list[]=
|
||||
{
|
||||
{ PF_RGBA4, 4,{'R','G','B','A'},{ 4, 4, 4, 4},VulkanNumberType::UNORM}, //Android 部分不支持
|
||||
{ PF_BGRA4, 4,{'B','G','R','A'},{ 4, 4, 4, 4},VulkanNumberType::UNORM}, //ios不支持这个
|
||||
{UPF_RGB565, 3,{'R','G','B', 0 },{ 5, 6, 5, 0},VulkanNumberType::UNORM},
|
||||
{UPF_A1RGB5, 4,{'A','R','G','B'},{ 1, 5, 5, 5},VulkanNumberType::UNORM},
|
||||
{UPF_R8, 1,{'R', 0 , 0 , 0 },{ 8, 0, 0, 0},VulkanNumberType::UNORM},
|
||||
{UPF_RG8, 2,{'R','G', 0 , 0 },{ 8, 8, 0, 0},VulkanNumberType::UNORM},
|
||||
{UPF_RGBA8, 4,{'R','G','B','A'},{ 8, 8, 8, 8},VulkanNumberType::UNORM},
|
||||
{UPF_RGBA8S, 4,{'R','G','B','A'},{ 8, 8, 8, 8},VulkanNumberType::SNORM},
|
||||
{UPF_RGBA8U, 4,{'R','G','B','A'},{ 8, 8, 8, 8},VulkanNumberType::UINT},
|
||||
{UPF_RGBA8I, 4,{'R','G','B','A'},{ 8, 8, 8, 8},VulkanNumberType::SINT},
|
||||
{UPF_ABGR8, 4,{'A','B','G','R'},{ 8, 8, 8, 8},VulkanNumberType::UNORM},
|
||||
{UPF_A2BGR10, 4,{'A','B','G','R'},{ 2,10,10,10},VulkanNumberType::UNORM},
|
||||
{UPF_R16, 1,{'R', 0 , 0 , 0 },{16, 0, 0, 0},VulkanNumberType::UNORM},
|
||||
{UPF_R16U, 1,{'R', 0 , 0 , 0 },{16, 0, 0, 0},VulkanNumberType::UINT},
|
||||
{UPF_R16I, 1,{'R', 0 , 0 , 0 },{16, 0, 0, 0},VulkanNumberType::SINT},
|
||||
{UPF_R16F, 1,{'R', 0 , 0 , 0 },{16, 0, 0, 0},VulkanNumberType::SFLOAT},
|
||||
{UPF_RG16, 2,{'R','G', 0 , 0 },{16,16, 0, 0},VulkanNumberType::UNORM},
|
||||
{UPF_RG16U, 2,{'R','G', 0 , 0 },{16,16, 0, 0},VulkanNumberType::UINT},
|
||||
{UPF_RG16I, 2,{'R','G', 0 , 0 },{16,16, 0, 0},VulkanNumberType::SINT},
|
||||
{UPF_RG16F, 2,{'R','G', 0 , 0 },{16,16, 0, 0},VulkanNumberType::SFLOAT},
|
||||
{ PF_RGBA16UN, 4,{'R','G','B','A'},{16,16,16,16},VulkanNumberType::UNORM},
|
||||
{ PF_RGBA16SN, 4,{'R','G','B','A'},{16,16,16,16},VulkanNumberType::SNORM},
|
||||
{UPF_RGBA16U, 4,{'R','G','B','A'},{16,16,16,16},VulkanNumberType::UINT},
|
||||
{UPF_RGBA16I, 4,{'R','G','B','A'},{16,16,16,16},VulkanNumberType::SINT},
|
||||
{UPF_RGBA16F, 4,{'R','G','B','A'},{16,16,16,16},VulkanNumberType::SFLOAT},
|
||||
{UPF_R32U, 1,{'R', 0 , 0 , 0 },{32, 0, 0, 0},VulkanNumberType::UINT},
|
||||
{UPF_R32I, 1,{'R', 0 , 0 , 0 },{32, 0, 0, 0},VulkanNumberType::SINT},
|
||||
{UPF_R32F, 1,{'R', 0 , 0 , 0 },{32, 0, 0, 0},VulkanNumberType::SFLOAT},
|
||||
{UPF_RG32U, 2,{'R','G', 0 , 0 },{32,32, 0, 0},VulkanNumberType::UINT},
|
||||
{UPF_RG32I, 2,{'R','G', 0 , 0 },{32,32, 0, 0},VulkanNumberType::SINT},
|
||||
{UPF_RG32F, 2,{'R','G', 0 , 0 },{32,32, 0, 0},VulkanNumberType::SFLOAT},
|
||||
{ PF_RGB32U, 3,{'R','G','B', 0 },{32,32,32, 0},VulkanNumberType::UINT},
|
||||
{ PF_RGB32I, 3,{'R','G','B', 0 },{32,32,32, 0},VulkanNumberType::SINT},
|
||||
{ PF_RGB32F, 3,{'R','G','B', 0 },{32,32,32, 0},VulkanNumberType::SFLOAT},
|
||||
{UPF_RGBA32U, 4,{'R','G','B','A'},{32,32,32,32},VulkanNumberType::UINT},
|
||||
{UPF_RGBA32I, 4,{'R','G','B','A'},{32,32,32,32},VulkanNumberType::SINT},
|
||||
{UPF_RGBA32F, 4,{'R','G','B','A'},{32,32,32,32},VulkanNumberType::SFLOAT},
|
||||
{UPF_B10GR11UF, 3,{'B','G','R', 0 },{10,11,11, 0},VulkanNumberType::UFLOAT}
|
||||
{ PF_RGBA4, 4,{'R','G','B','A'},{ 4, 4, 4, 4},VulkanBaseType::UNORM}, //Android 部分不支持
|
||||
{ PF_BGRA4, 4,{'B','G','R','A'},{ 4, 4, 4, 4},VulkanBaseType::UNORM}, //ios不支持这个
|
||||
{UPF_RGB565, 3,{'R','G','B', 0 },{ 5, 6, 5, 0},VulkanBaseType::UNORM},
|
||||
{UPF_A1RGB5, 4,{'A','R','G','B'},{ 1, 5, 5, 5},VulkanBaseType::UNORM},
|
||||
{UPF_R8, 1,{'R', 0 , 0 , 0 },{ 8, 0, 0, 0},VulkanBaseType::UNORM},
|
||||
{UPF_RG8, 2,{'R','G', 0 , 0 },{ 8, 8, 0, 0},VulkanBaseType::UNORM},
|
||||
{UPF_RGBA8, 4,{'R','G','B','A'},{ 8, 8, 8, 8},VulkanBaseType::UNORM},
|
||||
{UPF_RGBA8S, 4,{'R','G','B','A'},{ 8, 8, 8, 8},VulkanBaseType::SNORM},
|
||||
{UPF_RGBA8U, 4,{'R','G','B','A'},{ 8, 8, 8, 8},VulkanBaseType::UINT},
|
||||
{UPF_RGBA8I, 4,{'R','G','B','A'},{ 8, 8, 8, 8},VulkanBaseType::SINT},
|
||||
{UPF_ABGR8, 4,{'A','B','G','R'},{ 8, 8, 8, 8},VulkanBaseType::UNORM},
|
||||
{UPF_A2BGR10, 4,{'A','B','G','R'},{ 2,10,10,10},VulkanBaseType::UNORM},
|
||||
{UPF_R16, 1,{'R', 0 , 0 , 0 },{16, 0, 0, 0},VulkanBaseType::UNORM},
|
||||
{UPF_R16U, 1,{'R', 0 , 0 , 0 },{16, 0, 0, 0},VulkanBaseType::UINT},
|
||||
{UPF_R16I, 1,{'R', 0 , 0 , 0 },{16, 0, 0, 0},VulkanBaseType::SINT},
|
||||
{UPF_R16F, 1,{'R', 0 , 0 , 0 },{16, 0, 0, 0},VulkanBaseType::SFLOAT},
|
||||
{UPF_RG16, 2,{'R','G', 0 , 0 },{16,16, 0, 0},VulkanBaseType::UNORM},
|
||||
{UPF_RG16U, 2,{'R','G', 0 , 0 },{16,16, 0, 0},VulkanBaseType::UINT},
|
||||
{UPF_RG16I, 2,{'R','G', 0 , 0 },{16,16, 0, 0},VulkanBaseType::SINT},
|
||||
{UPF_RG16F, 2,{'R','G', 0 , 0 },{16,16, 0, 0},VulkanBaseType::SFLOAT},
|
||||
{ PF_RGBA16UN, 4,{'R','G','B','A'},{16,16,16,16},VulkanBaseType::UNORM},
|
||||
{ PF_RGBA16SN, 4,{'R','G','B','A'},{16,16,16,16},VulkanBaseType::SNORM},
|
||||
{UPF_RGBA16U, 4,{'R','G','B','A'},{16,16,16,16},VulkanBaseType::UINT},
|
||||
{UPF_RGBA16I, 4,{'R','G','B','A'},{16,16,16,16},VulkanBaseType::SINT},
|
||||
{UPF_RGBA16F, 4,{'R','G','B','A'},{16,16,16,16},VulkanBaseType::SFLOAT},
|
||||
{UPF_R32U, 1,{'R', 0 , 0 , 0 },{32, 0, 0, 0},VulkanBaseType::UINT},
|
||||
{UPF_R32I, 1,{'R', 0 , 0 , 0 },{32, 0, 0, 0},VulkanBaseType::SINT},
|
||||
{UPF_R32F, 1,{'R', 0 , 0 , 0 },{32, 0, 0, 0},VulkanBaseType::SFLOAT},
|
||||
{UPF_RG32U, 2,{'R','G', 0 , 0 },{32,32, 0, 0},VulkanBaseType::UINT},
|
||||
{UPF_RG32I, 2,{'R','G', 0 , 0 },{32,32, 0, 0},VulkanBaseType::SINT},
|
||||
{UPF_RG32F, 2,{'R','G', 0 , 0 },{32,32, 0, 0},VulkanBaseType::SFLOAT},
|
||||
{ PF_RGB32U, 3,{'R','G','B', 0 },{32,32,32, 0},VulkanBaseType::UINT},
|
||||
{ PF_RGB32I, 3,{'R','G','B', 0 },{32,32,32, 0},VulkanBaseType::SINT},
|
||||
{ PF_RGB32F, 3,{'R','G','B', 0 },{32,32,32, 0},VulkanBaseType::SFLOAT},
|
||||
{UPF_RGBA32U, 4,{'R','G','B','A'},{32,32,32,32},VulkanBaseType::UINT},
|
||||
{UPF_RGBA32I, 4,{'R','G','B','A'},{32,32,32,32},VulkanBaseType::SINT},
|
||||
{UPF_RGBA32F, 4,{'R','G','B','A'},{32,32,32,32},VulkanBaseType::SFLOAT},
|
||||
{UPF_B10GR11UF, 3,{'B','G','R', 0 },{10,11,11, 0},VulkanBaseType::UFLOAT}
|
||||
};
|
||||
|
||||
constexpr uint VulkanTexturePixelFormatCount=sizeof(pf_list)/sizeof(VulkanTexturePixelFormat);
|
||||
|
@@ -22,17 +22,17 @@ namespace hgl
|
||||
tile_max_count=tile_rows*tile_cols;
|
||||
tile_count=0;
|
||||
|
||||
to_pool.PreMalloc(tile_max_count);
|
||||
to_pool.PreAlloc(tile_max_count);
|
||||
{
|
||||
int col=0,row=0;
|
||||
TileObject **to=to_pool.GetInactiveData();
|
||||
TileObject *to=new TileObject;
|
||||
|
||||
for(uint i=0;i<tile_max_count;i++)
|
||||
{
|
||||
(*to)->col =col;
|
||||
(*to)->row =row;
|
||||
to->col =col;
|
||||
to->row =row;
|
||||
|
||||
(*to)->uv_pixel.Set(col*tile_width,
|
||||
to->uv_pixel.Set(col*tile_width,
|
||||
row*tile_height,
|
||||
0,
|
||||
0);
|
||||
@@ -45,6 +45,8 @@ namespace hgl
|
||||
++row;
|
||||
col=0;
|
||||
}
|
||||
|
||||
to_pool.AppendToIdle(to);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,7 +65,7 @@ namespace hgl
|
||||
|
||||
void TileData::BeginCommit()
|
||||
{
|
||||
commit_list.ClearData();
|
||||
commit_list.Clear();
|
||||
commit_ptr=(uint8 *)tile_buffer->Map();
|
||||
}
|
||||
|
||||
@@ -82,7 +84,7 @@ namespace hgl
|
||||
|
||||
const int result=commit_list.GetCount();
|
||||
|
||||
commit_list.ClearData();
|
||||
commit_list.Clear();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@@ -1,18 +1,19 @@
|
||||
#include<hgl/graph/VertexAttribData.h>
|
||||
#include<hgl/graph/VKVertexInputFormat.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
VAD *CreateVertexAttribData(const uint32_t vertex_count,const VkFormat fmt,const int vec_size,const uint stride)
|
||||
VAD *CreateVertexAttribData(const uint32_t vertex_count,const VertexInputFormat *vif)
|
||||
{
|
||||
if(vertex_count<=0
|
||||
||vec_size<1||vec_size>4
|
||||
||stride<1||stride>8*4
|
||||
||!CheckVulkanFormat(fmt))
|
||||
||vif->vec_size<1||vif->vec_size>4
|
||||
||vif->stride<1||vif->stride>8*4
|
||||
||!CheckVulkanFormat(vif->format))
|
||||
return(nullptr);
|
||||
|
||||
return(new VertexAttribData(vertex_count,vec_size,stride,fmt));
|
||||
return(new VertexAttribData(vertex_count,vif->format,vif->stride*vertex_count));
|
||||
}
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
|
350
src/SceneGraph/Vulkan/Debug/VKPhysicalDeviceCapsOutput.cpp
Normal file
350
src/SceneGraph/Vulkan/Debug/VKPhysicalDeviceCapsOutput.cpp
Normal file
@@ -0,0 +1,350 @@
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/graph/VKUUID.h>
|
||||
#include<hgl/graph/VKPhysicalDevice.h>
|
||||
|
||||
#include<iostream>
|
||||
#include<iomanip>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
namespace
|
||||
{
|
||||
void DebugOut(const VkPhysicalDeviceFeatures &features)
|
||||
{
|
||||
std::cout<<"Vulkan 1.0 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(robustBufferAccess)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(fullDrawIndexUint32)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(imageCubeArray)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(independentBlend)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(geometryShader)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(tessellationShader)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(sampleRateShading)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(dualSrcBlend)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(logicOp)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(multiDrawIndirect)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(drawIndirectFirstInstance)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(depthClamp)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(depthBiasClamp)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(fillModeNonSolid)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(depthBounds)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(wideLines)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(largePoints)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(alphaToOne)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(multiViewport)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(samplerAnisotropy)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(textureCompressionETC2)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(textureCompressionASTC_LDR)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(textureCompressionBC)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(occlusionQueryPrecise)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(pipelineStatisticsQuery)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(vertexPipelineStoresAndAtomics)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(fragmentStoresAndAtomics)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(shaderTessellationAndGeometryPointSize)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(shaderImageGatherExtended)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(shaderStorageImageExtendedFormats)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(shaderStorageImageMultisample)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(shaderStorageImageReadWithoutFormat)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(shaderStorageImageWriteWithoutFormat)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(shaderUniformBufferArrayDynamicIndexing)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(shaderSampledImageArrayDynamicIndexing)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(shaderStorageBufferArrayDynamicIndexing)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(shaderStorageImageArrayDynamicIndexing)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(shaderClipDistance)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(shaderCullDistance)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(shaderFloat64)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(shaderInt64)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(shaderInt16)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(shaderResourceResidency)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(shaderResourceMinLod)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(sparseBinding)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(sparseResidencyBuffer)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(sparseResidencyImage2D)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(sparseResidencyImage3D)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(sparseResidency2Samples)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(sparseResidency4Samples)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(sparseResidency8Samples)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(sparseResidency16Samples)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(sparseResidencyAliased)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(variableMultisampleRate)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(inheritedQueries)
|
||||
#undef OUTPUT_PHYSICAL_DEVICE_FEATURE
|
||||
}
|
||||
|
||||
void DebugOut(const VkPhysicalDeviceVulkan11Features &features)
|
||||
{
|
||||
std::cout<<"Vulkan 1.1 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(storageBuffer16BitAccess)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(uniformAndStorageBuffer16BitAccess)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(storagePushConstant16)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(storageInputOutput16)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(multiview)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(multiviewGeometryShader)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(multiviewTessellationShader)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(variablePointersStorageBuffer)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(variablePointers)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(protectedMemory)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(samplerYcbcrConversion)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(shaderDrawParameters)
|
||||
#undef OUTPUT_PHYSICAL_DEVICE_FEATURE
|
||||
}
|
||||
|
||||
void DebugOut(const VkPhysicalDeviceVulkan12Features &features)
|
||||
{
|
||||
std::cout<<"Vulkan 1.2 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(samplerMirrorClampToEdge)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(drawIndirectCount)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(storageBuffer8BitAccess)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(uniformAndStorageBuffer8BitAccess)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(storagePushConstant8)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(shaderBufferInt64Atomics)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(shaderSharedInt64Atomics)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(shaderFloat16)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(shaderInt8)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(descriptorIndexing)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(shaderInputAttachmentArrayDynamicIndexing)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(shaderUniformTexelBufferArrayDynamicIndexing)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(shaderStorageTexelBufferArrayDynamicIndexing)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(shaderUniformBufferArrayNonUniformIndexing)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(shaderSampledImageArrayNonUniformIndexing)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(shaderStorageBufferArrayNonUniformIndexing)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(shaderStorageImageArrayNonUniformIndexing)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(shaderInputAttachmentArrayNonUniformIndexing)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(shaderUniformTexelBufferArrayNonUniformIndexing)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(shaderStorageTexelBufferArrayNonUniformIndexing)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(descriptorBindingUniformBufferUpdateAfterBind)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(descriptorBindingSampledImageUpdateAfterBind)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(descriptorBindingStorageImageUpdateAfterBind)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(descriptorBindingStorageBufferUpdateAfterBind)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(descriptorBindingUniformTexelBufferUpdateAfterBind)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(descriptorBindingStorageTexelBufferUpdateAfterBind)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(descriptorBindingUpdateUnusedWhilePending)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(descriptorBindingPartiallyBound)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(descriptorBindingVariableDescriptorCount)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(runtimeDescriptorArray)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(samplerFilterMinmax)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(scalarBlockLayout)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(imagelessFramebuffer)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(uniformBufferStandardLayout)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(shaderSubgroupExtendedTypes)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(separateDepthStencilLayouts)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(hostQueryReset)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(timelineSemaphore)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(bufferDeviceAddress)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(bufferDeviceAddressCaptureReplay)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(bufferDeviceAddressMultiDevice)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(vulkanMemoryModel)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(vulkanMemoryModelDeviceScope)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(vulkanMemoryModelAvailabilityVisibilityChains)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(shaderOutputViewportIndex)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(shaderOutputLayer)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(subgroupBroadcastDynamicId)
|
||||
#undef OUTPUT_PHYSICAL_DEVICE_FEATURE
|
||||
}
|
||||
|
||||
void DebugOut(const VkPhysicalDeviceVulkan13Features &features)
|
||||
{
|
||||
std::cout<<"Vulkan 1.3 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(robustImageAccess)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(inlineUniformBlock)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(descriptorBindingInlineUniformBlockUpdateAfterBind)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(pipelineCreationCacheControl)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(privateData)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(shaderDemoteToHelperInvocation)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(shaderTerminateInvocation)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(subgroupSizeControl)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(computeFullSubgroups)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(synchronization2)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(textureCompressionASTC_HDR)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(shaderZeroInitializeWorkgroupMemory)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(dynamicRendering)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(shaderIntegerDotProduct)
|
||||
OUTPUT_PHYSICAL_DEVICE_FEATURE(maintenance4)
|
||||
#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;
|
||||
}
|
||||
|
||||
void DebugOut(const VkPhysicalDeviceLimits &limits)
|
||||
{
|
||||
#define OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(name) std::cout<<std::setw(60)<<std::right<<#name<<": "<<limits.name<<std::endl;
|
||||
#define OUT_PHYSICAL_DEVICE_LIMIT_VECTOR2(name) std::cout<<std::setw(60)<<std::right<<#name<<": "<<limits.name[0]<<", "<<limits.name[1]<<std::endl;
|
||||
#define OUT_PHYSICAL_DEVICE_LIMIT_VECTOR3(name) std::cout<<std::setw(60)<<std::right<<#name<<": "<<limits.name[0]<<", "<<limits.name[1]<<", "<<limits.name[2]<<std::endl;
|
||||
#define OUT_PHYSICAL_DEVICE_LIMIT_BOOLEAN(name) std::cout<<std::setw(60)<<std::right<<#name<<": "<<(limits.name?"true":"false")<<std::endl;
|
||||
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxImageDimension1D)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxImageDimension2D)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxImageDimension3D)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxImageDimensionCube)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxImageArrayLayers)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxTexelBufferElements)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxUniformBufferRange)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxStorageBufferRange)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxPushConstantsSize)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxMemoryAllocationCount)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxSamplerAllocationCount)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(bufferImageGranularity)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(sparseAddressSpaceSize)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxBoundDescriptorSets)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxPerStageDescriptorSamplers)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxPerStageDescriptorUniformBuffers)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxPerStageDescriptorStorageBuffers)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxPerStageDescriptorSampledImages)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxPerStageDescriptorStorageImages)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxPerStageDescriptorInputAttachments)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxPerStageResources)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxDescriptorSetSamplers)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxDescriptorSetUniformBuffers)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxDescriptorSetUniformBuffersDynamic)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxDescriptorSetStorageBuffers)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxDescriptorSetStorageBuffersDynamic)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxDescriptorSetSampledImages)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxDescriptorSetStorageImages)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxDescriptorSetInputAttachments)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxVertexInputAttributes)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxVertexInputBindings)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxVertexInputAttributeOffset)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxVertexInputBindingStride)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxVertexOutputComponents)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxTessellationGenerationLevel)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxTessellationPatchSize)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxTessellationControlPerVertexInputComponents)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxTessellationControlPerVertexOutputComponents)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxTessellationControlPerPatchOutputComponents)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxTessellationControlTotalOutputComponents)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxTessellationEvaluationInputComponents)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxTessellationEvaluationOutputComponents)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxGeometryShaderInvocations)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxGeometryInputComponents)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxGeometryOutputComponents)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxGeometryOutputVertices)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxGeometryTotalOutputComponents)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxFragmentInputComponents)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxFragmentOutputAttachments)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxFragmentDualSrcAttachments)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxFragmentCombinedOutputResources)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxComputeSharedMemorySize)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_VECTOR3(maxComputeWorkGroupCount)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxComputeWorkGroupInvocations)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_VECTOR3(maxComputeWorkGroupSize)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(subPixelPrecisionBits)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(subTexelPrecisionBits)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(mipmapPrecisionBits)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxDrawIndexedIndexValue)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxDrawIndirectCount)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxSamplerLodBias)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxSamplerAnisotropy)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxViewports)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_VECTOR2(maxViewportDimensions)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_VECTOR2(viewportBoundsRange)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(viewportSubPixelBits)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(minMemoryMapAlignment)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(minTexelBufferOffsetAlignment)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(minUniformBufferOffsetAlignment)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(minStorageBufferOffsetAlignment)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(minTexelOffset)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxTexelOffset)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(minTexelGatherOffset)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxTexelGatherOffset)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(minInterpolationOffset)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxInterpolationOffset)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(subPixelInterpolationOffsetBits)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxFramebufferWidth)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxFramebufferHeight)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxFramebufferLayers)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(framebufferColorSampleCounts)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(framebufferDepthSampleCounts)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(framebufferStencilSampleCounts)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(framebufferNoAttachmentsSampleCounts)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxColorAttachments)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(sampledImageColorSampleCounts)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(sampledImageIntegerSampleCounts)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(sampledImageDepthSampleCounts)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(sampledImageStencilSampleCounts)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(storageImageSampleCounts)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxSampleMaskWords)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_BOOLEAN(timestampComputeAndGraphics)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(timestampPeriod)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxClipDistances)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxCullDistances)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(maxCombinedClipAndCullDistances)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(discreteQueuePriorities)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_VECTOR2(pointSizeRange)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_VECTOR2(lineWidthRange)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(pointSizeGranularity)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(lineWidthGranularity)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_BOOLEAN(strictLines)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_BOOLEAN(standardSampleLocations)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(optimalBufferCopyOffsetAlignment)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(optimalBufferCopyRowPitchAlignment)
|
||||
OUT_PHYSICAL_DEVICE_LIMIT_INTEGER(nonCoherentAtomSize)
|
||||
|
||||
#undef OUT_PHYSICAL_DEVICE_LIMIT_BOOLEAN
|
||||
#undef OUT_PHYSICAL_DEVICE_LIMIT_VECTOR3
|
||||
#undef OUT_PHYSICAL_DEVICE_LIMIT_VECTOR2
|
||||
#undef OUT_PHYSICAL_DEVICE_LIMIT_INTEGER
|
||||
}
|
||||
|
||||
#ifndef VK_PHYSICAL_DEVICE_TYPE_BEGIN_RANGE
|
||||
#define VK_PHYSICAL_DEVICE_TYPE_BEGIN_RANGE VK_PHYSICAL_DEVICE_TYPE_OTHER
|
||||
#endif//VK_PHYSICAL_DEVICE_TYPE_BEGIN_RANGE
|
||||
|
||||
#ifndef VK_PHYSICAL_DEVICE_TYPE_END_RANGE
|
||||
#define VK_PHYSICAL_DEVICE_TYPE_END_RANGE VK_PHYSICAL_DEVICE_TYPE_CPU
|
||||
#endif//VK_PHYSICAL_DEVICE_TYPE_END_RANGE
|
||||
|
||||
#ifndef VK_PHYSICAL_DEVICE_TYPE_RANGE_SIZE
|
||||
constexpr size_t VK_PHYSICAL_DEVICE_TYPE_RANGE_SIZE=VK_PHYSICAL_DEVICE_TYPE_END_RANGE-VK_PHYSICAL_DEVICE_TYPE_BEGIN_RANGE+1;
|
||||
#endif//VK_PHYSICAL_DEVICE_TYPE_RANGE_SIZE
|
||||
|
||||
void DebugOut(const VkPhysicalDeviceProperties &pdp)
|
||||
{
|
||||
constexpr char DeviceTypeString[VK_PHYSICAL_DEVICE_TYPE_RANGE_SIZE][16]=
|
||||
{
|
||||
"Other",
|
||||
"Integrated GPU",
|
||||
"Discrete GPU",
|
||||
"Virtual GPU",
|
||||
"CPU"
|
||||
};
|
||||
|
||||
std::cout<<" apiVersion: ";DebugOutVersion(pdp.apiVersion);
|
||||
std::cout<<" driverVersion: ";DebugOutVersion(pdp.driverVersion);
|
||||
std::cout<<" vendorID: 0x"<<HexToString<char>(pdp.vendorID).c_str()<<std::endl;
|
||||
std::cout<<" deviceID: 0x"<<HexToString<char>(pdp.deviceID).c_str()<<std::endl;
|
||||
std::cout<<" deviceType: "<<DeviceTypeString[pdp.deviceType]<<std::endl;
|
||||
std::cout<<" deviceName: "<<pdp.deviceName<<std::endl;
|
||||
|
||||
if(memcmp(pdp.pipelineCacheUUID,"rdoc",4)==0)
|
||||
{
|
||||
std::cout<<"pipelineCahceUUID: "<<(char *)pdp.pipelineCacheUUID<<std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
AnsiString uuid=VkUUID2String<char>(pdp.pipelineCacheUUID);
|
||||
|
||||
std::cout<<"pipelineCahceUUID: "<<uuid.c_str()<<std::endl;
|
||||
}
|
||||
|
||||
DebugOut(pdp.limits);
|
||||
}
|
||||
}//namespace
|
||||
|
||||
void OutputPhysicalDeviceCaps(const GPUPhysicalDevice *pd)
|
||||
{
|
||||
DebugOut(pd->GetProperties());
|
||||
DebugOut(pd->GetFeatures10());
|
||||
DebugOut(pd->GetFeatures11());
|
||||
DebugOut(pd->GetFeatures12());
|
||||
DebugOut(pd->GetFeatures13());
|
||||
}
|
||||
VK_NAMESPACE_END
|
52
src/SceneGraph/Vulkan/DebugOutProperties.h
Normal file
52
src/SceneGraph/Vulkan/DebugOutProperties.h
Normal file
@@ -0,0 +1,52 @@
|
||||
#include<hgl/type/List.h>
|
||||
#include<hgl/graph/VKNamespace.h>
|
||||
#include<iostream>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
inline void debug_out_vk_version(const uint32_t version)
|
||||
{
|
||||
std::cout<<VK_VERSION_MAJOR(version)<<"."
|
||||
<<VK_VERSION_MINOR(version)<<"."
|
||||
<<VK_VERSION_PATCH(version);
|
||||
}
|
||||
|
||||
inline void debug_out(const char *front,const hgl::List<VkLayerProperties> &layer_properties)
|
||||
{
|
||||
const int property_count=layer_properties.GetCount();
|
||||
|
||||
if(property_count<=0)return;
|
||||
|
||||
const VkLayerProperties *lp=layer_properties.GetData();
|
||||
|
||||
for(int i=0;i<property_count;i++)
|
||||
{
|
||||
std::cout<<front<<" Layer Propertyes ["<<i<<"] : "<<lp->layerName<<" [spec: ";
|
||||
debug_out_vk_version(lp->specVersion);
|
||||
|
||||
std::cout<<", impl: ";
|
||||
debug_out_vk_version(lp->implementationVersion);
|
||||
|
||||
std::cout<<"] desc: "<<lp->description<<std::endl;
|
||||
++lp;
|
||||
}
|
||||
}
|
||||
|
||||
inline void debug_out(const char *front,const hgl::List<VkExtensionProperties> &extension_properties)
|
||||
{
|
||||
const int extension_count=extension_properties.GetCount();
|
||||
|
||||
if(extension_count<=0)return;
|
||||
|
||||
VkExtensionProperties *ep=extension_properties.GetData();
|
||||
for(int i=0;i<extension_count;i++)
|
||||
{
|
||||
std::cout<<front<<" Extension Propertyes ["<<i<<"] : "<<ep->extensionName<<" ver: ";
|
||||
|
||||
debug_out_vk_version(ep->specVersion);
|
||||
|
||||
std::cout<<std::endl;
|
||||
++ep;
|
||||
}
|
||||
}
|
||||
VK_NAMESPACE_END
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user