Skip to content

Commit

Permalink
Dump root parameters, insted of descriptor heap (#1862)
Browse files Browse the repository at this point in the history
* Dump root parameters, insted of descriptor heap

1. Dump SetXXXRootDescriptorTable, SetXXXRootConstantBufferView, SetXXXRootShaderResourceView, SetXXXRootUnorderedAccessView, instead of descriptor heap. Root parameters are more straightforward since they are used by shaders.

2. Find RootParameters info in dx12_browse_consumer.h and Dx12DumpResources::CreateRootSignature, and then dump them.

3. Dump some infos about root parameters. Although root_signature_type and cmd_bind_type are the same thing, but I saw some titles that they were different, so I chose to write both. That's mistakes and should trigger validation log. Added a function Dx12DumpResourcesDelegate::WriteNote to write some help info into .json, like some mistakes are found.

4. Added two flags in dx12_dump_resources.cpp: TEST_WRITE_NOT_FOUND_VIEWS,TEST_WRITE_NULL_RESOURCE_VIEWS.

The NumDescriptors in RootParameters could be large, but the index might not be found in cbv_srv_uav_infos of D3D12DescriptorHeapInfo. Set TEST_WRITE_NOT_FOUND_VIEWS: true to write the heap index info even if the index isn't found. Set false to skip it.

BufferLocation in CreateConstantBufferView or pResource in CreateShaderResourceView or CreateUnorderedAccessView could be 0. Set TEST_WRITE_NULL_RESOURCE_VIEWS: true to write the heap index info even if the value is 0. Set false to skip it.

5. CreateConstantBufferView, CreateShaderResourceView and CreateUnorderedAccessView could set the same DestDescriptor. The newer view setting could override it to get the DestDescriptor. The older view setting is quit. In this case, changed these struct infos into one struct info.

6. If the target drawcall is dispatch, dump compute root parameters. If it's not, dump graphics. But if it's ExecuteIndirect, dump both graphics and compute root parameters, since we don't know what it's inside.

7. CaptureGPUAddrMatchDescriptorHeap find the index of the heap for the address of root descriptor tables. Use the index to find the view in the map in the heap.

Not using MatchDescriptorCPUGPUHandle and "for loop" to find the view any more. MatchDescriptorCPUGPUHandle has a bug to find a wrong view.

RelayCPUAddrMatchDescriptorHeap find the index of the heap for the address of rtvs and dsv. Use the index to find the view in the map in the heap.

8. Skip dump vertices, index, rtv and dsv if the taget drawcall is dispatch.

* Move GetDescriptorSubresourceIndices

Move GetDescriptorSubresourceIndices to Dx12DumpResources. And fix two "<=" to "<".

* Clean up writing dump infos

Add WriteRootParameterInfo, WriteNotFoundView, WriteNULLResource,
WriteNULLBufferLocation in Dx12DumpResourcesDelegate to make writing
infos simpler.

Move checking TEST_WRITE_NULL_RESOURCE_VIEWS into
CopyDrawCallResourceByGPUVA and CopyDrawCallResourceBySubresource.
  • Loading branch information
locke-lunarg authored Nov 20, 2024
1 parent 3d082df commit 0000a1e
Show file tree
Hide file tree
Showing 7 changed files with 1,846 additions and 963 deletions.
10 changes: 10 additions & 0 deletions framework/decode/custom_dx12_replay_commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ struct CustomReplayPostCall<format::ApiCallId::ApiCall_ID3D12Device_CreateConsta
}
};

template <>
struct CustomReplayPostCall<format::ApiCallId::ApiCall_ID3D12Device_CreateSampler>
{
template <typename... Args>
static void Dispatch(Dx12ReplayConsumerBase* replay, Args... args)
{
replay->PostCall_ID3D12Device_CreateSampler(args...);
}
};

template <>
struct CustomReplayPostCall<format::ApiCallId::ApiCall_ID3D12Device_CreateShaderResourceView>
{
Expand Down
305 changes: 274 additions & 31 deletions framework/decode/dx12_browse_consumer.h

Large diffs are not rendered by default.

1,749 changes: 1,360 additions & 389 deletions framework/decode/dx12_dump_resources.cpp

Large diffs are not rendered by default.

74 changes: 72 additions & 2 deletions framework/decode/dx12_dump_resources.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ enum class Dx12DumpResourceType : uint32_t
kCbv,
kExecuteIndirectArg,
kExecuteIndirectCount,
kGraphicsRootParameters,
kComputeRootParameters,
};

struct CopyResourceData
Expand Down Expand Up @@ -152,6 +154,28 @@ class Dx12DumpResourcesDelegate
virtual void BeginDumpResources(const std::string& filename, const TrackDumpResources& track_dump_resources) = 0;
virtual void DumpResource(CopyResourceDataPtr resource_data) = 0;
virtual void EndDumpResources() = 0;
virtual void WriteSingleData(const std::vector<std::pair<std::string, int32_t>>& json_path,
const std::string& key,
uint64_t value) = 0;
virtual void WriteSingleData(const std::vector<std::pair<std::string, int32_t>>& json_path,
const uint32_t index,
uint64_t value) = 0;
virtual void WriteSingleData(const std::vector<std::pair<std::string, int32_t>>& json_path,
const std::string& key,
const std::string& value) = 0;
virtual void WriteNote(const std::vector<std::pair<std::string, int32_t>>& json_path, const std::string& value) = 0;
virtual void WriteRootParameterInfo(const std::vector<std::pair<std::string, int32_t>>& json_path,
uint32_t root_parameter_index,
const TrackRootParameter& root_parameter) = 0;
virtual void WriteNotFoundView(const std::vector<std::pair<std::string, int32_t>>& json_path,
format::HandleId heap_id,
uint32_t heap_index) = 0;
virtual void WriteNULLResource(const std::vector<std::pair<std::string, int32_t>>& json_path,
format::HandleId heap_id,
uint32_t heap_index) = 0;
virtual void WriteNULLBufferLocation(const std::vector<std::pair<std::string, int32_t>>& json_path,
format::HandleId heap_id,
uint32_t heap_index) = 0;
};

class DefaultDx12DumpResourcesDelegate : public Dx12DumpResourcesDelegate
Expand All @@ -163,6 +187,29 @@ class DefaultDx12DumpResourcesDelegate : public Dx12DumpResourcesDelegate
const TrackDumpResources& track_dump_resources) override;
virtual void DumpResource(CopyResourceDataPtr resource_data) override;
virtual void EndDumpResources() override;
virtual void WriteSingleData(const std::vector<std::pair<std::string, int32_t>>& json_path,
const std::string& key,
uint64_t value) override;
virtual void WriteSingleData(const std::vector<std::pair<std::string, int32_t>>& json_path,
const uint32_t index,
uint64_t value) override;
virtual void WriteSingleData(const std::vector<std::pair<std::string, int32_t>>& json_path,
const std::string& key,
const std::string& value) override;
virtual void WriteNote(const std::vector<std::pair<std::string, int32_t>>& json_path,
const std::string& value) override;
virtual void WriteRootParameterInfo(const std::vector<std::pair<std::string, int32_t>>& json_path,
uint32_t root_parameter_index,
const TrackRootParameter& root_parameter) override;
virtual void WriteNotFoundView(const std::vector<std::pair<std::string, int32_t>>& json_path,
format::HandleId heap_id,
uint32_t heap_index) override;
virtual void WriteNULLResource(const std::vector<std::pair<std::string, int32_t>>& json_path,
format::HandleId heap_id,
uint32_t heap_index) override;
virtual void WriteNULLBufferLocation(const std::vector<std::pair<std::string, int32_t>>& json_path,
format::HandleId heap_id,
uint32_t heap_index) override;

private:
void WriteResource(const CopyResourceDataPtr resource_data);
Expand All @@ -175,7 +222,10 @@ class DefaultDx12DumpResourcesDelegate : public Dx12DumpResourcesDelegate
void WriteBlockStart();
void WriteBlockEnd();

nlohmann::ordered_json* FindDrawCallJsonNode(const std::vector<std::pair<std::string, int32_t>>& json_path);

constexpr const char* NameDrawCall() const { return "draw_call"; }
constexpr const char* NameNotes() const { return "notes"; }

bool WriteBinaryFile(const std::string& filename, const std::vector<uint8_t>& data, uint64_t offset, uint64_t size);

Expand Down Expand Up @@ -241,17 +291,37 @@ class Dx12DumpResources
StructPointerDecoder<Decoded_D3D12_RENDER_PASS_DEPTH_STENCIL_DESC>* pDepthStencil,
D3D12_RENDER_PASS_FLAGS Flags,
uint64_t block_index);
void GetDescriptorSubresourceIndices(DHShaderResourceViewInfo& info, const DxObjectInfo* resource);
void GetDescriptorSubresourceIndices(DHUnorderedAccessViewInfo& info, const DxObjectInfo* resource);
void GetDescriptorSubresourceIndices(DHRenderTargetViewInfo& info, const DxObjectInfo* resource);
void GetDescriptorSubresourceIndices(DHDepthStencilViewInfo& info, const DxObjectInfo* resource);

private:
void StartDump(ID3D12Device* device, const std::string& filename);
void FinishDump(DxObjectInfo* queue_object_info);
void CloseDump();

void WriteDescripotTable(DxObjectInfo* queue_object_info,
const std::vector<format::HandleId>& front_command_list_ids,
graphics::dx12::Dx12DumpResourcePos pos,
std::vector<std::pair<std::string, int32_t>> json_path,
const D3D12DescriptorHeapInfo* heap_info,
format::HandleId heap_id,
uint32_t heap_index,
const D3D12_DESCRIPTOR_RANGE1* range);

void WriteRootParameters(DxObjectInfo* queue_object_info,
const std::vector<format::HandleId>& front_command_list_ids,
graphics::dx12::Dx12DumpResourcePos pos,
Dx12DumpResourceType res_type,
const std::vector<format::HandleId>& descriptor_heap_ids,
const std::unordered_map<uint32_t, TrackRootParameter>& root_parameters);

void CopyDrawCallResources(DxObjectInfo* queue_object_info,
const std::vector<format::HandleId>& front_command_list_ids,
graphics::dx12::Dx12DumpResourcePos pos);

void CopyDrawCallResourceByGPUVA(DxObjectInfo* queue_object_info,
bool CopyDrawCallResourceByGPUVA(DxObjectInfo* queue_object_info,
const std::vector<format::HandleId>& front_command_list_ids,
D3D12_GPU_VIRTUAL_ADDRESS capture_source_gpu_va,
uint64_t source_size,
Expand All @@ -261,7 +331,7 @@ class Dx12DumpResources
format::HandleId descriptor_heap_id,
uint32_t descriptor_heap_index);

void CopyDrawCallResourceBySubresource(DxObjectInfo* queue_object_info,
bool CopyDrawCallResourceBySubresource(DxObjectInfo* queue_object_info,
const std::vector<format::HandleId>& front_command_list_ids,
format::HandleId source_resource_id,
uint64_t source_offset,
Expand Down
64 changes: 39 additions & 25 deletions framework/decode/dx12_object_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ GFXRECON_BEGIN_NAMESPACE(decode)
constexpr size_t kNullCpuAddress = 0;
constexpr uint64_t kNullGpuAddress = 0;

typedef std::array<UINT, D3D12_DESCRIPTOR_HEAP_TYPE_NUM_TYPES> DescriptorIncrements;

enum class DxObjectInfoType : uint32_t
{
kUnused = 0,
Expand Down Expand Up @@ -286,47 +284,64 @@ struct D3D12DeviceInfo : DxObjectExtraInfo
bool is_uma{ false };
};

struct ConstantBufferInfo
// Constant Buffer View, Shader Resource View and Unordered Access View could overrride each other.
// So they should be in the one container.
struct DHConstantBufferViewInfo
{
D3D12_CONSTANT_BUFFER_VIEW_DESC captured_view{};
D3D12_CONSTANT_BUFFER_VIEW_DESC captured_desc{};
bool is_desc_null{ false };
D3D12_CPU_DESCRIPTOR_HANDLE replay_handle{ kNullCpuAddress };
};

struct ShaderResourceInfo
struct DHShaderResourceViewInfo
{
D3D12_SHADER_RESOURCE_VIEW_DESC desc{};
bool is_desc_null{ false };
format::HandleId resource_id{ format::kNullHandleId };
D3D12_SHADER_RESOURCE_VIEW_DESC view{};
bool is_view_null{ false };
D3D12_CPU_DESCRIPTOR_HANDLE replay_handle{ kNullCpuAddress };
std::vector<uint32_t> subresource_indices;
std::vector<uint32_t> subresource_indices; // Only use for dump resources
};

struct UnorderedAccessInfo
struct DHUnorderedAccessViewInfo
{
D3D12_UNORDERED_ACCESS_VIEW_DESC desc{};
bool is_desc_null{ false };
format::HandleId resource_id{ format::kNullHandleId };
format::HandleId counter_resource_id{ format::kNullHandleId };
D3D12_UNORDERED_ACCESS_VIEW_DESC view{};
bool is_view_null{ false };
D3D12_CPU_DESCRIPTOR_HANDLE replay_handle{ kNullCpuAddress };
std::vector<uint32_t> subresource_indices;
std::vector<uint32_t> subresource_indices; // Only use for dump resources
};

struct DHCbvSrvUavInfo
{
D3D12_DESCRIPTOR_RANGE_TYPE type{};
DHConstantBufferViewInfo cbv;
DHShaderResourceViewInfo srv;
DHUnorderedAccessViewInfo uav;
};

struct RenderTargetInfo
struct DHRenderTargetViewInfo
{
format::HandleId resource_id{ format::kNullHandleId };
D3D12_RENDER_TARGET_VIEW_DESC view{};
bool is_view_null{ false };
D3D12_RENDER_TARGET_VIEW_DESC desc{};
bool is_desc_null{ false };
D3D12_CPU_DESCRIPTOR_HANDLE replay_handle{ kNullCpuAddress };
std::vector<uint32_t> subresource_indices;
std::vector<uint32_t> subresource_indices; // Only use for dump resources
};

struct DepthStencilInfo
struct DHDepthStencilViewInfo
{
format::HandleId resource_id{ format::kNullHandleId };
D3D12_DEPTH_STENCIL_VIEW_DESC view{};
bool is_view_null{ false };
D3D12_DEPTH_STENCIL_VIEW_DESC desc{};
bool is_desc_null{ false };
D3D12_CPU_DESCRIPTOR_HANDLE replay_handle{ kNullCpuAddress };
std::vector<uint32_t> subresource_indices;
std::vector<uint32_t> subresource_indices; // Only use for dump resources
};

struct DHSamplerInfo
{
D3D12_SAMPLER_DESC desc{};
D3D12_CPU_DESCRIPTOR_HANDLE replay_handle{ kNullCpuAddress };
};

struct D3D12DescriptorHeapInfo : DxObjectExtraInfo
Expand All @@ -344,11 +359,10 @@ struct D3D12DescriptorHeapInfo : DxObjectExtraInfo
uint64_t replay_gpu_addr_begin{ kNullGpuAddress };

// Descriptor info maps. Key is descriptor's uint32_t heap index.
std::map<uint32_t, ConstantBufferInfo> constant_buffer_infos;
std::map<uint32_t, ShaderResourceInfo> shader_resource_infos;
std::map<uint32_t, UnorderedAccessInfo> unordered_access_infos;
std::map<uint32_t, RenderTargetInfo> render_target_infos;
std::map<uint32_t, DepthStencilInfo> depth_stencil_infos;
std::map<uint32_t, DHCbvSrvUavInfo> cbv_srv_uav_infos;
std::map<uint32_t, DHRenderTargetViewInfo> rtv_infos;
std::map<uint32_t, DHDepthStencilViewInfo> dsv_infos;
std::map<uint32_t, DHSamplerInfo> sampler_infos;
};

struct D3D12FenceInfo : DxObjectExtraInfo
Expand Down
Loading

0 comments on commit 0000a1e

Please sign in to comment.