Example #1
0
        public static uint GetSizeInBytes(VertexElementFormat format)
        {
            switch (format)
            {
            case VertexElementFormat.Byte2_Norm:
            case VertexElementFormat.Byte2:
            case VertexElementFormat.SByte2_Norm:
            case VertexElementFormat.SByte2:
            case VertexElementFormat.Half1:
                return(2);

            case VertexElementFormat.Float1:
            case VertexElementFormat.UInt1:
            case VertexElementFormat.Int1:
            case VertexElementFormat.Byte4_Norm:
            case VertexElementFormat.Byte4:
            case VertexElementFormat.SByte4_Norm:
            case VertexElementFormat.SByte4:
            case VertexElementFormat.UShort2_Norm:
            case VertexElementFormat.UShort2:
            case VertexElementFormat.Short2_Norm:
            case VertexElementFormat.Short2:
            case VertexElementFormat.Half2:
                return(4);

            case VertexElementFormat.Float2:
            case VertexElementFormat.UInt2:
            case VertexElementFormat.Int2:
            case VertexElementFormat.UShort4_Norm:
            case VertexElementFormat.UShort4:
            case VertexElementFormat.Short4_Norm:
            case VertexElementFormat.Short4:
            case VertexElementFormat.Half4:
                return(8);

            case VertexElementFormat.Float3:
            case VertexElementFormat.UInt3:
            case VertexElementFormat.Int3:
                return(12);

            case VertexElementFormat.Float4:
            case VertexElementFormat.UInt4:
            case VertexElementFormat.Int4:
                return(16);

            default:
                throw Illegal.Value <VertexElementFormat>();
            }
        }
Example #2
0
        public static uint GetBlockSizeInBytes(PixelFormat format)
        {
            switch (format)
            {
            case PixelFormat.BC1_Rgba_UNorm:
            case PixelFormat.BC1_Rgb_UNorm:
                return(8);

            case PixelFormat.BC2_UNorm:
            case PixelFormat.BC3_UNorm:
                return(16);

            default:
                throw Illegal.Value <PixelFormat>();
            }
        }
Example #3
0
        public static int GetElementCount(VertexElementFormat format)
        {
            switch (format)
            {
            case VertexElementFormat.Float1:
            case VertexElementFormat.UInt1:
            case VertexElementFormat.Int1:
                return(1);

            case VertexElementFormat.Float2:
            case VertexElementFormat.Byte2_Norm:
            case VertexElementFormat.Byte2:
            case VertexElementFormat.SByte2_Norm:
            case VertexElementFormat.SByte2:
            case VertexElementFormat.UShort2_Norm:
            case VertexElementFormat.UShort2:
            case VertexElementFormat.Short2_Norm:
            case VertexElementFormat.Short2:
            case VertexElementFormat.UInt2:
            case VertexElementFormat.Int2:
                return(2);

            case VertexElementFormat.Float3:
            case VertexElementFormat.UInt3:
            case VertexElementFormat.Int3:
                return(3);

            case VertexElementFormat.Float4:
            case VertexElementFormat.Byte4_Norm:
            case VertexElementFormat.Byte4:
            case VertexElementFormat.SByte4_Norm:
            case VertexElementFormat.SByte4:
            case VertexElementFormat.UShort4_Norm:
            case VertexElementFormat.UShort4:
            case VertexElementFormat.Short4_Norm:
            case VertexElementFormat.Short4:
            case VertexElementFormat.UInt4:
            case VertexElementFormat.Int4:
                return(4);

            default:
                throw Illegal.Value <VertexElementFormat>();
            }
        }
Example #4
0
        public static uint GetSizeInBytes(PixelFormat format)
        {
            switch (format)
            {
            case PixelFormat.R8_UNorm:
                return(1);

            case PixelFormat.R16_UNorm:
                return(2);

            case PixelFormat.R8_G8_B8_A8_UNorm:
            case PixelFormat.B8_G8_R8_A8_UNorm:
            case PixelFormat.R32_Float:
                return(4);

            case PixelFormat.R32_G32_B32_A32_Float:
                return(16);

            default: throw Illegal.Value <PixelFormat>();
            }
        }
Example #5
0
        internal static int GetElementCount(VertexElementFormat format)
        {
            switch (format)
            {
            case VertexElementFormat.Float1:
            case VertexElementFormat.Byte1:
                return(1);

            case VertexElementFormat.Float2:
            case VertexElementFormat.Byte2:
                return(2);

            case VertexElementFormat.Float3:
                return(3);

            case VertexElementFormat.Float4:
            case VertexElementFormat.Byte4:
                return(4);

            default:
                throw Illegal.Value <VertexElementFormat>();
            }
        }
        public static uint GetSizeInBytes(PixelFormat format)
        {
            switch (format)
            {
            case PixelFormat.R8_UNorm:
            case PixelFormat.R8_SNorm:
            case PixelFormat.R8_UInt:
            case PixelFormat.R8_SInt:
                return(1);

            case PixelFormat.R16_UNorm:
            case PixelFormat.R16_SNorm:
            case PixelFormat.R16_UInt:
            case PixelFormat.R16_SInt:
            case PixelFormat.R16_Float:
            case PixelFormat.R8_G8_UNorm:
            case PixelFormat.R8_G8_SNorm:
            case PixelFormat.R8_G8_UInt:
            case PixelFormat.R8_G8_SInt:
                return(2);

            case PixelFormat.R32_UInt:
            case PixelFormat.R32_SInt:
            case PixelFormat.R32_Float:
            case PixelFormat.R16_G16_UNorm:
            case PixelFormat.R16_G16_SNorm:
            case PixelFormat.R16_G16_UInt:
            case PixelFormat.R16_G16_SInt:
            case PixelFormat.R16_G16_Float:
            case PixelFormat.R8_G8_B8_A8_UNorm:
            case PixelFormat.R8_G8_B8_A8_SNorm:
            case PixelFormat.R8_G8_B8_A8_UInt:
            case PixelFormat.R8_G8_B8_A8_SInt:
            case PixelFormat.B8_G8_R8_A8_UNorm:
            case PixelFormat.R10_G10_B10_A2_UNorm:
            case PixelFormat.R10_G10_B10_A2_UInt:
            case PixelFormat.R11_G11_B10_Float:
            case PixelFormat.D24_UNorm_S8_UInt:
                return(4);

            case PixelFormat.D32_Float_S8_UInt:
                return(5);

            case PixelFormat.R16_G16_B16_A16_UNorm:
            case PixelFormat.R16_G16_B16_A16_SNorm:
            case PixelFormat.R16_G16_B16_A16_UInt:
            case PixelFormat.R16_G16_B16_A16_SInt:
            case PixelFormat.R16_G16_B16_A16_Float:
            case PixelFormat.R32_G32_UInt:
            case PixelFormat.R32_G32_SInt:
            case PixelFormat.R32_G32_Float:
                return(8);

            case PixelFormat.R32_G32_B32_A32_Float:
            case PixelFormat.R32_G32_B32_A32_UInt:
            case PixelFormat.R32_G32_B32_A32_SInt:
                return(16);

            case PixelFormat.BC1_Rgb_UNorm:
            case PixelFormat.BC1_Rgba_UNorm:
            case PixelFormat.BC2_UNorm:
            case PixelFormat.BC3_UNorm:
            case PixelFormat.BC4_UNorm:
            case PixelFormat.BC4_SNorm:
            case PixelFormat.BC5_UNorm:
            case PixelFormat.BC5_SNorm:
            case PixelFormat.BC7_UNorm:
            case PixelFormat.ETC2_R8_G8_B8_UNorm:
            case PixelFormat.ETC2_R8_G8_B8_A1_UNorm:
            case PixelFormat.ETC2_R8_G8_B8_A8_UNorm:
                Debug.Fail("GetSizeInBytes should not be used on a compressed format.");
                throw Illegal.Value <PixelFormat>();

            default: throw Illegal.Value <PixelFormat>();
            }
        }
        private static void ValidateResourceKind(ResourceKind kind, BindableResource resource, uint slot)
        {
            switch (kind)
            {
            case ResourceKind.UniformBuffer:
            {
                if (!Util.GetDeviceBuffer(resource, out DeviceBuffer b) ||
                    (b.Usage & BufferUsage.UniformBuffer) == 0)
                {
                    throw new VeldridException(
                              $"Resource in slot {slot} does not match {nameof(ResourceKind)}.{kind} specified in the {nameof(ResourceLayout)}. " +
                              $"It must be a {nameof(DeviceBuffer)} or {nameof(DeviceBufferRange)} with {nameof(BufferUsage)}.{nameof(BufferUsage.UniformBuffer)}.");
                }
                break;
            }

            case ResourceKind.StructuredBufferReadOnly:
            {
                if (!Util.GetDeviceBuffer(resource, out DeviceBuffer b) ||
                    (b.Usage & (BufferUsage.StructuredBufferReadOnly | BufferUsage.StructuredBufferReadWrite)) == 0)
                {
                    throw new VeldridException(
                              $"Resource in slot {slot} does not match {nameof(ResourceKind)}.{kind} specified in the {nameof(ResourceLayout)}. It must be a {nameof(DeviceBuffer)} with {nameof(BufferUsage)}.{nameof(BufferUsage.StructuredBufferReadOnly)}.");
                }
                break;
            }

            case ResourceKind.StructuredBufferReadWrite:
            {
                if (!Util.GetDeviceBuffer(resource, out DeviceBuffer b) ||
                    (b.Usage & BufferUsage.StructuredBufferReadWrite) == 0)
                {
                    throw new VeldridException(
                              $"Resource in slot {slot} does not match {nameof(ResourceKind)} specified in the {nameof(ResourceLayout)}. It must be a {nameof(DeviceBuffer)} with {nameof(BufferUsage)}.{nameof(BufferUsage.StructuredBufferReadWrite)}.");
                }
                break;
            }

            case ResourceKind.TextureReadOnly:
            {
                if (!(resource is TextureView tv && (tv.Target.Usage & TextureUsage.Sampled) != 0) &&
                    !(resource is Texture t && (t.Usage & TextureUsage.Sampled) != 0))
                {
                    throw new VeldridException(
                              $"Resource in slot {slot} does not match {nameof(ResourceKind)}.{kind} specified in the " +
                              $"{nameof(ResourceLayout)}. It must be a {nameof(Texture)} or {nameof(TextureView)} whose target " +
                              $"has {nameof(TextureUsage)}.{nameof(TextureUsage.Sampled)}.");
                }
                break;
            }

            case ResourceKind.TextureReadWrite:
            {
                if (!(resource is TextureView tv && (tv.Target.Usage & TextureUsage.Storage) != 0) &&
                    !(resource is Texture t && (t.Usage & TextureUsage.Storage) != 0))
                {
                    throw new VeldridException(
                              $"Resource in slot {slot} does not match {nameof(ResourceKind)}.{kind} specified in the " +
                              $"{nameof(ResourceLayout)}. It must be a {nameof(Texture)} or {nameof(TextureView)} whose target " +
                              $"has {nameof(TextureUsage)}.{nameof(TextureUsage.Storage)}.");
                }
                break;
            }

            case ResourceKind.Sampler:
            {
                if (!(resource is Sampler s))
                {
                    throw new VeldridException(
                              $"Resource in slot {slot} does not match {nameof(ResourceKind)}.{kind} specified in the {nameof(ResourceLayout)}. It must be a {nameof(Sampler)}.");
                }
                break;
            }

            default:
                throw Illegal.Value <ResourceKind>();
            }
        }