Exemple #1
0
        public void Process(GraphicsContext graphicsContext, MiscProcessContext context)
        {
            if (!Ready)
            {
                return;
            }
            if (context.miscProcessPairs.Count == 0)
            {
                return;
            }
            graphicsContext.BeginCommand();
            graphicsContext.SetDescriptorHeapDefault();
            for (int i = 0; i < context.miscProcessPairs.Count; i++)
            {
                var    texture0 = context.miscProcessPairs[i].source;
                var    texture1 = context.miscProcessPairs[i].IrradianceMap;
                var    texture2 = context.miscProcessPairs[i].EnvMap;
                IntPtr ptr1     = Marshal.UnsafeAddrOfPinnedArrayElement(cpuBuffer1, 0);
                _XyzData.x1      = (int)texture1.m_width;
                _XyzData.y1      = (int)texture1.m_height;
                _XyzData.x2      = (int)texture2.m_width;
                _XyzData.y2      = (int)texture2.m_height;
                _XyzData.Quality = context.miscProcessPairs[i].Level;
                int itCount = context.miscProcessPairs[i].Level;

                for (int j = 0; j < itCount; j++)
                {
                    _XyzData.Batch = j;

                    Marshal.StructureToPtr(_XyzData, ptr1 + j * c_splitSize, true);
                }
                graphicsContext.UpdateResource(constantBuffers, cpuBuffer1, c_bufferSize, 0);

                graphicsContext.SetRootSignatureCompute(rootSignature);
                graphicsContext.SetComputeCBVR(constantBuffers, 0);
                graphicsContext.SetComputeSRVT(texture0, 2);
                graphicsContext.SetPObject(ClearIrradianceMap);

                int pow2a = 1;
                for (int j = 0; j < texture1.m_mipLevels; j++)
                {
                    graphicsContext.SetComputeUAVT(texture1, j, 3);
                    graphicsContext.Dispatch((int)(texture1.m_width + 7) / 8 / pow2a, (int)(texture1.m_height + 7) / 8 / pow2a, 6);
                    pow2a *= 2;
                }
                pow2a = 1;
                for (int j = 0; j < texture2.m_mipLevels; j++)
                {
                    graphicsContext.SetComputeUAVT(texture2, j, 3);
                    graphicsContext.Dispatch((int)(texture2.m_width + 7) / 8 / pow2a, (int)(texture2.m_height + 7) / 8 / pow2a, 6);
                    pow2a *= 2;
                }
                //graphicsContext.ClearTextureRTV(texture1);
                //graphicsContext.ClearTextureRTV(texture2);
                graphicsContext.SetPObject(IrradianceMap0);

                pow2a = 1;
                for (int j = 0; j < texture1.m_mipLevels; j++)
                {
                    for (int k = 0; k < itCount; k++)
                    {
                        graphicsContext.SetComputeUAVT(texture1, j, 3);
                        graphicsContext.SetComputeCBVR(constantBuffers, k, 1, 0);
                        graphicsContext.Dispatch((int)(texture1.m_width + 7) / 8 / pow2a, (int)(texture1.m_height + 7) / 8 / pow2a, 6);
                    }
                    pow2a *= 2;
                }

                graphicsContext.SetComputeSRVT(texture0, 2);
                graphicsContext.SetPObject(EnvironmentMap0);
                pow2a = 1;
                for (int j = 0; j < texture2.m_mipLevels; j++)
                {
                    for (int k = 0; k < itCount; k++)
                    {
                        graphicsContext.SetComputeUAVT(texture2, j, 3);
                        graphicsContext.SetComputeCBVR(constantBuffers, k, 1, 0);
                        graphicsContext.SetComputeCBVR(constantBuffers, j, 1, 1);
                        graphicsContext.Dispatch((int)(texture2.m_width + 7) / 8 / pow2a, (int)(texture2.m_height + 7) / 8 / pow2a, 6);
                    }
                    pow2a *= 2;
                }
            }
            graphicsContext.EndCommand();
            graphicsContext.Execute();
            context.Clear();
        }