Пример #1
0
 //internal FeaturesPerFormat(PixelFormat format, MultisampleCount maximumMultisampleCount, ComputeShaderFormatSupport computeShaderFormatSupport, FormatSupport formatSupport)
 internal FeaturesPerFormat(PixelFormat format, MultisampleCount maximumMultisampleCount, FormatSupport formatSupport)
 {
     Format = format;
     this.MultisampleCountMax = maximumMultisampleCount;
     //ComputeShaderFormatSupport = computeShaderFormatSupport;
     FormatSupport = formatSupport;
 }
Пример #2
0
 public RenderOutputDescription(PixelFormat renderTargetFormat, PixelFormat depthStencilFormat = PixelFormat.None, MultisampleCount multisampleCount = MultisampleCount.None) : this()
 {
     RenderTargetCount   = renderTargetFormat != PixelFormat.None ? 1 : 0;
     RenderTargetFormat0 = renderTargetFormat;
     DepthStencilFormat  = depthStencilFormat;
     MultisampleCount    = multisampleCount;
 }
        private void EnumerateMSAASupportPerFormat(GraphicsDevice deviceRoot)
        {
            // Query OpenGL for the highest supported multisample count:
            int globalMaxMSAASamples;

            GL.GetInteger(GL_MAX_SAMPLES, out globalMaxMSAASamples);

            // Now select the highest engine-supported multisample mode:    // TODO: Adjust comment.
            MultisampleCount actualMultisampleCount = MultisampleCount.None;

            // Technically we could just cast "globalMaxMSAASamples" to "actualMultisampleCount",
            // but AFAIK nothing prevents an implementation from exposing things like 6x MSAA or some other uncommon mode.
            if (globalMaxMSAASamples >= 8)
            {
                // If the maximum supported MSAA mode by the OpenGL implementation is higher than the maximum supported by the engine (8xMSAA), we clamp it.
                actualMultisampleCount = MultisampleCount.X8;
            }
            else if (globalMaxMSAASamples >= 4)
            {
                // If the maximum supported MSAA mode by the OpenGL implementation is between 4 and 7 samples, we fall back to the next lowest engine-supported one (4x).
                actualMultisampleCount = MultisampleCount.X4; // 4-7 x MSAA => 4 x MSAA (next lowest)
            }
            else if (globalMaxMSAASamples == 2)
            {
                // If the maximum supported MSAA mode by the OpenGL implementation is between 2 and 3 samples, we fall back to the next lowest engine-supported one (2x).
                actualMultisampleCount = MultisampleCount.X2;
            }

            for (int i = 0; i < mapFeaturesPerFormat.Length; i++)
            {
                // 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).
                mapFeaturesPerFormat[i] = new FeaturesPerFormat((PixelFormat)i, actualMultisampleCount, FormatSupport.None);
            }
        }
Пример #4
0
        protected override void InitializeCore()
        {
            base.InitializeCore();

            shadowMapRenderer = Context.RenderSystem.RenderFeatures
                                .OfType <MeshRenderFeature>().FirstOrDefault()?.RenderFeatures
                                .OfType <ForwardLightingRenderFeature>().FirstOrDefault()?.ShadowMapRenderer;

            if (MSAALevel != MultisampleCount.None)
            {
                actualMultisampleCount = (MultisampleCount)Math.Min((int)MSAALevel, (int)GraphicsDevice.Features[PixelFormat.R16G16B16A16_Float].MultisampleCountMax);
                actualMultisampleCount = (MultisampleCount)Math.Min((int)actualMultisampleCount, (int)GraphicsDevice.Features[DepthBufferFormat].MultisampleCountMax);

                // TODO: We cannot support MSAA on DX10 now
                //   Direct3D has MSAA support starting from version 11 because it requires multisample depth buffers as shader resource views.
                //   Therefore we force-disable MSAA on any platform that doesn't support MSAA.

                if (actualMultisampleCount != MSAALevel)
                {
                    logger.Warning($"Multisample count of {(int) MSAALevel} samples is not supported. Falling back to highest supported sample count of {(int) actualMultisampleCount} samples.");
                }
            }

            var camera = Context.GetCurrentCamera();
        }
Пример #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PresentationParameters" /> class with default values.
 /// </summary>
 public PresentationParameters()
 {
     BackBufferWidth      = 800;
     BackBufferHeight     = 480;
     BackBufferFormat     = PixelFormat.R8G8B8A8_UNorm;
     PresentationInterval = PresentInterval.Immediate;
     DepthStencilFormat   = PixelFormat.D24_UNorm_S8_UInt;
     MultisampleCount     = MultisampleCount.None;
     IsFullScreen         = false;
     RefreshRate          = new Rational(60, 1); // by default
     ColorSpace           = ColorSpace.Linear;
 }
 /// <summary>
 /// Sets default values for this instance.
 /// </summary>
 public void SetDefault()
 {
     CullMode                  = CullMode.Back;
     FillMode                  = FillMode.Solid;
     DepthClipEnable           = true;
     FrontFaceCounterClockwise = false;
     ScissorTestEnable         = false;
     MultisampleCount          = MultisampleCount.None;
     MultisampleAntiAliasLine  = false;
     DepthBias                 = 0;
     DepthBiasClamp            = 0f;
     SlopeScaleDepthBias       = 0f;
 }
Пример #7
0
 /// <summary>
 /// Creates a new 2D <see cref="Texture" />.
 /// </summary>
 /// <param name="device">The <see cref="GraphicsDevice"/>.</param>
 /// <param name="width">The width.</param>
 /// <param name="height">The height.</param>
 /// <param name="format">Describes the format to use.</param>
 /// <param name="mipCount">Number of mipmaps, set to true to have all mipmaps, set to an int >=1 for a particular mipmap count.</param>
 /// <param name="textureData">Texture datas through an array of <see cref="DataBox"/> </param>
 /// <param name="textureFlags">true if the texture needs to support unordered read write.</param>
 /// <param name="arraySize">Size of the texture 2D array, default to 1.</param>
 /// <param name="usage">The usage.</param>
 /// <param name="multisampleCount">The multisample count.</param>
 /// <returns>A new instance of 2D <see cref="Texture" /> class.</returns>
 public static Texture New2D(
     GraphicsDevice device,
     int width,
     int height,
     MipMapCount mipCount,
     PixelFormat format,
     DataBox[] textureData,
     TextureFlags textureFlags         = TextureFlags.ShaderResource,
     int arraySize                     = 1,
     GraphicsResourceUsage usage       = GraphicsResourceUsage.Default,
     MultisampleCount multisampleCount = MultisampleCount.None)
 {
     return(new Texture(device).InitializeFrom(TextureDescription.New2D(width, height, mipCount, format, textureFlags, arraySize, usage, multisampleCount), textureData));
 }
Пример #8
0
        public void BeginCustomValidation(PixelFormat depthStencilFormat, MultisampleCount multisampleCount = MultisampleCount.None)
        {
            validatedTargetCount = 0;
            hasChanged           = false;

            if (this.depthStencilFormat != depthStencilFormat)
            {
                hasChanged = true;
                this.depthStencilFormat = depthStencilFormat;
            }
            if (this.multisampleCount != multisampleCount)
            {
                hasChanged            = true;
                this.multisampleCount = multisampleCount;
            }
        }
Пример #9
0
        public unsafe void CaptureState(CommandList commandList)
        {
            DepthStencilFormat = commandList.DepthStencilBuffer != null ? commandList.DepthStencilBuffer.ViewFormat : PixelFormat.None;
            MultisampleCount   = commandList.DepthStencilBuffer != null ? commandList.DepthStencilBuffer.MultisampleCount : MultisampleCount.None;

            RenderTargetCount = commandList.RenderTargetCount;
            fixed(PixelFormat *renderTargetFormat0 = &RenderTargetFormat0)
            {
                var renderTargetFormat = renderTargetFormat0;

                for (int i = 0; i < RenderTargetCount; ++i)
                {
                    *renderTargetFormat++ = commandList.RenderTargets[i].ViewFormat;
                    MultisampleCount = commandList.RenderTargets[i].MultisampleCount; // multisample should all be equal
                }
            }
        }
Пример #10
0
        public void Validate(ref RenderOutputDescription renderOutput)
        {
            hasChanged = false;
            if (multisampleCount != renderOutput.MultisampleCount)
            {
                hasChanged       = true;
                multisampleCount = renderOutput.MultisampleCount;
            }

            if (hasChanged)
            {
                // Recalculate shader sources
                ShaderSource = new ShaderMixinSource();
                ShaderSource.Macros.Add(new ShaderMacro("XENKO_MULTISAMPLE_COUNT", (int)multisampleCount));
            }

            renderStage.Output = renderOutput;
        }
        private static TextureDescription New2D(int width, int height, PixelFormat format, TextureFlags textureFlags, int mipCount, int arraySize, GraphicsResourceUsage usage, MultisampleCount multisampleCount, TextureOptions textureOptions = TextureOptions.None)
        {
            if ((textureFlags & TextureFlags.UnorderedAccess) != 0)
            {
                usage = GraphicsResourceUsage.Default;
            }

            var desc = new TextureDescription
            {
                Dimension        = TextureDimension.Texture2D,
                Width            = width,
                Height           = height,
                Depth            = 1,
                ArraySize        = arraySize,
                MultisampleCount = multisampleCount,
                Flags            = textureFlags,
                Format           = format,
                MipLevels        = Texture.CalculateMipMapCount(mipCount, width, height),
                Usage            = Texture.GetUsageWithFlags(usage, textureFlags),
                Options          = textureOptions
            };

            return(desc);
        }
 /// <summary>
 /// Creates a new <see cref="TextureDescription" />.
 /// </summary>
 /// <param name="width">The width.</param>
 /// <param name="height">The height.</param>
 /// <param name="mipCount">Number of mipmaps, set to true to have all mipmaps, set to an int &gt;=1 for a particular mipmap count.</param>
 /// <param name="format">Describes the format to use.</param>
 /// <param name="textureFlags">true if the texture needs to support unordered read write.</param>
 /// <param name="arraySize">Size of the texture 2D array, default to 1.</param>
 /// <param name="usage">The usage.</param>
 /// <param name="multisampleCount">The multisample count.</param>
 /// <returns>A new instance of <see cref="TextureDescription" /> class.</returns>
 public static TextureDescription New2D(int width, int height, MipMapCount mipCount, PixelFormat format, TextureFlags textureFlags = TextureFlags.ShaderResource, int arraySize = 1, GraphicsResourceUsage usage = GraphicsResourceUsage.Default, MultisampleCount multisampleCount = MultisampleCount.None, TextureOptions textureOptions = TextureOptions.None)
 {
     return(New2D(width, height, format, textureFlags, mipCount, arraySize, usage, multisampleCount, textureOptions));
 }
Пример #13
0
        public static bool DisposeTextureBySpecs(Texture tex, Vector3 dim, PixelFormat pixelFormat, MultisampleCount samples)
        {
            if (tex is null ||
                !TextureDimensionsEqual(tex, dim) ||
                tex.Format != pixelFormat ||
                tex.MultisampleCount != samples)
            {
                if (tex != null)
                {
                    tex.Dispose();
                }

                return(true);
            }
            return(false);
        }
Пример #14
0
        protected override void InitializeCore()
        {
            base.InitializeCore();

            shadowMapRenderer = Context.RenderSystem.RenderFeatures.OfType <MeshRenderFeature>().FirstOrDefault()?.RenderFeatures.OfType <ForwardLightingRenderFeature>().FirstOrDefault()?.ShadowMapRenderer;

            if (MSAALevel != MultisampleCount.None)
            {
                actualMultisampleCount = (MultisampleCount)Math.Min((int)MSAALevel, (int)GraphicsDevice.Features[PixelFormat.R16G16B16A16_Float].MultisampleCountMax);
                actualMultisampleCount = (MultisampleCount)Math.Min((int)actualMultisampleCount, (int)GraphicsDevice.Features[DepthBufferFormat].MultisampleCountMax);

                // Note: we cannot support MSAA on DX10 now
                if (GraphicsDevice.Features.HasMultisampleDepthAsSRV == false)
                {
                    actualMultisampleCount = MultisampleCount.None;
                }
            }

            var camera = Context.GetCurrentCamera();

            vrSystem = Services.GetService <VRDeviceSystem>();
            if (vrSystem != null)
            {
                if (VRSettings.Enabled)
                {
                    var requiredDescs = VRSettings.RequiredApis.ToArray();
                    vrSystem.PreferredApis = requiredDescs.Select(x => x.Api).Distinct().ToArray();

                    // remove VR API duplicates and keep first desired config only
                    var preferredScalings = new Dictionary <VRApi, float>();
                    foreach (var desc in requiredDescs)
                    {
                        if (!preferredScalings.ContainsKey(desc.Api))
                        {
                            preferredScalings[desc.Api] = desc.ResolutionScale;
                        }
                    }
                    vrSystem.PreferredScalings = preferredScalings;

                    vrSystem.RequireMirror = VRSettings.CopyMirror;
                    vrSystem.MirrorWidth   = GraphicsDevice.Presenter.BackBuffer.Width;
                    vrSystem.MirrorHeight  = GraphicsDevice.Presenter.BackBuffer.Height;

                    vrSystem.Enabled = true; //careful this will trigger the whole chain of initialization!
                    vrSystem.Visible = true;

                    VRSettings.VRDevice = vrSystem.Device;

                    vrSystem.PreviousUseCustomProjectionMatrix = camera.UseCustomProjectionMatrix;
                    vrSystem.PreviousUseCustomViewMatrix       = camera.UseCustomViewMatrix;
                    vrSystem.PreviousCameraProjection          = camera.ProjectionMatrix;

                    if (VRSettings.VRDevice.SupportsOverlays)
                    {
                        foreach (var overlay in VRSettings.Overlays)
                        {
                            if (overlay != null && overlay.Texture != null)
                            {
                                overlay.Overlay = VRSettings.VRDevice.CreateOverlay(overlay.Texture.Width, overlay.Texture.Height, overlay.Texture.MipLevels, (int)overlay.Texture.MultisampleCount);
                            }
                        }
                    }
                }
                else
                {
                    vrSystem.Enabled = false;
                    vrSystem.Visible = false;

                    VRSettings.VRDevice = null;

                    if (vrSystem.Device != null) //we had a device before so we know we need to restore the camera
                    {
                        camera.UseCustomViewMatrix       = vrSystem.PreviousUseCustomViewMatrix;
                        camera.UseCustomProjectionMatrix = vrSystem.PreviousUseCustomProjectionMatrix;
                        camera.ProjectionMatrix          = vrSystem.PreviousCameraProjection;
                    }
                }
            }
        }
Пример #15
0
        protected override void InitializeCore()
        {
            base.InitializeCore();

            shadowMapRenderer = Context.RenderSystem.RenderFeatures.OfType <MeshRenderFeature>().FirstOrDefault()?.RenderFeatures.OfType <ForwardLightingRenderFeature>().FirstOrDefault()?.ShadowMapRenderer;

            if (MSAALevel != MultisampleCount.None)
            {
                actualMultisampleCount = (MultisampleCount)Math.Min((int)MSAALevel, (int)GraphicsDevice.Features[PixelFormat.R16G16B16A16_Float].MultisampleCountMax);
                actualMultisampleCount = (MultisampleCount)Math.Min((int)actualMultisampleCount, (int)GraphicsDevice.Features[DepthBufferFormat].MultisampleCountMax);

                // Note: we cannot support MSAA on DX10 now
                if (GraphicsDevice.Features.HasMultisampleDepthAsSRV == false &&     // TODO: Try enabling MSAA on DX9!
                    GraphicsDevice.Platform != GraphicsPlatform.OpenGL &&
                    GraphicsDevice.Platform != GraphicsPlatform.OpenGLES)
                {
                    // OpenGL has MSAA support on every version.
                    // OpenGL ES has MSAA support starting from version 3.0.
                    // Direct3D has MSAA support starting from version 11 because it requires multisample depth buffers as shader resource views.
                    // Therefore we force-disable MSAA on any platform that doesn't support MSAA.

                    actualMultisampleCount = MultisampleCount.None;
                }

                if (actualMultisampleCount != MSAALevel)
                {
                    logger.Warning("Multisample count of " + (int)MSAALevel + " samples not supported. Falling back to highest supported sample count of " + (int)actualMultisampleCount + " samples.");
                }

#if XENKO_PLATFORM_IOS
                // MSAA is not supported on iOS currently because OpenTK doesn't expose "GL.BlitFramebuffer()" on iOS for some reason.
                actualMultisampleCount = MultisampleCount.None;
#endif
            }

            var camera = Context.GetCurrentCamera();

            vrSystem = Services.GetService <VRDeviceSystem>();
            if (vrSystem != null)
            {
                if (VRSettings.Enabled)
                {
                    var requiredDescs = VRSettings.RequiredApis.ToArray();
                    vrSystem.PreferredApis = requiredDescs.Select(x => x.Api).Distinct().ToArray();

                    // remove VR API duplicates and keep first desired config only
                    var preferredScalings = new Dictionary <VRApi, float>();
                    foreach (var desc in requiredDescs)
                    {
                        if (!preferredScalings.ContainsKey(desc.Api))
                        {
                            preferredScalings[desc.Api] = desc.ResolutionScale;
                        }
                    }
                    vrSystem.PreferredScalings = preferredScalings;

                    vrSystem.RequireMirror = VRSettings.CopyMirror;
                    vrSystem.MirrorWidth   = GraphicsDevice.Presenter.BackBuffer.Width;
                    vrSystem.MirrorHeight  = GraphicsDevice.Presenter.BackBuffer.Height;

                    vrSystem.Enabled = true; //careful this will trigger the whole chain of initialization!
                    vrSystem.Visible = true;

                    VRSettings.VRDevice = vrSystem.Device;

                    vrSystem.PreviousUseCustomProjectionMatrix = camera.UseCustomProjectionMatrix;
                    vrSystem.PreviousUseCustomViewMatrix       = camera.UseCustomViewMatrix;
                    vrSystem.PreviousCameraProjection          = camera.ProjectionMatrix;

                    if (VRSettings.VRDevice.SupportsOverlays)
                    {
                        foreach (var overlay in VRSettings.Overlays)
                        {
                            if (overlay != null && overlay.Texture != null)
                            {
                                overlay.Overlay = VRSettings.VRDevice.CreateOverlay(overlay.Texture.Width, overlay.Texture.Height, overlay.Texture.MipLevels, (int)overlay.Texture.MultisampleCount);
                            }
                        }
                    }
                }
                else
                {
                    vrSystem.Enabled = false;
                    vrSystem.Visible = false;

                    VRSettings.VRDevice = null;

                    if (vrSystem.Device != null) //we had a device before so we know we need to restore the camera
                    {
                        camera.UseCustomViewMatrix       = vrSystem.PreviousUseCustomViewMatrix;
                        camera.UseCustomProjectionMatrix = vrSystem.PreviousUseCustomProjectionMatrix;
                        camera.ProjectionMatrix          = vrSystem.PreviousCameraProjection;
                    }
                }
            }
        }
    private bool NeedToRecreateTexture(Xenko.Graphics.Texture tex, Vector3 dim, Xenko.Graphics.PixelFormat pixelFormat, MultisampleCount samples)
    {
        if (tex == null || !TextureDimensionsEqual(tex, dim) || tex.Format != pixelFormat || tex.MultisampleCount != samples)
        {
            if (tex != null)
            {
                tex.Dispose();
            }

            return(true);
        }
        return(false);
    }