Added GetPatchDrawingShaderSource()

This is a new method for GLSL, HLSL, and MSL which returns patch
drawing shader source which excludes legacy shader source aspects.

This improves portability and compatibility and may also improve
shader compile times since the resulting shader source strings
are smaller without the legacy shader source aspects.

Tested with Vulkan and DX12 in addition to GL, DX11, and Metal.
This commit is contained in:
David G Yu 2023-09-07 16:46:26 -07:00 committed by David G Yu
parent c2ed7d5cf0
commit fdb9ac9afb
6 changed files with 101 additions and 16 deletions

View File

@ -67,10 +67,18 @@ static const char *gregoryTriangleShaderSource =
/*static*/
std::string
GLSLPatchShaderSource::GetCommonShaderSource() {
GLSLPatchShaderSource::GetPatchDrawingShaderSource() {
std::stringstream ss;
ss << std::string(commonShaderSource);
ss << std::string(commonTessShaderSource);
return ss.str();
}
/*static*/
std::string
GLSLPatchShaderSource::GetCommonShaderSource() {
std::stringstream ss;
ss << GetPatchDrawingShaderSource();
ss << std::string(patchLegacyShaderSource);
return ss.str();
}

View File

@ -26,20 +26,39 @@
#define OPENSUBDIV3_OSD_GLSL_PATCH_SHADER_SOURCE_H
#include "../version.h"
#include <string>
#include "../far/patchDescriptor.h"
#include <string>
namespace OpenSubdiv {
namespace OPENSUBDIV_VERSION {
namespace Osd {
/// \brief Provides shader source which can be used by client code.
class GLSLPatchShaderSource {
public:
static std::string GetCommonShaderSource();
/// \brief Returns shader source which can be used to evaluate
/// position and first and second derivatives on piecewise parametric
/// patches resulting from subdivision refinement.
static std::string GetPatchBasisShaderSource();
/// \brief Returns shader source which can be used while drawing
/// piecewise parametric patches resulting from subdivision refinement,
/// e.g. while using GPU HW tessellation.
static std::string GetPatchDrawingShaderSource();
/// \name Alternative methods
/// \{
/// These methods return shader source which can be used
/// while drawing. Unlike the methods above, the source returned
/// by these methods includes support for legacy patch types along
/// with dependencies on specific resource bindings and interstage
/// shader variable declarations.
static std::string GetCommonShaderSource();
static std::string GetVertexShaderSource(
Far::PatchDescriptor::Type type);
@ -48,6 +67,8 @@ public:
static std::string GetTessEvalShaderSource(
Far::PatchDescriptor::Type type);
/// \}
};
} // end namespace Osd

View File

@ -69,10 +69,18 @@ static const char *gregoryTriangleShaderSource =
/*static*/
std::string
HLSLPatchShaderSource::GetCommonShaderSource() {
HLSLPatchShaderSource::GetPatchDrawingShaderSource() {
std::stringstream ss;
ss << std::string(commonShaderSource);
ss << std::string(commonTessShaderSource);
return ss.str();
}
/*static*/
std::string
HLSLPatchShaderSource::GetCommonShaderSource() {
std::stringstream ss;
ss << GetPatchDrawingShaderSource();
ss << std::string(patchLegacyShaderSource);
return ss.str();
}

View File

@ -26,25 +26,46 @@
#define OPENSUBDIV3_OSD_HLSL_PATCH_SHADER_SOURCE_H
#include "../version.h"
#include <string>
#include "../far/patchDescriptor.h"
#include <string>
namespace OpenSubdiv {
namespace OPENSUBDIV_VERSION {
namespace Osd {
/// \brief Provides shader source which can be used by client code.
class HLSLPatchShaderSource {
public:
static std::string GetCommonShaderSource();
/// \brief Returns shader source which can be used to evaluate
/// position and first and second derivatives on piecewise parametric
/// patches resulting from subdivision refinement.
static std::string GetPatchBasisShaderSource();
/// \brief Returns shader source which can be used while drawing
/// piecewise parametric patches resulting from subdivision refinement,
/// e.g. while using GPU HW tessellation.
static std::string GetPatchDrawingShaderSource();
/// \name Alternative methods
/// \{
/// These methods return shader source which can be used
/// while drawing. Unlike the methods above, the source returned
/// by these methods includes support for legacy patch types along
/// with dependencies on specific resource bindings and interstage
/// shader variable declarations.
static std::string GetCommonShaderSource();
static std::string GetVertexShaderSource(Far::PatchDescriptor::Type type);
static std::string GetHullShaderSource(Far::PatchDescriptor::Type type);
static std::string GetDomainShaderSource(Far::PatchDescriptor::Type type);
/// @}
};
} // end namespace Osd

View File

@ -26,7 +26,9 @@
#define OPENSUBDIV3_OSD_MTL_PATCH_SHADER_SOURCE_H
#import "../version.h"
#import "../far/patchDescriptor.h"
#import <string>
namespace OpenSubdiv {
@ -34,12 +36,29 @@ namespace OPENSUBDIV_VERSION {
namespace Osd {
/// \brief Provides shader source which can be used by client code.
class MTLPatchShaderSource {
public:
static std::string GetCommonShaderSource();
public:
/// \brief Returns shader source which can be used to evaluate
/// position and first and second derivatives on piecewise parametric
/// patches resulting from subdivision refinement.
static std::string GetPatchBasisShaderSource();
/// \brief Returns shader source which can be used while drawing
/// piecewise parametric patches resulting from subdivision refinement,
/// e.g. while using GPU HW tessellation.
static std::string GetPatchDrawingShaderSource();
/// \name Alternative methods
/// \{
/// These methods return shader source which can be used
/// while drawing. Unlike the methods above, the source returned
/// by these methods includes support for legacy patch types along
/// with dependencies on specific resource bindings and interstage
/// shader variable declarations.
static std::string GetCommonShaderSource();
static std::string GetVertexShaderSource(Far::PatchDescriptor::Type type);
static std::string GetHullShaderSource(Far::PatchDescriptor::Type type);
@ -59,6 +78,9 @@ class MTLPatchShaderSource {
static std::string GetDomainShaderSource(
Far::PatchDescriptor::Type type,
Far::PatchDescriptor::Type fvarType);
/// @}
};
} // end namespace Osd

View File

@ -147,20 +147,25 @@ GetPatchTypeSource(Far::PatchDescriptor::Type type) {
/*static*/
std::string
MTLPatchShaderSource::GetCommonShaderSource() {
MTLPatchShaderSource::GetPatchDrawingShaderSource() {
#if TARGET_OS_IOS || TARGET_OS_TV
return std::string("#define OSD_METAL_IOS 1\n")
.append(commonShaderSource)
.append(commonTessShaderSource)
.append(patchLegacyShaderSource);
.append(commonTessShaderSource);
#elif TARGET_OS_OSX
return std::string("#define OSD_METAL_OSX 1\n")
.append(commonShaderSource)
.append(commonTessShaderSource)
.append(patchLegacyShaderSource);
.append(commonTessShaderSource);
#endif
}
/*static*/
std::string
MTLPatchShaderSource::GetCommonShaderSource() {
return GetPatchDrawingShaderSource()
.append(patchLegacyShaderSource);
}
/*static*/
std::string
MTLPatchShaderSource::GetPatchBasisShaderSource() {