1#include "ContextCommon.h"
3#include "../IBuffers.h"
5#include "Foundation/Logging/Logger.h"
19 return prevUploadStats;
23 prevStats = currStats;
26 prevUploadStats = currUploadStats;
30void Cogs::ContextCommon::frameStatisticsAccountDrawCall(
size_t count,
bool indexed)
35 if ((t & 0xFFFF0000) != 0) { bucket += 16; t = t >> 16u; }
36 if ((t & 0x0000FF00) != 0) { bucket += 8; t = t >> 8u; }
37 if ((t & 0x000000F0) != 0) { bucket += 4; t = t >> 4u; }
38 if ((t & 0x0000000C) != 0) { bucket += 2; t = t >> 2u; }
39 if ((t & 0x00000002) != 0) { bucket += 1; }
42 assert(uint64_t(count) < (uint64_t(1) << (bucket + 1)));
44 assert((uint64_t(1) << bucket) <= uint64_t(count));
51 currStats.drawCallHistogram[bucket]++;
52 currStats.vertices += count;
53 if (indexed) currStats.indices += count;
56void Cogs::ContextCommon::uploadStatisticsBufferUpload(
size_t size)
58 currUploadStats.bufferUploads++;
59 currUploadStats.bufferUploadSize += size;
62void Cogs::ContextCommon::uploadStatisticsTextureUpload(
size_t size)
64 currUploadStats.textureUploads++;
65 currUploadStats.textureUploadSize += size;
70 setConstantBuffer(getEffects()->getConstantBufferBinding(getCurrentEffect(), name), bufferHandle, offset, size);
74 auto binding = getEffects()->getBufferBinding(getCurrentEffect(), name);
75 setBuffer(binding, bufferHandle);
76 getEffects()->releaseBufferBinding(binding);
80 setTexture(getEffects()->getTextureBinding(getCurrentEffect(), name, unit), textureHandle);
84 setTexture(getEffects()->getTextureBinding(getCurrentEffect(), name, 0), textureViewHandle);
88 setSamplerState(getEffects()->getSamplerStateBinding(getCurrentEffect(), name, unit), handle);
91void Cogs::ContextCommon::setCurrentEffect(
Effect * currentEffect)
93 this->effect = currentEffect;
96void Cogs::ContextCommon::updateConstantBuffers()
100 auto updateConstantBuffer = [&](ShaderConstantBuffer & constantBuffer) {
101 if (!constantBuffer.dirty || constantBuffer.manual)
return;
106 std::memcpy(mappedBuffer, constantBuffer.memoryBuffer.data(), constantBuffer.memoryBuffer.size());
108 constantBuffer.dirty =
false;
111 for (
auto & shader : effect->shaders) {
112 for (
auto & constantBuffer : shader.reflection.constantBuffers) {
114 updateConstantBuffer(constantBuffer);
124 std::memcpy(mappedBuffer, data, size);
127 LOG_ERROR_ONCE(logger,
"updateBuffer: Faild to map buffer");
133 LOG_ERROR_ONCE(logger,
"Rendering context does not support vertex array objects.");
Log implementation class.
Provides a weakly referenced view over the contents of a string.
bool HandleIsValid(const ResourceHandle_t< T > &handle)
Check if the given resource is valid, that is not equal to NoHandle or InvalidHandle.
constexpr Log getLogger(const char(&name)[LEN]) noexcept
void frameStatisticsBeginFrame()
void setConstantBuffer(const StringView &name, const BufferHandle bufferHandle, const uint32_t offset, const uint32_t size) final
Sets a constant buffer to be bound to the given name and slot.
void setSamplerState(const StringView &name, unsigned int unit, SamplerStateHandle handle) final
Sets the sampler slot given by unit with the given name to contain the given sampler state.
void setVertexArrayObject(VertexArrayObjectHandle vertexArrayObject) override
void updateBuffer(BufferHandle bufferHandle, const void *data, size_t size) override
Replace contents of buffer with new data.
void setTexture(const StringView &name, unsigned int unit, TextureHandle textureHandle) final
Sets the texture slot given by unit with the given name to contain the given texture.
void setBuffer(const StringView &name, BufferHandle bufferHandle) final
Sets the given buffer to the buffer binding slot with the given name.
@ WriteDiscard
Write access. When unmapping the graphics system will discard the old contents of the resource.
Provides RAII style mapping of a buffer resource.