Changeset View
Standalone View
source/blender/gpu/intern/gpu_context_private.hh
| Show First 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | public: | ||||
| */ | */ | ||||
| FrameBuffer *back_left = nullptr; | FrameBuffer *back_left = nullptr; | ||||
| FrameBuffer *front_left = nullptr; | FrameBuffer *front_left = nullptr; | ||||
| FrameBuffer *back_right = nullptr; | FrameBuffer *back_right = nullptr; | ||||
| FrameBuffer *front_right = nullptr; | FrameBuffer *front_right = nullptr; | ||||
| DebugStack debug_stack; | DebugStack debug_stack; | ||||
| /* GPUContext counter used to assign a unique ID to each GPUContext. | |||||
| * NOTE(Metal): This is required by the Metal Backend, as a bug exists in the global OS shader | |||||
fclem: So by the look of it, this is not a count, but a counter to assign unique IDs to each context. | |||||
Not Done Inline ActionsI can clarify this comment. This is to deal with a source collision, which happens particularly if shader compilation is occurring on different threads for the same shader source. This is a problem with the OS-level global shader cache, and only affects certain older OS's, rather than anything inside Blender itself. The context ID being a number ensures we can still benefit from shader caching between runs of the application, as this ID is appended onto the end of the source to make it slightly different, though ensuring that the same source hashes will exist between runs. Unfortunately using the pointer would produce a different result between re-runs meaning full shader compilation would happen every time. MichaelPW: I can clarify this comment. This is to deal with a source collision, which happens particularly… | |||||
Not Done Inline ActionsWell my issue is that a new context is created for each render context. So does this mean doing multiple render will always create a new shader in the OS cache? The material thumbnails also use a temporary context if I remember correctly. fclem: Well my issue is that a new context is created for each render context. So does this mean doing… | |||||
Not Done Inline ActionsIn most cases, this is avoided, and once the cache is populated with several permutations, there are no issues on future runs. However, I'll add an OS version guard for this, and only apply the context ID to the affected OS, as it is still needed to avoid crashing. (Even guarding compilation on the app-side can be problematic, as shading cache is still handled outside of the app). If it is preferred, the ContextID can be moved inside the Metal backend? MichaelPW: In most cases, this is avoided, and once the cache is populated with several permutations… | |||||
Not Done Inline Actions
Absolutely. This makes it clearer that this is Metal related. Also would put a bit more context (not the full context, maybe a link to a more in depth comment) in the comment about why this is needed. fclem: >If it is preferred, the ContextID can be moved inside the Metal backend?
Absolutely. This… | |||||
| * cache wherein compilation of identical source from two distinct threads can result in an | |||||
| * invalid cache collision, result in a broken shader object. Appending the unique context ID | |||||
| * onto compiled sources ensures the source hashes are different. */ | |||||
| static int context_counter; | |||||
| int context_id = 0; | |||||
| protected: | protected: | ||||
| /** Thread on which this context is active. */ | /** Thread on which this context is active. */ | ||||
| pthread_t thread_; | pthread_t thread_; | ||||
| bool is_active_; | bool is_active_; | ||||
| /** Avoid including GHOST headers. Can be nullptr for off-screen contexts. */ | /** Avoid including GHOST headers. Can be nullptr for off-screen contexts. */ | ||||
| void *ghost_window_; | void *ghost_window_; | ||||
| public: | public: | ||||
| Show All 38 Lines | |||||
So by the look of it, this is not a count, but a counter to assign unique IDs to each context. So I would rename this context_counter.
I wonder if you could use the context pointer itself as ID instead of this, as this seems to only be used to generate MTL_CONTEXT_IND. By the way, could you explain why this is necessary? What is this cross-context source collisions thing? Is that because you use the shader string as a hashmap key? and shaders need to be unique per context? If that is the case I think using the pointer to generate the id is enough. But maybe I am missing something.