#pragma once #include "RuntimeSnapshotProvider.h" #include "ShaderTypes.h" #include #include #include #include #include #include struct PreparedLayerShader { RuntimeRenderState state; std::vector passes; }; struct PreparedShaderBuild { uint64_t generation = 0; bool succeeded = false; std::string message; RuntimeRenderStateSnapshot renderSnapshot; std::vector layers; }; class ShaderBuildQueue { public: explicit ShaderBuildQueue(RuntimeSnapshotProvider& runtimeSnapshotProvider); ~ShaderBuildQueue(); ShaderBuildQueue(const ShaderBuildQueue&) = delete; ShaderBuildQueue& operator=(const ShaderBuildQueue&) = delete; void RequestBuild(unsigned outputWidth, unsigned outputHeight); bool TryConsumeReadyBuild(PreparedShaderBuild& build); void Stop(); private: void WorkerLoop(); PreparedShaderBuild Build(uint64_t generation, unsigned outputWidth, unsigned outputHeight); RuntimeSnapshotProvider& mRuntimeSnapshotProvider; std::thread mWorkerThread; std::mutex mMutex; std::condition_variable mCondition; bool mStopping = false; bool mHasRequest = false; uint64_t mRequestedGeneration = 0; unsigned mRequestedOutputWidth = 0; unsigned mRequestedOutputHeight = 0; bool mHasReadyBuild = false; PreparedShaderBuild mReadyBuild; };