internal int GetSwapchainCount(SurfaceKhr surface)
        {
            SurfaceCapabilitiesKhr capabilities = GetCurrentCapabilities(surface);

            //1 more then min to support triple buffering
            int count = capabilities.MinImageCount + 1;

            //If the capabilities specify a max then clamp to that
            if (capabilities.MaxImageCount > 0)
            {
                count = IntUtils.Min(count, capabilities.MaxImageCount);
            }
            return(count);
        }
示例#2
0
        private void Process(byte[] Input, int InOffset, byte[] Output, int OutOffset, int Length)
        {
            int prcSze = (Length >= Input.Length - InOffset) && Length >= Output.Length - OutOffset ? IntUtils.Min(Input.Length - InOffset, Output.Length - OutOffset) : Length;

            if (!m_isParallel || prcSze < m_parallelBlockSize)
            {
                // generate random
                Generate(prcSze, m_ctrVector, Output, OutOffset);
                // output is input xor with random
                int sze = prcSze - (prcSze % BLOCK_SIZE);

                if (sze != 0)
                {
                    IntUtils.XORBLK(Input, InOffset, Output, OutOffset, sze);
                }

                // get the remaining bytes
                if (sze != prcSze)
                {
                    for (int i = sze; i < prcSze; i++)
                    {
                        Output[i + OutOffset] ^= Input[i + InOffset];
                    }
                }
            }
            else
            {
                // parallel CTR processing //
                int    cnkSize = (prcSze / BLOCK_SIZE / m_processorCount) * BLOCK_SIZE;
                int    rndSize = cnkSize * m_processorCount;
                int    subSize = (cnkSize / BLOCK_SIZE);
                uint[] tmpCtr  = new uint[m_ctrVector.Length];

                // create random, and xor to output in parallel
                System.Threading.Tasks.Parallel.For(0, m_processorCount, i =>
                {
                    // thread level counter
                    uint[] thdCtr = new uint[m_ctrVector.Length];
                    // offset counter by chunk size / block size
                    thdCtr = Increase(m_ctrVector, subSize * i);
                    // create random at offset position
                    this.Generate(cnkSize, thdCtr, Output, OutOffset + (i * cnkSize));
                    // xor with input at offset
                    IntUtils.XORBLK(Input, InOffset + (i * cnkSize), Output, OutOffset + (i * cnkSize), cnkSize);
                    // store last counter
                    if (i == m_processorCount - 1)
                    {
                        Array.Copy(thdCtr, 0, tmpCtr, 0, thdCtr.Length);
                    }
                });

                // last block processing
                if (rndSize < prcSze)
                {
                    int fnlSize = prcSze % rndSize;
                    Generate(fnlSize, tmpCtr, Output, rndSize);

                    for (int i = 0; i < fnlSize; ++i)
                    {
                        Output[i + OutOffset + rndSize] ^= (byte)(Input[i + InOffset + rndSize]);
                    }
                }

                // copy the last counter position to class variable
                Array.Copy(tmpCtr, 0, m_ctrVector, 0, m_ctrVector.Length);
            }
        }