diff options
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/MC/DXContainerPSVInfo.cpp | 13 | ||||
| -rw-r--r-- | llvm/lib/Object/DXContainer.cpp | 62 | ||||
| -rw-r--r-- | llvm/lib/ObjectYAML/DXContainerEmitter.cpp | 20 | ||||
| -rw-r--r-- | llvm/lib/ObjectYAML/DXContainerYAML.cpp | 18 |
4 files changed, 113 insertions, 0 deletions
diff --git a/llvm/lib/MC/DXContainerPSVInfo.cpp b/llvm/lib/MC/DXContainerPSVInfo.cpp index 03df6be..5336590 100644 --- a/llvm/lib/MC/DXContainerPSVInfo.cpp +++ b/llvm/lib/MC/DXContainerPSVInfo.cpp @@ -147,4 +147,17 @@ void PSVRuntimeInfo::write(raw_ostream &OS, uint32_t Version) const { OS.write(reinterpret_cast<const char *>(&SignatureElements[0]), SignatureElements.size() * sizeof(v0::SignatureElement)); } + + for (const auto &MaskVector : OutputVectorMasks) + support::endian::write_array(OS, ArrayRef<uint32_t>(MaskVector), + support::little); + support::endian::write_array(OS, ArrayRef<uint32_t>(PatchOrPrimMasks), + support::little); + for (const auto &MaskVector : InputOutputMap) + support::endian::write_array(OS, ArrayRef<uint32_t>(MaskVector), + support::little); + support::endian::write_array(OS, ArrayRef<uint32_t>(InputPatchMap), + support::little); + support::endian::write_array(OS, ArrayRef<uint32_t>(PatchOutputMap), + support::little); } diff --git a/llvm/lib/Object/DXContainer.cpp b/llvm/lib/Object/DXContainer.cpp index df1f982..a3071d2 100644 --- a/llvm/lib/Object/DXContainer.cpp +++ b/llvm/lib/Object/DXContainer.cpp @@ -321,6 +321,68 @@ Error DirectX::PSVRuntimeInfo::parse(uint16_t ShaderKind) { Current += PSize; } + ArrayRef<uint8_t> OutputVectorCounts = getOutputVectorCounts(); + uint8_t PatchConstOrPrimVectorCount = getPatchConstOrPrimVectorCount(); + uint8_t InputVectorCount = getInputVectorCount(); + + auto maskDwordSize = [](uint8_t Vector) { + return (static_cast<uint32_t>(Vector) + 7) >> 3; + }; + + auto mapTableSize = [maskDwordSize](uint8_t X, uint8_t Y) { + return maskDwordSize(Y) * X * 4; + }; + + if (usesViewID()) { + for (uint32_t I = 0; I < OutputVectorCounts.size(); ++I) { + // The vector mask is one bit per component and 4 components per vector. + // We can compute the number of dwords required by rounding up to the next + // multiple of 8. + uint32_t NumDwords = + maskDwordSize(static_cast<uint32_t>(OutputVectorCounts[I])); + size_t NumBytes = NumDwords * sizeof(uint32_t); + OutputVectorMasks[I].Data = Data.substr(Current - Data.begin(), NumBytes); + Current += NumBytes; + } + + if (ShaderStage == Triple::Hull && PatchConstOrPrimVectorCount > 0) { + uint32_t NumDwords = maskDwordSize(PatchConstOrPrimVectorCount); + size_t NumBytes = NumDwords * sizeof(uint32_t); + PatchOrPrimMasks.Data = Data.substr(Current - Data.begin(), NumBytes); + Current += NumBytes; + } + } + + // Input/Output mapping table + for (uint32_t I = 0; I < OutputVectorCounts.size(); ++I) { + if (InputVectorCount == 0 || OutputVectorCounts[I] == 0) + continue; + uint32_t NumDwords = mapTableSize(InputVectorCount, OutputVectorCounts[I]); + size_t NumBytes = NumDwords * sizeof(uint32_t); + InputOutputMap[I].Data = Data.substr(Current - Data.begin(), NumBytes); + Current += NumBytes; + } + + // Hull shader: Input/Patch mapping table + if (ShaderStage == Triple::Hull && PatchConstOrPrimVectorCount > 0 && + InputVectorCount > 0) { + uint32_t NumDwords = + mapTableSize(InputVectorCount, PatchConstOrPrimVectorCount); + size_t NumBytes = NumDwords * sizeof(uint32_t); + InputPatchMap.Data = Data.substr(Current - Data.begin(), NumBytes); + Current += NumBytes; + } + + // Domain Shader: Patch/Output mapping table + if (ShaderStage == Triple::Domain && PatchConstOrPrimVectorCount > 0 && + OutputVectorCounts[0] > 0) { + uint32_t NumDwords = + mapTableSize(PatchConstOrPrimVectorCount, OutputVectorCounts[0]); + size_t NumBytes = NumDwords * sizeof(uint32_t); + PatchOutputMap.Data = Data.substr(Current - Data.begin(), NumBytes); + Current += NumBytes; + } + return Error::success(); } diff --git a/llvm/lib/ObjectYAML/DXContainerEmitter.cpp b/llvm/lib/ObjectYAML/DXContainerEmitter.cpp index c5d5d65..6b0e179 100644 --- a/llvm/lib/ObjectYAML/DXContainerEmitter.cpp +++ b/llvm/lib/ObjectYAML/DXContainerEmitter.cpp @@ -219,6 +219,26 @@ void DXContainerWriter::writeParts(raw_ostream &OS) { El.Allocated, El.Kind, El.Type, El.Mode, El.DynamicMask, El.Stream}); + static_assert(PSV.OutputVectorMasks.size() == PSV.InputOutputMap.size()); + for (unsigned I = 0; I < PSV.OutputVectorMasks.size(); ++I) { + PSV.OutputVectorMasks[I].insert(PSV.OutputVectorMasks[I].begin(), + P.Info->OutputVectorMasks[I].begin(), + P.Info->OutputVectorMasks[I].end()); + PSV.InputOutputMap[I].insert(PSV.InputOutputMap[I].begin(), + P.Info->InputOutputMap[I].begin(), + P.Info->InputOutputMap[I].end()); + } + + PSV.PatchOrPrimMasks.insert(PSV.PatchOrPrimMasks.begin(), + P.Info->PatchOrPrimMasks.begin(), + P.Info->PatchOrPrimMasks.end()); + PSV.InputPatchMap.insert(PSV.InputPatchMap.begin(), + P.Info->InputPatchMap.begin(), + P.Info->InputPatchMap.end()); + PSV.PatchOutputMap.insert(PSV.PatchOutputMap.begin(), + P.Info->PatchOutputMap.begin(), + P.Info->PatchOutputMap.end()); + PSV.finalize(static_cast<Triple::EnvironmentType>( Triple::Pixel + P.Info->Info.ShaderStage)); PSV.write(OS, P.Info->Version); diff --git a/llvm/lib/ObjectYAML/DXContainerYAML.cpp b/llvm/lib/ObjectYAML/DXContainerYAML.cpp index 2b03098..c7cf1ec9 100644 --- a/llvm/lib/ObjectYAML/DXContainerYAML.cpp +++ b/llvm/lib/ObjectYAML/DXContainerYAML.cpp @@ -139,6 +139,24 @@ void MappingTraits<DXContainerYAML::PSVInfo>::mapping( IO.mapRequired("SigInputElements", PSV.SigInputElements); IO.mapRequired("SigOutputElements", PSV.SigOutputElements); IO.mapRequired("SigPatchOrPrimElements", PSV.SigPatchOrPrimElements); + + Triple::EnvironmentType Stage = dxbc::getShaderStage(PSV.Info.ShaderStage); + if (PSV.Info.UsesViewID) { + MutableArrayRef<SmallVector<llvm::yaml::Hex32>> MutableOutMasks( + PSV.OutputVectorMasks); + IO.mapRequired("OutputVectorMasks", MutableOutMasks); + if (Stage == Triple::EnvironmentType::Hull) + IO.mapRequired("PatchOrPrimMasks", PSV.PatchOrPrimMasks); + } + MutableArrayRef<SmallVector<llvm::yaml::Hex32>> MutableIOMap( + PSV.InputOutputMap); + IO.mapRequired("InputOutputMap", MutableIOMap); + + if (Stage == Triple::EnvironmentType::Hull) + IO.mapRequired("InputPatchMap", PSV.InputPatchMap); + + if (Stage == Triple::EnvironmentType::Domain) + IO.mapRequired("PatchOutputMap", PSV.PatchOutputMap); } void MappingTraits<DXContainerYAML::Part>::mapping(IO &IO, |
