示例#1
0
        /// <summary>
        /// Gets the sampler with the given ID.
        /// </summary>
        /// <param name="id">ID of the sampler. This is effectively a zero-based index</param>
        /// <returns>The sampler with the given ID</returns>
        public override Sampler Get(int id)
        {
            if ((uint)id >= Items.Length)
            {
                return(null);
            }

            if (_sequenceNumber != Context.SequenceNumber)
            {
                _sequenceNumber = Context.SequenceNumber;

                SynchronizeMemory();
            }

            Sampler sampler = Items[id];

            if (sampler == null)
            {
                ulong address = Address + (ulong)(uint)id * DescriptorSize;

                ReadOnlySpan <byte> data = Context.PhysicalMemory.GetSpan(address, DescriptorSize);

                SamplerDescriptor descriptor = MemoryMarshal.Cast <byte, SamplerDescriptor>(data)[0];

                sampler = new Sampler(Context, descriptor);

                Items[id] = sampler;
            }

            return(sampler);
        }
示例#2
0
        /// <summary>
        /// Creates a new instance of the cached sampler.
        /// </summary>
        /// <param name="context">The GPU context the sampler belongs to</param>
        /// <param name="descriptor">The Maxwell sampler descriptor</param>
        public Sampler(GpuContext context, SamplerDescriptor descriptor)
        {
            MinFilter minFilter = descriptor.UnpackMinFilter();
            MagFilter magFilter = descriptor.UnpackMagFilter();

            bool seamlessCubemap = descriptor.UnpackSeamlessCubemap();

            AddressMode addressU = descriptor.UnpackAddressU();
            AddressMode addressV = descriptor.UnpackAddressV();
            AddressMode addressP = descriptor.UnpackAddressP();

            CompareMode compareMode = descriptor.UnpackCompareMode();
            CompareOp   compareOp   = descriptor.UnpackCompareOp();

            ColorF color = new ColorF(
                descriptor.BorderColorR,
                descriptor.BorderColorG,
                descriptor.BorderColorB,
                descriptor.BorderColorA);

            float minLod     = descriptor.UnpackMinLod();
            float maxLod     = descriptor.UnpackMaxLod();
            float mipLodBias = descriptor.UnpackMipLodBias();

            float maxRequestedAnisotropy = GraphicsConfig.MaxAnisotropy >= 0 && GraphicsConfig.MaxAnisotropy <= 16 ? GraphicsConfig.MaxAnisotropy : descriptor.UnpackMaxAnisotropy();
            float maxSupportedAnisotropy = context.Capabilities.MaximumSupportedAnisotropy;

            if (maxRequestedAnisotropy > maxSupportedAnisotropy)
            {
                maxRequestedAnisotropy = maxSupportedAnisotropy;
            }

            HostSampler = context.Renderer.CreateSampler(new SamplerCreateInfo(
                                                             minFilter,
                                                             magFilter,
                                                             seamlessCubemap,
                                                             addressU,
                                                             addressV,
                                                             addressP,
                                                             compareMode,
                                                             compareOp,
                                                             color,
                                                             minLod,
                                                             maxLod,
                                                             mipLodBias,
                                                             maxRequestedAnisotropy));
        }
示例#3
0
        /// <summary>
        /// Creates a new instance of the cached sampler.
        /// </summary>
        /// <param name="context">The GPU context the sampler belongs to</param>
        /// <param name="descriptor">The Maxwell sampler descriptor</param>
        public Sampler(GpuContext context, SamplerDescriptor descriptor)
        {
            MinFilter minFilter = descriptor.UnpackMinFilter();
            MagFilter magFilter = descriptor.UnpackMagFilter();

            AddressMode addressU = descriptor.UnpackAddressU();
            AddressMode addressV = descriptor.UnpackAddressV();
            AddressMode addressP = descriptor.UnpackAddressP();

            CompareMode compareMode = descriptor.UnpackCompareMode();
            CompareOp   compareOp   = descriptor.UnpackCompareOp();

            ColorF color = new ColorF(
                descriptor.BorderColorR,
                descriptor.BorderColorG,
                descriptor.BorderColorB,
                descriptor.BorderColorA);

            float minLod     = descriptor.UnpackMinLod();
            float maxLod     = descriptor.UnpackMaxLod();
            float mipLodBias = descriptor.UnpackMipLodBias();

            float maxAnisotropy = descriptor.UnpackMaxAnisotropy();

            HostSampler = context.Renderer.CreateSampler(new SamplerCreateInfo(
                                                             minFilter,
                                                             magFilter,
                                                             addressU,
                                                             addressV,
                                                             addressP,
                                                             compareMode,
                                                             compareOp,
                                                             color,
                                                             minLod,
                                                             maxLod,
                                                             mipLodBias,
                                                             maxAnisotropy));
        }
示例#4
0
 /// <summary>
 /// Check if two descriptors are equal.
 /// </summary>
 /// <param name="other">The descriptor to compare against</param>
 /// <returns>True if they are equal, false otherwise</returns>
 public bool Equals(ref SamplerDescriptor other)
 {
     return(Unsafe.As <SamplerDescriptor, Vector256 <byte> >(ref this).Equals(Unsafe.As <SamplerDescriptor, Vector256 <byte> >(ref other)));
 }