-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathUtilities.cs
589 lines (492 loc) · 19.6 KB
/
Utilities.cs
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
/**
Copyright 2014-2024 Robert McNeel and Associates
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
**/
using ccl;
using ccl.ShaderNodes;
using ccl.ShaderNodes.Sockets;
using Rhino;
using Rhino.Display;
using Rhino.Render;
using Rhino.Render.Fields;
using Rhino.Runtime;
using RhinoCyclesCore.Converters;
using RhinoCyclesCore.Core;
using RhinoCyclesCore.ExtensionMethods;
using RhinoCyclesCore.Settings;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
namespace RhinoCyclesCore
{
public class DeviceAndPath
{
Device _device;
public Device Device => _device;
string _path;
public string Path => _path;
public DeviceAndPath(Device device, string path)
{
_device = device;
_path = path;
}
}
/// <summary>
/// Exception thrown when TexturedSlot type is unsupported.
/// </summary>
/// <since>6.12</since>
internal class UnrecognizedTexturedSlotType : Exception
{
/// <summary>
/// Construct exception
/// </summary>
/// <param name="message"></param>
/// <since>6.12</since>
internal UnrecognizedTexturedSlotType(string message) : base(message) { }
}
public static class Utilities
{
public static IAllSettings GetEngineDocumentSettings(uint doc_serial)
{
return new EngineDocumentSettings(doc_serial);
}
public static void TexturedSlot(RenderMaterial rm, string slotname, Color4f defaultColor, string prompt)
{
rm.Fields.AddTextured(slotname, defaultColor, prompt, false);
}
public static void TexturedSlot(RenderMaterial rm, string slotname, float defaultValue, string prompt)
{
rm.Fields.AddTextured(slotname, defaultValue, prompt, false);
}
public static (bool Success, float4 Result, bool IsOn, float Amount, RenderMaterial Child) HandleMaterialSlot(RenderMaterial rm, string slotname)
{
bool success = false;
float4 rc = new float4(0.0f);
bool onness = false;
float amount = 0.0f;
RenderMaterial rmchild = null;
if (rm.Fields.TryGetValue(slotname, out Color4f c))
{
rc = c.ToFloat4();
success = true;
}
var texamount = rm.GetChildSlotParameter(slotname, "texture-amount") as IConvertible;
if(texamount != null) {
amount = Convert.ToSingle(texamount) / 100.0f;
}
var texon = rm.GetChildSlotParameter(slotname, "texture-on") as IConvertible;
if(texon != null) {
onness = Convert.ToBoolean(texon);
}
if(rm.FindChild(slotname) is RenderMaterial rt) {
rmchild = rt;
}
return (success, rc, onness, amount, rmchild);
}
private static void GatherAdjustments(RenderTexture render_texture, CyclesTextureImage textureImage)
{
var rtf = render_texture.Fields;
if (rtf.TryGetValue("rdk-texture-adjust-grayscale", out bool grayscale))
textureImage.AdjustGrayscale = grayscale;
if (rtf.TryGetValue("rdk-texture-adjust-invert", out bool invert))
textureImage.AdjustInvert = invert;
if (rtf.TryGetValue("rdk-texture-adjust-clamp", out bool clamp))
textureImage.AdjustClamp = clamp;
if (rtf.TryGetValue("rdk-texture-adjust-scale-to-clamp", out bool scale_to_clamp))
textureImage.AdjustScaleToClamp = scale_to_clamp;
if (rtf.TryGetValue("rdk-texture-adjust-multiplier", out double multiplier))
textureImage.AdjustMultiplier = (float)multiplier;
if (rtf.TryGetValue("rdk-texture-adjust-clamp-min", out double clamp_min))
textureImage.AdjustClampMin = (float)clamp_min;
if (rtf.TryGetValue("rdk-texture-adjust-clamp-max", out double clamp_max))
textureImage.AdjustClampMax = (float)clamp_max;
if (rtf.TryGetValue("rdk-texture-adjust-gain", out double gain))
textureImage.AdjustGain = (float)gain;
if (rtf.TryGetValue("rdk-texture-adjust-gamma", out double gamma))
textureImage.AdjustGamma = (float)gamma;
if (rtf.TryGetValue("rdk-texture-adjust-saturation", out double saturation))
textureImage.AdjustSaturation = (float)saturation;
if (rtf.TryGetValue("rdk-texture-adjust-hue-shift", out double hue_shift))
textureImage.AdjustHueShift = (float)hue_shift;
textureImage.AdjustIsHdr = render_texture.IsHdrCapable();
if (textureImage.AdjustClamp || textureImage.AdjustScaleToClamp || textureImage.AdjustInvert || textureImage.AdjustGrayscale)
{
textureImage.AdjustNeeded = true;
}
else if (textureImage.AdjustGain != 0.5f ||
textureImage.AdjustGamma != 1.0f ||
textureImage.AdjustMultiplier != 1.0f ||
textureImage.AdjustClampMin != 0.0f ||
textureImage.AdjustClampMax != 1.0f ||
textureImage.AdjustHueShift != 0.0f ||
textureImage.AdjustSaturation != 1.0f)
{
textureImage.AdjustNeeded = true;
}
}
public static void HandleRenderTexture(RenderTexture rt, CyclesTextureImage tex, bool check_for_normal_map, bool is_leaf_bitmap, Converters.BitmapConverter bitmapConverter, uint docsrn, float gamma, bool should_simulate, bool is_color)
{
if (rt == null) return;
// JohnC: I had to change this to also exclude linear workflow because when I changed from using
// the incorrect TextureRenderHashFlags to the correct CrcRenderHashFlags, an assert started firing
// because we are not on the main thread.
uint rid = rt.RenderHashWithoutLocalMappingOrLinearWorkflow;
var rotationvec = rt.GetRotation();
var repeatvec = rt.GetRepeat();
var offsetvec = rt.GetOffset();
Transform tt = new Transform(
(float)offsetvec.X, (float)offsetvec.Y, (float)offsetvec.Z, 0.0f,
(float)repeatvec.X, (float)repeatvec.Y, (float)repeatvec.Z, 0.0f,
(float)rotationvec.X, (float)rotationvec.Y, (float)rotationvec.Z, 0.0f
);
var projectionMode = rt.GetProjectionMode();
var envProjectionMode = rt.GetInternalEnvironmentMappingMode();
var repeat = rt.GetWrapType() == TextureWrapType.Repeating;
GatherAdjustments(rt, tex);
var use_color_mask = false;
{
var use_mask = rt.GetParameter("has-transparent-color");
if (use_mask != null)
{
use_color_mask = Convert.ToBoolean(use_mask);
}
}
var color_mask = Color4f.White;
{
bool has_mask_color = rt.Fields.TryGetValue("transparent-color", out Color4f mask_color);
if(has_mask_color)
{
color_mask = mask_color;
}
}
var color_mask_sensitivity = 0.0f;
{
bool has_col_mask_sens = rt.Fields.TryGetValue("transparent-color-sensitivity", out double col_mask_sens);
if(has_col_mask_sens)
{
color_mask_sensitivity = (float)col_mask_sens;
}
}
bool alternate = false;
if (rt.Fields.TryGetValue("mirror-alternate-tiles", out bool mirror_alternate_tiles))
alternate = mirror_alternate_tiles;
else if (rt.Fields.TryGetValue("flip-alternate", out bool flip_alternate))
alternate = flip_alternate;
tex.ProjectionMode = projectionMode;
Procedural procedural = null;
if (!is_leaf_bitmap)
{
procedural = Procedural.CreateProcedural(rt, tex.TextureList, bitmapConverter, docsrn, gamma, is_color);
}
if (procedural != null)
{
tex.Procedural = procedural;
tex.IsNormalMap = tex.TextureList.Any<CyclesTextureImage>(cti => cti.IsNormalMap == true);
tex.MappingChannel = rt.GetMappingChannel();
}
else
{
var fs = "";
if (!should_simulate)
{
Field tf = rt.Fields.GetField("filename");
if (tf != null)
{
var ofs = tf.GetValue<string>();
RhinoDoc doc = rt.DocumentAssoc;
fs = Rhino.Render.Utilities.FindFile(doc, ofs, true);
}
} else {
SimulatedTexture simtex = rt.SimulatedTexture(RenderTexture.TextureGeneration.Allow);
RhinoDoc doc = rt.DocumentAssoc;
fs = simtex.Filename; //Rhino.Render.Utilities.FindFile(doc, simtex.Filename, true);
}
tex.IsNormalMap = rt.IsNormalMap();
tex.Filename = string.IsNullOrEmpty(fs) ? null : fs;
tex.Name = rid.ToString(CultureInfo.InvariantCulture);
tex.EnvProjectionMode = envProjectionMode;
tex.Transform = tt;
tex.Repeat = repeat;
tex.AlternateTiles = alternate;
tex.MappingChannel = rt.GetMappingChannel();
tex.UseColorMask = use_color_mask;
tex.ColorMask = color_mask;
tex.ColorMaskSensitivity = color_mask_sensitivity;
}
}
/// <summary>
/// Create the partial graph for a PBR-type slot.
/// </summary>
/// <since>6.12</since>
/// <typeparam name="T"></typeparam>
/// <param name="sh"></param>
/// <param name="slot"></param>
/// <param name="teximg"></param>
/// <param name="socks"></param>
public static ISocket PbrGraphForSlot<T>(Shader sh, TexturedValue<T> slot, CyclesTextureImage teximg, List<ISocket> socks, bool invert, float gamma, bool IsData, bool hasDecals)
{
Type t = typeof(T);
ISocket valsock = null;
if (t == typeof(float))
{
ValueNode vn = new ValueNode(sh, $"input_value_for_{slot.Name}_");
vn.Value = (float)(object)slot.Value;
if (invert)
{
MathSubtract invval = new MathSubtract(sh, $"invert_value_for_{slot.Name}_");
invval.ins.Value1.Value = 1.0f;
vn.outs.Value.Connect(invval.ins.Value2);
valsock = invval.outs.Value;
}
else
{
valsock = vn.outs.Value;
}
}
else if (t == typeof(Color4f))
{
ColorNode cn = new ColorNode(sh, $"input_color_for_{slot.Name}_");
cn.Value = ((Color4f)(object)slot.Value).ToFloat4();
if (invert)
{
InvertNode invcol = new InvertNode(sh, $"invert_input_color_for_{slot.Name}_");
invcol.ins.Fac.Value = 1.0f;
cn.outs.Color.Connect(invcol.ins.Color);
valsock = invcol.outs.Color;
}
else
{
valsock = cn.outs.Color;
}
}
if(valsock == null) {
throw new UnrecognizedTexturedSlotType($"Type tried is {t}");
}
return GraphForSlot(sh, valsock, slot.On, slot.Amount, teximg, socks, false, false, invert, IsData, gamma, hasDecals);
}
public static ISocket GraphForSlot(Shader sh, ISocket valueSocket, bool IsOn, float amount, CyclesTextureImage teximg, List<ISocket> socketsToConnectTo, bool toBw, bool normalMap, bool invert, bool IsData, float gamma, bool hasDecals)
{
ISocket alphaOut = null;
if(IsOn && null != teximg && teximg.HasProcedural)
{
var texco = new RhinoTextureCoordinateNode(sh, $"texco for input {valueSocket?.Parent.VariableName ?? "unknown input"}");
var mixerNode = new MixNode(sh, $"rgb mix node for imtexnode and {valueSocket?.Parent.VariableName ?? "unknown input"}");
mixerNode.ins.Fac.Value = Math.Min(1.0f, Math.Max(0.0f, amount));
var alpha_node = new MathAdd(sh);
alpha_node.ins.Value1.Value = 0.0f;
alpha_node.ins.Value2.Value = 1.0f;
VectorSocket uv_output_socket = RenderEngine.GetProjectionModeOutputSocket(sh, teximg.Procedural.ProjectionMode, teximg.Procedural.EnvironmentMappingMode, texco);
ColorSocket color_input_node = mixerNode.ins.Color2;
FloatSocket alpha_input_node = alpha_node.ins.Value2;
GammaNode gammaNode = null;
alphaOut = alpha_node.outs.Value;
texco.UvMap = teximg.GetUvMapForChannel();
valueSocket?.Connect(mixerNode.ins.Color1);
ISocket use_outsocket = null;
List<ISocket> alphaNodes = new List<ISocket>() { alpha_input_node };
if (valueSocket == null) {
mixerNode.ins.Fac.Value = 1.0f;
} else {
var alphamult = new MathMultiply(sh, $"alpha multiplier for {valueSocket?.Parent.VariableName ?? "unknown input"}");
alphamult.ins.Value1.Value = Math.Min(1.0f, Math.Max(0.0f, amount));
alphamult.ins.Value2.Value = 1.0f;
alphamult.outs.Value.Connect(mixerNode.ins.Fac);
alphaNodes.Add(alphamult.ins.Value2);
}
teximg.Procedural.CreateAndConnectProceduralNode(sh, uv_output_socket, color_input_node, alphaNodes, IsData);
// apply gamma now also to bitmaps since the change to no longer do
// czolor conversion in the kernel. RH-83550
if (!IsData)
{
gammaNode = new GammaNode(sh, "gamma node for color channel");
gammaNode.ins.Gamma.Value = gamma;
mixerNode.outs.Color.Connect(gammaNode.ins.Color);
}
if (normalMap)
{
var normalmapnode = new NormalMapNode(sh, $"Normal map node for {valueSocket?.Parent.VariableName ?? "unknown input"}")
{
Attribute = teximg.GetUvMapForChannel(),
// ideally we calculate the tangents and switch to Tangent space here.
SpaceType = NormalMapNode.Space.Tangent
};
mixerNode.outs.Color.Connect(normalmapnode.ins.Color);
normalmapnode.ins.Strength.Value = amount * RcCore.It.AllSettings.NormalStrengthFactor;
foreach(var sock in socketsToConnectTo) {
normalmapnode.outs.Normal.Connect(sock);
}
}
else
{
if (invert)
{
var invcol = new InvertNode(sh, $"invert color for imtexnode for {valueSocket?.Parent.VariableName ?? "unknown input"}");
mixerNode.outs.Color.Connect(invcol.ins.Color);
invcol.ins.Fac.Value = 1.0f;
use_outsocket = invcol.outs.Color;
}
else
{
use_outsocket = mixerNode.outs.Color;
if(toBw) {
var tobwnode = new RgbToBwNode(sh, $"convert imtexnode to bw for {valueSocket?.Parent.VariableName ?? "unknown input"}");
use_outsocket.Connect(tobwnode.ins.Color);
use_outsocket = tobwnode.outs.Val;
}
if(!IsData && gammaNode != null) {
use_outsocket = gammaNode.outs.Color;
}
}
if (amount >= 0.0f && amount <= 1.0f)
{
foreach (var sock in socketsToConnectTo)
{
use_outsocket.Connect(sock);
}
} else { // multiply the output of mixerNode.outs.Color with amount.
SeparateRgbNode separateRgbNode = new SeparateRgbNode(sh, $"separating the color for multiplication {valueSocket?.Parent.VariableName ?? "unknown input"}");
MathMultiply multiplyR = new MathMultiply(sh, $"multiplier for R {valueSocket?.Parent.VariableName ?? "unknown input"}");
MathMultiply multiplyG = new MathMultiply(sh, $"multiplier for G {valueSocket?.Parent.VariableName ?? "unknown input"}");
MathMultiply multiplyB = new MathMultiply(sh, $"multiplier for B {valueSocket?.Parent.VariableName ?? "unknown input"}");
CombineRgbNode combineRgbNode = new CombineRgbNode(sh, $"combining the new color values {valueSocket?.Parent.VariableName ?? "unknown input"}");
multiplyR.UseClamp = false;
multiplyG.UseClamp = false;
multiplyB.UseClamp = false;
multiplyR.ins.Value1.Value = amount;
multiplyG.ins.Value1.Value = amount;
multiplyB.ins.Value1.Value = amount;
use_outsocket.Connect(separateRgbNode.ins.Image);
separateRgbNode.outs.R.Connect(multiplyR.ins.Value2);
separateRgbNode.outs.G.Connect(multiplyG.ins.Value2);
separateRgbNode.outs.B.Connect(multiplyB.ins.Value2);
multiplyR.outs.Value.Connect(combineRgbNode.ins.R);
multiplyG.outs.Value.Connect(combineRgbNode.ins.G);
multiplyB.outs.Value.Connect(combineRgbNode.ins.B);
use_outsocket = combineRgbNode.outs.Image;
if(!IsData && gammaNode != null) {
combineRgbNode.outs.Image.Connect(gammaNode.ins.Color);
use_outsocket = gammaNode.outs.Color;
}
foreach (var sock in socketsToConnectTo)
{
use_outsocket.Connect(sock);
}
}
}
return alphaOut;
}
else
{
if(!hasDecals && valueSocket.XmlName.Equals("color"))
{
GammaNode gammaNode = new GammaNode(sh, "gamma node for color inpunputt");
gammaNode.ins.Gamma.Value = gamma;
valueSocket.Connect(gammaNode.ins.Color);
valueSocket = gammaNode.outs.Color;
}
foreach (var sock in socketsToConnectTo)
{
valueSocket?.Connect(sock);
}
}
return null;
}
/// <summary>
/// Add a graph branch that implements a color mask as Rhino does.
/// </summary>
/// <param name="image_texture_node"></param>
/// <param name="cyclesTexture"></param>
/// <returns>MathMultiply node that combines image_texture_node alpha with the color mask alpha</returns>
public static MathMultiply ApplyColorMaskGraph(ImageTextureNode image_texture_node, CyclesTextureImage cyclesTexture)
{
Shader shader = image_texture_node.Shader;
var sep_img_col = new SeparateRgbNode(shader, "separate image color");
var sep_mask_col = new SeparateRgbNode(shader, "separate mask color");
MathSubtract sub_r = new(shader, "subtract r channels");
MathSubtract sub_g = new(shader, "subtract g channels");
MathSubtract sub_b = new(shader, "subtract b channels");
sub_r.UseClamp = false;
sub_g.UseClamp = false;
sub_b.UseClamp = false;
MathAbsolute abs_r = new(shader, "abs(r)");
MathAbsolute abs_g = new(shader, "abs(g)");
MathAbsolute abs_b = new(shader, "abs(b)");
MathDivide div_sum_three = new(shader, "sum_abs_rgb__div_three");
div_sum_three.ins.Value2.Value = 3.0f;
MathLess_Than sensitivity_lt_absdiv3 = new(shader, "sensitivity lt absdiv3");
sensitivity_lt_absdiv3.ins.Value1.Value = cyclesTexture.ColorMaskSensitivity;
MathAdd add_abs_rg = new (shader, "add r and g abs");
MathAdd add_abs_rg_b = new (shader, "add rg b abs");
add_abs_rg.UseClamp = false;
add_abs_rg_b.UseClamp = false;
MathMultiply adjust_img_alpha = new (shader, "adjust_img_alpha");
adjust_img_alpha.UseClamp = false;
image_texture_node.outs.Color.Connect(sep_img_col.ins.Image);
// Since images are most likely undergoing sRGB to Linear conversion
// inside Cycles do the same for the color mask value.
sep_mask_col.ins.Image.Value = float4.SrgbToLinear(cyclesTexture.ColorMask.ToFloat4());
sep_img_col.outs.R.Connect(sub_r.ins.Value1);
sep_mask_col.outs.R.Connect(sub_r.ins.Value2);
sep_img_col.outs.G.Connect(sub_g.ins.Value1);
sep_mask_col.outs.G.Connect(sub_g.ins.Value2);
sep_img_col.outs.B.Connect(sub_b.ins.Value1);
sep_mask_col.outs.B.Connect(sub_b.ins.Value2);
sub_r.outs.Value.Connect(abs_r.ins.Value1);
sub_g.outs.Value.Connect(abs_g.ins.Value1);
sub_b.outs.Value.Connect(abs_b.ins.Value1);
abs_r.outs.Value.Connect(add_abs_rg.ins.Value1);
abs_g.outs.Value.Connect(add_abs_rg.ins.Value2);
add_abs_rg.outs.Value.Connect(add_abs_rg_b.ins.Value1);
abs_b.outs.Value.Connect(add_abs_rg_b.ins.Value2);
add_abs_rg_b.outs.Value.Connect(div_sum_three.ins.Value1);
div_sum_three.outs.Value.Connect(sensitivity_lt_absdiv3.ins.Value2);
image_texture_node.outs.Alpha.Connect(adjust_img_alpha.ins.Value1);
sensitivity_lt_absdiv3.outs.Value.Connect(adjust_img_alpha.ins.Value2);
return adjust_img_alpha;
}
public static int GetSystemProcessorCount()
{
return HostUtils.GetSystemProcessorCount();
}
//public static readonly PlugIn RcPlugIn = Rhino.PlugIns.PlugIn.Find(new Guid("9BC28E9E-7A6C-4B8F-A0C6-3D05E02D1B97"));
public static readonly Rhino.PlugIns.PlugIn RcPlugIn = Rhino.PlugIns.PlugIn.Find(new Guid("9BC28E9E-7A6C-4B8F-A0C6-3D05E02D1B97"));
private static string _DisableGpusFile {
get
{
var settingsDirectory = RcPlugIn.SettingsDirectory;
if(!Directory.Exists(settingsDirectory))
{
Directory.CreateDirectory(settingsDirectory);
}
var disableGpusFile = Path.Combine(settingsDirectory, "disable_gpus");
return disableGpusFile;
}
}
public static bool GpusDisabled => File.Exists(_DisableGpusFile);
public static bool HasGpus => Device.FirstGpu.Type != DeviceType.Cpu;
public static void EnableGpus()
{
if(File.Exists(_DisableGpusFile))
{
File.Delete(_DisableGpusFile);
}
}
public static void DisableGpus()
{
if(!File.Exists(_DisableGpusFile))
{
File.Create(_DisableGpusFile);
}
}
}
}