mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-10-10 22:31:32 +00:00
Add an SDBasic type for ResourceId.
* This type is core enum and used globally (not API specific) that it merits becoming a specific structured data type
This commit is contained in:
9 files changed
+109
-71
No files matched your search
@@ -251,6 +251,54 @@ inline enum_name operator++(enum_name &a) \
|
||||
|
||||
#define ENUM_ARRAY_SIZE(enum_name) size_t(enum_name::Count)
|
||||
|
||||
// declare ResourceId extremely early so that it can be referenced in structured_data.h
|
||||
|
||||
#ifdef RENDERDOC_EXPORTS
|
||||
struct ResourceId;
|
||||
|
||||
namespace ResourceIDGen
|
||||
{
|
||||
// the only function allowed access to ResourceId internals, for allocating a new ID
|
||||
ResourceId GetNewUniqueID();
|
||||
};
|
||||
#endif
|
||||
|
||||
// We give every resource a globally unique ID so that we can differentiate
|
||||
// between two textures allocated in the same memory (after the first is freed)
|
||||
//
|
||||
// it's a struct around a uint64_t to aid in template selection
|
||||
DOCUMENT(R"(This is an opaque identifier that uniquely locates a resource.
|
||||
|
||||
.. note::
|
||||
These IDs do not overlap ever - textures, buffers, shaders and samplers will all have unique IDs
|
||||
and do not reuse the namespace. Likewise the IDs assigned for resources during capture are not
|
||||
re-used on replay - the corresponding resources created on replay to stand-in for capture-time
|
||||
resources are given unique IDs and a mapping is stored to between the capture-time resource and
|
||||
the replay-time one.
|
||||
)");
|
||||
struct ResourceId
|
||||
{
|
||||
ResourceId() : id() {}
|
||||
DOCUMENT("A helper function that explicitly creates an empty/invalid/null :class:`ResourceId`.");
|
||||
inline static ResourceId Null() { return ResourceId(); }
|
||||
DOCUMENT("Compares two ``ResourceId`` objects for equality.");
|
||||
bool operator==(const ResourceId u) const { return id == u.id; }
|
||||
DOCUMENT("Compares two ``ResourceId`` objects for inequality.");
|
||||
bool operator!=(const ResourceId u) const { return id != u.id; }
|
||||
DOCUMENT("Compares two ``ResourceId`` objects for less-than.");
|
||||
bool operator<(const ResourceId u) const { return id < u.id; }
|
||||
#if defined(RENDERDOC_QT_COMPAT)
|
||||
operator QVariant() const { return QVariant::fromValue(*this); }
|
||||
#endif
|
||||
|
||||
private:
|
||||
uint64_t id;
|
||||
|
||||
#ifdef RENDERDOC_EXPORTS
|
||||
friend ResourceId ResourceIDGen::GetNewUniqueID();
|
||||
#endif
|
||||
};
|
||||
|
||||
#include "basic_types.h"
|
||||
#include "stringise.h"
|
||||
#include "structured_data.h"
|
||||
@@ -422,52 +470,8 @@ struct GlobalEnvironment
|
||||
Display *xlibDisplay = NULL;
|
||||
};
|
||||
|
||||
#ifdef RENDERDOC_EXPORTS
|
||||
struct ResourceId;
|
||||
|
||||
namespace ResourceIDGen
|
||||
{
|
||||
// the only function allowed access to ResourceId internals, for allocating a new ID
|
||||
ResourceId GetNewUniqueID();
|
||||
};
|
||||
#endif
|
||||
|
||||
// We give every resource a globally unique ID so that we can differentiate
|
||||
// between two textures allocated in the same memory (after the first is freed)
|
||||
//
|
||||
// it's a struct around a uint64_t to aid in template selection
|
||||
DOCUMENT(R"(This is an opaque identifier that uniquely locates a resource.
|
||||
|
||||
.. note::
|
||||
These IDs do not overlap ever - textures, buffers, shaders and samplers will all have unique IDs
|
||||
and do not reuse the namespace. Likewise the IDs assigned for resources during capture are not
|
||||
re-used on replay - the corresponding resources created on replay to stand-in for capture-time
|
||||
resources are given unique IDs and a mapping is stored to between the capture-time resource and
|
||||
the replay-time one.
|
||||
)");
|
||||
struct ResourceId
|
||||
{
|
||||
ResourceId() : id() {}
|
||||
DOCUMENT("A helper function that explicitly creates an empty/invalid/null :class:`ResourceId`.");
|
||||
inline static ResourceId Null() { return ResourceId(); }
|
||||
DOCUMENT("Compares two ``ResourceId`` objects for equality.");
|
||||
bool operator==(const ResourceId u) const { return id == u.id; }
|
||||
DOCUMENT("Compares two ``ResourceId`` objects for inequality.");
|
||||
bool operator!=(const ResourceId u) const { return id != u.id; }
|
||||
DOCUMENT("Compares two ``ResourceId`` objects for less-than.");
|
||||
bool operator<(const ResourceId u) const { return id < u.id; }
|
||||
#if defined(RENDERDOC_QT_COMPAT)
|
||||
operator QVariant() const { return QVariant::fromValue(*this); }
|
||||
#endif
|
||||
|
||||
private:
|
||||
uint64_t id;
|
||||
|
||||
#ifdef RENDERDOC_EXPORTS
|
||||
friend ResourceId ResourceIDGen::GetNewUniqueID();
|
||||
#endif
|
||||
};
|
||||
|
||||
// declare metatype/reflection for ResourceId here as the struct itself is declared before including
|
||||
// all relevant headers above
|
||||
#if defined(RENDERDOC_QT_COMPAT)
|
||||
Q_DECLARE_METATYPE(ResourceId);
|
||||
#endif
|
||||
|
||||
@@ -81,6 +81,11 @@ DOCUMENT(R"(The basic irreducible type of an object. Every other more complex ty
|
||||
|
||||
A single byte character. Wide/multi-byte characters are not supported (these would be stored as a
|
||||
string with 1 character and multiple bytes in UTF-8).
|
||||
|
||||
.. data:: ResourceId
|
||||
|
||||
A ResourceId. Equivalent to (and stored as) an 8-byte unsigned integer, but specifically contains
|
||||
the unique Id of a resource in a capture.
|
||||
)");
|
||||
enum class SDBasic : uint32_t
|
||||
{
|
||||
@@ -96,6 +101,7 @@ enum class SDBasic : uint32_t
|
||||
Float,
|
||||
Boolean,
|
||||
Character,
|
||||
ResourceId,
|
||||
};
|
||||
|
||||
DECLARE_REFLECTION_ENUM(SDBasic);
|
||||
@@ -251,9 +257,14 @@ union SDObjectPODData
|
||||
DOCUMENT("The value as a single byte character.");
|
||||
char c;
|
||||
|
||||
DOCUMENT("The value as a :class:`ResourceId`.");
|
||||
ResourceId id;
|
||||
|
||||
// mostly here just for debugging
|
||||
DOCUMENT("A useful alias of :data:`u` - the number of children when a struct/array.");
|
||||
uint64_t numChildren;
|
||||
|
||||
SDObjectPODData() : u(0) {}
|
||||
};
|
||||
|
||||
DECLARE_REFLECTION_STRUCT(SDObjectPODData);
|
||||
@@ -378,6 +389,7 @@ struct SDObject
|
||||
case SDBasic::Enum:
|
||||
case SDBasic::UnsignedInteger: return QVariant(qulonglong(data.basic.u));
|
||||
case SDBasic::SignedInteger: return QVariant(qlonglong(data.basic.i));
|
||||
case SDBasic::ResourceId: return (QVariant)data.basic.id;
|
||||
case SDBasic::Float: return data.basic.d;
|
||||
case SDBasic::Boolean: return data.basic.b;
|
||||
case SDBasic::Character: return data.basic.c;
|
||||
@@ -523,6 +535,16 @@ inline SDObject *makeSDObject(const char *name, const char *val)
|
||||
return ret;
|
||||
}
|
||||
|
||||
DOCUMENT("Make a structured object out of a ResourceId");
|
||||
inline SDObject *makeSDObject(const char *name, ResourceId val)
|
||||
{
|
||||
SDObject *ret = new SDObject(name, "ResourceId");
|
||||
ret->type.basetype = SDBasic::ResourceId;
|
||||
ret->type.byteSize = 8;
|
||||
ret->data.basic.id = val;
|
||||
return ret;
|
||||
}
|
||||
|
||||
DOCUMENT("Make an array-type structured object out of a string");
|
||||
inline SDObject *makeSDArray(const char *name)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user