From 079433f7fb3c18acb93f9ec482342a0d83281654 Mon Sep 17 00:00:00 2001
From: Nicolas Pope <nwpope@utu.fi>
Date: Sun, 30 Aug 2020 18:08:28 +0300
Subject: [PATCH] Fix some horizontal costs

---
 lib/libsgm/src/horizontal_path_aggregation.cu | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/lib/libsgm/src/horizontal_path_aggregation.cu b/lib/libsgm/src/horizontal_path_aggregation.cu
index acd53e114..11a94bc07 100644
--- a/lib/libsgm/src/horizontal_path_aggregation.cu
+++ b/lib/libsgm/src/horizontal_path_aggregation.cu
@@ -88,7 +88,7 @@ __global__ void aggregate_horizontal_path_kernel(
 	}else{
 		for(unsigned int i = 0; i < DP_BLOCKS_PER_THREAD; ++i){
 			for(unsigned int j = 0; j < DP_BLOCK_SIZE; ++j){
-				const int x = static_cast<int>(width - min_disp - (j + dp_offset));
+				const int x = static_cast<int>(width - (j + dp_offset)) - min_disp;
 				if(0 <= x && x < static_cast<int>(width)){
 					right_buffer[i][j] = __ldg(&right[i * feature_step + x]);
 				}else{
@@ -121,9 +121,9 @@ __global__ void aggregate_horizontal_path_kernel(
 #else
 					right_buffer[j][0] = __shfl_up(t, 1, SUBGROUP_SIZE);
 #endif
-					if(lane_id == 0){
+					if(lane_id == 0 && x >= min_disp + dp_offset){
 						right_buffer[j][0] =
-							__ldg(&right[j * feature_step + x - dp_offset]);
+							__ldg(&right[j * feature_step + x - min_disp - dp_offset]);
 					}
 				}else{
 					const feature_type t = right_buffer[j][0];
@@ -137,9 +137,9 @@ __global__ void aggregate_horizontal_path_kernel(
 					right_buffer[j][DP_BLOCK_SIZE - 1] = __shfl_down(t, 1, SUBGROUP_SIZE);
 #endif
 					if(lane_id + 1 == SUBGROUP_SIZE){
-						if(x >= dp_offset + DP_BLOCK_SIZE - 1){
+						if(x >= min_disp + dp_offset + DP_BLOCK_SIZE - 1){
 							right_buffer[j][DP_BLOCK_SIZE - 1] =
-								__ldg(&right[j * feature_step + x - (dp_offset + DP_BLOCK_SIZE - 1)]);
+								__ldg(&right[j * feature_step + x - min_disp - (dp_offset + DP_BLOCK_SIZE - 1)]);
 						}else{
 							right_buffer[j][DP_BLOCK_SIZE - 1] = 0;
 						}
-- 
GitLab