Skip to content

Commit

Permalink
VR: Update to latest OpenXR (and Silk.NET AssImp), may fix validation…
Browse files Browse the repository at this point in the history
… error
  • Loading branch information
phr00t committed Jun 18, 2023
1 parent b815c07 commit bb105bb
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 31 deletions.
53 changes: 28 additions & 25 deletions sources/engine/Xenko.VirtualReality/OpenXR/OpenXRHmd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ public unsafe ulong GetSwapchainImage()
{
// Get the swapchain image
var swapchainIndex = 0u;
var acquireInfo = new SwapchainImageAcquireInfo() { Type = StructureType.TypeSwapchainImageAcquireInfo };
var acquireInfo = new SwapchainImageAcquireInfo() { Type = StructureType.SwapchainImageAcquireInfo };
CheckResult(Xr.AcquireSwapchainImage(globalSwapchain, in acquireInfo, ref swapchainIndex), "AcquireSwapchainImage");

var waitInfo = new SwapchainImageWaitInfo(timeout: long.MaxValue) { Type = StructureType.TypeSwapchainImageWaitInfo };
var waitInfo = new SwapchainImageWaitInfo(timeout: long.MaxValue) { Type = StructureType.SwapchainImageWaitInfo };
swapImageCollected = Xr.WaitSwapchainImage(globalSwapchain, in waitInfo) == Result.Success;

return images[swapchainIndex].Image;
Expand All @@ -108,7 +108,7 @@ private unsafe void Prepare()
Xr.EnumerateInstanceExtensionProperties((byte*)null, 0, &propCount, null);

ExtensionProperties[] props = new ExtensionProperties[propCount];
for (int i = 0; i < props.Length; i++) props[i].Type = StructureType.TypeExtensionProperties;
for (int i = 0; i < props.Length; i++) props[i].Type = StructureType.ExtensionProperties;

fixed (ExtensionProperties* pptr = &props[0])
Xr.EnumerateInstanceExtensionProperties((byte*)null, propCount, ref propCount, pptr);
Expand Down Expand Up @@ -272,13 +272,13 @@ public override unsafe void Flush()
begunFrame = false;

// Release the swapchain image
var releaseInfo = new SwapchainImageReleaseInfo() { Type = StructureType.TypeSwapchainImageReleaseInfo };
var releaseInfo = new SwapchainImageReleaseInfo() { Type = StructureType.SwapchainImageReleaseInfo };
CheckResult(Xr.ReleaseSwapchainImage(globalSwapchain, in releaseInfo), "ReleaseSwapchainImage");

// https://github.com/dotnet/Silk.NET/blob/b0b31779ce4db9b68922977fa11772b95f506e09/examples/CSharp/OpenGL%20Demos/OpenGL%20VR%20Demo/OpenXR/Renderer.cs#L507
var frameEndInfo = new FrameEndInfo()
{
Type = StructureType.TypeFrameEndInfo,
Type = StructureType.FrameEndInfo,
DisplayTime = globalFrameState.PredictedDisplayTime,
EnvironmentBlendMode = EnvironmentBlendMode.Opaque
};
Expand Down Expand Up @@ -321,7 +321,7 @@ public override unsafe void UpdatePositions(GameTime gameTime)

ActionsSyncInfo actions_sync_info = new ActionsSyncInfo()
{
Type = StructureType.TypeActionsSyncInfo,
Type = StructureType.ActionsSyncInfo,
CountActiveActionSets = 1,
ActiveActionSets = &active_actionsets,
};
Expand All @@ -334,15 +334,15 @@ public override unsafe void UpdatePositions(GameTime gameTime)
// --- Create projection matrices and view matrices for each eye
ViewLocateInfo view_locate_info = new ViewLocateInfo()
{
Type = StructureType.TypeViewLocateInfo,
Type = StructureType.ViewLocateInfo,
ViewConfigurationType = ViewConfigurationType.PrimaryStereo,
DisplayTime = globalFrameState.PredictedDisplayTime,
Space = globalPlaySpace
};

ViewState view_state = new ViewState()
{
Type = StructureType.TypeViewState
Type = StructureType.ViewState
};

uint view_count;
Expand All @@ -369,7 +369,7 @@ public override unsafe void Draw(GameTime gameTime)
// --- Wait for our turn to do head-pose dependent computation and render a frame
FrameWaitInfo frame_wait_info = new FrameWaitInfo()
{
Type = StructureType.TypeFrameWaitInfo,
Type = StructureType.FrameWaitInfo,
};

CheckResult(Xr.WaitFrame(globalSession, in frame_wait_info, ref globalFrameState), "WaitFrame");
Expand Down Expand Up @@ -464,17 +464,20 @@ public override unsafe void Enable(GraphicsDevice device, GraphicsDeviceManager
Prepare();

SystemProperties system_props = new SystemProperties() {
Type = StructureType.TypeSystemProperties,
Type = StructureType.SystemProperties,
};

CheckResult(Xr.GetSystemProperties(Instance, system_id, &system_props), "GetSystemProperties");

ViewConfigurationView vcv = new ViewConfigurationView()
viewconfig_views = new ViewConfigurationView[32];
for (int i=0; i<viewconfig_views.Length; i++)
{
Type = StructureType.TypeViewConfigurationView,
};
viewconfig_views[i] = new ViewConfigurationView()
{
Type = StructureType.ViewConfigurationView,
};
}

viewconfig_views = new ViewConfigurationView[128];
fixed (ViewConfigurationView* viewspnt = &viewconfig_views[0])
CheckResult(Xr.EnumerateViewConfigurationView(Instance, system_id, view_type, (uint)viewconfig_views.Length, ref view_count, viewspnt), "EnumerateViewConfigurationView");
Array.Resize<ViewConfigurationView>(ref viewconfig_views, (int)view_count);
Expand All @@ -485,7 +488,7 @@ public override unsafe void Enable(GraphicsDevice device, GraphicsDeviceManager

GraphicsRequirementsVulkanKHR vulk = new GraphicsRequirementsVulkanKHR()
{
Type = StructureType.TypeGraphicsRequirementsVulkanKhr
Type = StructureType.GraphicsRequirementsVulkanKhr
};

Silk.NET.Core.PfnVoidFunction func = new Silk.NET.Core.PfnVoidFunction();
Expand Down Expand Up @@ -561,7 +564,7 @@ public override unsafe void Enable(GraphicsDevice device, GraphicsDeviceManager
Window.GenerateGenericError(null, "OpenXR couldn't find a physical device.\n\nIs an OpenXR runtime running (e.g. SteamVR)?");

SessionCreateInfo session_create_info = new SessionCreateInfo() {
Type = StructureType.TypeSessionCreateInfo,
Type = StructureType.SessionCreateInfo,
Next = &graphics_binding_vulkan,
SystemId = system_id
};
Expand All @@ -585,10 +588,10 @@ public override unsafe void Enable(GraphicsDevice device, GraphicsDeviceManager
swapchain = new Swapchain();
swapchain_lengths = new uint[1];
SwapchainCreateInfo swapchain_create_info = new SwapchainCreateInfo() {
Type = StructureType.TypeSwapchainCreateInfo,
UsageFlags = SwapchainUsageFlags.SwapchainUsageTransferDstBit |
SwapchainUsageFlags.SwapchainUsageSampledBit |
SwapchainUsageFlags.SwapchainUsageColorAttachmentBit,
Type = StructureType.SwapchainCreateInfo,
UsageFlags = SwapchainUsageFlags.TransferDstBit |
SwapchainUsageFlags.SampledBit |
SwapchainUsageFlags.ColorAttachmentBit,
CreateFlags = 0,
Format = (long)43, // VK_FORMAT_R8G8B8A8_SRGB = 43
SampleCount = 1, //viewconfig_views[0].RecommendedSwapchainSampleCount,
Expand Down Expand Up @@ -678,12 +681,12 @@ public override unsafe void Enable(GraphicsDevice device, GraphicsDeviceManager
// Do not allocate these every frame to save some resources
views = new View[view_count]; //(XrView*)malloc(sizeof(XrView) * view_count);
for (int i = 0; i < view_count; i++)
views[i].Type = StructureType.TypeView;
views[i].Type = StructureType.View;

projection_views = new CompositionLayerProjectionView[view_count]; //(XrCompositionLayerProjectionView*)malloc(sizeof(XrCompositionLayerProjectionView) * view_count);
for (int i = 0; i < view_count; i++)
{
projection_views[i].Type = StructureType.TypeCompositionLayerProjectionView; //XR_TYPE_COMPOSITION_LAYER_PROJECTION_VIEW;
projection_views[i].Type = StructureType.CompositionLayerProjectionView; //XR_TYPE_COMPOSITION_LAYER_PROJECTION_VIEW;
projection_views[i].SubImage.Swapchain = swapchain;
projection_views[i].SubImage.ImageArrayIndex = 0;
projection_views[i].SubImage.ImageRect.Offset.X = (renderSize.Width * i) / 2;
Expand Down Expand Up @@ -744,23 +747,23 @@ public override unsafe void Enable(GraphicsDevice device, GraphicsDeviceManager
// --- Begin session */
SessionBeginInfo session_begin_info = new SessionBeginInfo()
{
Type = StructureType.TypeSessionBeginInfo,
Type = StructureType.SessionBeginInfo,
PrimaryViewConfigurationType = view_type
};

CheckResult(Xr.BeginSession(session, &session_begin_info), "BeginSession");

SessionActionSetsAttachInfo actionset_attach_info = new SessionActionSetsAttachInfo()
{
Type = StructureType.TypeSessionActionSetsAttachInfo,
Type = StructureType.SessionActionSetsAttachInfo,
CountActionSets = 1,
ActionSets = &gameplay_actionset
};

CheckResult(Xr.AttachSessionActionSets(session, &actionset_attach_info), "AttachSessionActionSets");

// figure out what interaction profile we are using, and determine if it has a touchpad/thumbstick or both
handProfileState.Type = StructureType.TypeInteractionProfileState;
handProfileState.Type = StructureType.InteractionProfileState;
Xr.StringToPath(Instance, "/user/hand/left", ref leftHandPath);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<Project>{84deb606-77ed-49cd-9aed-d2b13c1f5a1e}</Project>
<Name>Xenko.Input</Name>
</ProjectReference>
<PackageReference Include="Silk.NET.OpenXR" Version="2.16.0" />
<PackageReference Include="Silk.NET.OpenXR" Version="2.17.1" />
<PackageReference Include="Microsoft.Win32.Registry" Version="5.0.0" />
</ItemGroup>
<Import Project="$(XenkoPostSettingsTargets)" />
Expand Down
2 changes: 1 addition & 1 deletion sources/shared/SharedAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ internal class XenkoVersion
/// <summary>
/// This version will be shown in the editor and actually is the version. Can be changed without triggering weird NuGet behavior.
/// </summary>
public const string VersionToShowInEditor = "4.13.8";
public const string VersionToShowInEditor = "4.13.9";

/// <summary>1
/// The current assembly version as text, currently same as <see cref="PublicVersion"/>.
Expand Down
6 changes: 3 additions & 3 deletions sources/tools/Xenko.Importer.Assimp/MeshConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public unsafe AnimationInfo ConvertAnimation(string inputFilename, string output
return ProcessAnimations(scene);
}

public unsafe Skeleton ConvertSkeleton(string inputFilename, string outputFilename)
public unsafe Xenko.Rendering.Skeleton ConvertSkeleton(string inputFilename, string outputFilename)
{
uint importFlags = 0;
var postProcessFlags = PostProcessSteps.None;
Expand Down Expand Up @@ -229,7 +229,7 @@ private unsafe Model ConvertAssimpScene(Scene* scene)
return modelData;
}

private unsafe Skeleton ProcessSkeleton(Scene* scene)
private unsafe Xenko.Rendering.Skeleton ProcessSkeleton(Scene* scene)
{
var nodeNames = new Dictionary<IntPtr, string>();
GenerateNodeNames(scene, nodeNames);
Expand All @@ -238,7 +238,7 @@ private unsafe Skeleton ProcessSkeleton(Scene* scene)
var meshIndexToNodeIndex = new Dictionary<int, List<int>>();
RegisterNodes(scene->MRootNode, -1, nodeNames, meshIndexToNodeIndex);

return new Skeleton
return new Xenko.Rendering.Skeleton
{
Nodes = nodes.ToArray()
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<_SettingsFiles Remove="Analysis\**" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Silk.NET.Assimp" Version="2.16.0" />
<PackageReference Include="Silk.NET.Assimp" Version="2.17.1" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
Expand Down

0 comments on commit bb105bb

Please sign in to comment.