Browse Source

add texture:getDebugName and buffer:getDebugName

niki 1 year ago
parent
commit
7a25dfa7fc

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

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

+ 5 - 2
src/modules/graphics/Buffer.h

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

+ 1 - 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)
 	, requestedMSAA(settings.msaa > 1 ? settings.msaa : 0)
 	, samplerState()
 	, samplerState()
 	, graphicsMemorySize(0)
 	, graphicsMemorySize(0)
+	, debugName(settings.debugName)
 {
 {
 	const auto &caps = gfx->getCapabilities();
 	const auto &caps = gfx->getCapabilities();
 	int requestedMipmapCount = settings.mipmapCount;
 	int requestedMipmapCount = settings.mipmapCount;

+ 5 - 1
src/modules/graphics/Texture.h

@@ -195,7 +195,7 @@ public:
 		bool renderTarget = false;
 		bool renderTarget = false;
 		bool computeWrite = false;
 		bool computeWrite = false;
 		OptionalBool readable;
 		OptionalBool readable;
-		std::string debugName;
+		Optional<std::string> debugName;
 	};
 	};
 
 
 	struct Slices
 	struct Slices
@@ -290,6 +290,8 @@ public:
 
 
 	Quad *getQuad() const;
 	Quad *getQuad() const;
 
 
+	const Optional<std::string>& getDebugName() const { return debugName; }
+
 	static int getTotalMipmapCount(int w, int h);
 	static int getTotalMipmapCount(int w, int h);
 	static int getTotalMipmapCount(int w, int h, int d);
 	static int getTotalMipmapCount(int w, int h, int d);
 
 
@@ -345,6 +347,8 @@ protected:
 
 
 	int64 graphicsMemorySize;
 	int64 graphicsMemorySize;
 
 
+	Optional<std::string> debugName;
+
 }; // Texture
 }; // Texture
 
 
 } // graphics
 } // graphics

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

@@ -68,7 +68,6 @@ static GLenum getGLFormat(DataFormat format)
 
 
 Buffer::Buffer(love::graphics::Graphics *gfx, const Settings &settings, const std::vector<DataDeclaration> &format, const void *data, size_t size, size_t arraylength)
 Buffer::Buffer(love::graphics::Graphics *gfx, const Settings &settings, const std::vector<DataDeclaration> &format, const void *data, size_t size, size_t arraylength)
 	: love::graphics::Buffer(gfx, settings, format, size, arraylength)
 	: love::graphics::Buffer(gfx, settings, format, size, arraylength)
-	, debugName(settings.debugName)
 {
 {
 	size = getSize();
 	size = getSize();
 	arraylength = getArrayLength();
 	arraylength = getArrayLength();
@@ -165,8 +164,8 @@ bool Buffer::load(const void *initialdata)
 		glTexBuffer(target, glformat, buffer);
 		glTexBuffer(target, glformat, buffer);
 	}
 	}
 
 
-	if (!debugName.empty())
-		glObjectLabel(GL_BUFFER, buffer, -1, debugName.c_str());
+	if (debugName.hasValue)
+		glObjectLabel(GL_BUFFER, buffer, -1, debugName.value.c_str());
 
 
 	return (glGetError() == GL_NO_ERROR);
 	return (glGetError() == GL_NO_ERROR);
 }
 }

+ 0 - 2
src/modules/graphics/opengl/Buffer.h

@@ -81,8 +81,6 @@ private:
 
 
 	Range mappedRange;
 	Range mappedRange;
 
 
-	std::string debugName;
-
 }; // Buffer
 }; // Buffer
 
 
 } // opengl
 } // opengl

+ 3 - 4
src/modules/graphics/opengl/Texture.cpp

@@ -227,7 +227,6 @@ Texture::Texture(love::graphics::Graphics *gfx, const Settings &settings, const
 	, framebufferStatus(GL_FRAMEBUFFER_COMPLETE)
 	, framebufferStatus(GL_FRAMEBUFFER_COMPLETE)
 	, textureGLError(GL_NO_ERROR)
 	, textureGLError(GL_NO_ERROR)
 	, actualSamples(1)
 	, actualSamples(1)
-	, debugName(settings.debugName)
 {
 {
 	if (data != nullptr)
 	if (data != nullptr)
 		slices = *data;
 		slices = *data;
@@ -423,12 +422,12 @@ bool Texture::loadVolatile()
 
 
 	setGraphicsMemorySize(memsize);
 	setGraphicsMemorySize(memsize);
 
 
-	if (!debugName.empty())
+	if (debugName.hasValue)
 	{
 	{
 		if (texture)
 		if (texture)
-			glObjectLabel(GL_TEXTURE, texture, -1, debugName.c_str());
+			glObjectLabel(GL_TEXTURE, texture, -1, debugName.value.c_str());
 		else
 		else
-			glObjectLabel(GL_FRAMEBUFFER, renderbuffer, -1, debugName.c_str());
+			glObjectLabel(GL_FRAMEBUFFER, renderbuffer, -1, debugName.value.c_str());
 	}
 	}
 
 
 	return true;
 	return true;

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

@@ -78,9 +78,6 @@ private:
 	GLenum textureGLError;
 	GLenum textureGLError;
 
 
 	int actualSamples;
 	int actualSamples;
-
-	std::string debugName;
-
 }; // Texture
 }; // Texture
 
 
 } // opengl
 } // opengl

+ 3 - 4
src/modules/graphics/vulkan/Buffer.cpp

@@ -58,7 +58,6 @@ static VkBufferUsageFlags getVulkanUsageFlags(BufferUsageFlags flags)
 Buffer::Buffer(love::graphics::Graphics *gfx, const Settings &settings, const std::vector<DataDeclaration> &format, const void *data, size_t size, size_t arraylength)
 Buffer::Buffer(love::graphics::Graphics *gfx, const Settings &settings, const std::vector<DataDeclaration> &format, const void *data, size_t size, size_t arraylength)
 	: love::graphics::Buffer(gfx, settings, format, size, arraylength)
 	: love::graphics::Buffer(gfx, settings, format, size, arraylength)
 	, zeroInitialize(settings.zeroInitialize)
 	, zeroInitialize(settings.zeroInitialize)
-	, debugName(settings.debugName)
 	, initialData(data)
 	, initialData(data)
 	, vgfx(dynamic_cast<Graphics*>(gfx))
 	, vgfx(dynamic_cast<Graphics*>(gfx))
 	, usageFlags(settings.usageFlags)
 	, usageFlags(settings.usageFlags)
@@ -109,15 +108,15 @@ bool Buffer::loadVolatile()
 	else
 	else
 		coherent = false;
 		coherent = false;
 
 
-	if (!debugName.empty() && vgfx->getEnabledOptionalInstanceExtensions().debugInfo)
+	if (debugName.hasValue && vgfx->getEnabledOptionalInstanceExtensions().debugInfo)
 	{
 	{
 		auto device = vgfx->getDevice();
 		auto device = vgfx->getDevice();
 
 
 		VkDebugUtilsObjectNameInfoEXT nameInfo{};
 		VkDebugUtilsObjectNameInfoEXT nameInfo{};
 		nameInfo.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT;
 		nameInfo.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT;
-		nameInfo.objectType = VK_OBJECT_TYPE_IMAGE;
+		nameInfo.objectType = VK_OBJECT_TYPE_BUFFER;
 		nameInfo.objectHandle = (uint64_t)buffer;
 		nameInfo.objectHandle = (uint64_t)buffer;
-		nameInfo.pObjectName = debugName.c_str();
+		nameInfo.pObjectName = debugName.value.c_str();
 		vkSetDebugUtilsObjectNameEXT(device, &nameInfo);
 		vkSetDebugUtilsObjectNameEXT(device, &nameInfo);
 	}
 	}
 
 

+ 0 - 1
src/modules/graphics/vulkan/Buffer.h

@@ -71,7 +71,6 @@ private:
 	BufferUsageFlags usageFlags;
 	BufferUsageFlags usageFlags;
 	Range mappedRange;
 	Range mappedRange;
 	bool coherent;
 	bool coherent;
-	std::string debugName;
 };
 };
 
 
 } // vulkan
 } // vulkan

+ 2 - 3
src/modules/graphics/vulkan/Texture.cpp

@@ -34,7 +34,6 @@ namespace vulkan
 Texture::Texture(love::graphics::Graphics *gfx, const Settings &settings, const Slices *data)
 Texture::Texture(love::graphics::Graphics *gfx, const Settings &settings, const Slices *data)
 	: love::graphics::Texture(gfx, settings, data)
 	: love::graphics::Texture(gfx, settings, data)
 	, vgfx(dynamic_cast<Graphics*>(gfx))
 	, vgfx(dynamic_cast<Graphics*>(gfx))
-	, debugName(settings.debugName)
 	, slices(settings.type)
 	, slices(settings.type)
 	, imageAspect(0)
 	, imageAspect(0)
 {
 {
@@ -202,7 +201,7 @@ bool Texture::loadVolatile()
 
 
 	setGraphicsMemorySize(memsize);
 	setGraphicsMemorySize(memsize);
 
 
-	if (!debugName.empty())
+	if (debugName.hasValue)
 	{
 	{
 		if (vgfx->getEnabledOptionalInstanceExtensions().debugInfo)
 		if (vgfx->getEnabledOptionalInstanceExtensions().debugInfo)
 		{
 		{
@@ -210,7 +209,7 @@ bool Texture::loadVolatile()
 			nameInfo.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT;
 			nameInfo.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT;
 			nameInfo.objectType = VK_OBJECT_TYPE_IMAGE;
 			nameInfo.objectType = VK_OBJECT_TYPE_IMAGE;
 			nameInfo.objectHandle = (uint64_t)textureImage;
 			nameInfo.objectHandle = (uint64_t)textureImage;
-			nameInfo.pObjectName = debugName.c_str();
+			nameInfo.pObjectName = debugName.value.c_str();
 			vkSetDebugUtilsObjectNameEXT(device, &nameInfo);
 			vkSetDebugUtilsObjectNameEXT(device, &nameInfo);
 		}
 		}
 	}
 	}

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

@@ -85,7 +85,6 @@ private:
 	Slices slices;
 	Slices slices;
 	int layerCount = 0;
 	int layerCount = 0;
 	VkSampleCountFlagBits msaaSamples = VK_SAMPLE_COUNT_1_BIT;
 	VkSampleCountFlagBits msaaSamples = VK_SAMPLE_COUNT_1_BIT;
-	std::string debugName;
 };
 };
 
 
 } // vulkan
 } // vulkan

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

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

+ 1 - 1
src/modules/graphics/wrap_Graphics.cpp

@@ -741,7 +741,7 @@ static void luax_checktexturesettings(lua_State *L, int idx, bool opt, bool chec
 	lua_getfield(L, idx, Texture::getConstant(Texture::SETTING_DEBUGNAME));
 	lua_getfield(L, idx, Texture::getConstant(Texture::SETTING_DEBUGNAME));
 	if (!lua_isnoneornil(L, -1))
 	if (!lua_isnoneornil(L, -1))
 	{
 	{
-		s.debugName = luaL_checkstring(L, -1);
+		s.debugName.set(luaL_checkstring(L, -1));
 	}
 	}
 	lua_pop(L, 1);
 	lua_pop(L, 1);
 
 

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

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