Ejemplo n.º 1
0
        public static void Initialize(Device device, int resX, int resY)
        {
            int numQuads            = resX * resY;
            int numIndices          = numQuads * 6;
            int numParticlesMax     = 1024 * 1024; // million particles max
            int numIndicesParticles = numParticlesMax * 6;
            int numRandomNumbers    = 1024 * 1024; // million

            var indices          = new DataStream(sizeof(System.Int32) * numIndices, true, true);
            var indicesParticles = new DataStream(sizeof(System.Int32) * numIndicesParticles, true, true);

            var randomNumbers = new DataStream(sizeof(System.Single) * numRandomNumbers, true, true);

            for (int i = 0; i < numQuads; i++)
            {
                indices.Write(i * 4 + 0);
                indices.Write(i * 4 + 1);
                indices.Write(i * 4 + 2);

                indices.Write(i * 4 + 1);
                indices.Write(i * 4 + 3);
                indices.Write(i * 4 + 2);
            }
            indices.Position = 0;

            for (int i = 0; i < numParticlesMax; i++)
            {
                indicesParticles.Write(i * 4 + 0);
                indicesParticles.Write(i * 4 + 1);
                indicesParticles.Write(i * 4 + 2);

                indicesParticles.Write(i * 4 + 1);
                indicesParticles.Write(i * 4 + 3);
                indicesParticles.Write(i * 4 + 2);
            }
            indicesParticles.Position = 0;

            System.Random rand = new System.Random();

            for (int i = 0; i < numRandomNumbers; i++)
            {
                randomNumbers.Write((float)rand.NextDouble());
            }
            randomNumbers.Position = 0;

            // create the vertex layout and buffer
            m_FullResTriangleGridIndexBuffer = new Buffer(device, indices, sizeof(System.Int32) * numIndices, ResourceUsage.Default, BindFlags.IndexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);
            m_ParticleHelperIndexBuffer      = new Buffer(device, indicesParticles, sizeof(System.Int32) * numIndicesParticles, ResourceUsage.Default, BindFlags.IndexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);
            m_RandomNumbersBuffer            = GPUBufferObject.CreateBuffer(device, numRandomNumbers, 4, randomNumbers, true, false);
        }
Ejemplo n.º 2
0
        public static void Initialize(Device device, int resolutionX, int resolutionY)
        {
            RenderTargetSet.RenderTargetDescriptor rtDesc = new RenderTargetSet.RenderTargetDescriptor()
            {
                m_Format = SlimDX.DXGI.Format.R8G8B8A8_UNorm,
                m_HasDepth = false,
                m_Width = resolutionX,
                m_Height = resolutionY,
                m_NumSurfaces = 1,
            };

            m_DebugRenderTarget = RenderTargetManager.RequestRenderTargetFromPool(rtDesc);
            m_DebugAppendBuffer = GPUBufferObject.CreateBuffer(device, 1024, 8 * sizeof(uint), null, true, true);
        }
Ejemplo n.º 3
0
        public static void Initialize(Device device, int resolutionX, int resolutionY)
        {
            RenderTargetSet.RenderTargetDescriptor rtDesc = new RenderTargetSet.RenderTargetDescriptor()
            {
                m_Format      = SlimDX.DXGI.Format.R8G8B8A8_UNorm,
                m_HasDepth    = false,
                m_Width       = resolutionX,
                m_Height      = resolutionY,
                m_NumSurfaces = 1,
            };

            m_DebugRenderTarget = RenderTargetManager.RequestRenderTargetFromPool(rtDesc);
            m_DebugAppendBuffer = GPUBufferObject.CreateBuffer(device, 1024, 8 * sizeof(uint), null, true, true);
        }
Ejemplo n.º 4
0
        // Static functions
        static public GPUBufferObject CreateBuffer(Device device, int size, int elementSizeInBytes, DataStream stream = null, bool append = false, bool allowStaging = false)
        {
            GPUBufferObject newBuffer = new GPUBufferObject();

            // Variables
            newBuffer.m_Size = size;

            BindFlags bindFlags = BindFlags.ShaderResource | BindFlags.UnorderedAccess;

            BufferDescription description = new BufferDescription(size * elementSizeInBytes, ResourceUsage.Default, bindFlags, CpuAccessFlags.None, ResourceOptionFlags.StructuredBuffer, elementSizeInBytes);

            newBuffer.m_BufferObject = stream != null ? new Buffer(device, stream, description) : new Buffer(device, description);

            ShaderResourceViewDescription srvViewDesc = new ShaderResourceViewDescription
            {
                FirstElement = 0,
                ElementCount = size,
                Format       = Format.Unknown,
                Dimension    = ShaderResourceViewDimension.ExtendedBuffer,
                Flags        = 0,
            };

            newBuffer.m_ShaderResourceView = new ShaderResourceView(device, newBuffer.m_BufferObject, srvViewDesc);


            UnorderedAccessViewDescription uavDesc = new UnorderedAccessViewDescription
            {
                ArraySize    = 0,
                Dimension    = UnorderedAccessViewDimension.Buffer,
                ElementCount = size,
                Flags        = append ? UnorderedAccessViewBufferFlags.AllowAppend : UnorderedAccessViewBufferFlags.None,
                Format       = Format.Unknown,
                MipSlice     = 0
            };

            newBuffer.m_UnorderedAccessView = new UnorderedAccessView(device, newBuffer.m_BufferObject, uavDesc);

            if (allowStaging)
            {
                description = new BufferDescription(size * elementSizeInBytes, ResourceUsage.Staging, BindFlags.None, CpuAccessFlags.Read, ResourceOptionFlags.StructuredBuffer, elementSizeInBytes);
                newBuffer.m_StagingBufferObject = new Buffer(device, description);

                description = new BufferDescription(16, ResourceUsage.Staging, BindFlags.None, CpuAccessFlags.Read, ResourceOptionFlags.None, 4);
                newBuffer.m_StagingCountBufferObject = new Buffer(device, description);
            }

            return(newBuffer);
        }
Ejemplo n.º 5
0
        // Static functions
        static public GPUBufferObject CreateBuffer(Device device, int size, int elementSizeInBytes, DataStream stream = null, bool append = false, bool allowStaging = false)
        {
            GPUBufferObject newBuffer = new GPUBufferObject();

            // Variables
            newBuffer.m_Size = size;

            BindFlags bindFlags = BindFlags.ShaderResource | BindFlags.UnorderedAccess;

            BufferDescription description = new BufferDescription(size * elementSizeInBytes, ResourceUsage.Default, bindFlags, CpuAccessFlags.None, ResourceOptionFlags.StructuredBuffer, elementSizeInBytes);

            newBuffer.m_BufferObject = stream != null ? new Buffer(device, stream, description) : new Buffer(device, description);

            ShaderResourceViewDescription srvViewDesc = new ShaderResourceViewDescription
            {
                FirstElement = 0,
                ElementCount = size,
                Format = Format.Unknown,
                Dimension = ShaderResourceViewDimension.ExtendedBuffer,
                Flags = 0,
            };

            newBuffer.m_ShaderResourceView = new ShaderResourceView(device, newBuffer.m_BufferObject, srvViewDesc);


            UnorderedAccessViewDescription uavDesc = new UnorderedAccessViewDescription
            {
                ArraySize = 0,
                Dimension = UnorderedAccessViewDimension.Buffer,
                ElementCount = size,
                Flags = append ? UnorderedAccessViewBufferFlags.AllowAppend : UnorderedAccessViewBufferFlags.None,
                Format = Format.Unknown,
                MipSlice = 0
            };
            newBuffer.m_UnorderedAccessView = new UnorderedAccessView(device, newBuffer.m_BufferObject, uavDesc);

            if (allowStaging)
            {
                description = new BufferDescription(size * elementSizeInBytes, ResourceUsage.Staging, BindFlags.None, CpuAccessFlags.Read, ResourceOptionFlags.StructuredBuffer, elementSizeInBytes);
                newBuffer.m_StagingBufferObject = new Buffer(device, description);

                description = new BufferDescription(16, ResourceUsage.Staging, BindFlags.None, CpuAccessFlags.Read, ResourceOptionFlags.None, 4);
                newBuffer.m_StagingCountBufferObject = new Buffer(device, description);
            }

            return newBuffer;
        }
Ejemplo n.º 6
0
        // Static functions
        static public GPUBufferObject CreateBuffer(Device device, int size)
        {
            GPUBufferObject newBuffer = new GPUBufferObject();

            // Variables
            newBuffer.m_Size = size;

            BindFlags bindFlags = BindFlags.ShaderResource | BindFlags.UnorderedAccess;

            BufferDescription description = new BufferDescription(size * 4, ResourceUsage.Default, bindFlags, CpuAccessFlags.None, ResourceOptionFlags.StructuredBuffer, 4);

            newBuffer.m_BufferObject = new Buffer(device, description);

            ShaderResourceViewDescription srvViewDesc = new ShaderResourceViewDescription
            {
                ArraySize       = 0,
                ElementCount    = size,
                ElementWidth    = size,
                Format          = Format.Unknown,
                Dimension       = ShaderResourceViewDimension.Buffer,
                Flags           = 0,
                FirstArraySlice = 0,
                MostDetailedMip = 0,
                MipLevels       = 0
            };

            newBuffer.m_ShaderResourceView = new ShaderResourceView(device, newBuffer.m_BufferObject, srvViewDesc);


            UnorderedAccessViewDescription uavDesc = new UnorderedAccessViewDescription
            {
                ArraySize    = 0,
                Dimension    = UnorderedAccessViewDimension.Buffer,
                ElementCount = size,
                Flags        = UnorderedAccessViewBufferFlags.None,
                Format       = Format.Unknown,
                MipSlice     = 0
            };

            newBuffer.m_UnorderedAccessView = new UnorderedAccessView(device, newBuffer.m_BufferObject, uavDesc);

            return(newBuffer);
        }