|
13 | 13 | #include "DXILRootSignature.h"
|
14 | 14 | #include "DirectX.h"
|
15 | 15 | #include "llvm/ADT/APFloat.h"
|
| 16 | +#include "llvm/ADT/STLForwardCompat.h" |
16 | 17 | #include "llvm/ADT/StringSwitch.h"
|
17 | 18 | #include "llvm/ADT/Twine.h"
|
18 | 19 | #include "llvm/Analysis/DXILMetadataAnalysis.h"
|
|
28 | 29 | #include "llvm/Support/Error.h"
|
29 | 30 | #include "llvm/Support/ErrorHandling.h"
|
30 | 31 | #include "llvm/Support/raw_ostream.h"
|
| 32 | +#include <cmath> |
31 | 33 | #include <cstdint>
|
32 | 34 | #include <optional>
|
33 | 35 | #include <utility>
|
@@ -478,6 +480,127 @@ static bool verifyDescriptorRangeFlag(uint32_t Version, uint32_t Type,
|
478 | 480 | return (Flags & ~DataFlags) == FlagT::NONE;
|
479 | 481 | }
|
480 | 482 |
|
| 483 | +static bool verifySamplerFilter(uint32_t Filter) { |
| 484 | + switch (Filter) { |
| 485 | + case llvm::to_underlying(dxbc::StaticSamplerFilter::MIN_MAG_MIP_POINT): |
| 486 | + case llvm::to_underlying(dxbc::StaticSamplerFilter::MIN_MAG_POINT_MIP_LINEAR): |
| 487 | + case llvm::to_underlying( |
| 488 | + dxbc::StaticSamplerFilter::MIN_POINT_MAG_LINEAR_MIP_POINT): |
| 489 | + case llvm::to_underlying(dxbc::StaticSamplerFilter::MIN_POINT_MAG_MIP_LINEAR): |
| 490 | + case llvm::to_underlying(dxbc::StaticSamplerFilter::MIN_LINEAR_MAG_MIP_POINT): |
| 491 | + case llvm::to_underlying( |
| 492 | + dxbc::StaticSamplerFilter::MIN_LINEAR_MAG_POINT_MIP_LINEAR): |
| 493 | + case llvm::to_underlying(dxbc::StaticSamplerFilter::MIN_MAG_LINEAR_MIP_POINT): |
| 494 | + case llvm::to_underlying(dxbc::StaticSamplerFilter::MIN_MAG_MIP_LINEAR): |
| 495 | + case llvm::to_underlying(dxbc::StaticSamplerFilter::ANISOTROPIC): |
| 496 | + case llvm::to_underlying( |
| 497 | + dxbc::StaticSamplerFilter::COMPARISON_MIN_MAG_MIP_POINT): |
| 498 | + case llvm::to_underlying( |
| 499 | + dxbc::StaticSamplerFilter::COMPARISON_MIN_MAG_POINT_MIP_LINEAR): |
| 500 | + case llvm::to_underlying( |
| 501 | + dxbc::StaticSamplerFilter::COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT): |
| 502 | + case llvm::to_underlying( |
| 503 | + dxbc::StaticSamplerFilter::COMPARISON_MIN_POINT_MAG_MIP_LINEAR): |
| 504 | + case llvm::to_underlying( |
| 505 | + dxbc::StaticSamplerFilter::COMPARISON_MIN_LINEAR_MAG_MIP_POINT): |
| 506 | + case llvm::to_underlying( |
| 507 | + dxbc::StaticSamplerFilter::COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR): |
| 508 | + case llvm::to_underlying( |
| 509 | + dxbc::StaticSamplerFilter::COMPARISON_MIN_MAG_LINEAR_MIP_POINT): |
| 510 | + case llvm::to_underlying( |
| 511 | + dxbc::StaticSamplerFilter::COMPARISON_MIN_MAG_MIP_LINEAR): |
| 512 | + case llvm::to_underlying(dxbc::StaticSamplerFilter::COMPARISON_ANISOTROPIC): |
| 513 | + case llvm::to_underlying( |
| 514 | + dxbc::StaticSamplerFilter::MINIMUM_MIN_MAG_MIP_POINT): |
| 515 | + case llvm::to_underlying( |
| 516 | + dxbc::StaticSamplerFilter::MINIMUM_MIN_MAG_POINT_MIP_LINEAR): |
| 517 | + case llvm::to_underlying( |
| 518 | + dxbc::StaticSamplerFilter::MINIMUM_MIN_POINT_MAG_LINEAR_MIP_POINT): |
| 519 | + case llvm::to_underlying( |
| 520 | + dxbc::StaticSamplerFilter::MINIMUM_MIN_POINT_MAG_MIP_LINEAR): |
| 521 | + case llvm::to_underlying( |
| 522 | + dxbc::StaticSamplerFilter::MINIMUM_MIN_LINEAR_MAG_MIP_POINT): |
| 523 | + case llvm::to_underlying( |
| 524 | + dxbc::StaticSamplerFilter::MINIMUM_MIN_LINEAR_MAG_POINT_MIP_LINEAR): |
| 525 | + case llvm::to_underlying( |
| 526 | + dxbc::StaticSamplerFilter::MINIMUM_MIN_MAG_LINEAR_MIP_POINT): |
| 527 | + case llvm::to_underlying( |
| 528 | + dxbc::StaticSamplerFilter::MINIMUM_MIN_MAG_MIP_LINEAR): |
| 529 | + case llvm::to_underlying(dxbc::StaticSamplerFilter::MINIMUM_ANISOTROPIC): |
| 530 | + case llvm::to_underlying( |
| 531 | + dxbc::StaticSamplerFilter::MAXIMUM_MIN_MAG_MIP_POINT): |
| 532 | + case llvm::to_underlying( |
| 533 | + dxbc::StaticSamplerFilter::MAXIMUM_MIN_MAG_POINT_MIP_LINEAR): |
| 534 | + case llvm::to_underlying( |
| 535 | + dxbc::StaticSamplerFilter::MAXIMUM_MIN_POINT_MAG_LINEAR_MIP_POINT): |
| 536 | + case llvm::to_underlying( |
| 537 | + dxbc::StaticSamplerFilter::MAXIMUM_MIN_POINT_MAG_MIP_LINEAR): |
| 538 | + case llvm::to_underlying( |
| 539 | + dxbc::StaticSamplerFilter::MAXIMUM_MIN_LINEAR_MAG_MIP_POINT): |
| 540 | + case llvm::to_underlying( |
| 541 | + dxbc::StaticSamplerFilter::MAXIMUM_MIN_LINEAR_MAG_POINT_MIP_LINEAR): |
| 542 | + case llvm::to_underlying( |
| 543 | + dxbc::StaticSamplerFilter::MAXIMUM_MIN_MAG_LINEAR_MIP_POINT): |
| 544 | + case llvm::to_underlying( |
| 545 | + dxbc::StaticSamplerFilter::MAXIMUM_MIN_MAG_MIP_LINEAR): |
| 546 | + case llvm::to_underlying(dxbc::StaticSamplerFilter::MAXIMUM_ANISOTROPIC): |
| 547 | + return true; |
| 548 | + } |
| 549 | + return false; |
| 550 | +} |
| 551 | + |
| 552 | +// Values allowed here: |
| 553 | +// https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ne-d3d12-d3d12_texture_address_mode#syntax |
| 554 | +static bool verifyAddress(uint32_t Address) { |
| 555 | + switch (Address) { |
| 556 | + case llvm::to_underlying(dxbc::TextureAddressMode::Border): |
| 557 | + case llvm::to_underlying(dxbc::TextureAddressMode::Clamp): |
| 558 | + case llvm::to_underlying(dxbc::TextureAddressMode::Mirror): |
| 559 | + case llvm::to_underlying(dxbc::TextureAddressMode::MirrorOnce): |
| 560 | + case llvm::to_underlying(dxbc::TextureAddressMode::Wrap): |
| 561 | + return true; |
| 562 | + } |
| 563 | + |
| 564 | + return false; |
| 565 | +} |
| 566 | + |
| 567 | +static bool verifyMipLODBias(float MipLODBias) { |
| 568 | + return MipLODBias >= -16.f && MipLODBias <= 16.f; |
| 569 | +} |
| 570 | + |
| 571 | +static bool verifyMaxAnisotropy(uint32_t MaxAnisotropy) { |
| 572 | + return MaxAnisotropy <= 16u; |
| 573 | +} |
| 574 | + |
| 575 | +static bool verifyComparisonFunc(uint32_t ComparisonFunc) { |
| 576 | + switch (ComparisonFunc) { |
| 577 | + case llvm::to_underlying(dxbc::SamplersComparisonFunction::Never): |
| 578 | + case llvm::to_underlying(dxbc::SamplersComparisonFunction::Less): |
| 579 | + case llvm::to_underlying(dxbc::SamplersComparisonFunction::Equal): |
| 580 | + case llvm::to_underlying(dxbc::SamplersComparisonFunction::LessEqual): |
| 581 | + case llvm::to_underlying(dxbc::SamplersComparisonFunction::Greater): |
| 582 | + case llvm::to_underlying(dxbc::SamplersComparisonFunction::NotEqual): |
| 583 | + case llvm::to_underlying(dxbc::SamplersComparisonFunction::GreaterEqual): |
| 584 | + case llvm::to_underlying(dxbc::SamplersComparisonFunction::Always): |
| 585 | + return true; |
| 586 | + } |
| 587 | + return false; |
| 588 | +} |
| 589 | + |
| 590 | +static bool verifyBorderColor(uint32_t BorderColor) { |
| 591 | + switch (BorderColor) { |
| 592 | + case llvm::to_underlying(dxbc::SamplersBorderColor::TransparentBlack): |
| 593 | + case llvm::to_underlying(dxbc::SamplersBorderColor::OpaqueBlack): |
| 594 | + case llvm::to_underlying(dxbc::SamplersBorderColor::OpaqueWhite): |
| 595 | + case llvm::to_underlying(dxbc::SamplersBorderColor::OpaqueBlackUint): |
| 596 | + case llvm::to_underlying(dxbc::SamplersBorderColor::OpaqueWhiteUint): |
| 597 | + return true; |
| 598 | + } |
| 599 | + return false; |
| 600 | +} |
| 601 | + |
| 602 | +static bool verifyLOD(float LOD) { return !std::isnan(LOD); } |
| 603 | + |
481 | 604 | static bool validate(LLVMContext *Ctx, const mcdxbc::RootSignatureDesc &RSD) {
|
482 | 605 |
|
483 | 606 | if (!verifyVersion(RSD.Version)) {
|
@@ -535,6 +658,51 @@ static bool validate(LLVMContext *Ctx, const mcdxbc::RootSignatureDesc &RSD) {
|
535 | 658 | }
|
536 | 659 | }
|
537 | 660 |
|
| 661 | + for (const dxbc::RTS0::v1::StaticSampler &Sampler : RSD.StaticSamplers) { |
| 662 | + if (!verifySamplerFilter(Sampler.Filter)) |
| 663 | + return reportValueError(Ctx, "Filter", Sampler.Filter); |
| 664 | + |
| 665 | + if (!verifyAddress(Sampler.AddressU)) |
| 666 | + return reportValueError(Ctx, "AddressU", Sampler.AddressU); |
| 667 | + |
| 668 | + if (!verifyAddress(Sampler.AddressV)) |
| 669 | + return reportValueError(Ctx, "AddressU", Sampler.AddressV); |
| 670 | + |
| 671 | + if (!verifyAddress(Sampler.AddressW)) |
| 672 | + return reportValueError(Ctx, "AddressU", Sampler.AddressW); |
| 673 | + |
| 674 | + if (!verifyMipLODBias(Sampler.MipLODBias)) |
| 675 | + return reportValueError(Ctx, "MipLODBias", Sampler.MipLODBias); |
| 676 | + |
| 677 | + if (!verifyMaxAnisotropy(Sampler.MaxAnisotropy)) |
| 678 | + return reportValueError(Ctx, "MaxAnisotropy", Sampler.MaxAnisotropy); |
| 679 | + |
| 680 | + if (!verifyComparisonFunc(Sampler.ComparisonFunc)) |
| 681 | + return reportValueError(Ctx, "ComparisonFunc", Sampler.ComparisonFunc); |
| 682 | + |
| 683 | + if (!verifyComparisonFunc(Sampler.ComparisonFunc)) |
| 684 | + return reportValueError(Ctx, "ComparisonFunc", Sampler.ComparisonFunc); |
| 685 | + |
| 686 | + if (!verifyBorderColor(Sampler.BorderColor)) |
| 687 | + return reportValueError(Ctx, "BorderColor ", Sampler.BorderColor); |
| 688 | + |
| 689 | + if (!verifyLOD(Sampler.MinLOD)) |
| 690 | + return reportValueError(Ctx, "MinLOD ", Sampler.MinLOD); |
| 691 | + |
| 692 | + if (!verifyLOD(Sampler.MaxLOD)) |
| 693 | + return reportValueError(Ctx, "MaxLOD ", Sampler.MaxLOD); |
| 694 | + |
| 695 | + if (!verifyRegisterValue(Sampler.ShaderRegister)) |
| 696 | + return reportValueError(Ctx, "ShaderRegister", Sampler.ShaderRegister); |
| 697 | + |
| 698 | + if (!verifyRegisterSpace(Sampler.RegisterSpace)) |
| 699 | + return reportValueError(Ctx, "RegisterSpace", Sampler.RegisterSpace); |
| 700 | + |
| 701 | + if (!dxbc::isValidShaderVisibility(Sampler.ShaderVisibility)) |
| 702 | + return reportValueError(Ctx, "ShaderVisibility", |
| 703 | + Sampler.ShaderVisibility); |
| 704 | + } |
| 705 | + |
538 | 706 | return false;
|
539 | 707 | }
|
540 | 708 |
|
|
0 commit comments