/usr/share/psychtoolbox-3/PsychHardware/PsychGPURasterizerOffsets.m is in psychtoolbox-3-common 3.0.12.20160126.dfsg1-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 | function [rpfx, rpfy, rpix, rpiy, vix, viy, vfx, vfy] = PsychGPURasterizerOffsets(win, drivername)
% PsychGPURasterizerOffsets - Test GPU drivers for spatial misplacement of content.
%
% The function tests if the GPU places content where it is told
% to place it. It warns if this isn't the case and returns corrective
% offsets to compensate for the problem.
%
% Different postioning methods are tested and potentially different
% offsets are reported for the different methods.
%
% Input args:
% 'win' Window handle to open onscreen window.
% 'drivername' driver name string to prefix to output messages.
%
% Returns args: (x,y) offsets created by driver inaccuracy. You will need
% to apply the negation of these to correct for driver misplacement!
%
% (rpfx, rpfy) Corrective offsets for glRasterPos2f()
% (rpix, rpiy) Corrective offsets for glRasterPos2i()
% (vix, viy) Corrective offsets for glVertex2i()
% (vfx, vfy) Corrective offsets for glVertex2f()
global GL;
if isempty(GL);
InitializeMatlabOpenGL();
end
winfo = Screen('GetWindowInfo', win);
if bitand(winfo.ImagingMode, kPsychNeedFastBackingStore)
% Imaging pipeline: Read from drawBuffer. Important in case imaging
% pipeline applies geometric transformations, e.g., gpu panel
% fitting. Otherwise we'd get false positives in test below.
readbuffer = 'drawBuffer';
else
% Read from system backbuffer:
readbuffer = 'backBuffer';
end
% Test for off-by-one bugs in graphics drivers / GPU's and compute
% corrective offsets for our Bits++ T-Lock blitters...
% glRasterPos2f(): Used by Screen('PutImage') for output-positioning:
% Clear out top-left 20x20 rectangle of framebuffer:
Screen('FillRect', win, 0, [0 0 20 20]);
% Define drawposition via glRasterPos2f:
glRasterPos2f(2, 1);
% Draw RGB = [128, 0, 0] pixel to that location:
testpixel = uint8([128 0 0]);
glDrawPixels(1, 1, GL.RGB, GL.UNSIGNED_BYTE, testpixel);
% Sync the pipeline, so we know the backbuffer contains the result:
Screen('DrawingFinished', win, 0, 1);
% Read top-left 4x4 rectangle back, only the red channel:
testreadback = Screen('GetImage', win, [0 0 4 4], readbuffer, 0, 1);
% Must flip here, to clear the "drawingfinished" state from above:
Screen('Flip', win);
% Find location of red == 128 pixel:
pixposition = find(testreadback == 128);
if ~isempty(pixposition)
[pixy, pixx] = ind2sub(size(testreadback), pixposition);
% Map from Matlab indexing to OpenGL indexing: Only x is remapped,
% y-offset is consistent due to 1 offset inside our y-origin inside
% Screen:
pixx = pixx - 1;
else
pixy = -1;
pixx = -1;
end
rpfx = pixx - 2;
rpfy = pixy - 1;
% At expected location?
if rpfx~=0
fprintf('%s:GPU-Rasterizertest: Warning: glRasterPos2f() command draws at wrong position (Offset %i, %i)!\n', drivername, rpfx, rpfy);
end
% glRasterPos2i(): Used by our DIO T-Lock blitter for output-positioning:
% Clear out top-left 20x20 rectangle of framebuffer:
Screen('FillRect', win, 0, [0 0 20 20]);
% Define drawposition via glRasterPos2i:
glRasterPos2i(2, 1);
% Draw RGB = [128, 0, 0] pixel to that location:
testpixel = uint8([128 0 0]);
glDrawPixels(1, 1, GL.RGB, GL.UNSIGNED_BYTE, testpixel);
% Sync the pipeline, so we know the backbuffer contains the result:
Screen('DrawingFinished', win, 0, 1);
% Read top-left 4x4 rectangle back, only the red channel:
testreadback = Screen('GetImage', win, [0 0 4 4], readbuffer, 0, 1);
% Must flip here, to clear the "drawingfinished" state from above:
Screen('Flip', win);
% Find location of red == 128 pixel:
pixposition = find(testreadback == 128);
if ~isempty(pixposition)
[pixy, pixx] = ind2sub(size(testreadback), pixposition);
% Map from Matlab indexing to OpenGL indexing: Only x is remapped,
% y-offset is consistent due to 1 offset inside our y-origin inside
% Screen:
pixx = pixx - 1;
else
pixy = -1;
pixx = -1;
end
rpix = pixx - 2;
rpiy = pixy - 1;
% At expected location?
if rpix~=0
fprintf('%s:GPU-Rasterizertest: Warning: glRasterPos2i() command draws at wrong position (Offset %i, %i)!\n', drivername, rpix, rpiy);
end
% glVertex2i(): Used by Screen's CLUT T-Lock blitter for output-positioning:
% Clear out top-left 20x20 rectangle of framebuffer:
Screen('FillRect', win, 0, [0 0 20 20]);
glPointSize(1);
glBegin(GL.POINTS);
% Draw RGB = [128, 0, 0] pixel:
glColor3ub(128, 0, 0);
% Submit glVertex2i at test location:
glVertex2i(2, 1);
glEnd;
% Sync the pipeline, so we know the backbuffer contains the result:
Screen('DrawingFinished', win, 0, 1);
% Read top-left 4x4 rectangle back, only the red channel:
testreadback = Screen('GetImage', win, [0 0 4 4], readbuffer, 0, 1);
% Must flip here, to clear the "drawingfinished" state from above:
Screen('Flip', win);
% Find location of red == 128 pixel:
pixposition = find(testreadback == 128);
if ~isempty(pixposition)
[pixy, pixx] = ind2sub(size(testreadback), pixposition);
% Map from Matlab indexing to OpenGL indexing: Only x is remapped,
% y-offset is consistent due to 1 offset inside our y-origin inside
% Screen:
pixx = pixx - 1;
else
pixy = -1;
pixx = -1;
end
vix = pixx - 2;
viy = pixy - 1;
% At expected location?
if vix~=0
fprintf('%s:GPU-Rasterizertest: Warning: glVertex2i() command draws at wrong position (Offset %i, %i)!\n', drivername, vix, viy);
end
% glVertex2f(): Used by Screen's drawing commands, e.g., 'DrawTexture' for output-positioning:
% Clear out top-left 20x20 rectangle of framebuffer:
Screen('FillRect', win, 0, [0 0 20 20]);
glPointSize(1);
glBegin(GL.POINTS);
% Draw RGB = [128, 0, 0] pixel:
glColor3ub(128, 0, 0);
% Submit glVertex2f at test location:
glVertex2f(2, 1);
glEnd;
% Sync the pipeline, so we know the backbuffer contains the result:
Screen('DrawingFinished', win, 0, 1);
% Read top-left 4x4 rectangle back, only the red channel:
testreadback = Screen('GetImage', win, [0 0 4 4], readbuffer, 0, 1);
% Must flip here, to clear the "drawingfinished" state from above:
Screen('Flip', win);
% Find location of red == 128 pixel:
pixposition = find(testreadback == 128);
if ~isempty(pixposition)
[pixy, pixx] = ind2sub(size(testreadback), pixposition);
% Map from Matlab indexing to OpenGL indexing: Only x is remapped,
% y-offset is consistent due to 1 offset inside our y-origin inside
% Screen:
pixx = pixx - 1;
else
pixy = -1;
pixx = -1;
end
vfx = pixx - 2;
vfy = pixy - 1;
% At expected location?
if vfx~=0 || vfy~=0
fprintf('%s:GPU-Rasterizertest: Warning: glVertex2f() command draws at wrong position (Offset %i, %i)!\n', drivername, vfx, vfy);
end
end
|