Skip to content

Commit f7e2a18

Browse files
committed
Minor fixes for all graphics APIs
1 parent a03189c commit f7e2a18

11 files changed

Lines changed: 88 additions & 52 deletions

sources/core/Stride.Core/Storage/ObjectId.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,19 @@ public static ObjectId New()
269269
return FromBytes(Guid.NewGuid().ToByteArray());
270270
}
271271

272+
/// <summary>
273+
/// Computes a hash from a byte buffer.
274+
/// </summary>
275+
/// <param name="buffer">The byte buffer.</param>
276+
/// <returns>The hash of the object.</returns>
277+
/// <exception cref="System.ArgumentNullException">buffer</exception>
278+
public static ObjectId FromBytes(ReadOnlySpan<byte> buffer)
279+
{
280+
var builder = new ObjectIdBuilder();
281+
builder.Write(buffer);
282+
return builder.ComputeHash();
283+
}
284+
272285
/// <summary>
273286
/// Computes a hash from a byte buffer.
274287
/// </summary>

sources/engine/Stride.Graphics/Direct3D/SwapChainGraphicsPresenter.Direct3D.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#if STRIDE_GRAPHICS_API_DIRECT3D11
3333
using BackBufferResourceType = Silk.NET.Direct3D11.ID3D11Texture2D;
3434
#elif STRIDE_GRAPHICS_API_DIRECT3D12
35-
using BackBufferResourceType = SharpDX.Direct3D12.Resource;
35+
using BackBufferResourceType = Silk.NET.Direct3D12.ID3D12Resource;
3636
#endif
3737

3838
namespace Stride.Graphics
@@ -54,7 +54,7 @@ public unsafe class SwapChainGraphicsPresenter : GraphicsPresenter
5454
private int bufferCount;
5555

5656
#if STRIDE_GRAPHICS_API_DIRECT3D12
57-
private int bufferSwapIndex;
57+
private uint bufferSwapIndex;
5858
#endif
5959

6060
public SwapChainGraphicsPresenter(GraphicsDevice device, PresentationParameters presentationParameters)
@@ -272,7 +272,7 @@ public override void Present()
272272
? DXGI.PresentAllowTearing
273273
: 0;
274274

275-
HResult result = swapChain->Present((uint) presentInterval, (uint) presentFlags);
275+
HResult result = swapChain->Present((uint) presentInterval, presentFlags);
276276

277277
if (result.IsFailure)
278278
{
@@ -285,7 +285,7 @@ public override void Present()
285285
#if STRIDE_GRAPHICS_API_DIRECT3D12
286286
// Manually swap back buffer
287287
backBuffer.NativeResource->Release();
288-
bufferSwapIndex = (++bufferSwapIndex) % bufferCount;
288+
bufferSwapIndex = (uint)((++bufferSwapIndex) % bufferCount);
289289
var nextBackBuffer = GetBackBuffer<BackBufferResourceType>(bufferSwapIndex);
290290
backBuffer.InitializeFromImpl(nextBackBuffer, Description.BackBufferFormat.IsSRgb());
291291
#endif

sources/engine/Stride.Graphics/Direct3D12/GraphicsResourceBase.Direct3D12.cs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
#if STRIDE_GRAPHICS_API_DIRECT3D12
55

66
using System;
7+
using System.Diagnostics;
78
using Silk.NET.Core.Native;
89
using Silk.NET.Direct3D12;
10+
using Stride.Core;
911

1012
namespace Stride.Graphics
1113
{
@@ -28,15 +30,30 @@ protected internal ID3D12DeviceChild* NativeDeviceChild
2830

2931
set
3032
{
33+
if (nativeDeviceChild == value)
34+
return;
35+
36+
var oldDeviceChild = nativeDeviceChild;
37+
if (oldDeviceChild != null)
38+
oldDeviceChild->Release();
39+
3140
nativeDeviceChild = value;
41+
if (nativeDeviceChild != null)
42+
nativeDeviceChild->AddRef();
43+
else
44+
return;
45+
46+
Debug.Assert(nativeDeviceChild != null);
3247

3348
ID3D12Resource* d3d12Resource;
3449
HResult result = nativeDeviceChild->QueryInterface(SilkMarshal.GuidPtrOf<ID3D12Resource>(), (void**) &d3d12Resource);
3550

36-
if (result.IsFailure)
37-
result.Throw();
38-
39-
NativeResource = d3d12Resource;
51+
// The device child can be something that is not a Direct3D resource actually,
52+
// like a Sampler State, for example
53+
if (result.IsSuccess)
54+
{
55+
NativeResource = d3d12Resource;
56+
}
4057

4158
// Associate PrivateData to this DeviceResource
4259
SetDebugName(GraphicsDevice, nativeDeviceChild, Name);

sources/engine/Stride.Graphics/OpenGL/CommandList.OpenGL.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public void Reset()
8989

9090
public void Flush()
9191
{
92-
92+
9393
}
9494

9595
public CompiledCommandList Close()
@@ -1080,7 +1080,7 @@ private unsafe MappedResource MapTexture(Texture texture, bool adjustOffsetForSu
10801080

10811081
return new MappedResource(texture, subResourceIndex, new DataBox { DataPointer = mapResult, SlicePitch = texture.ComputeSlicePitch(mipLevel), RowPitch = texture.ComputeRowPitch(mipLevel) }, offsetInBytes, lengthInBytes)
10821082
{
1083-
PixelBufferObjectId = pixelBufferObjectId,
1083+
PixelBufferObjectId = pixelBufferObjectId
10841084
};
10851085
}
10861086

@@ -1352,7 +1352,7 @@ internal void SetUnorderedAccessView(ShaderStage stage, int slot, GraphicsResour
13521352

13531353
Internal.Refactor.ThrowNotImplementedException();
13541354
}
1355-
1355+
13561356
/// <summary>
13571357
/// Unsets an unordered access view from the shader pipeline.
13581358
/// </summary>
@@ -1362,7 +1362,7 @@ internal void UnsetUnorderedAccessView(GraphicsResource unorderedAccessView)
13621362
#if DEBUG
13631363
GraphicsDevice.EnsureContextActive();
13641364
#endif
1365-
1365+
13661366
//Internal.Refactor.ThrowNotImplementedException();
13671367
}
13681368

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// Copyright (c) Silk.NET
22
// Licensed to the .NET Foundation under one or more agreements.
33
// The .NET Foundation licenses this file to you under the MIT license.
4-
#if STRIDE_GRAPHICS_API_OPENGL
4+
5+
#if STRIDE_GRAPHICS_API_OPENGL
6+
57
using Silk.NET.Core.Loader;
68

79
namespace Silk.NET.OpenGL
@@ -12,22 +14,23 @@ namespace Silk.NET.OpenGL
1214
internal class GLCoreLibraryNameContainer : SearchPathContainer
1315
{
1416
/// <inheritdoc />
15-
public override string Linux => "libGL.so.1";
17+
public override string[] Linux => new[] { "libGL.so.1" };
1618

1719
/// <inheritdoc />
18-
public override string MacOS => "/System/Library/Frameworks/OpenGL.framework/OpenGL";
20+
public override string[] MacOS => new[] { "/System/Library/Frameworks/OpenGL.framework/OpenGL" };
1921

2022
/// <inheritdoc />
21-
public override string Android => "libGL.so.1";
23+
public override string[] Android => new[] { "libGL.so.1" };
2224

2325
/// <inheritdoc />
24-
public override string IOS => "/System/Library/Frameworks/OpenGL.framework/OpenGL";
26+
public override string[] IOS => new[] { "/System/Library/Frameworks/OpenGL.framework/OpenGL" };
2527

2628
/// <inheritdoc />
27-
public override string Windows64 => "opengl32.dll";
29+
public override string[] Windows64 => new[] { "opengl32.dll" };
2830

2931
/// <inheritdoc />
30-
public override string Windows86 => "opengl32.dll";
32+
public override string[] Windows86 => new[] { "opengl32.dll" };
3133
}
3234
}
35+
3336
#endif

sources/engine/Stride.Graphics/OpenGL/GraphicsAdapter.OpenGL.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
33

44
#if STRIDE_GRAPHICS_API_OPENGL
5-
using System.Linq;
5+
66
using Silk.NET.SDL;
77
using Stride.Graphics.OpenGL;
88

@@ -21,7 +21,7 @@ public unsafe partial class GraphicsAdapter
2121

2222
internal GraphicsAdapter()
2323
{
24-
outputs = new [] { new GraphicsOutput() };
24+
Outputs = new [] { new GraphicsOutput() };
2525

2626
// set default values
2727
int detectedVersion = 100;

sources/engine/Stride.Graphics/OpenGL/GraphicsDeviceFeatures.OpenGL.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
11
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
22
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
3+
34
#if STRIDE_GRAPHICS_API_OPENGL
5+
46
// Copyright (c) 2010-2012 SharpDX - Alexandre Mutel
5-
//
7+
//
68
// Permission is hereby granted, free of charge, to any person obtaining a copy
79
// of this software and associated documentation files (the "Software"), to deal
810
// in the Software without restriction, including without limitation the rights
911
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1012
// copies of the Software, and to permit persons to whom the Software is
1113
// furnished to do so, subject to the following conditions:
12-
//
14+
//
1315
// The above copyright notice and this permission notice shall be included in
1416
// all copies or substantial portions of the Software.
15-
//
17+
//
1618
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1719
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1820
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1921
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2022
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2123
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2224
// THE SOFTWARE.
23-
using System;
24-
using System.Collections.Generic;
25+
2526
using Stride.Graphics.OpenGL;
2627
using Stride.Core.Diagnostics;
2728

@@ -36,7 +37,7 @@ namespace Stride.Graphics
3637
public partial struct GraphicsDeviceFeatures
3738
{
3839
private const GetPName GL_MAX_SAMPLES = (GetPName)36183; // We define this constant here because it is not contained within OpenTK...
39-
40+
4041
private static Logger logger = GlobalLogger.GetLogger(nameof(GraphicsDeviceFeatures));
4142

4243
private void EnumerateMSAASupportPerFormat(GraphicsDevice deviceRoot)
@@ -71,7 +72,7 @@ private void EnumerateMSAASupportPerFormat(GraphicsDevice deviceRoot)
7172
for (int i = 0; i < mapFeaturesPerFormat.Length; i++)
7273
{
7374
// TODO: This ignores the supported multisample capabilities of each render target format. But I don't know how to query this in OpenGL (assuming it's even possible at all).
74-
mapFeaturesPerFormat[i] = new FeaturesPerFormat((PixelFormat)i, actualMultisampleCount, FormatSupport.None);
75+
mapFeaturesPerFormat[i] = new FeaturesPerFormat((PixelFormat)i, actualMultisampleCount, ComputeShaderFormatSupport.None, FormatSupport.None);
7576
}
7677
}
7778

@@ -155,4 +156,5 @@ internal GraphicsDeviceFeatures(GraphicsDevice deviceRoot)
155156
}
156157
}
157158
}
159+
158160
#endif

sources/engine/Stride.Graphics/OpenGL/MappedResource.OpenGL.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
33

44
#if STRIDE_GRAPHICS_API_OPENGL
5+
56
namespace Stride.Graphics
67
{
78
public partial struct MappedResource
89
{
9-
internal uint PixelBufferObjectId;
10+
internal uint PixelBufferObjectId { get; init; }
1011
}
1112
}
13+
1214
#endif
Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// Copyright (c) Silk.NET
22
// Licensed to the .NET Foundation under one or more agreements.
33
// The .NET Foundation licenses this file to you under the MIT license.
4-
#if STRIDE_GRAPHICS_API_OPENGL
4+
5+
#if STRIDE_GRAPHICS_API_OPENGL
6+
57
using Silk.NET.Core.Loader;
68

79
namespace Silk.NET.OpenGLES
@@ -12,22 +14,23 @@ namespace Silk.NET.OpenGLES
1214
internal class OpenGLESLibraryNameContainer : SearchPathContainer
1315
{
1416
/// <inheritdoc />
15-
public override string Linux => "libGLESv2.so";
17+
public override string[] Linux => new[] { "libGLESv2.so" };
1618

1719
/// <inheritdoc />
18-
public override string MacOS => "/System/Library/Frameworks/OpenGLES.framework/OpenGLES";
20+
public override string[] MacOS => new[] { "/System/Library/Frameworks/OpenGLES.framework/OpenGLES" };
1921

2022
/// <inheritdoc />
21-
public override string Android => "libGLESv2.so";
23+
public override string[] Android => new[] { "libGLESv2.so" };
2224

2325
/// <inheritdoc />
24-
public override string IOS => "/System/Library/Frameworks/OpenGLES.framework/OpenGLES";
26+
public override string[] IOS => new[] { "/System/Library/Frameworks/OpenGLES.framework/OpenGLES" };
2527

2628
/// <inheritdoc />
27-
public override string Windows64 => "libGLESv2.dll";
29+
public override string[] Windows64 => new[] { "libGLESv2.dll" };
2830

2931
/// <inheritdoc />
30-
public override string Windows86 => "libGLESv2.dll";
32+
public override string[] Windows86 => new[] { "libGLESv2.dll" };
3133
}
3234
}
35+
3336
#endif

sources/engine/Stride.Graphics/Vulkan/GraphicsAdapter.Vulkan.cs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
11
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
22
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
3+
34
#if STRIDE_GRAPHICS_API_VULKAN
5+
46
using System;
57
using System.Collections.Generic;
6-
using System.Resources;
78
using System.Runtime.InteropServices;
8-
using System.Text;
99
using Vortice.Vulkan;
10-
using static Vortice.Vulkan.Vulkan;
11-
using Stride.Core;
1210

13-
using ComponentBase = Stride.Core.ComponentBase;
14-
using Utilities = Stride.Core.Utilities;
11+
using static Vortice.Vulkan.Vulkan;
1512

1613
namespace Stride.Graphics
1714
{
1815
/// <summary>
1916
/// Provides methods to retrieve and manipulate graphics adapters. This is the equivalent to <see cref="Adapter1"/>.
2017
/// </summary>
21-
/// <msdn-id>ff471329</msdn-id>
22-
/// <unmanaged>IDXGIAdapter1</unmanaged>
23-
/// <unmanaged-short>IDXGIAdapter1</unmanaged-short>
18+
/// <msdn-id>ff471329</msdn-id>
19+
/// <unmanaged>IDXGIAdapter1</unmanaged>
20+
/// <unmanaged-short>IDXGIAdapter1</unmanaged-short>
2421
public partial class GraphicsAdapter
2522
{
2623
private VkPhysicalDevice defaultPhysicalDevice;
@@ -56,7 +53,7 @@ internal GraphicsAdapter(VkPhysicalDevice defaultPhysicalDevice, int adapterOrdi
5653
//outputs = new GraphicsOutput[displayProperties.Length];
5754
//for (var i = 0; i < outputs.Length; i++)
5855
// outputs[i] = new GraphicsOutput(this, displayProperties[i], i).DisposeBy(this);
59-
outputs = new[] { new GraphicsOutput() };
56+
Outputs = new[] { new GraphicsOutput() };
6057
}
6158

6259
/// <summary>
@@ -132,5 +129,6 @@ public bool IsProfileSupported(GraphicsProfile graphicsProfile)
132129
//return SharpDX.Direct3D11.Device.IsSupportedFeatureLevel(this.NativeAdapter, (SharpDX.Direct3D.FeatureLevel)graphicsProfile);
133130
}
134131
}
135-
}
132+
}
133+
136134
#endif

0 commit comments

Comments
 (0)