31#include <rhi_shaders.h>
56 desc.
bytecode = useSource ?
reinterpret_cast<const uint8_t*
>( aBlob.msl ) : aBlob.spirv;
57 desc.
sizeBytes = useSource ? aBlob.mslSize : aBlob.spirvSize;
58 return m_device.CreateShader( desc );
67 bool aHasInstanceBinding,
73 if( !aShaders.
vert || !aShaders.
frag )
82 if( aHasInstanceBinding )
102 else if( aNegativeBlend )
130 if( aSingleCoverage )
150 if( glyphs && pipeline )
167 if( pipeline == aPipeline )
179 if( pipeline == aPipeline )
188 const ShaderPair& aShaders,
bool aBlendEnabled,
189 const std::vector<RHI_BIND_GROUP_LAYOUT_DESC>& aBindGroupLayouts,
190 bool aPremultipliedAlpha,
bool aRenderPassHasDepthStencil,
bool aSquareAlpha )
192 if( !aShaders.
vert || !aShaders.
frag )
226 for(
const auto& bgl : aBindGroupLayouts )
232 return m_device.CreatePipeline( desc );
243 uboLayoutDesc.
entries.push_back(
270 const SHADER_DEF shaderDefs[] = {
271 { k_pcb_track_vert, k_pcb_track_frag },
272 { k_pcb_pad_vert, k_pcb_pad_frag },
273 { k_pcb_arc_vert, k_pcb_arc_frag },
274 { k_pcb_zone_vert, k_pcb_zone_frag },
275 { k_sch_wire_vert, k_sch_wire_frag },
277 { k_cursor_vert, k_grid_frag },
278 { k_cursor_vert, k_cursor_frag },
279 { k_compositor_vert, k_compositor_frag },
280 { k_bitmap_vert, k_bitmap_frag },
281 { k_compositor_vert, k_compositor_difference_frag },
284 constexpr size_t SHADER_COUNT = std::size( shaderDefs );
288 for(
size_t i = 0; i < SHADER_COUNT; i++ )
301 if( aPipeline && aVariant )
304 m_device.DestroyPipeline( aVariant );
308 bool aSingleCoverage )
313 if( aPipeline && variant )
316 m_device.DestroyPipeline( variant );
347 addOverlayVariants( pipelines[
static_cast<int>( BLEND )], pipelines[
static_cast<int>( ONCE )], shaders,
352 addPremultipliedVariant( pipelines[
static_cast<int>( BLEND )], shaders,
false );
353 addPremultipliedVariant( pipelines[
static_cast<int>( ONCE )], shaders,
true );
364 fsUboLayoutDesc.
entries.push_back(
371 fprintf( stderr,
"RHI: fullscreen UBO layout creation FAILED\n" );
380 fprintf( stderr,
"RHI: grid pipeline creation FAILED\n" );
387 texLayoutDesc.entries.push_back(
394 fprintf( stderr,
"RHI: texture sampler layout creation FAILED\n" );
403 { texLayoutDesc },
true, true );
411 m_device.DestroyPipeline( variant );
415 differenceLayoutDesc.
entries.push_back(
428 fprintf( stderr,
"RHI: difference pipeline creation FAILED\n" );
435 if( bmpShaders.
vert && bmpShaders.
frag )
471 fprintf( stderr,
"RHI: bitmap pipeline creation FAILED\n" );
486 for(
int mode = 0; mode <
DRAW_MODES; ++mode )
Creates, uses and destroys GPU resources through one graphics API backend.
RHI_BindGroupLayoutHandle m_differenceLayout
bool Initialize()
Create all shader modules and pipeline objects.
ShaderPair loadShaderPair(const RHI_SHADER_BLOB &aVert, const RHI_SHADER_BLOB &aFrag)
RHI_BindGroupLayoutHandle m_textureSamplerLayout
RHI_BindGroupLayoutHandle m_fullscreenUBOLayout
RHI_PipelineHandle m_compositorPipeline
RHI_GAL_PIPELINES(RHI_DEVICE &aDevice)
std::vector< std::pair< RHI_PipelineHandle, RHI_PipelineHandle > > m_premultipliedVariants
RHI_BindGroupLayoutHandle m_frameUBOLayout
RHI_PipelineHandle m_gridPipeline
RHI_PipelineHandle m_bitmapPipeline
std::vector< ShaderPair > m_shaderPairs
Shader modules kept alive for the lifetime of the pipelines.
RHI_PipelineHandle GetPremultipliedVariant(RHI_PipelineHandle aPipeline) const
The variant of a pipeline for a cached layer that the legacy canvas draws on its overlay.
static constexpr int DRAW_MODES
void Destroy()
Release all GPU resources.
RHI_BIND_GROUP_LAYOUT_DESC m_glyphLayoutDesc
std::vector< RHI_PipelineHandle > m_glyphPipelines
RHI_BIND_GROUP_LAYOUT_DESC m_frameUBOLayoutDesc
RHI_PipelineHandle GetOverlayVariant(RHI_PipelineHandle aPipeline) const
The variant of a pipeline for content drawn into the overlay target.
RHI_BindGroupLayoutHandle m_glyphLayout
std::array< std::array< RHI_PipelineHandle, DRAW_MODES >, KIGFX::RHI_SHAPES > m_shapePipelines
RHI_PipelineHandle m_wirePipeline
RHI_PipelineHandle m_differencePipeline
bool UsesGlyphAtlas(RHI_PipelineHandle aPipeline) const
True for a pipeline that expects the glyph bind group at set 1.
RHI_PipelineHandle createInstancedPipeline(const ShaderPair &aShaders, bool aNegativeBlend=false, bool aHasInstanceBinding=true, bool aSingleCoverage=false, bool aKnockoutMark=false, bool aSquareAlpha=false, bool aPremultiplied=false)
Build a pipeline reading RHI_VERTEX from slot 0 and, with aHasInstanceBinding, RHI_INSTANCE from slot...
RHI_PipelineHandle m_inlineCompositorPipeline
RHI_PipelineHandle createFullscreenPipeline(const ShaderPair &aShaders, bool aBlendEnabled, const std::vector< RHI_BIND_GROUP_LAYOUT_DESC > &aBindGroupLayouts={}, bool aPremultipliedAlpha=false, bool aRenderPassHasDepthStencil=false, bool aSquareAlpha=false)
RHI_PipelineHandle m_wireOncePipeline
std::vector< std::pair< RHI_PipelineHandle, RHI_PipelineHandle > > m_overlayVariants
Each pipeline that has an overlay variant, paired with it.
RHI_PipelineHandle m_cursorCompositePipeline
@ MARK
write depth only, so the layer's later draws stay out of these pixels
@ ALL
Graphics stages only, compute is opted into explicitly.
constexpr uint32_t RHI_UBO_BINDING
MSL is generated with –msl-decoration-binding, so a Metal buffer index is its binding number in every...
@ COMBINED_TEXTURE_SAMPLER
constexpr uint32_t RHI_GLYPH_TABLE_BINDING
Binding of the glyph table beside the atlas texture at 0, see RHI_UBO_BINDING.
RHI_HANDLE< RHI_TAG_PIPELINE > RHI_PipelineHandle
RHI_HANDLE< RHI_TAG_BIND_GROUP_LAYOUT > RHI_BindGroupLayoutHandle
RHI_VERTEX_BUFFER_LAYOUT_DESC RhiInstanceLayout()
Per-instance vertex layout of RHI_INSTANCE, starting at location 3 after the RHI_VERTEX attributes.
RHI_VERTEX_BUFFER_LAYOUT_DESC RhiStandardVertexLayout()
Shaders read position at location 0, color at 1 and texture coordinates at 2.
std::vector< RHI_BINDING_ENTRY > entries
RHI_BIND_FREQUENCY frequency
RHI_BLEND_FACTOR dstAlpha
RHI_BLEND_FACTOR srcColor
RHI_BLEND_FACTOR dstColor
RHI_BLEND_FACTOR srcAlpha
RHI_COMPARE_OP depthCompareOp
Everything here is fixed at creation except the states listed in dynamicStates.
std::vector< RHI_BIND_GROUP_LAYOUT_DESC > bindGroupLayouts
Element n is bind group n, as passed to RHI_DEVICE::BindGroup().
std::vector< RHI_DYNAMIC_STATE > dynamicStates
RHI_TEXTURE_FORMAT colorFormat
RHI_PRIMITIVE_TOPOLOGY topology
std::vector< RHI_VERTEX_BUFFER_LAYOUT_DESC > vertexBuffers
RHI_ShaderHandle vertexShader
RHI_ShaderHandle fragmentShader
std::vector< RHI_BLEND_STATE > blendStates
One per color attachment.
bool renderPassHasDepthStencil
RHI_DEPTH_STENCIL_STATE depthStencil
One shader stage as GenerateShaderHeader.cmake embeds it.
The bytecode is SPIR-V on Vulkan and MSL source text on Metal.