Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dx12 option: GFXRECON_CAPTURE_DRAW_CALLS #1680

Merged
merged 18 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions USAGE_desktop_D3D12.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ Quit after capturing frame ranges | GFXRECON_QUIT_AFTER_CAPTURE_FRAMES | BOOL |
Hotkey Capture Trigger | GFXRECON_CAPTURE_TRIGGER | STRING | Specify a hotkey (any one of F1-F12, TAB, CONTROL) that will be used to start/stop capture. Example: `F3` will set the capture trigger to F3 hotkey. One capture file will be generated for each pair of start/stop hotkey presses. Default is: Empty string (hotkey capture trigger is disabled).
Hotkey Capture Trigger Frames | GFXRECON_CAPTURE_TRIGGER_FRAMES | STRING | Specify a limit on the number of frames to be captured via hotkey. Example: `1` will capture exactly one frame when the trigger key is pressed. Default is: Empty string (no limit)
Capture Specific GPU Queue Submits | GFXRECON_CAPTURE_QUEUE_SUBMITS | STRING | Specify one or more comma-separated GPU queue submit call ranges to capture. Queue submit calls are `vkQueueSubmit` for Vulkan and `ID3D12CommandQueue::ExecuteCommandLists` for DX12. Queue submit ranges work as described above in `GFXRECON_CAPTURE_FRAMES` but on GPU queue submit calls instead of frames. Default is: Empty string (all queue submits are captured).
Capture Specific Draw Calls | GFXRECON_CAPTURE_DRAW_CALLS | STRING | Specify one index or a range indices drawacalls(include dispatch) based on a ExecuteCommandList index and a CommandList index to capture. The index is 0-based. The args are one submit index, one command index, one or a range indices of draw calls, one or a range indices of bundle draw calls(option), like "0,0,0" or "0,0,0-2" or "0,0,0-2,0". The forth arg is an option for bundle case. If the the 3rd arg is a bundle commandlist, but it doesn't set the 4th arg, it will set 0 as default. Default is: Empty string (all draw calls are captured).
Capture File Compression Type | GFXRECON_CAPTURE_COMPRESSION_TYPE | STRING | Compression format to use with the capture file. Valid values are: `LZ4`, `ZLIB`, `ZSTD`, and `NONE`. Default is: `LZ4`
Capture File Timestamp | GFXRECON_CAPTURE_FILE_TIMESTAMP | BOOL | Add a timestamp to the capture file as described by [Timestamps](#timestamps). Default is: `true`
Capture File Flush After Write | GFXRECON_CAPTURE_FILE_FLUSH | BOOL | Flush output stream after each packet is written to the capture file. Default is: `false`
Expand Down Expand Up @@ -211,7 +212,7 @@ Usage:
[--fwo <x,y> | --force-windowed-origin <x,y>]
[--log-level <level>] [--log-file <file>] [--log-debugview]
[--batching-memory-usage <pct>]
[--dump-resources <submit-index,command-index,drawcall-index>] <file>
[--dump-resources <submit-index,command-index,draw-call-index>] <file>
[--pbi-all] [--pbis <index1,index2>]

Required arguments:
Expand Down Expand Up @@ -338,12 +339,12 @@ D3D12-only:
for batching and does not guarantee overall max memory usage.
Acceptable values range from 0 to 100 (default: 80). 0 means no batching,
100 means use all available system and GPU memory.
--dump-resources <submit-index,command-index,drawcall-index>
Output binaray resources for a specific drawcall.
--dump-resources <submit-index,command-index,draw-call-index>
Output binaray resources for a specific draw call.
Include vertex, index, const buffer, shader resource, render target,
and depth stencil. And for before and after drawcall.
and depth stencil. And for before and after draw call.
Arguments becomes three indices, submit index, command index,
drawcall index. The command index is based on its in ExecuteCommandLists.
draw call index. The command index is based on its in ExecuteCommandLists.
```


Expand Down
174 changes: 93 additions & 81 deletions framework/decode/dx12_browse_consumer.h

Large diffs are not rendered by default.

227 changes: 110 additions & 117 deletions framework/decode/dx12_dump_resources.cpp

Large diffs are not rendered by default.

52 changes: 19 additions & 33 deletions framework/decode/dx12_dump_resources.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,6 @@ enum class Dx12DumpResourceType : uint32_t
kExecuteIndirectCount,
};

enum class Dx12DumpResourcePos : uint32_t
{
kUnknown,
kBeforeDrawCall,
kDrawCall,
kAfterDrawCall,
};

struct CopyResourceData
{
// Allow default constructor, disallow copy constructor.
Expand All @@ -83,15 +75,15 @@ struct CopyResourceData
uint64_t total_size{ 0 };
bool is_cpu_accessible{ false };

std::vector<std::vector<uint8_t>> datas; // copy resource drawcall
std::vector<std::vector<uint8_t>> datas; // copy resource draw call

graphics::dx12::ID3D12GraphicsCommandListComPtr cmd_list{ nullptr };
graphics::dx12::ID3D12ResourceComPtr read_resource{ nullptr };
bool read_resource_is_staging_buffer{ false };

std::vector<std::pair<std::string, int32_t>> json_path;
Dx12DumpResourceType resource_type{ Dx12DumpResourceType::kUnknown };
Dx12DumpResourcePos dump_position{ Dx12DumpResourcePos::kUnknown };
graphics::dx12::Dx12DumpResourcePos dump_position{ graphics::dx12::Dx12DumpResourcePos::kUnknown };

format::HandleId descriptor_heap_id{ format::kNullHandleId };
uint32_t descriptor_heap_index{ 0 };
Expand All @@ -113,23 +105,17 @@ struct CopyResourceData
read_resource = nullptr;
read_resource_is_staging_buffer = false;
resource_type = Dx12DumpResourceType::kUnknown;
dump_position = Dx12DumpResourcePos::kUnknown;
dump_position = graphics::dx12::Dx12DumpResourcePos::kUnknown;
descriptor_heap_id = format::kUnknown;
descriptor_heap_index = 0;
}
};

typedef std::shared_ptr<CopyResourceData> CopyResourceDataPtr;

struct CommandSet
{
graphics::dx12::ID3D12CommandAllocatorComPtr allocator;
graphics::dx12::ID3D12GraphicsCommandListComPtr list;
};

struct TrackDumpResources
{
TrackDumpDrawcall target{};
TrackDumpDrawCall target{};

// render target
std::vector<format::HandleId> render_target_heap_ids;
Expand All @@ -141,8 +127,8 @@ struct TrackDumpResources
graphics::dx12::ID3D12ResourceComPtr copy_staging_buffer{ nullptr };
uint64_t copy_staging_buffer_size{ 0 };

std::array<CommandSet, 3> split_command_sets;
std::array<CommandSet, 3> split_bundle_command_sets;
std::array<graphics::dx12::CommandSet, 3> split_command_sets;
std::array<graphics::dx12::CommandSet, 3> split_bundle_command_sets;

graphics::dx12::ID3D12FenceComPtr fence;
HANDLE fence_event;
Expand Down Expand Up @@ -189,7 +175,7 @@ class DefaultDx12DumpResourcesDelegate : public Dx12DumpResourcesDelegate
void WriteBlockStart();
void WriteBlockEnd();

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

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

Expand All @@ -204,7 +190,7 @@ class DefaultDx12DumpResourcesDelegate : public Dx12DumpResourcesDelegate
FILE* json_file_handle_{ nullptr };
nlohmann::ordered_json json_data_;
nlohmann::ordered_json header_;
nlohmann::ordered_json drawcall_;
nlohmann::ordered_json draw_call_;
uint32_t num_objects_{ 0 };
uint32_t num_files_{ 0 };
};
Expand All @@ -220,11 +206,11 @@ class Dx12DumpResources

void SetDelegate(Dx12DumpResourcesDelegate* delegate) { user_delegate_ = delegate; }

std::vector<CommandSet> GetCommandListsForDumpResources(DxObjectInfo* command_list_object_info,
uint64_t block_index,
format::ApiCallId api_call_id);
std::vector<graphics::dx12::CommandSet> GetCommandListsForDumpResources(DxObjectInfo* command_list_object_info,
uint64_t block_index,
format::ApiCallId api_call_id);

inline void SetDumpTarget(TrackDumpDrawcall& track_dump_target)
inline void SetDumpTarget(TrackDumpDrawCall& track_dump_target)
{
track_dump_resources_.target = track_dump_target;
}
Expand Down Expand Up @@ -261,33 +247,33 @@ class Dx12DumpResources
void FinishDump(DxObjectInfo* queue_object_info);
void CloseDump();

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

void CopyDrawcallResourceByGPUVA(DxObjectInfo* queue_object_info,
void 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,
const std::vector<std::pair<std::string, int32_t>>& json_path,
Dx12DumpResourceType resource_type,
Dx12DumpResourcePos pos,
graphics::dx12::Dx12DumpResourcePos pos,
format::HandleId descriptor_heap_id,
uint32_t descriptor_heap_index);

void CopyDrawcallResourceBySubresource(DxObjectInfo* queue_object_info,
void CopyDrawCallResourceBySubresource(DxObjectInfo* queue_object_info,
const std::vector<format::HandleId>& front_command_list_ids,
format::HandleId source_resource_id,
uint64_t source_offset,
uint64_t source_size,
const std::vector<uint32_t>& subresource_indices,
const std::vector<std::pair<std::string, int32_t>>& json_path,
Dx12DumpResourceType resource_type,
Dx12DumpResourcePos pos,
graphics::dx12::Dx12DumpResourcePos pos,
format::HandleId descriptor_heap_id,
uint32_t descriptor_heap_index);

void CopyDrawcallResource(DxObjectInfo* queue_object_info,
void CopyDrawCallResource(DxObjectInfo* queue_object_info,
const std::vector<format::HandleId>& front_command_list_ids,
format::HandleId source_resource_id,
uint64_t source_offset,
Expand Down
2 changes: 2 additions & 0 deletions framework/decode/dx12_object_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ struct DxgiSwapchainInfo : DxObjectExtraInfo
static constexpr char kObjectType[] = "IDXGISwapChain";
DxgiSwapchainInfo() : DxObjectExtraInfo(kType) {}

uint32_t init_buffer_index{ 0 };
Window* window{ nullptr }; ///< Pointer to the platform-specific window object associated with the swapchain.
uint64_t hwnd_id{ 0 }; ///< Capture ID for the HWND handle used with swapchain creation.

Expand Down Expand Up @@ -386,6 +387,7 @@ struct D3D12ResourceInfo : DxObjectExtraInfo

D3D12_RESOURCE_DESC1 desc = {};
format::HandleId swap_chain_id{ format::kNullHandleId };
uint32_t buffer_index{ 0 };

size_t subresource_count{ 0 };
std::vector<graphics::dx12::ResourceStateInfo> resource_state_infos;
Expand Down
Loading
Loading