Skip to content

Commit

Permalink
Expressions for call arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
houmaster committed Nov 8, 2019
1 parent 25e6fc6 commit e22c6b1
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 124 deletions.
73 changes: 44 additions & 29 deletions src/render/GLCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ void GLCall::setIndexBuffer(GLBuffer *indices, const Buffer &buffer)
mUsedItems += column->id;
mIndexBuffer = indices;
mIndexType = column->dataType;
mIndicesOffset =
static_cast<uintptr_t>(mCall.first * getStride(buffer));
mIndexSize = getStride(buffer);
}
}

Expand Down Expand Up @@ -77,7 +76,7 @@ void GLCall::execute(MessagePtrSet &messages, ScriptEngine &scriptEngine)
executeDraw(messages, scriptEngine);
break;
case Call::CallType::Compute:
executeCompute(messages);
executeCompute(messages, scriptEngine);
break;
case Call::CallType::ClearTexture:
executeClearTexture(messages);
Expand All @@ -97,6 +96,11 @@ void GLCall::execute(MessagePtrSet &messages, ScriptEngine &scriptEngine)

void GLCall::executeDraw(MessagePtrSet &messages, ScriptEngine &scriptEngine)
{
const auto evaluate = [&](const auto &expression) {
return static_cast<int>(scriptEngine.evaluateValue(
expression, mCall.id, messages));
};

if (mTarget)
mTarget->bind();

Expand All @@ -110,74 +114,81 @@ void GLCall::executeDraw(MessagePtrSet &messages, ScriptEngine &scriptEngine)
auto &gl = GLContext::currentContext();

if (mCall.primitiveType == Call::PrimitiveType::Patches && gl.v4_0)
gl.v4_0->glPatchParameteri(GL_PATCH_VERTICES, mCall.patchVertices);

auto guard = beginTimerQuery();
gl.v4_0->glPatchParameteri(GL_PATCH_VERTICES,
evaluate(mCall.patchVertices));

const auto count = static_cast<int>(scriptEngine.evaluateValue(
mCall.count, mCall.id, messages));
const auto first = evaluate(mCall.first);
const auto count = evaluate(mCall.count);
const auto instanceCount = evaluate(mCall.instanceCount);
const auto baseVertex = evaluate(mCall.baseVertex);
const auto baseInstance = evaluate(mCall.baseInstance);
const auto drawCount = evaluate(mCall.drawCount);

auto guard = beginTimerQuery();
if (mCall.callType == Call::CallType::Draw) {
// DrawArrays(InstancedBaseInstance)
if (!mCall.baseInstance) {
if (!baseInstance) {
gl.glDrawArraysInstanced(
mCall.primitiveType,
mCall.first,
first,
count,
mCall.instanceCount);
instanceCount);
}
else if (auto gl42 = check(gl.v4_2, mCall.id, messages)) {
gl42->glDrawArraysInstancedBaseInstance(
mCall.primitiveType,
mCall.first,
first,
count,
mCall.instanceCount,
static_cast<GLuint>(mCall.baseInstance));
instanceCount,
baseInstance);
}
}
else if (mCall.callType == Call::CallType::DrawIndexed) {
// DrawElements(InstancedBaseVertexBaseInstance)
if (!mCall.baseInstance && !mCall.baseVertex) {
const auto offset = static_cast<intptr_t>(first * mIndexSize);
if (!baseVertex && !baseInstance) {
gl.glDrawElementsInstanced(
mCall.primitiveType,
count,
mIndexType,
reinterpret_cast<void*>(mIndicesOffset),
mCall.instanceCount);
reinterpret_cast<void*>(offset),
instanceCount);
}
else if (auto gl42 = check(gl.v4_2, mCall.id, messages)) {
gl42->glDrawElementsInstancedBaseVertexBaseInstance(
mCall.primitiveType,
count,
mIndexType,
reinterpret_cast<void*>(mIndicesOffset),
mCall.instanceCount,
mCall.baseVertex,
static_cast<GLuint>(mCall.baseInstance));
reinterpret_cast<void*>(offset),
instanceCount,
baseVertex,
baseInstance);
}
}
else if (mCall.callType == Call::CallType::DrawIndirect) {
// (Multi)DrawArraysIndirect
if (mCall.drawCount == 1) {
if (drawCount == 1) {
if (auto gl40 = check(gl.v4_0, mCall.id, messages))
gl40->glDrawArraysIndirect(mCall.primitiveType,
reinterpret_cast<void*>(mIndirectOffset));
}
else if (auto gl43 = check(gl.v4_3, mCall.id, messages)) {
gl43->glMultiDrawArraysIndirect(mCall.primitiveType,
reinterpret_cast<void*>(mIndirectOffset), mCall.drawCount, mIndirectStride);
reinterpret_cast<void*>(mIndirectOffset),
drawCount, mIndirectStride);
}
}
else if (mCall.callType == Call::CallType::DrawIndexedIndirect) {
// (Multi)DrawElementsIndirect
if (mCall.drawCount == 1) {
if (drawCount == 1) {
if (auto gl40 = check(gl.v4_0, mCall.id, messages))
gl40->glDrawElementsIndirect(mCall.primitiveType, mIndexType,
reinterpret_cast<void*>(mIndirectOffset));
}
else if (auto gl43 = check(gl.v4_3, mCall.id, messages)) {
gl43->glMultiDrawElementsIndirect(mCall.primitiveType, mIndexType,
reinterpret_cast<void*>(mIndirectOffset), mCall.drawCount, mIndirectStride);
reinterpret_cast<void*>(mIndirectOffset),
drawCount, mIndirectStride);
}
}
}
Expand All @@ -200,16 +211,20 @@ void GLCall::executeDraw(MessagePtrSet &messages, ScriptEngine &scriptEngine)
}
}

void GLCall::executeCompute(MessagePtrSet &messages)
void GLCall::executeCompute(MessagePtrSet &messages, ScriptEngine &scriptEngine)
{
const auto evaluate = [&](const auto &expression) {
return static_cast<int>(scriptEngine.evaluateValue(
expression, mCall.id, messages));
};
if (mProgram) {
auto &gl = GLContext::currentContext();
auto guard = beginTimerQuery();
if (auto gl43 = check(gl.v4_3, mCall.id, messages))
gl43->glDispatchCompute(
static_cast<GLuint>(mCall.workGroupsX),
static_cast<GLuint>(mCall.workGroupsY),
static_cast<GLuint>(mCall.workGroupsZ));
evaluate(mCall.workGroupsX),
evaluate(mCall.workGroupsY),
evaluate(mCall.workGroupsZ));
}
else {
messages += MessageList::insert(
Expand Down
4 changes: 2 additions & 2 deletions src/render/GLCall.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class GLCall
private:
std::shared_ptr<void> beginTimerQuery();
void executeDraw(MessagePtrSet &messages, ScriptEngine &scriptEngine);
void executeCompute(MessagePtrSet &messages);
void executeCompute(MessagePtrSet &messages, ScriptEngine &scriptEngine);
void executeClearTexture(MessagePtrSet &messages);
void executeClearBuffer(MessagePtrSet &messages);
void executeGenerateMipmaps(MessagePtrSet &messages);
Expand All @@ -48,7 +48,7 @@ class GLCall

GLBuffer *mIndexBuffer{ };
GLuint mIndexType{ };
uintptr_t mIndicesOffset{ };
GLuint mIndexSize{ };

GLBuffer *mIndirectBuffer{ };
uintptr_t mIndirectOffset{ };
Expand Down
114 changes: 30 additions & 84 deletions src/session/CallProperties.ui
Original file line number Diff line number Diff line change
Expand Up @@ -101,40 +101,20 @@
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QSpinBox" name="patchVertices">
<property name="minimum">
<number>1</number>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QLabel" name="labelVertexCount">
<property name="text">
<string>Vertex Count</string>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="ExpressionLineEdit" name="vertexCount"/>
</item>
<item row="8" column="0">
<widget class="QLabel" name="labelFirstVertex">
<property name="text">
<string>First Vertex</string>
</property>
</widget>
</item>
<item row="8" column="1">
<widget class="QSpinBox" name="firstVertex">
<property name="minimum">
<number>0</number>
</property>
<property name="maximum">
<number>100000000</number>
</property>
</widget>
</item>
<item row="9" column="0">
<widget class="QLabel" name="labelIndexBuffer">
<property name="text">
Expand All @@ -152,44 +132,20 @@
</property>
</widget>
</item>
<item row="10" column="1">
<widget class="QSpinBox" name="baseVertex">
<property name="maximum">
<number>100000000</number>
</property>
</widget>
</item>
<item row="11" column="0">
<widget class="QLabel" name="labelInstanceCount">
<property name="text">
<string>Instance Count</string>
</property>
</widget>
</item>
<item row="11" column="1">
<widget class="QSpinBox" name="instanceCount">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>100000000</number>
</property>
</widget>
</item>
<item row="12" column="0">
<widget class="QLabel" name="labelBaseInstance">
<property name="text">
<string>Base Instance</string>
</property>
</widget>
</item>
<item row="12" column="1">
<widget class="QSpinBox" name="baseInstance">
<property name="maximum">
<number>100000000</number>
</property>
</widget>
</item>
<item row="13" column="0">
<widget class="QLabel" name="labelIndirectBuffer">
<property name="text">
Expand All @@ -207,67 +163,27 @@
</property>
</widget>
</item>
<item row="14" column="1">
<widget class="QSpinBox" name="drawCount">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>100000000</number>
</property>
</widget>
</item>
<item row="15" column="0">
<widget class="QLabel" name="labelWorkGroupsX">
<property name="text">
<string>Work Groups X</string>
</property>
</widget>
</item>
<item row="15" column="1">
<widget class="QSpinBox" name="workGroupsX">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>100000000</number>
</property>
</widget>
</item>
<item row="16" column="0">
<widget class="QLabel" name="labelWorkGroupsY">
<property name="text">
<string>Y</string>
</property>
</widget>
</item>
<item row="16" column="1">
<widget class="QSpinBox" name="workGroupsY">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>100000000</number>
</property>
</widget>
</item>
<item row="17" column="0">
<widget class="QLabel" name="labelWorkGroupsZ">
<property name="text">
<string>Z</string>
</property>
</widget>
</item>
<item row="17" column="1">
<widget class="QSpinBox" name="workGroupsZ">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>100000000</number>
</property>
</widget>
</item>
<item row="18" column="0">
<widget class="QLabel" name="labelBuffer">
<property name="text">
Expand Down Expand Up @@ -342,6 +258,36 @@
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="ExpressionLineEdit" name="vertexCount"/>
</item>
<item row="6" column="1">
<widget class="ExpressionLineEdit" name="patchVertices"/>
</item>
<item row="8" column="1">
<widget class="ExpressionLineEdit" name="firstVertex"/>
</item>
<item row="10" column="1">
<widget class="ExpressionLineEdit" name="baseVertex"/>
</item>
<item row="11" column="1">
<widget class="ExpressionLineEdit" name="instanceCount"/>
</item>
<item row="12" column="1">
<widget class="ExpressionLineEdit" name="baseInstance"/>
</item>
<item row="14" column="1">
<widget class="ExpressionLineEdit" name="drawCount"/>
</item>
<item row="15" column="1">
<widget class="ExpressionLineEdit" name="workGroupsX"/>
</item>
<item row="16" column="1">
<widget class="ExpressionLineEdit" name="workGroupsY"/>
</item>
<item row="17" column="1">
<widget class="ExpressionLineEdit" name="workGroupsZ"/>
</item>
</layout>
</item>
</layout>
Expand Down
Loading

0 comments on commit e22c6b1

Please sign in to comment.