GithubHelp home page GithubHelp logo

Comments (9)

CookiePLMonster avatar CookiePLMonster commented on June 14, 2024 1

You are right about alignas, true. And since we only need a single bit the assert could even be >= 2 - which makes it even less likely it's ever an issue.

I'd say opt for nothing and maybe just include this assumption in a comment above the code doing the bit shifting witchcraft.

from d3d8to9.

crosire avatar crosire commented on June 14, 2024

The bottom 16 bits are reserved for the FVF codes that can be passed into the SetVertexShader method. That's why I use the highest bit.

from d3d8to9.

CookiePLMonster avatar CookiePLMonster commented on June 14, 2024

I see... what about using the top bit AND shr'ing the pointer by 1 (thus assuming at-least-2-byte alignment on pointer which can be assumed safely) then? Maybe large addresses could be supported this way.

from d3d8to9.

crosire avatar crosire commented on June 14, 2024

"shr'ing"? Shifting?

from d3d8to9.

CookiePLMonster avatar CookiePLMonster commented on June 14, 2024

SHifting to Right, yes. Since the addresses are at least 4 byte aligned bottom bit can safely be discarded, so the top bit can be reused for tagging.

from d3d8to9.

crosire avatar crosire commented on June 14, 2024

Yes, sounds reasonable. To be 100% safe vertex_shader_info could be declared like this: struct alignas(4) vertex_shader_info { ... }; or struct __declspec(align(4)) vertex_shader_info { ... }; for compatibility with older compilers.

from d3d8to9.

CookiePLMonster avatar CookiePLMonster commented on June 14, 2024

malloc (which new should use internally) is guaranteed to be aligned to 8 bytes on x86 platforms (and 16 bytes on x64). Moreover, malloc/new do not respect __declspec(align) and probably alignas too, so you'd need to use _aligned_malloc for that.

I'd leave it as is and assume 8b alignment is real. After all, only one byte is needed so for it to break you would need to get a pointer which isn't even an even number!

EDIT: If in doubt, maybe put assert((mem & 1) == 0)?

from d3d8to9.

crosire avatar crosire commented on June 14, 2024

Well, alignas technically does work with new unless the type is over-aligned, which since we are on x86 won't happen as allocations align to 8 bytes (alignof(std::max_align_t)), as you mentioned.
But yeah, could also do static_assert(alignof(std::max_align_t) >= 4, "Well, shit") or nothing at all. Nothing at all is probably enough here.

from d3d8to9.

CookiePLMonster avatar CookiePLMonster commented on June 14, 2024

See #8

from d3d8to9.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.