Unverified Commit 30463fbc authored by Joshua Batista's avatar Joshua Batista Committed by GitHub
Browse files

[HLSL] Leave out entryname from string table for PSV versions < 3 (#191528)

This PR adjusts how the string table is generated for PSV versions 1 and
2. Previously, the
string name would be unconditionally added to the string table, when it
should only be added in version 3.
Adds a test to verify there is no entry name in the string table for
older PSV versions.
Fixes https://github.com/llvm/llvm-project/issues/117267

Assisted by: Github Copilot
parent bcd75cb4
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -562,6 +562,8 @@ struct ResourceBindInfo : public v0::ResourceBindInfo {

namespace v3 {
struct RuntimeInfo : public v2::RuntimeInfo {
  // Offset into the string table, which is stored separately in the PSV0 part.
  // The entry name string itself is not stored in the RuntimeInfo record.
  uint32_t EntryNameOffset;

  void swapBytes() {
+3 −2
Original line number Diff line number Diff line
@@ -68,7 +68,7 @@ struct PSVRuntimeInfo {
  std::array<SmallVector<uint32_t>, 4> InputOutputMap;
  SmallVector<uint32_t> InputPatchMap;
  SmallVector<uint32_t> PatchOutputMap;
  llvm::StringRef EntryName;
  StringRef EntryName;

  // Serialize PSVInfo into the provided raw_ostream. The version field
  // specifies the data version to encode, the default value specifies encoding
@@ -76,7 +76,8 @@ struct PSVRuntimeInfo {
  void write(raw_ostream &OS,
             uint32_t Version = std::numeric_limits<uint32_t>::max()) const;

  void finalize(Triple::EnvironmentType Stage);
  void finalize(Triple::EnvironmentType Stage,
                uint32_t Version = std::numeric_limits<uint32_t>::max());

private:
  SmallVector<uint32_t, 64> IndexBuffer;
+14 −0
Original line number Diff line number Diff line
@@ -240,6 +240,11 @@ struct SignatureElement {
  uint8_t Stream;
};

struct StringTableEntry {
  StringRef String;
  uint32_t Offset;
};

struct PSVInfo {
  // The version field isn't actually encoded in the file, but it is inferred by
  // the size of data regions. We include it in the yaml because it simplifies
@@ -262,6 +267,10 @@ struct PSVInfo {

  StringRef EntryName;

  // Output-only fields populated by obj2yaml for inspection.
  SmallVector<StringTableEntry> StringTable;
  uint32_t RuntimeInfoSize = 0;

  LLVM_ABI void mapInfoForVersion(yaml::IO &IO);

  LLVM_ABI PSVInfo();
@@ -316,6 +325,7 @@ LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DXContainerYAML::SignatureParameter)
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DXContainerYAML::RootParameterLocationYaml)
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DXContainerYAML::DescriptorRangeYaml)
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DXContainerYAML::StaticSamplerYamlDesc)
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DXContainerYAML::StringTableEntry)
LLVM_YAML_DECLARE_ENUM_TRAITS(llvm::dxbc::PSV::SemanticKind)
LLVM_YAML_DECLARE_ENUM_TRAITS(llvm::dxbc::PSV::ComponentType)
LLVM_YAML_DECLARE_ENUM_TRAITS(llvm::dxbc::PSV::InterpolationMode)
@@ -384,6 +394,10 @@ template <> struct MappingTraits<DXContainerYAML::SignatureElement> {
                               llvm::DXContainerYAML::SignatureElement &El);
};

template <> struct MappingTraits<DXContainerYAML::StringTableEntry> {
  static void mapping(IO &IO, DXContainerYAML::StringTableEntry &E);
};

template <> struct MappingTraits<DXContainerYAML::SignatureParameter> {
  LLVM_ABI static void mapping(IO &IO,
                               llvm::DXContainerYAML::SignatureParameter &El);
+6 −4
Original line number Diff line number Diff line
@@ -146,7 +146,7 @@ void PSVRuntimeInfo::write(raw_ostream &OS, uint32_t Version) const {
                               llvm::endianness::little);
}

void PSVRuntimeInfo::finalize(Triple::EnvironmentType Stage) {
void PSVRuntimeInfo::finalize(Triple::EnvironmentType Stage, uint32_t Version) {
  IsFinalized = true;
  BaseData.SigInputElements = static_cast<uint32_t>(InputElements.size());
  BaseData.SigOutputElements = static_cast<uint32_t>(OutputElements.size());
@@ -164,6 +164,7 @@ void PSVRuntimeInfo::finalize(Triple::EnvironmentType Stage) {
  ProcessElementList(DXConStrTabBuilder, IndexBuffer, SignatureElements,
                     SemanticNames, PatchOrPrimElements);

  if (Version >= 3 && !EntryName.empty())
    DXConStrTabBuilder.add(EntryName);

  DXConStrTabBuilder.finalize();
@@ -175,6 +176,7 @@ void PSVRuntimeInfo::finalize(Triple::EnvironmentType Stage) {
      El.swapBytes();
  }

  if (Version >= 3 && !EntryName.empty())
    BaseData.EntryNameOffset =
        static_cast<uint32_t>(DXConStrTabBuilder.getOffset(EntryName));

+1 −1
Original line number Diff line number Diff line
@@ -201,7 +201,7 @@ void StringTableBuilder::finalizeStringTable(bool Optimize) {
  // specification. In 'initSize()' we reserved the first byte to hold null for
  // this purpose and here we actually add the string to allow 'getOffset()' to
  // be called on an empty string.
  if (K == ELF)
  if (K == ELF || K == DXContainer)
    StringIndexMap[CachedHashStringRef("")] = 0;
}

Loading