Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Glsl.meta.slang raytracing #3560 #10

Closed

Conversation

jkwak-work
Copy link
Owner

This PR is only for a code review purpose.

ArielG-NV and others added 4 commits February 16, 2024 14:29
all functions part of ray_query, shader_invocation_reorder and ray_tracing_motion_blur are implemented for GLSL.meta. If HLSL lacks an implementation equal GLSL/SPIR-V was implemented without an HLSL equivalent in HLSL.meta (anticipation of HLSL equivalent function eventually); completed

built in variables have only been stubbed thus far; NOT completed

the following commit sets up formatting & tests for all ray_query functions (compute shader); completed

the commit also sets up structure for compile testing glsl raytracing shaders; NOT completed
…L_EXT_ray_query, GLSL_NV_shader_invocation_reorder & GLSL_NV_ray_tracing_motion_blur

Implement all functions & built-in variables (with tests) for the GLSL_EXT_ray_query, GLSL_NV_shader_invocation_reorder & GLSL_NV_ray_tracing_motion_blur glsl extension based on specification (https://github.com/KhronosGroup/GLSL/blob/main/extensions/nv/).

implementation details of worth{
All functions with alternatives in GLSL->HLSL have been implemented in GLSL, HLSL & SPRI-V (hlsl implementation has a few errors); otherwise only GLSL & SPIR-V was implemented.
* modified slang compiler to add support for query'ing and fetching raytracing payloads/attributes based on bound layout(location) and input a 'constexpr int'. This allows'dynamic typing' for these operations to late evaluate all location tied raytracing objects. An attribute to functions were also added to force setting a generic's type based on a payload object (this is also required to allow 'generic typed' raytracing object functions); all of the hacky generic forcing will be removed in next commit in regards to removing hlsl code

GL_EXT_ray_tracing was NOT implemented and part of scope of this commit, they will be for the next commit

This commit will be overrided with removing HLSL functions and logic. commit is happening just to keep code history

}

testing details of worth{
Raytracing shader (non compute, compute can test properly) tests only test compiling and opcodes due to testing system limitations
}
…L_EXT_ray_tracing, GLSL_EXT_ray_query, GLSL_NV_shader_invocation_reorder & GLSL_NV_ray_tracing_motion_blur glsl extension based on specification (https://github.com/KhronosGroup/GLSL/blob/main/extensions/).

implementation details of worth{
spirv required direct referencing of raytracing objects, as a result, __rayPayloadFromLocation, __rayAttributeFromLocation, and __rayCallableFromLocation, all take in a integer literal and use this to add a placeholder to fillin with an actual layout(location) bound object.

layout(location) bound raytracing objects are never optimized out, this was intentionally added to the code.

GL_EXT_ray_tracing was implemented as noted in the commit description.

all HLSL support has been removed.
}

testing details of worth{
Raytracing shader tests only test compiling and opcodes due to testing system limitations (raygen, intersection, miss, anyhit cover all raytracing functions/builtins/syntax); Compute raytracing works with actual value testing
}
change dictionary usage to be more correct syntax-wise

compact and organize parser code to be more like other parser code (this structure is important since there will be many attributes along with layout() syntax later on)

code style adjustments to match slang use of braces
Copy link
Owner Author

@jkwak-work jkwak-work left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks good to me overall.

@@ -74,14 +76,14 @@ void rayGenerationMain()
someValues);

uint r = calcValue(hit);
// SPIRV: OpReorderThreadWithHitObjectNV
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this test removed?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I broke the tests during development; I forgot to add them back since I broke them at the start; I am adding them 👍

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this file removed?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are not tests and go against the .gitignore; they don't do anything

Comment on lines +17 to +35
__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>
bool equals(matrix<T, N, M> lhs, matrix<T, N, M> rhs)
{
for (int i = 0; i < N; i++)
{
for (int j = 0; j < M; j++)
{
if (
lhs[i][j]
!=
rhs[i][j]
)
{
return false;
}
}
}
return true;
}
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we have a equality testing function already for Matrix?

Copy link

@ArielG-NV ArielG-NV Mar 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we do not, other testing code also has an "equals" function for this purpose

Comment on lines 4343 to 4351
else if (kIROp_SPIRVAsmOperandRayCallableFromLocation == op)
{
varLayoutPointsTo = this->getRayCallableVariableFromLocation(intLitValue);
}
else
{
// should be impossible to hit
assert(false);
}
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be better with

else
{
    SLANG_ASSERT(kIROp_SPIRVAsmOperandRayCallableFromLocation == op);
    varLayoutPointsTo = this->getRayCallableVariableFromLocation(intLitValue);
}

Copy link
Owner Author

@jkwak-work jkwak-work left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have some comments.

Comment on lines 9534 to 9535
//__target_intrinsic(glsl, RayDesc)
//__target_intrinsic(spirv, RayDesc)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you either uncomment these or remove?

Comment on lines 9835 to 9836
case _GL_EXT_ray_tracing:
case glsl: __intrinsic_asm "reportIntersectionEXT";
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change actually needed?
It seems like _GL_EXT_ray_tracing will cover all the GLSL target, doesn't it?

Copy link

@ArielG-NV ArielG-NV Mar 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

glsl->_GL_EXT_ray_tracing does/did not seem to work, this is needed
I think its a superset->subset type of problem (_GL_EXT_ray_tracing -> glsl is fine, other way is not)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean you don't need to have "case _GL_EXT_ray_tracing" when you have "case glsl"?

Copy link

@ArielG-NV ArielG-NV Mar 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some code & tests enable/use the _GL_EXT_ray_tracing (hlsl->glsl) capability, I use glsl capability instead (but the code is identical since both are glsl)

Comment on lines 9896 to 9897
case glsl:
case glsl:
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks to be a mistake.
There should be only one "glsl" case.

Comment on lines 12204 to 12206
spirv_asm {
result:$$float = OpHitObjectGetCurrentTimeNV &this
};
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this have "return"?

return spirv_asm { ... };

Comment on lines 2962 to 2974
goto rayExtensionAddition;
case kIROp_VulkanHitObjectAttributesDecoration:
// needed since GLSL will not set optypes accordingly, but will keep the decoration
ensureExtensionDeclaration(UnownedStringSlice("SPV_NV_shader_invocation_reorder"));
requireSPIRVCapability(SpvCapabilityShaderInvocationReorderNV);
goto rayExtensionAddition;
case kIROp_VulkanRayPayloadDecoration:
case kIROp_VulkanRayPayloadInDecoration:
// needed since GLSL will not set optypes accordingly, but will keep the decoration
ensureExtensionDeclaration(UnownedStringSlice("SPV_KHR_ray_query"));
requireSPIRVCapability(SpvCapabilityRayQueryKHR);
goto rayExtensionAddition;
rayExtensionAddition:;
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not use GOTO within switch statement.
In this case, you can set a temporary variable to be true and handle the action later.

bool isRayExtension = false;
...
case kIROp_VulkanCallablePayloadInDecoration:
...
    isRayExtension = true;
    break;
...
if (isRayExtension)
{
   emitOpDecorateLocation(...);
}

In general, "goto" should be limited to error handling; not for code reuse.

IRSPIRVAsmOperand* IRBuilder::emitSPIRVAsmOperandRayPayloadFromLocation(IRInst* inst)
{
SLANG_ASSERT(as<IRSPIRVAsm>(m_insertLoc.getParent()));
const auto i = createInst<IRSPIRVAsmOperand>(
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that you shouldn't have const here because your return type doesn't have const and "i" will be returned.

Copy link

@ArielG-NV ArielG-NV Mar 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const is used since other functions which do the same thing also set a const ptr for return; likely const is used since in the function we are signaling that the ptr's value won't change value between instantiation and returning

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"const" is not a "signal"-ing keyword, and it cannot automatically become non-const.
Something doesn't look right on this code to me.

Copy link

@ArielG-NV ArielG-NV Mar 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did some checking, in godbolt -- it should not compile in MSVC (without a flag), nor does it likely emit different ASM... I will check to see if there is a reason the other functions use a const~

Copy link

@ArielG-NV ArielG-NV Mar 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope, just a cause of warnings; I suppose I will remove all of the const'ness from these type of functions and if there is a question of why that will be a different discussion

@@ -2239,6 +2240,8 @@ struct IRAnalysis
IRDominatorTree* getDominatorTree();
};

struct DiagnosticSink;
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may need to move this line up to the top where other classes are declared; around line 28~38.

@@ -7013,6 +7013,27 @@ namespace Slang
{
return SPIRVAsmOperand{ SPIRVAsmOperand::NonSemanticDebugPrintfExtSet, parser->ReadToken() };
}
else if (AdvanceIf(parser, "__rayPayloadFromLocation")) {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should keep the coding style same as how the previous code was written.
Please add a new line character between ")" and "{".
I see that this mistake occurs on multiple lines in this PR.

@@ -7771,6 +7793,20 @@ namespace Slang
parser->ReadToken(TokenType::Comma);
}

#define CASE(key, type) if (AdvanceIf(parser, #key)) { auto modifier = parser->astBuilder->create<type>(); \
modifier->location = getIntegerLiteralValue(listBuilder.find<GLSLLayoutModifier>()->valToken); listBuilder.add(modifier); } else
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is "modifier->location" only for debugging purpose?

Copy link

@ArielG-NV ArielG-NV Mar 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

modifier->location is for creating a modifier and tying a glsl layout(location) location value to it

@jkwak-work
Copy link
Owner Author

Looks good to me

fix various code-style warnings

fix vkray regression: remove assumption that layout-val will be attached to a vk object decoration (causes crashes in some specific senarios)

add missing ext's to hlsl.meta

removed __specialized_for_target(glsl) for specific function due to causing a regression and not doing anything functional
@ArielG-NV ArielG-NV force-pushed the glsl.meta.slang_raytracing_#3560 branch from 9f4ec6e to b8c3f4c Compare March 5, 2024 19:34
…syntax + glsl syntax for raytracing objects as well, which is quite cool)

changed comment about early raytracing object addition to ir (more about positioning of code emitted)
change code emit'ing to ensure it emits properly at top of scope

refactored a bit of the descriptions to be more accurate for why we need things done the way they are
…ess conflicts

changed spirv replacement to be proper and not a hacky 'working' implementation (since the code is being finalized now and I don't need a 'just working' implementation for testing)
@jkwak-work jkwak-work closed this Mar 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants