From 8e21b287855387643f55e1d659556ec179399fdd Mon Sep 17 00:00:00 2001 From: baldurk Date: Tue, 3 Dec 2019 13:24:28 +0000 Subject: [PATCH] Split basic_types.h into separate independent headers --- qrenderdoc/Code/Interface/QRDInterface.h | 3 + qrenderdoc/Code/pyrenderdoc/pyconversion.i | 1 - qrenderdoc/Code/pyrenderdoc/qrenderdoc.i | 2 + qrenderdoc/Code/pyrenderdoc/renderdoc.i | 11 +- renderdoc/3rdparty/catch/catch.hpp | 2 +- renderdoc/CMakeLists.txt | 5 +- .../api/replay/{basic_types.h => rdcarray.h} | 198 +----------------- renderdoc/api/replay/rdcdatetime.h | 91 ++++++++ renderdoc/api/replay/rdcpair.h | 80 +++++++ renderdoc/api/replay/rdcstr.h | 14 +- renderdoc/api/replay/renderdoc_replay.h | 11 +- renderdoc/api/replay/shader_types.h | 3 +- renderdoc/renderdoc.vcxproj | 4 +- renderdoc/renderdoc.vcxproj.filters | 12 +- 14 files changed, 225 insertions(+), 212 deletions(-) rename renderdoc/api/replay/{basic_types.h => rdcarray.h} (78%) create mode 100644 renderdoc/api/replay/rdcdatetime.h create mode 100644 renderdoc/api/replay/rdcpair.h diff --git a/qrenderdoc/Code/Interface/QRDInterface.h b/qrenderdoc/Code/Interface/QRDInterface.h index 47f249781..a4a8ceea1 100644 --- a/qrenderdoc/Code/Interface/QRDInterface.h +++ b/qrenderdoc/Code/Interface/QRDInterface.h @@ -85,6 +85,9 @@ class QMenu; // we depend on the internal RenderDoc API, but the bindings for that are imported entirely #include "renderdoc_replay.h" +typedef rdcpair rdcstrpair; +typedef rdcarray rdcstrpairs; + struct ICaptureContext; #include "Analytics.h" diff --git a/qrenderdoc/Code/pyrenderdoc/pyconversion.i b/qrenderdoc/Code/pyrenderdoc/pyconversion.i index e721ed4ae..1782abcd7 100644 --- a/qrenderdoc/Code/pyrenderdoc/pyconversion.i +++ b/qrenderdoc/Code/pyrenderdoc/pyconversion.i @@ -122,7 +122,6 @@ SIMPLE_TYPEMAPS_VARIANT(SimpleType, SimpleType &) DECLARE_STRINGISE_TYPE(float); DECLARE_STRINGISE_TYPE(double); DECLARE_STRINGISE_TYPE(rdcstr); - DECLARE_STRINGISE_TYPE(rdcstrpair); %} diff --git a/qrenderdoc/Code/pyrenderdoc/qrenderdoc.i b/qrenderdoc/Code/pyrenderdoc/qrenderdoc.i index 878cd5b73..f91a0197a 100644 --- a/qrenderdoc/Code/pyrenderdoc/qrenderdoc.i +++ b/qrenderdoc/Code/pyrenderdoc/qrenderdoc.i @@ -69,6 +69,8 @@ TEMPLATE_ARRAY_DECLARE(rdcarray); #ifndef slots #define slots #endif + + DECLARE_STRINGISE_TYPE(rdcstrpair); %} %include diff --git a/qrenderdoc/Code/pyrenderdoc/renderdoc.i b/qrenderdoc/Code/pyrenderdoc/renderdoc.i index 0b6f4bd93..259b8d086 100644 --- a/qrenderdoc/Code/pyrenderdoc/renderdoc.i +++ b/qrenderdoc/Code/pyrenderdoc/renderdoc.i @@ -79,8 +79,11 @@ %typemap(in) xcb_connection_t* = HWND; %typemap(in) wl_surface* = HWND; -// completely ignore rdcdatetime, we custom convert to/from a native python datetime +// completely ignore types that we custom convert to/from a native python type %ignore rdcdatetime; +%ignore rdcstr; +%ignore rdcliteral; +%ignore rdcpair; // special handling for RENDERDOC_GetDefaultCaptureOptions to transform output parameter to a return value %typemap(in, numinputs=0) CaptureOptions *defaultOpts { $1 = new CaptureOptions; } @@ -153,10 +156,6 @@ %ignore rdcarray::removeOne; %ignore rdcarray::operator=; %ignore rdcarray::operator[]; -%ignore rdcstr::operator=; -%ignore rdcstr::operator std::string; -%ignore rdcpair::operator=; -%ignore rdcpair::swap; // simple typemap to delete old byte arrays in a buffer list before assigning the new one %typemap(memberin) StructuredBufferList { @@ -211,7 +210,7 @@ TEMPLATE_ARRAY_DECLARE(rdcarray); %include %include "renderdoc_replay.h" -%include "basic_types.h" +%include "rdcarray.h" %include "stringise.h" %include "structured_data.h" %include "capture_options.h" diff --git a/renderdoc/3rdparty/catch/catch.hpp b/renderdoc/3rdparty/catch/catch.hpp index f2e568de3..3fc35c35c 100644 --- a/renderdoc/3rdparty/catch/catch.hpp +++ b/renderdoc/3rdparty/catch/catch.hpp @@ -29,7 +29,7 @@ #define CATCH_CONFIG_FORCE_FALLBACK_STRINGIFIER #define CATCH_CONFIG_INLINE_DEBUG_BREAK -#include "api/replay/basic_types.h" +#include "api/replay/rdcstr.h" #include "api/replay/stringise.h" #include "official/catch.hpp" diff --git a/renderdoc/CMakeLists.txt b/renderdoc/CMakeLists.txt index 82e4105d4..f418e6f5e 100644 --- a/renderdoc/CMakeLists.txt +++ b/renderdoc/CMakeLists.txt @@ -95,7 +95,10 @@ endif() set(sources api/app/renderdoc_app.h - api/replay/basic_types.h + api/replay/rdcarray.h + api/replay/rdcdatetime.h + api/replay/rdcstr.h + api/replay/rdcpair.h api/replay/stringise.h api/replay/structured_data.h api/replay/capture_options.h diff --git a/renderdoc/api/replay/basic_types.h b/renderdoc/api/replay/rdcarray.h similarity index 78% rename from renderdoc/api/replay/basic_types.h rename to renderdoc/api/replay/rdcarray.h index 90050a268..383f0aa5b 100644 --- a/renderdoc/api/replay/basic_types.h +++ b/renderdoc/api/replay/rdcarray.h @@ -25,170 +25,17 @@ #pragma once -#include -#include -#include -#include +#include // for standard types +#include // for memcpy, etc +#include #include #include -typedef uint8_t byte; - -#ifndef DOCUMENT -#define DOCUMENT(text) +#ifdef RENDERDOC_EXPORTS +#include // for malloc/free +void RENDERDOC_OutOfMemory(uint64_t sz); #endif -#ifndef DOCUMENT2 -#define DOCUMENT2(text1, text2) -#endif - -#ifndef DOCUMENT3 -#define DOCUMENT3(text1, text2, text3) -#endif - -#ifndef DOCUMENT4 -#define DOCUMENT4(text1, text2, text3, text4) -#endif - -// primarily here just to remove a dependency on QDateTime in the Qt UI, so we don't have to bind -// against Qt at all in the interface. -DOCUMENT(""); -struct rdcdatetime -{ - DOCUMENT(""); - int32_t year = 0; - int32_t month = 0; - int32_t day = 0; - int32_t hour = 0; - int32_t minute = 0; - int32_t second = 0; - int32_t microsecond = 0; - - rdcdatetime() = default; - - rdcdatetime(int y, int mn, int d, int h = 0, int m = 0, int s = 0, int us = 0) - : year(y), month(mn), day(d), hour(h), minute(m), second(s), microsecond(us) - { - } - - bool operator==(const rdcdatetime &o) const - { - return year == o.year && month == o.month && day == o.day && hour == o.hour && - minute == o.minute && second == o.second && microsecond == o.microsecond; - } - bool operator!=(const rdcdatetime &o) const { return !(*this == o); } - bool operator<(const rdcdatetime &o) const - { - if(year != o.year) - return year < o.year; - if(month != o.month) - return month < o.month; - if(day != o.day) - return day < o.day; - if(hour != o.hour) - return hour < o.hour; - if(minute != o.minute) - return minute < o.minute; - if(second != o.second) - return second < o.second; - if(microsecond != o.microsecond) - return microsecond < o.microsecond; - return false; - } - -#if defined(RENDERDOC_QT_COMPAT) - rdcdatetime(const QDateTime &in) - { - year = in.date().year(); - month = in.date().month(); - day = in.date().day(); - hour = in.time().hour(); - minute = in.time().minute(); - second = in.time().second(); - microsecond = in.time().msec() * 1000; - } - operator QDateTime() const - { - return QDateTime(QDate(year, month, day), QTime(hour, minute, second, microsecond / 1000)); - } - operator QVariant() const { return QVariant(QDateTime(*this)); } -#endif -}; - -// here we define our own data structures that are ABI compatible between modules, as STL is not -// safe to pass a module boundary. -template -struct rdcpair -{ - A first; - B second; - - rdcpair(const A &a, const B &b) : first(a), second(b) {} - rdcpair() = default; - rdcpair(const rdcpair &o) = default; - rdcpair(rdcpair &&o) = default; - ~rdcpair() = default; - inline void swap(rdcpair &o) - { - std::swap(first, o.first); - std::swap(second, o.second); - } - - template - rdcpair &operator=(const rdcpair &o) - { - first = o.first; - second = o.second; - return *this; - } - - rdcpair &operator=(const rdcpair &o) - { - first = o.first; - second = o.second; - return *this; - } - - bool operator==(const rdcpair &o) const { return first == o.first && second == o.second; } - bool operator<(const rdcpair &o) const - { - if(first != o.first) - return first < o.first; - return second < o.second; - } -}; - -template -rdcpair make_rdcpair(const A &a, const B &b) -{ - return rdcpair(a, b); -} - -template -rdcpair rdctie(A &a, B &b) -{ - return rdcpair(a, b); -} - -// utility class that adds a NULL terminator to array operations only if T == char -template -struct null_terminator -{ - // adds 1 to every allocation to ensure we have space. Happens invisibly so even capacity() - // doesn't know about it - inline static size_t allocCount(size_t c) { return c; } - // adds the NULL terminator after a resize operation - inline static void fixup(T *elems, size_t count) {} -}; - -template <> -struct null_terminator -{ - inline static size_t allocCount(size_t c) { return c + 1; } - // indexing 'off the end' of elems is safe because we over-allocated above - inline static void fixup(char *elems, size_t count) { elems[count] = 0; } -}; - template ::value> struct ItemHelper { @@ -267,10 +114,6 @@ struct ItemDestroyHelper static void destroyRange(T *first, size_t itemCount) {} }; -#ifdef RENDERDOC_EXPORTS -void RENDERDOC_OutOfMemory(uint64_t sz); -#endif - template struct rdcarray { @@ -302,12 +145,7 @@ protected: #endif } - inline void setUsedCount(size_t newCount) - { - usedCount = newCount; - null_terminator::fixup(elems, usedCount); - } - + inline void setUsedCount(size_t newCount) { usedCount = newCount; } public: typedef T value_type; @@ -360,14 +198,6 @@ public: void reserve(size_t s) { - // if we're empty then normally reserving s==0 would do nothing, but if we need to append a null - // terminator then we do actually need to allocate - if(s == 0 && capacity() == 0 && elems == NULL && null_terminator::allocCount(0) > 0) - { - elems = allocate(null_terminator::allocCount(0)); - return; - } - // nothing to do if we already have this much space. We only size up if(s <= capacity()) return; @@ -377,7 +207,7 @@ public: if(size_t(allocatedCount) * 2 > s) s = size_t(allocatedCount) * 2; - T *newElems = allocate(null_terminator::allocCount(s)); + T *newElems = allocate(s); // when elems is NULL, usedCount should also be 0, but add an extra check in here just to // satisfy coverity's static analysis which can't figure that out from the copy constructor @@ -686,8 +516,6 @@ public: // copy construct the new elems ItemCopyHelper::copyRange(elems, in.data(), usedCount); - null_terminator::fixup(elems, usedCount); - return *this; } @@ -709,8 +537,6 @@ public: i++; } - null_terminator::fixup(elems, usedCount); - return *this; } @@ -731,8 +557,6 @@ public: // copy construct the new elems ItemCopyHelper::copyRange(elems, in.data(), usedCount); - null_terminator::fixup(elems, usedCount); - return *this; } @@ -802,9 +626,8 @@ public: #endif }; -#include "rdcstr.h" +typedef uint8_t byte; -DOCUMENT(""); struct bytebuf : public rdcarray { bytebuf() : rdcarray() {} @@ -821,6 +644,3 @@ struct bytebuf : public rdcarray } #endif }; - -typedef rdcpair rdcstrpair; -typedef rdcarray rdcstrpairs; diff --git a/renderdoc/api/replay/rdcdatetime.h b/renderdoc/api/replay/rdcdatetime.h new file mode 100644 index 000000000..64c3a8e6e --- /dev/null +++ b/renderdoc/api/replay/rdcdatetime.h @@ -0,0 +1,91 @@ +/****************************************************************************** + * The MIT License (MIT) + * + * Copyright (c) 2015-2019 Baldur Karlsson + * Copyright (c) 2014 Crytek + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + ******************************************************************************/ + +#pragma once + +#include + +// primarily here just to remove a dependency on QDateTime in the Qt UI, so we don't have to bind +// against Qt at all in the interface. +struct rdcdatetime +{ + int32_t year = 0; + int32_t month = 0; + int32_t day = 0; + int32_t hour = 0; + int32_t minute = 0; + int32_t second = 0; + int32_t microsecond = 0; + + rdcdatetime() = default; + + rdcdatetime(int y, int mn, int d, int h = 0, int m = 0, int s = 0, int us = 0) + : year(y), month(mn), day(d), hour(h), minute(m), second(s), microsecond(us) + { + } + + bool operator==(const rdcdatetime &o) const + { + return year == o.year && month == o.month && day == o.day && hour == o.hour && + minute == o.minute && second == o.second && microsecond == o.microsecond; + } + bool operator!=(const rdcdatetime &o) const { return !(*this == o); } + bool operator<(const rdcdatetime &o) const + { + if(year != o.year) + return year < o.year; + if(month != o.month) + return month < o.month; + if(day != o.day) + return day < o.day; + if(hour != o.hour) + return hour < o.hour; + if(minute != o.minute) + return minute < o.minute; + if(second != o.second) + return second < o.second; + if(microsecond != o.microsecond) + return microsecond < o.microsecond; + return false; + } + +#if defined(RENDERDOC_QT_COMPAT) + rdcdatetime(const QDateTime &in) + { + year = in.date().year(); + month = in.date().month(); + day = in.date().day(); + hour = in.time().hour(); + minute = in.time().minute(); + second = in.time().second(); + microsecond = in.time().msec() * 1000; + } + operator QDateTime() const + { + return QDateTime(QDate(year, month, day), QTime(hour, minute, second, microsecond / 1000)); + } + operator QVariant() const { return QVariant(QDateTime(*this)); } +#endif +}; diff --git a/renderdoc/api/replay/rdcpair.h b/renderdoc/api/replay/rdcpair.h new file mode 100644 index 000000000..a64f1afeb --- /dev/null +++ b/renderdoc/api/replay/rdcpair.h @@ -0,0 +1,80 @@ +/****************************************************************************** + * The MIT License (MIT) + * + * Copyright (c) 2015-2019 Baldur Karlsson + * Copyright (c) 2014 Crytek + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + ******************************************************************************/ + +#pragma once + +template +struct rdcpair +{ + A first; + B second; + + rdcpair(const A &a, const B &b) : first(a), second(b) {} + rdcpair() = default; + rdcpair(const rdcpair &o) = default; + rdcpair(rdcpair &&o) = default; + ~rdcpair() = default; + inline void swap(rdcpair &o) + { + rdcpair tmp = *this; + *this = o; + o = tmp; + } + + template + rdcpair &operator=(const rdcpair &o) + { + first = o.first; + second = o.second; + return *this; + } + + rdcpair &operator=(const rdcpair &o) + { + first = o.first; + second = o.second; + return *this; + } + + bool operator==(const rdcpair &o) const { return first == o.first && second == o.second; } + bool operator<(const rdcpair &o) const + { + if(first != o.first) + return first < o.first; + return second < o.second; + } +}; + +template +rdcpair make_rdcpair(const A &a, const B &b) +{ + return rdcpair(a, b); +} + +template +rdcpair rdctie(A &a, B &b) +{ + return rdcpair(a, b); +} diff --git a/renderdoc/api/replay/rdcstr.h b/renderdoc/api/replay/rdcstr.h index 1562f4386..2fbadd8c1 100644 --- a/renderdoc/api/replay/rdcstr.h +++ b/renderdoc/api/replay/rdcstr.h @@ -24,10 +24,16 @@ #pragma once +#include // for standard types +#include // for memcpy, etc #include +#ifdef RENDERDOC_EXPORTS +#include // for malloc/free +void RENDERDOC_OutOfMemory(uint64_t sz); +#endif + // special type for storing literals. This allows functions to force callers to pass them literals -DOCUMENT(""); class rdcliteral { const char *str; @@ -49,11 +55,6 @@ inline rdcliteral operator"" _lit(const char *str, size_t len) return rdcliteral(str, len); } -#ifdef RENDERDOC_EXPORTS -void RENDERDOC_OutOfMemory(uint64_t sz); -#endif - -DOCUMENT(""); class rdcstr { private: @@ -128,7 +129,6 @@ private: ///////////////////////////////////////////////////////////////// // memory management, in a dll safe way - DOCUMENT(""); static char *allocate(size_t count) { char *ret = NULL; diff --git a/renderdoc/api/replay/renderdoc_replay.h b/renderdoc/api/replay/renderdoc_replay.h index 3ef3faff8..cf40d2040 100644 --- a/renderdoc/api/replay/renderdoc_replay.h +++ b/renderdoc/api/replay/renderdoc_replay.h @@ -105,7 +105,7 @@ #define RENDERDOC_API RENDERDOC_IMPORT_API #endif -// needs to be declared up here for reference in basic_types +// needs to be declared up here for reference in rdcarray/rdcstr extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_FreeArrayMem(void *mem); typedef void(RENDERDOC_CC *pRENDERDOC_FreeArrayMem)(void *mem); @@ -302,7 +302,14 @@ private: #endif }; -#include "basic_types.h" +DOCUMENT(""); + +typedef uint8_t byte; + +#include "rdcdatetime.h" +#include "rdcpair.h" +#include "rdcarray.h" +#include "rdcstr.h" #include "stringise.h" #include "structured_data.h" diff --git a/renderdoc/api/replay/shader_types.h b/renderdoc/api/replay/shader_types.h index a2b63b67b..092980a3c 100644 --- a/renderdoc/api/replay/shader_types.h +++ b/renderdoc/api/replay/shader_types.h @@ -26,7 +26,8 @@ #pragma once #include -#include "basic_types.h" +#include "rdcarray.h" +#include "rdcstr.h" #include "replay_enums.h" DOCUMENT("A ``float`` 4 component vector.") diff --git a/renderdoc/renderdoc.vcxproj b/renderdoc/renderdoc.vcxproj index c957d1e7e..5e31fe054 100644 --- a/renderdoc/renderdoc.vcxproj +++ b/renderdoc/renderdoc.vcxproj @@ -157,7 +157,7 @@ - + @@ -166,6 +166,8 @@ + + diff --git a/renderdoc/renderdoc.vcxproj.filters b/renderdoc/renderdoc.vcxproj.filters index bcfb9bff4..5972bb706 100644 --- a/renderdoc/renderdoc.vcxproj.filters +++ b/renderdoc/renderdoc.vcxproj.filters @@ -204,9 +204,6 @@ Common\Maths - - API\Replay - API\Replay @@ -489,6 +486,15 @@ Core\networking + + API\Replay + + + API\Replay + + + API\Replay +