<commit_before>// Copyright 2017 The NXT Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef COMMON_VULKANPLATFORM_H_
#define COMMON_VULKANPLATFORM_H_

#if !defined(NXT_ENABLE_BACKEND_VULKAN)
#    error "vulkan_platform.h included without the Vulkan backend enabled"
#endif

#include <cstddef>
#include <cstdint>

// vulkan.h defines non-dispatchable handles to opaque pointers on 64bit architectures and uint64_t
// on 32bit architectures. This causes a problem in 32bit where the handles cannot be used to
// distinguish between overloads of the same function.
// Change the definition of non-dispatchable handles to be opaque structures containing a uint64_t
// and overload the comparison operators between themselves and VK_NULL_HANDLE (which will be
// redefined to be nullptr). This keeps the type-safety of having the handles be different types
// (like vulkan.h on 64 bit) but makes sure the types are different on 32 bit architectures.

// Simple handle types that supports "nullptr_t" as a 0 value.
template <typename Tag>
class VkNonDispatchableHandle {
  public:
    // Default constructor and assigning of VK_NULL_HANDLE
    VkNonDispatchableHandle() = default;
    VkNonDispatchableHandle(std::nullptr_t) : mHandle(0) {
    }

    // Use default copy constructor/assignment
    VkNonDispatchableHandle(const VkNonDispatchableHandle<Tag>& other) = default;
    VkNonDispatchableHandle& operator=(const VkNonDispatchableHandle<Tag>&) = default;

    // Comparisons between handles
    bool operator==(VkNonDispatchableHandle<Tag> other) {
        return mHandle == other.mHandle;
    }
    bool operator!=(VkNonDispatchableHandle<Tag> other) {
        return mHandle != other.mHandle;
    }

    // Comparisons between handles and VK_NULL_HANDLE
    bool operator==(std::nullptr_t) {
        return mHandle == 0;
    }
    bool operator!=(std::nullptr_t) {
        return mHandle != 0;
    }

    static VkNonDispatchableHandle<Tag> CreateFromHandle(uint64_t handle) {
        return {handle};
    }

  private:
    VkNonDispatchableHandle(uint64_t handle) : mHandle(handle) {
    }
<commit_msg>vulkan_platform: Add a method to get the uint64_t handle<commit_after>// Copyright 2017 The NXT Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef COMMON_VULKANPLATFORM_H_
#define COMMON_VULKANPLATFORM_H_

#if !defined(NXT_ENABLE_BACKEND_VULKAN)
#    error "vulkan_platform.h included without the Vulkan backend enabled"
#endif

#include <cstddef>
#include <cstdint>

// vulkan.h defines non-dispatchable handles to opaque pointers on 64bit architectures and uint64_t
// on 32bit architectures. This causes a problem in 32bit where the handles cannot be used to
// distinguish between overloads of the same function.
// Change the definition of non-dispatchable handles to be opaque structures containing a uint64_t
// and overload the comparison operators between themselves and VK_NULL_HANDLE (which will be
// redefined to be nullptr). This keeps the type-safety of having the handles be different types
// (like vulkan.h on 64 bit) but makes sure the types are different on 32 bit architectures.

// Simple handle types that supports "nullptr_t" as a 0 value.
template <typename Tag>
class VkNonDispatchableHandle {
  public:
    // Default constructor and assigning of VK_NULL_HANDLE
    VkNonDispatchableHandle() = default;
    VkNonDispatchableHandle(std::nullptr_t) : mHandle(0) {
    }

    // Use default copy constructor/assignment
    VkNonDispatchableHandle(const VkNonDispatchableHandle<Tag>& other) = default;
    VkNonDispatchableHandle& operator=(const VkNonDispatchableHandle<Tag>&) = default;

    // Comparisons between handles
    bool operator==(VkNonDispatchableHandle<Tag> other) {
        return mHandle == other.mHandle;
    }
    bool operator!=(VkNonDispatchableHandle<Tag> other) {
        return mHandle != other.mHandle;
    }

    // Comparisons between handles and VK_NULL_HANDLE
    bool operator==(std::nullptr_t) {
        return mHandle == 0;
    }
    bool operator!=(std::nullptr_t) {
        return mHandle != 0;
    }

    static VkNonDispatchableHandle<Tag> CreateFromHandle(uint64_t handle) {
        return {handle};
    }

    uint64_t GetHandle() const {
        return mHandle;
    }

  private:
    VkNonDispatchableHandle(uint64_t handle) : mHandle(handle) {
    }

{'fraction_non_alphanumeric': 0.07822685788787484, 'fraction_numerical': 0.011920283106723785, 'mean_word_length': 3.8075201432408234, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5804385', 'n_tokens_mistral': 1564, 'n_tokens_neox': 1494, 'n_words': 559}