public void CreateResources(
                Device logicalDevice,
                ShaderInputManager shaderInputManager,
                RenderPass renderPass,
                ReadOnlySpan <DeviceTexture> targets,
                ReadOnlySpan <IShaderInput> globalInputs)
            {
                //Update the shader inputs
                //TODO: Get rid of all the array allocation here
                var totalInputs = globalInputs.ToArray().Concat(renderObject.Inputs.ToArray());

                if (inputBlock == null)
                {
                    inputBlock = shaderInputManager.Allocate(totalInputs);
                }
                else
                {
                    inputBlock.Value.Update(totalInputs);
                }

                //Create a pipeline layout if we don't have one allready
                if (pipelineLayout == null)
                {
                    pipelineLayout = logicalDevice.CreatePipelineLayout(new PipelineLayoutCreateInfo(
                                                                            setLayouts: new [] { inputBlock.Value.Layout },
                                                                            pushConstantRanges: pushDataContainer.GetRanges()));
                }

                //Create a pipeline if we don't have one allready
                if (pipeline == null)
                {
                    pipeline = PipelineUtils.CreatePipeline(
                        logicalDevice,
                        renderPass,
                        pipelineLayout,
                        vertModule,
                        fragModule,
                        specializationContainer,
                        depthClamp,
                        depthBias,
                        targets,
                        renderObject);
                }
            }
Beispiel #2
0
        public RenderScene(Window window,
                           TextureInfo reflectionTexture,
                           ShaderProgram postVertProg,
                           ShaderProgram bloomFragProg,
                           ShaderProgram aoFragProg,
                           ShaderProgram gaussBlurFragProg,
                           ShaderProgram boxBlurFragProg,
                           ShaderProgram compositionFragProg,
                           Logger logger = null)
        {
            if (window == null)
            {
                throw new ArgumentNullException(nameof(window));
            }
            if (reflectionTexture.Texture == null)
            {
                throw new ArgumentNullException(nameof(reflectionTexture));
            }
            if (postVertProg == null)
            {
                throw new ArgumentNullException(nameof(postVertProg));
            }
            if (bloomFragProg == null)
            {
                throw new ArgumentNullException(nameof(bloomFragProg));
            }
            if (aoFragProg == null)
            {
                throw new ArgumentNullException(nameof(aoFragProg));
            }
            if (gaussBlurFragProg == null)
            {
                throw new ArgumentNullException(nameof(gaussBlurFragProg));
            }
            if (boxBlurFragProg == null)
            {
                throw new ArgumentNullException(nameof(boxBlurFragProg));
            }
            if (compositionFragProg == null)
            {
                throw new ArgumentNullException(nameof(compositionFragProg));
            }

            this.window = window;
            this.logger = logger;
            camera      = new Camera();

            //Create resources
            executor      = new TransientExecutor(window.LogicalDevice, window.GraphicsFamilyIndex);
            memoryPool    = new Memory.Pool(window.LogicalDevice, window.HostDevice, logger);
            stagingBuffer = new Memory.HostBuffer(
                window.LogicalDevice,
                memoryPool,
                BufferUsages.TransferSrc,
                size: ByteUtils.MegabyteToByte(16));
            sceneDataBuffer = new Memory.HostBuffer(
                window.LogicalDevice, memoryPool, BufferUsages.UniformBuffer,
                size: SceneData.SIZE * window.SwapchainCount);
            inputManager = new ShaderInputManager(window.LogicalDevice, logger);

            //Create techniques
            gbufferTechnique = new GBufferTechnique(this, logger);
            shadowTechnique  = new ShadowTechnique(this, logger);
            bloomTechnique   = new BloomTechnique(
                gbufferTechnique, postVertProg, bloomFragProg, gaussBlurFragProg, this, logger);
            aoTechnique = new AmbientOcclusionTechnique(
                gbufferTechnique, postVertProg, aoFragProg, boxBlurFragProg, this, logger);
            deferredTechnique = new DeferredTechnique(
                gbufferTechnique, shadowTechnique, bloomTechnique, aoTechnique,
                reflectionTexture, postVertProg, compositionFragProg,
                this, logger);
        }