| … | … | @@ -606,6 +606,14 @@ public: |
| 606 | 606 | NVSDK_NGX_Handle *dlss_rr_handle = nullptr; |
| 607 | 607 | NVSDK_NGX_Handle *dlss_sr_handle = nullptr; |
| 608 | 608 | bool feature_created = false; |
| 609 | // DLSS-RR camera matrices. These MUST outlive the evaluate() call: the NGX |
| 610 | // helper hands them to NVSDK_NGX_Parameter_SetVoidPointer, which stores the |
| 611 | // POINTER rather than copying, and NGX dereferences it during evaluation -- |
| 612 | // including on later frames and on the SR path, which never sets them. Held |
| 613 | // as stack locals they dangled the moment evaluate() returned, which is what |
| 614 | // produced "WorldToScreenMatrix not invertible!" every frame. |
| 615 | float world_to_view_matrix[16] = {}; |
| 616 | float view_to_clip_matrix[16] = {}; |
| 609 | 617 | NVSDK_NGX_PerfQuality_Value perf_quality = NVSDK_NGX_PerfQuality_Value_Balanced; |
| 610 | 618 | uint32_t render_width = 0; |
| 611 | 619 | uint32_t render_height = 0; |
| … | … | @@ -1034,25 +1042,24 @@ void DLSSEffect::_upscale_internal(RDD::CommandBufferID cmdid, const DLSSContext |
| 1034 | 1042 | eval.pInSpecularHitDistance = &hit_dist_res; |
| 1035 | 1043 | } |
| 1036 | 1044 | |
| 1037 | | // View/projection matrices for DLSS-RR |
| 1045 | // View/projection matrices for DLSS-RR. Stored on the context, NOT on the |
| 1046 | // stack -- see the declaration: NGX keeps the pointer and reads it later. |
| 1038 | 1047 | Transform3D view_matrix = p_params.cam_transform.affine_inverse(); |
| 1039 | | Projection view_proj(view_matrix); |
| 1040 | | float world_to_view[16]; |
| 1041 | | float view_to_clip[16]; |
| 1048 | Projection world_to_view(view_matrix); |
| 1042 | 1049 | for (int i = 0; i < 4; i++) { |
| 1043 | | world_to_view[i * 4 + 0] = view_proj.columns[0][i]; |
| 1044 | | world_to_view[i * 4 + 1] = view_proj.columns[1][i]; |
| 1045 | | world_to_view[i * 4 + 2] = view_proj.columns[2][i]; |
| 1046 | | world_to_view[i * 4 + 3] = view_proj.columns[3][i]; |
| 1050 | ctx->world_to_view_matrix[i * 4 + 0] = world_to_view.columns[0][i]; |
| 1051 | ctx->world_to_view_matrix[i * 4 + 1] = world_to_view.columns[1][i]; |
| 1052 | ctx->world_to_view_matrix[i * 4 + 2] = world_to_view.columns[2][i]; |
| 1053 | ctx->world_to_view_matrix[i * 4 + 3] = world_to_view.columns[3][i]; |
| 1047 | 1054 | } |
| 1048 | 1055 | for (int i = 0; i < 4; i++) { |
| 1049 | | view_to_clip[i * 4 + 0] = p_params.cam_projection.columns[0][i]; |
| 1050 | | view_to_clip[i * 4 + 1] = p_params.cam_projection.columns[1][i]; |
| 1051 | | view_to_clip[i * 4 + 2] = p_params.cam_projection.columns[2][i]; |
| 1052 | | view_to_clip[i * 4 + 3] = p_params.cam_projection.columns[3][i]; |
| 1056 | ctx->view_to_clip_matrix[i * 4 + 0] = p_params.cam_projection.columns[0][i]; |
| 1057 | ctx->view_to_clip_matrix[i * 4 + 1] = p_params.cam_projection.columns[1][i]; |
| 1058 | ctx->view_to_clip_matrix[i * 4 + 2] = p_params.cam_projection.columns[2][i]; |
| 1059 | ctx->view_to_clip_matrix[i * 4 + 3] = p_params.cam_projection.columns[3][i]; |
| 1053 | 1060 | } |
| 1054 | | eval.pInWorldToViewMatrix = world_to_view; |
| 1055 | | eval.pInViewToClipMatrix = view_to_clip; |
| 1061 | eval.pInWorldToViewMatrix = ctx->world_to_view_matrix; |
| 1062 | eval.pInViewToClipMatrix = ctx->view_to_clip_matrix; |
| 1056 | 1063 | |
| 1057 | 1064 | NVSDK_NGX_Result result = NGX_VULKAN_EVALUATE_DLSSD_EXT(vk_cmd, ctx->dlss_rr_handle, g_ngx_params, &eval); |
| 1058 | 1065 | |