add usd-21-11-win64_py39

This commit is contained in:
Sébastien Albert committed 2021-12-07 17:43:55 +01:00
1 parent 41d23e71ba
commit ba5e1f7e67
15684 files changed
+3069957

No files matched your search

+47
View File
@@ -0,0 +1,47 @@
//
// Copyright 2019 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_IMAGING_HGI_API_H
#define PXR_IMAGING_HGI_API_H
#include "pxr/base/arch/export.h"
#if defined(PXR_STATIC)
# define HGI_API
# define HGI_API_TEMPLATE_CLASS(...)
# define HGI_API_TEMPLATE_STRUCT(...)
# define HGI_LOCAL
#else
# if defined(HGI_EXPORTS)
# define HGI_API ARCH_EXPORT
# define HGI_API_TEMPLATE_CLASS(...) ARCH_EXPORT_TEMPLATE(class, __VA_ARGS__)
# define HGI_API_TEMPLATE_STRUCT(...) ARCH_EXPORT_TEMPLATE(struct, __VA_ARGS__)
# else
# define HGI_API ARCH_IMPORT
# define HGI_API_TEMPLATE_CLASS(...) ARCH_IMPORT_TEMPLATE(class, __VA_ARGS__)
# define HGI_API_TEMPLATE_STRUCT(...) ARCH_IMPORT_TEMPLATE(struct, __VA_ARGS__)
# endif
# define HGI_LOCAL ARCH_HIDDEN
#endif
#endif // PXR_IMAGING_HGI_API_H
+112
View File
@@ -0,0 +1,112 @@
//
// Copyright 2020 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_IMAGING_HGI_ATTACHMENT_DESC_H
#define PXR_IMAGING_HGI_ATTACHMENT_DESC_H
#include "pxr/pxr.h"
#include "pxr/imaging/hgi/api.h"
#include "pxr/imaging/hgi/enums.h"
#include "pxr/imaging/hgi/types.h"
#include "pxr/base/gf/vec4f.h"
#include <vector>
PXR_NAMESPACE_OPEN_SCOPE
/// \struct HgiAttachmentDesc
///
/// Describes the properties of a framebuffer attachment.
///
/// <ul>
/// <li>format:
/// The format of the attachment.
/// Must match what is set in HgiTextureDesc.</li>
/// <li>usage:
/// Describes how the texture is intended to be used.
/// Must match what is set in HgiTextureDesc.</li>
/// <li>loadOp:
/// The operation to perform on the attachment pixel data prior to rendering.</li>
/// <li>storeOp:
/// The operation to perform on the attachment pixel data after rendering.</li>
/// <li>clearValue:
/// The value to clear the attachment with (r,g,b,a) or (depth,stencil,x,x)</li>
/// <li>blendEnabled:
/// Determines if a blend operation should be applied to the attachment.</li>
/// <li> ***BlendFactor:
/// The blend factors for source and destination.</li>
/// <li> ***BlendOp:
/// The blending operation.</li>
///
struct HgiAttachmentDesc
{
HgiAttachmentDesc()
: format(HgiFormatInvalid)
, usage(0)
, loadOp(HgiAttachmentLoadOpLoad)
, storeOp(HgiAttachmentStoreOpStore)
, clearValue(0)
, blendEnabled(false)
, srcColorBlendFactor(HgiBlendFactorZero)
, dstColorBlendFactor(HgiBlendFactorZero)
, colorBlendOp(HgiBlendOpAdd)
, srcAlphaBlendFactor(HgiBlendFactorZero)
, dstAlphaBlendFactor(HgiBlendFactorZero)
, alphaBlendOp(HgiBlendOpAdd)
{}
HgiFormat format;
HgiTextureUsage usage;
HgiAttachmentLoadOp loadOp;
HgiAttachmentStoreOp storeOp;
GfVec4f clearValue;
bool blendEnabled;
HgiBlendFactor srcColorBlendFactor;
HgiBlendFactor dstColorBlendFactor;
HgiBlendOp colorBlendOp;
HgiBlendFactor srcAlphaBlendFactor;
HgiBlendFactor dstAlphaBlendFactor;
HgiBlendOp alphaBlendOp;
};
using HgiAttachmentDescVector = std::vector<HgiAttachmentDesc>;
HGI_API
bool operator==(
const HgiAttachmentDesc& lhs,
const HgiAttachmentDesc& rhs);
HGI_API
bool operator!=(
const HgiAttachmentDesc& lhs,
const HgiAttachmentDesc& rhs);
HGI_API
std::ostream& operator<<(
std::ostream& out,
const HgiAttachmentDesc& attachment);
PXR_NAMESPACE_CLOSE_SCOPE
#endif
+123
View File
@@ -0,0 +1,123 @@
//
// Copyright 2019 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_IMAGING_HGI_BLIT_CMDS_H
#define PXR_IMAGING_HGI_BLIT_CMDS_H
#include "pxr/pxr.h"
#include "pxr/imaging/hgi/api.h"
#include "pxr/imaging/hgi/buffer.h"
#include "pxr/imaging/hgi/cmds.h"
#include "pxr/imaging/hgi/texture.h"
#include <memory>
PXR_NAMESPACE_OPEN_SCOPE
struct HgiTextureGpuToCpuOp;
struct HgiTextureCpuToGpuOp;
struct HgiBufferGpuToGpuOp;
struct HgiBufferCpuToGpuOp;
struct HgiBufferGpuToCpuOp;
struct HgiTextureToBufferOp;
struct HgiBufferToTextureOp;
struct HgiResolveImageOp;
using HgiBlitCmdsUniquePtr = std::unique_ptr<class HgiBlitCmds>;
/// \class HgiBlitCmds
///
/// A graphics API independent abstraction of resource copy commands.
/// HgiBlitCmds is a lightweight object that cannot be re-used after it has
/// been submitted. A new cmds object should be acquired for each frame.
///
class HgiBlitCmds : public HgiCmds
{
public:
HGI_API
~HgiBlitCmds() override;
/// Push a debug marker.
HGI_API
virtual void PushDebugGroup(const char* label) = 0;
/// Pop the lastest debug.
HGI_API
virtual void PopDebugGroup() = 0;
/// Copy a texture resource from GPU to CPU.
/// Synchronization between GPU writes and CPU reads must be managed by
/// the client by supplying the correct 'wait' flags in SubmitCmds.
HGI_API
virtual void CopyTextureGpuToCpu(HgiTextureGpuToCpuOp const& copyOp) = 0;
/// Copy new data from the CPU into a GPU texture.
HGI_API
virtual void CopyTextureCpuToGpu(HgiTextureCpuToGpuOp const& copyOp) = 0;
/// Copy a buffer resource from GPU to GPU.
HGI_API
virtual void CopyBufferGpuToGpu(HgiBufferGpuToGpuOp const& copyOp) = 0;
/// Copy new data from CPU into GPU buffer.
/// For example copy new data into a uniform block or storage buffer.
HGI_API
virtual void CopyBufferCpuToGpu(HgiBufferCpuToGpuOp const& copyOp) = 0;
/// Copy new data from GPU into CPU buffer.
/// Synchronization between GPU writes and CPU reads must be managed by
/// the client by supplying the correct 'wait' flags in SubmitCmds.
HGI_API
virtual void CopyBufferGpuToCpu(HgiBufferGpuToCpuOp const& copyOp) = 0;
/// Copy a texture resource into a buffer resource from GPU to GPU.
HGI_API
virtual void CopyTextureToBuffer(HgiTextureToBufferOp const& copyOp) = 0;
/// Copy a buffer resource into a texture resource from GPU to GPU.
HGI_API
virtual void CopyBufferToTexture(HgiBufferToTextureOp const& copyOp) = 0;
/// Generate mip maps for a texture
HGI_API
virtual void GenerateMipMaps(HgiTextureHandle const& texture) = 0;
/// Inserts a barrier so that data written to memory by commands before
/// the barrier is available to commands after the barrier.
HGI_API
virtual void MemoryBarrier(HgiMemoryBarrier barrier) = 0;
protected:
HGI_API
HgiBlitCmds();
private:
HgiBlitCmds & operator=(const HgiBlitCmds&) = delete;
HgiBlitCmds(const HgiBlitCmds&) = delete;
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif
+336
View File
@@ -0,0 +1,336 @@
//
// Copyright 2019 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_IMAGING_HGI_BLIT_CMDS_OPS_H
#define PXR_IMAGING_HGI_BLIT_CMDS_OPS_H
#include "pxr/pxr.h"
#include "pxr/base/gf/vec3i.h"
#include "pxr/imaging/hgi/api.h"
#include "pxr/imaging/hgi/buffer.h"
#include "pxr/imaging/hgi/enums.h"
#include "pxr/imaging/hgi/texture.h"
#include "pxr/imaging/hgi/types.h"
#include <stddef.h>
PXR_NAMESPACE_OPEN_SCOPE
//// \struct HgiTextureGpuToCpuOp
///
/// Describes the properties needed to copy texture data from GPU to CPU.
/// This copies one mip at a time.
///
/// It is the responsibility of the caller to:
/// - ensure the destination buffer is large enough to receive the data
/// (keep in mind the destinationByteOffset, mipLevel, numLayers, etc).
/// - ensure the source texture and destination buffer are valid at the time
/// the command is executed.
///
/// <ul>
/// <li>gpuSourceTexture:
/// The gpu texture to copy pixels from.</li>
/// <li>sourceTexelOffset:
/// The texel offset (width, height, depth) of where to start copying.
/// If the texture is a 2d_array the third element is the layer/slice.</li>
/// <li>mipLevel:
/// Mip level to copy from.</li>
/// <li>cpuDestinationBuffer:
/// The copy destination cpu buffer.</li>
/// <li>destinationByteOffset:
/// The byte offset in destination buffer where to start copying the data to.</li>
/// <li>destinationBufferByteSize:
/// Size of the destination buffer (in bytes)</li>
/// </ul>
///
struct HgiTextureGpuToCpuOp
{
HgiTextureGpuToCpuOp()
: gpuSourceTexture()
, sourceTexelOffset(GfVec3i(0))
, mipLevel(0)
, cpuDestinationBuffer(nullptr)
, destinationByteOffset(0)
, destinationBufferByteSize(0)
{}
HgiTextureHandle gpuSourceTexture;
GfVec3i sourceTexelOffset;
uint32_t mipLevel;
void* cpuDestinationBuffer;
size_t destinationByteOffset;
size_t destinationBufferByteSize;
};
//// \struct HgiTextureCpuToGpuOp
///
/// Describes the properties needed to copy texture data from CPU to GPU.
/// This uploads one mip at a time.
///
/// It is the responsibility of the caller to:
/// - ensure the destination textures is large enough to receive the data.
/// - ensure the source buffer and destination texture are valid at the time
/// the command is executed.
///
/// <ul>
/// <li>cpuSourceBuffer:
/// Pointer to CPU source (ie. texels) to copy the data from.</li>
/// <li>bufferByteSize:
/// Byte size (length) of cpuSourceBuffer.</li>
/// <li>destinationTexelOffset:
/// The texel offset (width, height, depth) of where to upload the data.
/// If the texture is a 2d_array the third element is the layer/slice.</li>
/// <li>mipLevel:
/// Mip level to upload into.</li>
/// <li>gpuDestinationTexture:
/// The GPU texture to upload the data into.</li>
/// </ul>
///
struct HgiTextureCpuToGpuOp
{
HgiTextureCpuToGpuOp()
: cpuSourceBuffer(nullptr)
, bufferByteSize(0)
, destinationTexelOffset(GfVec3i(0))
, mipLevel(0)
, gpuDestinationTexture()
{}
void const* cpuSourceBuffer;
size_t bufferByteSize;
GfVec3i destinationTexelOffset;
uint32_t mipLevel;
HgiTextureHandle gpuDestinationTexture;
};
//// \struct HgiBufferGpuToGpuOp
///
/// Describes the properties needed to copy buffer data from GPU to GPU.
///
/// It is the responsibility of the caller to:
/// - ensure the destination buffer is large enough to receive the data
/// (keep in mind the destinationByteOffset).
/// - ensure the source buffer and destination buffer are valid at the time
/// the command is executed.
///
/// <ul>
/// <li>gpuSourceBuffer:
/// The gpu buffer to copy data from.</li>
/// <li>sourceByteOffset:
/// The byte offset in source buffer to start copying the data from.</li>
/// <li>byteSize:
/// Size of the data (in bytes) to copy</li>
/// <li>gpuDestinationBuffer:
/// The copy destination gpu buffer.</li>
/// <li>destinationByteOffset:
/// The byte offset in destination buffer where to start copying the data to.</li>
/// </ul>
///
struct HgiBufferGpuToGpuOp
{
HgiBufferGpuToGpuOp()
: gpuSourceBuffer()
, sourceByteOffset(0)
, byteSize(0)
, gpuDestinationBuffer()
, destinationByteOffset(0)
{}
HgiBufferHandle gpuSourceBuffer;
size_t sourceByteOffset;
size_t byteSize;
HgiBufferHandle gpuDestinationBuffer;
size_t destinationByteOffset;
};
//// \struct HgiBufferCpuToGpuOp
///
/// Describes the properties needed to copy buffer data from CPU to GPU.
///
/// It is the responsibility of the caller to:
/// - ensure the destination buffer is large enough to receive the data.
/// - ensure the source buffer and destination buffer are valid at the time
/// the command is executed.
///
/// <ul>
/// <li>cpuSourceBuffer:
/// Pointer to CPU source to copy the data from.</li>
/// <li>sourceByteOffset:
/// The byte location in cpuSourceBuffer where copying starts.</li>
/// <li>gpuDestinationBuffer:
/// The GPU buffer to copy the data into.</li>
/// <li>destinationByteOffset:
/// The byte location in gpuDestinationBuffer where copying starts.</li>
/// <li>byteSize:
/// The size in bytes to copy.</li>
/// </ul>
///
struct HgiBufferCpuToGpuOp
{
HgiBufferCpuToGpuOp()
: cpuSourceBuffer(nullptr)
, sourceByteOffset(0)
, gpuDestinationBuffer()
, destinationByteOffset(0)
, byteSize(0)
{}
void const* cpuSourceBuffer;
size_t sourceByteOffset;
HgiBufferHandle gpuDestinationBuffer;
size_t destinationByteOffset;
size_t byteSize;
};
//// \struct HgiBufferGpuToCpuOp
///
/// Describes the properties needed to copy buffer data from GPU to CPU.
///
/// It is the responsibility of the caller to:
/// - ensure the destination buffer is large enough to receive the data
/// (keep in mind the destinationByteOffset).
/// - ensure the source buffer and destination buffer are valid at the time
/// the command is executed.
///
/// <ul>
/// <li>gpuSourceBuffer:
/// The gpu buffer to copy data from.</li>
/// <li>sourceByteOffset:
/// The byte offset in source buffer to start copying the data from.</li>
/// <li>byteSize:
/// Size of the data (in bytes) to copy</li>
/// <li>cpuDestinationBuffer:
/// The copy destination cpu buffer.</li>
/// <li>destinationByteOffset:
/// The byte offset in destination buffer where to start copying the data to.</li>
/// </ul>
///
struct HgiBufferGpuToCpuOp
{
HgiBufferGpuToCpuOp()
: gpuSourceBuffer()
, sourceByteOffset(0)
, byteSize(0)
, cpuDestinationBuffer()
, destinationByteOffset(0)
{}
HgiBufferHandle gpuSourceBuffer;
size_t sourceByteOffset;
size_t byteSize;
void* cpuDestinationBuffer;
size_t destinationByteOffset;
};
//// \struct HgiTextureToBufferOp
///
/// Describes the properties needed to copy GPU texture data into a GPU buffer.
///
/// It is the responsibility of the caller to:
/// - ensure the destination buffer is large enough to receive the data
/// (keep in mind the destinationByteOffset).
/// - ensure the source texture and destination buffer are valid at the time
/// the command is executed.
///
/// <ul>
/// <li>gpuSourceTexture:
/// The gpu texture to copy pixels from.</li>
/// <li>mipLevel:
/// Mip level to copy from.</li>
/// <li>gpuDestinationBuffer:
/// The GPU buffer to copy the data into.</li>
/// <li>destinationByteOffset:
/// The byte offset in destination buffer where to start copying the data to.</li>
/// <li>byteSize:
/// Size of the data (in bytes) to copy</li>
/// </ul>
///
struct HgiTextureToBufferOp
{
HgiTextureToBufferOp()
: gpuSourceTexture()
, sourceTexelOffset(GfVec3i(0))
, mipLevel(0)
, gpuDestinationBuffer()
, destinationByteOffset(0)
, byteSize(0)
{}
HgiTextureHandle gpuSourceTexture;
GfVec3i sourceTexelOffset;
uint32_t mipLevel;
HgiBufferHandle gpuDestinationBuffer;
size_t destinationByteOffset;
size_t byteSize;
};
//// \struct HgiBufferToTextureOp
///
/// Describes the properties needed to copy GPU buffer data into a GPU texture.
///
/// It is the responsibility of the caller to:
/// - ensure the destination textures is large enough to receive the data.
/// - ensure the source buffer and destination texture are valid at the time
/// the command is executed.
///
/// <ul>
/// <li>gpuSourceBuffer:
/// The gpu buffer to copy data from.</li>
/// <li>sourceByteOffset:
/// The byte offset in source buffer to start copying the data from.</li>
/// <li>gpuDestinationTexture:
/// The GPU texture to upload the data into.</li>
/// <li>destinationTexelOffset:
/// The texel offset (width, height, depth) of where to upload the data.
/// If the texture is a 2d_array the third element is the layer/slice.</li>
/// <li>mipLevel:
/// Mip level to upload into.</li>
/// <li>byteSize:
/// Size of the data (in bytes) to copy</li>
/// </ul>
///
struct HgiBufferToTextureOp
{
HgiBufferToTextureOp()
: gpuSourceBuffer()
, sourceByteOffset(0)
, gpuDestinationTexture()
, destinationTexelOffset(GfVec3i(0))
, mipLevel(0)
, byteSize(0)
{}
HgiBufferHandle gpuSourceBuffer;
size_t sourceByteOffset;
HgiTextureHandle gpuDestinationTexture;
GfVec3i destinationTexelOffset;
uint32_t mipLevel;
size_t byteSize;
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif
+157
View File
@@ -0,0 +1,157 @@
//
// Copyright 2020 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_IMAGING_HGI_BUFFER_H
#define PXR_IMAGING_HGI_BUFFER_H
#include <string>
#include <vector>
#include "pxr/pxr.h"
#include "pxr/base/gf/vec3i.h"
#include "pxr/imaging/hgi/api.h"
#include "pxr/imaging/hgi/enums.h"
#include "pxr/imaging/hgi/handle.h"
#include "pxr/imaging/hgi/types.h"
PXR_NAMESPACE_OPEN_SCOPE
/// \struct HgiBufferDesc
///
/// Describes the properties needed to create a GPU buffer.
///
/// <ul>
/// <li>debugName:
/// This label can be applied as debug label for gpu debugging.</li>
/// <li>usage:
/// Bits describing the intended usage and properties of the buffer.</li>
/// <li>byteSize:
/// Length of buffer in bytes</li>
/// <Li>vertexStride:
/// The size of a vertex in a vertex buffer.
/// This property is only required for vertex buffers.</li>
/// <li>initialData:
/// CPU pointer to initialization data of buffer.
/// The memory is consumed immediately during the creation of the HgiBuffer.
/// The application may alter or free this memory as soon as the constructor
/// of the HgiBuffer has returned.</li>
/// </ul>
///
struct HgiBufferDesc
{
HGI_API
HgiBufferDesc()
: usage(HgiBufferUsageUniform)
, byteSize(0)
, vertexStride(0)
, initialData(nullptr)
{}
std::string debugName;
HgiBufferUsage usage;
size_t byteSize;
uint32_t vertexStride;
void const* initialData;
};
HGI_API
bool operator==(
const HgiBufferDesc& lhs,
const HgiBufferDesc& rhs);
HGI_API
inline bool operator!=(
const HgiBufferDesc& lhs,
const HgiBufferDesc& rhs);
///
/// \class HgiBuffer
///
/// Represents a graphics platform independent GPU buffer resource (base class).
/// Buffers should be created via Hgi::CreateBuffer.
/// The fill the buffer with data you supply `initialData` in the descriptor.
/// To update the data inside the buffer later on, use blitCmds.
///
class HgiBuffer
{
public:
HGI_API
virtual ~HgiBuffer();
/// The descriptor describes the object.
HGI_API
HgiBufferDesc const& GetDescriptor() const;
/// Returns the byte size of the GPU buffer.
/// This can be helpful if the application wishes to tally up memory usage.
HGI_API
virtual size_t GetByteSizeOfResource() const = 0;
/// This function returns the handle to the Hgi backend's gpu resource, cast
/// to a uint64_t. Clients should avoid using this function and instead
/// use Hgi base classes so that client code works with any Hgi platform.
/// For transitioning code to Hgi, it can however we useful to directly
/// access a platform's internal resource handles.
/// There is no safety provided in using this. If you by accident pass a
/// HgiMetal resource into an OpenGL call, bad things may happen.
/// In OpenGL this returns the GLuint resource name.
/// In Metal this returns the id<MTLBuffer> as uint64_t.
/// In Vulkan this returns the VkBuffer as uint64_t.
/// In DX12 this returns the ID3D12Resource pointer as uint64_t.
HGI_API
virtual uint64_t GetRawResource() const = 0;
/// Returns the 'staging area' in which new buffer data is copied before
/// it is flushed to GPU.
/// Some implementations (e.g. Metal) may have build in support for
/// queueing up CPU->GPU copies. Those implementations can return the
/// CPU pointer to the buffer's content directly.
/// The caller should not assume that the data from the CPU staging area
/// is automatically flushed to the GPU. Instead, after copying is finished,
/// the caller should use BlitCmds CopyBufferCpuToGpu to ensure the transfer
/// from the staging area to the GPU is scheduled.
HGI_API
virtual void* GetCPUStagingAddress() = 0;
protected:
HGI_API
HgiBuffer(HgiBufferDesc const& desc);
HgiBufferDesc _descriptor;
private:
HgiBuffer() = delete;
HgiBuffer & operator=(const HgiBuffer&) = delete;
HgiBuffer(const HgiBuffer&) = delete;
};
using HgiBufferHandle = HgiHandle<HgiBuffer>;
using HgiBufferHandleVector = std::vector<HgiBufferHandle>;
PXR_NAMESPACE_CLOSE_SCOPE
#endif
+68
View File
@@ -0,0 +1,68 @@
//
// Copyright 2021 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_IMAGING_HGI_CAPABILITIES_H
#define PXR_IMAGING_HGI_CAPABILITIES_H
#include "pxr/pxr.h"
#include "pxr/imaging/hgi/api.h"
#include "pxr/imaging/hgi/enums.h"
PXR_NAMESPACE_OPEN_SCOPE
/// \class HgiCapabilities
///
/// Reports the capabilities of the Hgi device.
///
class HgiCapabilities
{
public:
HGI_API
virtual ~HgiCapabilities() = 0;
bool IsSet(HgiDeviceCapabilities mask) const {
return (_flags & mask) != 0;
}
protected:
HgiCapabilities() : _flags(0) {}
void _SetFlag(HgiDeviceCapabilities mask, bool value) {
if (value) {
_flags |= mask;
} else {
_flags &= ~mask;
}
}
private:
HgiCapabilities & operator=(const HgiCapabilities&) = delete;
HgiCapabilities(const HgiCapabilities&) = delete;
HgiDeviceCapabilities _flags;
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif
+80
View File
@@ -0,0 +1,80 @@
//
// Copyright 2020 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_IMAGING_HGI_CMDS_H
#define PXR_IMAGING_HGI_CMDS_H
#include "pxr/pxr.h"
#include "pxr/imaging/hgi/api.h"
#include "pxr/imaging/hgi/enums.h"
#include <memory>
PXR_NAMESPACE_OPEN_SCOPE
class Hgi;
using HgiCmdsUniquePtr = std::unique_ptr<class HgiCmds>;
/// \class HgiCmds
///
/// Graphics commands are recorded in 'cmds' objects which are later submitted
/// to hgi. HgiCmds is the base class for other cmds objects.
///
class HgiCmds
{
public:
HGI_API
virtual ~HgiCmds();
/// Returns true if the HgiCmds object has been submitted to GPU.
HGI_API
bool IsSubmitted() const;
protected:
friend class Hgi;
HGI_API
HgiCmds();
// Submit can be called inside of Hgi::SubmitCmds to commit the
// command buffer to the GPU. Returns true if work was committed.
// The default implementation returns false.
HGI_API
virtual bool _Submit(Hgi* hgi, HgiSubmitWaitType wait);
// Flags the HgiCmds object as 'submitted' to GPU.
HGI_API
void _SetSubmitted();
private:
HgiCmds & operator=(const HgiCmds&) = delete;
HgiCmds(const HgiCmds&) = delete;
bool _submitted;
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif
+110
View File
@@ -0,0 +1,110 @@
//
// Copyright 2020 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_IMAGING_HGI_COMPUTE_CMDS_H
#define PXR_IMAGING_HGI_COMPUTE_CMDS_H
#include "pxr/pxr.h"
#include "pxr/imaging/hgi/api.h"
#include "pxr/imaging/hgi/computePipeline.h"
#include "pxr/imaging/hgi/resourceBindings.h"
#include "pxr/imaging/hgi/cmds.h"
#include <memory>
PXR_NAMESPACE_OPEN_SCOPE
using HgiComputeCmdsUniquePtr = std::unique_ptr<class HgiComputeCmds>;
/// \class HgiComputeCmds
///
/// A graphics API independent abstraction of compute commands.
/// HgiComputeCmds is a lightweight object that cannot be re-used after it has
/// been submitted. A new cmds object should be acquired for each frame.
///
class HgiComputeCmds : public HgiCmds
{
public:
HGI_API
~HgiComputeCmds() override;
/// Push a debug marker.
HGI_API
virtual void PushDebugGroup(const char* label) = 0;
/// Pop the last debug marker.
HGI_API
virtual void PopDebugGroup() = 0;
/// Bind a pipeline state object. Usually you call this right after calling
/// CreateGraphicsCmds to set the graphics pipeline state.
/// The resource bindings used when creating the pipeline must be compatible
/// with the resources bound via BindResources().
HGI_API
virtual void BindPipeline(HgiComputePipelineHandle pipeline) = 0;
/// Bind resources such as textures and uniform buffers.
/// Usually you call this right after BindPipeline() and the resources bound
/// must be compatible with the bound pipeline.
HGI_API
virtual void BindResources(HgiResourceBindingsHandle resources) = 0;
/// Set Push / Function constants.
/// `pipeline` is the compute pipeline that you are binding before the
/// draw call. It contains the program used for the uniform buffer
/// constant values for.
/// `bindIndex` is the binding point index in the pipeline's shader
/// to bind the data to.
/// `byteSize` is the size of the data you are updating.
/// `data` is the data you are copying into the push constants block.
HGI_API
virtual void SetConstantValues(
HgiComputePipelineHandle pipeline,
uint32_t bindIndex,
uint32_t byteSize,
const void* data) = 0;
/// Execute a compute shader with provided thread group count in each
/// dimension.
HGI_API
virtual void Dispatch(int dimX, int dimY) = 0;
/// Inserts a barrier so that data written to memory by commands before
/// the barrier is available to commands after the barrier.
HGI_API
virtual void MemoryBarrier(HgiMemoryBarrier barrier) = 0;
protected:
HGI_API
HgiComputeCmds();
private:
HgiComputeCmds & operator=(const HgiComputeCmds&) = delete;
HgiComputeCmds(const HgiComputeCmds&) = delete;
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif
+137
View File
@@ -0,0 +1,137 @@
//
// Copyright 2020 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_IMAGING_HGI_COMPUTE_PIPELINE_H
#define PXR_IMAGING_HGI_COMPUTE_PIPELINE_H
#include "pxr/pxr.h"
#include "pxr/imaging/hgi/api.h"
#include "pxr/imaging/hgi/attachmentDesc.h"
#include "pxr/imaging/hgi/enums.h"
#include "pxr/imaging/hgi/handle.h"
#include "pxr/imaging/hgi/resourceBindings.h"
#include "pxr/imaging/hgi/shaderProgram.h"
#include "pxr/imaging/hgi/types.h"
#include <string>
#include <vector>
PXR_NAMESPACE_OPEN_SCOPE
/// \struct HgiComputeShaderConstantsDesc
///
/// A small, but fast buffer of uniform data for shaders.
///
/// <ul>
/// <li>byteSize:
/// Size of the constants in bytes. (max 256 bytes)</li>
/// </ul>
///
struct HgiComputeShaderConstantsDesc {
HGI_API
HgiComputeShaderConstantsDesc();
uint32_t byteSize;
};
HGI_API
bool operator==(
const HgiComputeShaderConstantsDesc& lhs,
const HgiComputeShaderConstantsDesc& rhs);
HGI_API
bool operator!=(
const HgiComputeShaderConstantsDesc& lhs,
const HgiComputeShaderConstantsDesc& rhs);
/// \struct HgiComputePipelineDesc
///
/// Describes the properties needed to create a GPU compute pipeline.
///
/// <ul>
/// <li>shaderProgram:
/// Shader function used in this pipeline.</li>
/// <li>shaderConstantsDesc:
/// Describes the shader uniforms.</li>
/// </ul>
///
struct HgiComputePipelineDesc
{
HGI_API
HgiComputePipelineDesc();
std::string debugName;
HgiShaderProgramHandle shaderProgram;
HgiComputeShaderConstantsDesc shaderConstantsDesc;
};
HGI_API
bool operator==(
const HgiComputePipelineDesc& lhs,
const HgiComputePipelineDesc& rhs);
HGI_API
bool operator!=(
const HgiComputePipelineDesc& lhs,
const HgiComputePipelineDesc& rhs);
///
/// \class HgiComputePipeline
///
/// Represents a graphics platform independent GPU compute pipeline resource.
///
/// Base class for Hgi compute pipelines.
/// To the client (HdSt) compute pipeline resources are referred to via
/// opaque, stateless handles (HgiComputePipelineHandle).
///
class HgiComputePipeline
{
public:
HGI_API
virtual ~HgiComputePipeline();
/// The descriptor describes the object.
HGI_API
HgiComputePipelineDesc const& GetDescriptor() const;
protected:
HGI_API
HgiComputePipeline(HgiComputePipelineDesc const& desc);
HgiComputePipelineDesc _descriptor;
private:
HgiComputePipeline() = delete;
HgiComputePipeline & operator=(const HgiComputePipeline&) = delete;
HgiComputePipeline(const HgiComputePipeline&) = delete;
};
using HgiComputePipelineHandle = HgiHandle<class HgiComputePipeline>;
using HgiComputePipelineHandleVector = std::vector<HgiComputePipelineHandle>;
PXR_NAMESPACE_CLOSE_SCOPE
#endif
+551
View File
@@ -0,0 +1,551 @@
//
// Copyright 2019 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_IMAGING_HGI_ENUMS_H
#define PXR_IMAGING_HGI_ENUMS_H
#include "pxr/pxr.h"
#include "pxr/imaging/hgi/api.h"
#include <cstdint>
PXR_NAMESPACE_OPEN_SCOPE
using HgiBits = uint32_t;
/// \enum HgiDeviceCapabilitiesBits
///
/// Describes what capabilities the requested device must have.
///
/// <ul>
/// <li>HgiDeviceCapabilitiesBitsPresentation:
/// The device must be capable of presenting graphics to screen</li>
/// <li>HgiDeviceCapabilitiesBitsBindlessBuffers:
/// THe device can access GPU buffers using bindless handles</li>
/// <li>HgiDeviceCapabilitiesBitsConcurrentDispatch:
/// The device can execute commands concurrently</li>
/// <li>HgiDeviceCapabilitiesBitsUnifiedMemory:
/// The device shares all GPU and CPU memory</li>
/// </ul>
///
enum HgiDeviceCapabilitiesBits : HgiBits
{
HgiDeviceCapabilitiesBitsPresentation = 1 << 0,
HgiDeviceCapabilitiesBitsBindlessBuffers = 1 << 1,
HgiDeviceCapabilitiesBitsConcurrentDispatch = 1 << 2,
HgiDeviceCapabilitiesBitsUnifiedMemory = 1 << 3,
};
using HgiDeviceCapabilities = HgiBits;
/// \enum HgiTextureType
///
/// Describes the kind of texture.
///
/// <ul>
/// <li>HgiTextureType1D:
/// A one-dimensional texture.</li>
/// <li>HgiTextureType2D:
/// A two-dimensional texture.</li>
/// <li>HgiTextureType3D:
/// A three-dimensional texture.</li>
/// <li>HgiTextureType1DArray:
/// An array of one-dimensional textures.</li>
/// <li>HgiTextureType2DArray:
/// An array of two-dimensional textures.</li>
/// </ul>
///
enum HgiTextureType
{
HgiTextureType1D = 0,
HgiTextureType2D,
HgiTextureType3D,
HgiTextureType1DArray,
HgiTextureType2DArray,
HgiTextureTypeCount
};
/// \enum HgiTextureUsageBits
///
/// Describes how the texture will be used. If a texture has multiple uses you
/// can combine multiple bits.
///
/// <ul>
/// <li>HgiTextureUsageBitsColorTarget:
/// The texture is a color attachment rendered into via a render pass.</li>
/// <li>HgiTextureUsageBitsDepthTarget:
/// The texture is a depth attachment rendered into via a render pass.</li>
/// <li>HgiTextureUsageBitsStencilTarget:
/// The texture is a stencil attachment rendered into via a render pass.</li>
/// <li>HgiTextureUsageBitsShaderRead:
/// The texture is sampled from in a shader (sampling)</li>
/// <li>HgiTextureUsageBitsShaderWrite:
/// The texture is written into from in a shader (image store)
/// When a texture is used as HgiBindResourceTypeStorageImage you must
/// add this flag (even if you only read from the image).</li>
///
/// <li>HgiTextureUsageCustomBitsBegin:
/// This bit (and any bit after) can be used to attached custom, backend
/// specific bits to the usage bit. </li>
/// </ul>
///
enum HgiTextureUsageBits : HgiBits
{
HgiTextureUsageBitsColorTarget = 1 << 0,
HgiTextureUsageBitsDepthTarget = 1 << 1,
HgiTextureUsageBitsStencilTarget = 1 << 2,
HgiTextureUsageBitsShaderRead = 1 << 3,
HgiTextureUsageBitsShaderWrite = 1 << 4,
HgiTextureUsageCustomBitsBegin = 1 << 5,
};
using HgiTextureUsage = HgiBits;
/// \enum HgiSamplerAddressMode
///
/// Various modes used during sampling of a texture.
///
enum HgiSamplerAddressMode
{
HgiSamplerAddressModeClampToEdge = 0,
HgiSamplerAddressModeMirrorClampToEdge,
HgiSamplerAddressModeRepeat,
HgiSamplerAddressModeMirrorRepeat,
HgiSamplerAddressModeClampToBorderColor,
HgiSamplerAddressModeCount
};
/// \enum HgiSamplerFilter
///
/// Sampler filtering modes that determine the pixel value that is returned.
///
/// <ul>
/// <li>HgiSamplerFilterNearest:
/// Returns the value of a single mipmap level.</li>
/// <li>HgiSamplerFilterLinear:
/// Combines the values of multiple mipmap levels.</li>
/// </ul>
///
enum HgiSamplerFilter
{
HgiSamplerFilterNearest = 0,
HgiSamplerFilterLinear = 1,
HgiSamplerFilterCount
};
/// \enum HgiMipFilter
///
/// Sampler filtering modes that determine the pixel value that is returned.
///
/// <ul>
/// <li>HgiMipFilterNotMipmapped:
/// Texture is always sampled at mipmap level 0. (ie. max lod=0)</li>
/// <li>HgiMipFilterNearest:
/// Returns the value of a single mipmap level.</li>
/// <li>HgiMipFilterLinear:
/// Linear interpolates the values of up to two mipmap levels.</li>
/// </ul>
///
enum HgiMipFilter
{
HgiMipFilterNotMipmapped = 0,
HgiMipFilterNearest = 1,
HgiMipFilterLinear = 2,
HgiMipFilterCount
};
/// \enum HgiSampleCount
///
/// Sample count for multi-sampling
///
enum HgiSampleCount
{
HgiSampleCount1 = 1,
HgiSampleCount2 = 2,
HgiSampleCount4 = 4,
HgiSampleCount8 = 8,
HgiSampleCount16 = 16,
HgiSampleCountEnd
};
/// \enum HgiAttachmentLoadOp
///
/// Describes what will happen to the attachment pixel data prior to rendering.
///
/// <ul>
/// <li>HgiAttachmentLoadOpDontCare:
/// All pixels are rendered to. Pixel data in render target starts undefined.</li>
/// <li>HgiAttachmentLoadOpClear:
/// The attachment pixel data is cleared to a specified color value.</li>
/// <li>HgiAttachmentLoadOpLoad:
/// Previous pixel data is loaded into attachment prior to rendering.</li>
/// </ul>
///
enum HgiAttachmentLoadOp
{
HgiAttachmentLoadOpDontCare = 0,
HgiAttachmentLoadOpClear,
HgiAttachmentLoadOpLoad,
HgiAttachmentLoadOpCount
};
/// \enum HgiAttachmentStoreOp
///
/// Describes what will happen to the attachment pixel data after rendering.
///
/// <ul>
/// <li>HgiAttachmentStoreOpDontCare:
/// Pixel data is undefined after rendering has completed (no store cost)</li>
/// <li>HgiAttachmentStoreOpStore:
/// The attachment pixel data is stored in memory.</li>
/// </ul>
///
enum HgiAttachmentStoreOp
{
HgiAttachmentStoreOpDontCare = 0,
HgiAttachmentStoreOpStore,
HgiAttachmentStoreOpCount
};
/// \enum HgiBufferUsageBits
///
/// Describes the properties and usage of the buffer.
///
/// <ul>
/// <li>HgiBufferUsageUniform:
/// Shader uniform buffer </li>
/// <li>HgiBufferUsageIndex32:
/// Topology 32 bit indices.</li>
/// <li>HgiBufferUsageVertex:
/// Vertex attributes.</li>
/// <li>HgiBufferUsageStorage:
/// Shader storage buffer / Argument buffer.</li>
///
/// <li>HgiBufferUsageCustomBitsBegin:
/// This bit (and any bit after) can be used to attached custom, backend
/// specific bits to the usage bit. </li>
/// </ul>
///
enum HgiBufferUsageBits : HgiBits
{
HgiBufferUsageUniform = 1 << 0,
HgiBufferUsageIndex32 = 1 << 1,
HgiBufferUsageVertex = 1 << 2,
HgiBufferUsageStorage = 1 << 3,
HgiBufferUsageCustomBitsBegin = 1 << 4,
};
using HgiBufferUsage = HgiBits;
/// \enum HgiShaderStage
///
/// Describes the stage a shader function operates in.
///
/// <ul>
/// <li>HgiShaderStageVertex:
/// Vertex Shader.</li>
/// <li>HgiShaderStageFragment:
/// Fragment Shader.</li>
/// <li>HgiShaderStageCompute:
/// Compute Shader.</li>
/// <li>HgiShaderStageTessellationControl:
/// Transforms the control points of the low order surface (patch).
/// This runs before the tessellator fixed function stage.</li>
/// <li>HgiShaderStageTessellationEval:
/// Generates the surface geometry (the points) from the transformed control
/// points for every coordinate coming out of the tessellator fixed function
/// stage. </li>
/// <li>HgiShaderStageGeometry:
/// Governs the processing of Primitives.</li>
/// </ul>
///
enum HgiShaderStageBits : HgiBits
{
HgiShaderStageVertex = 1 << 0,
HgiShaderStageFragment = 1 << 1,
HgiShaderStageCompute = 1 << 2,
HgiShaderStageTessellationControl = 1 << 3,
HgiShaderStageTessellationEval = 1 << 4,
HgiShaderStageGeometry = 1 << 5,
HgiShaderStageCustomBitsBegin = 1 << 6,
};
using HgiShaderStage = HgiBits;
/// \enum HgiBindResourceType
///
/// Describes the type of the resource to be bound.
///
/// <ul>
/// <li>HgiBindResourceTypeSampler:
/// Sampler.
/// Glsl example: uniform sampler samplerOnly</li>
/// <li>HgiBindResourceTypeSampledImage:
/// Image for use with sampling ops.
/// Glsl example: uniform texture2D textureOnly
/// texture(sampler2D(textureOnly, samplerOnly), ...)</li>
/// <li>HgiBindResourceTypeCombinedSamplerImage:
/// Image and sampler combined into one.
/// Glsl example: uniform sampler2D texSmp;
/// texture(texSmp, ...)</li>
/// <li>HgiBindResourceTypeStorageImage:
/// Storage image used for image store/load ops (Unordered Access View).</li>
/// <li>HgiBindResourceTypeUniformBuffer:
/// Uniform buffer (UBO).</li>
/// <li>HgiBindResourceTypeStorageBuffer:
/// Shader storage buffer (SSBO).</li>
/// </ul>
///
enum HgiBindResourceType
{
HgiBindResourceTypeSampler = 0,
HgiBindResourceTypeSampledImage,
HgiBindResourceTypeCombinedSamplerImage,
HgiBindResourceTypeStorageImage,
HgiBindResourceTypeUniformBuffer,
HgiBindResourceTypeStorageBuffer,
HgiBindResourceTypeCount
};
/// \enum HgiPolygonMode
///
/// Controls polygon mode during rasterization
///
/// <ul>
/// <li>HgiPolygonModeFill:
/// Polygons are filled.</li>
/// <li>HgiPolygonModeLine:
/// Polygon edges are drawn as line segments.</li>
/// <li>HgiPolygonModePoint:
/// Polygon vertices are drawn as points.</li>
/// </ul>
///
enum HgiPolygonMode
{
HgiPolygonModeFill = 0,
HgiPolygonModeLine,
HgiPolygonModePoint,
HgiPolygonModeCount
};
/// \enum HgiCullMode
///
/// Controls primitive (faces) culling.
///
/// <ul>
/// <li>HgiPolygonModeNone:
/// No primitive are discarded.</li>
/// <li>HgiPolygonModeFront:
/// Front-facing primitive are discarded.</li>
/// <li>HgiPolygonModeBack:
/// Back-facing primitive are discarded.</li>
/// <li>HgiPolygonModeFrontAndBack:
/// All primitive are discarded.</li>
/// </ul>
///
enum HgiCullMode
{
HgiCullModeNone = 0,
HgiCullModeFront,
HgiCullModeBack,
HgiCullModeFrontAndBack,
HgiCullModeCount
};
/// \enum HgiWinding
///
/// Determines the front-facing orientation of a primitive (face).
///
/// <ul>
/// <li>HgiWindingClockwise:
/// Primitives with clockwise vertex-order are front facing.</li>
/// <li>HgiWindingCounterClockwise:
/// Primitives with counter-clockwise vertex-order are front facing.</li>
/// </ul>
///
enum HgiWinding
{
HgiWindingClockwise = 0,
HgiWindingCounterClockwise,
HgiWindingCount
};
/// \enum HgiBlendOp
///
/// Blend operations
///
enum HgiBlendOp
{
HgiBlendOpAdd = 0,
HgiBlendOpSubtract,
HgiBlendOpReverseSubtract,
HgiBlendOpMin,
HgiBlendOpMax,
HgiBlendOpCount
};
/// \enum HgiBlendFactor
///
/// Blend factors
///
enum HgiBlendFactor
{
HgiBlendFactorZero = 0,
HgiBlendFactorOne,
HgiBlendFactorSrcColor,
HgiBlendFactorOneMinusSrcColor,
HgiBlendFactorDstColor,
HgiBlendFactorOneMinusDstColor,
HgiBlendFactorSrcAlpha,
HgiBlendFactorOneMinusSrcAlpha,
HgiBlendFactorDstAlpha,
HgiBlendFactorOneMinusDstAlpha,
HgiBlendFactorConstantColor,
HgiBlendFactorOneMinusConstantColor,
HgiBlendFactorConstantAlpha,
HgiBlendFactorOneMinusConstantAlpha,
HgiBlendFactorSrcAlphaSaturate,
HgiBlendFactorSrc1Color,
HgiBlendFactorOneMinusSrc1Color,
HgiBlendFactorSrc1Alpha,
HgiBlendFactorOneMinusSrc1Alpha,
HgiBlendFactorCount
};
/// \enum HgiCompareFunction
///
/// Compare functions.
///
enum HgiCompareFunction
{
HgiCompareFunctionNever = 0,
HgiCompareFunctionLess,
HgiCompareFunctionEqual,
HgiCompareFunctionLEqual,
HgiCompareFunctionGreater,
HgiCompareFunctionNotEqual,
HgiCompareFunctionGEqual,
HgiCompareFunctionAlways,
HgiCompareFunctionCount
};
/// \enum HgiComponentSwizzle
///
/// Swizzle for a component.
///
enum HgiComponentSwizzle
{
HgiComponentSwizzleZero = 0,
HgiComponentSwizzleOne,
HgiComponentSwizzleR,
HgiComponentSwizzleG,
HgiComponentSwizzleB,
HgiComponentSwizzleA,
HgiComponentSwizzleCount
};
/// \enum HgiPrimitiveType
///
/// What the stream of vertices being rendered represents
///
/// <ul>
/// <li>HgiPrimitiveTypePointList:
/// Rasterize a point at each vertex.</li>
/// <li>HgiPrimitiveTypeLineList:
/// Rasterize a line between each separate pair of vertices.</li>
/// <li>HgiPrimitiveTypeLineStrip:
/// Rasterize a line between each pair of adjacent vertices.</li>
/// <li>HgiPrimitiveTypeTriangleList:
/// Rasterize a triangle for every separate set of three vertices.</li>
/// <li>HgiPrimitiveTypePatchList:
/// A user-defined number of vertices, which is tessellated into
/// points, lines, or triangles.</li>
/// </ul>
///
enum HgiPrimitiveType
{
HgiPrimitiveTypePointList = 0,
HgiPrimitiveTypeLineList,
HgiPrimitiveTypeLineStrip,
HgiPrimitiveTypeTriangleList,
HgiPrimitiveTypePatchList,
HgiPrimitiveTypeCount
};
/// \enum HgiSubmitWaitType
///
/// Describes command submission wait behavior.
///
/// <ul>
/// <li>HgiSubmitWaitTypeNoWait:
/// CPU should not wait for the GPU to finish processing the cmds.</li>
/// <li>HgiSubmitWaitTypeWaitUntilCompleted:
/// The CPU waits ("blocked") until the GPU has consumed the cmds.</li>
/// </ul>
///
enum HgiSubmitWaitType
{
HgiSubmitWaitTypeNoWait = 0,
HgiSubmitWaitTypeWaitUntilCompleted,
};
/// \enum HgiMemoryBarrier
///
/// Describes what objects the memory barrier affects.
///
/// <ul>
/// <li>HgiMemoryBarrierNone:
/// No barrier (no-op).</li>
/// <li>HgiMemoryBarrierAll:
/// The barrier affects all memory writes and reads.</li>
/// </ul>
///
enum HgiMemoryBarrierBits
{
HgiMemoryBarrierNone = 0,
HgiMemoryBarrierAll = 1 << 0
};
using HgiMemoryBarrier = HgiBits;
PXR_NAMESPACE_CLOSE_SCOPE
#endif
+204
View File
@@ -0,0 +1,204 @@
//
// Copyright 2019 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_IMAGING_HGI_GRAPHICS_CMDS_H
#define PXR_IMAGING_HGI_GRAPHICS_CMDS_H
#include "pxr/pxr.h"
#include "pxr/base/gf/vec4i.h"
#include "pxr/imaging/hgi/api.h"
#include "pxr/imaging/hgi/graphicsCmdsDesc.h"
#include "pxr/imaging/hgi/graphicsPipeline.h"
#include "pxr/imaging/hgi/resourceBindings.h"
#include "pxr/imaging/hgi/cmds.h"
#include <memory>
PXR_NAMESPACE_OPEN_SCOPE
using HgiGraphicsCmdsUniquePtr = std::unique_ptr<class HgiGraphicsCmds>;
/// \class HgiGraphicsCmds
///
/// A graphics API independent abstraction of graphics commands.
/// HgiGraphicsCmds is a lightweight object that cannot be re-used after it has
/// been submitted. A new cmds object should be acquired for each frame.
///
class HgiGraphicsCmds : public HgiCmds
{
public:
HGI_API
~HgiGraphicsCmds() override;
/// Push a debug marker.
HGI_API
virtual void PushDebugGroup(const char* label) = 0;
/// Pop the last debug marker.
HGI_API
virtual void PopDebugGroup() = 0;
/// Set viewport [left, BOTTOM, width, height] - OpenGL coords
HGI_API
virtual void SetViewport(GfVec4i const& vp) = 0;
/// Only pixels that lie within the scissor box are modified by
/// drawing commands.
HGI_API
virtual void SetScissor(GfVec4i const& sc) = 0;
/// Bind a pipeline state object. Usually you call this right after calling
/// CreateGraphicsCmds to set the graphics pipeline state.
/// The resource bindings used when creating the pipeline must be compatible
/// with the resources bound via BindResources().
HGI_API
virtual void BindPipeline(HgiGraphicsPipelineHandle pipeline) = 0;
/// Bind resources such as textures and uniform buffers.
/// Usually you call this right after BindPipeline() and the resources bound
/// must be compatible with the bound pipeline.
HGI_API
virtual void BindResources(HgiResourceBindingsHandle resources) = 0;
/// Set Push / Function constants.
/// `pipeline` is the pipeline that you are binding before the draw call. It
/// contains the program used for the uniform buffer
/// `stages` describes for what shader stage you are setting the push
/// constant values for. Each stage can have its own (or none) binding
/// and they must match what is described in the shader functions.
/// `bindIndex` is the binding point index in the pipeline's shader
/// to bind the data to.
/// `byteSize` is the size of the data you are updating.
/// `data` is the data you are copying into the push constants block.
HGI_API
virtual void SetConstantValues(
HgiGraphicsPipelineHandle pipeline,
HgiShaderStage stages,
uint32_t bindIndex,
uint32_t byteSize,
const void* data) = 0;
/// Binds the vertex buffer(s) that describe the vertex attributes.
/// `firstBinding` the first index to which buffers are bound (usually 0).
/// `byteOffsets` offset to where the data of each buffer starts, in bytes.
/// `strides` the size of a vertex in each of the buffers.
HGI_API
virtual void BindVertexBuffers(
uint32_t firstBinding,
HgiBufferHandleVector const& buffers,
std::vector<uint32_t> const& byteOffsets) = 0;
/// Records a draw command that renders one or more instances of primitives
/// using the number of vertices provided.
/// The 'primitive type' (eg. Lines, Triangles, etc) can be acquired from
/// the bound HgiPipeline.
/// `vertexCount`: The number of vertices to draw.
/// `firstVertex`: The index of the first vertex to draw.
/// `instanceCount`: Number of instances to draw.
HGI_API
virtual void Draw(
uint32_t vertexCount,
uint32_t firstVertex,
uint32_t instanceCount) = 0;
/// Records a multi-draw command that reads the draw parameters
/// from a provided drawParameterBuffer.
/// The 'primitive type' (eg. Lines, Triangles, etc) can be acquired from
/// the bound HgiPipeline.
/// `drawParameterBuffer`: an array of structures:
// struct IndirectCommand {
// uint32_t vertexCount;
// uint32_t instanceCount;
// uint32_t firstVertex;
// uint32_t firstInstance;
// }
/// `drawBufferOffset`: Byte offset where the draw parameters begin.
/// `drawCount`: The number of draws to execute.
/// `stride`: byte stride between successive sets of draw parameters.
HGI_API
virtual void DrawIndirect(
HgiBufferHandle const& drawParameterBuffer,
uint32_t drawBufferOffset,
uint32_t drawCount,
uint32_t stride) = 0;
/// Records a draw command that renders one or more instances of primitives
/// using an indexBuffer starting from the base vertex.
/// The 'primitive type' (eg. Lines, Triangles, etc) can be acquired from
/// the bound HgiPipeline.
/// `indexCount`: The number of indices in the index buffer (num vertices).
/// `indexBufferByteOffset`: Byte offset within index buffer to start
/// reading the indices from.
/// `vertexOffset`: The value added to the vertex index before indexing
/// into the vertex buffer (baseVertex).
/// `instanceCount`: Number of instances to draw.
HGI_API
virtual void DrawIndexed(
HgiBufferHandle const& indexBuffer,
uint32_t indexCount,
uint32_t indexBufferByteOffset,
uint32_t vertexOffset,
uint32_t instanceCount) = 0;
/// Records a indexed multi-draw command that reads the draw parameters
/// from a provided drawParameterBuffer, and indices from indexBuffer.
/// The 'primitive type' (eg. Lines, Triangles, etc) can be acquired from
/// the bound HgiPipeline.
/// `drawParameterBuffer`: an array of structures:
// struct IndirectCommand {
// uint32_t indexCount;
// uint32_t instanceCount;
// uint32_t firstIndex;
// uint32_t vertexOffset;
// uint32_t firstInstance;
// }
/// `drawBufferOffset`: Byte offset where the draw parameters begin.
/// `drawCount`: The number of draws to execute.
/// `stride`: byte stride between successive sets of draw parameters.
HGI_API
virtual void DrawIndexedIndirect(
HgiBufferHandle const& indexBuffer,
HgiBufferHandle const& drawParameterBuffer,
uint32_t drawBufferOffset,
uint32_t drawCount,
uint32_t stride) = 0;
/// Inserts a barrier so that data written to memory by commands before
/// the barrier is available to commands after the barrier.
HGI_API
virtual void MemoryBarrier(HgiMemoryBarrier barrier) = 0;
protected:
HGI_API
HgiGraphicsCmds();
private:
HgiGraphicsCmds & operator=(const HgiGraphicsCmds&) = delete;
HgiGraphicsCmds(const HgiGraphicsCmds&) = delete;
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif
+104
View File
@@ -0,0 +1,104 @@
//
// Copyright 2019 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_IMAGING_HGI_GRAPHICS_CMDS_DESC_H
#define PXR_IMAGING_HGI_GRAPHICS_CMDS_DESC_H
#include "pxr/pxr.h"
#include "pxr/imaging/hgi/api.h"
#include "pxr/imaging/hgi/attachmentDesc.h"
#include "pxr/imaging/hgi/texture.h"
#include <vector>
PXR_NAMESPACE_OPEN_SCOPE
/// \struct HgiGraphicsCmdsDesc
///
/// Describes the properties to begin a HgiGraphicsCmds.
///
/// <ul>
/// <li>colorAttachmentDescs:
/// Describes each of the color attachments.</li>
/// <li>depthAttachmentDesc:
/// Describes the depth attachment (optional)</li>
/// <li>colorTextures:
/// The color attachment render targets.</li>
/// <li>colorResolveTextures:
/// The (optional) textures that the color textures will be resolved into
/// at the end of the render pass.</li>
/// <li>depthTexture:
/// The depth attachment render target (optional)</li>
/// <li>depthResolveTexture:
/// The (optional) texture that the depth texture will be resolved into
/// at the end of the render pass.</li>
/// <li>width:
/// Render target width (in pixels)</li>
/// <li>height:
/// Render target height (in pixels)</li>
/// </ul>
///
struct HgiGraphicsCmdsDesc
{
HgiGraphicsCmdsDesc()
: colorAttachmentDescs()
, depthAttachmentDesc()
, colorTextures()
, colorResolveTextures()
, depthTexture()
, depthResolveTexture()
{}
inline bool HasAttachments() const {
return !colorAttachmentDescs.empty() || depthTexture;
}
HgiAttachmentDescVector colorAttachmentDescs;
HgiAttachmentDesc depthAttachmentDesc;
HgiTextureHandleVector colorTextures;
HgiTextureHandleVector colorResolveTextures;
HgiTextureHandle depthTexture;
HgiTextureHandle depthResolveTexture;
};
HGI_API
bool operator==(
const HgiGraphicsCmdsDesc& lhs,
const HgiGraphicsCmdsDesc& rhs);
HGI_API
bool operator!=(
const HgiGraphicsCmdsDesc& lhs,
const HgiGraphicsCmdsDesc& rhs);
HGI_API
std::ostream& operator<<(
std::ostream& out,
const HgiGraphicsCmdsDesc& desc);
PXR_NAMESPACE_CLOSE_SCOPE
#endif
+349
View File
@@ -0,0 +1,349 @@
//
// Copyright 2020 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_IMAGING_HGI_GRAPHICS_PIPELINE_H
#define PXR_IMAGING_HGI_GRAPHICS_PIPELINE_H
#include "pxr/pxr.h"
#include "pxr/imaging/hgi/api.h"
#include "pxr/imaging/hgi/attachmentDesc.h"
#include "pxr/imaging/hgi/enums.h"
#include "pxr/imaging/hgi/handle.h"
#include "pxr/imaging/hgi/resourceBindings.h"
#include "pxr/imaging/hgi/shaderProgram.h"
#include "pxr/imaging/hgi/types.h"
#include <string>
#include <vector>
PXR_NAMESPACE_OPEN_SCOPE
/// \struct HgiVertexAttributeDesc
///
/// Describes one attribute of a vertex.
///
/// <ul>
/// <li>format:
/// Format of the vertex attribute.</li>
/// <li>offset:
/// The byte offset of the attribute in vertex buffer</li>
/// <li>shaderBindLocation:
/// The location of the attribute in the shader. layout(location = X)</li>
/// </ul>
///
struct HgiVertexAttributeDesc
{
HGI_API
HgiVertexAttributeDesc();
HgiFormat format;
uint32_t offset;
uint32_t shaderBindLocation;
};
using HgiVertexAttributeDescVector = std::vector<HgiVertexAttributeDesc>;
HGI_API
bool operator==(
const HgiVertexAttributeDesc& lhs,
const HgiVertexAttributeDesc& rhs);
HGI_API
inline bool operator!=(
const HgiVertexAttributeDesc& lhs,
const HgiVertexAttributeDesc& rhs);
/// \struct HgiVertexBufferDesc
///
/// Describes the attributes of a vertex buffer.
///
/// <ul>
/// <li>bindingIndex:
/// Binding location for this vertex buffer.</li>
/// <li>vertexAttributes:
/// List of vertex attributes (in vertex buffer).</li>
/// <li>vertexStride:
/// The byte size of a vertex (distance between two vertices).</li>
/// </ul>
///
struct HgiVertexBufferDesc
{
HGI_API
HgiVertexBufferDesc();
uint32_t bindingIndex;
HgiVertexAttributeDescVector vertexAttributes;
uint32_t vertexStride;
};
using HgiVertexBufferDescVector = std::vector<HgiVertexBufferDesc>;
HGI_API
bool operator==(
const HgiVertexBufferDesc& lhs,
const HgiVertexBufferDesc& rhs);
HGI_API
inline bool operator!=(
const HgiVertexBufferDesc& lhs,
const HgiVertexBufferDesc& rhs);
/// \struct HgiMultiSampleState
///
/// Properties to configure multi sampling.
///
/// <ul>
/// <li>alphaToCoverageEnable:
/// Fragment's color.a determines coverage (screen door transparency).</li>
/// <li>sampleCount:
/// The number of samples for each fragment. Must match attachments</li>
/// </ul>
///
struct HgiMultiSampleState
{
HGI_API
HgiMultiSampleState();
bool alphaToCoverageEnable;
HgiSampleCount sampleCount;
};
HGI_API
bool operator==(
const HgiMultiSampleState& lhs,
const HgiMultiSampleState& rhs);
HGI_API
bool operator!=(
const HgiMultiSampleState& lhs,
const HgiMultiSampleState& rhs);
/// \struct HgiRasterizationState
///
/// Properties to configure multi sampling.
///
/// <ul>
/// <li>polygonMode:
/// Determines the rasterization draw mode of primitve (triangles).</li>
/// <li>lineWidth:
/// The width of lines when polygonMode is set to line drawing.</li>
/// <li>cullMode:
/// Determines the culling rules for primitives (triangles).</li>
/// <li>winding:
/// The rule that determines what makes a front-facing primitive.</li>
/// <li>rasterizationEnabled:
/// When false all primitives are discarded before rasterization stage.</li>
/// </ul>
///
struct HgiRasterizationState
{
HGI_API
HgiRasterizationState();
HgiPolygonMode polygonMode;
float lineWidth;
HgiCullMode cullMode;
HgiWinding winding;
bool rasterizerEnabled;
};
HGI_API
bool operator==(
const HgiRasterizationState& lhs,
const HgiRasterizationState& rhs);
HGI_API
bool operator!=(
const HgiRasterizationState& lhs,
const HgiRasterizationState& rhs);
/// \struct HgiDepthStencilState
///
/// Properties to configure depth and stencil test.
///
/// <ul>
/// <li>depthTestEnabled:
/// When enabled uses `depthCompareFn` to test if a fragment passes the
/// depth test. Note that depth writes are automatically disabled when
/// depthTestEnabled is false.</li>
/// <li>depthWriteEnabled:
/// When enabled uses `depthCompareFn` to test if a fragment passes the
/// depth test. Note that depth writes are automatically disabled when
/// depthTestEnabled is false.</li>
/// <li>stencilTestEnabled:
/// Enables the stencil test.</li>
/// </ul>
///
struct HgiDepthStencilState
{
HGI_API
HgiDepthStencilState();
bool depthTestEnabled;
bool depthWriteEnabled;
HgiCompareFunction depthCompareFn;
bool stencilTestEnabled;
};
HGI_API
bool operator==(
const HgiDepthStencilState& lhs,
const HgiDepthStencilState& rhs);
HGI_API
bool operator!=(
const HgiDepthStencilState& lhs,
const HgiDepthStencilState& rhs);
/// \struct HgiGraphicsShaderConstantsDesc
///
/// A small, but fast buffer of uniform data for shaders.
///
/// <ul>
/// <li>byteSize:
/// Size of the constants in bytes. (max 256 bytes)</li>
/// <li>stageUsage:
/// What shader stage(s) the constants will be used in.</li>
/// </ul>
///
struct HgiGraphicsShaderConstantsDesc {
HGI_API
HgiGraphicsShaderConstantsDesc();
uint32_t byteSize;
HgiShaderStage stageUsage;
};
HGI_API
bool operator==(
const HgiGraphicsShaderConstantsDesc& lhs,
const HgiGraphicsShaderConstantsDesc& rhs);
HGI_API
bool operator!=(
const HgiGraphicsShaderConstantsDesc& lhs,
const HgiGraphicsShaderConstantsDesc& rhs);
/// \struct HgiGraphicsPipelineDesc
///
/// Describes the properties needed to create a GPU pipeline.
///
/// <ul>
/// <li>primitiveType:
/// Describes the stream of vertices (primitive topology).</li>
/// <li>shaderProgram:
/// Shader functions/stages used in this pipeline.</li>
/// <li>depthState:
/// Describes depth state for a pipeline.</li>
/// <li>multiSampleState:
/// Various settings to control multi-sampling.</li>
/// <li>rasterizationState:
/// Various settings to control rasterization.</li>
/// <li>vertexBuffers:
/// Description of the vertex buffers (per-vertex attributes).
/// The actual VBOs are bound via GraphicsCmds.</li>
/// <li>colorAttachmentDescs:
/// Describes each of the color attachments.</li>
/// <li>colorResolveAttachmentDescs:
/// Describes each of the color resolve attachments (optional).</li>
/// <li>depthAttachmentDesc:
/// Describes the depth attachment (optional)
/// Use HgiFormatInvalid to indicate no depth attachment.</li>
/// <li>depthResolveAttachmentDesc:
/// Describes the depth resolve attachment (optional).
/// Use HgiFormatInvalid to indicate no depth resolve attachment.</li>
/// <li>shaderConstantsDesc:
/// Describes the shader uniforms.</li>
/// </ul>
///
struct HgiGraphicsPipelineDesc
{
HGI_API
HgiGraphicsPipelineDesc();
std::string debugName;
HgiPrimitiveType primitiveType;
HgiShaderProgramHandle shaderProgram;
HgiDepthStencilState depthState;
HgiMultiSampleState multiSampleState;
HgiRasterizationState rasterizationState;
HgiVertexBufferDescVector vertexBuffers;
HgiAttachmentDescVector colorAttachmentDescs;
HgiAttachmentDescVector colorResolveAttachmentDescs;
HgiAttachmentDesc depthAttachmentDesc;
HgiAttachmentDesc depthResolveAttachmentDesc;
HgiGraphicsShaderConstantsDesc shaderConstantsDesc;
};
HGI_API
bool operator==(
const HgiGraphicsPipelineDesc& lhs,
const HgiGraphicsPipelineDesc& rhs);
HGI_API
bool operator!=(
const HgiGraphicsPipelineDesc& lhs,
const HgiGraphicsPipelineDesc& rhs);
///
/// \class HgiGraphicsPipeline
///
/// Represents a graphics platform independent GPU graphics pipeline
/// resource.
///
/// Base class for Hgi pipelines.
/// To the client (HdSt) pipeline resources are referred to via
/// opaque, stateless handles (HgiPipelineHandle).
///
class HgiGraphicsPipeline
{
public:
HGI_API
virtual ~HgiGraphicsPipeline();
/// The descriptor describes the object.
HGI_API
HgiGraphicsPipelineDesc const& GetDescriptor() const;
protected:
HGI_API
HgiGraphicsPipeline(HgiGraphicsPipelineDesc const& desc);
HgiGraphicsPipelineDesc _descriptor;
private:
HgiGraphicsPipeline() = delete;
HgiGraphicsPipeline & operator=(const HgiGraphicsPipeline&) = delete;
HgiGraphicsPipeline(const HgiGraphicsPipeline&) = delete;
};
using HgiGraphicsPipelineHandle = HgiHandle<HgiGraphicsPipeline>;
using HgiGraphicsPipelineHandleVector = std::vector<HgiGraphicsPipelineHandle>;
PXR_NAMESPACE_CLOSE_SCOPE
#endif
+82
View File
@@ -0,0 +1,82 @@
//
// Copyright 2020 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_IMAGING_HGI_HANDLE_H
#define PXR_IMAGING_HGI_HANDLE_H
#include "pxr/pxr.h"
#include "pxr/imaging/hgi/api.h"
#include <stdint.h>
PXR_NAMESPACE_OPEN_SCOPE
/// \class HgiHandle
///
/// Handle that contains a hgi object and unique id.
///
/// The unique id is used to compare two handles to guard against pointer
/// aliasing, where the same memory address is used to create a similar object,
/// but it is not actually the same object.
///
/// Handle is not a shared or weak_ptr and destruction of the contained object
/// should be explicitely managed by the client via the HgiDestroy*** functions.
///
/// If shared/weak ptr functionality is desired, the client creating Hgi objects
/// can wrap the returned handle in a shared_ptr.
///
template<class T>
class HgiHandle
{
public:
HgiHandle() : _ptr(nullptr), _id(0) {}
HgiHandle(T* obj, uint64_t id) : _ptr(obj), _id(id) {}
T*
Get() const {
return _ptr;
}
// Note this only checks if a ptr is set, it does not offer weak_ptr safety.
explicit operator bool() const {return _ptr!=nullptr;}
// Pointer access operator
T* operator ->() const {return _ptr;}
bool operator==(const HgiHandle& other) const {
return _id == other._id;
}
bool operator!=(const HgiHandle& other) const {
return !(*this == other);
}
private:
T* _ptr;
uint64_t _id;
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif
+342
View File
@@ -0,0 +1,342 @@
//
// Copyright 2019 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_IMAGING_HGI_HGI_H
#define PXR_IMAGING_HGI_HGI_H
#include "pxr/pxr.h"
#include "pxr/base/tf/token.h"
#include "pxr/base/tf/type.h"
#include "pxr/imaging/hgi/api.h"
#include "pxr/imaging/hgi/blitCmds.h"
#include "pxr/imaging/hgi/buffer.h"
#include "pxr/imaging/hgi/computeCmds.h"
#include "pxr/imaging/hgi/graphicsCmds.h"
#include "pxr/imaging/hgi/graphicsCmdsDesc.h"
#include "pxr/imaging/hgi/graphicsPipeline.h"
#include "pxr/imaging/hgi/resourceBindings.h"
#include "pxr/imaging/hgi/sampler.h"
#include "pxr/imaging/hgi/shaderFunction.h"
#include "pxr/imaging/hgi/shaderProgram.h"
#include "pxr/imaging/hgi/texture.h"
#include "pxr/imaging/hgi/types.h"
#include <atomic>
#include <memory>
PXR_NAMESPACE_OPEN_SCOPE
class HgiCapabilities;
using HgiUniquePtr = std::unique_ptr<class Hgi>;
/// \class Hgi
///
/// Hydra Graphics Interface.
/// Hgi is used to communicate with one or more physical gpu devices.
///
/// Hgi provides API to create/destroy resources that a gpu device owns.
/// The lifetime of resources is not managed by Hgi, so it is up to the caller
/// to destroy resources and ensure those resources are no longer used.
///
/// Commands are recorded in 'HgiCmds' objects and submitted via Hgi.
///
/// Thread-safety:
///
/// Modern graphics APIs like Metal and Vulkan are designed with multi-threading
/// in mind. We want to try and take advantage of this where possible.
/// However we also wish to continue to support OpenGL for the time being.
///
/// In an application where OpenGL is involved, when we say "main thread" we
/// mean the thread on which the gl-context is bound.
///
/// Each Hgi backend should at minimum support the following:
///
/// * Single threaded Hgi::SubmitCmds on main thread.
/// * Single threaded Hgi::Resource Create*** / Destroy*** on main thread.
/// * Multi threaded recording of commands in Hgi***Cmds objects.
/// * A Hgi***Cmds object should be creatable on the main thread, recorded
/// into with one secondary thread (only one thread may use a Cmds object) and
/// submitted via the main thread.
///
/// Each Hgi backend is additionally encouraged to support:
///
/// * Multi threaded support for resource creation and destruction.
///
/// We currently do not rely on these additional multi-threading features in
/// Hydra / Storm where we still wish to run OpenGL. In Hydra we make sure to
/// use the main-thread for resource creation and command submission.
/// One day we may wish to switch this to be multi-threaded so new Hgi backends
/// are encouraged to support it.
///
/// Pseudo code what should minimally be supported:
///
/// vector<HgiGraphicsCmds> cmds
///
/// for num_threads
/// cmds.push_back( Hgi->CreateGraphicsCmds() )
///
/// parallel_for i to num_threads
/// cmds[i]->SetViewport()
/// cmds[i]->Draw()
///
/// for i to num_threads
/// hgi->SubmitCmds( cmds[i] )
///
class Hgi
{
public:
HGI_API
Hgi();
HGI_API
virtual ~Hgi();
/// Submit one HgiCmds objects.
/// Once the cmds object is submitted it cannot be re-used to record cmds.
/// A call to SubmitCmds would usually result in the hgi backend submitting
/// the cmd buffers of the cmds object(s) to the device queue.
/// Derived classes can override _SubmitCmds to customize submission.
/// Thread safety: This call is not thread-safe. Submission must happen on
/// the main thread so we can continue to support the OpenGL platform.
/// See notes above.
HGI_API
void SubmitCmds(
HgiCmds* cmds,
HgiSubmitWaitType wait = HgiSubmitWaitTypeNoWait);
/// *** DEPRECATED *** Please use: CreatePlatformDefaultHgi
HGI_API
static Hgi* GetPlatformDefaultHgi();
/// Helper function to return a Hgi object for the current platform.
/// For example on Linux this may return HgiGL while on macOS HgiMetal.
/// Caller, usually the application, owns the lifetime of the Hgi object and
/// the object is destroyed when the caller drops the unique ptr.
/// Thread safety: Not thread safe.
HGI_API
static HgiUniquePtr CreatePlatformDefaultHgi();
/// Returns a GraphicsCmds object (for temporary use) that is ready to
/// record draw commands. GraphicsCmds is a lightweight object that
/// should be re-acquired each frame (don't hold onto it after EndEncoding).
/// Thread safety: Each Hgi backend must ensure that a Cmds object can be
/// created on the main thread, recorded into (exclusively) by one secondary
/// thread and be submitted on the main thread. See notes above.
HGI_API
virtual HgiGraphicsCmdsUniquePtr CreateGraphicsCmds(
HgiGraphicsCmdsDesc const& desc) = 0;
/// Returns a BlitCmds object (for temporary use) that is ready to execute
/// resource copy commands. BlitCmds is a lightweight object that
/// should be re-acquired each frame (don't hold onto it after EndEncoding).
/// Thread safety: Each Hgi backend must ensure that a Cmds object can be
/// created on the main thread, recorded into (exclusively) by one secondary
/// thread and be submitted on the main thread. See notes above.
HGI_API
virtual HgiBlitCmdsUniquePtr CreateBlitCmds() = 0;
/// Returns a ComputeCmds object (for temporary use) that is ready to
/// record dispatch commands. ComputeCmds is a lightweight object that
/// should be re-acquired each frame (don't hold onto it after EndEncoding).
/// Thread safety: Each Hgi backend must ensure that a Cmds object can be
/// created on the main thread, recorded into (exclusively) by one secondary
/// thread and be submitted on the main thread. See notes above.
HGI_API
virtual HgiComputeCmdsUniquePtr CreateComputeCmds() = 0;
/// Create a texture in rendering backend.
/// Thread safety: Creation must happen on main thread. See notes above.
HGI_API
virtual HgiTextureHandle CreateTexture(HgiTextureDesc const & desc) = 0;
/// Destroy a texture in rendering backend.
/// Thread safety: Destruction must happen on main thread. See notes above.
HGI_API
virtual void DestroyTexture(HgiTextureHandle* texHandle) = 0;
/// Create a texture view in rendering backend.
/// A texture view aliases another texture's data.
/// It is the responsibility of the client to ensure that the sourceTexture
/// is not destroyed while the texture view is in use.
/// Thread safety: Creation must happen on main thread. See notes above.
HGI_API
virtual HgiTextureViewHandle CreateTextureView(
HgiTextureViewDesc const & desc) = 0;
/// Destroy a texture view in rendering backend.
/// This will destroy the view's texture, but not the sourceTexture that
/// was aliased by the view. The sourceTexture data remains unchanged.
/// Thread safety: Destruction must happen on main thread. See notes above.
HGI_API
virtual void DestroyTextureView(HgiTextureViewHandle* viewHandle) = 0;
/// Create a sampler in rendering backend.
/// Thread safety: Creation must happen on main thread. See notes above.
HGI_API
virtual HgiSamplerHandle CreateSampler(HgiSamplerDesc const & desc) = 0;
/// Destroy a sampler in rendering backend.
/// Thread safety: Destruction must happen on main thread. See notes above.
HGI_API
virtual void DestroySampler(HgiSamplerHandle* smpHandle) = 0;
/// Create a buffer in rendering backend.
/// Thread safety: Creation must happen on main thread. See notes above.
HGI_API
virtual HgiBufferHandle CreateBuffer(HgiBufferDesc const & desc) = 0;
/// Destroy a buffer in rendering backend.
/// Thread safety: Destruction must happen on main thread. See notes above.
HGI_API
virtual void DestroyBuffer(HgiBufferHandle* bufHandle) = 0;
/// Create a new shader function.
/// Thread safety: Creation must happen on main thread. See notes above.
HGI_API
virtual HgiShaderFunctionHandle CreateShaderFunction(
HgiShaderFunctionDesc const& desc) = 0;
/// Destroy a shader function.
/// Thread safety: Destruction must happen on main thread. See notes above.
HGI_API
virtual void DestroyShaderFunction(
HgiShaderFunctionHandle* shaderFunctionHandle) = 0;
/// Create a new shader program.
/// Thread safety: Creation must happen on main thread. See notes above.
HGI_API
virtual HgiShaderProgramHandle CreateShaderProgram(
HgiShaderProgramDesc const& desc) = 0;
/// Destroy a shader program.
/// Note that this does NOT automatically destroy the shader functions in
/// the program since shader functions may be used by more than one program.
/// Thread safety: Destruction must happen on main thread. See notes above.
HGI_API
virtual void DestroyShaderProgram(
HgiShaderProgramHandle* shaderProgramHandle) = 0;
/// Create a new resource binding object.
/// Thread safety: Creation must happen on main thread. See notes above.
HGI_API
virtual HgiResourceBindingsHandle CreateResourceBindings(
HgiResourceBindingsDesc const& desc) = 0;
/// Destroy a resource binding object.
/// Thread safety: Destruction must happen on main thread. See notes above.
HGI_API
virtual void DestroyResourceBindings(
HgiResourceBindingsHandle* resHandle) = 0;
/// Create a new graphics pipeline state object.
/// Thread safety: Creation must happen on main thread. See notes above.
HGI_API
virtual HgiGraphicsPipelineHandle CreateGraphicsPipeline(
HgiGraphicsPipelineDesc const& pipeDesc) = 0;
/// Destroy a graphics pipeline state object.
/// Thread safety: Destruction must happen on main thread. See notes above.
HGI_API
virtual void DestroyGraphicsPipeline(
HgiGraphicsPipelineHandle* pipeHandle) = 0;
/// Create a new compute pipeline state object.
/// Thread safety: Creation must happen on main thread. See notes above.
HGI_API
virtual HgiComputePipelineHandle CreateComputePipeline(
HgiComputePipelineDesc const& pipeDesc) = 0;
/// Destroy a compute pipeline state object.
/// Thread safety: Destruction must happen on main thread. See notes above.
HGI_API
virtual void DestroyComputePipeline(HgiComputePipelineHandle* pipeHandle)=0;
/// Return the name of the api (e.g. "OpenGL").
/// Thread safety: This call is thread safe.
HGI_API
virtual TfToken const& GetAPIName() const = 0;
/// Returns the device-specific capabilities structure.
/// Thread safety: This call is thread safe.
HGI_API
virtual HgiCapabilities const* GetCapabilities() const = 0;
/// Optionally called by client app at the start of a new rendering frame.
/// We can't rely on StartFrame for anything important, because it is up to
/// the external client to (optionally) call this and they may never do.
/// Hydra doesn't have a clearly defined start or end frame.
/// This can be helpful to insert GPU frame debug markers.
/// Thread safety: Not thread safe. Should be called on the main thread.
HGI_API
virtual void StartFrame() = 0;
/// Optionally called at the end of a rendering frame.
/// Please read the comments in StartFrame.
/// Thread safety: Not thread safe. Should be called on the main thread.
HGI_API
virtual void EndFrame() = 0;
protected:
// Returns a unique id for handle creation.
// Thread safety: Thread-safe atomic increment.
HGI_API
uint64_t GetUniqueId();
// Calls Submit on provided Cmds.
// Derived classes can override this function if they need customize the
// command submission. The default implementation calls cmds->_Submit().
HGI_API
virtual bool _SubmitCmds(
HgiCmds* cmds, HgiSubmitWaitType wait);
private:
Hgi & operator=(const Hgi&) = delete;
Hgi(const Hgi&) = delete;
std::atomic<uint64_t> _uniqueIdCounter;
};
///
/// Hgi factory for plugin system
///
class HgiFactoryBase : public TfType::FactoryBase {
public:
virtual Hgi* New() const = 0;
};
template <class T>
class HgiFactory : public HgiFactoryBase {
public:
Hgi* New() const {
return new T;
}
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif
+204
View File
@@ -0,0 +1,204 @@
//
// Copyright 2020 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_IMAGING_HGI_RESOURCEBINDINGS_H
#define PXR_IMAGING_HGI_RESOURCEBINDINGS_H
#include "pxr/pxr.h"
#include "pxr/imaging/hgi/api.h"
#include "pxr/imaging/hgi/buffer.h"
#include "pxr/imaging/hgi/enums.h"
#include "pxr/imaging/hgi/handle.h"
#include "pxr/imaging/hgi/sampler.h"
#include "pxr/imaging/hgi/texture.h"
#include "pxr/imaging/hgi/types.h"
#include <string>
#include <vector>
PXR_NAMESPACE_OPEN_SCOPE
/// \struct HgiBufferBindDesc
///
/// Describes the binding information of a buffer (or array of buffers).
///
/// <ul>
/// <li>buffers:
/// The buffer(s) to be bound.
/// If there are more than one buffer, the buffers will be put in an
/// array-of-buffers. Please note that different platforms have varying
/// limits to max buffers in an array.</li>
/// <li>offsets:
/// Offset (in bytes) where data begins from the start of the buffer.
/// This if an offset for each buffer in 'buffers'.</li>
/// <li>resourceType:
/// The type of buffer(s) that is to be bound.
/// All buffers in the array must have the same type.
/// Vertex, index and indirect buffers are not bound to a resourceSet.
/// They are instead passed to the draw command.</li>
/// <li>bindingIndex:
/// Binding location for the buffer(s).</li>
/// <li>stageUsage:
/// What shader stage(s) the buffer will be used in.</li>
/// </ul>
///
struct HgiBufferBindDesc
{
HGI_API
HgiBufferBindDesc();
HgiBufferHandleVector buffers;
std::vector<uint32_t> offsets;
HgiBindResourceType resourceType;
uint32_t bindingIndex;
HgiShaderStage stageUsage;
};
using HgiBufferBindDescVector = std::vector<HgiBufferBindDesc>;
HGI_API
bool operator==(
const HgiBufferBindDesc& lhs,
const HgiBufferBindDesc& rhs);
HGI_API
inline bool operator!=(
const HgiBufferBindDesc& lhs,
const HgiBufferBindDesc& rhs);
/// \struct HgiTextureBindDesc
///
/// Describes the binding information of a texture (or array of textures).
///
/// <ul>
/// <li>textures:
/// The texture(s) to be bound.
/// If there are more than one texture, the textures will be put in an
/// array-of-textures (not texture-array). Please note that different
/// platforms have varying limits to max textures in an array.</li>
/// <li>samplers:
/// (optional) The sampler(s) to be bound for each texture in `textures`.
/// If empty a default sampler (clamp_to_edge, linear) should be used. </li>
/// <li>resourceType:
/// The type of the texture(s) that is to be bound.
/// All textures in the array must have the same type.</li>
/// <li>bindingIndex:
/// Binding location for the texture</li>
/// <li>stageUsage:
/// What shader stage(s) the texture will be used in.</li>
/// </ul>
///
struct HgiTextureBindDesc
{
HGI_API
HgiTextureBindDesc();
HgiTextureHandleVector textures;
HgiSamplerHandleVector samplers;
HgiBindResourceType resourceType;
uint32_t bindingIndex;
HgiShaderStage stageUsage;
};
using HgiTextureBindDescVector = std::vector<HgiTextureBindDesc>;
HGI_API
bool operator==(
const HgiTextureBindDesc& lhs,
const HgiTextureBindDesc& rhs);
HGI_API
bool operator!=(
const HgiTextureBindDesc& lhs,
const HgiTextureBindDesc& rhs);
/// \struct HgiResourceBindingsDesc
///
/// Describes a set of resources that are bound to the GPU during encoding.
///
/// <ul>
/// <li>buffers:
/// The buffers to be bound (E.g. uniform or shader storage).</li>
/// <li>textures:
/// The textures to be bound.</li>
/// </ul>
///
struct HgiResourceBindingsDesc
{
HGI_API
HgiResourceBindingsDesc();
std::string debugName;
HgiBufferBindDescVector buffers;
HgiTextureBindDescVector textures;
};
HGI_API
bool operator==(
const HgiResourceBindingsDesc& lhs,
const HgiResourceBindingsDesc& rhs);
HGI_API
bool operator!=(
const HgiResourceBindingsDesc& lhs,
const HgiResourceBindingsDesc& rhs);
///
/// \class HgiResourceBindings
///
/// Represents a collection of buffers, texture and vertex attributes that will
/// be used by an cmds object (and pipeline).
///
class HgiResourceBindings
{
public:
HGI_API
virtual ~HgiResourceBindings();
/// The descriptor describes the object.
HGI_API
HgiResourceBindingsDesc const& GetDescriptor() const;
protected:
HGI_API
HgiResourceBindings(HgiResourceBindingsDesc const& desc);
HgiResourceBindingsDesc _descriptor;
private:
HgiResourceBindings() = delete;
HgiResourceBindings & operator=(const HgiResourceBindings&) = delete;
HgiResourceBindings(const HgiResourceBindings&) = delete;
};
using HgiResourceBindingsHandle = HgiHandle<HgiResourceBindings>;
using HgiResourceBindingsHandleVector = std::vector<HgiResourceBindingsHandle>;
PXR_NAMESPACE_CLOSE_SCOPE
#endif
+137
View File
@@ -0,0 +1,137 @@
//
// Copyright 2020 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_IMAGING_HGI_SAMPLER_H
#define PXR_IMAGING_HGI_SAMPLER_H
#include "pxr/pxr.h"
#include "pxr/imaging/hgi/api.h"
#include "pxr/imaging/hgi/enums.h"
#include "pxr/imaging/hgi/handle.h"
#include "pxr/imaging/hgi/types.h"
#include <string>
#include <vector>
PXR_NAMESPACE_OPEN_SCOPE
/// \struct HgiSamplerDesc
///
/// Describes the properties needed to create a GPU sampler.
///
/// <ul>
/// <li>debugName:
/// This label can be applied as debug label for GPU debugging.</li>
/// <li>magFilter:
/// The (magnification) filter used to combine pixels when the sample area is
/// smaller than a pixel.</li>
/// <li>minFilter:
/// The (minification) filter used to combine pixels when the sample area is
/// larger than a pixel.</li>
/// <li> mipFilter:
/// The filter used for combining pixels between two mipmap levels.</li>
/// <li>addressMode***:
/// Wrapping modes.</li>
/// </ul>
///
struct HgiSamplerDesc
{
HgiSamplerDesc()
: magFilter(HgiSamplerFilterNearest)
, minFilter(HgiSamplerFilterNearest)
, mipFilter(HgiMipFilterNotMipmapped)
, addressModeU(HgiSamplerAddressModeClampToEdge)
, addressModeV(HgiSamplerAddressModeClampToEdge)
, addressModeW(HgiSamplerAddressModeClampToEdge)
{}
std::string debugName;
HgiSamplerFilter magFilter;
HgiSamplerFilter minFilter;
HgiMipFilter mipFilter;
HgiSamplerAddressMode addressModeU;
HgiSamplerAddressMode addressModeV;
HgiSamplerAddressMode addressModeW;
};
HGI_API
bool operator==(
const HgiSamplerDesc& lhs,
const HgiSamplerDesc& rhs);
HGI_API
bool operator!=(
const HgiSamplerDesc& lhs,
const HgiSamplerDesc& rhs);
///
/// \class HgiSampler
///
/// Represents a graphics platform independent GPU sampler resource that
/// perform texture sampling operations.
/// Samplers should be created via Hgi::CreateSampler.
///
class HgiSampler
{
public:
HGI_API
virtual ~HgiSampler();
/// The descriptor describes the object.
HGI_API
HgiSamplerDesc const& GetDescriptor() const;
/// This function returns the handle to the Hgi backend's gpu resource, cast
/// to a uint64_t. Clients should avoid using this function and instead
/// use Hgi base classes so that client code works with any Hgi platform.
/// For transitioning code to Hgi, it can however we useful to directly
/// access a platform's internal resource handles.
/// There is no safety provided in using this. If you by accident pass a
/// HgiMetal resource into an OpenGL call, bad things may happen.
/// In OpenGL this returns the GLuint resource name.
/// In Metal this returns the id<MTLSamplerState> as uint64_t.
/// In Vulkan this returns the VkSampler as uint64_t.
HGI_API
virtual uint64_t GetRawResource() const = 0;
protected:
HGI_API
HgiSampler(HgiSamplerDesc const& desc);
HgiSamplerDesc _descriptor;
private:
HgiSampler() = delete;
HgiSampler & operator=(const HgiSampler&) = delete;
HgiSampler(const HgiSampler&) = delete;
};
using HgiSamplerHandle = HgiHandle<HgiSampler>;
using HgiSamplerHandleVector = std::vector<HgiSamplerHandle>;
PXR_NAMESPACE_CLOSE_SCOPE
#endif
+101
View File
@@ -0,0 +1,101 @@
//
// Copyright 2020 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_IMAGING_HGI_SHADERFUNCTION_H
#define PXR_IMAGING_HGI_SHADERFUNCTION_H
#include "pxr/pxr.h"
#include "pxr/imaging/hgi/api.h"
#include "pxr/imaging/hgi/enums.h"
#include "pxr/imaging/hgi/handle.h"
#include "pxr/imaging/hgi/shaderFunctionDesc.h"
#include "pxr/imaging/hgi/types.h"
PXR_NAMESPACE_OPEN_SCOPE
///
/// \class HgiShaderFunction
///
/// Represents one shader stage function (code snippet).
///
/// ShaderFunctions are usually passed to a ShaderProgram, however be careful
/// not to destroy the ShaderFunction after giving it to the program.
/// While this may be safe for OpenGL after the program is created, it does not
/// apply to other graphics backends, such as Vulkan, where the shader functions
/// are used during rendering.
///
class HgiShaderFunction
{
public:
HGI_API
virtual ~HgiShaderFunction();
/// The descriptor describes the object.
HGI_API
HgiShaderFunctionDesc const& GetDescriptor() const;
/// Returns false if any shader compile errors occured.
HGI_API
virtual bool IsValid() const = 0;
/// Returns shader compile errors.
HGI_API
virtual std::string const& GetCompileErrors() = 0;
/// Returns the byte size of the GPU shader function.
/// This can be helpful if the application wishes to tally up memory usage.
HGI_API
virtual size_t GetByteSizeOfResource() const = 0;
/// This function returns the handle to the Hgi backend's gpu resource, cast
/// to a uint64_t. Clients should avoid using this function and instead
/// use Hgi base classes so that client code works with any Hgi platform.
/// For transitioning code to Hgi, it can however we useful to directly
/// access a platform's internal resource handles.
/// There is no safety provided in using this. If you by accident pass a
/// HgiMetal resource into an OpenGL call, bad things may happen.
/// In OpenGL this returns the GLuint resource name.
/// In Metal this returns the id<MTLFunction> as uint64_t.
/// In Vulkan this returns the VkShaderModule as uint64_t.
/// In DX12 this returns the ID3D12Resource pointer as uint64_t.
HGI_API
virtual uint64_t GetRawResource() const = 0;
protected:
HGI_API
HgiShaderFunction(HgiShaderFunctionDesc const& desc);
HgiShaderFunctionDesc _descriptor;
private:
HgiShaderFunction() = delete;
HgiShaderFunction & operator=(const HgiShaderFunction&) = delete;
HgiShaderFunction(const HgiShaderFunction&) = delete;
};
using HgiShaderFunctionHandle = HgiHandle<class HgiShaderFunction>;
using HgiShaderFunctionHandleVector = std::vector<HgiShaderFunctionHandle>;
PXR_NAMESPACE_CLOSE_SCOPE
#endif
@@ -0,0 +1,256 @@
//
// Copyright 2020 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_IMAGING_HGI_SHADERFUNCTIONDESC_H
#define PXR_IMAGING_HGI_SHADERFUNCTIONDESC_H
#include "pxr/pxr.h"
#include "pxr/imaging/hgi/api.h"
#include "pxr/imaging/hgi/enums.h"
#include "pxr/imaging/hgi/types.h"
#include <string>
#include <vector>
PXR_NAMESPACE_OPEN_SCOPE
/// \struct HgiShaderFunctionTextureDesc
///
/// Describes a texture to be passed into a shader
///
/// <ul>
/// <li>nameInShader:
/// The name written from the codegen into shader file for the texture.</li>
/// <li>dimensions:
/// 1d, 2d or 3d texture declaration.</li>
/// <li>format
/// Format of the texture. This is required in APIs where sampler types depend
/// on the texture (e.g., GL) </li>
/// </ul>
///
struct HgiShaderFunctionTextureDesc
{
HGI_API
HgiShaderFunctionTextureDesc();
std::string nameInShader;
uint32_t dimensions;
HgiFormat format;
};
using HgiShaderFunctionTextureDescVector =
std::vector<HgiShaderFunctionTextureDesc>;
HGI_API
bool operator==(
const HgiShaderFunctionTextureDesc& lhs,
const HgiShaderFunctionTextureDesc& rhs);
HGI_API
bool operator!=(
const HgiShaderFunctionTextureDesc& lhs,
const HgiShaderFunctionTextureDesc& rhs);
/// \struct HgiShaderFunctionBufferDesc
///
/// Describes a buffer to be passed into a shader
///
/// <ul>
/// <li>nameInShader:
/// The name written from the codegen into shader file for the texture.</li>
/// <li>type:
/// Type of the param within the shader file.</li>
/// </ul>
///
struct HgiShaderFunctionBufferDesc
{
HGI_API
HgiShaderFunctionBufferDesc();
std::string nameInShader;
std::string type;
};
using HgiShaderFunctionBufferDescVector =
std::vector<HgiShaderFunctionBufferDesc>;
HGI_API
bool operator==(
const HgiShaderFunctionBufferDesc& lhs,
const HgiShaderFunctionBufferDesc& rhs);
HGI_API
bool operator!=(
const HgiShaderFunctionBufferDesc& lhs,
const HgiShaderFunctionBufferDesc& rhs);
/// \struct HgiShaderFunctionParamDesc
///
/// Describes a constant param passed into a shader
///
/// <ul>
/// <li>nameInShader:
/// The name written from the codegen into the shader file for the param.</li>
/// <li>type:
/// Type of the param within the shader file.</li>
/// <li>role:
/// Optionally a role can be specified, like position, uv, color.</li>
/// <li>attribute:
/// Optionally an attribute can be specified, like versions or addresses.</li>
/// <li>attributeIndex:
/// Used in metal, to specify indicies of attributes.</li>
/// </ul>
///
struct HgiShaderFunctionParamDesc
{
HGI_API
HgiShaderFunctionParamDesc();
std::string nameInShader;
std::string type;
std::string role;
std::string attribute;
std::string attributeIndex;
};
using HgiShaderFunctionParamDescVector =
std::vector<HgiShaderFunctionParamDesc>;
HGI_API
bool operator==(
const HgiShaderFunctionParamDesc& lhs,
const HgiShaderFunctionParamDesc& rhs);
HGI_API
bool operator!=(
const HgiShaderFunctionParamDesc& lhs,
const HgiShaderFunctionParamDesc& rhs);
/// \struct HgiShaderFunctionDesc
///
/// Describes the properties needed to create a GPU shader function.
///
/// <ul>
/// <li>debugName:
/// This label can be applied as debug label for gpu debugging.</li>
/// <li>shaderStage:
/// The shader stage this function represents.</li>
/// <li>shaderCode:
/// The ascii shader code used to compile the shader.</li>
/// <li>textures:
/// List of texture descriptions to be passed into a shader.</li>
/// <li>buffers:
/// List of buffer descriptions to be passed into a shader.</li>
/// <li>constantParams:
/// List of descriptions of constant params passed into a shader.</li>
/// <li>stageInputs:
/// List of descriptions of the inputs of the shader.</li>
/// <li>stageOutputs:
/// List of descriptions of the outputs of the shader.</li>
/// </ul>
///
struct HgiShaderFunctionDesc
{
HGI_API
HgiShaderFunctionDesc();
std::string debugName;
HgiShaderStage shaderStage;
const char* shaderCode;
std::vector<HgiShaderFunctionTextureDesc> textures;
std::vector<HgiShaderFunctionBufferDesc> buffers;
std::vector<HgiShaderFunctionParamDesc> constantParams;
std::vector<HgiShaderFunctionParamDesc> stageInputs;
std::vector<HgiShaderFunctionParamDesc> stageOutputs;
};
using HgiShaderFunctionDescVector =
std::vector<HgiShaderFunctionDesc>;
HGI_API
bool operator==(
const HgiShaderFunctionDesc& lhs,
const HgiShaderFunctionDesc& rhs);
HGI_API
bool operator!=(
const HgiShaderFunctionDesc& lhs,
const HgiShaderFunctionDesc& rhs);
/// Adds texture descriptor to given shader function descriptor.
HGI_API
void
HgiShaderFunctionAddTexture(
HgiShaderFunctionDesc *desc,
const std::string &nameInShader,
uint32_t dimensions = 2,
const HgiFormat &format = HgiFormatFloat32Vec4);
/// Adds buffer descriptor to given shader function descriptor.
HGI_API
void
HgiShaderFunctionAddBuffer(
HgiShaderFunctionDesc *desc,
const std::string &nameInShader,
const std::string &type);
/// Adds constant function param descriptor to given shader function
/// descriptor.
HGI_API
void
HgiShaderFunctionAddConstantParam(
HgiShaderFunctionDesc *desc,
const std::string &nameInShader,
const std::string &type,
const std::string &role = std::string(),
const std::string &attribute = std::string(),
const std::string &attributeIndex = std::string());
/// Adds stage input function param descriptor to given shader function
/// descriptor.
HGI_API
void
HgiShaderFunctionAddStageInput(
HgiShaderFunctionDesc *desc,
const std::string &nameInShader,
const std::string &type,
const std::string &role = std::string(),
const std::string &attribute = std::string(),
const std::string &attributeIndex = std::string());
/// Adds stage output function param descriptor to given shader function
/// descriptor.
HGI_API
void
HgiShaderFunctionAddStageOutput(
HgiShaderFunctionDesc *desc,
const std::string &nameInShader,
const std::string &type,
const std::string &role = std::string(),
const std::string &attribute = std::string(),
const std::string &attributeIndex = std::string());
PXR_NAMESPACE_CLOSE_SCOPE
#endif
+87
View File
@@ -0,0 +1,87 @@
//
// Copyright 2020 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_IMAGING_HGI_SHADERGENERATOR_H
#define PXR_IMAGING_HGI_SHADERGENERATOR_H
#include "pxr/pxr.h"
#include "pxr/imaging/hgi/api.h"
#include "pxr/imaging/hgi/enums.h"
#include <iosfwd>
#include <string>
PXR_NAMESPACE_OPEN_SCOPE
struct HgiShaderFunctionDesc;
/// \class HgiShaderGenerator
///
/// Base class for shader function generation
/// Given a descriptor, converts glslfx domain language to concrete shader
/// languages. Can be extended with new types of code sections and specialized
/// for different APIs. It's main role is to make GLSLFX a write once language,
/// no matter the API
///
class HgiShaderGenerator
{
public:
//Write the generated code to the stringstream given once set up
HGI_API
void Execute(std::ostream &ss);
HGI_API
virtual ~HgiShaderGenerator();
protected:
HGI_API
explicit HgiShaderGenerator(const HgiShaderFunctionDesc &descriptor);
HGI_API
virtual void _Execute(
std::ostream &ss,
const std::string &originalShaderCode) = 0;
HGI_API
const std::string& _GetOriginalShader() const;
HGI_API
HgiShaderStage _GetShaderStage() const;
HGI_API
const std::string& _GetVersion() const;
private:
HgiShaderGenerator() = delete;
HgiShaderGenerator & operator=(const HgiShaderGenerator&) = delete;
HgiShaderGenerator(const HgiShaderGenerator&) = delete;
const std::string _version;
const std::string _originalShader;
const HgiShaderStage _stage;
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif
+139
View File
@@ -0,0 +1,139 @@
//
// Copyright 2020 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_IMAGING_HGI_SHADERPROGRAM_H
#define PXR_IMAGING_HGI_SHADERPROGRAM_H
#include "pxr/pxr.h"
#include "pxr/imaging/hgi/api.h"
#include "pxr/imaging/hgi/enums.h"
#include "pxr/imaging/hgi/handle.h"
#include "pxr/imaging/hgi/shaderFunction.h"
#include "pxr/imaging/hgi/types.h"
#include <vector>
PXR_NAMESPACE_OPEN_SCOPE
/// \struct HgiShaderProgramDesc
///
/// Describes the properties needed to create a GPU shader program.
///
/// <ul>
/// <li>debugName:
/// This label can be applied as debug label for gpu debugging.</li>
/// <li>shaderFunctions:
/// Holds handles to shader functions for each shader stage.</li>
/// </ul>
///
struct HgiShaderProgramDesc
{
HGI_API
HgiShaderProgramDesc();
std::string debugName;
HgiShaderFunctionHandleVector shaderFunctions;
};
HGI_API
inline bool operator==(
const HgiShaderProgramDesc& lhs,
const HgiShaderProgramDesc& rhs);
HGI_API
inline bool operator!=(
const HgiShaderProgramDesc& lhs,
const HgiShaderProgramDesc& rhs);
///
/// \class HgiShaderProgram
///
/// Represents a collection of shader functions.
/// This object does not take ownership of the shader functions and does not
/// destroy them automatically. The client must destroy the shader functions
/// when the program is detroyed, because only the client knows if the shader
/// functions are used by other shader programs.
///
class HgiShaderProgram
{
public:
HGI_API
virtual ~HgiShaderProgram();
/// The descriptor describes the object.
HGI_API
HgiShaderProgramDesc const& GetDescriptor() const;
/// Returns false if any shader compile errors occured.
HGI_API
virtual bool IsValid() const = 0;
/// Returns shader compile errors.
HGI_API
virtual std::string const& GetCompileErrors() = 0;
/// Returns the shader functions that are part of this program.
HGI_API
virtual HgiShaderFunctionHandleVector const& GetShaderFunctions() const = 0;
/// Returns the byte size of the GPU shader program.
/// APIs that do not have programs can return the combined byte size of the
/// shader functions used by the program.
/// This can be helpful if the application wishes to tally up memory usage.
HGI_API
virtual size_t GetByteSizeOfResource() const = 0;
/// This function returns the handle to the Hgi backend's gpu resource, cast
/// to a uint64_t. Clients should avoid using this function and instead
/// use Hgi base classes so that client code works with any Hgi platform.
/// For transitioning code to Hgi, it can however we useful to directly
/// access a platform's internal resource handles.
/// There is no safety provided in using this. If you by accident pass a
/// HgiMetal resource into an OpenGL call, bad things may happen.
/// In OpenGL this returns the GLuint resource name.
/// In Metal, Vulkan this returns 0.
HGI_API
virtual uint64_t GetRawResource() const = 0;
protected:
HGI_API
HgiShaderProgram(HgiShaderProgramDesc const& desc);
HgiShaderProgramDesc _descriptor;
private:
HgiShaderProgram() = delete;
HgiShaderProgram & operator=(const HgiShaderProgram&) = delete;
HgiShaderProgram(const HgiShaderProgram&) = delete;
};
using HgiShaderProgramHandle = HgiHandle<class HgiShaderProgram>;
using HgiShaderProgramHandleVector = std::vector<HgiShaderProgramHandle>;
PXR_NAMESPACE_CLOSE_SCOPE
#endif
+100
View File
@@ -0,0 +1,100 @@
//
// Copyright 2020 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_IMAGING_HGI_SHADERSECTION_H
#define PXR_IMAGING_HGI_SHADERSECTION_H
#include "pxr/pxr.h"
#include "pxr/imaging/hgi/api.h"
#include <memory>
#include <ostream>
#include <string>
#include <vector>
PXR_NAMESPACE_OPEN_SCOPE
//struct to hold attribute definitions
struct HgiShaderSectionAttribute
{
std::string identifier;
std::string index;
};
using HgiShaderSectionAttributeVector =
std::vector<HgiShaderSectionAttribute>;
/// \class HgiShaderSection
///
/// A base class for a Shader Section.
/// In its simplest form then it is a construct that knows
/// how to declare itself, define and pass as param.
/// Can be subclassed to add more behaviour for complex cases
/// and to hook into the visitor tree.
///
class HgiShaderSection
{
public:
HGI_API
virtual ~HgiShaderSection();
/// Write out the type, shader section does not hold a type
/// string as how a type is defined is fully controlled
/// by sub classes and no assumptions are made
HGI_API
virtual void WriteType(std::ostream& ss) const;
/// Writes the unique name of an instance of the section
HGI_API
virtual void WriteIdentifier(std::ostream& ss) const;
/// Writes a decleration statement for a member or in global scope
HGI_API
virtual void WriteDeclaration(std::ostream& ss) const;
/// Writes the section as a parameter to a function
HGI_API
virtual void WriteParameter(std::ostream& ss) const;
HGI_API
const HgiShaderSectionAttributeVector& GetAttributes() const;
protected:
HGI_API
explicit HgiShaderSection(
const std::string &identifier,
const HgiShaderSectionAttributeVector& attributes = {},
const std::string &defaultValue = std::string());
HGI_API
const std::string& _GetDefaultValue() const;
private:
const std::string _identifierVar;
const HgiShaderSectionAttributeVector _attributes;
const std::string _defaultValue;
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif
+317
View File
@@ -0,0 +1,317 @@
//
// Copyright 2019 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_IMAGING_HGI_TEXTURE_H
#define PXR_IMAGING_HGI_TEXTURE_H
#include "pxr/pxr.h"
#include "pxr/base/gf/vec3i.h"
#include "pxr/imaging/hgi/api.h"
#include "pxr/imaging/hgi/enums.h"
#include "pxr/imaging/hgi/handle.h"
#include "pxr/imaging/hgi/types.h"
#include <string>
#include <vector>
PXR_NAMESPACE_OPEN_SCOPE
/// \struct HgiComponentMapping
///
/// Describes color component mapping.
///
/// <ul>
/// <li>r:
/// What component is used for red channel.
/// <li>g:
/// What component is used for green channel.
/// <li>b:
/// What component is used for blue channel.
/// <li>a:
/// What component is used for alpha channel.
/// </ul>
///
struct HgiComponentMapping
{
HgiComponentSwizzle r;
HgiComponentSwizzle g;
HgiComponentSwizzle b;
HgiComponentSwizzle a;
};
HGI_API
bool operator==(
const HgiComponentMapping& lhs,
const HgiComponentMapping& rhs);
HGI_API
bool operator!=(
const HgiComponentMapping& lhs,
const HgiComponentMapping& rhs);
/// \struct HgiTextureDesc
///
/// Describes the properties needed to create a GPU texture.
///
/// <ul>
/// <li>debugName:
/// This label can be applied as debug label for GPU debugging.</li>
/// <li>usage:
/// Describes how the texture is intended to be used.</li>
/// <li>format:
/// The format of the texture.
/// <li>componentMapping:
/// The mapping of rgba components when accessing the texture.</li>
/// <li>dimensions:
/// The resolution of the texture (width, height, depth).</li>
/// <li>type:
/// Type of texture (2D, 3D).</li>
/// <li>layerCount:
/// The number of layers (texture-arrays).</li>
/// <li>mipLevels:
/// The number of mips in texture.</li>
/// <li>sampleCount:
/// samples per texel (multi-sampling).</li>
/// <li>pixelsByteSize:
/// Byte size (length) of pixel data (i.e., initialData).</li>
/// <li>initialData:
/// CPU pointer to initialization pixels of the texture.
/// The memory is consumed immediately during the creation of the HgiTexture.
/// The application may alter or free this memory as soon as the constructor
/// of the HgiTexture has returned.
/// Data may optionally include pixels for each mip-level.
/// HgiGetMipInitialData can be used to get to each mip's data and describes
/// in more detail how mip dimensions are rounded.</li>
/// </ul>
///
struct HgiTextureDesc
{
HgiTextureDesc()
: usage(0)
, format(HgiFormatInvalid)
, componentMapping{
HgiComponentSwizzleR,
HgiComponentSwizzleG,
HgiComponentSwizzleB,
HgiComponentSwizzleA}
, type(HgiTextureType2D)
, dimensions(0)
, layerCount(1)
, mipLevels(1)
, sampleCount(HgiSampleCount1)
, pixelsByteSize(0)
, initialData(nullptr)
{}
std::string debugName;
HgiTextureUsage usage;
HgiFormat format;
HgiComponentMapping componentMapping;
HgiTextureType type;
GfVec3i dimensions;
uint16_t layerCount;
uint16_t mipLevels;
HgiSampleCount sampleCount;
size_t pixelsByteSize;
void const* initialData;
};
HGI_API
bool operator==(
const HgiTextureDesc& lhs,
const HgiTextureDesc& rhs);
HGI_API
bool operator!=(
const HgiTextureDesc& lhs,
const HgiTextureDesc& rhs);
///
/// \class HgiTexture
///
/// Represents a graphics platform independent GPU texture resource.
/// Textures should be created via Hgi::CreateTexture.
///
/// Base class for Hgi textures.
/// To the client (HdSt) texture resources are referred to via
/// opaque, stateless handles (HgTextureHandle).
///
class HgiTexture
{
public:
HGI_API
virtual ~HgiTexture();
/// The descriptor describes the object.
HGI_API
HgiTextureDesc const& GetDescriptor() const;
/// Returns the byte size of the GPU texture.
/// This can be helpful if the application wishes to tally up memory usage.
HGI_API
virtual size_t GetByteSizeOfResource() const = 0;
/// This function returns the handle to the Hgi backend's gpu resource, cast
/// to a uint64_t. Clients should avoid using this function and instead
/// use Hgi base classes so that client code works with any Hgi platform.
/// For transitioning code to Hgi, it can however we useful to directly
/// access a platform's internal resource handles.
/// There is no safety provided in using this. If you by accident pass a
/// HgiMetal resource into an OpenGL call, bad things may happen.
/// In OpenGL this returns the GLuint resource name.
/// In Metal this returns the id<MTLTexture> as uint64_t.
/// In Vulkan this returns the VkImage as uint64_t.
/// In DX12 this returns the ID3D12Resource pointer as uint64_t.
HGI_API
virtual uint64_t GetRawResource() const = 0;
protected:
HGI_API
static
size_t _GetByteSizeOfResource(const HgiTextureDesc &descriptor);
HGI_API
HgiTexture(HgiTextureDesc const& desc);
HgiTextureDesc _descriptor;
private:
HgiTexture() = delete;
HgiTexture & operator=(const HgiTexture&) = delete;
HgiTexture(const HgiTexture&) = delete;
};
using HgiTextureHandle = HgiHandle<class HgiTexture>;
using HgiTextureHandleVector = std::vector<HgiTextureHandle>;
/// \struct HgiTextureViewDesc
///
/// Describes the properties needed to create a GPU texture view from an
/// existing GPU texture object.
///
/// <ul>
/// <li>debugName:
/// This label can be applied as debug label for GPU debugging.</li>
/// <li>format:
/// The format of the texture view. This format must be compatible with
/// the sourceTexture, but does not have to be the identical format.
/// Generally: All 8-, 16-, 32-, 64-, and 128-bit color formats are
/// compatible with other formats with the same bit length.
/// For example HgiFormatFloat32Vec4 and HgiFormatInt32Vec4 are compatible.
/// <li>layerCount:
/// The number of layers (texture-arrays).</li>
/// <li>mipLevels:
/// The number of mips in texture.</li>
/// <li>sourceTexture:
/// Handle to the HgiTexture to be used as the source data backing.</li>
/// <li>sourceFirstLayer:
/// The layer index to use from the source texture as the first layer of the
/// view.</li>
/// <li>sourceFirstMip:
/// The mip index to ues from the source texture as the first mip of the
/// view.</li>
/// </ul>
///
struct HgiTextureViewDesc
{
HgiTextureViewDesc()
: format(HgiFormatInvalid)
, layerCount(1)
, mipLevels(1)
, sourceTexture()
, sourceFirstLayer(0)
, sourceFirstMip(0)
{}
std::string debugName;
HgiFormat format;
uint16_t layerCount;
uint16_t mipLevels;
HgiTextureHandle sourceTexture;
uint16_t sourceFirstLayer;
uint16_t sourceFirstMip;
};
HGI_API
bool operator==(
const HgiTextureViewDesc& lhs,
const HgiTextureViewDesc& rhs);
HGI_API
bool operator!=(
const HgiTextureViewDesc& lhs,
const HgiTextureViewDesc& rhs);
///
/// \class HgiTextureView
///
/// Represents a graphics platform independent GPU texture view resource.
/// Texture Views should be created via Hgi::CreateTextureView.
///
/// A TextureView aliases the data of another texture and is a thin wrapper
/// around a HgiTextureHandle. The embeded texture handle is used to
/// add the texture to resource bindings for use in shaders.
///
/// For example when using a compute shader to fill the mip levels of a
/// texture, like a lightDome texture, we can use a texture view to give the
/// shader access to a specific mip level of a sourceTexture via a TextureView.
///
/// Another example is to conserve resources by reusing a RGBAF32 texture as
/// a RGBAI32 texture once the F32 texture is no longer needed
/// (transient resources).
///
class HgiTextureView
{
public:
HGI_API
HgiTextureView(HgiTextureViewDesc const& desc);
HGI_API
virtual ~HgiTextureView();
/// Set the handle to the texture that aliases another texture.
HGI_API
void SetViewTexture(HgiTextureHandle const& handle);
/// Returns the handle to the texture that aliases another texture.
HGI_API
HgiTextureHandle const& GetViewTexture() const;
protected:
HgiTextureHandle _viewTexture;
private:
HgiTextureView() = delete;
HgiTextureView & operator=(const HgiTextureView&) = delete;
HgiTextureView(const HgiTextureView&) = delete;
};
using HgiTextureViewHandle = HgiHandle<class HgiTextureView>;
using HgiTextureViewHandleVector = std::vector<HgiTextureViewHandle>;
PXR_NAMESPACE_CLOSE_SCOPE
#endif
+52
View File
@@ -0,0 +1,52 @@
//
// Copyright 2020 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_IMAGING_HGI_TOKENS_H
#define PXR_IMAGING_HGI_TOKENS_H
#include "pxr/pxr.h"
#include "pxr/base/tf/staticTokens.h"
#include "pxr/imaging/hgi/api.h"
PXR_NAMESPACE_OPEN_SCOPE
#define HGI_TOKENS \
(taskDriver) \
(renderDriver) \
(OpenGL) \
(Metal) \
(Vulkan)
TF_DECLARE_PUBLIC_TOKENS(HgiTokens, HGI_API, HGI_TOKENS);
#define HGI_SHADER_KEYWORD_TOKENS \
(hdGlobalInvocationID) \
(hdPosition)
TF_DECLARE_PUBLIC_TOKENS(
HgiShaderKeywordTokens, HGI_API, HGI_SHADER_KEYWORD_TOKENS);
PXR_NAMESPACE_CLOSE_SCOPE
#endif
+195
View File
@@ -0,0 +1,195 @@
//
// Copyright 2020 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_IMAGING_HGI_TYPES_H
#define PXR_IMAGING_HGI_TYPES_H
#include "pxr/pxr.h"
#include "pxr/base/gf/vec3i.h"
#include "pxr/imaging/hgi/api.h"
#include <vector>
#include <limits>
#include <stdlib.h>
PXR_NAMESPACE_OPEN_SCOPE
/// \enum HgiFormat
///
/// HgiFormat describes the memory format of image buffers used in Hgi.
/// These formats are closely aligned with HdFormat and allow us to keep Hgi
/// independent of Hd.
///
/// For reference, see:
/// https://www.khronos.org/registry/vulkan/specs/1.1/html/vkspec.html#VkFormat
enum HgiFormat : int
{
HgiFormatInvalid = -1,
// UNorm8 - a 1-byte value representing a float between 0 and 1.
// float value = (unorm / 255.0f);
HgiFormatUNorm8 = 0,
HgiFormatUNorm8Vec2,
/* HgiFormatUNorm8Vec3 */ // Unsupported Metal (MTLPixelFormat)
HgiFormatUNorm8Vec4,
// SNorm8 - a 1-byte value representing a float between -1 and 1.
// float value = max(snorm / 127.0f, -1.0f);
HgiFormatSNorm8,
HgiFormatSNorm8Vec2,
/* HgiFormatSNorm8Vec3 */ // Unsupported Metal (MTLPixelFormat)
HgiFormatSNorm8Vec4,
// Float16 - a 2-byte IEEE half-precision float.
HgiFormatFloat16,
HgiFormatFloat16Vec2,
HgiFormatFloat16Vec3,
HgiFormatFloat16Vec4,
// Float32 - a 4-byte IEEE float.
HgiFormatFloat32,
HgiFormatFloat32Vec2,
HgiFormatFloat32Vec3,
HgiFormatFloat32Vec4,
// Int16 - a 2-byte signed integer
HgiFormatInt16,
HgiFormatInt16Vec2,
HgiFormatInt16Vec3,
HgiFormatInt16Vec4,
// UInt16 - a 2-byte unsigned integer
HgiFormatUInt16,
HgiFormatUInt16Vec2,
HgiFormatUInt16Vec3,
HgiFormatUInt16Vec4,
// Int32 - a 4-byte signed integer
HgiFormatInt32,
HgiFormatInt32Vec2,
HgiFormatInt32Vec3,
HgiFormatInt32Vec4,
// UNorm8 SRGB - a 1-byte value representing a float between 0 and 1.
// Gamma compression/decompression happens during read/write.
// Alpha component is linear.
/* HgiFormatUNorm8srgb */ // Unsupported by OpenGL
/* HgiFormatUNorm8Vec2srgb */ // Unsupported by OpenGL
/* HgiFormatUNorm8Vec3srgb */ // Unsupported Metal (MTLPixelFormat)
HgiFormatUNorm8Vec4srgb,
// BPTC compressed. 3-component, 4x4 blocks, signed floating-point
HgiFormatBC6FloatVec3,
// BPTC compressed. 3-component, 4x4 blocks, unsigned floating-point
HgiFormatBC6UFloatVec3,
// BPTC compressed. 4-component, 4x4 blocks, unsigned byte.
// Representing a float between 0 and 1.
HgiFormatBC7UNorm8Vec4,
// BPTC compressed. 4-component, 4x4 blocks, unsigned byte, sRGB.
// Representing a float between 0 and 1.
HgiFormatBC7UNorm8Vec4srgb,
// S3TC/DXT compressed. 4-component, 4x4 blocks, unsigned byte
// Representing a float between 0 and 1.
HgiFormatBC1UNorm8Vec4,
// S3TC/DXT compressed. 4-component, 4x4 blocks, unsigned byte
// Representing a float between 0 and 1.
HgiFormatBC3UNorm8Vec4,
// Depth stencil format (Float32 can be used for just depth)
HgiFormatFloat32UInt8,
HgiFormatCount
};
/// \class HgiMipInfo
///
/// HgiMipInfo describes size and other info for a mip level.
struct HgiMipInfo
{
/// Offset in bytes from start of texture data to start of mip map.
size_t byteOffset;
/// Dimension of mip GfVec3i.
GfVec3i dimensions;
/// size of (one layer if array of) mip map in bytes.
size_t byteSizePerLayer;
};
/// Return the count of components in the given format.
HGI_API
size_t HgiGetComponentCount(HgiFormat f);
/// Return the size of a single element of the given format.
///
/// For an uncompressed format, returns the number of bytes per pixel
/// and sets blockWidth and blockHeight to 1.
/// For a compressed format (e.g., BC6), returns the number of bytes per
/// block and sets blockWidth and blockHeight to the width and height of
/// a block.
///
HGI_API
size_t HgiGetDataSizeOfFormat(
HgiFormat f,
size_t *blockWidth = nullptr,
size_t *blockHeight = nullptr);
/// Return whether the given format uses compression.
HGI_API
bool HgiIsCompressed(HgiFormat f);
/// Returns the size necessary to allocate a buffer of given dimensions
/// and format, rounding dimensions up to suitable multiple when
/// using a compressed format.
HGI_API
size_t HgiGetDataSize(
HgiFormat f,
const GfVec3i &dimensions);
/// Returns mip infos.
///
/// If dataByteSize is specified, the levels stops when the total memory
/// required by all levels up to that point reach the specified value.
/// Otherwise, the levels stop when all dimensions are 1.
/// Mip map sizes are calculated by dividing the previous mip level by two and
/// rounding down to the nearest integer (minimum integer is 1).
/// level 0: 37x53
/// level 1: 18x26
/// level 2: 9x13
/// level 3: 4x6
/// level 4: 2x3
/// level 5: 1x1
HGI_API
std::vector<HgiMipInfo>
HgiGetMipInfos(
HgiFormat format,
const GfVec3i& dimensions,
size_t layerCount,
size_t dataByteSize = std::numeric_limits<size_t>::max());
PXR_NAMESPACE_CLOSE_SCOPE
#endif