共 11 个文件变更+109-60
@@ -36,7 +36,7 @@ OH_NativeXComponent_Callback PluginRender::m_callback;
36static bool isSystemSupport = false;36static bool isSystemSupport = false;
37// 设备状态,用于描述当前状态是否允许启用该特性(例如折叠机展开态允许,折叠态不允许)37// 设备状态,用于描述当前状态是否允许启用该特性(例如折叠机展开态允许,折叠态不允许)
38static XEG_ControlDisplaySeparationStatus status = XEG_ControlDisplaySeparationStatus::UNAVAILABLE;38static XEG_ControlDisplaySeparationStatus status = XEG_ControlDisplaySeparationStatus::UNAVAILABLE;
39-// 用户配置开关,用于描述用户或者游戏本身是否打开该特性(目前默认打开,实际使用根据用户)39+// 用户配置开关,用于描述用户或者游戏本身是否打开该特性(目前默认关闭)
40static bool isFeatureOn = false;40static bool isFeatureOn = false;
41// 特性使能开关,用于描述当前场景是否使能控显分离(例如:游戏大厅场景不使能,游戏对局内使能)41// 特性使能开关,用于描述当前场景是否使能控显分离(例如:游戏大厅场景不使能,游戏对局内使能)
42static bool isActive = false;42static bool isActive = false;
@@ -69,9 +69,14 @@ void EGLCore::ExampleInit(int width, int height)
69 return;69 return;
70 }70 }
71 LOGI("EGLCore start init model3dsponza");71 LOGI("EGLCore start init model3dsponza");
72+ if (m_model3dSponza != nullptr) {
73+ return;
74+ }
72 m_model3dSponza = new Model3DSponza();75 m_model3dSponza = new Model3DSponza();
73 if (!m_model3dSponza->Init(width, height)) {76 if (!m_model3dSponza->Init(width, height)) {
74 m_exampleInited = false;77 m_exampleInited = false;
78+ delete m_model3dSponza;
79+ m_model3dSponza = nullptr;
75 return;80 return;
76 }81 }
77 m_exampleInited = true;82 m_exampleInited = true;
@@ -103,6 +108,7 @@ void EGLCore::Release()
103{108{
104 if (m_model3dSponza) {109 if (m_model3dSponza) {
105 delete m_model3dSponza;110 delete m_model3dSponza;
111+ m_model3dSponza = nullptr;
106 }112 }
107 LOGI("EGLCore release");113 LOGI("EGLCore release");
108 if ((nullptr == m_eglDisplay) || (nullptr == m_eglSurface) || (!eglDestroySurface(m_eglDisplay, m_eglSurface))) {114 if ((nullptr == m_eglDisplay) || (nullptr == m_eglSurface) || (!eglDestroySurface(m_eglDisplay, m_eglSurface))) {
@@ -44,8 +44,8 @@ private:
44 EGLSurface m_eglSurface = EGL_NO_SURFACE;44 EGLSurface m_eglSurface = EGL_NO_SURFACE;
45 EGLContext m_eglContext = EGL_NO_CONTEXT;45 EGLContext m_eglContext = EGL_NO_CONTEXT;
46 int m_width, m_height;46 int m_width, m_height;
47- void* m_window;47+ void* m_window = nullptr;
48- Model3DSponza* m_model3dSponza;48+ Model3DSponza* m_model3dSponza = nullptr;
49 bool m_exampleInited = false;49 bool m_exampleInited = false;
50 bool m_eglInited = false;50 bool m_eglInited = false;
51};51};
@@ -112,7 +112,7 @@ bool Model3DSponza::CheckXEngine()
112 // [EndExclude CheckXengine_ai_temporal]112 // [EndExclude CheckXengine_ai_temporal]
113 113
114 // 查询是否支持时域AI超分114 // 查询是否支持时域AI超分
115- if (std::find(extensions.begin(), extensions.end(), XEG_TEMPORAL_UPSCALE_EXTENSION_NAME) != extensions.end()) {115+ if (std::find(extensions.begin(), extensions.end(), XEG_TEMPORAL_UPSCALE_EXTENSION_NAME) != extensions.end()) {
116 // 正常业务逻辑116 // 正常业务逻辑
117 // [StartExclude CheckXengine_ai_temporal]117 // [StartExclude CheckXengine_ai_temporal]
118 isSupportTemporal = true;118 isSupportTemporal = true;
@@ -120,14 +120,14 @@ bool Model3DSponza::CheckXEngine()
120 } else {120 } else {
121 // 错误处理121 // 错误处理
122 // [StartExclude CheckXengine_ai_temporal]122 // [StartExclude CheckXengine_ai_temporal]
123- isSupportTemporal = false;123+ isSupportTemporal = false;
124 LOGE("Model3DSponza demo not support temporal upscale.");124 LOGE("Model3DSponza demo not support temporal upscale.");
125- // [EndExclude CheckXengine_ai_temporal] 125+ // [EndExclude CheckXengine_ai_temporal]
126 }126 }
127 // [End CheckXengine_ai_temporal]127 // [End CheckXengine_ai_temporal]
128 // [EndExclude CheckXengine_gpu_spatial]128 // [EndExclude CheckXengine_gpu_spatial]
129 // 查询是否支持空域GPU超分129 // 查询是否支持空域GPU超分
130- if (std::find(extensions.begin(), extensions.end(), XEG_SPATIAL_UPSCALE_EXTENSION_NAME) != extensions.end()) {130+ if (std::find(extensions.begin(), extensions.end(), XEG_SPATIAL_UPSCALE_EXTENSION_NAME) != extensions.end()) {
131 // 正常业务逻辑131 // 正常业务逻辑
132 // [StartExclude CheckXengine_gpu_spatial]132 // [StartExclude CheckXengine_gpu_spatial]
133 isSupportSpatial = true;133 isSupportSpatial = true;
@@ -136,28 +136,28 @@ bool Model3DSponza::CheckXEngine()
136 // 错误处理136 // 错误处理
137 // [StartExclude CheckXengine_gpu_spatial]137 // [StartExclude CheckXengine_gpu_spatial]
138 isSupportSpatial = false;138 isSupportSpatial = false;
139- LOGE("Model3DSponza demo not support spatial upscale."); 139+ LOGE("Model3DSponza demo not support spatial upscale.");
140 // [EndExclude CheckXengine_gpu_spatial]140 // [EndExclude CheckXengine_gpu_spatial]
141 }141 }
142 // [End CheckXengine_gpu_spatial]142 // [End CheckXengine_gpu_spatial]
143 // [EndExclude CheckXengine_VRS]143 // [EndExclude CheckXengine_VRS]
144 // 查询是否支持自适应VRS144 // 查询是否支持自适应VRS
145- if (std::find(extensions.begin(), extensions.end(), XEG_ADAPTIVE_VRS_EXTENSION_NAME) != extensions.end()) {145+ if (std::find(extensions.begin(), extensions.end(), XEG_ADAPTIVE_VRS_EXTENSION_NAME) != extensions.end()) {
146 // 正常业务逻辑146 // 正常业务逻辑
147 // [StartExclude CheckXengine_VRS]147 // [StartExclude CheckXengine_VRS]
148- isSupportVrs = true;148+ isSupportVrs = true;
149 // [EndExclude CheckXengine_VRS]149 // [EndExclude CheckXengine_VRS]
150 } else {150 } else {
151 // 错误处理151 // 错误处理
152 // [StartExclude CheckXengine_VRS]152 // [StartExclude CheckXengine_VRS]
153- isSupportVrs = false;153+ isSupportVrs = false;
154- LOGE("Model3DSponza demo not support VRS."); 154+ LOGE("Model3DSponza demo not support VRS.");
155 // [EndExclude CheckXengine_VRS]155 // [EndExclude CheckXengine_VRS]
156 }156 }
157 // [End CheckXengine_VRS]157 // [End CheckXengine_VRS]
158 // [EndExclude CheckXengine_ai_spatial]158 // [EndExclude CheckXengine_ai_spatial]
159 // 查询是否支持空域AI超分159 // 查询是否支持空域AI超分
160- if (std::find(extensions.begin(), extensions.end(), XEG_NEURAL_UPSCALE_EXTENSION_NAME) != extensions.end()) {160+ if (std::find(extensions.begin(), extensions.end(), XEG_NEURAL_UPSCALE_EXTENSION_NAME) != extensions.end()) {
161 // 正常业务逻辑161 // 正常业务逻辑
162 // [StartExclude CheckXengine_ai_spatial]162 // [StartExclude CheckXengine_ai_spatial]
163 isSupportNeural = true;163 isSupportNeural = true;
@@ -165,13 +165,13 @@ bool Model3DSponza::CheckXEngine()
165 } else {165 } else {
166 // 错误处理166 // 错误处理
167 // [StartExclude CheckXengine_ai_spatial]167 // [StartExclude CheckXengine_ai_spatial]
168- isSupportNeural = false;168+ isSupportNeural = false;
169- LOGE("Model3DSponza demo not support neural upscale.");169+ LOGE("Model3DSponza demo not support neural upscale.");
170 // [EndExclude CheckXengine_ai_spatial]170 // [EndExclude CheckXengine_ai_spatial]
171 }171 }
172 172 
173 // 查询是否支持空域AI超分2173 // 查询是否支持空域AI超分2
174- if (std::find(extensions.begin(), extensions.end(), XEG_NEURAL_UPSCALE2_EXTENSION_NAME) != extensions.end()) {174+ if (std::find(extensions.begin(), extensions.end(), XEG_NEURAL_UPSCALE2_EXTENSION_NAME) != extensions.end()) {
175 // 正常业务逻辑175 // 正常业务逻辑
176 // [StartExclude CheckXengine_ai_spatial]176 // [StartExclude CheckXengine_ai_spatial]
177 isSupportNeural2 = true;177 isSupportNeural2 = true;
@@ -179,10 +179,10 @@ bool Model3DSponza::CheckXEngine()
179 } else {179 } else {
180 // 错误处理180 // 错误处理
181 // [StartExclude CheckXengine_ai_spatial]181 // [StartExclude CheckXengine_ai_spatial]
182- isSupportNeural2 = false;182+ isSupportNeural2 = false;
183- LOGE("Model3DSponza demo not support neural upscale 2."); 183+ LOGE("Model3DSponza demo not support neural upscale 2.");
184 // [EndExclude CheckXengine_ai_spatial]184 // [EndExclude CheckXengine_ai_spatial]
185- } 185+ }
186 // [End CheckXengine_ai_spatial]186 // [End CheckXengine_ai_spatial]
187 return true;187 return true;
188}188}
@@ -227,9 +227,9 @@ void Model3DSponza::DispatchVRS(bool isUpscale)
227 light = m_lightColorTexture;227 light = m_lightColorTexture;
228 } else if (m_upscalemode == 1) {228 } else if (m_upscalemode == 1) {
229 if (isSupportNeural) {229 if (isSupportNeural) {
230- light = m_lowLightNativeTexture;230+ light = m_lowLightNativeTexture;
231- } else {231+ } else {
232- light = m_lowLightColorTexture;232+ light = m_lowLightColorTexture;
233 }233 }
234 } else {234 } else {
235 light = m_lowLightColorTexture;235 light = m_lowLightColorTexture;
@@ -375,9 +375,9 @@ void Model3DSponza::InitTemporalUpscale()
375 }375 }
376 // [Start InitTemporalUpscale_gles]376 // [Start InitTemporalUpscale_gles]
377 // m_lowResWidth与m_lowResHeight分别为用户自定义的渲染宽度与渲染高度377 // m_lowResWidth与m_lowResHeight分别为用户自定义的渲染宽度与渲染高度
378- GLsizei inputeSize[2] = {static_cast<GLsizei>(m_lowResWidth), static_cast<GLsizei>(m_lowResHeight)};378+ GLuint inputSize[2] = {static_cast<GLuint>(m_lowResWidth), static_cast<GLuint>(m_lowResHeight)};
379 // 设置超分输入纹理的真实宽高379 // 设置超分输入纹理的真实宽高
380- HMS_XEG_TemporalUpscaleParameter(XEG_TEMPORAL_UPSCALE_INPUT_SIZE, inputeSize);380+ HMS_XEG_TemporalUpscaleParameter(XEG_TEMPORAL_UPSCALE_INPUT_SIZE, inputSize);
381 // 设置相机抖动的周期数,此处以8为例381 // 设置相机抖动的周期数,此处以8为例
382 GLuint jitterNum = 8;382 GLuint jitterNum = 8;
383 HMS_XEG_TemporalUpscaleParameter(XEG_TEMPORAL_UPSCALE_JITTER_NUM, &jitterNum);383 HMS_XEG_TemporalUpscaleParameter(XEG_TEMPORAL_UPSCALE_JITTER_NUM, &jitterNum);
@@ -423,7 +423,7 @@ void Model3DSponza::DispatchTemporalUpscale()
423 423 
424void Model3DSponza::InitDraw(int screenW, int screenH)424void Model3DSponza::InitDraw(int screenW, int screenH)
425{425{
426- if (m_screenWidth != screenW && m_screenHeight != screenH) {426+ if (m_screenWidth != screenW || m_screenHeight != screenH) {
427 m_initialized = false;427 m_initialized = false;
428 }428 }
429 429
@@ -441,6 +441,7 @@ void Model3DSponza::InitDraw(int screenW, int screenH)
441 m_highResHeight = m_screenHeight * m_highScale;441 m_highResHeight = m_screenHeight * m_highScale;
442 442 
443 if (!m_initialized) {443 if (!m_initialized) {
444+ DeleteFrameAndTexture();
444 InitVerticesBuffer();445 InitVerticesBuffer();
445 InitFrameBuffer();446 InitFrameBuffer();
446 InitVRS(m_upscalemode != 0);447 InitVRS(m_upscalemode != 0);
@@ -657,8 +658,8 @@ unsigned int Model3DSponza::CreateFramebufferTexture(unsigned int width, unsigne
657 // [StartExclude OH_NativeBuffer_ai_spatial_gles]658 // [StartExclude OH_NativeBuffer_ai_spatial_gles]
658 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);659 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
659 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);660 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
660- // [EndExclude OH_NativeBuffer_ai_spatial_gles] 661+ // [EndExclude OH_NativeBuffer_ai_spatial_gles]
661- // isNativeBuffer表示输入纹理需要关联OH_NativeBuffer662+ // isNativeBuffer为true表示纹理需要关联OH_NativeBuffer,为false表示纹理不需要关联OH_NativeBuffer
662 if (isNativeBuffer) {663 if (isNativeBuffer) {
663 // 当支持XEG_NEURAL_UPSCALE_EXTENSION_NAME时,输入纹理关联一个OH_NativeBuffer664 // 当支持XEG_NEURAL_UPSCALE_EXTENSION_NAME时,输入纹理关联一个OH_NativeBuffer
664 // 创建OH_NativeBuffer665 // 创建OH_NativeBuffer
@@ -698,6 +699,9 @@ unsigned int Model3DSponza::CreateFramebufferTexture(unsigned int width, unsigne
698 glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, m_eglImage);699 glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, m_eglImage);
699 } else {700 } else {
700 // 当支持XEG_NEURAL_UPSCALE2_EXTENSION_NAME时,输入纹理不需要关联OH_NativeBuffer701 // 当支持XEG_NEURAL_UPSCALE2_EXTENSION_NAME时,输入纹理不需要关联OH_NativeBuffer
702+ // internalformat为GLint类型,指定纹理中的颜色分量数量,如GL_RGBA。
703+ // format为GLenum类型,指定像素数据的格式,如GL_RED。
704+ // type为GLenum类型,指定像素数据的数据类型,如GL_BYTE。
701 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, width, height, 0, format, type, NULL);705 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, width, height, 0, format, type, NULL);
702 }706 }
703 // [End OH_NativeBuffer_ai_spatial_gles]707 // [End OH_NativeBuffer_ai_spatial_gles]
@@ -725,11 +729,8 @@ void Model3DSponza::InitGBufferFrameBuffer()
725 CreateFramebufferTexture(m_highResWidth, m_highResHeight, GL_RGBA16F, GL_RGBA, GL_COLOR_ATTACHMENT1, GL_FLOAT);729 CreateFramebufferTexture(m_highResWidth, m_highResHeight, GL_RGBA16F, GL_RGBA, GL_COLOR_ATTACHMENT1, GL_FLOAT);
726 m_gAlbedo =730 m_gAlbedo =
727 CreateFramebufferTexture(m_highResWidth, m_highResHeight, GL_RGBA16F, GL_RGBA, GL_COLOR_ATTACHMENT2, GL_FLOAT);731 CreateFramebufferTexture(m_highResWidth, m_highResHeight, GL_RGBA16F, GL_RGBA, GL_COLOR_ATTACHMENT2, GL_FLOAT);
728- m_gNormalView =732+ unsigned int attachmentsLight[3] = {GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2};
729- CreateFramebufferTexture(m_highResWidth, m_highResHeight, GL_RGBA16F, GL_RGBA, GL_COLOR_ATTACHMENT3, GL_FLOAT);733+ glDrawBuffers(3, attachmentsLight);
730- unsigned int attachmentsLight[4] = {GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2,
731- GL_COLOR_ATTACHMENT3};
732- glDrawBuffers(4, attachmentsLight);
733 m_rboDepth = CreateFramebufferTexture(m_highResWidth, m_highResHeight, GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT,734 m_rboDepth = CreateFramebufferTexture(m_highResWidth, m_highResHeight, GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT,
734 GL_DEPTH_ATTACHMENT, GL_UNSIGNED_SHORT);735 GL_DEPTH_ATTACHMENT, GL_UNSIGNED_SHORT);
735 CheckFrameBuffer("GBufferHighResolution");736 CheckFrameBuffer("GBufferHighResolution");
@@ -741,9 +742,7 @@ void Model3DSponza::InitGBufferFrameBuffer()
741 CreateFramebufferTexture(m_lowResWidth, m_lowResHeight, GL_RGBA16F, GL_RGBA, GL_COLOR_ATTACHMENT1, GL_FLOAT);742 CreateFramebufferTexture(m_lowResWidth, m_lowResHeight, GL_RGBA16F, GL_RGBA, GL_COLOR_ATTACHMENT1, GL_FLOAT);
742 m_lowGAlbedo =743 m_lowGAlbedo =
743 CreateFramebufferTexture(m_lowResWidth, m_lowResHeight, GL_RGBA16F, GL_RGBA, GL_COLOR_ATTACHMENT2, GL_FLOAT);744 CreateFramebufferTexture(m_lowResWidth, m_lowResHeight, GL_RGBA16F, GL_RGBA, GL_COLOR_ATTACHMENT2, GL_FLOAT);
744- m_gNormalView =745+ glDrawBuffers(3, attachmentsLight);
745- CreateFramebufferTexture(m_lowResWidth, m_lowResHeight, GL_RGBA16F, GL_RGBA, GL_COLOR_ATTACHMENT3, GL_FLOAT);
746- glDrawBuffers(4, attachmentsLight);
747 m_lowGboDepth = CreateFramebufferTexture(m_lowResWidth, m_lowResHeight, GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT,746 m_lowGboDepth = CreateFramebufferTexture(m_lowResWidth, m_lowResHeight, GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT,
748 GL_DEPTH_ATTACHMENT, GL_FLOAT);747 GL_DEPTH_ATTACHMENT, GL_FLOAT);
749 CheckFrameBuffer("GBufferLowResolution");748 CheckFrameBuffer("GBufferLowResolution");
@@ -804,9 +803,9 @@ void Model3DSponza::InitFrameBuffer()
804 HMS_XEG_NeuralUpscaleParameter(XEG_NEURAL_UPSCALE_SCISSOR, upscaleScissor);803 HMS_XEG_NeuralUpscaleParameter(XEG_NEURAL_UPSCALE_SCISSOR, upscaleScissor);
805 // 设置超分输入纹理对应的OH_NativeBuffer句柄804 // 设置超分输入纹理对应的OH_NativeBuffer句柄
806 // isSupportNeural表示是否支持XEG_NEURAL_UPSCALE_EXTENSION_NAME805 // isSupportNeural表示是否支持XEG_NEURAL_UPSCALE_EXTENSION_NAME
807- if (isSupportNeural) {806+ if (isSupportNeural) {
808- HMS_XEG_NeuralUpscaleParameter(XEG_NEURAL_UPSCALE_INPUT_HANDLE, m_lightNativeBufferHandle);807+ HMS_XEG_NeuralUpscaleParameter(XEG_NEURAL_UPSCALE_INPUT_HANDLE, m_lightNativeBufferHandle);
809- }808+ }
810 // [End HMS_XEG_NeuralUpscaleParameter_gles]809 // [End HMS_XEG_NeuralUpscaleParameter_gles]
811 // Init VRS ShadingRateImage810 // Init VRS ShadingRateImage
812 // high resolution sir811 // high resolution sir
@@ -854,14 +853,17 @@ void Model3DSponza::Destroy()
854 // 当支持XEG_NEURAL_UPSCALE_EXTENSION_NAME时,销毁相关资源853 // 当支持XEG_NEURAL_UPSCALE_EXTENSION_NAME时,销毁相关资源
855 if (m_eglImage != nullptr) {854 if (m_eglImage != nullptr) {
856 eglDestroyImageKHR(eglGetCurrentDisplay(), m_eglImage);855 eglDestroyImageKHR(eglGetCurrentDisplay(), m_eglImage);
856+ m_eglImage = nullptr;
857 }857 }
858 858 
859 if (m_nativeWindowBuffer != nullptr) {859 if (m_nativeWindowBuffer != nullptr) {
860 OH_NativeWindow_DestroyNativeWindowBuffer(m_nativeWindowBuffer);860 OH_NativeWindow_DestroyNativeWindowBuffer(m_nativeWindowBuffer);
861+ m_nativeWindowBuffer = nullptr;
861 }862 }
862 863 
863 if (m_lightNativeBufferHandle != nullptr) {864 if (m_lightNativeBufferHandle != nullptr) {
864 OH_NativeBuffer_Unreference(m_lightNativeBufferHandle);865 OH_NativeBuffer_Unreference(m_lightNativeBufferHandle);
866+ m_lightNativeBufferHandle = nullptr;
865 }867 }
866 // [StartExclude Destory_ai_spatial_gles]868 // [StartExclude Destory_ai_spatial_gles]
867 869 
@@ -871,25 +873,48 @@ void Model3DSponza::Destroy()
871 m_pModel = nullptr;873 m_pModel = nullptr;
872 }874 }
873 875 
876+ DestroyShader();
877+
878+ DeleteFrameAndTexture();
879+}
880+ 
881+void Model3DSponza::DestroyShader()
882+{
874 if (m_shaderGBufferLight != nullptr) {883 if (m_shaderGBufferLight != nullptr) {
875 m_shaderGBufferLight->Destroy();884 m_shaderGBufferLight->Destroy();
876 delete m_shaderGBufferLight;885 delete m_shaderGBufferLight;
877 m_shaderGBufferLight = nullptr;886 m_shaderGBufferLight = nullptr;
878 }887 }
879- 888+
880 if (m_shaderLight != nullptr) {889 if (m_shaderLight != nullptr) {
881 m_shaderLight->Destroy();890 m_shaderLight->Destroy();
882 delete m_shaderLight;891 delete m_shaderLight;
883 m_shaderLight = nullptr;892 m_shaderLight = nullptr;
884 }893 }
885- 894+
886 if (m_shaderWindow != nullptr) {895 if (m_shaderWindow != nullptr) {
887 m_shaderWindow->Destroy();896 m_shaderWindow->Destroy();
888 delete m_shaderWindow;897 delete m_shaderWindow;
889 m_shaderWindow = nullptr;898 m_shaderWindow = nullptr;
890 }899 }
891- 900+
892- DeleteFrameAndTexture();901+ if (m_shaderFSREASU != nullptr) {
902+ m_shaderFSREASU->Destroy();
903+ delete m_shaderFSREASU;
904+ m_shaderFSREASU = nullptr;
905+ }
906+
907+ if (m_shaderFSRRCAS != nullptr) {
908+ m_shaderFSRRCAS->Destroy();
909+ delete m_shaderFSRRCAS;
910+ m_shaderFSRRCAS = nullptr;
911+ }
912+
913+ if (m_shaderMotionVector != nullptr) {
914+ m_shaderMotionVector->Destroy();
915+ delete m_shaderMotionVector;
916+ m_shaderMotionVector = nullptr;
917+ }
893}918}
894 919 
895void Model3DSponza::DeleteFrameAndTexture()920void Model3DSponza::DeleteFrameAndTexture()
@@ -903,10 +928,10 @@ void Model3DSponza::DeleteFrameAndTexture()
903 glDeleteFramebuffers(1, &m_lowNativeLightFBO);928 glDeleteFramebuffers(1, &m_lowNativeLightFBO);
904 glDeleteFramebuffers(1, &m_upscaleFBO);929 glDeleteFramebuffers(1, &m_upscaleFBO);
905 glDeleteFramebuffers(1, &m_fsrEASUFBO);930 glDeleteFramebuffers(1, &m_fsrEASUFBO);
931+ glDeleteFramebuffers(1, &m_motionVectorFBO);
906 932 
907 glDeleteTextures(1, &m_gPosition);933 glDeleteTextures(1, &m_gPosition);
908 glDeleteTextures(1, &m_gNormal);934 glDeleteTextures(1, &m_gNormal);
909- glDeleteTextures(1, &m_gNormalView);
910 glDeleteTextures(1, &m_gAlbedo);935 glDeleteTextures(1, &m_gAlbedo);
911 936 
912 glDeleteTextures(1, &m_lowGPosition);937 glDeleteTextures(1, &m_lowGPosition);
@@ -924,9 +949,11 @@ void Model3DSponza::DeleteFrameAndTexture()
924 949 
925 glDeleteTextures(1, &m_upscaleColorTexture);950 glDeleteTextures(1, &m_upscaleColorTexture);
926 glDeleteTextures(1, &m_fsrEASUColorTexture);951 glDeleteTextures(1, &m_fsrEASUColorTexture);
952+ glDeleteTextures(1, &m_motionVectorTexture);
953+ glDeleteTextures(1, &m_dynamicMaskTexture);
927 glDeleteTextures(1, &m_shadingRateImageTexture);954 glDeleteTextures(1, &m_shadingRateImageTexture);
928 glDeleteTextures(1, &m_lowShadingRateImageTexture);955 glDeleteTextures(1, &m_lowShadingRateImageTexture);
929 956 
930- glDeleteRenderbuffers(1, &m_rboDepth);957+ glDeleteTextures(1, &m_rboDepth);
931- glDeleteRenderbuffers(1, &m_lowGboDepth);958+ glDeleteTextures(1, &m_lowGboDepth);
932}959}
@@ -64,6 +64,7 @@ public:
64 bool Init(int screenW, int screenH);64 bool Init(int screenW, int screenH);
65 void Draw(int screenW, int screenH);65 void Draw(int screenW, int screenH);
66 void Destroy();66 void Destroy();
67+ void DestroyShader();
67 void SetUpscaleMode(int mode)68 void SetUpscaleMode(int mode)
68 {69 {
69 LOGD("Model3DSponza curr set upscale mode is %{public}d", mode);70 LOGD("Model3DSponza curr set upscale mode is %{public}d", mode);
@@ -199,7 +200,7 @@ private:
199 bool isSupportSpatial = true;200 bool isSupportSpatial = true;
200 bool isSupportVrs = true;201 bool isSupportVrs = true;
201 bool isSupportNeural = true;202 bool isSupportNeural = true;
202- bool isSupportNeural2 = false;203+ bool isSupportNeural2 = false;
203 bool isSupportTemporal = true;204 bool isSupportTemporal = true;
204 int m_currmode = 0;205 int m_currmode = 0;
205 int m_upscalemode = 0;206 int m_upscalemode = 0;
@@ -241,13 +241,19 @@ void PluginRender::Release(std::string& id)
241{241{
242 PluginRender* render = PluginRender::GetInstance(id);242 PluginRender* render = PluginRender::GetInstance(id);
243 if (render != nullptr) {243 if (render != nullptr) {
244- std::unique_lock<std::mutex> locker(m_mutex);244+ {
245- m_stop = true;245+ std::unique_lock<std::mutex> locker(m_mutex);
246- m_con.wait(locker);246+ m_stop = true;
247- m_instance.erase(m_instance.find(id));247+ m_con.wait(locker);
248- if (render->m_eglCore != nullptr) {248+ }
249+ if (render->m_renderThread.joinable()) {
250+ render->m_renderThread.join();
251+ }
252+ if (nullptr != render->m_eglCore) {
249 delete render->m_eglCore;253 delete render->m_eglCore;
250 render->m_eglCore = nullptr;254 render->m_eglCore = nullptr;
251 }255 }
256+ m_instance.erase(id);
257+ delete render;
252 }258 }
253}259}
@@ -1006,6 +1006,11 @@ bool DDGI::OnRender()
1006 1006 
1007void DDGI::OnDestroy()1007void DDGI::OnDestroy()
1008{1008{
1009+ // [Start HMS_XEG_DestroyRTGI_DDGI]
1010+ if (xegRTGI != nullptr) {
1011+ HMS_XEG_DestroyRTGI(xegRTGI);
1012+ }
1013+ // [End HMS_XEG_DestroyRTGI_DDGI]
1009}1014}
1010 1015 
1011DDGI::~DDGI()1016DDGI::~DDGI()
@@ -334,7 +334,6 @@ void VulkanExample::PrepareVisibleMaskStage()
334 // [StartExclude PrepareVisibleMaskStage_rt_vulkan]334 // [StartExclude PrepareVisibleMaskStage_rt_vulkan]
335 LOGI("create xeg SHADOW AO :(%d,%d) mode = %d", visibleMaskWidth, visibleMaskHeight, 1);335 LOGI("create xeg SHADOW AO :(%d,%d) mode = %d", visibleMaskWidth, visibleMaskHeight, 1);
336 // [EndExclude PrepareVisibleMaskStage_rt_vulkan]336 // [EndExclude PrepareVisibleMaskStage_rt_vulkan]
337- auto start = std::chrono::high_resolution_clock::now();
338 // device为当前应用程序的Vulkan设备对象,需用户进行初始化337 // device为当前应用程序的Vulkan设备对象,需用户进行初始化
339 VkResult ret = HMS_XEG_CreateRTVisibleMask(device, &createInfo, &rtVisibleMaskQuality);338 VkResult ret = HMS_XEG_CreateRTVisibleMask(device, &createInfo, &rtVisibleMaskQuality);
340 if (ret != VK_SUCCESS) {339 if (ret != VK_SUCCESS) {
@@ -589,7 +588,7 @@ void VulkanExample::PrepareReflectionStage()
589{588{
590 auto start = std::chrono::high_resolution_clock::now();589 auto start = std::chrono::high_resolution_clock::now();
591 // [Start HMS_XEG_CreateRTReflection_rt_vulkan]590 // [Start HMS_XEG_CreateRTReflection_rt_vulkan]
592- // XEG_RTReflectionCreateInfo为创建xegRTReflection对象信息591+ // XEG_RTReflectionCreateInfo为创建rtReflection对象信息
593 XEG_RTReflectionCreateInfo xegRTReflectionCreateInfo;592 XEG_RTReflectionCreateInfo xegRTReflectionCreateInfo;
594 // 指定是否开启快速求交模式。1表示开启快速求交模式593 // 指定是否开启快速求交模式。1表示开启快速求交模式
595 xegRTReflectionCreateInfo.enableFastTrace = 1;594 xegRTReflectionCreateInfo.enableFastTrace = 1;
@@ -17,7 +17,10 @@
17#include "nngi_config.h"17#include "nngi_config.h"
18#include "file/file_operator.h"18#include "file/file_operator.h"
19#include "render/framework/vulkan_utils.h"19#include "render/framework/vulkan_utils.h"
20+// [Start xeg_vulkan_rtgi_h]
20#include "xengine/xeg_vulkan_extension.h"21#include "xengine/xeg_vulkan_extension.h"
22+#include "xengine/xeg_vulkan_rtgi.h"
23+// [End xeg_vulkan_rtgi_h]
21#include "nngi_render.h"24#include "nngi_render.h"
22 25 
23VulkanExample::VulkanExample() : VulkanRaytracingSample(), cameraManager(camera)26VulkanExample::VulkanExample() : VulkanRaytracingSample(), cameraManager(camera)
@@ -132,7 +135,7 @@ void VulkanExample::CreateNNGI()
132 // 指定扩展为空135 // 指定扩展为空
133 xegNngiCreateInfo.pNext = nullptr;136 xegNngiCreateInfo.pNext = nullptr;
134 // 指定质量模式为质量137 // 指定质量模式为质量
135- xegNngiCreateInfo.qualityMode = XEG_RTGIQualityMode::XEG_RTGI_QUALITY_MODE_QUALITY;138+ xegNngiCreateInfo.qualityMode = XEG_RTGI_QUALITY_MODE_QUALITY;
136 // NNGI_RENDER_WIDTH, NNGI_RENDER_HEIGHT分别表示指定推理输入图像的分辨率宽高139 // NNGI_RENDER_WIDTH, NNGI_RENDER_HEIGHT分别表示指定推理输入图像的分辨率宽高
137 xegNngiCreateInfo.inferenceInputSize = {NNGI_RENDER_WIDTH, NNGI_RENDER_HEIGHT};140 xegNngiCreateInfo.inferenceInputSize = {NNGI_RENDER_WIDTH, NNGI_RENDER_HEIGHT};
138 // NNGI_IL_WIDTH, NNGI_IL_HEIGHT分别表示指定推理输出图像的分辨率宽高141 // NNGI_IL_WIDTH, NNGI_IL_HEIGHT分别表示指定推理输出图像的分辨率宽高
@@ -550,8 +553,6 @@ void VulkanExample::AssemblyNNGIRenderInfo()
550 // xegNNGIDescription.sceneAabb表示用户创建的渲染包围盒范围VkAabbPositionsKHR553 // xegNNGIDescription.sceneAabb表示用户创建的渲染包围盒范围VkAabbPositionsKHR
551 xegNNGIDescription.sceneAabb = {sceneAabbMin.x, sceneAabbMin.y, sceneAabbMin.z,554 xegNNGIDescription.sceneAabb = {sceneAabbMin.x, sceneAabbMin.y, sceneAabbMin.z,
552 sceneAabbMax.x, sceneAabbMax.y, sceneAabbMax.z};555 sceneAabbMax.x, sceneAabbMax.y, sceneAabbMax.z};
553- // xegNNGIDescription.spatialScaleFactor表示场景缩放因子,对于有界场景,无需设置,XEngine根据sceneAabb计算该值
554- xegNNGIDescription.spatialScaleFactor = 1.0f / glm::length(sceneAabbMax - sceneAabbMin);
555 // [StartExclude AssemblyNNGIRenderInfo_nngi_vulkan]556 // [StartExclude AssemblyNNGIRenderInfo_nngi_vulkan]
556}557}
557 558
@@ -26,7 +26,6 @@
26#include "component/deferred_gbuffer.h"26#include "component/deferred_gbuffer.h"
27#include "component/fullscreen_pass.h"27#include "component/fullscreen_pass.h"
28#include "VulkanRaytracingSample.h"28#include "VulkanRaytracingSample.h"
29-#include "xengine/xeg_vulkan_rtgi.h"
30 29 
31struct RenderSwapChainInfo {30struct RenderSwapChainInfo {
32 VkCommandBuffer cmdBuffer = VK_NULL_HANDLE;31 VkCommandBuffer cmdBuffer = VK_NULL_HANDLE;
@@ -96,7 +95,9 @@ private:
96 std::vector<VkCommandBuffer> gbufferCmdBuffers;95 std::vector<VkCommandBuffer> gbufferCmdBuffers;
97 96 
98 // NNGI Info97 // NNGI Info
98+ // [Start XEG_RTGI]
99 XEG_RTGI xegRtgi;99 XEG_RTGI xegRtgi;
100+ // [End XEG_RTGI]
100 XEG_NNGICreateInfo xegNNGICreateInfo;101 XEG_NNGICreateInfo xegNNGICreateInfo;
101 XEG_NNGIDescription xegNNGIDescription;102 XEG_NNGIDescription xegNNGIDescription;
102 FrameBufferAttachment outputIndirectGIImage; // When NNGI is turned on, use the RTGI Interface output103 FrameBufferAttachment outputIndirectGIImage; // When NNGI is turned on, use the RTGI Interface output
@@ -1642,8 +1642,8 @@ void VulkanExample::InitXegNeuralUpscale()
1642 createInfo.sType = XEG_STRUCTURE_TYPE_NEURAL_UPSCALE_CREATE_INFO;1642 createInfo.sType = XEG_STRUCTURE_TYPE_NEURAL_UPSCALE_CREATE_INFO;
1643 createInfo.pNext = nullptr;1643 createInfo.pNext = nullptr;
1644 createInfo.inputRegion = srcRect2D;1644 createInfo.inputRegion = srcRect2D;
1645- createInfo.inputSize = {lowResWidth, lowResHeight};1645+ createInfo.inputSize = VkExtent2D{lowResWidth, lowResHeight};
1646- createInfo.outputSize = {highResWidth, highResHeight};1646+ createInfo.outputSize = VkExtent2D{highResWidth, highResHeight};
1647 createInfo.outputRegion = dstRect2D;1647 createInfo.outputRegion = dstRect2D;
1648 createInfo.outputFormat = VK_FORMAT_R8G8B8A8_UNORM;1648 createInfo.outputFormat = VK_FORMAT_R8G8B8A8_UNORM;
1649 // device逻辑设备,用户需进行初始化1649 // device逻辑设备,用户需进行初始化
@@ -1696,10 +1696,13 @@ void VulkanExample::InitXEGVRS()
1696 // xegCreateInfo为自适应VRS实例句柄对象的参数信息1696 // xegCreateInfo为自适应VRS实例句柄对象的参数信息
1697 // xeg_adaptiveVRS为下发绘制着色率纹理命令所需参数信息1697 // xeg_adaptiveVRS为下发绘制着色率纹理命令所需参数信息
1698 VkResult res = HMS_XEG_CreateAdaptiveVRS(device, &xegCreateInfo, &xegAdaptiveVRS);1698 VkResult res = HMS_XEG_CreateAdaptiveVRS(device, &xegCreateInfo, &xegAdaptiveVRS);
1699- // [End adaptive_vrs_vulkan]
1700 if (res != VK_SUCCESS) {1699 if (res != VK_SUCCESS) {
1700+ // 错误处理
1701+ // [StartExclude adaptive_vrs_vulkan]
1701 LOGE("VulkanExample xegAdaptiveVRS create failed");1702 LOGE("VulkanExample xegAdaptiveVRS create failed");
1703+ // [EndExclude adaptive_vrs_vulkan]
1702 }1704 }
1705+ // [End adaptive_vrs_vulkan]
1703 1706 
1704 inputSize.width = lowResWidth;1707 inputSize.width = lowResWidth;
1705 inputSize.height = lowResHeight;1708 inputSize.height = lowResHeight;