From ee75e05e252e450480ea5adc46649b0c96544a0b Mon Sep 17 00:00:00 2001 From: Minmin Gong Date: Sat, 29 Jun 2019 17:58:22 -0700 Subject: [PATCH] Engineering: Fix some crashes during deploying --- DeployKlayGE.py | 10 +- KlayGE/Core/Include/KlayGE/RenderMaterial.hpp | 14 +- KlayGE/Core/Src/Render/RenderMaterial.cpp | 397 +++++++++++++++--- KlayGE/Core/Src/Render/Renderable.cpp | 17 +- .../Src/Render/D3D11/D3D11RenderEngine.cpp | 1 + .../Src/Render/D3D12/D3D12RenderEngine.cpp | 1 + 6 files changed, 361 insertions(+), 79 deletions(-) diff --git a/DeployKlayGE.py b/DeployKlayGE.py index 46c1e9bac5..b772bd47a2 100644 --- a/DeployKlayGE.py +++ b/DeployKlayGE.py @@ -3,7 +3,7 @@ from __future__ import print_function import os, sys -from BLibUtil import * +from Build import BuildInfo def CopyToDst(src_name, dst_dir): print("Copy %s to %s" % (src_name, dst_dir)) @@ -57,9 +57,7 @@ def DeployKlayGE(target_dir, build_info, compiler_arch): CopyToDst(fname, bin_dst_dir); print("Deploying OpenAL...\n") - for fname in glob.iglob("KlayGE/bin/win_%s/OpenAL32.%s" % (compiler_arch, dll_suffix)): - CopyToDst(fname, bin_dst_dir); - for fname in glob.iglob("KlayGE/bin/win_%s/wrap_oal.%s" % (compiler_arch, dll_suffix)): + for fname in glob.iglob("KlayGE/bin/win_%s/OpenAL%s" % (compiler_arch, lib_suffix)): CopyToDst(fname, bin_dst_dir); print("Deploying assimp...\n") @@ -70,6 +68,10 @@ def DeployKlayGE(target_dir, build_info, compiler_arch): for fname in glob.iglob("KlayGE/bin/win_%s/FreeImage%s" % (compiler_arch, lib_suffix)): CopyToDst(fname, bin_dst_dir); + print("Deploying zlib...\n") + for fname in glob.iglob("KlayGE/bin/win_%s/zlib%s" % (compiler_arch, lib_suffix)): + CopyToDst(fname, bin_dst_dir); + print("Deploying glloader...\n") for fname in glob.iglob("KlayGE/bin/win_%s/glloader%s" % (compiler_arch, lib_suffix)): CopyToDst(fname, bin_dst_dir); diff --git a/KlayGE/Core/Include/KlayGE/RenderMaterial.hpp b/KlayGE/Core/Include/KlayGE/RenderMaterial.hpp index a9e45e770a..7d20dddbc6 100644 --- a/KlayGE/Core/Include/KlayGE/RenderMaterial.hpp +++ b/KlayGE/Core/Include/KlayGE/RenderMaterial.hpp @@ -154,13 +154,15 @@ namespace KlayGE private: std::string name_; + bool is_sw_mode_ = false; RenderEffectConstantBufferPtr cbuffer_; - RenderEffectParameter* albedo_tex_param_; - RenderEffectParameter* metalness_glossiness_tex_param_; - RenderEffectParameter* emissive_tex_param_; - RenderEffectParameter* normal_tex_param_; - RenderEffectParameter* height_tex_param_; - RenderEffectParameter* occlusion_tex_param_; + std::vector sw_cbuffer_; + RenderEffectParameter* albedo_tex_param_ = nullptr; + RenderEffectParameter* metalness_glossiness_tex_param_ = nullptr; + RenderEffectParameter* emissive_tex_param_ = nullptr; + RenderEffectParameter* normal_tex_param_ = nullptr; + RenderEffectParameter* height_tex_param_ = nullptr; + RenderEffectParameter* occlusion_tex_param_ = nullptr; bool transparent_ = false; bool sss_ = false; diff --git a/KlayGE/Core/Src/Render/RenderMaterial.cpp b/KlayGE/Core/Src/Render/RenderMaterial.cpp index d9a6fe1600..995dc8a490 100644 --- a/KlayGE/Core/Src/Render/RenderMaterial.cpp +++ b/KlayGE/Core/Src/Render/RenderMaterial.cpp @@ -386,11 +386,14 @@ namespace } } - RenderFactory& rf = Context::Instance().RenderFactoryInstance(); - RenderDeviceCaps const & caps = rf.RenderEngineInstance().DeviceCaps(); - if (caps.multithread_res_creating_support) + if (Context::Instance().RenderFactoryValid()) { - this->MainThreadStageNoLock(); + RenderFactory& rf = Context::Instance().RenderFactoryInstance(); + RenderDeviceCaps const& caps = rf.RenderEngineInstance().DeviceCaps(); + if (caps.multithread_res_creating_support) + { + this->MainThreadStageNoLock(); + } } } @@ -479,6 +482,23 @@ namespace std::mutex main_thread_stage_mutex_; }; + // TODO: Need refactors + + uint32_t constexpr sw_albedo_clr_offset_ = 0; + uint32_t constexpr sw_metalness_glossiness_factor_offset_ = sw_albedo_clr_offset_ + sizeof(float4); + uint32_t constexpr sw_emissive_clr_offset_ = sw_metalness_glossiness_factor_offset_ + sizeof(float4); + uint32_t constexpr sw_albedo_map_enabled_offset_ = sw_emissive_clr_offset_ + sizeof(float4); + uint32_t constexpr sw_normal_map_enabled_offset_ = sw_albedo_map_enabled_offset_ + sizeof(uint32_t); + uint32_t constexpr sw_height_map_parallax_enabled_offset_ = sw_normal_map_enabled_offset_ + sizeof(uint32_t); + uint32_t constexpr sw_height_map_tess_enabled_offset_ = sw_height_map_parallax_enabled_offset_ + sizeof(uint32_t); + uint32_t constexpr sw_occlusion_map_enabled_offset_ = sw_height_map_tess_enabled_offset_ + sizeof(uint32_t); + uint32_t constexpr sw_alpha_test_threshold_offset_ = sw_occlusion_map_enabled_offset_ + sizeof(uint32_t); + uint32_t constexpr sw_normal_scale_offset_ = sw_alpha_test_threshold_offset_ + sizeof(uint32_t); + uint32_t constexpr sw_occlusion_strength_offset_ = sw_normal_scale_offset_ + sizeof(float); + uint32_t constexpr sw_height_offset_scale_offset_ = sw_occlusion_strength_offset_ + sizeof(float); + uint32_t constexpr sw_tess_factors_offset_ = sw_occlusion_strength_offset_ + sizeof(float4); + uint32_t constexpr sw_pdmc_size = sw_tess_factors_offset_ + sizeof(float4); + RenderEngine::PredefinedMaterialCBuffer const& PredefinedMaterialCBufferInstance() { return Context::Instance().RenderFactoryInstance().RenderEngineInstance().PredefinedMaterialCBufferInstance(); @@ -489,8 +509,17 @@ namespace KlayGE { RenderMaterial::RenderMaterial() { - auto* curr_cbuff = PredefinedMaterialCBufferInstance().CBuffer(); - cbuffer_ = curr_cbuff->Clone(curr_cbuff->OwnerEffect()); + if (Context::Instance().RenderFactoryValid()) + { + auto* curr_cbuff = PredefinedMaterialCBufferInstance().CBuffer(); + cbuffer_ = curr_cbuff->Clone(curr_cbuff->OwnerEffect()); + is_sw_mode_ = false; + } + else + { + sw_cbuffer_.resize(sw_pdmc_size); + is_sw_mode_ = true; + } } RenderMaterialPtr RenderMaterial::Clone() const @@ -498,7 +527,15 @@ namespace KlayGE RenderMaterialPtr ret = MakeSharedPtr(); ret->Name(this->Name()); - ret->cbuffer_ = cbuffer_->Clone(cbuffer_->OwnerEffect()); + ret->is_sw_mode_ = is_sw_mode_; + if (is_sw_mode_) + { + ret->sw_cbuffer_ = sw_cbuffer_; + } + else + { + ret->cbuffer_ = cbuffer_->Clone(cbuffer_->OwnerEffect()); + } ret->transparent_ = transparent_; ret->sss_ = sss_; @@ -511,79 +548,177 @@ namespace KlayGE void RenderMaterial::Albedo(float4 const& value) { - PredefinedMaterialCBufferInstance().AlbedoClr(*cbuffer_) = value; - cbuffer_->Dirty(true); + if (is_sw_mode_) + { + reinterpret_cast(sw_cbuffer_[sw_albedo_clr_offset_]) = value; + } + else + { + PredefinedMaterialCBufferInstance().AlbedoClr(*cbuffer_) = value; + cbuffer_->Dirty(true); + } } float4 const& RenderMaterial::Albedo() const { - return PredefinedMaterialCBufferInstance().AlbedoClr(*cbuffer_); + if (is_sw_mode_) + { + return reinterpret_cast(sw_cbuffer_[sw_albedo_clr_offset_]); + } + else + { + return PredefinedMaterialCBufferInstance().AlbedoClr(*cbuffer_); + } } void RenderMaterial::Metalness(float value) { - PredefinedMaterialCBufferInstance().MetalnessGlossinessFactor(*cbuffer_).x() = value; - cbuffer_->Dirty(true); + if (is_sw_mode_) + { + reinterpret_cast(sw_cbuffer_[sw_metalness_glossiness_factor_offset_]).x() = value; + } + else + { + PredefinedMaterialCBufferInstance().MetalnessGlossinessFactor(*cbuffer_).x() = value; + cbuffer_->Dirty(true); + } } float RenderMaterial::Metalness() const { - return PredefinedMaterialCBufferInstance().MetalnessGlossinessFactor(*cbuffer_).x(); + if (is_sw_mode_) + { + return reinterpret_cast(sw_cbuffer_[sw_metalness_glossiness_factor_offset_]).x(); + } + else + { + return PredefinedMaterialCBufferInstance().MetalnessGlossinessFactor(*cbuffer_).x(); + } } void RenderMaterial::Glossiness(float value) { - PredefinedMaterialCBufferInstance().MetalnessGlossinessFactor(*cbuffer_).y() = MathLib::clamp(value, 1e-6f, 0.999f); - cbuffer_->Dirty(true); + if (is_sw_mode_) + { + reinterpret_cast(sw_cbuffer_[sw_metalness_glossiness_factor_offset_]).y() = value; + } + else + { + PredefinedMaterialCBufferInstance().MetalnessGlossinessFactor(*cbuffer_).y() = MathLib::clamp(value, 1e-6f, 0.999f); + cbuffer_->Dirty(true); + } } float RenderMaterial::Glossiness() const { - return PredefinedMaterialCBufferInstance().MetalnessGlossinessFactor(*cbuffer_).y(); + if (is_sw_mode_) + { + return reinterpret_cast(sw_cbuffer_[sw_metalness_glossiness_factor_offset_]).y(); + } + else + { + return PredefinedMaterialCBufferInstance().MetalnessGlossinessFactor(*cbuffer_).y(); + } } void RenderMaterial::Emissive(float3 const& value) { - reinterpret_cast(PredefinedMaterialCBufferInstance().EmissiveClr(*cbuffer_)) = value; - cbuffer_->Dirty(true); + if (is_sw_mode_) + { + reinterpret_cast(sw_cbuffer_[sw_emissive_clr_offset_]) = value; + } + else + { + reinterpret_cast(PredefinedMaterialCBufferInstance().EmissiveClr(*cbuffer_)) = value; + cbuffer_->Dirty(true); + } } float3 const& RenderMaterial::Emissive() const { - return reinterpret_cast(PredefinedMaterialCBufferInstance().EmissiveClr(*cbuffer_)); + if (is_sw_mode_) + { + return reinterpret_cast(sw_cbuffer_[sw_emissive_clr_offset_]); + } + else + { + return reinterpret_cast(PredefinedMaterialCBufferInstance().EmissiveClr(*cbuffer_)); + } } void RenderMaterial::AlphaTestThreshold(float value) { - PredefinedMaterialCBufferInstance().AlphaTestThreshold(*cbuffer_) = value; - cbuffer_->Dirty(true); + if (is_sw_mode_) + { + reinterpret_cast(sw_cbuffer_[sw_alpha_test_threshold_offset_]) = value; + } + else + { + PredefinedMaterialCBufferInstance().AlphaTestThreshold(*cbuffer_) = value; + cbuffer_->Dirty(true); + } } float RenderMaterial::AlphaTestThreshold() const { - return PredefinedMaterialCBufferInstance().AlphaTestThreshold(*cbuffer_); + if (is_sw_mode_) + { + return reinterpret_cast(sw_cbuffer_[sw_alpha_test_threshold_offset_]); + } + else + { + return PredefinedMaterialCBufferInstance().AlphaTestThreshold(*cbuffer_); + } } void RenderMaterial::NormalScale(float value) { - PredefinedMaterialCBufferInstance().NormalScale(*cbuffer_) = value; - cbuffer_->Dirty(true); + if (is_sw_mode_) + { + reinterpret_cast(sw_cbuffer_[sw_normal_scale_offset_]) = value; + } + else + { + PredefinedMaterialCBufferInstance().NormalScale(*cbuffer_) = value; + cbuffer_->Dirty(true); + } } float RenderMaterial::NormalScale() const { - return PredefinedMaterialCBufferInstance().NormalScale(*cbuffer_); + if (is_sw_mode_) + { + return reinterpret_cast(sw_cbuffer_[sw_normal_scale_offset_]); + } + else + { + return PredefinedMaterialCBufferInstance().NormalScale(*cbuffer_); + } } void RenderMaterial::OcclusionStrength(float value) { - PredefinedMaterialCBufferInstance().OcclusionStrength(*cbuffer_) = value; - cbuffer_->Dirty(true); + if (is_sw_mode_) + { + reinterpret_cast(sw_cbuffer_[sw_occlusion_strength_offset_]) = value; + } + else + { + PredefinedMaterialCBufferInstance().OcclusionStrength(*cbuffer_) = value; + cbuffer_->Dirty(true); + } } float RenderMaterial::OcclusionStrength() const { - return PredefinedMaterialCBufferInstance().OcclusionStrength(*cbuffer_); + if (is_sw_mode_) + { + return reinterpret_cast(sw_cbuffer_[sw_occlusion_strength_offset_]); + } + else + { + return PredefinedMaterialCBufferInstance().OcclusionStrength(*cbuffer_); + } } void RenderMaterial::TextureName(TextureSlot slot, std::string_view name) @@ -597,36 +732,87 @@ namespace KlayGE switch (slot) { case TS_Albedo: - pmcb.AlbedoMapEnabled(*cbuffer_) = srv ? 1 : 0; + if (is_sw_mode_) + { + reinterpret_cast(sw_cbuffer_[sw_albedo_map_enabled_offset_]) = srv ? 1 : 0; + } + else + { + pmcb.AlbedoMapEnabled(*cbuffer_) = srv ? 1 : 0; + } break; case TS_MetalnessGlossiness: - pmcb.MetalnessGlossinessFactor(*cbuffer_).z() = srv ? 1.0f : 0.0f; + if (is_sw_mode_) + { + reinterpret_cast(sw_cbuffer_[sw_metalness_glossiness_factor_offset_]).z() = srv ? 1.0f : 0.0f; + } + else + { + pmcb.MetalnessGlossinessFactor(*cbuffer_).z() = srv ? 1.0f : 0.0f; + } break; case TS_Emissive: - pmcb.EmissiveClr(*cbuffer_).w() = srv ? 1.0f : 0.0f; + if (is_sw_mode_) + { + reinterpret_cast(sw_cbuffer_[sw_emissive_clr_offset_]).w() = srv ? 1.0f : 0.0f; + } + else + { + pmcb.EmissiveClr(*cbuffer_).w() = srv ? 1.0f : 0.0f; + } break; case TS_Normal: - pmcb.NormalMapEnabled(*cbuffer_) = srv ? 1 : 0; + if (is_sw_mode_) + { + reinterpret_cast(sw_cbuffer_[sw_normal_map_enabled_offset_]) = srv ? 1 : 0; + } + else + { + pmcb.NormalMapEnabled(*cbuffer_) = srv ? 1 : 0; + } break; case TS_Height: if (detail_mode_ == RenderMaterial::SDM_Parallax) { - pmcb.HeightMapParallaxEnabled(*cbuffer_) = srv ? 1 : 0; - pmcb.HeightMapTessEnabled(*cbuffer_) = 0; + if (is_sw_mode_) + { + reinterpret_cast(sw_cbuffer_[sw_height_map_parallax_enabled_offset_]) = srv ? 1 : 0; + reinterpret_cast(sw_cbuffer_[sw_height_map_tess_enabled_offset_]) = 0; + } + else + { + pmcb.HeightMapParallaxEnabled(*cbuffer_) = srv ? 1 : 0; + pmcb.HeightMapTessEnabled(*cbuffer_) = 0; + } } else { - pmcb.HeightMapParallaxEnabled(*cbuffer_) = 0; - pmcb.HeightMapTessEnabled(*cbuffer_) = srv ? 1 : 0; + if (is_sw_mode_) + { + reinterpret_cast(sw_cbuffer_[sw_height_map_parallax_enabled_offset_]) = 0; + reinterpret_cast(sw_cbuffer_[sw_height_map_tess_enabled_offset_]) = srv ? 1 : 0; + } + else + { + pmcb.HeightMapParallaxEnabled(*cbuffer_) = 0; + pmcb.HeightMapTessEnabled(*cbuffer_) = srv ? 1 : 0; + } } break; case TS_Occlusion: - pmcb.OcclusionMapEnabled(*cbuffer_) = srv ? 1 : 0; + if (is_sw_mode_) + { + reinterpret_cast(sw_cbuffer_[sw_occlusion_map_enabled_offset_]) = 0; + } + else + { + pmcb.OcclusionMapEnabled(*cbuffer_) = srv ? 1 : 0; + } break; default: @@ -641,85 +827,172 @@ namespace KlayGE void RenderMaterial::HeightOffset(float value) { - PredefinedMaterialCBufferInstance().HeightOffsetScale(*cbuffer_).x() = value; - cbuffer_->Dirty(true); + if (is_sw_mode_) + { + reinterpret_cast(sw_cbuffer_[sw_height_offset_scale_offset_]).x() = value; + } + else + { + PredefinedMaterialCBufferInstance().HeightOffsetScale(*cbuffer_).x() = value; + cbuffer_->Dirty(true); + } } float RenderMaterial::HeightOffset() const { - return PredefinedMaterialCBufferInstance().HeightOffsetScale(*cbuffer_).x(); + if (is_sw_mode_) + { + return reinterpret_cast(sw_cbuffer_[sw_height_offset_scale_offset_]).x(); + } + else + { + return PredefinedMaterialCBufferInstance().HeightOffsetScale(*cbuffer_).x(); + } } void RenderMaterial::HeightScale(float value) { - PredefinedMaterialCBufferInstance().HeightOffsetScale(*cbuffer_).y() = value; - cbuffer_->Dirty(true); + if (is_sw_mode_) + { + reinterpret_cast(sw_cbuffer_[sw_height_offset_scale_offset_]).y() = value; + } + else + { + PredefinedMaterialCBufferInstance().HeightOffsetScale(*cbuffer_).y() = value; + cbuffer_->Dirty(true); + } } float RenderMaterial::HeightScale() const { - return PredefinedMaterialCBufferInstance().HeightOffsetScale(*cbuffer_).y(); + if (is_sw_mode_) + { + return reinterpret_cast(sw_cbuffer_[sw_height_offset_scale_offset_]).y(); + } + else + { + return PredefinedMaterialCBufferInstance().HeightOffsetScale(*cbuffer_).y(); + } } void RenderMaterial::EdgeTessHint(float value) { - PredefinedMaterialCBufferInstance().TessFactors(*cbuffer_).x() = value; - cbuffer_->Dirty(true); + if (is_sw_mode_) + { + reinterpret_cast(sw_cbuffer_[sw_tess_factors_offset_]).x() = value; + } + else + { + PredefinedMaterialCBufferInstance().TessFactors(*cbuffer_).x() = value; + cbuffer_->Dirty(true); + } } float RenderMaterial::EdgeTessHint() const { - return PredefinedMaterialCBufferInstance().TessFactors(*cbuffer_).x(); + if (is_sw_mode_) + { + return reinterpret_cast(sw_cbuffer_[sw_tess_factors_offset_]).x(); + } + else + { + return PredefinedMaterialCBufferInstance().TessFactors(*cbuffer_).x(); + } } void RenderMaterial::InsideTessHint(float value) { - PredefinedMaterialCBufferInstance().TessFactors(*cbuffer_).y() = value; - cbuffer_->Dirty(true); + if (is_sw_mode_) + { + reinterpret_cast(sw_cbuffer_[sw_tess_factors_offset_]).y() = value; + } + else + { + PredefinedMaterialCBufferInstance().TessFactors(*cbuffer_).y() = value; + cbuffer_->Dirty(true); + } } float RenderMaterial::InsideTessHint() const { - return PredefinedMaterialCBufferInstance().TessFactors(*cbuffer_).y(); + if (is_sw_mode_) + { + return reinterpret_cast(sw_cbuffer_[sw_tess_factors_offset_]).y(); + } + else + { + return PredefinedMaterialCBufferInstance().TessFactors(*cbuffer_).y(); + } } void RenderMaterial::MinTessFactor(float value) { - PredefinedMaterialCBufferInstance().TessFactors(*cbuffer_).z() = value; - cbuffer_->Dirty(true); + if (is_sw_mode_) + { + reinterpret_cast(sw_cbuffer_[sw_tess_factors_offset_]).z() = value; + } + else + { + PredefinedMaterialCBufferInstance().TessFactors(*cbuffer_).z() = value; + cbuffer_->Dirty(true); + } } float RenderMaterial::MinTessFactor() const { - return PredefinedMaterialCBufferInstance().TessFactors(*cbuffer_).z(); + if (is_sw_mode_) + { + return reinterpret_cast(sw_cbuffer_[sw_tess_factors_offset_]).z(); + } + else + { + return PredefinedMaterialCBufferInstance().TessFactors(*cbuffer_).z(); + } } void RenderMaterial::MaxTessFactor(float value) { - PredefinedMaterialCBufferInstance().TessFactors(*cbuffer_).z() = value; - cbuffer_->Dirty(true); + if (is_sw_mode_) + { + reinterpret_cast(sw_cbuffer_[sw_tess_factors_offset_]).w() = value; + } + else + { + PredefinedMaterialCBufferInstance().TessFactors(*cbuffer_).w() = value; + cbuffer_->Dirty(true); + } } float RenderMaterial::MaxTessFactor() const { - return PredefinedMaterialCBufferInstance().TessFactors(*cbuffer_).z(); + if (is_sw_mode_) + { + return reinterpret_cast(sw_cbuffer_[sw_tess_factors_offset_]).w(); + } + else + { + return PredefinedMaterialCBufferInstance().TessFactors(*cbuffer_).w(); + } } void RenderMaterial::Active(RenderEffect& effect) { + if (&cbuffer_->OwnerEffect() != &effect) + { + albedo_tex_param_ = effect.ParameterByName("albedo_tex"); + metalness_glossiness_tex_param_ = effect.ParameterByName("metalness_glossiness_tex"); + emissive_tex_param_ = effect.ParameterByName("emissive_tex"); + normal_tex_param_ = effect.ParameterByName("normal_tex"); + height_tex_param_ = effect.ParameterByName("height_tex"); + occlusion_tex_param_ = effect.ParameterByName("occlusion_tex"); + } + uint32_t const index = effect.FindCBuffer("klayge_material"); if (index != static_cast(-1) && (effect.CBufferByIndex(index)->Size() > 0)) { if (&cbuffer_->OwnerEffect() != &effect) { cbuffer_ = cbuffer_->Clone(effect); - - albedo_tex_param_ = effect.ParameterByName("albedo_tex"); - metalness_glossiness_tex_param_ = effect.ParameterByName("metalness_glossiness_tex"); - emissive_tex_param_ = effect.ParameterByName("emissive_tex"); - normal_tex_param_ = effect.ParameterByName("normal_tex"); - height_tex_param_ = effect.ParameterByName("height_tex"); - occlusion_tex_param_ = effect.ParameterByName("occlusion_tex"); } effect.BindCBufferByIndex(index, cbuffer_); diff --git a/KlayGE/Core/Src/Render/Renderable.cpp b/KlayGE/Core/Src/Render/Renderable.cpp index 17af1cfe93..89d1d8355e 100644 --- a/KlayGE/Core/Src/Render/Renderable.cpp +++ b/KlayGE/Core/Src/Render/Renderable.cpp @@ -49,15 +49,18 @@ namespace KlayGE this->BindDeferredEffect(drl->GBufferEffect(nullptr, false, false)); } - auto const& re = Context::Instance().RenderFactoryInstance().RenderEngineInstance(); + if (Context::Instance().RenderFactoryValid()) + { + auto const& re = Context::Instance().RenderFactoryInstance().RenderEngineInstance(); - auto const& mesh_cb = re.PredefinedMeshCBufferInstance(); - auto* mesh_cbuff = mesh_cb.CBuffer(); - mesh_cbuffer_ = mesh_cbuff->Clone(mesh_cbuff->OwnerEffect()); + auto const& mesh_cb = re.PredefinedMeshCBufferInstance(); + auto* mesh_cbuff = mesh_cb.CBuffer(); + mesh_cbuffer_ = mesh_cbuff->Clone(mesh_cbuff->OwnerEffect()); - auto const& model_camera_cb = re.PredefinedModelCameraCBufferInstance(); - auto* model_camera_cbuff = model_camera_cb.CBuffer(); - model_camera_cbuffer_ = model_camera_cbuff->Clone(model_camera_cbuff->OwnerEffect()); + auto const& model_camera_cb = re.PredefinedModelCameraCBufferInstance(); + auto* model_camera_cbuff = model_camera_cb.CBuffer(); + model_camera_cbuffer_ = model_camera_cbuff->Clone(model_camera_cbuff->OwnerEffect()); + } } Renderable::~Renderable() diff --git a/KlayGE/Plugins/Src/Render/D3D11/D3D11RenderEngine.cpp b/KlayGE/Plugins/Src/Render/D3D11/D3D11RenderEngine.cpp index e50cb226ff..9a7c2300e0 100644 --- a/KlayGE/Plugins/Src/Render/D3D11/D3D11RenderEngine.cpp +++ b/KlayGE/Plugins/Src/Render/D3D11/D3D11RenderEngine.cpp @@ -915,6 +915,7 @@ namespace KlayGE gi_factory_3_.reset(); gi_factory_4_.reset(); gi_factory_5_.reset(); + gi_factory_6_.reset(); DynamicCreateDXGIFactory1_ = nullptr; DynamicD3D11CreateDevice_ = nullptr; diff --git a/KlayGE/Plugins/Src/Render/D3D12/D3D12RenderEngine.cpp b/KlayGE/Plugins/Src/Render/D3D12/D3D12RenderEngine.cpp index 3a51268f72..49cc0b82a8 100644 --- a/KlayGE/Plugins/Src/Render/D3D12/D3D12RenderEngine.cpp +++ b/KlayGE/Plugins/Src/Render/D3D12/D3D12RenderEngine.cpp @@ -1127,6 +1127,7 @@ namespace KlayGE gi_factory_4_.reset(); gi_factory_5_.reset(); + gi_factory_6_.reset(); D3D12InterfaceLoader::Instance().Destroy(); }