@@ -139,8 +139,8 @@ namespace sw
139139 Float w = v.w ;
140140 Float rhw = IfThenElse (w != 0 .0f , 1 .0f / w, Float (1 .0f ));
141141
142- X[i] = RoundInt (*Pointer<Float>(data + OFFSET (DrawData,X0x16 )) + v.x * rhw * *Pointer<Float>(data + OFFSET (DrawData,Wx16 )));
143- Y[i] = RoundInt (*Pointer<Float>(data + OFFSET (DrawData,Y0x16 )) + v.y * rhw * *Pointer<Float>(data + OFFSET (DrawData,Hx16 )));
142+ X[i] = RoundInt (*Pointer<Float>(data + OFFSET (DrawData,X0xF )) + v.x * rhw * *Pointer<Float>(data + OFFSET (DrawData,WxF )));
143+ Y[i] = RoundInt (*Pointer<Float>(data + OFFSET (DrawData,Y0xF )) + v.y * rhw * *Pointer<Float>(data + OFFSET (DrawData,HxF )));
144144
145145 i++;
146146 }
@@ -162,15 +162,19 @@ namespace sw
162162 }
163163 Until (i >= n)
164164
165+ constexpr int subPixB = vk::SUBPIXEL_PRECISION_BITS;
166+ constexpr int subPixM = vk::SUBPIXEL_PRECISION_MASK;
167+ constexpr float subPixF = vk::SUBPIXEL_PRECISION_FACTOR;
168+
165169 if (state.multiSample > 1 )
166170 {
167- yMin = (yMin + 0x0A ) >> 4 ;
168- yMax = (yMax + 0x14 ) >> 4 ;
171+ yMin = (yMin + Constants::yMinMultiSampleOffset ) >> subPixB ;
172+ yMax = (yMax + Constants::yMaxMultiSampleOffset ) >> subPixB ;
169173 }
170174 else
171175 {
172- yMin = (yMin + 0x0F ) >> 4 ;
173- yMax = (yMax + 0x0F ) >> 4 ;
176+ yMin = (yMin + subPixM ) >> subPixB ;
177+ yMax = (yMax + subPixM ) >> subPixB ;
174178 }
175179
176180 yMin = Max (yMin, *Pointer<Int>(data + OFFSET (DrawData,scissorY0)));
@@ -213,7 +217,7 @@ namespace sw
213217 {
214218 Int xMin = *Pointer<Int>(data + OFFSET (DrawData, scissorX0));
215219 Int xMax = *Pointer<Int>(data + OFFSET (DrawData, scissorX1));
216- Short x = Short (Clamp ((X[0 ] + 0xF ) >> 4 , xMin, xMax));
220+ Short x = Short (Clamp ((X[0 ] + subPixM ) >> subPixB , xMin, xMax));
217221
218222 For (Int y = yMin - 1 , y < yMax + 1 , y++)
219223 {
@@ -323,20 +327,20 @@ namespace sw
323327 Y2 = Y1 + X0 - X1;
324328 }
325329
326- Float dx = Float (X0) * (1 .0f / 16 . 0f );
327- Float dy = Float (Y0) * (1 .0f / 16 . 0f );
330+ Float dx = Float (X0) * (1 .0f / subPixF );
331+ Float dy = Float (Y0) * (1 .0f / subPixF );
328332
329333 X1 -= X0;
330334 Y1 -= Y0;
331335
332336 X2 -= X0;
333337 Y2 -= Y0;
334338
335- Float x1 = w1 * (1 .0f / 16 . 0f ) * Float (X1);
336- Float y1 = w1 * (1 .0f / 16 . 0f ) * Float (Y1);
339+ Float x1 = w1 * (1 .0f / subPixF ) * Float (X1);
340+ Float y1 = w1 * (1 .0f / subPixF ) * Float (Y1);
337341
338- Float x2 = w2 * (1 .0f / 16 . 0f ) * Float (X2);
339- Float y2 = w2 * (1 .0f / 16 . 0f ) * Float (Y2);
342+ Float x2 = w2 * (1 .0f / subPixF ) * Float (X2);
343+ Float y2 = w2 * (1 .0f / subPixF ) * Float (Y2);
340344
341345 Float a = x1 * y2 - x2 * y1;
342346
@@ -403,10 +407,10 @@ namespace sw
403407
404408 if (!point)
405409 {
406- Float x1 = Float (X1) * (1 .0f / 16 . 0f );
407- Float y1 = Float (Y1) * (1 .0f / 16 . 0f );
408- Float x2 = Float (X2) * (1 .0f / 16 . 0f );
409- Float y2 = Float (Y2) * (1 .0f / 16 . 0f );
410+ Float x1 = Float (X1) * (1 .0f / subPixF );
411+ Float y1 = Float (Y1) * (1 .0f / subPixF );
412+ Float x2 = Float (X2) * (1 .0f / subPixF );
413+ Float y2 = Float (Y2) * (1 .0f / subPixF );
410414
411415 Float D = *Pointer<Float>(data + OFFSET (DrawData,depthRange)) / (x1 * y2 - x2 * y1);
412416
@@ -509,8 +513,11 @@ namespace sw
509513 Int Y1 = IfThenElse (swap, Yb, Ya);
510514 Int Y2 = IfThenElse (swap, Ya, Yb);
511515
512- Int y1 = Max ((Y1 + 0x0000000F ) >> 4 , *Pointer<Int>(data + OFFSET (DrawData,scissorY0)));
513- Int y2 = Min ((Y2 + 0x0000000F ) >> 4 , *Pointer<Int>(data + OFFSET (DrawData,scissorY1)));
516+ constexpr int subPixB = vk::SUBPIXEL_PRECISION_BITS;
517+ constexpr int subPixM = vk::SUBPIXEL_PRECISION_MASK;
518+
519+ Int y1 = Max ((Y1 + subPixM) >> subPixB, *Pointer<Int>(data + OFFSET (DrawData,scissorY0)));
520+ Int y2 = Min ((Y2 + subPixM) >> subPixB, *Pointer<Int>(data + OFFSET (DrawData,scissorY1)));
514521
515522 If (y1 < y2)
516523 {
@@ -525,11 +532,11 @@ namespace sw
525532 Int DX12 = X2 - X1;
526533 Int DY12 = Y2 - Y1;
527534
528- Int FDX12 = DX12 << 4 ;
529- Int FDY12 = DY12 << 4 ;
535+ Int FDX12 = DX12 << subPixB ;
536+ Int FDY12 = DY12 << subPixB ;
530537
531- Int X = DX12 * ((y1 << 4 ) - Y1) + (X1 & 0x0000000F ) * DY12;
532- Int x = (X1 >> 4 ) + X / FDY12; // Edge
538+ Int X = DX12 * ((y1 << subPixB ) - Y1) + (X1 & subPixM ) * DY12;
539+ Int x = (X1 >> subPixB ) + X / FDY12; // Edge
533540 Int d = X % FDY12; // Error-term
534541 Int ceil = -d >> 31 ; // Ceiling division: remainder <= 0
535542 x -= ceil;
0 commit comments