Exemplo n.º 1
0
        public override void ResetDirtyFlag()
        {
            lock (dirtyLock)
            {
                SerfCounts.ResetDirtyFlag();
                ResourceCounts.ResetDirtyFlag();
                CompletedBuildingCount.ResetDirtyFlag();
                IncompleteBuildingCount.ResetDirtyFlag();

                ResetDirtyFlagUnlocked();
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Creates a new GPU accessor state.
 /// </summary>
 /// <param name="poolState">GPU texture pool state</param>
 /// <param name="computeState">GPU compute state, for compute shaders</param>
 /// <param name="graphicsState">GPU graphics state, for vertex, tessellation, geometry and fragment shaders</param>
 /// <param name="specializationState">Shader specialization state (shared by all stages)</param>
 /// <param name="transformFeedbackDescriptors">Transform feedback information, if the shader uses transform feedback. Otherwise, should be null</param>
 public GpuAccessorState(
     GpuChannelPoolState poolState,
     GpuChannelComputeState computeState,
     GpuChannelGraphicsState graphicsState,
     ShaderSpecializationState specializationState,
     TransformFeedbackDescriptor[] transformFeedbackDescriptors = null)
 {
     PoolState                    = poolState;
     GraphicsState                = graphicsState;
     ComputeState                 = computeState;
     SpecializationState          = specializationState;
     TransformFeedbackDescriptors = transformFeedbackDescriptors;
     ResourceCounts               = new ResourceCounts();
 }
Exemplo n.º 3
0
        /// <summary>
        /// Recompiles a compute program from guest code.
        /// </summary>
        /// <param name="shaders">Shader stages</param>
        /// <param name="specState">Specialization state</param>
        /// <param name="programIndex">Program index</param>
        private void RecompileComputeFromGuestCode(CachedShaderStage[] shaders, ShaderSpecializationState specState, int programIndex)
        {
            CachedShaderStage         shader       = shaders[0];
            ResourceCounts            counts       = new ResourceCounts();
            ShaderSpecializationState newSpecState = new ShaderSpecializationState(specState.ComputeState);
            DiskCacheGpuAccessor      gpuAccessor  = new DiskCacheGpuAccessor(_context, shader.Code, shader.Cb1Data, specState, newSpecState, counts, 0);

            TranslatorContext translatorContext = DecodeComputeShader(gpuAccessor, 0);

            ShaderProgram program = translatorContext.Translate();

            shaders[0] = new CachedShaderStage(program.Info, shader.Code, shader.Cb1Data);

            _compilationQueue.Enqueue(new ProgramCompilation(new[] { program }, shaders, newSpecState, programIndex, isCompute: true));
        }
Exemplo n.º 4
0
 /// <summary>
 /// Creates a new instance of the cached GPU state accessor for shader translation.
 /// </summary>
 /// <param name="context">GPU context</param>
 /// <param name="data">The data of the shader</param>
 /// <param name="cb1Data">The constant buffer 1 data of the shader</param>
 /// <param name="oldSpecState">Shader specialization state of the cached shader</param>
 /// <param name="newSpecState">Shader specialization state of the recompiled shader</param>
 /// <param name="stageIndex">Shader stage index</param>
 public DiskCacheGpuAccessor(
     GpuContext context,
     ReadOnlyMemory <byte> data,
     ReadOnlyMemory <byte> cb1Data,
     ShaderSpecializationState oldSpecState,
     ShaderSpecializationState newSpecState,
     ResourceCounts counts,
     int stageIndex) : base(context)
 {
     _data           = data;
     _cb1Data        = cb1Data;
     _oldSpecState   = oldSpecState;
     _newSpecState   = newSpecState;
     _stageIndex     = stageIndex;
     _resourceCounts = counts;
 }
Exemplo n.º 5
0
 /// <summary>
 /// Creates a new instance of the cached GPU state accessor for shader translation.
 /// </summary>
 /// <param name="context">GPU context</param>
 /// <param name="data">The data of the shader</param>
 /// <param name="cb1Data">The constant buffer 1 data of the shader</param>
 /// <param name="oldSpecState">Shader specialization state of the cached shader</param>
 /// <param name="newSpecState">Shader specialization state of the recompiled shader</param>
 /// <param name="stageIndex">Shader stage index</param>
 public DiskCacheGpuAccessor(
     GpuContext context,
     ReadOnlyMemory <byte> data,
     ReadOnlyMemory <byte> cb1Data,
     ShaderSpecializationState oldSpecState,
     ShaderSpecializationState newSpecState,
     ResourceCounts counts,
     int stageIndex) : base(context, counts, stageIndex)
 {
     _data           = data;
     _cb1Data        = cb1Data;
     _oldSpecState   = oldSpecState;
     _newSpecState   = newSpecState;
     _stageIndex     = stageIndex;
     _isVulkan       = context.Capabilities.Api == TargetApi.Vulkan;
     _resourceCounts = counts;
 }
Exemplo n.º 6
0
        /// <summary>
        /// Recompiles a graphics program from guest code.
        /// </summary>
        /// <param name="shaders">Shader stages</param>
        /// <param name="specState">Specialization state</param>
        /// <param name="programIndex">Program index</param>
        private void RecompileGraphicsFromGuestCode(CachedShaderStage[] shaders, ShaderSpecializationState specState, int programIndex)
        {
            ShaderSpecializationState newSpecState = new ShaderSpecializationState(specState.GraphicsState, specState.TransformFeedbackDescriptors);
            ResourceCounts            counts       = new ResourceCounts();

            TranslatorContext[] translatorContexts = new TranslatorContext[Constants.ShaderStages + 1];
            TranslatorContext   nextStage          = null;

            for (int stageIndex = Constants.ShaderStages - 1; stageIndex >= 0; stageIndex--)
            {
                CachedShaderStage shader = shaders[stageIndex + 1];

                if (shader != null)
                {
                    byte[] guestCode = shader.Code;
                    byte[] cb1Data   = shader.Cb1Data;

                    DiskCacheGpuAccessor gpuAccessor  = new DiskCacheGpuAccessor(_context, guestCode, cb1Data, specState, newSpecState, counts, stageIndex);
                    TranslatorContext    currentStage = DecodeGraphicsShader(gpuAccessor, DefaultFlags, 0);

                    if (nextStage != null)
                    {
                        currentStage.SetNextStage(nextStage);
                    }

                    if (stageIndex == 0 && shaders[0] != null)
                    {
                        byte[] guestCodeA = shaders[0].Code;
                        byte[] cb1DataA   = shaders[0].Cb1Data;

                        DiskCacheGpuAccessor gpuAccessorA = new DiskCacheGpuAccessor(_context, guestCodeA, cb1DataA, specState, newSpecState, counts, 0);
                        translatorContexts[0] = DecodeGraphicsShader(gpuAccessorA, DefaultFlags | TranslationFlags.VertexA, 0);
                    }

                    translatorContexts[stageIndex + 1] = currentStage;
                    nextStage = currentStage;
                }
            }

            List <ShaderProgram> translatedStages = new List <ShaderProgram>();

            for (int stageIndex = 0; stageIndex < Constants.ShaderStages; stageIndex++)
            {
                TranslatorContext currentStage = translatorContexts[stageIndex + 1];

                if (currentStage != null)
                {
                    ShaderProgram program;

                    byte[] guestCode = shaders[stageIndex + 1].Code;
                    byte[] cb1Data   = shaders[stageIndex + 1].Cb1Data;

                    if (stageIndex == 0 && shaders[0] != null)
                    {
                        program = currentStage.Translate(translatorContexts[0]);

                        byte[] guestCodeA = shaders[0].Code;
                        byte[] cb1DataA   = shaders[0].Cb1Data;

                        shaders[0] = new CachedShaderStage(null, guestCodeA, cb1DataA);
                        shaders[1] = new CachedShaderStage(program.Info, guestCode, cb1Data);
                    }
                    else
                    {
                        program = currentStage.Translate();

                        shaders[stageIndex + 1] = new CachedShaderStage(program.Info, guestCode, cb1Data);
                    }

                    if (program != null)
                    {
                        translatedStages.Add(program);
                    }
                }
            }

            _compilationQueue.Enqueue(new ProgramCompilation(translatedStages.ToArray(), shaders, newSpecState, programIndex, isCompute: false));
        }