Skip to content

Commit

Permalink
More feedback implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
colincornaby committed Nov 5, 2023
1 parent 55ff113 commit 2e01bf9
Show file tree
Hide file tree
Showing 15 changed files with 89 additions and 72 deletions.
1 change: 0 additions & 1 deletion Sources/Plasma/FeatureLib/pfMetalPipeline/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ include(FetchContent)

FetchContent_Declare(
metalcpp
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
URL_HASH_SHA256 0afd87ca851465191ae4e3980aa036c7e9e02fe32e7c760ac1a74244aae6023b
URL "https://developer.apple.com/metal/cpp/files/metal-cpp_macOS13.3_iOS16.4.zip"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,9 +403,9 @@ half4 FragmentShaderArguments::sampleLayer(const size_t index, const half4 verte
}

// do the actual sample
if(passType == PassTypeTexture) {
if (passType == PassTypeTexture) {
return (&textures)[index].sample((&samplers)[index], sampleCoord.xy);
} else if(passType == PassTypeCubicTexture) {
} else if (passType == PassTypeCubicTexture) {
return (&cubicTextures)[index].sample((&samplers)[index], sampleCoord.xyz);
} else {
return half4(0);
Expand Down
23 changes: 23 additions & 0 deletions Sources/Plasma/FeatureLib/pfMetalPipeline/ShaderSrc/ShaderTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ You can contact Cyan Worlds, Inc. by email [email protected]
#include <simd/simd.h>

#ifndef __METAL_VERSION__
#include <type_traits>

typedef _Float16 half;
typedef __attribute__((__ext_vector_type__(2))) half half2;
typedef __attribute__((__ext_vector_type__(3))) half half3;
Expand Down Expand Up @@ -120,10 +122,16 @@ enum plMetalLayerPassType: uint8_t
struct plMetalFragmentShaderArgumentBuffer {
__fp16 alphaThreshold;
};
#ifndef __METAL_VERSION__
static_assert(std::is_trivial_v<plMetalFragmentShaderArgumentBuffer>, "plMetalFragmentShaderArgumentBuffer must be a trivial type!");
#endif

struct plMetalShadowCastFragmentShaderArgumentBuffer {
bool pointLightCast;
};
#ifndef __METAL_VERSION__
static_assert(std::is_trivial_v<plMetalShadowCastFragmentShaderArgumentBuffer>, "plMetalShadowCastFragmentShaderArgumentBuffer must be a trivial type!");
#endif

enum plMetalFragmentShaderTextures {
FragmentShaderArgumentAttributeTextures = 0,
Expand All @@ -143,12 +151,18 @@ struct plMetalShaderLightSource {
__fp16 quadAtten;
__fp16 scale;
};
#ifndef __METAL_VERSION__
static_assert(std::is_trivial_v<plMetalShaderLightSource>, "plMetalShaderLightSource must be a trivial type!");
#endif

typedef struct
{
uint32_t UVWSrc;
matrix_float4x4 transform;
} UVOutDescriptor;
#ifndef __METAL_VERSION__
static_assert(std::is_trivial_v<UVOutDescriptor>, "UVOutDescriptor must be a trivial type!");
#endif

typedef struct
{
Expand Down Expand Up @@ -180,13 +194,19 @@ typedef struct
half4 calcFog(float4 camPosition) constant;
#endif
} VertexUniforms;
#ifndef __METAL_VERSION__
static_assert(std::is_trivial_v<VertexUniforms>, "VertexUniforms must be a trivial type!");
#endif

#define kMetalMaxLightCount 32

typedef struct {
uint8_t count;
plMetalShaderLightSource lampSources[kMetalMaxLightCount];
} plMetalLights;
#ifndef __METAL_VERSION__
static_assert(std::is_trivial_v<plMetalLights>, "plMetalLights must be a trivial type!");
#endif

typedef struct {
simd::float3 lightPosition;
Expand All @@ -195,6 +215,9 @@ typedef struct {
float power;
half opacity;
} plShadowState;
#ifndef __METAL_VERSION__
static_assert(std::is_trivial_v<plShadowState>, "plShadowState must be a trivial type!");
#endif

#endif /* ShaderTypes_h */

6 changes: 3 additions & 3 deletions Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ void plMetalDevice::FillVertexBufferRef(VertexBufferRef* ref, plGBufferGroup* gr
const uint32_t size = group->GetVertBufferEnd(idx) * vertSize - vertStart;

if (ref->GetBuffer()) {
assert(size <= ref->GetBuffer()->length());
hsAssert(size <= ref->GetBuffer()->length(), "Allocated buffer does not fit fill data");
}

if (!size) {
Expand Down Expand Up @@ -1169,7 +1169,7 @@ void plMetalDevice::SubmitCommandBuffer()
fClearDrawableDepth = 1.0;
}

MTL::SamplerState* plMetalDevice::SampleStateForClampFlags(hsGMatState::hsGMatClampFlags sampleState)
MTL::SamplerState* plMetalDevice::SampleStateForClampFlags(hsGMatState::hsGMatClampFlags sampleState) const
{
return fSamplerStates[sampleState];
}
Expand Down Expand Up @@ -1256,7 +1256,7 @@ MTL::RenderCommandEncoder* plMetalDevice::CurrentRenderCommandEncoder()
return fCurrentRenderTargetCommandEncoder;
}

CA::MetalDrawable* plMetalDevice::GetCurrentDrawable()
CA::MetalDrawable* plMetalDevice::GetCurrentDrawable() const
{
return fCurrentDrawable;
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,15 @@ class plMetalDevice
// Currently requires a CA drawable and not a Metal drawable. In since CA drawable is only abstract implementation I know about, not sure where we would find others?
void CreateNewCommandBuffer(CA::MetalDrawable* drawable);
MTL::CommandBuffer* GetCurrentCommandBuffer();
CA::MetalDrawable* GetCurrentDrawable();
CA::MetalDrawable* GetCurrentDrawable() const;
/// Submit the command buffer to the GPU and draws all the render passes. Clears the current command buffer.
void SubmitCommandBuffer();
void Clear(bool shouldClearColor, simd_float4 clearColor, bool shouldClearDepth, float clearDepth);

void SetMaxAnsiotropy(uint8_t maxAnsiotropy);
void SetMSAASampleCount(uint8_t sampleCount);

MTL::SamplerState* SampleStateForClampFlags(hsGMatState::hsGMatClampFlags sampleState);
MTL::SamplerState* SampleStateForClampFlags(hsGMatState::hsGMatClampFlags sampleState) const;

NS::UInteger CurrentTargetSampleCount()
{
Expand Down
10 changes: 5 additions & 5 deletions Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalDeviceRef.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ class plMetalDeviceRef : public hsGDeviceRef
public:
void Unlink();
void Link(plMetalDeviceRef** back);
plMetalDeviceRef* GetNext() { return fNext; }
bool IsLinked() { return fBack != nullptr; }
plMetalDeviceRef* GetNext() const { return fNext; }
bool IsLinked() { return fBack != nullptr; } const

bool HasFlag(uint32_t f) const { return 0 != (fFlags & f); }
void SetFlag(uint32_t f, bool on)
Expand Down Expand Up @@ -212,7 +212,7 @@ class plMetalVertexBufferRef : public plMetalBufferPoolRef
virtual ~plMetalVertexBufferRef();

void Link(plMetalVertexBufferRef** back) { plMetalDeviceRef::Link((plMetalDeviceRef**)back); }
plMetalVertexBufferRef* GetNext() const { return (plMetalVertexBufferRef*)fNext; }
plMetalVertexBufferRef* const GetNext() const { return (plMetalVertexBufferRef*)fNext; }

void Release() override;
};
Expand Down Expand Up @@ -244,7 +244,7 @@ class plMetalIndexBufferRef : public plMetalBufferPoolRef
void Release() override;

void Link(plMetalIndexBufferRef** back) { plMetalDeviceRef::Link((plMetalDeviceRef**)back); }
plMetalIndexBufferRef* GetNext() { return (plMetalIndexBufferRef*)fNext; }
plMetalIndexBufferRef* const GetNext() { return (plMetalIndexBufferRef*)fNext; }
virtual ~plMetalIndexBufferRef();

plMetalIndexBufferRef() : plMetalBufferPoolRef(),
Expand Down Expand Up @@ -287,7 +287,7 @@ class plMetalRenderTargetRef : public plMetalTextureRef
MTL::Texture* fDepthBuffer;

void Link(plMetalRenderTargetRef** back) { plMetalDeviceRef::Link((plMetalDeviceRef**)back); }
plMetalRenderTargetRef* GetNext() { return (plMetalRenderTargetRef*)fNext; }
plMetalRenderTargetRef* GetNext() const { return (plMetalRenderTargetRef*)fNext; }

plMetalRenderTargetRef() : fDepthBuffer(nullptr)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,22 @@ class plLayerInterface;
class plMetalMaterialShaderRef : public plMetalDeviceRef
{
protected:
plMetalPipeline *fPipeline;
hsGMaterial *fMaterial;
plMetalPipeline* fPipeline;
hsGMaterial* fMaterial;
// temporary holder for the fragment shader to use, we don't own this reference
MTL::Function *fFragFunction;
MTL::Function* fFragFunction;

private:
std::vector<uint32_t> fPassIndices;
// FIXME: This should be retained/released
MTL::Device *fDevice;
std::vector<MTL::Buffer *> fPassArgumentBuffers;
MTL::Device* fDevice;
std::vector<MTL::Buffer*> fPassArgumentBuffers;

public:
void Link(plMetalMaterialShaderRef **back) { plMetalDeviceRef::Link((plMetalDeviceRef **)back); }
plMetalMaterialShaderRef* GetNext() const { return (plMetalMaterialShaderRef *)fNext; }
plMetalMaterialShaderRef* GetNext() const { return (plMetalMaterialShaderRef*)fNext; }

plMetalMaterialShaderRef(hsGMaterial *mat, plMetalPipeline *pipe);
plMetalMaterialShaderRef(hsGMaterial* mat, plMetalPipeline* pipe);
~plMetalMaterialShaderRef();

void Release() override;
Expand Down Expand Up @@ -116,7 +116,7 @@ class plMetalMaterialShaderRef : public plMetalDeviceRef
std::vector<plLayerInterface*>* piggybacks,
const std::function<plLayerInterface* (plLayerInterface*, uint32_t)>& preEncodeTransform,
const std::function<plLayerInterface* (plLayerInterface*, uint32_t)>& postEncodeTransform);
bool ICanEatLayer(plLayerInterface *lay);
bool ICanEatLayer(plLayerInterface* lay);
uint32_t ILayersAtOnce(uint32_t which);

void IBuildLayerTexture(MTL::RenderCommandEncoder* encoder, uint32_t offsetFromRootLayer, plLayerInterface* layer);
Expand Down
Loading

0 comments on commit 2e01bf9

Please sign in to comment.