use standalone DescriptorSetType,ShaderDescriptor,ShaderStage

This commit is contained in:
2023-03-02 20:19:25 +08:00
parent f2d5209681
commit b4dccf7814
26 changed files with 139 additions and 217 deletions

View File

@@ -33,7 +33,7 @@ class VulkanInstance;
class GPUPhysicalDevice;
class GPUDevice;
struct GPUDeviceAttribute;
class Queue;
class DeviceQueue;
class ImageView;
class Framebuffer;
struct Swapchain;
@@ -70,33 +70,6 @@ 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;
@@ -194,32 +167,6 @@ enum IndexType
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:
*

View File

@@ -147,7 +147,7 @@ public:
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);
}

View File

@@ -15,6 +15,7 @@
#include<hgl/graph/VertexAttribData.h>
#include<hgl/graph/VKShaderModuleMap.h>
#include<hgl/graph/VKArrayBuffer.h>
#include<hgl/graph/VKDescriptorSetType.h>
namespace hgl
{
@@ -43,7 +44,7 @@ class GPUDevice
{
GPUDeviceAttribute *attr;
Queue *texture_queue;
DeviceQueue *texture_queue;
TextureCmdBuffer *texture_cmd_buf;
private:
@@ -243,7 +244,7 @@ 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相关

View File

@@ -5,6 +5,7 @@
#include<hgl/type/Map.h>
#include<hgl/type/String.h>
#include<hgl/graph/VKShaderModuleMap.h>
#include<hgl/graph/VKDescriptorSetType.h>
VK_NAMESPACE_BEGIN
using ShaderStageCreateInfoList=List<VkPipelineShaderStageCreateInfo>;

View File

@@ -2,22 +2,9 @@
#define HGL_GRAPH_VULKAN_MATERIAL_DESCRIPTOR_SETS_INCLUDE
#include<hgl/graph/VK.h>
#include<hgl/graph/VKShaderDescriptor.h>
VK_NAMESPACE_BEGIN
struct ShaderDescriptor
{
char name[128];
VkDescriptorType desc_type;
DescriptorSetType set_type;
uint8 set;
uint8 binding;
uint32 stage_flag;
};
using ShaderDescriptorList=List<ShaderDescriptor *>;
class MaterialDescriptorSets
{
UTF8String mtl_name;

View File

@@ -4,6 +4,7 @@
#include<hgl/graph/VK.h>
#include<hgl/type/String.h>
#include<hgl/graph/VKDescriptorSet.h>
#include<hgl/graph/VKDescriptorSetType.h>
VK_NAMESPACE_BEGIN
class MaterialParameters
{

View File

@@ -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

View File

@@ -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();}
@@ -75,7 +75,7 @@ class SwapchainRenderTarget:public RenderTarget
public:
SwapchainRenderTarget(VkDevice dev,Swapchain *sc,Queue *q,Semaphore *rcs,Semaphore *pcs,RenderPass *rp);
SwapchainRenderTarget(VkDevice dev,Swapchain *sc,DeviceQueue *q,Semaphore *rcs,Semaphore *pcs,RenderPass *rp);
~SwapchainRenderTarget();
Framebuffer * GetFramebuffer ()override {return swapchain->render_frame[current_frame];}
@@ -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:

View File

@@ -1,7 +1,9 @@
#ifndef HGL_GRAPH_VULKAN_SHADER_MODULE_INCLUDE
#define HGL_GRAPH_VULKAN_SHADER_MODULE_INCLUDE
#include<hgl/graph/VK.h>
#include<hgl/graph/VKShaderResource.h>
#include<hgl/graph/VKVertexInputLayout.h>
#include<hgl/type/SortedSets.h>
VK_NAMESPACE_BEGIN
@@ -57,7 +59,7 @@ class VertexShaderModule:public ShaderModule
{
uint32_t attr_count;
VertexAttribType *type_list;
const AnsiString **name_list;
const char **name_list;
ShaderStage **ssi_list;
private:

View File

@@ -4,23 +4,11 @@
#include<hgl/type/String.h>
#include<hgl/type/List.h>
#include<hgl/type/StringList.h>
#include<hgl/graph/VK.h>
#include<hgl/io/ConstBufferReader.h>
#include<hgl/graph/VKShaderStage.h>
#include<hgl/graph/VKStruct.h>
VK_NAMESPACE_BEGIN
struct ShaderStage
{
AnsiString name;
uint8 location;
VertexAttribType type; ///<成份数量(如vec4中的4)
bool dynamic; ///<是否动态数据
};//struct ShaderStage
using ShaderStageList =ObjectList<ShaderStage>;
class ShaderResource
{
VkShaderStageFlagBits stage_flag;
@@ -37,7 +25,7 @@ public:
virtual ~ShaderResource()=default;
const VkShaderStageFlagBits GetStage ()const {return stage_flag;}
const os_char * GetStageName ()const;
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;}
@@ -52,8 +40,6 @@ public:
const int GetStageInputBinding(const AnsiString &)const;
};//class ShaderResource
ShaderResource *LoadShaderResource(io::ConstBufferReader &);
struct ShaderModuleCreateInfo:public vkstruct_flag<VkShaderModuleCreateInfo,VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO>
{
public: