不再使用RefDeviceAttribute
This commit is contained in:
parent
89369484da
commit
ca2a20aabd
@ -55,6 +55,11 @@ namespace
|
|||||||
}
|
}
|
||||||
}//namespace
|
}//namespace
|
||||||
|
|
||||||
|
Device::~Device()
|
||||||
|
{
|
||||||
|
delete attr;
|
||||||
|
}
|
||||||
|
|
||||||
VertexBuffer *Device::CreateBuffer(VkBufferUsageFlags buf_usage,VkFormat format,uint32_t count,VkSharingMode sharing_mode)
|
VertexBuffer *Device::CreateBuffer(VkBufferUsageFlags buf_usage,VkFormat format,uint32_t count,VkSharingMode sharing_mode)
|
||||||
{
|
{
|
||||||
const uint32_t stride=GetStrideByFormat(format);
|
const uint32_t stride=GetStrideByFormat(format);
|
||||||
@ -69,42 +74,42 @@ VertexBuffer *Device::CreateBuffer(VkBufferUsageFlags buf_usage,VkFormat format,
|
|||||||
|
|
||||||
VulkanBuffer vb;
|
VulkanBuffer vb;
|
||||||
|
|
||||||
if(!CreateVulkanBuffer(vb,rsa,buf_usage,size,sharing_mode))
|
if(!CreateVulkanBuffer(vb,attr,buf_usage,size,sharing_mode))
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
return(new VertexBuffer(rsa->device,vb,format,stride,count));
|
return(new VertexBuffer(attr->device,vb,format,stride,count));
|
||||||
}
|
}
|
||||||
|
|
||||||
Buffer *Device::CreateBuffer(VkBufferUsageFlags buf_usage,VkDeviceSize size,VkSharingMode sharing_mode)
|
Buffer *Device::CreateBuffer(VkBufferUsageFlags buf_usage,VkDeviceSize size,VkSharingMode sharing_mode)
|
||||||
{
|
{
|
||||||
VulkanBuffer vb;
|
VulkanBuffer vb;
|
||||||
|
|
||||||
if(!CreateVulkanBuffer(vb,rsa,buf_usage,size,sharing_mode))
|
if(!CreateVulkanBuffer(vb,attr,buf_usage,size,sharing_mode))
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
return(new Buffer(rsa->device,vb));
|
return(new Buffer(attr->device,vb));
|
||||||
}
|
}
|
||||||
|
|
||||||
CommandBuffer *Device::CreateCommandBuffer()
|
CommandBuffer *Device::CreateCommandBuffer()
|
||||||
{
|
{
|
||||||
if(!rsa->cmd_pool)
|
if(!attr->cmd_pool)
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
VkCommandBufferAllocateInfo cmd={};
|
VkCommandBufferAllocateInfo cmd={};
|
||||||
cmd.sType=VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
|
cmd.sType=VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
|
||||||
cmd.pNext=nullptr;
|
cmd.pNext=nullptr;
|
||||||
cmd.commandPool=rsa->cmd_pool;
|
cmd.commandPool=attr->cmd_pool;
|
||||||
cmd.level=VK_COMMAND_BUFFER_LEVEL_PRIMARY;
|
cmd.level=VK_COMMAND_BUFFER_LEVEL_PRIMARY;
|
||||||
cmd.commandBufferCount=1;
|
cmd.commandBufferCount=1;
|
||||||
|
|
||||||
VkCommandBuffer cmd_buf;
|
VkCommandBuffer cmd_buf;
|
||||||
|
|
||||||
VkResult res=vkAllocateCommandBuffers(rsa->device,&cmd,&cmd_buf);
|
VkResult res=vkAllocateCommandBuffers(attr->device,&cmd,&cmd_buf);
|
||||||
|
|
||||||
if(res!=VK_SUCCESS)
|
if(res!=VK_SUCCESS)
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
return(new CommandBuffer(rsa->device,rsa->cmd_pool,cmd_buf));
|
return(new CommandBuffer(attr->device,attr->cmd_pool,cmd_buf));
|
||||||
}
|
}
|
||||||
|
|
||||||
//DescriptorSet *Device::CreateDescSet(int count)
|
//DescriptorSet *Device::CreateDescSet(int count)
|
||||||
@ -125,7 +130,7 @@ CommandBuffer *Device::CreateCommandBuffer()
|
|||||||
RenderPass *Device::CreateRenderPass()
|
RenderPass *Device::CreateRenderPass()
|
||||||
{
|
{
|
||||||
VkAttachmentDescription attachments[2];
|
VkAttachmentDescription attachments[2];
|
||||||
attachments[0].format=rsa->format;
|
attachments[0].format=attr->format;
|
||||||
attachments[0].samples=VK_SAMPLE_COUNT_1_BIT;
|
attachments[0].samples=VK_SAMPLE_COUNT_1_BIT;
|
||||||
attachments[0].loadOp=VK_ATTACHMENT_LOAD_OP_CLEAR;
|
attachments[0].loadOp=VK_ATTACHMENT_LOAD_OP_CLEAR;
|
||||||
attachments[0].storeOp=VK_ATTACHMENT_STORE_OP_STORE;
|
attachments[0].storeOp=VK_ATTACHMENT_STORE_OP_STORE;
|
||||||
@ -135,7 +140,7 @@ RenderPass *Device::CreateRenderPass()
|
|||||||
attachments[0].finalLayout=VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
|
attachments[0].finalLayout=VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
|
||||||
attachments[0].flags=0;
|
attachments[0].flags=0;
|
||||||
|
|
||||||
attachments[1].format=rsa->depth.format;
|
attachments[1].format=attr->depth.format;
|
||||||
attachments[1].samples=VK_SAMPLE_COUNT_1_BIT;
|
attachments[1].samples=VK_SAMPLE_COUNT_1_BIT;
|
||||||
attachments[1].loadOp=VK_ATTACHMENT_LOAD_OP_CLEAR;
|
attachments[1].loadOp=VK_ATTACHMENT_LOAD_OP_CLEAR;
|
||||||
attachments[1].storeOp=VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
attachments[1].storeOp=VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
||||||
@ -172,9 +177,9 @@ RenderPass *Device::CreateRenderPass()
|
|||||||
|
|
||||||
VkRenderPass render_pass;
|
VkRenderPass render_pass;
|
||||||
|
|
||||||
if(vkCreateRenderPass(rsa->device,&rp_info,nullptr,&render_pass)!=VK_SUCCESS)
|
if(vkCreateRenderPass(attr->device,&rp_info,nullptr,&render_pass)!=VK_SUCCESS)
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
return(new RenderPass(rsa->device,render_pass));
|
return(new RenderPass(attr->device,render_pass));
|
||||||
}
|
}
|
||||||
VK_NAMESPACE_END
|
VK_NAMESPACE_END
|
||||||
|
@ -13,29 +13,27 @@ class VertexBuffer;
|
|||||||
class CommandBuffer;
|
class CommandBuffer;
|
||||||
class RenderPass;
|
class RenderPass;
|
||||||
|
|
||||||
using RefDeviceAttribute=SharedPtr<DeviceAttribute>;
|
|
||||||
|
|
||||||
class Device
|
class Device
|
||||||
{
|
{
|
||||||
RefDeviceAttribute rsa;
|
DeviceAttribute *attr;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
friend Device *CreateRenderDevice(VkInstance,const PhysicalDevice *,Window *);
|
friend Device *CreateRenderDevice(VkInstance,const PhysicalDevice *,Window *);
|
||||||
|
|
||||||
Device(RefDeviceAttribute &ref_rsa)
|
Device(DeviceAttribute *da)
|
||||||
{
|
{
|
||||||
rsa=ref_rsa;
|
attr=da;
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
virtual ~Device()=default;
|
virtual ~Device();
|
||||||
|
|
||||||
VkSurfaceKHR GetSurface () {return rsa->surface;}
|
VkSurfaceKHR GetSurface () {return attr->surface;}
|
||||||
VkDevice GetDevice () {return rsa->device;}
|
VkDevice GetDevice () {return attr->device;}
|
||||||
const PhysicalDevice *GetPhysicalDevice ()const {return rsa->physical_device;}
|
const PhysicalDevice *GetPhysicalDevice ()const {return attr->physical_device;}
|
||||||
const VkExtent2D & GetExtent ()const {return rsa->swapchain_extent;}
|
const VkExtent2D & GetExtent ()const {return attr->swapchain_extent;}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
#include"VKDevice.h"
|
#include"VKDevice.h"
|
||||||
#include"VKInstance.h"
|
#include"VKInstance.h"
|
||||||
#include"VKPhysicalDevice.h"
|
#include"VKPhysicalDevice.h"
|
||||||
#include<hgl/type/Smart.h>
|
|
||||||
|
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
|
|
||||||
VkSurfaceKHR CreateRenderDevice(VkInstance,Window *);
|
VkSurfaceKHR CreateRenderDevice(VkInstance,Window *);
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
@ -288,6 +286,26 @@ namespace
|
|||||||
|
|
||||||
return desc_pool;
|
return desc_pool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct RenderDeviceCreater
|
||||||
|
{
|
||||||
|
DeviceAttribute *attr;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
RenderDeviceCreater(VkInstance inst,const PhysicalDevice *pd,VkSurfaceKHR sur)
|
||||||
|
{
|
||||||
|
attr=new DeviceAttribute(inst,pd,sur);
|
||||||
|
}
|
||||||
|
|
||||||
|
~RenderDeviceCreater()
|
||||||
|
{
|
||||||
|
if(attr)
|
||||||
|
delete attr;
|
||||||
|
}
|
||||||
|
|
||||||
|
DeviceAttribute *operator -> (){return attr;}
|
||||||
|
};//struct RenderDeviceCreater
|
||||||
}//namespace
|
}//namespace
|
||||||
|
|
||||||
Device *CreateRenderDevice(VkInstance inst,const PhysicalDevice *physical_device,Window *win)
|
Device *CreateRenderDevice(VkInstance inst,const PhysicalDevice *physical_device,Window *win)
|
||||||
@ -297,39 +315,42 @@ Device *CreateRenderDevice(VkInstance inst,const PhysicalDevice *physical_device
|
|||||||
if(!surface)
|
if(!surface)
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
RefDeviceAttribute rsa=new DeviceAttribute(inst,physical_device,surface);
|
RenderDeviceCreater rdc(inst,physical_device,surface);
|
||||||
|
|
||||||
rsa->swapchain_extent=GetSwapchainExtent(rsa->surface_caps,win->GetWidth(),win->GetHeight());
|
rdc->swapchain_extent=GetSwapchainExtent(rdc->surface_caps,win->GetWidth(),win->GetHeight());
|
||||||
|
|
||||||
if(rsa->graphics_family==ERROR_FAMILY_INDEX)
|
if(rdc->graphics_family==ERROR_FAMILY_INDEX)
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
rsa->device=CreateDevice(inst,physical_device->physical_device,rsa->graphics_family);
|
rdc->device=CreateDevice(inst,physical_device->physical_device,rdc->graphics_family);
|
||||||
|
|
||||||
if(!rsa->device)
|
if(!rdc->device)
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
rsa->cmd_pool=CreateCommandPool(rsa->device,rsa->graphics_family);
|
rdc->cmd_pool=CreateCommandPool(rdc->device,rdc->graphics_family);
|
||||||
|
|
||||||
if(!rsa->cmd_pool)
|
if(!rdc->cmd_pool)
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
rsa->swap_chain=CreateSwapChain(rsa);
|
rdc->swap_chain=CreateSwapChain(rdc.attr);
|
||||||
|
|
||||||
if(!rsa->swap_chain)
|
if(!rdc->swap_chain)
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
if(!CreateSwapchainImageView(rsa))
|
if(!CreateSwapchainImageView(rdc.attr))
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
if(!CreateDepthBuffer(rsa))
|
if(!CreateDepthBuffer(rdc.attr))
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
rsa->desc_pool=CreateDescriptorPool(rsa->device,1);
|
rdc->desc_pool=CreateDescriptorPool(rdc->device,1);
|
||||||
|
|
||||||
if(!rsa->desc_pool)
|
if(!rdc->desc_pool)
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
return(new Device(rsa));
|
Device *dev=new Device(rdc.attr);
|
||||||
|
rdc.attr=nullptr;
|
||||||
|
|
||||||
|
return dev;
|
||||||
}
|
}
|
||||||
VK_NAMESPACE_END
|
VK_NAMESPACE_END
|
||||||
|
Loading…
x
Reference in New Issue
Block a user