textures
This commit is contained in:
@@ -3,7 +3,7 @@ CVkMaterial::CVkMaterial( IShader *pShader )
|
||||
{
|
||||
m_pVkShader = (CVkShader*)pShader;
|
||||
|
||||
VkDescriptorPoolSize pools[2] =
|
||||
VkDescriptorPoolSize pools[4] =
|
||||
{
|
||||
{
|
||||
VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
|
||||
@@ -12,43 +12,31 @@ CVkMaterial::CVkMaterial( IShader *pShader )
|
||||
{
|
||||
VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
||||
128,
|
||||
},
|
||||
{
|
||||
VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
|
||||
128,
|
||||
},
|
||||
{
|
||||
VK_DESCRIPTOR_TYPE_SAMPLER,
|
||||
1,
|
||||
}
|
||||
};
|
||||
VkDescriptorPoolCreateInfo stPool = {};
|
||||
stPool.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
|
||||
stPool.poolSizeCount = 2;
|
||||
stPool.poolSizeCount = 4;
|
||||
stPool.pPoolSizes = pools;
|
||||
stPool.maxSets = 1;
|
||||
stPool.maxSets = 16;
|
||||
stPool.flags = VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT_EXT;
|
||||
vkCreateDescriptorPool(m_pVkShader->m_hDevice, &stPool, NULL, &m_hPool);
|
||||
|
||||
VkDescriptorSetAllocateInfo stInfo = {};
|
||||
stInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
|
||||
stInfo.descriptorSetCount = 1;
|
||||
stInfo.descriptorPool = m_hPool;
|
||||
stInfo.descriptorSetCount = m_pVkShader->m_setLayouts.GetSize();
|
||||
stInfo.pSetLayouts = m_pVkShader->m_setLayouts.GetData();
|
||||
vkAllocateDescriptorSets(m_pVkShader->m_hDevice, &stInfo, &m_hSet);
|
||||
|
||||
for ( auto b: m_pVkShader->m_bindings )
|
||||
{
|
||||
VkWriteDescriptorSet write = {};
|
||||
write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
|
||||
write.dstSet = m_hSet;
|
||||
write.dstBinding = b.uBinding;
|
||||
write.dstArrayElement = 0;
|
||||
write.descriptorType = b.eDescriptorType;
|
||||
write.descriptorCount = 1;
|
||||
switch (b.eDescriptorType)
|
||||
{
|
||||
case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
|
||||
case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
|
||||
write.pBufferInfo = new VkDescriptorBufferInfo;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
};
|
||||
m_writes.AppendTail(write);
|
||||
}
|
||||
m_hSets.Resize(m_pVkShader->m_setLayouts.GetSize());
|
||||
vkAllocateDescriptorSets(m_pVkShader->m_hDevice, &stInfo, m_hSets.GetData());
|
||||
}
|
||||
|
||||
CVkMaterial::~CVkMaterial()
|
||||
@@ -63,22 +51,27 @@ void CVkMaterial::Frame()
|
||||
|
||||
void CVkMaterial::VSSetShaderResource( uint32_t uRegister, IRenderingObject *pResource )
|
||||
{
|
||||
SetShaderResource(uRegister, SHADER_STAGE_VERTEX, pResource);
|
||||
SetShaderResource(uRegister, 0, pResource);
|
||||
}
|
||||
|
||||
void CVkMaterial::PSSetShaderResource( uint32_t uRegister, IRenderingObject *pResource )
|
||||
{
|
||||
SetShaderResource(uRegister, SHADER_STAGE_PIXEL, pResource);
|
||||
SetShaderResource(uRegister, 0, pResource);
|
||||
}
|
||||
|
||||
void CVkMaterial::VSSetConstantsBuffer( uint32_t uRegister, IBuffer *pConstants )
|
||||
{
|
||||
SetShaderResource(uRegister, SHADER_STAGE_VERTEX, pConstants);
|
||||
SetShaderResource(uRegister, 0, pConstants);
|
||||
}
|
||||
|
||||
void CVkMaterial::PSSetConstantsBuffer( uint32_t uRegister, IBuffer *pConstants )
|
||||
{
|
||||
SetShaderResource(uRegister, SHADER_STAGE_PIXEL, pConstants);
|
||||
SetShaderResource(uRegister, 0, pConstants);
|
||||
}
|
||||
|
||||
void CVkMaterial::PSSetTextureArray( uint32_t uSet, ITextureArray *pArray )
|
||||
{
|
||||
SetShaderResource(0, uSet, pArray);
|
||||
}
|
||||
|
||||
void CVkMaterial::SetShaderResource( uint32_t uRegister, uint32_t uSet, IRenderingObject *pObject)
|
||||
@@ -86,13 +79,65 @@ void CVkMaterial::SetShaderResource( uint32_t uRegister, uint32_t uSet, IRenderi
|
||||
union {
|
||||
IRenderingObject *pVkObject;
|
||||
CVkBuffer *pBuffer;
|
||||
CVkTextureArray *pArray;
|
||||
};
|
||||
pVkObject = pObject;
|
||||
if (dynamic_cast<IBuffer*>(pObject))
|
||||
{
|
||||
((VkDescriptorBufferInfo*)m_writes[uRegister].pBufferInfo)->buffer = pBuffer->m_buffer;
|
||||
((VkDescriptorBufferInfo*)m_writes[uRegister].pBufferInfo)->range = pBuffer->m_nSize;
|
||||
VkWriteDescriptorSet write = {};
|
||||
VkDescriptorBufferInfo stInfo = {};
|
||||
write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
|
||||
write.dstSet = m_hSets[uSet];
|
||||
write.dstBinding = uRegister;
|
||||
write.dstArrayElement = 0;
|
||||
write.descriptorType = pBuffer->m_eDescriptorType;
|
||||
write.descriptorCount = 1;
|
||||
write.pBufferInfo = &stInfo;
|
||||
stInfo.buffer = pBuffer->m_buffer;
|
||||
stInfo.range = pBuffer->m_nSize;
|
||||
vkUpdateDescriptorSets(m_pVkShader->m_hDevice, 1, &write, 0, 0);
|
||||
}
|
||||
if (dynamic_cast<ITextureArray*>(pObject))
|
||||
{
|
||||
VkWriteDescriptorSet writes[2] = {};
|
||||
VkDescriptorImageInfo stWrites[128];
|
||||
VkDescriptorImageInfo stSampler = {};
|
||||
|
||||
for ( int i = 0; i < 128; i++ )
|
||||
{
|
||||
if (pArray->m_pImages[i] == NULL)
|
||||
{
|
||||
stWrites[i] = {
|
||||
.imageView = pArray->m_pImages[0]->m_imageView,
|
||||
.imageLayout = VK_IMAGE_LAYOUT_GENERAL,
|
||||
};
|
||||
continue;
|
||||
}
|
||||
stWrites[i] = {
|
||||
.imageView = pArray->m_pImages[i]->m_imageView,
|
||||
.imageLayout = VK_IMAGE_LAYOUT_GENERAL,
|
||||
};
|
||||
}
|
||||
|
||||
writes[0] = {};
|
||||
writes[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
|
||||
writes[0].dstSet = m_hSets[uSet];
|
||||
writes[0].dstBinding = 0;
|
||||
writes[0].dstArrayElement = 0;
|
||||
writes[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
|
||||
writes[0].descriptorCount = 1;
|
||||
writes[0].pImageInfo = &stSampler;
|
||||
stSampler.sampler = pArray->m_hSampler;
|
||||
|
||||
writes[1] = {};
|
||||
writes[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
|
||||
writes[1].dstSet = m_hSets[uSet];
|
||||
writes[1].dstBinding = 1;
|
||||
writes[1].dstArrayElement = 0;
|
||||
writes[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
|
||||
writes[1].descriptorCount = 128;
|
||||
writes[1].pImageInfo = stWrites;
|
||||
vkUpdateDescriptorSets(m_pVkShader->m_hDevice, 2, writes, 0, 0);
|
||||
}
|
||||
vkUpdateDescriptorSets(m_pVkShader->m_hDevice, 1, &m_writes[uRegister], 0, 0);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user