public MaterialExpressionTextureSampleParameter2D(string name, int editorX, int editorY, string parameterName, ParsedPropertyBag coordinates, ResourceReference texture, SamplerType samplerType)
     : base(name, editorX, editorY, parameterName, null)
 {
     Coordinates = coordinates;
     Texture     = texture;
     SamplerType = samplerType;
 }
        /// <summary>
        ///  Regression learner for XGBoost
        /// </summary>
        /// <param name="maximumTreeDepth">Maximum tree depth for base learners. (default is 3)</param>
        /// <param name="learningRate">Boosting learning rate (xgb's "eta"). 0 indicates no limit. (default is 0.1)</param>
        /// <param name="estimators">Number of estimators to fit. (default is 100)</param>
        /// <param name="silent">Whether to print messages while running boosting. (default is false)</param>
        /// <param name="objective">Specify the learning task and the corresponding learning objective. (default is LinearRegression)</param>
        /// <param name="boosterType"> which booster to use, can be gbtree, gblinear or dart.
        /// gbtree and dart use tree based model while gblinear uses linear function (default is gbtree)</param>
        /// <param name="treeMethod">The tree construction algorithm used in XGBoost. See reference paper: https://arxiv.org/abs/1603.02754. (default is auto)</param>
        /// <param name="samplerType">Type of sampling algorithm for DART. (default is uniform)</param>
        /// <param name="normalizeType">Type of normalization algorithm for DART. (default is tree)</param>
        /// <param name="dropoutRate">Dropout rate for DART (a fraction of previous trees to drop during the dropout). (default is 0.0)</param>
        /// <param name="oneDrop">When this is true, at least one tree is always dropped during the dropout.
        /// Allows Binomial-plus-one or epsilon-dropout from the original DART paper. (default is false)</param>
        /// <param name="skipDrop">Probability of skipping the dropout procedure during a boosting iteration. (default is 0.0)
        /// If a dropout is skipped, new trees are added in the same manner as gbtree.
        /// Note that non-zero skip_drop has higher priority than rate_drop or one_drop.</param>
        /// <param name="numberOfThreads">Number of parallel threads used to run xgboost. -1 means use all thread avialable. (default is -1)</param>
        /// <param name="gamma">Minimum loss reduction required to make a further partition on a leaf node of the tree. (default is 0) </param>
        /// <param name="minChildWeight">Minimum sum of instance weight(hessian) needed in a child. (default is 1)</param>
        /// <param name="maxDeltaStep">Maximum delta step we allow each tree's weight estimation to be. (default is 0)</param>
        /// <param name="subSample">Subsample ratio of the training instance. (default is 1)</param>
        /// <param name="colSampleByTree">Subsample ratio of columns when constructing each tree. (defualt is 1)</param>
        /// <param name="colSampleByLevel">Subsample ratio of columns for each split, in each level. (defualt is 1)</param>
        /// <param name="l1Regularization">L1 regularization term on weights. Also known as RegAlpha. (default is 0)</param>
        /// <param name="l2Reguralization">L2 regularization term on weights. Also known as regLambda. (default is 1)</param>
        /// <param name="scalePosWeight">Balancing of positive and negative weights. (default is 1)</param>
        /// <param name="baseScore">The initial prediction score of all instances, global bias. (default is 0.5)</param>
        /// <param name="seed">Random number seed. (defaukt is 0)</param>
        /// <param name="missing">Value in the data which needs to be present as a missing value. (default is NaN)</param>
        public RegressionXGBoostLearner(int maximumTreeDepth          = 3, double learningRate = 0.1, int estimators = 100,
                                        bool silent                   = true,
                                        RegressionObjective objective = RegressionObjective.LinearRegression,
                                        BoosterType boosterType       = BoosterType.GBTree,
                                        TreeMethod treeMethod         = TreeMethod.Auto,
                                        SamplerType samplerType       = SamplerType.Uniform,
                                        NormalizeType normalizeType   = NormalizeType.Tree,
                                        double dropoutRate            = 0.0,
                                        bool oneDrop                  = false,
                                        double skipDrop               = 0.0,
                                        int numberOfThreads           = -1, double gamma    = 0, int minChildWeight     = 1,
                                        int maxDeltaStep              = 0, double subSample = 1, double colSampleByTree = 1,
                                        double colSampleByLevel       = 1, double l1Regularization = 0, double l2Reguralization = 1,
                                        double scalePosWeight         = 1, double baseScore        = 0.5, int seed = 0,
                                        double missing                = double.NaN)
        {
            ArgumentChecks.ThrowOnArgumentLessThan(nameof(maximumTreeDepth), maximumTreeDepth, 0);
            ArgumentChecks.ThrowOnArgumentLessThanOrHigherThan(nameof(learningRate), learningRate, 0, 1.0);
            ArgumentChecks.ThrowOnArgumentLessThan(nameof(estimators), estimators, 1);
            ArgumentChecks.ThrowOnArgumentLessThan(nameof(numberOfThreads), numberOfThreads, -1);
            ArgumentChecks.ThrowOnArgumentLessThan(nameof(gamma), gamma, 0);
            ArgumentChecks.ThrowOnArgumentLessThan(nameof(minChildWeight), minChildWeight, 0);
            ArgumentChecks.ThrowOnArgumentLessThan(nameof(maxDeltaStep), maxDeltaStep, 0);
            ArgumentChecks.ThrowOnArgumentLessThanOrHigherThan(nameof(subSample), subSample, 0, 1.0);
            ArgumentChecks.ThrowOnArgumentLessThanOrHigherThan(nameof(colSampleByTree), colSampleByTree, 0, 1.0);
            ArgumentChecks.ThrowOnArgumentLessThanOrHigherThan(nameof(colSampleByLevel), colSampleByLevel, 0, 1.0);
            ArgumentChecks.ThrowOnArgumentLessThan(nameof(l1Regularization), l1Regularization, 0);
            ArgumentChecks.ThrowOnArgumentLessThan(nameof(l2Reguralization), l2Reguralization, 0);
            ArgumentChecks.ThrowOnArgumentLessThan(nameof(scalePosWeight), scalePosWeight, 0);

            m_parameters[ParameterNames.MaxDepth]     = maximumTreeDepth;
            m_parameters[ParameterNames.LearningRate] = (float)learningRate;
            m_parameters[ParameterNames.Estimators]   = estimators;
            m_parameters[ParameterNames.Silent]       = silent;
            m_parameters[ParameterNames.objective]    = objective.ToXGBoostString();

            m_parameters[ParameterNames.Threads]          = numberOfThreads;
            m_parameters[ParameterNames.Gamma]            = (float)gamma;
            m_parameters[ParameterNames.MinChildWeight]   = minChildWeight;
            m_parameters[ParameterNames.MaxDeltaStep]     = maxDeltaStep;
            m_parameters[ParameterNames.SubSample]        = (float)subSample;
            m_parameters[ParameterNames.ColSampleByTree]  = (float)colSampleByTree;
            m_parameters[ParameterNames.ColSampleByLevel] = (float)colSampleByLevel;
            m_parameters[ParameterNames.RegAlpha]         = (float)l1Regularization;
            m_parameters[ParameterNames.RegLambda]        = (float)l2Reguralization;
            m_parameters[ParameterNames.ScalePosWeight]   = (float)scalePosWeight;

            m_parameters[ParameterNames.BaseScore]       = (float)baseScore;
            m_parameters[ParameterNames.Seed]            = seed;
            m_parameters[ParameterNames.Missing]         = (float)missing;
            m_parameters[ParameterNames.ExistingBooster] = null;
            m_parameters[ParameterNames.Booster]         = boosterType.ToXGBoostString();
            m_parameters[ParameterNames.TreeMethod]      = treeMethod.ToXGBoostString();

            m_parameters[ParameterNames.SampleType]    = samplerType.ToXGBoostString();
            m_parameters[ParameterNames.NormalizeType] = normalizeType.ToXGBoostString();
            m_parameters[ParameterNames.RateDrop]      = (float)dropoutRate;
            m_parameters[ParameterNames.OneDrop]       = oneDrop ? 1 : 0;
            m_parameters[ParameterNames.SkipDrop]      = (float)skipDrop;
        }
Example #3
0
        public IRenderTarget CreateRenderTarget(uint width,
                                                uint height,
                                                bool autoClearColourAndDepthEachFrame = true,
                                                SamplerType samplerType   = SamplerType.Anisotropic,
                                                uint numberOfMipMapLevels = 1)

        {
            if (width == 0 || height == 0)
            {
                throw new Yak2DException("Surfaces -> CreateRenderTarget(), dimensions cannot be zero");
            }

            if (numberOfMipMapLevels == 0)
            {
                numberOfMipMapLevels = 1;
            }

            return(_surfaceManager.CreateRenderSurface(
                       false,
                       width,
                       height,
                       TexturePixelFormatConverter.ConvertYakToVeldrid(_systemComponents.SwapChainFramebufferPixelFormat),
                       true,
                       autoClearColourAndDepthEachFrame,
                       autoClearColourAndDepthEachFrame,
                       samplerType,
                       numberOfMipMapLevels
                       ));
        }
Example #4
0
        public void SetUsedTexture(
            Instruction inst,
            SamplerType type,
            TextureFormat format,
            TextureFlags flags,
            int cbufSlot,
            int handle)
        {
            inst &= Instruction.Mask;
            bool isImage      = inst == Instruction.ImageLoad || inst == Instruction.ImageStore || inst == Instruction.ImageAtomic;
            bool isWrite      = inst == Instruction.ImageStore || inst == Instruction.ImageAtomic;
            bool accurateType = inst != Instruction.Lod && inst != Instruction.TextureSize;
            bool coherent     = flags.HasFlag(TextureFlags.Coherent);

            if (isImage)
            {
                SetUsedTextureOrImage(_usedImages, cbufSlot, handle, type, format, true, isWrite, false, coherent);
            }
            else
            {
                bool intCoords = flags.HasFlag(TextureFlags.IntCoords) || inst == Instruction.TextureSize;
                SetUsedTextureOrImage(_usedTextures, cbufSlot, handle, type, TextureFormat.Unknown, intCoords, false, accurateType, coherent);
            }

            GpuAccessor.RegisterTexture(handle, cbufSlot);
        }
Example #5
0
        private ITexture LoadTextureFromEmbeddedPngResource(bool isFrameworkInternal,
                                                            bool isFontTexture,
                                                            IAssembly assembly,
                                                            string assetPathWithoutExtension,
                                                            ImageFormat imageFormat,
                                                            SamplerType samplerType,
                                                            bool generateMipMaps)
        {
            var extension = GetFileExtensionFromImageFormat(imageFormat);

            var fullAssemblyName = string.Concat(assembly.Name, ".", assetPathWithoutExtension, extension);

            var stream = assembly.GetManifestResourceStream(fullAssemblyName);

            if (stream == null)
            {
                var names = assembly.GetManifestResourceNames();

                if (names.Contains(fullAssemblyName))
                {
                    _frameworkMessenger.Report("Unable to load texture. Unknown Error. Asset stream was found by name in manifest: " + fullAssemblyName);
                }
                else
                {
                    _frameworkMessenger.Report("Unable to load texture. The provided texture name was not found in assembly: " + fullAssemblyName + " | Expect location format as ASSEMBLYNAME.PATHTOTEXTURES.NAMEPROVIDED.PNG");
                }
                return(null);
            }

            return(GenerateTextureFromStream(stream, isFrameworkInternal, isFontTexture, samplerType, generateMipMaps));
        }
Example #6
0
 public TextureMeta(int cbufSlot, int handle, TextureFormat format, SamplerType type)
 {
     CbufSlot = cbufSlot;
     Handle   = handle;
     Format   = format;
     Type     = type;
 }
Example #7
0
        private static string GetImageTypeName(SamplerType type)
        {
            string typeName;

            switch (type & SamplerType.Mask)
            {
            case SamplerType.Texture1D:     typeName = "image1D";     break;

            case SamplerType.TextureBuffer: typeName = "imageBuffer"; break;

            case SamplerType.Texture2D:     typeName = "image2D";     break;

            case SamplerType.Texture3D:     typeName = "image3D";     break;

            case SamplerType.TextureCube:   typeName = "imageCube";   break;

            default: throw new ArgumentException($"Invalid sampler type \"{type}\".");
            }

            if ((type & SamplerType.Multisample) != 0)
            {
                typeName += "MS";
            }

            if ((type & SamplerType.Array) != 0)
            {
                typeName += "Array";
            }

            return(typeName);
        }
Example #8
0
        public static Filter Convert(SamplerType type, TextureFilter min, TextureFilter mag, TextureFilter mip)
        {
            int offset;

            switch (type)
            {
            case SamplerType.Normal:
                offset = 0;
                break;

            case SamplerType.Comparison:
                offset = 0x80;
                break;

            case SamplerType.Minimum:
                offset = 0x100;
                break;

            case SamplerType.Maximum:
                offset = 0x180;
                break;

            default:
                throw new NotSupportedException("SamplerType is not supported.");
            }
            Filter f;

            if (!filters.TryGetValue(new Tuple <TextureFilter, TextureFilter, TextureFilter>(min, mag, mip), out f))
            {
                throw new NotSupportedException("TextureFilter variant not supported.");
            }
            return((Filter)(f + offset));
        }
Example #9
0
        private static SamplerBase CreateSampler(SamplerType samplerType, int numSamples, int numSets = 83)
        {
            SamplerBase sampler = null;

            switch (samplerType)
            {
            case SamplerType.Hammersley:
                sampler = new HammersleySampler(numSamples, numSets);
                break;

            case SamplerType.Jittered:
                sampler = new JitteredSampler(numSamples, numSets);
                break;

            case SamplerType.Random:
                sampler = new RandomSampler(numSamples, numSets);
                break;

            case SamplerType.Regular:
                sampler = new RegularSampler(numSamples, numSets);
                break;

            default:
                sampler = new RegularSampler(numSamples, numSets);
                break;
            }

            return(sampler);
        }
Example #10
0
 public MaterialExpressionTextureSample(string name, int editorX, int editorY, ParsedPropertyBag coordinates, ResourceReference texture, ParsedPropertyBag textureObject, SamplerType samplerType)
     : base(name, editorX, editorY)
 {
     Coordinates   = coordinates;
     Texture       = texture;
     TextureObject = textureObject;
     SamplerType   = samplerType;
 }
Example #11
0
        public static SamplerState GetSamplerState(SamplerType type)
        {
            if (!m_Initialized)
            {
                throw new Exception("Uninitialized sampler states!");
            }

            return m_SamplerStates[(int)type];
        }
Example #12
0
        public static SamplerState GetSamplerState(SamplerType type)
        {
            if (!m_Initialized)
            {
                throw new Exception("Uninitialized sampler states!");
            }

            return(m_SamplerStates[(int)type]);
        }
Example #13
0
 public TextureDescriptor(int binding, SamplerType type, TextureFormat format, int cbufSlot, int handleIndex)
 {
     Binding     = binding;
     Type        = type;
     Format      = format;
     CbufSlot    = cbufSlot;
     HandleIndex = handleIndex;
     Flags       = TextureUsageFlags.None;
 }
Example #14
0
 protected void SetSamplerState(int slot, SamplerType sampler)
 {
     if (CurrentSamplerState[slot] == (int)sampler)
     {
         return;
     }
     GetContext.PixelShader.SetSampler(slot, GetSharedItems.GetSamplerState(sampler));
     CurrentSamplerState[slot] = (int)sampler;
 }
Example #15
0
 public void SetSampler(SamplerType samplerType, int numSamples, int numSets = 83)
 {
     m_Samplers = new SamplerBase[Environment.ProcessorCount];
     for (int i = 0; i < m_Samplers.Length; i++)
     {
         m_Samplers[i] = SamplerFactory.Create(samplerType, numSamples, numSets);
     }
     //m_Sampler = sampler;
 }
Example #16
0
        public GpuSurface CreateGpuSurfaceFromTexture(Texture texture,
                                                      bool isFrameworkInternal,
                                                      bool isFontTexture,
                                                      SamplerType samplerType)
        {
            if (texture == null)
            {
                throw new Yak2DException("Internal Framework Exception: GpuSurfaceFactory passed a null Veldrid Texture", new ArgumentNullException("texture"));
            }

            var view = _components.Factory.CreateTextureView(texture);

            Sampler wrap   = null;
            Sampler mirror = null;

            switch (samplerType)
            {
            case SamplerType.Anisotropic:
                wrap   = _anisotropicSamplerWrap;
                mirror = _anisotropicSamplerMirror;
                break;

            case SamplerType.Linear:
                wrap   = _linearSamplerWrap;
                mirror = _linearSamplerMirror;
                break;

            case SamplerType.Point:
                wrap   = _pointSamplerWrap;
                mirror = _pointSamplerMirror;
                break;
            }

            var resourceSet_Wrap = _components.Factory.CreateResourceSet(new ResourceSetDescription(
                                                                             _cachedTextureResourceLayout,
                                                                             view,
                                                                             wrap
                                                                             ));

            var resourceSet_Mirror = _components.Factory.CreateResourceSet(new ResourceSetDescription(
                                                                               _cachedTextureResourceLayout,
                                                                               view,
                                                                               mirror
                                                                               ));

            return(new GpuSurface
            {
                //Note Surfaces related to USER FONTS are also tagged as internal. This is so their destruction is related to
                //The FONT item and not caught up in any DestroyAllUserSurfaces type calls (that being reserved for TEXTURES and RENDERTARGETS
                Type = GpuSurfaceType.Texture | (isFrameworkInternal ? GpuSurfaceType.Internal : isFontTexture ? GpuSurfaceType.Internal : GpuSurfaceType.User),
                Texture = texture,
                TextureView = view,
                Framebuffer = null,
                ResourceSet_TexWrap = resourceSet_Wrap,
                ResourceSet_TexMirror = resourceSet_Mirror
            });
        }
Example #17
0
        private void SetUsedTextureOrImage(
            Dictionary <TextureInfo, TextureMeta> dict,
            int cbufSlot,
            int handle,
            SamplerType type,
            TextureFormat format,
            bool intCoords,
            bool write,
            bool accurateType)
        {
            var dimensions = type.GetDimensions();
            var isIndexed  = type.HasFlag(SamplerType.Indexed);

            var usageFlags = TextureUsageFlags.None;

            if (intCoords)
            {
                usageFlags |= TextureUsageFlags.NeedsScaleValue;

                var canScale = (Stage == ShaderStage.Fragment || Stage == ShaderStage.Compute) && !isIndexed && !write && dimensions == 2;

                if (!canScale)
                {
                    // Resolution scaling cannot be applied to this texture right now.
                    // Flag so that we know to blacklist scaling on related textures when binding them.
                    usageFlags |= TextureUsageFlags.ResScaleUnsupported;
                }
            }

            if (write)
            {
                usageFlags |= TextureUsageFlags.ImageStore;
            }

            int arraySize = isIndexed ? SamplerArraySize : 1;

            for (int layer = 0; layer < arraySize; layer++)
            {
                var info = new TextureInfo(cbufSlot, handle + layer * 2, isIndexed, format);
                var meta = new TextureMeta()
                {
                    AccurateType = accurateType,
                    Type         = type,
                    UsageFlags   = usageFlags
                };

                if (dict.TryGetValue(info, out var existingMeta))
                {
                    dict[info] = MergeTextureMeta(meta, existingMeta);
                }
                else
                {
                    dict.Add(info, meta);
                }
            }
        }
 public SamplerInfo(
     SamplerType type, int textureSlot, int samplerSlot, string name, SamplerState?state, int parameter)
 {
     Type        = type;
     TextureSlot = textureSlot;
     SamplerSlot = samplerSlot;
     Name        = name ?? throw new ArgumentNullException(nameof(name));
     State       = state;
     Parameter   = parameter;
 }
Example #19
0
 public TextureOperation(
     Instruction inst,
     SamplerType type,
     TextureFormat format,
     TextureFlags flags,
     int handle,
     int compIndex,
     Operand dest,
     Operand[] sources) : this(inst, type, format, flags, DefaultCbufSlot, handle, compIndex, dest, sources)
 {
 }
Example #20
0
 public static int GetDimensions(this SamplerType type)
 {
     return((type & SamplerType.Mask) switch
     {
         SamplerType.Texture1D => 1,
         SamplerType.TextureBuffer => 1,
         SamplerType.Texture2D => 2,
         SamplerType.Texture3D => 3,
         SamplerType.TextureCube => 3,
         _ => throw new ArgumentException($"Invalid sampler type \"{type}\".")
     });
Example #21
0
        public TextureDescriptor(string name, SamplerType type, int cbufSlot, int cbufOffset)
        {
            Name        = name;
            Type        = type;
            HandleIndex = 0;

            IsBindless = true;

            CbufSlot   = cbufSlot;
            CbufOffset = cbufOffset;
        }
Example #22
0
 private static Dim GetDim(SamplerType type)
 {
     return((type & SamplerType.Mask) switch
     {
         SamplerType.Texture1D => Dim.Dim1D,
         SamplerType.Texture2D => Dim.Dim2D,
         SamplerType.Texture3D => Dim.Dim3D,
         SamplerType.TextureCube => Dim.Cube,
         SamplerType.TextureBuffer => Dim.Buffer,
         _ => throw new ArgumentException($"Invalid sampler type \"{type & SamplerType.Mask}\".")
     });
Example #23
0
        public TextureDescriptor(string name, SamplerType type, int handleIndex)
        {
            Name        = name;
            Type        = type;
            HandleIndex = handleIndex;

            IsBindless = false;

            CbufSlot   = 0;
            CbufOffset = 0;
        }
Example #24
0
 private ulong CreateSurface(uint width, uint height, SamplerType samplerType, PixelFormat pixelFormat)
 {
     return(_surfaceManager.CreateRenderSurface(true,
                                                width,
                                                height,
                                                pixelFormat,
                                                false,
                                                false,
                                                false,
                                                samplerType,
                                                1).Id);
 }
Example #25
0
 private ulong CreateSurface(uint width, uint height, SamplerType samplerType)
 {
     return(_surfaceManager.CreateRenderSurface(true,
                                                width,
                                                height,
                                                TexturePixelFormatConverter.ConvertYakToVeldrid(_systemComponents.SwapChainFramebufferPixelFormat),
                                                false,
                                                false,
                                                false,
                                                samplerType,
                                                1).Id);
 }
Example #26
0
 public TextureOperation(
     Instruction inst,
     SamplerType type,
     TextureFlags flags,
     int handle,
     int compIndex,
     Operand dest,
     params Operand[] sources) : base(inst, compIndex, dest, sources)
 {
     Type   = type;
     Flags  = flags;
     Handle = handle;
 }
Example #27
0
        public static ISampler GetSampler(SamplerType type)
        {
            var defaultSampler = new ConstSampler(sample: true);

            switch (type)
            {
            case SamplerType.Const:
                return(defaultSampler);

            default:
                return(defaultSampler);
            }
        }
Example #28
0
        public TextureDescriptor(string name, SamplerType type, TextureFormat format, int handleIndex)
        {
            Name        = name;
            Type        = type;
            Format      = format;
            HandleIndex = handleIndex;

            IsBindless = false;

            CbufSlot   = 0;
            CbufOffset = 0;

            Flags = TextureUsageFlags.None;
        }
Example #29
0
        public TextureDescriptor(string name, SamplerType type, int cbufSlot, int cbufOffset)
        {
            Name        = name;
            Type        = type;
            Format      = TextureFormat.Unknown;
            HandleIndex = 0;

            IsBindless = true;

            CbufSlot   = cbufSlot;
            CbufOffset = cbufOffset;

            Flags = TextureUsageFlags.None;
        }
Example #30
0
        public ITexture GenerateTextureFromStream(Stream stream,
                                                  bool isFrameworkInternal,
                                                  bool isFontTexture,
                                                  SamplerType samplerType,
                                                  bool generateMipMaps)
        {
            var veldridTexture = _imageSharpLoader.GenerateVeldridTextureFromStream(stream, generateMipMaps);

            var id = _idGenerator.New();

            var surface = _gpuSurfaceFactory.CreateGpuSurfaceFromTexture(veldridTexture, isFrameworkInternal, isFontTexture, samplerType);

            return(_surfaceCollection.Add(id, surface) ? new TextureReference(id) : null);
        }
 public AstTextureOperation(
     Instruction inst,
     SamplerType type,
     TextureFlags flags,
     int handle,
     int arraySize,
     int index,
     params IAstNode[] sources) : base(inst, index, sources)
 {
     Type      = type;
     Flags     = flags;
     Handle    = handle;
     ArraySize = arraySize;
 }