コード例 #1
0
 public static ShaderResourceView FromTexture2D(GraphicsResource resource, PixelFormat format)
 {
     return(new ShaderResourceView(resource, new ShaderResourceViewDescription
     {
         Shader4ComponentMapping = D3DXUtilities.DefaultComponentMapping(),
         ViewDimension = ShaderResourceViewDimension.Texture2D,
         Format = (Format)format,
         Texture2D =
         {
             MipLevels = resource.Description.MipLevels
         }
     }));
 }
コード例 #2
0
 public static ShaderResourceView FromBuffer(GraphicsResource resource, long firstElement, int elementCount, int structureByteStride)
 {
     return(new ShaderResourceView(resource, new ShaderResourceViewDescription
     {
         Shader4ComponentMapping = D3DXUtilities.DefaultComponentMapping(),
         ViewDimension = ShaderResourceViewDimension.Buffer,
         Buffer =
         {
             FirstElement        = firstElement,
             NumElements         = elementCount,
             StructureByteStride = structureByteStride
         }
     }));
 }
コード例 #3
0
        public override void Load(string path2)
        {
            if (done)
            {
                return;
            }
            done = true;

            Bitmap bm = new Bitmap(path);

            Width  = bm.Width;
            Height = bm.Height;
            Depth  = 4;

            var textureDesc = ResourceDescription.Texture2D(Format.R8G8B8A8_UNorm, Width, Height);

            texture = DXGlobal.device.CreateCommittedResource(new HeapProperties(HeapType.Default), HeapFlags.None, textureDesc, ResourceStates.CopyDestination);

            long uploadBufferSize = GetRequiredIntermediateSize(this.texture, 0, 1);

            // Create the GPU upload buffer.
            var textureUploadHeap = DXGlobal.device.CreateCommittedResource(new HeapProperties(CpuPageProperty.WriteBack, MemoryPool.L0), HeapFlags.None, ResourceDescription.Texture2D(Format.R8G8B8A8_UNorm, Width, Height), ResourceStates.GenericRead);

            // Copy data to the intermediate upload heap and then schedule a copy
            // from the upload heap to the Texture2D.
            byte[] textureData = new byte[Width * Height * 4];

            int loc = 0;

            for (int y = 0; y < Height; y++)
            {
                for (int x = 0; x < Width; x++)
                {
                    var pix = bm.GetPixel(x, y);
                    textureData[loc++] = 0xff; //pix.R;
                    textureData[loc++] = 0xff; //pix.G;
                    textureData[loc++] = 0xff; // pix.B;
                    textureData[loc++] = 0xff;
                }
            }

            var handle = GCHandle.Alloc(textureData, GCHandleType.Pinned);
            var ptr    = Marshal.UnsafeAddrOfPinnedArrayElement(textureData, 0);

            textureUploadHeap.WriteToSubresource(0, null, ptr, Depth * Width, textureData.Length);
            handle.Free();
            //   DXGlobal.Display.CommandList.Close();
            DXGlobal.Display.CommandList.Reset(DXGlobal.Display.DirectCmdListAlloc, Effect.Effect._pip);

            DXGlobal.Display.CommandList.CopyTextureRegion(new TextureCopyLocation(texture, 0), 0, 0, 0, new TextureCopyLocation(textureUploadHeap, 0), null);

            DXGlobal.Display.CommandList.ResourceBarrierTransition(this.texture, ResourceStates.CopyDestination, ResourceStates.PixelShaderResource);

            // Describe and create a SRV for the texture.
            srvDesc = new ShaderResourceViewDescription
            {
                Shader4ComponentMapping = D3DXUtilities.DefaultComponentMapping(),
                Format    = textureDesc.Format,
                Dimension = ShaderResourceViewDimension.Texture2D,
                Texture2D = { MipLevels = 1 },
            };
            var srvHeapDesc = new DescriptorHeapDescription()
            {
                DescriptorCount = 1,
                Flags           = DescriptorHeapFlags.ShaderVisible,
                Type            = DescriptorHeapType.ConstantBufferViewShaderResourceViewUnorderedAccessView
            };

            DescriptorHeap srvH = DXGlobal.device.CreateDescriptorHeap(srvHeapDesc);


            DXGlobal.device.CreateShaderResourceView(texture, srvDesc, srvH.CPUDescriptorHandleForHeapStart);



            DXGlobal.Display.CommandList.Close();
            DXGlobal.Display.CommandQueue.ExecuteCommandList(DXGlobal.Display.CommandList);
            DXGlobal.Display.FlushCommandQueue();
        }