diff --git a/src/modules/graphics/Buffer.cpp b/src/modules/graphics/Buffer.cpp index 3ebbc61d1..9345859c6 100644 --- a/src/modules/graphics/Buffer.cpp +++ b/src/modules/graphics/Buffer.cpp @@ -38,6 +38,7 @@ Buffer::Buffer(Graphics *gfx, const Settings &settings, const std::vector debugName; Settings(uint32 usageflags, BufferDataUsage dataUsage) : usageFlags((BufferUsageFlags)usageflags) , dataUsage(dataUsage) , zeroInitialize(false) + , debugName() {} }; @@ -112,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 Optional &getDebugName() const { return debugName; } void setImmutable(bool immutable) { this->immutable = immutable; }; bool isImmutable() const { return immutable; } @@ -185,7 +188,7 @@ protected: // Usage hint. GL_[DYNAMIC, STATIC, STREAM]_DRAW. BufferDataUsage dataUsage; - std::string debugName; + Optional debugName; bool mapped; MapType mappedType; diff --git a/src/modules/graphics/Texture.cpp b/src/modules/graphics/Texture.cpp index 0e329c744..a6f3936ee 100644 --- a/src/modules/graphics/Texture.cpp +++ b/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; diff --git a/src/modules/graphics/Texture.h b/src/modules/graphics/Texture.h index 15f413ea7..8a1d817f0 100644 --- a/src/modules/graphics/Texture.h +++ b/src/modules/graphics/Texture.h @@ -195,7 +195,7 @@ public: bool renderTarget = false; bool computeWrite = false; OptionalBool readable; - std::string debugName; + Optional debugName; }; struct Slices @@ -290,6 +290,8 @@ public: Quad *getQuad() const; + const Optional& getDebugName() const { return debugName; } + static int getTotalMipmapCount(int w, int h); static int getTotalMipmapCount(int w, int h, int d); @@ -345,6 +347,8 @@ protected: int64 graphicsMemorySize; + Optional debugName; + }; // Texture } // graphics diff --git a/src/modules/graphics/opengl/Buffer.cpp b/src/modules/graphics/opengl/Buffer.cpp index 3222a6cd7..ff6a9a4fc 100644 --- a/src/modules/graphics/opengl/Buffer.cpp +++ b/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 &format, const void *data, size_t size, size_t arraylength) : love::graphics::Buffer(gfx, settings, format, size, arraylength) - , debugName(settings.debugName) { size = getSize(); arraylength = getArrayLength(); @@ -165,8 +164,8 @@ bool Buffer::load(const void *initialdata) 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); } diff --git a/src/modules/graphics/opengl/Buffer.h b/src/modules/graphics/opengl/Buffer.h index 001fedbe2..acee82aa7 100644 --- a/src/modules/graphics/opengl/Buffer.h +++ b/src/modules/graphics/opengl/Buffer.h @@ -81,8 +81,6 @@ private: Range mappedRange; - std::string debugName; - }; // Buffer } // opengl diff --git a/src/modules/graphics/opengl/Texture.cpp b/src/modules/graphics/opengl/Texture.cpp index 7b38707e1..1c8ad1bc9 100644 --- a/src/modules/graphics/opengl/Texture.cpp +++ b/src/modules/graphics/opengl/Texture.cpp @@ -227,7 +227,6 @@ Texture::Texture(love::graphics::Graphics *gfx, const Settings &settings, const , framebufferStatus(GL_FRAMEBUFFER_COMPLETE) , textureGLError(GL_NO_ERROR) , actualSamples(1) - , debugName(settings.debugName) { if (data != nullptr) slices = *data; @@ -423,12 +422,12 @@ bool Texture::loadVolatile() setGraphicsMemorySize(memsize); - if (!debugName.empty()) + if (debugName.hasValue) { if (texture) - glObjectLabel(GL_TEXTURE, texture, -1, debugName.c_str()); + glObjectLabel(GL_TEXTURE, texture, -1, debugName.value.c_str()); else - glObjectLabel(GL_FRAMEBUFFER, renderbuffer, -1, debugName.c_str()); + glObjectLabel(GL_FRAMEBUFFER, renderbuffer, -1, debugName.value.c_str()); } return true; diff --git a/src/modules/graphics/opengl/Texture.h b/src/modules/graphics/opengl/Texture.h index 5ad41f41d..321f7b21c 100644 --- a/src/modules/graphics/opengl/Texture.h +++ b/src/modules/graphics/opengl/Texture.h @@ -78,9 +78,6 @@ private: GLenum textureGLError; int actualSamples; - - std::string debugName; - }; // Texture } // opengl diff --git a/src/modules/graphics/vulkan/Buffer.cpp b/src/modules/graphics/vulkan/Buffer.cpp index 6a3f5c963..1d5681858 100644 --- a/src/modules/graphics/vulkan/Buffer.cpp +++ b/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 &format, const void *data, size_t size, size_t arraylength) : love::graphics::Buffer(gfx, settings, format, size, arraylength) , zeroInitialize(settings.zeroInitialize) - , debugName(settings.debugName) , initialData(data) , vgfx(dynamic_cast(gfx)) , usageFlags(settings.usageFlags) @@ -109,15 +108,15 @@ bool Buffer::loadVolatile() else coherent = false; - if (!debugName.empty() && vgfx->getEnabledOptionalInstanceExtensions().debugInfo) + if (debugName.hasValue && 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_IMAGE; + nameInfo.objectType = VK_OBJECT_TYPE_BUFFER; nameInfo.objectHandle = (uint64_t)buffer; - nameInfo.pObjectName = debugName.c_str(); + nameInfo.pObjectName = debugName.value.c_str(); vkSetDebugUtilsObjectNameEXT(device, &nameInfo); } diff --git a/src/modules/graphics/vulkan/Buffer.h b/src/modules/graphics/vulkan/Buffer.h index c717a7708..e6dd674b3 100644 --- a/src/modules/graphics/vulkan/Buffer.h +++ b/src/modules/graphics/vulkan/Buffer.h @@ -71,7 +71,6 @@ private: BufferUsageFlags usageFlags; Range mappedRange; bool coherent; - std::string debugName; }; } // vulkan diff --git a/src/modules/graphics/vulkan/Texture.cpp b/src/modules/graphics/vulkan/Texture.cpp index afaf70f6b..0ace94e1f 100644 --- a/src/modules/graphics/vulkan/Texture.cpp +++ b/src/modules/graphics/vulkan/Texture.cpp @@ -34,7 +34,6 @@ namespace vulkan Texture::Texture(love::graphics::Graphics *gfx, const Settings &settings, const Slices *data) : love::graphics::Texture(gfx, settings, data) , vgfx(dynamic_cast(gfx)) - , debugName(settings.debugName) , slices(settings.type) , imageAspect(0) { @@ -202,7 +201,7 @@ bool Texture::loadVolatile() setGraphicsMemorySize(memsize); - if (!debugName.empty()) + if (debugName.hasValue) { if (vgfx->getEnabledOptionalInstanceExtensions().debugInfo) { @@ -210,7 +209,7 @@ bool Texture::loadVolatile() 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(); + nameInfo.pObjectName = debugName.value.c_str(); vkSetDebugUtilsObjectNameEXT(device, &nameInfo); } } diff --git a/src/modules/graphics/vulkan/Texture.h b/src/modules/graphics/vulkan/Texture.h index 63684da3b..571621a05 100644 --- a/src/modules/graphics/vulkan/Texture.h +++ b/src/modules/graphics/vulkan/Texture.h @@ -85,7 +85,6 @@ private: Slices slices; int layerCount = 0; VkSampleCountFlagBits msaaSamples = VK_SAMPLE_COUNT_1_BIT; - std::string debugName; }; } // vulkan diff --git a/src/modules/graphics/wrap_Buffer.cpp b/src/modules/graphics/wrap_Buffer.cpp index d4073d6e0..cd23bfc6c 100644 --- a/src/modules/graphics/wrap_Buffer.cpp +++ b/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 Optional &debugName = t->getDebugName(); + if (debugName.hasValue) + luax_pushstring(L, debugName.value); + else + lua_pushnil(L); + 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 } }; diff --git a/src/modules/graphics/wrap_Graphics.cpp b/src/modules/graphics/wrap_Graphics.cpp index bc92aa97e..bae7d29a9 100644 --- a/src/modules/graphics/wrap_Graphics.cpp +++ b/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)); if (!lua_isnoneornil(L, -1)) { - s.debugName = luaL_checkstring(L, -1); + s.debugName.set(luaL_checkstring(L, -1)); } lua_pop(L, 1); diff --git a/src/modules/graphics/wrap_Texture.cpp b/src/modules/graphics/wrap_Texture.cpp index 00f6058af..965bdbc13 100644 --- a/src/modules/graphics/wrap_Texture.cpp +++ b/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 Optional &debugName = t->getDebugName(); + if (debugName.hasValue) + luax_pushstring(L, debugName.value); + else + lua_pushnil(L); + 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 },