Skip to content

Commit f182936

Browse files
committed
Merge branch 'master' of https://github.com/dpjudas/VkDoom into gzdoom_unstable
2 parents 948cd13 + 1d2a496 commit f182936

File tree

9 files changed

+48
-35
lines changed

9 files changed

+48
-35
lines changed

libraries/ZVulkan/src/vulkaninstance.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,10 +351,13 @@ VkBool32 VulkanInstance::DebugCallback(VkDebugUtilsMessageSeverityFlagBitsEXT me
351351
if (parts.size() == 3)
352352
{
353353
msg = parts[2];
354-
size_t pos = msg.find(" The Vulkan spec states:");
354+
size_t pos = msg.find("The Vulkan spec states:");
355355
if (pos != std::string::npos)
356356
msg = msg.substr(0, pos);
357357

358+
while (!msg.empty() && (msg.back() == '\n' || msg.back() == '\r' || msg.back() == ' '))
359+
msg.pop_back();
360+
358361
if (callbackData->objectCount > 0)
359362
{
360363
msg += " (";

src/common/rendering/vulkan/descriptorsets/vk_descriptorset.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ void VkDescriptorSetManager::Init()
7373
.AddBuffer(RSBuffer.Set.get(), 0, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, rsbuffers->Viewpoint.UBO.get(), 0, sizeof(HWViewpointUniforms))
7474
.AddBuffer(RSBuffer.Set.get(), 1, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, rsbuffers->MatrixBuffer->UBO(), 0, sizeof(MatricesUBO))
7575
.AddBuffer(RSBuffer.Set.get(), 2, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, rsbuffers->SurfaceUniformsBuffer->UBO(), 0, sizeof(SurfaceUniformsUBO))
76-
.AddBuffer(RSBuffer.Set.get(), 3, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, rsbuffers->Lightbuffer.SSO.get(), 0, sizeof(LightBufferSSO))
76+
.AddBuffer(RSBuffer.Set.get(), 3, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, rsbuffers->Lightbuffer.SSO.get(), 0, sizeof(LightBufferSSO))
7777
.AddBuffer(RSBuffer.Set.get(), 4, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, rsbuffers->Fogballbuffer.UBO.get(), 0, sizeof(FogballBufferUBO))
7878
.AddBuffer(RSBuffer.Set.get(), 5, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, rsbuffers->Bonebuffer.SSO.get())
7979
.Execute(fb->GetDevice());
@@ -263,7 +263,7 @@ void VkDescriptorSetManager::CreateRSBufferLayout()
263263
.AddBinding(0, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, 1, VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT)
264264
.AddBinding(1, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, 1, VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT)
265265
.AddBinding(2, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, 1, VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT)
266-
.AddBinding(3, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT)
266+
.AddBinding(3, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, 1, VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT)
267267
.AddBinding(4, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, 1, VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT)
268268
.AddBinding(5, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_VERTEX_BIT)
269269
.DebugName("VkDescriptorSetManager.RSBuffer.Layout")

src/common/rendering/vulkan/pipelines/vk_renderpass.cpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ std::unique_ptr<VulkanPipeline> VkRenderPassSetup::CreatePipeline(const VkPipeli
309309
if (program->frag)
310310
builder.AddFragmentShader(program->frag.get());
311311

312-
const VkVertexFormat &vfmt = *fb->GetRenderPassManager()->GetVertexFormat(key.VertexFormat);
312+
const VkVertexFormat &vfmt = *fb->GetRenderPassManager()->GetVertexFormat(key.ShaderKey.VertexFormat);
313313

314314
for (int i = 0; i < vfmt.BufferStrides.size(); i++)
315315
builder.AddVertexBufferBinding(i, vfmt.BufferStrides[i]);
@@ -325,20 +325,10 @@ std::unique_ptr<VulkanPipeline> VkRenderPassSetup::CreatePipeline(const VkPipeli
325325
VK_FORMAT_R32_SINT
326326
};
327327

328-
bool inputLocations[VATTR_MAX] = {};
329-
330328
for (size_t i = 0; i < vfmt.Attrs.size(); i++)
331329
{
332330
const auto &attr = vfmt.Attrs[i];
333331
builder.AddVertexAttribute(attr.location, attr.binding, vkfmts[attr.format], attr.offset);
334-
inputLocations[attr.location] = true;
335-
}
336-
337-
// Vulkan requires an attribute binding for each location specified in the shader
338-
for (int i = 0; i < VATTR_MAX; i++)
339-
{
340-
if (!inputLocations[i])
341-
builder.AddVertexAttribute(i, 0, i != 8 ? VK_FORMAT_R32G32B32_SFLOAT : VK_FORMAT_R8G8B8A8_UINT, 0);
342332
}
343333

344334
builder.AddDynamicState(VK_DYNAMIC_STATE_VIEWPORT);

src/common/rendering/vulkan/pipelines/vk_renderpass.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,22 @@ class VkPipelineKey
4040
uint64_t AsQWORD = 0;
4141
};
4242

43-
int VertexFormat = 0;
44-
int Padding0 = 0;
43+
int Padding1 = 0;
44+
int Padding2 = 0;
4545

4646
VkShaderKey ShaderKey;
4747
FRenderStyle RenderStyle;
4848

49-
int Padding1 = 0; // for 64 bit alignment
49+
int Padding3 = 0; // for 64 bit alignment
5050

5151
bool operator<(const VkPipelineKey &other) const { return memcmp(this, &other, sizeof(VkPipelineKey)) < 0; }
5252
bool operator==(const VkPipelineKey &other) const { return memcmp(this, &other, sizeof(VkPipelineKey)) == 0; }
5353
bool operator!=(const VkPipelineKey &other) const { return memcmp(this, &other, sizeof(VkPipelineKey)) != 0; }
5454
};
5555

5656
static_assert(sizeof(FRenderStyle) == 4, "sizeof(FRenderStyle) is not its expected size!");
57-
static_assert(sizeof(VkShaderKey) == 16, "sizeof(VkShaderKey) is not its expected size!");
58-
static_assert(sizeof(VkPipelineKey) == 16 + 16 + 8, "sizeof(VkPipelineKey) is not its expected size!"); // If this assert fails, the flags union no longer adds up to 64 bits. Or there are gaps in the class so the memcmp doesn't work.
57+
static_assert(sizeof(VkShaderKey) == 24, "sizeof(VkShaderKey) is not its expected size!");
58+
static_assert(sizeof(VkPipelineKey) == 16 + 24 + 8, "sizeof(VkPipelineKey) is not its expected size!"); // If this assert fails, the flags union no longer adds up to 64 bits. Or there are gaps in the class so the memcmp doesn't work.
5959

6060
class VkRenderPassKey
6161
{

src/common/rendering/vulkan/shaders/vk_shader.cpp

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "vk_shader.h"
2424
#include "vk_ppshader.h"
2525
#include "vulkan/vk_renderdevice.h"
26+
#include "vulkan/pipelines/vk_renderpass.h"
2627
#include <zvulkan/vulkanbuilders.h>
2728
#include "hw_shaderpatcher.h"
2829
#include "filesystem.h"
@@ -224,7 +225,17 @@ static std::vector<BuiltinFieldDesc> fragShaderOutputs
224225
{"FragNormal", "", UniformType::Vec4, FieldCondition::GBUFFER_PASS}, //2
225226
};
226227

227-
void AddFields(FString &layoutBlock, int &index, bool is_in, const std::vector<VaryingFieldDesc> &fields)
228+
static void AddVertexInFields(VulkanRenderDevice* fb, FString& layoutBlock, const VkShaderKey& key)
229+
{
230+
const VkVertexFormat& vfmt = *fb->GetRenderPassManager()->GetVertexFormat(key.VertexFormat);
231+
for (const FVertexBufferAttribute& attr : vfmt.Attrs)
232+
{
233+
const VaryingFieldDesc& desc = vertexShaderInputs[attr.location];
234+
layoutBlock.AppendFormat("layout(location = %d) %s %s %s %s;\n", attr.location, desc.Property.GetChars(), "in", GetTypeStr(desc.Type), desc.Name.GetChars());
235+
}
236+
}
237+
238+
static void AddFields(FString &layoutBlock, int &index, bool is_in, const std::vector<VaryingFieldDesc> &fields)
228239
{
229240
for(auto &field : fields)
230241
{
@@ -233,7 +244,7 @@ void AddFields(FString &layoutBlock, int &index, bool is_in, const std::vector<V
233244
}
234245
}
235246

236-
void AddBuiltinFields(FString &layoutBlock, int &index, bool is_in, const std::vector<BuiltinFieldDesc> &fields, const VkShaderKey& key, bool hasClipDistance)
247+
static void AddBuiltinFields(FString &layoutBlock, int &index, bool is_in, const std::vector<BuiltinFieldDesc> &fields, const VkShaderKey& key, bool hasClipDistance)
237248
{
238249
for(auto &field : fields)
239250
{
@@ -294,8 +305,7 @@ void VkShaderManager::BuildLayoutBlock(FString &layoutBlock, bool isFrag, const
294305

295306
if(!isFrag)
296307
{
297-
int index = 0;
298-
AddFields(layoutBlock, index, true, vertexShaderInputs);
308+
AddVertexInFields(fb, layoutBlock, key);
299309
}
300310

301311
{
@@ -314,11 +324,6 @@ void VkShaderManager::BuildLayoutBlock(FString &layoutBlock, bool isFrag, const
314324
int index = 0;
315325
AddBuiltinFields(layoutBlock, index, false, fragShaderOutputs, key, hasClipDistance);
316326
}
317-
318-
layoutBlock << "#line 1\n";
319-
320-
layoutBlock << LoadPrivateShaderLump("shaders/scene/layout_shared.glsl").GetChars() << "\n";
321-
322327
}
323328

324329
void VkShaderManager::BuildDefinesBlock(FString &definesBlock, const char *defines, bool isFrag, const VkShaderKey& key, const UserShaderDesc *shader)
@@ -426,6 +431,19 @@ void VkShaderManager::BuildDefinesBlock(FString &definesBlock, const char *defin
426431
if (key.UseSpriteCenter) definesBlock << "#define USE_SPRITE_CENTER\n";
427432

428433
definesBlock << ((key.Simple2D) ? "#define uFogEnabled -3\n" : "#define uFogEnabled 0\n");
434+
435+
// Setup fake variables for the 'in' attributes that aren't actually available because the garbage shader code thinks they exist
436+
// God I hate this engine... :(
437+
std::vector<bool> definedFields(vertexShaderInputs.size());
438+
bool hasNormal = false;
439+
const VkVertexFormat& vfmt = *fb->GetRenderPassManager()->GetVertexFormat(key.VertexFormat);
440+
for (const FVertexBufferAttribute& attr : vfmt.Attrs)
441+
definedFields[attr.location] = true;
442+
for (size_t i = 0; i < vertexShaderInputs.size(); i++)
443+
{
444+
if (!definedFields[i])
445+
definesBlock << "#define " << vertexShaderInputs[i].Name << " " << GetTypeStr(vertexShaderInputs[i].Type) << "(0)\n";
446+
}
429447
}
430448

431449
std::unique_ptr<VulkanShader> VkShaderManager::LoadVertShader(FString shadername, const char *vert_lump, const char *vert_lump_custom, const char *defines, const VkShaderKey& key, const UserShaderDesc *shader)
@@ -436,7 +454,6 @@ std::unique_ptr<VulkanShader> VkShaderManager::LoadVertShader(FString shadername
436454
FString layoutBlock;
437455
BuildLayoutBlock(layoutBlock, false, key, shader);
438456

439-
440457
FString codeBlock;
441458
codeBlock << LoadPrivateShaderLump(vert_lump).GetChars() << "\n";
442459
if(vert_lump_custom)
@@ -454,7 +471,8 @@ std::unique_ptr<VulkanShader> VkShaderManager::LoadVertShader(FString shadername
454471
.DebugName(shadername.GetChars())
455472
.AddSource("VersionBlock", GetVersionBlock().GetChars())
456473
.AddSource("DefinesBlock", definesBlock.GetChars())
457-
.AddSource("shaders/scene/layout_shared.glsl", layoutBlock.GetChars())
474+
.AddSource("LayoutBlock", layoutBlock.GetChars())
475+
.AddSource("shaders/scene/layout_shared.glsl", LoadPrivateShaderLump("shaders/scene/layout_shared.glsl").GetChars())
458476
.AddSource(vert_lump_custom ? vert_lump_custom : vert_lump, codeBlock.GetChars())
459477
.OnIncludeLocal([=](std::string headerName, std::string includerName, size_t depth) { return OnInclude(headerName.c_str(), includerName.c_str(), depth, false); })
460478
.OnIncludeSystem([=](std::string headerName, std::string includerName, size_t depth) { return OnInclude(headerName.c_str(), includerName.c_str(), depth, true); })
@@ -469,7 +487,6 @@ std::unique_ptr<VulkanShader> VkShaderManager::LoadFragShader(FString shadername
469487
FString layoutBlock;
470488
BuildLayoutBlock(layoutBlock, true, key, shader);
471489

472-
473490
FString codeBlock;
474491
codeBlock << LoadPrivateShaderLump(frag_lump).GetChars() << "\n";
475492

@@ -554,6 +571,7 @@ std::unique_ptr<VulkanShader> VkShaderManager::LoadFragShader(FString shadername
554571
.AddSource("VersionBlock", GetVersionBlock().GetChars())
555572
.AddSource("DefinesBlock", definesBlock.GetChars())
556573
.AddSource("LayoutBlock", layoutBlock.GetChars())
574+
.AddSource("shaders/scene/layout_shared.glsl", LoadPrivateShaderLump("shaders/scene/layout_shared.glsl").GetChars())
557575
.AddSource("shaders/scene/includes.glsl", LoadPrivateShaderLump("shaders/scene/includes.glsl").GetChars())
558576
.AddSource(mateffectname.GetChars(), mateffectBlock.GetChars())
559577
.AddSource(materialname.GetChars(), materialBlock.GetChars())

src/common/rendering/vulkan/shaders/vk_shader.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,15 @@ class VkShaderKey
118118

119119
int SpecialEffect = 0;
120120
int EffectState = 0;
121+
int VertexFormat = 0;
122+
int Padding = 0;
121123

122124
bool operator<(const VkShaderKey& other) const { return memcmp(this, &other, sizeof(VkShaderKey)) < 0; }
123125
bool operator==(const VkShaderKey& other) const { return memcmp(this, &other, sizeof(VkShaderKey)) == 0; }
124126
bool operator!=(const VkShaderKey& other) const { return memcmp(this, &other, sizeof(VkShaderKey)) != 0; }
125127
};
126128

127-
static_assert(sizeof(VkShaderKey) == 16, "sizeof(VkShaderKey) is not its expected size!"); // If this assert fails, the flags union no longer adds up to 64 bits. Or there are gaps in the class so the memcmp doesn't work.
129+
static_assert(sizeof(VkShaderKey) == 24, "sizeof(VkShaderKey) is not its expected size!"); // If this assert fails, the flags union no longer adds up to 64 bits. Or there are gaps in the class so the memcmp doesn't work.
128130

129131
class VkShaderProgram
130132
{

src/common/rendering/vulkan/vk_levelmesh.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ VkLevelMesh::BLAS VkLevelMesh::CreateBLAS(bool preferFastBuild, int indexOffset,
333333
accelStructBLDesc.geometryType = VK_GEOMETRY_TYPE_TRIANGLES_KHR;
334334
accelStructBLDesc.flags = VK_GEOMETRY_OPAQUE_BIT_KHR;
335335
accelStructBLDesc.geometry.triangles = { VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_TRIANGLES_DATA_KHR };
336-
accelStructBLDesc.geometry.triangles.vertexFormat = VK_FORMAT_R32G32B32A32_SFLOAT;
336+
accelStructBLDesc.geometry.triangles.vertexFormat = VK_FORMAT_R32G32B32_SFLOAT;
337337
accelStructBLDesc.geometry.triangles.vertexData.deviceAddress = VertexBuffer->GetDeviceAddress();
338338
accelStructBLDesc.geometry.triangles.vertexStride = sizeof(FFlatVertex);
339339
accelStructBLDesc.geometry.triangles.indexType = VK_INDEX_TYPE_UINT32;

src/common/rendering/vulkan/vk_renderdevice.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,9 +686,9 @@ int VulkanRenderDevice::GetLevelMeshPipelineID(const MeshApplyData& applyData, c
686686

687687
VkPipelineKey pipelineKey;
688688
pipelineKey.DrawType = DT_Triangles;
689-
pipelineKey.VertexFormat = levelVertexFormatIndex;
690689
pipelineKey.RenderStyle = applyData.RenderStyle;
691690
pipelineKey.DepthFunc = applyData.DepthFunc;
691+
pipelineKey.ShaderKey.VertexFormat = levelVertexFormatIndex;
692692
if (applyData.SpecialEffect > EFF_NONE)
693693
{
694694
pipelineKey.ShaderKey.SpecialEffect = applyData.SpecialEffect;

src/common/rendering/vulkan/vk_renderstate.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,6 @@ void VkRenderState::ApplyRenderPass(int dt)
249249
VkPipelineKey pipelineKey;
250250
pipelineKey.DrawType = dt;
251251
pipelineKey.DrawLine = mDrawLine || mWireframe;
252-
pipelineKey.VertexFormat = mVertexBuffer ? static_cast<VkHardwareVertexBuffer*>(mVertexBuffer)->VertexFormat : mRSBuffers->Flatbuffer.VertexFormat;
253252
pipelineKey.RenderStyle = mRenderStyle;
254253
pipelineKey.DepthTest = mDepthTest && !mWireframe;
255254
pipelineKey.DepthWrite = mDepthTest && !mWireframe && mDepthWrite;
@@ -260,6 +259,7 @@ void VkRenderState::ApplyRenderPass(int dt)
260259
pipelineKey.StencilPassOp = mStencilOp;
261260
pipelineKey.ColorMask = mColorMask;
262261
pipelineKey.CullMode = mCullMode;
262+
pipelineKey.ShaderKey.VertexFormat = mVertexBuffer ? static_cast<VkHardwareVertexBuffer*>(mVertexBuffer)->VertexFormat : mRSBuffers->Flatbuffer.VertexFormat;
263263
if (mSpecialEffect > EFF_NONE)
264264
{
265265
pipelineKey.ShaderKey.SpecialEffect = mSpecialEffect;

0 commit comments

Comments
 (0)