1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
|
/*
** Copyright (c) 2022 LunarG, Inc.
** Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved.
**
** 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.
*/
#include "block_skipping_file_processor.h"
#include "decode/decode_allocator.h"
#include "format/format_util.h"
#include "util/logging.h"
GFXRECON_BEGIN_NAMESPACE(gfxrecon)
GFXRECON_BEGIN_NAMESPACE(decode)
void BlockSkippingFileProcessor::SetBlocksToSkip(std::unordered_set<uint64_t> blocks_to_skip)
{
blocks_to_skip_ = blocks_to_skip;
blocks_skipped_ = 0;
}
bool BlockSkippingFileProcessor::IsSkippingFinished()
{
return blocks_skipped_ == blocks_to_skip_.size();
}
bool BlockSkippingFileProcessor::ShouldSkipBlock()
{
return (!(blocks_to_skip_.empty())) && (blocks_to_skip_.find(block_index_) != blocks_to_skip_.end());
}
bool BlockSkippingFileProcessor::ProcessBlocks()
{
format::BlockHeader block_header;
bool success = true;
while (success)
{
success = ContinueDecoding();
if (success)
{
success = ReadBlockHeader(&block_header);
for (auto decoder : decoders_)
{
decoder->SetCurrentBlockIndex(block_index_);
}
if (success)
{
if (ShouldSkipBlock())
{
GFXRECON_CHECK_CONVERSION_DATA_LOSS(size_t, block_header.size);
success = SkipBytes(static_cast<size_t>(block_header.size));
blocks_skipped_++;
}
else if (format::RemoveCompressedBlockBit(block_header.type) == format::BlockType::kFunctionCallBlock)
{
format::ApiCallId api_call_id = format::ApiCallId::ApiCall_Unknown;
success = ReadBytes(&api_call_id, sizeof(api_call_id));
if (success)
{
success = ProcessFunctionCall(block_header, api_call_id);
// Break from loop on frame delimiter.
if (IsFrameDelimiter(api_call_id))
{
// Make sure to increment the frame number on the way out.
++current_frame_number_;
++block_index_;
break;
}
}
else
{
HandleBlockReadError(kErrorReadingBlockHeader, "Failed to read function call block header");
}
}
else if (format::RemoveCompressedBlockBit(block_header.type) == format::BlockType::kMethodCallBlock)
{
format::ApiCallId api_call_id = format::ApiCallId::ApiCall_Unknown;
success = ReadBytes(&api_call_id, sizeof(api_call_id));
if (success)
{
success = ProcessMethodCall(block_header, api_call_id);
// Break from loop on frame delimiter.
if (IsFrameDelimiter(api_call_id))
{
// Make sure to increment the frame number on the way out.
++current_frame_number_;
++block_index_;
break;
}
}
else
{
HandleBlockReadError(kErrorReadingBlockHeader, "Failed to read function call block header");
}
}
else if (format::RemoveCompressedBlockBit(block_header.type) == format::BlockType::kMetaDataBlock)
{
format::MetaDataId meta_data_id = format::MakeMetaDataId(
format::ApiFamilyId::ApiFamily_None, format::MetaDataType::kUnknownMetaDataType);
success = ReadBytes(&meta_data_id, sizeof(meta_data_id));
if (success)
{
success = ProcessMetaData(block_header, meta_data_id);
}
else
{
HandleBlockReadError(kErrorReadingBlockHeader, "Failed to read meta-data block header");
}
}
else if (block_header.type == format::BlockType::kStateMarkerBlock)
{
format::MarkerType marker_type = format::MarkerType::kUnknownMarker;
uint64_t frame_number = 0;
success = ReadBytes(&marker_type, sizeof(marker_type));
if (success)
{
success = ProcessStateMarker(block_header, marker_type);
}
else
{
HandleBlockReadError(kErrorReadingBlockHeader, "Failed to read state marker header");
}
}
else if (block_header.type == format::BlockType::kAnnotation)
{
if (annotation_handler_ != nullptr)
{
format::AnnotationType annotation_type = format::AnnotationType::kUnknown;
success = ReadBytes(&annotation_type, sizeof(annotation_type));
if (success)
{
success = ProcessAnnotation(block_header, annotation_type);
}
else
{
HandleBlockReadError(kErrorReadingBlockHeader, "Failed to read annotation block header");
}
}
else
{
// If there is no annotation handler to process the annotation, we can skip the annotation
// block.
GFXRECON_CHECK_CONVERSION_DATA_LOSS(size_t, block_header.size);
success = SkipBytes(static_cast<size_t>(block_header.size));
}
}
else
{
// Unrecognized block type.
GFXRECON_LOG_WARNING("Skipping unrecognized file block with type %u", block_header.type);
GFXRECON_CHECK_CONVERSION_DATA_LOSS(size_t, block_header.size);
success = SkipBytes(static_cast<size_t>(block_header.size));
}
}
else
{
if (!feof(file_descriptor_))
{
// No data has been read for the current block, so we don't use 'HandleBlockReadError' here, as it
// assumes that the block header has been successfully read and will print an incomplete block at
// end of file warning when the file is at EOF without an error. For this case (the normal EOF case)
// we print nothing at EOF, or print an error message and set the error code directly when not at
// EOF.
GFXRECON_LOG_ERROR("Failed to read block header");
error_state_ = kErrorReadingBlockHeader;
}
}
++block_index_;
}
}
return success;
}
GFXRECON_END_NAMESPACE(decode)
GFXRECON_END_NAMESPACE(gfxrecon)
|