Browse Source

Merge pull request #1994 from nikeinikei/12.0-development

Implement #1992
Sasha Szpakowski 1 year ago
parent
commit
9b79d3a91b

+ 1 - 0
src/modules/graphics/Buffer.cpp

@@ -38,6 +38,7 @@ Buffer::Buffer(Graphics *gfx, const Settings &settings, const std::vector<DataDe
 	, mapped(false)
 	, mappedType(MAP_WRITE_INVALIDATE)
 	, immutable(false)
+	, debugName(settings.debugName)
 {
 	if (size == 0 && arraylength == 0)
 		throw love::Exception("Size or array length must be specified.");

+ 6 - 0
src/modules/graphics/Buffer.h

@@ -24,6 +24,7 @@
 #include "common/config.h"
 #include "common/int.h"
 #include "common/Object.h"
+#include "common/Optional.h"
 #include "vertex.h"
 #include "Resource.h"
 
@@ -89,11 +90,13 @@ public:
 		BufferUsageFlags usageFlags;
 		BufferDataUsage dataUsage;
 		bool zeroInitialize;
+		std::string debugName;
 
 		Settings(uint32 usageflags, BufferDataUsage dataUsage)
 			: usageFlags((BufferUsageFlags)usageflags)
 			, dataUsage(dataUsage)
 			, zeroInitialize(false)
+			, debugName()
 		{}
 	};
 
@@ -111,6 +114,7 @@ public:
 	const DataMember &getDataMember(int index) const { return dataMembers[index]; }
 	size_t getMemberOffset(int index) const { return dataMembers[index].offset; }
 	int getDataMemberIndex(const std::string &name) const;
+	const std::string &getDebugName() const { return debugName; }
 
 	void setImmutable(bool immutable) { this->immutable = immutable; };
 	bool isImmutable() const { return immutable; }
@@ -184,6 +188,8 @@ protected:
 	// Usage hint. GL_[DYNAMIC, STATIC, STREAM]_DRAW.
 	BufferDataUsage dataUsage;
 
+	std::string debugName;
+
 	bool mapped;
 	MapType mappedType;
 	bool immutable;

+ 2 - 0
src/modules/graphics/Texture.cpp

@@ -178,6 +178,7 @@ Texture::Texture(Graphics *gfx, const Settings &settings, const Slices *slices)
 	, requestedMSAA(settings.msaa > 1 ? settings.msaa : 0)
 	, samplerState()
 	, graphicsMemorySize(0)
+	, debugName(settings.debugName)
 {
 	const auto &caps = gfx->getCapabilities();
 	int requestedMipmapCount = settings.mipmapCount;
@@ -975,6 +976,7 @@ static StringMap<Texture::SettingType, Texture::SETTING_MAX_ENUM>::Entry setting
 	{ "canvas",       Texture::SETTING_RENDER_TARGET },
 	{ "computewrite", Texture::SETTING_COMPUTE_WRITE },
 	{ "readable",     Texture::SETTING_READABLE      },
+	{ "debugname",    Texture::SETTING_DEBUGNAME     },
 };
 
 static StringMap<Texture::SettingType, Texture::SETTING_MAX_ENUM> settingTypes(settingTypeEntries, sizeof(settingTypeEntries));

+ 6 - 0
src/modules/graphics/Texture.h

@@ -175,6 +175,7 @@ public:
 		SETTING_RENDER_TARGET,
 		SETTING_COMPUTE_WRITE,
 		SETTING_READABLE,
+		SETTING_DEBUGNAME,
 		SETTING_MAX_ENUM
 	};
 
@@ -194,6 +195,7 @@ public:
 		bool renderTarget = false;
 		bool computeWrite = false;
 		OptionalBool readable;
+		std::string debugName;
 	};
 
 	struct Slices
@@ -288,6 +290,8 @@ public:
 
 	Quad *getQuad() const;
 
+	const std::string &getDebugName() const { return debugName; }
+
 	static int getTotalMipmapCount(int w, int h);
 	static int getTotalMipmapCount(int w, int h, int d);
 
@@ -343,6 +347,8 @@ protected:
 
 	int64 graphicsMemorySize;
 
+	std::string debugName;
+
 }; // Texture
 
 } // graphics

+ 3 - 0
src/modules/graphics/opengl/Buffer.cpp

@@ -164,6 +164,9 @@ bool Buffer::load(const void *initialdata)
 		glTexBuffer(target, glformat, buffer);
 	}
 
+	if (!debugName.empty())
+		glObjectLabel(GL_BUFFER, buffer, -1, debugName.c_str());
+
 	return (glGetError() == GL_NO_ERROR);
 }
 

+ 8 - 0
src/modules/graphics/opengl/Texture.cpp

@@ -422,6 +422,14 @@ bool Texture::loadVolatile()
 
 	setGraphicsMemorySize(memsize);
 
+	if (!debugName.empty())
+	{
+		if (texture)
+			glObjectLabel(GL_TEXTURE, texture, -1, debugName.c_str());
+		else
+			glObjectLabel(GL_FRAMEBUFFER, renderbuffer, -1, debugName.c_str());
+	}
+
 	return true;
 }
 

+ 0 - 1
src/modules/graphics/opengl/Texture.h

@@ -78,7 +78,6 @@ private:
 	GLenum textureGLError;
 
 	int actualSamples;
-
 }; // Texture
 
 } // opengl

+ 12 - 0
src/modules/graphics/vulkan/Buffer.cpp

@@ -108,6 +108,18 @@ bool Buffer::loadVolatile()
 	else
 		coherent = false;
 
+	if (!debugName.empty() && vgfx->getEnabledOptionalInstanceExtensions().debugInfo)
+	{
+		auto device = vgfx->getDevice();
+
+		VkDebugUtilsObjectNameInfoEXT nameInfo{};
+		nameInfo.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT;
+		nameInfo.objectType = VK_OBJECT_TYPE_BUFFER;
+		nameInfo.objectHandle = (uint64_t)buffer;
+		nameInfo.pObjectName = debugName.c_str();
+		vkSetDebugUtilsObjectNameEXT(device, &nameInfo);
+	}
+
 	return true;
 }
 

+ 9 - 0
src/modules/graphics/vulkan/Graphics.cpp

@@ -89,6 +89,8 @@ static void checkOptionalInstanceExtensions(OptionalInstanceExtensions& ext)
 	{
 		if (strcmp(extension.extensionName, VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME) == 0)
 			ext.physicalDeviceProperties2 = true;
+		if (strcmp(extension.extensionName, VK_EXT_DEBUG_UTILS_EXTENSION_NAME) == 0)
+			ext.debugInfo = true;
 	}
 }
 
@@ -127,6 +129,8 @@ Graphics::Graphics()
 
 	if (optionalInstanceExtensions.physicalDeviceProperties2)
 		extensions.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
+	if (optionalInstanceExtensions.debugInfo)
+		extensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
 
 	size_t additional_extension_count = extensions.size();
 	extensions.resize(additional_extension_count + count);
@@ -1399,6 +1403,11 @@ const OptionalDeviceExtensions &Graphics::getEnabledOptionalDeviceExtensions() c
 	return optionalDeviceExtensions;
 }
 
+const OptionalInstanceExtensions &Graphics::getEnabledOptionalInstanceExtensions() const
+{
+	return optionalInstanceExtensions;
+}
+
 bool Graphics::checkValidationSupport()
 {
 	uint32_t layerCount;

+ 4 - 0
src/modules/graphics/vulkan/Graphics.h

@@ -144,6 +144,9 @@ struct OptionalInstanceExtensions
 {
 	// VK_KHR_get_physical_device_properties2
 	bool physicalDeviceProperties2 = false;
+
+	// VK_EXT_debug_info
+	bool debugInfo = false;
 };
 
 struct OptionalDeviceExtensions
@@ -318,6 +321,7 @@ public:
 	void setComputeShader(Shader *computeShader);
 	graphics::Shader::BuiltinUniformData getCurrentBuiltinUniformData();
 	const OptionalDeviceExtensions &getEnabledOptionalDeviceExtensions() const;
+	const OptionalInstanceExtensions &getEnabledOptionalInstanceExtensions() const;
 	VkSampleCountFlagBits getMsaaCount(int requestedMsaa) const;
 	void setVsync(int vsync);
 	int getVsync() const;

+ 13 - 0
src/modules/graphics/vulkan/Texture.cpp

@@ -201,6 +201,19 @@ bool Texture::loadVolatile()
 
 	setGraphicsMemorySize(memsize);
 
+	if (!debugName.empty())
+	{
+		if (vgfx->getEnabledOptionalInstanceExtensions().debugInfo)
+		{
+			VkDebugUtilsObjectNameInfoEXT nameInfo{};
+			nameInfo.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT;
+			nameInfo.objectType = VK_OBJECT_TYPE_IMAGE;
+			nameInfo.objectHandle = (uint64_t)textureImage;
+			nameInfo.pObjectName = debugName.c_str();
+			vkSetDebugUtilsObjectNameEXT(device, &nameInfo);
+		}
+	}
+
 	return true;
 }
 

+ 12 - 0
src/modules/graphics/wrap_Buffer.cpp

@@ -413,6 +413,17 @@ static int w_Buffer_isBufferType(lua_State *L)
 	return 1;
 }
 
+static int w_Buffer_getDebugName(lua_State *L)
+{
+	Buffer *t = luax_checkbuffer(L, 1);
+	const std::string &debugName = t->getDebugName();
+	if (debugName.empty())
+		lua_pushnil(L);
+	else
+		luax_pushstring(L, debugName);
+	return 1;
+}
+
 static const luaL_Reg w_Buffer_functions[] =
 {
 	{ "setArrayData", w_Buffer_setArrayData },
@@ -422,6 +433,7 @@ static const luaL_Reg w_Buffer_functions[] =
 	{ "getSize", w_Buffer_getSize },
 	{ "getFormat", w_Buffer_getFormat },
 	{ "isBufferType", w_Buffer_isBufferType },
+	{ "getDebugName", w_Buffer_getDebugName },
 	{ 0, 0 }
 };
 

+ 12 - 0
src/modules/graphics/wrap_Graphics.cpp

@@ -738,6 +738,13 @@ static void luax_checktexturesettings(lua_State *L, int idx, bool opt, bool chec
 	if (!forceRenderTarget.hasValue)
 		s.renderTarget = luax_boolflag(L, idx, Texture::getConstant(Texture::SETTING_RENDER_TARGET), s.renderTarget);
 
+	lua_getfield(L, idx, Texture::getConstant(Texture::SETTING_DEBUGNAME));
+	if (!lua_isnoneornil(L, -1))
+	{
+		s.debugName = luaL_checkstring(L, -1);
+	}
+	lua_pop(L, 1);
+
 	lua_getfield(L, idx, Texture::getConstant(Texture::SETTING_FORMAT));
 	if (!lua_isnoneornil(L, -1))
 	{
@@ -1570,6 +1577,11 @@ static void luax_optbuffersettings(lua_State *L, int idx, Buffer::Settings &sett
 	lua_getfield(L, idx, "usage");
 	settings.dataUsage = luax_optdatausage(L, -1, settings.dataUsage);
 	lua_pop(L, 1);
+
+	lua_getfield(L, idx, "debugname");
+	if (!lua_isnoneornil(L, -1))
+		settings.debugName = luax_checkstring(L, -1);
+	lua_pop(L, 1);
 }
 
 static Buffer::DataDeclaration luax_checkdatadeclaration(lua_State* L, int formattableidx, int arrayindex, int declindex, bool requirename)

+ 12 - 0
src/modules/graphics/wrap_Texture.cpp

@@ -474,6 +474,17 @@ int w_Texture_renderTo(lua_State *L)
 	return 0;
 }
 
+static int w_Texture_getDebugName(lua_State *L)
+{
+	Texture *t = luax_checktexture(L, 1);
+	const std::string &debugName = t->getDebugName();
+	if (debugName.empty())
+		lua_pushnil(L);
+	else
+		luax_pushstring(L, debugName);
+	return 1;
+}
+
 const luaL_Reg w_Texture_functions[] =
 {
 	{ "getTextureType", w_Texture_getTextureType },
@@ -506,6 +517,7 @@ const luaL_Reg w_Texture_functions[] =
 	{ "generateMipmaps", w_Texture_generateMipmaps },
 	{ "replacePixels", w_Texture_replacePixels },
 	{ "renderTo", w_Texture_renderTo },
+	{ "getDebugName", w_Texture_getDebugName },
 
 	// Deprecated
 	{ "newImageData", w_Texture_newImageData },