{"action":"created","comment":{"url":"https://api.github.com/repos/gfx-rs/gfx/pulls/comments/212156922","pull_request_review_id":148727789,"id":212156922,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIxMjE1NjkyMg==","diff_hunk":"@@ -3454,31 +3501,192 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {\n \n     fn begin_query(\n         &mut self,\n-        _query: Query<Backend>,\n-        _flags: QueryControl,\n+        query: query::Query<Backend>,\n+        flags: query::ControlFlags,\n     ) {\n-        unimplemented!()\n+        match query.pool {\n+            native::QueryPool::Occlusion(ref pool_range) => {\n+                debug_assert!(pool_range.start + query.id < pool_range.end);\n+                let offset = (query.id + pool_range.start) as buffer::Offset * mem::size_of::<u64>() as buffer::Offset;\n+                let mode = if flags.contains(query::ControlFlags::PRECISE) {\n+                    metal::MTLVisibilityResultMode::Counting\n+                } else {\n+                    metal::MTLVisibilityResultMode::Boolean\n+                };\n+\n+                let com = self.state.set_visibility_query(mode, offset);\n+                self.inner\n+                    .borrow_mut()\n+                    .sink()\n+                    .pre_render()\n+                    .issue(com);\n+            }\n+        }\n     }\n \n     fn end_query(\n         &mut self,\n-        _query: Query<Backend>,\n+        query: query::Query<Backend>,\n     ) {\n-        unimplemented!()\n+        match query.pool {\n+            native::QueryPool::Occlusion(ref pool_range) => {\n+                let mut inner = self.inner.borrow_mut();\n+                debug_assert!(pool_range.start + query.id < pool_range.end);\n+                inner.active_visibility_queries.push(pool_range.start + query.id);\n+\n+                let com = self.state.set_visibility_query(metal::MTLVisibilityResultMode::Disabled, 0);\n+                inner\n+                    .sink()\n+                    .pre_render()\n+                    .issue(com);\n+            }\n+        }\n     }\n \n     fn reset_query_pool(\n         &mut self,\n-        _pool: &(),\n-        _queries: Range<QueryId>,\n+        pool: &native::QueryPool,\n+        queries: Range<query::Id>,\n     ) {\n-        unimplemented!()\n+        let visibility = &self.shared.visibility;\n+        match *pool {\n+            native::QueryPool::Occlusion(ref pool_range) => {\n+                let mut inner = self.inner.borrow_mut();\n+                debug_assert!(pool_range.start + queries.end <= pool_range.end);\n+                inner.active_visibility_queries.retain(|&id| id < pool_range.start + queries.start || id >= pool_range.start + queries.end);\n+\n+                let size_data = mem::size_of::<u64>() as buffer::Offset;\n+                let offset_data = pool_range.start as buffer::Offset * size_data;\n+                let command_data = soft::BlitCommand::FillBuffer {\n+                    dst: AsNative::from(visibility.buffer.as_ref()),\n+                    range:\n+                        offset_data + queries.start as buffer::Offset * size_data ..\n+                        offset_data + queries.end as buffer::Offset * size_data,\n+                    value: 0,\n+                };\n+\n+                let size_meta = mem::size_of::<u32>() as buffer::Offset;\n+                let offset_meta = visibility.availability_offset + pool_range.start as buffer::Offset * size_meta;\n+                let command_meta = soft::BlitCommand::FillBuffer {\n+                    dst: AsNative::from(visibility.buffer.as_ref()),\n+                    range:\n+                        offset_meta + queries.start as buffer::Offset * size_meta ..\n+                        offset_meta + queries.end as buffer::Offset * size_meta,\n+                    value: 0,\n+                };\n+\n+                let commands = iter::once(command_data)\n+                    .chain(iter::once(command_meta));\n+                inner\n+                    .sink()\n+                    .blit_commands(commands);\n+            }\n+        }\n+    }\n+\n+    fn copy_query_pool_results(\n+        &mut self,\n+        pool: &native::QueryPool,\n+        queries: Range<query::Id>,\n+        buffer: &native::Buffer,\n+        offset: buffer::Offset,\n+        stride: buffer::Offset,\n+        flags: query::ResultFlags,\n+    ) {\n+        match *pool {\n+            native::QueryPool::Occlusion(ref pool_range) => {\n+                let visibility = &self.shared.visibility;\n+                let size_data = mem::size_of::<u64>() as buffer::Offset;\n+                let size_meta = mem::size_of::<u32>() as buffer::Offset;\n+\n+                if stride == size_data && flags.contains(query::ResultFlags::BITS_64) &&\n+                    !flags.contains(query::ResultFlags::WITH_AVAILABILITY)\n+                {\n+                    // if stride is matching, copy everything in one go\n+                    let com = soft::BlitCommand::CopyBuffer {\n+                        src: AsNative::from(visibility.buffer.as_ref()),\n+                        dst: AsNative::from(buffer.raw.as_ref()),\n+                        region: com::BufferCopy {\n+                            src: (pool_range.start + queries.start) as buffer::Offset * size_data,\n+                            dst: buffer.range.start + offset,\n+                            size: (queries.end - queries.start) as buffer::Offset * size_data,\n+                        },\n+                    };\n+                    self.inner\n+                        .borrow_mut()\n+                        .sink()\n+                        .blit_commands(iter::once(com));\n+                } else {\n+                    // copy parts of individual entries\n+                    let size_payload = if flags.contains(query::ResultFlags::BITS_64) {\n+                        mem::size_of::<u64>() as buffer::Offset\n+                    } else {\n+                        mem::size_of::<u32>() as buffer::Offset\n+                    };\n+                    let commands = (0 .. queries.end - queries.start).flat_map(|i| {\n+                        let absolute_index = (pool_range.start + queries.start + i) as buffer::Offset;\n+                        let dst_offset = buffer.range.start + offset + i as buffer::Offset * stride;\n+                        let com_data = soft::BlitCommand::CopyBuffer {\n+                            src: AsNative::from(visibility.buffer.as_ref()),\n+                            dst: AsNative::from(buffer.raw.as_ref()),\n+                            region: com::BufferCopy {\n+                                src: absolute_index * size_data,\n+                                dst: dst_offset,\n+                                size: size_payload,\n+                            },\n+                        };\n+\n+                        let (com_avail, com_pad) = if flags.contains(query::ResultFlags::WITH_AVAILABILITY | query::ResultFlags::WAIT) {\n+                            // Technically waiting is a no-op on a single queue. However,\n+                            // the client expects the avaiability to be set regardless.","path":"src/backend/metal/src/command.rs","position":361,"original_position":361,"commit_id":"def110ebb5f05adcbbca402bcb8f58b5f42f9541","original_commit_id":"def110ebb5f05adcbbca402bcb8f58b5f42f9541","user":{"login":"grovesNL","id":2113872,"node_id":"MDQ6VXNlcjIxMTM4NzI=","avatar_url":"https://avatars3.githubusercontent.com/u/2113872?v=4","gravatar_id":"","url":"https://api.github.com/users/grovesNL","html_url":"https://github.com/grovesNL","followers_url":"https://api.github.com/users/grovesNL/followers","following_url":"https://api.github.com/users/grovesNL/following{/other_user}","gists_url":"https://api.github.com/users/grovesNL/gists{/gist_id}","starred_url":"https://api.github.com/users/grovesNL/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/grovesNL/subscriptions","organizations_url":"https://api.github.com/users/grovesNL/orgs","repos_url":"https://api.github.com/users/grovesNL/repos","events_url":"https://api.github.com/users/grovesNL/events{/privacy}","received_events_url":"https://api.github.com/users/grovesNL/received_events","type":"User","site_admin":false},"body":"`avaiability` -> `availability`","created_at":"2018-08-23T01:12:23Z","updated_at":"2018-08-23T01:12:23Z","html_url":"https://github.com/gfx-rs/gfx/pull/2334#discussion_r212156922","pull_request_url":"https://api.github.com/repos/gfx-rs/gfx/pulls/2334","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/gfx-rs/gfx/pulls/comments/212156922"},"html":{"href":"https://github.com/gfx-rs/gfx/pull/2334#discussion_r212156922"},"pull_request":{"href":"https://api.github.com/repos/gfx-rs/gfx/pulls/2334"}}},"pull_request":{"url":"https://api.github.com/repos/gfx-rs/gfx/pulls/2334","id":209587539,"node_id":"MDExOlB1bGxSZXF1ZXN0MjA5NTg3NTM5","html_url":"https://github.com/gfx-rs/gfx/pull/2334","diff_url":"https://github.com/gfx-rs/gfx/pull/2334.diff","patch_url":"https://github.com/gfx-rs/gfx/pull/2334.patch","issue_url":"https://api.github.com/repos/gfx-rs/gfx/issues/2334","number":2334,"state":"open","locked":false,"title":"Query API and basic support on Metal","user":{"login":"kvark","id":107301,"node_id":"MDQ6VXNlcjEwNzMwMQ==","avatar_url":"https://avatars1.githubusercontent.com/u/107301?v=4","gravatar_id":"","url":"https://api.github.com/users/kvark","html_url":"https://github.com/kvark","followers_url":"https://api.github.com/users/kvark/followers","following_url":"https://api.github.com/users/kvark/following{/other_user}","gists_url":"https://api.github.com/users/kvark/gists{/gist_id}","starred_url":"https://api.github.com/users/kvark/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kvark/subscriptions","organizations_url":"https://api.github.com/users/kvark/orgs","repos_url":"https://api.github.com/users/kvark/repos","events_url":"https://api.github.com/users/kvark/events{/privacy}","received_events_url":"https://api.github.com/users/kvark/received_events","type":"User","site_admin":false},"body":"Fixes #1638 (for the most part)\r\nPR checklist:\r\n- [x] `make` succeeds (on *nix)\r\n- [x] `make reftests` succeeds\r\n- [ ] tested examples with the following backends:\r\n- [ ] `rustfmt` run on changed code\r\n","created_at":"2018-08-20T17:15:03Z","updated_at":"2018-08-23T01:12:23Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5999a8e890a2f0f60c2bbd0a476ff88a9d92792a","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/gfx-rs/gfx/pulls/2334/commits","review_comments_url":"https://api.github.com/repos/gfx-rs/gfx/pulls/2334/comments","review_comment_url":"https://api.github.com/repos/gfx-rs/gfx/pulls/comments{/number}","comments_url":"https://api.github.com/repos/gfx-rs/gfx/issues/2334/comments","statuses_url":"https://api.github.com/repos/gfx-rs/gfx/statuses/def110ebb5f05adcbbca402bcb8f58b5f42f9541","head":{"label":"kvark:query","ref":"query","sha":"def110ebb5f05adcbbca402bcb8f58b5f42f9541","user":{"login":"kvark","id":107301,"node_id":"MDQ6VXNlcjEwNzMwMQ==","avatar_url":"https://avatars1.githubusercontent.com/u/107301?v=4","gravatar_id":"","url":"https://api.github.com/users/kvark","html_url":"https://github.com/kvark","followers_url":"https://api.github.com/users/kvark/followers","following_url":"https://api.github.com/users/kvark/following{/other_user}","gists_url":"https://api.github.com/users/kvark/gists{/gist_id}","starred_url":"https://api.github.com/users/kvark/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kvark/subscriptions","organizations_url":"https://api.github.com/users/kvark/orgs","repos_url":"https://api.github.com/users/kvark/repos","events_url":"https://api.github.com/users/kvark/events{/privacy}","received_events_url":"https://api.github.com/users/kvark/received_events","type":"User","site_admin":false},"repo":{"id":21021936,"node_id":"MDEwOlJlcG9zaXRvcnkyMTAyMTkzNg==","name":"gfx","full_name":"kvark/gfx","owner":{"login":"kvark","id":107301,"node_id":"MDQ6VXNlcjEwNzMwMQ==","avatar_url":"https://avatars1.githubusercontent.com/u/107301?v=4","gravatar_id":"","url":"https://api.github.com/users/kvark","html_url":"https://github.com/kvark","followers_url":"https://api.github.com/users/kvark/followers","following_url":"https://api.github.com/users/kvark/following{/other_user}","gists_url":"https://api.github.com/users/kvark/gists{/gist_id}","starred_url":"https://api.github.com/users/kvark/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kvark/subscriptions","organizations_url":"https://api.github.com/users/kvark/orgs","repos_url":"https://api.github.com/users/kvark/repos","events_url":"https://api.github.com/users/kvark/events{/privacy}","received_events_url":"https://api.github.com/users/kvark/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/kvark/gfx","description":"A lightweight graphics device manager for Rust","fork":true,"url":"https://api.github.com/repos/kvark/gfx","forks_url":"https://api.github.com/repos/kvark/gfx/forks","keys_url":"https://api.github.com/repos/kvark/gfx/keys{/key_id}","collaborators_url":"https://api.github.com/repos/kvark/gfx/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/kvark/gfx/teams","hooks_url":"https://api.github.com/repos/kvark/gfx/hooks","issue_events_url":"https://api.github.com/repos/kvark/gfx/issues/events{/number}","events_url":"https://api.github.com/repos/kvark/gfx/events","assignees_url":"https://api.github.com/repos/kvark/gfx/assignees{/user}","branches_url":"https://api.github.com/repos/kvark/gfx/branches{/branch}","tags_url":"https://api.github.com/repos/kvark/gfx/tags","blobs_url":"https://api.github.com/repos/kvark/gfx/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/kvark/gfx/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/kvark/gfx/git/refs{/sha}","trees_url":"https://api.github.com/repos/kvark/gfx/git/trees{/sha}","statuses_url":"https://api.github.com/repos/kvark/gfx/statuses/{sha}","languages_url":"https://api.github.com/repos/kvark/gfx/languages","stargazers_url":"https://api.github.com/repos/kvark/gfx/stargazers","contributors_url":"https://api.github.com/repos/kvark/gfx/contributors","subscribers_url":"https://api.github.com/repos/kvark/gfx/subscribers","subscription_url":"https://api.github.com/repos/kvark/gfx/subscription","commits_url":"https://api.github.com/repos/kvark/gfx/commits{/sha}","git_commits_url":"https://api.github.com/repos/kvark/gfx/git/commits{/sha}","comments_url":"https://api.github.com/repos/kvark/gfx/comments{/number}","issue_comment_url":"https://api.github.com/repos/kvark/gfx/issues/comments{/number}","contents_url":"https://api.github.com/repos/kvark/gfx/contents/{+path}","compare_url":"https://api.github.com/repos/kvark/gfx/compare/{base}...{head}","merges_url":"https://api.github.com/repos/kvark/gfx/merges","archive_url":"https://api.github.com/repos/kvark/gfx/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/kvark/gfx/downloads","issues_url":"https://api.github.com/repos/kvark/gfx/issues{/number}","pulls_url":"https://api.github.com/repos/kvark/gfx/pulls{/number}","milestones_url":"https://api.github.com/repos/kvark/gfx/milestones{/number}","notifications_url":"https://api.github.com/repos/kvark/gfx/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/kvark/gfx/labels{/name}","releases_url":"https://api.github.com/repos/kvark/gfx/releases{/id}","deployments_url":"https://api.github.com/repos/kvark/gfx/deployments","created_at":"2014-06-20T01:55:38Z","updated_at":"2018-07-27T01:12:11Z","pushed_at":"2018-08-22T19:23:32Z","git_url":"git://github.com/kvark/gfx.git","ssh_url":"git@github.com:kvark/gfx.git","clone_url":"https://github.com/kvark/gfx.git","svn_url":"https://github.com/kvark/gfx","homepage":"","size":15484,"stargazers_count":0,"watchers_count":0,"language":"Rust","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"other","name":"Other","spdx_id":null,"url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"gfx-rs:master","ref":"master","sha":"ed120a46aa58bc4206cd86b78701c6670cf0868a","user":{"login":"gfx-rs","id":8213174,"node_id":"MDEyOk9yZ2FuaXphdGlvbjgyMTMxNzQ=","avatar_url":"https://avatars3.githubusercontent.com/u/8213174?v=4","gravatar_id":"","url":"https://api.github.com/users/gfx-rs","html_url":"https://github.com/gfx-rs","followers_url":"https://api.github.com/users/gfx-rs/followers","following_url":"https://api.github.com/users/gfx-rs/following{/other_user}","gists_url":"https://api.github.com/users/gfx-rs/gists{/gist_id}","starred_url":"https://api.github.com/users/gfx-rs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gfx-rs/subscriptions","organizations_url":"https://api.github.com/users/gfx-rs/orgs","repos_url":"https://api.github.com/users/gfx-rs/repos","events_url":"https://api.github.com/users/gfx-rs/events{/privacy}","received_events_url":"https://api.github.com/users/gfx-rs/received_events","type":"Organization","site_admin":false},"repo":{"id":13847975,"node_id":"MDEwOlJlcG9zaXRvcnkxMzg0Nzk3NQ==","name":"gfx","full_name":"gfx-rs/gfx","owner":{"login":"gfx-rs","id":8213174,"node_id":"MDEyOk9yZ2FuaXphdGlvbjgyMTMxNzQ=","avatar_url":"https://avatars3.githubusercontent.com/u/8213174?v=4","gravatar_id":"","url":"https://api.github.com/users/gfx-rs","html_url":"https://github.com/gfx-rs","followers_url":"https://api.github.com/users/gfx-rs/followers","following_url":"https://api.github.com/users/gfx-rs/following{/other_user}","gists_url":"https://api.github.com/users/gfx-rs/gists{/gist_id}","starred_url":"https://api.github.com/users/gfx-rs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gfx-rs/subscriptions","organizations_url":"https://api.github.com/users/gfx-rs/orgs","repos_url":"https://api.github.com/users/gfx-rs/repos","events_url":"https://api.github.com/users/gfx-rs/events{/privacy}","received_events_url":"https://api.github.com/users/gfx-rs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/gfx-rs/gfx","description":"A high-performance, bindless graphics API for Rust.","fork":false,"url":"https://api.github.com/repos/gfx-rs/gfx","forks_url":"https://api.github.com/repos/gfx-rs/gfx/forks","keys_url":"https://api.github.com/repos/gfx-rs/gfx/keys{/key_id}","collaborators_url":"https://api.github.com/repos/gfx-rs/gfx/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/gfx-rs/gfx/teams","hooks_url":"https://api.github.com/repos/gfx-rs/gfx/hooks","issue_events_url":"https://api.github.com/repos/gfx-rs/gfx/issues/events{/number}","events_url":"https://api.github.com/repos/gfx-rs/gfx/events","assignees_url":"https://api.github.com/repos/gfx-rs/gfx/assignees{/user}","branches_url":"https://api.github.com/repos/gfx-rs/gfx/branches{/branch}","tags_url":"https://api.github.com/repos/gfx-rs/gfx/tags","blobs_url":"https://api.github.com/repos/gfx-rs/gfx/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/gfx-rs/gfx/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/gfx-rs/gfx/git/refs{/sha}","trees_url":"https://api.github.com/repos/gfx-rs/gfx/git/trees{/sha}","statuses_url":"https://api.github.com/repos/gfx-rs/gfx/statuses/{sha}","languages_url":"https://api.github.com/repos/gfx-rs/gfx/languages","stargazers_url":"https://api.github.com/repos/gfx-rs/gfx/stargazers","contributors_url":"https://api.github.com/repos/gfx-rs/gfx/contributors","subscribers_url":"https://api.github.com/repos/gfx-rs/gfx/subscribers","subscription_url":"https://api.github.com/repos/gfx-rs/gfx/subscription","commits_url":"https://api.github.com/repos/gfx-rs/gfx/commits{/sha}","git_commits_url":"https://api.github.com/repos/gfx-rs/gfx/git/commits{/sha}","comments_url":"https://api.github.com/repos/gfx-rs/gfx/comments{/number}","issue_comment_url":"https://api.github.com/repos/gfx-rs/gfx/issues/comments{/number}","contents_url":"https://api.github.com/repos/gfx-rs/gfx/contents/{+path}","compare_url":"https://api.github.com/repos/gfx-rs/gfx/compare/{base}...{head}","merges_url":"https://api.github.com/repos/gfx-rs/gfx/merges","archive_url":"https://api.github.com/repos/gfx-rs/gfx/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/gfx-rs/gfx/downloads","issues_url":"https://api.github.com/repos/gfx-rs/gfx/issues{/number}","pulls_url":"https://api.github.com/repos/gfx-rs/gfx/pulls{/number}","milestones_url":"https://api.github.com/repos/gfx-rs/gfx/milestones{/number}","notifications_url":"https://api.github.com/repos/gfx-rs/gfx/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/gfx-rs/gfx/labels{/name}","releases_url":"https://api.github.com/repos/gfx-rs/gfx/releases{/id}","deployments_url":"https://api.github.com/repos/gfx-rs/gfx/deployments","created_at":"2013-10-25T00:35:35Z","updated_at":"2018-08-22T23:46:24Z","pushed_at":"2018-08-22T19:23:34Z","git_url":"git://github.com/gfx-rs/gfx.git","ssh_url":"git@github.com:gfx-rs/gfx.git","clone_url":"https://github.com/gfx-rs/gfx.git","svn_url":"https://github.com/gfx-rs/gfx","homepage":"http://gfx-rs.github.io/","size":15385,"stargazers_count":1994,"watchers_count":1994,"language":"Rust","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":270,"mirror_url":null,"archived":false,"open_issues_count":281,"license":{"key":"other","name":"Other","spdx_id":null,"url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":270,"open_issues":281,"watchers":1994,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/gfx-rs/gfx/pulls/2334"},"html":{"href":"https://github.com/gfx-rs/gfx/pull/2334"},"issue":{"href":"https://api.github.com/repos/gfx-rs/gfx/issues/2334"},"comments":{"href":"https://api.github.com/repos/gfx-rs/gfx/issues/2334/comments"},"review_comments":{"href":"https://api.github.com/repos/gfx-rs/gfx/pulls/2334/comments"},"review_comment":{"href":"https://api.github.com/repos/gfx-rs/gfx/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/gfx-rs/gfx/pulls/2334/commits"},"statuses":{"href":"https://api.github.com/repos/gfx-rs/gfx/statuses/def110ebb5f05adcbbca402bcb8f58b5f42f9541"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"grovesNL"}}