Render State Overrides

namespace shaders

Typedefs

typedef GenerationRefId<8, OverrideStateIdDummy> OverrideStateId

A type used to identify override state.

class OverrideStateIdDummy
#include <dag_overrideStateId.h>

A helper class used to declare OverrideStateId type.

struct UniqueOverrideStateId
#include <dag_overrideStateId.h>

A unique handle to the override state.

It will destroy the referenced override state id in the destructor.

Public Functions

inline ~UniqueOverrideStateId()

Destructor.

It will destroy the referenced override state id.

UniqueOverrideStateId() = default

Default constructor.

It creates an empty handle.

inline UniqueOverrideStateId(const OverrideStateId &id)

Constructor with the override state id.

It creates a handle with the given override state id.

Parameters:

id – The override state id.

inline UniqueOverrideStateId &operator=(OverrideStateId id)

Assignment operator.

It destroys the current override state id and sets the new one.

Parameters:

id – The override state id.

Returns:

Reference to this object.

inline bool reset(OverrideStateId id = OverrideStateId())

Reset the handle with the new override state id.

It destroys the current override state id and sets the new one.

Parameters:

id – The override state id.

Returns:

true if the override state was reset, false otherwise.

inline const OverrideStateId &get() const

Get the override state id.

Returns:

The override state id.

inline OverrideStateId &get()

Get the override state id.

Returns:

The override state id.

inline UniqueOverrideStateId(UniqueOverrideStateId &&id)

Move constructor.

It moves the override state id from the given handle. The given handle will be empty after the move.

Parameters:

id – The handle to move.

inline UniqueOverrideStateId &operator=(UniqueOverrideStateId &&id)

Move assignment operator.

It moves the override state id from the given handle. The given handle will be empty after the move.

Parameters:

id – The handle to move.

Returns:

Reference to this object.

UniqueOverrideStateId(const UniqueOverrideStateId &id) = delete

Copy constructor.

It is deleted because UniqueOverrideStateId owns the state id exclusivelly.

Parameters:

id – The handle to copy.

UniqueOverrideStateId &operator=(const UniqueOverrideStateId &id) = delete

Copy assignment operator.

It is deleted because UniqueOverrideStateId owns the state id exclusivelly.

Parameters:

id – The handle to copy.

Returns:

Reference to this object.

inline explicit operator bool() const

Check if the handle is valid.

Returns:

true if the handle is valid, false otherwise.

Protected Attributes

OverrideStateId ref

The override state id owned by the class.

namespace overrides

Functions

OverrideStateId create(const OverrideState&)

Create a new override state.

Parameters:

s – The override state description.

Returns:

A handle to the created override state.

bool destroy(OverrideStateId &override_id)

Destroy an override state.

Parameters:

override_id – The handle to the override state to destroy.

Returns:

true if the override state was destroyed, false otherwise (state id wasn’t found).

bool exists(OverrideStateId override_id)

Check if an override state exists.

Parameters:

override_id – The handle to the override state to check.

Returns:

true if the override state exists, false otherwise.

bool set(OverrideStateId override_id)

set current override. It will fail, if there is already one set, and override_id is not invalid.

Set the current override state.

If there is already an override state set, this function will fail. The user will be notified with a logerr message. If the override_id is invalid, the current override state will be reset. The user will be notified with a logerr message. The method invalidates the cached state block.

Parameters:

override_id – The handle to the override state to set.

Returns:

true if the override state was set, false otherwise.

inline bool reset()

Reset the current override state. It sets the override state that doesn’t have any effect.

The method invalidates the cached state block.

Returns:

true if the override state was reset, false otherwise.

OverrideState get(OverrideStateId override_id)

Get the override state description.

Parameters:

override_id – The handle to the override state to get.

Returns:

The override state description.

OverrideStateId get_current()

Get the current override state.

Returns:

The handle to the current override state.

OverrideStateId get_current_with_master()

Get the current override state with the master override state applied.

The master override is applied to all the render states.

Returns:

The handle to the current override state with the master override state applied.

void set_master_state(const OverrideState &s)

Set the master override state.

The master override state is applied to all the render states.

Parameters:

s – The master override state description.

void reset_master_state()

Reset the master override state.

void destroy_all_managed_master_states()

Destroy all managed master override states.

inline bool destroy(UniqueOverrideStateId &id)

Destroy the unique override state id.

It makes the handle empty, so the override state doesn’t have any effect.

Parameters:

id – The unique override state id to destroy.

inline void set(UniqueOverrideStateId &id)

Set the override state.

It sets the override state to the current state.

Parameters:

id – The unique override state id to set.

inline void set(const UniqueOverrideStateId &id)

Set the override state.

It sets the override state to the current state.

Parameters:

id – The unique override state id to set.

inline bool exists(UniqueOverrideStateId id)

Check if the override state exists.

Parameters:

id – The unique override state id to check.

Returns:

true if the override state exists, false otherwise.

OverrideState get(const UniqueOverrideStateId &id)

Get the override state description.

Parameters:

id – The unique override state id to get.

Returns:

The override state description.

namespace shaders

Functions

void set_stencil_ref(uint8_t ref)

Set reference value for stencil operations.

Todo:

In the moment, we use this instead of absent d3d::set_stencil_ref. To be replaced

Parameters:

ref – Reference value to set.

struct OverrideState
#include <dag_overrideStates.h>

A structure that describes current override for a render state.

It is used to override some render state parameters.

Public Types

enum StateBits

Bit flags that describe which parameters are overridden.

Values:

enumerator Z_TEST_DISABLE

Disable depth test.

enumerator Z_WRITE_DISABLE

Disable depth write. Can’t be used with Z_WRITE_ENABLE.

enumerator Z_BOUNDS_ENABLED

Enable depth bounds test. Check hasDepthBoundsTest driver cap to see if it is supported.

enumerator Z_CLAMP_ENABLED

Enable depth clamp.

enumerator Z_FUNC

Override depth comparison function.

enumerator Z_BIAS

Override depth bias or/and slope depth bias. See zBias and slopeZBias.

enumerator STENCIL

Override the whole stencil state.

enumerator BLEND_OP

Override blend operation.

enumerator BLEND_OP_A

Override alpha blend operation.

enumerator BLEND_SRC_DEST

Override source and destination blend factors.

enumerator BLEND_SRC_DEST_A

Override source and destination alpha blend factors.

enumerator CULL_NONE

Disables any face culling even if FLIP_CULL is used.

enumerator FLIP_CULL

Flip culling mode.

enumerator FORCED_SAMPLE_COUNT

Override forced sample count. Check hasForcedSamplerCount and hasUAVOnlyForcedSampleCount driver caps to see if it is supported. Doesn’t have any effect if forcedSampleCount is 0.

enumerator CONSERVATIVE

Enable conservative rasterization. Check hasConservativeRassterization driver cap to see if it is supported.

enumerator SCISSOR_ENABLED

Enable scissor test.

enumerator ALPHA_TO_COVERAGE

Enable alpha-to-coverage.

enumerator Z_WRITE_ENABLE

Enable depth write. Can’t be used with Z_WRITE_DISABLE. It doesn’t have any effect if FORCED_SAMPLE_COUNT is enabled.

Public Functions

inline bool isOn(uint32_t mask) const

Check if any of the given features (bitset) is set. Use it to check only a single feature.

Parameters:

mask – Bitset to check.

Returns:

true if any of the given features is set.

inline void set(uint32_t mask)

Set the given features (bitset).

Parameters:

mask – Bitset to set.

inline void reset(uint32_t mask)

Reset the given features (bitset).

Parameters:

mask – Bitset to reset.

inline OverrideState()

Default constructor.

None of the features are set. Color write mask is set to 0xFFFFFFFF, so it doesn’t have any effect.

inline OverrideState(const OverrideState &a)

Copy constructor.

Since it’s a POD class, it’s safe to use memcpy.

Parameters:

a – The object to copy.

inline OverrideState &operator=(const OverrideState &a)

Assignment operator.

Since it’s a POD class, it’s safe to use memcpy.

Parameters:

a – The object to copy.

Returns:

Reference to this object.

inline bool operator==(const OverrideState &s) const

Compare two objects.

Warning

zBias and slopeZBias are float values, so be careful with the operator because it compares override states bitwise.

Parameters:

s – The object to compare.

Returns:

true if the objects are equal.

inline bool operator!=(const OverrideState &s) const

Compare two objects.

Warning

zBias and slopeZBias are float values, so be careful with the operator because it compares override states bitwise.

Parameters:

s – The object to compare.

Returns:

true if the objects are not equal.

inline void validate()

Validate the object.

If some features are not set, it sets the corresponding values to 0. Overrides for zBias, slopeZBias, forcedSampleCount, zFunc, blendOp, and stencil are set to 0 if corresponding bits are not set.

Todo:

Rename the method since it doesn’t validate the object, but moves the object to a valid state.

Public Members

uint32_t bits = 0

Bit flags that describe which parameters are overridden.

uint8_t zFunc

Overridden depth function value.

Todo:

zFunc can be 3 bits

uint8_t forcedSampleCount

Overridden forced sample count.

uint8_t blendOp = 0

Overridden blend operation.

Todo:

blendOp can be 3 bits

uint8_t blendOpA = 0

Overridden alpha blend operation.

Todo:

blendOpA can be 3 bits

uint8_t sblend = 0

Overridden source blend factor.

uint8_t dblend = 0

Overridden destination blend factor.

uint8_t sblenda = 0

Overridden source alpha blend factor.

uint8_t dblenda = 0

Overridden destination alpha blend factor.

uint32_t colorWr = 0xFFFFFFFF

Overridden color write mask. It is always &= with the color write mask of the current render state.

StencilState stencil

Overridden stencil state.

float zBias = 0

Overridden depth bias value.

float slopeZBias = 0

Overridden slope depth bias value.

struct StencilState
#include <dag_overrideStates.h>

A structure that describes current stencil state.

Public Functions

inline StencilState()

Default constructor.

inline StencilState(uint8_t stencil_func, uint8_t stencil_fail, uint8_t z_fail, uint8_t stencil_z_pass, uint8_t write_mask, uint8_t read_mask)

Constructor with all parameters. It just calls set() method.

Warning

stencil_func, stencil_fail, z_fail, stencil_z_pass must be non-zero.

Parameters:
  • stencil_func – Comparison function CMPF_*.

  • stencil_fail – Stencil operation STNCLOP_* for failed stencil test.

  • z_fail – Stencil operation STNCLOP_* for passed stencil test and failed depth test.

  • stencil_z_pass – Stencil operation STNCLOP_* for passed stencil and depth tests.

  • write_mask – Identify a portion of the depth-stencil buffer for writing stencil data.

  • read_mask – Identify a portion of the depth-stencil buffer for reading stencil data.

inline void set(uint8_t stencil_func, uint8_t stencil_fail, uint8_t z_fail, uint8_t stencil_z_pass, uint8_t write_mask, uint8_t read_mask)

Set all parameters.

Warning

stencil_func, stencil_fail, z_fail, stencil_z_pass must be non-zero.

Parameters:
  • stencil_func – Comparison function CMPF_*.

  • stencil_fail – Stencil operation STNCLOP_* for failed stencil test.

  • z_fail – Stencil operation STNCLOP_* for passed stencil test and failed depth test.

  • stencil_z_pass – Stencil operation STNCLOP_* for passed stencil and depth tests.

  • write_mask – Identify a portion of the depth-stencil buffer for writing stencil data.

  • read_mask – Identify a portion of the depth-stencil buffer for reading stencil data.

Public Members

uint8_t func

Comparison function CMPF_*.

uint8_t fail

Stencil operation STNCLOP_* for failed stencil test.

uint8_t zFail

Stencil operation STNCLOP_* for passed stencil test and failed depth test.

uint8_t pass

Stencil operation STNCLOP_* for passed stencil and depth tests.

uint8_t readMask = 255

Identify a portion of the depth-stencil buffer for reading stencil data.

uint8_t writeMask = 255

Identify a portion of the depth-stencil buffer for writing stencil data.