- bind the layer textures

This commit is contained in:
Magnus Norddahl 2019-03-01 01:30:10 +01:00
parent 7f3e473f56
commit f1f8797d3c
4 changed files with 46 additions and 32 deletions

View file

@ -74,14 +74,11 @@ void VkRenderPassManager::CreateDynamicSetLayout()
void VkRenderPassManager::CreateTextureSetLayout()
{
DescriptorSetLayoutBuilder builder;
builder.addBinding(0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_FRAGMENT_BIT);
/*
for (int i = 0; i < 6; i++)
{
builder.addBinding(i, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_FRAGMENT_BIT);
}
builder.addBinding(16, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_FRAGMENT_BIT);
*/
TextureSetLayout = builder.create(GetVulkanFrameBuffer()->device);
}

View file

@ -78,12 +78,12 @@ static const char *shaderBindings = R"(
// textures
layout(set = 1, binding = 0) uniform sampler2D tex;
// layout(set = 1, binding = 1) uniform sampler2D texture2;
// layout(set = 1, binding = 2) uniform sampler2D texture3;
// layout(set = 1, binding = 3) uniform sampler2D texture4;
// layout(set = 1, binding = 4) uniform sampler2D texture5;
// layout(set = 1, binding = 5) uniform sampler2D texture6;
// layout(set = 1, binding = 16) uniform sampler2D ShadowMap;
layout(set = 1, binding = 1) uniform sampler2D texture2;
layout(set = 1, binding = 2) uniform sampler2D texture3;
layout(set = 1, binding = 3) uniform sampler2D texture4;
layout(set = 1, binding = 4) uniform sampler2D texture5;
layout(set = 1, binding = 5) uniform sampler2D texture6;
layout(set = 1, binding = 16) uniform sampler2D ShadowMap;
// This must match the PushConstants struct
layout(push_constant) uniform PushConstants

View file

@ -54,19 +54,48 @@ void VkHardwareTexture::Reset()
}
VulkanDescriptorSet *VkHardwareTexture::GetDescriptorSet(const FMaterialState &state)
{
if (!mDescriptorSet)
{
auto fb = GetVulkanFrameBuffer();
FMaterial *mat = state.mMaterial;
FTexture *tex = state.mMaterial->tex;
int clampmode = state.mClampMode;
int translation = state.mTranslation;
//if (tex->UseType == ETextureType::SWCanvas) clampmode = CLAMP_NOFILTER;
//if (tex->isHardwareCanvas()) clampmode = CLAMP_CAMTEX;
//else if ((tex->isWarped() || tex->shaderindex >= FIRST_USER_SHADER) && clampmode <= CLAMP_XY) clampmode = CLAMP_NONE;
// Textures that are already scaled in the texture lump will not get replaced by hires textures.
int flags = state.mMaterial->isExpanded() ? CTF_Expand : (gl_texture_usehires && !tex->isScaled() && clampmode <= CLAMP_XY) ? CTF_CheckHires : 0;
mDescriptorSet = fb->GetRenderPassManager()->DescriptorPool->allocate(fb->GetRenderPassManager()->TextureSetLayout.get());
VulkanSampler *sampler = fb->GetSamplerManager()->Get(clampmode);
int numLayers = mat->GetLayers();
WriteDescriptors update;
update.addCombinedImageSampler(mDescriptorSet.get(), 0, GetImageView(tex, clampmode, translation, flags), sampler, mImageLayout);
for (int i = 1; i < numLayers; i++)
{
FTexture *layer;
auto systex = static_cast<VkHardwareTexture*>(mat->GetLayer(i, 0, &layer));
update.addCombinedImageSampler(mDescriptorSet.get(), i, systex->GetImageView(layer, clampmode, 0, mat->isExpanded() ? CTF_Expand : 0), sampler, mImageLayout);
}
update.updateSets(fb->device);
}
return mDescriptorSet.get();
}
VulkanImageView *VkHardwareTexture::GetImageView(FTexture *tex, int clampmode, int translation, int flags)
{
if (!mImage)
{
FTexture *tex = state.mMaterial->tex;
if (!tex->isHardwareCanvas())
{
int clampmode = state.mClampMode;
//if (tex->UseType == ETextureType::SWCanvas) clampmode = CLAMP_NOFILTER;
//if (tex->isHardwareCanvas()) clampmode = CLAMP_CAMTEX;
//else if ((tex->isWarped() || tex->shaderindex >= FIRST_USER_SHADER) && clampmode <= CLAMP_XY) clampmode = CLAMP_NONE;
int translation = state.mTranslation;
if (translation <= 0)
{
translation = -translation;
@ -79,9 +108,6 @@ VulkanDescriptorSet *VkHardwareTexture::GetDescriptorSet(const FMaterialState &s
bool needmipmap = (clampmode <= CLAMP_XY);
// Textures that are already scaled in the texture lump will not get replaced by hires textures.
int flags = state.mMaterial->isExpanded() ? CTF_Expand : (gl_texture_usehires && !tex->isScaled() && clampmode <= CLAMP_XY) ? CTF_CheckHires : 0;
FTextureBuffer texbuffer = tex->CreateTexBuffer(translation, flags | CTF_ProcessData);
CreateTexture(texbuffer.mWidth, texbuffer.mHeight, 4, VK_FORMAT_B8G8R8A8_UNORM, texbuffer.mBuffer);
}
@ -97,18 +123,7 @@ VulkanDescriptorSet *VkHardwareTexture::GetDescriptorSet(const FMaterialState &s
CreateTexture(4, 4, 4, VK_FORMAT_R8G8B8A8_UNORM, testpixels);
}
}
if (!mDescriptorSet)
{
auto fb = GetVulkanFrameBuffer();
mDescriptorSet = fb->GetRenderPassManager()->DescriptorPool->allocate(fb->GetRenderPassManager()->TextureSetLayout.get());
WriteDescriptors update;
update.addCombinedImageSampler(mDescriptorSet.get(), 0, mImageView.get(), fb->GetSamplerManager()->Get(0), mImageLayout);
update.updateSets(fb->device);
}
return mDescriptorSet.get();
return mImageView.get();
}
void VkHardwareTexture::CreateTexture(int w, int h, int pixelsize, VkFormat format, const void *pixels)

View file

@ -33,6 +33,8 @@ public:
unsigned int CreateTexture(unsigned char * buffer, int w, int h, int texunit, bool mipmap, int translation, const char *name) override;
private:
VulkanImageView *GetImageView(FTexture *tex, int clampmode, int translation, int flags);
void CreateTexture(int w, int h, int pixelsize, VkFormat format, const void *pixels);
void GenerateMipmaps(VulkanImage *image, VulkanCommandBuffer *cmdbuffer);
static int GetMipLevels(int w, int h);