Different rendering results with Debug and Release builds

Hello,

I am attempting to render models in Vulkan whilst following the Vulkan tutorial website and simply extended it to include multiple meshes and import textures. I tested this on the Viking model provided and it worked fine in debug builds.

I tested it with Sponza and it works fine in debug

However when I ran it in Release ( I still have validation layers on in release and got no errors from that).


Where the order or something like that of indices seemed to be messed up causing them to connect weirdly. I tested it out with the original Viking model, and I get the same issues.

I don’t have any code at all that is removed/different from debug/release builds so not sure what the issue could be. The code to load in the models is very similar but here it is in caseI have made any errors.

Model Importer::LoadModel(const std::filesystem::path& Path)
{
	Model Data{};

	tinyobj::attrib_t Attrib;
	std::vector<tinyobj::shape_t> Shapes;
	std::vector<tinyobj::material_t> Materials;
	std::string Error, Warn;

	bool Result = tinyobj::LoadObj(&Attrib, &Shapes, &Materials, &Warn, &Error, Path.string().c_str());
	
	ILLUMINA_VERIFY(Result, "failed to load model ", Path, " ", Warn, " ", Error);

	ILLUMINA_DEBUG_LOG_INFO(Warn, " ", Error);

	std::unordered_map<Vertex, uint32_t> UnqiueVertices;

	for (const auto& Shape : Shapes)
	{
		Data.List.push_back({});
		
		auto& Mesh = Data.List.back();
		int ID = Shape.mesh.material_ids[0];

		//for now assuming each mesh has only one material
		if (ID >= 0)
		{
			auto& Material = Materials[ID]; 
			Mesh.Material = ConstructMaterial(Material);
		}
		else
		{	
			memset(&Mesh.Material, 0, sizeof(Material) / sizeof(int));
		}


		for (const auto& Index : Shape.mesh.indices)
		{
			Vertex Vert{};

			memcpy(&Vert.Position,          &Attrib.vertices[3 * Index.vertex_index], sizeof(float) * 3);
			memcpy(&Vert.Normal,            &Attrib.normals[3 * Index.normal_index], sizeof(float) * 3);
			memcpy(&Vert.TextureCoordinate, &Attrib.texcoords[2 * Index.texcoord_index], sizeof(float) * 2);
			
			Vert.Color = { 1.0f, 1.0f, 1.0f };

			if (UnqiueVertices.count(Vert) == 0)
			{
				UnqiueVertices[Vert] = (uint32_t)Mesh.Vertices.size();
				Mesh.Vertices.push_back(Vert);
			}

			Mesh.Indices.push_back(UnqiueVertices[Vert]);
		}
	}

	return Data;
}

I have tried changing the winding order in my graphics pipelines from clockwise to counterclockwise and that didn’t fix this issue. Is there anything else I can try?

UPDATE:


I managed to produce these and

Simply by changing where I included the defines for glm that i was using:
#define GLM_FORCE_ALIGNED_GENTYPES
#define GLM_FORCE_RADIANS
#define GLM_FORCE_DEPTH_ZERO_TO_ONE
#define GLM_ENABLE_EXPERIMENTAL

Seems like its a glm issue not vulkan.

EDIT:
for anyone experiencing similar issues make sure to separate out GLM_USE_EXPERIMENTAL from the rest of your code otherwise it will produce these weird bug. I solved it by having a dedicated glm header.

glm_include.h

#pragma once

#define GLM_FORCE_ALIGNED_GENTYPES
#define GLM_FORCE_RADIANS
#define GLM_FORCE_DEPTH_ZERO_TO_ONE
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>

Then when i needed to use hashing from glm I would include it the define and hash in the c++ file

in importer.cpp

#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/hash.hpp>