-
Notifications
You must be signed in to change notification settings - Fork 2
/
CL_VideoMemory.ps1
181 lines (159 loc) · 5.44 KB
/
CL_VideoMemory.ps1
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
# Copyright © 2008, Microsoft Corporation. All rights reserved.
# constant variable
[double]$script:targetFramesPerSecond = 30.0
[double]$script:fltEpsilon = 0.0000001
[double]$script:gpuBudget = 0.65
[double]$script:assumedAspectRatio = 4.0 / 3.0
[int]$script:bytesPerPixel = 4
[int]$script:numFullScreenBuffersForTransparent = 3
[int]$script:numFullScreenBuffersForOpaque = 3
[int]$script:numSingleMonitorBuffersForTransparent = 2
[int]$script:numSingleMonitorBuffersForOpaque = 0
[double]$script:allowedMemoryBudgetFraction = 0.50
[Array]$script:dragMovePolynomials = (0.4594, 18.783, 196),(0.4594, 1538.1, 196),(0.7061, 23.377, 196),(0.7061, 1922.5, 196)
#variable
[int]$script:largestMonitorWidth = 0
[int]$script:largestMonitorHeight = 0
[int]$script:numMonitors = 1
[int]$script:totalPixelArea = 0
#Initiatie resolution data
function InitiateResolutionData([int]$priMonWidth = $(throw "No primary monitor resolution is specified"), [int]$priMonHeight = $(throw "No primary monitor resolution is specified"), [int]$secMonWidth = 0, [int]$secMonHeight = 0)
{
#compute the data of resolutin
[int]$priTotalPixels = $priMonWidth * $priMonHeight
[int]$secTotalPixels = $secMonWidth * $secMonHeight
$script:totalPixelArea = $priTotalPixels + $secTotalPixels
if ($priTotalPixels -gt $secTotalPixels)
{
$script:largestMonitorHeight = $priMonHeight
$script:largestMonitorWidth = $priMonWidth
}
else
{
$script:largestMonitorHeight = $secMonHeight;
$script:largestMonitorWidth = $secMonWidth;
}
if ($secTotalPixels -eq 0)
{
$script:numMonitors = 1
}
else
{
$script:numMonitors = 2
}
}
#According to Aero Model coefficiants compute the pixel required
function Evaluate([Array]$dragMovePolynomials, [int]$longerEdge )
{
return $dragMovePolynomials[0] * $longerEdge * $longerEdge + $dragMovePolynomials[1] * $longerEdge + $dragMovePolynomials[2]
}
#Check if two double values are effectivly equal
function IsCloseDouble([double]$a, [double]$b)
{
return ([System.Math]::Abs($a - $b) -lt $script:fltEpsilon * 100)
}
#Check the performance requirements
function CheckPerformance([bool]$transparency, [double]$pVideoMemoryBandwidth)
{
[double]$longerEdge = 0
[double]$shorterEdge = 0
if ($script:largestMonitorWidth -gt $script:largestMonitorHeight)
{
$longerEdge = $script:largestMonitorWidth
$shorterEdge = $script:largestMonitorHeight
}
else
{
$longerEdge = $script:largestMonitorHeight
$shorterEdge = $script:largestMonitorWidth
}
if (-not (IsCloseDouble ($shorterEdge * $script:assumedAspectRatio) $longerEdge))
{
[double]$area = $longerEdge * $shorterEdge
$longerEdge = [System.Math]::Sqrt($area * $script:assumedAspectRatio)
$shorterEdge = $longerEdge / $script:assumedAspectRatio
}
[int]$idx = 0
if ($script:numMonitors -gt 1 -and $transparency)
{
$idx = 3
}
elseif($script:numMonitors -gt 1 -and -not $transparency)
{
$idx = 2
}
elseif($script:numMonitors -eq 1 -and $transparency)
{
$idx = 1
}
[double]$pixelsRequired = Evaluate $script:dragMovePolynomials[$idx] $longerEdge
[double]$gpuTimePerFrame = ($script:bytesPerPixel * $pixelsRequired) / $pVideoMemoryBandwidth
[double]$gpuTimePerSecond = $gpuTimePerFrame * $script:targetFramesPerSecond
return $gpuTimePerSecond -le $script:gpuBudget
}
#Compute the lowest passing performance value
function ComputeForLowestPassingPerformance([bool]$transparency)
{
[long]$top = 5000
[long]$bottom = 0
do
{
[double]$douVal = ($bottom + ($top - $bottom) / 2) * 1024 * 1024
#$perf = CheckPerformance $transparency $douVal
if (CheckPerformance $transparency $douVal)
{
$top = $top - (($top - $bottom) / 2)
}
else
{
$bottom = $bottom + (($top - $bottom) / 2)
}
} while (($top - $bottom) -gt 1);
return $top;
}
#Check the video memory requirements
function CheckVideoMemory([bool]$transparency, [double]$pTotalVideoMemory)
{
[int]$numFullScreenBuffers = 0
if ($transparency)
{
$numFullScreenBuffers = $script:numFullScreenBuffersForTransparent
}
else
{
$numFullScreenBuffers = $script:numFullScreenBuffersForOpaque
}
[int]$bufferPixels = $script:totalPixelArea * $numFullScreenBuffers
[int]$numSingleMonitorBuffers = 0
if ($transparency)
{
$numSingleMonitorBuffers= $script:numSingleMonitorBuffersForTransparent
}
else
{
$numSingleMonitorBuffers= $script:numSingleMonitorBuffersForOpaque
}
[int]$largestMonitorArea = $largestMonitorWidth * $largestMonitorHeight
$bufferPixels += $largestMonitorArea * $numSingleMonitorBuffers
[int]$bytesNeeded = $bufferPixels * $script:bytesPerPixel
[double]$bytesBudget = $pTotalVideoMemory * $script:allowedMemoryBudgetFraction;
return $bytesNeeded -le $bytesBudget
}
#Compute the lowest passing memory size
function ComputeForLowestPassingMemSize([bool]$transparency)
{
[int]$top = 1024;
[int]$bottom = 0
do {
[double]$douVal = ($bottom + ($top - $bottom) / 2) * 1024 * 1024
if (CheckVideoMemory $transparency $douVal)
{
$top = $top - (($top - $bottom) / 2)
}
else
{
$bottom = $bottom + (($top - $bottom) / 2)
}
} while(($top - $bottom) -gt 1);
return $top
}