diff --git a/inc/hgl/graph/vulkan/VKDevice.h b/inc/hgl/graph/vulkan/VKDevice.h index ea2e629c..346f6f58 100644 --- a/inc/hgl/graph/vulkan/VKDevice.h +++ b/inc/hgl/graph/vulkan/VKDevice.h @@ -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 *); diff --git a/inc/hgl/graph/vulkan/VKDeviceAttribute.h b/inc/hgl/graph/vulkan/VKDeviceAttribute.h index 0c71f655..f7f23d61 100644 --- a/inc/hgl/graph/vulkan/VKDeviceAttribute.h +++ b/inc/hgl/graph/vulkan/VKDeviceAttribute.h @@ -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(); diff --git a/inc/hgl/graph/vulkan/VKFence.h b/inc/hgl/graph/vulkan/VKFence.h index 0bbca265..a15165ea 100644 --- a/inc/hgl/graph/vulkan/VKFence.h +++ b/inc/hgl/graph/vulkan/VKFence.h @@ -1,4 +1,4 @@ -#ifndef HGL_VULKAN_GRAPH_FENCE_INCLUDE +#ifndef HGL_VULKAN_GRAPH_FENCE_INCLUDE #define HGL_VULKAN_GRAPH_FENCE_INCLUDE #include diff --git a/inc/hgl/graph/vulkan/VKFormat.h b/inc/hgl/graph/vulkan/VKFormat.h index 19b847b0..389c2439 100644 --- a/inc/hgl/graph/vulkan/VKFormat.h +++ b/inc/hgl/graph/vulkan/VKFormat.h @@ -1,4 +1,4 @@ -#ifndef HGL_GRAPH_VULKAN_FORMAT_INCLUDE +#ifndef HGL_GRAPH_VULKAN_FORMAT_INCLUDE #define HGL_GRAPH_VULKAN_FORMAT_INCLUDE #include diff --git a/inc/hgl/graph/vulkan/VKFramebuffer.h b/inc/hgl/graph/vulkan/VKFramebuffer.h index 093fbf68..600324d1 100644 --- a/inc/hgl/graph/vulkan/VKFramebuffer.h +++ b/inc/hgl/graph/vulkan/VKFramebuffer.h @@ -1,4 +1,4 @@ -#ifndef HGL_GRAPH_VULKAN_FRAMEBUFFER_INCLUDE +#ifndef HGL_GRAPH_VULKAN_FRAMEBUFFER_INCLUDE #define HGL_GRAPH_VULKAN_FRAMEBUFFER_INCLUDE #include diff --git a/inc/hgl/graph/vulkan/VKImageView.h b/inc/hgl/graph/vulkan/VKImageView.h index 0041a975..1ffb1537 100644 --- a/inc/hgl/graph/vulkan/VKImageView.h +++ b/inc/hgl/graph/vulkan/VKImageView.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 @@ -41,12 +41,12 @@ public: };//class ImageView /** - * һImageViewصDzԶɾ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); diff --git a/inc/hgl/graph/vulkan/VKPhysicalDevice.h b/inc/hgl/graph/vulkan/VKPhysicalDevice.h index b475bd4d..3b027409 100644 --- a/inc/hgl/graph/vulkan/VKPhysicalDevice.h +++ b/inc/hgl/graph/vulkan/VKPhysicalDevice.h @@ -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;} diff --git a/inc/hgl/graph/vulkan/VKSemaphore.h b/inc/hgl/graph/vulkan/VKSemaphore.h index cef645ee..1c969608 100644 --- a/inc/hgl/graph/vulkan/VKSemaphore.h +++ b/inc/hgl/graph/vulkan/VKSemaphore.h @@ -1,4 +1,4 @@ -#ifndef HGL_GRAPH_VULKAN_SEMAPHORE_INCLUDE +#ifndef HGL_GRAPH_VULKAN_SEMAPHORE_INCLUDE #define HGL_GRAPH_VULKAN_SEMAPHORE_INCLUDE #include diff --git a/inc/hgl/graph/vulkan/VKTexture.h b/inc/hgl/graph/vulkan/VKTexture.h index d372ba51..83956564 100644 --- a/inc/hgl/graph/vulkan/VKTexture.h +++ b/inc/hgl/graph/vulkan/VKTexture.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;} diff --git a/src/RenderDevice/Vulkan/VKDeviceAttribute.cpp b/src/RenderDevice/Vulkan/VKDeviceAttribute.cpp index 2f7308ef..381e0b6c 100644 --- a/src/RenderDevice/Vulkan/VKDeviceAttribute.cpp +++ b/src/RenderDevice/Vulkan/VKDeviceAttribute.cpp @@ -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() diff --git a/src/RenderDevice/Vulkan/VKDeviceBuffer.cpp b/src/RenderDevice/Vulkan/VKDeviceBuffer.cpp index 260ee65e..da3dee77 100644 --- a/src/RenderDevice/Vulkan/VKDeviceBuffer.cpp +++ b/src/RenderDevice/Vulkan/VKDeviceBuffer.cpp @@ -1,4 +1,4 @@ -#include +#include #include VK_NAMESPACE_BEGIN diff --git a/src/RenderDevice/Vulkan/VKDeviceRenderPass.cpp b/src/RenderDevice/Vulkan/VKDeviceRenderPass.cpp index 2e10b1b6..58779417 100644 --- a/src/RenderDevice/Vulkan/VKDeviceRenderPass.cpp +++ b/src/RenderDevice/Vulkan/VKDeviceRenderPass.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include diff --git a/src/RenderDevice/Vulkan/VKDeviceTexture.cpp b/src/RenderDevice/Vulkan/VKDeviceTexture.cpp index f984b586..11ee3e29 100644 --- a/src/RenderDevice/Vulkan/VKDeviceTexture.cpp +++ b/src/RenderDevice/Vulkan/VKDeviceTexture.cpp @@ -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_formatVK_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) diff --git a/src/RenderDevice/Vulkan/VKFence.cpp b/src/RenderDevice/Vulkan/VKFence.cpp index 37248ec1..382d61e4 100644 --- a/src/RenderDevice/Vulkan/VKFence.cpp +++ b/src/RenderDevice/Vulkan/VKFence.cpp @@ -1,4 +1,4 @@ -#include +#include VK_NAMESPACE_BEGIN Fence::~Fence() { diff --git a/src/RenderDevice/Vulkan/VKImageView.cpp b/src/RenderDevice/Vulkan/VKImageView.cpp index e0b02027..be2af9ec 100644 --- a/src/RenderDevice/Vulkan/VKImageView.cpp +++ b/src/RenderDevice/Vulkan/VKImageView.cpp @@ -1,4 +1,4 @@ -#include +#include VK_NAMESPACE_BEGIN class StandaloneImageView:public ImageView diff --git a/src/RenderDevice/Vulkan/VKPhysicalDevice.cpp b/src/RenderDevice/Vulkan/VKPhysicalDevice.cpp index 621900d7..07cb4fa9 100644 --- a/src/RenderDevice/Vulkan/VKPhysicalDevice.cpp +++ b/src/RenderDevice/Vulkan/VKPhysicalDevice.cpp @@ -1,4 +1,4 @@ -#include +#include 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 +#include VK_NAMESPACE_BEGIN RenderPass::~RenderPass() { diff --git a/src/RenderDevice/Vulkan/VKSemaphore.cpp b/src/RenderDevice/Vulkan/VKSemaphore.cpp index 63ec2f6a..6e7ef4e2 100644 --- a/src/RenderDevice/Vulkan/VKSemaphore.cpp +++ b/src/RenderDevice/Vulkan/VKSemaphore.cpp @@ -1,4 +1,4 @@ -#include +#include VK_NAMESPACE_BEGIN Semaphore::~Semaphore() { diff --git a/src/RenderDevice/Vulkan/VKShaderModule.cpp b/src/RenderDevice/Vulkan/VKShaderModule.cpp index 1e5bdcc5..3d9de9e3 100644 --- a/src/RenderDevice/Vulkan/VKShaderModule.cpp +++ b/src/RenderDevice/Vulkan/VKShaderModule.cpp @@ -1,4 +1,4 @@ -#include +#include #include #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); diff --git a/src/RenderDevice/Vulkan/VKShaderModuleManage.cpp b/src/RenderDevice/Vulkan/VKShaderModuleManage.cpp index 4150af1b..15064e31 100644 --- a/src/RenderDevice/Vulkan/VKShaderModuleManage.cpp +++ b/src/RenderDevice/Vulkan/VKShaderModuleManage.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include diff --git a/src/RenderDevice/Vulkan/VKShaderParse.h b/src/RenderDevice/Vulkan/VKShaderParse.h index e9294555..2c78363f 100644 --- a/src/RenderDevice/Vulkan/VKShaderParse.h +++ b/src/RenderDevice/Vulkan/VKShaderParse.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include"spirv_cross.hpp" #include #include diff --git a/src/RenderDevice/Vulkan/VKVertexAttributeBinding.cpp b/src/RenderDevice/Vulkan/VKVertexAttributeBinding.cpp index 5e2e383e..3a5956be 100644 --- a/src/RenderDevice/Vulkan/VKVertexAttributeBinding.cpp +++ b/src/RenderDevice/Vulkan/VKVertexAttributeBinding.cpp @@ -1,4 +1,4 @@ -#include +#include #include VK_NAMESPACE_BEGIN