From 1c614029d8f937e6bb78a7dc5684c91f0b7cfebd Mon Sep 17 00:00:00 2001 From: baldurk Date: Mon, 13 Nov 2017 12:21:26 +0000 Subject: [PATCH] Add a way to return basic information about all resources in a capture * This provides a way to find the name of any resource besides 'special' resources like textures and buffers. In a follow-up commit, the names will be removed from their descriptors. * It also allows us to list which chunks in the structured file were used to initialise the resource, giving the ability to look up and display the initialisation parameters. * At the same time we also list the derived/parent resources to better allow the user to browse between related resources. --- renderdoc/api/replay/data_types.h | 51 +++++++++ renderdoc/api/replay/renderdoc_replay.h | 14 ++- renderdoc/api/replay/renderdoc_tostr.inl | 27 +++++ renderdoc/api/replay/replay_enums.h | 121 +++++++++++++++++++++ renderdoc/core/image_viewer.cpp | 11 +- renderdoc/core/replay_proxy.cpp | 25 +++++ renderdoc/core/replay_proxy.h | 5 + renderdoc/driver/d3d11/d3d11_device.cpp | 2 +- renderdoc/driver/d3d11/d3d11_initstate.cpp | 8 +- renderdoc/driver/d3d11/d3d11_replay.cpp | 27 ++++- renderdoc/driver/d3d11/d3d11_replay.h | 10 +- renderdoc/driver/d3d11/d3d11_resources.cpp | 2 +- renderdoc/driver/d3d11/d3d11_resources.h | 6 +- renderdoc/driver/d3d11/d3d11_stringise.cpp | 4 +- renderdoc/driver/d3d12/d3d12_replay.cpp | 27 ++++- renderdoc/driver/d3d12/d3d12_replay.h | 10 +- renderdoc/driver/gl/gl_replay.cpp | 27 ++++- renderdoc/driver/gl/gl_replay.h | 10 +- renderdoc/driver/vulkan/vk_replay.cpp | 27 ++++- renderdoc/driver/vulkan/vk_replay.h | 10 +- renderdoc/replay/renderdoc_serialise.inl | 15 +++ renderdoc/replay/replay_controller.cpp | 47 ++++---- renderdoc/replay/replay_controller.h | 10 +- renderdoc/replay/replay_driver.h | 6 +- 24 files changed, 436 insertions(+), 66 deletions(-) diff --git a/renderdoc/api/replay/data_types.h b/renderdoc/api/replay/data_types.h index 834577fcd..a4ece8b5f 100644 --- a/renderdoc/api/replay/data_types.h +++ b/renderdoc/api/replay/data_types.h @@ -147,6 +147,57 @@ struct TextureFilter DECLARE_REFLECTION_STRUCT(TextureFilter); +DOCUMENT("A description of any type of resource."); +struct ResourceDescription +{ + DOCUMENT("The unique :class:`ResourceId` that identifies this resource."); + ResourceId ID; + + DOCUMENT("The :class:`ResourceType` of the resource."); + ResourceType type = ResourceType::Unknown; + + DOCUMENT(R"(``True`` if :data:`name` was just autogenerated based on the ID, not assigned a +human-readable name by the application. +)"); + bool autogeneratedName = true; + + DOCUMENT("The name given to this resource."); + rdcstr name; + + DOCUMENT(R"(The chunk indices in the structured file that initialised this resource. + +This will at least contain the first call that created it, but may contain other auxilliary calls. +)"); + rdcarray initialisationChunks; + + DOCUMENT(R"(The :class:`ResourceId` of any derived resources, such as resource views or aliases. + +Can be empty if there are no derived resources. + +This is the inverse of :data:`parentResources` in a potentially many:many relationship, but +typically it is one parent to many derived. +)"); + rdcarray derivedResources; + + DOCUMENT(R"(The :class:`ResourceId` of parent resources, of which this is derived. + +Can be empty if there are no parent resources. + +This is the inverse of :data:derivedResources in a potentially many:many relationship, but +typically it is one parent to many derived. +)"); + rdcarray parentResources; + + DOCUMENT("Utility function for setting up a custom name to overwrite the auto-generated one."); + inline void SetCustomName(const rdcstr &givenName) + { + autogeneratedName = false; + name = givenName; + } +}; + +DECLARE_REFLECTION_STRUCT(ResourceDescription); + DOCUMENT("A description of a buffer resource."); struct BufferDescription { diff --git a/renderdoc/api/replay/renderdoc_replay.h b/renderdoc/api/replay/renderdoc_replay.h index 7a707d1b1..c45c6aa7b 100644 --- a/renderdoc/api/replay/renderdoc_replay.h +++ b/renderdoc/api/replay/renderdoc_replay.h @@ -800,19 +800,29 @@ understanding as well as the type and unit of the resulting information. )"); virtual CounterDescription DescribeCounter(GPUCounter counterID) = 0; + DOCUMENT(R"(Retrieve the list of all resources in the capture. + +This includes any object allocated a :class:`ResourceId`, that don't have any other state or +are only used as intermediary elements. + +:return: The list of resources in the capture. +:rtype: ``list`` of :class:`ResourceDescription` +)"); + virtual const rdcarray &GetResources() = 0; + DOCUMENT(R"(Retrieve the list of textures alive in the capture. :return: The list of textures in the capture. :rtype: ``list`` of :class:`TextureDescription` )"); - virtual rdcarray GetTextures() = 0; + virtual const rdcarray &GetTextures() = 0; DOCUMENT(R"(Retrieve the list of buffers alive in the capture. :return: The list of buffers in the capture. :rtype: ``list`` of :class:`BufferDescription` )"); - virtual rdcarray GetBuffers() = 0; + virtual const rdcarray &GetBuffers() = 0; DOCUMENT(R"(Retrieve a list of any newly generated diagnostic messages. diff --git a/renderdoc/api/replay/renderdoc_tostr.inl b/renderdoc/api/replay/renderdoc_tostr.inl index 1fd4ecd9b..e8e8de398 100644 --- a/renderdoc/api/replay/renderdoc_tostr.inl +++ b/renderdoc/api/replay/renderdoc_tostr.inl @@ -416,6 +416,33 @@ std::string DoStringise(const AddressMode &el) END_ENUM_STRINGISE(); } +template <> +std::string DoStringise(const ResourceType &el) +{ + BEGIN_ENUM_STRINGISE(ResourceType) + { + STRINGISE_ENUM_CLASS(Unknown); + STRINGISE_ENUM_CLASS(Device); + STRINGISE_ENUM_CLASS(Queue); + STRINGISE_ENUM_CLASS(CommandBuffer); + STRINGISE_ENUM_CLASS(Texture); + STRINGISE_ENUM_CLASS(Buffer); + STRINGISE_ENUM_CLASS(View); + STRINGISE_ENUM_CLASS(Sampler); + STRINGISE_ENUM_CLASS(SwapchainImage); + STRINGISE_ENUM_CLASS(Memory); + STRINGISE_ENUM_CLASS(Shader); + STRINGISE_ENUM_CLASS(ShaderBinding); + STRINGISE_ENUM_CLASS(PipelineState); + STRINGISE_ENUM_CLASS(StateObject); + STRINGISE_ENUM_CLASS(RenderPass); + STRINGISE_ENUM_CLASS(Query); + STRINGISE_ENUM_CLASS(Sync); + STRINGISE_ENUM_CLASS(Pool); + } + END_ENUM_STRINGISE(); +} + template <> std::string DoStringise(const TextureDim &el) { diff --git a/renderdoc/api/replay/replay_enums.h b/renderdoc/api/replay/replay_enums.h index 6f20aa95d..1ee85560f 100644 --- a/renderdoc/api/replay/replay_enums.h +++ b/renderdoc/api/replay/replay_enums.h @@ -252,6 +252,127 @@ enum class AddressMode : uint32_t DECLARE_REFLECTION_ENUM(AddressMode); +DOCUMENT(R"(The type of a resource referred to by binding or API usage. + +In some cases there is a little overlap or fudging when mapping API concepts - this is primarily +just intended for e.g. fuzzy user filtering or rough categorisation. Precise mapping would require +API-specific concepts. + +.. data:: Unknown + + An unknown type of resource. + +.. data:: Device + + A system-level object, typically unique. + +.. data:: Queue + + A queue representing the ability to execute commands in a single stream, possibly in parallel to + other queues. + +.. data:: CommandBuffer + + A recorded set of commands that can then be subsequently executed. + +.. data:: Texture + + A texture - one- to three- dimensional, possibly with array layers and mip levels. See + :class:`TextureDescription`. + +.. data:: Buffer + + A linear (possibly typed) view of memory. See :class:`BufferDescription`. + +.. data:: View + + A particular view into a texture or buffer, e.g. either accessing the underlying resource through + a different type, or only a subset of the resource. + +.. data:: Sampler + + The information regarding how a texture is accessed including wrapping, minification/magnification + and other information. The precise details are API-specific and listed in the API state when + bound. + +.. data:: SwapchainImage + + A special class of :data:`Texture` that is owned by the swapchain and is used for presentation. + +.. data:: Memory + + An object corresponding to an actual memory allocation, which other resources can then be bound + to. + +.. data:: Shader + + A single shader object for any shader stage. May be bound directly, or used to compose into a + :data:`PipelineState` depending on the API. + +.. data:: ShaderBinding + + An object that determines some manner of shader binding. Since this varies significantly by API, + different concepts used for shader resource binding fall under this type. + +.. data:: PipelineState + + A single object containing all information regarding the current GPU pipeline, containing both + shader objects, potentially some shader binding information, and fixed-function state. + +.. data:: StateObject + + A single object encapsulating some amount of related state that can be set together, instead of + setting each individual state separately. + +.. data:: RenderPass + + An object related to collecting render pass information together. This may not be an actual + explicit render pass object if it doesn't exist in the API, it may also be a collection of + textures in a framebuffer that are bound together to the API for rendering. + +.. data:: Query + + A query for retrieving some kind of feedback from the GPU, either as a fixed number or a boolean + value which can be used in predicated rendering. + +.. data:: Sync + + A synchronisation object used for either synchronisation between GPU and CPU, or GPU-to-GPU work. + +.. data:: Pool + + An object which pools together other objects in an opaque way, either for runtime allocation and + deallocation, or for caching purposes. +)"); +enum class ResourceType : uint32_t +{ + Unknown, + + Device, + Queue, + CommandBuffer, + + Texture, + Buffer, + View, + Sampler, + SwapchainImage, + Memory, + + Shader, + ShaderBinding, + PipelineState, + + StateObject, + RenderPass, + + Query, + Sync, + Pool, +}; + +DECLARE_REFLECTION_ENUM(ResourceType); + DOCUMENT(R"(The dimensionality of a texture binding. .. data:: Unknown diff --git a/renderdoc/core/image_viewer.cpp b/renderdoc/core/image_viewer.cpp index d503b6f52..f4cc6abee 100644 --- a/renderdoc/core/image_viewer.cpp +++ b/renderdoc/core/image_viewer.cpp @@ -55,6 +55,11 @@ public: RefreshFile(); + m_Resources.push_back(ResourceDescription()); + m_Resources[0].ID = m_TextureID; + m_Resources[0].autogeneratedName = false; + m_Resources[0].name = m_Filename; + m_PipelineState.m_OM.RenderTargets.resize(1); m_PipelineState.m_OM.RenderTargets[0].Resource = m_TextureID; } @@ -135,7 +140,8 @@ public: { return m_Proxy->ApplyCustomShader(shader, m_TextureID, mip, arrayIdx, sampleIdx, typeHint); } - vector GetTextures() { return {m_TextureID}; } + const std::vector &GetResources() { return m_Resources; } + std::vector GetTextures() { return {m_TextureID}; } TextureDescription GetTexture(ResourceId id) { return m_Proxy->GetTexture(m_TextureID); } void GetTextureData(ResourceId tex, uint32_t arrayIdx, uint32_t mip, const GetTextureDataParams ¶ms, bytebuf &data) @@ -153,7 +159,7 @@ public: void RenderMesh(uint32_t eventID, const vector &secondaryDraws, const MeshDisplay &cfg) { } - vector GetBuffers() { return vector(); } + std::vector GetBuffers() { return vector(); } vector GetDebugMessages() { return vector(); } BufferDescription GetBuffer(ResourceId id) { @@ -277,6 +283,7 @@ private: IReplayDriver *m_Proxy; string m_Filename; ResourceId m_TextureID; + std::vector m_Resources; SDFile m_File; TextureDescription m_TexDetails; }; diff --git a/renderdoc/core/replay_proxy.cpp b/renderdoc/core/replay_proxy.cpp index 2aadb8310..18ff3d904 100644 --- a/renderdoc/core/replay_proxy.cpp +++ b/renderdoc/core/replay_proxy.cpp @@ -261,6 +261,30 @@ std::vector ReplayProxy::GetBuffers() PROXY_FUNCTION(GetBuffers); } +template +const std::vector &ReplayProxy::Proxied_GetResources(ParamSerialiser ¶mser, + ReturnSerialiser &retser) +{ + const ReplayProxyPacket packet = eReplayProxy_GetResources; + + { + BEGIN_PARAMS(); + END_PARAMS(); + } + + if(paramser.IsReading() && !paramser.IsErrored() && !m_IsErrored) + m_Resources = m_Remote->GetResources(); + + SERIALISE_RETURN(m_Resources); + + return m_Resources; +} + +const std::vector &ReplayProxy::GetResources() +{ + PROXY_FUNCTION(GetResources); +} + template BufferDescription ReplayProxy::Proxied_GetBuffer(ParamSerialiser ¶mser, ReturnSerialiser &retser, ResourceId id) @@ -1461,6 +1485,7 @@ bool ReplayProxy::Tick(int type) case eReplayProxy_FetchStructuredFile: FetchStructuredFile(); break; case eReplayProxy_GetAPIProperties: GetAPIProperties(); break; case eReplayProxy_GetPassEvents: GetPassEvents(0); break; + case eReplayProxy_GetResources: GetResources(); break; case eReplayProxy_GetTextures: GetTextures(); break; case eReplayProxy_GetTexture: GetTexture(ResourceId()); break; case eReplayProxy_GetBuffers: GetBuffers(); break; diff --git a/renderdoc/core/replay_proxy.h b/renderdoc/core/replay_proxy.h index 6f6fdd97e..bf1588fa5 100644 --- a/renderdoc/core/replay_proxy.h +++ b/renderdoc/core/replay_proxy.h @@ -42,6 +42,7 @@ enum ReplayProxyPacket eReplayProxy_GetPassEvents, + eReplayProxy_GetResources, eReplayProxy_GetTextures, eReplayProxy_GetTexture, eReplayProxy_GetBuffers, @@ -391,6 +392,8 @@ public: const SDFile &GetStructuredFile() { return m_StructuredFile; } IMPLEMENT_FUNCTION_PROXIED(void, FetchStructuredFile); + IMPLEMENT_FUNCTION_PROXIED(const std::vector &, GetResources); + IMPLEMENT_FUNCTION_PROXIED(std::vector, GetBuffers); IMPLEMENT_FUNCTION_PROXIED(BufferDescription, GetBuffer, ResourceId id); @@ -559,6 +562,8 @@ private: SDFile m_StructuredFile; + std::vector m_Resources; + D3D11Pipe::State m_D3D11PipelineState; D3D12Pipe::State m_D3D12PipelineState; GLPipe::State m_GLPipelineState; diff --git a/renderdoc/driver/d3d11/d3d11_device.cpp b/renderdoc/driver/d3d11/d3d11_device.cpp index 673f3c3b0..becebc962 100644 --- a/renderdoc/driver/d3d11/d3d11_device.cpp +++ b/renderdoc/driver/d3d11/d3d11_device.cpp @@ -2184,7 +2184,7 @@ void WrappedID3D11Device::ReleaseResource(ID3D11DeviceChild *res) SCOPED_LOCK(m_D3DLock); - ResourceType type = IdentifyTypeByPtr(res); + D3D11ResourceType type = IdentifyTypeByPtr(res); D3D11ResourceRecord *record = m_DeviceRecord; diff --git a/renderdoc/driver/d3d11/d3d11_initstate.cpp b/renderdoc/driver/d3d11/d3d11_initstate.cpp index fe82cb8e6..e622c3379 100644 --- a/renderdoc/driver/d3d11/d3d11_initstate.cpp +++ b/renderdoc/driver/d3d11/d3d11_initstate.cpp @@ -28,7 +28,7 @@ bool WrappedID3D11Device::Prepare_InitialState(ID3D11DeviceChild *res) { - ResourceType type = IdentifyTypeByPtr(res); + D3D11ResourceType type = IdentifyTypeByPtr(res); ResourceId Id = GetIDForResource(res); RDCASSERT(IsCaptureMode(m_State)); @@ -284,7 +284,7 @@ uint32_t WrappedID3D11Device::GetSize_InitialState(ResourceId id, ID3D11DeviceCh // pessimistic DepthPitch alignment const UINT WorstDepthPitchAlign = 256; - ResourceType type = IdentifyTypeByPtr(res); + D3D11ResourceType type = IdentifyTypeByPtr(res); if(type == Resource_UnorderedAccessView) { @@ -401,7 +401,7 @@ template bool WrappedID3D11Device::Serialise_InitialState(SerialiserType &ser, ResourceId resid, ID3D11DeviceChild *res) { - ResourceType type = Resource_Unknown; + D3D11ResourceType type = Resource_Unknown; ResourceId Id = ResourceId(); if(IsCaptureMode(m_State)) @@ -937,7 +937,7 @@ void WrappedID3D11Device::Create_InitialState(ResourceId id, ID3D11DeviceChild * if(IsStructuredExporting(m_State)) return; - ResourceType type = IdentifyTypeByPtr(live); + D3D11ResourceType type = IdentifyTypeByPtr(live); { RDCDEBUG("Create_InitialState(%llu)", id); diff --git a/renderdoc/driver/d3d11/d3d11_replay.cpp b/renderdoc/driver/d3d11/d3d11_replay.cpp index 4b2b5eec3..0a5f62f61 100644 --- a/renderdoc/driver/d3d11/d3d11_replay.cpp +++ b/renderdoc/driver/d3d11/d3d11_replay.cpp @@ -391,9 +391,28 @@ APIProperties D3D11Replay::GetAPIProperties() return ret; } -vector D3D11Replay::GetBuffers() +ResourceDescription &D3D11Replay::GetResourceDesc(ResourceId id) { - vector ret; + auto it = m_ResourceIdx.find(id); + if(it == m_ResourceIdx.end()) + { + m_ResourceIdx[id] = m_Resources.size(); + m_Resources.push_back(ResourceDescription()); + m_Resources.back().ID = id; + return m_Resources.back(); + } + + return m_Resources[it->second]; +} + +const std::vector &D3D11Replay::GetResources() +{ + return m_Resources; +} + +std::vector D3D11Replay::GetBuffers() +{ + std::vector ret; ret.reserve(WrappedID3D11Buffer::m_BufferList.size()); @@ -452,9 +471,9 @@ BufferDescription D3D11Replay::GetBuffer(ResourceId id) return ret; } -vector D3D11Replay::GetTextures() +std::vector D3D11Replay::GetTextures() { - vector ret; + std::vector ret; ret.reserve(WrappedID3D11Texture1D::m_TextureList.size() + WrappedID3D11Texture2D1::m_TextureList.size() + diff --git a/renderdoc/driver/d3d11/d3d11_replay.h b/renderdoc/driver/d3d11/d3d11_replay.h index b1f5f45ab..67ff80c2c 100644 --- a/renderdoc/driver/d3d11/d3d11_replay.h +++ b/renderdoc/driver/d3d11/d3d11_replay.h @@ -48,10 +48,13 @@ public: void SetDevice(WrappedID3D11Device *d) { m_pDevice = d; } APIProperties GetAPIProperties(); - vector GetBuffers(); + ResourceDescription &GetResourceDesc(ResourceId id); + const std::vector &GetResources(); + + std::vector GetBuffers(); BufferDescription GetBuffer(ResourceId id); - vector GetTextures(); + std::vector GetTextures(); TextureDescription GetTexture(ResourceId id); vector GetDebugMessages(); @@ -174,6 +177,9 @@ private: WrappedID3D11Device *m_pDevice; + std::vector m_Resources; + std::map m_ResourceIdx; + D3D11Pipe::State m_CurPipelineState; D3D12Pipe::State m_D3D12State; VKPipe::State m_VKState; diff --git a/renderdoc/driver/d3d11/d3d11_resources.cpp b/renderdoc/driver/d3d11/d3d11_resources.cpp index 651bdce87..a36655675 100644 --- a/renderdoc/driver/d3d11/d3d11_resources.cpp +++ b/renderdoc/driver/d3d11/d3d11_resources.cpp @@ -349,7 +349,7 @@ ResourceId GetIDForDeviceChild(ID3D11DeviceChild *ptr) return ResourceId(); } -ResourceType IdentifyTypeByPtr(IUnknown *ptr) +D3D11ResourceType IdentifyTypeByPtr(IUnknown *ptr) { if(WrappedID3D11InputLayout::IsAlloc(ptr)) return Resource_InputLayout; diff --git a/renderdoc/driver/d3d11/d3d11_resources.h b/renderdoc/driver/d3d11/d3d11_resources.h index 91a03b081..0860fa0e5 100644 --- a/renderdoc/driver/d3d11/d3d11_resources.h +++ b/renderdoc/driver/d3d11/d3d11_resources.h @@ -30,7 +30,7 @@ #include "driver/d3d11/d3d11_manager.h" #include "driver/shaders/dxbc/dxbc_inspect.h" -enum ResourceType +enum D3D11ResourceType { Resource_Unknown = 0, Resource_InputLayout, @@ -60,9 +60,9 @@ enum ResourceType Resource_DeviceState, }; -DECLARE_REFLECTION_ENUM(ResourceType); +DECLARE_REFLECTION_ENUM(D3D11ResourceType); -ResourceType IdentifyTypeByPtr(IUnknown *ptr); +D3D11ResourceType IdentifyTypeByPtr(IUnknown *ptr); ResourceId GetIDForDeviceChild(ID3D11DeviceChild *ptr); template inline ResourceId GetIDForResource(T *ptr); diff --git a/renderdoc/driver/d3d11/d3d11_stringise.cpp b/renderdoc/driver/d3d11/d3d11_stringise.cpp index c77628964..100a772b4 100644 --- a/renderdoc/driver/d3d11/d3d11_stringise.cpp +++ b/renderdoc/driver/d3d11/d3d11_stringise.cpp @@ -27,9 +27,9 @@ #include "d3d11_resources.h" template <> -std::string DoStringise(const ResourceType &el) +std::string DoStringise(const D3D11ResourceType &el) { - BEGIN_ENUM_STRINGISE(ResourceType); + BEGIN_ENUM_STRINGISE(D3D11ResourceType); { STRINGISE_ENUM(Resource_InputLayout) STRINGISE_ENUM(Resource_Buffer) diff --git a/renderdoc/driver/d3d12/d3d12_replay.cpp b/renderdoc/driver/d3d12/d3d12_replay.cpp index 6a081e90e..38baaef2d 100644 --- a/renderdoc/driver/d3d12/d3d12_replay.cpp +++ b/renderdoc/driver/d3d12/d3d12_replay.cpp @@ -86,9 +86,28 @@ const SDFile &D3D12Replay::GetStructuredFile() return m_pDevice->GetStructuredFile(); } -vector D3D12Replay::GetBuffers() +ResourceDescription &D3D12Replay::GetResourceDesc(ResourceId id) { - vector ret; + auto it = m_ResourceIdx.find(id); + if(it == m_ResourceIdx.end()) + { + m_ResourceIdx[id] = m_Resources.size(); + m_Resources.push_back(ResourceDescription()); + m_Resources.back().ID = id; + return m_Resources.back(); + } + + return m_Resources[it->second]; +} + +const std::vector &D3D12Replay::GetResources() +{ + return m_Resources; +} + +std::vector D3D12Replay::GetBuffers() +{ + std::vector ret; for(auto it = WrappedID3D12Resource::GetList().begin(); it != WrappedID3D12Resource::GetList().end(); it++) @@ -98,9 +117,9 @@ vector D3D12Replay::GetBuffers() return ret; } -vector D3D12Replay::GetTextures() +std::vector D3D12Replay::GetTextures() { - vector ret; + std::vector ret; for(auto it = WrappedID3D12Resource::GetList().begin(); it != WrappedID3D12Resource::GetList().end(); it++) diff --git a/renderdoc/driver/d3d12/d3d12_replay.h b/renderdoc/driver/d3d12/d3d12_replay.h index 6b56a87a3..dc5b51b6e 100644 --- a/renderdoc/driver/d3d12/d3d12_replay.h +++ b/renderdoc/driver/d3d12/d3d12_replay.h @@ -46,10 +46,13 @@ public: void SetDevice(WrappedID3D12Device *d) { m_pDevice = d; } APIProperties GetAPIProperties(); - vector GetBuffers(); + ResourceDescription &GetResourceDesc(ResourceId id); + const std::vector &GetResources(); + + std::vector GetBuffers(); BufferDescription GetBuffer(ResourceId id); - vector GetTextures(); + std::vector GetTextures(); TextureDescription GetTexture(ResourceId id); vector GetDebugMessages(); @@ -184,6 +187,9 @@ private: vector m_ProxyResources; + std::vector m_Resources; + std::map m_ResourceIdx; + D3D12Pipe::State m_PipelineState; D3D11Pipe::State m_D3D11State; VKPipe::State m_VKState; diff --git a/renderdoc/driver/gl/gl_replay.cpp b/renderdoc/driver/gl/gl_replay.cpp index b3080b3be..208bd9d2b 100644 --- a/renderdoc/driver/gl/gl_replay.cpp +++ b/renderdoc/driver/gl/gl_replay.cpp @@ -145,9 +145,9 @@ APIProperties GLReplay::GetAPIProperties() return ret; } -vector GLReplay::GetBuffers() +std::vector GLReplay::GetBuffers() { - vector ret; + std::vector ret; for(auto it = m_pDriver->m_Buffers.begin(); it != m_pDriver->m_Buffers.end(); ++it) { @@ -161,9 +161,28 @@ vector GLReplay::GetBuffers() return ret; } -vector GLReplay::GetTextures() +ResourceDescription &GLReplay::GetResourceDesc(ResourceId id) { - vector ret; + auto it = m_ResourceIdx.find(id); + if(it == m_ResourceIdx.end()) + { + m_ResourceIdx[id] = m_Resources.size(); + m_Resources.push_back(ResourceDescription()); + m_Resources.back().ID = id; + return m_Resources.back(); + } + + return m_Resources[it->second]; +} + +const std::vector &GLReplay::GetResources() +{ + return m_Resources; +} + +std::vector GLReplay::GetTextures() +{ + std::vector ret; ret.reserve(m_pDriver->m_Textures.size()); for(auto it = m_pDriver->m_Textures.begin(); it != m_pDriver->m_Textures.end(); ++it) diff --git a/renderdoc/driver/gl/gl_replay.h b/renderdoc/driver/gl/gl_replay.h index 6b10b42b3..808a57c69 100644 --- a/renderdoc/driver/gl/gl_replay.h +++ b/renderdoc/driver/gl/gl_replay.h @@ -93,10 +93,13 @@ public: void SetDriver(WrappedOpenGL *d) { m_pDriver = d; } APIProperties GetAPIProperties(); - vector GetBuffers(); + ResourceDescription &GetResourceDesc(ResourceId id); + const std::vector &GetResources(); + + std::vector GetBuffers(); BufferDescription GetBuffer(ResourceId id); - vector GetTextures(); + std::vector GetTextures(); TextureDescription GetTexture(ResourceId id); ShaderReflection *GetShader(ResourceId shader, string entryPoint); @@ -412,6 +415,9 @@ private: WrappedOpenGL *m_pDriver; + std::vector m_Resources; + std::map m_ResourceIdx; + GLPipe::State m_CurPipelineState; D3D11Pipe::State m_D3D11State; D3D12Pipe::State m_D3D12State; diff --git a/renderdoc/driver/vulkan/vk_replay.cpp b/renderdoc/driver/vulkan/vk_replay.cpp index 10ace3115..74a261ae8 100644 --- a/renderdoc/driver/vulkan/vk_replay.cpp +++ b/renderdoc/driver/vulkan/vk_replay.cpp @@ -750,9 +750,28 @@ vector VulkanReplay::GetDebugMessages() return m_pDriver->GetDebugMessages(); } -vector VulkanReplay::GetTextures() +ResourceDescription &VulkanReplay::GetResourceDesc(ResourceId id) { - vector texs; + auto it = m_ResourceIdx.find(id); + if(it == m_ResourceIdx.end()) + { + m_ResourceIdx[id] = m_Resources.size(); + m_Resources.push_back(ResourceDescription()); + m_Resources.back().ID = id; + return m_Resources.back(); + } + + return m_Resources[it->second]; +} + +const std::vector &VulkanReplay::GetResources() +{ + return m_Resources; +} + +std::vector VulkanReplay::GetTextures() +{ + std::vector texs; for(auto it = m_pDriver->m_ImageLayouts.begin(); it != m_pDriver->m_ImageLayouts.end(); ++it) { @@ -766,9 +785,9 @@ vector VulkanReplay::GetTextures() return texs; } -vector VulkanReplay::GetBuffers() +std::vector VulkanReplay::GetBuffers() { - vector bufs; + std::vector bufs; for(auto it = m_pDriver->m_CreationInfo.m_Buffer.begin(); it != m_pDriver->m_CreationInfo.m_Buffer.end(); ++it) diff --git a/renderdoc/driver/vulkan/vk_replay.h b/renderdoc/driver/vulkan/vk_replay.h index 15a7b1e30..3269dbf5e 100644 --- a/renderdoc/driver/vulkan/vk_replay.h +++ b/renderdoc/driver/vulkan/vk_replay.h @@ -136,10 +136,13 @@ public: void SetDriver(WrappedVulkan *d) { m_pDriver = d; } APIProperties GetAPIProperties(); - vector GetBuffers(); + ResourceDescription &GetResourceDesc(ResourceId id); + const std::vector &GetResources(); + + std::vector GetBuffers(); BufferDescription GetBuffer(ResourceId id); - vector GetTextures(); + std::vector GetTextures(); TextureDescription GetTexture(ResourceId id); ShaderReflection *GetShader(ResourceId shader, string entryPoint); @@ -321,6 +324,9 @@ private: VulkanResourceManager *m_ResourceManager; }; + std::vector m_Resources; + std::map m_ResourceIdx; + VKPipe::State m_VulkanPipelineState; D3D11Pipe::State m_D3D11State; D3D12Pipe::State m_D3D12State; diff --git a/renderdoc/replay/renderdoc_serialise.inl b/renderdoc/replay/renderdoc_serialise.inl index 25b2306ad..9db78f13c 100644 --- a/renderdoc/replay/renderdoc_serialise.inl +++ b/renderdoc/replay/renderdoc_serialise.inl @@ -323,6 +323,20 @@ void DoSerialise(SerialiserType &ser, TextureFilter &el) SIZE_CHECK(16); } +template +void DoSerialise(SerialiserType &ser, ResourceDescription &el) +{ + SERIALISE_MEMBER(ID); + SERIALISE_MEMBER(type); + SERIALISE_MEMBER(name); + SERIALISE_MEMBER(autogeneratedName); + SERIALISE_MEMBER(initialisationChunks); + SERIALISE_MEMBER(derivedResources); + SERIALISE_MEMBER(parentResources); + + SIZE_CHECK(80); +} + template void DoSerialise(SerialiserType &ser, TextureDescription &el) { @@ -2202,6 +2216,7 @@ INSTANTIATE_SERIALISE_TYPE(ShaderReflection) INSTANTIATE_SERIALISE_TYPE(ShaderVariable) INSTANTIATE_SERIALISE_TYPE(ShaderDebugState) INSTANTIATE_SERIALISE_TYPE(ShaderDebugTrace) +INSTANTIATE_SERIALISE_TYPE(ResourceDescription) INSTANTIATE_SERIALISE_TYPE(TextureDescription) INSTANTIATE_SERIALISE_TYPE(BufferDescription) INSTANTIATE_SERIALISE_TYPE(APIProperties) diff --git a/renderdoc/replay/replay_controller.cpp b/renderdoc/replay/replay_controller.cpp index ac5ca0710..8c9185d18 100644 --- a/renderdoc/replay/replay_controller.cpp +++ b/renderdoc/replay/replay_controller.cpp @@ -293,33 +293,18 @@ CounterDescription ReplayController::DescribeCounter(GPUCounter counterID) return m_pDevice->DescribeCounter(counterID); } -rdcarray ReplayController::GetBuffers() +const rdcarray &ReplayController::GetResources() { - if(m_Buffers.empty()) - { - vector ids = m_pDevice->GetBuffers(); - - m_Buffers.resize(ids.size()); - - for(size_t i = 0; i < ids.size(); i++) - m_Buffers[i] = m_pDevice->GetBuffer(ids[i]); - } + return m_Resources; +} +const rdcarray &ReplayController::GetBuffers() +{ return m_Buffers; } -rdcarray ReplayController::GetTextures() +const rdcarray &ReplayController::GetTextures() { - if(m_Textures.empty()) - { - vector ids = m_pDevice->GetTextures(); - - m_Textures.resize(ids.size()); - - for(size_t i = 0; i < ids.size(); i++) - m_Textures[i] = m_pDevice->GetTexture(ids[i]); - } - return m_Textures; } @@ -1564,6 +1549,26 @@ ReplayStatus ReplayController::PostCreateInit(IReplayDriver *device, RDCFile *rd FetchPipelineState(); + { + std::vector ids = m_pDevice->GetBuffers(); + + m_Buffers.resize(ids.size()); + + for(size_t i = 0; i < ids.size(); i++) + m_Buffers[i] = m_pDevice->GetBuffer(ids[i]); + } + + { + std::vector ids = m_pDevice->GetTextures(); + + m_Textures.resize(ids.size()); + + for(size_t i = 0; i < ids.size(); i++) + m_Textures[i] = m_pDevice->GetTexture(ids[i]); + } + + m_Resources = m_pDevice->GetResources(); + m_FrameRecord = m_pDevice->GetFrameRecord(); DrawcallDescription *previous = NULL; diff --git a/renderdoc/replay/replay_controller.h b/renderdoc/replay/replay_controller.h index 58607a5e7..5b07e5be2 100644 --- a/renderdoc/replay/replay_controller.h +++ b/renderdoc/replay/replay_controller.h @@ -162,8 +162,9 @@ public: rdcarray FetchCounters(const rdcarray &counters); rdcarray EnumerateCounters(); CounterDescription DescribeCounter(GPUCounter counterID); - rdcarray GetTextures(); - rdcarray GetBuffers(); + const rdcarray &GetTextures(); + const rdcarray &GetBuffers(); + const rdcarray &GetResources(); rdcarray GetDebugMessages(); rdcarray PixelHistory(ResourceId target, uint32_t x, uint32_t y, uint32_t slice, @@ -218,8 +219,9 @@ private: std::vector m_Outputs; - std::vector m_Buffers; - std::vector m_Textures; + rdcarray m_Resources; + rdcarray m_Buffers; + rdcarray m_Textures; IReplayDriver *m_pDevice; diff --git a/renderdoc/replay/replay_driver.h b/renderdoc/replay/replay_driver.h index 7d8a2e0bf..133bbab3a 100644 --- a/renderdoc/replay/replay_driver.h +++ b/renderdoc/replay/replay_driver.h @@ -90,10 +90,12 @@ public: virtual APIProperties GetAPIProperties() = 0; - virtual vector GetBuffers() = 0; + virtual const std::vector &GetResources() = 0; + + virtual std::vector GetBuffers() = 0; virtual BufferDescription GetBuffer(ResourceId id) = 0; - virtual vector GetTextures() = 0; + virtual std::vector GetTextures() = 0; virtual TextureDescription GetTexture(ResourceId id) = 0; virtual vector GetDebugMessages() = 0;