mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-08-08 04:59:08 +00:00
Member rename: src/backend/opengl
This commit is contained in:
parent
b0c75a5b68
commit
7ee1610f38
@ -23,17 +23,17 @@ namespace opengl {
|
|||||||
|
|
||||||
Buffer::Buffer(BufferBuilder* builder)
|
Buffer::Buffer(BufferBuilder* builder)
|
||||||
: BufferBase(builder) {
|
: BufferBase(builder) {
|
||||||
glGenBuffers(1, &buffer);
|
glGenBuffers(1, &mBuffer);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, buffer);
|
glBindBuffer(GL_ARRAY_BUFFER, mBuffer);
|
||||||
glBufferData(GL_ARRAY_BUFFER, GetSize(), nullptr, GL_STATIC_DRAW);
|
glBufferData(GL_ARRAY_BUFFER, GetSize(), nullptr, GL_STATIC_DRAW);
|
||||||
}
|
}
|
||||||
|
|
||||||
GLuint Buffer::GetHandle() const {
|
GLuint Buffer::GetHandle() const {
|
||||||
return buffer;
|
return mBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Buffer::SetSubDataImpl(uint32_t start, uint32_t count, const uint32_t* data) {
|
void Buffer::SetSubDataImpl(uint32_t start, uint32_t count, const uint32_t* data) {
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, buffer);
|
glBindBuffer(GL_ARRAY_BUFFER, mBuffer);
|
||||||
glBufferSubData(GL_ARRAY_BUFFER, start * sizeof(uint32_t), count * sizeof(uint32_t), data);
|
glBufferSubData(GL_ARRAY_BUFFER, start * sizeof(uint32_t), count * sizeof(uint32_t), data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,13 +41,13 @@ namespace opengl {
|
|||||||
// TODO(cwallez@chromium.org): this does GPU->CPU synchronization, we could require a high
|
// TODO(cwallez@chromium.org): this does GPU->CPU synchronization, we could require a high
|
||||||
// version of OpenGL that would let us map the buffer unsynchronized.
|
// version of OpenGL that would let us map the buffer unsynchronized.
|
||||||
// TODO(cwallez@chromium.org): this crashes on Mac NVIDIA, use GetBufferSubData there instead?
|
// TODO(cwallez@chromium.org): this crashes on Mac NVIDIA, use GetBufferSubData there instead?
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, buffer);
|
glBindBuffer(GL_ARRAY_BUFFER, mBuffer);
|
||||||
void* data = glMapBufferRange(GL_ARRAY_BUFFER, start, count, GL_MAP_READ_BIT);
|
void* data = glMapBufferRange(GL_ARRAY_BUFFER, start, count, GL_MAP_READ_BIT);
|
||||||
CallMapReadCallback(serial, NXT_BUFFER_MAP_READ_STATUS_SUCCESS, data);
|
CallMapReadCallback(serial, NXT_BUFFER_MAP_READ_STATUS_SUCCESS, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Buffer::UnmapImpl() {
|
void Buffer::UnmapImpl() {
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, buffer);
|
glBindBuffer(GL_ARRAY_BUFFER, mBuffer);
|
||||||
glUnmapBuffer(GL_ARRAY_BUFFER);
|
glUnmapBuffer(GL_ARRAY_BUFFER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ namespace opengl {
|
|||||||
void UnmapImpl() override;
|
void UnmapImpl() override;
|
||||||
void TransitionUsageImpl(nxt::BufferUsageBit currentUsage, nxt::BufferUsageBit targetUsage) override;
|
void TransitionUsageImpl(nxt::BufferUsageBit currentUsage, nxt::BufferUsageBit targetUsage) override;
|
||||||
|
|
||||||
GLuint buffer = 0;
|
GLuint mBuffer = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class BufferView : public BufferViewBase {
|
class BufferView : public BufferViewBase {
|
||||||
|
@ -61,13 +61,11 @@ namespace opengl {
|
|||||||
//
|
//
|
||||||
// This structure tracks the current values of push constants as well as dirty bits for push constants
|
// This structure tracks the current values of push constants as well as dirty bits for push constants
|
||||||
// that should be applied before the next draw or dispatch.
|
// that should be applied before the next draw or dispatch.
|
||||||
struct PushConstantTracker {
|
class PushConstantTracker {
|
||||||
PerStage<std::array<uint32_t, kMaxPushConstants>> values;
|
public:
|
||||||
PerStage<std::bitset<kMaxPushConstants>> dirtyBits;
|
|
||||||
|
|
||||||
void OnBeginPass() {
|
void OnBeginPass() {
|
||||||
for (auto stage : IterateStages(kAllStages)) {
|
for (auto stage : IterateStages(kAllStages)) {
|
||||||
values[stage].fill(0);
|
mValues[stage].fill(0);
|
||||||
// No need to set dirty bits as a pipeline will be set before the next operation
|
// No need to set dirty bits as a pipeline will be set before the next operation
|
||||||
// using push constants.
|
// using push constants.
|
||||||
}
|
}
|
||||||
@ -76,17 +74,17 @@ namespace opengl {
|
|||||||
void OnSetPushConstants(nxt::ShaderStageBit stages, uint32_t count,
|
void OnSetPushConstants(nxt::ShaderStageBit stages, uint32_t count,
|
||||||
uint32_t offset, const uint32_t* data) {
|
uint32_t offset, const uint32_t* data) {
|
||||||
for (auto stage : IterateStages(stages)) {
|
for (auto stage : IterateStages(stages)) {
|
||||||
memcpy(&values[stage][offset], data, count * sizeof(uint32_t));
|
memcpy(&mValues[stage][offset], data, count * sizeof(uint32_t));
|
||||||
|
|
||||||
// Use 64 bit masks and make sure there are no shift UB
|
// Use 64 bit masks and make sure there are no shift UB
|
||||||
static_assert(kMaxPushConstants <= 8 * sizeof(unsigned long long) - 1, "");
|
static_assert(kMaxPushConstants <= 8 * sizeof(unsigned long long) - 1, "");
|
||||||
dirtyBits[stage] |= ((1ull << count) - 1ull) << offset;
|
mDirtyBits[stage] |= ((1ull << count) - 1ull) << offset;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnSetPipeline(PipelineBase* pipeline) {
|
void OnSetPipeline(PipelineBase* pipeline) {
|
||||||
for (auto stage : IterateStages(kAllStages)) {
|
for (auto stage : IterateStages(kAllStages)) {
|
||||||
dirtyBits[stage] = pipeline->GetPushConstants(stage).mask;
|
mDirtyBits[stage] = pipeline->GetPushConstants(stage).mask;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,88 +93,84 @@ namespace opengl {
|
|||||||
const auto& pushConstants = pipeline->GetPushConstants(stage);
|
const auto& pushConstants = pipeline->GetPushConstants(stage);
|
||||||
const auto& glPushConstants = glPipeline->GetGLPushConstants(stage);
|
const auto& glPushConstants = glPipeline->GetGLPushConstants(stage);
|
||||||
|
|
||||||
for (uint32_t constant : IterateBitSet(dirtyBits[stage] & pushConstants.mask)) {
|
for (uint32_t constant : IterateBitSet(mDirtyBits[stage] & pushConstants.mask)) {
|
||||||
GLint location = glPushConstants[constant];
|
GLint location = glPushConstants[constant];
|
||||||
switch (pushConstants.types[constant]) {
|
switch (pushConstants.types[constant]) {
|
||||||
case PushConstantType::Int:
|
case PushConstantType::Int:
|
||||||
glUniform1i(location, *reinterpret_cast<GLint*>(&values[stage][constant]));
|
glUniform1i(location, *reinterpret_cast<GLint*>(&mValues[stage][constant]));
|
||||||
break;
|
break;
|
||||||
case PushConstantType::UInt:
|
case PushConstantType::UInt:
|
||||||
glUniform1ui(location, *reinterpret_cast<GLuint*>(&values[stage][constant]));
|
glUniform1ui(location, *reinterpret_cast<GLuint*>(&mValues[stage][constant]));
|
||||||
break;
|
break;
|
||||||
case PushConstantType::Float:
|
case PushConstantType::Float:
|
||||||
glUniform1f(location, *reinterpret_cast<GLfloat*>(&values[stage][constant]));
|
glUniform1f(location, *reinterpret_cast<GLfloat*>(&mValues[stage][constant]));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dirtyBits[stage].reset();
|
mDirtyBits[stage].reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
PerStage<std::array<uint32_t, kMaxPushConstants>> mValues;
|
||||||
|
PerStage<std::bitset<kMaxPushConstants>> mDirtyBits;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Vertex buffers and index buffers are implemented as part of an OpenGL VAO that corresponds to an
|
// Vertex buffers and index buffers are implemented as part of an OpenGL VAO that corresponds to an
|
||||||
// InputState. On the contrary in NXT they are part of the global state. This means that we have to
|
// InputState. On the contrary in NXT they are part of the global state. This means that we have to
|
||||||
// re-apply these buffers on an InputState change.
|
// re-apply these buffers on an InputState change.
|
||||||
struct InputBufferTracker {
|
class InputBufferTracker {
|
||||||
bool indexBufferDirty = false;
|
public:
|
||||||
Buffer* indexBuffer = nullptr;
|
|
||||||
|
|
||||||
std::bitset<kMaxVertexInputs> dirtyVertexBuffers;
|
|
||||||
std::array<Buffer*, kMaxVertexInputs> vertexBuffers;
|
|
||||||
std::array<uint32_t, kMaxVertexInputs> vertexBufferOffsets;
|
|
||||||
|
|
||||||
InputState* lastInputState = nullptr;
|
|
||||||
|
|
||||||
void OnBeginPass() {
|
void OnBeginPass() {
|
||||||
// We don't know what happened between this pass and the last one, just reset the
|
// We don't know what happened between this pass and the last one, just reset the
|
||||||
// input state so everything gets reapplied.
|
// input state so everything gets reapplied.
|
||||||
lastInputState = nullptr;
|
mLastInputState = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnSetIndexBuffer(BufferBase* buffer) {
|
void OnSetIndexBuffer(BufferBase* buffer) {
|
||||||
indexBufferDirty = true;
|
mIndexBufferDirty = true;
|
||||||
indexBuffer = ToBackend(buffer);
|
mIndexBuffer = ToBackend(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnSetVertexBuffers(uint32_t startSlot, uint32_t count, Ref<BufferBase>* buffers, uint32_t* offsets) {
|
void OnSetVertexBuffers(uint32_t startSlot, uint32_t count, Ref<BufferBase>* buffers, uint32_t* offsets) {
|
||||||
for (uint32_t i = 0; i < count; ++i) {
|
for (uint32_t i = 0; i < count; ++i) {
|
||||||
uint32_t slot = startSlot + i;
|
uint32_t slot = startSlot + i;
|
||||||
vertexBuffers[slot] = ToBackend(buffers[i].Get());
|
mVertexBuffers[slot] = ToBackend(buffers[i].Get());
|
||||||
vertexBufferOffsets[slot] = offsets[i];
|
mVertexBufferOffsets[slot] = offsets[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use 64 bit masks and make sure there are no shift UB
|
// Use 64 bit masks and make sure there are no shift UB
|
||||||
static_assert(kMaxVertexInputs <= 8 * sizeof(unsigned long long) - 1, "");
|
static_assert(kMaxVertexInputs <= 8 * sizeof(unsigned long long) - 1, "");
|
||||||
dirtyVertexBuffers |= ((1ull << count) - 1ull) << startSlot;
|
mDirtyVertexBuffers |= ((1ull << count) - 1ull) << startSlot;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnSetPipeline(RenderPipelineBase* pipeline) {
|
void OnSetPipeline(RenderPipelineBase* pipeline) {
|
||||||
InputStateBase* inputState = pipeline->GetInputState();
|
InputStateBase* inputState = pipeline->GetInputState();
|
||||||
if (lastInputState == inputState) {
|
if (mLastInputState == inputState) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
indexBufferDirty = true;
|
mIndexBufferDirty = true;
|
||||||
dirtyVertexBuffers |= inputState->GetInputsSetMask();
|
mDirtyVertexBuffers |= inputState->GetInputsSetMask();
|
||||||
|
|
||||||
lastInputState = ToBackend(inputState);
|
mLastInputState = ToBackend(inputState);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Apply() {
|
void Apply() {
|
||||||
if (indexBufferDirty && indexBuffer != nullptr) {
|
if (mIndexBufferDirty && mIndexBuffer != nullptr) {
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer->GetHandle());
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mIndexBuffer->GetHandle());
|
||||||
indexBufferDirty = false;
|
mIndexBufferDirty = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint32_t slot : IterateBitSet(dirtyVertexBuffers & lastInputState->GetInputsSetMask())) {
|
for (uint32_t slot : IterateBitSet(mDirtyVertexBuffers & mLastInputState->GetInputsSetMask())) {
|
||||||
for (uint32_t location : IterateBitSet(lastInputState->GetAttributesUsingInput(slot))) {
|
for (uint32_t location : IterateBitSet(mLastInputState->GetAttributesUsingInput(slot))) {
|
||||||
auto attribute = lastInputState->GetAttribute(location);
|
auto attribute = mLastInputState->GetAttribute(location);
|
||||||
|
|
||||||
GLuint buffer = vertexBuffers[slot]->GetHandle();
|
GLuint buffer = mVertexBuffers[slot]->GetHandle();
|
||||||
uint32_t offset = vertexBufferOffsets[slot];
|
uint32_t offset = mVertexBufferOffsets[slot];
|
||||||
|
|
||||||
auto input = lastInputState->GetInput(slot);
|
auto input = mLastInputState->GetInput(slot);
|
||||||
auto components = VertexFormatNumComponents(attribute.format);
|
auto components = VertexFormatNumComponents(attribute.format);
|
||||||
auto formatType = VertexFormatType(attribute.format);
|
auto formatType = VertexFormatType(attribute.format);
|
||||||
|
|
||||||
@ -188,18 +182,28 @@ namespace opengl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dirtyVertexBuffers.reset();
|
mDirtyVertexBuffers.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool mIndexBufferDirty = false;
|
||||||
|
Buffer* mIndexBuffer = nullptr;
|
||||||
|
|
||||||
|
std::bitset<kMaxVertexInputs> mDirtyVertexBuffers;
|
||||||
|
std::array<Buffer*, kMaxVertexInputs> mVertexBuffers;
|
||||||
|
std::array<uint32_t, kMaxVertexInputs> mVertexBufferOffsets;
|
||||||
|
|
||||||
|
InputState* mLastInputState = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CommandBuffer::CommandBuffer(CommandBufferBuilder* builder)
|
CommandBuffer::CommandBuffer(CommandBufferBuilder* builder)
|
||||||
: CommandBufferBase(builder), commands(builder->AcquireCommands()) {
|
: CommandBufferBase(builder), mCommands(builder->AcquireCommands()) {
|
||||||
}
|
}
|
||||||
|
|
||||||
CommandBuffer::~CommandBuffer() {
|
CommandBuffer::~CommandBuffer() {
|
||||||
FreeCommands(&commands);
|
FreeCommands(&mCommands);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommandBuffer::Execute() {
|
void CommandBuffer::Execute() {
|
||||||
@ -220,18 +224,18 @@ namespace opengl {
|
|||||||
uint32_t currentSubpass = 0;
|
uint32_t currentSubpass = 0;
|
||||||
GLuint currentFBO = 0;
|
GLuint currentFBO = 0;
|
||||||
|
|
||||||
while(commands.NextCommandId(&type)) {
|
while(mCommands.NextCommandId(&type)) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case Command::BeginComputePass:
|
case Command::BeginComputePass:
|
||||||
{
|
{
|
||||||
commands.NextCommand<BeginComputePassCmd>();
|
mCommands.NextCommand<BeginComputePassCmd>();
|
||||||
pushConstants.OnBeginPass();
|
pushConstants.OnBeginPass();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Command::BeginRenderPass:
|
case Command::BeginRenderPass:
|
||||||
{
|
{
|
||||||
auto* cmd = commands.NextCommand<BeginRenderPassCmd>();
|
auto* cmd = mCommands.NextCommand<BeginRenderPassCmd>();
|
||||||
currentRenderPass = ToBackend(cmd->renderPass.Get());
|
currentRenderPass = ToBackend(cmd->renderPass.Get());
|
||||||
currentFramebuffer = ToBackend(cmd->framebuffer.Get());
|
currentFramebuffer = ToBackend(cmd->framebuffer.Get());
|
||||||
currentSubpass = 0;
|
currentSubpass = 0;
|
||||||
@ -240,7 +244,7 @@ namespace opengl {
|
|||||||
|
|
||||||
case Command::BeginRenderSubpass:
|
case Command::BeginRenderSubpass:
|
||||||
{
|
{
|
||||||
commands.NextCommand<BeginRenderSubpassCmd>();
|
mCommands.NextCommand<BeginRenderSubpassCmd>();
|
||||||
pushConstants.OnBeginPass();
|
pushConstants.OnBeginPass();
|
||||||
inputBuffers.OnBeginPass();
|
inputBuffers.OnBeginPass();
|
||||||
|
|
||||||
@ -359,7 +363,7 @@ namespace opengl {
|
|||||||
|
|
||||||
case Command::CopyBufferToBuffer:
|
case Command::CopyBufferToBuffer:
|
||||||
{
|
{
|
||||||
CopyBufferToBufferCmd* copy = commands.NextCommand<CopyBufferToBufferCmd>();
|
CopyBufferToBufferCmd* copy = mCommands.NextCommand<CopyBufferToBufferCmd>();
|
||||||
auto& src = copy->source;
|
auto& src = copy->source;
|
||||||
auto& dst = copy->destination;
|
auto& dst = copy->destination;
|
||||||
|
|
||||||
@ -374,7 +378,7 @@ namespace opengl {
|
|||||||
|
|
||||||
case Command::CopyBufferToTexture:
|
case Command::CopyBufferToTexture:
|
||||||
{
|
{
|
||||||
CopyBufferToTextureCmd* copy = commands.NextCommand<CopyBufferToTextureCmd>();
|
CopyBufferToTextureCmd* copy = mCommands.NextCommand<CopyBufferToTextureCmd>();
|
||||||
auto& src = copy->source;
|
auto& src = copy->source;
|
||||||
auto& dst = copy->destination;
|
auto& dst = copy->destination;
|
||||||
Buffer* buffer = ToBackend(src.buffer.Get());
|
Buffer* buffer = ToBackend(src.buffer.Get());
|
||||||
@ -398,7 +402,7 @@ namespace opengl {
|
|||||||
|
|
||||||
case Command::CopyTextureToBuffer:
|
case Command::CopyTextureToBuffer:
|
||||||
{
|
{
|
||||||
CopyTextureToBufferCmd* copy = commands.NextCommand<CopyTextureToBufferCmd>();
|
CopyTextureToBufferCmd* copy = mCommands.NextCommand<CopyTextureToBufferCmd>();
|
||||||
auto& src = copy->source;
|
auto& src = copy->source;
|
||||||
auto& dst = copy->destination;
|
auto& dst = copy->destination;
|
||||||
Texture* texture = ToBackend(src.texture.Get());
|
Texture* texture = ToBackend(src.texture.Get());
|
||||||
@ -431,7 +435,7 @@ namespace opengl {
|
|||||||
|
|
||||||
case Command::Dispatch:
|
case Command::Dispatch:
|
||||||
{
|
{
|
||||||
DispatchCmd* dispatch = commands.NextCommand<DispatchCmd>();
|
DispatchCmd* dispatch = mCommands.NextCommand<DispatchCmd>();
|
||||||
pushConstants.Apply(lastPipeline, lastGLPipeline);
|
pushConstants.Apply(lastPipeline, lastGLPipeline);
|
||||||
glDispatchCompute(dispatch->x, dispatch->y, dispatch->z);
|
glDispatchCompute(dispatch->x, dispatch->y, dispatch->z);
|
||||||
// TODO(cwallez@chromium.org): add barriers to the API
|
// TODO(cwallez@chromium.org): add barriers to the API
|
||||||
@ -441,7 +445,7 @@ namespace opengl {
|
|||||||
|
|
||||||
case Command::DrawArrays:
|
case Command::DrawArrays:
|
||||||
{
|
{
|
||||||
DrawArraysCmd* draw = commands.NextCommand<DrawArraysCmd>();
|
DrawArraysCmd* draw = mCommands.NextCommand<DrawArraysCmd>();
|
||||||
pushConstants.Apply(lastPipeline, lastGLPipeline);
|
pushConstants.Apply(lastPipeline, lastGLPipeline);
|
||||||
inputBuffers.Apply();
|
inputBuffers.Apply();
|
||||||
|
|
||||||
@ -458,7 +462,7 @@ namespace opengl {
|
|||||||
|
|
||||||
case Command::DrawElements:
|
case Command::DrawElements:
|
||||||
{
|
{
|
||||||
DrawElementsCmd* draw = commands.NextCommand<DrawElementsCmd>();
|
DrawElementsCmd* draw = mCommands.NextCommand<DrawElementsCmd>();
|
||||||
pushConstants.Apply(lastPipeline, lastGLPipeline);
|
pushConstants.Apply(lastPipeline, lastGLPipeline);
|
||||||
inputBuffers.Apply();
|
inputBuffers.Apply();
|
||||||
|
|
||||||
@ -483,19 +487,19 @@ namespace opengl {
|
|||||||
|
|
||||||
case Command::EndComputePass:
|
case Command::EndComputePass:
|
||||||
{
|
{
|
||||||
commands.NextCommand<EndComputePassCmd>();
|
mCommands.NextCommand<EndComputePassCmd>();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Command::EndRenderPass:
|
case Command::EndRenderPass:
|
||||||
{
|
{
|
||||||
commands.NextCommand<EndRenderPassCmd>();
|
mCommands.NextCommand<EndRenderPassCmd>();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Command::EndRenderSubpass:
|
case Command::EndRenderSubpass:
|
||||||
{
|
{
|
||||||
commands.NextCommand<EndRenderSubpassCmd>();
|
mCommands.NextCommand<EndRenderSubpassCmd>();
|
||||||
glDeleteFramebuffers(1, ¤tFBO);
|
glDeleteFramebuffers(1, ¤tFBO);
|
||||||
currentFBO = 0;
|
currentFBO = 0;
|
||||||
currentSubpass += 1;
|
currentSubpass += 1;
|
||||||
@ -504,7 +508,7 @@ namespace opengl {
|
|||||||
|
|
||||||
case Command::SetComputePipeline:
|
case Command::SetComputePipeline:
|
||||||
{
|
{
|
||||||
SetComputePipelineCmd* cmd = commands.NextCommand<SetComputePipelineCmd>();
|
SetComputePipelineCmd* cmd = mCommands.NextCommand<SetComputePipelineCmd>();
|
||||||
ToBackend(cmd->pipeline)->ApplyNow();
|
ToBackend(cmd->pipeline)->ApplyNow();
|
||||||
lastGLPipeline = ToBackend(cmd->pipeline).Get();
|
lastGLPipeline = ToBackend(cmd->pipeline).Get();
|
||||||
lastPipeline = ToBackend(cmd->pipeline).Get();
|
lastPipeline = ToBackend(cmd->pipeline).Get();
|
||||||
@ -514,7 +518,7 @@ namespace opengl {
|
|||||||
|
|
||||||
case Command::SetRenderPipeline:
|
case Command::SetRenderPipeline:
|
||||||
{
|
{
|
||||||
SetRenderPipelineCmd* cmd = commands.NextCommand<SetRenderPipelineCmd>();
|
SetRenderPipelineCmd* cmd = mCommands.NextCommand<SetRenderPipelineCmd>();
|
||||||
ToBackend(cmd->pipeline)->ApplyNow(persistentPipelineState);
|
ToBackend(cmd->pipeline)->ApplyNow(persistentPipelineState);
|
||||||
lastRenderPipeline = ToBackend(cmd->pipeline).Get();
|
lastRenderPipeline = ToBackend(cmd->pipeline).Get();
|
||||||
lastGLPipeline = ToBackend(cmd->pipeline).Get();
|
lastGLPipeline = ToBackend(cmd->pipeline).Get();
|
||||||
@ -527,29 +531,29 @@ namespace opengl {
|
|||||||
|
|
||||||
case Command::SetPushConstants:
|
case Command::SetPushConstants:
|
||||||
{
|
{
|
||||||
SetPushConstantsCmd* cmd = commands.NextCommand<SetPushConstantsCmd>();
|
SetPushConstantsCmd* cmd = mCommands.NextCommand<SetPushConstantsCmd>();
|
||||||
uint32_t* data = commands.NextData<uint32_t>(cmd->count);
|
uint32_t* data = mCommands.NextData<uint32_t>(cmd->count);
|
||||||
pushConstants.OnSetPushConstants(cmd->stages, cmd->count, cmd->offset, data);
|
pushConstants.OnSetPushConstants(cmd->stages, cmd->count, cmd->offset, data);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Command::SetStencilReference:
|
case Command::SetStencilReference:
|
||||||
{
|
{
|
||||||
SetStencilReferenceCmd* cmd = commands.NextCommand<SetStencilReferenceCmd>();
|
SetStencilReferenceCmd* cmd = mCommands.NextCommand<SetStencilReferenceCmd>();
|
||||||
persistentPipelineState.SetStencilReference(cmd->reference);
|
persistentPipelineState.SetStencilReference(cmd->reference);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Command::SetBlendColor:
|
case Command::SetBlendColor:
|
||||||
{
|
{
|
||||||
SetBlendColorCmd* cmd = commands.NextCommand<SetBlendColorCmd>();
|
SetBlendColorCmd* cmd = mCommands.NextCommand<SetBlendColorCmd>();
|
||||||
glBlendColor(cmd->r, cmd->g, cmd->b, cmd->a);
|
glBlendColor(cmd->r, cmd->g, cmd->b, cmd->a);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Command::SetBindGroup:
|
case Command::SetBindGroup:
|
||||||
{
|
{
|
||||||
SetBindGroupCmd* cmd = commands.NextCommand<SetBindGroupCmd>();
|
SetBindGroupCmd* cmd = mCommands.NextCommand<SetBindGroupCmd>();
|
||||||
size_t groupIndex = cmd->index;
|
size_t groupIndex = cmd->index;
|
||||||
BindGroup* group = ToBackend(cmd->group.Get());
|
BindGroup* group = ToBackend(cmd->group.Get());
|
||||||
|
|
||||||
@ -610,7 +614,7 @@ namespace opengl {
|
|||||||
|
|
||||||
case Command::SetIndexBuffer:
|
case Command::SetIndexBuffer:
|
||||||
{
|
{
|
||||||
SetIndexBufferCmd* cmd = commands.NextCommand<SetIndexBufferCmd>();
|
SetIndexBufferCmd* cmd = mCommands.NextCommand<SetIndexBufferCmd>();
|
||||||
indexBufferOffset = cmd->offset;
|
indexBufferOffset = cmd->offset;
|
||||||
inputBuffers.OnSetIndexBuffer(cmd->buffer.Get());
|
inputBuffers.OnSetIndexBuffer(cmd->buffer.Get());
|
||||||
}
|
}
|
||||||
@ -618,16 +622,16 @@ namespace opengl {
|
|||||||
|
|
||||||
case Command::SetVertexBuffers:
|
case Command::SetVertexBuffers:
|
||||||
{
|
{
|
||||||
SetVertexBuffersCmd* cmd = commands.NextCommand<SetVertexBuffersCmd>();
|
SetVertexBuffersCmd* cmd = mCommands.NextCommand<SetVertexBuffersCmd>();
|
||||||
auto buffers = commands.NextData<Ref<BufferBase>>(cmd->count);
|
auto buffers = mCommands.NextData<Ref<BufferBase>>(cmd->count);
|
||||||
auto offsets = commands.NextData<uint32_t>(cmd->count);
|
auto offsets = mCommands.NextData<uint32_t>(cmd->count);
|
||||||
inputBuffers.OnSetVertexBuffers(cmd->startSlot, cmd->count, buffers, offsets);
|
inputBuffers.OnSetVertexBuffers(cmd->startSlot, cmd->count, buffers, offsets);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Command::TransitionBufferUsage:
|
case Command::TransitionBufferUsage:
|
||||||
{
|
{
|
||||||
TransitionBufferUsageCmd* cmd = commands.NextCommand<TransitionBufferUsageCmd>();
|
TransitionBufferUsageCmd* cmd = mCommands.NextCommand<TransitionBufferUsageCmd>();
|
||||||
|
|
||||||
cmd->buffer->UpdateUsageInternal(cmd->usage);
|
cmd->buffer->UpdateUsageInternal(cmd->usage);
|
||||||
}
|
}
|
||||||
@ -635,7 +639,7 @@ namespace opengl {
|
|||||||
|
|
||||||
case Command::TransitionTextureUsage:
|
case Command::TransitionTextureUsage:
|
||||||
{
|
{
|
||||||
TransitionTextureUsageCmd* cmd = commands.NextCommand<TransitionTextureUsageCmd>();
|
TransitionTextureUsageCmd* cmd = mCommands.NextCommand<TransitionTextureUsageCmd>();
|
||||||
|
|
||||||
cmd->texture->UpdateUsageInternal(cmd->usage);
|
cmd->texture->UpdateUsageInternal(cmd->usage);
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ namespace opengl {
|
|||||||
void Execute();
|
void Execute();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CommandIterator commands;
|
CommandIterator mCommands;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -22,8 +22,8 @@ namespace opengl {
|
|||||||
|
|
||||||
InputState::InputState(InputStateBuilder* builder)
|
InputState::InputState(InputStateBuilder* builder)
|
||||||
: InputStateBase(builder) {
|
: InputStateBase(builder) {
|
||||||
glGenVertexArrays(1, &vertexArrayObject);
|
glGenVertexArrays(1, &mVertexArrayObject);
|
||||||
glBindVertexArray(vertexArrayObject);
|
glBindVertexArray(mVertexArrayObject);
|
||||||
auto& attributesSetMask = GetAttributesSetMask();
|
auto& attributesSetMask = GetAttributesSetMask();
|
||||||
for (uint32_t location = 0; location < attributesSetMask.size(); ++location) {
|
for (uint32_t location = 0; location < attributesSetMask.size(); ++location) {
|
||||||
if (!attributesSetMask[location]) {
|
if (!attributesSetMask[location]) {
|
||||||
@ -58,7 +58,7 @@ namespace opengl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
GLuint InputState::GetVAO() {
|
GLuint InputState::GetVAO() {
|
||||||
return vertexArrayObject;
|
return mVertexArrayObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ namespace opengl {
|
|||||||
GLuint GetVAO();
|
GLuint GetVAO();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GLuint vertexArrayObject;
|
GLuint mVertexArrayObject;
|
||||||
std::array<std::bitset<kMaxVertexAttributes>, kMaxVertexInputs> attributesUsingInput;
|
std::array<std::bitset<kMaxVertexAttributes>, kMaxVertexInputs> attributesUsingInput;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -24,36 +24,36 @@ namespace opengl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PersistentPipelineState::SetStencilFuncsAndMask(GLenum stencilBackCompareFunction, GLenum stencilFrontCompareFunction, uint32_t stencilReadMask) {
|
void PersistentPipelineState::SetStencilFuncsAndMask(GLenum stencilBackCompareFunction, GLenum stencilFrontCompareFunction, uint32_t stencilReadMask) {
|
||||||
if (this->stencilBackCompareFunction == stencilBackCompareFunction &&
|
if (mStencilBackCompareFunction == stencilBackCompareFunction &&
|
||||||
this->stencilFrontCompareFunction == stencilFrontCompareFunction &&
|
mStencilFrontCompareFunction == stencilFrontCompareFunction &&
|
||||||
this->stencilReadMask == stencilReadMask) {
|
mStencilReadMask == stencilReadMask) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->stencilBackCompareFunction = stencilBackCompareFunction;
|
mStencilBackCompareFunction = stencilBackCompareFunction;
|
||||||
this->stencilFrontCompareFunction = stencilFrontCompareFunction;
|
mStencilFrontCompareFunction = stencilFrontCompareFunction;
|
||||||
this->stencilReadMask = stencilReadMask;
|
mStencilReadMask = stencilReadMask;
|
||||||
CallGLStencilFunc();
|
CallGLStencilFunc();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PersistentPipelineState::SetStencilReference(uint32_t stencilReference) {
|
void PersistentPipelineState::SetStencilReference(uint32_t stencilReference) {
|
||||||
if (this->stencilReference == stencilReference) {
|
if (mStencilReference == stencilReference) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->stencilReference = stencilReference;
|
mStencilReference = stencilReference;
|
||||||
CallGLStencilFunc();
|
CallGLStencilFunc();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PersistentPipelineState::CallGLStencilFunc() {
|
void PersistentPipelineState::CallGLStencilFunc() {
|
||||||
glStencilFuncSeparate(GL_BACK,
|
glStencilFuncSeparate(GL_BACK,
|
||||||
stencilBackCompareFunction,
|
mStencilBackCompareFunction,
|
||||||
stencilReference,
|
mStencilReference,
|
||||||
stencilReadMask);
|
mStencilReadMask);
|
||||||
glStencilFuncSeparate(GL_FRONT,
|
glStencilFuncSeparate(GL_FRONT,
|
||||||
stencilFrontCompareFunction,
|
mStencilFrontCompareFunction,
|
||||||
stencilReference,
|
mStencilReference,
|
||||||
stencilReadMask);
|
mStencilReadMask);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -31,10 +31,10 @@ namespace opengl {
|
|||||||
private:
|
private:
|
||||||
void CallGLStencilFunc();
|
void CallGLStencilFunc();
|
||||||
|
|
||||||
GLenum stencilBackCompareFunction = GL_ALWAYS;
|
GLenum mStencilBackCompareFunction = GL_ALWAYS;
|
||||||
GLenum stencilFrontCompareFunction = GL_ALWAYS;
|
GLenum mStencilFrontCompareFunction = GL_ALWAYS;
|
||||||
GLuint stencilReadMask = 0xffffffff;
|
GLuint mStencilReadMask = 0xffffffff;
|
||||||
GLuint stencilReference = 0;
|
GLuint mStencilReference = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -87,26 +87,26 @@ namespace opengl {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
program = glCreateProgram();
|
mProgram = glCreateProgram();
|
||||||
|
|
||||||
for (auto stage : IterateStages(parent->GetStageMask())) {
|
for (auto stage : IterateStages(parent->GetStageMask())) {
|
||||||
const ShaderModule* module = ToBackend(builder->GetStageInfo(stage).module.Get());
|
const ShaderModule* module = ToBackend(builder->GetStageInfo(stage).module.Get());
|
||||||
|
|
||||||
GLuint shader = CreateShader(GLShaderType(stage), module->GetSource());
|
GLuint shader = CreateShader(GLShaderType(stage), module->GetSource());
|
||||||
glAttachShader(program, shader);
|
glAttachShader(mProgram, shader);
|
||||||
}
|
}
|
||||||
|
|
||||||
glLinkProgram(program);
|
glLinkProgram(mProgram);
|
||||||
|
|
||||||
GLint linkStatus = GL_FALSE;
|
GLint linkStatus = GL_FALSE;
|
||||||
glGetProgramiv(program, GL_LINK_STATUS, &linkStatus);
|
glGetProgramiv(mProgram, GL_LINK_STATUS, &linkStatus);
|
||||||
if (linkStatus == GL_FALSE) {
|
if (linkStatus == GL_FALSE) {
|
||||||
GLint infoLogLength = 0;
|
GLint infoLogLength = 0;
|
||||||
glGetProgramiv(program, GL_INFO_LOG_LENGTH, &infoLogLength);
|
glGetProgramiv(mProgram, GL_INFO_LOG_LENGTH, &infoLogLength);
|
||||||
|
|
||||||
if (infoLogLength > 1) {
|
if (infoLogLength > 1) {
|
||||||
std::vector<char> buffer(infoLogLength);
|
std::vector<char> buffer(infoLogLength);
|
||||||
glGetProgramInfoLog(program, infoLogLength, nullptr, &buffer[0]);
|
glGetProgramInfoLog(mProgram, infoLogLength, nullptr, &buffer[0]);
|
||||||
std::cout << "Program link failed:\n";
|
std::cout << "Program link failed:\n";
|
||||||
std::cout << buffer.data() << std::endl;
|
std::cout << buffer.data() << std::endl;
|
||||||
}
|
}
|
||||||
@ -114,10 +114,10 @@ namespace opengl {
|
|||||||
|
|
||||||
for (auto stage : IterateStages(parent->GetStageMask())) {
|
for (auto stage : IterateStages(parent->GetStageMask())) {
|
||||||
const ShaderModule* module = ToBackend(builder->GetStageInfo(stage).module.Get());
|
const ShaderModule* module = ToBackend(builder->GetStageInfo(stage).module.Get());
|
||||||
FillPushConstants(module, &glPushConstants[stage], program);
|
FillPushConstants(module, &mGlPushConstants[stage], mProgram);
|
||||||
}
|
}
|
||||||
|
|
||||||
glUseProgram(program);
|
glUseProgram(mProgram);
|
||||||
|
|
||||||
// The uniforms are part of the program state so we can pre-bind buffer units, texture units etc.
|
// The uniforms are part of the program state so we can pre-bind buffer units, texture units etc.
|
||||||
const auto& layout = ToBackend(parent->GetLayout());
|
const auto& layout = ToBackend(parent->GetLayout());
|
||||||
@ -135,15 +135,15 @@ namespace opengl {
|
|||||||
switch (groupInfo.types[binding]) {
|
switch (groupInfo.types[binding]) {
|
||||||
case nxt::BindingType::UniformBuffer:
|
case nxt::BindingType::UniformBuffer:
|
||||||
{
|
{
|
||||||
GLint location = glGetUniformBlockIndex(program, name.c_str());
|
GLint location = glGetUniformBlockIndex(mProgram, name.c_str());
|
||||||
glUniformBlockBinding(program, location, indices[group][binding]);
|
glUniformBlockBinding(mProgram, location, indices[group][binding]);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case nxt::BindingType::StorageBuffer:
|
case nxt::BindingType::StorageBuffer:
|
||||||
{
|
{
|
||||||
GLuint location = glGetProgramResourceIndex(program, GL_SHADER_STORAGE_BLOCK, name.c_str());
|
GLuint location = glGetProgramResourceIndex(mProgram, GL_SHADER_STORAGE_BLOCK, name.c_str());
|
||||||
glShaderStorageBlockBinding(program, location, indices[group][binding]);
|
glShaderStorageBlockBinding(mProgram, location, indices[group][binding]);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -167,20 +167,20 @@ namespace opengl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unitsForSamplers.resize(layout->GetNumSamplers());
|
mUnitsForSamplers.resize(layout->GetNumSamplers());
|
||||||
unitsForTextures.resize(layout->GetNumSampledTextures());
|
mUnitsForTextures.resize(layout->GetNumSampledTextures());
|
||||||
|
|
||||||
GLuint textureUnit = layout->GetTextureUnitsUsed();
|
GLuint textureUnit = layout->GetTextureUnitsUsed();
|
||||||
for (const auto& combined : combinedSamplersSet) {
|
for (const auto& combined : combinedSamplersSet) {
|
||||||
std::string name = combined.GetName();
|
std::string name = combined.GetName();
|
||||||
GLint location = glGetUniformLocation(program, name.c_str());
|
GLint location = glGetUniformLocation(mProgram, name.c_str());
|
||||||
glUniform1i(location, textureUnit);
|
glUniform1i(location, textureUnit);
|
||||||
|
|
||||||
GLuint samplerIndex = indices[combined.samplerLocation.group][combined.samplerLocation.binding];
|
GLuint samplerIndex = indices[combined.samplerLocation.group][combined.samplerLocation.binding];
|
||||||
unitsForSamplers[samplerIndex].push_back(textureUnit);
|
mUnitsForSamplers[samplerIndex].push_back(textureUnit);
|
||||||
|
|
||||||
GLuint textureIndex = indices[combined.textureLocation.group][combined.textureLocation.binding];
|
GLuint textureIndex = indices[combined.textureLocation.group][combined.textureLocation.binding];
|
||||||
unitsForTextures[textureIndex].push_back(textureUnit);
|
mUnitsForTextures[textureIndex].push_back(textureUnit);
|
||||||
|
|
||||||
textureUnit ++;
|
textureUnit ++;
|
||||||
}
|
}
|
||||||
@ -188,25 +188,25 @@ namespace opengl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const PipelineGL::GLPushConstantInfo& PipelineGL::GetGLPushConstants(nxt::ShaderStage stage) const {
|
const PipelineGL::GLPushConstantInfo& PipelineGL::GetGLPushConstants(nxt::ShaderStage stage) const {
|
||||||
return glPushConstants[stage];
|
return mGlPushConstants[stage];
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<GLuint>& PipelineGL::GetTextureUnitsForSampler(GLuint index) const {
|
const std::vector<GLuint>& PipelineGL::GetTextureUnitsForSampler(GLuint index) const {
|
||||||
ASSERT(index < unitsForSamplers.size());
|
ASSERT(index < mUnitsForSamplers.size());
|
||||||
return unitsForSamplers[index];
|
return mUnitsForSamplers[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<GLuint>& PipelineGL::GetTextureUnitsForTexture(GLuint index) const {
|
const std::vector<GLuint>& PipelineGL::GetTextureUnitsForTexture(GLuint index) const {
|
||||||
ASSERT(index < unitsForSamplers.size());
|
ASSERT(index < mUnitsForSamplers.size());
|
||||||
return unitsForTextures[index];
|
return mUnitsForTextures[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
GLuint PipelineGL::GetProgramHandle() const {
|
GLuint PipelineGL::GetProgramHandle() const {
|
||||||
return program;
|
return mProgram;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PipelineGL::ApplyNow() {
|
void PipelineGL::ApplyNow() {
|
||||||
glUseProgram(program);
|
glUseProgram(mProgram);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -43,10 +43,10 @@ namespace opengl {
|
|||||||
void ApplyNow();
|
void ApplyNow();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GLuint program;
|
GLuint mProgram;
|
||||||
PerStage<GLPushConstantInfo> glPushConstants;
|
PerStage<GLPushConstantInfo> mGlPushConstants;
|
||||||
std::vector<std::vector<GLuint>> unitsForSamplers;
|
std::vector<std::vector<GLuint>> mUnitsForSamplers;
|
||||||
std::vector<std::vector<GLuint>> unitsForTextures;
|
std::vector<std::vector<GLuint>> mUnitsForTextures;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -36,32 +36,32 @@ namespace opengl {
|
|||||||
|
|
||||||
switch (groupInfo.types[binding]) {
|
switch (groupInfo.types[binding]) {
|
||||||
case nxt::BindingType::UniformBuffer:
|
case nxt::BindingType::UniformBuffer:
|
||||||
indexInfo[group][binding] = uboIndex;
|
mIndexInfo[group][binding] = uboIndex;
|
||||||
uboIndex ++;
|
uboIndex ++;
|
||||||
break;
|
break;
|
||||||
case nxt::BindingType::Sampler:
|
case nxt::BindingType::Sampler:
|
||||||
indexInfo[group][binding] = samplerIndex;
|
mIndexInfo[group][binding] = samplerIndex;
|
||||||
samplerIndex ++;
|
samplerIndex ++;
|
||||||
break;
|
break;
|
||||||
case nxt::BindingType::SampledTexture:
|
case nxt::BindingType::SampledTexture:
|
||||||
indexInfo[group][binding] = sampledTextureIndex;
|
mIndexInfo[group][binding] = sampledTextureIndex;
|
||||||
sampledTextureIndex ++;
|
sampledTextureIndex ++;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case nxt::BindingType::StorageBuffer:
|
case nxt::BindingType::StorageBuffer:
|
||||||
indexInfo[group][binding] = ssboIndex;
|
mIndexInfo[group][binding] = ssboIndex;
|
||||||
ssboIndex ++;
|
ssboIndex ++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
numSamplers = samplerIndex;
|
mNumSamplers = samplerIndex;
|
||||||
numSampledTextures = sampledTextureIndex;
|
mNumSampledTextures = sampledTextureIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
const PipelineLayout::BindingIndexInfo& PipelineLayout::GetBindingIndexInfo() const {
|
const PipelineLayout::BindingIndexInfo& PipelineLayout::GetBindingIndexInfo() const {
|
||||||
return indexInfo;
|
return mIndexInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
GLuint PipelineLayout::GetTextureUnitsUsed() const {
|
GLuint PipelineLayout::GetTextureUnitsUsed() const {
|
||||||
@ -69,11 +69,11 @@ namespace opengl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t PipelineLayout::GetNumSamplers() const {
|
size_t PipelineLayout::GetNumSamplers() const {
|
||||||
return numSamplers;
|
return mNumSamplers;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t PipelineLayout::GetNumSampledTextures() const {
|
size_t PipelineLayout::GetNumSampledTextures() const {
|
||||||
return numSampledTextures;
|
return mNumSampledTextures;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -36,9 +36,9 @@ namespace opengl {
|
|||||||
size_t GetNumSampledTextures() const;
|
size_t GetNumSampledTextures() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BindingIndexInfo indexInfo;
|
BindingIndexInfo mIndexInfo;
|
||||||
size_t numSamplers;
|
size_t mNumSamplers;
|
||||||
size_t numSampledTextures;
|
size_t mNumSampledTextures;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -44,11 +44,11 @@ namespace opengl {
|
|||||||
|
|
||||||
RenderPipeline::RenderPipeline(RenderPipelineBuilder* builder)
|
RenderPipeline::RenderPipeline(RenderPipelineBuilder* builder)
|
||||||
: RenderPipelineBase(builder), PipelineGL(this, builder),
|
: RenderPipelineBase(builder), PipelineGL(this, builder),
|
||||||
glPrimitiveTopology(GLPrimitiveTopology(GetPrimitiveTopology())) {
|
mGlPrimitiveTopology(GLPrimitiveTopology(GetPrimitiveTopology())) {
|
||||||
}
|
}
|
||||||
|
|
||||||
GLenum RenderPipeline::GetGLPrimitiveTopology() const {
|
GLenum RenderPipeline::GetGLPrimitiveTopology() const {
|
||||||
return glPrimitiveTopology;
|
return mGlPrimitiveTopology;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderPipeline::ApplyNow(PersistentPipelineState &persistentPipelineState) {
|
void RenderPipeline::ApplyNow(PersistentPipelineState &persistentPipelineState) {
|
||||||
|
@ -37,7 +37,7 @@ namespace opengl {
|
|||||||
void ApplyNow(PersistentPipelineState &persistentPipelineState);
|
void ApplyNow(PersistentPipelineState &persistentPipelineState);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GLenum glPrimitiveTopology;
|
GLenum mGlPrimitiveTopology;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -59,13 +59,13 @@ namespace opengl {
|
|||||||
|
|
||||||
Sampler::Sampler(SamplerBuilder* builder)
|
Sampler::Sampler(SamplerBuilder* builder)
|
||||||
: SamplerBase(builder) {
|
: SamplerBase(builder) {
|
||||||
glGenSamplers(1, &handle);
|
glGenSamplers(1, &mHandle);
|
||||||
glSamplerParameteri(handle, GL_TEXTURE_MAG_FILTER, MagFilterMode(builder->GetMagFilter()));
|
glSamplerParameteri(mHandle, GL_TEXTURE_MAG_FILTER, MagFilterMode(builder->GetMagFilter()));
|
||||||
glSamplerParameteri(handle, GL_TEXTURE_MIN_FILTER, MinFilterMode(builder->GetMinFilter(), builder->GetMipMapFilter()));
|
glSamplerParameteri(mHandle, GL_TEXTURE_MIN_FILTER, MinFilterMode(builder->GetMinFilter(), builder->GetMipMapFilter()));
|
||||||
}
|
}
|
||||||
|
|
||||||
GLuint Sampler::GetHandle() const {
|
GLuint Sampler::GetHandle() const {
|
||||||
return handle;
|
return mHandle;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ namespace opengl {
|
|||||||
GLuint GetHandle() const;
|
GLuint GetHandle() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GLuint handle;
|
GLuint mHandle;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -92,9 +92,9 @@ namespace opengl {
|
|||||||
compiler.build_combined_image_samplers();
|
compiler.build_combined_image_samplers();
|
||||||
|
|
||||||
for (const auto& combined : compiler.get_combined_image_samplers()) {
|
for (const auto& combined : compiler.get_combined_image_samplers()) {
|
||||||
combinedInfo.emplace_back();
|
mCombinedInfo.emplace_back();
|
||||||
|
|
||||||
auto& info = combinedInfo.back();
|
auto& info = mCombinedInfo.back();
|
||||||
info.samplerLocation.group = compiler.get_decoration(combined.sampler_id, spv::DecorationDescriptorSet);
|
info.samplerLocation.group = compiler.get_decoration(combined.sampler_id, spv::DecorationDescriptorSet);
|
||||||
info.samplerLocation.binding = compiler.get_decoration(combined.sampler_id, spv::DecorationBinding);
|
info.samplerLocation.binding = compiler.get_decoration(combined.sampler_id, spv::DecorationBinding);
|
||||||
info.textureLocation.group = compiler.get_decoration(combined.image_id, spv::DecorationDescriptorSet);
|
info.textureLocation.group = compiler.get_decoration(combined.image_id, spv::DecorationDescriptorSet);
|
||||||
@ -116,15 +116,15 @@ namespace opengl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
glslSource = compiler.compile();
|
mGlslSource = compiler.compile();
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* ShaderModule::GetSource() const {
|
const char* ShaderModule::GetSource() const {
|
||||||
return reinterpret_cast<const char*>(glslSource.data());
|
return reinterpret_cast<const char*>(mGlslSource.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
const ShaderModule::CombinedSamplerInfo& ShaderModule::GetCombinedSamplerInfo() const {
|
const ShaderModule::CombinedSamplerInfo& ShaderModule::GetCombinedSamplerInfo() const {
|
||||||
return combinedInfo;
|
return mCombinedInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -49,8 +49,8 @@ namespace opengl {
|
|||||||
const CombinedSamplerInfo& GetCombinedSamplerInfo() const;
|
const CombinedSamplerInfo& GetCombinedSamplerInfo() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CombinedSamplerInfo combinedInfo;
|
CombinedSamplerInfo mCombinedInfo;
|
||||||
std::string glslSource;
|
std::string mGlslSource;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -64,8 +64,8 @@ namespace opengl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Texture::Texture(TextureBuilder* builder, GLuint handle)
|
Texture::Texture(TextureBuilder* builder, GLuint handle)
|
||||||
: TextureBase(builder), handle(handle) {
|
: TextureBase(builder), mHandle(handle) {
|
||||||
target = TargetForDimension(GetDimension());
|
mTarget = TargetForDimension(GetDimension());
|
||||||
|
|
||||||
uint32_t width = GetWidth();
|
uint32_t width = GetWidth();
|
||||||
uint32_t height = GetHeight();
|
uint32_t height = GetHeight();
|
||||||
@ -73,17 +73,17 @@ namespace opengl {
|
|||||||
|
|
||||||
auto formatInfo = GetGLFormatInfo(GetFormat());
|
auto formatInfo = GetGLFormatInfo(GetFormat());
|
||||||
|
|
||||||
glBindTexture(target, handle);
|
glBindTexture(mTarget, handle);
|
||||||
|
|
||||||
for (uint32_t i = 0; i < levels; ++i) {
|
for (uint32_t i = 0; i < levels; ++i) {
|
||||||
glTexImage2D(target, i, formatInfo.internalFormat, width, height, 0, formatInfo.format, formatInfo.type, nullptr);
|
glTexImage2D(mTarget, i, formatInfo.internalFormat, width, height, 0, formatInfo.format, formatInfo.type, nullptr);
|
||||||
width = std::max(uint32_t(1), width / 2);
|
width = std::max(uint32_t(1), width / 2);
|
||||||
height = std::max(uint32_t(1), height / 2);
|
height = std::max(uint32_t(1), height / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
// The texture is not complete if it uses mipmapping and not all levels up to
|
// The texture is not complete if it uses mipmapping and not all levels up to
|
||||||
// MAX_LEVEL have been defined.
|
// MAX_LEVEL have been defined.
|
||||||
glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, levels - 1);
|
glTexParameteri(mTarget, GL_TEXTURE_MAX_LEVEL, levels - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
Texture::~Texture() {
|
Texture::~Texture() {
|
||||||
@ -91,11 +91,11 @@ namespace opengl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
GLuint Texture::GetHandle() const {
|
GLuint Texture::GetHandle() const {
|
||||||
return handle;
|
return mHandle;
|
||||||
}
|
}
|
||||||
|
|
||||||
GLenum Texture::GetGLTarget() const {
|
GLenum Texture::GetGLTarget() const {
|
||||||
return target;
|
return mTarget;
|
||||||
}
|
}
|
||||||
|
|
||||||
TextureFormatInfo Texture::GetGLFormat() const {
|
TextureFormatInfo Texture::GetGLFormat() const {
|
||||||
|
@ -43,8 +43,8 @@ namespace opengl {
|
|||||||
void TransitionUsageImpl(nxt::TextureUsageBit currentUsage, nxt::TextureUsageBit targetUsage) override;
|
void TransitionUsageImpl(nxt::TextureUsageBit currentUsage, nxt::TextureUsageBit targetUsage) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GLuint handle;
|
GLuint mHandle;
|
||||||
GLenum target;
|
GLenum mTarget;
|
||||||
};
|
};
|
||||||
|
|
||||||
class TextureView : public TextureViewBase {
|
class TextureView : public TextureViewBase {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user