增加新的CreateTexture,并整理优化代码
This commit is contained in:
parent
d3bdaa3c15
commit
9a22fa937b
@ -125,23 +125,30 @@ public: //material相关
|
||||
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
|
||||
}
|
||||
|
||||
Texture2D *CreateAttachmentTexture(const VkFormat video_format,uint32_t width,uint32_t height,const VkImageAspectFlags aspectMask,const VkImageUsageFlagBits usage,const VkImageLayout image_layout)
|
||||
{
|
||||
return CreateTexture2D(video_format,width,height,aspectMask,usage|VK_IMAGE_USAGE_SAMPLED_BIT,image_layout);
|
||||
}
|
||||
|
||||
Texture2D *CreateAttachmentTextureColor(const VkFormat video_format,uint32_t width,uint32_t height)
|
||||
{
|
||||
return CreateTexture2D(video_format,width,height,
|
||||
VK_IMAGE_ASPECT_COLOR_BIT,
|
||||
VK_IMAGE_USAGE_SAMPLED_BIT,
|
||||
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
|
||||
return CreateAttachmentTexture( video_format,width,height,
|
||||
VK_IMAGE_ASPECT_COLOR_BIT,
|
||||
VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
|
||||
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
|
||||
}
|
||||
|
||||
Texture2D *CreateAttachmentTextureDepth(const VkFormat video_format,uint32_t width,uint32_t height)
|
||||
{
|
||||
return CreateTexture2D(video_format,width,height,
|
||||
VK_IMAGE_ASPECT_DEPTH_BIT|VK_IMAGE_ASPECT_STENCIL_BIT,
|
||||
VK_IMAGE_USAGE_SAMPLED_BIT,
|
||||
VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
|
||||
}
|
||||
return CreateAttachmentTexture( video_format,width,height,
|
||||
VK_IMAGE_ASPECT_DEPTH_BIT|VK_IMAGE_ASPECT_STENCIL_BIT,
|
||||
VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
|
||||
VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL );}
|
||||
|
||||
Texture2D *CreateTexture2D(const VkFormat video_format,void *data,uint32_t width,uint32_t height,uint32_t size,bool force_linear=false,const VkImageLayout image_layout=VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
|
||||
Texture2D *CreateTexture2D( const VkFormat video_format,void *data,uint32_t width,uint32_t height,uint32_t size,
|
||||
const VkImageAspectFlags aspectMask =VK_IMAGE_ASPECT_COLOR_BIT,
|
||||
const uint usage =VK_IMAGE_USAGE_TRANSFER_DST_BIT|VK_IMAGE_USAGE_SAMPLED_BIT,
|
||||
const VkImageLayout image_layout=VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
|
||||
|
||||
bool ChangeTexture2D(Texture2D *,void *data,uint32_t left,uint32_t top,uint32_t width,uint32_t height,uint32_t size);
|
||||
Sampler *CreateSampler(VkSamplerCreateInfo *);
|
||||
|
@ -57,7 +57,7 @@ public:
|
||||
DeviceAttribute(VkInstance inst,const PhysicalDevice *pd,VkSurfaceKHR s);
|
||||
~DeviceAttribute();
|
||||
|
||||
bool CheckMemoryType(uint32_t typeBits,VkFlags requirements_mask,uint32_t *typeIndex) const;
|
||||
bool CheckMemoryType(uint32_t typeBits,VkMemoryPropertyFlags properties,uint32_t *typeIndex) const;
|
||||
|
||||
void ClearSwapchain();
|
||||
void Refresh();
|
||||
|
@ -1,4 +1,4 @@
|
||||
#ifndef HGL_VULKAN_GRAPH_FENCE_INCLUDE
|
||||
#ifndef HGL_VULKAN_GRAPH_FENCE_INCLUDE
|
||||
#define HGL_VULKAN_GRAPH_FENCE_INCLUDE
|
||||
|
||||
#include<hgl/graph/vulkan/VK.h>
|
||||
|
@ -1,4 +1,4 @@
|
||||
#ifndef HGL_GRAPH_VULKAN_FORMAT_INCLUDE
|
||||
#ifndef HGL_GRAPH_VULKAN_FORMAT_INCLUDE
|
||||
#define HGL_GRAPH_VULKAN_FORMAT_INCLUDE
|
||||
|
||||
#include<vulkan/vulkan.h>
|
||||
|
@ -1,4 +1,4 @@
|
||||
#ifndef HGL_GRAPH_VULKAN_FRAMEBUFFER_INCLUDE
|
||||
#ifndef HGL_GRAPH_VULKAN_FRAMEBUFFER_INCLUDE
|
||||
#define HGL_GRAPH_VULKAN_FRAMEBUFFER_INCLUDE
|
||||
|
||||
#include<hgl/graph/vulkan/VK.h>
|
||||
|
@ -1,4 +1,4 @@
|
||||
#ifndef HGL_GRAPH_VULKAN_IMAGE_VIEW_INCLUDE
|
||||
#ifndef HGL_GRAPH_VULKAN_IMAGE_VIEW_INCLUDE
|
||||
#define HGL_GRAPH_VULKAN_IMAGE_VIEW_INCLUDE
|
||||
|
||||
#include<hgl/graph/vulkan/VK.h>
|
||||
@ -41,12 +41,12 @@ public:
|
||||
};//class ImageView
|
||||
|
||||
/**
|
||||
* 创建一个引用ImageView,它的特点是不会自动删除VkImageView
|
||||
* 创建一个引用ImageView,它的特点是不会自动删除VkImageView
|
||||
*/
|
||||
ImageView *CreateRefImageView(VkDevice device,VkImageViewType type,VkFormat format,VkImageAspectFlags aspectMask,VkImageView img_view);
|
||||
|
||||
/**
|
||||
* 根据VkImage创建一个VkImageView,在删除它时,它也会删除VkImageView
|
||||
* 根据VkImage创建一个VkImageView,在删除它时,它也会删除VkImageView
|
||||
*/
|
||||
ImageView *CreateImageView(VkDevice device,VkImageViewType type,VkFormat format,VkImageAspectFlags aspectMask,VkImage img=nullptr);
|
||||
|
||||
|
@ -23,7 +23,7 @@ public:
|
||||
operator VkPhysicalDevice(){return physical_device;}
|
||||
operator const VkPhysicalDevice()const{return physical_device;}
|
||||
|
||||
const bool CheckMemoryType(uint32_t,VkFlags,uint32_t *)const;
|
||||
const bool CheckMemoryType(uint32_t,VkMemoryPropertyFlags,uint32_t *)const;
|
||||
|
||||
VkPhysicalDeviceType GetDeviceType()const{return properties.deviceType;}
|
||||
const char * GetDeviceName()const{return properties.deviceName;}
|
||||
|
@ -1,4 +1,4 @@
|
||||
#ifndef HGL_GRAPH_VULKAN_SEMAPHORE_INCLUDE
|
||||
#ifndef HGL_GRAPH_VULKAN_SEMAPHORE_INCLUDE
|
||||
#define HGL_GRAPH_VULKAN_SEMAPHORE_INCLUDE
|
||||
|
||||
#include<hgl/graph/vulkan/VK.h>
|
||||
|
@ -25,6 +25,9 @@ protected:
|
||||
|
||||
public:
|
||||
|
||||
operator TextureData * (){return data;}
|
||||
|
||||
operator VkDeviceMemory (){return data?data->memory:nullptr;}
|
||||
operator VkImage (){return data?data->image:nullptr;}
|
||||
operator VkImageLayout (){return data?data->image_layout:VK_IMAGE_LAYOUT_UNDEFINED;}
|
||||
operator VkImageView (){return data?data->image_view->operator VkImageView():nullptr;}
|
||||
|
@ -34,9 +34,9 @@ DeviceAttribute::~DeviceAttribute()
|
||||
vkDestroySurfaceKHR(instance,surface,nullptr);
|
||||
}
|
||||
|
||||
bool DeviceAttribute::CheckMemoryType(uint32_t typeBits,VkFlags requirements_mask,uint32_t *typeIndex) const
|
||||
bool DeviceAttribute::CheckMemoryType(uint32_t typeBits,VkMemoryPropertyFlags properties,uint32_t *typeIndex) const
|
||||
{
|
||||
return physical_device->CheckMemoryType(typeBits,requirements_mask,typeIndex);
|
||||
return physical_device->CheckMemoryType(typeBits,properties,typeIndex);
|
||||
}
|
||||
|
||||
void DeviceAttribute::ClearSwapchain()
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include<hgl/graph/vulkan/VKDevice.h>
|
||||
#include<hgl/graph/vulkan/VKDevice.h>
|
||||
#include<hgl/graph/vulkan/VKBuffer.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include<hgl/graph/vulkan/VKDevice.h>
|
||||
#include<hgl/graph/vulkan/VKDevice.h>
|
||||
#include<hgl/graph/vulkan/VKPhysicalDevice.h>
|
||||
#include<hgl/graph/vulkan/VKRenderPass.h>
|
||||
|
||||
|
@ -32,26 +32,28 @@ Texture2D *Device::CreateTexture2D(const VkFormat video_format,uint32_t width,ui
|
||||
|
||||
VkImageCreateInfo imageCreateInfo;
|
||||
|
||||
imageCreateInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
|
||||
imageCreateInfo.pNext = nullptr;
|
||||
imageCreateInfo.flags = 0;
|
||||
imageCreateInfo.imageType = VK_IMAGE_TYPE_2D;
|
||||
imageCreateInfo.format = video_format;
|
||||
imageCreateInfo.mipLevels = 1;
|
||||
imageCreateInfo.arrayLayers = 1;
|
||||
imageCreateInfo.samples = VK_SAMPLE_COUNT_1_BIT;
|
||||
imageCreateInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
|
||||
imageCreateInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
|
||||
imageCreateInfo.pNext = nullptr;
|
||||
imageCreateInfo.flags = 0;
|
||||
imageCreateInfo.imageType = VK_IMAGE_TYPE_2D;
|
||||
imageCreateInfo.format = video_format;
|
||||
imageCreateInfo.extent.width = width;
|
||||
imageCreateInfo.extent.height = height;
|
||||
imageCreateInfo.extent.depth = 1;
|
||||
imageCreateInfo.mipLevels = 1;
|
||||
imageCreateInfo.arrayLayers = 1;
|
||||
imageCreateInfo.samples = VK_SAMPLE_COUNT_1_BIT;
|
||||
imageCreateInfo.usage = usage;
|
||||
imageCreateInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
|
||||
// Set initial layout of the image to undefined
|
||||
imageCreateInfo.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||
imageCreateInfo.extent.width = width;
|
||||
imageCreateInfo.extent.height = height;
|
||||
imageCreateInfo.extent.depth = 1;
|
||||
imageCreateInfo.usage = usage;
|
||||
imageCreateInfo.queueFamilyIndexCount = 0;
|
||||
imageCreateInfo.pQueueFamilyIndices = nullptr;
|
||||
imageCreateInfo.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||
|
||||
if(fp.optimalTilingFeatures&VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)
|
||||
imageCreateInfo.tiling = VK_IMAGE_TILING_OPTIMAL;
|
||||
imageCreateInfo.tiling = VK_IMAGE_TILING_OPTIMAL;
|
||||
else
|
||||
imageCreateInfo.tiling = VK_IMAGE_TILING_LINEAR;
|
||||
imageCreateInfo.tiling = VK_IMAGE_TILING_LINEAR;
|
||||
|
||||
VkImage image;
|
||||
|
||||
@ -64,150 +66,107 @@ Texture2D *Device::CreateTexture2D(const VkFormat video_format,uint32_t width,ui
|
||||
tex_data->mip_levels = 1;
|
||||
tex_data->image_layout = image_layout;
|
||||
tex_data->image = image;
|
||||
|
||||
tex_data->image_view=CreateImageView2D(attr->device,video_format,aspectMask,image);
|
||||
|
||||
return(new Texture2D(width,height,attr->device,tex_data));
|
||||
VkMemoryAllocateInfo memAllocInfo;
|
||||
VkMemoryRequirements memReqs;
|
||||
|
||||
memAllocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
|
||||
memAllocInfo.pNext = nullptr;
|
||||
|
||||
vkGetImageMemoryRequirements(attr->device, tex_data->image, &memReqs);
|
||||
|
||||
memAllocInfo.allocationSize = memReqs.size;
|
||||
attr->CheckMemoryType(memReqs.memoryTypeBits,VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,&memAllocInfo.memoryTypeIndex);
|
||||
|
||||
if(vkAllocateMemory(attr->device, &memAllocInfo, nullptr, &tex_data->memory)==VK_SUCCESS)
|
||||
if(vkBindImageMemory(attr->device, tex_data->image, tex_data->memory, 0)==VK_SUCCESS)
|
||||
{
|
||||
tex_data->image_view=CreateImageView2D(attr->device,video_format,aspectMask,tex_data->image);
|
||||
|
||||
return(new Texture2D(width,height,attr->device,tex_data));
|
||||
}
|
||||
|
||||
delete tex_data;
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
Texture2D *Device::CreateTexture2D(const VkFormat video_format,void *data,uint32_t width,uint32_t height,uint32_t size,bool force_linear,const VkImageLayout image_layout)
|
||||
Texture2D *Device::CreateTexture2D(const VkFormat video_format,void *data,uint32_t width,uint32_t height,uint32_t size,const VkImageAspectFlags aspectMask,const uint usage,const VkImageLayout image_layout)
|
||||
{
|
||||
if(video_format<VK_FORMAT_BEGIN_RANGE||video_format>VK_FORMAT_END_RANGE)return(nullptr);
|
||||
if(!data||width<1||height<1)return(nullptr);
|
||||
Texture2D *tex=CreateTexture2D(video_format,width,height,aspectMask,usage,image_layout);
|
||||
|
||||
const VkFormatProperties fp=attr->physical_device->GetFormatProperties(video_format);
|
||||
if(!tex)return(nullptr);
|
||||
|
||||
if(fp.optimalTilingFeatures&VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)
|
||||
{
|
||||
if(force_linear)
|
||||
{
|
||||
if(!(fp.linearTilingFeatures&VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT))
|
||||
force_linear=false;
|
||||
}
|
||||
}
|
||||
else //不能用优化存储,这种现像好像不存在啊
|
||||
{
|
||||
if(!(fp.linearTilingFeatures&VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT))
|
||||
{
|
||||
//也不能用线性储存??WTF ?
|
||||
return(nullptr);
|
||||
}
|
||||
TextureData *tex_data=*tex;
|
||||
|
||||
force_linear=true;
|
||||
return(nullptr); //这个我们暂时不支持
|
||||
}
|
||||
#define VK_CHECK_RESULT(func) if(func!=VK_SUCCESS){delete tex_data;delete buf;return(nullptr);}
|
||||
|
||||
TextureData *tex_data=new TextureData;
|
||||
Buffer *buf=CreateBuffer(VK_BUFFER_USAGE_TRANSFER_SRC_BIT,size,data);
|
||||
|
||||
tex_data->ref = false;
|
||||
tex_data->mip_levels = 1;
|
||||
tex_data->image_layout = image_layout;
|
||||
VkBufferImageCopy buffer_image_copy{};
|
||||
buffer_image_copy.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
||||
buffer_image_copy.imageSubresource.mipLevel = 0;
|
||||
buffer_image_copy.imageSubresource.baseArrayLayer = 0;
|
||||
buffer_image_copy.imageSubresource.layerCount = 1;
|
||||
buffer_image_copy.imageExtent.width = width;
|
||||
buffer_image_copy.imageExtent.height = height;
|
||||
buffer_image_copy.imageExtent.depth = 1;
|
||||
buffer_image_copy.bufferOffset = 0;
|
||||
|
||||
if(force_linear)
|
||||
{
|
||||
delete tex_data;
|
||||
return(nullptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
#define VK_CHECK_RESULT(func) if(func!=VK_SUCCESS){delete tex_data;delete buf;return(nullptr);}
|
||||
VkImageSubresourceRange subresourceRange = {};
|
||||
subresourceRange.aspectMask = aspectMask;
|
||||
subresourceRange.baseMipLevel = 0;
|
||||
subresourceRange.levelCount = 1;
|
||||
subresourceRange.layerCount = 1;
|
||||
|
||||
Buffer *buf=CreateBuffer(VK_BUFFER_USAGE_TRANSFER_SRC_BIT,size,data);
|
||||
VkImageMemoryBarrier imageMemoryBarrier{};
|
||||
imageMemoryBarrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
|
||||
imageMemoryBarrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||
imageMemoryBarrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||
imageMemoryBarrier.image = tex_data->image;
|
||||
imageMemoryBarrier.subresourceRange = subresourceRange;
|
||||
imageMemoryBarrier.srcAccessMask = 0;
|
||||
imageMemoryBarrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
|
||||
imageMemoryBarrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||
imageMemoryBarrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
|
||||
|
||||
VkBufferImageCopy buffer_image_copy{};
|
||||
buffer_image_copy.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
||||
buffer_image_copy.imageSubresource.mipLevel = 0;
|
||||
buffer_image_copy.imageSubresource.baseArrayLayer = 0;
|
||||
buffer_image_copy.imageSubresource.layerCount = 1;
|
||||
buffer_image_copy.imageExtent.width = width;
|
||||
buffer_image_copy.imageExtent.height = height;
|
||||
buffer_image_copy.imageExtent.depth = 1;
|
||||
buffer_image_copy.bufferOffset = 0;
|
||||
texture_cmd_buf->Begin();
|
||||
texture_cmd_buf->PipelineBarrier(
|
||||
VK_PIPELINE_STAGE_HOST_BIT,
|
||||
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
||||
0,
|
||||
0, nullptr,
|
||||
0, nullptr,
|
||||
1, &imageMemoryBarrier);
|
||||
|
||||
VkImageCreateInfo imageCreateInfo{};
|
||||
imageCreateInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
|
||||
imageCreateInfo.imageType = VK_IMAGE_TYPE_2D;
|
||||
imageCreateInfo.format = video_format;
|
||||
imageCreateInfo.mipLevels = 1;
|
||||
imageCreateInfo.arrayLayers = 1;
|
||||
imageCreateInfo.samples = VK_SAMPLE_COUNT_1_BIT;
|
||||
imageCreateInfo.tiling = VK_IMAGE_TILING_OPTIMAL;
|
||||
imageCreateInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
|
||||
// Set initial layout of the image to undefined
|
||||
imageCreateInfo.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||
imageCreateInfo.extent = buffer_image_copy.imageExtent;
|
||||
imageCreateInfo.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
|
||||
VK_CHECK_RESULT(vkCreateImage(attr->device, &imageCreateInfo, nullptr, &tex_data->image))
|
||||
texture_cmd_buf->CopyBufferToImage(
|
||||
*buf,
|
||||
tex_data->image,
|
||||
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, //对应上方的imageMemoryBarrier.newLayout
|
||||
1,
|
||||
&buffer_image_copy);
|
||||
|
||||
VkMemoryAllocateInfo memAllocInfo{};
|
||||
VkMemoryRequirements memReqs{};
|
||||
imageMemoryBarrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
|
||||
imageMemoryBarrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
|
||||
imageMemoryBarrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
|
||||
imageMemoryBarrier.newLayout = image_layout;
|
||||
|
||||
memAllocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
|
||||
texture_cmd_buf->PipelineBarrier(
|
||||
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
||||
VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
|
||||
0,
|
||||
0, nullptr,
|
||||
0, nullptr,
|
||||
1, &imageMemoryBarrier);
|
||||
|
||||
vkGetImageMemoryRequirements(attr->device, tex_data->image, &memReqs);
|
||||
memAllocInfo.allocationSize = memReqs.size;
|
||||
attr->CheckMemoryType(memReqs.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,&memAllocInfo.memoryTypeIndex);
|
||||
VK_CHECK_RESULT(vkAllocateMemory(attr->device, &memAllocInfo, nullptr, &tex_data->memory))
|
||||
VK_CHECK_RESULT(vkBindImageMemory(attr->device, tex_data->image, tex_data->memory, 0))
|
||||
texture_cmd_buf->End();
|
||||
|
||||
VkImageSubresourceRange subresourceRange = {};
|
||||
subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
||||
subresourceRange.baseMipLevel = 0;
|
||||
subresourceRange.levelCount = 1;
|
||||
subresourceRange.layerCount = 1;
|
||||
SubmitTexture(*texture_cmd_buf);
|
||||
|
||||
VkImageMemoryBarrier imageMemoryBarrier{};
|
||||
imageMemoryBarrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
|
||||
imageMemoryBarrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||
imageMemoryBarrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||
imageMemoryBarrier.image = tex_data->image;
|
||||
imageMemoryBarrier.subresourceRange = subresourceRange;
|
||||
imageMemoryBarrier.srcAccessMask = 0;
|
||||
imageMemoryBarrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
|
||||
imageMemoryBarrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||
imageMemoryBarrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
|
||||
delete buf;
|
||||
|
||||
texture_cmd_buf->Begin();
|
||||
texture_cmd_buf->PipelineBarrier(
|
||||
VK_PIPELINE_STAGE_HOST_BIT,
|
||||
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
||||
0,
|
||||
0, nullptr,
|
||||
0, nullptr,
|
||||
1, &imageMemoryBarrier);
|
||||
#undef VK_CHECK_RESULT
|
||||
|
||||
texture_cmd_buf->CopyBufferToImage(
|
||||
*buf,
|
||||
tex_data->image,
|
||||
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
|
||||
1,
|
||||
&buffer_image_copy);
|
||||
|
||||
imageMemoryBarrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
|
||||
imageMemoryBarrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
|
||||
imageMemoryBarrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
|
||||
imageMemoryBarrier.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
|
||||
|
||||
texture_cmd_buf->PipelineBarrier(
|
||||
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
||||
VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
|
||||
0,
|
||||
0, nullptr,
|
||||
0, nullptr,
|
||||
1, &imageMemoryBarrier);
|
||||
|
||||
texture_cmd_buf->End();
|
||||
|
||||
SubmitTexture(*texture_cmd_buf);
|
||||
|
||||
delete buf;
|
||||
|
||||
tex_data->image_view=CreateImageView2D(attr->device,video_format,VK_IMAGE_ASPECT_COLOR_BIT,tex_data->image);
|
||||
|
||||
#undef VK_CHECK_RESULT
|
||||
}
|
||||
|
||||
return(new Texture2D(width,height,attr->device,tex_data));
|
||||
return(tex);
|
||||
}
|
||||
|
||||
Texture2D *Device::CreateRefTexture2D(uint32_t width,uint32_t height,VkFormat format,VkImageAspectFlagBits flag,VkImage image,VkImageLayout image_layout,VkImageView image_view)
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include<hgl/graph/vulkan/VKFence.h>
|
||||
#include<hgl/graph/vulkan/VKFence.h>
|
||||
VK_NAMESPACE_BEGIN
|
||||
Fence::~Fence()
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include<hgl/graph/vulkan/VKImageView.h>
|
||||
#include<hgl/graph/vulkan/VKImageView.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
class StandaloneImageView:public ImageView
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include<hgl/graph/vulkan/VKPhysicalDevice.h>
|
||||
#include<hgl/graph/vulkan/VKPhysicalDevice.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
PhysicalDevice::PhysicalDevice(VkInstance inst,VkPhysicalDevice pd)
|
||||
@ -72,7 +72,7 @@ const uint32_t PhysicalDevice::GetExtensionSpecVersion(const UTF8String &name)co
|
||||
return 0;
|
||||
}
|
||||
|
||||
const bool PhysicalDevice::CheckMemoryType(uint32_t typeBits,VkFlags requirements_mask,uint32_t *typeIndex)const
|
||||
const bool PhysicalDevice::CheckMemoryType(uint32_t typeBits,VkMemoryPropertyFlags properties,uint32_t *typeIndex)const
|
||||
{
|
||||
// Search memtypes to find first index with those properties
|
||||
for(uint32_t i=0; i<memory_properties.memoryTypeCount; i++)
|
||||
@ -80,7 +80,7 @@ const bool PhysicalDevice::CheckMemoryType(uint32_t typeBits,VkFlags requirement
|
||||
if((typeBits&1)==1)
|
||||
{
|
||||
// Type is available, does it match user properties?
|
||||
if((memory_properties.memoryTypes[i].propertyFlags&requirements_mask)==requirements_mask)
|
||||
if((memory_properties.memoryTypes[i].propertyFlags&properties)==properties)
|
||||
{
|
||||
*typeIndex=i;
|
||||
return true;
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include<hgl/graph/vulkan/VKRenderPass.h>
|
||||
#include<hgl/graph/vulkan/VKRenderPass.h>
|
||||
VK_NAMESPACE_BEGIN
|
||||
RenderPass::~RenderPass()
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include<hgl/graph/vulkan/VKSemaphore.h>
|
||||
#include<hgl/graph/vulkan/VKSemaphore.h>
|
||||
VK_NAMESPACE_BEGIN
|
||||
Semaphore::~Semaphore()
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include<hgl/graph/vulkan/VKShaderModule.h>
|
||||
#include<hgl/graph/vulkan/VKShaderModule.h>
|
||||
#include<hgl/graph/vulkan/VKVertexAttributeBinding.h>
|
||||
#include"VKShaderParse.h"
|
||||
|
||||
@ -52,21 +52,21 @@ VertexShaderModule::VertexShaderModule(VkDevice dev,int id,VkPipelineShaderStage
|
||||
|
||||
for(const auto &si:stage_inputs)
|
||||
{
|
||||
const VkFormat format =parse->GetFormat(si); //注意这个格式有可能会解析不出来(比如各种压缩格式)
|
||||
const VkFormat format =parse->GetFormat(si); //注意这个格式有可能会解析不出来(比如各种压缩格式)
|
||||
const UTF8String & name =parse->GetName(si);
|
||||
|
||||
bind->binding =binding_index; //binding对应在vkCmdBindVertexBuffer中设置的缓冲区的序列号,所以这个数字必须从0开始,而且紧密排列。
|
||||
//在VertexInput类中,buf_list需要严格按照本此binding为序列号排列
|
||||
bind->binding =binding_index; //binding对应在vkCmdBindVertexBuffer中设置的缓冲区的序列号,所以这个数字必须从0开始,而且紧密排列。
|
||||
//在VertexInput类中,buf_list需要严格按照本此binding为序列号排列
|
||||
bind->stride =GetStrideByFormat(format);
|
||||
bind->inputRate =VK_VERTEX_INPUT_RATE_VERTEX;
|
||||
|
||||
//binding对应的是第几个数据输入流
|
||||
//实际使用一个binding可以绑定多个attrib
|
||||
//比如在一个流中传递{pos,color}这样两个数据,就需要两个attrib
|
||||
//但在我们的设计中,仅支持一个流传递一个attrib
|
||||
//binding对应的是第几个数据输入流
|
||||
//实际使用一个binding可以绑定多个attrib
|
||||
//比如在一个流中传递{pos,color}这样两个数据,就需要两个attrib
|
||||
//但在我们的设计中,仅支持一个流传递一个attrib
|
||||
|
||||
attr->binding =binding_index;
|
||||
attr->location =parse->GetLocation(si); //此值对应shader中的layout(location=
|
||||
attr->location =parse->GetLocation(si); //此值对应shader中的layout(location=
|
||||
attr->format =format;
|
||||
attr->offset =0;
|
||||
|
||||
@ -82,7 +82,7 @@ VertexShaderModule::~VertexShaderModule()
|
||||
{
|
||||
if(vab_sets.GetCount()>0)
|
||||
{
|
||||
//还有在用的,这是个错误
|
||||
//还有在用的,这是个错误
|
||||
}
|
||||
|
||||
SAFE_CLEAR_ARRAY(binding_list);
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include<hgl/graph/vulkan/VKShaderModuleManage.h>
|
||||
#include<hgl/graph/vulkan/VKShaderModuleManage.h>
|
||||
#include<hgl/graph/vulkan/VKShaderModule.h>
|
||||
#include<hgl/graph/vulkan/VKMaterial.h>
|
||||
#include<hgl/graph/vulkan/VKDevice.h>
|
||||
|
@ -1,4 +1,4 @@
|
||||
#pragma once
|
||||
#pragma once
|
||||
#include"spirv_cross.hpp"
|
||||
#include<vulkan/vulkan.h>
|
||||
#include<hgl/type/BaseString.h>
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include<hgl/graph/vulkan/VKVertexAttributeBinding.h>
|
||||
#include<hgl/graph/vulkan/VKVertexAttributeBinding.h>
|
||||
#include<hgl/graph/vulkan/VKShaderModule.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
Loading…
x
Reference in New Issue
Block a user