Skip to content

Commit

Permalink
Merge branch 'master' into bepu_integration
Browse files Browse the repository at this point in the history
  • Loading branch information
Eideren authored Nov 2, 2024
2 parents 413c24d + d744a42 commit 36c9807
Show file tree
Hide file tree
Showing 25 changed files with 320 additions and 346 deletions.
13 changes: 9 additions & 4 deletions sources/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,16 @@
<PackageVersion Include="Xunit.SkippableFact" Version="1.4.13" />
</ItemGroup>
<!-- Avalonia dependencies -->
<PropertyGroup>
<AvaloniaVersion>11.0.6</AvaloniaVersion>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Avalonia" Version="11.0.6" />
<PackageVersion Include="Avalonia.Desktop" Version="11.0.6" />
<PackageVersion Include="Avalonia.Fonts.Inter" Version="11.0.6" />
<PackageVersion Include="Avalonia.Themes.Fluent" Version="11.0.6" />
<PackageVersion Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageVersion Include="Avalonia.Controls.DataGrid" Version="$(AvaloniaVersion)" />
<PackageVersion Include="Avalonia.Desktop" Version="$(AvaloniaVersion)" />
<PackageVersion Include="Avalonia.Diagnostics" Version="$(AvaloniaVersion)" />
<PackageVersion Include="Avalonia.Fonts.Inter" Version="$(AvaloniaVersion)" />
<PackageVersion Include="Avalonia.Themes.Fluent" Version="$(AvaloniaVersion)" />
<PackageVersion Include="CommunityToolkit.Mvvm" Version="8.2.2" />
</ItemGroup>
<!-- Windows/WPF dependencies -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ private Project ReadProject([NotNull] string firstLine)

var projectTypeGuid = new Guid(match.Groups["PROJECTTYPEGUID"].Value.Trim());
var projectName = match.Groups["PROJECTNAME"].Value.Trim();
var relativePath = match.Groups["RELATIVEPATH"].Value.Trim();
var relativePath = match.Groups["RELATIVEPATH"].Value.Trim().Replace('\\', Path.DirectorySeparatorChar);
var projectGuid = new Guid(match.Groups["PROJECTGUID"].Value.Trim());

var projectSections = new List<Section>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ protected override void Prepare(AssetCompilerContext context, AssetItem assetIte
var textureAssetItem = new AssetItem(textureUrl, textureAsset);

// Create and add the texture command.
var textureParameters = new TextureConvertParameters(assetSource, textureAsset, PlatformType.Windows, GraphicsPlatform.Direct3D11, graphicsProfile, gameSettingsAsset.GetOrCreate<TextureSettings>().TextureQuality, colorSpace);
var textureParameters = new TextureConvertParameters(assetSource, textureAsset, context.Platform, context.Platform.GetDefaultGraphicsPlatform(), graphicsProfile, gameSettingsAsset.GetOrCreate<TextureSettings>().TextureQuality, colorSpace);
var prereqStep = new AssetBuildStep(textureAssetItem);
prereqStep.Add(new TextureAssetCompiler.TextureConvertCommand(textureUrl, textureParameters, assetItem.Package));
result.BuildSteps.Add(prereqStep);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ public void DrawInstanced(Buffer argumentsBuffer, int alignedByteOffsetForArgs =

PrepareDraw();

NativeDeviceContext.DrawIndexedInstancedIndirect(argumentsBuffer.NativeBuffer, alignedByteOffsetForArgs);
NativeDeviceContext.DrawInstancedIndirect(argumentsBuffer.NativeBuffer, alignedByteOffsetForArgs);

GraphicsDevice.FrameDrawCalls++;
}
Expand Down
27 changes: 9 additions & 18 deletions sources/engine/Stride.Graphics/OpenGL/CommandList.OpenGL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -920,8 +920,7 @@ public unsafe MappedResource MapSubresource(GraphicsResource resource, int subRe
mapMode = MapMode.WriteDiscard;


var buffer = resource as Buffer;
if (buffer != null)
if (resource is Buffer buffer)
{
if (lengthInBytes == 0)
lengthInBytes = buffer.Description.SizeInBytes;
Expand All @@ -930,29 +929,21 @@ public unsafe MappedResource MapSubresource(GraphicsResource resource, int subRe

GL.BindBuffer(buffer.BufferTarget, buffer.BufferId);

#if !STRIDE_GRAPHICS_API_OPENGLES
//if (mapMode != MapMode.WriteDiscard && mapMode != MapMode.WriteNoOverwrite)
// mapResult = GL.MapBuffer(buffer.bufferTarget, mapMode.ToOpenGL());
//else
#endif
// Orphan the buffer (let driver knows we don't need it anymore)
if (mapMode == MapMode.WriteDiscard)
{
// Orphan the buffer (let driver knows we don't need it anymore)
if (mapMode == MapMode.WriteDiscard)
{
doNotWait = true;
GL.BufferData(buffer.BufferTarget, (UIntPtr)buffer.Description.SizeInBytes, IntPtr.Zero, buffer.BufferUsageHint);
}
doNotWait = true;
GL.BufferData(buffer.BufferTarget, (uint)buffer.Description.SizeInBytes, null, buffer.BufferUsageHint);
}

var unsynchronized = doNotWait && mapMode != MapMode.Read && mapMode != MapMode.ReadWrite;
var unsynchronized = doNotWait && mapMode != MapMode.Read && mapMode != MapMode.ReadWrite;

mapResult = (IntPtr)GL.MapBufferRange(buffer.BufferTarget, (IntPtr)offsetInBytes, (UIntPtr)lengthInBytes, mapMode.ToOpenGLMask() | (unsynchronized ? MapBufferAccessMask.MapUnsynchronizedBit : 0));
}
mapResult = (IntPtr)GL.MapBufferRange(buffer.BufferTarget, offsetInBytes, (UIntPtr)lengthInBytes, mapMode.ToOpenGLMask() | (unsynchronized ? MapBufferAccessMask.UnsynchronizedBit : 0));

return new MappedResource(resource, subResourceIndex, new DataBox { DataPointer = mapResult, SlicePitch = 0, RowPitch = 0 });
}

var texture = resource as Texture;
if (texture != null)
if (resource is Texture texture)
{
if (lengthInBytes == 0)
lengthInBytes = texture.ComputeSubresourceSize(subResourceIndex);
Expand Down
15 changes: 8 additions & 7 deletions sources/engine/Stride.Graphics/OpenGL/GraphicsDevice.OpenGL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -658,23 +658,24 @@ protected unsafe void InitializePlatformDevice(GraphicsProfile[] graphicsProfile
#endif

#if STRIDE_UI_SDL
gameWindow = (Stride.Graphics.SDL.Window)windowHandle.NativeWindow;
// NOTE : This null handling is specific for Linux AssetCompiler #2504 (refactor required?)
gameWindow = windowHandle?.NativeWindow as SDL.Window ?? new SDL.Window("");

var SDL = Graphics.SDL.Window.SDL;

#if STRIDE_GRAPHICS_API_OPENGLES
SDL.GLSetAttribute(GLattr.GLContextProfileMask, (int)GLprofile.GLContextProfileES);
SDL.GLSetAttribute(GLattr.ContextProfileMask, (int)GLprofile.ES);
#else
SDL.GLSetAttribute(GLattr.GLContextProfileMask, (int)GLprofile.GLContextProfileCore);
SDL.GLSetAttribute(GLattr.ContextProfileMask, (int)GLprofile.Core);
#endif


if (IsDebugMode)
SDL.GLSetAttribute(GLattr.GLContextFlags, (int)GLcontextFlag.GLContextDebugFlag);
SDL.GLSetAttribute(GLattr.ContextFlags, (int)GLcontextFlag.DebugFlag);

// Setup version
SDL.GLSetAttribute(GLattr.GLContextMajorVersion, currentVersion / 100);
SDL.GLSetAttribute(GLattr.GLContextMinorVersion, (currentVersion / 10) % 10);
SDL.GLSetAttribute(GLattr.ContextMajorVersion, currentVersion / 100);
SDL.GLSetAttribute(GLattr.ContextMinorVersion, (currentVersion / 10) % 10);

MainGraphicsContext = new SdlContext(SDL, (Silk.NET.SDL.Window*)gameWindow.SdlHandle);
((SdlContext)MainGraphicsContext).Create();
Expand All @@ -690,7 +691,7 @@ protected unsafe void InitializePlatformDevice(GraphicsProfile[] graphicsProfile
#endif

// Create shared context for creating graphics resources from other threads
SDL.GLSetAttribute(GLattr.GLShareWithCurrentContext, 1);
SDL.GLSetAttribute(GLattr.ShareWithCurrentContext, 1);
deviceCreationContext = new SdlContext(SDL, (Silk.NET.SDL.Window*)gameWindow.SdlHandle);
((SdlContext)deviceCreationContext).Create();

Expand Down
6 changes: 3 additions & 3 deletions sources/engine/Stride.Graphics/OpenGL/Texture.OpenGL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -413,11 +413,11 @@ private void CreateTexture2DArray(bool compressed, int width, int height, int mi
{
if (compressed)
{
GL.CompressedTexImage3D(TextureTarget, mipLevel, TextureInternalFormat, (uint) width, (uint) height, (uint) ArraySize, border: 0, imageSize: 0, data: IntPtr.Zero);
GL.CompressedTexImage3D(TextureTarget, mipLevel, TextureInternalFormat, (uint) width, (uint) height, (uint) ArraySize, border: 0, imageSize: 0, data: null);
}
else
{
GL.TexImage3D(TextureTarget, mipLevel, TextureInternalFormat, (uint) width, (uint) height, (uint) ArraySize, border: 0, TextureFormat, TextureType, IntPtr.Zero);
GL.TexImage3D(TextureTarget, mipLevel, TextureInternalFormat, (uint) width, (uint) height, (uint) ArraySize, border: 0, TextureFormat, TextureType, null);
}
}

Expand Down Expand Up @@ -620,7 +620,7 @@ internal uint GeneratePixelBufferObject(BufferTargetARB target, PixelStoreParame
GL.BindBuffer(target, result);
if (RowPitch < 4)
GL.PixelStore(alignment, 1);
GL.BufferData(target, (UIntPtr) totalSize, IntPtr.Zero, bufferUsage);
GL.BufferData(target, (UIntPtr) totalSize, null, bufferUsage);
GL.BindBuffer(target, 0);

return result;
Expand Down
9 changes: 3 additions & 6 deletions sources/engine/Stride.Graphics/Texture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -474,10 +474,7 @@ internal Texture InitializeFrom(Texture parentTexture, TextureViewDescription vi
internal Texture InitializeFrom(Texture parentTexture, TextureDescription description, TextureViewDescription viewDescription, DataBox[] textureDatas = null)
{
ParentTexture = parentTexture;
if (ParentTexture != null)
{
ParentTexture.AddReferenceInternal();
}
ParentTexture?.AddReferenceInternal();

textureDescription = description;
textureViewDescription = viewDescription;
Expand Down Expand Up @@ -1143,8 +1140,8 @@ public Image GetDataAsImage(CommandList commandList)
if (Usage == GraphicsResourceUsage.Staging)
return GetDataAsImage(commandList, this); // Directly if this is a staging resource

using (var stagingTexture = ToStaging())
return GetDataAsImage(commandList, stagingTexture);
using var stagingTexture = ToStaging();
return GetDataAsImage(commandList, stagingTexture);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Stride.Rendering.Images
{
var u = 0.0;
var p = 0.5;
for (int kk=k; kk; p*=0.5, kk>>=1)
for (int kk=k; kk > 0; p*=0.5, kk>>=1)
{
if (kk & 1) // kk mod 2 == 1
u += p;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,41 +96,37 @@ protected override void DrawCore(RenderDrawContext context)
{
for (int faceIndex = 0; faceIndex < faceCount; faceIndex++)
{
using (var outputView = output.ToTextureView(ViewType.Single, faceIndex, mipLevel))
using var outputView = output.ToTextureView(ViewType.Single, faceIndex, mipLevel);
var inputLevel = MathUtil.Log2(input.Width / output.Width);
if (mipLevel == 0 && DoNotFilterHighestLevel)
{
var inputLevel = MathUtil.Log2(input.Width / output.Width);
if (mipLevel == 0 && DoNotFilterHighestLevel)
if (input.Width >= output.Width && inputLevel < input.MipLevels && input.Format == output.Format)
{
if (input.Width >= output.Width && inputLevel < input.MipLevels && input.Format == output.Format)
{
// Optimization: make a simple copy of the texture when possible
var inputSubresource = inputLevel + faceIndex * input.MipLevels;
var outputSubresource = 0 + faceIndex * output.MipLevels;
context.CommandList.CopyRegion(input, inputSubresource, null, output, outputSubresource);
}
else // otherwise rescale the closest mipmap
{
var inputMipmapLevel = Math.Min(inputLevel, input.MipLevels - 1);
using (var inputView = input.ToTextureView(ViewType.Single, faceIndex, inputMipmapLevel))
{
scaler.SetInput(inputView);
scaler.SetOutput(outputView);
scaler.Draw(context);
}
}
// Optimization: make a simple copy of the texture when possible
var inputSubresource = inputLevel + faceIndex * input.MipLevels;
var outputSubresource = 0 + faceIndex * output.MipLevels;
context.CommandList.CopyRegion(input, inputSubresource, null, output, outputSubresource);
}
else
else // otherwise rescale the closest mipmap
{
shader.Parameters.Set(RadiancePrefilteringGGXNoComputeShaderKeys.Face, faceIndex);
shader.Parameters.Set(RadiancePrefilteringGGXNoComputeShaderKeys.Roughness, roughness);
shader.Parameters.Set(RadiancePrefilteringGGXNoComputeShaderKeys.MipmapCount, input.MipLevels - 1);
shader.Parameters.Set(RadiancePrefilteringGGXNoComputeShaderKeys.RadianceMap, input);
shader.Parameters.Set(RadiancePrefilteringGGXNoComputeShaderKeys.RadianceMapSize, input.Width);
shader.Parameters.Set(RadiancePrefilteringGGXNoComputeParams.NbOfSamplings, SamplingsCount);
shader.SetOutput(outputView);
shader.Draw(context);
var inputMipmapLevel = Math.Min(inputLevel, input.MipLevels - 1);
using var inputView = input.ToTextureView(ViewType.Single, faceIndex, inputMipmapLevel);
scaler.SetInput(inputView);
scaler.SetOutput(outputView);
scaler.Draw(context);
}
}
else
{
shader.Parameters.Set(RadiancePrefilteringGGXNoComputeShaderKeys.Face, faceIndex);
shader.Parameters.Set(RadiancePrefilteringGGXNoComputeShaderKeys.Roughness, roughness);
shader.Parameters.Set(RadiancePrefilteringGGXNoComputeShaderKeys.MipmapCount, input.MipLevels - 1);
shader.Parameters.Set(RadiancePrefilteringGGXNoComputeShaderKeys.RadianceMap, input);
shader.Parameters.Set(RadiancePrefilteringGGXNoComputeShaderKeys.RadianceMapSize, input.Width);
shader.Parameters.Set(RadiancePrefilteringGGXNoComputeParams.NbOfSamplings, SamplingsCount);
shader.SetOutput(outputView);
shader.Draw(context);
}
}

if (mipCount > 1)
Expand Down
1 change: 1 addition & 0 deletions sources/tools/Stride.StorageTool/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nupkg/*
11 changes: 11 additions & 0 deletions sources/tools/Stride.StorageTool/App.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Application xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="Stride.StorageTool.App"
RequestedThemeVariant="Default">
<!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. -->

<Application.Styles>
<FluentTheme />
<StyleInclude Source="avares://Avalonia.Controls.DataGrid/Themes/Fluent.xaml"/>
</Application.Styles>
</Application>
24 changes: 24 additions & 0 deletions sources/tools/Stride.StorageTool/App.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;

namespace Stride.StorageTool;

public partial class App : Application
{
public override void Initialize()
{
AvaloniaXamlLoader.Load(this);
}

public override void OnFrameworkInitializationCompleted()
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
var bundlePath = desktop.Args?.Length > 0 ? desktop.Args[0] : null;
desktop.MainWindow = new MainWindow(bundlePath);
}

base.OnFrameworkInitializationCompleted();
}
}
33 changes: 33 additions & 0 deletions sources/tools/Stride.StorageTool/MainWindow.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Stride.StorageTool.MainWindow"
Title="Stride.StorageTool">
<Grid RowDefinitions="Auto,*">
<Menu>
<MenuItem Header="_File">
<MenuItem Header="_Open bundle (Ctrl+O)" HotKey="Ctrl+O" Click="OpenBundle" />
<Separator/>
<MenuItem Header="_Exit (Ctrl+Q)" HotKey="Ctrl+Q" Click="Exit" />
</MenuItem>
</Menu>
<StackPanel VerticalAlignment="Center" Grid.Row="1" Name="WelcomePanel">
<TextBlock
FontSize="32"
FontWeight="SemiBold"
HorizontalAlignment="Center"
Text="Stride StorageTool" />
<TextBlock
FontSize="28"
TextAlignment="Center"
HorizontalAlignment="Center"
Text="Choose File > Open Bundle to open the .bundle file"/>
</StackPanel>
<DataGrid Grid.Row="1" Margin="20" Name="ObjectDataGrid" IsReadOnly="True"
GridLinesVisibility="All"
AutoGenerateColumns="True"
BorderThickness="1" BorderBrush="Gray"/>
</Grid>
</Window>
Loading

0 comments on commit 36c9807

Please sign in to comment.