From 50459a5f0e4d3d5b02825c3251e20ca44fcad9a7 Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Thu, 23 Jan 2025 17:20:12 -0800 Subject: [PATCH] try fix --- .../DxilContainerValidation.cpp | 58 ++++++++++++------- 1 file changed, 36 insertions(+), 22 deletions(-) diff --git a/lib/DxilValidation/DxilContainerValidation.cpp b/lib/DxilValidation/DxilContainerValidation.cpp index 96066a6e55..3dbeff6cb9 100644 --- a/lib/DxilValidation/DxilContainerValidation.cpp +++ b/lib/DxilValidation/DxilContainerValidation.cpp @@ -1275,28 +1275,6 @@ static HRESULT ValidateLoadModuleFromContainer( } } - // Verify that the ProgramHeader in the container contains a program version - // that matches the DxilModule's shader model version - const DxilProgramHeader *pProgramHeader = - reinterpret_cast(GetDxilPartData(pPart)); - if (pProgramHeader) { - int PV = pProgramHeader->ProgramVersion; - int major = (PV >> 4) & 0xF; // Extract the major version (next 4 bits) - int minor = PV & 0xF; // Extract the minor version (lowest 4 bits) - DxilModule *pDxilModule = DxilModule::TryGetDxilModule(pModule.get()); - - ValidationContext ValCtx(*pModule, &*pDebugModule, *pDxilModule); - int moduleMajor = ValCtx.DxilMod.GetShaderModel()->GetMajor(); - int moduleMinor = ValCtx.DxilMod.GetShaderModel()->GetMinor(); - if (moduleMajor != major || moduleMinor != minor) { - ValCtx.EmitFormatError(ValidationRule::SmProgramVersion, - {std::to_string(major), std::to_string(minor), - std::to_string(moduleMajor), - std::to_string(moduleMinor)}); - return DXC_E_INCORRECT_PROGRAM_VERSION; - } - } - return S_OK; } @@ -1320,6 +1298,39 @@ HRESULT ValidateLoadModuleFromContainerLazy( /*bLazyLoad*/ true); } +HRESULT ValidateDxilContainerAgainstModule(const void *pContainer, + uint32_t ContainerSize, + llvm::Module *pModule, + llvm::Module *pDebugModule, + llvm::raw_ostream &DiagStream) { + const DxilPartHeader *pPart = nullptr; + IFR(FindDxilPart(pContainer, ContainerSize, DFCC_DXIL, &pPart)); + // Verify that the ProgramHeader in the container contains a program version + // that matches the DxilModule's shader model version + const DxilProgramHeader *pProgramHeader = + reinterpret_cast(GetDxilPartData(pPart)); + if (pProgramHeader) { + int PV = pProgramHeader->ProgramVersion; + int major = (PV >> 4) & 0xF; // Extract the major version (next 4 bits) + int minor = PV & 0xF; // Extract the minor version (lowest 4 bits) + DxilModule *pDxilModule = DxilModule::TryGetDxilModule(pModule); + if (!pDxilModule) { + return DXC_E_IR_VERIFICATION_FAILED; + } + ValidationContext ValCtx(*pModule, pDebugModule, *pDxilModule); + int moduleMajor = ValCtx.DxilMod.GetShaderModel()->GetMajor(); + int moduleMinor = ValCtx.DxilMod.GetShaderModel()->GetMinor(); + if (moduleMajor != major || moduleMinor != minor) { + ValCtx.EmitFormatError(ValidationRule::SmProgramVersion, + {std::to_string(major), std::to_string(minor), + std::to_string(moduleMajor), + std::to_string(moduleMinor)}); + return DXC_E_INCORRECT_PROGRAM_VERSION; + } + } + return S_OK; +} + HRESULT ValidateDxilContainer(const void *pContainer, uint32_t ContainerSize, llvm::Module *pDebugModule, llvm::raw_ostream &DiagStream) { @@ -1345,6 +1356,9 @@ HRESULT ValidateDxilContainer(const void *pContainer, uint32_t ContainerSize, // Validate DXIL Module IFR(ValidateDxilModule(pModule.get(), pDebugModule)); + IFR(ValidateDxilContainerAgainstModule( + pContainer, ContainerSize, pModule.get(), pDebugModule, DiagStream)); + if (DiagContext.HasErrors() || DiagContext.HasWarnings()) { return DXC_E_IR_VERIFICATION_FAILED; }