#ifndef HGL_GRAPH_VULKAN_INCLUDE #define HGL_GRAPH_VULKAN_INCLUDE #include #include #include #include #include #include #include #include #include #include VK_NAMESPACE_BEGIN #ifndef VK_DESCRIPTOR_TYPE_BEGIN_RANGE constexpr size_t VK_DESCRIPTOR_TYPE_BEGIN_RANGE=VK_DESCRIPTOR_TYPE_SAMPLER; #endif//VK_DESCRIPTOR_TYPE_BEGIN_RANGE #ifndef VK_DESCRIPTOR_TYPE_END_RANGE constexpr size_t VK_DESCRIPTOR_TYPE_END_RANGE=VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; #endif//VK_DESCRIPTOR_TYPE_END_RANGE #ifndef VK_DESCRIPTOR_TYPE_RANGE_SIZE constexpr size_t VK_DESCRIPTOR_TYPE_RANGE_SIZE=VK_DESCRIPTOR_TYPE_END_RANGE-VK_DESCRIPTOR_TYPE_BEGIN_RANGE+1; #endif//VK_DESCRIPTOR_TYPE_RANGE_SIZE using CharPointerList=hgl::List; using BindingMapping=Map; class VulkanInstance; class GPUPhysicalDevice; class GPUDevice; struct GPUDeviceAttribute; class GPUQueue; class ImageView; class Framebuffer; struct Swapchain; class RenderTarget; class SwapchainRenderTarget; class Texture; class Texture1D; class Texture1DArray; class Texture2D; class Texture2DArray; class Texture3D; class TextureCube; class TextureCubeArray; class Sampler; class GPUMemory; class GPUBuffer; struct GPUBufferData; class VertexAttribBuffer; using VBO=VertexAttribBuffer; class IndexBuffer; class GPUCmdBuffer; class RenderCmdBuffer; class TextureCmdBuffer; class RenderPass; class DeviceRenderPassManage; class GPUFence; class GPUSemaphore; enum class DescriptorSetsType { //设计使其对应shader中的set Global=0, ///<全局参数(如太阳光等) Material, ///<材质中永远不变的参数 // Texture, ///<材质中的纹理参数 Value, ///<材质中的变量参数 Renderable, ///<渲染实例参数(如Local2World matrix) ENUM_CLASS_RANGE(Global,Renderable) };// const DescriptorSetsType CheckDescriptorSetsType(const char *str); constexpr char *DescriptSetsTypeName[]= { "Global","Material","Value","Renderable" }; inline const char *GetDescriptorSetsTypeName(const enum class DescriptorSetsType &type) { ENUM_CLASS_RANGE_ERROR_RETURN_NULLPTR(type); return DescriptSetsTypeName[(size_t)type]; } struct PipelineLayoutData; class DescriptorSets; struct ShaderStage; class ShaderResource; class ShaderModule; class VertexShaderModule; class ShaderModuleMap; class MaterialDescriptorSets; class Material; class MaterialParameters; class MaterialInstance; struct PipelineData; enum class InlinePipeline; class Pipeline; struct VAConfig { VkFormat format=PF_UNDEFINED; bool instance=false; public: CompOperatorMemcmp(const VAConfig &); }; using VABConfigInfo=Map; class VertexAttributeBinding; using VAB=VertexAttributeBinding; class Renderable; class RenderableInstance; class RenderResource; enum class SharingMode { Exclusive = 0, Concurrent };// enum class Filter { Nearest=0, Linear, };// enum ImageTiling { Optimal=0, Linear };// inline const uint32_t GetMipLevel(const VkExtent2D &ext) { return hgl::GetMipLevel(ext.width,ext.height); } inline const uint32_t GetMipLevel(const VkExtent3D &ext) { return hgl::GetMipLevel(ext.width,ext.height,ext.depth); } /** * 索引类型,等同于VkIndexType */ enum IndexType { U16=0, U32 }; 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: * 256 bytes: nvidia,arm 128 bytes: amd,intel,powervr,adreno */ struct PushConstant { Matrix4f local_to_world; Matrix4f normal; }; constexpr uint32_t MAX_PUSH_CONSTANT_BYTES=sizeof(PushConstant); inline void copy(VkExtent3D &e3d,const VkExtent2D &e2d,const uint32 depth=1) { e3d.width =e2d.width; e3d.height =e2d.height; e3d.depth =depth; } inline void debug_out_vk_version(const uint32_t version) { std::cout< inline hgl::String VkUUID2String(const uint8_t *pipelineCacheUUID) { T *hstr=new T[VK_UUID_SIZE*2+1]; DataToLowerHexStr(hstr,pipelineCacheUUID,VK_UUID_SIZE); return hgl::String::newOf(hstr,VK_UUID_SIZE*2); } inline void debug_out(const char *front,const hgl::List &layer_properties) { const int property_count=layer_properties.GetCount(); if(property_count<=0)return; const VkLayerProperties *lp=layer_properties.GetData(); for(int i=0;ilayerName<<" [spec: "; debug_out_vk_version(lp->specVersion); std::cout<<", impl: "; debug_out_vk_version(lp->implementationVersion); std::cout<<"] desc: "<description< &extension_properties) { const int extension_count=extension_properties.GetCount(); if(extension_count<=0)return; VkExtensionProperties *ep=extension_properties.GetData(); for(int i=0;iextensionName<<" ver: "; debug_out_vk_version(ep->specVersion); std::cout<