Skip to content

Commit

Permalink
Merge pull request #1994 from nikeinikei/12.0-development
Browse files Browse the repository at this point in the history
Implement #1992
  • Loading branch information
slime73 authored Dec 13, 2023
2 parents a6ae0ae + c8da517 commit 9b79d3a
Show file tree
Hide file tree
Showing 14 changed files with 100 additions and 1 deletion.
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;
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 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;

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;
std::string debugName;
};

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

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);

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

int64 graphicsMemorySize;

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.empty())
glObjectLabel(GL_BUFFER, buffer, -1, debugName.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.empty())
{
if (texture)
glObjectLabel(GL_TEXTURE, texture, -1, debugName.c_str());
else
glObjectLabel(GL_FRAMEBUFFER, renderbuffer, -1, debugName.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.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;
}

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.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;
}

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 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 },
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 = 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 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 },
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

0 comments on commit 9b79d3a

Please sign in to comment.