Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement #1992 #1994

Merged
merged 5 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/modules/graphics/Buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down
6 changes: 6 additions & 0 deletions src/modules/graphics/Buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -89,11 +90,13 @@ class Buffer : public love::Object, public Resource
BufferUsageFlags usageFlags;
BufferDataUsage dataUsage;
bool zeroInitialize;
Optional<std::string> debugName;

Settings(uint32 usageflags, BufferDataUsage dataUsage)
: usageFlags((BufferUsageFlags)usageflags)
, dataUsage(dataUsage)
, zeroInitialize(false)
, debugName()
{}
};

Expand All @@ -111,6 +114,7 @@ class Buffer : public love::Object, public Resource
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<std::string> &getDebugName() const { return debugName; }

void setImmutable(bool immutable) { this->immutable = immutable; };
bool isImmutable() const { return immutable; }
Expand Down Expand Up @@ -184,6 +188,8 @@ class Buffer : public love::Object, public Resource
// Usage hint. GL_[DYNAMIC, STATIC, STREAM]_DRAW.
BufferDataUsage dataUsage;

Optional<std::string> debugName;

bool mapped;
MapType mappedType;
bool immutable;
Expand Down
2 changes: 2 additions & 0 deletions src/modules/graphics/Texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down
6 changes: 6 additions & 0 deletions src/modules/graphics/Texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ class Texture : public Drawable, public Resource
SETTING_RENDER_TARGET,
SETTING_COMPUTE_WRITE,
SETTING_READABLE,
SETTING_DEBUGNAME,
SETTING_MAX_ENUM
};

Expand All @@ -194,6 +195,7 @@ class Texture : public Drawable, public Resource
bool renderTarget = false;
bool computeWrite = false;
OptionalBool readable;
Optional<std::string> debugName;
slime73 marked this conversation as resolved.
Show resolved Hide resolved
};

struct Slices
Expand Down Expand Up @@ -288,6 +290,8 @@ class Texture : public Drawable, public Resource

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, int d);

Expand Down Expand Up @@ -343,6 +347,8 @@ class Texture : public Drawable, public Resource

int64 graphicsMemorySize;

Optional<std::string> debugName;

}; // Texture

} // graphics
Expand Down
3 changes: 3 additions & 0 deletions src/modules/graphics/opengl/Buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ bool Buffer::load(const void *initialdata)
glTexBuffer(target, glformat, buffer);
}

if (debugName.hasValue)
glObjectLabel(GL_BUFFER, buffer, -1, debugName.value.c_str());

return (glGetError() == GL_NO_ERROR);
}

Expand Down
8 changes: 8 additions & 0 deletions src/modules/graphics/opengl/Texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,14 @@ bool Texture::loadVolatile()

setGraphicsMemorySize(memsize);

if (debugName.hasValue)
{
if (texture)
glObjectLabel(GL_TEXTURE, texture, -1, debugName.value.c_str());
else
glObjectLabel(GL_FRAMEBUFFER, renderbuffer, -1, debugName.value.c_str());
}

return true;
}

Expand Down
1 change: 0 additions & 1 deletion src/modules/graphics/opengl/Texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ class Texture final : public love::graphics::Texture, public Volatile
GLenum textureGLError;

int actualSamples;

}; // Texture

} // opengl
Expand Down
12 changes: 12 additions & 0 deletions src/modules/graphics/vulkan/Buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,18 @@ bool Buffer::loadVolatile()
else
coherent = false;

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_BUFFER;
nameInfo.objectHandle = (uint64_t)buffer;
nameInfo.pObjectName = debugName.value.c_str();
vkSetDebugUtilsObjectNameEXT(device, &nameInfo);
}

return true;
}

Expand Down
9 changes: 9 additions & 0 deletions src/modules/graphics/vulkan/Graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -1399,6 +1403,11 @@ const OptionalDeviceExtensions &Graphics::getEnabledOptionalDeviceExtensions() c
return optionalDeviceExtensions;
}

const OptionalInstanceExtensions &Graphics::getEnabledOptionalInstanceExtensions() const
{
return optionalInstanceExtensions;
}

bool Graphics::checkValidationSupport()
{
uint32_t layerCount;
Expand Down
4 changes: 4 additions & 0 deletions src/modules/graphics/vulkan/Graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ struct OptionalInstanceExtensions
{
// VK_KHR_get_physical_device_properties2
bool physicalDeviceProperties2 = false;

// VK_EXT_debug_info
bool debugInfo = false;
};

struct OptionalDeviceExtensions
Expand Down Expand Up @@ -318,6 +321,7 @@ class Graphics final : public love::graphics::Graphics
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;
Expand Down
13 changes: 13 additions & 0 deletions src/modules/graphics/vulkan/Texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,19 @@ bool Texture::loadVolatile()

setGraphicsMemorySize(memsize);

if (debugName.hasValue)
{
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.value.c_str();
vkSetDebugUtilsObjectNameEXT(device, &nameInfo);
}
}

return true;
}

Expand Down
12 changes: 12 additions & 0 deletions src/modules/graphics/wrap_Buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<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[] =
{
{ "setArrayData", w_Buffer_setArrayData },
Expand All @@ -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 }
};

Expand Down
12 changes: 12 additions & 0 deletions src/modules/graphics/wrap_Graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.set(luaL_checkstring(L, -1));
}
lua_pop(L, 1);

lua_getfield(L, idx, Texture::getConstant(Texture::SETTING_FORMAT));
if (!lua_isnoneornil(L, -1))
{
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions src/modules/graphics/wrap_Texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<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[] =
{
{ "getTextureType", w_Texture_getTextureType },
Expand Down Expand Up @@ -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 },
Expand Down