| 717 | } |
| 718 | |
| 719 | void HnMaterial::UpdateSRB(HnRenderDelegate& RendererDelegate) |
| 720 | { |
| 721 | RefCntAutoPtr<HnMaterialSRBCache> SRBCache{RendererDelegate.GetMaterialSRBCache(), IID_HnMaterialSRBCache}; |
| 722 | VERIFY_EXPR(SRBCache); |
| 723 | |
| 724 | HN_MATERIAL_TEXTURES_BINDING_MODE BindingMode = static_cast<const HnRenderParam*>(RendererDelegate.GetRenderParam())->GetTextureBindingMode(); |
| 725 | |
| 726 | const Uint32 AtlasVersion = RendererDelegate.GetTextureRegistry().GetAtlasVersion(); |
| 727 | if (BindingMode == HN_MATERIAL_TEXTURES_BINDING_MODE_ATLAS && AtlasVersion != m_AtlasVersion) |
| 728 | { |
| 729 | m_SRB.Release(); |
| 730 | m_PrimitiveAttribsVar = nullptr; |
| 731 | m_PBRPrimitiveAttribsBufferRange = 0; |
| 732 | m_AtlasVersion = AtlasVersion; |
| 733 | } |
| 734 | |
| 735 | if (m_SRB) |
| 736 | return; |
| 737 | |
| 738 | const USD_Renderer& UsdRenderer = *RendererDelegate.GetUSDRenderer(); |
| 739 | const PBR_Renderer::CreateInfo& RendererSettings = UsdRenderer.GetSettings(); |
| 740 | const Uint32 TexturesArraySize = RendererSettings.MaterialTexturesArraySize; |
| 741 | |
| 742 | // Texture array to bind to "g_MaterialTextures" |
| 743 | std::vector<ITexture*> TexArray; |
| 744 | |
| 745 | // Standalone textures not allocated in the atlas. |
| 746 | std::unordered_map<PBR_Renderer::TEXTURE_ATTRIB_ID, ITexture*> StandaloneTextures; |
| 747 | |
| 748 | HnMaterialSRBCache::ResourceKey SRBKey; |
| 749 | |
| 750 | if (BindingMode == HN_MATERIAL_TEXTURES_BINDING_MODE_LEGACY || |
| 751 | BindingMode == HN_MATERIAL_TEXTURES_BINDING_MODE_ATLAS) |
| 752 | { |
| 753 | // Allocated texture atlas formats, for example: |
| 754 | // {RGBA8_UNORM, R8_UNORM, RGBA8_UNORM_SRGB} |
| 755 | std::vector<TEXTURE_FORMAT> AtlasFormats; |
| 756 | |
| 757 | // Texture atlas format to atlas id, for example: |
| 758 | // RGBA8_UNORM -> 0 |
| 759 | // R8_UNORM -> 1 |
| 760 | // RGBA8_UNORM_SRGB -> 2 |
| 761 | std::unordered_map<TEXTURE_FORMAT, Uint32> AtlasFormatIds; |
| 762 | if (BindingMode == HN_MATERIAL_TEXTURES_BINDING_MODE_ATLAS) |
| 763 | { |
| 764 | AtlasFormats = RendererDelegate.GetResourceManager().GetAllocatedAtlasFormats(); |
| 765 | for (Uint32 i = 0; i < AtlasFormats.size(); ++i) |
| 766 | { |
| 767 | AtlasFormatIds.emplace(AtlasFormats[i], i); |
| 768 | } |
| 769 | } |
| 770 | |
| 771 | TexArray.resize(TexturesArraySize); |
| 772 | |
| 773 | PBR_Renderer::StaticShaderTextureIdsArrayType StaticShaderTexIds; |
| 774 | StaticShaderTexIds.fill(decltype(PBR_Renderer::InvalidMaterialTextureId){PBR_Renderer::InvalidMaterialTextureId}); |
| 775 | |
| 776 | for (Uint32 id = 0; id < PBR_Renderer::TEXTURE_ATTRIB_ID_COUNT; ++id) |
no test coverage detected