Hook up bindless textures for gl_levelmesh

This commit is contained in:
Magnus Norddahl 2023-10-23 19:52:47 +02:00
commit f550f5b05a
12 changed files with 51 additions and 10 deletions

View file

@ -312,7 +312,7 @@ void VkRaytrace::UploadMeshes(bool dynamicOnly)
}
else
{
info.TextureIndex = -1;
info.TextureIndex = 0;
}
submesh->MeshSurfaceUniforms[j].uTextureIndex = info.TextureIndex; // Bit of a hack, but we don't know the texture index before now

View file

@ -141,6 +141,9 @@ void VkDescriptorSetManager::ResetHWTextureSets()
Bindless.Writer = WriteDescriptors();
Bindless.NextIndex = 0;
// Slot zero always needs to be the null texture
AddBindlessTextureIndex(fb->GetTextureManager()->GetNullTextureView(), fb->GetSamplerManager()->Get(CLAMP_XY_NOMIP));
}
VulkanDescriptorSet* VkDescriptorSetManager::GetNullTextureSet()

View file

@ -151,7 +151,9 @@ VulkanPipelineLayout* VkRenderPassManager::GetPipelineLayout(int numLayers, bool
PipelineLayoutBuilder builder;
builder.AddSetLayout(descriptors->GetFixedLayout());
builder.AddSetLayout(levelmesh ? descriptors->GetLevelMeshLayout() : descriptors->GetRSBufferLayout());
if (numLayers != 0)
if (levelmesh)
builder.AddSetLayout(descriptors->GetBindlessLayout());
else if (numLayers != 0)
builder.AddSetLayout(descriptors->GetTextureLayout(numLayers));
builder.AddPushConstantRange(VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0, sizeof(PushConstants));
builder.DebugName("VkRenderPassManager.PipelineLayout");

View file

@ -321,6 +321,7 @@ FString VkShaderManager::GetVersionBlock()
}
versionBlock << "#extension GL_GOOGLE_include_directive : enable\n";
versionBlock << "#extension GL_EXT_nonuniform_qualifier : enable\r\n";
if (fb->GetDevice()->SupportsExtension(VK_KHR_RAY_QUERY_EXTENSION_NAME) && fb->GetDevice()->PhysicalDevice.Features.RayQuery.rayQuery)
{

View file

@ -218,7 +218,7 @@ void VkTextureManager::CreateLightmap(int newLMTextureSize, int newLMTextureCoun
auto cmdbuffer = fb->GetCommands()->GetTransferCommands();
if (newPixelData.Size() >= (size_t)w * h * count * 3)
if (count > 0 && newPixelData.Size() >= (size_t)w * h * count * 3)
{
assert(newPixelData.Size() == (size_t)w * h * count * 3);

View file

@ -163,6 +163,7 @@ VulkanRenderDevice::~VulkanRenderDevice()
if (mDescriptorSetManager)
mDescriptorSetManager->Deinit();
mCommands->DeleteFrameObjects();
if (mTextureManager)
mTextureManager->Deinit();
if (mBufferManager)
@ -715,7 +716,7 @@ void VulkanRenderDevice::DrawLevelMesh(const HWViewpointUniforms& viewpoint)
uint32_t offsets[] = { viewpointOffset, matrixOffset, lightsOffset };
cmdbuffer->bindDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, layout, 0, descriptors->GetFixedSet());
cmdbuffer->bindDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, layout, 1, descriptors->GetLevelMeshSet(), 3, offsets);
cmdbuffer->bindDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, layout, 2, descriptors->GetNullTextureSet());
cmdbuffer->bindDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, layout, 2, descriptors->GetBindlessSet());
PushConstants pushConstants = {};
pushConstants.uDataIndex = 0;

View file

@ -567,14 +567,12 @@ void DoomLevelSubmesh::BindLightmapSurfacesToGeometry(FLevelLocals& doomMap)
if (surface.Type == ST_FLOOR || surface.Type == ST_CEILING)
{
surface.Subsector = &doomMap.subsectors[surface.TypeIndex];
if (surface.Subsector->firstline && surface.Subsector->firstline->sidedef)
surface.Subsector->firstline->sidedef->sector->HasLightmaps = true;
SetSubsectorLightmap(&surface);
}
else
{
surface.Side = &doomMap.sides[surface.TypeIndex];
SetSideLightmap(&surface);
}
}
@ -662,6 +660,7 @@ void DoomLevelSubmesh::CreateLinePortalSurface(FLevelLocals& doomMap, side_t* si
surf.sampleDimension = side->textures[side_t::mid].LightmapSampleDistance;
surf.startVertIndex = MeshVertices.Size();
surf.numVerts = 4;
surf.Side = side;
MeshVertices.Push(verts[0]);
MeshVertices.Push(verts[1]);
@ -756,6 +755,7 @@ void DoomLevelSubmesh::CreateLineHorizonSurface(FLevelLocals& doomMap, side_t* s
surf.TypeIndex = side->Index();
surf.bSky = front->GetTexture(sector_t::floor) == skyflatnum || front->GetTexture(sector_t::ceiling) == skyflatnum;
surf.sampleDimension = side->textures[side_t::mid].LightmapSampleDistance;
surf.Side = side;
FFlatVertex verts[4];
verts[0].x = verts[2].x = v1.X;
@ -847,6 +847,7 @@ void DoomLevelSubmesh::CreateFrontWallSurface(FLevelLocals& doomMap, side_t* sid
surf.sectorGroup = sectorGroup[front->Index()];
surf.texture = side->textures[side_t::mid].texture;
surf.AlwaysUpdate = !!(front->Flags & SECF_LM_DYNAMIC);
surf.Side = side;
SurfaceUniforms uniforms = DefaultUniforms();
uniforms.uLightLevel = front->lightlevel;
@ -946,6 +947,7 @@ void DoomLevelSubmesh::CreateMidWallSurface(FLevelLocals& doomMap, side_t* side)
surf.texture = texture;
surf.alpha = float(side->linedef->alpha);
surf.AlwaysUpdate = !!(front->Flags & SECF_LM_DYNAMIC);
surf.Side = side;
SurfaceUniforms uniforms = DefaultUniforms();
uniforms.uLightLevel = front->lightlevel;
@ -993,6 +995,7 @@ void DoomLevelSubmesh::Create3DFloorWallSurfaces(FLevelLocals& doomMap, side_t*
surf.ControlSector = xfloor->model;
surf.bSky = false;
surf.sampleDimension = side->textures[side_t::mid].LightmapSampleDistance;
surf.Side = side;
float blZ = (float)xfloor->model->floorplane.ZatPoint(v1);
float brZ = (float)xfloor->model->floorplane.ZatPoint(v2);
@ -1088,6 +1091,7 @@ void DoomLevelSubmesh::CreateTopWallSurface(FLevelLocals& doomMap, side_t* side)
surf.sectorGroup = sectorGroup[front->Index()];
surf.texture = side->textures[side_t::top].texture;
surf.AlwaysUpdate = !!(front->Flags & SECF_LM_DYNAMIC);
surf.Side = side;
SurfaceUniforms uniforms = DefaultUniforms();
uniforms.uLightLevel = front->lightlevel;
@ -1148,6 +1152,7 @@ void DoomLevelSubmesh::CreateBottomWallSurface(FLevelLocals& doomMap, side_t* si
surf.sectorGroup = sectorGroup[front->Index()];
surf.texture = side->textures[side_t::bottom].texture;
surf.AlwaysUpdate = !!(front->Flags & SECF_LM_DYNAMIC);
surf.Side = side;
SurfaceUniforms uniforms = DefaultUniforms();
uniforms.uLightLevel = front->lightlevel;
@ -1250,6 +1255,7 @@ void DoomLevelSubmesh::CreateFloorSurface(FLevelLocals &doomMap, subsector_t *su
surf.plane = FVector4((float)plane.Normal().X, (float)plane.Normal().Y, (float)plane.Normal().Z, -(float)plane.D);
surf.sectorGroup = sectorGroup[sector->Index()];
surf.AlwaysUpdate = !!(sector->Flags & SECF_LM_DYNAMIC);
surf.Subsector = sub;
SurfaceUniforms uniforms = DefaultUniforms();
uniforms.uLightLevel = sector->lightlevel;
@ -1309,6 +1315,7 @@ void DoomLevelSubmesh::CreateCeilingSurface(FLevelLocals& doomMap, subsector_t*
surf.plane = FVector4((float)plane.Normal().X, (float)plane.Normal().Y, (float)plane.Normal().Z, -(float)plane.D);
surf.sectorGroup = sectorGroup[sector->Index()];
surf.AlwaysUpdate = !!(sector->Flags & SECF_LM_DYNAMIC);
surf.Subsector = sub;
SurfaceUniforms uniforms = DefaultUniforms();
uniforms.uLightLevel = sector->lightlevel;

View file

@ -53,7 +53,7 @@ public:
void BindLightmapSurfacesToGeometry(FLevelLocals& doomMap);
void PackLightmapAtlas(int lightmapStartIndex);
void CreatePortals();
void DisableLightmaps() { Surfaces.Clear(); } // Temp hack that disables lightmapping
void DisableLightmaps() { /*Surfaces.Clear();*/ } // Temp hack that disables lightmapping
TArray<DoomLevelMeshSurface> Surfaces;
TArray<int> sectorGroup; // index is sector, value is sectorGroup

View file

@ -25,7 +25,7 @@ int TraceFirstHitTriangleT(vec3 origin, float tmin, vec3 dir, float tmax, out fl
int index = primitiveID * 3;
vec2 uv = vertices[elements[index + 1]].uv * primitiveWeights.x + vertices[elements[index + 2]].uv * primitiveWeights.y + vertices[elements[index + 0]].uv * primitiveWeights.z;
if (surface.TextureIndex < 0)
if (surface.TextureIndex == 0)
{
break;
}
@ -88,7 +88,7 @@ bool TracePoint(vec3 origin, vec3 target, float tmin, vec3 dir, float tmax)
int index = primitiveID * 3;
vec2 uv = vertices[elements[index + 1]].uv * primitiveWeights.x + vertices[elements[index + 2]].uv * primitiveWeights.y + vertices[elements[index + 0]].uv * primitiveWeights.z;
if (surface.TextureIndex < 0)
if (surface.TextureIndex == 0)
{
break;
}

View file

@ -1,4 +1,22 @@
#ifdef USE_LEVELMESH
layout(set = 2, binding = 0) uniform sampler2D textures[];
#define tex 0
#define texture2 1
#define texture3 2
#define texture4 3
#define texture5 4
#define texture6 5
#define texture7 6
#define texture8 7
#define texture9 8
#define texture10 9
#define texture11 10
#else
// textures
layout(set = 2, binding = 0) uniform sampler2D tex;
layout(set = 2, binding = 1) uniform sampler2D texture2;
@ -11,3 +29,5 @@ layout(set = 2, binding = 7) uniform sampler2D texture8;
layout(set = 2, binding = 8) uniform sampler2D texture9;
layout(set = 2, binding = 9) uniform sampler2D texture10;
layout(set = 2, binding = 10) uniform sampler2D texture11;
#endif

View file

@ -10,7 +10,7 @@ void main()
{
FragColor = vec4(vec3(pixelpos.w / 1000), 1.0);
}*/
FragColor.rgb = vec3(uLightLevel / 255.0);
FragColor.rgb = texture(tex, vTexCoord.st).rgb * (uLightLevel / 255.0);
FragColor.a = 1.0;
#else

View file

@ -25,3 +25,10 @@ layout(location=0) out vec4 FragColor;
layout(location=1) out vec4 FragFog;
layout(location=2) out vec4 FragNormal;
#endif
#if defined(USE_LEVELMESH)
vec4 texture(int index, vec2 p)
{
return texture(textures[uTextureIndex + index], p);
}
#endif