diff options
| author | kaizhangNV <149626564+kaizhangNV@users.noreply.github.com> | 2024-07-23 10:45:26 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-23 08:45:26 -0700 |
| commit | 986256ffb92ab7c8fc7cf9f2c424919a439a824f (patch) | |
| tree | 260e37bd439275e3398d16fe238b20cd00d08cb7 /source/slang-record-replay/replay/parameter-decoder.cpp | |
| parent | c28d8b6aec721fa3350fc52647f1572a353f6151 (diff) | |
Feature/capture (#4625)
* Add decoder
* Add a replay executable to consume the decoded content
Add file-processor.cpp/h where we implement the logic to process
the captured file block by block. Each block is:
function header + parameter buffer + function tailer + function
output[optional].
After reading one block, the block of data is sent to decoder module
to dispatch the corresponding API.
Add slang-decoder.cpp/h where we implement the logic to dispatch
the slang API according to the input block data.
- Rename api_callId.h to capture-format.h
- Renmae capture_utility.cpp to capture-utility.cpp
- Renmae capture_utility.h to capture-utility.h
- Change the #include file name accordingly.
* Reorganize source files structure
Move all the capture logic code into `capture` directory.
- the capture code will be build with slang dll.
Move all the replay logic code into `relay` directoy.
- the replay code is not part of slang dll, it will be built
as a stand alone binary and link against slang dll.
Change the #include file names accordingly.
Add tools/slang-replay/main.cpp for the slang-replay stand alone
binary place holder. Will implement it later.
Update premake5.lua accordingly.
* Update cmake files
Update cmake files to change the build process for
capture and relay system.
- capture component should be build with slang dll, so we
should not include replay component.
- replay component should be a separate executable tool, which
should not include capture component.
- In order to easy use our current cmake infrastructure, move
the shared files to a `util` folder
- change the header include path
* Redesgin the interfaces of consumers
Fix some issues in capture
Finish implementing all slang-decoder functions
* Fix the AppleClang build issue
* Address few comments
- Fix the weird indent issues.
- Correct the function name for CreateGlobalSession()
- Rename file-processor to captureFile-processor to be more specific.
- Use Slang::List instead of std::vector
* record/replay: name refactor change
Refactor the naming.
Change the name "encoder/capture" to "record".
Diffstat (limited to 'source/slang-record-replay/replay/parameter-decoder.cpp')
| -rw-r--r-- | source/slang-record-replay/replay/parameter-decoder.cpp | 215 |
1 files changed, 215 insertions, 0 deletions
diff --git a/source/slang-record-replay/replay/parameter-decoder.cpp b/source/slang-record-replay/replay/parameter-decoder.cpp new file mode 100644 index 000000000..ed1c1dfe2 --- /dev/null +++ b/source/slang-record-replay/replay/parameter-decoder.cpp @@ -0,0 +1,215 @@ +#include <string.h> +#include "parameter-decoder.h" + +namespace SlangRecord +{ + size_t ParameterDecoder::decodeString(const uint8_t* buffer, int64_t bufferSize, PointerDecoder<char*>& typeDecoder) + { + SLANG_RECORD_ASSERT((buffer != nullptr) && (bufferSize > 0)); + + if (bufferSize < (int64_t)sizeof(uint32_t)) + { + return 0; + } + + uint32_t stringLength = 0; + size_t readByte = 0; + readByte += decodeUint32(buffer, bufferSize - readByte, stringLength); + + SLANG_RECORD_ASSERT(bufferSize >= (int64_t)(readByte + stringLength)); + + if (stringLength == 0) + { + return readByte; + } + + uint8_t* data = (uint8_t*)typeDecoder.allocate(stringLength + 1); + memcpy(data, buffer + readByte, stringLength); + typeDecoder.setPointer(data); + typeDecoder.setDataSize(stringLength + 1); + return readByte + stringLength; + } + + size_t ParameterDecoder::decodePointer(const uint8_t* buffer, int64_t bufferSize, PointerDecoder<void*>& pointerDecoder) + { + SLANG_RECORD_ASSERT((buffer != nullptr) && (bufferSize > 0)); + + if (bufferSize < (int64_t)sizeof(uint32_t)) + { + return 0; + } + + uint64_t address = 0; + size_t readByte = decodeAddress(buffer, bufferSize, address); + pointerDecoder.setPointerAddress(address); + + uint64_t dataSize = 0; + readByte += decodeUint64(buffer + readByte, bufferSize - readByte, dataSize); + + // return if the data size is 0 + if (dataSize == 0) + { + return readByte; + } + + SLANG_RECORD_ASSERT(bufferSize >= (int64_t)(readByte + dataSize)); + + uint8_t* data = (uint8_t*)pointerDecoder.allocate(dataSize); + memcpy(data, buffer + readByte, dataSize); + pointerDecoder.setPointer(data); + pointerDecoder.setDataSize(dataSize); + return readByte + dataSize; + } + + size_t ParameterDecoder::decodeStruct(const uint8_t* buffer, int64_t bufferSize, ValueDecoder<slang::SessionDesc>& sessionDesc) + { + SLANG_RECORD_ASSERT((buffer != nullptr) && (bufferSize > 0)); + + if(bufferSize < (int64_t)sizeof(uint64_t)) + { + return 0; + } + + size_t readByte = 0; + slang::SessionDesc& desc = sessionDesc.getValue(); + + uint64_t structSize = 0; + readByte = decodeUint64(buffer, bufferSize, structSize); + desc.structureSize = structSize; + + readByte += decodeInt64(buffer + readByte, bufferSize - readByte, desc.targetCount); + + if (desc.targetCount > 0) + { + slang::TargetDesc* targets = (slang::TargetDesc*)sessionDesc.allocate(sizeof(slang::TargetDesc) * desc.targetCount); + readByte += decodeStructArray(buffer + readByte, bufferSize - readByte, targets, desc.targetCount); + desc.targets = targets; + } + + readByte += decodeUint32(buffer + readByte, bufferSize - readByte, desc.flags); + readByte += decodeEnumValue(buffer + readByte, bufferSize - readByte, desc.defaultMatrixLayoutMode); + readByte += decodeInt64(buffer + readByte, bufferSize - readByte, desc.searchPathCount); + + if (desc.searchPathCount > 0) + { + char** searchPaths = (char**)sessionDesc.allocate(sizeof(char*) * desc.searchPathCount); + decodeStringArray(buffer + readByte, bufferSize - readByte, searchPaths, desc.searchPathCount); + desc.searchPaths = searchPaths; + } + + readByte += decodeInt64(buffer + readByte, bufferSize - readByte, desc.preprocessorMacroCount); + if (desc.preprocessorMacroCount > 0) + { + slang::PreprocessorMacroDesc* macros = (slang::PreprocessorMacroDesc*) + sessionDesc.allocate(sizeof(slang::PreprocessorMacroDesc) * desc.preprocessorMacroCount); + readByte += decodeStructArray(buffer + readByte, bufferSize - readByte, macros, desc.preprocessorMacroCount); + desc.preprocessorMacros = macros; + } + + readByte += decodeBool(buffer + readByte, bufferSize - readByte, desc.enableEffectAnnotations); + readByte += decodeBool(buffer + readByte, bufferSize - readByte, desc.allowGLSLSyntax); + readByte += decodeUint32(buffer + readByte, bufferSize - readByte, desc.compilerOptionEntryCount); + + if (desc.compilerOptionEntryCount > 0) + { + slang::CompilerOptionEntry* entries = (slang::CompilerOptionEntry*) + sessionDesc.allocate(sizeof(slang::CompilerOptionEntry) * desc.compilerOptionEntryCount); + readByte += decodeStructArray(buffer + readByte, bufferSize - readByte, entries, desc.compilerOptionEntryCount); + desc.compilerOptionEntries = entries; + } + + return readByte; + } + + size_t ParameterDecoder::decodeStruct(const uint8_t* buffer, int64_t bufferSize, ValueDecoder<slang::PreprocessorMacroDesc>& desc) + { + SLANG_RECORD_ASSERT((buffer != nullptr) && (bufferSize > 0)); + + size_t readByte = 0; + PointerDecoder<char*> name; + PointerDecoder<char*> value; + + readByte = decodeString(buffer, bufferSize, name); + readByte += decodeString(buffer + readByte, bufferSize - readByte, value); + + desc.getValue().name = name.getPointer(); + desc.getValue().value = value.getPointer(); + + return readByte; + } + + size_t ParameterDecoder::decodeStruct(const uint8_t* buffer, int64_t bufferSize, ValueDecoder<slang::CompilerOptionEntry>& entry) + { + SLANG_RECORD_ASSERT((buffer != nullptr) && (bufferSize > 0)); + + size_t readByte = 0; + readByte = decodeEnumValue(buffer, bufferSize, entry.getValue().name); + + ValueDecoder<slang::CompilerOptionValue> value; + readByte += decodeStruct(buffer + readByte, bufferSize - readByte, value); + entry.getValue().value = value.getValue(); + + return readByte; + } + + size_t ParameterDecoder::decodeStruct(const uint8_t* buffer, int64_t bufferSize, ValueDecoder<slang::CompilerOptionValue>& value) + { + SLANG_RECORD_ASSERT((buffer != nullptr) && (bufferSize > 0)); + + size_t readByte = 0; + readByte = decodeEnumValue(buffer, bufferSize, value.getValue().kind); + readByte += decodeInt32(buffer + readByte, bufferSize - readByte, value.getValue().intValue0); + + PointerDecoder<char*> stringValue0; + readByte += decodeString(buffer + readByte, bufferSize - readByte, stringValue0); + value.getValue().stringValue0 = stringValue0.getPointer(); + + PointerDecoder<char*> stringValue1; + readByte += decodeString(buffer + readByte, bufferSize - readByte, stringValue1); + value.getValue().stringValue1 = stringValue1.getPointer(); + return 0; + } + + size_t ParameterDecoder::decodeStruct(const uint8_t* buffer, int64_t bufferSize, ValueDecoder<slang::TargetDesc>& targetDesc) + { + SLANG_RECORD_ASSERT((buffer != nullptr) && (bufferSize > 0)); + + size_t readByte = 0; + uint64_t structSize = 0; + readByte = decodeUint64(buffer, bufferSize, structSize); + targetDesc.getValue().structureSize = structSize; + + readByte += decodeEnumValue(buffer + readByte, bufferSize - readByte, targetDesc.getValue().format); + readByte += decodeEnumValue(buffer + readByte, bufferSize - readByte, targetDesc.getValue().profile); + readByte += decodeEnumValue(buffer + readByte, bufferSize - readByte, targetDesc.getValue().flags); + readByte += decodeEnumValue(buffer + readByte, bufferSize - readByte, targetDesc.getValue().floatingPointMode); + readByte += decodeEnumValue(buffer + readByte, bufferSize - readByte, targetDesc.getValue().lineDirectiveMode); + readByte += decodeBool(buffer + readByte, bufferSize - readByte, targetDesc.getValue().forceGLSLScalarBufferLayout); + readByte += decodeUint32(buffer + readByte, bufferSize - readByte, targetDesc.getValue().compilerOptionEntryCount); + + if (targetDesc.getValue().compilerOptionEntryCount > 0) + { + slang::CompilerOptionEntry* entries = (slang::CompilerOptionEntry*) + targetDesc.allocate(sizeof(slang::CompilerOptionEntry) * targetDesc.getValue().compilerOptionEntryCount); + readByte += decodeStructArray(buffer + readByte, bufferSize - readByte, entries, targetDesc.getValue().compilerOptionEntryCount); + targetDesc.getValue().compilerOptionEntries = entries; + } + + return readByte; + } + + size_t ParameterDecoder::decodeStruct(const uint8_t* buffer, int64_t bufferSize, ValueDecoder<slang::SpecializationArg>& specializationArg) + { + SLANG_RECORD_ASSERT((buffer != nullptr) && (bufferSize > 0)); + + size_t readByte = 0; + readByte = decodeEnumValue(buffer, bufferSize, specializationArg.getValue().kind); + + // TODO: Special handle to address decode is needed. + uint64_t address = 0; + readByte += decodeAddress(buffer + readByte, bufferSize - readByte, address); + (void)address; + + return readByte; + } +} |
