c

class RenderPlatform

Include: Platform/CrossPlatform/DeviceContext.h
Tells the renderer what to do with shader source to get binaries. values can be combined, e.g. ALWAYS_BUILD TRY_AGAIN_ON_FAIL

Functions

void ActivateRenderTargets(simul::crossplatform::DeviceContext deviceContext, int num, simul::crossplatform::Texture targs, simul::crossplatform::Texture depth)
ID3D12GraphicsCommandList * AsD3D12CommandList()
void BeginEvent(simul::crossplatform::DeviceContext deviceContext, char name)
void Clear(simul::crossplatform::DeviceContext deviceContext, vec4 colour_rgba)
void ClearTexture(simul::crossplatform::DeviceContext deviceContext, simul::crossplatform::Texture texture, vec4 colour)
simul::crossplatform::Buffer * CreateBuffer()
simul::crossplatform::Effect * CreateEffect(char filename_utf8)
simul::crossplatform::Effect * CreateEffect()
simul::crossplatform::Effect * CreateEffect(char filename_utf8, std::map defines)
simul::crossplatform::BaseFramebuffer * CreateFramebuffer(char)
simul::crossplatform::Layout * CreateLayout(int num_elements, simul::crossplatform::LayoutDesc layoutDesc)
simul::crossplatform::Mesh * CreateMesh()
simul::crossplatform::PlatformConstantBuffer * CreatePlatformConstantBuffer()
simul::crossplatform::PlatformStructuredBuffer * CreatePlatformStructuredBuffer()
simul::crossplatform::Query * CreateQuery(simul::crossplatform::QueryType q)
simul::crossplatform::RenderState * CreateRenderState(simul::crossplatform::RenderStateDesc desc)
simul::crossplatform::SamplerState * CreateSamplerState(simul::crossplatform::SamplerStateDesc)
simul::crossplatform::Shader * CreateShader()
simul::crossplatform::Texture * CreateTexture(char lFileNameUtf8)
void DispatchCompute(simul::crossplatform::DeviceContext deviceContext, int w, int l, int d)
void Draw(simul::crossplatform::DeviceContext deviceContext, int num_verts, int start_vert)
void DrawCircle(simul::crossplatform::DeviceContext deviceContext, float dir, float rads, float colr, bool fill)
void DrawCircle(simul::crossplatform::DeviceContext deviceContext, float pos, float dir, float radius, float colr, bool fill)
void DrawCubemap(simul::crossplatform::DeviceContext deviceContext, simul::crossplatform::Texture cubemap, float offsetx, float offsety, float size, float exposure, float gamma, float displayLod)
void DrawIndexed(simul::crossplatform::DeviceContext deviceContext, int num_indices, int start_index, int base_vertex)
void EndEvent(simul::crossplatform::DeviceContext)
void EnsureEffectIsBuilt(char filename_utf8, std::vector options)
simul::crossplatform::Shader * EnsureShader(char filenameUtf8, simul::crossplatform::ShaderType t)
void GenerateMips(simul::crossplatform::DeviceContext deviceContext, simul::crossplatform::Texture t, bool wrap, int array_idx)
simul::crossplatform::ContextState * GetContextState(simul::crossplatform::DeviceContext deviceContext)
simul::crossplatform::Effect * GetEffect(char name_utf8)
unsigned char GetIdx()
simul::crossplatform::DeviceContext & GetImmediateContext()
char const * GetName()
simul::crossplatform::Material * GetOrCreateMaterial(char name)
simul::crossplatform::SamplerState * GetOrCreateSamplerStateByName(char name_utf8, simul::crossplatform::SamplerStateDesc desc)
char const * GetShaderBinaryPath()
simul::crossplatform::ShaderBuildMode GetShaderBuildMode()
std::vector GetShaderPathsUtf8()
simul::crossplatform::Viewport GetViewport(simul::crossplatform::DeviceContext deviceContext, int index)
void InvalidateDeviceObjects()
void PopRenderTargets(simul::crossplatform::DeviceContext deviceContext)
void PopShaderPath()
void PopTexturePath()
void PushRenderTargets(simul::crossplatform::DeviceContext deviceContext, simul::crossplatform::TargetsAndViewport tv)
void PushShaderPath(char path_utf8)
void PushTexturePath(char pathUtf8)
void RecompileShaders()
void Resolve(simul::crossplatform::DeviceContext, simul::crossplatform::Texture, simul::crossplatform::Texture)
void ResourceTransition(simul::crossplatform::DeviceContext, simul::crossplatform::Texture, simul::crossplatform::ResourceTransition)
void RestoreDeviceObjects(void)
void RestoreRenderState(simul::crossplatform::DeviceContext)
void SaveTexture(simul::crossplatform::Texture, char)
void SetIndexBuffer(simul::crossplatform::DeviceContext deviceContext, simul::crossplatform::Buffer buffer)
void SetLayout(simul::crossplatform::DeviceContext deviceContext, simul::crossplatform::Layout l)
void SetRenderState(simul::crossplatform::DeviceContext deviceContext, simul::crossplatform::RenderState s)
void SetShaderBinaryPath(char path_utf8)
void SetShaderBuildMode(simul::crossplatform::ShaderBuildMode s)
void SetShaderPathsUtf8(std::vector pathsUtf8)
void SetStandardRenderState(simul::crossplatform::DeviceContext deviceContext, simul::crossplatform::StandardRenderState s)
void SetStreamOutTarget(simul::crossplatform::DeviceContext, simul::crossplatform::Buffer, int)
void SetTopology(simul::crossplatform::DeviceContext deviceContext, simul::crossplatform::Topology t)
void SetVertexBuffers(simul::crossplatform::DeviceContext deviceContext, int slot, int num_buffers, simul::crossplatform::Buffer buffers, simul::crossplatform::Layout layout, int vertexSteps)
void StoreRenderState(simul::crossplatform::DeviceContext)
void SynchronizeCacheAndState(simul::crossplatform::DeviceContext)
vec4 TexelQuery(simul::crossplatform::DeviceContext deviceContext, int query_id, uint2 pos, simul::crossplatform::Texture texture)
bool ApplyContextState(simul::crossplatform::DeviceContext, bool)
simul::crossplatform::Viewport PlatformGetViewport(simul::crossplatform::DeviceContext deviceContext, int index)
Tells the renderer what to do with shader source to get binaries. values can be combined, e.g. ALWAYS_BUILD TRY_AGAIN_ON_FAIL

Functions

void ActivateRenderTargets(simul::crossplatform::DeviceContext deviceContext, int num, simul::crossplatform::Texture targs, simul::crossplatform::Texture depth)

Make the specified rendertargets and optional depth target active.

ID3D12GraphicsCommandList * AsD3D12CommandList()

Returns the DX12 graphics command list

void BeginEvent(simul::crossplatform::DeviceContext deviceContext, char name)

For platforms that support named events, e.g. PIX in DirectX. Use BeginEvent(), EndEvent() as pairs.

void Clear(simul::crossplatform::DeviceContext deviceContext, vec4 colour_rgba)

Clear the current render target (i.e. the screen). In most API’s this is simply a case of drawing a full-screen quad in the specified rgba colour.

void ClearTexture(simul::crossplatform::DeviceContext deviceContext, simul::crossplatform::Texture texture, vec4 colour)

Clear the contents of the given texture to the specified colour

simul::crossplatform::Buffer * CreateBuffer()

Create a platform-specific buffer instance - e.g. vertex buffers, index buffers etc.

simul::crossplatform::Effect * CreateEffect(char filename_utf8)

Create a platform-specific effect instance.

simul::crossplatform::Effect * CreateEffect()

Create a platform-specific effect instance.

simul::crossplatform::Effect * CreateEffect(char filename_utf8, std::map defines)

Create a platform-specific effect instance.

simul::crossplatform::BaseFramebuffer * CreateFramebuffer(char)

Create a platform-specific framebuffer instance - i.e. an optional colour and an optional depth rendertarget. Optionally takes a name string.

simul::crossplatform::Layout * CreateLayout(int num_elements, simul::crossplatform::LayoutDesc layoutDesc)

Create a platform-specific layout instance based on the given layout description layoutDescand buffer buffer.

simul::crossplatform::Mesh * CreateMesh()

Create a platform-specific mesh instance.

simul::crossplatform::PlatformConstantBuffer * CreatePlatformConstantBuffer()

Create a platform-specific constant buffer instance. This is not usually used directly, instead, create a simul::crossplatform::ConstantBuffer, and pass this RenderPlatform’s pointer to it in RestoreDeviceObjects().

simul::crossplatform::PlatformStructuredBuffer * CreatePlatformStructuredBuffer()

Create a platform-specific structured buffer instance. This is not usually used directly, instead, create a simul::crossplatform::StructuredBuffer, and pass this RenderPlatform’s pointer to it in RestoreDeviceObjects().

simul::crossplatform::Query * CreateQuery(simul::crossplatform::QueryType q)

Create an API-specific query object, e.g. for occlusion or timing tests.

simul::crossplatform::RenderState * CreateRenderState(simul::crossplatform::RenderStateDesc desc)

Create a platform-specific RenderState object - e.g. a Blend state, Depth state, etc.

simul::crossplatform::SamplerState * CreateSamplerState(simul::crossplatform::SamplerStateDesc)

Create a platform-specific sampler state instance.

simul::crossplatform::Shader * CreateShader()

Create a shader.

simul::crossplatform::Texture * CreateTexture(char lFileNameUtf8)

Create a platform-specific texture instance.

void DispatchCompute(simul::crossplatform::DeviceContext deviceContext, int w, int l, int d)

Execute the currently applied compute shader.

void Draw(simul::crossplatform::DeviceContext deviceContext, int num_verts, int start_vert)

Draw the specified number of vertices.

void DrawCircle(simul::crossplatform::DeviceContext deviceContext, float dir, float rads, float colr, bool fill)

Draw a circle facing the viewer at the specified direction and angular size.

void DrawCircle(simul::crossplatform::DeviceContext deviceContext, float pos, float dir, float radius, float colr, bool fill)

Draw a circle in 3D space at pos

void DrawCubemap(simul::crossplatform::DeviceContext deviceContext, simul::crossplatform::Texture cubemap, float offsetx, float offsety, float size, float exposure, float gamma, float displayLod)

Draw a cubemap as a sphere at the specified screen position and size.

void DrawIndexed(simul::crossplatform::DeviceContext deviceContext, int num_indices, int start_index, int base_vertex)

Draw the specified number of vertices using the bound index arrays.

void EndEvent(simul::crossplatform::DeviceContext)

For platforms that support named events, e.g. PIX in DirectX. Use BeginEvent(), EndEvent() as pairs.

void EnsureEffectIsBuilt(char filename_utf8, std::vector options)

simul::crossplatform::Shader * EnsureShader(char filenameUtf8, simul::crossplatform::ShaderType t)

Get or create an API-specific shader object.

void GenerateMips(simul::crossplatform::DeviceContext deviceContext, simul::crossplatform::Texture t, bool wrap, int array_idx)

Fill in mipmaps from the zero level down.

simul::crossplatform::ContextState * GetContextState(simul::crossplatform::DeviceContext deviceContext)

Get the current state to be applied to the given context at the next draw or dispatch.

simul::crossplatform::Effect * GetEffect(char name_utf8)

Get the effect named, or return null if it’s not been created.

unsigned char GetIdx()

Returns the current idx (used in ring buffers)

simul::crossplatform::DeviceContext & GetImmediateContext()

Gets an object containing immediate-context API-specific values.

char const * GetName()

Returns the name of the render platform - DirectX 11, OpenGL, etc.

simul::crossplatform::Material * GetOrCreateMaterial(char name)

Create a platform-specific material instance.

simul::crossplatform::SamplerState * GetOrCreateSamplerStateByName(char name_utf8, simul::crossplatform::SamplerStateDesc desc)

Look for a sampler state of the stated name, and create one if it does not exist. The resulting state will be owned by the RenderPlatform, so do not destroy it. This is for states that will be shared by multiple shaders. There will be a warning if a description is passed that conflicts with the current definition, as the Effects system assumes that SamplerState names are unique.

char const * GetShaderBinaryPath()

Returns the path where generated shader binaries should be saved, and where stored shader binaries should be loaded from.

simul::crossplatform::ShaderBuildMode GetShaderBuildMode()

When shaders should be built, or loaded if available.

std::vector GetShaderPathsUtf8()

Returns the stack of shader source paths.

simul::crossplatform::Viewport GetViewport(simul::crossplatform::DeviceContext deviceContext, int index)

Get the viewport at the given index.

void InvalidateDeviceObjects()

Call this once, when the 3d graphics device object is being shut down.

void PopRenderTargets(simul::crossplatform::DeviceContext deviceContext)

Restore rendertargets and viewports from the top of the stack.

void PopShaderPath()

Remove a path from the top of the shader source path stack.

void PopTexturePath()

Remove a path from the top of the texture path stack.

void PushRenderTargets(simul::crossplatform::DeviceContext deviceContext, simul::crossplatform::TargetsAndViewport tv)

Store the current rendertargets and viewports at the top of the stack

void PushShaderPath(char path_utf8)

Push the given file path onto the shader path stack.

void PushTexturePath(char pathUtf8)

Push the given file path onto the texture path stack.

void RecompileShaders()

Optional - call this to recompile the standard shaders.

void Resolve(simul::crossplatform::DeviceContext, simul::crossplatform::Texture, simul::crossplatform::Texture)

Resolve an MSAA texture to a normal texture.

void ResourceTransition(simul::crossplatform::DeviceContext, simul::crossplatform::Texture, simul::crossplatform::ResourceTransition)

Makes sure the resource is in the required state specified by transition.

void RestoreDeviceObjects(void)

Call this once, when the 3D graphics device has been initialized, and pass the API-specific device pointer/identifier.

void RestoreRenderState(simul::crossplatform::DeviceContext)

Called to restore the render state previously stored with StoreRenderState. There must be exactly one call of RestoreRenderState for each StoreRenderState call, and they are not expected to be nested.

void SaveTexture(simul::crossplatform::Texture, char)

Save a texture to disk.

void SetIndexBuffer(simul::crossplatform::DeviceContext deviceContext, simul::crossplatform::Buffer buffer)

Activate the specified index buffer in preparation for rendering.

void SetLayout(simul::crossplatform::DeviceContext deviceContext, simul::crossplatform::Layout l)

Set the layout for following draw calls - format of the vertex buffer.

void SetRenderState(simul::crossplatform::DeviceContext deviceContext, simul::crossplatform::RenderState s)

Apply the RenderState to the device context - e.g. blend state, depth masking etc.

void SetShaderBinaryPath(char path_utf8)

Set the path where generated shader binaries should be saved, and where stored shader binaries should be loaded from.

void SetShaderBuildMode(simul::crossplatform::ShaderBuildMode s)

When shaders should be built, or loaded if available.

void SetShaderPathsUtf8(std::vector pathsUtf8)

Replace the entire stack of shader source paths.

void SetStandardRenderState(simul::crossplatform::DeviceContext deviceContext, simul::crossplatform::StandardRenderState s)

Apply a standard renderstate - e.g. opaque blending

void SetStreamOutTarget(simul::crossplatform::DeviceContext, simul::crossplatform::Buffer, int)

Graphics hardware can write to vertex buffers using vertex and geometry shaders; use this function to set the target buffer.

void SetTopology(simul::crossplatform::DeviceContext deviceContext, simul::crossplatform::Topology t)

Set the topology for following draw calls, e.g. TRIANGLELIST etc.

void SetVertexBuffers(simul::crossplatform::DeviceContext deviceContext, int slot, int num_buffers, simul::crossplatform::Buffer buffers, simul::crossplatform::Layout layout, int vertexSteps)

Activate the specifided vertex buffers in preparation for rendering.

void StoreRenderState(simul::crossplatform::DeviceContext)

Called to store the render state - blending, depth check, etc. - for later retrieval with RestoreRenderState. Some platforms may not support this.

void SynchronizeCacheAndState(simul::crossplatform::DeviceContext)

Implementations of RenderPlatform will cache the API state in order to reduce driver overhead. But we can’t always be sure that external render code hasn’t modified the API state. So by calling SynchronizeCacheAndState() the API state is forced to the cached state. This can be called at the start of Renderplatform’s rendering per-frame.

vec4 TexelQuery(simul::crossplatform::DeviceContext deviceContext, int query_id, uint2 pos, simul::crossplatform::Texture texture)

Query for the texture value at the specified position in the texture. On most API’s, the query will have a few frames’ latency.

bool ApplyContextState(simul::crossplatform::DeviceContext, bool)

This is called by draw functions to do any lazy updating prior to the actual API draw/dispatch call.

simul::crossplatform::Viewport PlatformGetViewport(simul::crossplatform::DeviceContext deviceContext, int index)

RenderPlatform is an interface that allows Simul’s rendering functions to be developed in a cross-platform manner. By abstracting the common functionality of the different graphics API’s into an interface, we can write render code that need not know which API is being used. It is possible to create platform-specific objects like /link CreateTexture textures/endlink, /link CreateEffect effects/endlink and /link CreateBuffer buffers/endlink

Be sure to make the following calls at the appropriate places: RestoreDeviceObjects(), InvalidateDeviceObjects(), RecompileShaders()

Fields

Variables

mirrorY This was introduced because Unity’s deferred renderer flips the image vertically sometime after we render.

mCurIdx Value used to select the current heap, it will be looping around: [0,kNumIdx)

mLastFrame Last frame number