2017-02-15 10 views
0

こんにちは私は深さのメモリバッファをバインドしようとしていますが、私は以下のようにエラーが発生します。なぜこのエラーがポップアップしているのか分かりません。Vulkan深度画像の結合エラー

奥行きフォーマットはVK_FORMAT_D16_UNORMで、使用法はVK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BITです。私はオンラインでTILINGが線形ではないはずですが、別のエラーが発生します。ありがとう!!!

イメージの作成とバインドのコードは次のとおりです。

VkImageCreateInfo imageInfo = {}; 

// If the depth format is undefined, use fallback as 16-byte value 
if (Depth.format == VK_FORMAT_UNDEFINED) { 
    Depth.format = VK_FORMAT_D16_UNORM; 
} 

const VkFormat depthFormat = Depth.format; 

VkFormatProperties props; 
vkGetPhysicalDeviceFormatProperties(*deviceObj->gpu, depthFormat, &props); 

if (props.linearTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) { 
    imageInfo.tiling = VK_IMAGE_TILING_LINEAR; 
} 
else if (props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) { 
    imageInfo.tiling = VK_IMAGE_TILING_OPTIMAL; 
} 
else { 
    std::cout << "Unsupported Depth Format, try other Depth formats.\n"; 
    exit(-1); 
} 

imageInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; 
imageInfo.pNext = NULL; 
imageInfo.imageType = VK_IMAGE_TYPE_2D; 
imageInfo.format = depthFormat; 
imageInfo.extent.width = width; 
imageInfo.extent.height = height; 
imageInfo.extent.depth = 1; 
imageInfo.mipLevels = 1; 
imageInfo.arrayLayers = 1; 
imageInfo.samples = NUM_SAMPLES; 
imageInfo.queueFamilyIndexCount = 0; 
imageInfo.pQueueFamilyIndices = NULL; 
imageInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE; 
imageInfo.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; 
imageInfo.flags = 0; 

// User create image info and create the image objects 
result = vkCreateImage(deviceObj->device, &imageInfo, NULL, &Depth.image); 
assert(result == VK_SUCCESS); 

// Get the image memory requirements 
VkMemoryRequirements memRqrmnt; 
vkGetImageMemoryRequirements(deviceObj->device, Depth.image, &memRqrmnt); 

VkMemoryAllocateInfo memAlloc = {}; 
memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; 
memAlloc.pNext = NULL; 
memAlloc.allocationSize = 0; 
memAlloc.memoryTypeIndex = 0; 
memAlloc.allocationSize = memRqrmnt.size; 

// Determine the type of memory required with the help of memory properties 
pass = deviceObj->memoryTypeFromProperties(memRqrmnt.memoryTypeBits, 0, /* No requirements */ &memAlloc.memoryTypeIndex); 
assert(pass); 

// Allocate the memory for image objects 
result = vkAllocateMemory(deviceObj->device, &memAlloc, NULL, &Depth.mem); 
assert(result == VK_SUCCESS); 

// Bind the allocated memeory 
result = vkBindImageMemory(deviceObj->device, Depth.image, Depth.mem, 0); 
assert(result == VK_SUCCESS); 

enter image description here

答えて

3

はい、線形タイルは、深さの使用イメージのためにサポートされない場合があります。 VkImageCreateInfoの仕様と有効使用法セクションを参照してください。機能は、vkGetPhysicalDeviceFormatPropertiesvkGetPhysicalDeviceImageFormatPropertiesコマンドによって照会されます。深度のフォーマットは "opaque"ですが、線形タイリングを使用する理由はあまりありません。

これはあなたのコードでやっているようです。
しかし、このエラーは、指定されたイメージに対して許可されていないメモリタイプを使用しようとしていることを通知します。許可されているメモリの種類を照会するには、vkGetImageMemoryRequirementsコマンドを使用します。

おそらく、いくつかのエラーがあります(メッセージあたり0x84の部分ではない0x1を使用しています)。 Device Memory chapter of the specificationのサンプルコードを再利用することができます。より具体的な回答のためにmemoryTypeFromProperties実装を提供してください。

+0

HI助けてくれてありがとう... memoryTypeFromPropertiesため、私は132と132としてmemRqrmntTypeBitsを取得するには、私はオット深度の形式を試して、サポートされていない深さフォーマットを取得VK_FORMAT_BC1_RGB_SRGB_BLOCK = 132です。 –

0

誤ってtypeIndexをiの代わりに1に設定しましたが、今は動作します。私の防衛の中で私は一日中コーディングしていて、私の目は出血しています:)。助けてくれてありがとう。

bool VulkanDevice::memoryTypeFromProperties(uint32_t typeBits, VkFlags  
requirementsMask, uint32_t *typeIndex) 
{ 
    // Search memtypes to find first index with those properties 
for (uint32_t i = 0; i < 32; i++) { 
    if ((typeBits & 1) == 1) { 
     // Type is available, does it match user properties? 
     if ((memoryProperties.memoryTypes[i].propertyFlags & requirementsMask) == requirementsMask) { 
      *typeIndex = i;// was set to 1 :(
      return true; 
     } 
    } 
    typeBits >>= 1; 
} 
// No memory types matched, return failure 
return false; 
} 
関連する問題