Example #1
0
        public unsafe void EndCustomValidation()
        {
            if (validatedTargetCount < renderTargets.Count || hasChanged)
            {
                renderTargets.Resize(validatedTargetCount, false);

                // Recalculate shader sources
                ShaderSource = new ShaderMixinSource();
                ShaderSource.Macros.Add(new ShaderMacro("XENKO_RENDER_TARGET_COUNT", renderTargets.Count));
                for (var index = 0; index < renderTargets.Count; index++)
                {
                    var renderTarget = renderTargets[index];
                    if (index > 0)
                    {
                        ShaderSource.Compositions.Add($"ShadingColor{index}", renderTarget.Semantic.ShaderClass);
                    }
                }

                ShaderSource.Macros.Add(new ShaderMacro("XENKO_MULTISAMPLE_COUNT", (int)multisampleCount));
            }

            renderStage.Output.RenderTargetCount  = renderTargets.Count;
            renderStage.Output.MultisampleCount   = multisampleCount;
            renderStage.Output.DepthStencilFormat = depthStencilFormat;

            fixed(PixelFormat *formats = &renderStage.Output.RenderTargetFormat0)
            {
                for (int i = 0; i < renderTargets.Count; ++i)
                {
                    formats[i] = renderTargets[i].Format;
                }
            }
        }
Example #2
0
        public int GetId()
        {
            var id = idHelper.GetNextId();

            if (binaryArray.Count <= id * structSize)
            {
                var newSize = (id * 2) * structSize;
                if (newSize > MaxArraySizeExpoentialIncrement)
                {
                    newSize = (id + 1) * structSize;
                }
                rwLock.EnterWriteLock();
                binaryArray.Resize(newSize, false);
                rwLock.ExitWriteLock();
                if (logger.IsEnabled(LogLevel.Debug))
                {
                    logger.LogDebug("Resize struct array to {} * {} = {}", structSize, id + 1, binaryArray.Count);
                }
            }
            if (logger.IsEnabled(LogLevel.Debug))
            {
                logger.LogDebug("Getting new id {} on struct size {}.", id, StructSize);
            }
            return(id);
        }
Example #3
0
        private void PrepareRenderTargets(RenderDrawContext drawContext, Texture outputRenderTarget, Texture outputDepthStencil)
        {
            if (OpaqueRenderStage is null)
            {
                return;
            }

            var renderTargets = OpaqueRenderStage.OutputValidator.RenderTargets;

            currentRenderTargets.Resize(renderTargets.Count, false);

            for (int index = 0; index < renderTargets.Count; index++)
            {
                if (renderTargets[index].Semantic is ColorTargetSemantic && PostEffects is null && actualMultisampleCount == MultisampleCount.None)
                {
                    currentRenderTargets[index] = outputRenderTarget;
                }
Example #4
0
        /// <summary>
        /// Resolves the MSAA textures. Converts MSAA currentRenderTargets and currentDepthStencil into currentRenderTargetsNonMSAA and currentDepthStencilNonMSAA.
        /// </summary>
        /// <param name="drawContext">The draw context.</param>
        private void ResolveMSAA(RenderDrawContext drawContext)
        {
            // Resolve render targets
            currentRenderTargetsNonMSAA.Resize(currentRenderTargets.Count, false);
            for (int index = 0; index < currentRenderTargets.Count; index++)
            {
                var input = currentRenderTargets[index];

                var outputDescription = TextureDescription.New2D(input.ViewWidth, input.ViewHeight, 1, input.Format, TextureFlags.ShaderResource | TextureFlags.RenderTarget);
                var output            = PushScopedResource(drawContext.GraphicsContext.Allocator.GetTemporaryTexture2D(outputDescription));

                currentRenderTargetsNonMSAA[index] = output;
                ResolveMSAA(drawContext, input, output);
            }

            // Resolve depth buffer
            currentDepthStencilNonMSAA = ViewDepthStencil;
            ResolveMSAA(drawContext, currentDepthStencil, currentDepthStencilNonMSAA);
        }
        public int GetId()
        {
            var id = idHelper.GetNextId();

            if (binaryArray.Count <= id * structSize)
            {
                var newSize = (id * 2) * structSize;
                if (newSize > MaxArraySizeExpoentialIncrement)
                {
                    newSize = (id + 1) * structSize;
                }
                rwLock.EnterWriteLock();
                binaryArray.Resize(newSize, false);
                rwLock.ExitWriteLock();
                logger.Log(Logger.LogLevel.Debug, $"Resize struct array to " +
                           $"{structSize} * {id + 1} = {binaryArray.Count}", tag);
            }
            logger.Log(Logger.LogLevel.Debug, $"Getting new id {id} on struct size {StructSize}.", tag);
            return(id);
        }
Example #6
0
        private void PrepareRenderTargets(RenderDrawContext drawContext, Texture outputRenderTarget, Texture outputDepthStencil)
        {
            if (OpaqueRenderStage == null)
            {
                return;
            }

            var renderTargets = OpaqueRenderStage.OutputValidator.RenderTargets;

            currentRenderTargets.Resize(renderTargets.Count, false);

            for (int index = 0; index < renderTargets.Count; index++)
            {
                if (renderTargets[index].Semantic is ColorTargetSemantic && PostEffects == null && actualMultisampleCount == MultisampleCount.None)
                {
                    currentRenderTargets[index] = outputRenderTarget;
                }
                else
                {
                    var description        = renderTargets[index];
                    var textureDescription = TextureDescription.New2D(outputRenderTarget.Width, outputRenderTarget.Height, 1, description.Format, TextureFlags.RenderTarget | TextureFlags.ShaderResource, 1, GraphicsResourceUsage.Default, actualMultisampleCount);
                    currentRenderTargets[index] = PushScopedResource(drawContext.GraphicsContext.Allocator.GetTemporaryTexture2D(textureDescription));
                }

                drawContext.CommandList.ResourceBarrierTransition(currentRenderTargets[index], GraphicsResourceState.RenderTarget);
            }

            // Prepare depth buffer
            if (actualMultisampleCount == MultisampleCount.None)
            {
                currentDepthStencil = outputDepthStencil;
            }
            else
            {
                var description        = outputDepthStencil.Description;
                var textureDescription = TextureDescription.New2D(description.Width, description.Height, 1, description.Format, TextureFlags.DepthStencil | TextureFlags.ShaderResource, 1, GraphicsResourceUsage.Default, actualMultisampleCount);
                currentDepthStencil = PushScopedResource(drawContext.GraphicsContext.Allocator.GetTemporaryTexture2D(textureDescription));
            }
            drawContext.CommandList.ResourceBarrierTransition(currentDepthStencil, GraphicsResourceState.DepthWrite);
        }
Example #7
0
        private void InitializePrimitives(int from, int to)
        {
            var random = new Random();

            primitivePositions.Resize(to, true);
            primitiveRotations.Resize(to, true);
            primitiveVelocities.Resize(to, true);
            primitiveRotVelocities.Resize(to, true);
            primitiveColors.Resize(to, true);

            for (int i = from; i < to; ++i)
            {
                // initialize boxes

                var randX = random.Next(-AreaSize, AreaSize);
                var randY = random.Next(-AreaSize, AreaSize);
                var randZ = random.Next(-AreaSize, AreaSize);

                var velX    = random.NextDouble() * 4.0;
                var velY    = random.NextDouble() * 4.0;
                var velZ    = random.NextDouble() * 4.0;
                var ballVel = new Vector3((float)velX, (float)velY, (float)velZ);

                var rotVelX    = random.NextDouble();
                var rotVelY    = random.NextDouble();
                var rotVelZ    = random.NextDouble();
                var ballRotVel = new Vector3((float)rotVelX, (float)rotVelY, (float)rotVelZ);

                primitivePositions.Items[i]     = new Vector3(randX, randY, randZ);
                primitiveRotations.Items[i]     = Quaternion.Identity;
                primitiveVelocities.Items[i]    = ballVel;
                primitiveRotVelocities.Items[i] = ballRotVel;

                ref var color = ref primitiveColors.Items[i];
                color.R = (byte)(((primitivePositions[i].X / AreaSize) + 1f) / 2.0f * 255.0f);
                color.G = (byte)(((primitivePositions[i].Y / AreaSize) + 1f) / 2.0f * 255.0f);
                color.B = (byte)(((primitivePositions[i].Z / AreaSize) + 1f) / 2.0f * 255.0f);
                color.A = 255;
            }