mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-05-15 06:20:41 +00:00
Create new image view for sampling, to ensure it's array-sized
This commit is contained in:
@@ -979,23 +979,6 @@ void VulkanCreationInfo::Sampler::Init(VulkanResourceManager *resourceMan, Vulka
|
||||
}
|
||||
}
|
||||
|
||||
static TextureSwizzle Convert(VkComponentSwizzle s, int i)
|
||||
{
|
||||
switch(s)
|
||||
{
|
||||
default: RDCWARN("Unexpected component swizzle value %d", (int)s); DELIBERATE_FALLTHROUGH();
|
||||
case VK_COMPONENT_SWIZZLE_IDENTITY: break;
|
||||
case VK_COMPONENT_SWIZZLE_ZERO: return TextureSwizzle::Zero;
|
||||
case VK_COMPONENT_SWIZZLE_ONE: return TextureSwizzle::One;
|
||||
case VK_COMPONENT_SWIZZLE_R: return TextureSwizzle::Red;
|
||||
case VK_COMPONENT_SWIZZLE_G: return TextureSwizzle::Green;
|
||||
case VK_COMPONENT_SWIZZLE_B: return TextureSwizzle::Blue;
|
||||
case VK_COMPONENT_SWIZZLE_A: return TextureSwizzle::Alpha;
|
||||
}
|
||||
|
||||
return TextureSwizzle(uint32_t(TextureSwizzle::Red) + i);
|
||||
}
|
||||
|
||||
void VulkanCreationInfo::YCbCrSampler::Init(VulkanResourceManager *resourceMan,
|
||||
VulkanCreationInfo &info,
|
||||
const VkSamplerYcbcrConversionCreateInfo *pCreateInfo)
|
||||
@@ -1037,10 +1020,7 @@ void VulkanCreationInfo::YCbCrSampler::Init(VulkanResourceManager *resourceMan,
|
||||
case VK_CHROMA_LOCATION_RANGE_SIZE: break;
|
||||
}
|
||||
|
||||
swizzle[0] = Convert(pCreateInfo->components.r, 0);
|
||||
swizzle[1] = Convert(pCreateInfo->components.g, 1);
|
||||
swizzle[2] = Convert(pCreateInfo->components.b, 2);
|
||||
swizzle[3] = Convert(pCreateInfo->components.a, 3);
|
||||
componentMapping = pCreateInfo->components;
|
||||
chromaFilter = MakeFilterMode(pCreateInfo->chromaFilter);
|
||||
forceExplicitReconstruction = pCreateInfo->forceExplicitReconstruction != 0;
|
||||
}
|
||||
@@ -1051,6 +1031,7 @@ void VulkanCreationInfo::ImageView::Init(VulkanResourceManager *resourceMan, Vul
|
||||
image = GetResID(pCreateInfo->image);
|
||||
format = pCreateInfo->format;
|
||||
range = pCreateInfo->subresourceRange;
|
||||
viewType = pCreateInfo->viewType;
|
||||
|
||||
if(range.levelCount == VK_REMAINING_MIP_LEVELS)
|
||||
range.levelCount = info.m_Image[image].mipLevels - range.baseMipLevel;
|
||||
@@ -1058,10 +1039,7 @@ void VulkanCreationInfo::ImageView::Init(VulkanResourceManager *resourceMan, Vul
|
||||
if(range.layerCount == VK_REMAINING_ARRAY_LAYERS)
|
||||
range.layerCount = info.m_Image[image].arrayLayers - range.baseArrayLayer;
|
||||
|
||||
swizzle[0] = Convert(pCreateInfo->components.r, 0);
|
||||
swizzle[1] = Convert(pCreateInfo->components.g, 1);
|
||||
swizzle[2] = Convert(pCreateInfo->components.b, 2);
|
||||
swizzle[3] = Convert(pCreateInfo->components.a, 3);
|
||||
componentMapping = pCreateInfo->components;
|
||||
}
|
||||
|
||||
void VulkanCreationInfo::ShaderModule::Init(VulkanResourceManager *resourceMan,
|
||||
|
||||
@@ -499,7 +499,7 @@ struct VulkanCreationInfo
|
||||
|
||||
YcbcrConversion ycbcrModel;
|
||||
YcbcrRange ycbcrRange;
|
||||
TextureSwizzle swizzle[4];
|
||||
VkComponentMapping componentMapping;
|
||||
ChromaSampleLocation xChromaOffset;
|
||||
ChromaSampleLocation yChromaOffset;
|
||||
FilterMode chromaFilter;
|
||||
@@ -513,9 +513,10 @@ struct VulkanCreationInfo
|
||||
const VkImageViewCreateInfo *pCreateInfo);
|
||||
|
||||
ResourceId image;
|
||||
VkImageViewType viewType;
|
||||
VkFormat format;
|
||||
VkImageSubresourceRange range;
|
||||
TextureSwizzle swizzle[4];
|
||||
VkComponentMapping componentMapping;
|
||||
};
|
||||
std::map<ResourceId, ImageView> m_ImageView;
|
||||
|
||||
|
||||
@@ -1015,6 +1015,31 @@ void VulkanReplay::SetDriverInformation(const VkPhysicalDeviceProperties &props)
|
||||
memcpy(m_DriverInfo.version, versionString.c_str(), versionString.size());
|
||||
}
|
||||
|
||||
static void Convert(TextureSwizzle dst[4], VkComponentMapping src)
|
||||
{
|
||||
VkComponentSwizzle srcComps[4] = {
|
||||
src.r, src.g, src.b, src.a,
|
||||
};
|
||||
for(int i = 0; i < 4; i++)
|
||||
{
|
||||
switch(srcComps[i])
|
||||
{
|
||||
default:
|
||||
RDCWARN("Unexpected component swizzle value %d", (int)srcComps[i]);
|
||||
DELIBERATE_FALLTHROUGH();
|
||||
case VK_COMPONENT_SWIZZLE_IDENTITY: break;
|
||||
case VK_COMPONENT_SWIZZLE_ZERO: dst[i] = TextureSwizzle::Zero; break;
|
||||
case VK_COMPONENT_SWIZZLE_ONE: dst[i] = TextureSwizzle::One; break;
|
||||
case VK_COMPONENT_SWIZZLE_R: dst[i] = TextureSwizzle::Red; break;
|
||||
case VK_COMPONENT_SWIZZLE_G: dst[i] = TextureSwizzle::Green; break;
|
||||
case VK_COMPONENT_SWIZZLE_B: dst[i] = TextureSwizzle::Blue; break;
|
||||
case VK_COMPONENT_SWIZZLE_A: dst[i] = TextureSwizzle::Alpha; break;
|
||||
}
|
||||
|
||||
dst[i] = TextureSwizzle(uint32_t(TextureSwizzle::Red) + i);
|
||||
}
|
||||
}
|
||||
|
||||
void VulkanReplay::SavePipelineState(uint32_t eventId)
|
||||
{
|
||||
const VulkanRenderState &state = m_pDriver->m_RenderState;
|
||||
@@ -1486,8 +1511,8 @@ void VulkanReplay::SavePipelineState(uint32_t eventId)
|
||||
m_VulkanPipelineState.currentPass.framebuffer.attachments[i].numSlices =
|
||||
c.m_ImageView[viewid].range.layerCount;
|
||||
|
||||
memcpy(m_VulkanPipelineState.currentPass.framebuffer.attachments[i].swizzle,
|
||||
c.m_ImageView[viewid].swizzle, sizeof(TextureSwizzle) * 4);
|
||||
Convert(m_VulkanPipelineState.currentPass.framebuffer.attachments[i].swizzle,
|
||||
c.m_ImageView[viewid].componentMapping);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1737,7 +1762,7 @@ void VulkanReplay::SavePipelineState(uint32_t eventId)
|
||||
|
||||
el.ycbcrModel = ycbcr.ycbcrModel;
|
||||
el.ycbcrRange = ycbcr.ycbcrRange;
|
||||
memcpy(el.ycbcrSwizzle, ycbcr.swizzle, sizeof(TextureSwizzle) * 4);
|
||||
Convert(el.ycbcrSwizzle, ycbcr.componentMapping);
|
||||
el.xChromaOffset = ycbcr.xChromaOffset;
|
||||
el.yChromaOffset = ycbcr.yChromaOffset;
|
||||
el.chromaFilter = ycbcr.chromaFilter;
|
||||
@@ -1761,8 +1786,7 @@ void VulkanReplay::SavePipelineState(uint32_t eventId)
|
||||
dst.bindings[b].binds[a].viewFormat =
|
||||
MakeResourceFormat(c.m_ImageView[viewid].format);
|
||||
|
||||
memcpy(dst.bindings[b].binds[a].swizzle, c.m_ImageView[viewid].swizzle,
|
||||
sizeof(TextureSwizzle) * 4);
|
||||
Convert(dst.bindings[b].binds[a].swizzle, c.m_ImageView[viewid].componentMapping);
|
||||
dst.bindings[b].binds[a].firstMip = c.m_ImageView[viewid].range.baseMipLevel;
|
||||
dst.bindings[b].binds[a].firstSlice = c.m_ImageView[viewid].range.baseArrayLayer;
|
||||
dst.bindings[b].binds[a].numMips = c.m_ImageView[viewid].range.levelCount;
|
||||
|
||||
@@ -221,6 +221,15 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
~VulkanAPIWrapper()
|
||||
{
|
||||
m_pDriver->FlushQ();
|
||||
|
||||
VkDevice dev = m_pDriver->GetDev();
|
||||
for(auto it = m_SampleViews.begin(); it != m_SampleViews.end(); it++)
|
||||
m_pDriver->vkDestroyImageView(dev, it->second, NULL);
|
||||
}
|
||||
|
||||
virtual void AddDebugMessage(MessageCategory c, MessageSeverity sv, MessageSource src,
|
||||
rdcstr d) override
|
||||
{
|
||||
@@ -344,11 +353,43 @@ public:
|
||||
|
||||
// promote view to Array view
|
||||
|
||||
const VulkanCreationInfo::Image &imageProps =
|
||||
m_Creation.m_Image[m_Creation.m_ImageView[GetResID(view)].image];
|
||||
const VulkanCreationInfo::ImageView &viewProps = m_Creation.m_ImageView[GetResID(view)];
|
||||
const VulkanCreationInfo::Image &imageProps = m_Creation.m_Image[viewProps.image];
|
||||
VkImageType imageType = imageProps.type;
|
||||
uint32_t samples = (uint32_t)imageProps.samples;
|
||||
|
||||
VkDevice dev = m_pDriver->GetDev();
|
||||
|
||||
// create our own view (if we haven't already for this view) so we can promote to array
|
||||
VkImageView sampleView = m_SampleViews[GetResID(view)];
|
||||
if(sampleView == VK_NULL_HANDLE)
|
||||
{
|
||||
VkImageViewCreateInfo viewInfo = {VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO};
|
||||
viewInfo.image = m_pDriver->GetResourceManager()->GetCurrentHandle<VkImage>(viewProps.image);
|
||||
viewInfo.format = viewProps.format;
|
||||
viewInfo.viewType = viewProps.viewType;
|
||||
if(viewInfo.viewType == VK_IMAGE_VIEW_TYPE_1D)
|
||||
viewInfo.viewType = VK_IMAGE_VIEW_TYPE_1D_ARRAY;
|
||||
else if(viewInfo.viewType == VK_IMAGE_VIEW_TYPE_2D)
|
||||
viewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D_ARRAY;
|
||||
|
||||
viewInfo.components = viewProps.componentMapping;
|
||||
viewInfo.subresourceRange = viewProps.range;
|
||||
|
||||
// if KHR_maintenance2 is available, ensure we have sampled usage available
|
||||
VkImageViewUsageCreateInfo usageCreateInfo = {VK_STRUCTURE_TYPE_IMAGE_VIEW_USAGE_CREATE_INFO};
|
||||
if(m_pDriver->GetExtensions(NULL).ext_KHR_maintenance2)
|
||||
{
|
||||
usageCreateInfo.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
|
||||
viewInfo.pNext = &usageCreateInfo;
|
||||
}
|
||||
|
||||
VkResult vkr = m_pDriver->vkCreateImageView(dev, &viewInfo, NULL, &sampleView);
|
||||
RDCASSERTEQUAL(vkr, VK_SUCCESS);
|
||||
|
||||
m_SampleViews[GetResID(view)] = sampleView;
|
||||
}
|
||||
|
||||
params.operation = (uint32_t)opcode;
|
||||
|
||||
switch(imageType)
|
||||
@@ -414,7 +455,7 @@ public:
|
||||
|
||||
VkDescriptorImageInfo samplerWriteInfo = {Unwrap(sampler), VK_NULL_HANDLE,
|
||||
VK_IMAGE_LAYOUT_UNDEFINED};
|
||||
VkDescriptorImageInfo imageWriteInfo = {VK_NULL_HANDLE, Unwrap(view), layout};
|
||||
VkDescriptorImageInfo imageWriteInfo = {VK_NULL_HANDLE, Unwrap(sampleView), layout};
|
||||
|
||||
VkWriteDescriptorSet writeSets[] = {
|
||||
{
|
||||
@@ -434,8 +475,6 @@ public:
|
||||
writeSets[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
|
||||
}
|
||||
|
||||
VkDevice dev = m_pDriver->GetDev();
|
||||
|
||||
ObjDisp(dev)->UpdateDescriptorSets(Unwrap(dev), sampler != VK_NULL_HANDLE ? 2 : 1, writeSets, 0,
|
||||
NULL);
|
||||
|
||||
@@ -506,6 +545,8 @@ private:
|
||||
ShaderDebugData &m_DebugData;
|
||||
VulkanCreationInfo &m_Creation;
|
||||
|
||||
std::map<ResourceId, VkImageView> m_SampleViews;
|
||||
|
||||
std::map<rdcpair<uint32_t, uint32_t>, bytebuf> cbufferCache;
|
||||
template <typename T>
|
||||
const T &GetDescriptor(const rdcstr &access, BindpointIndex index, bool &valid)
|
||||
|
||||
Reference in New Issue
Block a user